2 Copyright © 2014, The AROS Development Team. All rights reserved.
5 Desc: PCI XHCI USB host controller
15 #include <aros/debug.h>
16 #include <aros/macros.h>
17 #include <aros/asmcall.h>
18 #include <aros/symbolsets.h>
20 #include <proto/oop.h>
21 #include <proto/exec.h>
22 #include <proto/stdc.h>
23 #include <proto/arossupport.h>
25 #include <devices/usb.h>
26 #include <devices/usb_hub.h>
27 #include <devices/newstyle.h>
28 #include <devices/usbhardware.h>
29 #include <devices/timer.h>
35 #include <hidd/hidd.h>
37 #include "pcixhci_intern.h"
39 #include LC_LIBDEFS_FILE
41 void PCIXHCI_Delay(struct PCIXHCIUnit
*unit
, ULONG msec
) {
42 /* Allocate a signal within this task context */
43 unit
->tr
->tr_node
.io_Message
.mn_ReplyPort
->mp_SigBit
= SIGB_SINGLE
;
44 unit
->tr
->tr_node
.io_Message
.mn_ReplyPort
->mp_SigTask
= FindTask(NULL
);
46 /* Specify the request */
47 unit
->tr
->tr_node
.io_Command
= TR_ADDREQUEST
;
48 unit
->tr
->tr_time
.tv_secs
= msec
/ 1000;
49 unit
->tr
->tr_time
.tv_micro
= 1000 * (msec
% 1000);
52 DoIO((struct IORequest
*)unit
->tr
);
54 unit
->tr
->tr_node
.io_Message
.mn_ReplyPort
->mp_SigTask
= NULL
;
57 BOOL
PCIXHCI_CreateTimer(struct PCIXHCIUnit
*unit
) {
58 mybug_unit(0, ("Entering function\n"));
60 struct MsgPort
*mp
= NULL
;
64 unit
->tr
= (struct timerequest
*)CreateIORequest(mp
, sizeof(struct timerequest
));
66 FreeSignal(mp
->mp_SigBit
);
67 if (!OpenDevice((STRPTR
)"timer.device", UNIT_MICROHZ
, (struct IORequest
*)unit
->tr
, 0)) {
70 DeleteIORequest((struct IORequest
*)unit
->tr
);
71 mp
->mp_SigBit
= AllocSignal(-1);
79 void PCIXHCI_DeleteTimer(struct PCIXHCIUnit
*unit
) {
80 mybug_unit(0, ("Entering function\n"));
83 unit
->tr
->tr_node
.io_Message
.mn_ReplyPort
->mp_SigBit
= AllocSignal(-1);
84 CloseDevice((struct IORequest
*)unit
->tr
);
85 DeleteMsgPort(unit
->tr
->tr_node
.io_Message
.mn_ReplyPort
);
86 DeleteIORequest((struct IORequest
*)unit
->tr
);
90 void FreeVecOnBoundary(APTR onboundary
) {
93 APTR
AllocVecOnBoundary(ULONG size
, ULONG boundary
, STRPTR description
) {
100 IPTR description_size
;
102 STRPTR default_description
= "(something?!?)";
104 mybug(-1, ("[ALLOCVECONBOUNDARY] size %d(0x%x), boundary %d(0x%x), %s\n", size
, size
, boundary
, boundary
, (description
? description
: default_description
)));
107 mybug(-1, (" - Allocation called with zero size\n"));
111 /* Sanity check, size can never exceed boundary if boundary is set */
112 if((boundary
<size
) && (boundary
!= 0)) {
113 mybug(-1, (" - Allocation called with size exceeding boundary (%d<%d)\n", boundary
, size
));
118 alignement
= boundary
; // Align allocation to start at boundary
120 alignement
= 64; // Else allocation is aligned to 64 bytes
123 description_size
= AROS_ROUNDUP2(strlen((description
? description
: default_description
)) + 1, sizeof(IPTR
));
125 newsize
= size
+ 2*(sizeof(IPTR
)) + description_size
+ alignement
;
127 mybug(-1, (" - Allocating size %d->%d\n", size
, newsize
));
129 allocation
= AllocMem(newsize
, (MEMF_ANY
|MEMF_CLEAR
));
131 mybug(-1, (" - Allocated space from %p to %p with boundary %d\n", allocation
, allocation
+newsize
-1, boundary
));
136 description string rounded up to IPTR
137 padding to 64 byte alignement or to boundary alignement
138 return address minus one IPTR = address of original allocation
143 *(IPTR
*)ret
=newsize
;
146 strcpy(ret
, (description
? description
: default_description
));
147 ret
+= description_size
;
149 ret
= (UBYTE
*)AROS_ROUNDUP2((IPTR
)ret
, alignement
) - sizeof(IPTR
);
150 *(IPTR
*)ret
= (IPTR
)allocation
;
154 mybug(-1, (" - Return allocation space from %p to %p\n", ret
, ret
+size
-1));
159 mybug(-1, ("Allocation for %s failed!\n", (description
? description
: default_description
)));