Commit 4cb3cee0 authored by Benjamin Herrenschmidt's avatar Benjamin Herrenschmidt Committed by Paul Mackerras

[POWERPC] Allow hooking of PCI MMIO & PIO accessors on 64 bits

This patch reworks the way iSeries hooks on PCI IO operations (both MMIO
and PIO) and provides a generic way for other platforms to do so (we
have need to do that for various other platforms).

While reworking the IO ops, I ended up doing some spring cleaning in
io.h and eeh.h which I might want to split into 2 or 3 patches (among
others, eeh.h had a lot of useless stuff in it).

A side effect is that EEH for PIO should work now (it used to pass IO
ports down to the eeh address check functions which is bogus).

Also, new are MMIO "repeat" ops, which other archs like ARM already had,
and that we have too now: readsb, readsw, readsl, writesb, writesw,
writesl.

In the long run, I might also make EEH use the hooks instead
of wrapping at the toplevel, which would make things even cleaner and
relegate EEH completely in platforms/iseries, but we have to measure the
performance impact there (though it's really only on MMIO reads)

Since I also need to hook on ioremap, I shuffled the functions a bit
there. I introduced ioremap_flags() to use by drivers who want to pass
explicit flags to ioremap (and it can be hooked). The old __ioremap() is
still there as a low level and cannot be hooked, thus drivers who use it
should migrate unless they know they want the low level version.

The patch "arch provides generic iomap missing accessors" (should be
number 4 in this series) is a pre-requisite to provide full iomap
API support with this patch.
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent d03f387e
......@@ -394,6 +394,7 @@ config PPC_PSERIES
config PPC_ISERIES
bool "IBM Legacy iSeries"
depends on PPC_MULTIPLATFORM && PPC64
select PPC_INDIRECT_IO
config PPC_CHRP
bool "Common Hardware Reference Platform (CHRP) based machines"
......@@ -548,6 +549,15 @@ config PPC_970_NAP
bool
default n
config PPC_INDIRECT_IO
bool
select GENERIC_IOMAP
default n
config GENERIC_IOMAP
bool
default n
source "drivers/cpufreq/Kconfig"
config CPU_FREQ_PMAC
......
......@@ -62,7 +62,7 @@ obj-$(CONFIG_PPC_UDBG_16550) += legacy_serial.o udbg_16550.o
module-$(CONFIG_PPC64) += module_64.o
obj-$(CONFIG_MODULES) += $(module-y)
pci64-$(CONFIG_PPC64) += pci_64.o pci_dn.o iomap.o
pci64-$(CONFIG_PPC64) += pci_64.o pci_dn.o
pci32-$(CONFIG_PPC32) := pci_32.o
obj-$(CONFIG_PCI) += $(pci64-y) $(pci32-y)
kexec-$(CONFIG_PPC64) := machine_kexec_64.o
......@@ -71,6 +71,10 @@ obj-$(CONFIG_KEXEC) += machine_kexec.o crash.o $(kexec-y)
obj-$(CONFIG_AUDIT) += audit.o
obj64-$(CONFIG_AUDIT) += compat_audit.o
ifneq ($(CONFIG_PPC_INDIRECT_IO),y)
pci64-$(CONFIG_PPC64) += iomap.o
endif
ifeq ($(CONFIG_PPC_ISERIES),y)
$(obj)/head_64.o: $(obj)/lparmap.s
AFLAGS_head_64.o += -I$(obj)
......
......@@ -25,13 +25,11 @@
#include <asm/firmware.h>
#include <asm/bug.h>
void _insb(volatile u8 __iomem *port, void *buf, long count)
void _insb(const volatile u8 __iomem *port, void *buf, long count)
{
u8 *tbuf = buf;
u8 tmp;
BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
if (unlikely(count <= 0))
return;
asm volatile("sync");
......@@ -48,8 +46,6 @@ void _outsb(volatile u8 __iomem *port, const void *buf, long count)
{
const u8 *tbuf = buf;
BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
if (unlikely(count <= 0))
return;
asm volatile("sync");
......@@ -60,13 +56,11 @@ void _outsb(volatile u8 __iomem *port, const void *buf, long count)
}
EXPORT_SYMBOL(_outsb);
void _insw_ns(volatile u16 __iomem *port, void *buf, long count)
void _insw_ns(const volatile u16 __iomem *port, void *buf, long count)
{
u16 *tbuf = buf;
u16 tmp;
BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
if (unlikely(count <= 0))
return;
asm volatile("sync");
......@@ -83,8 +77,6 @@ void _outsw_ns(volatile u16 __iomem *port, const void *buf, long count)
{
const u16 *tbuf = buf;
BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
if (unlikely(count <= 0))
return;
asm volatile("sync");
......@@ -95,13 +87,11 @@ void _outsw_ns(volatile u16 __iomem *port, const void *buf, long count)
}
EXPORT_SYMBOL(_outsw_ns);
void _insl_ns(volatile u32 __iomem *port, void *buf, long count)
void _insl_ns(const volatile u32 __iomem *port, void *buf, long count)
{
u32 *tbuf = buf;
u32 tmp;
BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
if (unlikely(count <= 0))
return;
asm volatile("sync");
......@@ -118,8 +108,6 @@ void _outsl_ns(volatile u32 __iomem *port, const void *buf, long count)
{
const u32 *tbuf = buf;
BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
if (unlikely(count <= 0))
return;
asm volatile("sync");
......
......@@ -1137,7 +1137,7 @@ int unmap_bus_range(struct pci_bus *bus)
if (get_bus_io_range(bus, &start_phys, &start_virt, &size))
return 1;
if (iounmap_explicit((void __iomem *) start_virt, size))
if (__iounmap_explicit((void __iomem *) start_virt, size))
return 1;
return 0;
......
......@@ -599,3 +599,10 @@ void __init setup_per_cpu_areas(void)
}
}
#endif
#ifdef CONFIG_PPC_INDIRECT_IO
struct ppc_pci_io ppc_pci_io;
EXPORT_SYMBOL(ppc_pci_io);
#endif /* CONFIG_PPC_INDIRECT_IO */
......@@ -129,22 +129,12 @@ static void __iomem * __ioremap_com(unsigned long addr, unsigned long pa,
return (void __iomem *) (ea + (addr & ~PAGE_MASK));
}
void __iomem *
ioremap(unsigned long addr, unsigned long size)
{
return __ioremap(addr, size, _PAGE_NO_CACHE | _PAGE_GUARDED);
}
void __iomem * __ioremap(unsigned long addr, unsigned long size,
unsigned long flags)
{
unsigned long pa, ea;
void __iomem *ret;
if (firmware_has_feature(FW_FEATURE_ISERIES))
return (void __iomem *)addr;
/*
* Choose an address to map it to.
* Once the imalloc system is running, we use it.
......@@ -178,6 +168,25 @@ void __iomem * __ioremap(unsigned long addr, unsigned long size,
return ret;
}
void __iomem * ioremap(unsigned long addr, unsigned long size)
{
unsigned long flags = _PAGE_NO_CACHE | _PAGE_GUARDED;
if (ppc_md.ioremap)
return ppc_md.ioremap(addr, size, flags);
return __ioremap(addr, size, flags);
}
void __iomem * ioremap_flags(unsigned long addr, unsigned long size,
unsigned long flags)
{
if (ppc_md.ioremap)
return ppc_md.ioremap(addr, size, flags);
return __ioremap(addr, size, flags);
}
#define IS_PAGE_ALIGNED(_val) ((_val) == ((_val) & PAGE_MASK))
int __ioremap_explicit(unsigned long pa, unsigned long ea,
......@@ -235,13 +244,10 @@ int __ioremap_explicit(unsigned long pa, unsigned long ea,
*
* XXX what about calls before mem_init_done (ie python_countermeasures())
*/
void iounmap(volatile void __iomem *token)
void __iounmap(void __iomem *token)
{
void *addr;
if (firmware_has_feature(FW_FEATURE_ISERIES))
return;
if (!mem_init_done)
return;
......@@ -250,6 +256,14 @@ void iounmap(volatile void __iomem *token)
im_free(addr);
}
void iounmap(void __iomem *token)
{
if (ppc_md.iounmap)
ppc_md.iounmap(token);
else
__iounmap(token);
}
static int iounmap_subset_regions(unsigned long addr, unsigned long size)
{
struct vm_struct *area;
......@@ -268,7 +282,7 @@ static int iounmap_subset_regions(unsigned long addr, unsigned long size)
return 0;
}
int iounmap_explicit(volatile void __iomem *start, unsigned long size)
int __iounmap_explicit(void __iomem *start, unsigned long size)
{
struct vm_struct *area;
unsigned long addr;
......@@ -303,8 +317,10 @@ int iounmap_explicit(volatile void __iomem *start, unsigned long size)
}
EXPORT_SYMBOL(ioremap);
EXPORT_SYMBOL(ioremap_flags);
EXPORT_SYMBOL(__ioremap);
EXPORT_SYMBOL(iounmap);
EXPORT_SYMBOL(__iounmap);
void __iomem * reserve_phb_iospace(unsigned long size)
{
......
This diff is collapsed.
......@@ -617,6 +617,16 @@ static void iseries_dedicated_idle(void)
void __init iSeries_init_IRQ(void) { }
#endif
static void __iomem *iseries_ioremap(unsigned long address, unsigned long size,
unsigned long flags)
{
return (void __iomem *)address;
}
static void iseries_iounmap(void __iomem *token)
{
}
/*
* iSeries has no legacy IO, anything calling this function has to
* fail or bad things will happen
......@@ -655,6 +665,8 @@ define_machine(iseries) {
.progress = iSeries_progress,
.probe = iseries_probe,
.check_legacy_ioport = iseries_check_legacy_ioport,
.ioremap = iseries_ioremap,
.iounmap = iseries_iounmap,
/* XXX Implement enable_pmcs for iSeries */
};
......
......@@ -120,10 +120,6 @@ static inline u8 eeh_readb(const volatile void __iomem *addr)
return eeh_check_failure(addr, val);
return val;
}
static inline void eeh_writeb(u8 val, volatile void __iomem *addr)
{
out_8(addr, val);
}
static inline u16 eeh_readw(const volatile void __iomem *addr)
{
......@@ -132,21 +128,6 @@ static inline u16 eeh_readw(const volatile void __iomem *addr)
return eeh_check_failure(addr, val);
return val;
}
static inline void eeh_writew(u16 val, volatile void __iomem *addr)
{
out_le16(addr, val);
}
static inline u16 eeh_raw_readw(const volatile void __iomem *addr)
{
u16 val = in_be16(addr);
if (EEH_POSSIBLE_ERROR(val, u16))
return eeh_check_failure(addr, val);
return val;
}
static inline void eeh_raw_writew(u16 val, volatile void __iomem *addr) {
volatile u16 __iomem *vaddr = (volatile u16 __iomem *) addr;
out_be16(vaddr, val);
}
static inline u32 eeh_readl(const volatile void __iomem *addr)
{
......@@ -155,44 +136,38 @@ static inline u32 eeh_readl(const volatile void __iomem *addr)
return eeh_check_failure(addr, val);
return val;
}
static inline void eeh_writel(u32 val, volatile void __iomem *addr)
{
out_le32(addr, val);
}
static inline u32 eeh_raw_readl(const volatile void __iomem *addr)
static inline u64 eeh_readq(const volatile void __iomem *addr)
{
u32 val = in_be32(addr);
if (EEH_POSSIBLE_ERROR(val, u32))
u64 val = in_le64(addr);
if (EEH_POSSIBLE_ERROR(val, u64))
return eeh_check_failure(addr, val);
return val;
}
static inline void eeh_raw_writel(u32 val, volatile void __iomem *addr)
{
out_be32(addr, val);
}
static inline u64 eeh_readq(const volatile void __iomem *addr)
static inline u16 eeh_readw_be(const volatile void __iomem *addr)
{
u64 val = in_le64(addr);
if (EEH_POSSIBLE_ERROR(val, u64))
u16 val = in_be16(addr);
if (EEH_POSSIBLE_ERROR(val, u16))
return eeh_check_failure(addr, val);
return val;
}
static inline void eeh_writeq(u64 val, volatile void __iomem *addr)
static inline u32 eeh_readl_be(const volatile void __iomem *addr)
{
out_le64(addr, val);
u32 val = in_be32(addr);
if (EEH_POSSIBLE_ERROR(val, u32))
return eeh_check_failure(addr, val);
return val;
}
static inline u64 eeh_raw_readq(const volatile void __iomem *addr)
static inline u64 eeh_readq_be(const volatile void __iomem *addr)
{
u64 val = in_be64(addr);
if (EEH_POSSIBLE_ERROR(val, u64))
return eeh_check_failure(addr, val);
return val;
}
static inline void eeh_raw_writeq(u64 val, volatile void __iomem *addr)
{
out_be64(addr, val);
}
#define EEH_CHECK_ALIGN(v,a) \
((((unsigned long)(v)) & ((a) - 1)) == 0)
......@@ -292,68 +267,29 @@ static inline void eeh_memcpy_toio(volatile void __iomem *dest, const void *src,
#undef EEH_CHECK_ALIGN
static inline u8 eeh_inb(unsigned long port)
{
u8 val;
val = in_8((u8 __iomem *)(port+pci_io_base));
if (EEH_POSSIBLE_ERROR(val, u8))
return eeh_check_failure((void __iomem *)(port), val);
return val;
}
static inline void eeh_outb(u8 val, unsigned long port)
{
out_8((u8 __iomem *)(port+pci_io_base), val);
}
static inline u16 eeh_inw(unsigned long port)
{
u16 val;
val = in_le16((u16 __iomem *)(port+pci_io_base));
if (EEH_POSSIBLE_ERROR(val, u16))
return eeh_check_failure((void __iomem *)(port), val);
return val;
}
static inline void eeh_outw(u16 val, unsigned long port)
{
out_le16((u16 __iomem *)(port+pci_io_base), val);
}
static inline u32 eeh_inl(unsigned long port)
{
u32 val;
val = in_le32((u32 __iomem *)(port+pci_io_base));
if (EEH_POSSIBLE_ERROR(val, u32))
return eeh_check_failure((void __iomem *)(port), val);
return val;
}
static inline void eeh_outl(u32 val, unsigned long port)
{
out_le32((u32 __iomem *)(port+pci_io_base), val);
}
/* in-string eeh macros */
static inline void eeh_insb(unsigned long port, void * buf, int ns)
static inline void eeh_readsb(const volatile void __iomem *addr, void * buf,
int ns)
{
_insb((u8 __iomem *)(port+pci_io_base), buf, ns);
_insb(addr, buf, ns);
if (EEH_POSSIBLE_ERROR((*(((u8*)buf)+ns-1)), u8))
eeh_check_failure((void __iomem *)(port), *(u8*)buf);
eeh_check_failure(addr, *(u8*)buf);
}
static inline void eeh_insw_ns(unsigned long port, void * buf, int ns)
static inline void eeh_readsw(const volatile void __iomem *addr, void * buf,
int ns)
{
_insw_ns((u16 __iomem *)(port+pci_io_base), buf, ns);
_insw(addr, buf, ns);
if (EEH_POSSIBLE_ERROR((*(((u16*)buf)+ns-1)), u16))
eeh_check_failure((void __iomem *)(port), *(u16*)buf);
eeh_check_failure(addr, *(u16*)buf);
}
static inline void eeh_insl_ns(unsigned long port, void * buf, int nl)
static inline void eeh_readsl(const volatile void __iomem *addr, void * buf,
int nl)
{
_insl_ns((u32 __iomem *)(port+pci_io_base), buf, nl);
_insl(addr, buf, nl);
if (EEH_POSSIBLE_ERROR((*(((u32*)buf)+nl-1)), u32))
eeh_check_failure((void __iomem *)(port), *(u32*)buf);
eeh_check_failure(addr, *(u32*)buf);
}
#endif /* __KERNEL__ */
......
......@@ -22,10 +22,17 @@
#endif
#endif
#ifdef __powerpc64__
#define __ide_mm_insw(p, a, c) readsw((void __iomem *)(p), (a), (c))
#define __ide_mm_insl(p, a, c) readsl((void __iomem *)(p), (a), (c))
#define __ide_mm_outsw(p, a, c) writesw((void __iomem *)(p), (a), (c))
#define __ide_mm_outsl(p, a, c) writesl((void __iomem *)(p), (a), (c))
#else
#define __ide_mm_insw(p, a, c) _insw_ns((volatile u16 __iomem *)(p), (a), (c))
#define __ide_mm_insl(p, a, c) _insl_ns((volatile u32 __iomem *)(p), (a), (c))
#define __ide_mm_outsw(p, a, c) _outsw_ns((volatile u16 __iomem *)(p), (a), (c))
#define __ide_mm_outsl(p, a, c) _outsl_ns((volatile u32 __iomem *)(p), (a), (c))
#endif
#ifndef __powerpc64__
#include <linux/hdreg.h>
......
/* This file is meant to be include multiple times by other headers */
DEF_PCI_AC_RET(readb, u8, (const PCI_IO_ADDR addr), (addr))
DEF_PCI_AC_RET(readw, u16, (const PCI_IO_ADDR addr), (addr))
DEF_PCI_AC_RET(readl, u32, (const PCI_IO_ADDR addr), (addr))
DEF_PCI_AC_RET(readq, u64, (const PCI_IO_ADDR addr), (addr))
DEF_PCI_AC_RET(readw_be, u16, (const PCI_IO_ADDR addr), (addr))
DEF_PCI_AC_RET(readl_be, u32, (const PCI_IO_ADDR addr), (addr))
DEF_PCI_AC_RET(readq_be, u64, (const PCI_IO_ADDR addr), (addr))
DEF_PCI_AC_NORET(writeb, (u8 val, PCI_IO_ADDR addr), (val, addr))
DEF_PCI_AC_NORET(writew, (u16 val, PCI_IO_ADDR addr), (val, addr))
DEF_PCI_AC_NORET(writel, (u32 val, PCI_IO_ADDR addr), (val, addr))
DEF_PCI_AC_NORET(writeq, (u64 val, PCI_IO_ADDR addr), (val, addr))
DEF_PCI_AC_NORET(writew_be, (u16 val, PCI_IO_ADDR addr), (val, addr))
DEF_PCI_AC_NORET(writel_be, (u32 val, PCI_IO_ADDR addr), (val, addr))
DEF_PCI_AC_NORET(writeq_be, (u64 val, PCI_IO_ADDR addr), (val, addr))
DEF_PCI_AC_RET(inb, u8, (unsigned long port), (port))
DEF_PCI_AC_RET(inw, u16, (unsigned long port), (port))
DEF_PCI_AC_RET(inl, u32, (unsigned long port), (port))
DEF_PCI_AC_NORET(outb, (u8 val, unsigned long port), (val, port))
DEF_PCI_AC_NORET(outw, (u16 val, unsigned long port), (val, port))
DEF_PCI_AC_NORET(outl, (u32 val, unsigned long port), (val, port))
DEF_PCI_AC_NORET(readsb, (const PCI_IO_ADDR a, void *b, unsigned long c), \
(a, b, c))
DEF_PCI_AC_NORET(readsw, (const PCI_IO_ADDR a, void *b, unsigned long c), \
(a, b, c))
DEF_PCI_AC_NORET(readsl, (const PCI_IO_ADDR a, void *b, unsigned long c), \
(a, b, c))
DEF_PCI_AC_NORET(writesb, (PCI_IO_ADDR a, const void *b, unsigned long c), \
(a, b, c))
DEF_PCI_AC_NORET(writesw, (PCI_IO_ADDR a, const void *b, unsigned long c), \
(a, b, c))
DEF_PCI_AC_NORET(writesl, (PCI_IO_ADDR a, const void *b, unsigned long c), \
(a, b, c))
DEF_PCI_AC_NORET(insb, (unsigned long p, void *b, unsigned long c), \
(p, b, c))
DEF_PCI_AC_NORET(insw, (unsigned long p, void *b, unsigned long c), \
(p, b, c))
DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c), \
(p, b, c))
DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c), \
(p, b, c))
DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c), \
(p, b, c))
DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c), \
(p, b, c))
DEF_PCI_AC_NORET(memset_io, (PCI_IO_ADDR a, int c, unsigned long n), \
(a, c, n))
DEF_PCI_AC_NORET(memcpy_fromio,(void *d,const PCI_IO_ADDR s,unsigned long n), \
(d, s, n))
DEF_PCI_AC_NORET(memcpy_toio,(PCI_IO_ADDR d,const void *s,unsigned long n), \
(d, s, n))
This diff is collapsed.
......@@ -87,6 +87,10 @@ struct machdep_calls {
void (*tce_flush)(struct iommu_table *tbl);
void (*pci_dma_dev_setup)(struct pci_dev *dev);
void (*pci_dma_bus_setup)(struct pci_bus *bus);
void __iomem * (*ioremap)(unsigned long addr, unsigned long size,
unsigned long flags);
void (*iounmap)(void __iomem *token);
#endif /* CONFIG_PPC64 */
int (*probe)(void);
......
......@@ -321,12 +321,12 @@ __do_out_asm(outl, "stwbrx")
#define inl_p(port) inl((port))
#define outl_p(val, port) outl((val), (port))
extern void _insb(volatile u8 __iomem *port, void *buf, long count);
extern void _outsb(volatile u8 __iomem *port, const void *buf, long count);
extern void _insw_ns(volatile u16 __iomem *port, void *buf, long count);
extern void _outsw_ns(volatile u16 __iomem *port, const void *buf, long count);
extern void _insl_ns(volatile u32 __iomem *port, void *buf, long count);
extern void _outsl_ns(volatile u32 __iomem *port, const void *buf, long count);
extern void _insb(const volatile u8 __iomem *addr, void *buf, long count);
extern void _outsb(volatile u8 __iomem *addr,const void *buf,long count);
extern void _insw_ns(const volatile u16 __iomem *addr, void *buf, long count);
extern void _outsw_ns(volatile u16 __iomem *addr, const void *buf, long count);
extern void _insl_ns(const volatile u32 __iomem *addr, void *buf, long count);
extern void _outsl_ns(volatile u32 __iomem *addr, const void *buf, long count);
#define IO_SPACE_LIMIT ~0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment