io.h 5.94 KB
Newer Older
Hirokazu Takata's avatar
Hirokazu Takata committed
1 2 3
#ifndef _ASM_M32R_IO_H
#define _ASM_M32R_IO_H

4 5
#include <linux/string.h>
#include <linux/compiler.h>
Hirokazu Takata's avatar
Hirokazu Takata committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <asm/page.h>  /* __va */

#ifdef __KERNEL__

#define IO_SPACE_LIMIT  0xFFFFFFFF

/**
 *	virt_to_phys	-	map virtual addresses to physical
 *	@address: address to remap
 *
 *	The returned physical address is the physical (CPU) mapping for
 *	the memory address given. It is only valid to use this function on
 *	addresses directly mapped or allocated via kmalloc.
 *
 *	This function does not give bus mappings for DMA transfers. In
 *	almost all conceivable cases a device driver should not be using
 *	this function
 */

25
static inline unsigned long virt_to_phys(volatile void * address)
Hirokazu Takata's avatar
Hirokazu Takata committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
{
	return __pa(address);
}

/**
 *	phys_to_virt	-	map physical address to virtual
 *	@address: address to remap
 *
 *	The returned virtual address is a current CPU mapping for
 *	the memory address given. It is only valid to use this function on
 *	addresses that have a kernel mapping
 *
 *	This function does not handle bus mappings for DMA transfers. In
 *	almost all conceivable cases a device driver should not be using
 *	this function
 */

43
static inline void *phys_to_virt(unsigned long address)
Hirokazu Takata's avatar
Hirokazu Takata committed
44 45 46 47
{
	return __va(address);
}

48 49
extern void __iomem *
__ioremap(unsigned long offset, unsigned long size, unsigned long flags);
Hirokazu Takata's avatar
Hirokazu Takata committed
50 51 52 53 54 55 56 57 58 59 60 61 62

/**
 *	ioremap		-	map bus memory into CPU space
 *	@offset:	bus address of the memory
 *	@size:		size of the resource to map
 *
 *	ioremap performs a platform specific sequence of operations to
 *	make bus memory CPU accessible via the readb/readw/readl/writeb/
 *	writew/writel functions and the other mmio helpers. The returned
 *	address is not guaranteed to be usable directly as a virtual
 *	address.
 */

63
static inline void * ioremap(unsigned long offset, unsigned long size)
Hirokazu Takata's avatar
Hirokazu Takata committed
64 65 66 67
{
	return __ioremap(offset, size, 0);
}

68
extern void iounmap(volatile void __iomem *addr);
Hirokazu Takata's avatar
Hirokazu Takata committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#define ioremap_nocache(off,size) ioremap(off,size)

/*
 * IO bus memory addresses are also 1:1 with the physical address
 */
#define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
#define page_to_bus	page_to_phys
#define virt_to_bus	virt_to_phys

extern unsigned char _inb(unsigned long);
extern unsigned short _inw(unsigned long);
extern unsigned long _inl(unsigned long);
extern unsigned char _inb_p(unsigned long);
extern unsigned short _inw_p(unsigned long);
extern unsigned long _inl_p(unsigned long);
extern void _outb(unsigned char, unsigned long);
extern void _outw(unsigned short, unsigned long);
extern void _outl(unsigned long, unsigned long);
extern void _outb_p(unsigned char, unsigned long);
extern void _outw_p(unsigned short, unsigned long);
extern void _outl_p(unsigned long, unsigned long);
extern void _insb(unsigned int, void *, unsigned long);
extern void _insw(unsigned int, void *, unsigned long);
extern void _insl(unsigned int, void *, unsigned long);
extern void _outsb(unsigned int, const void *, unsigned long);
extern void _outsw(unsigned int, const void *, unsigned long);
extern void _outsl(unsigned int, const void *, unsigned long);

static inline unsigned char _readb(unsigned long addr)
{
99
	return *(volatile unsigned char __force *)addr;
Hirokazu Takata's avatar
Hirokazu Takata committed
100 101 102 103
}

static inline unsigned short _readw(unsigned long addr)
{
104
	return *(volatile unsigned short __force *)addr;
Hirokazu Takata's avatar
Hirokazu Takata committed
105 106 107 108
}

static inline unsigned long _readl(unsigned long addr)
{
109
	return *(volatile unsigned long __force *)addr;
Hirokazu Takata's avatar
Hirokazu Takata committed
110 111 112 113
}

static inline void _writeb(unsigned char b, unsigned long addr)
{
114
	*(volatile unsigned char __force *)addr = b;
Hirokazu Takata's avatar
Hirokazu Takata committed
115 116 117 118
}

static inline void _writew(unsigned short w, unsigned long addr)
{
119
	*(volatile unsigned short __force *)addr = w;
Hirokazu Takata's avatar
Hirokazu Takata committed
120 121 122 123
}

static inline void _writel(unsigned long l, unsigned long addr)
{
124
	*(volatile unsigned long __force *)addr = l;
Hirokazu Takata's avatar
Hirokazu Takata committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
}

#define inb     _inb
#define inw     _inw
#define inl     _inl
#define outb    _outb
#define outw    _outw
#define outl    _outl

#define inb_p   _inb_p
#define inw_p   _inw_p
#define inl_p   _inl_p
#define outb_p  _outb_p
#define outw_p  _outw_p
#define outl_p  _outl_p

#define insb    _insb
#define insw    _insw
#define insl    _insl
#define outsb   _outsb
#define outsw   _outsw
#define outsl   _outsl

#define readb(addr)   _readb((unsigned long)(addr))
#define readw(addr)   _readw((unsigned long)(addr))
#define readl(addr)   _readl((unsigned long)(addr))
#define __raw_readb readb
#define __raw_readw readw
#define __raw_readl readl
154 155 156
#define readb_relaxed readb
#define readw_relaxed readw
#define readl_relaxed readl
Hirokazu Takata's avatar
Hirokazu Takata committed
157 158 159 160 161 162 163 164

#define writeb(val, addr)  _writeb((val), (unsigned long)(addr))
#define writew(val, addr)  _writew((val), (unsigned long)(addr))
#define writel(val, addr)  _writel((val), (unsigned long)(addr))
#define __raw_writeb writeb
#define __raw_writew writew
#define __raw_writel writel

165 166
#define mmiowb()

Hirokazu Takata's avatar
Hirokazu Takata committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
#define flush_write_buffers() do { } while (0)  /* M32R_FIXME */

/**
 *	isa_check_signature		-	find BIOS signatures
 *	@io_addr: mmio address to check
 *	@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.
 */

static inline int isa_check_signature(unsigned long io_addr,
        const unsigned char *signature, int length)
{
        int retval = 0;
#if 0
printk("isa_check_signature\n");
        do {
                if (isa_readb(io_addr) != *signature)
                        goto out;
                io_addr++;
                signature++;
                length--;
        } while (length);
        retval = 1;
out:
#endif
        return retval;
}

201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
static inline void
memset_io(volatile void __iomem *addr, unsigned char val, int count)
{
	memset((void __force *) addr, val, count);
}

static inline void
memcpy_fromio(void *dst, volatile void __iomem *src, int count)
{
	memcpy(dst, (void __force *) src, count);
}

static inline void
memcpy_toio(volatile void __iomem *dst, const void *src, int count)
{
	memcpy((void __force *) dst, src, count);
}
Hirokazu Takata's avatar
Hirokazu Takata committed
218 219 220 221

#endif  /* __KERNEL__ */

#endif  /* _ASM_M32R_IO_H */