Repository navigation
Expand file tree
/
Copy pathIOPCIEDeviceWrapper.cpp
More file actions
123 lines (108 loc) · 3.29 KB
/
Copy pathIOPCIEDeviceWrapper.cpp
File metadata and controls
123 lines (108 loc) · 3.29 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
//
// IOPCIEDeviceWrapper.cpp
// AirportMtwlm-Sonoma
//
// Created by qcwap on 2023/6/27.
// Copyright © 2023 钟先耀. All rights reserved.
//
#include "IOPCIEDeviceWrapper.hpp"
#include "Apple80211.h"
#include "ItlMwx.hpp"
#define super IOService
OSDefineMetaClassAndStructors(IOPCIEDeviceWrapper, IOService);
#define PCI_MSI_FLAGS 2 /* Message Control */
#define PCI_CAP_ID_MSI 0x05 /* Message Signalled Interrupts */
#define PCI_MSIX_FLAGS 2 /* Message Control */
#define PCI_CAP_ID_MSIX 0x11 /* MSI-X */
#define PCI_MSIX_FLAGS_ENABLE 0x8000 /* MSI-X enable */
#define PCI_MSI_FLAGS_ENABLE 0x0001 /* MSI feature enabled */
static IOPMPowerState powerStateArray[2] =
{
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{1, kIOPMDeviceUsable, kIOPMPowerOn, kIOPMPowerOn, 0, 0, 0, 0, 0, 0, 0, 0}
};
static void pciMsiSetEnable(IOPCIDevice *device, UInt8 msiCap, int enable)
{
UInt16 control;
control = device->configRead16(msiCap + PCI_MSI_FLAGS);
control &= ~PCI_MSI_FLAGS_ENABLE;
if (enable)
control |= PCI_MSI_FLAGS_ENABLE;
device->configWrite16(msiCap + PCI_MSI_FLAGS, control);
}
static void pciMsiXClearAndSet(IOPCIDevice *device, UInt8 msixCap, UInt16 clear, UInt16 set)
{
UInt16 ctrl;
ctrl = device->configRead16(msixCap + PCI_MSIX_FLAGS);
ctrl &= ~clear;
ctrl |= set;
device->configWrite16(msixCap + PCI_MSIX_FLAGS, ctrl);
}
extern IOWorkLoop *_fWorkloop;
IOWorkLoop *IOPCIEDeviceWrapper::getWorkLoop() const
{
return _fWorkloop;
}
IOService* IOPCIEDeviceWrapper::
probe(IOService *provider, SInt32 *score)
{
XYLog("%s\n", __PRETTY_FUNCTION__);
bool isMatch = false;
super::probe(provider, score);
UInt8 msiCap;
UInt8 msixCap;
IOPCIDevice* device = OSDynamicCast(IOPCIDevice, provider);
if (!device)
return NULL;
if (ItlMwx::mwx_match(device)) {
isMatch = true;
fHalService = new ItlMwx;
}
if (isMatch) {
XYLog("%s Found\n", __FUNCTION__);
device->findPCICapability(PCI_CAP_ID_MSIX, &msixCap);
if (msixCap)
pciMsiXClearAndSet(device, msixCap, PCI_MSIX_FLAGS_ENABLE, 0);
device->findPCICapability(PCI_CAP_ID_MSI, &msiCap);
if (msiCap)
pciMsiSetEnable(device, msiCap, 1);
if (!msiCap && !msixCap) {
XYLog("%s No MSI cap\n", __FUNCTION__);
fHalService->release();
fHalService = NULL;
return NULL;
}
this->pciNub = device;
return this;
}
return NULL;
}
bool IOPCIEDeviceWrapper::
start(IOService *provider)
{
XYLog("%s\n", __PRETTY_FUNCTION__);
_fWorkloop = IO80211WorkQueue::workQueue();
if (!super::start(provider)) {
return false;
}
IOLog("%s::super start succeed\n", getName());
UInt8 builtIn = 0;
setProperty("built-in", OSData::withBytes(&builtIn, sizeof(builtIn)));
PMinit();
registerPowerDriver(this, powerStateArray, 2);
provider->joinPMtree(this);
registerService();
return true;
}
void IOPCIEDeviceWrapper::
stop(IOService *provider)
{
XYLog("%s\n", __PRETTY_FUNCTION__);
PMstop();
super::stop(provider);
}
IOReturn IOPCIEDeviceWrapper::
setPowerState(unsigned long powerStateOrdinal, IOService *whatDevice)
{
return IOPMAckImplied;
}