Debian Codegraph @

src/mainboard/emulation/qemu-sbsa/mainboard.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include "chip.h"
4 #include <acpi/acpigen.h>
5 #include <arch/mmu.h>
6 #include <bootmem.h>
7 #include <cbfs.h>
8 #include <device/device.h>
9 #include <commonlib/device_tree.h>
10 #include <mainboard/addressmap.h>
11 #include <stdint.h>
12 #include <symbols.h>
13
14 static size_t ram_size(void)
15 {
16 return (size_t)cbmem_top() - (uintptr_t)_dram;
17 }
18
19 static void mainboard_init(void *chip_info)
20 {
21 mmu_config_range(_dram, ram_size(), MA_MEM | MA_RW);
22 }
23
24 void smbios_cpu_get_core_counts(u16 *core_count, u16 *thread_count)
25 {
26 *core_count = 0;
27 struct device *dev = NULL;
28 while ((dev = dev_find_path(dev, DEVICE_PATH_GICC_V3)))
29 *core_count += 1;
30
31 *thread_count = 1;
32 }
33
34 static void qemu_aarch64_init(struct device *dev)
35 {
36 struct memory_info *mem_info;
37
38 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(*mem_info));
39 if (mem_info == NULL)
40 return;
41
42 memset(mem_info, 0, sizeof(*mem_info));
43
44 mem_info->ecc_type = MEMORY_ARRAY_ECC_UNKNOWN;
45 mem_info->max_capacity_mib = 0x800000; // Fixed at 8 TiB for qemu-sbsa
46 mem_info->number_of_devices = mem_info->dimm_cnt = 1;
47
48 mem_info->dimm[0].dimm_size = ram_size() / MiB;
49 mem_info->dimm[0].ddr_type = MEMORY_TYPE_DRAM;
50 mem_info->dimm[0].ddr_frequency = 0;
51 mem_info->dimm[0].channel_num = mem_info->dimm[0].dimm_num = 0;
52 mem_info->dimm[0].bank_locator = 0;
53
54 mem_info->dimm[0].bus_width = 0x03; // 64-bit, no parity
55 mem_info->dimm[0].vdd_voltage = 0;
56 mem_info->dimm[0].max_speed_mts = mem_info->dimm[0].configured_speed_mts = 0;
57 }
58
59 static unsigned long mb_write_acpi_tables(const struct device *dev, unsigned long current,
60 acpi_rsdp_t *rsdp)
61 {
62 printk(BIOS_DEBUG, "ACPI: * DBG2\n");
63 return acpi_pl011_write_dbg2_uart(rsdp, current, SBSA_UART_BASE, "\\_SB.COM0");
64 }
65
66
67 static void mainboard_enable(struct device *dev)
68 {
69 dev->ops->init = qemu_aarch64_init;
70 dev->ops->write_acpi_tables = mb_write_acpi_tables;
71 }
72
73
74 struct chip_operations mainboard_ops = {
75 .enable_dev = mainboard_enable,
76 .init = mainboard_init,
77 };
78
79 struct chip_operations mainboard_emulation_qemu_sbsa_ops = { };
80
81 static void qemu_aarch64_domain_read_resources(struct device *dev)
82 {
83 struct resource *res;
84 int index = 0;
85
86 /* Initialize the system-wide I/O space constraints. */
87 res = new_resource(dev, index++);
88 res->limit = 0xffffUL;
89 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED;
90
91 /* Initialize the system-wide memory resources constraints. */
92 res = new_resource(dev, index++);
93 res->base = SBSA_PCIE_MMIO_BASE;
94 res->limit = SBSA_PCIE_MMIO_LIMIT;
95 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED;
96
97 res = new_resource(dev, index++);
98 res->base = SBSA_PCIE_MMIO_HIGH_BASE;
99 res->limit = SBSA_PCIE_MMIO_HIGH_LIMIT;
100 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED;
101
102 mmio_range(dev, index++, SBSA_PCIE_ECAM_BASE, SBSA_PCIE_ECAM_SIZE);
103
104 ram_range(dev, index++, (uintptr_t)_dram, ram_size());
105
106 mmio_range(dev, index++, SBSA_FLASH_BASE, SBSA_FLASH_SIZE);
107 reserved_ram_range(dev, index++, SBSA_SECMEM_BASE, SBSA_SECMEM_SIZE);
108 }
109
110 struct device_operations qemu_aarch64_pci_domain_ops = {
111 .read_resources = qemu_aarch64_domain_read_resources,
112 .set_resources = pci_domain_set_resources,
113 .scan_bus = pci_host_bridge_scan_bus,
114 };
115
116 static void qemu_sbsa_fill_cpu_ssdt(const struct device *dev)
117 {
118 acpigen_write_processor_device(dev->path.gicc_v3.mpidr);
119 acpigen_write_processor_device_end();
120 }
121
122 struct device_operations qemu_sbsa_cpu_ops = {
123 .acpi_fill_ssdt = qemu_sbsa_fill_cpu_ssdt,
124 };
125
126 DECLARE_REGION(fdt_pointer)
127 static void qemu_aarch64_scan_bus(struct device *dev)
128 {
129 struct bus *bus = alloc_bus(dev);
130 uintptr_t fdt_blob = *(uintptr_t *)_fdt_pointer;
131 struct device_tree *tree;
132 struct device_tree_node *node;
133 char path[14];
134 u16 fdt_cpu_count = 0;
135 struct mainboard_emulation_qemu_sbsa_config *config = dev->chip_info;
136
137 tree = fdt_unflatten((void *)fdt_blob);
138 if (tree == NULL)
139 return;
140
141 snprintf(path, sizeof(path), "/cpus/cpu@%d", fdt_cpu_count);
142 while ((node = dt_find_node_by_path(tree, path, NULL, NULL, 0)) != NULL) {
143 struct device_tree_property *prop;
144 int64_t mpidr = -1;
145 list_for_each(prop, node->properties, list_node) {
146 if (!strcmp("reg", prop->prop.name)) {
147 mpidr = be64toh(*(uint64_t *)prop->prop.data);
148 break;
149 }
150 }
151 if (mpidr >= 0) {
152 struct device_path devpath = { .type = DEVICE_PATH_GICC_V3,
153 .gicc_v3 = { .mpidr = mpidr,
154 .vgic_mi = config->vgic_maintenance_interrupt,
155 .pi_gsiv = config->performance_interrupt_gsiv, },
156
157 };
158 struct device *cpu = alloc_dev(bus, &devpath);
159 assert(cpu);
160 cpu->ops = &qemu_sbsa_cpu_ops;
161 }
162 snprintf(path, sizeof(path), "/cpus/cpu@%d", ++fdt_cpu_count);
163 }
164 }
165
166 struct device_operations qemu_aarch64_cpu_ops = {
167 .scan_bus = qemu_aarch64_scan_bus,
168 };