2 * USB xHCI controller emulation
4 * Copyright (c) 2011 Securiforest
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 #define TYPE_XHCI "base-xhci"
23 #define TYPE_NEC_XHCI "nec-usb-xhci"
24 #define TYPE_QEMU_XHCI "qemu-xhci"
27 OBJECT_CHECK(XHCIState, (obj), TYPE_XHCI)
32 #define MAXPORTS (MAXPORTS_2 + MAXPORTS_3)
36 /* Very pessimistic, let's hope it's enough for all cases */
37 #define EV_QUEUE (((3 * 24) + 16) * MAXSLOTS)
39 typedef struct XHCIState XHCIState;
40 typedef struct XHCIStreamContext XHCIStreamContext;
41 typedef struct XHCIEPContext XHCIEPContext;
44 XHCI_FLAG_SS_FIRST = 1,
45 XHCI_FLAG_FORCE_PCIE_ENDCAP,
46 XHCI_FLAG_ENABLE_STREAMS,
49 typedef enum TRBType {
62 CR_CONFIGURE_ENDPOINT,
70 CR_SET_LATENCY_TOLERANCE,
71 CR_GET_PORT_BANDWIDTH,
76 ER_PORT_STATUS_CHANGE,
80 ER_DEVICE_NOTIFICATION,
82 /* vendor specific bits */
83 CR_VENDOR_NEC_FIRMWARE_REVISION = 49,
84 CR_VENDOR_NEC_CHALLENGE_RESPONSE = 50,
87 typedef enum TRBCCode {
92 CC_USB_TRANSACTION_ERROR,
98 CC_INVALID_STREAM_TYPE_ERROR,
99 CC_SLOT_NOT_ENABLED_ERROR,
100 CC_EP_NOT_ENABLED_ERROR,
106 CC_BANDWIDTH_OVERRUN,
107 CC_CONTEXT_STATE_ERROR,
108 CC_NO_PING_RESPONSE_ERROR,
109 CC_EVENT_RING_FULL_ERROR,
110 CC_INCOMPATIBLE_DEVICE_ERROR,
111 CC_MISSED_SERVICE_ERROR,
112 CC_COMMAND_RING_STOPPED,
115 CC_STOPPED_LENGTH_INVALID,
116 CC_MAX_EXIT_LATENCY_TOO_LARGE_ERROR = 29,
117 CC_ISOCH_BUFFER_OVERRUN = 31,
120 CC_INVALID_STREAM_ID_ERROR,
121 CC_SECONDARY_BANDWIDTH_ERROR,
122 CC_SPLIT_TRANSACTION_ERROR
125 typedef struct XHCIRing {
130 typedef struct XHCIPort {
140 typedef struct XHCISlot {
145 XHCIEPContext *eps[31];
148 typedef struct XHCIEvent {
158 typedef struct XHCIInterrupter {
163 uint32_t erstba_high;
167 bool msix_used, er_pcs;
171 unsigned int er_ep_idx;
173 /* kept for live migration compat only */
175 XHCIEvent ev_buffer[EV_QUEUE];
176 unsigned int ev_buffer_put;
177 unsigned int ev_buffer_get;
183 PCIDevice parent_obj;
188 MemoryRegion mem_cap;
189 MemoryRegion mem_oper;
190 MemoryRegion mem_runtime;
191 MemoryRegion mem_doorbell;
199 uint32_t max_pstreams_mask;
203 /* Operational Registers */
210 uint32_t dcbaap_high;
213 USBPort uports[MAX(MAXPORTS_2, MAXPORTS_3)];
214 XHCIPort ports[MAXPORTS];
215 XHCISlot slots[MAXSLOTS];
218 /* Runtime Registers */
219 int64_t mfindex_start;
220 QEMUTimer *mfwrap_timer;
221 XHCIInterrupter intr[MAXINTRS];