2002-11-18 00:14:45 +00:00
|
|
|
#ifndef _ASM_IO_H
|
|
|
|
#define _ASM_IO_H
|
|
|
|
|
2012-10-23 18:04:44 +00:00
|
|
|
#include <compiler.h>
|
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
/*
|
|
|
|
* This file contains the definitions for the x86 IO instructions
|
|
|
|
* inb/inw/inl/outb/outw/outl and the "string versions" of the same
|
|
|
|
* (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
|
|
|
|
* versions of the single-IO instructions (inb_p/inw_p/..).
|
|
|
|
*
|
|
|
|
* This file is not meant to be obfuscating: it's just complicated
|
|
|
|
* to (a) handle it all in a way that makes gcc able to optimize it
|
|
|
|
* as well as possible and (b) trying to avoid writing the same thing
|
|
|
|
* over and over again with slight variations and possibly making a
|
|
|
|
* mistake somewhere.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Thanks to James van Artsdalen for a better timing-fix than
|
|
|
|
* the two short jumps: using outb's to a nonexistent port seems
|
|
|
|
* to guarantee better timings even on fast machines.
|
|
|
|
*
|
|
|
|
* On the other hand, I'd like to be sure of a non-existent port:
|
|
|
|
* I feel a bit unsafe about using 0x80 (should be safe, though)
|
|
|
|
*
|
|
|
|
* Linus
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bit simplified and optimized by Jan Hubicka
|
|
|
|
* Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
|
|
|
|
*
|
|
|
|
* isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added,
|
|
|
|
* isa_read[wl] and isa_write[wl] fixed
|
|
|
|
* - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define IO_SPACE_LIMIT 0xffff
|
|
|
|
|
2012-10-20 12:33:13 +00:00
|
|
|
#include <asm/types.h>
|
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* readX/writeX() are used to access memory mapped devices. On some
|
|
|
|
* architectures the memory mapped IO stuff needs to be accessed
|
|
|
|
* differently. On the x86 architecture, we just read/write the
|
|
|
|
* memory location directly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define readb(addr) (*(volatile unsigned char *) (addr))
|
|
|
|
#define readw(addr) (*(volatile unsigned short *) (addr))
|
|
|
|
#define readl(addr) (*(volatile unsigned int *) (addr))
|
|
|
|
#define __raw_readb readb
|
|
|
|
#define __raw_readw readw
|
|
|
|
#define __raw_readl readl
|
|
|
|
|
|
|
|
#define writeb(b,addr) (*(volatile unsigned char *) (addr) = (b))
|
|
|
|
#define writew(b,addr) (*(volatile unsigned short *) (addr) = (b))
|
|
|
|
#define writel(b,addr) (*(volatile unsigned int *) (addr) = (b))
|
|
|
|
#define __raw_writeb writeb
|
|
|
|
#define __raw_writew writew
|
|
|
|
#define __raw_writel writel
|
|
|
|
|
|
|
|
#define memset_io(a,b,c) memset((a),(b),(c))
|
|
|
|
#define memcpy_fromio(a,b,c) memcpy((a),(b),(c))
|
|
|
|
#define memcpy_toio(a,b,c) memcpy((a),(b),(c))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ISA space is 'always mapped' on a typical x86 system, no need to
|
|
|
|
* explicitly ioremap() it. The fact that the ISA IO space is mapped
|
|
|
|
* to PAGE_OFFSET is pure coincidence - it does not mean ISA values
|
|
|
|
* are physical addresses. The following constant pointer can be
|
|
|
|
* used as the IO-area pointer (it can be iounmapped as well, so the
|
|
|
|
* analogy with PCI is quite large):
|
|
|
|
*/
|
|
|
|
#define isa_readb(a) readb((a))
|
|
|
|
#define isa_readw(a) readw((a))
|
|
|
|
#define isa_readl(a) readl((a))
|
|
|
|
#define isa_writeb(b,a) writeb(b,(a))
|
|
|
|
#define isa_writew(w,a) writew(w,(a))
|
|
|
|
#define isa_writel(l,a) writel(l,(a))
|
|
|
|
#define isa_memset_io(a,b,c) memset_io((a),(b),(c))
|
|
|
|
#define isa_memcpy_fromio(a,b,c) memcpy_fromio((a),(b),(c))
|
|
|
|
#define isa_memcpy_toio(a,b,c) memcpy_toio((a),(b),(c))
|
|
|
|
|
|
|
|
|
|
|
|
static inline int check_signature(unsigned long io_addr,
|
|
|
|
const unsigned char *signature, int length)
|
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
do {
|
|
|
|
if (readb(io_addr) != *signature)
|
|
|
|
goto out;
|
|
|
|
io_addr++;
|
|
|
|
signature++;
|
|
|
|
length--;
|
|
|
|
} while (length);
|
|
|
|
retval = 1;
|
|
|
|
out:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* isa_check_signature - find BIOS signatures
|
2003-06-27 21:31:46 +00:00
|
|
|
* @io_addr: mmio address to check
|
2002-11-18 00:14:45 +00:00
|
|
|
* @signature: signature block
|
|
|
|
* @length: length of signature
|
|
|
|
*
|
|
|
|
* Perform a signature comparison with the ISA mmio address io_addr.
|
|
|
|
* Returns 1 on a match.
|
|
|
|
*
|
|
|
|
* This function is deprecated. New drivers should use ioremap and
|
|
|
|
* check_signature.
|
|
|
|
*/
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
|
|
|
|
static inline int isa_check_signature(unsigned long io_addr,
|
|
|
|
const unsigned char *signature, int length)
|
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
do {
|
|
|
|
if (isa_readb(io_addr) != *signature)
|
|
|
|
goto out;
|
|
|
|
io_addr++;
|
|
|
|
signature++;
|
|
|
|
length--;
|
|
|
|
} while (length);
|
|
|
|
retval = 1;
|
|
|
|
out:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
#ifdef SLOW_IO_BY_JUMPING
|
|
|
|
#define __SLOW_DOWN_IO "\njmp 1f\n1:\tjmp 1f\n1:"
|
|
|
|
#else
|
2012-10-20 12:33:16 +00:00
|
|
|
#define __SLOW_DOWN_IO "\noutb %%al,$0xed"
|
2002-11-18 00:14:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef REALLY_SLOW_IO
|
|
|
|
#define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO
|
|
|
|
#else
|
|
|
|
#define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Talk about misusing macros..
|
|
|
|
*/
|
|
|
|
#define __OUT1(s,x) \
|
|
|
|
static inline void out##s(unsigned x value, unsigned short port) {
|
|
|
|
|
|
|
|
#define __OUT2(s,s1,s2) \
|
|
|
|
__asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
|
|
|
|
|
|
|
|
|
|
|
|
#define __OUT(s,s1,x) \
|
|
|
|
__OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
|
2003-06-27 21:31:46 +00:00
|
|
|
__OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));}
|
2002-11-18 00:14:45 +00:00
|
|
|
|
|
|
|
#define __IN1(s) \
|
|
|
|
static inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
|
|
|
|
|
|
|
|
#define __IN2(s,s1,s2) \
|
|
|
|
__asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
|
|
|
|
|
|
|
|
#define __IN(s,s1,i...) \
|
|
|
|
__IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
|
2003-06-27 21:31:46 +00:00
|
|
|
__IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; }
|
2002-11-18 00:14:45 +00:00
|
|
|
|
|
|
|
#define __INS(s) \
|
|
|
|
static inline void ins##s(unsigned short port, void * addr, unsigned long count) \
|
|
|
|
{ __asm__ __volatile__ ("rep ; ins" #s \
|
|
|
|
: "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
|
|
|
|
|
|
|
|
#define __OUTS(s) \
|
|
|
|
static inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
|
|
|
|
{ __asm__ __volatile__ ("rep ; outs" #s \
|
|
|
|
: "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
|
|
|
|
|
|
|
|
#define RETURN_TYPE unsigned char
|
|
|
|
__IN(b,"")
|
|
|
|
#undef RETURN_TYPE
|
|
|
|
#define RETURN_TYPE unsigned short
|
|
|
|
__IN(w,"")
|
|
|
|
#undef RETURN_TYPE
|
|
|
|
#define RETURN_TYPE unsigned int
|
|
|
|
__IN(l,"")
|
|
|
|
#undef RETURN_TYPE
|
|
|
|
|
|
|
|
__OUT(b,"b",char)
|
|
|
|
__OUT(w,"w",short)
|
|
|
|
__OUT(l,,int)
|
|
|
|
|
|
|
|
__INS(b)
|
|
|
|
__INS(w)
|
|
|
|
__INS(l)
|
|
|
|
|
|
|
|
__OUTS(b)
|
|
|
|
__OUTS(w)
|
|
|
|
__OUTS(l)
|
|
|
|
|
2007-02-21 15:52:31 +00:00
|
|
|
static inline void sync(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-12-13 11:56:33 +00:00
|
|
|
/*
|
|
|
|
* Given a physical address and a length, return a virtual address
|
|
|
|
* that can be used to access the memory range with the caching
|
|
|
|
* properties specified by "flags".
|
|
|
|
*/
|
|
|
|
#define MAP_NOCACHE (0)
|
|
|
|
#define MAP_WRCOMBINE (0)
|
|
|
|
#define MAP_WRBACK (0)
|
|
|
|
#define MAP_WRTHROUGH (0)
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
|
|
|
|
{
|
2012-10-23 18:04:44 +00:00
|
|
|
return (void *)(uintptr_t)paddr;
|
2007-12-13 11:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take down a mapping set up by map_physmem().
|
|
|
|
*/
|
|
|
|
static inline void unmap_physmem(void *vaddr, unsigned long flags)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-13 23:20:27 +00:00
|
|
|
static inline phys_addr_t virt_to_phys(void * vaddr)
|
|
|
|
{
|
2012-10-23 18:04:44 +00:00
|
|
|
return (phys_addr_t)(uintptr_t)(vaddr);
|
2008-12-13 23:20:27 +00:00
|
|
|
}
|
|
|
|
|
2012-10-10 13:12:53 +00:00
|
|
|
/*
|
|
|
|
* TODO: The kernel offers some more advanced versions of barriers, it might
|
|
|
|
* have some advantages to use them instead of the simple one here.
|
|
|
|
*/
|
|
|
|
#define dmb() __asm__ __volatile__ ("" : : : "memory")
|
|
|
|
#define __iormb() dmb()
|
|
|
|
#define __iowmb() dmb()
|
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
#endif
|