smol-gilbraltar/kernel/mbox.c

24 lines
538 B
C
Raw Permalink Normal View History

2024-12-23 00:46:17 +00:00
#include <assert.h>
2024-12-20 22:45:12 +00:00
#include <mbox.h>
2024-12-23 00:46:17 +00:00
#include <mem.h>
2024-12-20 22:45:12 +00:00
uint32_t gilbraltar_mbox_write_read(uintptr_t dma) {
2024-12-23 00:46:17 +00:00
assert((dma & 3) == 0); // [dma] must be aligned to 32-bit
2024-12-20 22:45:12 +00:00
dma |= 0xc0000000U;
2024-12-23 00:46:17 +00:00
while (read32(MAILBOX1_STATUS) & MAILBOX_STATUS_FULL)
;
2024-12-20 22:45:12 +00:00
write32(MAILBOX1_WRITE, BCM_MAILBOX_PROP_OUT | dma);
uint32_t result;
do {
2024-12-23 00:46:17 +00:00
while (read32(MAILBOX0_STATUS) & MAILBOX_STATUS_EMPTY)
;
2024-12-20 22:45:12 +00:00
result = read32(MAILBOX0_READ);
} while ((result & 0xf) != BCM_MAILBOX_PROP_OUT);
2024-12-23 00:46:17 +00:00
return ((result & ~0xf) & 0x3fffffff);
2024-12-20 22:45:12 +00:00
}