Angel Pons | 0612b27 | 2020-04-05 15:46:56 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 3 | #include <device/pci_ops.h> |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 8 | #include <intelblocks/p2sb.h> |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 9 | #include <soc/iomap.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 10 | #include <soc/p2sb.h> |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 11 | #include <soc/pci_devs.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 12 | #include <string.h> |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 13 | |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 14 | #define PCH_P2SB_EPMASK(mask_number) (PCH_P2SB_EPMASK0 + ((mask_number) * 4)) |
| 15 | |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 16 | #define HIDE_BIT (1 << 0) |
| 17 | |
Arthur Heymans | a8798a3 | 2020-11-12 20:41:57 +0100 | [diff] [blame] | 18 | static bool p2sb_is_hidden(void) |
| 19 | { |
| 20 | const uint16_t pci_vid = pci_read_config16(PCH_DEV_P2SB, PCI_VENDOR_ID); |
| 21 | |
| 22 | if (pci_vid == 0xffff) |
| 23 | return true; |
| 24 | if (pci_vid == PCI_VENDOR_ID_INTEL) |
| 25 | return false; |
| 26 | printk(BIOS_ERR, "P2SB PCI_VENDOR_ID is invalid, unknown if hidden\n"); |
| 27 | return true; |
| 28 | } |
| 29 | |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 30 | void p2sb_enable_bar(void) |
| 31 | { |
| 32 | /* Enable PCR Base address in PCH */ |
Nico Huber | e549503 | 2020-02-17 18:26:51 +0100 | [diff] [blame] | 33 | 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 Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 35 | |
| 36 | /* Enable P2SB MSE */ |
Elyes HAOUAS | 2ec1c13 | 2020-04-29 09:57:05 +0200 | [diff] [blame] | 37 | pci_write_config16(PCH_DEV_P2SB, PCI_COMMAND, |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 38 | 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 | */ |
| 46 | void 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 Huber | e549503 | 2020-02-17 18:26:51 +0100 | [diff] [blame] | 54 | pci_write_config8(PCH_DEV_P2SB, HPTC_OFFSET, HPTC_ADDR_ENABLE_BIT); |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 55 | } |
| 56 | |
Arthur Heymans | f629f7b | 2020-11-12 21:00:03 +0100 | [diff] [blame] | 57 | union p2sb_bdf p2sb_get_hpet_bdf(void) |
| 58 | { |
| 59 | const bool was_hidden = p2sb_is_hidden(); |
| 60 | if (was_hidden) |
| 61 | p2sb_unhide(); |
| 62 | |
| 63 | union p2sb_bdf bdf = { .raw = pci_read_config16(PCH_DEV_P2SB, PCH_P2SB_HBDF) }; |
| 64 | |
| 65 | if (was_hidden) |
| 66 | p2sb_hide(); |
| 67 | |
| 68 | return bdf; |
| 69 | } |
| 70 | |
| 71 | void p2sb_set_hpet_bdf(union p2sb_bdf bdf) |
| 72 | { |
| 73 | pci_write_config16(PCH_DEV_P2SB, PCH_P2SB_HBDF, bdf.raw); |
| 74 | } |
| 75 | |
Arthur Heymans | a1f65be | 2020-11-12 21:07:13 +0100 | [diff] [blame] | 76 | union p2sb_bdf p2sb_get_ioapic_bdf(void) |
| 77 | { |
| 78 | const bool was_hidden = p2sb_is_hidden(); |
| 79 | if (was_hidden) |
| 80 | p2sb_unhide(); |
| 81 | |
| 82 | union p2sb_bdf bdf = { .raw = pci_read_config16(PCH_DEV_P2SB, PCH_P2SB_IBDF) }; |
| 83 | |
| 84 | if (was_hidden) |
| 85 | p2sb_hide(); |
| 86 | |
| 87 | return bdf; |
| 88 | } |
| 89 | |
| 90 | void p2sb_set_ioapic_bdf(union p2sb_bdf bdf) |
| 91 | { |
| 92 | pci_write_config16(PCH_DEV_P2SB, PCH_P2SB_IBDF, bdf.raw); |
| 93 | } |
| 94 | |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 95 | static void p2sb_set_hide_bit(int hide) |
| 96 | { |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 97 | const uint16_t reg = PCH_P2SB_E0 + 1; |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 98 | const uint8_t mask = HIDE_BIT; |
| 99 | uint8_t val; |
| 100 | |
Nico Huber | e549503 | 2020-02-17 18:26:51 +0100 | [diff] [blame] | 101 | val = pci_read_config8(PCH_DEV_P2SB, reg); |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 102 | val &= ~mask; |
| 103 | if (hide) |
| 104 | val |= mask; |
Nico Huber | e549503 | 2020-02-17 18:26:51 +0100 | [diff] [blame] | 105 | pci_write_config8(PCH_DEV_P2SB, reg, val); |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void p2sb_unhide(void) |
| 109 | { |
| 110 | p2sb_set_hide_bit(0); |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 111 | |
Arthur Heymans | a8798a3 | 2020-11-12 20:41:57 +0100 | [diff] [blame] | 112 | if (p2sb_is_hidden()) |
Keith Short | 15588b0 | 2019-05-09 11:40:34 -0600 | [diff] [blame] | 113 | die_with_post_code(POST_HW_INIT_FAILURE, |
| 114 | "Unable to unhide PCH_DEV_P2SB device !\n"); |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | void p2sb_hide(void) |
| 118 | { |
| 119 | p2sb_set_hide_bit(1); |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 120 | |
Arthur Heymans | a8798a3 | 2020-11-12 20:41:57 +0100 | [diff] [blame] | 121 | if (!p2sb_is_hidden()) |
Keith Short | 15588b0 | 2019-05-09 11:40:34 -0600 | [diff] [blame] | 122 | die_with_post_code(POST_HW_INIT_FAILURE, |
| 123 | "Unable to hide PCH_DEV_P2SB device !\n"); |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void p2sb_configure_endpoints(int epmask_id, uint32_t mask) |
| 127 | { |
| 128 | uint32_t reg32; |
| 129 | |
Nico Huber | e549503 | 2020-02-17 18:26:51 +0100 | [diff] [blame] | 130 | reg32 = pci_read_config32(PCH_DEV_P2SB, PCH_P2SB_EPMASK(epmask_id)); |
| 131 | pci_write_config32(PCH_DEV_P2SB, PCH_P2SB_EPMASK(epmask_id), |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 132 | reg32 | mask); |
| 133 | } |
| 134 | |
| 135 | static void p2sb_lock_endpoints(void) |
| 136 | { |
| 137 | uint8_t reg8; |
| 138 | |
| 139 | /* Set the "Endpoint Mask Lock!", P2SB PCI offset E2h bit[1] to 1. */ |
Nico Huber | e549503 | 2020-02-17 18:26:51 +0100 | [diff] [blame] | 140 | reg8 = pci_read_config8(PCH_DEV_P2SB, PCH_P2SB_E0 + 2); |
| 141 | pci_write_config8(PCH_DEV_P2SB, PCH_P2SB_E0 + 2, |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 142 | reg8 | P2SB_E0_MASKLOCK); |
| 143 | } |
| 144 | |
| 145 | void p2sb_disable_sideband_access(void) |
| 146 | { |
| 147 | uint32_t ep_mask[P2SB_EP_MASK_MAX_REG]; |
| 148 | int i; |
| 149 | |
| 150 | memset(ep_mask, 0, sizeof(ep_mask)); |
| 151 | |
| 152 | p2sb_soc_get_sb_mask(ep_mask, ARRAY_SIZE(ep_mask)); |
| 153 | |
| 154 | /* Remove the host accessing right to PSF register range. */ |
| 155 | for (i = 0; i < P2SB_EP_MASK_MAX_REG; i++) |
| 156 | p2sb_configure_endpoints(i, ep_mask[i]); |
| 157 | |
| 158 | p2sb_lock_endpoints(); |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static void read_resources(struct device *dev) |
| 162 | { |
| 163 | /* |
| 164 | * There's only one resource on the P2SB device. It's also already |
| 165 | * manually set to a fixed address in earlier boot stages. |
Patrick Rudolph | 8d7a89b | 2019-10-04 09:22:27 +0200 | [diff] [blame] | 166 | * The following code makes sure that it doesn't change if the device |
| 167 | * is visible and the resource allocator is being run. |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 168 | */ |
| 169 | mmio_resource(dev, PCI_BASE_ADDRESS_0, P2SB_BAR / KiB, P2SB_SIZE / KiB); |
| 170 | } |
| 171 | |
| 172 | static const struct device_operations device_ops = { |
| 173 | .read_resources = read_resources, |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 174 | .set_resources = noop_set_resources, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 175 | .ops_pci = &pci_dev_ops_pci, |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | static const unsigned short pci_device_ids[] = { |
| 179 | PCI_DEVICE_ID_INTEL_APL_P2SB, |
| 180 | PCI_DEVICE_ID_INTEL_GLK_P2SB, |
Maxim Polyakov | 571d07d | 2019-08-22 13:11:32 +0300 | [diff] [blame] | 181 | PCI_DEVICE_ID_INTEL_LWB_P2SB, |
| 182 | PCI_DEVICE_ID_INTEL_LWB_P2SB_SUPER, |
Patrick Rudolph | 8d7a89b | 2019-10-04 09:22:27 +0200 | [diff] [blame] | 183 | PCI_DEVICE_ID_INTEL_SKL_LP_P2SB, |
| 184 | PCI_DEVICE_ID_INTEL_SKL_P2SB, |
| 185 | PCI_DEVICE_ID_INTEL_KBL_P2SB, |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 186 | PCI_DEVICE_ID_INTEL_CNL_P2SB, |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 187 | PCI_DEVICE_ID_INTEL_CNP_H_P2SB, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 188 | PCI_DEVICE_ID_INTEL_ICL_P2SB, |
Ronak Kanabar | da7ffb48 | 2019-02-05 01:51:13 +0530 | [diff] [blame] | 189 | PCI_DEVICE_ID_INTEL_CMP_P2SB, |
Gaggery Tsai | 12a651c | 2019-12-05 11:23:20 -0800 | [diff] [blame] | 190 | PCI_DEVICE_ID_INTEL_CMP_H_P2SB, |
Ravi Sarawadi | 6b5bf40 | 2019-10-21 22:25:04 -0700 | [diff] [blame] | 191 | PCI_DEVICE_ID_INTEL_TGL_P2SB, |
Jeremy Soller | 191a8d7 | 2021-08-10 14:06:51 -0600 | [diff] [blame^] | 192 | PCI_DEVICE_ID_INTEL_TGL_H_P2SB, |
Tan, Lean Sheng | 2613609 | 2020-01-20 19:13:56 -0800 | [diff] [blame] | 193 | PCI_DEVICE_ID_INTEL_EHL_P2SB, |
Meera Ravindranath | 3f4af0d | 2020-02-12 16:01:22 +0530 | [diff] [blame] | 194 | PCI_DEVICE_ID_INTEL_JSP_P2SB, |
Subrata Banik | f672f7f | 2020-08-03 14:29:25 +0530 | [diff] [blame] | 195 | PCI_DEVICE_ID_INTEL_ADP_P_P2SB, |
| 196 | PCI_DEVICE_ID_INTEL_ADP_S_P2SB, |
Varshit Pandya | f4d98fdd2 | 2021-01-17 18:39:29 +0530 | [diff] [blame] | 197 | PCI_DEVICE_ID_INTEL_ADP_M_P2SB, |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 198 | 0, |
| 199 | }; |
| 200 | |
| 201 | static const struct pci_driver pmc __pci_driver = { |
| 202 | .ops = &device_ops, |
| 203 | .vendor = PCI_VENDOR_ID_INTEL, |
| 204 | .devices = pci_device_ids, |
| 205 | }; |