Changeset 04df063 in mainline for uspace/drv/bus/usb/xhci/rh.c


Ignore:
Timestamp:
2017-10-02T19:16:29Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1f76b7d
Parents:
370a1c8
Message:

xhci commands: enable (and encourage) keeping commands on the stack

It is now not necessary to use the heap for simple commands.

File:
1 edited

Legend:

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

    r370a1c8 r04df063  
    6363        int err;
    6464
    65         xhci_cmd_t *cmd = xhci_alloc_command();
    66         if (!cmd)
    67                 return ENOMEM;
    68 
    69         xhci_send_enable_slot_command(hc, cmd);
    70         if ((err = xhci_wait_for_command(cmd, 100000)) != EOK) {
    71                 usb_log_error("Failed to enable a slot for the device.");
    72                 goto err_command;
    73         }
    74 
    75         uint32_t slot_id = cmd->slot_id;
     65        xhci_cmd_t cmd;
     66        xhci_cmd_init(&cmd);
     67
     68        xhci_send_enable_slot_command(hc, &cmd);
     69        if ((err = xhci_cmd_wait(&cmd, 100000)) != EOK)
     70                return err;
     71
     72        uint32_t slot_id = cmd.slot_id;
     73
    7674        usb_log_debug2("Obtained slot ID: %u.\n", slot_id);
    77 
    78         xhci_free_command(cmd);
    79         cmd = NULL;
     75        xhci_cmd_fini(&cmd);
    8076
    8177        xhci_input_ctx_t *ictx = malloc32(sizeof(xhci_input_ctx_t));
    8278        if (!ictx) {
    83                 err = ENOMEM;
    84                 goto err_command;
     79                return ENOMEM;
    8580        }
    8681
     
    9085        XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 1);
    9186
    92         /* Initialize slot_ctx according to section 4.3.3 point 3. */
     87        /* Initialize slot_ctx according to section 4.3.3 point 3. */
    9388        /* Attaching to root hub port, root string equals to 0. */
    9489        XHCI_SLOT_ROOT_HUB_PORT_SET(ictx->slot_ctx, port);
     
    133128        hc->dcbaa_virt[slot_id].dev_ctx = dctx;
    134129
    135         cmd = xhci_alloc_command();
    136         cmd->ictx = ictx;
    137         xhci_send_address_device_command(hc, cmd);
    138         if ((err = xhci_wait_for_command(cmd, 100000)) != EOK)
     130        xhci_cmd_init(&cmd);
     131        xhci_send_address_device_command(hc, &cmd, ictx);
     132        if ((err = xhci_cmd_wait(&cmd, 100000)) != EOK)
    139133                goto err_dctx;
    140134
    141         xhci_free_command(cmd);
    142         ictx = NULL;
     135        xhci_cmd_fini(&cmd);
    143136
    144137        // TODO: Issue configure endpoint commands (sec 4.3.5).
     
    158151        }
    159152err_ictx:
    160         if (ictx) {
    161                 /* Avoid double free. */
    162                 if (cmd && cmd->ictx && cmd->ictx == ictx)
    163                         cmd->ictx = NULL;
    164                 free32(ictx);
    165         }
    166 err_command:
    167         if (cmd)
    168                 xhci_free_command(cmd);
     153        free32(ictx);
    169154        return err;
    170155}
Note: See TracChangeset for help on using the changeset viewer.