blob: 60b63132631b47fd945bfdb68a040474bf6bb57e [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Bruce Griffith27ed80b2014-08-15 11:46:25 -06002
Michał Żygowski2f399b72020-04-02 19:51:37 +02003#include <commonlib/helpers.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -06004#include <console/console.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07006#include <acpi/acpi.h>
7#include <acpi/acpi_ivrs.h>
Michał Żygowski208318c2020-03-20 15:54:27 +01008#include <arch/ioapic.h>
Felix Held61dd31c2023-06-05 19:38:36 +02009#include <arch/vga.h>
Elyes HAOUAS146d0c22020-07-22 11:47:08 +020010#include <types.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -060011#include <device/device.h>
12#include <device/pci.h>
13#include <device/pci_ids.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -060014#include <string.h>
Michał Żygowski2f399b72020-04-02 19:51:37 +020015#include <stdlib.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -060016#include <lib.h>
Michał Kopećdc35d2a2021-11-30 17:40:52 +010017#include <cpu/x86/mp.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -060018#include <Porting.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -060019#include <Topology.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +020020#include <cpu/amd/msr.h>
21#include <cpu/amd/mtrr.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070022#include <acpi/acpigen.h>
Angel Ponsec5cf152020-11-10 20:42:07 +010023#include <northbridge/amd/nb_common.h>
Kyösti Mälkkied8d2772017-07-15 17:12:44 +030024#include <northbridge/amd/agesa/agesa_helper.h>
Michał Żygowski2f399b72020-04-02 19:51:37 +020025#include <southbridge/amd/pi/hudson/pci_devs.h>
Arthur Heymans44807ac2022-09-13 12:43:37 +020026#include <amdblocks/cpu.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -060027
Michał Żygowski6ca5b472019-09-10 15:10:22 +020028#define PCIE_CAP_AER BIT(5)
29#define PCIE_CAP_ACS BIT(6)
Bruce Griffith27ed80b2014-08-15 11:46:25 -060030
Kyösti Mälkki90ac7362018-05-20 20:59:52 +030031static struct device *get_node_pci(u32 nodeid, u32 fn)
Bruce Griffith27ed80b2014-08-15 11:46:25 -060032{
Kyösti Mälkkibbd23772019-01-10 05:41:23 +020033 return pcidev_on_root(DEV_CDB + nodeid, fn);
Bruce Griffith27ed80b2014-08-15 11:46:25 -060034}
35
Michał Kopećca1e8aa2021-12-03 15:17:46 +010036static unsigned int get_node_nums(void)
37{
Felix Heldaaceeae2023-11-16 18:05:35 +010038 return 1;
Michał Kopećca1e8aa2021-12-03 15:17:46 +010039}
40
Michał Żygowski88a0ce62021-05-05 09:52:59 +020041static int get_dram_base_limit(u32 nodeid, resource_t *basek, resource_t *limitk)
42{
43 u32 temp;
44
Felix Held606e5632023-11-16 18:34:33 +010045 temp = pci_read_config32(get_node_pci(nodeid, 1), 0x40 + (nodeid << 3)); //[39:24] at [31:16]
Michał Żygowski88a0ce62021-05-05 09:52:59 +020046 if (!(temp & 1))
47 return 0; // this memory range is not enabled
48 /*
49 * BKDG: {DramBase[39:24], 00_0000h} <= address[39:0] so shift left by 8 bits
50 * for physical address and the convert to KiB by shifting 10 bits left
51 */
52 *basek = ((temp & 0xffff0000)) >> (10 - 8);
53 /*
54 * BKDG address[39:0] <= {DramLimit[39:24], FF_FFFFh} converted as above but
55 * ORed with 0xffff to get real limit before shifting.
56 */
Felix Held606e5632023-11-16 18:34:33 +010057 temp = pci_read_config32(get_node_pci(nodeid, 1), 0x44 + (nodeid << 3)); //[39:24] at [31:16]
Michał Żygowski88a0ce62021-05-05 09:52:59 +020058 *limitk = ((temp & 0xffff0000) | 0xffff) >> (10 - 8);
59 *limitk += 1; // round up last byte
60
61 return 1;
62}
63
Michał Żygowski58d6f962021-05-05 10:52:08 +020064static void add_fixed_resources(struct device *dev, int index)
65{
66 /* Reserve everything between A segment and 1MB:
67 *
68 * 0xa0000 - 0xbffff: legacy VGA
69 * 0xc0000 - 0xfffff: option ROMs and SeaBIOS (if used)
70 */
Felix Held61dd31c2023-06-05 19:38:36 +020071 mmio_resource_kb(dev, index++, VGA_MMIO_BASE >> 10, VGA_MMIO_SIZE >> 10);
Kyösti Mälkki27d62992022-05-24 20:25:58 +030072 reserved_ram_resource_kb(dev, index++, 0xc0000 >> 10, (0x100000 - 0xc0000) >> 10);
Michał Żygowski58d6f962021-05-05 10:52:08 +020073
Michał Żygowski58d6f962021-05-05 10:52:08 +020074 /* Check if CC6 save area is enabled (bit 18 CC6SaveEn) */
Felix Held606e5632023-11-16 18:34:33 +010075 if (pci_read_config32(get_node_pci(0, 2), 0x118) & (1 << 18)) {
Michał Żygowski58d6f962021-05-05 10:52:08 +020076 /* Add CC6 DRAM UC resource residing at DRAM Limit of size 16MB as per BKDG */
77 resource_t basek, limitk;
78 if (!get_dram_base_limit(0, &basek, &limitk))
79 return;
Elyes Haouasf9b535e2022-07-16 09:47:42 +020080 mmio_resource_kb(dev, index++, limitk, 16 * 1024);
Michał Żygowski58d6f962021-05-05 10:52:08 +020081 }
82}
83
Michał Żygowskifb198c62021-05-09 13:54:09 +020084static void nb_read_resources(struct device *dev)
Bruce Griffith27ed80b2014-08-15 11:46:25 -060085{
Kyösti Mälkki5d490382015-05-27 07:58:22 +030086 /*
87 * This MMCONF resource must be reserved in the PCI domain.
88 * It is not honored by the coreboot resource allocator if it is in
89 * the CPU_CLUSTER.
90 */
Elyes HAOUAS400ce552018-10-12 10:54:30 +020091 mmconf_resource(dev, MMIO_CONF_BASE);
Michał Żygowski208318c2020-03-20 15:54:27 +010092
93 /* NB IOAPIC2 resource */
Felix Held8f0075c2023-08-09 19:28:39 +020094 mmio_range(dev, IO_APIC2_ADDR, IO_APIC2_ADDR, 0x1000);
Michał Żygowski58d6f962021-05-05 10:52:08 +020095
96 add_fixed_resources(dev, 0);
Bruce Griffith27ed80b2014-08-15 11:46:25 -060097}
98
Bruce Griffith27ed80b2014-08-15 11:46:25 -060099static void northbridge_init(struct device *dev)
100{
Kyösti Mälkkid1534e42023-04-09 10:01:58 +0300101 register_new_ioapic((u8 *)IO_APIC2_ADDR);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600102}
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200103
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100104static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200105{
106 void *addr, *current;
107
108 /* Skip the HEST header. */
109 current = (void *)(hest + 1);
110
111 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
112 if (addr != NULL)
113 current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
114
115 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
116 if (addr != NULL)
117 current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
118
119 return (unsigned long)current;
120}
121
Arthur Heymansf9ee87f2023-06-07 15:29:02 +0200122static unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t *ivrs, unsigned long current)
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500123{
Michał Żygowski2f399b72020-04-02 19:51:37 +0200124 /* 8-byte IVHD structures must be aligned to the 8-byte boundary. */
125 current = ALIGN_UP(current, 8);
126 ivrs_ivhd_special_t *ivhd_ioapic = (ivrs_ivhd_special_t *)current;
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500127
Michał Żygowski2f399b72020-04-02 19:51:37 +0200128 ivhd_ioapic->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV;
129 ivhd_ioapic->reserved = 0x0000;
130 ivhd_ioapic->dte_setting = IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS |
131 IVHD_DTE_SYS_MGT_NO_TRANS | IVHD_DTE_NMI_PASS |
132 IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS;
Kyösti Mälkkid1534e42023-04-09 10:01:58 +0300133 ivhd_ioapic->handle = get_ioapic_id(VIO_APIC_VADDR);
Michał Żygowski2f399b72020-04-02 19:51:37 +0200134 ivhd_ioapic->source_dev_id = PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC);
135 ivhd_ioapic->variety = IVHD_SPECIAL_DEV_IOAPIC;
136 current += sizeof(ivrs_ivhd_special_t);
137
138 ivhd_ioapic = (ivrs_ivhd_special_t *)current;
Michał Żygowski2f399b72020-04-02 19:51:37 +0200139 ivhd_ioapic->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV;
140 ivhd_ioapic->reserved = 0x0000;
141 ivhd_ioapic->dte_setting = 0x00;
Kyösti Mälkkid1534e42023-04-09 10:01:58 +0300142 ivhd_ioapic->handle = get_ioapic_id((u8 *)IO_APIC2_ADDR);
Michał Żygowski2f399b72020-04-02 19:51:37 +0200143 ivhd_ioapic->source_dev_id = PCI_DEVFN(0, 1);
144 ivhd_ioapic->variety = IVHD_SPECIAL_DEV_IOAPIC;
145 current += sizeof(ivrs_ivhd_special_t);
146
147 return current;
148}
149
150static unsigned long ivhd_describe_hpet(unsigned long current)
151{
152 /* 8-byte IVHD structures must be aligned to the 8-byte boundary. */
153 current = ALIGN_UP(current, 8);
154 ivrs_ivhd_special_t *ivhd_hpet = (ivrs_ivhd_special_t *)current;
155
156 ivhd_hpet->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV;
157 ivhd_hpet->reserved = 0x0000;
158 ivhd_hpet->dte_setting = 0x00;
159 ivhd_hpet->handle = 0x00;
160 ivhd_hpet->source_dev_id = PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC);
161 ivhd_hpet->variety = IVHD_SPECIAL_DEV_HPET;
162 current += sizeof(ivrs_ivhd_special_t);
163
164 return current;
165}
166
167static unsigned long ivhd_dev_range(unsigned long current, uint16_t start_devid,
168 uint16_t end_devid, uint8_t setting)
169{
170 /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */
171 current = ALIGN_UP(current, 4);
172 ivrs_ivhd_generic_t *ivhd_range = (ivrs_ivhd_generic_t *)current;
173
174 /* Create the start range IVHD entry */
175 ivhd_range->type = IVHD_DEV_4_BYTE_START_RANGE;
176 ivhd_range->dev_id = start_devid;
177 ivhd_range->dte_setting = setting;
178 current += sizeof(ivrs_ivhd_generic_t);
179
180 /* Create the end range IVHD entry */
181 ivhd_range = (ivrs_ivhd_generic_t *)current;
182 ivhd_range->type = IVHD_DEV_4_BYTE_END_RANGE;
183 ivhd_range->dev_id = end_devid;
184 ivhd_range->dte_setting = setting;
185 current += sizeof(ivrs_ivhd_generic_t);
186
187 return current;
188}
189
190static unsigned long add_ivhd_dev_entry(struct device *parent, struct device *dev,
191 unsigned long *current, uint8_t type, uint8_t data)
192{
193 if (type == IVHD_DEV_4_BYTE_SELECT) {
194 /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */
195 *current = ALIGN_UP(*current, 4);
196 ivrs_ivhd_generic_t *ivhd_entry = (ivrs_ivhd_generic_t *)*current;
197
198 ivhd_entry->type = type;
199 ivhd_entry->dev_id = dev->path.pci.devfn | (dev->bus->secondary << 8);
200 ivhd_entry->dte_setting = data;
201 *current += sizeof(ivrs_ivhd_generic_t);
202 } else if (type == IVHD_DEV_8_BYTE_ALIAS_SELECT) {
203 /* 8-byte IVHD structures must be aligned to the 8-byte boundary. */
204 *current = ALIGN_UP(*current, 8);
205 ivrs_ivhd_alias_t *ivhd_entry = (ivrs_ivhd_alias_t *)*current;
206
207 ivhd_entry->type = type;
208 ivhd_entry->dev_id = dev->path.pci.devfn | (dev->bus->secondary << 8);
209 ivhd_entry->dte_setting = data;
210 ivhd_entry->reserved1 = 0;
211 ivhd_entry->reserved2 = 0;
212 ivhd_entry->source_dev_id = parent->path.pci.devfn |
213 (parent->bus->secondary << 8);
214 *current += sizeof(ivrs_ivhd_alias_t);
215 }
216
217 return *current;
218}
219
220static void ivrs_add_device_or_bridge(struct device *parent, struct device *dev,
221 unsigned long *current, uint16_t *ivhd_length)
222{
223 unsigned int header_type, is_pcie;
224 unsigned long current_backup;
225
226 header_type = dev->hdr_type & 0x7f;
227 is_pcie = pci_find_capability(dev, PCI_CAP_ID_PCIE);
228
229 if (((header_type == PCI_HEADER_TYPE_NORMAL) ||
230 (header_type == PCI_HEADER_TYPE_BRIDGE)) && is_pcie) {
231 /* Device or Bridge is PCIe */
232 current_backup = *current;
233 add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_4_BYTE_SELECT, 0x0);
234 *ivhd_length += (*current - current_backup);
235 } else if ((header_type == PCI_HEADER_TYPE_NORMAL) && !is_pcie) {
236 /* Device is legacy PCI or PCI-X */
237 current_backup = *current;
238 add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_8_BYTE_ALIAS_SELECT, 0x0);
239 *ivhd_length += (*current - current_backup);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500240 }
241}
242
Michał Żygowski2f399b72020-04-02 19:51:37 +0200243static void add_ivhd_device_entries(struct device *parent, struct device *dev,
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500244 unsigned int depth, int linknum, int8_t *root_level,
Michał Żygowski2f399b72020-04-02 19:51:37 +0200245 unsigned long *current, uint16_t *ivhd_length)
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500246{
247 struct device *sibling;
248 struct bus *link;
Michał Żygowski2f399b72020-04-02 19:51:37 +0200249
250 if (!root_level) {
251 root_level = malloc(sizeof(int8_t));
252 *root_level = -1;
253 }
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500254
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500255 if (dev->path.type == DEVICE_PATH_PCI) {
256
257 if ((dev->bus->secondary == 0x0) &&
258 (dev->path.pci.devfn == 0x0))
259 *root_level = depth;
260
261 if ((*root_level != -1) && (dev->enabled)) {
Michał Żygowski2f399b72020-04-02 19:51:37 +0200262 if (depth != *root_level)
263 ivrs_add_device_or_bridge(parent, dev, current, ivhd_length);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500264 }
265 }
266
267 for (link = dev->link_list; link; link = link->next)
268 for (sibling = link->children; sibling; sibling =
269 sibling->sibling)
Michał Żygowski2f399b72020-04-02 19:51:37 +0200270 add_ivhd_device_entries(dev, sibling, depth + 1, depth, root_level,
271 current, ivhd_length);
272
273 free(root_level);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500274}
275
Michał Żygowski2f399b72020-04-02 19:51:37 +0200276#define IOMMU_MMIO32(x) (*((volatile uint32_t *)(x)))
277#define EFR_SUPPORT BIT(27)
278
279static unsigned long acpi_fill_ivrs11(unsigned long current, acpi_ivrs_t *ivrs_agesa)
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500280{
Michał Żygowski2f399b72020-04-02 19:51:37 +0200281 acpi_ivrs_ivhd11_t *ivhd_11;
282 unsigned long current_backup;
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500283
Michał Żygowski2f399b72020-04-02 19:51:37 +0200284 /*
285 * These devices should be already found by previous function.
286 * Do not perform NULL checks.
287 */
288 struct device *nb_dev = pcidev_on_root(0, 0);
289 struct device *iommu_dev = pcidev_on_root(0, 2);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500290
Michał Żygowski2f399b72020-04-02 19:51:37 +0200291 /*
292 * In order to utilize all features, firmware should expose type 11h
293 * IVHD which supersedes the type 10h.
294 */
295 memset((void *)current, 0, sizeof(acpi_ivrs_ivhd11_t));
296 ivhd_11 = (acpi_ivrs_ivhd11_t *)current;
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500297
Michał Żygowski2f399b72020-04-02 19:51:37 +0200298 /* Enable EFR */
299 ivhd_11->type = IVHD_BLOCK_TYPE_FULL__FIXED;
300 /* For type 11h bits 6 and 7 are reserved */
301 ivhd_11->flags = ivrs_agesa->ivhd.flags & 0x3f;
302 ivhd_11->length = sizeof(struct acpi_ivrs_ivhd_11);
303 /* BDF <bus>:00.2 */
304 ivhd_11->device_id = 0x02 | (nb_dev->bus->secondary << 8);
305 /* PCI Capability block 0x40 (type 0xf, "Secure device") */
306 ivhd_11->capability_offset = 0x40;
307 ivhd_11->iommu_base_low = ivrs_agesa->ivhd.iommu_base_low;
308 ivhd_11->iommu_base_high = ivrs_agesa->ivhd.iommu_base_high;
309 ivhd_11->pci_segment_group = 0x0000;
310 ivhd_11->iommu_info = ivrs_agesa->ivhd.iommu_info;
311 ivhd_11->iommu_attributes.perf_counters =
312 (IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x4000) >> 7) & 0xf;
313 ivhd_11->iommu_attributes.perf_counter_banks =
314 (IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x4000) >> 12) & 0x3f;
315 ivhd_11->iommu_attributes.msi_num_ppr =
316 (pci_read_config32(iommu_dev, ivhd_11->capability_offset + 0x10) >> 27) & 0x1f;
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500317
Michał Żygowski2f399b72020-04-02 19:51:37 +0200318 if (pci_read_config32(iommu_dev, ivhd_11->capability_offset) & EFR_SUPPORT) {
319 ivhd_11->efr_reg_image_low = IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x30);
320 ivhd_11->efr_reg_image_high = IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x34);
321 }
322
323 current += sizeof(acpi_ivrs_ivhd11_t);
324
325 /* Now repeat all the device entries from type 10h */
326 current_backup = current;
327 current = ivhd_dev_range(current, PCI_DEVFN(1, 0), PCI_DEVFN(0x1f, 6), 0);
328 ivhd_11->length += (current - current_backup);
329 add_ivhd_device_entries(NULL, all_devices, 0, -1, NULL, &current, &ivhd_11->length);
330
331 /* Describe HPET */
332 current_backup = current;
333 current = ivhd_describe_hpet(current);
334 ivhd_11->length += (current - current_backup);
335
336 /* Describe IOAPICs */
337 current_backup = current;
338 current = acpi_fill_ivrs_ioapic(ivrs_agesa, current);
339 ivhd_11->length += (current - current_backup);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500340
341 return current;
342}
343
344static unsigned long acpi_fill_ivrs(acpi_ivrs_t *ivrs, unsigned long current)
345{
Piotr Król063e1562018-07-22 20:52:26 +0200346 acpi_ivrs_t *ivrs_agesa;
Michał Żygowski2f399b72020-04-02 19:51:37 +0200347 unsigned long current_backup;
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500348
Michał Żygowski2f399b72020-04-02 19:51:37 +0200349 struct device *nb_dev = pcidev_on_root(0, 0);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500350 if (!nb_dev) {
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500351 printk(BIOS_WARNING, "%s: G-series northbridge device not present!\n", __func__);
352 printk(BIOS_WARNING, "%s: IVRS table not generated...\n", __func__);
353
354 return (unsigned long)ivrs;
355 }
356
Michał Żygowski2f399b72020-04-02 19:51:37 +0200357 struct device *iommu_dev = pcidev_on_root(0, 2);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500358
Michał Żygowski2f399b72020-04-02 19:51:37 +0200359 if (!iommu_dev) {
360 printk(BIOS_WARNING, "%s: IOMMU device not found\n", __func__);
361
362 return (unsigned long)ivrs;
363 }
364
Piotr Król063e1562018-07-22 20:52:26 +0200365 ivrs_agesa = agesawrapper_getlateinitptr(PICK_IVRS);
366 if (ivrs_agesa != NULL) {
Michał Żygowski2f399b72020-04-02 19:51:37 +0200367 ivrs->iv_info = ivrs_agesa->iv_info;
368 ivrs->ivhd.type = IVHD_BLOCK_TYPE_LEGACY__FIXED;
369 ivrs->ivhd.flags = ivrs_agesa->ivhd.flags;
Piotr Król063e1562018-07-22 20:52:26 +0200370 ivrs->ivhd.length = sizeof(struct acpi_ivrs_ivhd);
371 /* BDF <bus>:00.2 */
Michał Żygowski2f399b72020-04-02 19:51:37 +0200372 ivrs->ivhd.device_id = 0x02 | (nb_dev->bus->secondary << 8);
373 /* PCI Capability block 0x40 (type 0xf, "Secure device") */
Piotr Król063e1562018-07-22 20:52:26 +0200374 ivrs->ivhd.capability_offset = 0x40;
375 ivrs->ivhd.iommu_base_low = ivrs_agesa->ivhd.iommu_base_low;
376 ivrs->ivhd.iommu_base_high = ivrs_agesa->ivhd.iommu_base_high;
Michał Żygowski2f399b72020-04-02 19:51:37 +0200377 ivrs->ivhd.pci_segment_group = 0x0000;
378 ivrs->ivhd.iommu_info = ivrs_agesa->ivhd.iommu_info;
379 ivrs->ivhd.iommu_feature_info = ivrs_agesa->ivhd.iommu_feature_info;
380 /* Enable EFR if supported */
381 if (pci_read_config32(iommu_dev, ivrs->ivhd.capability_offset) & EFR_SUPPORT)
382 ivrs->iv_info |= IVINFO_EFR_SUPPORTED;
Piotr Król063e1562018-07-22 20:52:26 +0200383 } else {
384 printk(BIOS_WARNING, "%s: AGESA returned NULL IVRS\n", __func__);
385
386 return (unsigned long)ivrs;
387 }
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500388
Michał Żygowski2f399b72020-04-02 19:51:37 +0200389 /*
390 * Add all possible PCI devices on bus 0 that can generate transactions
391 * processed by IOMMU. Start with device 00:01.0 since IOMMU does not
392 * translate transactions generated by itself.
393 */
394 current_backup = current;
395 current = ivhd_dev_range(current, PCI_DEVFN(1, 0), PCI_DEVFN(0x1f, 6), 0);
396 ivrs->ivhd.length += (current - current_backup);
397 add_ivhd_device_entries(NULL, all_devices, 0, -1, NULL, &current, &ivrs->ivhd.length);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500398
Michał Żygowski2f399b72020-04-02 19:51:37 +0200399 /* Describe HPET */
400 current_backup = current;
401 current = ivhd_describe_hpet(current);
402 ivrs->ivhd.length += (current - current_backup);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500403
404 /* Describe IOAPICs */
Michał Żygowski2f399b72020-04-02 19:51:37 +0200405 current_backup = current;
406 current = acpi_fill_ivrs_ioapic(ivrs_agesa, current);
407 ivrs->ivhd.length += (current - current_backup);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500408
Michał Żygowski2f399b72020-04-02 19:51:37 +0200409 /* If EFR is not supported, IVHD type 11h is reserved */
410 if (!(ivrs->iv_info & IVINFO_EFR_SUPPORTED))
411 return current;
412
413 return acpi_fill_ivrs11(current, ivrs_agesa);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500414}
415
Furquan Shaikh7536a392020-04-24 21:59:21 -0700416static void northbridge_fill_ssdt_generator(const struct device *device)
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200417{
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200418 char pscope[] = "\\_SB.PCI0";
419
420 acpigen_write_scope(pscope);
Felix Helde3453782023-04-20 13:06:08 +0200421 acpigen_write_name_dword("TOM1", get_top_of_mem_below_4gb());
422
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200423 /*
424 * Since XP only implements parts of ACPI 2.0, we can't use a qword
425 * here.
426 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
427 * slide 22ff.
428 * Shift value right by 20 bit to make it fit into 32bit,
429 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
430 */
Felix Held27af3e62023-04-22 05:59:52 +0200431 acpigen_write_name_dword("TOM2", get_top_of_mem_above_4gb() >> 20);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200432 acpigen_pop_len();
433}
434
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700435static unsigned long agesa_write_acpi_tables(const struct device *device,
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200436 unsigned long current,
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200437 acpi_rsdp_t *rsdp)
438{
439 acpi_srat_t *srat;
440 acpi_slit_t *slit;
441 acpi_header_t *ssdt;
442 acpi_header_t *alib;
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500443 acpi_ivrs_t *ivrs;
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200444
445 /* HEST */
Elyes Haouasd6b6b222022-10-10 12:34:21 +0200446 current = ALIGN_UP(current, 8);
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100447 acpi_write_hest((void *)current, acpi_fill_hest);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200448 acpi_add_table(rsdp, (void *)current);
449 current += ((acpi_header_t *)current)->length;
450
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500451 /* IVRS */
Elyes Haouasd6b6b222022-10-10 12:34:21 +0200452 current = ALIGN_UP(current, 8);
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500453 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200454 ivrs = (acpi_ivrs_t *)current;
Timothy Pearson9ef07d82016-06-13 13:48:58 -0500455 acpi_create_ivrs(ivrs, acpi_fill_ivrs);
456 current += ivrs->header.length;
457 acpi_add_table(rsdp, ivrs);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200458
459 /* SRAT */
Elyes Haouasd6b6b222022-10-10 12:34:21 +0200460 current = ALIGN_UP(current, 8);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200461 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200462 srat = (acpi_srat_t *)agesawrapper_getlateinitptr(PICK_SRAT);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200463 if (srat != NULL) {
464 memcpy((void *)current, srat, srat->header.length);
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200465 srat = (acpi_srat_t *)current;
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200466 current += srat->header.length;
467 acpi_add_table(rsdp, srat);
468 } else {
469 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
470 }
471
472 /* SLIT */
Elyes Haouasd6b6b222022-10-10 12:34:21 +0200473 current = ALIGN_UP(current, 8);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200474 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200475 slit = (acpi_slit_t *)agesawrapper_getlateinitptr(PICK_SLIT);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200476 if (slit != NULL) {
477 memcpy((void *)current, slit, slit->header.length);
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200478 slit = (acpi_slit_t *)current;
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200479 current += slit->header.length;
480 acpi_add_table(rsdp, slit);
481 } else {
482 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
483 }
484
485 /* ALIB */
Elyes Haouasd6b6b222022-10-10 12:34:21 +0200486 current = ALIGN_UP(current, 16);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200487 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200488 alib = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_ALIB);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200489 if (alib != NULL) {
490 memcpy((void *)current, alib, alib->length);
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200491 alib = (acpi_header_t *)current;
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200492 current += alib->length;
493 acpi_add_table(rsdp, (void *)alib);
494 }
495 else {
496 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
497 }
498
499 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
500 /* SSDT */
Elyes Haouasd6b6b222022-10-10 12:34:21 +0200501 current = ALIGN_UP(current, 16);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200502 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200503 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_PSTATE);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200504 if (ssdt != NULL) {
505 memcpy((void *)current, ssdt, ssdt->length);
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200506 ssdt = (acpi_header_t *)current;
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200507 current += ssdt->length;
508 }
509 else {
510 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
511 }
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200512 acpi_add_table(rsdp, ssdt);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200513
514 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
515 return current;
516}
517
Felix Held7b9c6472023-11-16 16:06:49 +0100518struct device_operations amd_pi_northbridge_ops = {
Michał Żygowskifb198c62021-05-09 13:54:09 +0200519 .read_resources = nb_read_resources,
Felix Heldb986e212023-12-16 00:58:09 +0100520 .set_resources = pci_dev_set_resources,
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600521 .enable_resources = pci_dev_enable_resources,
522 .init = northbridge_init,
Michał Żygowskifb198c62021-05-09 13:54:09 +0200523 .ops_pci = &pci_dev_ops_pci,
Nico Huber68680dd2020-03-31 17:34:52 +0200524 .acpi_fill_ssdt = northbridge_fill_ssdt_generator,
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200525 .write_acpi_tables = agesa_write_acpi_tables,
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600526};
527
Dave Frodin891f71a2015-01-19 15:58:24 -0700528static void fam16_finalize(void *chip_info)
529{
Kyösti Mälkki90ac7362018-05-20 20:59:52 +0300530 struct device *dev;
Kyösti Mälkki33ff44c2018-05-22 01:15:22 +0300531 dev = pcidev_on_root(0, 0); /* clear IoapicSbFeatureEn */
Elyes Haouasa1f5ad02022-02-17 18:14:08 +0100532
Dave Frodin891f71a2015-01-19 15:58:24 -0700533 pci_write_config32(dev, 0xF8, 0);
534 pci_write_config32(dev, 0xFC, 5); /* TODO: move it to dsdt.asl */
535
Michał Żygowski6ca5b472019-09-10 15:10:22 +0200536 /*
537 * Currently it is impossible to enable ACS with AGESA by setting the
538 * correct bit for AmdInitMid phase. AGESA code path does not call the
539 * right function that enables these functionalities. Disabled ACS
540 * result in multiple PCIe devices to be assigned to the same IOMMU
541 * group. Without IOMMU group separation the devices cannot be passed
542 * through independently.
543 */
544
545 /* Select GPP link core IO Link Strap Control register 0xB0 */
546 pci_write_config32(dev, 0xE0, 0x014000B0);
Michał Żygowski6ca5b472019-09-10 15:10:22 +0200547
548 /* Enable AER (bit 5) and ACS (bit 6 undocumented) */
Elyes Haouasa1f5ad02022-02-17 18:14:08 +0100549 pci_or_config32(dev, 0xE4, PCIE_CAP_AER | PCIE_CAP_ACS);
Michał Żygowski6ca5b472019-09-10 15:10:22 +0200550
551 /* Select GPP link core Wrapper register 0x00 (undocumented) */
552 pci_write_config32(dev, 0xE0, 0x01300000);
Michał Żygowski6ca5b472019-09-10 15:10:22 +0200553
554 /*
555 * Enable ACS capabilities straps including sub-items. From lspci it
556 * looks like these bits enable: Source Validation and Translation
557 * Blocking
558 */
Elyes Haouasa1f5ad02022-02-17 18:14:08 +0100559 pci_or_config32(dev, 0xE4, (BIT(24) | BIT(25) | BIT(26)));
Michał Żygowski6ca5b472019-09-10 15:10:22 +0200560
Dave Frodin891f71a2015-01-19 15:58:24 -0700561 /* disable No Snoop */
Kyösti Mälkki33ff44c2018-05-22 01:15:22 +0300562 dev = pcidev_on_root(1, 1);
Kyösti Mälkki69f6fd42019-01-21 14:19:01 +0200563 if (dev != NULL) {
Elyes Haouasa1f5ad02022-02-17 18:14:08 +0100564 pci_and_config32(dev, 0x60, ~(1 << 11));
Kyösti Mälkki69f6fd42019-01-21 14:19:01 +0200565 }
Dave Frodin891f71a2015-01-19 15:58:24 -0700566}
567
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600568#if CONFIG_HW_MEM_HOLE_SIZEK != 0
569struct hw_mem_hole_info {
Subrata Banikb1434fc2019-03-15 22:20:41 +0530570 unsigned int hole_startk;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600571 int node_id;
572};
573static struct hw_mem_hole_info get_hw_mem_hole_info(void)
574{
575 struct hw_mem_hole_info mem_hole;
576 int i;
577 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
578 mem_hole.node_id = -1;
Michał Kopećca1e8aa2021-12-03 15:17:46 +0100579 for (i = 0; i < get_node_nums(); i++) {
Michał Żygowski88a0ce62021-05-05 09:52:59 +0200580 resource_t basek, limitk;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600581 u32 hole;
Michał Żygowski88a0ce62021-05-05 09:52:59 +0200582 if (!get_dram_base_limit(i, &basek, &limitk))
583 continue; // no memory on this node
Felix Held606e5632023-11-16 18:34:33 +0100584 hole = pci_read_config32(get_node_pci(i, 1), 0xf0);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600585 if (hole & 2) { // we find the hole
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200586 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600587 mem_hole.node_id = i; // record the node No with hole
588 break; // only one hole
589 }
590 }
591
592 /* We need to double check if there is special set on base reg and limit reg
593 * are not continuous instead of hole, it will find out its hole_startk.
594 */
595 if (mem_hole.node_id == -1) {
596 resource_t limitk_pri = 0;
Michał Kopećca1e8aa2021-12-03 15:17:46 +0100597 for (i = 0; i < get_node_nums(); i++) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600598 resource_t base_k, limit_k;
Michał Żygowski88a0ce62021-05-05 09:52:59 +0200599 if (!get_dram_base_limit(i, &base_k, &limit_k))
600 continue; // no memory on this node
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200601 if (base_k > 4 * 1024 * 1024) break; // don't need to go to check
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600602 if (limitk_pri != base_k) { // we find the hole
Elyes HAOUAS38a4f2a92020-01-07 19:53:36 +0100603 mem_hole.hole_startk = (unsigned int)limitk_pri; // must be below 4G
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600604 mem_hole.node_id = i;
605 break; //only one hole
606 }
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600607 limitk_pri = limit_k;
608 }
609 }
610 return mem_hole;
611}
612#endif
613
Michał Żygowskif5d457d2021-05-09 13:58:04 +0200614static void domain_read_resources(struct device *dev)
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600615{
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600616 unsigned long mmio_basek;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600617 int i, idx;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600618#if CONFIG_HW_MEM_HOLE_SIZEK != 0
619 struct hw_mem_hole_info mem_hole;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600620#endif
621
Michał Żygowskif5d457d2021-05-09 13:58:04 +0200622 pci_domain_read_resources(dev);
623
Michał Żygowski58d6f962021-05-05 10:52:08 +0200624 /* TOP_MEM MSR is our boundary between DRAM and MMIO under 4G */
Felix Held5e9afe72023-04-20 12:55:55 +0200625 mmio_basek = get_top_of_mem_below_4gb() >> 10;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600626
627#if CONFIG_HW_MEM_HOLE_SIZEK != 0
628 /* if the hw mem hole is already set in raminit stage, here we will compare
629 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
630 * use hole_basek as mmio_basek and we don't need to reset hole.
631 * otherwise We reset the hole to the mmio_basek
632 */
633
634 mem_hole = get_hw_mem_hole_info();
635
636 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
637 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
638 mmio_basek = mem_hole.hole_startk;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600639 }
640#endif
641
642 idx = 0x10;
Michał Kopećca1e8aa2021-12-03 15:17:46 +0100643 for (i = 0; i < get_node_nums(); i++) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600644 resource_t basek, limitk, sizek; // 4 1T
645
Michał Żygowski88a0ce62021-05-05 09:52:59 +0200646 if (!get_dram_base_limit(i, &basek, &limitk))
647 continue; // no memory on this node
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600648
649 sizek = limitk - basek;
650
Michał Żygowski58d6f962021-05-05 10:52:08 +0200651 printk(BIOS_DEBUG, "node %d: basek=%08llx, limitk=%08llx, sizek=%08llx,\n",
652 i, basek, limitk, sizek);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600653
Elyes Haouas5213b192022-02-25 18:13:03 +0100654 /* See if we need a hole from 0xa0000 (640K) to 0xfffff (1024K) */
Elyes Haouas9d8df302022-02-25 18:23:01 +0100655 if (basek < 640 && sizek > 1024) {
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300656 ram_resource_kb(dev, (idx | i), basek, 640 - basek);
Michał Żygowski58d6f962021-05-05 10:52:08 +0200657 idx += 0x10;
Elyes Haouas9d8df302022-02-25 18:23:01 +0100658 basek = 1024;
Michał Żygowski58d6f962021-05-05 10:52:08 +0200659 sizek = limitk - basek;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600660 }
661
Michał Żygowski58d6f962021-05-05 10:52:08 +0200662 printk(BIOS_DEBUG, "node %d: basek=%08llx, limitk=%08llx, sizek=%08llx,\n",
663 i, basek, limitk, sizek);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600664
665 /* split the region to accommodate pci memory space */
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200666 if ((basek < 4 * 1024 * 1024) && (limitk > mmio_basek)) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600667 if (basek <= mmio_basek) {
Subrata Banikb1434fc2019-03-15 22:20:41 +0530668 unsigned int pre_sizek;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600669 pre_sizek = mmio_basek - basek;
Elyes HAOUASa8131602016-09-19 10:27:57 -0600670 if (pre_sizek > 0) {
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300671 ram_resource_kb(dev, (idx | i), basek, pre_sizek);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600672 idx += 0x10;
673 sizek -= pre_sizek;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600674 }
675 basek = mmio_basek;
676 }
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200677 if ((basek + sizek) <= 4 * 1024 * 1024) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600678 sizek = 0;
679 }
680 else {
Felix Held27af3e62023-04-22 05:59:52 +0200681 uint64_t topmem2 = get_top_of_mem_above_4gb();
Elyes Haouasf9b535e2022-07-16 09:47:42 +0200682 basek = 4 * 1024 * 1024;
683 sizek = topmem2 / 1024 - basek;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600684 }
685 }
686
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300687 ram_resource_kb(dev, (idx | i), basek, sizek);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600688 idx += 0x10;
689 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
690 i, mmio_basek, basek, limitk);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600691 }
692
Kyösti Mälkkie87564f2017-04-15 20:07:53 +0300693 add_uma_resource_below_tolm(dev, 7);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600694}
695
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600696static const char *domain_acpi_name(const struct device *dev)
Philipp Deppenwiese30670122017-03-01 02:24:33 +0100697{
698 if (dev->path.type == DEVICE_PATH_DOMAIN)
699 return "PCI0";
700
701 return NULL;
702}
703
Felix Held8ccd3142023-11-16 00:58:30 +0100704struct device_operations amd_fam16_mod30_pci_domain_ops = {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600705 .read_resources = domain_read_resources,
Michał Żygowskif5d457d2021-05-09 13:58:04 +0200706 .set_resources = pci_domain_set_resources,
Arthur Heymans0b0113f2023-08-31 17:09:28 +0200707 .scan_bus = pci_host_bridge_scan_bus,
Philipp Deppenwiese30670122017-03-01 02:24:33 +0100708 .acpi_name = domain_acpi_name,
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600709};
710
Michał Kopećdc35d2a2021-11-30 17:40:52 +0100711void mp_init_cpus(struct bus *cpu_bus)
712{
Arthur Heymans4fcaccf2022-06-02 13:17:37 +0200713 extern const struct mp_ops amd_mp_ops_no_smm;
Michał Kopećdc35d2a2021-11-30 17:40:52 +0100714 /* TODO: Handle mp_init_with_smm failure? */
Arthur Heymans4fcaccf2022-06-02 13:17:37 +0200715 mp_init_with_smm(cpu_bus, &amd_mp_ops_no_smm);
Michał Kopećdc35d2a2021-11-30 17:40:52 +0100716
717 /* The flash is now no longer cacheable. Reset to WP for performance. */
718 mtrr_use_temp_range(OPTIMAL_CACHE_ROM_BASE, OPTIMAL_CACHE_ROM_SIZE,
719 MTRR_TYPE_WRPROT);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600720}
721
Felix Heldc391bff2023-02-16 19:38:49 +0100722void generate_cpu_entries(const struct device *device)
723{
724 int cpu;
725 const int cores = get_cpu_count();
726
727 printk(BIOS_DEBUG, "ACPI \\_SB report %d core(s)\n", cores);
728
729 /* Generate \_SB.Pxxx */
730 for (cpu = 0; cpu < cores; cpu++) {
731 acpigen_write_processor_device(cpu);
732 acpigen_write_processor_device_end();
733 }
734}
735
Felix Held8ccd3142023-11-16 00:58:30 +0100736struct device_operations amd_fam16_mod30_cpu_bus_ops = {
Felix Heldc391bff2023-02-16 19:38:49 +0100737 .read_resources = noop_read_resources,
738 .set_resources = noop_set_resources,
739 .init = mp_cpu_bus_init,
740 .acpi_fill_ssdt = generate_cpu_entries,
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600741};
742
Felix Held1952d132023-11-16 00:54:30 +0100743struct chip_operations northbridge_amd_pi_00730F01_ops = {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600744 CHIP_NAME("AMD FAM16 Root Complex")
Felix Held1952d132023-11-16 00:54:30 +0100745 .final = fam16_finalize,
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600746};
747
748/*********************************************************************
749 * Change the vendor / device IDs to match the generic VBIOS header. *
750 *********************************************************************/
751u32 map_oprom_vendev(u32 vendev)
752{
753 u32 new_vendev;
754 new_vendev =
755 ((0x10029850 <= vendev) && (vendev <= 0x1002986F)) ? 0x10029850 : vendev;
756
757 if (vendev != new_vendev)
758 printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev);
759
760 return new_vendev;
761}