File Index
Files and directories
Sign in
FILE

io.h

File preview with syntax highlighting.

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