]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/asm-x86/io_32.h
Add a new sysfs_streq() string comparison function
[mirror_ubuntu-bionic-kernel.git] / include / asm-x86 / io_32.h
CommitLineData
1da177e4
LT
1#ifndef _ASM_IO_H
2#define _ASM_IO_H
3
1da177e4
LT
4#include <linux/string.h>
5#include <linux/compiler.h>
6
7/*
8 * This file contains the definitions for the x86 IO instructions
9 * inb/inw/inl/outb/outw/outl and the "string versions" of the same
10 * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
11 * versions of the single-IO instructions (inb_p/inw_p/..).
12 *
13 * This file is not meant to be obfuscating: it's just complicated
14 * to (a) handle it all in a way that makes gcc able to optimize it
15 * as well as possible and (b) trying to avoid writing the same thing
16 * over and over again with slight variations and possibly making a
17 * mistake somewhere.
18 */
19
20/*
21 * Thanks to James van Artsdalen for a better timing-fix than
22 * the two short jumps: using outb's to a nonexistent port seems
23 * to guarantee better timings even on fast machines.
24 *
25 * On the other hand, I'd like to be sure of a non-existent port:
26 * I feel a bit unsafe about using 0x80 (should be safe, though)
27 *
28 * Linus
29 */
30
31 /*
32 * Bit simplified and optimized by Jan Hubicka
33 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
34 *
35 * isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added,
36 * isa_read[wl] and isa_write[wl] fixed
37 * - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
38 */
39
40#define IO_SPACE_LIMIT 0xffff
41
42#define XQUAD_PORTIO_BASE 0xfe400000
43#define XQUAD_PORTIO_QUAD 0x40000 /* 256k per quad. */
44
45#ifdef __KERNEL__
46
47#include <asm-generic/iomap.h>
48
49#include <linux/vmalloc.h>
50
1da177e4
LT
51/*
52 * Convert a virtual cached pointer to an uncached pointer
53 */
54#define xlate_dev_kmem_ptr(p) p
55
56/**
57 * virt_to_phys - map virtual addresses to physical
58 * @address: address to remap
59 *
60 * The returned physical address is the physical (CPU) mapping for
61 * the memory address given. It is only valid to use this function on
dcd215c9 62 * addresses directly mapped or allocated via kmalloc.
1da177e4
LT
63 *
64 * This function does not give bus mappings for DMA transfers. In
65 * almost all conceivable cases a device driver should not be using
66 * this function
67 */
dcd215c9
JP
68
69static inline unsigned long virt_to_phys(volatile void *address)
1da177e4
LT
70{
71 return __pa(address);
72}
73
74/**
75 * phys_to_virt - map physical address to virtual
76 * @address: address to remap
77 *
78 * The returned virtual address is a current CPU mapping for
79 * the memory address given. It is only valid to use this function on
80 * addresses that have a kernel mapping
81 *
82 * This function does not handle bus mappings for DMA transfers. In
83 * almost all conceivable cases a device driver should not be using
84 * this function
85 */
86
dcd215c9 87static inline void *phys_to_virt(unsigned long address)
1da177e4
LT
88{
89 return __va(address);
90}
91
92/*
93 * Change "struct page" to physical address.
94 */
95#define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
96
1da177e4
LT
97/**
98 * ioremap - map bus memory into CPU space
99 * @offset: bus address of the memory
100 * @size: size of the resource to map
101 *
102 * ioremap performs a platform specific sequence of operations to
103 * make bus memory CPU accessible via the readb/readw/readl/writeb/
104 * writew/writel functions and the other mmio helpers. The returned
105 * address is not guaranteed to be usable directly as a virtual
6371b495 106 * address.
5ca24814
REB
107 *
108 * If the area you are trying to map is a PCI BAR you should have a
109 * look at pci_iomap().
1da177e4 110 */
b9e76a00
LT
111extern void __iomem *ioremap_nocache(resource_size_t offset, unsigned long size);
112extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
1da177e4 113
6371b495
IM
114/*
115 * The default ioremap() behavior is non-cached:
116 */
b9e76a00 117static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
6371b495
IM
118{
119 return ioremap_nocache(offset, size);
120}
121
1da177e4
LT
122extern void iounmap(volatile void __iomem *addr);
123
124/*
beacfaac 125 * early_ioremap() and early_iounmap() are for temporary early boot-time
1da177e4
LT
126 * mappings, before the real ioremap() is functional.
127 * A boot-time mapping is currently limited to at most 16 pages.
128 */
beacfaac
HY
129extern void early_ioremap_init(void);
130extern void early_ioremap_clear(void);
131extern void early_ioremap_reset(void);
132extern void *early_ioremap(unsigned long offset, unsigned long size);
133extern void early_iounmap(void *addr, unsigned long size);
18a8bd94 134extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys);
1da177e4 135
e9928674 136/* Use early IO mappings for DMI because it's initialized early */
beacfaac
HY
137#define dmi_ioremap early_ioremap
138#define dmi_iounmap early_iounmap
e9928674
AK
139#define dmi_alloc alloc_bootmem
140
1da177e4
LT
141/*
142 * ISA I/O bus memory addresses are 1:1 with the physical address.
143 */
144#define isa_virt_to_bus virt_to_phys
145#define isa_page_to_bus page_to_phys
146#define isa_bus_to_virt phys_to_virt
147
148/*
149 * However PCI ones are not necessarily 1:1 and therefore these interfaces
150 * are forbidden in portable PCI drivers.
151 *
152 * Allow them on x86 for legacy drivers, though.
153 */
154#define virt_to_bus virt_to_phys
155#define bus_to_virt phys_to_virt
156
157/*
158 * readX/writeX() are used to access memory mapped devices. On some
159 * architectures the memory mapped IO stuff needs to be accessed
160 * differently. On the x86 architecture, we just read/write the
161 * memory location directly.
162 */
163
164static inline unsigned char readb(const volatile void __iomem *addr)
165{
dcd215c9 166 return *(volatile unsigned char __force *)addr;
1da177e4 167}
dcd215c9 168
1da177e4
LT
169static inline unsigned short readw(const volatile void __iomem *addr)
170{
dcd215c9 171 return *(volatile unsigned short __force *)addr;
1da177e4 172}
dcd215c9 173
1da177e4
LT
174static inline unsigned int readl(const volatile void __iomem *addr)
175{
176 return *(volatile unsigned int __force *) addr;
177}
dcd215c9 178
1da177e4
LT
179#define readb_relaxed(addr) readb(addr)
180#define readw_relaxed(addr) readw(addr)
181#define readl_relaxed(addr) readl(addr)
182#define __raw_readb readb
183#define __raw_readw readw
184#define __raw_readl readl
185
186static inline void writeb(unsigned char b, volatile void __iomem *addr)
187{
dcd215c9 188 *(volatile unsigned char __force *)addr = b;
1da177e4 189}
dcd215c9 190
1da177e4
LT
191static inline void writew(unsigned short b, volatile void __iomem *addr)
192{
dcd215c9 193 *(volatile unsigned short __force *)addr = b;
1da177e4 194}
dcd215c9 195
1da177e4
LT
196static inline void writel(unsigned int b, volatile void __iomem *addr)
197{
dcd215c9 198 *(volatile unsigned int __force *)addr = b;
1da177e4
LT
199}
200#define __raw_writeb writeb
201#define __raw_writew writew
202#define __raw_writel writel
203
204#define mmiowb()
205
3c215b66
AM
206static inline void
207memset_io(volatile void __iomem *addr, unsigned char val, int count)
1da177e4 208{
3c215b66 209 memset((void __force *)addr, val, count);
1da177e4 210}
3c215b66
AM
211
212static inline void
213memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
1da177e4 214{
3c215b66 215 __memcpy(dst, (const void __force *)src, count);
1da177e4 216}
3c215b66
AM
217
218static inline void
219memcpy_toio(volatile void __iomem *dst, const void *src, int count)
1da177e4 220{
3c215b66 221 __memcpy((void __force *)dst, src, count);
1da177e4
LT
222}
223
224/*
225 * ISA space is 'always mapped' on a typical x86 system, no need to
226 * explicitly ioremap() it. The fact that the ISA IO space is mapped
227 * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
228 * are physical addresses. The following constant pointer can be
229 * used as the IO-area pointer (it can be iounmapped as well, so the
230 * analogy with PCI is quite large):
231 */
232#define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET))
233
1da177e4
LT
234/*
235 * Cache management
236 *
237 * This needed for two cases
238 * 1. Out of order aware processors
239 * 2. Accidentally out of order processors (PPro errata #51)
240 */
dcd215c9 241
1da177e4
LT
242#if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE)
243
244static inline void flush_write_buffers(void)
245{
dcd215c9 246 asm volatile("lock; addl $0,0(%%esp)": : :"memory");
1da177e4
LT
247}
248
1da177e4
LT
249#else
250
622a9edd 251#define flush_write_buffers() do { } while (0)
1da177e4
LT
252
253#endif
254
255#endif /* __KERNEL__ */
256
b02aae9c 257extern void native_io_delay(void);
90a0a06a 258
6e7c4025
IM
259extern int io_delay_type;
260extern void io_delay_init(void);
261
d3561b7f
RR
262#if defined(CONFIG_PARAVIRT)
263#include <asm/paravirt.h>
1da177e4 264#else
d3561b7f 265
dcd215c9
JP
266static inline void slow_down_io(void)
267{
90a0a06a 268 native_io_delay();
1da177e4 269#ifdef REALLY_SLOW_IO
90a0a06a
RR
270 native_io_delay();
271 native_io_delay();
272 native_io_delay();
1da177e4 273#endif
1da177e4
LT
274}
275
d3561b7f
RR
276#endif
277
dcd215c9
JP
278#define __BUILDIO(bwl, bw, type) \
279static inline void out##bwl(unsigned type value, int port) \
280{ \
281 out##bwl##_local(value, port); \
282} \
283 \
284static inline unsigned type in##bwl(int port) \
285{ \
286 return in##bwl##_local(port); \
1da177e4 287}
1da177e4 288
dcd215c9
JP
289#define BUILDIO(bwl, bw, type) \
290static inline void out##bwl##_local(unsigned type value, int port) \
291{ \
292 asm volatile("out" #bwl " %" #bw "0, %w1" \
293 : : "a"(value), "Nd"(port)); \
294} \
295 \
296static inline unsigned type in##bwl##_local(int port) \
297{ \
298 unsigned type value; \
299 asm volatile("in" #bwl " %w1, %" #bw "0" \
300 : "=a"(value) : "Nd"(port)); \
301 return value; \
302} \
303 \
304static inline void out##bwl##_local_p(unsigned type value, int port) \
305{ \
306 out##bwl##_local(value, port); \
307 slow_down_io(); \
308} \
309 \
310static inline unsigned type in##bwl##_local_p(int port) \
311{ \
312 unsigned type value = in##bwl##_local(port); \
313 slow_down_io(); \
314 return value; \
315} \
316 \
317__BUILDIO(bwl, bw, type) \
318 \
319static inline void out##bwl##_p(unsigned type value, int port) \
320{ \
321 out##bwl(value, port); \
322 slow_down_io(); \
323} \
324 \
325static inline unsigned type in##bwl##_p(int port) \
326{ \
327 unsigned type value = in##bwl(port); \
328 slow_down_io(); \
329 return value; \
330} \
331 \
332static inline void outs##bwl(int port, const void *addr, unsigned long count) \
333{ \
334 asm volatile("rep; outs" #bwl \
335 : "+S"(addr), "+c"(count) : "d"(port)); \
336} \
337 \
338static inline void ins##bwl(int port, void *addr, unsigned long count) \
339{ \
340 asm volatile("rep; ins" #bwl \
341 : "+D"(addr), "+c"(count) : "d"(port)); \
1da177e4
LT
342}
343
dcd215c9
JP
344BUILDIO(b, b, char)
345BUILDIO(w, w, short)
346BUILDIO(l, , int)
1da177e4
LT
347
348#endif