vc4: fix traps, add ic source detection and dispatch, add proper handler for mbox...
[rpi-open-firmware.git] / arm_chainloader / drivers / mailbox.cc
1 /*=============================================================================
2 Copyright (C) 2016 Kristina Brooks
3 All rights reserved.
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 FILE DESCRIPTION
16 Mailbox driver.
17
18 =============================================================================*/
19
20 #include "mailbox.hpp"
21 #include <hardware.h>
22
23 #define logf(fmt, ...) printf("[MBOX:%s]: " fmt, __FUNCTION__, ##__VA_ARGS__);
24
25 template<typename T>
26 static bool wait_for_mask(T& reg, uint32_t mask, bool is_set, int timeout) {
27 while ((reg & mask) == (is_set ? 0 : mask)) {
28 if (timeout == 0)
29 return false;
30 timeout--;
31 udelay(1);
32 }
33
34 return true;
35 }
36
37 Bcm2708Mailbox::Bcm2708Mailbox() {
38
39 }
40
41 bool Bcm2708Mailbox::write_word(uint32_t data, int timeout) {
42 if (!wait_for_mask(ARM_0_MAIL1_STA, ARM_MS_FULL, false, timeout)) {
43 logf("mailbox write timed out after %dus (STA=0x%X)\n", timeout, ARM_0_MAIL1_STA);
44 return false;
45 }
46
47 ARM_0_MAIL1_WRT = data;
48 return true;
49 }
50
51 Bcm2708Mailbox STATIC_DRIVER g_Mailbox {};
This page took 0.068192 seconds and 4 git commands to generate.