2 Copyright � 2013-2015, The AROS Development Team. All rights reserved.
8 #include <aros/debug.h>
9 #include <aros/symbolsets.h>
10 #include <aros/libcall.h>
11 #include <proto/kernel.h>
12 #include <proto/exec.h>
13 #include <proto/vcmbox.h>
15 #include <hardware/bcm283x.h>
16 #include <hardware/videocore.h>
18 #include "vcmbox_private.h"
21 static int vcmbox_init(struct VCMBoxBase
*VCMBoxBase
)
25 D(bug("[VCMBox] vcmbox_init()\n"));
27 InitSemaphore(&VCMBoxBase
->vcmb_Sem
);
29 D(bug("[VCMBox] vcmbox_init: Initialised Semaphore @ 0x%p\n", &VCMBoxBase
->vcmb_Sem
));
34 AROS_LH1(unsigned int, VCMBoxStatus
,
35 AROS_LHA(void *, mb
, A0
),
36 struct VCMBoxBase
*, VCMBoxBase
, 1, Vcmbox
)
40 D(bug("[VCMBox] VCMBoxStatus(0x%p)\n", mb
));
42 return *((volatile unsigned int *)(mb
+ VCMB_STATUS
));
47 AROS_LH2(volatile unsigned int *, VCMBoxRead
,
48 AROS_LHA(void *, mb
, A0
),
49 AROS_LHA( unsigned int, chan
, D0
),
50 struct VCMBoxBase
*, VCMBoxBase
, 2, Vcmbox
)
54 unsigned int try = 0x2000000;
57 D(bug("[VCMBox] VCMBoxRead(chan %d @ 0x%p)\n", chan
, mb
));
59 if (chan
<= VCMB_CHAN_MAX
)
63 ObtainSemaphore(&VCMBoxBase
->vcmb_Sem
);
64 APTR ssp
= SuperState();
65 while ((VCMBoxStatus(mb
) & VCMB_STATUS_READREADY
) != 0)
67 /* Data synchronization barrier */
68 asm volatile ("mcr p15, 0, %[r], c7, c10, 4" : : [r
] "r" (0) );
75 asm volatile ("mcr p15, 0, %[r], c7, c10, 5" : : [r
] "r" (0) );
77 msg
= *((volatile unsigned int *)(mb
+ VCMB_READ
));
79 asm volatile ("mcr p15, 0, %[r], c7, c10, 5" : : [r
] "r" (0) );
81 ReleaseSemaphore(&VCMBoxBase
->vcmb_Sem
);
83 if ((msg
& VCMB_CHAN_MASK
) == chan
)
84 return (volatile unsigned int *)(msg
& ~VCMB_CHAN_MASK
);
87 return (volatile unsigned int *)-1;
92 AROS_LH3(void, VCMBoxWrite
,
93 AROS_LHA(void *, mb
, A0
),
94 AROS_LHA( unsigned int, chan
, D0
),
95 AROS_LHA(void *, msg
, A1
),
96 struct VCMBoxBase
*, VCMBoxBase
, 3, Vcmbox
)
100 D(bug("[VCMB] VCMBWrite(chan %d @ 0x%p, msg @ 0x%p)\n", chan
, mb
, msg
));
102 if ((((unsigned int)msg
& VCMB_CHAN_MASK
) == 0) && (chan
<= VCMB_CHAN_MAX
))
104 ObtainSemaphore(&VCMBoxBase
->vcmb_Sem
);
105 APTR ssp
= SuperState();
106 while ((VCMBoxStatus(mb
) & VCMB_STATUS_WRITEREADY
) != 0)
108 /* Data synchronization barrier */
109 asm volatile ("mcr p15, 0, %[r], c7, c10, 4" : : [r
] "r" (0) );
112 asm volatile ("mcr p15, 0, %[r], c7, c10, 5" : : [r
] "r" (0) );
114 *((volatile unsigned int *)(mb
+ VCMB_WRITE
)) = ((unsigned int)msg
| chan
);
116 ReleaseSemaphore(&VCMBoxBase
->vcmb_Sem
);
122 ADD2INITLIB(vcmbox_init
, 0)