blob: dc3745061dd716ce2a4278d03d5982d55e6c53a6 [file] [log] [blame]
Felix Held926887c2023-10-13 21:19:53 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2
Felix Held474c5d62024-01-09 16:56:56 +01003#include <amdblocks/ioapic.h>
Felix Held926887c2023-10-13 21:19:53 +02004#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 Held2f58bbd2023-12-07 22:04:13 +010012#include <vendorcode/amd/opensil/genoa_poc/opensil.h>
13
Felix Held926887c2023-10-13 21:19:53 +020014#define IOHC_IOAPIC_BASE_ADDR_LO 0x2f0
15
Felix Held2f58bbd2023-12-07 22:04:13 +010016static 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
Felix Held3b5b66d2024-01-11 22:26:18 +010021 if (domain->link_list->secondary == 0 && domain->link_list->segment_group == 0) {
Felix Held2f58bbd2023-12-07 22:04:13 +010022 /* 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 Held926887c2023-10-13 21:19:53 +020028static 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 Helddd032e02023-12-12 16:55:52 +010052static 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 Held020d4b62023-12-12 18:45:06 +010061static 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 Held926887c2023-10-13 21:19:53 +020076struct device_operations genoa_pci_domain_ops = {
Felix Held0fe86432023-12-12 19:59:14 +010077 .read_resources = genoa_domain_read_resources,
78 .set_resources = genoa_domain_set_resources,
79 .scan_bus = amd_pci_domain_scan_bus,
Felix Helddd032e02023-12-12 16:55:52 +010080 .init = genoa_domain_init,
Felix Held020d4b62023-12-12 18:45:06 +010081 .acpi_name = genoa_domain_acpi_name,
82 .acpi_fill_ssdt = amd_pci_domain_fill_ssdt,
Felix Held926887c2023-10-13 21:19:53 +020083};