[45d105a] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jan Vesely
|
---|
[e0a5d4c] | 3 | * Copyright (c) 2018 Ondrej Hlavaty
|
---|
[45d105a] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup libusbhost
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | *
|
---|
| 35 | */
|
---|
[77ad86c] | 36 |
|
---|
[45d105a] | 37 | #ifndef LIBUSBHOST_HOST_HCD_H
|
---|
| 38 | #define LIBUSBHOST_HOST_HCD_H
|
---|
| 39 |
|
---|
[32fb6bce] | 40 | #include <ddf/driver.h>
|
---|
| 41 | #include <usb/request.h>
|
---|
| 42 |
|
---|
| 43 | typedef struct hw_resource_list_parsed hw_res_list_parsed_t;
|
---|
[64fea02] | 44 | typedef struct bus bus_t;
|
---|
| 45 | typedef struct device device_t;
|
---|
[32fb6bce] | 46 |
|
---|
[7c3fb9b] | 47 | /*
|
---|
| 48 | * Treat this header as read-only in driver code.
|
---|
[32fb6bce] | 49 | * It could be opaque, but why to complicate matters.
|
---|
| 50 | */
|
---|
| 51 | typedef struct hc_device {
|
---|
| 52 | /* Bus instance */
|
---|
[41924f30] | 53 | bus_t *bus;
|
---|
[9348862] | 54 |
|
---|
[32fb6bce] | 55 | /* Managed DDF device */
|
---|
| 56 | ddf_dev_t *ddf_dev;
|
---|
| 57 |
|
---|
| 58 | /* Control function */
|
---|
| 59 | ddf_fun_t *ctl_fun;
|
---|
| 60 |
|
---|
[eadaeae8] | 61 | /* IRQ capability handle of the subscribed IRQ code */
|
---|
| 62 | cap_irq_handle_t irq_handle;
|
---|
[32fb6bce] | 63 |
|
---|
[3e200736] | 64 | /** Interrupt replacement fibril */
|
---|
| 65 | fid_t polling_fibril;
|
---|
[b5f813c] | 66 |
|
---|
[32fb6bce] | 67 | /* This structure is meant to be extended by driver code. */
|
---|
| 68 | } hc_device_t;
|
---|
[41924f30] | 69 |
|
---|
[32fb6bce] | 70 | typedef struct hc_driver {
|
---|
| 71 | const char *name;
|
---|
[77ad86c] | 72 |
|
---|
[32fb6bce] | 73 | /** Size of the device data to be allocated, and passed as the
|
---|
[7c3fb9b] | 74 | * hc_device_t.
|
---|
| 75 | */
|
---|
[32fb6bce] | 76 | size_t hc_device_size;
|
---|
[77ad86c] | 77 |
|
---|
[32fb6bce] | 78 | /** Initialize device structures. */
|
---|
| 79 | int (*hc_add)(hc_device_t *, const hw_res_list_parsed_t *);
|
---|
| 80 |
|
---|
| 81 | /** Generate IRQ code to handle interrupts. */
|
---|
[ae3a941] | 82 | int (*irq_code_gen)(irq_code_t *, hc_device_t *,
|
---|
| 83 | const hw_res_list_parsed_t *, int *);
|
---|
[32fb6bce] | 84 |
|
---|
| 85 | /** Claim device from BIOS. */
|
---|
| 86 | int (*claim)(hc_device_t *);
|
---|
| 87 |
|
---|
| 88 | /** Start the host controller. */
|
---|
| 89 | int (*start)(hc_device_t *);
|
---|
| 90 |
|
---|
| 91 | /** Setup the virtual roothub. */
|
---|
| 92 | int (*setup_root_hub)(hc_device_t *);
|
---|
| 93 |
|
---|
| 94 | /** Stop the host controller (after start has been called) */
|
---|
| 95 | int (*stop)(hc_device_t *);
|
---|
| 96 |
|
---|
| 97 | /** HC was asked to be removed (after hc_add has been called) */
|
---|
| 98 | int (*hc_remove)(hc_device_t *);
|
---|
| 99 |
|
---|
| 100 | /** HC is gone. */
|
---|
| 101 | int (*hc_gone)(hc_device_t *);
|
---|
| 102 | } hc_driver_t;
|
---|
| 103 |
|
---|
| 104 | /* Drivers should call this before leaving hc_add */
|
---|
[ae3a941] | 105 | static inline void hc_device_setup(hc_device_t *hcd, bus_t *bus)
|
---|
| 106 | {
|
---|
[32fb6bce] | 107 | hcd->bus = bus;
|
---|
[b5f813c] | 108 | }
|
---|
| 109 |
|
---|
[32fb6bce] | 110 | static inline hc_device_t *dev_to_hcd(ddf_dev_t *dev)
|
---|
[4daee7a] | 111 | {
|
---|
[32fb6bce] | 112 | return ddf_dev_data_get(dev);
|
---|
[4daee7a] | 113 | }
|
---|
| 114 |
|
---|
[5a6cc679] | 115 | extern errno_t hc_driver_main(const hc_driver_t *);
|
---|
[9c7ed9c] | 116 |
|
---|
[45d105a] | 117 | #endif
|
---|
[58563585] | 118 |
|
---|
[45d105a] | 119 | /**
|
---|
| 120 | * @}
|
---|
| 121 | */
|
---|