2009-05-13 22:56:35 +00:00
|
|
|
/* Generic I/O port emulation, based on MN10300 code
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
|
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public Licence
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the Licence, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_GENERIC_IO_H
|
|
|
|
#define __ASM_GENERIC_IO_H
|
|
|
|
|
|
|
|
#include <asm/page.h> /* I/O is all done through memory accesses */
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_GENERIC_IOMAP
|
|
|
|
#include <asm-generic/iomap.h>
|
|
|
|
#endif
|
|
|
|
|
2011-11-24 18:45:20 +00:00
|
|
|
#include <asm-generic/pci_iomap.h>
|
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef mmiowb
|
2009-05-13 22:56:35 +00:00
|
|
|
#define mmiowb() do {} while (0)
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* readX/writeX() are used to access memory mapped devices. On some
|
|
|
|
* architectures the memory mapped IO stuff needs to be accessed
|
|
|
|
* differently. On the simple architectures, we just read/write the
|
|
|
|
* memory location directly.
|
|
|
|
*/
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef __raw_readb
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline u8 __raw_readb(const volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
return *(const volatile u8 __force *) addr;
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef __raw_readw
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline u16 __raw_readw(const volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
return *(const volatile u16 __force *) addr;
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef __raw_readl
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline u32 __raw_readl(const volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
return *(const volatile u32 __force *) addr;
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
|
|
|
#define readb __raw_readb
|
2013-01-07 13:17:23 +00:00
|
|
|
|
|
|
|
#define readw readw
|
|
|
|
static inline u16 readw(const volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
return __le16_to_cpu(__raw_readw(addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define readl readl
|
|
|
|
static inline u32 readl(const volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
return __le32_to_cpu(__raw_readl(addr));
|
|
|
|
}
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef __raw_writeb
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
*(volatile u8 __force *) addr = b;
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef __raw_writew
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void __raw_writew(u16 b, volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
*(volatile u16 __force *) addr = b;
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef __raw_writel
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void __raw_writel(u32 b, volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
*(volatile u32 __force *) addr = b;
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
|
|
|
#define writeb __raw_writeb
|
|
|
|
#define writew(b,addr) __raw_writew(__cpu_to_le16(b),addr)
|
|
|
|
#define writel(b,addr) __raw_writel(__cpu_to_le32(b),addr)
|
|
|
|
|
|
|
|
#ifdef CONFIG_64BIT
|
2012-11-29 11:50:30 +00:00
|
|
|
#ifndef __raw_readq
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline u64 __raw_readq(const volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
return *(const volatile u64 __force *) addr;
|
|
|
|
}
|
2012-11-29 11:50:30 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-07 13:17:23 +00:00
|
|
|
#define readq readq
|
|
|
|
static inline u64 readq(const volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
return __le64_to_cpu(__raw_readq(addr));
|
|
|
|
}
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2012-11-29 11:50:30 +00:00
|
|
|
#ifndef __raw_writeq
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void __raw_writeq(u64 b, volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
*(volatile u64 __force *) addr = b;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-29 11:50:30 +00:00
|
|
|
#define writeq(b, addr) __raw_writeq(__cpu_to_le64(b), addr)
|
|
|
|
#endif /* CONFIG_64BIT */
|
|
|
|
|
2011-02-22 11:06:43 +00:00
|
|
|
#ifndef PCI_IOBASE
|
|
|
|
#define PCI_IOBASE ((void __iomem *) 0)
|
|
|
|
#endif
|
|
|
|
|
2009-05-13 22:56:35 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* traditional input/output functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline u8 inb(unsigned long addr)
|
|
|
|
{
|
2011-02-22 11:06:43 +00:00
|
|
|
return readb(addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline u16 inw(unsigned long addr)
|
|
|
|
{
|
2011-02-22 11:06:43 +00:00
|
|
|
return readw(addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 inl(unsigned long addr)
|
|
|
|
{
|
2011-02-22 11:06:43 +00:00
|
|
|
return readl(addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void outb(u8 b, unsigned long addr)
|
|
|
|
{
|
2011-02-22 11:06:43 +00:00
|
|
|
writeb(b, addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void outw(u16 b, unsigned long addr)
|
|
|
|
{
|
2011-02-22 11:06:43 +00:00
|
|
|
writew(b, addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void outl(u32 b, unsigned long addr)
|
|
|
|
{
|
2011-02-22 11:06:43 +00:00
|
|
|
writel(b, addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define inb_p(addr) inb(addr)
|
|
|
|
#define inw_p(addr) inw(addr)
|
|
|
|
#define inl_p(addr) inl(addr)
|
|
|
|
#define outb_p(x, addr) outb((x), (addr))
|
|
|
|
#define outw_p(x, addr) outw((x), (addr))
|
|
|
|
#define outl_p(x, addr) outl((x), (addr))
|
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef insb
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void insb(unsigned long addr, void *buffer, int count)
|
|
|
|
{
|
|
|
|
if (count) {
|
|
|
|
u8 *buf = buffer;
|
|
|
|
do {
|
2012-12-17 23:59:42 +00:00
|
|
|
u8 x = __raw_readb(addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
*buf++ = x;
|
|
|
|
} while (--count);
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef insw
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void insw(unsigned long addr, void *buffer, int count)
|
|
|
|
{
|
|
|
|
if (count) {
|
|
|
|
u16 *buf = buffer;
|
|
|
|
do {
|
2012-12-17 23:59:42 +00:00
|
|
|
u16 x = __raw_readw(addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
*buf++ = x;
|
|
|
|
} while (--count);
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef insl
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void insl(unsigned long addr, void *buffer, int count)
|
|
|
|
{
|
|
|
|
if (count) {
|
|
|
|
u32 *buf = buffer;
|
|
|
|
do {
|
2012-12-17 23:59:42 +00:00
|
|
|
u32 x = __raw_readl(addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
*buf++ = x;
|
|
|
|
} while (--count);
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef outsb
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void outsb(unsigned long addr, const void *buffer, int count)
|
|
|
|
{
|
|
|
|
if (count) {
|
|
|
|
const u8 *buf = buffer;
|
|
|
|
do {
|
2012-12-17 23:59:42 +00:00
|
|
|
__raw_writeb(*buf++, addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
} while (--count);
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef outsw
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void outsw(unsigned long addr, const void *buffer, int count)
|
|
|
|
{
|
|
|
|
if (count) {
|
|
|
|
const u16 *buf = buffer;
|
|
|
|
do {
|
2012-12-17 23:59:42 +00:00
|
|
|
__raw_writew(*buf++, addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
} while (--count);
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2010-10-18 07:09:39 +00:00
|
|
|
#ifndef outsl
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void outsl(unsigned long addr, const void *buffer, int count)
|
|
|
|
{
|
|
|
|
if (count) {
|
|
|
|
const u32 *buf = buffer;
|
|
|
|
do {
|
2012-12-17 23:59:42 +00:00
|
|
|
__raw_writel(*buf++, addr + PCI_IOBASE);
|
2009-05-13 22:56:35 +00:00
|
|
|
} while (--count);
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 07:09:39 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
|
|
|
#ifndef CONFIG_GENERIC_IOMAP
|
|
|
|
#define ioread8(addr) readb(addr)
|
|
|
|
#define ioread16(addr) readw(addr)
|
2013-02-07 13:58:35 +00:00
|
|
|
#define ioread16be(addr) __be16_to_cpu(__raw_readw(addr))
|
2009-05-13 22:56:35 +00:00
|
|
|
#define ioread32(addr) readl(addr)
|
2013-02-07 13:58:35 +00:00
|
|
|
#define ioread32be(addr) __be32_to_cpu(__raw_readl(addr))
|
2009-05-13 22:56:35 +00:00
|
|
|
|
|
|
|
#define iowrite8(v, addr) writeb((v), (addr))
|
|
|
|
#define iowrite16(v, addr) writew((v), (addr))
|
2013-02-07 13:58:35 +00:00
|
|
|
#define iowrite16be(v, addr) __raw_writew(__cpu_to_be16(v), addr)
|
2009-05-13 22:56:35 +00:00
|
|
|
#define iowrite32(v, addr) writel((v), (addr))
|
2013-02-07 13:58:35 +00:00
|
|
|
#define iowrite32be(v, addr) __raw_writel(__cpu_to_be32(v), addr)
|
2009-05-13 22:56:35 +00:00
|
|
|
|
|
|
|
#define ioread8_rep(p, dst, count) \
|
|
|
|
insb((unsigned long) (p), (dst), (count))
|
|
|
|
#define ioread16_rep(p, dst, count) \
|
|
|
|
insw((unsigned long) (p), (dst), (count))
|
|
|
|
#define ioread32_rep(p, dst, count) \
|
|
|
|
insl((unsigned long) (p), (dst), (count))
|
|
|
|
|
|
|
|
#define iowrite8_rep(p, src, count) \
|
|
|
|
outsb((unsigned long) (p), (src), (count))
|
|
|
|
#define iowrite16_rep(p, src, count) \
|
|
|
|
outsw((unsigned long) (p), (src), (count))
|
|
|
|
#define iowrite32_rep(p, src, count) \
|
|
|
|
outsl((unsigned long) (p), (src), (count))
|
|
|
|
#endif /* CONFIG_GENERIC_IOMAP */
|
|
|
|
|
2011-02-22 11:06:43 +00:00
|
|
|
#ifndef IO_SPACE_LIMIT
|
|
|
|
#define IO_SPACE_LIMIT 0xffff
|
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#define __io_virt(x) ((void __force *) (x))
|
|
|
|
|
|
|
|
#ifndef CONFIG_GENERIC_IOMAP
|
|
|
|
struct pci_dev;
|
2012-11-29 11:50:30 +00:00
|
|
|
extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
|
|
|
|
|
|
|
|
#ifndef pci_iounmap
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
|
|
|
|
{
|
|
|
|
}
|
2012-11-29 11:50:30 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
#endif /* CONFIG_GENERIC_IOMAP */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change virtual addresses to physical addresses and vv.
|
|
|
|
* These are pretty trivial
|
|
|
|
*/
|
2012-11-29 11:50:30 +00:00
|
|
|
#ifndef virt_to_phys
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline unsigned long virt_to_phys(volatile void *address)
|
|
|
|
{
|
|
|
|
return __pa((unsigned long)address);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *phys_to_virt(unsigned long address)
|
|
|
|
{
|
|
|
|
return __va(address);
|
|
|
|
}
|
2012-11-29 11:50:30 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Change "struct page" to physical address.
|
2011-07-02 15:17:35 +00:00
|
|
|
*
|
|
|
|
* This implementation is for the no-MMU case only... if you have an MMU
|
|
|
|
* you'll need to provide your own definitions.
|
2009-05-13 22:56:35 +00:00
|
|
|
*/
|
2011-07-02 15:17:35 +00:00
|
|
|
#ifndef CONFIG_MMU
|
2009-05-13 22:56:35 +00:00
|
|
|
static inline void __iomem *ioremap(phys_addr_t offset, unsigned long size)
|
|
|
|
{
|
|
|
|
return (void __iomem*) (unsigned long)offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define __ioremap(offset, size, flags) ioremap(offset, size)
|
|
|
|
|
|
|
|
#ifndef ioremap_nocache
|
|
|
|
#define ioremap_nocache ioremap
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ioremap_wc
|
|
|
|
#define ioremap_wc ioremap_nocache
|
|
|
|
#endif
|
|
|
|
|
2011-10-04 13:25:56 +00:00
|
|
|
static inline void iounmap(void __iomem *addr)
|
2009-05-13 22:56:35 +00:00
|
|
|
{
|
|
|
|
}
|
2011-07-02 15:17:35 +00:00
|
|
|
#endif /* CONFIG_MMU */
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2014-04-07 22:39:19 +00:00
|
|
|
#ifdef CONFIG_HAS_IOPORT_MAP
|
2009-05-13 22:56:35 +00:00
|
|
|
#ifndef CONFIG_GENERIC_IOMAP
|
|
|
|
static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
|
|
|
|
{
|
|
|
|
return (void __iomem *) port;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void ioport_unmap(void __iomem *p)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#else /* CONFIG_GENERIC_IOMAP */
|
|
|
|
extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
|
|
|
|
extern void ioport_unmap(void __iomem *p);
|
|
|
|
#endif /* CONFIG_GENERIC_IOMAP */
|
2014-04-07 22:39:19 +00:00
|
|
|
#endif /* CONFIG_HAS_IOPORT_MAP */
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2013-05-21 14:08:22 +00:00
|
|
|
#ifndef xlate_dev_kmem_ptr
|
2009-05-13 22:56:35 +00:00
|
|
|
#define xlate_dev_kmem_ptr(p) p
|
2013-05-21 14:08:22 +00:00
|
|
|
#endif
|
|
|
|
#ifndef xlate_dev_mem_ptr
|
2011-07-02 15:17:35 +00:00
|
|
|
#define xlate_dev_mem_ptr(p) __va(p)
|
2013-05-21 14:08:22 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2012-11-23 16:13:05 +00:00
|
|
|
#ifdef CONFIG_VIRT_TO_BUS
|
2009-05-13 22:56:35 +00:00
|
|
|
#ifndef virt_to_bus
|
|
|
|
static inline unsigned long virt_to_bus(volatile void *address)
|
|
|
|
{
|
|
|
|
return ((unsigned long) address);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *bus_to_virt(unsigned long address)
|
|
|
|
{
|
|
|
|
return (void *) address;
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-23 16:13:05 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
2012-11-29 11:50:30 +00:00
|
|
|
#ifndef memset_io
|
2009-05-13 22:56:35 +00:00
|
|
|
#define memset_io(a, b, c) memset(__io_virt(a), (b), (c))
|
2012-11-29 11:50:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef memcpy_fromio
|
2009-05-13 22:56:35 +00:00
|
|
|
#define memcpy_fromio(a, b, c) memcpy((a), __io_virt(b), (c))
|
2012-11-29 11:50:30 +00:00
|
|
|
#endif
|
|
|
|
#ifndef memcpy_toio
|
2009-05-13 22:56:35 +00:00
|
|
|
#define memcpy_toio(a, b, c) memcpy(__io_virt(a), (b), (c))
|
2012-11-29 11:50:30 +00:00
|
|
|
#endif
|
2009-05-13 22:56:35 +00:00
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
#endif /* __ASM_GENERIC_IO_H */
|