xref: /OK3568_Linux_fs/kernel/include/linux/io.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright 2006 PathScale, Inc.  All Rights Reserved.
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #ifndef _LINUX_IO_H
7*4882a593Smuzhiyun #define _LINUX_IO_H
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/types.h>
10*4882a593Smuzhiyun #include <linux/init.h>
11*4882a593Smuzhiyun #include <linux/bug.h>
12*4882a593Smuzhiyun #include <linux/err.h>
13*4882a593Smuzhiyun #include <asm/io.h>
14*4882a593Smuzhiyun #include <asm/page.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun struct device;
17*4882a593Smuzhiyun struct resource;
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun __visible void __iowrite32_copy(void __iomem *to, const void *from, size_t count);
20*4882a593Smuzhiyun void __ioread32_copy(void *to, const void __iomem *from, size_t count);
21*4882a593Smuzhiyun void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #ifdef CONFIG_MMU
24*4882a593Smuzhiyun int ioremap_page_range(unsigned long addr, unsigned long end,
25*4882a593Smuzhiyun 		       phys_addr_t phys_addr, pgprot_t prot);
26*4882a593Smuzhiyun #else
ioremap_page_range(unsigned long addr,unsigned long end,phys_addr_t phys_addr,pgprot_t prot)27*4882a593Smuzhiyun static inline int ioremap_page_range(unsigned long addr, unsigned long end,
28*4882a593Smuzhiyun 				     phys_addr_t phys_addr, pgprot_t prot)
29*4882a593Smuzhiyun {
30*4882a593Smuzhiyun 	return 0;
31*4882a593Smuzhiyun }
32*4882a593Smuzhiyun #endif
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
35*4882a593Smuzhiyun void __init ioremap_huge_init(void);
36*4882a593Smuzhiyun int arch_ioremap_p4d_supported(void);
37*4882a593Smuzhiyun int arch_ioremap_pud_supported(void);
38*4882a593Smuzhiyun int arch_ioremap_pmd_supported(void);
39*4882a593Smuzhiyun #else
ioremap_huge_init(void)40*4882a593Smuzhiyun static inline void ioremap_huge_init(void) { }
41*4882a593Smuzhiyun #endif
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /*
44*4882a593Smuzhiyun  * Managed iomap interface
45*4882a593Smuzhiyun  */
46*4882a593Smuzhiyun #ifdef CONFIG_HAS_IOPORT_MAP
47*4882a593Smuzhiyun void __iomem * devm_ioport_map(struct device *dev, unsigned long port,
48*4882a593Smuzhiyun 			       unsigned int nr);
49*4882a593Smuzhiyun void devm_ioport_unmap(struct device *dev, void __iomem *addr);
50*4882a593Smuzhiyun #else
devm_ioport_map(struct device * dev,unsigned long port,unsigned int nr)51*4882a593Smuzhiyun static inline void __iomem *devm_ioport_map(struct device *dev,
52*4882a593Smuzhiyun 					     unsigned long port,
53*4882a593Smuzhiyun 					     unsigned int nr)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun 	return NULL;
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun 
devm_ioport_unmap(struct device * dev,void __iomem * addr)58*4882a593Smuzhiyun static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun #endif
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun #define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err)
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
66*4882a593Smuzhiyun 			   resource_size_t size);
67*4882a593Smuzhiyun void __iomem *devm_ioremap_uc(struct device *dev, resource_size_t offset,
68*4882a593Smuzhiyun 				   resource_size_t size);
69*4882a593Smuzhiyun void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
70*4882a593Smuzhiyun 				   resource_size_t size);
71*4882a593Smuzhiyun void devm_iounmap(struct device *dev, void __iomem *addr);
72*4882a593Smuzhiyun int check_signature(const volatile void __iomem *io_addr,
73*4882a593Smuzhiyun 			const unsigned char *signature, int length);
74*4882a593Smuzhiyun void devm_ioremap_release(struct device *dev, void *res);
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun void *devm_memremap(struct device *dev, resource_size_t offset,
77*4882a593Smuzhiyun 		size_t size, unsigned long flags);
78*4882a593Smuzhiyun void devm_memunmap(struct device *dev, void *addr);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun #ifdef CONFIG_PCI
81*4882a593Smuzhiyun /*
82*4882a593Smuzhiyun  * The PCI specifications (Rev 3.0, 3.2.5 "Transaction Ordering and
83*4882a593Smuzhiyun  * Posting") mandate non-posted configuration transactions. There is
84*4882a593Smuzhiyun  * no ioremap API in the kernel that can guarantee non-posted write
85*4882a593Smuzhiyun  * semantics across arches so provide a default implementation for
86*4882a593Smuzhiyun  * mapping PCI config space that defaults to ioremap(); arches
87*4882a593Smuzhiyun  * should override it if they have memory mapping implementations that
88*4882a593Smuzhiyun  * guarantee non-posted writes semantics to make the memory mapping
89*4882a593Smuzhiyun  * compliant with the PCI specification.
90*4882a593Smuzhiyun  */
91*4882a593Smuzhiyun #ifndef pci_remap_cfgspace
92*4882a593Smuzhiyun #define pci_remap_cfgspace pci_remap_cfgspace
pci_remap_cfgspace(phys_addr_t offset,size_t size)93*4882a593Smuzhiyun static inline void __iomem *pci_remap_cfgspace(phys_addr_t offset,
94*4882a593Smuzhiyun 					       size_t size)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun 	return ioremap(offset, size);
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun #endif
99*4882a593Smuzhiyun #endif
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /*
102*4882a593Smuzhiyun  * Some systems do not have legacy ISA devices.
103*4882a593Smuzhiyun  * /dev/port is not a valid interface on these systems.
104*4882a593Smuzhiyun  * So for those archs, <asm/io.h> should define the following symbol.
105*4882a593Smuzhiyun  */
106*4882a593Smuzhiyun #ifndef arch_has_dev_port
107*4882a593Smuzhiyun #define arch_has_dev_port()     (1)
108*4882a593Smuzhiyun #endif
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun /*
111*4882a593Smuzhiyun  * Some systems (x86 without PAT) have a somewhat reliable way to mark a
112*4882a593Smuzhiyun  * physical address range such that uncached mappings will actually
113*4882a593Smuzhiyun  * end up write-combining.  This facility should be used in conjunction
114*4882a593Smuzhiyun  * with pgprot_writecombine, ioremap-wc, or set_memory_wc, since it has
115*4882a593Smuzhiyun  * no effect if the per-page mechanisms are functional.
116*4882a593Smuzhiyun  * (On x86 without PAT, these functions manipulate MTRRs.)
117*4882a593Smuzhiyun  *
118*4882a593Smuzhiyun  * arch_phys_del_wc(0) or arch_phys_del_wc(any error code) is guaranteed
119*4882a593Smuzhiyun  * to have no effect.
120*4882a593Smuzhiyun  */
121*4882a593Smuzhiyun #ifndef arch_phys_wc_add
arch_phys_wc_add(unsigned long base,unsigned long size)122*4882a593Smuzhiyun static inline int __must_check arch_phys_wc_add(unsigned long base,
123*4882a593Smuzhiyun 						unsigned long size)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun 	return 0;  /* It worked (i.e. did nothing). */
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun 
arch_phys_wc_del(int handle)128*4882a593Smuzhiyun static inline void arch_phys_wc_del(int handle)
129*4882a593Smuzhiyun {
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun #define arch_phys_wc_add arch_phys_wc_add
133*4882a593Smuzhiyun #ifndef arch_phys_wc_index
arch_phys_wc_index(int handle)134*4882a593Smuzhiyun static inline int arch_phys_wc_index(int handle)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun 	return -1;
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun #define arch_phys_wc_index arch_phys_wc_index
139*4882a593Smuzhiyun #endif
140*4882a593Smuzhiyun #endif
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun enum {
143*4882a593Smuzhiyun 	/* See memremap() kernel-doc for usage description... */
144*4882a593Smuzhiyun 	MEMREMAP_WB = 1 << 0,
145*4882a593Smuzhiyun 	MEMREMAP_WT = 1 << 1,
146*4882a593Smuzhiyun 	MEMREMAP_WC = 1 << 2,
147*4882a593Smuzhiyun 	MEMREMAP_ENC = 1 << 3,
148*4882a593Smuzhiyun 	MEMREMAP_DEC = 1 << 4,
149*4882a593Smuzhiyun };
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun void *memremap(resource_size_t offset, size_t size, unsigned long flags);
152*4882a593Smuzhiyun void memunmap(void *addr);
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun /*
155*4882a593Smuzhiyun  * On x86 PAT systems we have memory tracking that keeps track of
156*4882a593Smuzhiyun  * the allowed mappings on memory ranges. This tracking works for
157*4882a593Smuzhiyun  * all the in-kernel mapping APIs (ioremap*), but where the user
158*4882a593Smuzhiyun  * wishes to map a range from a physical device into user memory
159*4882a593Smuzhiyun  * the tracking won't be updated. This API is to be used by
160*4882a593Smuzhiyun  * drivers which remap physical device pages into userspace,
161*4882a593Smuzhiyun  * and wants to make sure they are mapped WC and not UC.
162*4882a593Smuzhiyun  */
163*4882a593Smuzhiyun #ifndef arch_io_reserve_memtype_wc
arch_io_reserve_memtype_wc(resource_size_t base,resource_size_t size)164*4882a593Smuzhiyun static inline int arch_io_reserve_memtype_wc(resource_size_t base,
165*4882a593Smuzhiyun 					     resource_size_t size)
166*4882a593Smuzhiyun {
167*4882a593Smuzhiyun 	return 0;
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun 
arch_io_free_memtype_wc(resource_size_t base,resource_size_t size)170*4882a593Smuzhiyun static inline void arch_io_free_memtype_wc(resource_size_t base,
171*4882a593Smuzhiyun 					   resource_size_t size)
172*4882a593Smuzhiyun {
173*4882a593Smuzhiyun }
174*4882a593Smuzhiyun #endif
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun #endif /* _LINUX_IO_H */
177