From 5ed95fa7b60cd53f10edce2561a7fef7787aba29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Tue, 10 Oct 2017 13:11:54 +0200 Subject: [PATCH] rpi: Read the value of RSTS register MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit RSTS register allows passing information from OS too bootloader upon reboot. Change-Id: I2fa04fa0e63e5c81f78901c06ca8884f7e89f8e8 Signed-off-by: Łukasz Stelmach --- arch/arm/mach-bcm283x/include/mach/mbox.h | 14 ++++++++ board/raspberrypi/rpi/rpi.c | 56 +++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/arch/arm/mach-bcm283x/include/mach/mbox.h b/arch/arm/mach-bcm283x/include/mach/mbox.h index 2ae2d3d..7063163 100644 --- a/arch/arm/mach-bcm283x/include/mach/mbox.h +++ b/arch/arm/mach-bcm283x/include/mach/mbox.h @@ -504,6 +504,20 @@ struct bcm2835_mbox_tag_pci_dev_addr { } body; }; +#define BCM2835_MBOX_TAG_GET_RSTS 0x00040011 + +struct bcm2835_mbox_tag_get_rsts { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + } req; + struct { + u32 rsts; + } resp; + } body; +}; + + /* * Pass a raw u32 message to the VC, and receive a raw u32 back. * diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index 372b26b..b8f5b6e 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -65,6 +65,34 @@ struct msg_get_clock_rate { u32 end_tag; }; +struct msg_get_rsts { + struct bcm2835_mbox_hdr hdr; + struct bcm2835_mbox_tag_get_rsts get_rsts; + u32 end_tag; +}; + +/* Dump a message. */ +#ifdef BCM2835_MBOX_DUMP_MESSAGES +#define BCM2835_MBOX_DUMP_MSG(msg) { \ + u32 *p = msg; \ + int i; \ + printf("%s:%d", __func__, __LINE__); \ + if (msg->hdr.code == 0) \ + printf(" req"); \ + else if (msg->hdr.code == 0x80000000) \ + printf(" resp"); \ + else if (msg->hdr.code == 0x80000000) \ + printf(" err"); \ + else \ + printf(" WAT‽"); \ + for (i = 0; i < sizeof(*(msg)) / sizeof(*p); i++) \ + printf(" 0x%08X", p[i]); \ + printf("\n"); \ +} +#else +#define BCM2835_MBOX_DUMP_MSG(msg) +#endif + #ifdef CONFIG_ARM64 #define DTB_DIR "broadcom/" #else @@ -337,6 +365,33 @@ unsigned long board_get_usable_ram_top(unsigned long total_size) return fw_dtb_pointer & ~0xffff; } +static void get_rsts(void) +{ + ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_rsts, msg, 1); + int ret; + char rsts_string[11] = { 0 }; + + BCM2835_MBOX_INIT_HDR(msg); + BCM2835_MBOX_INIT_TAG(&msg->get_rsts, GET_RSTS); + + BCM2835_MBOX_DUMP_MSG(msg); + + ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); + if (ret) { + printf("bcm2835: Could not query RSTS value\n"); + /* Ignore the error, let's carry on. */ + return; + } + + BCM2835_MBOX_DUMP_MSG(msg); + + snprintf(rsts_string, sizeof(rsts_string), "0x%08X", + msg->get_rsts.body.resp.rsts); + env_set("reg_rsts", rsts_string); + + return; +} + static void set_usbethaddr(void) { ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1); @@ -411,6 +466,7 @@ int misc_init_r(void) set_fdt_addr(); set_fdtfile(); set_usbethaddr(); + get_rsts(); #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG set_board_info(); #endif -- 2.7.4