Path: blob/master/arch/arm/mach-ixp4xx/include/mach/io.h
17687 views
/*1* arch/arm/mach-ixp4xx/include/mach/io.h2*3* Author: Deepak Saxena <[email protected]>4*5* Copyright (C) 2002-2005 MontaVista Software, Inc.6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License version 2 as9* published by the Free Software Foundation.10*/1112#ifndef __ASM_ARM_ARCH_IO_H13#define __ASM_ARM_ARCH_IO_H1415#include <linux/bitops.h>1617#include <mach/hardware.h>1819#define IO_SPACE_LIMIT 0x0000ffff2021extern int (*ixp4xx_pci_read)(u32 addr, u32 cmd, u32* data);22extern int ixp4xx_pci_write(u32 addr, u32 cmd, u32 data);232425/*26* IXP4xx provides two methods of accessing PCI memory space:27*28* 1) A direct mapped window from 0x48000000 to 0x4BFFFFFF (64MB).29* To access PCI via this space, we simply ioremap() the BAR30* into the kernel and we can use the standard read[bwl]/write[bwl]31* macros. This is the preffered method due to speed but it32* limits the system to just 64MB of PCI memory. This can be33* problematic if using video cards and other memory-heavy targets.34*35* 2) If > 64MB of memory space is required, the IXP4xx can use indirect36* registers to access the whole 4 GB of PCI memory space (as we do below37* for I/O transactions). This allows currently for up to 1 GB (0x1000000038* to 0x4FFFFFFF) of memory on the bus. The disadvantage of this is that39* every PCI access requires three local register accesses plus a spinlock,40* but in some cases the performance hit is acceptable. In addition, you41* cannot mmap() PCI devices in this case.42*/43#ifndef CONFIG_IXP4XX_INDIRECT_PCI4445#define __mem_pci(a) (a)4647#else4849/*50* In the case of using indirect PCI, we simply return the actual PCI51* address and our read/write implementation use that to drive the52* access registers. If something outside of PCI is ioremap'd, we53* fallback to the default.54*/5556static inline int is_pci_memory(u32 addr)57{58return (addr >= PCIBIOS_MIN_MEM) && (addr <= 0x4FFFFFFF);59}6061static inline void __iomem * __indirect_ioremap(unsigned long addr, size_t size,62unsigned int mtype)63{64if (!is_pci_memory(addr))65return __arm_ioremap(addr, size, mtype);6667return (void __iomem *)addr;68}6970static inline void __indirect_iounmap(void __iomem *addr)71{72if (!is_pci_memory((__force u32)addr))73__iounmap(addr);74}7576#define __arch_ioremap __indirect_ioremap77#define __arch_iounmap __indirect_iounmap7879#define writeb(v, p) __indirect_writeb(v, p)80#define writew(v, p) __indirect_writew(v, p)81#define writel(v, p) __indirect_writel(v, p)8283#define writesb(p, v, l) __indirect_writesb(p, v, l)84#define writesw(p, v, l) __indirect_writesw(p, v, l)85#define writesl(p, v, l) __indirect_writesl(p, v, l)8687#define readb(p) __indirect_readb(p)88#define readw(p) __indirect_readw(p)89#define readl(p) __indirect_readl(p)9091#define readsb(p, v, l) __indirect_readsb(p, v, l)92#define readsw(p, v, l) __indirect_readsw(p, v, l)93#define readsl(p, v, l) __indirect_readsl(p, v, l)9495static inline void __indirect_writeb(u8 value, volatile void __iomem *p)96{97u32 addr = (u32)p;98u32 n, byte_enables, data;99100if (!is_pci_memory(addr)) {101__raw_writeb(value, addr);102return;103}104105n = addr % 4;106byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL;107data = value << (8*n);108ixp4xx_pci_write(addr, byte_enables | NP_CMD_MEMWRITE, data);109}110111static inline void __indirect_writesb(volatile void __iomem *bus_addr,112const u8 *vaddr, int count)113{114while (count--)115writeb(*vaddr++, bus_addr);116}117118static inline void __indirect_writew(u16 value, volatile void __iomem *p)119{120u32 addr = (u32)p;121u32 n, byte_enables, data;122123if (!is_pci_memory(addr)) {124__raw_writew(value, addr);125return;126}127128n = addr % 4;129byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL;130data = value << (8*n);131ixp4xx_pci_write(addr, byte_enables | NP_CMD_MEMWRITE, data);132}133134static inline void __indirect_writesw(volatile void __iomem *bus_addr,135const u16 *vaddr, int count)136{137while (count--)138writew(*vaddr++, bus_addr);139}140141static inline void __indirect_writel(u32 value, volatile void __iomem *p)142{143u32 addr = (__force u32)p;144145if (!is_pci_memory(addr)) {146__raw_writel(value, p);147return;148}149150ixp4xx_pci_write(addr, NP_CMD_MEMWRITE, value);151}152153static inline void __indirect_writesl(volatile void __iomem *bus_addr,154const u32 *vaddr, int count)155{156while (count--)157writel(*vaddr++, bus_addr);158}159160static inline unsigned char __indirect_readb(const volatile void __iomem *p)161{162u32 addr = (u32)p;163u32 n, byte_enables, data;164165if (!is_pci_memory(addr))166return __raw_readb(addr);167168n = addr % 4;169byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL;170if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_MEMREAD, &data))171return 0xff;172173return data >> (8*n);174}175176static inline void __indirect_readsb(const volatile void __iomem *bus_addr,177u8 *vaddr, u32 count)178{179while (count--)180*vaddr++ = readb(bus_addr);181}182183static inline unsigned short __indirect_readw(const volatile void __iomem *p)184{185u32 addr = (u32)p;186u32 n, byte_enables, data;187188if (!is_pci_memory(addr))189return __raw_readw(addr);190191n = addr % 4;192byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL;193if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_MEMREAD, &data))194return 0xffff;195196return data>>(8*n);197}198199static inline void __indirect_readsw(const volatile void __iomem *bus_addr,200u16 *vaddr, u32 count)201{202while (count--)203*vaddr++ = readw(bus_addr);204}205206static inline unsigned long __indirect_readl(const volatile void __iomem *p)207{208u32 addr = (__force u32)p;209u32 data;210211if (!is_pci_memory(addr))212return __raw_readl(p);213214if (ixp4xx_pci_read(addr, NP_CMD_MEMREAD, &data))215return 0xffffffff;216217return data;218}219220static inline void __indirect_readsl(const volatile void __iomem *bus_addr,221u32 *vaddr, u32 count)222{223while (count--)224*vaddr++ = readl(bus_addr);225}226227228/*229* We can use the built-in functions b/c they end up calling writeb/readb230*/231#define memset_io(c,v,l) _memset_io((c),(v),(l))232#define memcpy_fromio(a,c,l) _memcpy_fromio((a),(c),(l))233#define memcpy_toio(c,a,l) _memcpy_toio((c),(a),(l))234235#endif /* CONFIG_IXP4XX_INDIRECT_PCI */236237#ifndef CONFIG_PCI238239#define __io(v) __typesafe_io(v)240241#else242243/*244* IXP4xx does not have a transparent cpu -> PCI I/O translation245* window. Instead, it has a set of registers that must be tweaked246* with the proper byte lanes, command types, and address for the247* transaction. This means that we need to override the default248* I/O functions.249*/250251static inline void outb(u8 value, u32 addr)252{253u32 n, byte_enables, data;254n = addr % 4;255byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL;256data = value << (8*n);257ixp4xx_pci_write(addr, byte_enables | NP_CMD_IOWRITE, data);258}259260static inline void outsb(u32 io_addr, const u8 *vaddr, u32 count)261{262while (count--)263outb(*vaddr++, io_addr);264}265266static inline void outw(u16 value, u32 addr)267{268u32 n, byte_enables, data;269n = addr % 4;270byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL;271data = value << (8*n);272ixp4xx_pci_write(addr, byte_enables | NP_CMD_IOWRITE, data);273}274275static inline void outsw(u32 io_addr, const u16 *vaddr, u32 count)276{277while (count--)278outw(cpu_to_le16(*vaddr++), io_addr);279}280281static inline void outl(u32 value, u32 addr)282{283ixp4xx_pci_write(addr, NP_CMD_IOWRITE, value);284}285286static inline void outsl(u32 io_addr, const u32 *vaddr, u32 count)287{288while (count--)289outl(cpu_to_le32(*vaddr++), io_addr);290}291292static inline u8 inb(u32 addr)293{294u32 n, byte_enables, data;295n = addr % 4;296byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL;297if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_IOREAD, &data))298return 0xff;299300return data >> (8*n);301}302303static inline void insb(u32 io_addr, u8 *vaddr, u32 count)304{305while (count--)306*vaddr++ = inb(io_addr);307}308309static inline u16 inw(u32 addr)310{311u32 n, byte_enables, data;312n = addr % 4;313byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL;314if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_IOREAD, &data))315return 0xffff;316317return data>>(8*n);318}319320static inline void insw(u32 io_addr, u16 *vaddr, u32 count)321{322while (count--)323*vaddr++ = le16_to_cpu(inw(io_addr));324}325326static inline u32 inl(u32 addr)327{328u32 data;329if (ixp4xx_pci_read(addr, NP_CMD_IOREAD, &data))330return 0xffffffff;331332return data;333}334335static inline void insl(u32 io_addr, u32 *vaddr, u32 count)336{337while (count--)338*vaddr++ = le32_to_cpu(inl(io_addr));339}340341#define PIO_OFFSET 0x10000UL342#define PIO_MASK 0x0ffffUL343344#define __is_io_address(p) (((unsigned long)p >= PIO_OFFSET) && \345((unsigned long)p <= (PIO_MASK + PIO_OFFSET)))346347#define ioread8(p) ioread8(p)348static inline unsigned int ioread8(const void __iomem *addr)349{350unsigned long port = (unsigned long __force)addr;351if (__is_io_address(port))352return (unsigned int)inb(port & PIO_MASK);353else354#ifndef CONFIG_IXP4XX_INDIRECT_PCI355return (unsigned int)__raw_readb(addr);356#else357return (unsigned int)__indirect_readb(addr);358#endif359}360361#define ioread8_rep(p, v, c) ioread8_rep(p, v, c)362static inline void ioread8_rep(const void __iomem *addr, void *vaddr, u32 count)363{364unsigned long port = (unsigned long __force)addr;365if (__is_io_address(port))366insb(port & PIO_MASK, vaddr, count);367else368#ifndef CONFIG_IXP4XX_INDIRECT_PCI369__raw_readsb(addr, vaddr, count);370#else371__indirect_readsb(addr, vaddr, count);372#endif373}374375#define ioread16(p) ioread16(p)376static inline unsigned int ioread16(const void __iomem *addr)377{378unsigned long port = (unsigned long __force)addr;379if (__is_io_address(port))380return (unsigned int)inw(port & PIO_MASK);381else382#ifndef CONFIG_IXP4XX_INDIRECT_PCI383return le16_to_cpu((__force __le16)__raw_readw(addr));384#else385return (unsigned int)__indirect_readw(addr);386#endif387}388389#define ioread16_rep(p, v, c) ioread16_rep(p, v, c)390static inline void ioread16_rep(const void __iomem *addr, void *vaddr,391u32 count)392{393unsigned long port = (unsigned long __force)addr;394if (__is_io_address(port))395insw(port & PIO_MASK, vaddr, count);396else397#ifndef CONFIG_IXP4XX_INDIRECT_PCI398__raw_readsw(addr, vaddr, count);399#else400__indirect_readsw(addr, vaddr, count);401#endif402}403404#define ioread32(p) ioread32(p)405static inline unsigned int ioread32(const void __iomem *addr)406{407unsigned long port = (unsigned long __force)addr;408if (__is_io_address(port))409return (unsigned int)inl(port & PIO_MASK);410else {411#ifndef CONFIG_IXP4XX_INDIRECT_PCI412return le32_to_cpu((__force __le32)__raw_readl(addr));413#else414return (unsigned int)__indirect_readl(addr);415#endif416}417}418419#define ioread32_rep(p, v, c) ioread32_rep(p, v, c)420static inline void ioread32_rep(const void __iomem *addr, void *vaddr,421u32 count)422{423unsigned long port = (unsigned long __force)addr;424if (__is_io_address(port))425insl(port & PIO_MASK, vaddr, count);426else427#ifndef CONFIG_IXP4XX_INDIRECT_PCI428__raw_readsl(addr, vaddr, count);429#else430__indirect_readsl(addr, vaddr, count);431#endif432}433434#define iowrite8(v, p) iowrite8(v, p)435static inline void iowrite8(u8 value, void __iomem *addr)436{437unsigned long port = (unsigned long __force)addr;438if (__is_io_address(port))439outb(value, port & PIO_MASK);440else441#ifndef CONFIG_IXP4XX_INDIRECT_PCI442__raw_writeb(value, addr);443#else444__indirect_writeb(value, addr);445#endif446}447448#define iowrite8_rep(p, v, c) iowrite8_rep(p, v, c)449static inline void iowrite8_rep(void __iomem *addr, const void *vaddr,450u32 count)451{452unsigned long port = (unsigned long __force)addr;453if (__is_io_address(port))454outsb(port & PIO_MASK, vaddr, count);455else456#ifndef CONFIG_IXP4XX_INDIRECT_PCI457__raw_writesb(addr, vaddr, count);458#else459__indirect_writesb(addr, vaddr, count);460#endif461}462463#define iowrite16(v, p) iowrite16(v, p)464static inline void iowrite16(u16 value, void __iomem *addr)465{466unsigned long port = (unsigned long __force)addr;467if (__is_io_address(port))468outw(value, port & PIO_MASK);469else470#ifndef CONFIG_IXP4XX_INDIRECT_PCI471__raw_writew(cpu_to_le16(value), addr);472#else473__indirect_writew(value, addr);474#endif475}476477#define iowrite16_rep(p, v, c) iowrite16_rep(p, v, c)478static inline void iowrite16_rep(void __iomem *addr, const void *vaddr,479u32 count)480{481unsigned long port = (unsigned long __force)addr;482if (__is_io_address(port))483outsw(port & PIO_MASK, vaddr, count);484else485#ifndef CONFIG_IXP4XX_INDIRECT_PCI486__raw_writesw(addr, vaddr, count);487#else488__indirect_writesw(addr, vaddr, count);489#endif490}491492#define iowrite32(v, p) iowrite32(v, p)493static inline void iowrite32(u32 value, void __iomem *addr)494{495unsigned long port = (unsigned long __force)addr;496if (__is_io_address(port))497outl(value, port & PIO_MASK);498else499#ifndef CONFIG_IXP4XX_INDIRECT_PCI500__raw_writel((u32 __force)cpu_to_le32(value), addr);501#else502__indirect_writel(value, addr);503#endif504}505506#define iowrite32_rep(p, v, c) iowrite32_rep(p, v, c)507static inline void iowrite32_rep(void __iomem *addr, const void *vaddr,508u32 count)509{510unsigned long port = (unsigned long __force)addr;511if (__is_io_address(port))512outsl(port & PIO_MASK, vaddr, count);513else514#ifndef CONFIG_IXP4XX_INDIRECT_PCI515__raw_writesl(addr, vaddr, count);516#else517__indirect_writesl(addr, vaddr, count);518#endif519}520521#define ioport_map(port, nr) ((void __iomem*)(port + PIO_OFFSET))522#define ioport_unmap(addr)523#endif /* CONFIG_PCI */524525#endif /* __ASM_ARM_ARCH_IO_H */526527528