Changeset 7e5a12b in mainline for uspace/drv/bus/usb/xhci/hc.c


Ignore:
Timestamp:
2018-01-19T17:57:13Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
69b2dfee
Parents:
2833bb4
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-19 17:57:06)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-19 17:57:13)
Message:

xhci: make enable/disable slot symmetric

Previously, device slot context was allocated inside address_device,
complicating error paths.

File:
1 edited

Legend:

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

    r2833bb4 r7e5a12b  
    714714
    715715/**
    716  * Issue an Enable Slot command, returning the obtained Slot ID.
    717  *
    718  * @param slot_id Pointer where to store the obtained Slot ID.
    719  */
    720 int hc_enable_slot(xhci_hc_t *hc, uint32_t *slot_id)
    721 {
    722         assert(hc);
    723 
     716 * Issue an Enable Slot command. Allocate memory for the slot and fill the
     717 * DCBAA with the newly created slot.
     718 */
     719int hc_enable_slot(xhci_device_t *dev)
     720{
    724721        int err;
     722        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     723
     724        /* Prepare memory for the context */
     725        if ((err = dma_buffer_alloc(&dev->dev_ctx, sizeof(xhci_device_ctx_t))))
     726                return err;
     727        memset(dev->dev_ctx.virt, 0, sizeof(xhci_device_ctx_t));
     728
     729        /* Get the slot number */
    725730        xhci_cmd_t cmd;
    726731        xhci_cmd_init(&cmd, XHCI_CMD_ENABLE_SLOT);
    727732
    728         if ((err = xhci_cmd_sync(hc, &cmd))) {
    729                 goto end;
    730         }
    731 
    732         if (slot_id) {
    733                 *slot_id = cmd.slot_id;
    734         }
    735 
    736 end:
     733        err = xhci_cmd_sync(hc, &cmd);
     734
     735        /* Link them together */
     736        if (err == EOK) {
     737                dev->slot_id = cmd.slot_id;
     738                hc->dcbaa[dev->slot_id] = host2xhci(64, dev->dev_ctx.phys);
     739        }
     740
    737741        xhci_cmd_fini(&cmd);
    738742        return err;
     
    741745/**
    742746 * Issue a Disable Slot command for a slot occupied by device.
    743  *
    744  * Frees the device context
    745  */
    746 int hc_disable_slot(xhci_hc_t *hc, xhci_device_t *dev)
     747 * Frees the device context.
     748 */
     749int hc_disable_slot(xhci_device_t *dev)
    747750{
    748751        int err;
    749         assert(hc);
     752        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
    750753
    751754        if ((err = xhci_cmd_sync_inline(hc, DISABLE_SLOT, .slot_id = dev->slot_id))) {
     
    837840        }
    838841
    839         /* Setup and register device context */
    840         if (dma_buffer_alloc(&dev->dev_ctx, sizeof(xhci_device_ctx_t)))
    841                 goto err;
    842         memset(dev->dev_ctx.virt, 0, sizeof(xhci_device_ctx_t));
    843 
    844         hc->dcbaa[dev->slot_id] = host2xhci(64, dev->dev_ctx.phys);
    845 
    846842        /* Issue configure endpoint command (sec 4.3.5). */
    847843        dma_buffer_t ictx_dma_buf;
    848         if ((err = create_configure_ep_input_ctx(dev, &ictx_dma_buf))) {
    849                 goto err_dev_ctx;
    850         }
     844        if ((err = create_configure_ep_input_ctx(dev, &ictx_dma_buf)))
     845                return err;
    851846        xhci_input_ctx_t *ictx = ictx_dma_buf.virt;
    852847
     
    856851
    857852        /* Issue Address Device command. */
    858         if ((err = xhci_cmd_sync_inline(hc, ADDRESS_DEVICE, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf))) {
    859                 goto err_dev_ctx;
    860         }
     853        if ((err = xhci_cmd_sync_inline(hc, ADDRESS_DEVICE, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf)))
     854                return err;
    861855
    862856        xhci_device_ctx_t *dev_ctx = dev->dev_ctx.virt;
     
    865859
    866860        return EOK;
    867 
    868 err_dev_ctx:
    869         hc->dcbaa[dev->slot_id] = 0;
    870         dma_buffer_free(&dev->dev_ctx);
    871 err:
    872         return err;
    873861}
    874862
Note: See TracChangeset for help on using the changeset viewer.