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 | |
John Zhao | 41aa8d6 | 2022-01-20 11:29:18 -0800 | [diff] [blame] | 3 | #define __SIMPLE_DEVICE__ |
| 4 | |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/pci.h> |
| 9 | #include <device/pci_ids.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 10 | #include <intelblocks/p2sb.h> |
John Zhao | 41aa8d6 | 2022-01-20 11:29:18 -0800 | [diff] [blame] | 11 | #include <intelblocks/p2sblib.h> |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 12 | #include <soc/iomap.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 13 | #include <soc/p2sb.h> |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 14 | #include <soc/pci_devs.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 15 | #include <string.h> |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 16 | |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 17 | #define PCH_P2SB_EPMASK(mask_number) (PCH_P2SB_EPMASK0 + ((mask_number) * 4)) |
| 18 | |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 19 | void p2sb_enable_bar(void) |
| 20 | { |
Subrata Banik | 7c477a9 | 2022-03-14 12:47:31 +0530 | [diff] [blame] | 21 | p2sb_dev_enable_bar(PCH_DEV_P2SB, P2SB_BAR); |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | /* |
| 25 | * Enable decoding for HPET range. |
| 26 | * This is needed for FspMemoryInit to store and retrieve a global data |
| 27 | * pointer. |
| 28 | */ |
| 29 | void p2sb_configure_hpet(void) |
| 30 | { |
| 31 | /* |
| 32 | * Enable decoding for HPET memory address range. |
| 33 | * HPTC_OFFSET(0x60) bit 7, when set the P2SB will decode |
| 34 | * the High Performance Timer memory address range |
| 35 | * selected by bits 1:0 |
| 36 | */ |
Nico Huber | e549503 | 2020-02-17 18:26:51 +0100 | [diff] [blame] | 37 | pci_write_config8(PCH_DEV_P2SB, HPTC_OFFSET, HPTC_ADDR_ENABLE_BIT); |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 38 | } |
| 39 | |
Arthur Heymans | f629f7b | 2020-11-12 21:00:03 +0100 | [diff] [blame] | 40 | union p2sb_bdf p2sb_get_hpet_bdf(void) |
| 41 | { |
John Zhao | 41aa8d6 | 2022-01-20 11:29:18 -0800 | [diff] [blame] | 42 | const bool was_hidden = p2sb_dev_is_hidden(PCH_DEV_P2SB); |
Arthur Heymans | f629f7b | 2020-11-12 21:00:03 +0100 | [diff] [blame] | 43 | if (was_hidden) |
| 44 | p2sb_unhide(); |
| 45 | |
| 46 | union p2sb_bdf bdf = { .raw = pci_read_config16(PCH_DEV_P2SB, PCH_P2SB_HBDF) }; |
| 47 | |
| 48 | if (was_hidden) |
| 49 | p2sb_hide(); |
| 50 | |
| 51 | return bdf; |
| 52 | } |
| 53 | |
| 54 | void p2sb_set_hpet_bdf(union p2sb_bdf bdf) |
| 55 | { |
| 56 | pci_write_config16(PCH_DEV_P2SB, PCH_P2SB_HBDF, bdf.raw); |
| 57 | } |
| 58 | |
Arthur Heymans | a1f65be | 2020-11-12 21:07:13 +0100 | [diff] [blame] | 59 | union p2sb_bdf p2sb_get_ioapic_bdf(void) |
| 60 | { |
John Zhao | 41aa8d6 | 2022-01-20 11:29:18 -0800 | [diff] [blame] | 61 | const bool was_hidden = p2sb_dev_is_hidden(PCH_DEV_P2SB); |
Arthur Heymans | a1f65be | 2020-11-12 21:07:13 +0100 | [diff] [blame] | 62 | if (was_hidden) |
| 63 | p2sb_unhide(); |
| 64 | |
| 65 | union p2sb_bdf bdf = { .raw = pci_read_config16(PCH_DEV_P2SB, PCH_P2SB_IBDF) }; |
| 66 | |
| 67 | if (was_hidden) |
| 68 | p2sb_hide(); |
| 69 | |
| 70 | return bdf; |
| 71 | } |
| 72 | |
| 73 | void p2sb_set_ioapic_bdf(union p2sb_bdf bdf) |
| 74 | { |
| 75 | pci_write_config16(PCH_DEV_P2SB, PCH_P2SB_IBDF, bdf.raw); |
| 76 | } |
| 77 | |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 78 | void p2sb_unhide(void) |
| 79 | { |
John Zhao | 41aa8d6 | 2022-01-20 11:29:18 -0800 | [diff] [blame] | 80 | p2sb_dev_unhide(PCH_DEV_P2SB); |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void p2sb_hide(void) |
| 84 | { |
John Zhao | 41aa8d6 | 2022-01-20 11:29:18 -0800 | [diff] [blame] | 85 | p2sb_dev_hide(PCH_DEV_P2SB); |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static void p2sb_configure_endpoints(int epmask_id, uint32_t mask) |
| 89 | { |
| 90 | uint32_t reg32; |
| 91 | |
Nico Huber | e549503 | 2020-02-17 18:26:51 +0100 | [diff] [blame] | 92 | reg32 = pci_read_config32(PCH_DEV_P2SB, PCH_P2SB_EPMASK(epmask_id)); |
| 93 | pci_write_config32(PCH_DEV_P2SB, PCH_P2SB_EPMASK(epmask_id), |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 94 | reg32 | mask); |
| 95 | } |
| 96 | |
| 97 | static void p2sb_lock_endpoints(void) |
| 98 | { |
| 99 | uint8_t reg8; |
| 100 | |
| 101 | /* 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] | 102 | reg8 = pci_read_config8(PCH_DEV_P2SB, PCH_P2SB_E0 + 2); |
| 103 | pci_write_config8(PCH_DEV_P2SB, PCH_P2SB_E0 + 2, |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 104 | reg8 | P2SB_E0_MASKLOCK); |
| 105 | } |
| 106 | |
| 107 | void p2sb_disable_sideband_access(void) |
| 108 | { |
| 109 | uint32_t ep_mask[P2SB_EP_MASK_MAX_REG]; |
| 110 | int i; |
| 111 | |
| 112 | memset(ep_mask, 0, sizeof(ep_mask)); |
| 113 | |
| 114 | p2sb_soc_get_sb_mask(ep_mask, ARRAY_SIZE(ep_mask)); |
| 115 | |
| 116 | /* Remove the host accessing right to PSF register range. */ |
| 117 | for (i = 0; i < P2SB_EP_MASK_MAX_REG; i++) |
| 118 | p2sb_configure_endpoints(i, ep_mask[i]); |
| 119 | |
| 120 | p2sb_lock_endpoints(); |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static void read_resources(struct device *dev) |
| 124 | { |
| 125 | /* |
| 126 | * There's only one resource on the P2SB device. It's also already |
| 127 | * manually set to a fixed address in earlier boot stages. |
Patrick Rudolph | 8d7a89b | 2019-10-04 09:22:27 +0200 | [diff] [blame] | 128 | * The following code makes sure that it doesn't change if the device |
| 129 | * is visible and the resource allocator is being run. |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 130 | */ |
Arthur Heymans | d5e70b2 | 2023-07-05 11:58:20 +0200 | [diff] [blame] | 131 | mmio_range(dev, PCI_BASE_ADDRESS_0, P2SB_BAR, P2SB_SIZE); |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Nico Huber | 5768619 | 2022-08-06 19:11:55 +0200 | [diff] [blame] | 134 | const struct device_operations p2sb_ops = { |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 135 | .read_resources = read_resources, |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 136 | .set_resources = noop_set_resources, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 137 | .ops_pci = &pci_dev_ops_pci, |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static const unsigned short pci_device_ids[] = { |
Appukuttan V K | 50c8f2e | 2024-01-11 18:05:11 +0530 | [diff] [blame^] | 141 | PCI_DID_INTEL_LNL_P2SB, |
Wonkyu Kim | 9f40107 | 2020-11-13 15:16:32 -0800 | [diff] [blame] | 142 | PCI_DID_INTEL_MTL_SOC_P2SB, |
Bora Guvendik | a15b25f | 2022-02-28 14:43:49 -0800 | [diff] [blame] | 143 | PCI_DID_INTEL_RPP_P_P2SB, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 144 | PCI_DID_INTEL_APL_P2SB, |
| 145 | PCI_DID_INTEL_GLK_P2SB, |
| 146 | PCI_DID_INTEL_LWB_P2SB, |
| 147 | PCI_DID_INTEL_LWB_P2SB_SUPER, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 148 | PCI_DID_INTEL_CNL_P2SB, |
| 149 | PCI_DID_INTEL_CNP_H_P2SB, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 150 | PCI_DID_INTEL_CMP_P2SB, |
| 151 | PCI_DID_INTEL_CMP_H_P2SB, |
| 152 | PCI_DID_INTEL_TGL_P2SB, |
| 153 | PCI_DID_INTEL_TGL_H_P2SB, |
| 154 | PCI_DID_INTEL_EHL_P2SB, |
| 155 | PCI_DID_INTEL_JSP_P2SB, |
| 156 | PCI_DID_INTEL_ADP_P_P2SB, |
| 157 | PCI_DID_INTEL_ADP_S_P2SB, |
| 158 | PCI_DID_INTEL_ADP_M_P2SB, |
Tim Chu | 2ccbcc5 | 2022-12-08 11:05:36 +0000 | [diff] [blame] | 159 | PCI_DID_INTEL_SPR_SP_P2SB, |
Michał Żygowski | 24fba11 | 2023-08-25 12:20:17 +0200 | [diff] [blame] | 160 | PCI_DID_INTEL_RPP_S_P2SB, |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 161 | 0, |
| 162 | }; |
| 163 | |
| 164 | static const struct pci_driver pmc __pci_driver = { |
Nico Huber | 5768619 | 2022-08-06 19:11:55 +0200 | [diff] [blame] | 165 | .ops = &p2sb_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 166 | .vendor = PCI_VID_INTEL, |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 167 | .devices = pci_device_ids, |
| 168 | }; |