Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v2.6.22 139 lines 3.3 kB view raw
1/* 2 * Copyright (C) 2000 David J. Mckay (david.mckay@st.com) 3 * 4 * May be copied or modified under the terms of the GNU General Public 5 * License. See linux/COPYING for more information. 6 * 7 * This file contains the I/O routines for use on the overdrive board 8 * 9 */ 10 11#include <linux/kernel.h> 12#include <linux/types.h> 13#include <linux/delay.h> 14#include <asm/system.h> 15#include <asm/processor.h> 16#include <asm/io.h> 17 18/* 19 * readX/writeX() are used to access memory mapped devices. On some 20 * architectures the memory mapped IO stuff needs to be accessed 21 * differently. On the SuperH architecture, we just read/write the 22 * memory location directly. 23 */ 24 25/* This is horrible at the moment - needs more work to do something sensible */ 26#define IO_DELAY() 27 28#define OUT_DELAY(x,type) \ 29void out##x##_p(unsigned type value,unsigned long port){out##x(value,port);IO_DELAY();} 30 31#define IN_DELAY(x,type) \ 32unsigned type in##x##_p(unsigned long port) {unsigned type tmp=in##x(port);IO_DELAY();return tmp;} 33 34#if 1 35OUT_DELAY(b, long) OUT_DELAY(w, long) OUT_DELAY(l, long) 36 IN_DELAY(b, long) IN_DELAY(w, long) IN_DELAY(l, long) 37#endif 38/* Now for the string version of these functions */ 39void outsb(unsigned long port, const void *addr, unsigned long count) 40{ 41 int i; 42 unsigned char *p = (unsigned char *) addr; 43 44 for (i = 0; i < count; i++, p++) { 45 outb(*p, port); 46 } 47} 48 49void insb(unsigned long port, void *addr, unsigned long count) 50{ 51 int i; 52 unsigned char *p = (unsigned char *) addr; 53 54 for (i = 0; i < count; i++, p++) { 55 *p = inb(port); 56 } 57} 58 59/* For the 16 and 32 bit string functions, we have to worry about alignment. 60 * The SH does not do unaligned accesses, so we have to read as bytes and 61 * then write as a word or dword. 62 * This can be optimised a lot more, especially in the case where the data 63 * is aligned 64 */ 65 66void outsw(unsigned long port, const void *addr, unsigned long count) 67{ 68 int i; 69 unsigned short tmp; 70 unsigned char *p = (unsigned char *) addr; 71 72 for (i = 0; i < count; i++, p += 2) { 73 tmp = (*p) | ((*(p + 1)) << 8); 74 outw(tmp, port); 75 } 76} 77 78void insw(unsigned long port, void *addr, unsigned long count) 79{ 80 int i; 81 unsigned short tmp; 82 unsigned char *p = (unsigned char *) addr; 83 84 for (i = 0; i < count; i++, p += 2) { 85 tmp = inw(port); 86 p[0] = tmp & 0xff; 87 p[1] = (tmp >> 8) & 0xff; 88 } 89} 90 91void outsl(unsigned long port, const void *addr, unsigned long count) 92{ 93 int i; 94 unsigned tmp; 95 unsigned char *p = (unsigned char *) addr; 96 97 for (i = 0; i < count; i++, p += 4) { 98 tmp = (*p) | ((*(p + 1)) << 8) | ((*(p + 2)) << 16) | 99 ((*(p + 3)) << 24); 100 outl(tmp, port); 101 } 102} 103 104void insl(unsigned long port, void *addr, unsigned long count) 105{ 106 int i; 107 unsigned tmp; 108 unsigned char *p = (unsigned char *) addr; 109 110 for (i = 0; i < count; i++, p += 4) { 111 tmp = inl(port); 112 p[0] = tmp & 0xff; 113 p[1] = (tmp >> 8) & 0xff; 114 p[2] = (tmp >> 16) & 0xff; 115 p[3] = (tmp >> 24) & 0xff; 116 117 } 118} 119 120void memcpy_toio(void __iomem *to, const void *from, long count) 121{ 122 unsigned char *p = (unsigned char *) from; 123 124 while (count) { 125 count--; 126 writeb(*p++, to++); 127 } 128} 129 130void memcpy_fromio(void *to, void __iomem *from, long count) 131{ 132 int i; 133 unsigned char *p = (unsigned char *) to; 134 135 for (i = 0; i < count; i++) { 136 p[i] = readb(from); 137 from++; 138 } 139}