Patrick Rudolph | bdc7474 | 2024-10-23 15:20:11 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * (C) Copyright 2024 9elements GmbH |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | */ |
| 8 | |
| 9 | #include <string.h> |
| 10 | #include <tables_csum.h> |
| 11 | #include <acpi/acpi_table.h> |
| 12 | #include <asm/acpi_table.h> |
| 13 | #include <asm/armv8/sec_firmware.h> |
| 14 | #include <asm/arch/acpi/bcm2711.h> |
| 15 | #include <dm/uclass.h> |
| 16 | |
| 17 | void acpi_fill_fadt(struct acpi_fadt *fadt) |
| 18 | { |
| 19 | fadt->flags = ACPI_FADT_HW_REDUCED_ACPI | ACPI_FADT_LOW_PWR_IDLE_S0; |
| 20 | |
| 21 | if (CONFIG_IS_ENABLED(SEC_FIRMWARE_ARMV8_PSCI) && |
| 22 | sec_firmware_support_psci_version() != PSCI_INVALID_VER) |
| 23 | fadt->arm_boot_arch = ACPI_ARM_PSCI_COMPLIANT; |
| 24 | } |
| 25 | |
| 26 | #define L3_ATTRIBUTES (ACPI_PPTT_READ_ALLOC | ACPI_PPTT_WRITE_ALLOC | \ |
| 27 | (ACPI_PPTT_CACHE_TYPE_UNIFIED << \ |
| 28 | ACPI_PPTT_CACHE_TYPE_SHIFT)) |
| 29 | #define L3_SIZE 0x100000 |
| 30 | #define L3_SETS 0x400 |
| 31 | #define L3_WAYS 0x10 |
| 32 | |
| 33 | #define L1D_ATTRIBUTES (ACPI_PPTT_READ_ALLOC | ACPI_PPTT_WRITE_ALLOC | \ |
| 34 | (ACPI_PPTT_CACHE_TYPE_DATA << \ |
| 35 | ACPI_PPTT_CACHE_TYPE_SHIFT)) |
| 36 | #define L1D_SIZE 0x8000 |
| 37 | #define L1D_SETS 0x100 |
| 38 | #define L1D_WAYS 2 |
| 39 | |
| 40 | #define L1I_ATTRIBUTES (ACPI_PPTT_READ_ALLOC | \ |
| 41 | (ACPI_PPTT_CACHE_TYPE_INSTR << \ |
| 42 | ACPI_PPTT_CACHE_TYPE_SHIFT)) |
| 43 | #define L1I_SIZE 0xc000 |
| 44 | #define L1I_SETS 0x100 |
| 45 | #define L1I_WAYS 3 |
| 46 | |
| 47 | static int acpi_write_pptt(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 48 | { |
| 49 | struct acpi_table_header *header; |
| 50 | int cluster_offset, l3_offset; |
| 51 | u32 offsets[2]; |
| 52 | |
| 53 | header = ctx->current; |
| 54 | ctx->tab_start = ctx->current; |
| 55 | |
| 56 | memset(header, '\0', sizeof(struct acpi_table_header)); |
| 57 | |
| 58 | acpi_fill_header(header, "PPTT"); |
| 59 | header->revision = acpi_get_table_revision(ACPITAB_PPTT); |
| 60 | acpi_inc(ctx, sizeof(*header)); |
| 61 | |
| 62 | l3_offset = acpi_pptt_add_cache(ctx, ACPI_PPTT_ALL_VALID, 0, L3_SIZE, |
| 63 | L3_SETS, L3_WAYS, L3_ATTRIBUTES, 64); |
| 64 | |
| 65 | cluster_offset = acpi_pptt_add_proc(ctx, ACPI_PPTT_PHYSICAL_PACKAGE | |
| 66 | ACPI_PPTT_CHILDREN_IDENTICAL, |
| 67 | 0, 0, 1, &l3_offset); |
| 68 | |
| 69 | offsets[0] = acpi_pptt_add_cache(ctx, ACPI_PPTT_ALL_VALID, 0, L1D_SIZE, |
| 70 | L1D_SETS, L1D_WAYS, L1D_ATTRIBUTES, 64); |
| 71 | |
| 72 | offsets[1] = acpi_pptt_add_cache(ctx, ACPI_PPTT_ALL_BUT_WRITE_POL, 0, |
| 73 | L1I_SIZE, L1I_SETS, L1I_WAYS, |
| 74 | L1I_ATTRIBUTES, 64); |
| 75 | |
| 76 | for (int i = 0; i < uclass_id_count(UCLASS_CPU); i++) { |
| 77 | acpi_pptt_add_proc(ctx, ACPI_PPTT_CHILDREN_IDENTICAL | |
| 78 | ACPI_PPTT_NODE_IS_LEAF | |
| 79 | ACPI_PPTT_PROC_ID_VALID, |
| 80 | cluster_offset, i, 2, offsets); |
| 81 | } |
| 82 | |
| 83 | header->length = ctx->current - ctx->tab_start; |
| 84 | header->checksum = table_compute_checksum(header, header->length); |
| 85 | |
| 86 | acpi_inc(ctx, header->length); |
| 87 | acpi_add_table(ctx, header); |
| 88 | |
| 89 | return 0; |
| 90 | }; |
| 91 | |
| 92 | ACPI_WRITER(5pptt, "PPTT", acpi_write_pptt, 0); |
| 93 | |
| 94 | static int rpi_write_gtdt(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 95 | { |
| 96 | struct acpi_table_header *header; |
| 97 | struct acpi_gtdt *gtdt; |
| 98 | |
| 99 | gtdt = ctx->current; |
| 100 | header = >dt->header; |
| 101 | |
| 102 | memset(gtdt, '\0', sizeof(struct acpi_gtdt)); |
| 103 | |
| 104 | acpi_fill_header(header, "GTDT"); |
| 105 | header->length = sizeof(struct acpi_gtdt); |
| 106 | header->revision = acpi_get_table_revision(ACPITAB_GTDT); |
| 107 | |
| 108 | gtdt->cnt_ctrl_base = BCM2711_ARM_LOCAL_BASE_ADDRESS + 0x1c; |
| 109 | gtdt->sec_el1_gsiv = 29; |
| 110 | gtdt->sec_el1_flags = GTDT_FLAG_INT_ACTIVE_LOW; |
| 111 | gtdt->el1_gsiv = 30; |
| 112 | gtdt->el1_flags = GTDT_FLAG_INT_ACTIVE_LOW; |
| 113 | gtdt->virt_el1_gsiv = 27; |
| 114 | gtdt->virt_el1_flags = GTDT_FLAG_INT_ACTIVE_LOW; |
| 115 | gtdt->el2_gsiv = 26; |
| 116 | gtdt->el2_flags = GTDT_FLAG_INT_ACTIVE_LOW; |
| 117 | gtdt->cnt_read_base = 0xffffffffffffffff; |
| 118 | |
| 119 | header->checksum = table_compute_checksum(header, header->length); |
| 120 | |
| 121 | acpi_add_table(ctx, gtdt); |
| 122 | |
| 123 | acpi_inc(ctx, sizeof(struct acpi_gtdt)); |
| 124 | |
| 125 | return 0; |
| 126 | }; |
| 127 | |
| 128 | ACPI_WRITER(5gtdt, "GTDT", rpi_write_gtdt, 0); |