xref: /kernel/linux/linux-5.10/arch/x86/include/asm/io.h (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_IO_H
38c2ecf20Sopenharmony_ci#define _ASM_X86_IO_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * This file contains the definitions for the x86 IO instructions
78c2ecf20Sopenharmony_ci * inb/inw/inl/outb/outw/outl and the "string versions" of the same
88c2ecf20Sopenharmony_ci * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
98c2ecf20Sopenharmony_ci * versions of the single-IO instructions (inb_p/inw_p/..).
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * This file is not meant to be obfuscating: it's just complicated
128c2ecf20Sopenharmony_ci * to (a) handle it all in a way that makes gcc able to optimize it
138c2ecf20Sopenharmony_ci * as well as possible and (b) trying to avoid writing the same thing
148c2ecf20Sopenharmony_ci * over and over again with slight variations and possibly making a
158c2ecf20Sopenharmony_ci * mistake somewhere.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/*
198c2ecf20Sopenharmony_ci * Thanks to James van Artsdalen for a better timing-fix than
208c2ecf20Sopenharmony_ci * the two short jumps: using outb's to a nonexistent port seems
218c2ecf20Sopenharmony_ci * to guarantee better timings even on fast machines.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * On the other hand, I'd like to be sure of a non-existent port:
248c2ecf20Sopenharmony_ci * I feel a bit unsafe about using 0x80 (should be safe, though)
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci *		Linus
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci /*
308c2ecf20Sopenharmony_ci  *  Bit simplified and optimized by Jan Hubicka
318c2ecf20Sopenharmony_ci  *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
328c2ecf20Sopenharmony_ci  *
338c2ecf20Sopenharmony_ci  *  isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added,
348c2ecf20Sopenharmony_ci  *  isa_read[wl] and isa_write[wl] fixed
358c2ecf20Sopenharmony_ci  *  - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
368c2ecf20Sopenharmony_ci  */
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define ARCH_HAS_IOREMAP_WC
398c2ecf20Sopenharmony_ci#define ARCH_HAS_IOREMAP_WT
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#include <linux/string.h>
428c2ecf20Sopenharmony_ci#include <linux/compiler.h>
438c2ecf20Sopenharmony_ci#include <asm/page.h>
448c2ecf20Sopenharmony_ci#include <asm/early_ioremap.h>
458c2ecf20Sopenharmony_ci#include <asm/pgtable_types.h>
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define build_mmio_read(name, size, type, reg, barrier) \
488c2ecf20Sopenharmony_cistatic inline type name(const volatile void __iomem *addr) \
498c2ecf20Sopenharmony_ci{ type ret; asm volatile("mov" size " %1,%0":reg (ret) \
508c2ecf20Sopenharmony_ci:"m" (*(volatile type __force *)addr) barrier); return ret; }
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define build_mmio_write(name, size, type, reg, barrier) \
538c2ecf20Sopenharmony_cistatic inline void name(type val, volatile void __iomem *addr) \
548c2ecf20Sopenharmony_ci{ asm volatile("mov" size " %0,%1": :reg (val), \
558c2ecf20Sopenharmony_ci"m" (*(volatile type __force *)addr) barrier); }
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cibuild_mmio_read(readb, "b", unsigned char, "=q", :"memory")
588c2ecf20Sopenharmony_cibuild_mmio_read(readw, "w", unsigned short, "=r", :"memory")
598c2ecf20Sopenharmony_cibuild_mmio_read(readl, "l", unsigned int, "=r", :"memory")
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cibuild_mmio_read(__readb, "b", unsigned char, "=q", )
628c2ecf20Sopenharmony_cibuild_mmio_read(__readw, "w", unsigned short, "=r", )
638c2ecf20Sopenharmony_cibuild_mmio_read(__readl, "l", unsigned int, "=r", )
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cibuild_mmio_write(writeb, "b", unsigned char, "q", :"memory")
668c2ecf20Sopenharmony_cibuild_mmio_write(writew, "w", unsigned short, "r", :"memory")
678c2ecf20Sopenharmony_cibuild_mmio_write(writel, "l", unsigned int, "r", :"memory")
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cibuild_mmio_write(__writeb, "b", unsigned char, "q", )
708c2ecf20Sopenharmony_cibuild_mmio_write(__writew, "w", unsigned short, "r", )
718c2ecf20Sopenharmony_cibuild_mmio_write(__writel, "l", unsigned int, "r", )
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define readb readb
748c2ecf20Sopenharmony_ci#define readw readw
758c2ecf20Sopenharmony_ci#define readl readl
768c2ecf20Sopenharmony_ci#define readb_relaxed(a) __readb(a)
778c2ecf20Sopenharmony_ci#define readw_relaxed(a) __readw(a)
788c2ecf20Sopenharmony_ci#define readl_relaxed(a) __readl(a)
798c2ecf20Sopenharmony_ci#define __raw_readb __readb
808c2ecf20Sopenharmony_ci#define __raw_readw __readw
818c2ecf20Sopenharmony_ci#define __raw_readl __readl
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define writeb writeb
848c2ecf20Sopenharmony_ci#define writew writew
858c2ecf20Sopenharmony_ci#define writel writel
868c2ecf20Sopenharmony_ci#define writeb_relaxed(v, a) __writeb(v, a)
878c2ecf20Sopenharmony_ci#define writew_relaxed(v, a) __writew(v, a)
888c2ecf20Sopenharmony_ci#define writel_relaxed(v, a) __writel(v, a)
898c2ecf20Sopenharmony_ci#define __raw_writeb __writeb
908c2ecf20Sopenharmony_ci#define __raw_writew __writew
918c2ecf20Sopenharmony_ci#define __raw_writel __writel
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cibuild_mmio_read(readq, "q", u64, "=r", :"memory")
968c2ecf20Sopenharmony_cibuild_mmio_read(__readq, "q", u64, "=r", )
978c2ecf20Sopenharmony_cibuild_mmio_write(writeq, "q", u64, "r", :"memory")
988c2ecf20Sopenharmony_cibuild_mmio_write(__writeq, "q", u64, "r", )
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define readq_relaxed(a)	__readq(a)
1018c2ecf20Sopenharmony_ci#define writeq_relaxed(v, a)	__writeq(v, a)
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define __raw_readq		__readq
1048c2ecf20Sopenharmony_ci#define __raw_writeq		__writeq
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* Let people know that we have them */
1078c2ecf20Sopenharmony_ci#define readq			readq
1088c2ecf20Sopenharmony_ci#define writeq			writeq
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#endif
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
1138c2ecf20Sopenharmony_ciextern int valid_phys_addr_range(phys_addr_t addr, size_t size);
1148c2ecf20Sopenharmony_ciextern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/**
1178c2ecf20Sopenharmony_ci *	virt_to_phys	-	map virtual addresses to physical
1188c2ecf20Sopenharmony_ci *	@address: address to remap
1198c2ecf20Sopenharmony_ci *
1208c2ecf20Sopenharmony_ci *	The returned physical address is the physical (CPU) mapping for
1218c2ecf20Sopenharmony_ci *	the memory address given. It is only valid to use this function on
1228c2ecf20Sopenharmony_ci *	addresses directly mapped or allocated via kmalloc.
1238c2ecf20Sopenharmony_ci *
1248c2ecf20Sopenharmony_ci *	This function does not give bus mappings for DMA transfers. In
1258c2ecf20Sopenharmony_ci *	almost all conceivable cases a device driver should not be using
1268c2ecf20Sopenharmony_ci *	this function
1278c2ecf20Sopenharmony_ci */
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic inline phys_addr_t virt_to_phys(volatile void *address)
1308c2ecf20Sopenharmony_ci{
1318c2ecf20Sopenharmony_ci	return __pa(address);
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci#define virt_to_phys virt_to_phys
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci/**
1368c2ecf20Sopenharmony_ci *	phys_to_virt	-	map physical address to virtual
1378c2ecf20Sopenharmony_ci *	@address: address to remap
1388c2ecf20Sopenharmony_ci *
1398c2ecf20Sopenharmony_ci *	The returned virtual address is a current CPU mapping for
1408c2ecf20Sopenharmony_ci *	the memory address given. It is only valid to use this function on
1418c2ecf20Sopenharmony_ci *	addresses that have a kernel mapping
1428c2ecf20Sopenharmony_ci *
1438c2ecf20Sopenharmony_ci *	This function does not handle bus mappings for DMA transfers. In
1448c2ecf20Sopenharmony_ci *	almost all conceivable cases a device driver should not be using
1458c2ecf20Sopenharmony_ci *	this function
1468c2ecf20Sopenharmony_ci */
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistatic inline void *phys_to_virt(phys_addr_t address)
1498c2ecf20Sopenharmony_ci{
1508c2ecf20Sopenharmony_ci	return __va(address);
1518c2ecf20Sopenharmony_ci}
1528c2ecf20Sopenharmony_ci#define phys_to_virt phys_to_virt
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/*
1558c2ecf20Sopenharmony_ci * Change "struct page" to physical address.
1568c2ecf20Sopenharmony_ci */
1578c2ecf20Sopenharmony_ci#define page_to_phys(page)    ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci/*
1608c2ecf20Sopenharmony_ci * ISA I/O bus memory addresses are 1:1 with the physical address.
1618c2ecf20Sopenharmony_ci * However, we truncate the address to unsigned int to avoid undesirable
1628c2ecf20Sopenharmony_ci * promitions in legacy drivers.
1638c2ecf20Sopenharmony_ci */
1648c2ecf20Sopenharmony_cistatic inline unsigned int isa_virt_to_bus(volatile void *address)
1658c2ecf20Sopenharmony_ci{
1668c2ecf20Sopenharmony_ci	return (unsigned int)virt_to_phys(address);
1678c2ecf20Sopenharmony_ci}
1688c2ecf20Sopenharmony_ci#define isa_bus_to_virt		phys_to_virt
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci/*
1718c2ecf20Sopenharmony_ci * However PCI ones are not necessarily 1:1 and therefore these interfaces
1728c2ecf20Sopenharmony_ci * are forbidden in portable PCI drivers.
1738c2ecf20Sopenharmony_ci *
1748c2ecf20Sopenharmony_ci * Allow them on x86 for legacy drivers, though.
1758c2ecf20Sopenharmony_ci */
1768c2ecf20Sopenharmony_ci#define virt_to_bus virt_to_phys
1778c2ecf20Sopenharmony_ci#define bus_to_virt phys_to_virt
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci/*
1808c2ecf20Sopenharmony_ci * The default ioremap() behavior is non-cached; if you need something
1818c2ecf20Sopenharmony_ci * else, you probably want one of the following.
1828c2ecf20Sopenharmony_ci */
1838c2ecf20Sopenharmony_ciextern void __iomem *ioremap_uc(resource_size_t offset, unsigned long size);
1848c2ecf20Sopenharmony_ci#define ioremap_uc ioremap_uc
1858c2ecf20Sopenharmony_ciextern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
1868c2ecf20Sopenharmony_ci#define ioremap_cache ioremap_cache
1878c2ecf20Sopenharmony_ciextern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size, unsigned long prot_val);
1888c2ecf20Sopenharmony_ci#define ioremap_prot ioremap_prot
1898c2ecf20Sopenharmony_ciextern void __iomem *ioremap_encrypted(resource_size_t phys_addr, unsigned long size);
1908c2ecf20Sopenharmony_ci#define ioremap_encrypted ioremap_encrypted
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci/**
1938c2ecf20Sopenharmony_ci * ioremap     -   map bus memory into CPU space
1948c2ecf20Sopenharmony_ci * @offset:    bus address of the memory
1958c2ecf20Sopenharmony_ci * @size:      size of the resource to map
1968c2ecf20Sopenharmony_ci *
1978c2ecf20Sopenharmony_ci * ioremap performs a platform specific sequence of operations to
1988c2ecf20Sopenharmony_ci * make bus memory CPU accessible via the readb/readw/readl/writeb/
1998c2ecf20Sopenharmony_ci * writew/writel functions and the other mmio helpers. The returned
2008c2ecf20Sopenharmony_ci * address is not guaranteed to be usable directly as a virtual
2018c2ecf20Sopenharmony_ci * address.
2028c2ecf20Sopenharmony_ci *
2038c2ecf20Sopenharmony_ci * If the area you are trying to map is a PCI BAR you should have a
2048c2ecf20Sopenharmony_ci * look at pci_iomap().
2058c2ecf20Sopenharmony_ci */
2068c2ecf20Sopenharmony_civoid __iomem *ioremap(resource_size_t offset, unsigned long size);
2078c2ecf20Sopenharmony_ci#define ioremap ioremap
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ciextern void iounmap(volatile void __iomem *addr);
2108c2ecf20Sopenharmony_ci#define iounmap iounmap
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ciextern void set_iounmap_nonlazy(void);
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci#ifdef __KERNEL__
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_civoid memcpy_fromio(void *, const volatile void __iomem *, size_t);
2178c2ecf20Sopenharmony_civoid memcpy_toio(volatile void __iomem *, const void *, size_t);
2188c2ecf20Sopenharmony_civoid memset_io(volatile void __iomem *, int, size_t);
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci#define memcpy_fromio memcpy_fromio
2218c2ecf20Sopenharmony_ci#define memcpy_toio memcpy_toio
2228c2ecf20Sopenharmony_ci#define memset_io memset_io
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci#include <asm-generic/iomap.h>
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci/*
2278c2ecf20Sopenharmony_ci * ISA space is 'always mapped' on a typical x86 system, no need to
2288c2ecf20Sopenharmony_ci * explicitly ioremap() it. The fact that the ISA IO space is mapped
2298c2ecf20Sopenharmony_ci * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
2308c2ecf20Sopenharmony_ci * are physical addresses. The following constant pointer can be
2318c2ecf20Sopenharmony_ci * used as the IO-area pointer (it can be iounmapped as well, so the
2328c2ecf20Sopenharmony_ci * analogy with PCI is quite large):
2338c2ecf20Sopenharmony_ci */
2348c2ecf20Sopenharmony_ci#define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET))
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ciextern void native_io_delay(void);
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ciextern int io_delay_type;
2418c2ecf20Sopenharmony_ciextern void io_delay_init(void);
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci#if defined(CONFIG_PARAVIRT)
2448c2ecf20Sopenharmony_ci#include <asm/paravirt.h>
2458c2ecf20Sopenharmony_ci#else
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_cistatic inline void slow_down_io(void)
2488c2ecf20Sopenharmony_ci{
2498c2ecf20Sopenharmony_ci	native_io_delay();
2508c2ecf20Sopenharmony_ci#ifdef REALLY_SLOW_IO
2518c2ecf20Sopenharmony_ci	native_io_delay();
2528c2ecf20Sopenharmony_ci	native_io_delay();
2538c2ecf20Sopenharmony_ci	native_io_delay();
2548c2ecf20Sopenharmony_ci#endif
2558c2ecf20Sopenharmony_ci}
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci#endif
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci#ifdef CONFIG_AMD_MEM_ENCRYPT
2608c2ecf20Sopenharmony_ci#include <linux/jump_label.h>
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ciextern struct static_key_false sev_enable_key;
2638c2ecf20Sopenharmony_cistatic inline bool sev_key_active(void)
2648c2ecf20Sopenharmony_ci{
2658c2ecf20Sopenharmony_ci	return static_branch_unlikely(&sev_enable_key);
2668c2ecf20Sopenharmony_ci}
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci#else /* !CONFIG_AMD_MEM_ENCRYPT */
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cistatic inline bool sev_key_active(void) { return false; }
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci#endif /* CONFIG_AMD_MEM_ENCRYPT */
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci#define BUILDIO(bwl, bw, type)						\
2758c2ecf20Sopenharmony_cistatic inline void out##bwl(unsigned type value, int port)		\
2768c2ecf20Sopenharmony_ci{									\
2778c2ecf20Sopenharmony_ci	asm volatile("out" #bwl " %" #bw "0, %w1"			\
2788c2ecf20Sopenharmony_ci		     : : "a"(value), "Nd"(port));			\
2798c2ecf20Sopenharmony_ci}									\
2808c2ecf20Sopenharmony_ci									\
2818c2ecf20Sopenharmony_cistatic inline unsigned type in##bwl(int port)				\
2828c2ecf20Sopenharmony_ci{									\
2838c2ecf20Sopenharmony_ci	unsigned type value;						\
2848c2ecf20Sopenharmony_ci	asm volatile("in" #bwl " %w1, %" #bw "0"			\
2858c2ecf20Sopenharmony_ci		     : "=a"(value) : "Nd"(port));			\
2868c2ecf20Sopenharmony_ci	return value;							\
2878c2ecf20Sopenharmony_ci}									\
2888c2ecf20Sopenharmony_ci									\
2898c2ecf20Sopenharmony_cistatic inline void out##bwl##_p(unsigned type value, int port)		\
2908c2ecf20Sopenharmony_ci{									\
2918c2ecf20Sopenharmony_ci	out##bwl(value, port);						\
2928c2ecf20Sopenharmony_ci	slow_down_io();							\
2938c2ecf20Sopenharmony_ci}									\
2948c2ecf20Sopenharmony_ci									\
2958c2ecf20Sopenharmony_cistatic inline unsigned type in##bwl##_p(int port)			\
2968c2ecf20Sopenharmony_ci{									\
2978c2ecf20Sopenharmony_ci	unsigned type value = in##bwl(port);				\
2988c2ecf20Sopenharmony_ci	slow_down_io();							\
2998c2ecf20Sopenharmony_ci	return value;							\
3008c2ecf20Sopenharmony_ci}									\
3018c2ecf20Sopenharmony_ci									\
3028c2ecf20Sopenharmony_cistatic inline void outs##bwl(int port, const void *addr, unsigned long count) \
3038c2ecf20Sopenharmony_ci{									\
3048c2ecf20Sopenharmony_ci	if (sev_key_active()) {						\
3058c2ecf20Sopenharmony_ci		unsigned type *value = (unsigned type *)addr;		\
3068c2ecf20Sopenharmony_ci		while (count) {						\
3078c2ecf20Sopenharmony_ci			out##bwl(*value, port);				\
3088c2ecf20Sopenharmony_ci			value++;					\
3098c2ecf20Sopenharmony_ci			count--;					\
3108c2ecf20Sopenharmony_ci		}							\
3118c2ecf20Sopenharmony_ci	} else {							\
3128c2ecf20Sopenharmony_ci		asm volatile("rep; outs" #bwl				\
3138c2ecf20Sopenharmony_ci			     : "+S"(addr), "+c"(count)			\
3148c2ecf20Sopenharmony_ci			     : "d"(port) : "memory");			\
3158c2ecf20Sopenharmony_ci	}								\
3168c2ecf20Sopenharmony_ci}									\
3178c2ecf20Sopenharmony_ci									\
3188c2ecf20Sopenharmony_cistatic inline void ins##bwl(int port, void *addr, unsigned long count)	\
3198c2ecf20Sopenharmony_ci{									\
3208c2ecf20Sopenharmony_ci	if (sev_key_active()) {						\
3218c2ecf20Sopenharmony_ci		unsigned type *value = (unsigned type *)addr;		\
3228c2ecf20Sopenharmony_ci		while (count) {						\
3238c2ecf20Sopenharmony_ci			*value = in##bwl(port);				\
3248c2ecf20Sopenharmony_ci			value++;					\
3258c2ecf20Sopenharmony_ci			count--;					\
3268c2ecf20Sopenharmony_ci		}							\
3278c2ecf20Sopenharmony_ci	} else {							\
3288c2ecf20Sopenharmony_ci		asm volatile("rep; ins" #bwl				\
3298c2ecf20Sopenharmony_ci			     : "+D"(addr), "+c"(count)			\
3308c2ecf20Sopenharmony_ci			     : "d"(port) : "memory");			\
3318c2ecf20Sopenharmony_ci	}								\
3328c2ecf20Sopenharmony_ci}
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ciBUILDIO(b, b, char)
3358c2ecf20Sopenharmony_ciBUILDIO(w, w, short)
3368c2ecf20Sopenharmony_ciBUILDIO(l, , int)
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci#define inb inb
3398c2ecf20Sopenharmony_ci#define inw inw
3408c2ecf20Sopenharmony_ci#define inl inl
3418c2ecf20Sopenharmony_ci#define inb_p inb_p
3428c2ecf20Sopenharmony_ci#define inw_p inw_p
3438c2ecf20Sopenharmony_ci#define inl_p inl_p
3448c2ecf20Sopenharmony_ci#define insb insb
3458c2ecf20Sopenharmony_ci#define insw insw
3468c2ecf20Sopenharmony_ci#define insl insl
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci#define outb outb
3498c2ecf20Sopenharmony_ci#define outw outw
3508c2ecf20Sopenharmony_ci#define outl outl
3518c2ecf20Sopenharmony_ci#define outb_p outb_p
3528c2ecf20Sopenharmony_ci#define outw_p outw_p
3538c2ecf20Sopenharmony_ci#define outl_p outl_p
3548c2ecf20Sopenharmony_ci#define outsb outsb
3558c2ecf20Sopenharmony_ci#define outsw outsw
3568c2ecf20Sopenharmony_ci#define outsl outsl
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ciextern void *xlate_dev_mem_ptr(phys_addr_t phys);
3598c2ecf20Sopenharmony_ciextern void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci#define xlate_dev_mem_ptr xlate_dev_mem_ptr
3628c2ecf20Sopenharmony_ci#define unxlate_dev_mem_ptr unxlate_dev_mem_ptr
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ciextern int ioremap_change_attr(unsigned long vaddr, unsigned long size,
3658c2ecf20Sopenharmony_ci				enum page_cache_mode pcm);
3668c2ecf20Sopenharmony_ciextern void __iomem *ioremap_wc(resource_size_t offset, unsigned long size);
3678c2ecf20Sopenharmony_ci#define ioremap_wc ioremap_wc
3688c2ecf20Sopenharmony_ciextern void __iomem *ioremap_wt(resource_size_t offset, unsigned long size);
3698c2ecf20Sopenharmony_ci#define ioremap_wt ioremap_wt
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ciextern bool is_early_ioremap_ptep(pte_t *ptep);
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci#define IO_SPACE_LIMIT 0xffff
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci#include <asm-generic/io.h>
3768c2ecf20Sopenharmony_ci#undef PCI_IOBASE
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci#ifdef CONFIG_MTRR
3798c2ecf20Sopenharmony_ciextern int __must_check arch_phys_wc_index(int handle);
3808c2ecf20Sopenharmony_ci#define arch_phys_wc_index arch_phys_wc_index
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ciextern int __must_check arch_phys_wc_add(unsigned long base,
3838c2ecf20Sopenharmony_ci					 unsigned long size);
3848c2ecf20Sopenharmony_ciextern void arch_phys_wc_del(int handle);
3858c2ecf20Sopenharmony_ci#define arch_phys_wc_add arch_phys_wc_add
3868c2ecf20Sopenharmony_ci#endif
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_PAT
3898c2ecf20Sopenharmony_ciextern int arch_io_reserve_memtype_wc(resource_size_t start, resource_size_t size);
3908c2ecf20Sopenharmony_ciextern void arch_io_free_memtype_wc(resource_size_t start, resource_size_t size);
3918c2ecf20Sopenharmony_ci#define arch_io_reserve_memtype_wc arch_io_reserve_memtype_wc
3928c2ecf20Sopenharmony_ci#endif
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ciextern bool arch_memremap_can_ram_remap(resource_size_t offset,
3958c2ecf20Sopenharmony_ci					unsigned long size,
3968c2ecf20Sopenharmony_ci					unsigned long flags);
3978c2ecf20Sopenharmony_ci#define arch_memremap_can_ram_remap arch_memremap_can_ram_remap
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ciextern bool phys_mem_access_encrypted(unsigned long phys_addr,
4008c2ecf20Sopenharmony_ci				      unsigned long size);
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci/**
4038c2ecf20Sopenharmony_ci * iosubmit_cmds512 - copy data to single MMIO location, in 512-bit units
4048c2ecf20Sopenharmony_ci * @dst: destination, in MMIO space (must be 512-bit aligned)
4058c2ecf20Sopenharmony_ci * @src: source
4068c2ecf20Sopenharmony_ci * @count: number of 512 bits quantities to submit
4078c2ecf20Sopenharmony_ci *
4088c2ecf20Sopenharmony_ci * Submit data from kernel space to MMIO space, in units of 512 bits at a
4098c2ecf20Sopenharmony_ci * time.  Order of access is not guaranteed, nor is a memory barrier
4108c2ecf20Sopenharmony_ci * performed afterwards.
4118c2ecf20Sopenharmony_ci *
4128c2ecf20Sopenharmony_ci * Warning: Do not use this helper unless your driver has checked that the CPU
4138c2ecf20Sopenharmony_ci * instruction is supported on the platform.
4148c2ecf20Sopenharmony_ci */
4158c2ecf20Sopenharmony_cistatic inline void iosubmit_cmds512(void __iomem *dst, const void *src,
4168c2ecf20Sopenharmony_ci				    size_t count)
4178c2ecf20Sopenharmony_ci{
4188c2ecf20Sopenharmony_ci	const u8 *from = src;
4198c2ecf20Sopenharmony_ci	const u8 *end = from + count * 64;
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	while (from < end) {
4228c2ecf20Sopenharmony_ci		movdir64b(dst, from);
4238c2ecf20Sopenharmony_ci		from += 64;
4248c2ecf20Sopenharmony_ci	}
4258c2ecf20Sopenharmony_ci}
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci#endif /* _ASM_X86_IO_H */
428