Changeset 1998bcd in mainline


Ignore:
Timestamp:
2011-04-08T22:25:00Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
98064795
Parents:
297341b
Message:

Endpoint registration sends address as well

This is the first step towards using endpoint registration instead
of reservation of default address.

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ehci-hcd/hc_iface.c

    r297341b r1998bcd  
    123123 * @param[in] fun Device function the action was invoked on.
    124124 * @param[in] address USB address of the device.
     125 * @param[in] speed Endpoint speed (invalid means to use device one).
    125126 * @param[in] endpoint Endpoint number.
    126127 * @param[in] transfer_type USB transfer type.
     
    131132 */
    132133static int register_endpoint(ddf_fun_t *fun,
    133     usb_address_t address, usb_endpoint_t endpoint,
     134    usb_address_t address, usb_speed_t speed, usb_endpoint_t endpoint,
    134135    usb_transfer_type_t transfer_type, usb_direction_t direction,
    135136    size_t max_packet_size, unsigned int interval)
  • uspace/drv/ohci/iface.c

    r297341b r1998bcd  
    139139 * @param[in] fun Device function the action was invoked on.
    140140 * @param[in] address USB address of the device.
     141 * @param[in] ep_speed Endpoint speed (invalid means to use device one).
    141142 * @param[in] endpoint Endpoint number.
    142143 * @param[in] transfer_type USB transfer type.
     
    146147 * @return Error code.
    147148 */
    148 static int register_endpoint(
    149     ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
     149static int register_endpoint(ddf_fun_t *fun,
     150    usb_address_t address, usb_speed_t ep_speed, usb_endpoint_t endpoint,
    150151    usb_transfer_type_t transfer_type, usb_direction_t direction,
    151152    size_t max_packet_size, unsigned int interval)
     
    156157        if (address == hc->rh.address)
    157158                return EOK;
    158         const usb_speed_t speed =
    159                 usb_device_keeper_get_speed(&hc->manager, address);
     159        usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, address);
     160        if (speed >= USB_SPEED_MAX) {
     161                speed = ep_speed;
     162        }
    160163        const size_t size = max_packet_size;
    161164        usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
     
    183186        usb_log_debug("Unregister endpoint %d:%d %d.\n",
    184187            address, endpoint, direction);
     188        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     189            address, endpoint, direction, NULL);
     190        if (ep != NULL) {
     191                usb_device_keeper_del_ep(&hc->manager, address, ep);
     192        }
    185193        return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
    186194            endpoint, direction);
  • uspace/drv/uhci-hcd/iface.c

    r297341b r1998bcd  
    7474            name, target.address, target.endpoint, size, ep->max_packet_size);
    7575
    76         assert(ep->speed ==
    77             usb_device_keeper_get_speed(&(*hc)->manager, target.address));
     76//      assert(ep->speed ==
     77//          usb_device_keeper_get_speed(&(*hc)->manager, target.address));
    7878//      assert(ep->max_packet_size == max_packet_size);
    7979//      assert(ep->transfer_type == USB_TRANSFER_CONTROL);
     
    198198/*----------------------------------------------------------------------------*/
    199199static int register_endpoint(
    200     ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
     200    ddf_fun_t *fun, usb_address_t address, usb_speed_t ep_speed,
     201    usb_endpoint_t endpoint,
    201202    usb_transfer_type_t transfer_type, usb_direction_t direction,
    202203    size_t max_packet_size, unsigned int interval)
     
    204205        hc_t *hc = fun_to_hc(fun);
    205206        assert(hc);
    206         const usb_speed_t speed =
    207             usb_device_keeper_get_speed(&hc->manager, address);
     207        usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, address);
     208        if (speed >= USB_SPEED_MAX) {
     209                speed = ep_speed;
     210        }
    208211        const size_t size =
    209212            (transfer_type == USB_TRANSFER_INTERRUPT
     
    243246        usb_log_debug("Unregister endpoint %d:%d %d.\n",
    244247            address, endpoint, direction);
     248        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     249            address, endpoint, direction, NULL);
     250        if (ep != NULL) {
     251                usb_device_keeper_del_ep(&hc->manager, address, ep);
     252        }
    245253        return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
    246254            endpoint, direction);
  • uspace/lib/drv/generic/remote_usbhc.c

    r297341b r1998bcd  
    533533        }
    534534
    535 #define INIT_FROM_HIGH_DATA(type, var, arg_no) \
    536         type var = (type) DEV_IPC_GET_ARG##arg_no(*call) / 256
    537 #define INIT_FROM_LOW_DATA(type, var, arg_no) \
    538         type var = (type) DEV_IPC_GET_ARG##arg_no(*call) % 256
    539 
    540         INIT_FROM_HIGH_DATA(usb_address_t, address, 1);
    541         INIT_FROM_LOW_DATA(usb_endpoint_t, endpoint, 1);
    542         INIT_FROM_HIGH_DATA(usb_transfer_type_t, transfer_type, 2);
    543         INIT_FROM_LOW_DATA(usb_direction_t, direction, 2);
    544 
    545 #undef INIT_FROM_HIGH_DATA
    546 #undef INIT_FROM_LOW_DATA
    547 
    548         size_t max_packet_size = (size_t) DEV_IPC_GET_ARG3(*call);
    549         unsigned int interval  = (unsigned int) DEV_IPC_GET_ARG4(*call);
    550 
    551         int rc = usb_iface->register_endpoint(fun, address, endpoint,
     535#define _INIT_FROM_HIGH_DATA2(type, var, arg_no) \
     536        type var = (type) DEV_IPC_GET_ARG##arg_no(*call) / (1 << 16)
     537#define _INIT_FROM_LOW_DATA2(type, var, arg_no) \
     538        type var = (type) DEV_IPC_GET_ARG##arg_no(*call) % (1 << 16)
     539#define _INIT_FROM_HIGH_DATA3(type, var, arg_no) \
     540        type var = (type) DEV_IPC_GET_ARG##arg_no(*call) / (1 << 16)
     541#define _INIT_FROM_MIDDLE_DATA3(type, var, arg_no) \
     542        type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) / (1 << 8)) % (1 << 8)
     543#define _INIT_FROM_LOW_DATA3(type, var, arg_no) \
     544        type var = (type) DEV_IPC_GET_ARG##arg_no(*call) % (1 << 8)
     545
     546        _INIT_FROM_HIGH_DATA2(usb_address_t, address, 1);
     547        _INIT_FROM_LOW_DATA2(usb_endpoint_t, endpoint, 1);
     548
     549        _INIT_FROM_HIGH_DATA3(usb_speed_t, speed, 2);
     550        _INIT_FROM_MIDDLE_DATA3(usb_transfer_type_t, transfer_type, 2);
     551        _INIT_FROM_LOW_DATA3(usb_direction_t, direction, 2);
     552
     553        _INIT_FROM_HIGH_DATA2(size_t, max_packet_size, 3);
     554        _INIT_FROM_LOW_DATA2(unsigned int, interval, 3);
     555
     556#undef _INIT_FROM_HIGH_DATA2
     557#undef _INIT_FROM_LOW_DATA2
     558#undef _INIT_FROM_HIGH_DATA3
     559#undef _INIT_FROM_MIDDLE_DATA3
     560#undef _INIT_FROM_LOW_DATA3
     561
     562        int rc = usb_iface->register_endpoint(fun, address, speed, endpoint,
    552563            transfer_type, direction, max_packet_size, interval);
    553564
  • uspace/lib/drv/include/usbhc_iface.h

    r297341b r1998bcd  
    168168        /** Register endpoint attributes at host controller.
    169169         * This is used to reserve portion of USB bandwidth.
     170         * When speed is invalid, speed of the device is used.
    170171         * Parameters:
    171          * - USB address + endpoint number (ADDR * 256 + EP)
    172          * - transfer type + direction (TYPE * 256 + DIR)
    173          * - maximum packet size
    174          * - interval (in milliseconds)
     172         * - USB address + endpoint number
     173         *   - packed as ADDR << 16 + EP
     174         * - speed + transfer type + direction
     175         *   - packed as ( SPEED << 8 + TYPE ) << 8 + DIR
     176         * - maximum packet size + interval (in milliseconds)
     177         *   - packed as MPS << 16 + INT
    175178         * Answer:
    176179         * - EOK - reservation successful
     
    221224        int (*release_address)(ddf_fun_t *, usb_address_t);
    222225
    223         int (*register_endpoint)(ddf_fun_t *, usb_address_t, usb_endpoint_t,
     226        int (*register_endpoint)(ddf_fun_t *,
     227            usb_address_t, usb_speed_t, usb_endpoint_t,
    224228            usb_transfer_type_t, usb_direction_t, size_t, unsigned int);
    225229        int (*unregister_endpoint)(ddf_fun_t *, usb_address_t, usb_endpoint_t,
  • uspace/lib/usb/include/usb/host/device_keeper.h

    r297341b r1998bcd  
    7373void usb_device_keeper_add_ep(
    7474    usb_device_keeper_t *instance, usb_address_t address, endpoint_t *ep);
     75void usb_device_keeper_del_ep(
     76    usb_device_keeper_t *instance, usb_address_t address, endpoint_t *ep);
    7577
    7678void usb_device_keeper_reserve_default_address(
  • uspace/lib/usb/include/usb/pipes.h

    r297341b r1998bcd  
    134134int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
    135135    size_t, uint8_t *, size_t, usb_device_connection_t *);
     136int usb_pipe_register_with_speed(usb_pipe_t *, usb_speed_t,
     137    unsigned int, usb_hc_connection_t *);
    136138int usb_pipe_register(usb_pipe_t *, unsigned int, usb_hc_connection_t *);
    137139int usb_pipe_unregister(usb_pipe_t *, usb_hc_connection_t *);
  • uspace/lib/usb/src/host/device_keeper.c

    r297341b r1998bcd  
    5656                instance->devices[i].control_used = 0;
    5757                instance->devices[i].handle = 0;
     58                instance->devices[i].speed = USB_SPEED_MAX;
    5859                list_initialize(&instance->devices[i].endpoints);
    5960        }
     61        // TODO: is this hack enough?
     62        // (it is needed to allow smooth registration at default address)
     63        instance->devices[0].occupied = true;
    6064}
    6165/*----------------------------------------------------------------------------*/
     
    6771        assert(instance->devices[address].occupied);
    6872        list_append(&ep->same_device_eps, &instance->devices[address].endpoints);
     73        fibril_mutex_unlock(&instance->guard);
     74}
     75/*----------------------------------------------------------------------------*/
     76void usb_device_keeper_del_ep(
     77    usb_device_keeper_t *instance, usb_address_t address, endpoint_t *ep)
     78{
     79        assert(instance);
     80        fibril_mutex_lock(&instance->guard);
     81        assert(instance->devices[address].occupied);
     82        list_remove(&ep->same_device_eps);
     83        list_initialize(&ep->same_device_eps);
    6984        fibril_mutex_unlock(&instance->guard);
    7085}
  • uspace/lib/usb/src/pipesinit.c

    r297341b r1998bcd  
    461461    usb_hc_connection_t *hc_connection)
    462462{
     463        return usb_pipe_register_with_speed(pipe, USB_SPEED_MAX + 1,
     464            interval, hc_connection);
     465}
     466
     467/** Register endpoint with a speed at the host controller.
     468 *
     469 * You will rarely need to use this function because it is needed only
     470 * if the registered endpoint is of address 0 and there is no other way
     471 * to tell speed of the device at address 0.
     472 *
     473 * @param pipe Pipe to be registered.
     474 * @param speed Speed of the device
     475 *      (invalid speed means use previously specified one).
     476 * @param interval Polling interval.
     477 * @param hc_connection Connection to the host controller (must be opened).
     478 * @return Error code.
     479 */
     480int usb_pipe_register_with_speed(usb_pipe_t *pipe, usb_speed_t speed,
     481    unsigned int interval,
     482    usb_hc_connection_t *hc_connection)
     483{
    463484        assert(pipe);
    464485        assert(hc_connection);
     
    468489        }
    469490
    470 #define _PACK(high, low) ((high) * 256 + (low))
    471 
    472         return async_req_5_0(hc_connection->hc_phone,
     491#define _PACK2(high, low) (((high) << 16) + (low))
     492#define _PACK3(high, middle, low) (((((high) << 8) + (middle)) << 8) + (low))
     493
     494        return async_req_4_0(hc_connection->hc_phone,
    473495            DEV_IFACE_ID(USBHC_DEV_IFACE), IPC_M_USBHC_REGISTER_ENDPOINT,
    474             _PACK(pipe->wire->address, pipe->endpoint_no),
    475             _PACK(pipe->transfer_type, pipe->direction),
    476             pipe->max_packet_size, interval);
    477 
    478 #undef _PACK
     496            _PACK2(pipe->wire->address, pipe->endpoint_no),
     497            _PACK3(speed, pipe->transfer_type, pipe->direction),
     498            _PACK2(pipe->max_packet_size, interval));
     499
     500#undef _PACK2
     501#undef _PACK3
    479502}
    480503
Note: See TracChangeset for help on using the changeset viewer.