[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 |
|
---|
[32fb6bce] | 39 | #include <ddf/driver.h>
|
---|
| 40 | #include <usb/request.h>
|
---|
| 41 |
|
---|
| 42 | typedef struct hw_resource_list_parsed hw_res_list_parsed_t;
|
---|
[64fea02] | 43 | typedef struct bus bus_t;
|
---|
| 44 | typedef struct device device_t;
|
---|
[32fb6bce] | 45 |
|
---|
| 46 | /* Treat this header as read-only in driver code.
|
---|
| 47 | * It could be opaque, but why to complicate matters.
|
---|
| 48 | */
|
---|
| 49 | typedef struct hc_device {
|
---|
| 50 | /* Bus instance */
|
---|
[41924f30] | 51 | bus_t *bus;
|
---|
[9348862] | 52 |
|
---|
[32fb6bce] | 53 | /* Managed DDF device */
|
---|
| 54 | ddf_dev_t *ddf_dev;
|
---|
| 55 |
|
---|
| 56 | /* Control function */
|
---|
| 57 | ddf_fun_t *ctl_fun;
|
---|
| 58 |
|
---|
| 59 | /* Result of enabling HW IRQs */
|
---|
| 60 | int irq_cap;
|
---|
| 61 |
|
---|
[3e200736] | 62 | /** Interrupt replacement fibril */
|
---|
| 63 | fid_t polling_fibril;
|
---|
[b5f813c] | 64 |
|
---|
[32fb6bce] | 65 | /* This structure is meant to be extended by driver code. */
|
---|
| 66 | } hc_device_t;
|
---|
[41924f30] | 67 |
|
---|
[32fb6bce] | 68 | typedef struct hc_driver {
|
---|
| 69 | const char *name;
|
---|
[77ad86c] | 70 |
|
---|
[32fb6bce] | 71 | /** Size of the device data to be allocated, and passed as the
|
---|
| 72 | * hc_device_t. */
|
---|
| 73 | size_t hc_device_size;
|
---|
[77ad86c] | 74 |
|
---|
[32fb6bce] | 75 | /** Initialize device structures. */
|
---|
| 76 | int (*hc_add)(hc_device_t *, const hw_res_list_parsed_t *);
|
---|
| 77 |
|
---|
| 78 | /** Generate IRQ code to handle interrupts. */
|
---|
| 79 | int (*irq_code_gen)(irq_code_t *, hc_device_t *, const hw_res_list_parsed_t *);
|
---|
| 80 |
|
---|
| 81 | /** Claim device from BIOS. */
|
---|
| 82 | int (*claim)(hc_device_t *);
|
---|
| 83 |
|
---|
| 84 | /** Start the host controller. */
|
---|
| 85 | int (*start)(hc_device_t *);
|
---|
| 86 |
|
---|
| 87 | /** Setup the virtual roothub. */
|
---|
| 88 | int (*setup_root_hub)(hc_device_t *);
|
---|
| 89 |
|
---|
| 90 | /** Stop the host controller (after start has been called) */
|
---|
| 91 | int (*stop)(hc_device_t *);
|
---|
| 92 |
|
---|
| 93 | /** HC was asked to be removed (after hc_add has been called) */
|
---|
| 94 | int (*hc_remove)(hc_device_t *);
|
---|
| 95 |
|
---|
| 96 | /** HC is gone. */
|
---|
| 97 | int (*hc_gone)(hc_device_t *);
|
---|
| 98 | } hc_driver_t;
|
---|
| 99 |
|
---|
| 100 | /* Drivers should call this before leaving hc_add */
|
---|
| 101 | static inline void hc_device_setup(hc_device_t *hcd, bus_t *bus) {
|
---|
| 102 | hcd->bus = bus;
|
---|
[b5f813c] | 103 | }
|
---|
| 104 |
|
---|
[32fb6bce] | 105 | static inline hc_device_t *dev_to_hcd(ddf_dev_t *dev)
|
---|
[4daee7a] | 106 | {
|
---|
[32fb6bce] | 107 | return ddf_dev_data_get(dev);
|
---|
[4daee7a] | 108 | }
|
---|
| 109 |
|
---|
[32fb6bce] | 110 | int hc_driver_main(const hc_driver_t *);
|
---|
[9c7ed9c] | 111 |
|
---|
[45d105a] | 112 | #endif
|
---|
[58563585] | 113 |
|
---|
[45d105a] | 114 | /**
|
---|
| 115 | * @}
|
---|
| 116 | */
|
---|