Changeset d7869d7e in mainline


Ignore:
Timestamp:
2017-10-14T17:21:26Z (7 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
867b375
Parents:
2297fab
Message:

Reading assigned USB addresses, issuing Configure Endpoint commands to devices if needed.

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

Legend:

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

    r2297fab rd7869d7e  
    3939
    4040#include "bus.h"
     41#include "commands.h"
    4142#include "endpoint.h"
    4243
     
    114115}
    115116
     117int xhci_device_configure(xhci_device_t *dev, xhci_hc_t *hc)
     118{
     119        int err;
     120
     121        // Prepare input context.
     122        xhci_input_ctx_t *ictx = malloc(sizeof(xhci_input_ctx_t));
     123        if (!ictx) {
     124                return ENOMEM;
     125        }
     126
     127        memset(ictx, 0, sizeof(xhci_input_ctx_t));
     128
     129        // Quoting sec. 4.6.6: A1, D0, D1 are down, A0 is up.
     130        XHCI_INPUT_CTRL_CTX_ADD_CLEAR(ictx->ctrl_ctx, 1);
     131        XHCI_INPUT_CTRL_CTX_DROP_CLEAR(ictx->ctrl_ctx, 0);
     132        XHCI_INPUT_CTRL_CTX_DROP_CLEAR(ictx->ctrl_ctx, 1);
     133        XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 0);
     134
     135        // TODO: Set slot context and other flags. (probably forgot a lot of 'em)
     136
     137        // Issue configure endpoint command (sec 4.3.5).
     138        xhci_cmd_t cmd;
     139        xhci_cmd_init(&cmd);
     140
     141        cmd.slot_id = dev->slot_id;
     142        xhci_send_configure_endpoint_command(hc, &cmd, ictx);
     143        if ((err = xhci_cmd_wait(&cmd, 100000)) != EOK)
     144                goto err_cmd;
     145
     146        xhci_cmd_fini(&cmd);
     147        return EOK;
     148
     149err_cmd:
     150        free(ictx);
     151        return err;
     152}
     153
    116154/**
    117155 * @}
  • uspace/drv/bus/usb/xhci/endpoint.h

    r2297fab rd7869d7e  
    4343#include <usb/host/hcd.h>
    4444
     45#include "hc.h"
     46
    4547typedef struct xhci_device xhci_device_t;
    4648typedef struct xhci_endpoint xhci_endpoint_t;
     
    8587int xhci_device_remove_endpoint(xhci_device_t *, xhci_endpoint_t *);
    8688xhci_endpoint_t * xhci_device_get_endpoint(xhci_device_t *, usb_endpoint_t);
     89int xhci_device_configure(xhci_device_t *, xhci_hc_t *);
    8790
    8891static inline xhci_endpoint_t * xhci_endpoint_get(endpoint_t *ep)
  • uspace/drv/bus/usb/xhci/hw_struct/context.h

    r2297fab rd7869d7e  
    166166
    167167#define XHCI_INPUT_CTRL_CTX_DROP_SET(ctx, idx) (ctx).data[0] |= (1 << (idx))
     168#define XHCI_INPUT_CTRL_CTX_DROP_CLEAR(ctx, idx) (ctx).data[0] &= ~(1 << (idx))
    168169
    169170#define XHCI_INPUT_CTRL_CTX_ADD(ctx, idx) \
     
    171172
    172173#define XHCI_INPUT_CTRL_CTX_ADD_SET(ctx, idx) (ctx).data[1] |= (1 << (idx))
     174#define XHCI_INPUT_CTRL_CTX_ADD_CLEAR(ctx, idx) (ctx).data[1] &= ~(1 << (idx))
    173175
    174176#define XHCI_INPUT_CTRL_CTX_CONFIG_VALUE(ctx)   XHCI_DWORD_EXTRACT((ctx).data[7],  7,  0)
  • uspace/drv/bus/usb/xhci/rh.c

    r2297fab rd7869d7e  
    149149        xhci_cmd_fini(&cmd);
    150150
    151         // TODO: Issue configure endpoint commands (sec 4.3.5).
     151        usb_address_t address = XHCI_SLOT_DEVICE_ADDRESS(dctx->slot_ctx);
     152        usb_log_debug2("Obtained USB address: %d.\n", address);
     153
     154        // TODO: Ask libusbhost to create a control endpoint for EP0.
     155
     156        // TODO: Save all data structures in the corresponding xhci_device_t.
    152157
    153158        return EOK;
  • uspace/drv/bus/usb/xhci/transfers.c

    r2297fab rd7869d7e  
    103103}
    104104
     105static inline bool configure_endpoint_needed(usb_device_request_setup_packet_t *setup)
     106{
     107        usb_request_type_t request_type = SETUP_REQUEST_TYPE_GET_TYPE(setup->request_type);
     108
     109        if (request_type == USB_REQUEST_TYPE_STANDARD) {
     110                usb_stddevreq_t request = setup->request;
     111
     112                switch (request) {
     113                case USB_DEVREQ_SET_CONFIGURATION:
     114                case USB_DEVREQ_SET_INTERFACE:
     115                        return true;
     116
     117                default:
     118                        return false;
     119                }
     120        }
     121
     122        return false;
     123}
     124
    105125int xhci_init_transfers(xhci_hc_t *hc)
    106126{
     
    225245
    226246        /* For control transfers, the target is always 1. */
     247        // FIXME: ignoring return code
    227248        hc_ring_doorbell(hc, slot_id, 1);
     249
     250        // Issue a Configure Endpoint command, if needed.
     251        if (configure_endpoint_needed(setup)) {
     252                // TODO: figure out the best time to issue this command
     253                // FIXME: ignoring return code
     254                xhci_device_configure(xhci_ep->device, hc);
     255        }
     256
    228257        return EOK;
    229258}
Note: See TracChangeset for help on using the changeset viewer.