[6297465] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jan Vesely
|
---|
[e0a5d4c] | 3 | * Copyright (c) 2018 Ondrej Hlavaty
|
---|
[6297465] | 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 | /** @addtogroup drvusbehci
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * @brief EHCI host controller driver structure
|
---|
| 34 | */
|
---|
| 35 | #ifndef DRV_EHCI_HC_H
|
---|
| 36 | #define DRV_EHCI_HC_H
|
---|
| 37 |
|
---|
| 38 | #include <adt/list.h>
|
---|
| 39 | #include <ddi.h>
|
---|
| 40 | #include <ddf/driver.h>
|
---|
| 41 | #include <device/hw_res_parsed.h>
|
---|
| 42 | #include <fibril.h>
|
---|
| 43 | #include <fibril_synch.h>
|
---|
| 44 | #include <stdbool.h>
|
---|
[8d2dd7f2] | 45 | #include <stdint.h>
|
---|
[6297465] | 46 |
|
---|
| 47 | #include <usb/host/hcd.h>
|
---|
| 48 | #include <usb/host/endpoint.h>
|
---|
| 49 | #include <usb/host/usb_transfer_batch.h>
|
---|
| 50 |
|
---|
| 51 | #include "ehci_regs.h"
|
---|
| 52 | #include "ehci_rh.h"
|
---|
[478e243] | 53 | #include "hw_struct/link_pointer.h"
|
---|
[5f5321ee] | 54 | #include "endpoint_list.h"
|
---|
[6297465] | 55 |
|
---|
| 56 | /** Main EHCI driver structure */
|
---|
| 57 | typedef struct hc {
|
---|
[32fb6bce] | 58 | /* Common device header */
|
---|
| 59 | hc_device_t base;
|
---|
| 60 |
|
---|
[6297465] | 61 | /** Memory mapped CAPS register area */
|
---|
| 62 | ehci_caps_regs_t *caps;
|
---|
| 63 | /** Memory mapped I/O registers area */
|
---|
| 64 | ehci_regs_t *registers;
|
---|
| 65 |
|
---|
[35c37fc] | 66 | /** Iso transfer list, backed by dma_buffer */
|
---|
| 67 | link_pointer_t *periodic_list;
|
---|
| 68 |
|
---|
| 69 | dma_buffer_t dma_buffer;
|
---|
[478e243] | 70 |
|
---|
[5f5321ee] | 71 | /** CONTROL and BULK schedules */
|
---|
| 72 | endpoint_list_t async_list;
|
---|
| 73 |
|
---|
| 74 | /** INT schedule */
|
---|
| 75 | endpoint_list_t int_list;
|
---|
| 76 |
|
---|
[6297465] | 77 | /** List of active transfers */
|
---|
[8ad2b0a] | 78 | list_t pending_endpoints;
|
---|
[6297465] | 79 |
|
---|
| 80 | /** Guards schedule and endpoint manipulation */
|
---|
| 81 | fibril_mutex_t guard;
|
---|
| 82 |
|
---|
[763dbcb] | 83 | /** Wait for hc to restart async chedule */
|
---|
| 84 | fibril_condvar_t async_doorbell;
|
---|
| 85 |
|
---|
[6297465] | 86 | /** USB hub emulation structure */
|
---|
| 87 | ehci_rh_t rh;
|
---|
[741bcdeb] | 88 |
|
---|
| 89 | /** USB bookkeeping */
|
---|
| 90 | ehci_bus_t bus;
|
---|
[6297465] | 91 | } hc_t;
|
---|
| 92 |
|
---|
[32fb6bce] | 93 | static inline hc_t *hcd_to_hc(hc_device_t *hcd)
|
---|
| 94 | {
|
---|
| 95 | assert(hcd);
|
---|
| 96 | return (hc_t *) hcd;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | void hc_enqueue_endpoint(hc_t *, const endpoint_t *);
|
---|
| 100 | void hc_dequeue_endpoint(hc_t *, const endpoint_t *);
|
---|
[6297465] | 101 |
|
---|
[32fb6bce] | 102 | /* Boottime operations */
|
---|
[5a6cc679] | 103 | extern errno_t hc_add(hc_device_t *, const hw_res_list_parsed_t *);
|
---|
| 104 | extern errno_t hc_start(hc_device_t *);
|
---|
| 105 | extern errno_t hc_setup_roothub(hc_device_t *);
|
---|
[ae3a941] | 106 | extern errno_t hc_gen_irq_code(irq_code_t *, hc_device_t *,
|
---|
| 107 | const hw_res_list_parsed_t *, int *);
|
---|
[5a6cc679] | 108 | extern errno_t hc_gone(hc_device_t *);
|
---|
[6297465] | 109 |
|
---|
[32fb6bce] | 110 | /** Runtime operations */
|
---|
[8bfb163] | 111 | extern void ehci_hc_interrupt(bus_t *, uint32_t);
|
---|
[5a6cc679] | 112 | extern errno_t ehci_hc_status(bus_t *, uint32_t *);
|
---|
| 113 | extern errno_t ehci_hc_schedule(usb_transfer_batch_t *);
|
---|
[c9e954c] | 114 |
|
---|
[6297465] | 115 | #endif
|
---|
| 116 | /**
|
---|
| 117 | * @}
|
---|
| 118 | */
|
---|