Changeset d369b3b in mainline
- Timestamp:
- 2018-01-25T02:05:57Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 296d22fc
- Parents:
- b357377
- git-author:
- Ondřej Hlavatý <aearsis@…> (2018-01-25 01:52:13)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2018-01-25 02:05:57)
- Location:
- uspace
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/ehci_bus.c
rb357377 rd369b3b 57 57 } 58 58 59 static int ehci_device_enumerate(device_t *dev) 60 { 61 ehci_bus_t *bus = (ehci_bus_t *) dev->bus; 62 return usb2_bus_device_enumerate(&bus->helper, dev); 63 } 59 64 60 65 /** Creates new hcd endpoint representation. … … 101 106 ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep); 102 107 103 const int err = usb2_bus_ ops.endpoint_register(ep);108 const int err = usb2_bus_endpoint_register(&bus->helper, ep); 104 109 if (err) 105 110 return err; … … 119 124 assert(ep); 120 125 121 usb2_bus_ ops.endpoint_unregister(ep);126 usb2_bus_endpoint_unregister(&bus->helper, ep); 122 127 hc_dequeue_endpoint(hc, ep); 123 128 /* … … 154 159 155 160 static const bus_ops_t ehci_bus_ops = { 156 .parent = &usb2_bus_ops,157 158 161 .interrupt = ehci_hc_interrupt, 159 162 .status = ehci_hc_status, 163 164 .device_enumerate = ehci_device_enumerate, 160 165 161 166 .endpoint_destroy = ehci_endpoint_destroy, … … 174 179 assert(bus); 175 180 176 usb2_bus_t *usb2_bus = (usb2_bus_t *) bus;177 181 bus_t *bus_base = (bus_t *) bus; 182 bus_init(bus_base, sizeof(device_t)); 183 bus_base->ops = &ehci_bus_ops; 178 184 179 usb2_bus_init(usb2_bus, &bandwidth_accounting_usb2); 180 bus_base->ops = &ehci_bus_ops; 185 usb2_bus_helper_init(&bus->helper, &bandwidth_accounting_usb2); 181 186 182 187 bus->hc = hc; -
uspace/drv/bus/usb/ehci/ehci_bus.h
rb357377 rd369b3b 64 64 65 65 typedef struct { 66 usb2_bus_t base; 66 bus_t base; 67 usb2_bus_helper_t helper; 67 68 hc_t *hc; 68 69 } ehci_bus_t; -
uspace/drv/bus/usb/ohci/ohci_bus.c
rb357377 rd369b3b 57 57 } 58 58 59 static int ohci_device_enumerate(device_t *dev) 60 { 61 ohci_bus_t *bus = (ohci_bus_t *) dev->bus; 62 return usb2_bus_device_enumerate(&bus->helper, dev); 63 } 64 59 65 /** Creates new hcd endpoint representation. 60 66 */ … … 109 115 ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep); 110 116 111 const int err = usb2_bus_ ops.endpoint_register(ep);117 const int err = usb2_bus_endpoint_register(&bus->helper, ep); 112 118 if (err) 113 119 return err; … … 126 132 assert(ep); 127 133 128 usb2_bus_ ops.endpoint_unregister(ep);134 usb2_bus_endpoint_unregister(&bus->helper, ep); 129 135 hc_dequeue_endpoint(bus->hc, ep); 130 136 … … 162 168 163 169 static const bus_ops_t ohci_bus_ops = { 164 .parent = &usb2_bus_ops,165 166 170 .interrupt = ohci_hc_interrupt, 167 171 .status = ohci_hc_status, 172 173 .device_enumerate = ohci_device_enumerate, 168 174 169 175 .endpoint_destroy = ohci_endpoint_destroy, … … 183 189 assert(bus); 184 190 185 usb2_bus_t *usb2_bus = (usb2_bus_t *) bus;186 191 bus_t *bus_base = (bus_t *) bus; 187 188 usb2_bus_init(usb2_bus, &bandwidth_accounting_usb11); 192 bus_init(bus_base, sizeof(device_t)); 189 193 bus_base->ops = &ohci_bus_ops; 194 195 usb2_bus_helper_init(&bus->helper, &bandwidth_accounting_usb11); 190 196 191 197 bus->hc = hc; -
uspace/drv/bus/usb/ohci/ohci_bus.h
rb357377 rd369b3b 60 60 61 61 typedef struct { 62 usb2_bus_t base; 62 bus_t base; 63 usb2_bus_helper_t helper; 63 64 hc_t *hc; 64 65 } ohci_bus_t; -
uspace/drv/bus/usb/uhci/hc.c
rb357377 rd369b3b 329 329 hc_t * const hc = bus_to_hc(endpoint_get_bus(ep)); 330 330 331 const int err = usb2_bus_ ops.endpoint_register(ep);331 const int err = usb2_bus_endpoint_register(&hc->bus_helper, ep); 332 332 if (err) 333 333 return err; … … 350 350 { 351 351 hc_t * const hc = bus_to_hc(endpoint_get_bus(ep)); 352 usb2_bus_ ops.endpoint_unregister(ep);352 usb2_bus_endpoint_unregister(&hc->bus_helper, ep); 353 353 354 354 // Check for the roothub, as it does not schedule into lists … … 406 406 } 407 407 408 static int device_enumerate(device_t *dev) 409 { 410 hc_t * const hc = bus_to_hc(dev->bus); 411 return usb2_bus_device_enumerate(&hc->bus_helper, dev); 412 } 413 408 414 static int hc_status(bus_t *, uint32_t *); 409 415 static int hc_schedule(usb_transfer_batch_t *); 410 416 411 417 static const bus_ops_t uhci_bus_ops = { 412 .parent = &usb2_bus_ops,413 414 418 .interrupt = hc_interrupt, 415 419 .status = hc_status, 420 421 .device_enumerate = device_enumerate, 416 422 417 423 .endpoint_create = endpoint_create, … … 438 444 assert(instance); 439 445 440 usb2_bus_ init(&instance->bus, &bandwidth_accounting_usb11);441 442 bus_ t *bus = (bus_t *) &instance->bus;443 bus->ops = &uhci_bus_ops;444 445 hc_device_setup(&instance->base, bus);446 usb2_bus_helper_init(&instance->bus_helper, &bandwidth_accounting_usb11); 447 448 bus_init(&instance->bus, sizeof(device_t)); 449 instance->bus.ops = &uhci_bus_ops; 450 451 hc_device_setup(&instance->base, &instance->bus); 446 452 447 453 /* Init USB frame list page */ -
uspace/drv/bus/usb/uhci/hc.h
rb357377 rd369b3b 104 104 105 105 uhci_rh_t rh; 106 usb2_bus_t bus; 106 bus_t bus; 107 usb2_bus_helper_t bus_helper; 108 107 109 /** Addresses of I/O registers */ 108 110 uhci_regs_t *registers; -
uspace/drv/bus/usb/vhc/transfer.c
rb357377 rd369b3b 163 163 } 164 164 165 static int device_enumerate(device_t *device) 166 { 167 vhc_data_t *vhc = bus_to_vhc(device->bus); 168 return usb2_bus_device_enumerate(&vhc->bus_helper, device); 169 } 170 171 static int endpoint_register(endpoint_t *endpoint) 172 { 173 vhc_data_t *vhc = bus_to_vhc(endpoint->device->bus); 174 return usb2_bus_endpoint_register(&vhc->bus_helper, endpoint); 175 } 176 177 static void endpoint_unregister(endpoint_t *endpoint) 178 { 179 vhc_data_t *vhc = bus_to_vhc(endpoint->device->bus); 180 usb2_bus_endpoint_unregister(&vhc->bus_helper, endpoint); 181 182 // TODO: abort transfer? 183 } 184 165 185 static const bus_ops_t vhc_bus_ops = { 166 .parent = &usb2_bus_ops,167 168 186 .batch_create = batch_create, 169 187 .batch_schedule = vhc_schedule, 188 189 .device_enumerate = device_enumerate, 190 .endpoint_register = endpoint_register, 191 .endpoint_unregister = endpoint_unregister, 170 192 }; 171 193 … … 175 197 list_initialize(&instance->devices); 176 198 fibril_mutex_initialize(&instance->guard); 177 usb2_bus_init(&instance->bus, &bandwidth_accounting_usb11); 178 instance->bus.base.ops = &vhc_bus_ops; 199 bus_init(&instance->bus, sizeof(device_t)); 200 usb2_bus_helper_init(&instance->bus_helper, &bandwidth_accounting_usb11); 201 instance->bus.ops = &vhc_bus_ops; 179 202 return virthub_init(&instance->hub, "root hub"); 180 203 } -
uspace/drv/bus/usb/vhc/vhcd.h
rb357377 rd369b3b 60 60 hc_device_t base; 61 61 62 usb2_bus_t bus; 62 bus_t bus; 63 usb2_bus_helper_t bus_helper; 64 63 65 ddf_fun_t *virtual_fun; 64 66 list_t devices; -
uspace/lib/usbhost/include/usb/host/usb2_bus.h
rb357377 rd369b3b 47 47 typedef struct endpoint endpoint_t; 48 48 49 /** Endpoint management structure */ 50 typedef struct usb2_bus { 51 bus_t base; /**< Inheritance - keep this first */ 52 49 /** Endpoint and bandwidth management structure */ 50 typedef struct usb2_bus_helper { 53 51 /** Map of occupied addresses */ 54 52 bool address_occupied [USB_ADDRESS_COUNT]; … … 61 59 /* Configured bandwidth accounting */ 62 60 const bandwidth_accounting_t *bw_accounting; 63 } usb2_bus_ t;61 } usb2_bus_helper_t; 64 62 65 extern const bus_ops_t usb2_bus_ops;63 extern void usb2_bus_helper_init(usb2_bus_helper_t *, const bandwidth_accounting_t *); 66 64 67 extern void usb2_bus_init(usb2_bus_t *, const bandwidth_accounting_t *); 65 extern int usb2_bus_device_enumerate(usb2_bus_helper_t *, device_t *); 66 extern int usb2_bus_endpoint_register(usb2_bus_helper_t *, endpoint_t *); 67 extern void usb2_bus_endpoint_unregister(usb2_bus_helper_t *, endpoint_t *); 68 68 69 69 #endif -
uspace/lib/usbhost/src/usb2_bus.c
rb357377 rd369b3b 54 54 55 55 /** 56 * Ops receive generic bus_t pointer.57 */58 static inline usb2_bus_t *bus_to_usb2_bus(bus_t *bus_base)59 {60 assert(bus_base);61 return (usb2_bus_t *) bus_base;62 }63 64 /**65 56 * Request a new address. A free address is found and marked as occupied. 66 57 * … … 71 62 * @param addr Pointer to requested address value, place to store new address 72 63 */ 73 static int request_address(usb2_bus_ t *bus, usb_address_t *addr)64 static int request_address(usb2_bus_helper_t *helper, usb_address_t *addr) 74 65 { 75 66 // Find a free address 76 usb_address_t new_address = bus->last_address;67 usb_address_t new_address = helper->last_address; 77 68 do { 78 69 new_address = (new_address + 1) % USB_ADDRESS_COUNT; 79 70 if (new_address == USB_ADDRESS_DEFAULT) 80 71 new_address = 1; 81 if (new_address == bus->last_address)72 if (new_address == helper->last_address) 82 73 return ENOSPC; 83 } while ( bus->address_occupied[new_address]);84 bus->last_address = new_address;74 } while (helper->address_occupied[new_address]); 75 helper->last_address = new_address; 85 76 86 77 *addr = new_address; 87 bus->address_occupied[*addr] = true;78 helper->address_occupied[*addr] = true; 88 79 89 80 return EOK; … … 93 84 * Mark address as free. 94 85 */ 95 static void release_address(usb2_bus_ t *bus, usb_address_t address)96 { 97 bus->address_occupied[address] = false;86 static void release_address(usb2_bus_helper_t *helper, usb_address_t address) 87 { 88 helper->address_occupied[address] = false; 98 89 } 99 90 … … 109 100 * Configure the device with the new address, 110 101 */ 111 static int address_device( device_t *dev)102 static int address_device(usb2_bus_helper_t *helper, device_t *dev) 112 103 { 113 104 int err; 114 115 usb2_bus_t *bus = (usb2_bus_t *) dev->bus;116 105 117 106 /* The default address is currently reserved for this device */ … … 120 109 /** Reserve address early, we want pretty log messages */ 121 110 usb_address_t address = USB_ADDRESS_DEFAULT; 122 if ((err = request_address( bus, &address))) {111 if ((err = request_address(helper, &address))) { 123 112 usb_log_error("Failed to reserve new address: %s.", 124 113 str_error(err)); … … 141 130 } 142 131 143 if ((err = hc_get_ep0_max_packet_size(&ep0_desc.endpoint.max_packet_size, &bus->base, dev)))132 if ((err = hc_get_ep0_max_packet_size(&ep0_desc.endpoint.max_packet_size, dev->bus, dev))) 144 133 goto err_address; 145 134 … … 178 167 bus_endpoint_remove(default_ep); 179 168 err_address: 180 release_address( bus, address);169 release_address(helper, address); 181 170 return err; 182 171 } … … 186 175 * to create a DDF function node with proper characteristics. 187 176 */ 188 static int usb2_bus_device_enumerate(device_t *dev)177 int usb2_bus_device_enumerate(usb2_bus_helper_t *helper, device_t *dev) 189 178 { 190 179 int err; 191 usb2_bus_t *bus = bus_to_usb2_bus(dev->bus);192 193 180 usb_log_debug("Found new %s speed USB device.", usb_str_speed(dev->speed)); 194 181 195 182 /* Assign an address to the device */ 196 if ((err = address_device( dev))) {183 if ((err = address_device(helper, dev))) { 197 184 usb_log_error("Failed to setup address of the new device: %s", str_error(err)); 198 185 return err; … … 202 189 if ((err = hc_device_explore(dev))) { 203 190 usb_log_error("Device(%d): Failed to explore device: %s", dev->address, str_error(err)); 204 release_address( bus, dev->address);191 release_address(helper, dev->address); 205 192 return err; 206 193 } … … 210 197 211 198 /** 212 * Call the bus operation to count bandwidth. 213 * 214 * @param ep Endpoint on which the transfer will take place. 215 * @param size The payload size. 216 */ 217 static ssize_t endpoint_count_bw(endpoint_t *ep) 199 * Register an endpoint to the bus. Reserves bandwidth. 200 */ 201 int usb2_bus_endpoint_register(usb2_bus_helper_t *helper, endpoint_t *ep) 218 202 { 219 203 assert(ep); 220 221 usb2_bus_t *bus = bus_to_usb2_bus(ep->device->bus);222 223 return bus->bw_accounting->count_bw(ep);224 }225 226 /**227 * Register an endpoint to the bus. Reserves bandwidth.228 */229 static int usb2_bus_register_ep(endpoint_t *ep)230 {231 usb2_bus_t *bus = bus_to_usb2_bus(ep->device->bus);232 204 assert(fibril_mutex_is_locked(&ep->device->guard)); 205 206 size_t bw = helper->bw_accounting->count_bw(ep); 207 208 /* Check for available bandwidth */ 209 if (bw > helper->free_bw) 210 return ENOSPC; 211 212 helper->free_bw -= bw; 213 214 return EOK; 215 } 216 217 /** 218 * Release bandwidth reserved by the given endpoint. 219 */ 220 void usb2_bus_endpoint_unregister(usb2_bus_helper_t *helper, endpoint_t *ep) 221 { 222 assert(helper); 233 223 assert(ep); 234 224 235 size_t bw = endpoint_count_bw(ep); 236 237 /* Check for available bandwidth */ 238 if (bw > bus->free_bw) 239 return ENOSPC; 240 241 bus->free_bw -= bw; 242 243 return EOK; 244 } 245 246 /** 247 * Release bandwidth reserved by the given endpoint. 248 */ 249 static void usb2_bus_unregister_ep(endpoint_t *ep) 250 { 251 usb2_bus_t *bus = bus_to_usb2_bus(ep->device->bus); 252 assert(ep); 253 254 bus->free_bw += endpoint_count_bw(ep); 255 } 256 257 const bus_ops_t usb2_bus_ops = { 258 .device_enumerate = usb2_bus_device_enumerate, 259 .endpoint_register = usb2_bus_register_ep, 260 .endpoint_unregister = usb2_bus_unregister_ep, 261 }; 262 263 /** Initialize to default state. 264 * 265 * @param bus usb_bus structure, non-null. 266 * @param available_bandwidth Size of the bandwidth pool. 267 */ 268 void usb2_bus_init(usb2_bus_t *bus, const bandwidth_accounting_t *bw_accounting) 269 { 270 assert(bus); 225 helper->free_bw += helper->bw_accounting->count_bw(ep); 226 } 227 228 /** 229 * Initialize to default state. 230 * 231 * @param helper usb_bus_helper structure, non-null. 232 * @param bw_accounting a structure defining bandwidth accounting 233 */ 234 void usb2_bus_helper_init(usb2_bus_helper_t *helper, const bandwidth_accounting_t *bw_accounting) 235 { 236 assert(helper); 271 237 assert(bw_accounting); 272 238 273 bus_init(&bus->base, sizeof(device_t)); 274 bus->base.ops = &usb2_bus_ops; 275 276 bus->bw_accounting = bw_accounting; 277 bus->free_bw = bw_accounting->available_bandwidth; 239 helper->bw_accounting = bw_accounting; 240 helper->free_bw = bw_accounting->available_bandwidth; 278 241 279 242 /* … … 282 245 * address 1. 283 246 */ 284 bus->last_address = USB_ADDRESS_COUNT - 2;247 helper->last_address = USB_ADDRESS_COUNT - 2; 285 248 } 286 249
Note:
See TracChangeset
for help on using the changeset viewer.