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"
27 #include "sysemu/dma.h"
29 #define TYPE_XHCI "base-xhci"
30 #define TYPE_NEC_XHCI "nec-usb-xhci"
31 #define TYPE_QEMU_XHCI "qemu-xhci"
33 OBJECT_DECLARE_SIMPLE_TYPE(XHCIState
, XHCI
)
38 #define MAXPORTS (MAXPORTS_2 + MAXPORTS_3)
42 /* Very pessimistic, let's hope it's enough for all cases */
43 #define EV_QUEUE (((3 * 24) + 16) * MAXSLOTS)
45 typedef struct XHCIStreamContext XHCIStreamContext
;
46 typedef struct XHCIEPContext XHCIEPContext
;
49 XHCI_FLAG_SS_FIRST
= 1,
50 XHCI_FLAG_FORCE_PCIE_ENDCAP
,
51 XHCI_FLAG_ENABLE_STREAMS
,
54 typedef enum TRBType
{
67 CR_CONFIGURE_ENDPOINT
,
75 CR_SET_LATENCY_TOLERANCE
,
76 CR_GET_PORT_BANDWIDTH
,
81 ER_PORT_STATUS_CHANGE
,
85 ER_DEVICE_NOTIFICATION
,
87 /* vendor specific bits */
88 CR_VENDOR_NEC_FIRMWARE_REVISION
= 49,
89 CR_VENDOR_NEC_CHALLENGE_RESPONSE
= 50,
92 typedef enum TRBCCode
{
97 CC_USB_TRANSACTION_ERROR
,
103 CC_INVALID_STREAM_TYPE_ERROR
,
104 CC_SLOT_NOT_ENABLED_ERROR
,
105 CC_EP_NOT_ENABLED_ERROR
,
111 CC_BANDWIDTH_OVERRUN
,
112 CC_CONTEXT_STATE_ERROR
,
113 CC_NO_PING_RESPONSE_ERROR
,
114 CC_EVENT_RING_FULL_ERROR
,
115 CC_INCOMPATIBLE_DEVICE_ERROR
,
116 CC_MISSED_SERVICE_ERROR
,
117 CC_COMMAND_RING_STOPPED
,
120 CC_STOPPED_LENGTH_INVALID
,
121 CC_MAX_EXIT_LATENCY_TOO_LARGE_ERROR
= 29,
122 CC_ISOCH_BUFFER_OVERRUN
= 31,
125 CC_INVALID_STREAM_ID_ERROR
,
126 CC_SECONDARY_BANDWIDTH_ERROR
,
127 CC_SPLIT_TRANSACTION_ERROR
130 typedef struct XHCIRing
{
135 typedef struct XHCIPort
{
145 typedef struct XHCISlot
{
151 XHCIEPContext
*eps
[31];
154 typedef struct XHCIEvent
{
164 typedef struct XHCIInterrupter
{
169 uint32_t erstba_high
;
173 bool msix_used
, er_pcs
;
177 unsigned int er_ep_idx
;
179 /* kept for live migration compat only */
181 XHCIEvent ev_buffer
[EV_QUEUE
];
182 unsigned int ev_buffer_put
;
183 unsigned int ev_buffer_get
;
187 typedef struct XHCIState
{
192 MemoryRegion
*dma_mr
;
194 MemoryRegion mem_cap
;
195 MemoryRegion mem_oper
;
196 MemoryRegion mem_runtime
;
197 MemoryRegion mem_doorbell
;
205 uint32_t max_pstreams_mask
;
206 void (*intr_update
)(XHCIState
*s
, int n
, bool enable
);
207 void (*intr_raise
)(XHCIState
*s
, int n
, bool level
);
208 DeviceState
*hostOpaque
;
210 /* Operational Registers */
217 uint32_t dcbaap_high
;
220 USBPort uports
[MAX_CONST(MAXPORTS_2
, MAXPORTS_3
)];
221 XHCIPort ports
[MAXPORTS
];
222 XHCISlot slots
[MAXSLOTS
];
225 /* Runtime Registers */
226 int64_t mfindex_start
;
227 QEMUTimer
*mfwrap_timer
;
228 XHCIInterrupter intr
[MAXINTRS
];
235 extern const VMStateDescription vmstate_xhci
;
236 bool xhci_get_flag(XHCIState
*xhci
, enum xhci_flags bit
);
237 void xhci_set_flag(XHCIState
*xhci
, enum xhci_flags bit
);