VoodooSDHCI

View changes.diff

1Index: trunk/VoodooSDHC.cpp
2===================================================================
3--- trunk/VoodooSDHC.cpp(revision 2)
4+++ trunk/VoodooSDHC.cpp(working copy)
5@@ -14,7 +14,7 @@
6 /*
7 * Builds the driver with High Speed Card support.
8 */
9-//#define HIGHSPEED_CARD_MODE1
10+#define HIGHSPEED_CARD_MODE1
11
12 /*
13 * Builds the driver with 4-bit Bus support.
14@@ -95,7 +95,7 @@
15 if ((workLoop = IOWorkLoop::workLoop()) == NULL)
16 return false;
17 #endif
18-
19+
20 return true;
21 }
22
23@@ -345,7 +345,7 @@
24 SDCommand(slot, SD_APP_CMD, SDCR55, 0);
25 SDCommand(slot, SD_APP_OP_COND, SDACR41, 0x00FF8000);
26 IODelay(1000);
27-} while (!(this->PCIRegP[slot]->Response[0] & BIT31));
28+} while (!this->PCIRegP[slot]->Response[0] & BIT31);
29 } else {
30 // check and init SDHC (wait for 2 secs; spec requires 1 sec)
31 IOLog("VoodooSDHCI: initializing spec 2.0 SD card\n");
32@@ -543,7 +543,7 @@
33 bool VoodooSDHC::SDCommand(UInt8 slot, UInt8 command, UInt16 response,
34 UInt32 arg) {
35 if (command != 0) {
36-while(this->PCIRegP[slot]->PresentState & ComInhibitCMD);
37+while(this->PCIRegP[slot]->PresentState & ComInhibitCMD) ;
38 }
39
40 //if(command 1= COMMANDS?)
41@@ -629,6 +629,7 @@
42 this->PCIRegP[slot]->ClockControl = 0;
43 this->PCIRegP[slot]->ClockControl = 0;
44 this->PCIRegP[slot]->ClockControl |= BIT0;
45+
46 while(!this->PCIRegP[slot]->ClockControl & BIT1);
47 baseClock = ((this->PCIRegP[slot]->Capabilities[0] & 0x3F00) >> 8);
48 baseClock *= 1000000;
49@@ -941,20 +942,17 @@
50
51 bool VoodooSDHC::waitIntStatus(UInt32 maskBits)
52 {
53-// roughly 5 seconds before timeout
54-for (int cnt = 0; cnt < 500000; cnt++) {
55-while (1) {
56-UInt32 nis = PCIRegP[0]->NormalIntStatus;
57-if (nis & ErrorInterrupt) {
58-return false;
59-}
60-if (nis & maskBits) {
61-PCIRegP[0]->NormalIntStatus = nis | maskBits;
62-return true;
63-}
64-}
65-::IODelay(10);
66-}
67+for (int cnt = 0; cnt < 10000; cnt++) {
68+ UInt32 nis = PCIRegP[0]->NormalIntStatus;
69+ if (nis & ErrorInterrupt) {
70+ return false;
71+ }
72+ if (nis & maskBits) {
73+ PCIRegP[0]->NormalIntStatus = nis | maskBits;
74+ return true;
75+ }
76+ }
77+
78 return false;
79 }
80
81@@ -1052,13 +1050,12 @@
82 * bool read: true if read, false if write
83 */
84 IOReturn VoodooSDHC::sdma_access(IOMemoryDescriptor *buffer,
85-UInt32 block, UInt32 nblks, bool read) {
86+UInt32 block, UInt32 nblks, UInt32 offset, bool read) {
87 IOReturn ret = kIOReturnError;
88-UInt32 nis, offset = 0;
89 AbsoluteTime deadline;
90-
91+
92 #ifdef __DEBUG__
93-IOLog("VoodooSDHCI readBlockMulti_sdma: block = %d, nblks = %d\n", block, nblks);
94+ IOLog("VoodooSDHCI sdma_access: block = %d, nblks = %d\n", block, nblks);
95 #endif /* __DEBUG__ */
96 #ifndef NO_RESET_WAR
97 // Reset card before every operation. The Linux driver
98@@ -1093,14 +1090,26 @@
99 this->PCIRegP[0]->BlockSize = 512 | SDMA_BUFFER_SIZE_IN_REG;
100 this->PCIRegP[0]->BlockCount = nblks;
101 ::OSSynchronizeIO();
102-
103+
104 // Issue read command to host controller
105-SDCommand(0,
106+if (!SDCommand(0,
107 read ? SD_READ_MULTIPLE_BLOCK : SD_WRITE_MULTIPLE_BLOCK,
108 SDCR18,
109-isHighCapacity ? block : block * 512);
110+isHighCapacity ? block : block * 512))
111+ {
112+ IOLog("VoodooSDHCI: I/O can't send command %d (SDMA): Status: 0x%x, Error: 0x%x\n",
113+ read ? SD_READ_MULTIPLE_BLOCK : SD_WRITE_MULTIPLE_BLOCK, PCIRegP[0]->NormalIntStatus, PCIRegP[0]->ErrorIntStatus);
114+ Reset(0, FULL_RESET);
115+if (! cardInit(0)) {
116+IOLog("VoodooSDHCI: reset failed, disabling access\n");
117+cardPresence = kCardRemount;
118+}
119+ret = kIOReturnTimeout;
120+goto out;
121+ }
122+
123 ::OSSynchronizeIO();
124-
125+
126 // wait for CmdComplete
127 if (! waitIntStatus(CmdComplete)) {
128 IOLog("VoodooSDHCI: I/O error after command %d (SDMA): Status: 0x%x, Error: 0x%x\n",
129@@ -1113,6 +1122,7 @@
130 ret = kIOReturnTimeout;
131 goto out;
132 }
133+
134 // check response
135 if (PCIRegP[0]->Response[0] & (read ? 0xcff80000 : 0xeff80000)) {
136 IOLog("VoodooSDHCI: Unexpected response from command %d (SDMA): Response: 0x%x\n",
137@@ -1121,9 +1131,11 @@
138 }
139
140 clock_interval_to_deadline(5000, kMillisecondScale, (uint64_t*)&deadline);
141-IOLockLock(sdmaCond);
142-while ((PCIRegP[0]->NormalIntStatus & ErrorInterrupt) == 0) {
143-if (IOLockSleepDeadline(sdmaCond, sdmaCond, deadline, THREAD_UNINT) == THREAD_TIMED_OUT) {
144+
145+ IOLockLock(sdmaCond);
146+while ((PCIRegP[0]->NormalIntStatus & ErrorInterrupt) == 0)
147+ {
148+ if (IOLockSleepDeadline(sdmaCond, sdmaCond, deadline, THREAD_UNINT) == THREAD_TIMED_OUT) {
149 IOLockUnlock(sdmaCond);
150 // timeout
151 IOLog("VoodooSDHCI: I/O timeout during SDMA transfer: Status: 0x%x, Error: 0x%x, Block: %d, Offset: %d, Blocks: %d\n",
152@@ -1131,7 +1143,7 @@
153 ret = kIOReturnTimeout;
154 goto out;
155 }
156-nis = PCIRegP[0]->NormalIntStatus;
157+UInt32 nis = PCIRegP[0]->NormalIntStatus;
158 if (nis & XferComplete) {
159 IOLockUnlock(sdmaCond);
160 if (read) {
161@@ -1156,6 +1168,7 @@
162 PCIRegP[0]->SDMASysAddr = physSdmaBuff;
163 }
164 }
165+
166 IOLockUnlock(sdmaCond);
167 // error
168 IOLog("VoodooSDHCI: I/O error during SDMA transfer: Status: 0x%x, Error: 0x%x, Block: %d, Offset: %d, Blocks: %d\n",
169@@ -1512,16 +1525,22 @@
170 IOLog("READING FROM CARD!\n");
171 #endif
172 blk = block;
173-n = nblks;
174+ n = nblks;
175 while (n) {
176 if (USE_SDMA) {
177 int i;
178+ int b = MIN(8192 /* should fit in sdma buff */, n);
179 for (i = 0; i < SDMA_RETRY_COUNT; i++)
180-if ((ret = sdma_access(buffer, block, nblks, true)) != kIOReturnTimeout)
181+ {
182+if ((ret = sdma_access(buffer, blk, b, blk - block, true)) != kIOReturnTimeout)
183 break;
184-if (i != 0)
185-IOLog("VoodooSDHCI: retry succeeded\n");
186-n = 0;
187+ }
188+if (i != 0 && i < SDMA_RETRY_COUNT)
189+IOLog("VoodooSDHCI: read retry succeeded, tries = %d\n", i);
190+ else if (i >= SDMA_RETRY_COUNT)
191+ IOLog("VoodooSDHCI: read retry failed\n");
192+ n -= b;
193+ blk += b;
194 } else if ((nblks > 1) && USE_MULTIBLOCK) {
195 int b = MIN(2048 /* should fit in sdma buff */, n);
196
197@@ -1560,15 +1579,21 @@
198 while (n) {
199 if (USE_SDMA) {
200 int i;
201+ int b = MIN(8192 /* should fit in sdma buff */, n);
202 for (i = 0; i < SDMA_RETRY_COUNT; i++)
203-if ((ret = sdma_access(buffer, block, nblks, false)) != kIOReturnTimeout)
204+ {
205+if ((ret = sdma_access(buffer, blk, b, blk - block, false)) != kIOReturnTimeout)
206 break;
207-if (i != 0)
208-IOLog("VoodooSDHCI: retry succeeded\n");
209-n = 0;
210+ }
211+if (i != 0 && i < SDMA_RETRY_COUNT)
212+IOLog("VoodooSDHCI: write retry succeeded, tries = %d\n", i);
213+ else if (i >= SDMA_RETRY_COUNT)
214+ IOLog("VoodooSDHCI: write retry failed\n");
215+ n -= b;
216+ blk += b;
217 }
218 else if ((nblks > 1) && USE_MULTIBLOCK) {
219-int b = MIN(2048, n);
220+int b = MIN(2048 /* should fit in sdma buff */, n);
221 ret = writeBlockMulti_pio(buffer, blk, b,
222 blk - block);
223 n -= b;
224@@ -1640,11 +1665,14 @@
225 while (n) {
226 if (USE_SDMA) {
227 int i;
228+ int b = MIN(8192 /* should fit in sdma buff */, n);
229 for (i = 0; i < SDMA_RETRY_COUNT; i++)
230-if ((ret = sdma_access(buffer, block, nblks, true)) != kIOReturnTimeout)
231+if ((ret = sdma_access(buffer, blk, b, blk - block, true)) != kIOReturnTimeout)
232 break;
233-if (i != 0)
234-IOLog("VoodooSDHCI: retry succeeded\n");
235+if (i != 0 && i < SDMA_RETRY_COUNT)
236+IOLog("VoodooSDHCI: read retry succeeded, tries = %d\n", i);
237+ else if (i >= SDMA_RETRY_COUNT)
238+ IOLog("VoodooSDHCI: read retry failed\n");
239 n = 0;
240 } else if ((nblks > 1) && USE_MULTIBLOCK) {
241 int b = MIN(2048 /* should fit in sdma buff */, n);
242@@ -1684,11 +1712,14 @@
243 while (n) {
244 if (USE_SDMA) {
245 int i;
246+ int b = MIN(8192 /* should fit in sdma buff */, n);
247 for (i = 0; i < SDMA_RETRY_COUNT; i++)
248-if ((ret = sdma_access(buffer, block, nblks, false)) != kIOReturnTimeout)
249+if ((ret = sdma_access(buffer, blk, b, blk - block, false)) != kIOReturnTimeout)
250 break;
251-if (i != 0)
252-IOLog("VoodooSDHCI: retry succeeded\n");
253+if (i != 0 && i < SDMA_RETRY_COUNT)
254+IOLog("VoodooSDHCI: write retry succeeded, tries = %d\n", i);
255+ else if (i >= SDMA_RETRY_COUNT)
256+ IOLog("VoodooSDHCI: write retry failed\n");
257 n = 0;
258 }
259 else if ((nblks > 1) && USE_MULTIBLOCK) {
260@@ -1741,7 +1772,7 @@
261 void VoodooSDHC::handleInterrupt()
262 {
263 IOLockLock(sdmaCond);
264-IOLockWakeup(sdmaCond, sdmaCond, true);
265+IOLockWakeup(sdmaCond, sdmaCond, false);
266 IOLockUnlock(sdmaCond);
267 }
268
269Index: trunk/VoodooSDHC.h
270===================================================================
271--- trunk/VoodooSDHC.h(revision 2)
272+++ trunk/VoodooSDHC.h(working copy)
273@@ -144,7 +144,7 @@
274 IOReturnreportMaxWriteTransfer(UInt64 blockSize, UInt64 *max);
275 IOReturnreportMaxReadTransfer (UInt64 blockSize, UInt64 *max);
276 #endif
277-IOReturnsdma_access(IOMemoryDescriptor *buffer, UInt32 block, UInt32 nblks, bool read);
278+IOReturnsdma_access(IOMemoryDescriptor *buffer, UInt32 block, UInt32 nblks, UInt32 offset, bool read);
279 IOReturnreadBlockMulti_pio(IOMemoryDescriptor *buffer, UInt32 block, UInt32 nblks,
280 UInt32 offset);
281 IOReturnreadBlockSingle_pio(UInt8 *buff, UInt32 block);
282Index: trunk/VoodooSDHC.xcodeproj/project.pbxproj
283===================================================================
284--- trunk/VoodooSDHC.xcodeproj/project.pbxproj(revision 2)
285+++ trunk/VoodooSDHC.xcodeproj/project.pbxproj(working copy)
286@@ -9,7 +9,6 @@
287 /* Begin PBXBuildFile section */
288 052A08C50BF57D0A00D3692D /* SD_DataTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 052A08C40BF57D0A00D3692D /* SD_DataTypes.h */; };
289 05D69FA60BF0CE7D00AA4006 /* SDHCI_Register_Map.h in Headers */ = {isa = PBXBuildFile; fileRef = 05D69FA50BF0CE7D00AA4006 /* SDHCI_Register_Map.h */; };
290-05D69FBB0BF0D16100AA4006 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 32D94FCF0562CBF700B6AF17 /* Info.plist */; };
291 05D6A0630BF128B500AA4006 /* SD_Commands.h in Headers */ = {isa = PBXBuildFile; fileRef = 05D6A0620BF128B500AA4006 /* SD_Commands.h */; };
292 05D6A0670BF1293100AA4006 /* SD_Misc.h in Headers */ = {isa = PBXBuildFile; fileRef = 05D6A0660BF1293100AA4006 /* SD_Misc.h */; };
293 1A147D05107EB37E006FFB43 /* License.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C98484A0F9A5D7800A2842D /* License.h */; };
294@@ -133,6 +132,9 @@
295 /* Begin PBXProject section */
296 089C1669FE841209C02AAC07 /* Project object */ = {
297 isa = PBXProject;
298+attributes = {
299+LastUpgradeCheck = 0460;
300+};
301 buildConfigurationList = 1DEB91DD08733DB10010E9CD /* Build configuration list for PBXProject "VoodooSDHC" */;
302 compatibilityVersion = "Xcode 3.2";
303 developmentRegion = English;
304@@ -158,7 +160,6 @@
305 buildActionMask = 2147483647;
306 files = (
307 32D94FC80562CBF700B6AF17 /* InfoPlist.strings in Resources */,
308-05D69FBB0BF0D16100AA4006 /* Info.plist in Resources */,
309 );
310 runOnlyForDeploymentPostprocessing = 0;
311 };
312@@ -201,10 +202,10 @@
313 isa = XCBuildConfiguration;
314 buildSettings = {
315 ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
316+COMBINE_HIDPI_IMAGES = YES;
317 COPY_PHASE_STRIP = NO;
318 CURRENT_PROJECT_VERSION = 1.1d1;
319 GCC_DYNAMIC_NO_PIC = NO;
320-GCC_ENABLE_FIX_AND_CONTINUE = YES;
321 GCC_MODEL_TUNING = G5;
322 GCC_OPTIMIZATION_LEVEL = 0;
323 INFOPLIST_FILE = Info.plist;
324@@ -213,6 +214,7 @@
325 MODULE_VERSION = 1.1d1;
326 ONLY_ACTIVE_ARCH = NO;
327 PRODUCT_NAME = VoodooSDHC;
328+SDKROOT = macosx10.7;
329 WRAPPER_EXTENSION = kext;
330 ZERO_LINK = YES;
331 };
332@@ -221,7 +223,8 @@
333 1DEB91DB08733DB10010E9CD /* Release */ = {
334 isa = XCBuildConfiguration;
335 buildSettings = {
336-ARCHS = "$(NATIVE_ARCH)";
337+ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
338+COMBINE_HIDPI_IMAGES = YES;
339 CURRENT_PROJECT_VERSION = 1.1d1;
340 GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
341 GCC_MODEL_TUNING = G5;
342@@ -230,6 +233,7 @@
343 MODULE_NAME = com.Voodoo.driver.VoodooSDHC;
344 MODULE_VERSION = 1.1d1;
345 PRODUCT_NAME = VoodooSDHC;
346+SDKROOT = macosx10.7;
347 WRAPPER_EXTENSION = kext;
348 };
349 name = Release;
350@@ -243,8 +247,7 @@
351 GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = NO;
352 GCC_WARN_PEDANTIC = NO;
353 GCC_WARN_UNUSED_VARIABLE = YES;
354-PREBINDING = NO;
355-SDKROOT = macosx10.6;
356+SDKROOT = macosx;
357 VALID_ARCHS = "i386 x86_64";
358 };
359 name = Debug;
360@@ -254,8 +257,7 @@
361 buildSettings = {
362 GCC_WARN_ABOUT_RETURN_TYPE = YES;
363 GCC_WARN_UNUSED_VARIABLE = YES;
364-PREBINDING = NO;
365-SDKROOT = macosx10.6;
366+SDKROOT = macosx;
367 };
368 name = Release;
369 };
370

Archive Download this file

Attachment to issue 335

Created: 4 years 21 days ago by Sergey Lvov