• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <types.h>
4 #include <commonlib/helpers.h>
5 #include <console/console.h>
6 #include <acpi/acpi.h>
7 #include <acpi/acpigen.h>
8 #include <device/device.h>
9 #include <device/pci_def.h>
10 #include <device/pci_ops.h>
11 
12 #include "gm45.h"
13 
acpi_fill_dmar(unsigned long current)14 static unsigned long acpi_fill_dmar(unsigned long current)
15 {
16 	const struct device *dev;
17 
18 	dev = pcidev_on_root(3, 0);
19 	int me_active = dev && dev->enabled;
20 
21 	dev = pcidev_on_root(2, 0);
22 	int igd_active = dev && dev->enabled;
23 
24 	int stepping = pci_read_config8(pcidev_on_root(0, 0),
25 							   PCI_CLASS_REVISION);
26 
27 	unsigned long tmp = current;
28 	current += acpi_create_dmar_drhd_4k(current, 0, 0, IOMMU_BASE1);
29 	current += acpi_create_dmar_ds_pci(current, 0, 0x1b, 0);
30 	acpi_dmar_drhd_fixup(tmp, current);
31 
32 	if (stepping != STEPPING_B2 && igd_active) {
33 		tmp = current;
34 		current += acpi_create_dmar_drhd_4k(current, 0, 0, IOMMU_BASE2);
35 		current += acpi_create_dmar_ds_pci(current, 0, 0x2, 0);
36 		current += acpi_create_dmar_ds_pci(current, 0, 0x2, 1);
37 		acpi_dmar_drhd_fixup(tmp, current);
38 	}
39 
40 	if (me_active) {
41 		tmp = current;
42 		current += acpi_create_dmar_drhd_4k(current, 0, 0, IOMMU_BASE3);
43 		current += acpi_create_dmar_ds_pci(current, 0, 0x3, 0);
44 		current += acpi_create_dmar_ds_pci(current, 0, 0x3, 1);
45 		current += acpi_create_dmar_ds_pci(current, 0, 0x3, 2);
46 		current += acpi_create_dmar_ds_pci(current, 0, 0x3, 3);
47 		acpi_dmar_drhd_fixup(tmp, current);
48 	}
49 
50 	current += acpi_create_dmar_drhd_4k(current, DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE4);
51 
52 	/* TODO: reserve GTT for 0.2.0 and 0.2.1? */
53 	return current;
54 }
55 
northbridge_write_acpi_tables(const struct device * device,unsigned long start,struct acpi_rsdp * rsdp)56 unsigned long northbridge_write_acpi_tables(const struct device *device,
57 					    unsigned long start,
58 					    struct acpi_rsdp *rsdp)
59 {
60 	unsigned long current;
61 	acpi_dmar_t *dmar;
62 
63 	current = start;
64 
65 	printk(BIOS_DEBUG, "ACPI:     * DMAR\n");
66 	dmar = (acpi_dmar_t *)current;
67 	acpi_create_dmar(dmar, 0, acpi_fill_dmar);
68 	current += dmar->header.length;
69 	current = acpi_align_current(current);
70 	acpi_add_table(rsdp, dmar);
71 
72 	current = acpi_align_current(current);
73 
74 	printk(BIOS_DEBUG, "current = %lx\n", current);
75 
76 	return current;
77 }
78