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

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

Quiesce devices before proceeding with shutdown.

Only implemented for e1k, uhci and xhci.

  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[9351353]1/*
[8300c72]2 * Copyright (c) 2025 Jiri Svoboda
[a9f91cd]3 * Copyright (c) 2011 Jan Vesely
[e0a5d4c]4 * Copyright (c) 2018 Ondrej Hlavaty
[9351353]5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
[c8ea6eca]31/** @addtogroup drvusbuhci
[9351353]32 * @{
33 */
34/** @file
[17ceb72]35 * @brief UHCI host controller driver structure
[9351353]36 */
[58563585]37
[23f40280]38#ifndef DRV_UHCI_HC_H
39#define DRV_UHCI_HC_H
[9351353]40
[7de1988c]41#include <device/hw_res_parsed.h>
[9351353]42#include <fibril.h>
[c95c00e]43#include <macros.h>
[36795edf]44#include <member.h>
[8064c2f6]45#include <stdbool.h>
[7ee7e6a]46#include <ddi.h>
[5fe0a697]47#include <usb/host/hcd.h>
[fc0271a5]48#include <usb/host/usb2_bus.h>
[8064c2f6]49#include <usb/host/usb_transfer_batch.h>
[9351353]50
[8064c2f6]51#include "uhci_rh.h"
[9351353]52#include "transfer_list.h"
[8064c2f6]53#include "hw_struct/link_pointer.h"
[9351353]54
[ea993d18]55/** UHCI I/O registers layout */
[9351353]56typedef struct uhci_regs {
[ea993d18]57 /** Command register, controls HC behaviour */
[c95c00e]58 ioport16_t usbcmd;
[9351353]59#define UHCI_CMD_MAX_PACKET (1 << 7)
60#define UHCI_CMD_CONFIGURE (1 << 6)
61#define UHCI_CMD_DEBUG (1 << 5)
62#define UHCI_CMD_FORCE_GLOBAL_RESUME (1 << 4)
63#define UHCI_CMD_FORCE_GLOBAL_SUSPEND (1 << 3)
64#define UHCI_CMD_GLOBAL_RESET (1 << 2)
65#define UHCI_CMD_HCRESET (1 << 1)
66#define UHCI_CMD_RUN_STOP (1 << 0)
67
[ea993d18]68 /** Status register, 1 means interrupt is asserted (if enabled) */
[c95c00e]69 ioport16_t usbsts;
[9351353]70#define UHCI_STATUS_HALTED (1 << 5)
71#define UHCI_STATUS_PROCESS_ERROR (1 << 4)
72#define UHCI_STATUS_SYSTEM_ERROR (1 << 3)
73#define UHCI_STATUS_RESUME (1 << 2)
74#define UHCI_STATUS_ERROR_INTERRUPT (1 << 1)
75#define UHCI_STATUS_INTERRUPT (1 << 0)
[302a4b6]76#define UHCI_STATUS_NM_INTERRUPTS \
77 (UHCI_STATUS_PROCESS_ERROR | UHCI_STATUS_SYSTEM_ERROR)
[9351353]78
[ea993d18]79 /** Interrupt enabled registers */
[c95c00e]80 ioport16_t usbintr;
[9351353]81#define UHCI_INTR_SHORT_PACKET (1 << 3)
82#define UHCI_INTR_COMPLETE (1 << 2)
83#define UHCI_INTR_RESUME (1 << 1)
84#define UHCI_INTR_CRC (1 << 0)
85
[ea993d18]86 /** Register stores frame number used in SOF packet */
[c95c00e]87 ioport16_t frnum;
[ea993d18]88
89 /** Pointer(physical) to the Frame List */
[c95c00e]90 ioport32_t flbaseadd;
[ea993d18]91
92 /** SOF modification to match external timers */
[c95c00e]93 ioport8_t sofmod;
94
[af60409]95 PADD8(3);
[c95c00e]96 ioport16_t ports[];
[dfe4955]97} uhci_regs_t;
[9351353]98
99#define UHCI_FRAME_LIST_COUNT 1024
100#define UHCI_DEBUGER_TIMEOUT 5000000
[fcc525d]101#define UHCI_ALLOWED_HW_FAIL 5
[9351353]102
[02cacce]103/** Main UHCI driver structure */
[c01cd32]104typedef struct hc {
[32fb6bce]105 /* Common hc_device header */
106 hc_device_t base;
107
[c95c00e]108 uhci_rh_t rh;
[d369b3b]109 bus_t bus;
110 usb2_bus_helper_t bus_helper;
111
[ea993d18]112 /** Addresses of I/O registers */
[dfe4955]113 uhci_regs_t *registers;
[9351353]114
[ea993d18]115 /** Frame List contains 1024 link pointers */
[9351353]116 link_pointer_t *frame_list;
117
[ea993d18]118 /** List and queue of interrupt transfers */
119 transfer_list_t transfers_interrupt;
120 /** List and queue of low speed control transfers */
121 transfer_list_t transfers_control_slow;
122 /** List and queue of full speed bulk transfers */
[9351353]123 transfer_list_t transfers_bulk_full;
[ea993d18]124 /** List and queue of full speed control transfers */
[9351353]125 transfer_list_t transfers_control_full;
126
[ea993d18]127 /** Pointer table to the above lists, helps during scheduling */
[9351353]128 transfer_list_t *transfers[2][4];
129
[4db49344]130 /**
131 * Guard for the pending list. Can be locked under EP guard, but not
132 * vice versa.
133 */
134 fibril_mutex_t guard;
135 /** List of endpoints with a transfer scheduled */
136 list_t pending_endpoints;
137
[ea993d18]138 /** Number of hw failures detected. */
139 unsigned hw_failures;
[c01cd32]140} hc_t;
[3afb758]141
[c6f82e5]142typedef struct uhci_endpoint {
143 endpoint_t base;
144
145 bool toggle;
146} uhci_endpoint_t;
147
[32fb6bce]148static inline hc_t *hcd_to_hc(hc_device_t *hcd)
149{
150 assert(hcd);
151 return (hc_t *) hcd;
152}
153
154static inline hc_t *bus_to_hc(bus_t *bus)
155{
156 assert(bus);
157 return member_to_inst(bus, hc_t, bus);
158}
159
[929599a8]160int hc_unschedule_batch(usb_transfer_batch_t *);
161
[5a6cc679]162extern errno_t hc_add(hc_device_t *, const hw_res_list_parsed_t *);
163extern errno_t hc_gen_irq_code(irq_code_t *, hc_device_t *, const hw_res_list_parsed_t *, int *);
164extern errno_t hc_start(hc_device_t *);
165extern errno_t hc_setup_roothub(hc_device_t *);
166extern errno_t hc_gone(hc_device_t *);
[8300c72]167extern errno_t hc_quiesce(hc_device_t *);
[9351353]168
169#endif
[7de1988c]170
[9351353]171/**
172 * @}
173 */
Note: See TracBrowser for help on using the repository browser.