Patrick Rudolph | cb42bc8 | 2024-10-23 15:20:08 +0200 | [diff] [blame] | 1 | // 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> |
Patrick Rudolph | cb42bc8 | 2024-10-23 15:20:08 +0200 | [diff] [blame] | 13 | #include <dm/device.h> |
Patrick Rudolph | cd5de91 | 2025-03-20 13:51:58 +0100 | [diff] [blame] | 14 | #include <dm/read.h> |
| 15 | #include <dm/uclass.h> |
Patrick Rudolph | cb42bc8 | 2024-10-23 15:20:08 +0200 | [diff] [blame] | 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 | |
| 45 | int acpi_fill_iort(struct acpi_ctx *ctx) |
| 46 | { |
| 47 | u32 its_offset, smmu_offset; |
Patrick Rudolph | cd5de91 | 2025-03-20 13:51:58 +0100 | [diff] [blame] | 48 | struct udevice *dev; |
| 49 | int ret; |
Patrick Rudolph | cb42bc8 | 2024-10-23 15:20:08 +0200 | [diff] [blame] | 50 | |
Patrick Rudolph | cd5de91 | 2025-03-20 13:51:58 +0100 | [diff] [blame] | 51 | ret = uclass_get_device_by_driver(UCLASS_IRQ, |
| 52 | DM_DRIVER_GET(arm_gic_v3_its), &dev); |
| 53 | if (ret) { |
| 54 | pr_err("%s: failed to get %s irq device\n", __func__, |
| 55 | DM_DRIVER_GET(arm_gic_v3_its)->name); |
| 56 | return ret; |
| 57 | } |
Patrick Rudolph | cb42bc8 | 2024-10-23 15:20:08 +0200 | [diff] [blame] | 58 | |
Patrick Rudolph | cd5de91 | 2025-03-20 13:51:58 +0100 | [diff] [blame] | 59 | u32 identifiers[] = { dev_seq(dev) }; |
Patrick Rudolph | cb42bc8 | 2024-10-23 15:20:08 +0200 | [diff] [blame] | 60 | |
| 61 | its_offset = acpi_iort_add_its_group(ctx, ARRAY_SIZE(identifiers), |
| 62 | identifiers); |
| 63 | |
| 64 | struct acpi_iort_id_mapping map_smmu[] = {{ |
| 65 | 0, 0xffff, 0, its_offset, 0 |
| 66 | }}; |
| 67 | |
| 68 | smmu_offset = acpi_iort_add_smmu_v3(ctx, |
| 69 | SBSA_SMMU_BASE_ADDR, // Base address |
| 70 | ACPI_IORT_SMMU_V3_COHACC_OVERRIDE, // Flags |
| 71 | 0, // VATOS address |
| 72 | 0, // SMMUv3 Model |
| 73 | 74, // Event |
| 74 | 75, // Pri |
| 75 | 77, // Gerror |
| 76 | 76, // Sync |
| 77 | 0, // Proximity domain |
| 78 | 1, // DevIDMappingIndex |
| 79 | ARRAY_SIZE(map_smmu), |
| 80 | map_smmu); |
| 81 | |
| 82 | struct acpi_iort_id_mapping map_rc[] = {{ |
| 83 | 0, 0xffff, 0, smmu_offset, 0 |
| 84 | }}; |
| 85 | |
| 86 | acpi_iort_add_rc(ctx, |
| 87 | BIT(0) | BIT(56), // CacheCoherent + CPM |
| 88 | 0, // AtsAttribute |
| 89 | 0, // PciSegmentNumber |
| 90 | 64, // MemoryAddressSizeLimit |
| 91 | ARRAY_SIZE(map_rc), |
| 92 | map_rc); |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | void acpi_fill_fadt(struct acpi_fadt *fadt) |
| 97 | { |
| 98 | fadt->flags = ACPI_FADT_HW_REDUCED_ACPI | ACPI_FADT_LOW_PWR_IDLE_S0; |
| 99 | fadt->preferred_pm_profile = ACPI_PM_PERFORMANCE_SERVER; |
| 100 | fadt->arm_boot_arch = ACPI_ARM_PSCI_COMPLIANT; |
| 101 | } |
| 102 | |
| 103 | int acpi_fill_mcfg(struct acpi_ctx *ctx) |
| 104 | { |
| 105 | size_t size; |
| 106 | |
| 107 | /* PCI Segment Group 0, Start Bus Number 0, End Bus Number is 255 */ |
| 108 | size = acpi_create_mcfg_mmconfig((void *)ctx->current, |
| 109 | SBSA_PCIE_ECAM_BASE_ADDR, 0, 0, 255); |
| 110 | acpi_inc(ctx, size); |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static int sbsa_write_gtdt(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 116 | { |
| 117 | struct acpi_table_header *header; |
| 118 | struct acpi_gtdt *gtdt; |
| 119 | |
| 120 | gtdt = ctx->current; |
| 121 | header = >dt->header; |
| 122 | |
| 123 | memset(gtdt, '\0', sizeof(struct acpi_gtdt)); |
| 124 | |
| 125 | acpi_fill_header(header, "GTDT"); |
| 126 | header->length = sizeof(struct acpi_gtdt); |
| 127 | header->revision = acpi_get_table_revision(ACPITAB_GTDT); |
| 128 | |
| 129 | gtdt->cnt_ctrl_base = 0xFFFFFFFFFFFFFFFF; |
| 130 | gtdt->sec_el1_gsiv = 29; |
| 131 | gtdt->sec_el1_flags = GTDT_FLAG_INT_ACTIVE_LOW; |
| 132 | gtdt->el1_gsiv = 30; |
| 133 | gtdt->el1_flags = GTDT_FLAG_INT_ACTIVE_LOW; |
| 134 | gtdt->virt_el1_gsiv = 27; |
| 135 | gtdt->virt_el1_flags = GTDT_FLAG_INT_ACTIVE_LOW; |
| 136 | gtdt->el2_gsiv = 26; |
| 137 | gtdt->el2_flags = GTDT_FLAG_INT_ACTIVE_LOW; |
| 138 | gtdt->cnt_read_base = 0xffffffffffffffff; |
| 139 | |
| 140 | // FIXME: VirtualPL2Timer |
Heinrich Schuchardt | 198c422 | 2025-03-22 00:21:19 +0100 | [diff] [blame] | 141 | acpi_update_checksum(header); |
Patrick Rudolph | cb42bc8 | 2024-10-23 15:20:08 +0200 | [diff] [blame] | 142 | |
| 143 | acpi_add_table(ctx, gtdt); |
| 144 | |
| 145 | acpi_inc(ctx, sizeof(struct acpi_gtdt)); |
| 146 | |
| 147 | return 0; |
| 148 | }; |
| 149 | |
| 150 | ACPI_WRITER(5gtdt, "GTDT", sbsa_write_gtdt, 0); |
| 151 | |
| 152 | static int acpi_write_pptt(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 153 | { |
| 154 | struct acpi_table_header *header; |
| 155 | int cluster_offset, l2_offset; |
| 156 | u32 offsets[2]; |
| 157 | |
| 158 | header = ctx->current; |
| 159 | ctx->tab_start = ctx->current; |
| 160 | |
| 161 | memset(header, '\0', sizeof(struct acpi_table_header)); |
| 162 | |
| 163 | acpi_fill_header(header, "PPTT"); |
| 164 | header->revision = acpi_get_table_revision(ACPITAB_PPTT); |
| 165 | acpi_inc(ctx, sizeof(*header)); |
| 166 | |
| 167 | cluster_offset = acpi_pptt_add_proc(ctx, ACPI_PPTT_PHYSICAL_PACKAGE | |
| 168 | ACPI_PPTT_CHILDREN_IDENTICAL, |
| 169 | 0, 0, 0, NULL); |
| 170 | |
| 171 | l2_offset = acpi_pptt_add_cache(ctx, ACPI_PPTT_ALL_VALID, 0, L2_SIZE, |
| 172 | L2_SETS, L2_WAYS, L2_ATTRIBUTES, 64); |
| 173 | |
| 174 | offsets[0] = acpi_pptt_add_cache(ctx, ACPI_PPTT_ALL_VALID, l2_offset, |
| 175 | L1D_SIZE, L1D_SETS, L1D_WAYS, |
| 176 | L1D_ATTRIBUTES, 64); |
| 177 | |
| 178 | offsets[1] = acpi_pptt_add_cache(ctx, ACPI_PPTT_ALL_BUT_WRITE_POL, |
| 179 | l2_offset, L1I_SIZE, L1I_SETS, |
| 180 | L1I_WAYS, L1I_ATTRIBUTES, 64); |
| 181 | |
| 182 | for (int i = 0; i < uclass_id_count(UCLASS_CPU); i++) { |
| 183 | acpi_pptt_add_proc(ctx, ACPI_PPTT_CHILDREN_IDENTICAL | |
| 184 | ACPI_PPTT_NODE_IS_LEAF | ACPI_PPTT_PROC_ID_VALID, |
| 185 | cluster_offset, i, 2, offsets); |
| 186 | } |
| 187 | |
| 188 | header->length = ctx->current - ctx->tab_start; |
Heinrich Schuchardt | 198c422 | 2025-03-22 00:21:19 +0100 | [diff] [blame] | 189 | acpi_update_checksum(header); |
Patrick Rudolph | cb42bc8 | 2024-10-23 15:20:08 +0200 | [diff] [blame] | 190 | |
| 191 | acpi_inc(ctx, header->length); |
| 192 | acpi_add_table(ctx, header); |
| 193 | |
| 194 | return 0; |
| 195 | }; |
| 196 | |
| 197 | ACPI_WRITER(5pptt, "PPTT", acpi_write_pptt, 0); |