Changeset 867b375 in mainline for uspace/drv/bus/usb/xhci/rh.c


Ignore:
Timestamp:
2017-10-15T02:04:10Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
20eaa82
Parents:
d7869d7e
Message:

hcd_ddf_new_device refactoring

This long function is now split into parts. Instead of passing dozens of arguments, it now creates the usb_dev_t right away, and uses that to pass it along. The address_device part is now modifiable by drivers.

There is still a work to be done. The biggest problem I see is in the addressing - currently, there is usb_address_t, and for high speed transaction translating there is another address. For (near) future extensibility, we should pass address as a structure. Or even better, make a way how to reference a device, maybe in a similar way how we work with endpoints.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/rh.c

    rd7869d7e r867b375  
    3838#include <usb/debug.h>
    3939#include <usb/host/utils/malloc32.h>
     40#include <usb/host/ddf_helpers.h>
     41
    4042#include "debug.h"
    4143#include "commands.h"
     
    6971// TODO: Check device deallocation, we free device_ctx in hc.c, not
    7072//       sure about the other structs.
    71 static int alloc_dev(xhci_hc_t *hc, uint8_t port, uint32_t route_str)
     73// TODO: This currently assumes the device is attached to rh directly.
     74//       Also, we should consider moving a lot of functionailty to xhci bus
     75int xhci_rh_address_device(xhci_rh_t *rh, usb_speed_t unused_speed, usb_tt_address_t tt, usb_address_t *address)
    7276{
    7377        int err;
     78        xhci_hc_t *hc = rh->hc;
    7479
    7580        xhci_cmd_t cmd;
    7681        xhci_cmd_init(&cmd);
    7782
    78         const xhci_port_speed_t *speed = xhci_rh_get_port_speed(&hc->rh, port);
     83        uint8_t port = tt.port;
     84
     85        /* XXX Certainly not generic solution. */
     86        uint32_t route_str = 0;
     87
     88        const xhci_port_speed_t *speed = xhci_rh_get_port_speed(rh, port);
    7989
    8090        xhci_send_enable_slot_command(hc, &cmd);
     
    127137        XHCI_EP_ERROR_COUNT_SET(ictx->endpoint_ctx[0], 3);
    128138
    129         // TODO: What's the alignment?
    130         xhci_device_ctx_t *dctx = malloc(sizeof(xhci_device_ctx_t));
     139        xhci_device_ctx_t *dctx = malloc32(sizeof(xhci_device_ctx_t));
    131140        if (!dctx) {
    132141                err = ENOMEM;
     
    149158        xhci_cmd_fini(&cmd);
    150159
    151         usb_address_t address = XHCI_SLOT_DEVICE_ADDRESS(dctx->slot_ctx);
    152         usb_log_debug2("Obtained USB address: %d.\n", address);
     160        *address = XHCI_SLOT_DEVICE_ADDRESS(dctx->slot_ctx);
     161        usb_log_debug2("Obtained USB address: %d.\n", *address);
    153162
    154163        // TODO: Ask libusbhost to create a control endpoint for EP0.
     
    174183}
    175184
     185static int rh_setup_device(xhci_rh_t *rh, uint8_t port_id)
     186{
     187        /** This should ideally use the libusbhost in a clean and elegant way,
     188         * to create child function. The refactoring of libusbhost is not over
     189         * yet, so for now it is still quirky.
     190         */
     191
     192        return hcd_roothub_new_device(rh->hcd_rh, port_id);
     193}
     194
    176195static int handle_connected_device(xhci_rh_t *rh, uint8_t port_id)
    177196{
     
    186205                if (link_state == 0) {
    187206                        /* USB3 is automatically advanced to enabled. */
    188                         return alloc_dev(rh->hc, port_id, 0);
     207                        return rh_setup_device(rh, port_id);
    189208                }
    190209                else if (link_state == 5) {
     
    270289                                 * every time USB2 port is reset. This is a
    271290                                 * temporary workaround. */
    272                                 alloc_dev(rh->hc, i, 0);
     291                                rh_setup_device(rh, i);
    273292                        }
    274293                }
Note: See TracChangeset for help on using the changeset viewer.