Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 2770b66 in mainline


Ignore:
Timestamp:
2017-10-15T15:05:06Z (4 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master
Children:
816f5f4
Parents:
20eaa82
Message:

Fixed few bugs related to control transfers and some deadlocks. Registering control endpoint with HelenOS. Can read out device descriptors through MID and initialize mouse driver!

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

Legend:

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

    r20eaa82 r2770b66  
    7979
    8080        /* Assign an address to the device */
    81         if ((err = xhci_rh_address_device(&hc->rh, dev))) {
     81        if ((err = xhci_rh_address_device(&hc->rh, dev, bus))) {
    8282                usb_log_error("Failed to setup address of the new device: %s", str_error(err));
    8383                return err;
  • uspace/drv/bus/usb/xhci/endpoint.h

    r20eaa82 r2770b66  
    6666        endpoint_t base;        /**< Inheritance. Keep this first. */
    6767
     68        /** Parent device. */
    6869        xhci_device_t *device;
    6970} xhci_endpoint_t;
    7071
    7172typedef struct xhci_device {
     73        /** Unique USB address assigned to the device. */
    7274        usb_address_t address;
    7375
     76        /** Slot ID assigned to the device by xHC. */
    7477        uint32_t slot_id;
    7578
     79        /** Associated device in libusbhost. */
     80        device_t *device;
     81
     82        /** All endpoints of the device. Inactive ones are NULL */
    7683        xhci_endpoint_t *endpoints[XHCI_DEVICE_MAX_ENDPOINTS];
     84
     85        /** Number of non-NULL endpoints. Reference count of sorts. */
    7786        uint8_t active_endpoint_count;
    7887} xhci_device_t;
  • uspace/drv/bus/usb/xhci/hc.c

    r20eaa82 r2770b66  
    213213                goto err_scratch;
    214214
     215        if ((err = xhci_init_transfers(hc)))
     216                goto err_cmd;
     217
    215218        if ((err = xhci_rh_init(&hc->rh, hc)))
    216                 goto err_cmd;
     219                goto err_transfers;
    217220
    218221        if ((err = xhci_bus_init(&hc->bus)))
     
    224227err_rh:
    225228        xhci_rh_fini(&hc->rh);
     229err_transfers:
     230        xhci_fini_transfers(hc);
    226231err_cmd:
    227232        xhci_fini_commands(hc);
     
    472477        case USB_TRANSFER_ISOCHRONOUS:
    473478                /* TODO: Implement me. */
    474                 break;
     479                usb_log_error("Isochronous transfers are not yet implemented!");
     480                return ENOTSUP;
    475481        case USB_TRANSFER_BULK:
    476482                return xhci_schedule_bulk_transfer(hc, batch);
    477483        case USB_TRANSFER_INTERRUPT:
    478484                /* TODO: Implement me. */
    479                 break;
     485                usb_log_error("Interrupt transfers are not yet implemented!");
     486                return ENOTSUP;
    480487        }
    481488
     
    617624        xhci_event_ring_fini(&hc->event_ring);
    618625        hc_dcbaa_fini(hc);
     626        xhci_fini_transfers(hc);
    619627        xhci_fini_commands(hc);
    620628        xhci_rh_fini(&hc->rh);
  • uspace/drv/bus/usb/xhci/rh.c

    r20eaa82 r2770b66  
    3636#include <errno.h>
    3737#include <str_error.h>
     38#include <usb/request.h>
    3839#include <usb/debug.h>
    3940#include <usb/host/utils/malloc32.h>
    4041#include <usb/host/bus.h>
    4142#include <usb/host/ddf_helpers.h>
     43#include <usb/host/hcd.h>
    4244
    4345#include "debug.h"
     
    7476// TODO: This currently assumes the device is attached to rh directly.
    7577//       Also, we should consider moving a lot of functionailty to xhci bus
    76 int xhci_rh_address_device(xhci_rh_t *rh, device_t *dev)
     78int xhci_rh_address_device(xhci_rh_t *rh, device_t *dev, xhci_bus_t *bus)
    7779{
    7880        int err;
     
    160162        usb_log_debug2("Obtained USB address: %d.\n", dev->address);
    161163
    162         // TODO: Ask libusbhost to create a control endpoint for EP0.
    163 
    164         // TODO: Save all data structures in the corresponding xhci_device_t.
    165 
    166         return EOK;
    167 
     164        // Ask libusbhost to create a control endpoint for EP0.
     165        bus_t *bus_base = &bus->base;
     166        usb_target_t ep0_target = { .address = dev->address, .endpoint = 0 };
     167        usb_direction_t ep0_direction = USB_DIRECTION_BOTH;
     168
     169        // TODO: Should this call be unified with other calls to `bus_add_ep()`?
     170        err = bus_add_ep(bus_base, dev, ep0_target.endpoint, ep0_direction,
     171            USB_TRANSFER_CONTROL, CTRL_PIPE_MIN_PACKET_SIZE, CTRL_PIPE_MIN_PACKET_SIZE, 1);
     172
     173        if (err != EOK)
     174                goto err_add_ep;
     175
     176        // Save all data structures in the corresponding xhci_device_t.
     177        endpoint_t *ep0_base = bus_find_endpoint(bus_base, ep0_target, ep0_direction);
     178        xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base);
     179        xhci_device_t *xhci_dev = ep0->device;
     180
     181        xhci_dev->device = dev;
     182        xhci_dev->slot_id = slot_id;
     183
     184        // TODO: Save anything else?
     185
     186        return EOK;
     187
     188err_add_ep:
    168189err_dctx:
    169190        if (dctx) {
  • uspace/drv/bus/usb/xhci/rh.h

    r20eaa82 r2770b66  
    5454
    5555typedef struct hcd_roothub hcd_roothub_t;
     56typedef struct xhci_bus xhci_bus_t;
    5657
    5758/* XHCI root hub instance */
     
    8485void xhci_rh_handle_port_change(xhci_rh_t *);
    8586
    86 int xhci_rh_address_device(xhci_rh_t *rh, device_t *dev);
     87int xhci_rh_address_device(xhci_rh_t *rh, device_t *dev, xhci_bus_t *bus);
    8788
    8889#endif
  • uspace/drv/bus/usb/xhci/transfers.c

    r20eaa82 r2770b66  
    145145        transfer->batch = batch;
    146146        link_initialize(&transfer->link);
    147         transfer->hc_buffer = malloc32(batch->buffer_size);
     147        transfer->hc_buffer = batch->buffer_size > 0 ? malloc32(batch->buffer_size) : NULL;
    148148
    149149        return transfer;
     
    152152void xhci_transfer_fini(xhci_transfer_t* transfer) {
    153153        if (transfer) {
    154                 free32(transfer->hc_buffer);
     154                if (transfer->batch->buffer_size > 0)
     155                        free32(transfer->hc_buffer);
     156
     157                usb_transfer_batch_destroy(transfer->batch);
     158
    155159                free(transfer);
    156160        }
     
    179183        /* For the TRB formats, see xHCI specification 6.4.1.2 */
    180184        xhci_transfer_t *transfer = xhci_transfer_alloc(batch);
    181         memcpy(transfer->hc_buffer, batch->buffer, batch->buffer_size);
     185
     186        if (!transfer->direction) {
     187                // Sending stuff from host to device, we need to copy the actual data.
     188                memcpy(transfer->hc_buffer, batch->buffer, batch->buffer_size);
     189        }
    182190
    183191        xhci_trb_t trb_setup;
     
    318326        batch->transfered_size = batch->buffer_size - TRB_TRANSFER_LENGTH(*trb);
    319327        if (transfer->direction) {
     328                memcpy(batch->buffer, transfer->hc_buffer, batch->buffer_size);
     329
    320330                /* Device-to-host, IN */
    321331                if (batch->callback_in)
Note: See TracChangeset for help on using the changeset viewer.