revert between 56095 -> 55830 in arch
[AROS.git] / rom / usb / pciusbhc / xhci / pcixhci_misc.c
blob3f1c76c1a3913595eb8be31333687d5486eaf95a
1 /*
2 Copyright © 2014, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: PCI XHCI USB host controller
6 Lang: English
7 */
9 #ifdef DEBUG
10 #undef DEBUG
11 #endif
12 #define DEBUG 1
14 #include <aros/io.h>
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>
31 #include <asm/io.h>
32 #include <inttypes.h>
34 #include <hidd/pci.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);
51 /* Wait */
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;
62 mp = CreateMsgPort();
63 if (mp) {
64 unit->tr = (struct timerequest *)CreateIORequest(mp, sizeof(struct timerequest));
65 if (unit->tr) {
66 FreeSignal(mp->mp_SigBit);
67 if (!OpenDevice((STRPTR)"timer.device", UNIT_MICROHZ, (struct IORequest *)unit->tr, 0)) {
68 return TRUE;
70 DeleteIORequest((struct IORequest *)unit->tr);
71 mp->mp_SigBit = AllocSignal(-1);
73 DeleteMsgPort(mp);
76 return FALSE;
79 void PCIXHCI_DeleteTimer(struct PCIXHCIUnit *unit) {
80 mybug_unit(0, ("Entering function\n"));
82 if (unit->tr) {
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) {
95 UBYTE *allocation;
96 UBYTE *ret;
98 IPTR newsize;
99 IPTR alignement;
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)));
106 if(!size) {
107 mybug(-1, (" - Allocation called with zero size\n"));
108 return NULL;
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));
114 return NULL;
117 if(boundary) {
118 alignement = boundary; // Align allocation to start at boundary
119 } else {
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));
134 Allocation:
135 size (IPTR)
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
140 if(allocation) {
141 ret = allocation;
143 *(IPTR *)ret=newsize;
144 ret +=sizeof(IPTR);
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;
152 ret += sizeof(IPTR);
154 mybug(-1, (" - Return allocation space from %p to %p\n", ret, ret+size-1));
156 return ret;
159 mybug(-1, ("Allocation for %s failed!\n", (description ? description : default_description)));
160 return NULL;