fixed endianess of mbox message length detection
[AROS.git] / arch / arm-native / soc / broadcom / 2708 / mbox / mbox_init.c
blobdef94a5da0fcf8b87b81820bc342fd5e6565dbdc
1 /*
2 Copyright � 2013-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
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)
24 int retval = TRUE;
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));
32 return retval;
35 AROS_LH1(unsigned int, MBoxStatus,
36 AROS_LHA(void *, mb, A0),
37 struct MBoxBase *, MBoxBase, 1, Mbox)
39 AROS_LIBFUNC_INIT
41 D(bug("[MBox] MBoxStatus(0x%p)\n", mb));
43 return AROS_LE2LONG(*((volatile unsigned int *)(mb + VCMB_STATUS)));
45 AROS_LIBFUNC_EXIT
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)
53 AROS_LIBFUNC_INIT
55 unsigned int try = 0x2000000;
56 unsigned int msg;
58 D(bug("[MBox] MBoxRead(chan %d @ 0x%p)\n", chan, mb));
60 if (chan <= VCMB_CHAN_MAX)
62 while(1)
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) );
71 if(try-- == 0)
73 break;
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)
85 return (volatile unsigned int *)(msg & ~VCMB_CHAN_MASK);
88 return (volatile unsigned int *)-1;
90 AROS_LIBFUNC_EXIT
93 AROS_LH3(void, MBoxWrite,
94 AROS_LHA(void *, mb, A0),
95 AROS_LHA( unsigned int, chan, D0),
96 AROS_LHA(void *, msg, A1),
97 struct MBoxBase *, MBoxBase, 3, Mbox)
99 AROS_LIBFUNC_INIT
101 D(bug("[MBOX] MBoxWrite(chan %d @ 0x%p, msg @ 0x%p)\n", chan, mb, msg));
103 if ((((unsigned int)msg & VCMB_CHAN_MASK) == 0) && (chan <= VCMB_CHAN_MAX))
105 ULONG length = AROS_LE2LONG(((ULONG *)msg)[0]);
107 void *phys_addr = CachePreDMA(msg, &length, DMA_ReadFromRAM);
109 ObtainSemaphore(&MBoxBase->mbox_Sem);
111 while ((MBoxStatus(mb) & VCMB_STATUS_WRITEREADY) != 0)
113 /* Data synchronization barrier */
114 asm volatile ("mcr p15, 0, %[r], c7, c10, 4" : : [r] "r" (0) );
117 asm volatile ("mcr p15, 0, %[r], c7, c10, 5" : : [r] "r" (0) );
119 *((volatile unsigned int *)(mb + VCMB_WRITE)) = AROS_LONG2LE(((unsigned int)phys_addr | chan));
121 ReleaseSemaphore(&MBoxBase->mbox_Sem);
124 AROS_LIBFUNC_EXIT
127 ADD2INITLIB(mbox_init, 0)