Changeset 8dc762e0 in mainline


Ignore:
Timestamp:
2011-04-06T21:12:41Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f567bcf
Parents:
1e70157
Message:

Move endpoint_t to libusb

Location:
uspace
Files:
7 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/Makefile

    r1e70157 r8dc762e0  
    3737        transfer_list.c \
    3838        uhci.c \
    39         endpoint.c \
    4039        hc.c \
    4140        root_hub.c \
  • uspace/drv/uhci-hcd/batch.h

    r1e70157 r8dc762e0  
    3535#define DRV_UHCI_BATCH_H
    3636
    37 #include <adt/list.h>
    38 
    3937#include <usbhc_iface.h>
    4038#include <usb/usb.h>
    4139#include <usb/host/device_keeper.h>
     40#include <usb/host/endpoint.h>
    4241#include <usb/host/batch.h>
    4342
  • uspace/drv/uhci-hcd/iface.c

    r1e70157 r8dc762e0  
    3636
    3737#include <usb/debug.h>
    38 
    39 #include "endpoint.h"
     38#include <usb/host/endpoint.h>
     39
    4040#include "iface.h"
    4141#include "hc.h"
     
    159159        const usb_speed_t speed =
    160160            usb_device_keeper_get_speed(&hc->manager, address);
    161         const size_t size = max_packet_size;
     161        const size_t size =
     162            (transfer_type == USB_TRANSFER_INTERRUPT
     163            || transfer_type == USB_TRANSFER_ISOCHRONOUS) ?
     164            max_packet_size : 0;
    162165        int ret;
    163166
     
    175178            usb_str_speed(speed), direction, size, max_packet_size, interval);
    176179
    177         const size_t bw =
    178             (transfer_type == USB_TRANSFER_INTERRUPT
    179             || transfer_type == USB_TRANSFER_ISOCHRONOUS) ?
    180             bandwidth_count_usb11(speed, transfer_type, size, max_packet_size) :
    181             0;
    182 
    183180        ret = usb_endpoint_manager_register_ep(&hc->ep_manager,
    184             address, endpoint, direction, ep, endpoint_destroy, bw);
     181            address, endpoint, direction, ep, size);
    185182        if (ret != EOK) {
    186183                endpoint_destroy(ep);
     
    226223
    227224        size_t res_bw;
    228         endpoint_t *ep = usb_endpoint_manager_get_ep_data(&hc->ep_manager,
     225        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    229226            target.address, target.endpoint, USB_DIRECTION_OUT, &res_bw);
    230227        if (ep == NULL) {
     
    283280
    284281        size_t res_bw;
    285         endpoint_t *ep = usb_endpoint_manager_get_ep_data(&hc->ep_manager,
     282        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    286283            target.address, target.endpoint, USB_DIRECTION_IN, &res_bw);
    287284        if (ep == NULL) {
     
    340337            target.address, target.endpoint, size, max_packet_size);
    341338
    342         endpoint_t *ep = usb_endpoint_manager_get_ep_data(&hc->ep_manager,
     339        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    343340            target.address, target.endpoint, USB_DIRECTION_OUT, NULL);
    344341        if (ep == NULL) {
     
    387384            target.address, target.endpoint, size, max_packet_size);
    388385
    389         endpoint_t *ep = usb_endpoint_manager_get_ep_data(&hc->ep_manager,
     386        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    390387            target.address, target.endpoint, USB_DIRECTION_IN, NULL);
    391388        if (ep == NULL) {
     
    438435        usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
    439436            speed, target.address, target.endpoint, size, max_packet_size);
    440         endpoint_t *ep = usb_endpoint_manager_get_ep_data(&hc->ep_manager,
     437        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    441438            target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
    442439        if (ep == NULL) {
     
    489486        usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
    490487            speed, target.address, target.endpoint, size, max_packet_size);
    491         endpoint_t *ep = usb_endpoint_manager_get_ep_data(&hc->ep_manager,
     488        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    492489            target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
    493490        if (ep == NULL) {
  • uspace/lib/usb/Makefile

    r1e70157 r8dc762e0  
    5454        src/host/device_keeper.c \
    5555        src/host/batch.c \
     56        src/host/endpoint.c \
    5657        src/host/usb_endpoint_manager.c
    5758
  • uspace/lib/usb/include/usb/host/endpoint.h

    r1e70157 r8dc762e0  
    2727 */
    2828
    29 /** @addtogroup drvusbuhcihc
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief UHCI host controller driver structure
     33 *
    3434 */
    35 #ifndef DRV_UHCI_UHCI_ENDPOINT_H
    36 #define DRV_UHCI_UHCI_ENDPOINT_H
     35#ifndef LIBUSB_HOST_ENDPOINT_H
     36#define LIBUSB_HOST_ENDPOINT_H
    3737
    3838#include <assert.h>
     
    4040#include <adt/list.h>
    4141#include <usb/usb.h>
    42 
    43 #include "hw_struct/queue_head.h"
    4442
    4543typedef struct endpoint {
     
    5048        bool active;
    5149        int toggle:1;
    52         qh_t *qh;
    5350} endpoint_t;
    5451
     
    5653    usb_speed_t speed, size_t max_packet_size);
    5754
    58 void endpoint_destroy(void *ep);
     55void endpoint_destroy(endpoint_t *instance);
    5956
    6057void endpoint_toggle_reset(link_t *ep);
  • uspace/lib/usb/include/usb/host/usb_endpoint_manager.h

    r1e70157 r8dc762e0  
    4343#include <fibril_synch.h>
    4444#include <usb/usb.h>
     45#include <usb/host/endpoint.h>
    4546
    4647#define BANDWIDTH_TOTAL_USB11 12000000
     
    6364
    6465int usb_endpoint_manager_register_ep(usb_endpoint_manager_t *instance,
    65     usb_address_t address, usb_endpoint_t ep, usb_direction_t direction,
    66     void *data, void (*data_remove_callback)(void* data), size_t bw);
     66    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
     67    endpoint_t *ep, size_t data_size);
    6768
    6869int usb_endpoint_manager_register_ep_wait(usb_endpoint_manager_t *instance,
     
    7475    usb_address_t address, usb_endpoint_t ep, usb_direction_t direction);
    7576
    76 void * usb_endpoint_manager_get_ep_data(usb_endpoint_manager_t *instance,
     77endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance,
    7778    usb_address_t address, usb_endpoint_t ep, usb_direction_t direction,
    7879    size_t *bw);
  • uspace/lib/usb/src/host/device_keeper.c

    r1e70157 r8dc762e0  
    6363/*----------------------------------------------------------------------------*/
    6464void usb_device_keeper_add_ep(
    65     usb_device_keeper_t *instance, usb_address_t address, link_t *ep);
     65    usb_device_keeper_t *instance, usb_address_t address, link_t *ep)
     66{
     67        assert(instance);
     68        fibril_mutex_lock(&instance->guard);
     69        assert(instance->devices[address].occupied);
     70        list_append(ep, &instance->devices[address].endpoints);
     71        fibril_mutex_unlock(&instance->guard);
     72}
    6673/*----------------------------------------------------------------------------*/
    6774/** Attempt to obtain address 0, blocks.
  • uspace/lib/usb/src/host/endpoint.c

    r1e70157 r8dc762e0  
    3636#include <errno.h>
    3737
    38 #include "endpoint.h"
    39 #include "utils/malloc32.h"
     38#include <usb/host/endpoint.h>
    4039
    4140int endpoint_init(endpoint_t *instance, usb_transfer_type_t transfer_type,
     
    4847        instance->max_packet_size = max_packet_size;
    4948        instance->toggle = 0;
    50         instance->qh = malloc32(sizeof(qh_t));
    51         if (instance->qh == NULL)
    52                 return ENOMEM;
    5349        return EOK;
    5450}
    5551/*----------------------------------------------------------------------------*/
    56 void endpoint_destroy(void *ep)
     52void endpoint_destroy(endpoint_t *instance)
    5753{
    58         endpoint_t *instance = ep;
    5954        assert(instance);
    6055        list_remove(&instance->same_device_eps);
    61         free32(instance->qh);
    6256        free(instance);
    6357}
  • uspace/lib/usb/src/host/usb_endpoint_manager.c

    r1e70157 r8dc762e0  
    4848        link_t link;
    4949        size_t bw;
    50         void *data;
    51         void (*data_remove_callback)(void* data);
    52 } ep_t;
    53 /*----------------------------------------------------------------------------*/
    54 static hash_index_t ep_hash(unsigned long key[])
     50        endpoint_t *ep;
     51} node_t;
     52/*----------------------------------------------------------------------------*/
     53static hash_index_t node_hash(unsigned long key[])
    5554{
    5655        hash_index_t hash = 0;
     
    6362}
    6463/*----------------------------------------------------------------------------*/
    65 static int ep_compare(unsigned long key[], hash_count_t keys, link_t *item)
     64static int node_compare(unsigned long key[], hash_count_t keys, link_t *item)
    6665{
    6766        assert(item);
    68         ep_t *ep = hash_table_get_instance(item, ep_t, link);
     67        node_t *node = hash_table_get_instance(item, node_t, link);
    6968        hash_count_t i = 0;
    7069        for (; i < keys; ++i) {
    71                 if (key[i] != ep->key[i])
     70                if (key[i] != node->key[i])
    7271                        return false;
    7372        }
     
    7574}
    7675/*----------------------------------------------------------------------------*/
    77 static void ep_remove(link_t *item)
     76static void node_remove(link_t *item)
    7877{
    7978        assert(item);
    80         ep_t *ep =
    81             hash_table_get_instance(item, ep_t, link);
    82         ep->data_remove_callback(ep->data);
    83         free(ep);
     79        node_t *node = hash_table_get_instance(item, node_t, link);
     80        endpoint_destroy(node->ep);
     81        free(node);
    8482}
    8583/*----------------------------------------------------------------------------*/
    8684static hash_table_operations_t op = {
    87         .hash = ep_hash,
    88         .compare = ep_compare,
    89         .remove_callback = ep_remove,
     85        .hash = node_hash,
     86        .compare = node_compare,
     87        .remove_callback = node_remove,
    9088};
    9189/*----------------------------------------------------------------------------*/
     
    145143int usb_endpoint_manager_register_ep(usb_endpoint_manager_t *instance,
    146144    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
    147     void *data, void (*data_remove_callback)(void* data), size_t bw)
    148 {
     145    endpoint_t *ep, size_t data_size)
     146{
     147        assert(ep);
     148        size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
     149            data_size, ep->max_packet_size);
    149150        assert(instance);
    150151
     
    168169        }
    169170
    170         ep_t *ep = malloc(sizeof(ep_t));
    171         if (ep == NULL) {
     171        node_t *node = malloc(sizeof(node_t));
     172        if (node == NULL) {
    172173                fibril_mutex_unlock(&instance->guard);
    173174                return ENOMEM;
    174175        }
    175176
    176         ep->id = id;
    177         ep->bw = bw;
    178         ep->data = data;
    179         link_initialize(&ep->link);
    180 
    181         hash_table_insert(&instance->ep_table, (unsigned long*)&id, &ep->link);
     177        node->id = id;
     178        node->bw = bw;
     179        node->ep = ep;
     180        link_initialize(&node->link);
     181
     182        hash_table_insert(&instance->ep_table,
     183            (unsigned long*)&id, &node->link);
    182184        instance->free_bw -= bw;
    183185        fibril_mutex_unlock(&instance->guard);
     
    203205        }
    204206
    205         ep_t *ep = hash_table_get_instance(item, ep_t, link);
    206         instance->free_bw += ep->bw;
     207        node_t *node = hash_table_get_instance(item, node_t, link);
     208        instance->free_bw += node->bw;
    207209        hash_table_remove(&instance->ep_table, (unsigned long*)&id, MAX_KEYS);
    208210
     
    212214}
    213215/*----------------------------------------------------------------------------*/
    214 void * usb_endpoint_manager_get_ep_data(usb_endpoint_manager_t *instance,
     216endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance,
    215217    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
    216218    size_t *bw)
     
    229231                return NULL;
    230232        }
    231         ep_t *ep = hash_table_get_instance(item, ep_t, link);
     233        node_t *node = hash_table_get_instance(item, node_t, link);
    232234        if (bw)
    233                 *bw = ep->bw;
     235                *bw = node->bw;
    234236
    235237        fibril_mutex_unlock(&instance->guard);
    236         return ep->data;
    237 }
     238        return node->ep;
     239}
Note: See TracChangeset for help on using the changeset viewer.