2012-03-05 19:49:29 +08:00
|
|
|
/*
|
|
|
|
* Based on arch/arm/include/asm/io.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996-2000 Russell King
|
|
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_IO_H
|
|
|
|
#define __ASM_IO_H
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
2013-10-25 18:33:26 +08:00
|
|
|
#include <linux/blk_types.h>
|
2012-03-05 19:49:29 +08:00
|
|
|
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#include <asm/barrier.h>
|
arm64: Fix overlapping VA allocations
PCI IO space was intended to be 16MiB, at 32MiB below MODULES_VADDR, but
commit d1e6dc91b532d3d3 ("arm64: Add architectural support for PCI")
extended this to cover the full 32MiB. The final 8KiB of this 32MiB is
also allocated for the fixmap, allowing for potential clashes between
the two.
This change was masked by assumptions in mem_init and the page table
dumping code, which assumed the I/O space to be 16MiB long through
seaparte hard-coded definitions.
This patch changes the definition of the PCI I/O space allocation to
live in asm/memory.h, along with the other VA space allocations. As the
fixmap allocation depends on the number of fixmap entries, this is moved
below the PCI I/O space allocation. Both the fixmap and PCI I/O space
are guarded with 2MB of padding. Sites assuming the I/O space was 16MiB
are moved over use new PCI_IO_{START,END} definitions, which will keep
in sync with the size of the IO space (now restored to 16MiB).
As a useful side effect, the use of the new PCI_IO_{START,END}
definitions prevents a build issue in the dumping code due to a (now
redundant) missing include of io.h for PCI_IOBASE.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Laura Abbott <lauraa@codeaurora.org>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Cc: Steve Capper <steve.capper@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
[catalin.marinas@arm.com: reorder FIXADDR and PCI_IO address_markers_idx enum]
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2015-01-23 02:20:35 +08:00
|
|
|
#include <asm/memory.h>
|
2012-03-05 19:49:29 +08:00
|
|
|
#include <asm/pgtable.h>
|
2014-04-08 06:39:52 +08:00
|
|
|
#include <asm/early_ioremap.h>
|
2014-11-14 23:54:11 +08:00
|
|
|
#include <asm/alternative.h>
|
|
|
|
#include <asm/cpufeature.h>
|
2012-03-05 19:49:29 +08:00
|
|
|
|
2013-10-25 18:33:26 +08:00
|
|
|
#include <xen/xen.h>
|
|
|
|
|
2012-03-05 19:49:29 +08:00
|
|
|
/*
|
|
|
|
* Generic IO read/write. These perform native-endian accesses.
|
|
|
|
*/
|
2014-07-28 23:25:48 +08:00
|
|
|
#define __raw_writeb __raw_writeb
|
2012-03-05 19:49:29 +08:00
|
|
|
static inline void __raw_writeb(u8 val, volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
asm volatile("strb %w0, [%1]" : : "r" (val), "r" (addr));
|
|
|
|
}
|
|
|
|
|
2014-07-28 23:25:48 +08:00
|
|
|
#define __raw_writew __raw_writew
|
2012-03-05 19:49:29 +08:00
|
|
|
static inline void __raw_writew(u16 val, volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
asm volatile("strh %w0, [%1]" : : "r" (val), "r" (addr));
|
|
|
|
}
|
|
|
|
|
2014-07-28 23:25:48 +08:00
|
|
|
#define __raw_writel __raw_writel
|
2012-03-05 19:49:29 +08:00
|
|
|
static inline void __raw_writel(u32 val, volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
asm volatile("str %w0, [%1]" : : "r" (val), "r" (addr));
|
|
|
|
}
|
|
|
|
|
2014-07-28 23:25:48 +08:00
|
|
|
#define __raw_writeq __raw_writeq
|
2012-03-05 19:49:29 +08:00
|
|
|
static inline void __raw_writeq(u64 val, volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
asm volatile("str %0, [%1]" : : "r" (val), "r" (addr));
|
|
|
|
}
|
|
|
|
|
2014-07-28 23:25:48 +08:00
|
|
|
#define __raw_readb __raw_readb
|
2012-03-05 19:49:29 +08:00
|
|
|
static inline u8 __raw_readb(const volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
u8 val;
|
2014-11-14 23:54:11 +08:00
|
|
|
asm volatile(ALTERNATIVE("ldrb %w0, [%1]",
|
|
|
|
"ldarb %w0, [%1]",
|
|
|
|
ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE)
|
|
|
|
: "=r" (val) : "r" (addr));
|
2012-03-05 19:49:29 +08:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2014-07-28 23:25:48 +08:00
|
|
|
#define __raw_readw __raw_readw
|
2012-03-05 19:49:29 +08:00
|
|
|
static inline u16 __raw_readw(const volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
u16 val;
|
2014-11-14 23:54:11 +08:00
|
|
|
|
|
|
|
asm volatile(ALTERNATIVE("ldrh %w0, [%1]",
|
|
|
|
"ldarh %w0, [%1]",
|
|
|
|
ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE)
|
|
|
|
: "=r" (val) : "r" (addr));
|
2012-03-05 19:49:29 +08:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2014-07-28 23:25:48 +08:00
|
|
|
#define __raw_readl __raw_readl
|
2012-03-05 19:49:29 +08:00
|
|
|
static inline u32 __raw_readl(const volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
u32 val;
|
2014-11-14 23:54:11 +08:00
|
|
|
asm volatile(ALTERNATIVE("ldr %w0, [%1]",
|
|
|
|
"ldar %w0, [%1]",
|
|
|
|
ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE)
|
|
|
|
: "=r" (val) : "r" (addr));
|
2012-03-05 19:49:29 +08:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2014-07-28 23:25:48 +08:00
|
|
|
#define __raw_readq __raw_readq
|
2012-03-05 19:49:29 +08:00
|
|
|
static inline u64 __raw_readq(const volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
u64 val;
|
2014-11-14 23:54:11 +08:00
|
|
|
asm volatile(ALTERNATIVE("ldr %0, [%1]",
|
|
|
|
"ldar %0, [%1]",
|
|
|
|
ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE)
|
|
|
|
: "=r" (val) : "r" (addr));
|
2012-03-05 19:49:29 +08:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IO barriers */
|
|
|
|
#define __iormb() rmb()
|
|
|
|
#define __iowmb() wmb()
|
|
|
|
|
|
|
|
#define mmiowb() do { } while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Relaxed I/O memory access primitives. These follow the Device memory
|
|
|
|
* ordering rules but do not guarantee any ordering relative to Normal memory
|
|
|
|
* accesses.
|
|
|
|
*/
|
|
|
|
#define readb_relaxed(c) ({ u8 __v = __raw_readb(c); __v; })
|
|
|
|
#define readw_relaxed(c) ({ u16 __v = le16_to_cpu((__force __le16)__raw_readw(c)); __v; })
|
|
|
|
#define readl_relaxed(c) ({ u32 __v = le32_to_cpu((__force __le32)__raw_readl(c)); __v; })
|
2013-04-19 19:24:37 +08:00
|
|
|
#define readq_relaxed(c) ({ u64 __v = le64_to_cpu((__force __le64)__raw_readq(c)); __v; })
|
2012-03-05 19:49:29 +08:00
|
|
|
|
|
|
|
#define writeb_relaxed(v,c) ((void)__raw_writeb((v),(c)))
|
|
|
|
#define writew_relaxed(v,c) ((void)__raw_writew((__force u16)cpu_to_le16(v),(c)))
|
|
|
|
#define writel_relaxed(v,c) ((void)__raw_writel((__force u32)cpu_to_le32(v),(c)))
|
2013-04-19 19:24:37 +08:00
|
|
|
#define writeq_relaxed(v,c) ((void)__raw_writeq((__force u64)cpu_to_le64(v),(c)))
|
2012-03-05 19:49:29 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* I/O memory access primitives. Reads are ordered relative to any
|
|
|
|
* following Normal memory access. Writes are ordered relative to any prior
|
|
|
|
* Normal memory access.
|
|
|
|
*/
|
|
|
|
#define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })
|
|
|
|
#define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
|
|
|
|
#define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
|
2013-04-19 19:24:37 +08:00
|
|
|
#define readq(c) ({ u64 __v = readq_relaxed(c); __iormb(); __v; })
|
2012-03-05 19:49:29 +08:00
|
|
|
|
|
|
|
#define writeb(v,c) ({ __iowmb(); writeb_relaxed((v),(c)); })
|
|
|
|
#define writew(v,c) ({ __iowmb(); writew_relaxed((v),(c)); })
|
|
|
|
#define writel(v,c) ({ __iowmb(); writel_relaxed((v),(c)); })
|
2013-04-19 19:24:37 +08:00
|
|
|
#define writeq(v,c) ({ __iowmb(); writeq_relaxed((v),(c)); })
|
2012-03-05 19:49:29 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* I/O port access primitives.
|
|
|
|
*/
|
2014-09-29 22:29:31 +08:00
|
|
|
#define arch_has_dev_port() (1)
|
arm64: Fix overlapping VA allocations
PCI IO space was intended to be 16MiB, at 32MiB below MODULES_VADDR, but
commit d1e6dc91b532d3d3 ("arm64: Add architectural support for PCI")
extended this to cover the full 32MiB. The final 8KiB of this 32MiB is
also allocated for the fixmap, allowing for potential clashes between
the two.
This change was masked by assumptions in mem_init and the page table
dumping code, which assumed the I/O space to be 16MiB long through
seaparte hard-coded definitions.
This patch changes the definition of the PCI I/O space allocation to
live in asm/memory.h, along with the other VA space allocations. As the
fixmap allocation depends on the number of fixmap entries, this is moved
below the PCI I/O space allocation. Both the fixmap and PCI I/O space
are guarded with 2MB of padding. Sites assuming the I/O space was 16MiB
are moved over use new PCI_IO_{START,END} definitions, which will keep
in sync with the size of the IO space (now restored to 16MiB).
As a useful side effect, the use of the new PCI_IO_{START,END}
definitions prevents a build issue in the dumping code due to a (now
redundant) missing include of io.h for PCI_IOBASE.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Laura Abbott <lauraa@codeaurora.org>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Cc: Steve Capper <steve.capper@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
[catalin.marinas@arm.com: reorder FIXADDR and PCI_IO address_markers_idx enum]
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2015-01-23 02:20:35 +08:00
|
|
|
#define IO_SPACE_LIMIT (PCI_IO_SIZE - 1)
|
|
|
|
#define PCI_IOBASE ((void __iomem *)PCI_IO_START)
|
2012-03-05 19:49:29 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* String version of I/O memory access operations.
|
|
|
|
*/
|
|
|
|
extern void __memcpy_fromio(void *, const volatile void __iomem *, size_t);
|
|
|
|
extern void __memcpy_toio(volatile void __iomem *, const void *, size_t);
|
|
|
|
extern void __memset_io(volatile void __iomem *, int, size_t);
|
|
|
|
|
|
|
|
#define memset_io(c,v,l) __memset_io((c),(v),(l))
|
|
|
|
#define memcpy_fromio(a,c,l) __memcpy_fromio((a),(c),(l))
|
|
|
|
#define memcpy_toio(c,a,l) __memcpy_toio((c),(a),(l))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I/O memory mapping functions.
|
|
|
|
*/
|
|
|
|
extern void __iomem *__ioremap(phys_addr_t phys_addr, size_t size, pgprot_t prot);
|
|
|
|
extern void __iounmap(volatile void __iomem *addr);
|
2013-10-24 22:54:17 +08:00
|
|
|
extern void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size);
|
2012-03-05 19:49:29 +08:00
|
|
|
|
2012-10-23 21:24:21 +08:00
|
|
|
#define ioremap(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
|
|
|
|
#define ioremap_nocache(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
|
|
|
|
#define ioremap_wc(addr, size) __ioremap((addr), (size), __pgprot(PROT_NORMAL_NC))
|
2012-03-05 19:49:29 +08:00
|
|
|
#define iounmap __iounmap
|
|
|
|
|
|
|
|
/*
|
2014-07-28 23:25:48 +08:00
|
|
|
* io{read,write}{16,32}be() macros
|
2012-03-05 19:49:29 +08:00
|
|
|
*/
|
2014-07-28 23:25:48 +08:00
|
|
|
#define ioread16be(p) ({ __u16 __v = be16_to_cpu((__force __be16)__raw_readw(p)); __iormb(); __v; })
|
|
|
|
#define ioread32be(p) ({ __u32 __v = be32_to_cpu((__force __be32)__raw_readl(p)); __iormb(); __v; })
|
2012-03-05 19:49:29 +08:00
|
|
|
|
2014-07-28 23:25:48 +08:00
|
|
|
#define iowrite16be(v,p) ({ __iowmb(); __raw_writew((__force __u16)cpu_to_be16(v), p); })
|
|
|
|
#define iowrite32be(v,p) ({ __iowmb(); __raw_writel((__force __u32)cpu_to_be32(v), p); })
|
2012-03-05 19:49:29 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a physical pointer to a virtual kernel pointer for /dev/mem
|
|
|
|
* access
|
|
|
|
*/
|
|
|
|
#define xlate_dev_mem_ptr(p) __va(p)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a virtual cached pointer to an uncached pointer
|
|
|
|
*/
|
|
|
|
#define xlate_dev_kmem_ptr(p) p
|
|
|
|
|
2014-07-28 23:25:48 +08:00
|
|
|
#include <asm-generic/io.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* More restrictive address range checking than the default implementation
|
|
|
|
* (PHYS_OFFSET and PHYS_MASK taken into account).
|
|
|
|
*/
|
|
|
|
#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
|
|
|
|
extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
|
|
|
|
extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
|
|
|
|
|
|
|
|
extern int devmem_is_allowed(unsigned long pfn);
|
|
|
|
|
2013-11-06 20:38:28 +08:00
|
|
|
struct bio_vec;
|
2013-10-25 18:33:26 +08:00
|
|
|
extern bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
|
|
|
|
const struct bio_vec *vec2);
|
|
|
|
#define BIOVEC_PHYS_MERGEABLE(vec1, vec2) \
|
|
|
|
(__BIOVEC_PHYS_MERGEABLE(vec1, vec2) && \
|
|
|
|
(!xen_domain() || xen_biovec_phys_mergeable(vec1, vec2)))
|
|
|
|
|
2012-03-05 19:49:29 +08:00
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
#endif /* __ASM_IO_H */
|