diff --git a/u-boot/arch/arm/include/asm/acpi_table.h b/u-boot/arch/arm/include/asm/acpi_table.h index 930e857edeb..7d48557b96d 100644 --- a/u-boot/arch/arm/include/asm/acpi_table.h +++ b/u-boot/arch/arm/include/asm/acpi_table.h @@ -1,15 +1,18 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright 2019 Google LLC - */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef __ASM_ACPI_TABLE_H__ #define __ASM_ACPI_TABLE_H__ #ifndef __ACPI__ -ulong write_acpi_tables(ulong start); +void acpi_write_madt_gicc(struct acpi_madr_gicc *gicc, uint cpu_num, + uint perf_gsiv, ulong phys_base, ulong gicv, + ulong gich, uint vgic_maint_irq, ulong mpidr, + uint efficiency); -#endif +void acpi_write_madt_gicd(struct acpi_madr_gicd *gicd, uint gic_id, + ulong phys_base, uint gic_version); + +#endif /* !__ACPI__ */ #endif /* __ASM_ACPI_TABLE_H__ */ diff --git a/u-boot/arch/arm/lib/Makefile b/u-boot/arch/arm/lib/Makefile index 67275fba616..a7efed6771d 100644 --- a/u-boot/arch/arm/lib/Makefile +++ b/u-boot/arch/arm/lib/Makefile @@ -86,6 +86,7 @@ obj-y += psci-dt.o obj-$(CONFIG_DEBUG_LL) += debug.o obj-$(CONFIG_BLOBLIST) += xferlist.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o # For EABI conformant tool chains, provide eabi_compat() ifneq (,$(findstring -mabi=aapcs-linux,$(PLATFORM_CPPFLAGS))) diff --git a/u-boot/arch/arm/lib/acpi_table.c b/u-boot/arch/arm/lib/acpi_table.c new file mode 100644 index 00000000000..ff2d611ba3f --- /dev/null +++ b/u-boot/arch/arm/lib/acpi_table.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Based on acpi.c from coreboot + * + * Copyright (C) 2024 9elements GmbH + */ + +#define LOG_CATEGORY LOGC_ACPI + +#include +#include +#include +#include +#include + +void acpi_write_madt_gicc(struct acpi_madr_gicc *gicc, uint cpu_num, + uint perf_gsiv, ulong phys_base, ulong gicv, + ulong gich, uint vgic_maint_irq, ulong mpidr, + uint efficiency) +{ + memset(gicc, '\0', sizeof(struct acpi_madr_gicc)); + gicc->type = ACPI_APIC_GICC; + gicc->length = sizeof(struct acpi_madr_gicc); + gicc->cpu_if_num = cpu_num; + gicc->processor_id = cpu_num; + gicc->flags = ACPI_MADRF_ENABLED; + gicc->perf_gsiv = perf_gsiv; + gicc->phys_base = phys_base; + gicc->gicv = gicv; + gicc->gich = gich; + gicc->vgic_maint_irq = vgic_maint_irq; + gicc->mpidr = mpidr; + gicc->efficiency = efficiency; +} + +void acpi_write_madt_gicd(struct acpi_madr_gicd *gicd, uint gic_id, + ulong phys_base, uint gic_version) +{ + memset(gicd, '\0', sizeof(struct acpi_madr_gicd)); + gicd->type = ACPI_APIC_GICD; + gicd->length = sizeof(struct acpi_madr_gicd); + gicd->gic_id = gic_id; + gicd->phys_base = phys_base; + gicd->gic_version = gic_version; +} diff --git a/u-boot/arch/arm/mach-bcm283x/Makefile b/u-boot/arch/arm/mach-bcm283x/Makefile index 7cd068832f3..2e64740ea27 100644 --- a/u-boot/arch/arm/mach-bcm283x/Makefile +++ b/u-boot/arch/arm/mach-bcm283x/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_BCM2835) += lowlevel_init.o obj-y += init.o reset.o mbox.o msg.o phys2bus.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o diff --git a/u-boot/arch/arm/mach-bcm283x/acpi.c b/u-boot/arch/arm/mach-bcm283x/acpi.c new file mode 100644 index 00000000000..7d95a361ff1 --- /dev/null +++ b/u-boot/arch/arm/mach-bcm283x/acpi.c @@ -0,0 +1,185 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * (C) Copyright 2024 9elements GmbH + * + * See file CREDITS for list of people who contributed to this + * project. + */ + +#include +#include +#include +#include +#include + +void acpi_fill_fadt(struct acpi_fadt *fadt) +{ + fadt->flags = ACPI_FADT_HW_REDUCED_ACPI | ACPI_FADT_LOW_PWR_IDLE_S0; + + if (CONFIG_IS_ENABLED(SEC_FIRMWARE_ARMV8_PSCI) && + sec_firmware_support_psci_version() != PSCI_INVALID_VER) + fadt->arm_boot_arch = ACPI_ARM_PSCI_COMPLIANT; +} + +void *acpi_fill_madt(struct acpi_madt *madt, void *current) +{ + struct acpi_madr_gicc *gicc; + struct acpi_madr_gicd *gicd; + + madt->lapic_addr = 0; + madt->flags = 0; + + if (!CONFIG_IS_ENABLED(BCM2711_64B)) { + return current; + } + + gicc = current; + acpi_write_madt_gicc(gicc++, 0, 0x30, 0xff842000, 0xff846000, 0xff844000, 0x19, 0, 1); + acpi_write_madt_gicc(gicc++, 1, 0x31, 0xff842000, 0xff846000, 0xff844000, 0x19, 1, 1); + acpi_write_madt_gicc(gicc++, 2, 0x32, 0xff842000, 0xff846000, 0xff844000, 0x19, 2, 1); + acpi_write_madt_gicc(gicc++, 3, 0x33, 0xff842000, 0xff846000, 0xff844000, 0x19, 3, 1); + + gicd = (struct acpi_madr_gicd *)gicc; + acpi_write_madt_gicd(gicd++, 0, 0xff841000, 2); + return gicd; +} + +static u32 *add_proc(struct acpi_ctx *ctx, int flags, int parent, int proc_id, + int num_resources) +{ + struct acpi_pptt_proc *proc = ctx->current; + u32 *resource_list; + + proc->hdr.type = ACPI_PPTT_TYPE_PROC; + proc->flags = flags; + proc->parent = parent; + proc->proc_id = proc_id; + proc->num_resources = num_resources; + proc->hdr.length = sizeof(struct acpi_pptt_proc) + + sizeof(u32) * num_resources; + resource_list = ctx->current + sizeof(struct acpi_pptt_proc); + acpi_inc(ctx, proc->hdr.length); + + return resource_list; +} + +static int add_cache(struct acpi_ctx *ctx, int flags, int size, int sets, + int assoc, int attributes, int line_size) +{ + struct acpi_pptt_cache *cache = ctx->current; + int ofs; + + ofs = ctx->current - ctx->tab_start; + cache->hdr.type = ACPI_PPTT_TYPE_CACHE; + cache->hdr.length = sizeof(struct acpi_pptt_cache); + cache->flags = flags; + cache->next_cache_level = 0; + cache->size = size; + cache->sets = sets; + cache->assoc = assoc; + cache->attributes = attributes; + cache->line_size = line_size; + acpi_inc(ctx, cache->hdr.length); + + return ofs; +} + +static int acpi_write_pptt(struct acpi_ctx *ctx, const struct acpi_writer *entry) +{ + struct acpi_table_header *header; + int proc_ofs; + u32 *proc_ptr; + int ofs, ofs0, ofs1, i; + + if (!CONFIG_IS_ENABLED(BCM2711_64B)) { + return 0; + } + + header = ctx->current; + ctx->tab_start = ctx->current; + + memset(header, '\0', sizeof(struct acpi_table_header)); + + acpi_fill_header(header, "PPTT"); + header->revision = 0; + acpi_inc(ctx, sizeof(*header)); + + proc_ofs = ctx->current - ctx->tab_start; + proc_ptr = add_proc(ctx, ACPI_PPTT_PHYSICAL_PACKAGE | + ACPI_PPTT_CHILDREN_IDENTICAL, 0, 0, 1); + + ofs = add_cache(ctx, ACPI_PPTT_ALL_VALID, 0x100000, 0x400, 0x10, + ACPI_PPTT_WRITE_ALLOC | + (ACPI_PPTT_CACHE_TYPE_UNIFIED << + ACPI_PPTT_CACHE_TYPE_SHIFT), 0x40); + *proc_ptr = ofs; + + for (i = 0; i < 4; i++) { + proc_ptr = add_proc(ctx, ACPI_PPTT_CHILDREN_IDENTICAL | + ACPI_PPTT_NODE_IS_LEAF | ACPI_PPTT_PROC_ID_VALID, + proc_ofs, i, 2); + + ofs0 = add_cache(ctx, ACPI_PPTT_ALL_VALID, 0x8000, 0x100, 2, + ACPI_PPTT_WRITE_ALLOC, 0x40); + + ofs1 = add_cache(ctx, ACPI_PPTT_ALL_BUT_WRITE_POL, 0xc000, 0x100, 3, + ACPI_PPTT_CACHE_TYPE_INSTR << + ACPI_PPTT_CACHE_TYPE_SHIFT, 0x40); + proc_ptr[0] = ofs0; + proc_ptr[1] = ofs1; + } + + header->length = ctx->current - ctx->tab_start; + header->checksum = table_compute_checksum(header, header->length); + + acpi_inc(ctx, header->length); + acpi_add_table(ctx, header); + + return 0; +}; +ACPI_WRITER(5pptt, "PPTT", acpi_write_pptt, 0); + + +#define GTDT_FLAG_INT_ACTIVE_LOW BIT(1) +#define RPI_GTDT_GTIMER_FLAGS GTDT_FLAG_INT_ACTIVE_LOW + +/* ARM Architectural Timer Interrupt(GIC PPI) numbers */ +#define PcdArmArchTimerSecIntrNum 29 +#define PcdArmArchTimerIntrNum 30 +#define PcdArmArchTimerHypIntrNum 26 +#define PcdArmArchTimerVirtIntrNum 27 + +static int rpi_write_gtdt(struct acpi_ctx *ctx, const struct acpi_writer *entry) +{ + struct acpi_table_header *header; + struct acpi_gtdt *gtdt; + + gtdt = ctx->current; + header = >dt->header; + + memset(gtdt, '\0', sizeof(struct acpi_gtdt)); + + acpi_fill_header(header, "GTDT"); + header->length = sizeof(struct acpi_gtdt); + header->revision = 3; + + gtdt->cnt_ctrl_base = 0xff80001c; + gtdt->sec_el1_gsiv = PcdArmArchTimerSecIntrNum; + gtdt->sec_el1_flags = RPI_GTDT_GTIMER_FLAGS; + gtdt->el1_gsiv = PcdArmArchTimerIntrNum; + gtdt->el1_flags = RPI_GTDT_GTIMER_FLAGS; + gtdt->virt_el1_gsiv = PcdArmArchTimerVirtIntrNum; + gtdt->virt_el1_flags = RPI_GTDT_GTIMER_FLAGS; + gtdt->el2_gsiv = PcdArmArchTimerHypIntrNum; + gtdt->el2_flags = RPI_GTDT_GTIMER_FLAGS; + gtdt->cnt_read_base = 0xffffffffffffffff; + + header->checksum = table_compute_checksum(header, header->length); + + acpi_add_table(ctx, gtdt); + + acpi_inc(ctx, sizeof(struct acpi_gtdt)); + + return 0; +}; +ACPI_WRITER(5gtdt, "GTDT", rpi_write_gtdt, 0); \ No newline at end of file diff --git a/u-boot/arch/arm/mach-bcm283x/include/mach/acpi/bcm2711.h b/u-boot/arch/arm/mach-bcm283x/include/mach/acpi/bcm2711.h index dd0874280ef..1bfced2ea8f 100644 --- a/u-boot/arch/arm/mach-bcm283x/include/mach/acpi/bcm2711.h +++ b/u-boot/arch/arm/mach-bcm283x/include/mach/acpi/bcm2711.h @@ -86,7 +86,7 @@ #define GENET_BASE_ADDRESS FixedPcdGet64 (PcdBcmGenetRegistersAddress) #define GENET_LENGTH 0x00010000 -#define THERM_SENSOR 0xfd5d2200 +#define THERM_SENSOR 0x7d5d2200 #define ID_CHIPREV 0xfc404000 diff --git a/u-boot/arch/arm/mach-bcm283x/init.c b/u-boot/arch/arm/mach-bcm283x/init.c index 016bc1eb412..a7dd2876c09 100644 --- a/u-boot/arch/arm/mach-bcm283x/init.c +++ b/u-boot/arch/arm/mach-bcm283x/init.c @@ -7,11 +7,13 @@ */ #include +#include #include #include #include #include #include +#include #define BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS 0x600000000UL #define BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE 0x400000UL @@ -241,3 +243,26 @@ void enable_caches(void) dcache_enable(); } #endif + +#ifdef CONFIG_GENERATE_ACPI_TABLE +static int last_stage_init(void) +{ + ulong end; + void *ptr; + + /* Reserve 128K for ACPI tables, aligned to a 4K boundary */ + ptr = memalign(SZ_4K, SZ_128K); + + /* Generate ACPI tables */ + end = write_acpi_tables((uintptr_t)ptr); + if (end < 0) { + log_err("Failed to write tables\n"); + return log_msg_ret("table", end); + } + gd->arch.table_start = (uintptr_t)ptr; + gd->arch.table_end = end; + + return 0; +} +EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init); +#endif \ No newline at end of file diff --git a/u-boot/arch/x86/cpu/apollolake/acpi.c b/u-boot/arch/x86/cpu/apollolake/acpi.c index c610a7f4477..3aed38e2629 100644 --- a/u-boot/arch/x86/cpu/apollolake/acpi.c +++ b/u-boot/arch/x86/cpu/apollolake/acpi.c @@ -129,8 +129,10 @@ int arch_madt_sci_irq_polarity(int sci) return MP_IRQ_POLARITY_LOW; } -void fill_fadt(struct acpi_fadt *fadt) +void acpi_fill_fadt(struct acpi_fadt *fadt) { + intel_acpi_fill_fadt(fadt); + fadt->pm_tmr_blk = IOMAP_ACPI_BASE + PM1_TMR; fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; @@ -146,22 +148,6 @@ void fill_fadt(struct acpi_fadt *fadt) fadt->x_pm_tmr_blk.addrl = IOMAP_ACPI_BASE + PM1_TMR; } -static int apl_write_fadt(struct acpi_ctx *ctx, const struct acpi_writer *entry) -{ - struct acpi_table_header *header; - struct acpi_fadt *fadt; - - fadt = ctx->current; - acpi_fadt_common(fadt, ctx->facs, ctx->dsdt); - intel_acpi_fill_fadt(fadt); - fill_fadt(fadt); - header = &fadt->header; - header->checksum = table_compute_checksum(fadt, header->length); - - return acpi_add_fadt(ctx, fadt); -} -ACPI_WRITER(5fadt, "FADT", apl_write_fadt, 0); - int apl_acpi_fill_dmar(struct acpi_ctx *ctx) { struct udevice *dev, *sa_dev; diff --git a/u-boot/arch/x86/cpu/baytrail/acpi.c b/u-boot/arch/x86/cpu/baytrail/acpi.c index ccc4851b188..4cdc8e43147 100644 --- a/u-boot/arch/x86/cpu/baytrail/acpi.c +++ b/u-boot/arch/x86/cpu/baytrail/acpi.c @@ -16,20 +16,13 @@ #include #include -static int baytrail_write_fadt(struct acpi_ctx *ctx, - const struct acpi_writer *entry) +void acpi_fill_fadt(struct acpi_fadt *fadt) { struct acpi_table_header *header; - struct acpi_fadt *fadt; - fadt = ctx->current; header = &fadt->header; u16 pmbase = ACPI_BASE_ADDRESS; - memset(fadt, '\0', sizeof(struct acpi_fadt)); - - acpi_fill_header(header, "FACP"); - header->length = sizeof(struct acpi_fadt); header->revision = 4; fadt->preferred_pm_profile = ACPI_PM_MOBILE; @@ -78,9 +71,6 @@ static int baytrail_write_fadt(struct acpi_ctx *ctx, fadt->reset_reg.addrh = 0; fadt->reset_value = SYS_RST | RST_CPU | FULL_RST; - fadt->x_firmware_ctrl = map_to_sysmem(ctx->facs); - fadt->x_dsdt = map_to_sysmem(ctx->dsdt); - fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO; fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8; fadt->x_pm1a_evt_blk.bit_offset = 0; @@ -136,12 +126,7 @@ static int baytrail_write_fadt(struct acpi_ctx *ctx, fadt->x_gpe1_blk.access_size = 0; fadt->x_gpe1_blk.addrl = 0x0; fadt->x_gpe1_blk.addrh = 0x0; - - header->checksum = table_compute_checksum(fadt, header->length); - - return acpi_add_fadt(ctx, fadt); } -ACPI_WRITER(5fadt, "FADT", baytrail_write_fadt, 0); int acpi_create_gnvs(struct acpi_global_nvs *gnvs) { diff --git a/u-boot/arch/x86/cpu/intel_common/acpi.c b/u-boot/arch/x86/cpu/intel_common/acpi.c index d94ec208f65..dae8054a048 100644 --- a/u-boot/arch/x86/cpu/intel_common/acpi.c +++ b/u-boot/arch/x86/cpu/intel_common/acpi.c @@ -101,8 +101,11 @@ static unsigned long acpi_madt_irq_overrides(unsigned long current) return current; } -u32 acpi_fill_madt(u32 current) +u32 acpi_fill_madt(struct acpi_madt *madt, void *current) { + madt->lapic_addr = LAPIC_DEFAULT_BASE; + madt->flags = ACPI_MADT_PCAT_COMPAT; + /* Local APICs */ current += acpi_create_madt_lapics(current); diff --git a/u-boot/arch/x86/cpu/quark/acpi.c b/u-boot/arch/x86/cpu/quark/acpi.c index 0e18ceab68d..fd5b106684b 100644 --- a/u-boot/arch/x86/cpu/quark/acpi.c +++ b/u-boot/arch/x86/cpu/quark/acpi.c @@ -11,20 +11,12 @@ #include #include -static int quark_write_fadt(struct acpi_ctx *ctx, - const struct acpi_writer *entry) +void acpi_fill_fadt(struct acpi_fadt *fadt) { u16 pmbase = ACPI_PM1_BASE_ADDRESS; struct acpi_table_header *header; - struct acpi_fadt *fadt; - fadt = ctx->current; header = &fadt->header; - - memset(fadt, '\0', sizeof(struct acpi_fadt)); - - acpi_fill_header(header, "FACP"); - header->length = sizeof(struct acpi_fadt); header->revision = 4; fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED; @@ -73,9 +65,6 @@ static int quark_write_fadt(struct acpi_ctx *ctx, fadt->reset_reg.addrh = 0; fadt->reset_value = SYS_RST | RST_CPU | FULL_RST; - fadt->x_firmware_ctrl = map_to_sysmem(ctx->facs); - fadt->x_dsdt = map_to_sysmem(ctx->dsdt); - fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO; fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8; fadt->x_pm1a_evt_blk.bit_offset = 0; @@ -131,12 +120,7 @@ static int quark_write_fadt(struct acpi_ctx *ctx, fadt->x_gpe1_blk.access_size = 0; fadt->x_gpe1_blk.addrl = 0x0; fadt->x_gpe1_blk.addrh = 0x0; - - header->checksum = table_compute_checksum(fadt, header->length); - - return acpi_add_fadt(ctx, fadt); } -ACPI_WRITER(5fadt, "FADT", quark_write_fadt, 0); int acpi_create_gnvs(struct acpi_global_nvs *gnvs) { diff --git a/u-boot/arch/x86/cpu/tangier/acpi.c b/u-boot/arch/x86/cpu/tangier/acpi.c index 1d37cc9e2b0..f165dd16a1c 100644 --- a/u-boot/arch/x86/cpu/tangier/acpi.c +++ b/u-boot/arch/x86/cpu/tangier/acpi.c @@ -17,21 +17,8 @@ #include #include -static int tangier_write_fadt(struct acpi_ctx *ctx, - const struct acpi_writer *entry) +void acpi_fill_fadt(struct acpi_fadt *fadt) { - struct acpi_table_header *header; - struct acpi_fadt *fadt; - - fadt = ctx->current; - header = &fadt->header; - - memset(fadt, '\0', sizeof(struct acpi_fadt)); - - acpi_fill_header(header, "FACP"); - header->length = sizeof(struct acpi_fadt); - header->revision = 6; - fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED; fadt->iapc_boot_arch = ACPI_FADT_VGA_NOT_PRESENT | @@ -41,20 +28,13 @@ static int tangier_write_fadt(struct acpi_ctx *ctx, ACPI_FADT_POWER_BUTTON | ACPI_FADT_SLEEP_BUTTON | ACPI_FADT_SEALED_CASE | ACPI_FADT_HEADLESS | ACPI_FADT_HW_REDUCED_ACPI; - - fadt->minor_revision = 2; - - fadt->x_firmware_ctrl = map_to_sysmem(ctx->facs); - fadt->x_dsdt = map_to_sysmem(ctx->dsdt); - - header->checksum = table_compute_checksum(fadt, header->length); - - return acpi_add_fadt(ctx, fadt); } -ACPI_WRITER(5fadt, "FADT", tangier_write_fadt, 0); -u32 acpi_fill_madt(u32 current) +u32 acpi_fill_madt(struct acpi_madt *madt, void *current) { + madt->lapic_addr = LAPIC_DEFAULT_BASE; + madt->flags = ACPI_MADT_PCAT_COMPAT; + current += acpi_create_madt_lapics(current); current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current, diff --git a/u-boot/arch/x86/include/asm/acpi_table.h b/u-boot/arch/x86/include/asm/acpi_table.h index 3988898f66e..4c1a639e440 100644 --- a/u-boot/arch/x86/include/asm/acpi_table.h +++ b/u-boot/arch/x86/include/asm/acpi_table.h @@ -31,7 +31,6 @@ int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride, u8 bus, u8 source, u32 gsirq, u16 flags); int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi, u8 cpu, u16 flags, u8 lint); -u32 acpi_fill_madt(u32 current); int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base, u16 seg_nr, u8 start, u8 end); diff --git a/u-boot/arch/x86/lib/acpi_table.c b/u-boot/arch/x86/lib/acpi_table.c index 9588b841154..c66de8ae3e6 100644 --- a/u-boot/arch/x86/lib/acpi_table.c +++ b/u-boot/arch/x86/lib/acpi_table.c @@ -116,8 +116,11 @@ static int acpi_create_madt_irq_overrides(u32 current) return length; } -__weak u32 acpi_fill_madt(u32 current) +__weak u32 acpi_fill_madt(struct acpi_madt *madt, void *current) { + madt->lapic_addr = LAPIC_DEFAULT_BASE; + madt->flags = ACPI_MADT_PCAT_COMPAT; + current += acpi_create_madt_lapics(current); current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current, @@ -128,39 +131,6 @@ __weak u32 acpi_fill_madt(u32 current) return current; } -int acpi_write_madt(struct acpi_ctx *ctx, const struct acpi_writer *entry) -{ - struct acpi_table_header *header; - struct acpi_madt *madt; - u32 current; - - madt = ctx->current; - - memset(madt, '\0', sizeof(struct acpi_madt)); - header = &madt->header; - - /* Fill out header fields */ - acpi_fill_header(header, "APIC"); - header->length = sizeof(struct acpi_madt); - header->revision = ACPI_MADT_REV_ACPI_3_0; - - madt->lapic_addr = LAPIC_DEFAULT_BASE; - madt->flags = ACPI_MADT_PCAT_COMPAT; - - current = (u32)madt + sizeof(struct acpi_madt); - current = acpi_fill_madt(current); - - /* (Re)calculate length and checksum */ - header->length = current - (u32)madt; - - header->checksum = table_compute_checksum((void *)madt, header->length); - acpi_add_table(ctx, madt); - acpi_inc(ctx, madt->header.length); - - return 0; -} -ACPI_WRITER(5x86, NULL, acpi_write_madt, 0); - /** * acpi_create_tcpa() - Create a TCPA table * diff --git a/u-boot/board/raspberrypi/rpi/dsdt.asl b/u-boot/board/raspberrypi/rpi/dsdt.asl index 4dddbd068b8..1376fe47310 100644 --- a/u-boot/board/raspberrypi/rpi/dsdt.asl +++ b/u-boot/board/raspberrypi/rpi/dsdt.asl @@ -231,16 +231,6 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 2, "RPIFDN", "RPI", 2) { Return (0xf) } - Method (_CRS, 0x0, Serialized) - { - Name (RBUF, ResourceTemplate () - { - // No need for MEMORY32SETBASE on Genet as we have a straight base address constant - MEMORY32FIXED (ReadWrite, GENET_BASE_ADDRESS, GENET_LENGTH, ) - Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { GENET_INTERRUPT0, GENET_INTERRUPT1 } - }) - Return (RBUF) - } Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { @@ -281,5 +271,9 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 2, "RPIFDN", "RPI", 2) } } +#include "uart.asl" +#include "rhpx.asl" +#include "sdhc.asl" + } } diff --git a/u-boot/board/raspberrypi/rpi/gpudevs.asl b/u-boot/board/raspberrypi/rpi/gpudevs.asl index aa23651ac4a..e6b4fcc3aad 100644 --- a/u-boot/board/raspberrypi/rpi/gpudevs.asl +++ b/u-boot/board/raspberrypi/rpi/gpudevs.asl @@ -390,8 +390,4 @@ Device (PWM0) MEMORY32SETBASE (RBUF, RM03, RB03, BCM2836_PWM_CLK_OFFSET) Return (^RBUF) } -} - -#include "uart.asl" -#include "rhpx.asl" -#include "sdhc.asl" +} \ No newline at end of file diff --git a/u-boot/board/raspberrypi/rpi/rpi.c b/u-boot/board/raspberrypi/rpi/rpi.c index 4981bbdc0ad..373ccb26643 100644 --- a/u-boot/board/raspberrypi/rpi/rpi.c +++ b/u-boot/board/raspberrypi/rpi/rpi.c @@ -605,85 +605,6 @@ int ft_board_setup(void *blob, struct bd_info *bd) return 0; } -#ifdef CONFIG_GENERATE_ACPI_TABLE -int last_stage_init(void) -{ - int ret; - - ret = write_acpi_tables(0x10000); - if (ret < 0) { - log_err("Failed to write tables\n"); - return log_msg_ret("table", ret); - } - - return 0; -} -EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init); - -static int rpi_write_fadt(struct acpi_ctx *ctx, const struct acpi_writer *entry) -{ - struct acpi_table_header *header; - struct acpi_fadt *fadt; - - fadt = ctx->current; - acpi_fadt_common(fadt, ctx->facs, ctx->dsdt); - - fadt->firmware_ctrl = (ulong)ctx->facs; - fadt->dsdt = (ulong)ctx->dsdt; - fadt->preferred_pm_profile = ACPI_PM_APPLIANCE_PC; - //fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_SLEEP_BUTTON | ACPI_FADT_HW_REDUCED_ACPI; - fadt->flags = ACPI_FADT_HW_REDUCED_ACPI | ACPI_FADT_LOW_PWR_IDLE_S0; // from coreboot - //fadt->arm_boot_arch |= ACPI_ARM_PSCI_COMPLIANT; - fadt->minor_revision = 3; - fadt->header.revision = ACPI_FADT_REV_ACPI_6_0; //TODO see if it works - - header = &fadt->header; - header->checksum = table_compute_checksum(fadt, header->length); - - return acpi_add_fadt(ctx, fadt); -} -ACPI_WRITER(5fadt, "FADT", rpi_write_fadt, 0); - -#define GTDT_FLAG_INT_ACTIVE_LOW BIT(1) -#define RPI_GTDT_GTIMER_FLAGS GTDT_FLAG_INT_ACTIVE_LOW - -/* ARM Architectural Timer Interrupt(GIC PPI) numbers */ -#define PcdArmArchTimerSecIntrNum 29 -#define PcdArmArchTimerIntrNum 30 -#define PcdArmArchTimerHypIntrNum 26 -#define PcdArmArchTimerVirtIntrNum 27 - -static int rpi_write_gtdt(struct acpi_ctx *ctx, const struct acpi_writer *entry) -{ - struct acpi_table_header *header; - struct acpi_gtdt *gtdt; - - gtdt = ctx->current; - header = >dt->header; - - memset(gtdt, '\0', sizeof(struct acpi_gtdt)); - - acpi_fill_header(header, "GTDT"); - header->length = sizeof(struct acpi_gtdt); - header->revision = 3; - - gtdt->cnt_ctrl_base = RPI_SYSTEM_TIMER_BASE_ADDRESS; - gtdt->sec_el1_gsiv = PcdArmArchTimerSecIntrNum; - gtdt->sec_el1_flags = RPI_GTDT_GTIMER_FLAGS; - gtdt->el1_gsiv = PcdArmArchTimerIntrNum; - gtdt->el1_flags = RPI_GTDT_GTIMER_FLAGS; - gtdt->virt_el1_gsiv = PcdArmArchTimerVirtIntrNum; - gtdt->virt_el1_flags = RPI_GTDT_GTIMER_FLAGS; - gtdt->el2_gsiv = PcdArmArchTimerHypIntrNum; - gtdt->el2_flags = RPI_GTDT_GTIMER_FLAGS; - gtdt->cnt_read_base = 0xffffffffffffffff; - acpi_add_table(ctx, gtdt); - - acpi_inc(ctx, sizeof(struct acpi_gtdt)); - - return 0; -}; -ACPI_WRITER(5gtdt, "GTDT", rpi_write_gtdt, 0); static int rpi_write_dbg2(struct acpi_ctx *ctx, const struct acpi_writer *entry) { @@ -719,173 +640,6 @@ static int rpi_write_bgrt(struct acpi_ctx *ctx, const struct acpi_writer *entry) ACPI_WRITER(5bgrt, "BGRT", rpi_write_bgrt, 0); #endif -static u32 *add_proc(struct acpi_ctx *ctx, int flags, int parent, int proc_id, - int num_resources) -{ - struct acpi_pptt_proc *proc = ctx->current; - u32 *resource_list; - - proc->hdr.type = ACPI_PPTT_TYPE_PROC; - proc->flags = flags; - proc->parent = parent; - proc->proc_id = proc_id; - proc->num_resources = num_resources; - proc->hdr.length = sizeof(struct acpi_pptt_proc) + - sizeof(u32) * num_resources; - resource_list = ctx->current + sizeof(struct acpi_pptt_proc); - acpi_inc(ctx, proc->hdr.length); - - return resource_list; -} - -static int add_cache(struct acpi_ctx *ctx, int flags, int size, int sets, - int assoc, int attributes, int line_size) -{ - struct acpi_pptt_cache *cache = ctx->current; - int ofs; - - ofs = ctx->current - ctx->tab_start; - cache->hdr.type = ACPI_PPTT_TYPE_CACHE; - cache->hdr.length = sizeof(struct acpi_pptt_cache); - cache->flags = flags; - cache->next_cache_level = 0; - cache->size = size; - cache->sets = sets; - cache->assoc = assoc; - cache->attributes = attributes; - cache->line_size = line_size; - acpi_inc(ctx, cache->hdr.length); - - return ofs; -} - -static int rpi_write_pptt(struct acpi_ctx *ctx, const struct acpi_writer *entry) -{ - struct acpi_table_header *header; - int proc_ofs; - u32 *proc_ptr; - int ofs, ofs0, ofs1, i; - - header = ctx->current; - ctx->tab_start = ctx->current; - - memset(header, '\0', sizeof(struct acpi_table_header)); - - acpi_fill_header(header, "PPTT"); - header->revision = 0; - acpi_inc(ctx, sizeof(*header)); - - proc_ofs = ctx->current - ctx->tab_start; - proc_ptr = add_proc(ctx, ACPI_PPTT_PHYSICAL_PACKAGE | - ACPI_PPTT_CHILDREN_IDENTICAL, 0, 0, 1); - - ofs = add_cache(ctx, ACPI_PPTT_ALL_VALID, 0x100000, 0x400, 0x10, - ACPI_PPTT_WRITE_ALLOC | - (ACPI_PPTT_CACHE_TYPE_UNIFIED << - ACPI_PPTT_CACHE_TYPE_SHIFT), 0x40); - *proc_ptr = ofs; - - for (i = 0; i < 4; i++) { - proc_ptr = add_proc(ctx, ACPI_PPTT_CHILDREN_IDENTICAL | - ACPI_PPTT_NODE_IS_LEAF | ACPI_PPTT_PROC_ID_VALID, - proc_ofs, i, 2); - - ofs0 = add_cache(ctx, ACPI_PPTT_ALL_VALID, 0x8000, 0x100, 2, - ACPI_PPTT_WRITE_ALLOC, 0x40); - - ofs1 = add_cache(ctx, ACPI_PPTT_ALL_BUT_WRITE_POL, 0xc000, 0x100, 3, - ACPI_PPTT_CACHE_TYPE_INSTR << - ACPI_PPTT_CACHE_TYPE_SHIFT, 0x40); - proc_ptr[0] = ofs0; - proc_ptr[1] = ofs1; - } - - header->length = ctx->current - ctx->tab_start; - header->checksum = table_compute_checksum(header, header->length); - - acpi_inc(ctx, header->length); - acpi_add_table(ctx, header); - - return 0; -}; -ACPI_WRITER(5pptt, "PPTT", rpi_write_pptt, 0); - -static void acpi_write_madt_gicc(struct acpi_ctx *ctx, uint cpu_num, - uint perf_gsiv, ulong phys_base, ulong gicv, - ulong gich, uint vgic_maint_irq, ulong mpidr, - uint efficiency) -{ - struct acpi_madr_gicc *gicc = ctx->current; - - memset(gicc, '\0', sizeof(struct acpi_madr_gicc)); - gicc->type = ACPI_APIC_GICC; - gicc->length = sizeof(struct acpi_madr_gicc); - gicc->cpu_if_num = cpu_num; - gicc->processor_id = cpu_num; - gicc->flags = ACPI_MADRF_ENABLED; - gicc->perf_gsiv = perf_gsiv; - gicc->phys_base = phys_base; - gicc->gicv = gicv; - gicc->gich = gich; - gicc->vgic_maint_irq = vgic_maint_irq; - gicc->mpidr = mpidr; - gicc->efficiency = efficiency; - acpi_inc(ctx, gicc->length); -} - -static void acpi_write_madt_gicd(struct acpi_ctx *ctx, uint gic_id, - ulong phys_base, uint gic_version) -{ - struct acpi_madr_gicd *gicd = ctx->current; - - memset(gicd, '\0', sizeof(struct acpi_madr_gicd)); - gicd->type = ACPI_APIC_GICD; - gicd->length = sizeof(struct acpi_madr_gicd); - gicd->gic_id = gic_id; - gicd->phys_base = phys_base; - gicd->gic_version = gic_version; - - acpi_inc(ctx, gicd->length); -} - -static int rpi_write_madt(struct acpi_ctx *ctx, const struct acpi_writer *entry) -{ - struct acpi_table_header *header; - struct acpi_madt *madt; - int i; - - ctx->tab_start = ctx->current; - madt = ctx->current; - - memset(madt, '\0', sizeof(struct acpi_madt)); - header = &madt->header; - - /* Fill out header fields */ - acpi_fill_header(header, "APIC"); - header->length = sizeof(struct acpi_madt); - header->revision = ACPI_MADT_REV_ACPI_6_0; - - madt->lapic_addr = 0; - madt->flags = 0; - acpi_inc(ctx, sizeof(*madt)); - - for (i = 0; i < 4; i++) { - acpi_write_madt_gicc(ctx, i, 0x30 + i, 0xff842000, 0xff846000, - 0xff844000, 0x19, i, 1); - } - acpi_write_madt_gicd(ctx, 0, 0xff841000, 2); - - /* (Re)calculate length and checksum */ - header->length = (u32)(ctx->current - ctx->tab_start); - - header->checksum = table_compute_checksum((void *)madt, header->length); - acpi_add_table(ctx, madt); - acpi_inc(ctx, madt->header.length); - - return 0; -} -ACPI_WRITER(5madt, "APIC", rpi_write_madt, 0); - /* DMA Controller Vendor Data */ struct __packed dma_ctlr_vendor_data { u32 length; @@ -989,4 +743,3 @@ int acpi_fill_csrt(struct acpi_ctx *ctx) return 0; } -#endif diff --git a/u-boot/include/acpi/acpi_table.h b/u-boot/include/acpi/acpi_table.h index 1537c038a6c..f04c830991a 100644 --- a/u-boot/include/acpi/acpi_table.h +++ b/u-boot/include/acpi/acpi_table.h @@ -927,16 +927,24 @@ void acpi_fill_header(struct acpi_table_header *header, char *signature); int acpi_fill_csrt(struct acpi_ctx *ctx); /** - * acpi_fadt_common() - Handle common parts of filling out an FADT + * acpi_fill_fadt() - Fill out the body of the FADT * - * This sets up the Fixed ACPI Description Table + * Should be implemented in SoC specific code. * - * @fadt: Pointer to place to put FADT - * @facs: Pointer to the FACS - * @dsdt: Pointer to the DSDT + * @fadt: Pointer to FADT to update */ -void acpi_fadt_common(struct acpi_fadt *fadt, struct acpi_facs *facs, - void *dsdt); +void acpi_fill_fadt(struct acpi_fadt *fadt); + +/** + * acpi_fill_madt() - Fill out the body of the MADT + * + * Must be implemented in SoC specific code. + * + * @madt: The MADT to update + * @current: Pointer to the MADT body + * @return Pointer to the end of tables, where the next tables can be written + */ +void *acpi_fill_madt(struct acpi_madt *madt, void *current); /** * acpi_write_dbg2_pci_uart() - Write out a DBG2 table diff --git a/u-boot/lib/acpi/acpi_table.c b/u-boot/lib/acpi/acpi_table.c index ec332f146d7..f3e6b2d33a4 100644 --- a/u-boot/lib/acpi/acpi_table.c +++ b/u-boot/lib/acpi/acpi_table.c @@ -201,29 +201,80 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table) return 0; } -void acpi_fadt_common(struct acpi_fadt *fadt, struct acpi_facs *facs, - void *dsdt) +__weak void acpi_fill_fadt(struct acpi_fadt *fadt) { - struct acpi_table_header *header = &fadt->header; +} + +int acpi_write_fadt(struct acpi_ctx *ctx, const struct acpi_writer *entry) +{ + struct acpi_table_header *header; + struct acpi_fadt *fadt; + + fadt = ctx->current; + header = &fadt->header; memset((void *)fadt, '\0', sizeof(struct acpi_fadt)); acpi_fill_header(header, "FACP"); header->length = sizeof(struct acpi_fadt); - header->revision = ACPI_FADT_REV_ACPI_4_0; + header->revision = ACPI_FADT_REV_ACPI_6_0; memcpy(header->oem_id, OEM_ID, 6); memcpy(header->oem_table_id, OEM_TABLE_ID, 8); memcpy(header->creator_id, ASLC_ID, 4); header->creator_revision = 1; - fadt->x_firmware_ctrl = map_to_sysmem(facs); - fadt->x_dsdt = map_to_sysmem(dsdt); + fadt->x_firmware_ctrl = map_to_sysmem(ctx->facs); + fadt->x_dsdt = map_to_sysmem(ctx->dsdt); + + if (fadt->x_firmware_ctrl < 0x100000000UL) + fadt->firmware_ctrl = fadt->x_firmware_ctrl; + else + fadt->firmware_ctrl = 0; + + if (fadt->x_dsdt < 0x100000000UL) + fadt->dsdt = fadt->x_dsdt; + else + fadt->dsdt = 0; + + fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED; + + acpi_fill_fadt(fadt); + + header->checksum = table_compute_checksum(fadt, header->length); + + return acpi_add_fadt(ctx, fadt); +} +ACPI_WRITER(5fadt, "FADT", acpi_write_fadt, 0); + +int acpi_write_madt(struct acpi_ctx *ctx, const struct acpi_writer *entry) +{ + struct acpi_table_header *header; + struct acpi_madt *madt; + void *current; + + madt = ctx->current; - fadt->preferred_pm_profile = ACPI_PM_MOBILE; + memset(madt, '\0', sizeof(struct acpi_madt)); + header = &madt->header; - /* Use ACPI 3.0 revision */ - fadt->header.revision = 4; //TODO + /* Fill out header fields */ + acpi_fill_header(header, "APIC"); + header->length = sizeof(struct acpi_madt); + header->revision = ACPI_MADT_REV_ACPI_3_0; + + current = (void *)madt + sizeof(struct acpi_madt); + current = acpi_fill_madt(madt, current); + + /* (Re)calculate length and checksum */ + header->length = (u64)current - (u64)madt; + + header->checksum = table_compute_checksum((void *)madt, header->length); + acpi_add_table(ctx, madt); + acpi_inc(ctx, madt->header.length); + + return 0; } +ACPI_WRITER(5madt, NULL, acpi_write_madt, 0); static void acpi_create_dbg2(struct acpi_dbg2_header *dbg2, int port_type, int port_subtype,