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

Changeset a8435eb5 in mainline


Ignore:
Timestamp:
2017-10-12T16:42:26Z (3 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
master
Children:
0e3e1f6
Parents:
f9d787c
Message:

Implemented data structure for endpoint management using USB target as hash key. Added XHCI bus destructor.

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

Legend:

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

    rf9d787c ra8435eb5  
    3333 */
    3434
     35#include <adt/hash_table.h>
     36#include <adt/hash.h>
    3537#include <usb/host/endpoint.h>
    3638#include <usb/debug.h>
     
    4446#include "endpoint.h"
    4547
     48/** Element of the hash table. */
     49typedef struct {
     50        ht_link_t link;
     51
     52        /** Endpoint */
     53        endpoint_t *endpoint;
     54} hashed_endpoint_t;
     55
    4656/** Ops receive generic bus_t pointer. */
    4757static inline xhci_bus_t *bus_to_xhci_bus(bus_t *bus_base)
     
    7585}
    7686
     87static int endpoint_find_by_target(xhci_bus_t *bus, usb_target_t target, hashed_endpoint_t **ep)
     88{
     89        ht_link_t *link = hash_table_find(&bus->endpoints, &target.packed);
     90        if (link == NULL)
     91                return ENOENT;
     92
     93        *ep = hash_table_get_inst(link, hashed_endpoint_t, link);
     94        return EOK;
     95}
     96
    7797static int register_endpoint(bus_t *bus_base, endpoint_t *ep)
    7898{
    79         // TODO: Implement me!
    80         return ENOTSUP;
     99        xhci_bus_t *bus = bus_to_xhci_bus(bus_base);
     100        assert(bus);
     101
     102        hashed_endpoint_t *hashed_ep =
     103            (hashed_endpoint_t *) malloc(sizeof(hashed_endpoint_t));
     104        if (!hashed_ep)
     105                return ENOMEM;
     106
     107        hashed_ep->endpoint = ep;
     108        hash_table_insert(&bus->endpoints, &hashed_ep->link);
     109
     110        return EOK;
    81111}
    82112
    83113static int release_endpoint(bus_t *bus_base, endpoint_t *ep)
    84114{
    85         // TODO: Implement me!
    86         return ENOTSUP;
     115        xhci_bus_t *bus = bus_to_xhci_bus(bus_base);
     116        assert(bus);
     117
     118        hashed_endpoint_t *hashed_ep;
     119        int res = endpoint_find_by_target(bus, ep->target, &hashed_ep);
     120        if (res != EOK)
     121                return res;
     122
     123        hash_table_remove(&bus->endpoints, &ep->target.packed);
     124        free(hashed_ep);
     125
     126        return EOK;
    87127}
    88128
    89129static endpoint_t* find_endpoint(bus_t *bus_base, usb_target_t target, usb_direction_t direction)
    90130{
    91         // TODO: Implement me!
    92         return NULL;
     131        xhci_bus_t *bus = bus_to_xhci_bus(bus_base);
     132        assert(bus);
     133
     134        hashed_endpoint_t *hashed_ep;
     135        int res = endpoint_find_by_target(bus, target, &hashed_ep);
     136        if (res != EOK)
     137                return NULL;
     138
     139        return hashed_ep->endpoint;
    93140}
    94141
     
    154201};
    155202
     203static size_t endpoint_ht_hash(const ht_link_t *item)
     204{
     205        hashed_endpoint_t *ep = hash_table_get_inst(item, hashed_endpoint_t, link);
     206        return (size_t) ep->endpoint->target.packed;
     207}
     208
     209static size_t endpoint_ht_key_hash(void *key)
     210{
     211        return (size_t) hash_mix32(*(uint32_t *)key);
     212}
     213
     214static bool endpoint_ht_key_equal(void *key, const ht_link_t *item)
     215{
     216        hashed_endpoint_t *ep = hash_table_get_inst(item, hashed_endpoint_t, link);
     217        return ep->endpoint->target.packed == *(uint32_t *) key;
     218}
     219
     220/** Operations for the endpoint hash table. */
     221static hash_table_ops_t endpoint_ht_ops = {
     222        .hash = endpoint_ht_hash,
     223        .key_hash = endpoint_ht_key_hash,
     224        .key_equal = endpoint_ht_key_equal,
     225        .equal = NULL,
     226        .remove_callback = NULL
     227};
     228
    156229int xhci_bus_init(xhci_bus_t *bus, hcd_t *hcd)
    157230{
     
    160233        bus_init(&bus->base, hcd);
    161234
     235        if (!hash_table_create(&bus->endpoints, 0, 0, &endpoint_ht_ops)) {
     236                // FIXME: Dealloc base!
     237                return ENOMEM;
     238        }
     239
    162240        bus->base.ops = xhci_bus_ops;
    163241        return EOK;
     242}
     243
     244void xhci_bus_fini(xhci_bus_t *bus)
     245{
     246        hash_table_destroy(&bus->endpoints);
    164247}
    165248/**
  • uspace/drv/bus/usb/xhci/bus.h

    rf9d787c ra8435eb5  
    3838#define XHCI_BUS_H
    3939
     40#include <adt/hash_table.h>
    4041#include <usb/usb.h>
    4142#include <usb/host/bus.h>
     
    5051         * addresses can be just too big.
    5152         */
     53
     54        hash_table_t endpoints;
    5255} xhci_bus_t;
    5356
    54 int xhci_bus_init(xhci_bus_t *, hcd_t *hcd);
     57int xhci_bus_init(xhci_bus_t *, hcd_t *);
     58void xhci_bus_fini(xhci_bus_t *);
    5559
    5660#endif
  • uspace/drv/bus/usb/xhci/main.c

    rf9d787c ra8435eb5  
    150150
    151151        hc_fini(hc);
     152
     153        // FIXME: Probably move init/fini of XHCI bus into HC.
     154        xhci_bus_fini(&hc->bus);
     155
    152156        free(hc);
    153157}
Note: See TracChangeset for help on using the changeset viewer.