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

Changeset 1b78a7c1 in mainline


Ignore:
Timestamp:
2017-07-24T13:36:09Z (3 years ago)
Author:
Jaroslav Jindrak <dzejrou@…>
Branches:
master
Children:
7dee9b7
Parents:
2fa43d1
Message:

Added setter/getter macro for command trbs to eliminate repeated literals identifying bit ranges/flags.

File:
1 edited

Legend:

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

    r2fa43d1 r1b78a7c1  
    4343#include "hw_struct/context.h"
    4444#include "hw_struct/trb.h"
     45
     46#define TRB_SET_TCS(trb, tcs)   (trb).control |= host2xhci(32, ((tcs &0x1) << 9))
     47#define TRB_SET_TYPE(trb, type) (trb).control |= host2xhci(32, (type) << 10)
     48#define TRB_SET_EP(trb, ep)     (trb).control |= host2xhci(32, ((ep) & 0x5) << 16)
     49#define TRB_SET_SUSP(trb, susp) (trb).control |= host2xhci(32, ((susp) & 0x1) << 23)
     50#define TRB_SET_SLOT(trb, slot) (trb).control |= host2xhci(32, (slot) << 24)
     51
     52#define TRB_SET_ICTX(trb, phys) (trb).parameter |= host2xhci(32, phys_addr & (~0xF))
     53
     54#define TRB_GET_CODE(trb) XHCI_DWORD_EXTRACT((trb).status, 31, 24)
     55#define TRB_GET_SLOT(trb) XHCI_DWORD_EXTRACT((trb).control, 31, 24)
     56#define TRB_GET_PHYS(trb) (XHCI_QWORD_EXTRACT((trb).parameter, 63, 4) << 4)
    4557
    4658int xhci_init_commands(xhci_hc_t *hc)
     
    254266        memset(&trb, 0, sizeof(trb));
    255267
    256         trb.control = host2xhci(32, XHCI_TRB_TYPE_NO_OP_CMD << 10);
     268        TRB_SET_TYPE(trb, XHCI_TRB_TYPE_NO_OP_CMD);
    257269
    258270        cmd = add_cmd(hc, cmd);
     
    268280        memset(&trb, 0, sizeof(trb));
    269281
    270         trb.control = host2xhci(32, XHCI_TRB_TYPE_ENABLE_SLOT_CMD << 10);
     282        TRB_SET_TYPE(trb, XHCI_TRB_TYPE_ENABLE_SLOT_CMD);
    271283        trb.control |= host2xhci(32, XHCI_REG_RD(hc->xecp, XHCI_EC_SP_SLOT_TYPE) << 16);
    272284
     
    284296        memset(&trb, 0, sizeof(trb));
    285297
    286         trb.control = host2xhci(32, XHCI_TRB_TYPE_DISABLE_SLOT_CMD << 10);
    287         trb.control |= host2xhci(32, cmd->slot_id << 24);
     298        TRB_SET_TYPE(trb, XHCI_TRB_TYPE_DISABLE_SLOT_CMD);
     299        TRB_SET_SLOT(trb, cmd->slot_id);
    288300
    289301        add_cmd(hc, cmd);
     
    308320
    309321        uint64_t phys_addr = (uint64_t) addr_to_phys(cmd->ictx);
    310         trb.parameter = host2xhci(32, phys_addr & (~0xF));
     322        TRB_SET_ICTX(trb, phys_addr);
    311323
    312324        /**
     
    317329         *       that require their device descriptor to be read before such request.
    318330         */
    319         trb.control = host2xhci(32, XHCI_TRB_TYPE_ADDRESS_DEVICE_CMD << 10);
    320         trb.control |= host2xhci(32, cmd->slot_id << 24);
     331        TRB_SET_TYPE(trb, XHCI_TRB_TYPE_ADDRESS_DEVICE_CMD);
     332        TRB_SET_SLOT(trb, cmd->slot_id);
    321333
    322334        cmd = add_cmd(hc, cmd);
     
    335347
    336348        uint64_t phys_addr = (uint64_t) addr_to_phys(cmd->ictx);
    337         trb.parameter = host2xhci(32, phys_addr & (~0xF));
    338 
    339         trb.control = host2xhci(32, XHCI_TRB_TYPE_CONFIGURE_ENDPOINT_CMD << 10);
    340         trb.control |= host2xhci(32, cmd->slot_id << 24);
     349        TRB_SET_ICTX(trb, phys_addr);
     350
     351        TRB_SET_TYPE(trb, XHCI_TRB_TYPE_CONFIGURE_ENDPOINT_CMD);
     352        TRB_SET_SLOT(trb, cmd->slot_id);
    341353
    342354        cmd = add_cmd(hc, cmd);
     
    361373
    362374        uint64_t phys_addr = (uint64_t) addr_to_phys(cmd->ictx);
    363         trb.parameter = host2xhci(32, phys_addr & (~0xF));
    364 
    365         trb.control = host2xhci(32, XHCI_TRB_TYPE_EVALUATE_CONTEXT_CMD << 10);
    366         trb.control |= host2xhci(32, cmd->slot_id << 24);
     375        TRB_SET_ICTX(trb, phys_addr);
     376
     377        TRB_SET_TYPE(trb, XHCI_TRB_TYPE_EVALUATE_CONTEXT_CMD);
     378        TRB_SET_SLOT(trb, cmd->slot_id);
    367379
    368380        cmd = add_cmd(hc, cmd);
     
    383395        memset(&trb, 0, sizeof(trb));
    384396
    385         trb.control = host2xhci(32, XHCI_TRB_TYPE_RESET_ENDPOINT_CMD << 10);
    386         trb.control |= host2xhci(32, (tcs & 0x1) << 9);
    387         trb.control |= host2xhci(32, (ep_id & 0x5) << 16);
    388         trb.control |= host2xhci(32, cmd->slot_id << 24);
     397        TRB_SET_TYPE(trb, XHCI_TRB_TYPE_RESET_ENDPOINT_CMD);
     398        TRB_SET_TCS(trb, tcs);
     399        TRB_SET_EP(trb, ep_id);
     400        TRB_SET_SLOT(trb, cmd->slot_id);
    389401
    390402        return enqueue_trb(hc, &trb, 0, 0);
     
    399411        memset(&trb, 0, sizeof(trb));
    400412
    401         trb.control = host2xhci(32, XHCI_TRB_TYPE_STOP_ENDPOINT_CMD << 10);
    402         trb.control |= host2xhci(32, (ep_id & 0x5) << 16);
    403         trb.control |= host2xhci(32, (susp & 0x1) << 23);
    404         trb.control |= host2xhci(32, cmd->slot_id << 24);
     413        TRB_SET_TYPE(trb, XHCI_TRB_TYPE_STOP_ENDPOINT_CMD);
     414        TRB_SET_EP(trb, ep_id);
     415        TRB_SET_SUSP(trb, susp);
     416        TRB_SET_SLOT(trb, cmd->slot_id);
    405417
    406418        cmd = add_cmd(hc, cmd);
     
    417429        memset(&trb, 0, sizeof(trb));
    418430
    419         trb.control = host2xhci(32, XHCI_TRB_TYPE_RESET_DEVICE_CMD << 10);
    420         trb.control |= host2xhci(32, cmd->slot_id << 24);
     431        TRB_SET_TYPE(trb, XHCI_TRB_TYPE_RESET_DEVICE_CMD);
     432        TRB_SET_SLOT(trb, cmd->slot_id);
    421433
    422434        return enqueue_trb(hc, &trb, 0, 0);
     
    432444
    433445        int code;
    434         uint32_t slot_id;
    435446        uint64_t phys;
    436447        xhci_cmd_t *command;
    437448        xhci_trb_t *command_trb;
    438449
    439         code = XHCI_DWORD_EXTRACT(trb->status, 31, 24);
    440         phys = XHCI_QWORD_EXTRACT(trb->parameter, 63, 4) << 4;
     450        code = TRB_GET_CODE(*trb);
     451        phys = TRB_GET_PHYS(*trb);;
    441452        command = get_command(hc, phys);
    442453        if (command == NULL) {
     
    451462
    452463        command_trb = command->trb;
    453 
    454464        command->status = code;
    455 
    456         slot_id = XHCI_DWORD_EXTRACT(trb->control, 31, 24);
    457         command->slot_id = slot_id;
     465        command->slot_id = TRB_GET_SLOT(*trb);
    458466
    459467        usb_log_debug2("Completed command trb: %s", xhci_trb_str_type(TRB_TYPE(*command_trb)));
Note: See TracChangeset for help on using the changeset viewer.