1212#include <linux/module.h>
1313#include <asm/io.h>
1414
15- /*
16- ** Copies a block of memory from a device in an efficient manner.
17- ** Assumes the device can cope with 32-bit transfers. If it can't,
18- ** don't use this function.
19- **
20- ** CR16 counts on C3000 reading 256 bytes from Symbios 896 RAM:
21- ** 27341/64 = 427 cyc per int
22- ** 61311/128 = 478 cyc per short
23- ** 122637/256 = 479 cyc per byte
24- ** Ergo bus latencies dominant (not transfer size).
25- ** Minimize total number of transfers at cost of CPU cycles.
26- ** TODO: only look at src alignment and adjust the stores to dest.
27- */
28- void memcpy_fromio (void * dst , const volatile void __iomem * src , int count )
29- {
30- /* first compare alignment of src/dst */
31- if ( (((unsigned long )dst ^ (unsigned long )src ) & 1 ) || (count < 2 ) )
32- goto bytecopy ;
33-
34- if ( (((unsigned long )dst ^ (unsigned long )src ) & 2 ) || (count < 4 ) )
35- goto shortcopy ;
36-
37- /* Then check for misaligned start address */
38- if ((unsigned long )src & 1 ) {
39- * (u8 * )dst = readb (src );
40- src ++ ;
41- dst ++ ;
42- count -- ;
43- if (count < 2 ) goto bytecopy ;
44- }
45-
46- if ((unsigned long )src & 2 ) {
47- * (u16 * )dst = __raw_readw (src );
48- src += 2 ;
49- dst += 2 ;
50- count -= 2 ;
51- }
52-
53- while (count > 3 ) {
54- * (u32 * )dst = __raw_readl (src );
55- dst += 4 ;
56- src += 4 ;
57- count -= 4 ;
58- }
59-
60- shortcopy :
61- while (count > 1 ) {
62- * (u16 * )dst = __raw_readw (src );
63- src += 2 ;
64- dst += 2 ;
65- count -= 2 ;
66- }
67-
68- bytecopy :
69- while (count -- ) {
70- * (char * )dst = readb (src );
71- src ++ ;
72- dst ++ ;
73- }
74- }
75-
7615/*
7716 * Read COUNT 8-bit bytes from port PORT into memory starting at
7817 * SRC.
@@ -123,15 +62,15 @@ void insw (unsigned long port, void *dst, unsigned long count)
12362 unsigned char * p ;
12463
12564 p = (unsigned char * )dst ;
126-
65+
12766 if (!count )
12867 return ;
129-
68+
13069 switch (((unsigned long )p ) & 0x3 )
13170 {
13271 case 0x00 : /* Buffer 32-bit aligned */
13372 while (count >=2 ) {
134-
73+
13574 count -= 2 ;
13675 l = cpu_to_le16 (inw (port )) << 16 ;
13776 l |= cpu_to_le16 (inw (port ));
@@ -142,13 +81,13 @@ void insw (unsigned long port, void *dst, unsigned long count)
14281 * (unsigned short * )p = cpu_to_le16 (inw (port ));
14382 }
14483 break ;
145-
84+
14685 case 0x02 : /* Buffer 16-bit aligned */
14786 * (unsigned short * )p = cpu_to_le16 (inw (port ));
14887 p += 2 ;
14988 count -- ;
15089 while (count >=2 ) {
151-
90+
15291 count -= 2 ;
15392 l = cpu_to_le16 (inw (port )) << 16 ;
15493 l |= cpu_to_le16 (inw (port ));
@@ -159,13 +98,13 @@ void insw (unsigned long port, void *dst, unsigned long count)
15998 * (unsigned short * )p = cpu_to_le16 (inw (port ));
16099 }
161100 break ;
162-
101+
163102 case 0x01 : /* Buffer 8-bit aligned */
164103 case 0x03 :
165104 /* I don't bother with 32bit transfers
166105 * in this case, 16bit will have to do -- DE */
167106 -- count ;
168-
107+
169108 l = cpu_to_le16 (inw (port ));
170109 * p = l >> 8 ;
171110 p ++ ;
@@ -195,10 +134,10 @@ void insl (unsigned long port, void *dst, unsigned long count)
195134 unsigned char * p ;
196135
197136 p = (unsigned char * )dst ;
198-
137+
199138 if (!count )
200139 return ;
201-
140+
202141 switch (((unsigned long ) dst ) & 0x3 )
203142 {
204143 case 0x00 : /* Buffer 32-bit aligned */
@@ -208,14 +147,14 @@ void insl (unsigned long port, void *dst, unsigned long count)
208147 p += 4 ;
209148 }
210149 break ;
211-
150+
212151 case 0x02 : /* Buffer 16-bit aligned */
213152 -- count ;
214-
153+
215154 l = cpu_to_le32 (inl (port ));
216155 * (unsigned short * )p = l >> 16 ;
217156 p += 2 ;
218-
157+
219158 while (count -- )
220159 {
221160 l2 = cpu_to_le32 (inl (port ));
@@ -227,7 +166,7 @@ void insl (unsigned long port, void *dst, unsigned long count)
227166 break ;
228167 case 0x01 : /* Buffer 8-bit aligned */
229168 -- count ;
230-
169+
231170 l = cpu_to_le32 (inl (port ));
232171 * (unsigned char * )p = l >> 24 ;
233172 p ++ ;
@@ -244,7 +183,7 @@ void insl (unsigned long port, void *dst, unsigned long count)
244183 break ;
245184 case 0x03 : /* Buffer 8-bit aligned */
246185 -- count ;
247-
186+
248187 l = cpu_to_le32 (inl (port ));
249188 * p = l >> 24 ;
250189 p ++ ;
@@ -293,10 +232,10 @@ void outsw (unsigned long port, const void *src, unsigned long count)
293232 const unsigned char * p ;
294233
295234 p = (const unsigned char * )src ;
296-
235+
297236 if (!count )
298237 return ;
299-
238+
300239 switch (((unsigned long )p ) & 0x3 )
301240 {
302241 case 0x00 : /* Buffer 32-bit aligned */
@@ -311,13 +250,13 @@ void outsw (unsigned long port, const void *src, unsigned long count)
311250 outw (le16_to_cpu (* (unsigned short * )p ), port );
312251 }
313252 break ;
314-
253+
315254 case 0x02 : /* Buffer 16-bit aligned */
316-
255+
317256 outw (le16_to_cpu (* (unsigned short * )p ), port );
318257 p += 2 ;
319258 count -- ;
320-
259+
321260 while (count >=2 ) {
322261 count -= 2 ;
323262 l = * (unsigned int * )p ;
@@ -329,11 +268,11 @@ void outsw (unsigned long port, const void *src, unsigned long count)
329268 outw (le16_to_cpu (* (unsigned short * )p ), port );
330269 }
331270 break ;
332-
333- case 0x01 : /* Buffer 8-bit aligned */
271+
272+ case 0x01 : /* Buffer 8-bit aligned */
334273 /* I don't bother with 32bit transfers
335274 * in this case, 16bit will have to do -- DE */
336-
275+
337276 l = * p << 8 ;
338277 p ++ ;
339278 count -- ;
@@ -348,7 +287,7 @@ void outsw (unsigned long port, const void *src, unsigned long count)
348287 l2 = * (unsigned char * )p ;
349288 outw (le16_to_cpu (l | l2 >>8 ), port );
350289 break ;
351-
290+
352291 }
353292}
354293
@@ -365,10 +304,10 @@ void outsl (unsigned long port, const void *src, unsigned long count)
365304 const unsigned char * p ;
366305
367306 p = (const unsigned char * )src ;
368-
307+
369308 if (!count )
370309 return ;
371-
310+
372311 switch (((unsigned long )p ) & 0x3 )
373312 {
374313 case 0x00 : /* Buffer 32-bit aligned */
@@ -378,13 +317,13 @@ void outsl (unsigned long port, const void *src, unsigned long count)
378317 p += 4 ;
379318 }
380319 break ;
381-
320+
382321 case 0x02 : /* Buffer 16-bit aligned */
383322 -- count ;
384-
323+
385324 l = * (unsigned short * )p ;
386325 p += 2 ;
387-
326+
388327 while (count -- )
389328 {
390329 l2 = * (unsigned int * )p ;
@@ -415,7 +354,7 @@ void outsl (unsigned long port, const void *src, unsigned long count)
415354 break ;
416355 case 0x03 : /* Buffer 8-bit aligned */
417356 -- count ;
418-
357+
419358 l = * p << 24 ;
420359 p ++ ;
421360
0 commit comments