Debian Codegraph @

src/soc/amd/cezanne/root_complex.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <acpi/acpigen.h>
4 #include <amdblocks/alib.h>
5 #include <amdblocks/data_fabric.h>
6 #include <amdblocks/ioapic.h>
7 #include <amdblocks/root_complex.h>
8 #include <arch/ioapic.h>
9 #include <device/device.h>
10 #include <device/pci.h>
11 #include <soc/iomap.h>
12 #include <static.h>
13 #include <stdint.h>
14 #include "chip.h"
15
16 #define DPTC_TOTAL_UPDATE_PARAMS 4
17
18 struct dptc_input {
19 uint16_t size;
20 struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
21 } __packed;
22
23 #define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
24 { \
25 .size = sizeof(struct dptc_input), \
26 .params = { \
27 { \
28 .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \
29 .value = _thermctllmit, \
30 }, \
31 { \
32 .id = ALIB_DPTC_SUSTAINED_POWER_LIMIT_ID, \
33 .value = _sustained, \
34 }, \
35 { \
36 .id = ALIB_DPTC_FAST_PPT_LIMIT_ID, \
37 .value = _fast, \
38 }, \
39 { \
40 .id = ALIB_DPTC_SLOW_PPT_LIMIT_ID, \
41 .value = _slow, \
42 }, \
43 }, \
44 }
45
46 static void acipgen_dptci(void)
47 {
48 const struct soc_amd_cezanne_config *config = config_of_soc();
49
50 /* Normal mode DPTC values. */
51 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
52 config->sustained_power_limit_mW,
53 config->fast_ppt_limit_mW,
54 config->slow_ppt_limit_mW);
55 acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input));
56 }
57
58 static void root_complex_fill_ssdt(const struct device *device)
59 {
60 if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC))
61 acipgen_dptci();
62
63 /* Add ACPI device, opregion to host bridge needed for ACP driver.
64 *
65 * This is used by an ACPI method in the ACP's ACPI code to access different mailbox
66 * interfaces in th hardware. Some ACP drivers will use that to both notify the PSP
67 * that the DSP firmware has been loaded, so that the PSP can validate the firmware
68 * and set the qualifier bit to enable running it, and to configure the ACP's clock
69 * source.
70 *
71 * As this SMN access is not arbitrated and there may be other drivers or parts of
72 * the firmware attempting to use the SMN access register pair, there is a risk of
73 * conflict / incorrect data, but given the frequency and duration of accesses, the
74 * risk is deemed to be quite low.
75 *
76 * Scope (\_SB.PCI0)
77 * {
78 * Device (GNB)
79 * {
80 * Name (_ADR, 0x0000000000000000)
81 * Method (_STA, 0, NotSerialized)
82 * {
83 * Return (0x0F)
84 * }
85 * }
86 * }
87 * Scope (\_SB.PCI0.GNB)
88 * {
89 * OperationRegion(SMN, SystemMemory , 0xF80000B8, 0x8)
90 * Field(SMN, AnyAcc, NoLock, Preserve) {
91 * SMNA, 32,
92 * SMND, 32,
93 * }
94 * }
95 */
96 acpi_device_write_pci_dev(device);
97 acpigen_write_scope(acpi_device_path(device));
98 struct opregion opreg = OPREGION("SMN", SYSTEMMEMORY,
99 CONFIG_ECAM_MMCONF_BASE_ADDRESS + 0xb8, 0x8);
100 acpigen_write_opregion(&opreg);
101 static const struct fieldlist list[] = {
102 FIELDLIST_NAMESTR("SMNA", 32),
103 FIELDLIST_NAMESTR("SMND", 32),
104 };
105 acpigen_write_field(opreg.name, list, ARRAY_SIZE(list),
106 FIELD_ANYACC | FIELD_NOLOCK | FIELD_PRESERVE);
107 acpigen_write_scope_end();
108 }
109
110 static const char *gnb_acpi_name(const struct device *dev)
111 {
112 return "GNB";
113 }
114
115 struct device_operations cezanne_root_complex_operations = {
116 /* The root complex has no PCI BARs implemented, so there's no need to call
117 pci_dev_read_resources for it */
118 .read_resources = noop_read_resources,
119 .set_resources = noop_set_resources,
120 .enable_resources = pci_dev_enable_resources,
121 .acpi_name = gnb_acpi_name,
122 .acpi_fill_ssdt = root_complex_fill_ssdt,
123 };
124
125 static const struct domain_iohc_info iohc_info[] = {
126 [0] = {
127 .fabric_id = IOMS0_FABRIC_ID,
128 .misc_smn_base = SMN_IOHC_MISC_BASE_13B1,
129 },
130 };
131
132 const struct domain_iohc_info *get_iohc_info(size_t *count)
133 {
134 *count = ARRAY_SIZE(iohc_info);
135 return iohc_info;
136 }
137
138 static const struct non_pci_mmio_reg non_pci_mmio[] = {
139 { 0x2d8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
140 { 0x2e0, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
141 { 0x2e8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
142 /* The hardware has a 256 byte alignment requirement for the IOAPIC MMIO base, but we
143 tell the FSP to configure a 4k-aligned base address and this is reported as 4 KiB
144 resource. */
145 { 0x2f0, 0xffffffffff00ull, 4 * KiB, IOMMU_IOAPIC_IDX },
146 { 0x2f8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
147 { 0x300, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
148 { 0x308, 0xfffffffff000ull, 4 * KiB, NON_PCI_RES_IDX_AUTO },
149 { 0x318, 0xfffffff80000ull, 512 * KiB, NON_PCI_RES_IDX_AUTO },
150 };
151
152 const struct non_pci_mmio_reg *get_iohc_non_pci_mmio_regs(size_t *count)
153 {
154 *count = ARRAY_SIZE(non_pci_mmio);
155 return non_pci_mmio;
156 }