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


Ignore:
Timestamp:
2017-10-15T02:04:10Z (8 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.

Location:
uspace/drv/bus/usb/xhci
Files:
3 edited

Legend:

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

    rd7869d7e r867b375  
    4242
    4343#include "hc.h"
     44#include "rh.h"
    4445#include "endpoint.h"
    4546
     
    5051static int hcd_claim(hcd_t *, ddf_dev_t *);
    5152static int hcd_start(hcd_t *, bool);
     53static int hcd_setup_root_hub(hcd_t *, ddf_dev_t *);
    5254static int hcd_status(hcd_t *, uint32_t *);
    5355static void hcd_interrupt(hcd_t *, uint32_t);
    5456static int hcd_schedule(hcd_t *, usb_transfer_batch_t *);
     57static int hcd_address_device(hcd_t *, usb_speed_t, usb_tt_address_t, usb_address_t *);
    5558static void hc_driver_fini(hcd_t *);
    5659
     
    6265        .claim = hcd_claim,
    6366        .start = hcd_start,
     67        .setup_root_hub = hcd_setup_root_hub,
    6468        .fini = hc_driver_fini,
    6569        .ops = {
     
    6771                .irq_hook       = hcd_interrupt,
    6872                .status_hook    = hcd_status,
     73                .address_device = hcd_address_device,
    6974        }
    7075};
     
    116121}
    117122
     123static int hcd_setup_root_hub(hcd_t *hcd, ddf_dev_t *dev)
     124{
     125        xhci_hc_t *hc = hcd_get_driver_data(hcd);
     126        assert(hc);
     127
     128        hc->rh.hcd_rh = hcd_roothub_create(hcd, dev, USB_SPEED_SUPER);
     129        return hc->rh.hcd_rh ? EOK : ENOMEM;
     130}
     131
    118132static int hcd_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
    119133{
     
    139153
    140154        hc_interrupt(hc, status);
     155}
     156
     157static int hcd_address_device(hcd_t *hcd, usb_speed_t speed, usb_tt_address_t tt, usb_address_t *address)
     158{
     159        xhci_hc_t *hc = hcd_get_driver_data(hcd);
     160        assert(hc);
     161
     162        return xhci_rh_address_device(&hc->rh, speed, tt, address);
    141163}
    142164
  • 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                }
  • uspace/drv/bus/usb/xhci/rh.h

    rd7869d7e r867b375  
    5151} xhci_port_speed_t;
    5252
     53typedef struct hcd_roothub hcd_roothub_t;
     54
    5355/* XHCI root hub instance */
    5456typedef struct {
     
    6466        /* Number of hub ports. */
    6567        uint8_t max_ports;
     68
     69        /* We need this to create child devices */
     70        hcd_roothub_t *hcd_rh;
    6671} xhci_rh_t;
    6772
     
    7479void xhci_rh_handle_port_change(xhci_rh_t *);
    7580
     81int xhci_rh_address_device(xhci_rh_t *, usb_speed_t, usb_tt_address_t, usb_address_t *);
     82
    7683#endif
    7784
Note: See TracChangeset for help on using the changeset viewer.