msm-4.14/lib/iomap.c
Runmin Wang 253c6dff4b Merge remote-tracking branch 'remotes/origin/tmp-39dae59' into msm-next
* remotes/msm-4.9/tmp-39dae59:
  Linux 4.14-rc8
  x86/module: Detect and skip invalid relocations
  objtool: Prevent GCC from merging annotate_unreachable(), take 2
  Revert "x86/mm: Stop calling leave_mm() in idle code"
  Documentation: Add Frank Rowand to list of enforcement statement endorsers
  doc: add Willy Tarreau to the list of enforcement statement endorsers
  tools/headers: Synchronize kernel ABI headers
  objtool: Resync objtool's instruction decoder source code copy with the kernel's latest version
  Input: sparse-keymap - send sync event for KE_SW/KE_VSW
  Input: ar1021_i2c - set INPUT_PROP_DIRECT
  arch/tile: Implement ->set_state_oneshot_stopped()
  Update MIPS email addresses
  x86: CPU: Fix up "cpu MHz" in /proc/cpuinfo
  mm, swap: fix race between swap count continuation operations
  mm/huge_memory.c: deposit page table when copying a PMD migration entry
  initramfs: fix initramfs rebuilds w/ compression after disabling
  fs/hugetlbfs/inode.c: fix hwpoison reserve accounting
  ocfs2: fstrim: Fix start offset of first cluster group during fstrim
  mm, /proc/pid/pagemap: fix soft dirty marking for PMD migration entry
  userfaultfd: hugetlbfs: prevent UFFDIO_COPY to fill beyond the end of i_size
  Documentation: Add Tim Bird to list of enforcement statement endorsers
  net: systemport: Correct IPG length settings
  tcp: do not mangle skb->cb[] in tcp_make_synack()
  fib: fib_dump_info can no longer use __in_dev_get_rtnl
  stmmac: use of_property_read_u32 instead of read_u8
  net_sched: hold netns refcnt for each action
  net_sched: acquire RTNL in tc_action_net_exit()
  powerpc/perf: Fix core-imc hotplug callback failure during imc initialization
  Kbuild: don't pass "-C" to preprocessor when processing linker scripts
  Revert "x86: do not use cpufreq_quick_get() for /proc/cpuinfo "cpu MHz""
  arm64: ensure __dump_instr() checks addr_limit
  KVM: x86: Update APICv on APIC reset
  KVM: VMX: Do not fully reset PI descriptor on vCPU reset
  kvm: Return -ENODEV from update_persistent_clock
  futex: futex_wake_op, do not fail on invalid op
  MIPS: Update email address for Marcin Nowakowski
  License cleanup: add SPDX license identifier to uapi header files with a license
  License cleanup: add SPDX license identifier to uapi header files with no license
  License cleanup: add SPDX GPL-2.0 license identifier to files with no license
  KEYS: fix out-of-bounds read during ASN.1 parsing
  KEYS: trusted: fix writing past end of buffer in trusted_read()
  KEYS: return full count in keyring_read() if buffer is too small
  net: vrf: correct FRA_L3MDEV encode type
  tcp_nv: fix division by zero in tcpnv_acked()
  drm/amdgpu: allow harvesting check for Polaris VCE
  drm/amdgpu: return -ENOENT from uvd 6.0 early init for harvesting
  ARM: add debug ".edata_real" symbol
  MIPS: smp-cmp: Fix vpe_id build error
  MAINTAINERS: Update Pistachio platform maintainers
  MIPS: smp-cmp: Use right include for task_struct
  signal: Fix name of SIGEMT in #if defined() check
  MIPS: Update Goldfish RTC driver maintainer email address
  MIPS: Update RINT emulation maintainer email address
  MIPS: CPS: Fix use of current_cpu_data in preemptible code
  x86/mcelog: Get rid of RCU remnants
  watchdog/hardlockup/perf: Use atomics to track in-use cpu counter
  watchdog/harclockup/perf: Revert a33d44843d45 ("watchdog/hardlockup/perf: Simplify deferred event destroy")
  ARM: 8716/1: pass endianness info to sparse
  drm/i915: Check incoming alignment for unfenced buffers (on i915gm)
  x86/mm: fix use-after-free of vma during userfaultfd fault
  ide:ide-cd: fix kernel panic resulting from missing scsi_req_init
  mmc: dw_mmc: Fix the DTO timeout calculation
  tcp: fix tcp_mtu_probe() vs highest_sack
  ipv6: addrconf: increment ifp refcount before ipv6_del_addr()
  tun/tap: sanitize TUNSETSNDBUF input
  mlxsw: i2c: Fix buffer increment counter for write transaction
  netfilter: nf_reject_ipv4: Fix use-after-free in send_reset
  futex: Fix more put_pi_state() vs. exit_pi_state_list() races
  powerpc/kprobes: Dereference function pointers only if the address does not belong to kernel text
  Revert "powerpc64/elfv1: Only dereference function descriptor for non-text symbols"
  mlxsw: reg: Add high and low temperature thresholds
  MAINTAINERS: Remove Yotam from mlxfw
  MAINTAINERS: Update Yotam's E-mail
  net: hns: set correct return value
  net: lapbether: fix double free
  bpf: remove SK_REDIRECT from UAPI
  net: phy: marvell: Only configure RGMII delays when using RGMII
  MIPS: SMP: Fix deadlock & online race
  MIPS: bpf: Fix a typo in build_one_insn()
  MIPS: microMIPS: Fix incorrect mask in insn_table_MM
  MIPS: Fix CM region target definitions
  MIPS: generic: Fix compilation error from include asm/mips-cpc.h
  MIPS: Fix exception entry when CONFIG_EVA enabled
  irqchip/irq-mvebu-gicp: Add missing spin_lock init
  drm/nouveau/kms/nv50: use the correct state for base channel notifier setup
  MIPS: generic: Fix NI 169445 its build
  Update MIPS email addresses
  tile: pass machine size to sparse
  selftests: lib.mk: print individual test results to console by default
  RDMA/nldev: Enforce device index check for port callback
  Revert "PM / QoS: Fix device resume latency PM QoS"
  Revert "PM / QoS: Fix default runtime_pm device resume latency"
  scsi: qla2xxx: Fix oops in qla2x00_probe_one error path
  xfrm: Fix GSO for IPsec with GRE tunnel.
  ALSA: seq: Fix nested rwsem annotation for lockdep splat
  ALSA: timer: Add missing mutex lock for compat ioctls
  tc-testing: fix arg to ip command: -s -> -n
  net_sched: remove tcf_block_put_deferred()
  l2tp: hold tunnel in pppol2tp_connect()
  drm/i915: Hold rcu_read_lock when iterating over the radixtree (vma idr)
  drm/i915: Hold rcu_read_lock when iterating over the radixtree (objects)
  drm/i915/edp: read edp display control registers unconditionally
  drm/i915: Do not rely on wm preservation for ILK watermarks
  drm/i915: Cancel the modeset retry work during modeset cleanup
  Mark 'ioremap_page_range()' as possibly sleeping
  nvme: Fix setting logical block format when revalidating
  mmc: dw_mmc: Add locking to the CTO timer
  mmc: dw_mmc: Fix the CTO timeout calculation
  mmc: dw_mmc: cancel the CTO timer after a voltage switch
  perf/cgroup: Fix perf cgroup hierarchy support
  PM / QoS: Fix default runtime_pm device resume latency
  Revert "ath10k: fix napi_poll budget overflow"
  ath10k: rebuild crypto header in rx data frames
  cifs: check MaxPathNameComponentLength != 0 before using it
  KVM: arm/arm64: vgic-its: Check GITS_BASER Valid bit before saving tables
  KVM: arm/arm64: vgic-its: Check CBASER/BASER validity before enabling the ITS
  KVM: arm/arm64: vgic-its: Fix vgic_its_restore_collection_table returned value
  KVM: arm/arm64: vgic-its: Fix return value for device table restore
  efi/libstub: arm: omit sorting of the UEFI memory map
  perf tools: Unwind properly location after REJECT
  virtio_blk: Fix an SG_IO regression
  wcn36xx: Remove unnecessary rcu_read_unlock in wcn36xx_bss_info_changed
  ARM: dts: mvebu: pl310-cache disable double-linefill
  xfrm: Clear sk_dst_cache when applying per-socket policy.
  perf symbols: Fix memory corruption because of zero length symbols
  powerpc/64s/radix: Fix preempt imbalance in TLB flush
  netfilter: nft_set_hash: disable fast_ops for 2-len keys
  powerpc: Fix check for copy/paste instructions in alignment handler
  powerpc/perf: Fix IMC allocation routine
  xfrm: Fix xfrm_dst_cache memleak
  ARM: 8715/1: add a private asm/unaligned.h
  clk: uniphier: fix clock data for PXs3
  Documentation: Add my name to kernel enforcement statement
  nvme-rdma: fix possible hang when issuing commands during ctrl removal
  arm/arm64: kvm: Disable branch profiling in HYP code
  arm/arm64: kvm: Move initialization completion message
  arm/arm64: KVM: set right LR register value for 32 bit guest when inject abort
  Documentation: kernel-enforcement-statement.rst: proper sort names
  ASoC: rt5616: fix 0x91 default value
  Documentation: Add Arm Ltd to kernel-enforcement-statement.rst
  arm64: dts: uniphier: add STDMAC clock to EHCI nodes
  ARM: dts: uniphier: add STDMAC clock to EHCI nodes
  mmc: renesas_sdhi: fix kernel panic in _internal_dmac.c
  mmc: tmio: fix swiotlb buffer is full
  Documentation: kernel-enforcement-statement.rst: Remove Red Hat markings
  Documentation: Add myself to the enforcement statement list
  Documentation: Sign kernel enforcement statement
  Add ack for Trond Myklebust to the enforcement statement
  Documentation: update kernel enforcement support list
  Documentation: add my name to supporters
  ASoC: rt5659: connect LOUT Amp with Charge Pump
  ASoC: rt5659: register power bit of LOUT Amp
  KVM: arm64: its: Fix missing dynamic allocation check in scan_its_table
  crypto: x86/chacha20 - satisfy stack validation 2.0
  ASoC: rt5663: Change the dev getting function in rt5663_irq
  ASoC: rt5514: Revert Hotword Model control
  ASoC: topology: Fix a potential memory leak in 'soc_tplg_dapm_widget_denum_create()'
  ASoC: topology: Fix a potential NULL pointer dereference in 'soc_tplg_dapm_widget_denum_create()'
  ASoC: rt5514-spi: check irq status to schedule data copy
  ASoC: adau17x1: Workaround for noise bug in ADC

  Conflicts:
	drivers/gpu/drm/msm/Makefile
	drivers/soc/qcom/Makefile
	drivers/staging/android/ion/Makefile
	include/linux/coresight-stm.h
	include/trace/events/kmem.h

Change-Id: I01f1779762b652b9213924caa3d54f29cf03d285
Signed-off-by: Runmin Wang <runminw@codeaurora.org>
2017-11-06 11:37:20 -08:00

265 lines
7.2 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Implement the default iomap interfaces
*
* (C) Copyright 2004 Linus Torvalds
*/
#include <linux/pci.h>
#include <linux/io.h>
#include <linux/msm_rtb.h>
#include <linux/export.h>
/*
* Read/write from/to an (offsettable) iomem cookie. It might be a PIO
* access or a MMIO access, these functions don't care. The info is
* encoded in the hardware mapping set up by the mapping functions
* (or the cookie itself, depending on implementation and hw).
*
* The generic routines don't assume any hardware mappings, and just
* encode the PIO/MMIO as part of the cookie. They coldly assume that
* the MMIO IO mappings are not in the low address range.
*
* Architectures for which this is not true can't use this generic
* implementation and should do their own copy.
*/
#ifndef HAVE_ARCH_PIO_SIZE
/*
* We encode the physical PIO addresses (0-0xffff) into the
* pointer by offsetting them with a constant (0x10000) and
* assuming that all the low addresses are always PIO. That means
* we can do some sanity checks on the low bits, and don't
* need to just take things for granted.
*/
#define PIO_OFFSET 0x10000UL
#define PIO_MASK 0x0ffffUL
#define PIO_RESERVED 0x40000UL
#endif
static void bad_io_access(unsigned long port, const char *access)
{
static int count = 10;
if (count) {
count--;
WARN(1, KERN_ERR "Bad IO access at port %#lx (%s)\n", port, access);
}
}
/*
* Ugly macros are a way of life.
*/
#define IO_COND(addr, is_pio, is_mmio) do { \
unsigned long port = (unsigned long __force)addr; \
if (port >= PIO_RESERVED) { \
is_mmio; \
} else if (port > PIO_OFFSET) { \
port &= PIO_MASK; \
is_pio; \
} else \
bad_io_access(port, #is_pio ); \
} while (0)
#ifndef pio_read16be
#define pio_read16be(port) swab16(inw(port))
#define pio_read32be(port) swab32(inl(port))
#endif
#ifndef mmio_read16be
#define mmio_read16be(addr) be16_to_cpu(__raw_readw(addr))
#define mmio_read32be(addr) be32_to_cpu(__raw_readl(addr))
#endif
unsigned int ioread8(void __iomem *addr)
{
uncached_logk_pc(LOGK_READL, __builtin_return_address(0), addr);
IO_COND(addr, return inb(port), return readb_no_log(addr));
return 0xff;
}
unsigned int ioread16(void __iomem *addr)
{
uncached_logk_pc(LOGK_READL, __builtin_return_address(0), addr);
IO_COND(addr, return inw(port), return readw_no_log(addr));
return 0xffff;
}
unsigned int ioread16be(void __iomem *addr)
{
uncached_logk_pc(LOGK_READL, __builtin_return_address(0), addr);
IO_COND(addr, return pio_read16be(port), return mmio_read16be(addr));
return 0xffff;
}
unsigned int ioread32(void __iomem *addr)
{
uncached_logk_pc(LOGK_READL, __builtin_return_address(0), addr);
IO_COND(addr, return inl(port), return readl_no_log(addr));
return 0xffffffff;
}
unsigned int ioread32be(void __iomem *addr)
{
uncached_logk_pc(LOGK_READL, __builtin_return_address(0), addr);
IO_COND(addr, return pio_read32be(port), return mmio_read32be(addr));
return 0xffffffff;
}
EXPORT_SYMBOL(ioread8);
EXPORT_SYMBOL(ioread16);
EXPORT_SYMBOL(ioread16be);
EXPORT_SYMBOL(ioread32);
EXPORT_SYMBOL(ioread32be);
#ifndef pio_write16be
#define pio_write16be(val,port) outw(swab16(val),port)
#define pio_write32be(val,port) outl(swab32(val),port)
#endif
#ifndef mmio_write16be
#define mmio_write16be(val,port) __raw_writew(be16_to_cpu(val),port)
#define mmio_write32be(val,port) __raw_writel(be32_to_cpu(val),port)
#endif
void iowrite8(u8 val, void __iomem *addr)
{
uncached_logk_pc(LOGK_WRITEL, __builtin_return_address(0), addr);
IO_COND(addr, outb(val, port), writeb_no_log(val, addr));
}
void iowrite16(u16 val, void __iomem *addr)
{
uncached_logk_pc(LOGK_WRITEL, __builtin_return_address(0), addr);
IO_COND(addr, outw(val, port), writew_no_log(val, addr));
}
void iowrite16be(u16 val, void __iomem *addr)
{
uncached_logk_pc(LOGK_WRITEL, __builtin_return_address(0), addr);
IO_COND(addr, pio_write16be(val,port), mmio_write16be(val, addr));
}
void iowrite32(u32 val, void __iomem *addr)
{
uncached_logk_pc(LOGK_WRITEL, __builtin_return_address(0), addr);
IO_COND(addr, outl(val, port), writel_no_log(val, addr));
}
void iowrite32be(u32 val, void __iomem *addr)
{
uncached_logk_pc(LOGK_WRITEL, __builtin_return_address(0), addr);
IO_COND(addr, pio_write32be(val,port), mmio_write32be(val, addr));
}
EXPORT_SYMBOL(iowrite8);
EXPORT_SYMBOL(iowrite16);
EXPORT_SYMBOL(iowrite16be);
EXPORT_SYMBOL(iowrite32);
EXPORT_SYMBOL(iowrite32be);
/*
* These are the "repeat MMIO read/write" functions.
* Note the "__raw" accesses, since we don't want to
* convert to CPU byte order. We write in "IO byte
* order" (we also don't have IO barriers).
*/
#ifndef mmio_insb
static inline void mmio_insb(void __iomem *addr, u8 *dst, int count)
{
while (--count >= 0) {
u8 data = __raw_readb(addr);
*dst = data;
dst++;
}
}
static inline void mmio_insw(void __iomem *addr, u16 *dst, int count)
{
while (--count >= 0) {
u16 data = __raw_readw(addr);
*dst = data;
dst++;
}
}
static inline void mmio_insl(void __iomem *addr, u32 *dst, int count)
{
while (--count >= 0) {
u32 data = __raw_readl(addr);
*dst = data;
dst++;
}
}
#endif
#ifndef mmio_outsb
static inline void mmio_outsb(void __iomem *addr, const u8 *src, int count)
{
while (--count >= 0) {
__raw_writeb(*src, addr);
src++;
}
}
static inline void mmio_outsw(void __iomem *addr, const u16 *src, int count)
{
while (--count >= 0) {
__raw_writew(*src, addr);
src++;
}
}
static inline void mmio_outsl(void __iomem *addr, const u32 *src, int count)
{
while (--count >= 0) {
__raw_writel(*src, addr);
src++;
}
}
#endif
void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
{
IO_COND(addr, insb(port,dst,count), mmio_insb(addr, dst, count));
}
void ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
{
IO_COND(addr, insw(port,dst,count), mmio_insw(addr, dst, count));
}
void ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
{
IO_COND(addr, insl(port,dst,count), mmio_insl(addr, dst, count));
}
EXPORT_SYMBOL(ioread8_rep);
EXPORT_SYMBOL(ioread16_rep);
EXPORT_SYMBOL(ioread32_rep);
void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
{
IO_COND(addr, outsb(port, src, count), mmio_outsb(addr, src, count));
}
void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
{
IO_COND(addr, outsw(port, src, count), mmio_outsw(addr, src, count));
}
void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
{
IO_COND(addr, outsl(port, src,count), mmio_outsl(addr, src, count));
}
EXPORT_SYMBOL(iowrite8_rep);
EXPORT_SYMBOL(iowrite16_rep);
EXPORT_SYMBOL(iowrite32_rep);
#ifdef CONFIG_HAS_IOPORT_MAP
/* Create a virtual mapping cookie for an IO port range */
void __iomem *ioport_map(unsigned long port, unsigned int nr)
{
if (port > PIO_MASK)
return NULL;
return (void __iomem *) (unsigned long) (port + PIO_OFFSET);
}
void ioport_unmap(void __iomem *addr)
{
/* Nothing to do */
}
EXPORT_SYMBOL(ioport_map);
EXPORT_SYMBOL(ioport_unmap);
#endif /* CONFIG_HAS_IOPORT_MAP */
#ifdef CONFIG_PCI
/* Hide the details if this is a MMIO or PIO address space and just do what
* you expect in the correct way. */
void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
{
IO_COND(addr, /* nothing */, iounmap(addr));
}
EXPORT_SYMBOL(pci_iounmap);
#endif /* CONFIG_PCI */