This repository was archived by the owner on Sep 5, 2023. It is now read-only.
forked from RehabMan/OS-X-Generic-USB3
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathV2Pure.cpp
More file actions
164 lines (156 loc) · 5.33 KB
/
V2Pure.cpp
File metadata and controls
164 lines (156 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// V2Pure.cpp
// GenericUSBXHCI
//
// Created by Zenith432 on December 26th, 2012.
// Copyright (c) 2012-2013 Zenith432. All rights reserved.
//
#include "GenericUSBXHCI.h"
#include "Async.h"
#include "XHCITRB.h"
#include "XHCITypes.h"
#define CLASS GenericUSBXHCI
#define super IOUSBControllerV3
#pragma mark -
#pragma mark IOUSBControllerV2 Pure
#pragma mark -
IOReturn CLASS::UIMCreateControlEndpoint(UInt8 functionNumber, UInt8 endpointNumber, UInt16 maxPacketSize,
UInt8 speed, USBDeviceAddress highSpeedHub, int highSpeedPort)
{
TRBStruct localTrb = { 0U };
IOReturn rc;
ContextStruct* pContext;
ringStruct* pRing;
int32_t retFromCMD;
uint16_t packetSize;
uint8_t slot;
if (functionNumber == _hub3Address || functionNumber == _hub2Address)
return kIOReturnSuccess;
packetSize = maxPacketSize != 9U ? maxPacketSize : 512U;
if (!functionNumber) {
if (_numEndpoints >= _maxNumEndpoints)
return kIOUSBEndpointCountExceeded;
retFromCMD = WaitForCMD(&localTrb, XHCI_TRB_TYPE_ENABLE_SLOT, 0);
if (retFromCMD == -1 || retFromCMD <= -1000)
return retFromCMD == (-1000 - XHCI_TRB_ERROR_NO_SLOTS) ? kIOUSBDeviceCountExceeded : kIOReturnInternalError;
slot = static_cast<uint8_t>(retFromCMD);
#if 0
/*
* Note: Added Mavericks
*/
if (_vendorID == kVendorIntel && _IntelSlotWorkaround && slot == _numSlots) {
_IntelSlotWorkaround = false;
retFromCMD = CleanupControlEndpoint(slot, true);
_IntelSWSlot = slot;
if (retFromCMD == -1 || retFromCMD <= -1000)
return kIOReturnInternalError;
ClearTRB(&localTrb, true);
retFromCMD = WaitForCMD(&localTrb, XHCI_TRB_TYPE_ENABLE_SLOT, 0);
if (retFromCMD == -1 || retFromCMD <= -1000)
return retFromCMD == (-1000 - XHCI_TRB_ERROR_NO_SLOTS) ? kIOUSBDeviceCountExceeded : kIOReturnInternalError;
slot = static_cast<uint8_t>(retFromCMD);
if (slot == _numSlots)
ExecuteGetPortBandwidthWorkaround();
}
_IntelSlotWorkaround = false;
#endif
if (!slot || slot > _numSlots) {
/*
* Sanity check. Bail out, 'cause UIMDeleteEndpoint
* won't handle invalid slot # well.
*/
CleanupControlEndpoint(slot, true);
IOLog("%s: xHC assigned invalid slot number %u\n", __FUNCTION__, slot);
return kIOUSBDeviceCountExceeded;
}
pRing = CreateRing(slot, 1, 0U);
if (!pRing || pRing->md) {
CleanupControlEndpoint(slot, true);
return kIOReturnInternalError;
}
_addressMapper.Slot[0] = slot;
_addressMapper.Active[0] = true;
rc = AllocRing(pRing, 1);
if (rc != kIOReturnSuccess) {
CleanupControlEndpoint(slot, false);
return kIOReturnNoMemory;
}
rc = MakeBuffer(kIOMemoryPhysicallyContiguous | kIODirectionInOut,
GetDeviceContextSize(),
-PAGE_SIZE,
&SlotPtr(slot)->md,
reinterpret_cast<void**>(&SlotPtr(slot)->ctx),
&SlotPtr(slot)->physAddr);
if (rc != kIOReturnSuccess) {
CleanupControlEndpoint(slot, false);
return kIOReturnNoMemory;
}
if (!pRing->asyncEndpoint) {
pRing->epType = CTRL_EP;
pRing->asyncEndpoint = XHCIAsyncEndpoint::withParameters(this, pRing, packetSize, 0U, 0U);
if (!pRing->asyncEndpoint) {
CleanupControlEndpoint(slot, false);
return kIOReturnNoMemory;
}
static_cast<void>(__sync_fetch_and_add(&_numEndpoints, 1));
}
SetDCBAAAddr64(&_dcbaa.ptr[slot], ConstSlotPtr(slot)->physAddr);
return AddressDevice(slot,
packetSize,
false,
speed,
GetSlotID(highSpeedHub),
highSpeedPort);
}
if (endpointNumber)
return kIOReturnInternalError;
slot = GetSlotID(functionNumber);
if (!slot)
return kIOReturnInternalError;
pContext = GetSlotContext(slot, 1);
if (!pContext)
return kIOReturnInternalError;
if (XHCI_EPCTX_1_MAXP_SIZE_GET(pContext->_e.dwEpCtx1) == packetSize)
return kIOReturnSuccess;
GetInputContext();
pContext = GetInputContextPtr();
pContext->_ic.dwInCtx1 = XHCI_INCTX_1_ADD_MASK(1U);
pContext = GetInputContextPtr(2);
pContext->_e.dwEpCtx1 = XHCI_EPCTX_1_MAXP_SIZE_SET(static_cast<uint32_t>(packetSize));
SetTRBAddr64(&localTrb, _inputContext.physAddr);
localTrb.d = XHCI_TRB_3_SLOT_SET(static_cast<uint32_t>(slot));
retFromCMD = WaitForCMD(&localTrb, XHCI_TRB_TYPE_EVALUATE_CTX, 0);
ReleaseInputContext();
if (retFromCMD == -1)
return kIOReturnInternalError;
if (retFromCMD > -1000)
return kIOReturnSuccess;
if (retFromCMD == -1000 - XHCI_TRB_ERROR_PARAMETER) {
#if 0
PrintContext(GetInputContextPtr());
PrintContext(GetInputContextPtr(2));
#endif
}
return kIOReturnInternalError;
}
IOReturn CLASS::UIMCreateBulkEndpoint(UInt8 functionNumber, UInt8 endpointNumber, UInt8 direction, UInt8 speed,
UInt16 maxPacketSize, USBDeviceAddress highSpeedHub, int highSpeedPort)
{
return CreateBulkEndpoint(functionNumber, endpointNumber, direction, maxPacketSize, 0U, 0U);
}
IOReturn CLASS::UIMCreateInterruptEndpoint(short functionAddress, short endpointNumber,UInt8 direction,
short speed, UInt16 maxPacketSize, short pollingRate,
USBDeviceAddress highSpeedHub, int highSpeedPort)
{
uint32_t maxBurst = 0U;
/*
* Preprocessing code added OS 10.8.3
*/
if (maxPacketSize > kUSB_EPDesc_MaxMPS) {
maxBurst = ((maxPacketSize + kUSB_EPDesc_MaxMPS - 1U) / kUSB_EPDesc_MaxMPS);
maxPacketSize = (maxPacketSize + maxBurst - 1U) / maxBurst;
--maxBurst;
}
return CreateInterruptEndpoint(functionAddress, endpointNumber, direction, speed,
maxPacketSize, pollingRate, maxBurst);
}