This repository has been 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
/
Accessors.cpp
198 lines (178 loc) · 4.49 KB
/
Accessors.cpp
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//
// Accessors.cpp
// GenericUSBXHCI
//
// Created by Zenith432 on January 12th 2013.
// Copyright (c) 2013-2014 Zenith432. All rights reserved.
//
#include "GenericUSBXHCI.h"
#include "XHCITypes.h"
#define CLASS GenericUSBXHCI
#define super IOUSBControllerV3
#pragma mark -
#pragma mark Accessors
#pragma mark -
#pragma mark -
#pragma mark Register Space
#pragma mark -
__attribute__((noinline, visibility("hidden")))
uint8_t CLASS::Read8Reg(uint8_t volatile const* p)
{
uint8_t v;
if (m_invalid_regspace)
return UINT8_MAX;
v = *p;
if (v != UINT8_MAX)
return v;
if (ON_THUNDERBOLT)
m_invalid_regspace = true;
return UINT8_MAX;
}
__attribute__((noinline, visibility("hidden")))
uint16_t CLASS::Read16Reg(uint16_t volatile const* p)
{
uint16_t v;
if (m_invalid_regspace)
return UINT16_MAX;
v = *p;
if (v != UINT16_MAX)
return v;
if (ON_THUNDERBOLT)
m_invalid_regspace = true;
return UINT16_MAX;
}
__attribute__((noinline, visibility("hidden")))
uint32_t CLASS::Read32Reg(uint32_t volatile const* p)
{
uint32_t v;
if (m_invalid_regspace)
return UINT32_MAX;
v = *p;
if (v != UINT32_MAX)
return v;
if (ON_THUNDERBOLT)
m_invalid_regspace = true;
return UINT32_MAX;
}
__attribute__((noinline, visibility("hidden")))
uint64_t CLASS::Read64Reg(uint64_t volatile const* p)
{
uint64_t v;
uint32_t lowv, highv;
if (m_invalid_regspace)
return UINT64_MAX;
if (XHCI_HCC_AC64(_HCCLow)) {
#ifdef __LP64__
if (_vendorID != kVendorFrescoLogic) {
v = *p;
if (v == UINT64_MAX && ON_THUNDERBOLT)
goto scrap;
return v;
}
#endif
lowv = *reinterpret_cast<uint32_t volatile const*>(p);
if (lowv == UINT32_MAX && ON_THUNDERBOLT)
goto scrap;
highv = reinterpret_cast<uint32_t volatile const*>(p)[1];
if (highv == UINT32_MAX && ON_THUNDERBOLT)
goto scrap;
return (static_cast<uint64_t>(highv) << 32) | lowv;
}
lowv = *reinterpret_cast<uint32_t volatile const*>(p);
if (lowv == UINT32_MAX && ON_THUNDERBOLT)
goto scrap;
return lowv;
scrap:
m_invalid_regspace = true;
return UINT64_MAX;
}
__attribute__((noinline, visibility("hidden")))
void CLASS::Write32Reg(uint32_t volatile* p, uint32_t v)
{
if (m_invalid_regspace)
return;
*p = v;
}
__attribute__((noinline, visibility("hidden")))
void CLASS::Write64Reg(uint64_t volatile* p, uint64_t v, bool)
{
if (m_invalid_regspace)
return;
if (XHCI_HCC_AC64(_HCCLow)) {
#ifdef __LP64__
if (_vendorID != kVendorFrescoLogic) {
*p = v;
return;
}
#endif
*reinterpret_cast<uint32_t volatile*>(p) = static_cast<uint32_t>(v);
reinterpret_cast<uint32_t volatile*>(p)[1] = static_cast<uint32_t>(v >> 32);
return;
}
*reinterpret_cast<uint32_t volatile*>(p) = static_cast<uint32_t>(v);
reinterpret_cast<uint32_t volatile*>(p)[1] = 0U;
}
#pragma mark -
#pragma mark Contexts
#pragma mark -
__attribute__((noinline, visibility("hidden")))
ContextStruct* CLASS::GetSlotContext(int32_t slot, int32_t index)
{
ContextStruct* pContext = SlotPtr(slot)->ctx;
if (!pContext || index <= 0)
return pContext;
return XHCI_HCC_CSZ(_HCCLow) ? (pContext + 2 * index) : (pContext + index);
}
__attribute__((noinline, visibility("hidden")))
ContextStruct* CLASS::GetInputContextPtr(int32_t index)
{
return XHCI_HCC_CSZ(_HCCLow) ? (_inputContext.ptr + 2 * index) : (_inputContext.ptr + index);
}
__attribute__((visibility("hidden")))
uint8_t CLASS::GetSlCtxSpeed(ContextStruct const* pContext)
{
switch (XHCI_SCTX_0_SPEED_GET(pContext->_s.dwSctx0)) {
case XDEV_FS:
return kUSBDeviceSpeedFull;
case XDEV_LS:
return kUSBDeviceSpeedLow;
case XDEV_HS:
return kUSBDeviceSpeedHigh;
default: // (XDEV_SS)
return kUSBDeviceSpeedSuper;
}
}
__attribute__((visibility("hidden")))
void CLASS::SetSlCtxSpeed(ContextStruct* pContext, uint32_t speed)
{
pContext->_s.dwSctx0 |= XHCI_SCTX_0_SPEED_SET(speed);
}
#pragma mark -
#pragma mark TRB
#pragma mark -
__attribute__((noinline, visibility("hidden")))
void CLASS::SetTRBAddr64(TRBStruct* trb, uint64_t addr)
{
trb->a = static_cast<uint32_t>(addr);
trb->b = static_cast<uint32_t>(addr >> 32);
}
__attribute__((visibility("hidden")))
void CLASS::ClearTRB(TRBStruct* trb, bool wipeCycleBit)
{
trb->a = 0U;
trb->b = 0U;
trb->c = 0U;
if (wipeCycleBit)
trb->d = 0U;
else
trb->d &= XHCI_TRB_3_CYCLE_BIT;
}
#pragma mark -
#pragma mark DCBAA
#pragma mark -
__attribute__((noinline, visibility("hidden")))
void CLASS::SetDCBAAAddr64(uint64_t* p, uint64_t addr)
{
*reinterpret_cast<uint32_t*>(p) = static_cast<uint32_t>(addr) & ~0x3FU;
reinterpret_cast<uint32_t*>(p)[1] = static_cast<uint32_t>(addr >> 32);
}