Skip to content

Commit

Permalink
Merge commit '8e5de81824763342dc4a6ba2b85ace7dc575c5b9' into HEAD
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Rudolph <[email protected]>
  • Loading branch information
PatrickRudolph committed Jul 2, 2024
2 parents 5c15e9d + 8e5de81 commit d13b851
Show file tree
Hide file tree
Showing 19 changed files with 365 additions and 396 deletions.
15 changes: 9 additions & 6 deletions u-boot/arch/arm/include/asm/acpi_table.h
Original file line number Diff line number Diff line change
@@ -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__ */
1 change: 1 addition & 0 deletions u-boot/arch/arm/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
45 changes: 45 additions & 0 deletions u-boot/arch/arm/lib/acpi_table.c
Original file line number Diff line number Diff line change
@@ -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 <common.h>
#include <acpi/acpigen.h>
#include <acpi/acpi_device.h>
#include <acpi/acpi_table.h>
#include <string.h>

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;
}
1 change: 1 addition & 0 deletions u-boot/arch/arm/mach-bcm283x/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
185 changes: 185 additions & 0 deletions u-boot/arch/arm/mach-bcm283x/acpi.c
Original file line number Diff line number Diff line change
@@ -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 <common.h>
#include <acpi/acpi_table.h>
#include <asm/acpi_table.h>
#include <asm/armv8/sec_firmware.h>
#include <tables_csum.h>

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 = &gtdt->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);
2 changes: 1 addition & 1 deletion u-boot/arch/arm/mach-bcm283x/include/mach/acpi/bcm2711.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions u-boot/arch/arm/mach-bcm283x/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
*/

#include <common.h>
#include <acpi/acpi_table.h>
#include <cpu_func.h>
#include <init.h>
#include <dm/device.h>
#include <fdt_support.h>
#include <asm/global_data.h>
#include <malloc.h>

#define BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS 0x600000000UL
#define BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE 0x400000UL
Expand Down Expand Up @@ -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
20 changes: 3 additions & 17 deletions u-boot/arch/x86/cpu/apollolake/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit d13b851

Please sign in to comment.