FreeBSD kernel usb device Code
ohci.h
Go to the documentation of this file.
1/* $FreeBSD$ */
2/*-
3 * SPDX-License-Identifier: BSD-2-Clause-NetBSD
4 *
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net) at
10 * Carlstedt Research & Technology.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef _OHCI_H_
35#define _OHCI_H_
36
37#define OHCI_MAX_DEVICES MIN(USB_MAX_DEVICES, 128)
38
39#define OHCI_NO_INTRS 32
40#define OHCI_HCCA_SIZE 256
41
42/* Structures alignment (bytes) */
43#define OHCI_HCCA_ALIGN 256
44#define OHCI_ED_ALIGN 16
45#define OHCI_TD_ALIGN 16
46#define OHCI_ITD_ALIGN 32
47
48#define OHCI_PAGE_SIZE 0x1000
49#define OHCI_PAGE(x) ((x) &~ 0xfff)
50#define OHCI_PAGE_OFFSET(x) ((x) & 0xfff)
51#define OHCI_PAGE_MASK(x) ((x) & 0xfff)
52
53#if ((USB_PAGE_SIZE < OHCI_ED_ALIGN) || (OHCI_ED_ALIGN == 0) || \
54 (USB_PAGE_SIZE < OHCI_TD_ALIGN) || (OHCI_TD_ALIGN == 0) || \
55 (USB_PAGE_SIZE < OHCI_ITD_ALIGN) || (OHCI_ITD_ALIGN == 0) || \
56 (USB_PAGE_SIZE < OHCI_PAGE_SIZE) || (OHCI_PAGE_SIZE == 0))
57#error "Invalid USB page size!"
58#endif
59
60#define OHCI_VIRTUAL_FRAMELIST_COUNT 128/* dummy */
61
62#if (OHCI_VIRTUAL_FRAMELIST_COUNT < USB_MAX_FS_ISOC_FRAMES_PER_XFER)
63#error "maximum number of full-speed isochronous frames is higher than supported!"
64#endif
65
66struct ohci_hcca {
68 volatile uint32_t hcca_frame_number;
69 volatile uint32_t hcca_done_head;
70#define OHCI_DONE_INTRS 1
72
73typedef struct ohci_hcca ohci_hcca_t;
74
75struct ohci_ed {
76 volatile uint32_t ed_flags;
77#define OHCI_ED_GET_FA(s) ((s) & 0x7f)
78#define OHCI_ED_ADDRMASK 0x0000007f
79#define OHCI_ED_SET_FA(s) (s)
80#define OHCI_ED_GET_EN(s) (((s) >> 7) & 0xf)
81#define OHCI_ED_SET_EN(s) ((s) << 7)
82#define OHCI_ED_DIR_MASK 0x00001800
83#define OHCI_ED_DIR_TD 0x00000000
84#define OHCI_ED_DIR_OUT 0x00000800
85#define OHCI_ED_DIR_IN 0x00001000
86#define OHCI_ED_SPEED 0x00002000
87#define OHCI_ED_SKIP 0x00004000
88#define OHCI_ED_FORMAT_GEN 0x00000000
89#define OHCI_ED_FORMAT_ISO 0x00008000
90#define OHCI_ED_GET_MAXP(s) (((s) >> 16) & 0x07ff)
91#define OHCI_ED_SET_MAXP(s) ((s) << 16)
92#define OHCI_ED_MAXPMASK (0x7ff << 16)
93 volatile uint32_t ed_tailp;
94 volatile uint32_t ed_headp;
95#define OHCI_HALTED 0x00000001
96#define OHCI_TOGGLECARRY 0x00000002
97#define OHCI_HEADMASK 0xfffffffc
98 volatile uint32_t ed_next;
99/*
100 * Extra information needed:
101 */
102 struct ohci_ed *next;
103 struct ohci_ed *prev;
106 uint32_t ed_self;
108
109typedef struct ohci_ed ohci_ed_t;
110
111struct ohci_td {
112 volatile uint32_t td_flags;
113#define OHCI_TD_R 0x00040000 /* Buffer Rounding */
114#define OHCI_TD_DP_MASK 0x00180000 /* Direction / PID */
115#define OHCI_TD_SETUP 0x00000000
116#define OHCI_TD_OUT 0x00080000
117#define OHCI_TD_IN 0x00100000
118#define OHCI_TD_GET_DI(x) (((x) >> 21) & 7) /* Delay Interrupt */
119#define OHCI_TD_SET_DI(x) ((x) << 21)
120#define OHCI_TD_NOINTR 0x00e00000
121#define OHCI_TD_INTR_MASK 0x00e00000
122#define OHCI_TD_TOGGLE_CARRY 0x00000000
123#define OHCI_TD_TOGGLE_0 0x02000000
124#define OHCI_TD_TOGGLE_1 0x03000000
125#define OHCI_TD_TOGGLE_MASK 0x03000000
126#define OHCI_TD_GET_EC(x) (((x) >> 26) & 3) /* Error Count */
127#define OHCI_TD_GET_CC(x) ((x) >> 28) /* Condition Code */
128#define OHCI_TD_SET_CC(x) ((x) << 28)
129#define OHCI_TD_NOCC 0xf0000000
130 volatile uint32_t td_cbp; /* Current Buffer Pointer */
131 volatile uint32_t td_next; /* Next TD */
132#define OHCI_TD_NEXT_END 0
133 volatile uint32_t td_be; /* Buffer End */
134/*
135 * Extra information needed:
136 */
140 uint32_t td_self;
141 uint16_t len;
143
144typedef struct ohci_td ohci_td_t;
145
146struct ohci_itd {
147 volatile uint32_t itd_flags;
148#define OHCI_ITD_GET_SF(x) ((x) & 0x0000ffff)
149#define OHCI_ITD_SET_SF(x) ((x) & 0xffff)
150#define OHCI_ITD_GET_DI(x) (((x) >> 21) & 7) /* Delay Interrupt */
151#define OHCI_ITD_SET_DI(x) ((x) << 21)
152#define OHCI_ITD_NOINTR 0x00e00000
153#define OHCI_ITD_GET_FC(x) ((((x) >> 24) & 7)+1) /* Frame Count */
154#define OHCI_ITD_SET_FC(x) (((x)-1) << 24)
155#define OHCI_ITD_GET_CC(x) ((x) >> 28) /* Condition Code */
156#define OHCI_ITD_NOCC 0xf0000000
157#define OHCI_ITD_NOFFSET 8
158 volatile uint32_t itd_bp0; /* Buffer Page 0 */
159 volatile uint32_t itd_next; /* Next ITD */
160 volatile uint32_t itd_be; /* Buffer End */
161 volatile uint16_t itd_offset[OHCI_ITD_NOFFSET]; /* Buffer offsets and
162 * Status */
163#define OHCI_ITD_PAGE_SELECT 0x00001000
164#define OHCI_ITD_MK_OFFS(len) (0xe000 | ((len) & 0x1fff))
165#define OHCI_ITD_PSW_LENGTH(x) ((x) & 0xfff) /* Transfer length */
166#define OHCI_ITD_PSW_GET_CC(x) ((x) >> 12) /* Condition Code */
167/*
168 * Extra information needed:
169 */
172 uint32_t itd_self;
173 uint8_t frames;
175
176typedef struct ohci_itd ohci_itd_t;
177
178#define OHCI_CC_NO_ERROR 0
179#define OHCI_CC_CRC 1
180#define OHCI_CC_BIT_STUFFING 2
181#define OHCI_CC_DATA_TOGGLE_MISMATCH 3
182#define OHCI_CC_STALL 4
183#define OHCI_CC_DEVICE_NOT_RESPONDING 5
184#define OHCI_CC_PID_CHECK_FAILURE 6
185#define OHCI_CC_UNEXPECTED_PID 7
186#define OHCI_CC_DATA_OVERRUN 8
187#define OHCI_CC_DATA_UNDERRUN 9
188#define OHCI_CC_BUFFER_OVERRUN 12
189#define OHCI_CC_BUFFER_UNDERRUN 13
190#define OHCI_CC_NOT_ACCESSED 15
191
192/* Some delay needed when changing certain registers. */
193#define OHCI_ENABLE_POWER_DELAY 5
194#define OHCI_READ_DESC_DELAY 5
195
196#define OHCI_NO_EDS (2*OHCI_NO_INTRS)
197
204
211
217
222 uint8_t temp[128];
223};
224
225typedef struct ohci_softc {
227 struct usb_bus sc_bus; /* base device */
230
232 struct resource *sc_io_res;
233 struct resource *sc_irq_res;
240 device_t sc_dev;
241 bus_size_t sc_io_size;
242 bus_space_tag_t sc_io_tag;
243 bus_space_handle_t sc_io_hdl;
244
245 uint32_t sc_eintrs; /* enabled interrupts */
246
248 uint16_t sc_id_vendor;
249
250 uint8_t sc_noport;
251 uint8_t sc_addr; /* device address */
252 uint8_t sc_conf; /* device configuration */
253 uint8_t sc_hub_idata[32];
254
255 char sc_vendor[16];
256
258
260
262void ohci_detach(struct ohci_softc *sc);
264
265#endif /* _OHCI_H_ */
#define OHCI_ITD_NOFFSET
Definition: ohci.h:10
#define OHCI_MAX_DEVICES
Definition: ohci.h:37
struct ohci_hw_softc __aligned
void ohci_interrupt(ohci_softc_t *sc)
Definition: ohci.c:1106
void ohci_detach(struct ohci_softc *sc)
Definition: ohci.c:437
usb_bus_mem_cb_t ohci_iterate_hw_softc
Definition: ohci.h:259
struct ohci_config_desc __packed
#define OHCI_ED_ALIGN
Definition: ohci.h:44
#define OHCI_NO_INTRS
Definition: ohci.h:39
usb_error_t ohci_init(ohci_softc_t *sc)
Definition: ohci.c:323
#define OHCI_NO_EDS
Definition: ohci.h:196
#define OHCI_TD_ALIGN
Definition: ohci.h:45
#define OHCI_ITD_ALIGN
Definition: ohci.h:46
#define OHCI_HCCA_ALIGN
Definition: ohci.h:43
struct ohci_softc ohci_softc_t
struct usb_config_descriptor confd
Definition: ohci.h:213
struct usb_endpoint_descriptor endpd
Definition: ohci.h:215
struct usb_interface_descriptor ifcd
Definition: ohci.h:214
Definition: ohci.h:75
struct ohci_ed * next
Definition: ohci.h:102
volatile uint32_t ed_flags
Definition: ohci.h:76
struct usb_page_cache * page_cache
Definition: ohci.h:105
volatile uint32_t ed_next
Definition: ohci.h:98
struct ohci_ed * obj_next
Definition: ohci.h:104
uint32_t ed_self
Definition: ohci.h:106
struct ohci_ed * prev
Definition: ohci.h:103
volatile uint32_t ed_tailp
Definition: ohci.h:93
volatile uint32_t ed_headp
Definition: ohci.h:94
Definition: ohci.h:66
volatile uint32_t hcca_interrupt_table[OHCI_NO_INTRS]
Definition: ohci.h:67
volatile uint32_t hcca_done_head
Definition: ohci.h:69
volatile uint32_t hcca_frame_number
Definition: ohci.h:68
struct usb_page_cache bulk_start_pc
Definition: ohci.h:201
struct usb_page hcca_pg
Definition: ohci.h:205
struct usb_page_cache ctrl_start_pc
Definition: ohci.h:200
struct usb_page bulk_start_pg
Definition: ohci.h:207
struct usb_page_cache hcca_pc
Definition: ohci.h:199
struct usb_page_cache intr_start_pc[OHCI_NO_EDS]
Definition: ohci.h:203
struct usb_page isoc_start_pg
Definition: ohci.h:208
struct usb_page intr_start_pg[OHCI_NO_EDS]
Definition: ohci.h:209
struct usb_page_cache isoc_start_pc
Definition: ohci.h:202
struct usb_page ctrl_start_pg
Definition: ohci.h:206
Definition: ohci.h:146
volatile uint32_t itd_next
Definition: ohci.h:159
uint32_t itd_self
Definition: ohci.h:172
volatile uint32_t itd_be
Definition: ohci.h:160
struct ohci_itd * obj_next
Definition: ohci.h:170
volatile uint32_t itd_bp0
Definition: ohci.h:158
volatile uint32_t itd_flags
Definition: ohci.h:147
volatile uint16_t itd_offset[OHCI_ITD_NOFFSET]
Definition: ohci.h:161
struct usb_page_cache * page_cache
Definition: ohci.h:171
uint8_t frames
Definition: ohci.h:173
uint8_t sc_hub_idata[32]
Definition: ohci.h:253
uint8_t sc_addr
Definition: ohci.h:251
struct ohci_ed * sc_intr_p_last[OHCI_NO_EDS]
Definition: ohci.h:238
struct usb_callout sc_tmo_rhsc
Definition: ohci.h:228
struct ohci_ed * sc_bulk_p_last
Definition: ohci.h:236
bus_space_tag_t sc_io_tag
Definition: ohci.h:242
struct ohci_hw_softc sc_hw
Definition: ohci.h:226
struct ohci_ed * sc_isoc_p_last
Definition: ohci.h:237
union ohci_hub_desc sc_hub_desc
Definition: ohci.h:229
struct ohci_hcca * sc_hcca_p
Definition: ohci.h:234
struct usb_bus sc_bus
Definition: ohci.h:227
struct usb_device * sc_devices[OHCI_MAX_DEVICES]
Definition: ohci.h:231
uint16_t sc_id_vendor
Definition: ohci.h:248
struct ohci_ed * sc_ctrl_p_last
Definition: ohci.h:235
uint16_t sc_intr_stat[OHCI_NO_EDS]
Definition: ohci.h:247
struct resource * sc_irq_res
Definition: ohci.h:233
bus_size_t sc_io_size
Definition: ohci.h:241
struct resource * sc_io_res
Definition: ohci.h:232
device_t sc_dev
Definition: ohci.h:240
char sc_vendor[16]
Definition: ohci.h:255
bus_space_handle_t sc_io_hdl
Definition: ohci.h:243
uint32_t sc_eintrs
Definition: ohci.h:245
uint8_t sc_noport
Definition: ohci.h:250
uint8_t sc_conf
Definition: ohci.h:252
void * sc_intr_hdl
Definition: ohci.h:239
Definition: ohci.h:111
struct ohci_td * alt_next
Definition: ohci.h:138
volatile uint32_t td_be
Definition: ohci.h:133
volatile uint32_t td_cbp
Definition: ohci.h:130
struct ohci_td * obj_next
Definition: ohci.h:137
uint16_t len
Definition: ohci.h:141
volatile uint32_t td_flags
Definition: ohci.h:112
volatile uint32_t td_next
Definition: ohci.h:131
struct usb_page_cache * page_cache
Definition: ohci.h:139
uint32_t td_self
Definition: ohci.h:140
struct usb_status stat
Definition: ohci.h:219
struct usb_port_status ps
Definition: ohci.h:220
struct usb_hub_descriptor hubd
Definition: ohci.h:221
uint8_t temp[128]
Definition: ohci.h:222
void() usb_bus_mem_cb_t(struct usb_bus *bus, usb_bus_mem_sub_cb_t *scb)
usb_error_t
Definition: usbdi.h:45