[5cbccd4] | 1 | /*
|
---|
| 2 | * Copyright (c) 2017 Ondrej Hlavaty
|
---|
| 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 drvusbxhci
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * @brief The host controller data bookkeeping.
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[115f25b] | 36 | #ifndef XHCI_HC_H
|
---|
| 37 | #define XHCI_HC_H
|
---|
| 38 |
|
---|
[74b852b] | 39 | #include <fibril_synch.h>
|
---|
[e4d7363] | 40 | #include <usb/host/usb_transfer_batch.h>
|
---|
[5cbccd4] | 41 | #include "hw_struct/regs.h"
|
---|
[cb89430] | 42 | #include "hw_struct/context.h"
|
---|
[fd9f4ffe] | 43 | #include "scratchpad.h"
|
---|
[cb89430] | 44 | #include "trb_ring.h"
|
---|
[2cf28b9] | 45 |
|
---|
[d32d51d] | 46 | #include "rh.h"
|
---|
[889146e] | 47 | #include "commands.h"
|
---|
[41924f30] | 48 | #include "bus.h"
|
---|
[5cbccd4] | 49 |
|
---|
[889146e] | 50 | typedef struct xhci_command xhci_cmd_t;
|
---|
| 51 |
|
---|
[5cbccd4] | 52 | typedef struct xhci_hc {
|
---|
[32fb6bce] | 53 | /** Common HC device header */
|
---|
| 54 | hc_device_t base;
|
---|
| 55 |
|
---|
[91ca111] | 56 | /* MMIO range */
|
---|
| 57 | addr_range_t mmio_range;
|
---|
| 58 |
|
---|
| 59 | /* Mapped register sets */
|
---|
[20eaa82] | 60 | void *reg_base;
|
---|
[5cbccd4] | 61 | xhci_cap_regs_t *cap_regs;
|
---|
| 62 | xhci_op_regs_t *op_regs;
|
---|
[62ba2cbe] | 63 | xhci_rt_regs_t *rt_regs;
|
---|
| 64 | xhci_doorbell_t *db_arry;
|
---|
[91ca111] | 65 | xhci_extcap_t *xecp; /**< First extended capability */
|
---|
| 66 | xhci_legsup_t *legsup; /**< Legacy support capability */
|
---|
[cb89430] | 67 |
|
---|
[91ca111] | 68 | /* Structures in allocated memory */
|
---|
[cb89430] | 69 | xhci_event_ring_t event_ring;
|
---|
[73e5b62] | 70 | uint64_t *dcbaa;
|
---|
[b80c1ab] | 71 | dma_buffer_t dcbaa_dma;
|
---|
| 72 | dma_buffer_t scratchpad_array;
|
---|
[cb89430] | 73 |
|
---|
[889146e] | 74 | /* Command ring management */
|
---|
| 75 | xhci_cmd_ring_t cr;
|
---|
| 76 |
|
---|
[07c08ea] | 77 | /* Root hub emulation */
|
---|
[d32d51d] | 78 | xhci_rh_t rh;
|
---|
| 79 |
|
---|
[41924f30] | 80 | /* Bus bookkeeping */
|
---|
| 81 | xhci_bus_t bus;
|
---|
| 82 |
|
---|
[f3baab1] | 83 | /* Fibril that is currently hanling events */
|
---|
| 84 | fid_t event_handler;
|
---|
| 85 |
|
---|
[91ca111] | 86 | /* Cached capabilities */
|
---|
[cb89430] | 87 | unsigned max_slots;
|
---|
| 88 | bool ac64;
|
---|
[94e9c29] | 89 | uint64_t wrap_time; /** The last time when mfindex wrap happened */
|
---|
| 90 | uint64_t wrap_count; /** Amount of mfindex wraps HC has done */
|
---|
[708d8fcd] | 91 | unsigned ist; /**< IST in microframes */
|
---|
[110d795] | 92 |
|
---|
[f668d60] | 93 | /** Port speed mapping */
|
---|
| 94 | xhci_port_speed_t speeds [16];
|
---|
[5cbccd4] | 95 | } xhci_hc_t;
|
---|
| 96 |
|
---|
[32fb6bce] | 97 | static inline xhci_hc_t *bus_to_hc(bus_t *bus)
|
---|
| 98 | {
|
---|
| 99 | assert(bus);
|
---|
| 100 | return member_to_inst(bus, xhci_hc_t, bus);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[0206d35] | 103 | typedef struct xhci_endpoint xhci_endpoint_t;
|
---|
| 104 | typedef struct xhci_device xhci_device_t;
|
---|
| 105 |
|
---|
[e4d7363] | 106 | int hc_init_mmio(xhci_hc_t *, const hw_res_list_parsed_t *);
|
---|
[0f6b50f] | 107 | int hc_init_memory(xhci_hc_t *, ddf_dev_t *);
|
---|
[e4d7363] | 108 | int hc_claim(xhci_hc_t *, ddf_dev_t *);
|
---|
| 109 | int hc_irq_code_gen(irq_code_t *, xhci_hc_t *, const hw_res_list_parsed_t *);
|
---|
| 110 | int hc_start(xhci_hc_t *, bool);
|
---|
| 111 | void hc_fini(xhci_hc_t *);
|
---|
[708d8fcd] | 112 | void hc_ring_doorbell(xhci_hc_t *, unsigned, unsigned);
|
---|
[8ea7459] | 113 | int hc_enable_slot(xhci_hc_t *, uint32_t *);
|
---|
[9620a54] | 114 | int hc_disable_slot(xhci_hc_t *, xhci_device_t *);
|
---|
[0206d35] | 115 | int hc_address_device(xhci_hc_t *, xhci_device_t *, xhci_endpoint_t *);
|
---|
[b724494] | 116 | int hc_configure_device(xhci_hc_t *, uint32_t);
|
---|
| 117 | int hc_deconfigure_device(xhci_hc_t *, uint32_t);
|
---|
| 118 | int hc_add_endpoint(xhci_hc_t *, uint32_t, uint8_t, xhci_ep_ctx_t *);
|
---|
| 119 | int hc_drop_endpoint(xhci_hc_t *, uint32_t, uint8_t);
|
---|
[306a36d] | 120 | int hc_update_endpoint(xhci_hc_t *, uint32_t, uint8_t, xhci_ep_ctx_t *);
|
---|
[30fc56f] | 121 | int hc_stop_endpoint(xhci_hc_t *, uint32_t , uint8_t);
|
---|
[5cbccd4] | 122 |
|
---|
[32fb6bce] | 123 | int hc_status(bus_t *, uint32_t *);
|
---|
| 124 | void hc_interrupt(bus_t *, uint32_t);
|
---|
| 125 |
|
---|
[115f25b] | 126 | #endif
|
---|
| 127 |
|
---|
[5cbccd4] | 128 | /**
|
---|
| 129 | * @}
|
---|
| 130 | */
|
---|