Skip to contentSkip to conversation

Raspberry Pi EFI enablement

PATCH Superseded Alexander Graf 1 participant 11 messages Jun 6, 2016 – Nov 14, 2016

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Raspberry Pi EFI enablement

This is a follow-up to the RTS patch set from yesterday.

With this patch set I can successfully boot a Raspberry Pi 3 into Linux, with efifb, efi based reset/power off and spin table secondary bringup working.

I've put all of this into a single patch set so it doesn't get lost. In theory most patches could live by themselves, but it doesn't make much sense to introduce frameworks without adding users to them :).

Enjoy,

Alex

Alexander Graf (5):
efi_loader: Allow boards to implement get_time and reset_system
ARM: bcm283x: Implement EFI RTS reset_system
efi_loader: gop: Expose fb when 32bpp
bcm2835 video: Map frame buffer as 32bpp
bcm2835: Reserve the spin table in efi memory map

 arch/arm/mach-bcm283x/include/mach/wdog.h |   2 +-
 arch/arm/mach-bcm283x/reset.c             |  59 +++++++++++++++--
 board/raspberrypi/rpi/rpi.c               |   6 ++
 cmd/bootefi.c                             |   4 ++
 drivers/video/bcm2835.c                   |   6 +-
 include/configs/rpi.h                     |   2 +-
 include/efi_loader.h                      |  18 ++++++
 lib/efi_loader/efi_gop.c                  |  16 +++++
 lib/efi_loader/efi_runtime.c              | 101 ++++++++++++++++++++++++++----
 9 files changed, 192 insertions(+), 22 deletions(-)
Signature · 1 line
1.8.5.6
#1 lore raw

PATCH v2 1/5 efi_loader: Allow boards to implement get_time and reset_system

EFI allows an OS to leverage firmware drivers while the OS is running. In the generic code we so far had to stub those implementations out, because we would need board specific knowledge about MMIO setups for it.

However, boards can easily implement those themselves. This patch provides the framework so that a board can implement its own versions of get_time and reset_system which would actually do something useful.

While at it we also introduce a simple way for code to reserve MMIO pointers as runtime available.

---
 cmd/bootefi.c                |   4 ++
 include/efi_loader.h         |  18 ++++++++
 lib/efi_loader/efi_runtime.c | 101 ++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 112 insertions(+), 11 deletions(-)
cmd/bootefi.c +4 -0
index 2169065..edbe0b4 100644
@@ -205,6 +205,10 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt)
 		loaded_image_info.device_handle = nethandle;
 #endif
 
+	/* Initialize EFI runtime services */
+	efi_reset_system_init();
+	efi_get_time_init();
+
 	/* Call our payload! */
 	debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry);
 
include/efi_loader.h +18 -0
index 9738835..91d6a84 100644
@@ -150,11 +150,29 @@ static inline void ascii2unicode(u16 *unicode, const char *ascii)
 #define EFI_RUNTIME_DATA __attribute__ ((section ("efi_runtime_data")))
 #define EFI_RUNTIME_TEXT __attribute__ ((section ("efi_runtime_text")))
 
+/* Call this with mmio_ptr as the _pointer_ to a pointer to an MMIO region
+ * to make it available at runtime */
+void efi_add_runtime_mmio(void *mmio_ptr, u64 len);
+
+/* Boards may provide the functions below to implement RTS functionality */
+
+void EFI_RUNTIME_TEXT EFIAPI efi_reset_system(
+			enum efi_reset_type reset_type,
+			efi_status_t reset_status,
+			unsigned long data_size, void *reset_data);
+void efi_reset_system_init(void);
+
+efi_status_t EFI_RUNTIME_TEXT EFIAPI efi_get_time(
+			struct efi_time *time,
+			struct efi_time_cap *capabilities);
+void efi_get_time_init(void);
+
 #else /* defined(EFI_LOADER) && !defined(CONFIG_SPL_BUILD) */
 
 /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
 #define EFI_RUNTIME_DATA
 #define EFI_RUNTIME_TEXT
+static inline void efi_add_runtime_mmio(void **mmio_ptr, u64 len) { }
 
 /* No loader configured, stub out EFI_ENTRY */
 static inline void efi_restore_gd(void) { }
lib/efi_loader/efi_runtime.c +90 -11

166 lines not on this page · raw message

Signature · 1 line
1.8.5.6
#2 lore raw

PATCH v2 2/5 ARM: bcm283x: Implement EFI RTS reset_system

In reply to Alexander Graf

The rpi has a pretty simple way of resetting the whole system. All it takes is to poke a few registers at a well defined location in MMIO space.

This patch adds support for the EFI loader implementation to allow an OS to reset and power off the system when we're outside of boot time.

---
 arch/arm/mach-bcm283x/include/mach/wdog.h |  2 +-
 arch/arm/mach-bcm283x/reset.c             | 59 +++++++++++++++++++++++++++----
 2 files changed, 54 insertions(+), 7 deletions(-)
arch/arm/mach-bcm283x/include/mach/wdog.h +1 -1
index 7741d7b..b4caca1 100644
@@ -16,7 +16,7 @@
 struct bcm2835_wdog_regs {
 	u32 unknown0[7];
 	u32 rstc;
-	u32 unknown1;
+	u32 rsts;
 	u32 wdog;
 };
 
arch/arm/mach-bcm283x/reset.c +53 -6

72 lines not on this page · raw message

Signature · 1 line
1.8.5.6
author Applied
#3 lore raw

PATCH v2 2/5 ARM: bcm283x: Implement EFI RTS reset_system

Quoted 7 lines

The rpi has a pretty simple way of resetting the whole system. All it takes is to poke a few registers at a well defined location in MMIO space.

This patch adds support for the EFI loader implementation to allow an OS to reset and power off the system when we're outside of boot time.

Thanks, applied to efi-next

Alex

#4 lore raw

PATCH v2 3/5 efi_loader: gop: Expose fb when 32bpp

In reply to Alexander Graf

When we're running in 32bpp mode, expose the frame buffer address to our payloads so that Linux efifb can pick it up.

---
 lib/efi_loader/efi_gop.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
lib/efi_loader/efi_gop.c +16 -0
index 33a3d71..286ad83 100644
@@ -129,6 +129,7 @@ int efi_gop_register(void)
 {
 	struct efi_gop_obj *gopobj;
 	u32 bpix, col, row;
+	u64 fb_base, fb_size;
 
 #ifdef CONFIG_DM_VIDEO
 	struct udevice *vdev;
@@ -141,11 +142,16 @@ int efi_gop_register(void)
 	bpix = priv->bpix;
 	col = video_get_xsize(vdev);
 	row = video_get_ysize(vdev);
+	fb_base = (uintptr_t)priv->fb;
+	fb_size = priv->fb_size;
 #else
+	int line_len;
 
 	bpix = panel_info.vl_bpix;
 	col = panel_info.vl_col;
 	row = panel_info.vl_row;
+	fb_base = gd->fb_base;
+	fb_size = lcd_get_size(&line_len);
 #endif
 
 	switch (bpix) {
@@ -177,6 +183,16 @@ int efi_gop_register(void)
 	gopobj->mode.info = &gopobj->info;
 	gopobj->mode.info_size = sizeof(gopobj->info);
 
+#ifdef CONFIG_DM_VIDEO
+	if (bpix == VIDEO_BPP32) {
+#else
+	if (bpix == LCD_COLOR32) {
+#endif
+		/* With 32bit color space we can directly expose the fb */
+		gopobj->mode.fb_base = fb_base;
+		gopobj->mode.fb_size = fb_size;
+	}
+
 	gopobj->info.version = 0;
 	gopobj->info.width = col;
 	gopobj->info.height = row;
Signature · 1 line
1.8.5.6
author Applied
#5 lore raw

PATCH v2 3/5 efi_loader: gop: Expose fb when 32bpp

Quoted 4 lines

When we're running in 32bpp mode, expose the frame buffer address to our payloads so that Linux efifb can pick it up.

Thanks, applied to

#6 lore raw

PATCH v2 4/5 bcm2835 video: Map frame buffer as 32bpp

In reply to Alexander Graf

To enable working efifb support, let's map the frame buffer as 32bpp instead of 16bpp.

---
 drivers/video/bcm2835.c | 6 +++---
 include/configs/rpi.h   | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/video/bcm2835.c +3 -3
index cd605e6..cc6454f 100644
@@ -71,9 +71,9 @@ void lcd_ctrl_init(void *lcdbase)
 	msg_setup->virtual_w_h.body.req.width = w;
 	msg_setup->virtual_w_h.body.req.height = h;
 	BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH);
-	msg_setup->depth.body.req.bpp = 16;
+	msg_setup->depth.body.req.bpp = 32;
 	BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER);
-	msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_BGR;
+	msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_RGB;
 	BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE);
 	msg_setup->alpha_mode.body.req.alpha = BCM2835_MBOX_ALPHA_MODE_IGNORED;
 	BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET);
@@ -103,7 +103,7 @@ void lcd_ctrl_init(void *lcdbase)
 
 	panel_info.vl_col = w;
 	panel_info.vl_row = h;
-	panel_info.vl_bpix = LCD_COLOR16;
+	panel_info.vl_bpix = LCD_COLOR32;
 
 	gd->fb_base = bus_to_phys(
 		msg_setup->allocate_buffer.body.resp.fb_address);
include/configs/rpi.h +1 -1
index 9ef5eae..dc8d22a 100644
@@ -78,7 +78,7 @@
 /* LCD */
 #define CONFIG_LCD
 #define CONFIG_LCD_DT_SIMPLEFB
-#define LCD_BPP				LCD_COLOR16
+#define LCD_BPP				LCD_COLOR32
 /*
  * Prevent allocation of RAM for FB; the real FB address is queried
  * dynamically from the VideoCore co-processor, and comes from RAM
Signature · 1 line
1.8.5.6
author Applied
#7 lore raw

PATCH v2 4/5 bcm2835 video: Map frame buffer as 32bpp

Quoted 4 lines

To enable working efifb support, let's map the frame buffer as 32bpp instead of 16bpp.

Thanks, applied to efi-next

Alex

#8 lore raw

PATCH v2 4/5 bcm2835 video: Map frame buffer as 32bpp

Quoted 9 lines · Alexander Graf
Quoted 4 lines

To enable working efifb support, let's map the frame buffer as 32bpp instead of 16bpp.

Thanks, applied to efi-next

Alex

Sorry, that was script magic going wild. Bcm2835 patches obviously have to go via Stephen's tree :)

Alex

#9 lore raw

PATCH v2 5/5 bcm2835: Reserve the spin table in efi memory map

In reply to Alexander Graf

Firmware provides a spin table on the raspberry pi. This table shouldn't get overwritten by payloads, so we need to mark it as reserved.

---
 board/raspberrypi/rpi/rpi.c | 6 ++++++
 1 file changed, 6 insertions(+)
board/raspberrypi/rpi/rpi.c +6 -0
index c45ddb1..a2336fc 100644
@@ -8,6 +8,7 @@
 #include <inttypes.h>
 #include <config.h>
 #include <dm.h>
+#include <efi_loader.h>
 #include <fdt_support.h>
 #include <fdt_simplefb.h>
 #include <lcd.h>
@@ -480,5 +481,10 @@ int ft_board_setup(void *blob, bd_t *bd)
 	 */
 	lcd_dt_simplefb_add_node(blob);
 
+#ifdef CONFIG_EFI_LOADER
+	/* Reserve the spin table */
+	efi_add_memory_map(0, 1, EFI_RESERVED_MEMORY_TYPE, 0);
+#endif
+
 	return 0;
 }
Signature · 1 line
1.8.5.6
author Applied
#10 lore raw

PATCH v2 5/5 bcm2835: Reserve the spin table in efi memory map

Quoted 4 lines

Firmware provides a spin table on the raspberry pi. This table shouldn't get overwritten by payloads, so we need to mark it as reserved.

Thanks, applied to efi-next

Alex