Changeset 8b71f3e in mainline for uspace/drv/bus/usb/usbhub/usbhub.c


Ignore:
Timestamp:
2018-01-14T21:16:03Z (6 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
17c1d9db
Parents:
edc51615
git-author:
Petr Manek <petr.manek@…> (2018-01-14 21:16:00)
git-committer:
Petr Manek <petr.manek@…> (2018-01-14 21:16:03)
Message:

usbdev: refactor polling more

For clarity, the opaque usb_device_polling_t and its complementary
configuration data structure usb_device_polling_config_t have been
merged into usb_polling_t. All related methods have dropped the
"device" from their prefix as well.

The usage semantics have transitioned to malloc-free model, where the
user is entirely responsible for (de)allocation of the polling structure
and its data buffer, and (de)initialization happens in designated
functions during its lifetime in the system.

In addition, the distinction between mandatory / optional / internal
parameters has been documented. Optional parameters now have default
values, which are set to sensible constants in order to allow dropping
some lines in USB driver implementations.

The drivers usbhid and usbhub were refactored to match the API
changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/usbhub.c

    redc51615 r8b71f3e  
    161161
    162162        /* Start hub operation. */
    163         const usb_device_polling_config_t config = {
    164                 .debug = 1,
    165                 .auto_clear_halt = true,
    166                 .delay = -1,
    167                 .max_failures = 3,
    168                 .on_data = hub_port_changes_callback,
    169                 .on_polling_end = usb_hub_polling_terminated_callback,
    170                 .on_error = usb_hub_polling_error_callback,
    171                 .arg = hub_dev,
    172         };
    173 
    174         usb_endpoint_mapping_t *epm =
    175             usb_device_get_mapped_ep_desc(hub_dev->usb_device,
     163        usb_polling_t *polling = &hub_dev->polling;
     164        opResult = usb_polling_init(polling);
     165        if (opResult != EOK) {
     166                ddf_fun_unbind(hub_dev->hub_fun);
     167                ddf_fun_destroy(hub_dev->hub_fun);
     168                usb_log_error("Failed to initialize polling fibril: %s.\n",
     169                    str_error(opResult));
     170                return opResult;
     171        }
     172
     173        polling->device = hub_dev->usb_device;
     174        polling->ep_mapping = usb_device_get_mapped_ep_desc(hub_dev->usb_device,
    176175            &hub_status_change_endpoint_description);
    177         opResult = usb_device_poll(hub_dev->usb_device, epm, &config,
    178             ((hub_dev->port_count + 1 + 7) / 8), &hub_dev->polling);
    179        
     176        polling->request_size = ((hub_dev->port_count + 1 + 7) / 8);
     177        polling->buffer = malloc(polling->request_size);
     178        polling->on_data = hub_port_changes_callback;
     179        polling->on_polling_end = usb_hub_polling_terminated_callback;
     180        polling->on_error = usb_hub_polling_error_callback;
     181        polling->arg = hub_dev;
     182
     183        opResult = usb_polling_start(polling);
    180184        if (opResult != EOK) {
    181185                /* Function is already bound */
     186                free(polling->buffer);
    182187                ddf_fun_unbind(hub_dev->hub_fun);
    183188                ddf_fun_destroy(hub_dev->hub_fun);
     
    186191                return opResult;
    187192        }
     193
    188194        hub_dev->running = true;
    189195        usb_log_info("Controlling hub '%s' (%p: %zu ports).\n",
     
    197203{
    198204        assert(!hub->running);
     205
     206        free(hub->polling.buffer);
     207        usb_polling_fini(&hub->polling);
    199208
    200209        for (size_t port = 0; port < hub->port_count; ++port) {
     
    233242        usb_log_info("(%p) USB hub removed, joining polling fibril.", hub);
    234243
    235         /* Join polling fibril. */
    236         usb_device_poll_join(hub->polling);
     244        /* Join polling fibril (ignoring error code). */
     245        usb_polling_join(&hub->polling);
    237246        usb_log_info("(%p) USB hub polling stopped, freeing memory.", hub);
    238247
     
    254263        usb_log_info("(%p) USB hub gone, joining polling fibril.", hub);
    255264
    256         /* Join polling fibril. */
    257         usb_device_poll_join(hub->polling);
     265        /* Join polling fibril (ignoring error code). */
     266        usb_polling_join(&hub->polling);
    258267        usb_log_info("(%p) USB hub polling stopped, freeing memory.", hub);
    259268
Note: See TracChangeset for help on using the changeset viewer.