#include #include #include 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); }