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.1 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 "hw/usb/xhci.h"
28 #include "sysemu/dma.h"
30 OBJECT_DECLARE_SIMPLE_TYPE(XHCIState
, XHCI
)
32 /* Very pessimistic, let's hope it's enough for all cases */
33 #define EV_QUEUE (((3 * 24) + 16) * XHCI_MAXSLOTS)
35 typedef struct XHCIStreamContext XHCIStreamContext
;
36 typedef struct XHCIEPContext XHCIEPContext
;
39 XHCI_FLAG_SS_FIRST
= 1,
40 XHCI_FLAG_FORCE_PCIE_ENDCAP
,
41 XHCI_FLAG_ENABLE_STREAMS
,
44 typedef enum TRBType
{
57 CR_CONFIGURE_ENDPOINT
,
65 CR_SET_LATENCY_TOLERANCE
,
66 CR_GET_PORT_BANDWIDTH
,
71 ER_PORT_STATUS_CHANGE
,
75 ER_DEVICE_NOTIFICATION
,
77 /* vendor specific bits */
78 CR_VENDOR_NEC_FIRMWARE_REVISION
= 49,
79 CR_VENDOR_NEC_CHALLENGE_RESPONSE
= 50,
82 typedef enum TRBCCode
{
87 CC_USB_TRANSACTION_ERROR
,
93 CC_INVALID_STREAM_TYPE_ERROR
,
94 CC_SLOT_NOT_ENABLED_ERROR
,
95 CC_EP_NOT_ENABLED_ERROR
,
101 CC_BANDWIDTH_OVERRUN
,
102 CC_CONTEXT_STATE_ERROR
,
103 CC_NO_PING_RESPONSE_ERROR
,
104 CC_EVENT_RING_FULL_ERROR
,
105 CC_INCOMPATIBLE_DEVICE_ERROR
,
106 CC_MISSED_SERVICE_ERROR
,
107 CC_COMMAND_RING_STOPPED
,
110 CC_STOPPED_LENGTH_INVALID
,
111 CC_MAX_EXIT_LATENCY_TOO_LARGE_ERROR
= 29,
112 CC_ISOCH_BUFFER_OVERRUN
= 31,
115 CC_INVALID_STREAM_ID_ERROR
,
116 CC_SECONDARY_BANDWIDTH_ERROR
,
117 CC_SPLIT_TRANSACTION_ERROR
120 typedef struct XHCIRing
{
125 typedef struct XHCIPort
{
135 typedef struct XHCISlot
{
141 XHCIEPContext
*eps
[31];
144 typedef struct XHCIEvent
{
154 typedef struct XHCIInterrupter
{
159 uint32_t erstba_high
;
163 bool msix_used
, er_pcs
;
167 unsigned int er_ep_idx
;
169 /* kept for live migration compat only */
171 XHCIEvent ev_buffer
[EV_QUEUE
];
172 unsigned int ev_buffer_put
;
173 unsigned int ev_buffer_get
;
177 typedef struct XHCIState
{
182 MemoryRegion
*dma_mr
;
184 MemoryRegion mem_cap
;
185 MemoryRegion mem_oper
;
186 MemoryRegion mem_runtime
;
187 MemoryRegion mem_doorbell
;
195 uint32_t max_pstreams_mask
;
196 void (*intr_update
)(XHCIState
*s
, int n
, bool enable
);
197 bool (*intr_raise
)(XHCIState
*s
, int n
, bool level
);
198 DeviceState
*hostOpaque
;
200 /* Operational Registers */
207 uint32_t dcbaap_high
;
210 USBPort uports
[MAX_CONST(XHCI_MAXPORTS_2
, XHCI_MAXPORTS_3
)];
211 XHCIPort ports
[XHCI_MAXPORTS
];
212 XHCISlot slots
[XHCI_MAXSLOTS
];
215 /* Runtime Registers */
216 int64_t mfindex_start
;
217 QEMUTimer
*mfwrap_timer
;
218 XHCIInterrupter intr
[XHCI_MAXINTRS
];
225 extern const VMStateDescription vmstate_xhci
;
226 bool xhci_get_flag(XHCIState
*xhci
, enum xhci_flags bit
);
227 void xhci_set_flag(XHCIState
*xhci
, enum xhci_flags bit
);