smol-gilbraltar/kernel/mbox.c
2024-12-23 23:44:47 +01:00

23 lines
538 B
C

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