2 * USB xHCI controller emulation
4 * Copyright (c) 2011 Securiforest
5 * Date: 2011-05-11 ; Author: Hector Martin <hector@marcansoft.com>
6 * Based on usb-ohci.c, emulates Renesas NEC USB 3.0
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #ifndef HW_USB_HCD_XHCI_H
23 #define HW_USB_HCD_XHCI_H
24 #include "qom/object.h"
26 #define TYPE_XHCI "base-xhci"
27 #define TYPE_NEC_XHCI "nec-usb-xhci"
28 #define TYPE_QEMU_XHCI "qemu-xhci"
30 OBJECT_DECLARE_SIMPLE_TYPE(XHCIState
, XHCI
)
35 #define MAXPORTS (MAXPORTS_2 + MAXPORTS_3)
39 /* Very pessimistic, let's hope it's enough for all cases */
40 #define EV_QUEUE (((3 * 24) + 16) * MAXSLOTS)
42 typedef struct XHCIStreamContext XHCIStreamContext
;
43 typedef struct XHCIEPContext XHCIEPContext
;
46 XHCI_FLAG_SS_FIRST
= 1,
47 XHCI_FLAG_FORCE_PCIE_ENDCAP
,
48 XHCI_FLAG_ENABLE_STREAMS
,
51 typedef enum TRBType
{
64 CR_CONFIGURE_ENDPOINT
,
72 CR_SET_LATENCY_TOLERANCE
,
73 CR_GET_PORT_BANDWIDTH
,
78 ER_PORT_STATUS_CHANGE
,
82 ER_DEVICE_NOTIFICATION
,
84 /* vendor specific bits */
85 CR_VENDOR_NEC_FIRMWARE_REVISION
= 49,
86 CR_VENDOR_NEC_CHALLENGE_RESPONSE
= 50,
89 typedef enum TRBCCode
{
94 CC_USB_TRANSACTION_ERROR
,
100 CC_INVALID_STREAM_TYPE_ERROR
,
101 CC_SLOT_NOT_ENABLED_ERROR
,
102 CC_EP_NOT_ENABLED_ERROR
,
108 CC_BANDWIDTH_OVERRUN
,
109 CC_CONTEXT_STATE_ERROR
,
110 CC_NO_PING_RESPONSE_ERROR
,
111 CC_EVENT_RING_FULL_ERROR
,
112 CC_INCOMPATIBLE_DEVICE_ERROR
,
113 CC_MISSED_SERVICE_ERROR
,
114 CC_COMMAND_RING_STOPPED
,
117 CC_STOPPED_LENGTH_INVALID
,
118 CC_MAX_EXIT_LATENCY_TOO_LARGE_ERROR
= 29,
119 CC_ISOCH_BUFFER_OVERRUN
= 31,
122 CC_INVALID_STREAM_ID_ERROR
,
123 CC_SECONDARY_BANDWIDTH_ERROR
,
124 CC_SPLIT_TRANSACTION_ERROR
127 typedef struct XHCIRing
{
132 typedef struct XHCIPort
{
142 typedef struct XHCISlot
{
148 XHCIEPContext
*eps
[31];
151 typedef struct XHCIEvent
{
161 typedef struct XHCIInterrupter
{
166 uint32_t erstba_high
;
170 bool msix_used
, er_pcs
;
174 unsigned int er_ep_idx
;
176 /* kept for live migration compat only */
178 XHCIEvent ev_buffer
[EV_QUEUE
];
179 unsigned int ev_buffer_put
;
180 unsigned int ev_buffer_get
;
186 PCIDevice parent_obj
;
191 MemoryRegion mem_cap
;
192 MemoryRegion mem_oper
;
193 MemoryRegion mem_runtime
;
194 MemoryRegion mem_doorbell
;
202 uint32_t max_pstreams_mask
;
206 /* Operational Registers */
213 uint32_t dcbaap_high
;
216 USBPort uports
[MAX_CONST(MAXPORTS_2
, MAXPORTS_3
)];
217 XHCIPort ports
[MAXPORTS
];
218 XHCISlot slots
[MAXSLOTS
];
221 /* Runtime Registers */
222 int64_t mfindex_start
;
223 QEMUTimer
*mfwrap_timer
;
224 XHCIInterrupter intr
[MAXINTRS
];