Changeset 04df063 in mainline for uspace/drv/bus/usb/xhci/commands.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/commands.c

    r370a1c8 r04df063  
    7373        // Note: Untested.
    7474        assert(hc);
    75 
    76         // We assume that the hc is dying/stopping, so we ignore
    77         // the ownership of the commands.
    78         list_foreach(hc->commands, link, xhci_cmd_t, cmd) {
    79                 xhci_free_command(cmd);
    80         }
    81 }
    82 
    83 int xhci_wait_for_command(xhci_cmd_t *cmd, suseconds_t timeout)
     75}
     76
     77int xhci_cmd_wait(xhci_cmd_t *cmd, suseconds_t timeout)
    8478{
    8579        int rv = EOK;
     
    9993}
    10094
    101 xhci_cmd_t *xhci_alloc_command(void)
     95xhci_cmd_t *xhci_cmd_alloc(void)
    10296{
    10397        xhci_cmd_t *cmd = malloc32(sizeof(xhci_cmd_t));
    10498        xhci_cmd_init(cmd);
     99
     100        usb_log_debug2("Allocating cmd on the heap. Don't forget to deallocate it!");
    105101        return cmd;
    106102}
     
    114110        fibril_mutex_initialize(&cmd->completed_mtx);
    115111        fibril_condvar_initialize(&cmd->completed_cv);
    116 
    117         /**
    118          * Internal functions will set this to false, other are implicit
    119          * owners unless they overwrite this field.
    120          * TODO: Is this wise?
    121          */
    122         cmd->has_owner = true;
    123 }
    124 
    125 void xhci_free_command(xhci_cmd_t *cmd)
     112}
     113
     114void xhci_cmd_fini(xhci_cmd_t *cmd)
    126115{
    127116        list_remove(&cmd->link);
    128 
    129         if (cmd->ictx)
    130                 free32(cmd->ictx);
    131 
     117}
     118
     119void xhci_cmd_free(xhci_cmd_t *cmd)
     120{
     121        xhci_cmd_fini(cmd);
    132122        free32(cmd);
    133123}
     
    299289}
    300290
    301 int xhci_send_address_device_command(xhci_hc_t *hc, xhci_cmd_t *cmd)
    302 {
    303         assert(hc);
    304         assert(cmd);
    305         assert(cmd->ictx);
     291int xhci_send_address_device_command(xhci_hc_t *hc, xhci_cmd_t *cmd, xhci_input_ctx_t *ictx)
     292{
     293        assert(hc);
     294        assert(cmd);
     295        assert(ictx);
    306296
    307297        /**
     
    311301         *           other should be ignored at this point (see section 4.6.5).
    312302         */
    313         xhci_trb_clean(&cmd->trb);
    314 
    315         uint64_t phys_addr = (uint64_t) addr_to_phys(cmd->ictx);
     303
     304        xhci_trb_clean(&cmd->trb);
     305
     306        uint64_t phys_addr = (uint64_t) addr_to_phys(ictx);
    316307        TRB_SET_ICTX(cmd->trb, phys_addr);
    317308
     
    329320}
    330321
    331 int xhci_send_configure_endpoint_command(xhci_hc_t *hc, xhci_cmd_t *cmd)
    332 {
    333         assert(hc);
    334         assert(cmd);
    335         assert(cmd->ictx);
    336 
    337         xhci_trb_clean(&cmd->trb);
    338 
    339         uint64_t phys_addr = (uint64_t) addr_to_phys(cmd->ictx);
     322int xhci_send_configure_endpoint_command(xhci_hc_t *hc, xhci_cmd_t *cmd, xhci_input_ctx_t *ictx)
     323{
     324        assert(hc);
     325        assert(cmd);
     326        assert(ictx);
     327
     328        xhci_trb_clean(&cmd->trb);
     329
     330        uint64_t phys_addr = (uint64_t) addr_to_phys(ictx);
    340331        TRB_SET_ICTX(cmd->trb, phys_addr);
    341332
     
    346337}
    347338
    348 int xhci_send_evaluate_context_command(xhci_hc_t *hc, xhci_cmd_t *cmd)
    349 {
    350         assert(hc);
    351         assert(cmd);
    352         assert(cmd->ictx);
     339int xhci_send_evaluate_context_command(xhci_hc_t *hc, xhci_cmd_t *cmd, xhci_input_ctx_t *ictx)
     340{
     341        assert(hc);
     342        assert(cmd);
     343        assert(ictx);
    353344
    354345        /**
     
    360351        xhci_trb_clean(&cmd->trb);
    361352
    362         uint64_t phys_addr = (uint64_t) addr_to_phys(cmd->ictx);
     353        uint64_t phys_addr = (uint64_t) addr_to_phys(ictx);
    363354        TRB_SET_ICTX(cmd->trb, phys_addr);
    364355
     
    455446        if (command == NULL) {
    456447                // TODO: STOP & ABORT may not have command structs in the list!
    457                 usb_log_error("No command struct for this completion event");
     448                usb_log_debug("No command struct for this completion event found.");
    458449
    459450                if (code != XHCI_TRBC_SUCCESS)
     
    509500        fibril_mutex_unlock(&command->completed_mtx);
    510501
    511 
    512         if (!command->has_owner) {
    513                 usb_log_debug2("Command has no owner, deallocating.");
    514                 xhci_free_command(command);
    515         } else {
    516                 usb_log_debug2("Command has owner, don't forget to deallocate!");
    517         }
    518 
    519502        return EOK;
    520503}
Note: See TracChangeset for help on using the changeset viewer.