1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <commonlib/helpers.h>
4 #include <console/console.h>
5 #include <device/pci_ops.h>
7 #include <acpi/acpi_ivrs.h>
8 #include <arch/ioapic.h>
11 #include <device/device.h>
12 #include <device/pci.h>
13 #include <device/pci_ids.h>
17 #include <cpu/x86/mp.h>
20 #include <cpu/amd/msr.h>
21 #include <cpu/amd/mtrr.h>
22 #include <acpi/acpigen.h>
23 #include <northbridge/amd/nb_common.h>
24 #include <northbridge/amd/agesa/agesa_helper.h>
25 #include <southbridge/amd/pi/hudson/pci_devs.h>
26 #include <amdblocks/cpu.h>
28 #define PCIE_CAP_AER BIT(5)
29 #define PCIE_CAP_ACS BIT(6)
31 static int get_dram_base_limit(resource_t
*basek
, resource_t
*limitk
)
35 temp
= pci_read_config32(DEV_PTR(ht_1
), 0x40); //[39:24] at [31:16]
37 return 0; // this memory range is not enabled
39 * BKDG: {DramBase[39:24], 00_0000h} <= address[39:0] so shift left by 8 bits
40 * for physical address and the convert to KiB by shifting 10 bits left
42 *basek
= ((temp
& 0xffff0000)) >> (10 - 8);
44 * BKDG address[39:0] <= {DramLimit[39:24], FF_FFFFh} converted as above but
45 * ORed with 0xffff to get real limit before shifting.
47 temp
= pci_read_config32(DEV_PTR(ht_1
), 0x44); //[39:24] at [31:16]
48 *limitk
= ((temp
& 0xffff0000) | 0xffff) >> (10 - 8);
49 *limitk
+= 1; // round up last byte
54 static void add_fixed_resources(struct device
*dev
, int index
)
56 /* Reserve everything between A segment and 1MB:
58 * 0xa0000 - 0xbffff: legacy VGA
59 * 0xc0000 - 0xfffff: option ROMs and SeaBIOS (if used)
61 mmio_resource_kb(dev
, index
++, VGA_MMIO_BASE
>> 10, VGA_MMIO_SIZE
>> 10);
62 reserved_ram_resource_kb(dev
, index
++, 0xc0000 >> 10, (0x100000 - 0xc0000) >> 10);
64 /* Check if CC6 save area is enabled (bit 18 CC6SaveEn) */
65 if (pci_read_config32(DEV_PTR(ht_2
), 0x118) & (1 << 18)) {
66 /* Add CC6 DRAM UC resource residing at DRAM Limit of size 16MB as per BKDG */
67 resource_t basek
, limitk
;
68 if (!get_dram_base_limit(&basek
, &limitk
))
70 mmio_resource_kb(dev
, index
++, limitk
, 16 * 1024);
74 static void nb_read_resources(struct device
*dev
)
77 * This MMCONF resource must be reserved in the PCI domain.
78 * It is not honored by the coreboot resource allocator if it is in
81 mmconf_resource(dev
, MMIO_CONF_BASE
);
83 /* NB IOAPIC2 resource */
84 mmio_range(dev
, IO_APIC2_ADDR
, IO_APIC2_ADDR
, 0x1000);
86 add_fixed_resources(dev
, 0);
89 static void northbridge_init(struct device
*dev
)
91 register_new_ioapic(IO_APIC2_ADDR
);
94 static unsigned long acpi_fill_hest(acpi_hest_t
*hest
)
98 /* Skip the HEST header. */
99 current
= (void *)(hest
+ 1);
101 addr
= agesawrapper_getlateinitptr(PICK_WHEA_MCE
);
103 current
+= acpi_create_hest_error_source(hest
, current
, 0, (void *)((u32
)addr
+ 2), *(UINT16
*)addr
- 2);
105 addr
= agesawrapper_getlateinitptr(PICK_WHEA_CMC
);
107 current
+= acpi_create_hest_error_source(hest
, current
, 1, (void *)((u32
)addr
+ 2), *(UINT16
*)addr
- 2);
109 return (unsigned long)current
;
112 static unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t
*ivrs
, unsigned long current
)
114 /* 8-byte IVHD structures must be aligned to the 8-byte boundary. */
115 current
= ALIGN_UP(current
, 8);
116 ivrs_ivhd_special_t
*ivhd_ioapic
= (ivrs_ivhd_special_t
*)current
;
118 ivhd_ioapic
->type
= IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV
;
119 ivhd_ioapic
->reserved
= 0x0000;
120 ivhd_ioapic
->dte_setting
= IVHD_DTE_LINT_1_PASS
| IVHD_DTE_LINT_0_PASS
|
121 IVHD_DTE_SYS_MGT_NO_TRANS
| IVHD_DTE_NMI_PASS
|
122 IVHD_DTE_EXT_INT_PASS
| IVHD_DTE_INIT_PASS
;
123 ivhd_ioapic
->handle
= get_ioapic_id(IO_APIC_ADDR
);
124 ivhd_ioapic
->source_dev_id
= PCI_DEVFN(SMBUS_DEV
, SMBUS_FUNC
);
125 ivhd_ioapic
->variety
= IVHD_SPECIAL_DEV_IOAPIC
;
126 current
+= sizeof(ivrs_ivhd_special_t
);
128 ivhd_ioapic
= (ivrs_ivhd_special_t
*)current
;
129 ivhd_ioapic
->type
= IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV
;
130 ivhd_ioapic
->reserved
= 0x0000;
131 ivhd_ioapic
->dte_setting
= 0x00;
132 ivhd_ioapic
->handle
= get_ioapic_id(IO_APIC2_ADDR
);
133 ivhd_ioapic
->source_dev_id
= PCI_DEVFN(0, 1);
134 ivhd_ioapic
->variety
= IVHD_SPECIAL_DEV_IOAPIC
;
135 current
+= sizeof(ivrs_ivhd_special_t
);
140 static unsigned long ivhd_describe_hpet(unsigned long current
)
142 /* 8-byte IVHD structures must be aligned to the 8-byte boundary. */
143 current
= ALIGN_UP(current
, 8);
144 ivrs_ivhd_special_t
*ivhd_hpet
= (ivrs_ivhd_special_t
*)current
;
146 ivhd_hpet
->type
= IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV
;
147 ivhd_hpet
->reserved
= 0x0000;
148 ivhd_hpet
->dte_setting
= 0x00;
149 ivhd_hpet
->handle
= 0x00;
150 ivhd_hpet
->source_dev_id
= PCI_DEVFN(SMBUS_DEV
, SMBUS_FUNC
);
151 ivhd_hpet
->variety
= IVHD_SPECIAL_DEV_HPET
;
152 current
+= sizeof(ivrs_ivhd_special_t
);
157 static unsigned long ivhd_dev_range(unsigned long current
, uint16_t start_devid
,
158 uint16_t end_devid
, uint8_t setting
)
160 /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */
161 current
= ALIGN_UP(current
, 4);
162 ivrs_ivhd_generic_t
*ivhd_range
= (ivrs_ivhd_generic_t
*)current
;
164 /* Create the start range IVHD entry */
165 ivhd_range
->type
= IVHD_DEV_4_BYTE_START_RANGE
;
166 ivhd_range
->dev_id
= start_devid
;
167 ivhd_range
->dte_setting
= setting
;
168 current
+= sizeof(ivrs_ivhd_generic_t
);
170 /* Create the end range IVHD entry */
171 ivhd_range
= (ivrs_ivhd_generic_t
*)current
;
172 ivhd_range
->type
= IVHD_DEV_4_BYTE_END_RANGE
;
173 ivhd_range
->dev_id
= end_devid
;
174 ivhd_range
->dte_setting
= setting
;
175 current
+= sizeof(ivrs_ivhd_generic_t
);
180 static unsigned long add_ivhd_dev_entry(struct device
*parent
, struct device
*dev
,
181 unsigned long *current
, uint8_t type
, uint8_t data
)
183 if (type
== IVHD_DEV_4_BYTE_SELECT
) {
184 /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */
185 *current
= ALIGN_UP(*current
, 4);
186 ivrs_ivhd_generic_t
*ivhd_entry
= (ivrs_ivhd_generic_t
*)*current
;
188 ivhd_entry
->type
= type
;
189 ivhd_entry
->dev_id
= dev
->path
.pci
.devfn
| (dev
->upstream
->secondary
<< 8);
190 ivhd_entry
->dte_setting
= data
;
191 *current
+= sizeof(ivrs_ivhd_generic_t
);
192 } else if (type
== IVHD_DEV_8_BYTE_ALIAS_SELECT
) {
193 /* 8-byte IVHD structures must be aligned to the 8-byte boundary. */
194 *current
= ALIGN_UP(*current
, 8);
195 ivrs_ivhd_alias_t
*ivhd_entry
= (ivrs_ivhd_alias_t
*)*current
;
197 ivhd_entry
->type
= type
;
198 ivhd_entry
->dev_id
= dev
->path
.pci
.devfn
| (dev
->upstream
->secondary
<< 8);
199 ivhd_entry
->dte_setting
= data
;
200 ivhd_entry
->reserved1
= 0;
201 ivhd_entry
->reserved2
= 0;
202 ivhd_entry
->source_dev_id
= parent
->path
.pci
.devfn
|
203 (parent
->upstream
->secondary
<< 8);
204 *current
+= sizeof(ivrs_ivhd_alias_t
);
210 static void ivrs_add_device_or_bridge(struct device
*parent
, struct device
*dev
,
211 unsigned long *current
, uint16_t *ivhd_length
)
213 unsigned int header_type
, is_pcie
;
214 unsigned long current_backup
;
216 header_type
= dev
->hdr_type
& 0x7f;
217 is_pcie
= pci_find_capability(dev
, PCI_CAP_ID_PCIE
);
219 if (((header_type
== PCI_HEADER_TYPE_NORMAL
) ||
220 (header_type
== PCI_HEADER_TYPE_BRIDGE
)) && is_pcie
) {
221 /* Device or Bridge is PCIe */
222 current_backup
= *current
;
223 add_ivhd_dev_entry(parent
, dev
, current
, IVHD_DEV_4_BYTE_SELECT
, 0x0);
224 *ivhd_length
+= (*current
- current_backup
);
225 } else if ((header_type
== PCI_HEADER_TYPE_NORMAL
) && !is_pcie
) {
226 /* Device is legacy PCI or PCI-X */
227 current_backup
= *current
;
228 add_ivhd_dev_entry(parent
, dev
, current
, IVHD_DEV_8_BYTE_ALIAS_SELECT
, 0x0);
229 *ivhd_length
+= (*current
- current_backup
);
233 static void add_ivhd_device_entries(struct device
*parent
, struct device
*dev
,
234 unsigned int depth
, int linknum
, int8_t *root_level
,
235 unsigned long *current
, uint16_t *ivhd_length
)
237 struct device
*sibling
;
240 root_level
= malloc(sizeof(int8_t));
244 if (dev
->path
.type
== DEVICE_PATH_PCI
) {
245 if ((dev
->upstream
->secondary
== 0x0) &&
246 (dev
->path
.pci
.devfn
== 0x0))
249 if ((*root_level
!= -1) && (dev
->enabled
)) {
250 if (depth
!= *root_level
)
251 ivrs_add_device_or_bridge(parent
, dev
, current
, ivhd_length
);
255 if (dev
->downstream
) {
256 for (sibling
= dev
->downstream
->children
; sibling
; sibling
= sibling
->sibling
)
257 add_ivhd_device_entries(dev
, sibling
, depth
+ 1, depth
, root_level
,
258 current
, ivhd_length
);
264 #define IOMMU_MMIO32(x) (*((volatile uint32_t *)(x)))
265 #define EFR_SUPPORT BIT(27)
267 static unsigned long acpi_fill_ivrs11(unsigned long current
, acpi_ivrs_t
*ivrs_agesa
)
269 acpi_ivrs_ivhd11_t
*ivhd_11
;
270 unsigned long current_backup
;
273 * These devices should be already found by previous function.
274 * Do not perform NULL checks.
276 struct device
*nb_dev
= pcidev_on_root(0, 0);
277 struct device
*iommu_dev
= pcidev_on_root(0, 2);
280 * In order to utilize all features, firmware should expose type 11h
281 * IVHD which supersedes the type 10h.
283 memset((void *)current
, 0, sizeof(acpi_ivrs_ivhd11_t
));
284 ivhd_11
= (acpi_ivrs_ivhd11_t
*)current
;
287 ivhd_11
->type
= IVHD_BLOCK_TYPE_FULL__FIXED
;
288 /* For type 11h bits 6 and 7 are reserved */
289 ivhd_11
->flags
= ivrs_agesa
->ivhd
.flags
& 0x3f;
290 ivhd_11
->length
= sizeof(struct acpi_ivrs_ivhd_11
);
292 ivhd_11
->device_id
= 0x02 | (nb_dev
->upstream
->secondary
<< 8);
293 /* PCI Capability block 0x40 (type 0xf, "Secure device") */
294 ivhd_11
->capability_offset
= 0x40;
295 ivhd_11
->iommu_base_low
= ivrs_agesa
->ivhd
.iommu_base_low
;
296 ivhd_11
->iommu_base_high
= ivrs_agesa
->ivhd
.iommu_base_high
;
297 ivhd_11
->pci_segment_group
= nb_dev
->upstream
->segment_group
;
298 ivhd_11
->iommu_info
= ivrs_agesa
->ivhd
.iommu_info
;
299 ivhd_11
->iommu_attributes
.perf_counters
=
300 (IOMMU_MMIO32(ivhd_11
->iommu_base_low
+ 0x4000) >> 7) & 0xf;
301 ivhd_11
->iommu_attributes
.perf_counter_banks
=
302 (IOMMU_MMIO32(ivhd_11
->iommu_base_low
+ 0x4000) >> 12) & 0x3f;
303 ivhd_11
->iommu_attributes
.msi_num_ppr
=
304 (pci_read_config32(iommu_dev
, ivhd_11
->capability_offset
+ 0x10) >> 27) & 0x1f;
306 if (pci_read_config32(iommu_dev
, ivhd_11
->capability_offset
) & EFR_SUPPORT
) {
307 ivhd_11
->efr_reg_image_low
= IOMMU_MMIO32(ivhd_11
->iommu_base_low
+ 0x30);
308 ivhd_11
->efr_reg_image_high
= IOMMU_MMIO32(ivhd_11
->iommu_base_low
+ 0x34);
311 current
+= sizeof(acpi_ivrs_ivhd11_t
);
313 /* Now repeat all the device entries from type 10h */
314 current_backup
= current
;
315 current
= ivhd_dev_range(current
, PCI_DEVFN(1, 0), PCI_DEVFN(0x1f, 6), 0);
316 ivhd_11
->length
+= (current
- current_backup
);
317 add_ivhd_device_entries(NULL
, all_devices
, 0, -1, NULL
, ¤t
, &ivhd_11
->length
);
320 current_backup
= current
;
321 current
= ivhd_describe_hpet(current
);
322 ivhd_11
->length
+= (current
- current_backup
);
324 /* Describe IOAPICs */
325 current_backup
= current
;
326 current
= acpi_fill_ivrs_ioapic(ivrs_agesa
, current
);
327 ivhd_11
->length
+= (current
- current_backup
);
332 static unsigned long acpi_fill_ivrs(acpi_ivrs_t
*ivrs
, unsigned long current
)
334 acpi_ivrs_t
*ivrs_agesa
;
335 unsigned long current_backup
;
337 struct device
*nb_dev
= pcidev_on_root(0, 0);
339 printk(BIOS_WARNING
, "%s: G-series northbridge device not present!\n", __func__
);
340 printk(BIOS_WARNING
, "%s: IVRS table not generated...\n", __func__
);
342 return (unsigned long)ivrs
;
345 struct device
*iommu_dev
= pcidev_on_root(0, 2);
348 printk(BIOS_WARNING
, "%s: IOMMU device not found\n", __func__
);
350 return (unsigned long)ivrs
;
353 ivrs_agesa
= agesawrapper_getlateinitptr(PICK_IVRS
);
354 if (ivrs_agesa
!= NULL
) {
355 ivrs
->iv_info
= ivrs_agesa
->iv_info
;
356 ivrs
->ivhd
.type
= IVHD_BLOCK_TYPE_LEGACY__FIXED
;
357 ivrs
->ivhd
.flags
= ivrs_agesa
->ivhd
.flags
;
358 ivrs
->ivhd
.length
= sizeof(struct acpi_ivrs_ivhd
);
360 ivrs
->ivhd
.device_id
= 0x02 | (nb_dev
->upstream
->secondary
<< 8);
361 /* PCI Capability block 0x40 (type 0xf, "Secure device") */
362 ivrs
->ivhd
.capability_offset
= 0x40;
363 ivrs
->ivhd
.iommu_base_low
= ivrs_agesa
->ivhd
.iommu_base_low
;
364 ivrs
->ivhd
.iommu_base_high
= ivrs_agesa
->ivhd
.iommu_base_high
;
365 ivrs
->ivhd
.pci_segment_group
= nb_dev
->upstream
->segment_group
;
366 ivrs
->ivhd
.iommu_info
= ivrs_agesa
->ivhd
.iommu_info
;
367 ivrs
->ivhd
.iommu_feature_info
= ivrs_agesa
->ivhd
.iommu_feature_info
;
368 /* Enable EFR if supported */
369 if (pci_read_config32(iommu_dev
, ivrs
->ivhd
.capability_offset
) & EFR_SUPPORT
)
370 ivrs
->iv_info
|= IVINFO_EFR_SUPPORTED
;
372 printk(BIOS_WARNING
, "%s: AGESA returned NULL IVRS\n", __func__
);
374 return (unsigned long)ivrs
;
378 * Add all possible PCI devices on bus 0 that can generate transactions
379 * processed by IOMMU. Start with device 00:01.0 since IOMMU does not
380 * translate transactions generated by itself.
382 current_backup
= current
;
383 current
= ivhd_dev_range(current
, PCI_DEVFN(1, 0), PCI_DEVFN(0x1f, 6), 0);
384 ivrs
->ivhd
.length
+= (current
- current_backup
);
385 add_ivhd_device_entries(NULL
, all_devices
, 0, -1, NULL
, ¤t
, &ivrs
->ivhd
.length
);
388 current_backup
= current
;
389 current
= ivhd_describe_hpet(current
);
390 ivrs
->ivhd
.length
+= (current
- current_backup
);
392 /* Describe IOAPICs */
393 current_backup
= current
;
394 current
= acpi_fill_ivrs_ioapic(ivrs_agesa
, current
);
395 ivrs
->ivhd
.length
+= (current
- current_backup
);
397 /* If EFR is not supported, IVHD type 11h is reserved */
398 if (!(ivrs
->iv_info
& IVINFO_EFR_SUPPORTED
))
401 return acpi_fill_ivrs11(current
, ivrs_agesa
);
404 static void northbridge_fill_ssdt_generator(const struct device
*device
)
406 char pscope
[] = "\\_SB.PCI0";
408 acpigen_write_scope(pscope
);
409 acpigen_write_name_dword("TOM1", get_top_of_mem_below_4gb());
412 * Since XP only implements parts of ACPI 2.0, we can't use a qword
414 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
416 * Shift value right by 20 bit to make it fit into 32bit,
417 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
419 acpigen_write_name_dword("TOM2", get_top_of_mem_above_4gb() >> 20);
423 static unsigned long agesa_write_acpi_tables(const struct device
*device
,
424 unsigned long current
,
434 current
= ALIGN_UP(current
, 8);
435 acpi_write_hest((void *)current
, acpi_fill_hest
);
436 acpi_add_table(rsdp
, (void *)current
);
437 current
+= ((acpi_header_t
*)current
)->length
;
440 current
= ALIGN_UP(current
, 8);
441 printk(BIOS_DEBUG
, "ACPI: * IVRS at %lx\n", current
);
442 ivrs
= (acpi_ivrs_t
*)current
;
443 acpi_create_ivrs(ivrs
, acpi_fill_ivrs
);
444 current
+= ivrs
->header
.length
;
445 acpi_add_table(rsdp
, ivrs
);
448 current
= ALIGN_UP(current
, 8);
449 printk(BIOS_DEBUG
, "ACPI: * SRAT at %lx\n", current
);
450 srat
= (acpi_srat_t
*)agesawrapper_getlateinitptr(PICK_SRAT
);
452 memcpy((void *)current
, srat
, srat
->header
.length
);
453 srat
= (acpi_srat_t
*)current
;
454 current
+= srat
->header
.length
;
455 acpi_add_table(rsdp
, srat
);
457 printk(BIOS_DEBUG
, " AGESA SRAT table NULL. Skipping.\n");
461 current
= ALIGN_UP(current
, 8);
462 printk(BIOS_DEBUG
, "ACPI: * SLIT at %lx\n", current
);
463 slit
= (acpi_slit_t
*)agesawrapper_getlateinitptr(PICK_SLIT
);
465 memcpy((void *)current
, slit
, slit
->header
.length
);
466 slit
= (acpi_slit_t
*)current
;
467 current
+= slit
->header
.length
;
468 acpi_add_table(rsdp
, slit
);
470 printk(BIOS_DEBUG
, " AGESA SLIT table NULL. Skipping.\n");
474 current
= ALIGN_UP(current
, 16);
475 printk(BIOS_DEBUG
, "ACPI: * AGESA ALIB SSDT at %lx\n", current
);
476 alib
= (acpi_header_t
*)agesawrapper_getlateinitptr(PICK_ALIB
);
478 memcpy((void *)current
, alib
, alib
->length
);
479 alib
= (acpi_header_t
*)current
;
480 current
+= alib
->length
;
481 acpi_add_table(rsdp
, (void *)alib
);
484 printk(BIOS_DEBUG
, " AGESA ALIB SSDT table NULL. Skipping.\n");
487 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
489 current
= ALIGN_UP(current
, 16);
490 printk(BIOS_DEBUG
, "ACPI: * SSDT at %lx\n", current
);
491 ssdt
= (acpi_header_t
*)agesawrapper_getlateinitptr(PICK_PSTATE
);
493 memcpy((void *)current
, ssdt
, ssdt
->length
);
494 ssdt
= (acpi_header_t
*)current
;
495 current
+= ssdt
->length
;
498 printk(BIOS_DEBUG
, " AGESA PState table NULL. Skipping.\n");
500 acpi_add_table(rsdp
, ssdt
);
502 printk(BIOS_DEBUG
, "ACPI: * SSDT for PState at %lx\n", current
);
506 struct device_operations amd_pi_northbridge_ops
= {
507 .read_resources
= nb_read_resources
,
508 .set_resources
= pci_dev_set_resources
,
509 .enable_resources
= pci_dev_enable_resources
,
510 .init
= northbridge_init
,
511 .ops_pci
= &pci_dev_ops_pci
,
512 .acpi_fill_ssdt
= northbridge_fill_ssdt_generator
,
513 .write_acpi_tables
= agesa_write_acpi_tables
,
516 static void fam16_finalize(void *chip_info
)
519 dev
= pcidev_on_root(0, 0); /* clear IoapicSbFeatureEn */
521 pci_write_config32(dev
, 0xF8, 0);
522 pci_write_config32(dev
, 0xFC, 5); /* TODO: move it to dsdt.asl */
525 * Currently it is impossible to enable ACS with AGESA by setting the
526 * correct bit for AmdInitMid phase. AGESA code path does not call the
527 * right function that enables these functionalities. Disabled ACS
528 * result in multiple PCIe devices to be assigned to the same IOMMU
529 * group. Without IOMMU group separation the devices cannot be passed
530 * through independently.
533 /* Select GPP link core IO Link Strap Control register 0xB0 */
534 pci_write_config32(dev
, 0xE0, 0x014000B0);
536 /* Enable AER (bit 5) and ACS (bit 6 undocumented) */
537 pci_or_config32(dev
, 0xE4, PCIE_CAP_AER
| PCIE_CAP_ACS
);
539 /* Select GPP link core Wrapper register 0x00 (undocumented) */
540 pci_write_config32(dev
, 0xE0, 0x01300000);
543 * Enable ACS capabilities straps including sub-items. From lspci it
544 * looks like these bits enable: Source Validation and Translation
547 pci_or_config32(dev
, 0xE4, (BIT(24) | BIT(25) | BIT(26)));
549 /* disable No Snoop */
550 dev
= pcidev_on_root(1, 1);
552 pci_and_config32(dev
, 0x60, ~(1 << 11));
556 struct hw_mem_hole_info
{
557 unsigned int hole_startk
;
560 static struct hw_mem_hole_info
get_hw_mem_hole_info(void)
562 struct hw_mem_hole_info mem_hole
;
563 mem_hole
.node_id
= -1;
565 resource_t basek
, limitk
;
566 if (get_dram_base_limit(&basek
, &limitk
)) { // memory on this node
567 u32 hole
= pci_read_config32(DEV_PTR(ht_1
), 0xf0);
568 if (hole
& 2) { // we find the hole
569 mem_hole
.hole_startk
= (hole
& (0xff << 24)) >> 10;
570 mem_hole
.node_id
= 0; // record the node No with hole
576 static void domain_read_resources(struct device
*dev
)
578 unsigned long mmio_basek
;
579 unsigned long idx
= 0;
580 struct hw_mem_hole_info mem_hole
;
581 resource_t basek
= 0;
582 resource_t limitk
= 0;
585 pci_domain_read_resources(dev
);
587 /* TOP_MEM MSR is our boundary between DRAM and MMIO under 4G */
588 mmio_basek
= get_top_of_mem_below_4gb() >> 10;
590 /* if the hw mem hole is already set in raminit stage, here we will compare
591 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
592 * use hole_basek as mmio_basek and we don't need to reset hole.
593 * otherwise We reset the hole to the mmio_basek
596 mem_hole
= get_hw_mem_hole_info();
598 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
599 if ((mem_hole
.node_id
!= -1) && (mmio_basek
> mem_hole
.hole_startk
)) {
600 mmio_basek
= mem_hole
.hole_startk
;
603 get_dram_base_limit(&basek
, &limitk
);
604 sizek
= limitk
- basek
;
606 printk(BIOS_DEBUG
, "basek=%08llx, limitk=%08llx, sizek=%08llx,\n",
607 basek
, limitk
, sizek
);
609 /* See if we need a hole from 0xa0000 (640K) to 0xfffff (1024K) */
610 if (basek
< 640 && sizek
> 1024) {
611 ram_resource_kb(dev
, idx
++, basek
, 640 - basek
);
613 sizek
= limitk
- basek
;
616 printk(BIOS_DEBUG
, "basek=%08llx, limitk=%08llx, sizek=%08llx,\n",
617 basek
, limitk
, sizek
);
619 /* split the region to accommodate pci memory space */
620 if ((basek
< 4 * 1024 * 1024) && (limitk
> mmio_basek
)) {
621 if (basek
<= mmio_basek
) {
622 unsigned int pre_sizek
;
623 pre_sizek
= mmio_basek
- basek
;
625 ram_resource_kb(dev
, idx
++, basek
, pre_sizek
);
630 if ((basek
+ sizek
) <= 4 * 1024 * 1024) {
633 uint64_t topmem2
= get_top_of_mem_above_4gb();
634 basek
= 4 * 1024 * 1024;
635 sizek
= topmem2
/ 1024 - basek
;
639 ram_resource_kb(dev
, idx
++, basek
, sizek
);
640 printk(BIOS_DEBUG
, "mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
641 mmio_basek
, basek
, limitk
);
643 add_uma_resource_below_tolm(dev
, idx
++);
646 static const char *domain_acpi_name(const struct device
*dev
)
648 if (dev
->path
.type
== DEVICE_PATH_DOMAIN
)
654 struct device_operations amd_fam16_mod30_pci_domain_ops
= {
655 .read_resources
= domain_read_resources
,
656 .set_resources
= pci_domain_set_resources
,
657 .scan_bus
= pci_host_bridge_scan_bus
,
658 .acpi_name
= domain_acpi_name
,
661 void mp_init_cpus(struct bus
*cpu_bus
)
663 extern const struct mp_ops amd_mp_ops_no_smm
;
664 /* TODO: Handle mp_init_with_smm failure? */
665 mp_init_with_smm(cpu_bus
, &amd_mp_ops_no_smm
);
667 /* The flash is now no longer cacheable. Reset to WP for performance. */
668 mtrr_use_temp_range(OPTIMAL_CACHE_ROM_BASE
, OPTIMAL_CACHE_ROM_SIZE
,
672 void generate_cpu_entries(const struct device
*device
)
675 const int cores
= get_cpu_count();
677 printk(BIOS_DEBUG
, "ACPI \\_SB report %d core(s)\n", cores
);
679 /* Generate \_SB.Pxxx */
680 for (cpu
= 0; cpu
< cores
; cpu
++) {
681 acpigen_write_processor_device(cpu
);
682 acpigen_write_processor_device_end();
686 struct device_operations amd_fam16_mod30_cpu_bus_ops
= {
687 .read_resources
= noop_read_resources
,
688 .set_resources
= noop_set_resources
,
689 .init
= mp_cpu_bus_init
,
690 .acpi_fill_ssdt
= generate_cpu_entries
,
693 struct chip_operations northbridge_amd_pi_00730F01_ops
= {
694 .name
= "AMD FAM16 Root Complex",
695 .final
= fam16_finalize
,
698 /*********************************************************************
699 * Change the vendor / device IDs to match the generic VBIOS header. *
700 *********************************************************************/
701 u32
map_oprom_vendev(u32 vendev
)
705 ((0x10029850 <= vendev
) && (vendev
<= 0x1002986F)) ? 0x10029850 : vendev
;
707 if (vendev
!= new_vendev
)
708 printk(BIOS_NOTICE
, "Mapping PCI device %8x to %8x\n", vendev
, new_vendev
);