2 Copyright © 2013-2015, The AROS Development Team. All rights reserved.
8 #include <aros/macros.h>
9 #include <aros/debug.h>
10 #include <aros/symbolsets.h>
11 #include <aros/libcall.h>
12 #include <proto/kernel.h>
13 #include <proto/exec.h>
14 #include <proto/mbox.h>
16 #include <hardware/bcm2708.h>
17 #include <hardware/videocore.h>
19 #include "mbox_private.h"
22 static int mbox_init(struct MBoxBase
*MBoxBase
)
26 D(bug("[MBox] mbox_init()\n"));
28 InitSemaphore(&MBoxBase
->mbox_Sem
);
30 D(bug("[MBox] mbox_init: Initialised Semaphore @ 0x%p\n", &MBoxBase
->mbox_Sem
));
35 AROS_LH1(unsigned int, MBoxStatus
,
36 AROS_LHA(void *, mb
, A0
),
37 struct MBoxBase
*, MBoxBase
, 1, Mbox
)
41 D(bug("[MBox] MBoxStatus(0x%p)\n", mb
));
43 return AROS_LE2LONG(*((volatile unsigned int *)(mb
+ VCMB_STATUS
)));
48 AROS_LH2(volatile unsigned int *, MBoxRead
,
49 AROS_LHA(void *, mb
, A0
),
50 AROS_LHA( unsigned int, chan
, D0
),
51 struct MBoxBase
*, MBoxBase
, 2, Mbox
)
55 unsigned int try = 0x2000000;
58 D(bug("[MBox] MBoxRead(chan %d @ 0x%p)\n", chan
, mb
));
60 if (chan
<= VCMB_CHAN_MAX
)
64 ObtainSemaphore(&MBoxBase
->mbox_Sem
);
66 while ((MBoxStatus(mb
) & VCMB_STATUS_READREADY
) != 0)
68 /* Data synchronization barrier */
69 asm volatile ("mcr p15, 0, %[r], c7, c10, 4" : : [r
] "r" (0) );
76 asm volatile ("mcr p15, 0, %[r], c7, c10, 5" : : [r
] "r" (0) );
78 msg
= AROS_LE2LONG(*((volatile unsigned int *)(mb
+ VCMB_READ
)));
80 asm volatile ("mcr p15, 0, %[r], c7, c10, 5" : : [r
] "r" (0) );
82 ReleaseSemaphore(&MBoxBase
->mbox_Sem
);
84 if ((msg
& VCMB_CHAN_MASK
) == chan
)
86 uint32_t *addr
= (uint32_t *)(msg
& ~VCMB_CHAN_MASK
);
87 uint32_t len
= AROS_LE2LONG(addr
[0]);
89 CacheClearE(addr
, len
, CACRF_InvalidateD
);
91 return (volatile unsigned int *)(addr
);
95 return (volatile unsigned int *)-1;
100 AROS_LH3(void, MBoxWrite
,
101 AROS_LHA(void *, mb
, A0
),
102 AROS_LHA( unsigned int, chan
, D0
),
103 AROS_LHA(void *, msg
, A1
),
104 struct MBoxBase
*, MBoxBase
, 3, Mbox
)
108 D(bug("[MBOX] MBoxWrite(chan %d @ 0x%p, msg @ 0x%p)\n", chan
, mb
, msg
));
110 if ((((unsigned int)msg
& VCMB_CHAN_MASK
) == 0) && (chan
<= VCMB_CHAN_MAX
))
112 ULONG length
= AROS_LE2LONG(((ULONG
*)msg
)[0]);
114 void *phys_addr
= CachePreDMA(msg
, &length
, DMA_ReadFromRAM
);
116 ObtainSemaphore(&MBoxBase
->mbox_Sem
);
118 while ((MBoxStatus(mb
) & VCMB_STATUS_WRITEREADY
) != 0)
120 /* Data synchronization barrier */
121 asm volatile ("mcr p15, 0, %[r], c7, c10, 4" : : [r
] "r" (0) );
124 asm volatile ("mcr p15, 0, %[r], c7, c10, 5" : : [r
] "r" (0) );
126 *((volatile unsigned int *)(mb
+ VCMB_WRITE
)) = AROS_LONG2LE(((unsigned int)phys_addr
| chan
));
128 ReleaseSemaphore(&MBoxBase
->mbox_Sem
);
134 ADD2INITLIB(mbox_init
, 0)