From 5eeb4163fa05b86b46e9c3cceb980237c99cc758 Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Fri, 6 Mar 2015 10:15:31 -0600 Subject: [PATCH] platform/u-boot: Make bcm2708 mailbox code functional * Functional == compiles. Needs tested :-) --- src/system/boot/arch/arm/Jamfile | 2 +- src/system/boot/arch/arm/arch_cpu.cpp | 4 +- .../boot/arch/arm/arch_mailbox_bcm2708.cpp | 83 +++++++++---------- .../platform/u-boot/arch/arm/arch_mailbox.cpp | 3 +- 4 files changed, 42 insertions(+), 50 deletions(-) diff --git a/src/system/boot/arch/arm/Jamfile b/src/system/boot/arch/arm/Jamfile index db73f05587..783538e3e4 100644 --- a/src/system/boot/arch/arm/Jamfile +++ b/src/system/boot/arch/arm/Jamfile @@ -37,8 +37,8 @@ BootMergeObject boot_arch_$(TARGET_KERNEL_ARCH).o : arch_framebuffer_bcm2708.cpp arch_framebuffer_pxa.cpp arch_framebuffer_omap3.cpp - arch_cpu.cpp arch_mailbox_bcm2708.cpp + arch_cpu.cpp arch_mmu.cpp arch_start_kernel.S diff --git a/src/system/boot/arch/arm/arch_cpu.cpp b/src/system/boot/arch/arm/arch_cpu.cpp index 520d835bf1..5bb64e59ab 100644 --- a/src/system/boot/arch/arm/arch_cpu.cpp +++ b/src/system/boot/arch/arm/arch_cpu.cpp @@ -109,14 +109,14 @@ check_cpu_features() } -void +extern "C" void arch_cpu_memory_read_barrier(void) { asm volatile ("" : : : "memory"); } -void +extern "C" void arch_cpu_memory_write_barrier(void) { asm volatile ("" : : : "memory"); diff --git a/src/system/boot/arch/arm/arch_mailbox_bcm2708.cpp b/src/system/boot/arch/arm/arch_mailbox_bcm2708.cpp index c8b68e8aac..4b14f0f9f2 100644 --- a/src/system/boot/arch/arm/arch_mailbox_bcm2708.cpp +++ b/src/system/boot/arch/arm/arch_mailbox_bcm2708.cpp @@ -11,38 +11,10 @@ #include "arch_mailbox.h" -#include - +#include "arch_cpu.h" #include "bcm2708.h" -//extern addr_t gPeripheralBase; -// -// -//static inline addr_t -//convert_mailbox_reg(addr_t reg) -//{ -// return gPeripheralBase + ARM_CTRL_0_MAILBOX_BASE + reg; -//} -// -// -//static inline void -//write_mailbox_reg(addr_t reg, uint32 value) -//{ -// arch_cpu_memory_write_barrier(); -// *(volatile uint32*)convert_mailbox_reg(reg) = value; -//} -// -// -//static inline uint32 -//read_mailbox_reg(addr_t reg) -//{ -// uint32 result = *(volatile uint32*)convert_mailbox_reg(reg); -// arch_cpu_memory_read_barrier(); -// return result; -//} - - class ArchMailboxArmBCM2708 : public ArchMailbox { public: ArchMailboxArmBCM2708(addr_t base) @@ -52,6 +24,10 @@ public: virtual status_t Write(uint8 channel, uint32 value); virtual status_t Read(uint8 channel, uint32& value); + +private: + void RegisterWrite(addr_t reg, uint32 value); + uint32 RegisterRead(addr_t reg); }; @@ -66,11 +42,11 @@ status_t ArchMailboxArmBCM2708::Write(uint8 channel, uint32 value) { // We have to wait for the mailbox to drain if it is marked full. - //while ((read_mailbox_reg(ARM_MAILBOX_STATUS) & ARM_MAILBOX_FULL) != 0) - // ; + while ((RegisterRead(ARM_MAILBOX_STATUS) & ARM_MAILBOX_FULL) != 0) + ; - //value &= ARM_MAILBOX_DATA_MASK; - //write_mailbox_reg(ARM_MAILBOX_WRITE, value | channel); + value &= ARM_MAILBOX_DATA_MASK; + RegisterWrite(ARM_MAILBOX_WRITE, value | channel); return B_OK; } @@ -78,20 +54,37 @@ ArchMailboxArmBCM2708::Write(uint8 channel, uint32 value) status_t ArchMailboxArmBCM2708::Read(uint8 channel, uint32& value) { - //while (true) { - // // Wait for something to arrive in the mailbox. - // if ((read_mailbox_reg(ARM_MAILBOX_STATUS) & ARM_MAILBOX_EMPTY) != 0) - // continue; + while (true) { + // Wait for something to arrive in the mailbox. + if ((RegisterRead(ARM_MAILBOX_STATUS) & ARM_MAILBOX_EMPTY) != 0) + continue; - // value = read_mailbox_reg(ARM_MAILBOX_READ); - // if ((value & ARM_MAILBOX_CHANNEL_MASK) != channel) { - // // Not for us, retry. - // continue; - // } + value = RegisterRead(ARM_MAILBOX_READ); + if ((value & ARM_MAILBOX_CHANNEL_MASK) != channel) { + // Not for us, retry. + continue; + } - // break; - //} + break; + } - //value &= ARM_MAILBOX_DATA_MASK; + value &= ARM_MAILBOX_DATA_MASK; return B_OK; } + + +uint32 +ArchMailboxArmBCM2708::RegisterRead(addr_t reg) +{ + uint32 result = *(volatile uint32*)(fBase + ARM_CTRL_0_MAILBOX_BASE + reg); + arch_cpu_memory_read_barrier(); + return result; +} + + +void +ArchMailboxArmBCM2708::RegisterWrite(addr_t reg, uint32 value) +{ + arch_cpu_memory_write_barrier(); + *(volatile uint32*)(fBase + ARM_CTRL_0_MAILBOX_BASE + reg) = value; +} diff --git a/src/system/boot/platform/u-boot/arch/arm/arch_mailbox.cpp b/src/system/boot/platform/u-boot/arch/arm/arch_mailbox.cpp index b796a7892e..73f066c07e 100644 --- a/src/system/boot/platform/u-boot/arch/arm/arch_mailbox.cpp +++ b/src/system/boot/platform/u-boot/arch/arm/arch_mailbox.cpp @@ -20,8 +20,7 @@ arch_mailbox_init() { #if defined(BOARD_CPU_BCM2708) extern ArchMailbox *arch_get_mailbox_arm_bcm2708(addr_t base); - #warning ARM: Add gPeripheralBase to ARM_CTRL_0_MAILBOX_BASE - gMailbox = arch_get_mailbox_arm_bcm2708(ARM_CTRL_0_MAILBOX_BASE); + gMailbox = arch_get_mailbox_arm_bcm2708(DEVICE_BASE); #endif return B_OK; }