blob: 5bf196379c474dd67579e24cc02585c67faafe65 [file] [log] [blame]
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -07001/*
2 * This file is part of the coreboot project.
3 *
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -07004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020015#include <device/pci_ops.h>
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070016#include <console/console.h>
17#include <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
Subrata Banik7837c202018-05-07 17:13:40 +053020#include <intelblocks/p2sb.h>
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070021#include <soc/iomap.h>
Subrata Banik7837c202018-05-07 17:13:40 +053022#include <soc/p2sb.h>
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070023#include <soc/pci_devs.h>
Subrata Banik7837c202018-05-07 17:13:40 +053024#include <string.h>
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070025
Subrata Banik7837c202018-05-07 17:13:40 +053026#define PCH_P2SB_EPMASK(mask_number) (PCH_P2SB_EPMASK0 + ((mask_number) * 4))
27
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070028#define HIDE_BIT (1 << 0)
29
Subrata Banik7837c202018-05-07 17:13:40 +053030void p2sb_enable_bar(void)
31{
32 /* Enable PCR Base address in PCH */
Nico Hubere5495032020-02-17 18:26:51 +010033 pci_write_config32(PCH_DEV_P2SB, PCI_BASE_ADDRESS_0, P2SB_BAR);
34 pci_write_config32(PCH_DEV_P2SB, PCI_BASE_ADDRESS_1, 0);
Subrata Banik7837c202018-05-07 17:13:40 +053035
36 /* Enable P2SB MSE */
Nico Hubere5495032020-02-17 18:26:51 +010037 pci_write_config8(PCH_DEV_P2SB, PCI_COMMAND,
Subrata Banik7837c202018-05-07 17:13:40 +053038 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
39}
40
41/*
42 * Enable decoding for HPET range.
43 * This is needed for FspMemoryInit to store and retrieve a global data
44 * pointer.
45 */
46void p2sb_configure_hpet(void)
47{
48 /*
49 * Enable decoding for HPET memory address range.
50 * HPTC_OFFSET(0x60) bit 7, when set the P2SB will decode
51 * the High Performance Timer memory address range
52 * selected by bits 1:0
53 */
Nico Hubere5495032020-02-17 18:26:51 +010054 pci_write_config8(PCH_DEV_P2SB, HPTC_OFFSET, HPTC_ADDR_ENABLE_BIT);
Subrata Banik7837c202018-05-07 17:13:40 +053055}
56
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070057static void p2sb_set_hide_bit(int hide)
58{
Subrata Banik7837c202018-05-07 17:13:40 +053059 const uint16_t reg = PCH_P2SB_E0 + 1;
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070060 const uint8_t mask = HIDE_BIT;
61 uint8_t val;
62
Nico Hubere5495032020-02-17 18:26:51 +010063 val = pci_read_config8(PCH_DEV_P2SB, reg);
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070064 val &= ~mask;
65 if (hide)
66 val |= mask;
Nico Hubere5495032020-02-17 18:26:51 +010067 pci_write_config8(PCH_DEV_P2SB, reg, val);
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070068}
69
70void p2sb_unhide(void)
71{
72 p2sb_set_hide_bit(0);
Subrata Banik7837c202018-05-07 17:13:40 +053073
Nico Hubere5495032020-02-17 18:26:51 +010074 if (pci_read_config16(PCH_DEV_P2SB, PCI_VENDOR_ID) !=
Subrata Banik7837c202018-05-07 17:13:40 +053075 PCI_VENDOR_ID_INTEL)
Keith Short15588b02019-05-09 11:40:34 -060076 die_with_post_code(POST_HW_INIT_FAILURE,
77 "Unable to unhide PCH_DEV_P2SB device !\n");
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070078}
79
80void p2sb_hide(void)
81{
82 p2sb_set_hide_bit(1);
Subrata Banik7837c202018-05-07 17:13:40 +053083
Nico Hubere5495032020-02-17 18:26:51 +010084 if (pci_read_config16(PCH_DEV_P2SB, PCI_VENDOR_ID) !=
Subrata Banik7837c202018-05-07 17:13:40 +053085 0xFFFF)
Keith Short15588b02019-05-09 11:40:34 -060086 die_with_post_code(POST_HW_INIT_FAILURE,
87 "Unable to hide PCH_DEV_P2SB device !\n");
Subrata Banik7837c202018-05-07 17:13:40 +053088}
89
90static void p2sb_configure_endpoints(int epmask_id, uint32_t mask)
91{
92 uint32_t reg32;
93
Nico Hubere5495032020-02-17 18:26:51 +010094 reg32 = pci_read_config32(PCH_DEV_P2SB, PCH_P2SB_EPMASK(epmask_id));
95 pci_write_config32(PCH_DEV_P2SB, PCH_P2SB_EPMASK(epmask_id),
Subrata Banik7837c202018-05-07 17:13:40 +053096 reg32 | mask);
97}
98
99static void p2sb_lock_endpoints(void)
100{
101 uint8_t reg8;
102
103 /* Set the "Endpoint Mask Lock!", P2SB PCI offset E2h bit[1] to 1. */
Nico Hubere5495032020-02-17 18:26:51 +0100104 reg8 = pci_read_config8(PCH_DEV_P2SB, PCH_P2SB_E0 + 2);
105 pci_write_config8(PCH_DEV_P2SB, PCH_P2SB_E0 + 2,
Subrata Banik7837c202018-05-07 17:13:40 +0530106 reg8 | P2SB_E0_MASKLOCK);
107}
108
109void p2sb_disable_sideband_access(void)
110{
111 uint32_t ep_mask[P2SB_EP_MASK_MAX_REG];
112 int i;
113
114 memset(ep_mask, 0, sizeof(ep_mask));
115
116 p2sb_soc_get_sb_mask(ep_mask, ARRAY_SIZE(ep_mask));
117
118 /* Remove the host accessing right to PSF register range. */
119 for (i = 0; i < P2SB_EP_MASK_MAX_REG; i++)
120 p2sb_configure_endpoints(i, ep_mask[i]);
121
122 p2sb_lock_endpoints();
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -0700123}
124
125static void read_resources(struct device *dev)
126{
127 /*
128 * There's only one resource on the P2SB device. It's also already
129 * manually set to a fixed address in earlier boot stages.
Patrick Rudolph8d7a89b2019-10-04 09:22:27 +0200130 * The following code makes sure that it doesn't change if the device
131 * is visible and the resource allocator is being run.
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -0700132 */
133 mmio_resource(dev, PCI_BASE_ADDRESS_0, P2SB_BAR / KiB, P2SB_SIZE / KiB);
134}
135
136static const struct device_operations device_ops = {
137 .read_resources = read_resources,
138 .set_resources = DEVICE_NOOP,
Subrata Banik6bbc91a2017-12-07 14:55:51 +0530139 .ops_pci = &pci_dev_ops_pci,
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -0700140};
141
142static const unsigned short pci_device_ids[] = {
143 PCI_DEVICE_ID_INTEL_APL_P2SB,
144 PCI_DEVICE_ID_INTEL_GLK_P2SB,
Maxim Polyakov571d07d2019-08-22 13:11:32 +0300145 PCI_DEVICE_ID_INTEL_LWB_P2SB,
146 PCI_DEVICE_ID_INTEL_LWB_P2SB_SUPER,
Patrick Rudolph8d7a89b2019-10-04 09:22:27 +0200147 PCI_DEVICE_ID_INTEL_SKL_LP_P2SB,
148 PCI_DEVICE_ID_INTEL_SKL_P2SB,
149 PCI_DEVICE_ID_INTEL_KBL_P2SB,
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -0700150 PCI_DEVICE_ID_INTEL_CNL_P2SB,
praveen hodagatta praneshe26c4a42018-09-20 03:49:45 +0800151 PCI_DEVICE_ID_INTEL_CNP_H_P2SB,
Aamir Bohra9eac0392018-06-30 12:07:04 +0530152 PCI_DEVICE_ID_INTEL_ICL_P2SB,
Ronak Kanabarda7ffb482019-02-05 01:51:13 +0530153 PCI_DEVICE_ID_INTEL_CMP_P2SB,
Gaggery Tsai12a651c2019-12-05 11:23:20 -0800154 PCI_DEVICE_ID_INTEL_CMP_H_P2SB,
Ravi Sarawadi6b5bf402019-10-21 22:25:04 -0700155 PCI_DEVICE_ID_INTEL_TGL_P2SB,
Tan, Lean Sheng26136092020-01-20 19:13:56 -0800156 PCI_DEVICE_ID_INTEL_EHL_P2SB,
Meera Ravindranath3f4af0d2020-02-12 16:01:22 +0530157 PCI_DEVICE_ID_INTEL_JSP_P2SB,
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -0700158 0,
159};
160
161static const struct pci_driver pmc __pci_driver = {
162 .ops = &device_ops,
163 .vendor = PCI_VENDOR_ID_INTEL,
164 .devices = pci_device_ids,
165};