1 | #ifndef _VoodooSDHC_H_␊ |
2 | #define _VoodooSDHC_H_␊ |
3 | #include "License.h"␊ |
4 | #define SLOT1 0␊ |
5 | #define SLOT2 1␊ |
6 | #define SLOT3 2␊ |
7 | #define SLOT4 3␊ |
8 | #define SLOT5 4␊ |
9 | #define SLOT6 5␊ |
10 | ␊ |
11 | /* General IOKit includes */␊ |
12 | #include <IOKit/IOLib.h>␊ |
13 | #include <IOKit/IOMessage.h>␊ |
14 | #include <IOKit/IOService.h>␊ |
15 | #include <IOKit/IOFilterInterruptEventSource.h>␊ |
16 | #include <IOKit/IOTimerEventSource.h>␊ |
17 | #include <IOKit/storage/IOBlockStorageDriver.h>␊ |
18 | #include <IOKit/storage/IOBlockStorageDevice.h>␊ |
19 | #include <IOKit/IOBufferMemoryDescriptor.h>␊ |
20 | #include <libkern/locks.h>␊ |
21 | #include "SD_DataTypes.h"␊ |
22 | ␊ |
23 | class VoodooSDHC : public IOBlockStorageDevice␊ |
24 | {␊ |
25 | ␉␊ |
26 | ␉OSDeclareDefaultStructors ( VoodooSDHC )␊ |
27 | ␉␊ |
28 | protected:␊ |
29 | ␊ |
30 | public:␊ |
31 | ␉␊ |
32 | ␉// Overrides from IOService␊ |
33 | ␉␊ |
34 | ␉virtual bool␉init ␉( OSDictionary * propertyTable );␊ |
35 | ␉virtual void␉free␉();␊ |
36 | ␉virtual bool ␉start ␉( IOService * provider );␊ |
37 | ␉virtual void ␉stop ␉( IOService * provider );␊ |
38 | ␊ |
39 | private:␊ |
40 | ␉// This lock protects block I/O access to the card reader␊ |
41 | ␉class Lock {␊ |
42 | ␉␉IOLock␉*mutex_;␊ |
43 | ␉␉bool␉locked_;␊ |
44 | ␉␉int␉␉waiting_;␊ |
45 | ␉public:␊ |
46 | ␉␉void init() {␊ |
47 | ␉␉␉mutex_ = IOLockAlloc();␊ |
48 | ␉␉␉locked_ = false;␊ |
49 | ␉␉␉waiting_ = 0;␊ |
50 | ␉␉}␊ |
51 | ␉␉void free() {␊ |
52 | ␉␉␉IOLockFree(mutex_);␊ |
53 | ␉␉}␊ |
54 | ␉␉void lock() {␊ |
55 | ␉␉␉IOLockLock(mutex_);␊ |
56 | ␉␉␉if (locked_) {␊ |
57 | ␉␉␉␉waiting_++;␊ |
58 | ␉␉␉␉do {␊ |
59 | ␉␉␉␉␉IOLockSleep(mutex_, mutex_, THREAD_UNINT);␊ |
60 | ␉␉␉␉} while (locked_);␊ |
61 | ␉␉␉␉waiting_--;␊ |
62 | ␉␉␉}␊ |
63 | ␉␉␉locked_ = true;␊ |
64 | ␉␉␉IOLockUnlock(mutex_);␊ |
65 | ␉␉}␊ |
66 | ␉␉void unlock() {␊ |
67 | ␉␉␉IOLockLock(mutex_);␊ |
68 | ␉␉␉locked_ = false;␊ |
69 | ␉␉␉if (waiting_)␊ |
70 | ␉␉␉␉IOLockWakeup(mutex_, mutex_, true);␊ |
71 | ␉␉␉IOLockUnlock(mutex_);␊ |
72 | ␉␉}␊ |
73 | ␉} lock;␊ |
74 | ␉␊ |
75 | #ifdef USE_SDMA␊ |
76 | ␉IOLock␉␉␉*sdmaCond; // this lock handles I/O interrupt␊ |
77 | ␉IOLock␉␉␉*mediaStateLock; // this lock serializes reportMediaState␊ |
78 | ␉IOBufferMemoryDescriptor *sdmaBuffDesc;␊ |
79 | ␉UInt32␉␉␉physSdmaBuff;␊ |
80 | ␉void␉␉␉*virtSdmaBuff;␊ |
81 | ␉IOWorkLoop␉␉*workLoop;␊ |
82 | ␉IOFilterInterruptEventSource *interruptSrc;␊ |
83 | ␉IOTimerEventSource␉*timerSrc;␊ |
84 | ␉virtual IOWorkLoop *getWorkLoop() const { return workLoop; }␊ |
85 | #endif␊ |
86 | ␉␊ |
87 | ␉IOMemoryMap␉␉*PCIRegMap;␊ |
88 | ␉struct␉␉␉SDHCIRegMap_t *PCIRegP[6];␊ |
89 | ␉struct␉␉␉SDCIDReg_t SDCIDReg[6];␊ |
90 | ␉UInt32␉␉␉RCA;␊ |
91 | ␉UInt32␉␉␉maxBlock;␊ |
92 | ␉enum {␊ |
93 | ␉␉kCardNotPresent,␊ |
94 | ␉␉kCardIsPresent,␊ |
95 | ␉␉kCardRemount␊ |
96 | ␉} cardPresence;␊ |
97 | ␉bool␉␉␉isHighCapacity;␊ |
98 | ␉␊ |
99 | ␉bool␉␉␉setup(IOService *provider);␊ |
100 | ␉void␉␉␉dumpRegs(UInt8 slot);␊ |
101 | ␉bool␉␉␉isCardPresent(UInt8 slot);␊ |
102 | ␉bool␉␉␉isCardWP(UInt8 slot);␊ |
103 | ␉bool␉␉␉cardInit( UInt8 slot );␊ |
104 | ␉void␉␉␉LEDControl(UInt8 slot, bool state);␊ |
105 | ␉void␉␉␉Reset( UInt8 slot, UInt8 type );␊ |
106 | ␉bool␉␉␉SDCommand( UInt8 slot, UInt8 command, UInt16 response, UInt32 arg);␊ |
107 | ␉bool␉␉␉calcClock(UInt8 slot, UInt32 clockspeed);␊ |
108 | ␉bool␉␉␉powerSD(UInt8 slot);␊ |
109 | ␉void␉␉␉parseCID(UInt8 slot);␊ |
110 | ␉void␉␉␉parseCSD(UInt8 slot);␊ |
111 | ␉␊ |
112 | //␉IOReturn␉␉requestIdle(void); /* 10.6.0 */␊ |
113 | //␉IOReturn␉␉doDiscard(UInt64 block, UInt64 nblks); /* 10.6.0 */␊ |
114 | ␉IOReturn␉␉reportRemovability(bool *isRemovable);␊ |
115 | ␉IOReturn␉␉reportWriteProtection(bool *isWriteProtected);␊ |
116 | ␉IOReturn␉␉setWriteCacheState(bool enabled);␊ |
117 | ␉IOReturn␉␉reportPollRequirements(bool *pollRequired, bool *pollIsExpensive);␊ |
118 | ␉IOReturn␉␉reportMediaState(bool *mediaPresent, bool *changedState);␊ |
119 | ␉IOReturn␉␉reportMaxValidBlock(UInt64 *maxBlock);␊ |
120 | ␉IOReturn␉␉reportLockability(bool *isLockable);␊ |
121 | ␉IOReturn␉␉reportEjectability(bool *isEjectable);␊ |
122 | ␉IOReturn␉␉reportBlockSize(UInt64 *blockSize);␊ |
123 | ␉IOReturn␉␉getWriteCacheState(bool *enabled);␊ |
124 | ␉IOReturn␉␉setPowerState( unsigned long whichState, IOService * whatDevice );␊ |
125 | ␉char *␉␉␉getVendorString(void);␊ |
126 | ␉char *␉␉␉getRevisionString(void);␊ |
127 | ␉char *␉␉␉getProductString(void);␊ |
128 | ␉char *␉␉␉getAdditionalDeviceInfoString(void);␊ |
129 | ␉IOReturn␉␉doSynchronizeCache(void);␊ |
130 | ␉IOReturn␉␉doLockUnlockMedia(bool doLock);␊ |
131 | ␉UInt32␉␉␉doGetFormatCapacities(UInt64 *capacities, UInt32 capacitiesMaxCount) const;␊ |
132 | ␉IOReturn␉␉doFormatMedia(UInt64 byteCapacity);␊ |
133 | ␉IOReturn␉␉doEjectMedia(void);␊ |
134 | #ifdef __LP64__␊ |
135 | virtual IOReturn␉doAsyncReadWrite(IOMemoryDescriptor *buffer,␊ |
136 | ␉␉␉␉␉␉␉␉␉␉ UInt64 block, UInt64 nblks,␊ |
137 | ␉␉␉␉␉␉␉␉␉␉ IOStorageAttributes *attributes,␊ |
138 | ␉␉␉␉␉␉␉␉␉␉ IOStorageCompletion *completion);␊ |
139 | #endif␊ |
140 | #ifndef __LP64__␊ |
141 | ␉IOReturn␉␉doAsyncReadWrite(IOMemoryDescriptor *buffer, ␊ |
142 | ␉␉␉␉␉␉␉␉␉ UInt32 block, UInt32 nblks,␊ |
143 | ␉␉␉␉␉␉␉␉␉ IOStorageCompletion completion); //completion was start␊ |
144 | ␉IOReturn␉␉reportMaxWriteTransfer(UInt64 blockSize, UInt64 *max);␊ |
145 | ␉IOReturn␉␉reportMaxReadTransfer (UInt64 blockSize, UInt64 *max);␊ |
146 | #endif␊ |
147 | ␉IOReturn␉␉sdma_access(IOMemoryDescriptor *buffer, UInt32 block, UInt32 nblks, bool read);␊ |
148 | ␉IOReturn␉␉readBlockMulti_pio(IOMemoryDescriptor *buffer, UInt32 block, UInt32 nblks,␊ |
149 | ␉␉␉␉␉␉␉UInt32 offset);␊ |
150 | ␉IOReturn␉␉readBlockSingle_pio(UInt8 *buff, UInt32 block);␊ |
151 | ␉IOReturn␉␉writeBlockMulti_pio(IOMemoryDescriptor *buffer, UInt32 block, UInt32 nblks,␊ |
152 | ␉␉␉␉␉␉␉UInt32 offset);␊ |
153 | ␉IOReturn␉␉writeBlockSingle_pio(IOMemoryDescriptor *buffer, UInt32 block,␊ |
154 | ␉␉␉␉␉␉␉UInt32 offset);␊ |
155 | ␉bool␉␉␉waitIntStatus(UInt32 maskBits);␊ |
156 | ␉void␉␉␉handleInterrupt();␊ |
157 | ␉void␉␉␉handleTimer();␊ |
158 | ␉␊ |
159 | ␉static void interruptHandler(OSObject *owner, IOInterruptEventSource *source, int count);␊ |
160 | ␉static bool interruptFilter(OSObject *owner, IOFilterInterruptEventSource *source);␊ |
161 | ␉static void timerHandler(OSObject *owner, IOTimerEventSource *sender);␊ |
162 | };␊ |
163 | ␊ |
164 | #endif /* _VoodooSDHC_H_ */␊ |
165 | |