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

Changeset 5c5c9407 in mainline


Ignore:
Timestamp:
2017-10-03T23:12:40Z (4 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master
Children:
816335c
Parents:
7776cb1
Message:

Implemented GetPortStatus? request using XHCI port registers.

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

Legend:

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

    r7776cb1 r5c5c9407  
    202202                goto err_scratch;
    203203
    204         if ((err = xhci_rh_init(&hc->rh)))
     204        if ((err = xhci_rh_init(&hc->rh, hc->op_regs)))
    205205                goto err_cmd;
    206206
  • uspace/drv/bus/usb/xhci/rh.c

    r7776cb1 r5c5c9407  
    5151static usbvirt_device_ops_t ops;
    5252
    53 int xhci_rh_init(xhci_rh_t *rh)
    54 {
     53int xhci_rh_init(xhci_rh_t *rh, xhci_op_regs_t *op_regs)
     54{
     55        assert(rh);
     56        rh->op_regs = op_regs;
     57
    5558        usb_hub_descriptor_header_t *header = &rh->hub_descriptor.header;
    5659        header->length = sizeof(usb_hub_descriptor_header_t);
     
    316319}
    317320
     321#define XHCI_TO_USB(usb_feat, reg_set, ...) \
     322        (((XHCI_REG_RD(reg_set, ##__VA_ARGS__)) ? 1 : 0) << (usb_feat))
     323
    318324/** Port status request handler.
    319325 * @param device Virtual hub device
     
    328334    uint8_t *data, size_t *act_size)
    329335{
    330         /* TODO: Implement me! */
    331         usb_log_debug2("Called req_get_port_status().");
     336        xhci_rh_t *hub = virthub_get_data(device);
     337        assert(hub);
     338
     339        const uint16_t ports = 255; /* FIXME: Fetch this from somewhere. */
     340        if (!setup_packet->index || setup_packet->index > ports) {
     341                return ESTALL;
     342        }
     343
     344        /* The index is 1-based. */
     345        xhci_port_regs_t* regs = &hub->op_regs->portrs[setup_packet->index - 1];
     346
     347        const uint32_t status = uint32_host2usb(
     348            XHCI_TO_USB(USB_HUB_FEATURE_C_PORT_CONNECTION, regs, XHCI_PORT_CSC) |
     349            XHCI_TO_USB(USB_HUB_FEATURE_C_PORT_ENABLE, regs, XHCI_PORT_PEC) |
     350            XHCI_TO_USB(USB_HUB_FEATURE_C_PORT_OVER_CURRENT, regs, XHCI_PORT_OCC) |
     351            XHCI_TO_USB(USB_HUB_FEATURE_C_PORT_RESET, regs, XHCI_PORT_PRC) |
     352            XHCI_TO_USB(USB_HUB_FEATURE_PORT_CONNECTION, regs, XHCI_PORT_CCS) |
     353            XHCI_TO_USB(USB_HUB_FEATURE_PORT_ENABLE, regs, XHCI_PORT_PED) |
     354            XHCI_TO_USB(USB_HUB_FEATURE_PORT_OVER_CURRENT, regs, XHCI_PORT_OCA) |
     355            XHCI_TO_USB(USB_HUB_FEATURE_PORT_RESET, regs, XHCI_PORT_PR) |
     356            XHCI_TO_USB(USB_HUB_FEATURE_PORT_POWER, regs, XHCI_PORT_PP)
     357        );
     358
     359        usb_log_debug2("RH: GetPortStatus(%hu) = %u.", setup_packet->index,
     360                uint32_usb2host(status));
     361
     362        memcpy(data, &status, sizeof(status));
     363        *act_size = sizeof(status);
    332364        return EOK;
    333365}
     
    374406 * @param buffer_size Bytes available in buffer
    375407 * @param actual_size Size us the used part of the dest buffer.
     408 *
     409 * Produces status mask. Bit 0 indicates hub status change the other bits
     410 * represent port status change.
    376411 */
    377412static int req_status_change_handler(usbvirt_device_t *device,
     
    380415{
    381416        usb_log_debug2("Called req_status_change_handler().");
     417        xhci_rh_t *hub = virthub_get_data(device);
     418        assert(hub);
     419
     420        if (buffer_size < 16)
     421                return ESTALL;
     422
     423        /* TODO: Set this based on the received event TRBs. */
     424        memset(buffer, 0, 16);
     425        *actual_size = 16;
     426
     427        /* TODO: Set to EOK if something happened. */
    382428        return ENAK;
    383429}
  • uspace/drv/bus/usb/xhci/rh.h

    r7776cb1 r5c5c9407  
    4848        /** Virtual hub instance */
    4949        virthub_base_t base;
     50        /** XHCI operational registers */
     51        xhci_op_regs_t *op_regs;
    5052        /** USB hub descriptor describing the XHCI root hub */
    5153        struct {
     
    6264} xhci_rh_t;
    6365
    64 int xhci_rh_init(xhci_rh_t *);
     66int xhci_rh_init(xhci_rh_t *, xhci_op_regs_t *);
    6567int xhci_rh_fini(xhci_rh_t *);
    6668int xhci_handle_port_status_change_event(xhci_hc_t *, xhci_trb_t *);
Note: See TracChangeset for help on using the changeset viewer.