blob: ba85e08fc7d9750e313a02806fe22a292ef65d6a [file] [log] [blame]
Patrick Rudolphcb42bc82024-10-23 15:20:08 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2024 9elements GmbH
4 */
5
6#include <cpu.h>
7#include <tables_csum.h>
8#include <string.h>
9#include <acpi/acpi_table.h>
10#include <asm/acpi_table.h>
11#include <asm/armv8/sec_firmware.h>
12#include <configs/qemu-sbsa.h>
13#include <dm/uclass.h>
14#include <dm/device.h>
15#include "qemu-sbsa.h"
16
17#define SBSAQEMU_MADT_GIC_VBASE 0x2c020000
18#define SBSAQEMU_MADT_GIC_HBASE 0x2c010000
19#define SBSAQEMU_MADT_GIC_PMU_IRQ 23
20
21#define SBSA_PLATFORM_WATCHDOG_COUNT 1
22#define SBSA_PLATFORM_TIMER_COUNT (SBSA_PLATFORM_WATCHDOG_COUNT)
23
24#define L2_ATTRIBUTES (ACPI_PPTT_READ_ALLOC | ACPI_PPTT_WRITE_ALLOC | \
25 (ACPI_PPTT_CACHE_TYPE_UNIFIED << \
26 ACPI_PPTT_CACHE_TYPE_SHIFT))
27#define L2_SIZE 0x80000
28#define L2_SETS 0x400
29#define L2_WAYS 8
30
31#define L1D_ATTRIBUTES (ACPI_PPTT_READ_ALLOC | ACPI_PPTT_WRITE_ALLOC | \
32 (ACPI_PPTT_CACHE_TYPE_DATA << \
33 ACPI_PPTT_CACHE_TYPE_SHIFT))
34#define L1D_SIZE 0x8000
35#define L1D_SETS 0x100
36#define L1D_WAYS 2
37
38#define L1I_ATTRIBUTES (ACPI_PPTT_READ_ALLOC | \
39 (ACPI_PPTT_CACHE_TYPE_INSTR << \
40 ACPI_PPTT_CACHE_TYPE_SHIFT))
41#define L1I_SIZE 0x8000
42#define L1I_SETS 0x100
43#define L1I_WAYS 2
44
45int acpi_fill_iort(struct acpi_ctx *ctx)
46{
47 u32 its_offset, smmu_offset;
48 u64 gic_its_base = 0;
49
50 smc_get_gic_its_base(&gic_its_base);
51 if (gic_its_base == 0)
52 return 0;
53
54 u32 identifiers[] = { 0 };
55
56 its_offset = acpi_iort_add_its_group(ctx, ARRAY_SIZE(identifiers),
57 identifiers);
58
59 struct acpi_iort_id_mapping map_smmu[] = {{
60 0, 0xffff, 0, its_offset, 0
61 }};
62
63 smmu_offset = acpi_iort_add_smmu_v3(ctx,
64 SBSA_SMMU_BASE_ADDR, // Base address
65 ACPI_IORT_SMMU_V3_COHACC_OVERRIDE, // Flags
66 0, // VATOS address
67 0, // SMMUv3 Model
68 74, // Event
69 75, // Pri
70 77, // Gerror
71 76, // Sync
72 0, // Proximity domain
73 1, // DevIDMappingIndex
74 ARRAY_SIZE(map_smmu),
75 map_smmu);
76
77 struct acpi_iort_id_mapping map_rc[] = {{
78 0, 0xffff, 0, smmu_offset, 0
79 }};
80
81 acpi_iort_add_rc(ctx,
82 BIT(0) | BIT(56), // CacheCoherent + CPM
83 0, // AtsAttribute
84 0, // PciSegmentNumber
85 64, // MemoryAddressSizeLimit
86 ARRAY_SIZE(map_rc),
87 map_rc);
88 return 0;
89}
90
91void acpi_fill_fadt(struct acpi_fadt *fadt)
92{
93 fadt->flags = ACPI_FADT_HW_REDUCED_ACPI | ACPI_FADT_LOW_PWR_IDLE_S0;
94 fadt->preferred_pm_profile = ACPI_PM_PERFORMANCE_SERVER;
95 fadt->arm_boot_arch = ACPI_ARM_PSCI_COMPLIANT;
96}
97
98int acpi_fill_mcfg(struct acpi_ctx *ctx)
99{
100 size_t size;
101
102 /* PCI Segment Group 0, Start Bus Number 0, End Bus Number is 255 */
103 size = acpi_create_mcfg_mmconfig((void *)ctx->current,
104 SBSA_PCIE_ECAM_BASE_ADDR, 0, 0, 255);
105 acpi_inc(ctx, size);
106
107 return 0;
108}
109
110static int sbsa_write_gtdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
111{
112 struct acpi_table_header *header;
113 struct acpi_gtdt *gtdt;
114
115 gtdt = ctx->current;
116 header = &gtdt->header;
117
118 memset(gtdt, '\0', sizeof(struct acpi_gtdt));
119
120 acpi_fill_header(header, "GTDT");
121 header->length = sizeof(struct acpi_gtdt);
122 header->revision = acpi_get_table_revision(ACPITAB_GTDT);
123
124 gtdt->cnt_ctrl_base = 0xFFFFFFFFFFFFFFFF;
125 gtdt->sec_el1_gsiv = 29;
126 gtdt->sec_el1_flags = GTDT_FLAG_INT_ACTIVE_LOW;
127 gtdt->el1_gsiv = 30;
128 gtdt->el1_flags = GTDT_FLAG_INT_ACTIVE_LOW;
129 gtdt->virt_el1_gsiv = 27;
130 gtdt->virt_el1_flags = GTDT_FLAG_INT_ACTIVE_LOW;
131 gtdt->el2_gsiv = 26;
132 gtdt->el2_flags = GTDT_FLAG_INT_ACTIVE_LOW;
133 gtdt->cnt_read_base = 0xffffffffffffffff;
134
135 // FIXME: VirtualPL2Timer
136 header->checksum = table_compute_checksum(header, header->length);
137
138 acpi_add_table(ctx, gtdt);
139
140 acpi_inc(ctx, sizeof(struct acpi_gtdt));
141
142 return 0;
143};
144
145ACPI_WRITER(5gtdt, "GTDT", sbsa_write_gtdt, 0);
146
147static int acpi_write_pptt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
148{
149 struct acpi_table_header *header;
150 int cluster_offset, l2_offset;
151 u32 offsets[2];
152
153 header = ctx->current;
154 ctx->tab_start = ctx->current;
155
156 memset(header, '\0', sizeof(struct acpi_table_header));
157
158 acpi_fill_header(header, "PPTT");
159 header->revision = acpi_get_table_revision(ACPITAB_PPTT);
160 acpi_inc(ctx, sizeof(*header));
161
162 cluster_offset = acpi_pptt_add_proc(ctx, ACPI_PPTT_PHYSICAL_PACKAGE |
163 ACPI_PPTT_CHILDREN_IDENTICAL,
164 0, 0, 0, NULL);
165
166 l2_offset = acpi_pptt_add_cache(ctx, ACPI_PPTT_ALL_VALID, 0, L2_SIZE,
167 L2_SETS, L2_WAYS, L2_ATTRIBUTES, 64);
168
169 offsets[0] = acpi_pptt_add_cache(ctx, ACPI_PPTT_ALL_VALID, l2_offset,
170 L1D_SIZE, L1D_SETS, L1D_WAYS,
171 L1D_ATTRIBUTES, 64);
172
173 offsets[1] = acpi_pptt_add_cache(ctx, ACPI_PPTT_ALL_BUT_WRITE_POL,
174 l2_offset, L1I_SIZE, L1I_SETS,
175 L1I_WAYS, L1I_ATTRIBUTES, 64);
176
177 for (int i = 0; i < uclass_id_count(UCLASS_CPU); i++) {
178 acpi_pptt_add_proc(ctx, ACPI_PPTT_CHILDREN_IDENTICAL |
179 ACPI_PPTT_NODE_IS_LEAF | ACPI_PPTT_PROC_ID_VALID,
180 cluster_offset, i, 2, offsets);
181 }
182
183 header->length = ctx->current - ctx->tab_start;
184 header->checksum = table_compute_checksum(header, header->length);
185
186 acpi_inc(ctx, header->length);
187 acpi_add_table(ctx, header);
188
189 return 0;
190};
191
192ACPI_WRITER(5pptt, "PPTT", acpi_write_pptt, 0);