2 * Alpha IO and memory functions.
5 #include <linux/kernel.h>
6 #include <linux/types.h>
7 #include <linux/string.h>
8 #include <linux/module.h>
11 /* Out-of-line versions of the i/o routines that redirect into the
12 platform-specific version. Note that "platform-specific" may mean
13 "generic", which bumps through the machine vector. */
16 ioread8(void __iomem
*addr
)
18 unsigned int ret
= IO_CONCAT(__IO_PREFIX
,ioread8
)(addr
);
23 unsigned int ioread16(void __iomem
*addr
)
25 unsigned int ret
= IO_CONCAT(__IO_PREFIX
,ioread16
)(addr
);
30 unsigned int ioread32(void __iomem
*addr
)
32 unsigned int ret
= IO_CONCAT(__IO_PREFIX
,ioread32
)(addr
);
37 void iowrite8(u8 b
, void __iomem
*addr
)
39 IO_CONCAT(__IO_PREFIX
,iowrite8
)(b
, addr
);
43 void iowrite16(u16 b
, void __iomem
*addr
)
45 IO_CONCAT(__IO_PREFIX
,iowrite16
)(b
, addr
);
49 void iowrite32(u32 b
, void __iomem
*addr
)
51 IO_CONCAT(__IO_PREFIX
,iowrite32
)(b
, addr
);
55 EXPORT_SYMBOL(ioread8
);
56 EXPORT_SYMBOL(ioread16
);
57 EXPORT_SYMBOL(ioread32
);
58 EXPORT_SYMBOL(iowrite8
);
59 EXPORT_SYMBOL(iowrite16
);
60 EXPORT_SYMBOL(iowrite32
);
62 u8
inb(unsigned long port
)
64 return ioread8(ioport_map(port
, 1));
67 u16
inw(unsigned long port
)
69 return ioread16(ioport_map(port
, 2));
72 u32
inl(unsigned long port
)
74 return ioread32(ioport_map(port
, 4));
77 void outb(u8 b
, unsigned long port
)
79 iowrite8(b
, ioport_map(port
, 1));
82 void outw(u16 b
, unsigned long port
)
84 iowrite16(b
, ioport_map(port
, 2));
87 void outl(u32 b
, unsigned long port
)
89 iowrite32(b
, ioport_map(port
, 4));
99 u8
__raw_readb(const volatile void __iomem
*addr
)
101 return IO_CONCAT(__IO_PREFIX
,readb
)(addr
);
104 u16
__raw_readw(const volatile void __iomem
*addr
)
106 return IO_CONCAT(__IO_PREFIX
,readw
)(addr
);
109 u32
__raw_readl(const volatile void __iomem
*addr
)
111 return IO_CONCAT(__IO_PREFIX
,readl
)(addr
);
114 u64
__raw_readq(const volatile void __iomem
*addr
)
116 return IO_CONCAT(__IO_PREFIX
,readq
)(addr
);
119 void __raw_writeb(u8 b
, volatile void __iomem
*addr
)
121 IO_CONCAT(__IO_PREFIX
,writeb
)(b
, addr
);
124 void __raw_writew(u16 b
, volatile void __iomem
*addr
)
126 IO_CONCAT(__IO_PREFIX
,writew
)(b
, addr
);
129 void __raw_writel(u32 b
, volatile void __iomem
*addr
)
131 IO_CONCAT(__IO_PREFIX
,writel
)(b
, addr
);
134 void __raw_writeq(u64 b
, volatile void __iomem
*addr
)
136 IO_CONCAT(__IO_PREFIX
,writeq
)(b
, addr
);
139 EXPORT_SYMBOL(__raw_readb
);
140 EXPORT_SYMBOL(__raw_readw
);
141 EXPORT_SYMBOL(__raw_readl
);
142 EXPORT_SYMBOL(__raw_readq
);
143 EXPORT_SYMBOL(__raw_writeb
);
144 EXPORT_SYMBOL(__raw_writew
);
145 EXPORT_SYMBOL(__raw_writel
);
146 EXPORT_SYMBOL(__raw_writeq
);
148 u8
readb(const volatile void __iomem
*addr
)
150 u8 ret
= __raw_readb(addr
);
155 u16
readw(const volatile void __iomem
*addr
)
157 u16 ret
= __raw_readw(addr
);
162 u32
readl(const volatile void __iomem
*addr
)
164 u32 ret
= __raw_readl(addr
);
169 u64
readq(const volatile void __iomem
*addr
)
171 u64 ret
= __raw_readq(addr
);
176 void writeb(u8 b
, volatile void __iomem
*addr
)
178 __raw_writeb(b
, addr
);
182 void writew(u16 b
, volatile void __iomem
*addr
)
184 __raw_writew(b
, addr
);
188 void writel(u32 b
, volatile void __iomem
*addr
)
190 __raw_writel(b
, addr
);
194 void writeq(u64 b
, volatile void __iomem
*addr
)
196 __raw_writeq(b
, addr
);
200 EXPORT_SYMBOL(readb
);
201 EXPORT_SYMBOL(readw
);
202 EXPORT_SYMBOL(readl
);
203 EXPORT_SYMBOL(readq
);
204 EXPORT_SYMBOL(writeb
);
205 EXPORT_SYMBOL(writew
);
206 EXPORT_SYMBOL(writel
);
207 EXPORT_SYMBOL(writeq
);
211 * Read COUNT 8-bit bytes from port PORT into memory starting at SRC.
213 void ioread8_rep(void __iomem
*port
, void *dst
, unsigned long count
)
215 while ((unsigned long)dst
& 0x3) {
219 *(unsigned char *)dst
= ioread8(port
);
227 w
|= ioread8(port
) << 8;
228 w
|= ioread8(port
) << 16;
229 w
|= ioread8(port
) << 24;
230 *(unsigned int *)dst
= w
;
236 *(unsigned char *)dst
= ioread8(port
);
241 void insb(unsigned long port
, void *dst
, unsigned long count
)
243 ioread8_rep(ioport_map(port
, 1), dst
, count
);
246 EXPORT_SYMBOL(ioread8_rep
);
250 * Read COUNT 16-bit words from port PORT into memory starting at
251 * SRC. SRC must be at least short aligned. This is used by the
252 * IDE driver to read disk sectors. Performance is important, but
253 * the interfaces seems to be slow: just using the inlined version
254 * of the inw() breaks things.
256 void ioread16_rep(void __iomem
*port
, void *dst
, unsigned long count
)
258 if (unlikely((unsigned long)dst
& 0x3)) {
261 BUG_ON((unsigned long)dst
& 0x1);
263 *(unsigned short *)dst
= ioread16(port
);
271 w
|= ioread16(port
) << 16;
272 *(unsigned int *)dst
= w
;
277 *(unsigned short*)dst
= ioread16(port
);
281 void insw(unsigned long port
, void *dst
, unsigned long count
)
283 ioread16_rep(ioport_map(port
, 2), dst
, count
);
286 EXPORT_SYMBOL(ioread16_rep
);
291 * Read COUNT 32-bit words from port PORT into memory starting at
292 * SRC. Now works with any alignment in SRC. Performance is important,
293 * but the interfaces seems to be slow: just using the inlined version
294 * of the inl() breaks things.
296 void ioread32_rep(void __iomem
*port
, void *dst
, unsigned long count
)
298 if (unlikely((unsigned long)dst
& 0x3)) {
300 struct S
{ int x
__attribute__((packed
)); };
301 ((struct S
*)dst
)->x
= ioread32(port
);
305 /* Buffer 32-bit aligned. */
307 *(unsigned int *)dst
= ioread32(port
);
313 void insl(unsigned long port
, void *dst
, unsigned long count
)
315 ioread32_rep(ioport_map(port
, 4), dst
, count
);
318 EXPORT_SYMBOL(ioread32_rep
);
323 * Like insb but in the opposite direction.
324 * Don't worry as much about doing aligned memory transfers:
325 * doing byte reads the "slow" way isn't nearly as slow as
326 * doing byte writes the slow way (no r-m-w cycle).
328 void iowrite8_rep(void __iomem
*port
, const void *xsrc
, unsigned long count
)
330 const unsigned char *src
= xsrc
;
332 iowrite8(*src
++, port
);
335 void outsb(unsigned long port
, const void *src
, unsigned long count
)
337 iowrite8_rep(ioport_map(port
, 1), src
, count
);
340 EXPORT_SYMBOL(iowrite8_rep
);
341 EXPORT_SYMBOL(outsb
);
345 * Like insw but in the opposite direction. This is used by the IDE
346 * driver to write disk sectors. Performance is important, but the
347 * interfaces seems to be slow: just using the inlined version of the
348 * outw() breaks things.
350 void iowrite16_rep(void __iomem
*port
, const void *src
, unsigned long count
)
352 if (unlikely((unsigned long)src
& 0x3)) {
355 BUG_ON((unsigned long)src
& 0x1);
356 iowrite16(*(unsigned short *)src
, port
);
364 w
= *(unsigned int *)src
;
366 iowrite16(w
>> 0, port
);
367 iowrite16(w
>> 16, port
);
371 iowrite16(*(unsigned short *)src
, port
);
375 void outsw(unsigned long port
, const void *src
, unsigned long count
)
377 iowrite16_rep(ioport_map(port
, 2), src
, count
);
380 EXPORT_SYMBOL(iowrite16_rep
);
381 EXPORT_SYMBOL(outsw
);
385 * Like insl but in the opposite direction. This is used by the IDE
386 * driver to write disk sectors. Works with any alignment in SRC.
387 * Performance is important, but the interfaces seems to be slow:
388 * just using the inlined version of the outl() breaks things.
390 void iowrite32_rep(void __iomem
*port
, const void *src
, unsigned long count
)
392 if (unlikely((unsigned long)src
& 0x3)) {
394 struct S
{ int x
__attribute__((packed
)); };
395 iowrite32(((struct S
*)src
)->x
, port
);
399 /* Buffer 32-bit aligned. */
401 iowrite32(*(unsigned int *)src
, port
);
407 void outsl(unsigned long port
, const void *src
, unsigned long count
)
409 iowrite32_rep(ioport_map(port
, 4), src
, count
);
412 EXPORT_SYMBOL(iowrite32_rep
);
413 EXPORT_SYMBOL(outsl
);
417 * Copy data from IO memory space to "real" memory space.
418 * This needs to be optimized.
420 void memcpy_fromio(void *to
, const volatile void __iomem
*from
, long count
)
422 /* Optimize co-aligned transfers. Everything else gets handled
425 if (count
>= 8 && ((u64
)to
& 7) == ((u64
)from
& 7)) {
428 *(u64
*)to
= __raw_readq(from
);
432 } while (count
>= 0);
436 if (count
>= 4 && ((u64
)to
& 3) == ((u64
)from
& 3)) {
439 *(u32
*)to
= __raw_readl(from
);
443 } while (count
>= 0);
447 if (count
>= 2 && ((u64
)to
& 1) == ((u64
)from
& 1)) {
450 *(u16
*)to
= __raw_readw(from
);
454 } while (count
>= 0);
459 *(u8
*) to
= __raw_readb(from
);
467 EXPORT_SYMBOL(memcpy_fromio
);
471 * Copy data from "real" memory space to IO memory space.
472 * This needs to be optimized.
474 void memcpy_toio(volatile void __iomem
*to
, const void *from
, long count
)
476 /* Optimize co-aligned transfers. Everything else gets handled
478 /* FIXME -- align FROM. */
480 if (count
>= 8 && ((u64
)to
& 7) == ((u64
)from
& 7)) {
483 __raw_writeq(*(const u64
*)from
, to
);
487 } while (count
>= 0);
491 if (count
>= 4 && ((u64
)to
& 3) == ((u64
)from
& 3)) {
494 __raw_writel(*(const u32
*)from
, to
);
498 } while (count
>= 0);
502 if (count
>= 2 && ((u64
)to
& 1) == ((u64
)from
& 1)) {
505 __raw_writew(*(const u16
*)from
, to
);
509 } while (count
>= 0);
514 __raw_writeb(*(const u8
*) from
, to
);
522 EXPORT_SYMBOL(memcpy_toio
);
526 * "memset" on IO memory space.
528 void _memset_c_io(volatile void __iomem
*to
, unsigned long c
, long count
)
530 /* Handle any initial odd byte */
531 if (count
> 0 && ((u64
)to
& 1)) {
537 /* Handle any initial odd halfword */
538 if (count
>= 2 && ((u64
)to
& 2)) {
544 /* Handle any initial odd word */
545 if (count
>= 4 && ((u64
)to
& 4)) {
551 /* Handle all full-sized quadwords: we're aligned
552 (or have a small count) */
559 } while (count
>= 0);
563 /* The tail is word-aligned if we still have count >= 4 */
570 /* The tail is half-word aligned if we have count >= 2 */
577 /* And finally, one last byte.. */
584 EXPORT_SYMBOL(_memset_c_io
);
586 /* A version of memcpy used by the vga console routines to move data around
587 arbitrarily between screen and main memory. */
590 scr_memcpyw(u16
*d
, const u16
*s
, unsigned int count
)
592 const u16 __iomem
*ios
= (const u16 __iomem
*) s
;
593 u16 __iomem
*iod
= (u16 __iomem
*) d
;
594 int s_isio
= __is_ioaddr(s
);
595 int d_isio
= __is_ioaddr(d
);
599 /* FIXME: Should handle unaligned ops and
600 operation widening. */
604 u16 tmp
= __raw_readw(ios
++);
605 __raw_writew(tmp
, iod
++);
609 memcpy_fromio(d
, ios
, count
);
612 memcpy_toio(iod
, s
, count
);
618 EXPORT_SYMBOL(scr_memcpyw
);
620 void __iomem
*ioport_map(unsigned long port
, unsigned int size
)
622 return IO_CONCAT(__IO_PREFIX
,ioportmap
) (port
);
625 void ioport_unmap(void __iomem
*addr
)
629 EXPORT_SYMBOL(ioport_map
);
630 EXPORT_SYMBOL(ioport_unmap
);
This page took 0.050406 seconds and 5 git commands to generate.