Changeset 54b141a in mainline for uspace/drv
- Timestamp:
- 2010-12-04T17:01:24Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/fix-logger-deadlock, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e28d228
- Parents:
- 2cb6571 (diff), ad104e0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/drv
- Files:
-
- 7 added
- 8 edited
- 1 moved
-
uhci/Makefile (modified) (1 diff)
-
uhci/main.c (modified) (3 diffs)
-
uhci/transfers.c (added)
-
uhci/uhci.h (added)
-
uhci/uhci.ma (modified) (1 diff)
-
usbhub/Makefile (added)
-
usbhub/main.c (added)
-
usbhub/usbhub.h (added)
-
usbhub/usbhub.ma (added)
-
usbhub/utils.c (moved) (moved from uspace/lib/usb/src/hubdrv.c ) (7 diffs)
-
vhc/Makefile (modified) (1 diff)
-
vhc/addrmgm.c (added)
-
vhc/conn.h (modified) (2 diffs)
-
vhc/connhost.c (modified) (7 diffs)
-
vhc/hcd.c (modified) (4 diffs)
-
vhc/vhc.ma (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci/Makefile
r2cb6571 r54b141a 33 33 34 34 SOURCES = \ 35 main.c 35 main.c \ 36 transfers.c 36 37 37 38 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/uhci/main.c
r2cb6571 r54b141a 28 28 #include <usb/hcdhubd.h> 29 29 #include <errno.h> 30 #include "uhci.h" 30 31 31 static int enqueue_transfer_out(usb_hc_device_t *hc, 32 usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint, 33 void *buffer, size_t size, 34 usb_hcd_transfer_callback_out_t callback, void *arg) 35 { 36 printf("UHCI: transfer OUT [%d.%d (%s); %u]\n", 37 dev->address, endpoint->endpoint, 38 usb_str_transfer_type(endpoint->transfer_type), 39 size); 40 return ENOTSUP; 41 } 42 43 static int enqueue_transfer_setup(usb_hc_device_t *hc, 44 usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint, 45 void *buffer, size_t size, 46 usb_hcd_transfer_callback_out_t callback, void *arg) 47 { 48 printf("UHCI: transfer SETUP [%d.%d (%s); %u]\n", 49 dev->address, endpoint->endpoint, 50 usb_str_transfer_type(endpoint->transfer_type), 51 size); 52 return ENOTSUP; 53 } 54 55 static int enqueue_transfer_in(usb_hc_device_t *hc, 56 usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint, 57 void *buffer, size_t size, 58 usb_hcd_transfer_callback_in_t callback, void *arg) 59 { 60 printf("UHCI: transfer IN [%d.%d (%s); %u]\n", 61 dev->address, endpoint->endpoint, 62 usb_str_transfer_type(endpoint->transfer_type), 63 size); 64 return ENOTSUP; 65 } 66 67 static usb_hcd_transfer_ops_t uhci_transfer_ops = { 68 .transfer_out = enqueue_transfer_out, 69 .transfer_in = enqueue_transfer_in, 70 .transfer_setup = enqueue_transfer_setup 32 static device_ops_t uhci_ops = { 33 .interfaces[USBHC_DEV_IFACE] = &uhci_iface, 71 34 }; 72 35 73 static int uhci_add_ hc(usb_hc_device_t *device)36 static int uhci_add_device(device_t *device) 74 37 { 75 device-> transfer_ops = &uhci_transfer_ops;38 device->ops = &uhci_ops; 76 39 77 40 /* … … 83 46 } 84 47 85 usb_hc_driver_t uhci_driver = { 86 .name = "uhci", 87 .add_hc = uhci_add_hc 48 static driver_ops_t uhci_driver_ops = { 49 .add_device = uhci_add_device, 50 }; 51 52 static driver_t uhci_driver = { 53 .name = NAME, 54 .driver_ops = &uhci_driver_ops 88 55 }; 89 56 … … 93 60 * Do some global initializations. 94 61 */ 62 sleep(5); 95 63 96 return usb_hcd_main(&uhci_driver);64 return driver_main(&uhci_driver); 97 65 } -
uspace/drv/uhci/uhci.ma
r2cb6571 r54b141a 1 1 10 pci/ven=8086&dev=7020 2 10 usb&hc=uhci 3 10 usb&hc=uhci&hub 2 -
uspace/drv/usbhub/utils.c
r2cb6571 r54b141a 33 33 * @brief Hub driver. 34 34 */ 35 #include < usb/hcdhubd.h>35 #include <driver.h> 36 36 #include <usb/devreq.h> 37 37 #include <usbhc_iface.h> 38 #include <usb/usbdrv.h> 38 39 #include <usb/descriptor.h> 39 40 #include <driver.h> … … 41 42 #include <errno.h> 42 43 #include <usb/classes/hub.h> 43 #include " hcdhubd_private.h"44 #include "usbhub.h" 44 45 45 46 static void check_hub_changes(void); … … 108 109 //********************************************* 109 110 110 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address);111 112 111 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) { 113 112 usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t)); 114 //get parent device115 device_t * my_hcd = device;116 while (my_hcd->parent)117 my_hcd = my_hcd->parent;118 //dev->119 printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);120 //we add the hub into the first hc121 //link_t *link_hc = hc_list.next;122 //usb_hc_device_t *hc = list_get_instance(link_hc,123 // usb_hc_device_t, link);124 //must get generic device info125 126 113 127 114 return result; … … 134 121 */ 135 122 int usb_add_hub_device(device_t *dev) { 136 //usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link); 137 assert(dev->parent); 138 usb_hc_device_t *hc = (usb_hc_device_t*)dev->parent->driver_data; 139 usb_address_t addr =usb_use_free_address(hc); 140 if(addr<0){ 141 printf("[hcdhubd] ERROR: cannot find an address \n"); 142 } 143 set_hub_address(hc, addr); 123 printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle); 144 124 145 125 check_hub_changes(); … … 150 130 * connected devices. 151 131 */ 152 //insert hub into list153 //find owner hcd154 device_t * my_hcd = dev;155 while (my_hcd->parent)156 my_hcd = my_hcd->parent;157 //dev->158 printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);159 my_hcd = dev;160 while (my_hcd->parent)161 my_hcd = my_hcd->parent;162 //dev->163 164 printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);165 132 166 133 //create the hub structure 167 134 usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev); 168 169 170 //append into the list 171 //we add the hub into the first hc 172 list_append(&hub_info->link, &hc->hubs); 173 174 135 (void)hub_info; 175 136 176 137 return EOK; … … 178 139 } 179 140 180 /** Sample usage of usb_hc_async functions.181 * This function sets hub address using standard SET_ADDRESS request.182 *183 * @warning This function shall be removed once you are familiar with184 * the usb_hc_ API.185 *186 * @param hc Host controller the hub belongs to.187 * @param address New hub address.188 */189 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) {190 printf("[hcdhubd]%s: setting hub address to %d\n", hc->generic->name, address);191 usb_target_t target = {0, 0};192 usb_handle_t handle;193 int rc;194 195 usb_device_request_setup_packet_t setup_packet = {196 .request_type = 0,197 .request = USB_DEVREQ_SET_ADDRESS,198 .index = 0,199 .length = 0,200 };201 setup_packet.value = address;202 203 rc = usb_hc_async_control_write_setup(hc, target,204 &setup_packet, sizeof (setup_packet), &handle);205 if (rc != EOK) {206 return;207 }208 209 rc = usb_hc_async_wait_for(handle);210 if (rc != EOK) {211 return;212 }213 214 rc = usb_hc_async_control_write_status(hc, target, &handle);215 if (rc != EOK) {216 return;217 }218 219 rc = usb_hc_async_wait_for(handle);220 if (rc != EOK) {221 return;222 }223 224 printf("[hcdhubd]%s: hub address changed successfully to %d\n",225 hc->generic->name, address);226 }227 141 228 142 /** Check changes on all known hubs. … … 230 144 static void check_hub_changes(void) { 231 145 /* 232 * Iterate through all HCs.146 * Iterate through all hubs. 233 147 */ 234 link_t *link_hc; 235 for (link_hc = hc_list.next; 236 link_hc != &hc_list; 237 link_hc = link_hc->next) { 238 usb_hc_device_t *hc = list_get_instance(link_hc, 239 usb_hc_device_t, link); 148 for (; false; ) { 240 149 /* 241 * Iterate through all their hubs.150 * Check status change pipe of this hub. 242 151 */ 243 link_t *link_hub; 244 for (link_hub = hc->hubs.next; 245 link_hub != &hc->hubs; 246 link_hub = link_hub->next) { 247 usb_hcd_hub_info_t *hub = list_get_instance(link_hub, 248 usb_hcd_hub_info_t, link); 152 usb_target_t target = { 153 .address = 5, 154 .endpoint = 1 155 }; 249 156 250 /* 251 * Check status change pipe of this hub. 252 */ 253 usb_target_t target = { 254 .address = hub->device->address, 255 .endpoint = 1 256 }; 157 size_t port_count = 7; 257 158 258 // FIXME: count properly 259 size_t byte_length = (hub->port_count / 8) + 1; 159 /* 160 * Connect to respective HC. 161 */ 162 int hc = usb_drv_hc_connect(NULL, 0); 163 if (hc < 0) { 164 continue; 165 } 260 166 261 void *change_bitmap = malloc(byte_length); 262 size_t actual_size; 263 usb_handle_t handle; 167 // FIXME: count properly 168 size_t byte_length = (port_count / 8) + 1; 264 169 265 /* 266 * Send the request. 267 * FIXME: check returned value for possible errors 268 */ 269 usb_hc_async_interrupt_in(hc, target, 270 change_bitmap, byte_length, &actual_size, 271 &handle); 170 void *change_bitmap = malloc(byte_length); 171 size_t actual_size; 172 usb_handle_t handle; 272 173 273 usb_hc_async_wait_for(handle); 174 /* 175 * Send the request. 176 * FIXME: check returned value for possible errors 177 */ 178 usb_drv_async_interrupt_in(hc, target, 179 change_bitmap, byte_length, &actual_size, 180 &handle); 274 181 275 /* 276 * TODO: handle the changes. 277 */ 278 } 182 usb_drv_async_wait_for(handle); 183 184 /* 185 * TODO: handle the changes. 186 */ 187 188 189 /* 190 * Hang-up the HC-connected phone. 191 */ 192 ipc_hangup(hc); 279 193 } 280 194 } -
uspace/drv/vhc/Makefile
r2cb6571 r54b141a 39 39 40 40 SOURCES = \ 41 addrmgm.c \ 41 42 conndev.c \ 42 43 connhost.c \ -
uspace/drv/vhc/conn.h
r2cb6571 r54b141a 38 38 #include <usb/usb.h> 39 39 #include <usb/hcdhubd.h> 40 #include <usbhc_iface.h> 40 41 #include "vhcd.h" 41 42 #include "devices.h" … … 44 45 45 46 usb_hcd_transfer_ops_t vhc_transfer_ops; 47 usbhc_iface_t vhc_iface; 48 49 void address_init(void); 50 int reserve_default_address(device_t *); 51 int release_default_address(device_t *); 52 int request_address(device_t *, usb_address_t *); 53 int release_address(device_t *, usb_address_t); 54 46 55 47 56 void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *); -
uspace/drv/vhc/connhost.c
r2cb6571 r54b141a 43 43 typedef struct { 44 44 usb_direction_t direction; 45 usb _hcd_transfer_callback_out_t out_callback;46 usb _hcd_transfer_callback_in_t in_callback;47 usb_hc_device_t *hc;45 usbhc_iface_transfer_out_callback_t out_callback; 46 usbhc_iface_transfer_in_callback_t in_callback; 47 device_t *dev; 48 48 void *arg; 49 49 } transfer_info_t; … … 56 56 switch (transfer->direction) { 57 57 case USB_DIRECTION_IN: 58 transfer->in_callback(transfer-> hc,58 transfer->in_callback(transfer->dev, 59 59 size, outcome, 60 60 transfer->arg); 61 61 break; 62 62 case USB_DIRECTION_OUT: 63 transfer->out_callback(transfer-> hc,63 transfer->out_callback(transfer->dev, 64 64 outcome, 65 65 transfer->arg); … … 73 73 } 74 74 75 static transfer_info_t *create_transfer_info( usb_hc_device_t *hc,75 static transfer_info_t *create_transfer_info(device_t *dev, 76 76 usb_direction_t direction, void *arg) 77 77 { … … 82 82 transfer->out_callback = NULL; 83 83 transfer->arg = arg; 84 transfer-> hc = hc;84 transfer->dev = dev; 85 85 86 86 return transfer; 87 87 } 88 88 89 static int enqueue_transfer_out( usb_hc_device_t *hc,90 usb_ hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,89 static int enqueue_transfer_out(device_t *dev, 90 usb_target_t target, usb_transfer_type_t transfer_type, 91 91 void *buffer, size_t size, 92 usb _hcd_transfer_callback_out_t callback, void *arg)92 usbhc_iface_transfer_out_callback_t callback, void *arg) 93 93 { 94 94 printf(NAME ": transfer OUT [%d.%d (%s); %u]\n", 95 dev->address, endpoint->endpoint,96 usb_str_transfer_type( endpoint->transfer_type),95 target.address, target.endpoint, 96 usb_str_transfer_type(transfer_type), 97 97 size); 98 98 99 99 transfer_info_t *transfer 100 = create_transfer_info( hc, USB_DIRECTION_OUT, arg);100 = create_transfer_info(dev, USB_DIRECTION_OUT, arg); 101 101 transfer->out_callback = callback; 102 103 usb_target_t target = {104 .address = dev->address,105 .endpoint = endpoint->endpoint106 };107 102 108 103 hc_add_transaction_to_device(false, target, buffer, size, … … 112 107 } 113 108 114 static int enqueue_transfer_setup( usb_hc_device_t *hc,115 usb_ hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,109 static int enqueue_transfer_setup(device_t *dev, 110 usb_target_t target, usb_transfer_type_t transfer_type, 116 111 void *buffer, size_t size, 117 usb _hcd_transfer_callback_out_t callback, void *arg)112 usbhc_iface_transfer_out_callback_t callback, void *arg) 118 113 { 119 114 printf(NAME ": transfer SETUP [%d.%d (%s); %u]\n", 120 dev->address, endpoint->endpoint,121 usb_str_transfer_type( endpoint->transfer_type),115 target.address, target.endpoint, 116 usb_str_transfer_type(transfer_type), 122 117 size); 123 118 124 119 transfer_info_t *transfer 125 = create_transfer_info( hc, USB_DIRECTION_OUT, arg);120 = create_transfer_info(dev, USB_DIRECTION_OUT, arg); 126 121 transfer->out_callback = callback; 127 128 usb_target_t target = {129 .address = dev->address,130 .endpoint = endpoint->endpoint131 };132 122 133 123 hc_add_transaction_to_device(true, target, buffer, size, … … 137 127 } 138 128 139 static int enqueue_transfer_in( usb_hc_device_t *hc,140 usb_ hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,129 static int enqueue_transfer_in(device_t *dev, 130 usb_target_t target, usb_transfer_type_t transfer_type, 141 131 void *buffer, size_t size, 142 usb _hcd_transfer_callback_in_t callback, void *arg)132 usbhc_iface_transfer_in_callback_t callback, void *arg) 143 133 { 144 134 printf(NAME ": transfer IN [%d.%d (%s); %u]\n", 145 dev->address, endpoint->endpoint,146 usb_str_transfer_type( endpoint->transfer_type),135 target.address, target.endpoint, 136 usb_str_transfer_type(transfer_type), 147 137 size); 148 138 149 139 transfer_info_t *transfer 150 = create_transfer_info( hc, USB_DIRECTION_IN, arg);140 = create_transfer_info(dev, USB_DIRECTION_IN, arg); 151 141 transfer->in_callback = callback; 152 153 usb_target_t target = {154 .address = dev->address,155 .endpoint = endpoint->endpoint156 };157 142 158 143 hc_add_transaction_from_device(target, buffer, size, … … 163 148 164 149 165 usb_hcd_transfer_ops_t vhc_transfer_ops = { 166 .transfer_out = enqueue_transfer_out, 167 .transfer_in = enqueue_transfer_in, 168 .transfer_setup = enqueue_transfer_setup 150 static int get_address(device_t *dev, devman_handle_t handle, 151 usb_address_t *address) 152 { 153 return ENOTSUP; 154 } 155 156 static int interrupt_out(device_t *dev, usb_target_t target, 157 void *data, size_t size, 158 usbhc_iface_transfer_out_callback_t callback, void *arg) 159 { 160 return enqueue_transfer_out(dev, target, USB_TRANSFER_INTERRUPT, 161 data, size, 162 callback, arg); 163 } 164 165 static int interrupt_in(device_t *dev, usb_target_t target, 166 void *data, size_t size, 167 usbhc_iface_transfer_in_callback_t callback, void *arg) 168 { 169 return enqueue_transfer_in(dev, target, USB_TRANSFER_INTERRUPT, 170 data, size, 171 callback, arg); 172 } 173 174 static int control_write_setup(device_t *dev, usb_target_t target, 175 void *data, size_t size, 176 usbhc_iface_transfer_out_callback_t callback, void *arg) 177 { 178 return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL, 179 data, size, 180 callback, arg); 181 } 182 183 static int control_write_data(device_t *dev, usb_target_t target, 184 void *data, size_t size, 185 usbhc_iface_transfer_out_callback_t callback, void *arg) 186 { 187 return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL, 188 data, size, 189 callback, arg); 190 } 191 192 static int control_write_status(device_t *dev, usb_target_t target, 193 usbhc_iface_transfer_in_callback_t callback, void *arg) 194 { 195 return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL, 196 NULL, 0, 197 callback, arg); 198 } 199 200 static int control_read_setup(device_t *dev, usb_target_t target, 201 void *data, size_t size, 202 usbhc_iface_transfer_out_callback_t callback, void *arg) 203 { 204 return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL, 205 data, size, 206 callback, arg); 207 } 208 209 static int control_read_data(device_t *dev, usb_target_t target, 210 void *data, size_t size, 211 usbhc_iface_transfer_in_callback_t callback, void *arg) 212 { 213 return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL, 214 data, size, 215 callback, arg); 216 } 217 218 static int control_read_status(device_t *dev, usb_target_t target, 219 usbhc_iface_transfer_out_callback_t callback, void *arg) 220 { 221 return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL, 222 NULL, 0, 223 callback, arg); 224 } 225 226 227 usbhc_iface_t vhc_iface = { 228 .tell_address = get_address, 229 230 .reserve_default_address = reserve_default_address, 231 .release_default_address = release_default_address, 232 .request_address = request_address, 233 .release_address = release_address, 234 235 .interrupt_out = interrupt_out, 236 .interrupt_in = interrupt_in, 237 238 .control_write_setup = control_write_setup, 239 .control_write_data = control_write_data, 240 .control_write_status = control_write_status, 241 242 .control_read_setup = control_read_setup, 243 .control_read_data = control_read_data, 244 .control_read_status = control_read_status 169 245 }; 170 246 -
uspace/drv/vhc/hcd.c
r2cb6571 r54b141a 52 52 #include "conn.h" 53 53 54 static device_ops_t vhc_ops = { 55 .interfaces[USBHC_DEV_IFACE] = &vhc_iface, 56 .default_handler = default_connection_handler 57 }; 54 58 55 59 static int vhc_count = 0; 56 static int vhc_add_device( usb_hc_device_t *dev)60 static int vhc_add_device(device_t *dev) 57 61 { 58 62 /* … … 65 69 vhc_count++; 66 70 67 dev->transfer_ops = &vhc_transfer_ops; 68 dev->generic->ops->default_handler = default_connection_handler; 71 dev->ops = &vhc_ops; 72 73 /* 74 * Initialize address management. 75 */ 76 address_init(); 69 77 70 78 /* … … 79 87 } 80 88 81 static usb_hc_driver_t vhc_driver = { 89 static driver_ops_t vhc_driver_ops = { 90 .add_device = vhc_add_device, 91 }; 92 93 static driver_t vhc_driver = { 82 94 .name = NAME, 83 . add_hc = &vhc_add_device95 .driver_ops = &vhc_driver_ops 84 96 }; 85 97 … … 114 126 sleep(4); 115 127 116 return usb_hcd_main(&vhc_driver);128 return driver_main(&vhc_driver); 117 129 } 118 130 -
uspace/drv/vhc/vhc.ma
r2cb6571 r54b141a 1 1 10 usb&hc=vhc 2 10 usb&hc=vhc&hub 2
Note:
See TracChangeset
for help on using the changeset viewer.
