source: mainline/uspace/lib/usbhost/include/usb/host/hcd.h@ e657635

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e657635 was b5f813c, checked in by Jan Vesely <jano.vesely@…>, 10 years ago

libusbhost,ehci,ohci,uhci,vhc: Pass ops structure instead of function pointers to intialization

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[45d105a]1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libusbhost
30 * @{
31 */
32/** @file
33 *
34 */
[77ad86c]35
[45d105a]36#ifndef LIBUSBHOST_HOST_HCD_H
37#define LIBUSBHOST_HOST_HCD_H
38
[8d2e251]39#include <usb/host/endpoint.h>
[4cf5b8e0]40#include <usb/host/usb_bus.h>
[f58ef61]41#include <usb/host/usb_transfer_batch.h>
[8d2e251]42#include <usb/usb.h>
43
44#include <assert.h>
45#include <usbhc_iface.h>
46#include <sys/types.h>
[45d105a]47
48typedef struct hcd hcd_t;
49
[f29931c]50typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
51typedef int (*ep_add_hook_t)(hcd_t *, endpoint_t *);
52typedef void (*ep_remove_hook_t)(hcd_t *, endpoint_t *);
[7191992]53typedef void (*interrupt_hook_t)(hcd_t *, uint32_t);
[e26a9d95]54typedef int (*status_hook_t)(hcd_t *, uint32_t *);
[f29931c]55
[9348862]56typedef struct {
[4dfc905]57 /** Transfer scheduling, implement in device driver. */
[f29931c]58 schedule_hook_t schedule;
[4dfc905]59 /** Hook called upon registering new endpoint. */
[f29931c]60 ep_add_hook_t ep_add_hook;
[4dfc905]61 /** Hook called upon removing of an endpoint. */
[f29931c]62 ep_remove_hook_t ep_remove_hook;
[7191992]63 /** Hook to be called on device interrupt, passes ARG1 */
64 interrupt_hook_t irq_hook;
[e26a9d95]65 /** Periodic polling hook */
66 status_hook_t status_hook;
[b5f813c]67} hcd_ops_t;
[9348862]68
69/** Generic host controller driver structure. */
70struct hcd {
71 /** Endpoint manager. */
[4cf5b8e0]72 usb_bus_t bus;
[9348862]73
[3e200736]74 /** Interrupt replacement fibril */
75 fid_t polling_fibril;
[b5f813c]76
77 /** Driver implementation */
78 hcd_ops_t ops;
79 /** Device specific driver data. */
80 void * driver_data;
[45d105a]81};
[77ad86c]82
[21be46a]83void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
84 bw_count_func_t bw_count);
[77ad86c]85
[4daee7a]86static inline void hcd_set_implementation(hcd_t *hcd, void *data,
[b5f813c]87 const hcd_ops_t *ops)
88{
89 assert(hcd);
90 if (ops) {
91 hcd->driver_data = data;
92 hcd->ops = *ops;
93 } else {
94 memset(&hcd->ops, 0, sizeof(hcd->ops));
95 }
96}
97
98static inline void * hcd_get_driver_data(hcd_t *hcd)
[4daee7a]99{
100 assert(hcd);
[b5f813c]101 return hcd->driver_data;
[4daee7a]102}
103
[b4c1c95]104usb_address_t hcd_request_address(hcd_t *hcd, usb_speed_t speed);
105
106int hcd_release_address(hcd_t *hcd, usb_address_t address);
107
108int hcd_reserve_default_address(hcd_t *hcd, usb_speed_t speed);
109
[237df2f]110static inline int hcd_release_default_address(hcd_t *hcd)
[b4c1c95]111{
112 return hcd_release_address(hcd, USB_ADDRESS_DEFAULT);
113}
114
[0816c2e]115int hcd_add_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir,
[4e732f1a]116 usb_transfer_type_t type, size_t max_packet_size, unsigned packets,
117 size_t size, usb_address_t tt_address, unsigned tt_port);
[0816c2e]118
119int hcd_remove_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir);
120
[3c4663e]121int hcd_send_batch(hcd_t *hcd, usb_target_t target, usb_direction_t direction,
[d9b2c73]122 void *data, size_t size, uint64_t setup_data,
123 usbhc_iface_transfer_in_callback_t in,
124 usbhc_iface_transfer_out_callback_t out, void *arg, const char* name);
[9c7ed9c]125
[237df2f]126ssize_t hcd_send_batch_sync(hcd_t *hcd, usb_target_t target,
127 usb_direction_t dir, void *data, size_t size, uint64_t setup_data,
128 const char* name);
129
[45d105a]130#endif
131/**
132 * @}
133 */
Note: See TracBrowser for help on using the repository browser.