source: mainline/uspace/drv/bus/usb/xhci/hc.h

Last change on this file was 8300c72, checked in by Jiri Svoboda <jiri@…>, 4 months ago

Quiesce devices before proceeding with shutdown.

Only implemented for e1k, uhci and xhci.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * Copyright (c) 2025 Jiri Svoboda
3 * Copyright (c) 2018 Ondrej Hlavaty, Jan Hrach, Jaroslav Jindrak, Petr Manek
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 drvusbxhci
31 * @{
32 */
33/** @file
34 * @brief The host controller data bookkeeping.
35 */
36
37#ifndef XHCI_HC_H
38#define XHCI_HC_H
39
40#include <fibril_synch.h>
41#include <member.h>
42#include <usb/host/usb_transfer_batch.h>
43#include <usb/host/utility.h>
44#include "hw_struct/regs.h"
45#include "hw_struct/context.h"
46#include "scratchpad.h"
47#include "trb_ring.h"
48
49#include "rh.h"
50#include "commands.h"
51#include "bus.h"
52
53typedef struct xhci_command xhci_cmd_t;
54
55typedef struct xhci_hc {
56 /** Common HC device header */
57 hc_device_t base;
58
59 /* MMIO range */
60 addr_range_t mmio_range;
61
62 /* Mapped register sets */
63 void *reg_base;
64 xhci_cap_regs_t *cap_regs;
65 xhci_op_regs_t *op_regs;
66 xhci_rt_regs_t *rt_regs;
67 xhci_doorbell_t *db_arry;
68 xhci_extcap_t *xecp; /**< First extended capability */
69 xhci_legsup_t *legsup; /**< Legacy support capability */
70
71 /* Structures in allocated memory */
72 xhci_event_ring_t event_ring;
73 uint64_t *dcbaa;
74 dma_buffer_t dcbaa_dma;
75 dma_buffer_t scratchpad_array;
76
77 /* Command ring management */
78 xhci_cmd_ring_t cr;
79
80 /* Buffer for events */
81 xhci_sw_ring_t sw_ring;
82
83 /** Event handling fibril */
84 joinable_fibril_t *event_worker;
85
86 /* Root hub emulation */
87 xhci_rh_t rh;
88
89 /* Bus bookkeeping */
90 xhci_bus_t bus;
91
92 /* Fibril that is currently hanling events */
93 fid_t event_handler;
94
95 /* Cached capabilities */
96 unsigned max_slots;
97 bool ac64;
98 bool csz;
99 uint64_t wrap_time; /**< The last time when mfindex wrap happened */
100 uint64_t wrap_count; /**< Amount of mfindex wraps HC has done */
101 unsigned ist; /**< IST in microframes */
102
103 /** Port speed mapping */
104 xhci_port_speed_t speeds [16];
105} xhci_hc_t;
106
107static inline xhci_hc_t *bus_to_hc(bus_t *bus)
108{
109 assert(bus);
110 return member_to_inst(bus, xhci_hc_t, bus);
111}
112
113typedef struct xhci_endpoint xhci_endpoint_t;
114typedef struct xhci_device xhci_device_t;
115
116extern errno_t hc_init_mmio(xhci_hc_t *, const hw_res_list_parsed_t *);
117extern errno_t hc_init_memory(xhci_hc_t *, ddf_dev_t *);
118extern errno_t hc_claim(xhci_hc_t *, ddf_dev_t *);
119extern errno_t hc_irq_code_gen(irq_code_t *, xhci_hc_t *, const hw_res_list_parsed_t *, int *);
120extern errno_t hc_start(xhci_hc_t *);
121extern void hc_fini(xhci_hc_t *);
122extern errno_t hc_quiesce(xhci_hc_t *);
123
124extern void hc_ring_doorbell(xhci_hc_t *, unsigned, unsigned);
125extern void hc_ring_ep_doorbell(xhci_endpoint_t *, uint32_t);
126extern unsigned hc_speed_to_psiv(usb_speed_t);
127
128extern errno_t hc_enable_slot(xhci_device_t *);
129extern errno_t hc_disable_slot(xhci_device_t *);
130extern errno_t hc_address_device(xhci_device_t *);
131extern errno_t hc_configure_device(xhci_device_t *);
132extern errno_t hc_deconfigure_device(xhci_device_t *);
133extern errno_t hc_add_endpoint(xhci_endpoint_t *);
134extern errno_t hc_drop_endpoint(xhci_endpoint_t *);
135extern errno_t hc_update_endpoint(xhci_endpoint_t *);
136extern errno_t hc_stop_endpoint(xhci_endpoint_t *);
137extern errno_t hc_reset_endpoint(xhci_endpoint_t *);
138extern errno_t hc_reset_ring(xhci_endpoint_t *, uint32_t);
139
140extern errno_t hc_status(bus_t *, uint32_t *);
141extern void hc_interrupt(bus_t *, uint32_t);
142
143#endif
144
145/**
146 * @}
147 */
Note: See TracBrowser for help on using the repository browser.