Arthur Heymans | 3df6cc9 | 2023-06-27 16:44:59 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi.h> |
| 4 | |
| 5 | static int acpi_create_madt_one_gicc_v3(acpi_madt_gicc_t *gicc, u32 acpi_uid, u32 pi_gsiv, |
| 6 | uint32_t vgic_mi, uint64_t mpidr) |
| 7 | { |
| 8 | memset(gicc, 0, sizeof(acpi_madt_gicc_t)); |
| 9 | gicc->type = GICC; |
| 10 | gicc->length = sizeof(acpi_madt_gicc_t); |
| 11 | gicc->reserved = 0; |
| 12 | gicc->cpu_interface_number = 0; /* V3, no compat mode */ |
| 13 | gicc->acpi_processor_uid = acpi_uid; |
| 14 | gicc->flags.enabled = 1; |
Naresh Solanki | 75f0b60 | 2023-09-25 13:59:25 +0200 | [diff] [blame] | 15 | gicc->parking_protocol_version = 0; /* Assume PSCI exclusively */ |
Arthur Heymans | 3df6cc9 | 2023-06-27 16:44:59 +0200 | [diff] [blame] | 16 | gicc->performance_interrupt_gsiv = pi_gsiv; |
| 17 | gicc->parked_address = 0; |
| 18 | gicc->physical_base_address = 0; /* V3, no compat mode */ |
| 19 | gicc->vgic_maintenance_interrupt = vgic_mi; |
| 20 | gicc->gicr_base_address = 0; /* ignored by OSPM if GICR is present */ |
| 21 | gicc->processor_power_efficiency_class = 0; /* Ignore for now */ |
| 22 | /* For platforms implementing GIC V3 the format must be: |
| 23 | * Bits [63:40] Must be zero |
| 24 | * Bits [39:32] Aff3 : Match Aff3 of target processor MPIDR |
| 25 | * Bits [31:24] Must be zero |
| 26 | * Bits [23:16] Aff2 : Match Aff2 of target processor MPIDR |
| 27 | * Bits [15:8] Aff1 : Match Aff1 of target processor MPIDR |
| 28 | * Bits [7:0] Aff0 : Match Aff0 of target processor MPIDR |
| 29 | */ |
| 30 | gicc->mpidr = mpidr & 0xff00fffffful; |
| 31 | |
| 32 | return gicc->length; |
| 33 | } |
| 34 | |
| 35 | static unsigned long acpi_create_madt_giccs_v3(unsigned long current) |
| 36 | { |
| 37 | // Loop over CPUs GIC |
| 38 | uint32_t acpi_id = 0; |
| 39 | for (struct device *dev = dev_find_path(NULL, DEVICE_PATH_GICC_V3); dev; |
| 40 | dev = dev_find_path(dev, DEVICE_PATH_GICC_V3)) { |
| 41 | acpi_madt_gicc_t *gicc = (acpi_madt_gicc_t *)current; |
| 42 | current += acpi_create_madt_one_gicc_v3(gicc, acpi_id++, |
| 43 | dev->path.gicc_v3.pi_gsiv, |
| 44 | dev->path.gicc_v3.vgic_mi, |
| 45 | dev->path.gicc_v3.mpidr); |
| 46 | } |
| 47 | |
| 48 | return current; |
| 49 | } |
| 50 | |
| 51 | static unsigned long acpi_create_madt_gicd_v3(unsigned long current) |
| 52 | { |
| 53 | acpi_madt_gicd_t *gicd = (acpi_madt_gicd_t *)current; |
| 54 | memset(gicd, 0, sizeof(acpi_madt_gicd_t)); |
| 55 | gicd->type = GICD; |
| 56 | gicd->length = sizeof(acpi_madt_gicd_t); |
| 57 | gicd->physical_base_address = platform_get_gicd_base(); |
| 58 | gicd->system_vector_base = 0; |
| 59 | gicd->gic_version = 3; |
| 60 | |
| 61 | return current + gicd->length; |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * The redistributor in GICv3 has two 64KB frames per CPU; in |
| 66 | * GICv4 it has four 64KB frames per CPU. |
| 67 | */ |
| 68 | #define GICV3_REDIST_SIZE 0x20000 |
| 69 | #define GICV4_REDIST_SIZE 0x40000 |
| 70 | static unsigned long acpi_create_madt_gicr_v3(unsigned long current) |
| 71 | { |
| 72 | acpi_madt_gicr_t *gicr = (acpi_madt_gicr_t *)current; |
| 73 | memset(gicr, 0, sizeof(acpi_madt_gicr_t)); |
| 74 | gicr->type = GICR; |
| 75 | gicr->length = sizeof(acpi_madt_gicr_t); |
| 76 | gicr->discovery_range_base_address = platform_get_gicr_base(); |
| 77 | gicr->discovery_range_length = GICV3_REDIST_SIZE * CONFIG_MAX_CPUS; |
| 78 | |
| 79 | return current + gicr->length; |
| 80 | } |
| 81 | |
Naresh Solanki | 1fe1904 | 2023-09-25 14:24:34 +0200 | [diff] [blame] | 82 | __weak int platform_get_gic_its(uintptr_t **base) |
| 83 | { |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static unsigned long acpi_create_madt_gic_its_v3(unsigned long current) |
| 88 | { |
| 89 | int i, its_count; |
| 90 | uintptr_t *its_base; |
| 91 | |
| 92 | its_count = platform_get_gic_its(&its_base); |
| 93 | |
| 94 | for (i = 0; i < its_count; i++) { |
| 95 | acpi_madt_gic_its_t *gic_its = (acpi_madt_gic_its_t *)current; |
| 96 | memset(gic_its, 0, sizeof(acpi_madt_gic_its_t)); |
| 97 | gic_its->type = GIC_ITS; |
| 98 | gic_its->gic_its_id = i; |
| 99 | gic_its->physical_base_address = its_base[i]; |
| 100 | gic_its->length = sizeof(acpi_madt_gic_its_t); |
| 101 | |
| 102 | current = current + gic_its->length; |
| 103 | } |
| 104 | return current; |
| 105 | } |
| 106 | |
Arthur Heymans | 3df6cc9 | 2023-06-27 16:44:59 +0200 | [diff] [blame] | 107 | unsigned long acpi_arch_fill_madt(acpi_madt_t *madt, unsigned long current) |
| 108 | { |
| 109 | current = acpi_create_madt_giccs_v3(current); |
| 110 | current = acpi_create_madt_gicd_v3(current); |
| 111 | current = acpi_create_madt_gicr_v3(current); |
Naresh Solanki | 1fe1904 | 2023-09-25 14:24:34 +0200 | [diff] [blame] | 112 | current = acpi_create_madt_gic_its_v3(current); |
Arthur Heymans | 3df6cc9 | 2023-06-27 16:44:59 +0200 | [diff] [blame] | 113 | |
| 114 | return current; |
| 115 | } |