vc4: fix traps, add ic source detection and dispatch, add proper handler for mbox...
authorKristina <tinab@hush.ai>
Tue, 6 Sep 2016 19:03:44 +0000 (20:03 +0100)
committerKristina <tinab@hush.ai>
Tue, 6 Sep 2016 19:03:44 +0000 (20:03 +0100)
arm_chainloader/Makefile
arm_chainloader/drivers/mailbox.cc [new file with mode: 0644]
arm_chainloader/drivers/mailbox.hpp [new file with mode: 0644]
arm_chainloader/loader.cc
arm_monitor.c
start.s
trap.c

index 7da2213..bae9174 100644 (file)
@@ -11,6 +11,7 @@ SRCS = \
        drivers/fatfs/ff.c \
        drivers/sdhost_impl.cc \
        drivers/mbr_disk.cc \
        drivers/fatfs/ff.c \
        drivers/sdhost_impl.cc \
        drivers/mbr_disk.cc \
+       drivers/mailbox.cc \
        ../lib/xprintf.c \
        ../lib/panic.c \
        ../lib/udelay.c \
        ../lib/xprintf.c \
        ../lib/panic.c \
        ../lib/udelay.c \
diff --git a/arm_chainloader/drivers/mailbox.cc b/arm_chainloader/drivers/mailbox.cc
new file mode 100644 (file)
index 0000000..442efc7
--- /dev/null
@@ -0,0 +1,51 @@
+/*=============================================================================
+Copyright (C) 2016 Kristina Brooks
+All rights reserved.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+FILE DESCRIPTION
+Mailbox driver.
+
+=============================================================================*/
+
+#include "mailbox.hpp"
+#include <hardware.h>
+
+#define logf(fmt, ...) printf("[MBOX:%s]: " fmt, __FUNCTION__, ##__VA_ARGS__);
+
+template<typename T>
+static bool wait_for_mask(T& reg, uint32_t mask, bool is_set, int timeout) {
+       while ((reg & mask) == (is_set ? 0 : mask)) {
+               if (timeout == 0) 
+                       return false;
+               timeout--;
+               udelay(1);
+       }
+
+       return true;
+}
+
+Bcm2708Mailbox::Bcm2708Mailbox() {
+
+}
+
+bool Bcm2708Mailbox::write_word(uint32_t data, int timeout) {
+       if (!wait_for_mask(ARM_0_MAIL1_STA, ARM_MS_FULL, false, timeout)) {
+               logf("mailbox write timed out after %dus (STA=0x%X)\n", timeout, ARM_0_MAIL1_STA);
+               return false;
+       }
+
+       ARM_0_MAIL1_WRT = data;
+       return true;
+}
+
+Bcm2708Mailbox STATIC_DRIVER g_Mailbox {};
\ No newline at end of file
diff --git a/arm_chainloader/drivers/mailbox.hpp b/arm_chainloader/drivers/mailbox.hpp
new file mode 100644 (file)
index 0000000..aa4f8e6
--- /dev/null
@@ -0,0 +1,29 @@
+/*=============================================================================
+Copyright (C) 2016 Kristina Brooks
+All rights reserved.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+FILE DESCRIPTION
+Mailbox driver.
+
+=============================================================================*/
+
+#pragma once
+
+#include <chainloader.h>
+
+struct Bcm2708Mailbox {
+       Bcm2708Mailbox();
+       bool write_word(uint32_t data, int timeout = 10000);
+};
+
+extern Bcm2708Mailbox g_Mailbox;
\ No newline at end of file
index 9390e8b..762af88 100644 (file)
@@ -19,6 +19,7 @@ Second stage bootloader.
 \r
 #include <drivers/fatfs/ff.h>\r
 #include <chainloader.h>\r
 \r
 #include <drivers/fatfs/ff.h>\r
 #include <chainloader.h>\r
+#include <drivers/mailbox.hpp>\r
 \r
 #define logf(fmt, ...) printf("[LDR:%s]: " fmt, __FUNCTION__, ##__VA_ARGS__);\r
 \r
 \r
 #define logf(fmt, ...) printf("[LDR:%s]: " fmt, __FUNCTION__, ##__VA_ARGS__);\r
 \r
@@ -48,7 +49,7 @@ struct LoaderImpl {
                }\r
                logf("Boot partition mounted!\n");\r
 \r
                }\r
                logf("Boot partition mounted!\n");\r
 \r
-\r
+               g_Mailbox.write_word(0x1111);\r
        }\r
 };\r
 \r
        }\r
 };\r
 \r
index f9f67b7..7b1a22f 100644 (file)
@@ -20,26 +20,26 @@ First stage monitor.
 #include <common.h>\r
 #include "hardware.h"\r
 \r
 #include <common.h>\r
 #include "hardware.h"\r
 \r
-void monitor_irq() {\r
-\r
+/*\r
+ * called from sleh_irq (trap.c)\r
+ */\r
+void arm_monitor_interrupt() {\r
+       printf("VPU MBOX rcv: 0x%X, cnf 0x%X\n",\r
+               ARM_1_MAIL1_RD,\r
+               ARM_1_MAIL1_CNF);\r
 }\r
 \r
 void monitor_start() {\r
        printf("Starting IPC monitor ...\n");\r
 \r
        /* dump status */\r
 }\r
 \r
 void monitor_start() {\r
        printf("Starting IPC monitor ...\n");\r
 \r
        /* dump status */\r
-       printf("Status --- %X\n", mmio_read32(0x7E00B9B8));\r
+       printf("Mailbox status: 0x%X\n", ARM_1_MAIL1_STA);\r
 \r
        /* enable IRQ */\r
 \r
        /* enable IRQ */\r
-       mmio_write32(0x7E00B9BC, 0x1);\r
+       ARM_1_MAIL1_CNF = ARM_MC_IHAVEDATAIRQEN;\r
 \r
        for(;;) {\r
 \r
        for(;;) {\r
-               if(mmio_read32(0x7E00B9B8) != 0x40000000) {\r
-                       printf("Squeal!\n");\r
-               }\r
+               __asm__ __volatile__ ("sleep" :::);\r
+               printf("sleep interrupted!\n");\r
        }\r
        }\r
-\r
-       __asm__ __volatile__ ("sleep" :::);\r
-       \r
-       for(;;);\r
 }\r
 }\r
diff --git a/start.s b/start.s
index 09ce804..d24f951 100644 (file)
--- a/start.s
+++ b/start.s
@@ -168,7 +168,7 @@ delayloop2:
  ************************************************************/
 
 .macro SaveRegsLower 
  ************************************************************/
 
 .macro SaveRegsLower 
-               stm lr, (--sp)
+       stm lr, (--sp)
        stm r0-r5, (--sp)
 .endm
 
        stm r0-r5, (--sp)
 .endm
 
@@ -215,6 +215,7 @@ fleh_irq:
 
        /* top of savearea */
        mov r0, sp
 
        /* top of savearea */
        mov r0, sp
+       mov r1, r29
        bl sleh_irq
 
 return_from_exception:
        bl sleh_irq
 
 return_from_exception:
diff --git a/trap.c b/trap.c
index b71c657..4bbb3ca 100644 (file)
--- a/trap.c
+++ b/trap.c
@@ -38,9 +38,7 @@ static const char* exception_name(uint32_t n) {
        prefix " r12: 0x%08x r13: 0x%08x r14: 0x%08x r15: 0x%08x\n" \\r
        prefix "  pc: 0x%08x  lr: 0x%08x  sr: 0x%08x\n"\r
 \r
        prefix " r12: 0x%08x r13: 0x%08x r14: 0x%08x r15: 0x%08x\n" \\r
        prefix "  pc: 0x%08x  lr: 0x%08x  sr: 0x%08x\n"\r
 \r
-void sleh_fatal(vc4_saved_state_t* pcb, uint32_t n) {\r
-       printf("Fatal VPU Exception: %s\n", exception_name(n));\r
-\r
+static void print_vpu_state(vc4_saved_state_t* pcb) {\r
        printf("VPU registers:\n");\r
 \r
        printf(\r
        printf("VPU registers:\n");\r
 \r
        printf(\r
@@ -66,7 +64,7 @@ void sleh_fatal(vc4_saved_state_t* pcb, uint32_t n) {
                pcb->sr\r
        );\r
 \r
                pcb->sr\r
        );\r
 \r
-       printf("Exception info:\n");\r
+       printf("Exception info (IC0):\n");\r
 \r
        printf(\r
                "   src0: 0x%08x src1: 0x%08x vaddr: 0x%08x\n"\r
 \r
        printf(\r
                "   src0: 0x%08x src1: 0x%08x vaddr: 0x%08x\n"\r
@@ -78,13 +76,42 @@ void sleh_fatal(vc4_saved_state_t* pcb, uint32_t n) {
                IC0_S\r
        );\r
 \r
                IC0_S\r
        );\r
 \r
+       printf("Exception info (IC1):\n");\r
+\r
+       printf(\r
+               "   src0: 0x%08x src1: 0x%08x vaddr: 0x%08x\n"\r
+               "      C: 0x%08x    S: 0x%08x\n",\r
+               IC1_SRC0,\r
+               IC1_SRC1,\r
+               IC1_VADDR,\r
+               IC1_C,\r
+               IC1_S\r
+       );\r
+}\r
+\r
+void sleh_fatal(vc4_saved_state_t* pcb, uint32_t n) {\r
+       printf("Fatal VPU Exception: %s\n", exception_name(n));\r
+\r
+       print_vpu_state(pcb);\r
+\r
        printf("We are hanging here ...\n");\r
        printf("We are hanging here ...\n");\r
-    while(1) printf("Ahh!\n");\r
        \r
        hang_cpu();\r
 }\r
 \r
        \r
        hang_cpu();\r
 }\r
 \r
-void sleh_irq(vc4_saved_state_t* pcb) {\r
-    while(1) printf("Interrupt!\n");\r
-       panic("interrupt at 0x%X!", pcb->pc);\r
+extern void arm_monitor_interrupt();\r
+\r
+void sleh_irq(vc4_saved_state_t* pcb, uint32_t tp) {\r
+       uint32_t status = IC0_S;\r
+       uint32_t source = status & 0xFF;\r
+\r
+       printf("VPU Received interrupt from source %d\n", source);\r
+\r
+       if (source == INTERRUPT_ARM) {\r
+               arm_monitor_interrupt();\r
+       }\r
+       else {\r
+               print_vpu_state(pcb);\r
+               panic("unknown interrupt source!");\r
+       }\r
 }\r
 }\r
This page took 0.038684 seconds and 4 git commands to generate.