usbhandle.c
1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "os_bb.h"
#include "osint.h"
#include "host.h"
_usb_ext_handle _usb_ext_handles[OS_USB_MAX_HANDLES];
/*
* osBbUsbDevGetHandle
*
* Description:
* Open or attach to a particular USB device.
*
* Returns:
* 0 for success
* < 0 for failure
*/
s32
osBbUsbDevGetHandle(s32 which, OSBbUsbInfo *ip, OSBbUsbHandle *hp)
{
#ifdef USB_HOST
HOST_GLOBAL_STRUCT *hgp;
int i;
if (which < 0 || which >= OS_USB_MAX_CONTROLLERS) {
PRINTF("osBbUsbDevGetHandle called with bad arg %d\n", which);
return(-1);
}
for (i = 0; i < OS_USB_MAX_HANDLES; i++) {
if (_usb_ext_handles[i].uh_host_handle == NULL) {
bzero((void *) &_usb_ext_handles[i],
sizeof (_usb_ext_handle));
_usb_ext_handles[i].uh_which = which;
_usb_ext_handles[i].uh_mq =
&__osBbUsbCtlrQ[which];
_usb_ext_handles[i].uh_host_handle =
__osArcHostHandle[which];
*hp = (OSBbUsbHandle) &_usb_ext_handles[i];
hgp = &host_global_struct[which];
if (hgp->driver != NULL) {
hgp->driver->funcs->open
(_usb_ext_handles[i].uh_host_handle);
_usb_ext_handles[i].uh_blksize =
hgp->driver->desc->BMAXPACKETSIZE;
} else {
_usb_ext_handles[i].uh_blksize = 64; /* XXX */
}
return(0);
}
}
PRINTF("osBbUsbDevGetHandle: out of handles\n");
return(EUSBAGAIN);
#else /* !USB_HOST */
return(-1);
#endif /* !USB_HOST */
}
s32
osBbUsbDevFreeHandle(OSBbUsbHandle h)
{
bzero((void *)h, sizeof (_usb_ext_handle));
return(0);
}
/*
* Called from the host detach callback routine when a device is
* disconnected. Subsequent calls using any handles for the
* host will get ENXIO.
*/
void
__usbInvalidateHandles(s32 which)
{
int i;
if (which < 0 || which >= OS_USB_MAX_CONTROLLERS) {
PRINTF("osBbUsbDevGetHandle called with bad arg %d\n", which);
return;
}
for (i = 0; i < OS_USB_MAX_HANDLES; i++) {
/*
* Find handles for the given host and clear them
*/
if (_usb_ext_handles[i].uh_host_handle == __osArcHostHandle[which]) {
_usb_ext_handles[i].uh_host_handle = NULL;
}
}
}