Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Tim Wawrzynczak | b0d3a01 | 2021-12-02 16:19:29 -0700 | [diff] [blame] | 3 | #include <device/device.h> |
Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 4 | #include <intelblocks/pcie_rp.h> |
Tim Wawrzynczak | b0d3a01 | 2021-12-02 16:19:29 -0700 | [diff] [blame] | 5 | #include <soc/cpu.h> |
Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 6 | #include <soc/pci_devs.h> |
| 7 | #include <soc/pcie.h> |
| 8 | |
Tim Wawrzynczak | 40c9c8a | 2021-12-08 10:43:08 -0700 | [diff] [blame] | 9 | #define CPU_CPIE_VW_IDX_BASE 24 |
| 10 | |
Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 11 | static const struct pcie_rp_group pch_lp_rp_groups[] = { |
MAULIK V VAGHELA | d9c5b14 | 2022-02-14 22:04:03 +0530 | [diff] [blame] | 12 | { .slot = PCH_DEV_SLOT_PCIE, .count = 8, .lcap_port_base = 1 }, |
| 13 | { .slot = PCH_DEV_SLOT_PCIE_1, .count = 4, .lcap_port_base = 1 }, |
Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 14 | { 0 } |
| 15 | }; |
| 16 | |
Tim Wawrzynczak | b0d3a01 | 2021-12-02 16:19:29 -0700 | [diff] [blame] | 17 | static const struct pcie_rp_group pch_m_rp_groups[] = { |
MAULIK V VAGHELA | d9c5b14 | 2022-02-14 22:04:03 +0530 | [diff] [blame] | 18 | { .slot = PCH_DEV_SLOT_PCIE, .count = 8, .lcap_port_base = 1 }, |
| 19 | { .slot = PCH_DEV_SLOT_PCIE_1, .count = 2, .lcap_port_base = 1 }, |
Tim Wawrzynczak | b0d3a01 | 2021-12-02 16:19:29 -0700 | [diff] [blame] | 20 | { 0 } |
| 21 | }; |
| 22 | |
Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 23 | const struct pcie_rp_group *get_pch_pcie_rp_table(void) |
| 24 | { |
Tim Wawrzynczak | b0d3a01 | 2021-12-02 16:19:29 -0700 | [diff] [blame] | 25 | if (CONFIG(SOC_INTEL_ALDERLAKE_PCH_M)) |
| 26 | return pch_m_rp_groups; |
| 27 | |
| 28 | return pch_lp_rp_groups; /* Valid for PCH-P and PCH-N */ |
Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | /* |
| 32 | * ADL-P FSP define CPU RP as below: |
| 33 | * RP1: PEG60 : 0:6:0 : x4 CPU Slot |
| 34 | * RP2: PEG10 : 0:1:0 : x8 CPU Slot |
| 35 | * RP3: PEG62 : 0:6:2 : x4 CPU Slot |
| 36 | */ |
| 37 | static const struct pcie_rp_group cpu_rp_groups[] = { |
MAULIK V VAGHELA | d9c5b14 | 2022-02-14 22:04:03 +0530 | [diff] [blame] | 38 | { .slot = SA_DEV_SLOT_CPU_6, .start = 0, .count = 1, .lcap_port_base = 1 }, |
| 39 | { .slot = SA_DEV_SLOT_CPU_1, .start = 0, .count = 1, .lcap_port_base = 1 }, |
| 40 | { .slot = SA_DEV_SLOT_CPU_6, .start = 2, .count = 1, .lcap_port_base = 1 }, |
Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 41 | { 0 } |
| 42 | }; |
| 43 | |
Tim Wawrzynczak | b0d3a01 | 2021-12-02 16:19:29 -0700 | [diff] [blame] | 44 | static const struct pcie_rp_group cpu_m_rp_groups[] = { |
MAULIK V VAGHELA | d9c5b14 | 2022-02-14 22:04:03 +0530 | [diff] [blame] | 45 | { .slot = SA_DEV_SLOT_CPU_6, .start = 0, .count = 1, .lcap_port_base = 1 }, |
Tim Wawrzynczak | b0d3a01 | 2021-12-02 16:19:29 -0700 | [diff] [blame] | 46 | { 0 } |
| 47 | }; |
| 48 | |
| 49 | static const struct pcie_rp_group cpu_n_rp_groups[] = { |
| 50 | { 0 } |
| 51 | }; |
| 52 | |
Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 53 | const struct pcie_rp_group *get_cpu_pcie_rp_table(void) |
| 54 | { |
Tim Wawrzynczak | b0d3a01 | 2021-12-02 16:19:29 -0700 | [diff] [blame] | 55 | if (CONFIG(SOC_INTEL_ALDERLAKE_PCH_M)) |
| 56 | return cpu_m_rp_groups; |
| 57 | |
| 58 | if (CONFIG(SOC_INTEL_ALDERLAKE_PCH_N)) |
| 59 | return cpu_n_rp_groups; |
| 60 | |
Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 61 | return cpu_rp_groups; |
| 62 | } |
Tim Wawrzynczak | b0d3a01 | 2021-12-02 16:19:29 -0700 | [diff] [blame] | 63 | |
MAULIK V VAGHELA | d9c5b14 | 2022-02-14 22:04:03 +0530 | [diff] [blame] | 64 | /* |
| 65 | * TBT's LCAP registers are returning port index which starts from 2 (Usually for other PCIe |
| 66 | * root ports index starts from 1). Thus keeping lcap_port_base 2 for TBT, so that coreboot's |
| 67 | * PCIe remapping logic can return correct index (0-based) |
| 68 | */ |
| 69 | |
MAULIK V VAGHELA | 3e4f28f | 2022-01-21 14:17:53 +0530 | [diff] [blame] | 70 | static const struct pcie_rp_group tbt_rp_groups[] = { |
MAULIK V VAGHELA | d9c5b14 | 2022-02-14 22:04:03 +0530 | [diff] [blame] | 71 | { .slot = SA_DEV_SLOT_TBT, .count = CONFIG_MAX_TBT_ROOT_PORTS, .lcap_port_base = 2 }, |
MAULIK V VAGHELA | 3e4f28f | 2022-01-21 14:17:53 +0530 | [diff] [blame] | 72 | { 0 } |
| 73 | }; |
| 74 | |
| 75 | const struct pcie_rp_group *get_tbt_pcie_rp_table(void) |
| 76 | { |
| 77 | return tbt_rp_groups; |
| 78 | } |
| 79 | |
Tim Wawrzynczak | b0d3a01 | 2021-12-02 16:19:29 -0700 | [diff] [blame] | 80 | static bool is_part_of_group(const struct device *dev, |
| 81 | const struct pcie_rp_group *groups) |
| 82 | { |
| 83 | if (dev->path.type != DEVICE_PATH_PCI) |
| 84 | return false; |
| 85 | |
| 86 | const unsigned int slot_to_find = PCI_SLOT(dev->path.pci.devfn); |
| 87 | const unsigned int fn_to_find = PCI_FUNC(dev->path.pci.devfn); |
| 88 | const struct pcie_rp_group *group; |
| 89 | unsigned int i; |
| 90 | unsigned int fn; |
| 91 | |
| 92 | for (group = groups; group->count; ++group) { |
| 93 | for (i = 0, fn = rp_start_fn(group); i < group->count; i++, fn++) { |
| 94 | if (slot_to_find == group->slot && fn_to_find == fn) |
| 95 | return true; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | enum pcie_rp_type soc_get_pcie_rp_type(const struct device *dev) |
| 103 | { |
| 104 | if (is_part_of_group(dev, pch_lp_rp_groups)) |
| 105 | return PCIE_RP_PCH; |
| 106 | |
| 107 | if (CONFIG_MAX_CPU_ROOT_PORTS && is_part_of_group(dev, cpu_rp_groups)) |
| 108 | return PCIE_RP_CPU; |
| 109 | |
| 110 | return PCIE_RP_UNKNOWN; |
| 111 | } |
Tim Wawrzynczak | 40c9c8a | 2021-12-08 10:43:08 -0700 | [diff] [blame] | 112 | |
| 113 | int soc_get_cpu_rp_vw_idx(const struct device *dev) |
| 114 | { |
| 115 | if (dev->path.type != DEVICE_PATH_PCI) |
| 116 | return -1; |
| 117 | |
| 118 | switch (dev->path.pci.devfn) { |
| 119 | case SA_DEVFN_CPU_PCIE1_0: |
| 120 | return CPU_CPIE_VW_IDX_BASE; |
| 121 | case SA_DEVFN_CPU_PCIE6_0: |
| 122 | return CPU_CPIE_VW_IDX_BASE + 3; |
| 123 | case SA_DEVFN_CPU_PCIE6_2: |
| 124 | return CPU_CPIE_VW_IDX_BASE + 2; |
| 125 | default: |
| 126 | return -1; |
| 127 | } |
| 128 | } |