Felix Held | 926887c | 2023-10-13 21:19:53 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Felix Held | 474c5d6 | 2024-01-09 16:56:56 +0100 | [diff] [blame] | 3 | #include <amdblocks/ioapic.h> |
Felix Held | 926887c | 2023-10-13 21:19:53 +0200 | [diff] [blame] | 4 | #include <amdblocks/data_fabric.h> |
| 5 | #include <amdblocks/root_complex.h> |
| 6 | #include <amdblocks/smn.h> |
| 7 | #include <arch/ioapic.h> |
| 8 | #include <console/console.h> |
| 9 | #include <device/device.h> |
| 10 | #include <types.h> |
| 11 | |
Felix Held | 2f58bbd | 2023-12-07 22:04:13 +0100 | [diff] [blame] | 12 | #include <vendorcode/amd/opensil/genoa_poc/opensil.h> |
| 13 | |
Felix Held | 926887c | 2023-10-13 21:19:53 +0200 | [diff] [blame] | 14 | #define IOHC_IOAPIC_BASE_ADDR_LO 0x2f0 |
| 15 | |
Felix Held | 2f58bbd | 2023-12-07 22:04:13 +0100 | [diff] [blame] | 16 | static void genoa_domain_read_resources(struct device *domain) |
| 17 | { |
| 18 | amd_pci_domain_read_resources(domain); |
| 19 | |
| 20 | // We only want to add the DRAM memory map once |
| 21 | if (domain->link_list->secondary == 0) { |
| 22 | /* 0x1000 is a large enough first index to be sure to not overlap with the |
| 23 | resources added by amd_pci_domain_read_resources */ |
| 24 | add_opensil_memmap(domain, 0x1000); |
| 25 | } |
| 26 | } |
| 27 | |
Felix Held | 926887c | 2023-10-13 21:19:53 +0200 | [diff] [blame] | 28 | static void genoa_domain_set_resources(struct device *domain) |
| 29 | { |
| 30 | if (domain->link_list->bridge_ctrl & PCI_BRIDGE_CTL_VGA) { |
| 31 | printk(BIOS_DEBUG, "Setting VGA decoding for domain 0x%x\n", |
| 32 | domain->path.domain.domain); |
| 33 | const union df_vga_en vga_en = { |
| 34 | .ve = 1, |
| 35 | .dst_fabric_id = get_iohc_fabric_id(domain), |
| 36 | }; |
| 37 | data_fabric_broadcast_write32(DF_VGA_EN, vga_en.raw); |
| 38 | } |
| 39 | |
| 40 | pci_domain_set_resources(domain); |
| 41 | |
| 42 | /* Enable IOAPIC memory decoding */ |
| 43 | struct resource *res = probe_resource(domain, IOMMU_IOAPIC_IDX); |
| 44 | if (res) { |
| 45 | const uint32_t iohc_misc_base = get_iohc_misc_smn_base(domain); |
| 46 | uint32_t ioapic_base = smn_read32(iohc_misc_base | IOHC_IOAPIC_BASE_ADDR_LO); |
| 47 | ioapic_base |= (1 << 0); |
| 48 | smn_write32(iohc_misc_base | IOHC_IOAPIC_BASE_ADDR_LO, ioapic_base); |
| 49 | } |
| 50 | } |
| 51 | |
Felix Held | dd032e0 | 2023-12-12 16:55:52 +0100 | [diff] [blame] | 52 | static void genoa_domain_init(struct device *domain) |
| 53 | { |
| 54 | struct resource *res = probe_resource(domain, IOMMU_IOAPIC_IDX); |
| 55 | if (!res) |
| 56 | return; |
| 57 | |
| 58 | register_new_ioapic((void *)(uintptr_t)res->base); |
| 59 | } |
| 60 | |
Felix Held | 020d4b6 | 2023-12-12 18:45:06 +0100 | [diff] [blame] | 61 | static const char *genoa_domain_acpi_name(const struct device *domain) |
| 62 | { |
| 63 | const char *domain_acpi_names[4] = { |
| 64 | "S0B0", |
| 65 | "S0B1", |
| 66 | "S0B2", |
| 67 | "S0B3", |
| 68 | }; |
| 69 | |
| 70 | if (domain->path.domain.domain < ARRAY_SIZE(domain_acpi_names)) |
| 71 | return domain_acpi_names[domain->path.domain.domain]; |
| 72 | |
| 73 | return NULL; |
| 74 | } |
| 75 | |
Felix Held | 926887c | 2023-10-13 21:19:53 +0200 | [diff] [blame] | 76 | struct device_operations genoa_pci_domain_ops = { |
Felix Held | 0fe8643 | 2023-12-12 19:59:14 +0100 | [diff] [blame] | 77 | .read_resources = genoa_domain_read_resources, |
| 78 | .set_resources = genoa_domain_set_resources, |
| 79 | .scan_bus = amd_pci_domain_scan_bus, |
Felix Held | dd032e0 | 2023-12-12 16:55:52 +0100 | [diff] [blame] | 80 | .init = genoa_domain_init, |
Felix Held | 020d4b6 | 2023-12-12 18:45:06 +0100 | [diff] [blame] | 81 | .acpi_name = genoa_domain_acpi_name, |
| 82 | .acpi_fill_ssdt = amd_pci_domain_fill_ssdt, |
Felix Held | 926887c | 2023-10-13 21:19:53 +0200 | [diff] [blame] | 83 | }; |