2 ** Copyright 2003, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
6 #include <kernel/kernel.h>
7 #include <kernel/debug.h>
8 #include <kernel/lock.h>
9 #include <kernel/module.h>
10 #include <kernel/heap.h>
11 #include <kernel/thread.h>
14 #include <kernel/bus/usb/usb.h>
15 #include <kernel/bus/usb/usb_hc.h>
18 #define debug_level_flow 10
19 #define debug_level_error 10
20 #define debug_level_info 10
22 #define DEBUG_MSG_PREFIX "USB - "
24 #include <kernel/debug_ext.h>
29 hc_init_callback(void *hooks
, void *hc_cookie
)
33 SHOW_FLOW(1, "cookie %p", hc_cookie
);
35 hc
= (usb_hc
*)kmalloc(sizeof(usb_hc
));
39 memset(hc
, 0, sizeof(*hc
));
42 hc
->hc_cookie
= hc_cookie
;
44 // add it to the list of host controllers
45 hc
->next
= usb
->hc_list
;
48 // create an enumerator thread
49 hc
->enumerator_thread
= thread_create_kernel_thread("usb bus enumerator", &usb_enumerator_thread
, hc
);
50 thread_set_priority(hc
->enumerator_thread
, THREAD_MIN_RT_PRIORITY
);
51 thread_resume_thread(hc
->enumerator_thread
);
59 char module_name
[SYS_MAX_PATH_LEN
];
61 modules_cookie cookie
;
62 struct usb_hc_module_hooks
*hooks
;
66 // scan through the host controller module dir and load all of them
67 cookie
= module_open_list(USB_HC_MODULE_NAME_PREFIX
);
68 bufsize
= sizeof(module_name
);
69 while(read_next_module_name(cookie
, module_name
, &bufsize
) >= NO_ERROR
) {
70 bufsize
= sizeof(module_name
); // reset this for the next iteration
72 err
= module_get(module_name
, 0, (void **)&hooks
);
76 err
= hooks
->init_hc(&hc_init_callback
, hooks
);
78 module_put(module_name
); // it failed, put it away
83 close_module_list(cookie
);
91 usb
= kmalloc(sizeof(usb_bus
));
101 usb_module_uninit(void)
106 static struct usb_module_hooks usb_hooks
= {
110 static module_header usb_module_header
= {
119 module_header
*modules
[] = {