xref: /OK3568_Linux_fs/kernel/arch/x86/include/asm/io.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _ASM_X86_IO_H
3*4882a593Smuzhiyun #define _ASM_X86_IO_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun /*
6*4882a593Smuzhiyun  * This file contains the definitions for the x86 IO instructions
7*4882a593Smuzhiyun  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
8*4882a593Smuzhiyun  * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
9*4882a593Smuzhiyun  * versions of the single-IO instructions (inb_p/inw_p/..).
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * This file is not meant to be obfuscating: it's just complicated
12*4882a593Smuzhiyun  * to (a) handle it all in a way that makes gcc able to optimize it
13*4882a593Smuzhiyun  * as well as possible and (b) trying to avoid writing the same thing
14*4882a593Smuzhiyun  * over and over again with slight variations and possibly making a
15*4882a593Smuzhiyun  * mistake somewhere.
16*4882a593Smuzhiyun  */
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /*
19*4882a593Smuzhiyun  * Thanks to James van Artsdalen for a better timing-fix than
20*4882a593Smuzhiyun  * the two short jumps: using outb's to a nonexistent port seems
21*4882a593Smuzhiyun  * to guarantee better timings even on fast machines.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * On the other hand, I'd like to be sure of a non-existent port:
24*4882a593Smuzhiyun  * I feel a bit unsafe about using 0x80 (should be safe, though)
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  *		Linus
27*4882a593Smuzhiyun  */
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun  /*
30*4882a593Smuzhiyun   *  Bit simplified and optimized by Jan Hubicka
31*4882a593Smuzhiyun   *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
32*4882a593Smuzhiyun   *
33*4882a593Smuzhiyun   *  isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added,
34*4882a593Smuzhiyun   *  isa_read[wl] and isa_write[wl] fixed
35*4882a593Smuzhiyun   *  - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
36*4882a593Smuzhiyun   */
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #define ARCH_HAS_IOREMAP_WC
39*4882a593Smuzhiyun #define ARCH_HAS_IOREMAP_WT
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #include <linux/string.h>
42*4882a593Smuzhiyun #include <linux/compiler.h>
43*4882a593Smuzhiyun #include <asm/page.h>
44*4882a593Smuzhiyun #include <asm/early_ioremap.h>
45*4882a593Smuzhiyun #include <asm/pgtable_types.h>
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun #define build_mmio_read(name, size, type, reg, barrier) \
48*4882a593Smuzhiyun static inline type name(const volatile void __iomem *addr) \
49*4882a593Smuzhiyun { type ret; asm volatile("mov" size " %1,%0":reg (ret) \
50*4882a593Smuzhiyun :"m" (*(volatile type __force *)addr) barrier); return ret; }
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #define build_mmio_write(name, size, type, reg, barrier) \
53*4882a593Smuzhiyun static inline void name(type val, volatile void __iomem *addr) \
54*4882a593Smuzhiyun { asm volatile("mov" size " %0,%1": :reg (val), \
55*4882a593Smuzhiyun "m" (*(volatile type __force *)addr) barrier); }
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
58*4882a593Smuzhiyun build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
59*4882a593Smuzhiyun build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun build_mmio_read(__readb, "b", unsigned char, "=q", )
62*4882a593Smuzhiyun build_mmio_read(__readw, "w", unsigned short, "=r", )
63*4882a593Smuzhiyun build_mmio_read(__readl, "l", unsigned int, "=r", )
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
66*4882a593Smuzhiyun build_mmio_write(writew, "w", unsigned short, "r", :"memory")
67*4882a593Smuzhiyun build_mmio_write(writel, "l", unsigned int, "r", :"memory")
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun build_mmio_write(__writeb, "b", unsigned char, "q", )
70*4882a593Smuzhiyun build_mmio_write(__writew, "w", unsigned short, "r", )
71*4882a593Smuzhiyun build_mmio_write(__writel, "l", unsigned int, "r", )
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun #define readb readb
74*4882a593Smuzhiyun #define readw readw
75*4882a593Smuzhiyun #define readl readl
76*4882a593Smuzhiyun #define readb_relaxed(a) __readb(a)
77*4882a593Smuzhiyun #define readw_relaxed(a) __readw(a)
78*4882a593Smuzhiyun #define readl_relaxed(a) __readl(a)
79*4882a593Smuzhiyun #define __raw_readb __readb
80*4882a593Smuzhiyun #define __raw_readw __readw
81*4882a593Smuzhiyun #define __raw_readl __readl
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun #define writeb writeb
84*4882a593Smuzhiyun #define writew writew
85*4882a593Smuzhiyun #define writel writel
86*4882a593Smuzhiyun #define writeb_relaxed(v, a) __writeb(v, a)
87*4882a593Smuzhiyun #define writew_relaxed(v, a) __writew(v, a)
88*4882a593Smuzhiyun #define writel_relaxed(v, a) __writel(v, a)
89*4882a593Smuzhiyun #define __raw_writeb __writeb
90*4882a593Smuzhiyun #define __raw_writew __writew
91*4882a593Smuzhiyun #define __raw_writel __writel
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun #ifdef CONFIG_X86_64
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun build_mmio_read(readq, "q", u64, "=r", :"memory")
96*4882a593Smuzhiyun build_mmio_read(__readq, "q", u64, "=r", )
97*4882a593Smuzhiyun build_mmio_write(writeq, "q", u64, "r", :"memory")
98*4882a593Smuzhiyun build_mmio_write(__writeq, "q", u64, "r", )
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun #define readq_relaxed(a)	__readq(a)
101*4882a593Smuzhiyun #define writeq_relaxed(v, a)	__writeq(v, a)
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun #define __raw_readq		__readq
104*4882a593Smuzhiyun #define __raw_writeq		__writeq
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun /* Let people know that we have them */
107*4882a593Smuzhiyun #define readq			readq
108*4882a593Smuzhiyun #define writeq			writeq
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun #endif
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
113*4882a593Smuzhiyun extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
114*4882a593Smuzhiyun extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun /**
117*4882a593Smuzhiyun  *	virt_to_phys	-	map virtual addresses to physical
118*4882a593Smuzhiyun  *	@address: address to remap
119*4882a593Smuzhiyun  *
120*4882a593Smuzhiyun  *	The returned physical address is the physical (CPU) mapping for
121*4882a593Smuzhiyun  *	the memory address given. It is only valid to use this function on
122*4882a593Smuzhiyun  *	addresses directly mapped or allocated via kmalloc.
123*4882a593Smuzhiyun  *
124*4882a593Smuzhiyun  *	This function does not give bus mappings for DMA transfers. In
125*4882a593Smuzhiyun  *	almost all conceivable cases a device driver should not be using
126*4882a593Smuzhiyun  *	this function
127*4882a593Smuzhiyun  */
128*4882a593Smuzhiyun 
virt_to_phys(volatile void * address)129*4882a593Smuzhiyun static inline phys_addr_t virt_to_phys(volatile void *address)
130*4882a593Smuzhiyun {
131*4882a593Smuzhiyun 	return __pa(address);
132*4882a593Smuzhiyun }
133*4882a593Smuzhiyun #define virt_to_phys virt_to_phys
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun /**
136*4882a593Smuzhiyun  *	phys_to_virt	-	map physical address to virtual
137*4882a593Smuzhiyun  *	@address: address to remap
138*4882a593Smuzhiyun  *
139*4882a593Smuzhiyun  *	The returned virtual address is a current CPU mapping for
140*4882a593Smuzhiyun  *	the memory address given. It is only valid to use this function on
141*4882a593Smuzhiyun  *	addresses that have a kernel mapping
142*4882a593Smuzhiyun  *
143*4882a593Smuzhiyun  *	This function does not handle bus mappings for DMA transfers. In
144*4882a593Smuzhiyun  *	almost all conceivable cases a device driver should not be using
145*4882a593Smuzhiyun  *	this function
146*4882a593Smuzhiyun  */
147*4882a593Smuzhiyun 
phys_to_virt(phys_addr_t address)148*4882a593Smuzhiyun static inline void *phys_to_virt(phys_addr_t address)
149*4882a593Smuzhiyun {
150*4882a593Smuzhiyun 	return __va(address);
151*4882a593Smuzhiyun }
152*4882a593Smuzhiyun #define phys_to_virt phys_to_virt
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun /*
155*4882a593Smuzhiyun  * Change "struct page" to physical address.
156*4882a593Smuzhiyun  */
157*4882a593Smuzhiyun #define page_to_phys(page)    ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun /*
160*4882a593Smuzhiyun  * ISA I/O bus memory addresses are 1:1 with the physical address.
161*4882a593Smuzhiyun  * However, we truncate the address to unsigned int to avoid undesirable
162*4882a593Smuzhiyun  * promitions in legacy drivers.
163*4882a593Smuzhiyun  */
isa_virt_to_bus(volatile void * address)164*4882a593Smuzhiyun static inline unsigned int isa_virt_to_bus(volatile void *address)
165*4882a593Smuzhiyun {
166*4882a593Smuzhiyun 	return (unsigned int)virt_to_phys(address);
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun #define isa_bus_to_virt		phys_to_virt
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun /*
171*4882a593Smuzhiyun  * However PCI ones are not necessarily 1:1 and therefore these interfaces
172*4882a593Smuzhiyun  * are forbidden in portable PCI drivers.
173*4882a593Smuzhiyun  *
174*4882a593Smuzhiyun  * Allow them on x86 for legacy drivers, though.
175*4882a593Smuzhiyun  */
176*4882a593Smuzhiyun #define virt_to_bus virt_to_phys
177*4882a593Smuzhiyun #define bus_to_virt phys_to_virt
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun /*
180*4882a593Smuzhiyun  * The default ioremap() behavior is non-cached; if you need something
181*4882a593Smuzhiyun  * else, you probably want one of the following.
182*4882a593Smuzhiyun  */
183*4882a593Smuzhiyun extern void __iomem *ioremap_uc(resource_size_t offset, unsigned long size);
184*4882a593Smuzhiyun #define ioremap_uc ioremap_uc
185*4882a593Smuzhiyun extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
186*4882a593Smuzhiyun #define ioremap_cache ioremap_cache
187*4882a593Smuzhiyun extern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size, unsigned long prot_val);
188*4882a593Smuzhiyun #define ioremap_prot ioremap_prot
189*4882a593Smuzhiyun extern void __iomem *ioremap_encrypted(resource_size_t phys_addr, unsigned long size);
190*4882a593Smuzhiyun #define ioremap_encrypted ioremap_encrypted
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun /**
193*4882a593Smuzhiyun  * ioremap     -   map bus memory into CPU space
194*4882a593Smuzhiyun  * @offset:    bus address of the memory
195*4882a593Smuzhiyun  * @size:      size of the resource to map
196*4882a593Smuzhiyun  *
197*4882a593Smuzhiyun  * ioremap performs a platform specific sequence of operations to
198*4882a593Smuzhiyun  * make bus memory CPU accessible via the readb/readw/readl/writeb/
199*4882a593Smuzhiyun  * writew/writel functions and the other mmio helpers. The returned
200*4882a593Smuzhiyun  * address is not guaranteed to be usable directly as a virtual
201*4882a593Smuzhiyun  * address.
202*4882a593Smuzhiyun  *
203*4882a593Smuzhiyun  * If the area you are trying to map is a PCI BAR you should have a
204*4882a593Smuzhiyun  * look at pci_iomap().
205*4882a593Smuzhiyun  */
206*4882a593Smuzhiyun void __iomem *ioremap(resource_size_t offset, unsigned long size);
207*4882a593Smuzhiyun #define ioremap ioremap
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun extern void iounmap(volatile void __iomem *addr);
210*4882a593Smuzhiyun #define iounmap iounmap
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun extern void set_iounmap_nonlazy(void);
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun #ifdef __KERNEL__
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun void memcpy_fromio(void *, const volatile void __iomem *, size_t);
217*4882a593Smuzhiyun void memcpy_toio(volatile void __iomem *, const void *, size_t);
218*4882a593Smuzhiyun void memset_io(volatile void __iomem *, int, size_t);
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun #define memcpy_fromio memcpy_fromio
221*4882a593Smuzhiyun #define memcpy_toio memcpy_toio
222*4882a593Smuzhiyun #define memset_io memset_io
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun #include <asm-generic/iomap.h>
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun /*
227*4882a593Smuzhiyun  * ISA space is 'always mapped' on a typical x86 system, no need to
228*4882a593Smuzhiyun  * explicitly ioremap() it. The fact that the ISA IO space is mapped
229*4882a593Smuzhiyun  * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
230*4882a593Smuzhiyun  * are physical addresses. The following constant pointer can be
231*4882a593Smuzhiyun  * used as the IO-area pointer (it can be iounmapped as well, so the
232*4882a593Smuzhiyun  * analogy with PCI is quite large):
233*4882a593Smuzhiyun  */
234*4882a593Smuzhiyun #define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET))
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun #endif /* __KERNEL__ */
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun extern void native_io_delay(void);
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun extern int io_delay_type;
241*4882a593Smuzhiyun extern void io_delay_init(void);
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun #if defined(CONFIG_PARAVIRT)
244*4882a593Smuzhiyun #include <asm/paravirt.h>
245*4882a593Smuzhiyun #else
246*4882a593Smuzhiyun 
slow_down_io(void)247*4882a593Smuzhiyun static inline void slow_down_io(void)
248*4882a593Smuzhiyun {
249*4882a593Smuzhiyun 	native_io_delay();
250*4882a593Smuzhiyun #ifdef REALLY_SLOW_IO
251*4882a593Smuzhiyun 	native_io_delay();
252*4882a593Smuzhiyun 	native_io_delay();
253*4882a593Smuzhiyun 	native_io_delay();
254*4882a593Smuzhiyun #endif
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun #endif
258*4882a593Smuzhiyun 
259*4882a593Smuzhiyun #ifdef CONFIG_AMD_MEM_ENCRYPT
260*4882a593Smuzhiyun #include <linux/jump_label.h>
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun extern struct static_key_false sev_enable_key;
sev_key_active(void)263*4882a593Smuzhiyun static inline bool sev_key_active(void)
264*4882a593Smuzhiyun {
265*4882a593Smuzhiyun 	return static_branch_unlikely(&sev_enable_key);
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun #else /* !CONFIG_AMD_MEM_ENCRYPT */
269*4882a593Smuzhiyun 
sev_key_active(void)270*4882a593Smuzhiyun static inline bool sev_key_active(void) { return false; }
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun #endif /* CONFIG_AMD_MEM_ENCRYPT */
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun #define BUILDIO(bwl, bw, type)						\
275*4882a593Smuzhiyun static inline void out##bwl(unsigned type value, int port)		\
276*4882a593Smuzhiyun {									\
277*4882a593Smuzhiyun 	asm volatile("out" #bwl " %" #bw "0, %w1"			\
278*4882a593Smuzhiyun 		     : : "a"(value), "Nd"(port));			\
279*4882a593Smuzhiyun }									\
280*4882a593Smuzhiyun 									\
281*4882a593Smuzhiyun static inline unsigned type in##bwl(int port)				\
282*4882a593Smuzhiyun {									\
283*4882a593Smuzhiyun 	unsigned type value;						\
284*4882a593Smuzhiyun 	asm volatile("in" #bwl " %w1, %" #bw "0"			\
285*4882a593Smuzhiyun 		     : "=a"(value) : "Nd"(port));			\
286*4882a593Smuzhiyun 	return value;							\
287*4882a593Smuzhiyun }									\
288*4882a593Smuzhiyun 									\
289*4882a593Smuzhiyun static inline void out##bwl##_p(unsigned type value, int port)		\
290*4882a593Smuzhiyun {									\
291*4882a593Smuzhiyun 	out##bwl(value, port);						\
292*4882a593Smuzhiyun 	slow_down_io();							\
293*4882a593Smuzhiyun }									\
294*4882a593Smuzhiyun 									\
295*4882a593Smuzhiyun static inline unsigned type in##bwl##_p(int port)			\
296*4882a593Smuzhiyun {									\
297*4882a593Smuzhiyun 	unsigned type value = in##bwl(port);				\
298*4882a593Smuzhiyun 	slow_down_io();							\
299*4882a593Smuzhiyun 	return value;							\
300*4882a593Smuzhiyun }									\
301*4882a593Smuzhiyun 									\
302*4882a593Smuzhiyun static inline void outs##bwl(int port, const void *addr, unsigned long count) \
303*4882a593Smuzhiyun {									\
304*4882a593Smuzhiyun 	if (sev_key_active()) {						\
305*4882a593Smuzhiyun 		unsigned type *value = (unsigned type *)addr;		\
306*4882a593Smuzhiyun 		while (count) {						\
307*4882a593Smuzhiyun 			out##bwl(*value, port);				\
308*4882a593Smuzhiyun 			value++;					\
309*4882a593Smuzhiyun 			count--;					\
310*4882a593Smuzhiyun 		}							\
311*4882a593Smuzhiyun 	} else {							\
312*4882a593Smuzhiyun 		asm volatile("rep; outs" #bwl				\
313*4882a593Smuzhiyun 			     : "+S"(addr), "+c"(count)			\
314*4882a593Smuzhiyun 			     : "d"(port) : "memory");			\
315*4882a593Smuzhiyun 	}								\
316*4882a593Smuzhiyun }									\
317*4882a593Smuzhiyun 									\
318*4882a593Smuzhiyun static inline void ins##bwl(int port, void *addr, unsigned long count)	\
319*4882a593Smuzhiyun {									\
320*4882a593Smuzhiyun 	if (sev_key_active()) {						\
321*4882a593Smuzhiyun 		unsigned type *value = (unsigned type *)addr;		\
322*4882a593Smuzhiyun 		while (count) {						\
323*4882a593Smuzhiyun 			*value = in##bwl(port);				\
324*4882a593Smuzhiyun 			value++;					\
325*4882a593Smuzhiyun 			count--;					\
326*4882a593Smuzhiyun 		}							\
327*4882a593Smuzhiyun 	} else {							\
328*4882a593Smuzhiyun 		asm volatile("rep; ins" #bwl				\
329*4882a593Smuzhiyun 			     : "+D"(addr), "+c"(count)			\
330*4882a593Smuzhiyun 			     : "d"(port) : "memory");			\
331*4882a593Smuzhiyun 	}								\
332*4882a593Smuzhiyun }
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun BUILDIO(b, b, char)
335*4882a593Smuzhiyun BUILDIO(w, w, short)
336*4882a593Smuzhiyun BUILDIO(l, , int)
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun #define inb inb
339*4882a593Smuzhiyun #define inw inw
340*4882a593Smuzhiyun #define inl inl
341*4882a593Smuzhiyun #define inb_p inb_p
342*4882a593Smuzhiyun #define inw_p inw_p
343*4882a593Smuzhiyun #define inl_p inl_p
344*4882a593Smuzhiyun #define insb insb
345*4882a593Smuzhiyun #define insw insw
346*4882a593Smuzhiyun #define insl insl
347*4882a593Smuzhiyun 
348*4882a593Smuzhiyun #define outb outb
349*4882a593Smuzhiyun #define outw outw
350*4882a593Smuzhiyun #define outl outl
351*4882a593Smuzhiyun #define outb_p outb_p
352*4882a593Smuzhiyun #define outw_p outw_p
353*4882a593Smuzhiyun #define outl_p outl_p
354*4882a593Smuzhiyun #define outsb outsb
355*4882a593Smuzhiyun #define outsw outsw
356*4882a593Smuzhiyun #define outsl outsl
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun extern void *xlate_dev_mem_ptr(phys_addr_t phys);
359*4882a593Smuzhiyun extern void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun #define xlate_dev_mem_ptr xlate_dev_mem_ptr
362*4882a593Smuzhiyun #define unxlate_dev_mem_ptr unxlate_dev_mem_ptr
363*4882a593Smuzhiyun 
364*4882a593Smuzhiyun extern int ioremap_change_attr(unsigned long vaddr, unsigned long size,
365*4882a593Smuzhiyun 				enum page_cache_mode pcm);
366*4882a593Smuzhiyun extern void __iomem *ioremap_wc(resource_size_t offset, unsigned long size);
367*4882a593Smuzhiyun #define ioremap_wc ioremap_wc
368*4882a593Smuzhiyun extern void __iomem *ioremap_wt(resource_size_t offset, unsigned long size);
369*4882a593Smuzhiyun #define ioremap_wt ioremap_wt
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun extern bool is_early_ioremap_ptep(pte_t *ptep);
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun #define IO_SPACE_LIMIT 0xffff
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun #include <asm-generic/io.h>
376*4882a593Smuzhiyun #undef PCI_IOBASE
377*4882a593Smuzhiyun 
378*4882a593Smuzhiyun #ifdef CONFIG_MTRR
379*4882a593Smuzhiyun extern int __must_check arch_phys_wc_index(int handle);
380*4882a593Smuzhiyun #define arch_phys_wc_index arch_phys_wc_index
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun extern int __must_check arch_phys_wc_add(unsigned long base,
383*4882a593Smuzhiyun 					 unsigned long size);
384*4882a593Smuzhiyun extern void arch_phys_wc_del(int handle);
385*4882a593Smuzhiyun #define arch_phys_wc_add arch_phys_wc_add
386*4882a593Smuzhiyun #endif
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun #ifdef CONFIG_X86_PAT
389*4882a593Smuzhiyun extern int arch_io_reserve_memtype_wc(resource_size_t start, resource_size_t size);
390*4882a593Smuzhiyun extern void arch_io_free_memtype_wc(resource_size_t start, resource_size_t size);
391*4882a593Smuzhiyun #define arch_io_reserve_memtype_wc arch_io_reserve_memtype_wc
392*4882a593Smuzhiyun #endif
393*4882a593Smuzhiyun 
394*4882a593Smuzhiyun extern bool arch_memremap_can_ram_remap(resource_size_t offset,
395*4882a593Smuzhiyun 					unsigned long size,
396*4882a593Smuzhiyun 					unsigned long flags);
397*4882a593Smuzhiyun #define arch_memremap_can_ram_remap arch_memremap_can_ram_remap
398*4882a593Smuzhiyun 
399*4882a593Smuzhiyun extern bool phys_mem_access_encrypted(unsigned long phys_addr,
400*4882a593Smuzhiyun 				      unsigned long size);
401*4882a593Smuzhiyun 
402*4882a593Smuzhiyun /**
403*4882a593Smuzhiyun  * iosubmit_cmds512 - copy data to single MMIO location, in 512-bit units
404*4882a593Smuzhiyun  * @dst: destination, in MMIO space (must be 512-bit aligned)
405*4882a593Smuzhiyun  * @src: source
406*4882a593Smuzhiyun  * @count: number of 512 bits quantities to submit
407*4882a593Smuzhiyun  *
408*4882a593Smuzhiyun  * Submit data from kernel space to MMIO space, in units of 512 bits at a
409*4882a593Smuzhiyun  * time.  Order of access is not guaranteed, nor is a memory barrier
410*4882a593Smuzhiyun  * performed afterwards.
411*4882a593Smuzhiyun  *
412*4882a593Smuzhiyun  * Warning: Do not use this helper unless your driver has checked that the CPU
413*4882a593Smuzhiyun  * instruction is supported on the platform.
414*4882a593Smuzhiyun  */
iosubmit_cmds512(void __iomem * dst,const void * src,size_t count)415*4882a593Smuzhiyun static inline void iosubmit_cmds512(void __iomem *dst, const void *src,
416*4882a593Smuzhiyun 				    size_t count)
417*4882a593Smuzhiyun {
418*4882a593Smuzhiyun 	const u8 *from = src;
419*4882a593Smuzhiyun 	const u8 *end = from + count * 64;
420*4882a593Smuzhiyun 
421*4882a593Smuzhiyun 	while (from < end) {
422*4882a593Smuzhiyun 		movdir64b(dst, from);
423*4882a593Smuzhiyun 		from += 64;
424*4882a593Smuzhiyun 	}
425*4882a593Smuzhiyun }
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun #endif /* _ASM_X86_IO_H */
428