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