Skip to content

Commit

Permalink
RFC: rpi: Enable booting with ACPI tables
Browse files Browse the repository at this point in the history
This is only partially implemented and includes RFC patches.

So far it boots into grub but is unable to read the OS from the USB stick,
presumably because the XHCI SSDT is missing.

Signed-off-by: Simon Glass <sjg@chromium.org>
  • Loading branch information
Simon Glass authored and PatrickRudolph committed Jul 1, 2024
1 parent 81efa5f commit 8e5de81
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 6 deletions.
2 changes: 2 additions & 0 deletions board/raspberrypi/rpi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

obj-y := rpi.o
obj-y += lowlevel_init.o

obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o
158 changes: 157 additions & 1 deletion board/raspberrypi/rpi/rpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* (C) Copyright 2012-2016 Stephen Warren
*/

#define LOG_CATEGORY LOGC_BOARD

#define DEBUG
#define LOG_DEBUG

#include <common.h>
#include <config.h>
#include <dm.h>
Expand All @@ -11,19 +16,31 @@
#include <fdt_support.h>
#include <fdt_simplefb.h>
#include <init.h>
#include <log.h>
#include <memalign.h>
#include <mmc.h>
#include <signatures.h>
#include <tables_csum.h>
#include <acpi/acpi_table.h>
#include <asm/acpi_table.h>
#include <asm/global_data.h>
#include <asm/gpio.h>
#include <asm/arch/mbox.h>
#include <asm/arch/msg.h>
#include <asm/arch/sdhci.h>
#include <asm/global_data.h>
#include <asm/arch/acpi/bcm2836.h>
#include <dm/acpi.h>
#include <dm/platform_data/serial_bcm283x_mu.h>
#ifdef CONFIG_ARM64
#include <asm/armv8/mmu.h>
#endif
#include <watchdog.h>
#include <dm/pinctrl.h>
#ifdef CONFIG_GENERATE_ACPI_TABLE
#include "acpitables.h"
#endif
#include <asm/armv8/sec_firmware.h>
#include <serial.h>

DECLARE_GLOBAL_DATA_PTR;

Expand Down Expand Up @@ -588,3 +605,142 @@ int ft_board_setup(void *blob, struct bd_info *bd)

return 0;
}


static int rpi_write_dbg2(struct acpi_ctx *ctx, const struct acpi_writer *entry)
{
u64 addr = 0xfe201000;
char *name = "\\_SB.GDV0.URT0";

//TODO mini UART is not 100% compatible to 16550 (some registers are missing)
acpi_16550_mmio32_write_dbg2_uart(ctx, addr, name);

return 0;
};
ACPI_WRITER(5dbg2, "DBG2", rpi_write_dbg2, 0);

#if 0
/* Need to add a logo first */
static int rpi_write_bgrt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
{
struct acpi_table_header *header;
struct acpi_bgrt_header *bgrt;

bgrt = ctx->current;
header = &dbg2->header;

memset(bgrt, '\0', sizeof(struct acpi_bgrt));

acpi_fill_header(header, "BGRT");
header->revision = 0;

acpi_inc(ctx, header->length);

return 0;
};
ACPI_WRITER(5bgrt, "BGRT", rpi_write_bgrt, 0);
#endif

/* DMA Controller Vendor Data */
struct __packed dma_ctlr_vendor_data {
u32 length;
u32 type;
u64 chan_base;
u32 chan_size;
u64 ctlr_base;
u32 ctlr_size;
u32 chan_count;
u32 ctlr_irq;
u32 min_req_line;
u32 max_req_line;
u8 cache_coherent;
};

/* DMA Controller */
struct __packed rd_dma_ctlr {
struct acpi_csrt_descriptor hdr;
struct dma_ctlr_vendor_data data;
};

/* dma chan vendor data */
struct __packed dma_chan_vendor_data {
u32 chan;
u32 chan_irq;
u16 is_reserved;
u16 addr_incr;
};

/* dma chan */
struct __packed rd_dma_chan {
struct acpi_csrt_descriptor hdr;
struct dma_chan_vendor_data data;
};

/* dma resource group */
struct __packed rg_dma {
struct acpi_csrt_group hdr;
struct rd_dma_ctlr ctlr;
struct rd_dma_chan chan[];
};

#define RPI_DMA_MAX_REQ_LINES 32

static void add_cmd_chan(struct rd_dma_chan *dmac, uint uid, uint chan,
uint chan_irq, bool is_reserved, int addr_incr)
{
memset(dmac, '\0', sizeof(*dmac));
dmac->hdr.length = sizeof(struct rd_dma_chan);
dmac->hdr.type = EFI_ACPI_CSRT_RESOURCE_TYPE_DMA;
dmac->hdr.subtype = EFI_ACPI_CSRT_RESOURCE_SUBTYPE_DMA_CHANNEL;
dmac->hdr.uid = uid;

dmac->data.chan = chan;
dmac->data.chan_irq = chan_irq;
dmac->data.is_reserved = is_reserved;
dmac->data.addr_incr = addr_incr;
}

int acpi_fill_csrt(struct acpi_ctx *ctx)
{
struct dma_ctlr_vendor_data *data;
struct acpi_csrt_group *hdr;
struct rg_dma *dma;
int i;

dma = ctx->current;
hdr = &dma->hdr;
memset(hdr, '\0', sizeof(*hdr));
hdr->length = 0;
hdr->vendor_id = SIGNATURE_32('R', 'P', 'I', 'F');
hdr->device_id = EFI_ACPI_CSRT_DEVICE_ID_DMA;

dma->ctlr.hdr.length = sizeof(struct rd_dma_ctlr);
dma->ctlr.hdr.type = EFI_ACPI_CSRT_RESOURCE_TYPE_DMA;
dma->ctlr.hdr.subtype = EFI_ACPI_CSRT_RESOURCE_SUBTYPE_DMA_CONTROLLER;
dma->ctlr.hdr.uid = EFI_ACPI_CSRT_RESOURCE_ID_IN_DMA_GRP;

data = &dma->ctlr.data;
data->length = sizeof(struct dma_ctlr_vendor_data);
data->type = 1;
data->chan_base = BCM2836_DMA0_BASE_ADDRESS;
data->chan_size = RPI_DMA_CHANNEL_COUNT * BCM2836_DMA_CHANNEL_LENGTH;
data->ctlr_base = BCM2836_DMA_CTRL_BASE_ADDRESS;
data->ctlr_size = 8;
data->chan_count = RPI_DMA_USED_CHANNEL_COUNT;
data->max_req_line = RPI_DMA_MAX_REQ_LINES - 1;

acpi_inc(ctx, sizeof(struct rg_dma));

for (i = 0; i < 10; i++) {
add_cmd_chan(&dma->chan[i],
EFI_ACPI_CSRT_RESOURCE_ID_IN_DMA_GRP + 1 + i, i,
0x30 + i,
i == 1 || i == 2 || i == 3 || i == 6 || i == 7,
i == 4);
acpi_inc(ctx, sizeof(struct rd_dma_chan));
}

hdr->length = (u32)(ctx->current - (void *)dma);

return 0;
}
9 changes: 4 additions & 5 deletions cmd/bootefi.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,10 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc,
if (argc > 2) {
uintptr_t fdt_addr;

ret = efi_install_fdt(fdt);
if (ret == EFI_INVALID_PARAMETER)
return CMD_RET_USAGE;
else if (ret != EFI_SUCCESS)
return CMD_RET_FAILURE;
fdt_addr = hextoul(argv[2], NULL);
fdt = map_sysmem(fdt_addr, 0);
} else {
fdt = EFI_FDT_USE_INTERNAL;
}

if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR) &&
Expand Down
17 changes: 17 additions & 0 deletions configs/rpi_4_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CONFIG_PREBOOT="pci enum; usb start;"
CONFIG_SYS_PBSIZE=1049
# CONFIG_DISPLAY_CPUINFO is not set
# CONFIG_DISPLAY_BOARDINFO is not set
CONFIG_LAST_STAGE_INIT=y
CONFIG_MISC_INIT_R=y
CONFIG_SYS_PROMPT="U-Boot> "
CONFIG_CMD_DFU=y
Expand Down Expand Up @@ -65,3 +66,19 @@ CONFIG_SYS_WHITE_ON_BLACK=y
CONFIG_VIDEO_BCM2835=y
CONFIG_CONSOLE_SCROLL_LINES=10
CONFIG_PHYS_TO_BUS=y
CONFIG_OF_LIBFDT_OVERLAY=y

CONFIG_GENERATE_ACPI_TABLE=y
CONFIG_ACPI=y
CONFIG_CMD_ACPI=y
CONFIG_BOOTM_EFI=y
CONFIG_CMD_BOOTEFI=y
CONFIG_LOG=y
CONFIG_LOG_MAX_LEVEL=9
CONFIG_LOG_DEFAULT_LEVEL=8
CONFIG_LOGLEVEL=8
CONFIG_LOGF_LINE=y
CONFIG_LOGF_FUNC=y
CONFIG_EFI_VARIABLE_NO_STORE=y
#CONFIG_EFI_RT_VOLATILE_STORE=y
CONFIG_HEXDUMP=y

0 comments on commit 8e5de81

Please sign in to comment.