2019-06-04 16:11:37 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2008-10-31 10:38:18 +08:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 Keith Packard <keithp@keithp.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_IO_MAPPING_H
|
|
|
|
#define _LINUX_IO_MAPPING_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-11-24 09:12:59 +08:00
|
|
|
#include <linux/bug.h>
|
2015-08-11 11:07:05 +08:00
|
|
|
#include <linux/io.h>
|
2020-06-09 12:32:42 +08:00
|
|
|
#include <linux/pgtable.h>
|
2008-10-31 10:38:18 +08:00
|
|
|
#include <asm/page.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The io_mapping mechanism provides an abstraction for mapping
|
|
|
|
* individual pages from an io device to the CPU in an efficient fashion.
|
|
|
|
*
|
2020-03-11 19:51:17 +08:00
|
|
|
* See Documentation/driver-api/io-mapping.rst
|
2008-10-31 10:38:18 +08:00
|
|
|
*/
|
|
|
|
|
2009-02-25 09:35:12 +08:00
|
|
|
struct io_mapping {
|
|
|
|
resource_size_t base;
|
|
|
|
unsigned long size;
|
|
|
|
pgprot_t prot;
|
2016-08-19 23:54:26 +08:00
|
|
|
void __iomem *iomem;
|
2009-02-25 09:35:12 +08:00
|
|
|
};
|
|
|
|
|
2016-08-19 23:54:26 +08:00
|
|
|
#ifdef CONFIG_HAVE_ATOMIC_IOMAP
|
|
|
|
|
2020-01-31 14:17:32 +08:00
|
|
|
#include <linux/pfn.h>
|
2016-08-19 23:54:26 +08:00
|
|
|
#include <asm/iomap.h>
|
2008-11-04 01:21:45 +08:00
|
|
|
/*
|
|
|
|
* For small address space machines, mapping large objects
|
|
|
|
* into the kernel virtual space isn't practical. Where
|
|
|
|
* available, use fixmap support to dynamically map pages
|
|
|
|
* of the object at run time.
|
|
|
|
*/
|
2008-10-31 10:38:18 +08:00
|
|
|
|
|
|
|
static inline struct io_mapping *
|
2016-08-19 23:54:26 +08:00
|
|
|
io_mapping_init_wc(struct io_mapping *iomap,
|
|
|
|
resource_size_t base,
|
|
|
|
unsigned long size)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
2009-07-11 00:57:35 +08:00
|
|
|
pgprot_t prot;
|
2009-02-25 09:35:12 +08:00
|
|
|
|
2009-07-11 00:57:35 +08:00
|
|
|
if (iomap_create_wc(base, size, &prot))
|
2016-08-19 23:54:26 +08:00
|
|
|
return NULL;
|
2009-02-25 09:35:12 +08:00
|
|
|
|
|
|
|
iomap->base = base;
|
|
|
|
iomap->size = size;
|
2009-07-11 00:57:35 +08:00
|
|
|
iomap->prot = prot;
|
2009-02-25 09:35:12 +08:00
|
|
|
return iomap;
|
2008-10-31 10:38:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2016-08-19 23:54:26 +08:00
|
|
|
io_mapping_fini(struct io_mapping *mapping)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
2009-07-11 00:57:35 +08:00
|
|
|
iomap_free(mapping->base, mapping->size);
|
2008-10-31 10:38:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Atomic map/unmap */
|
2010-09-05 04:56:44 +08:00
|
|
|
static inline void __iomem *
|
2010-08-04 21:34:24 +08:00
|
|
|
io_mapping_map_atomic_wc(struct io_mapping *mapping,
|
2010-10-27 05:21:51 +08:00
|
|
|
unsigned long offset)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
2009-02-25 09:35:12 +08:00
|
|
|
resource_size_t phys_addr;
|
|
|
|
|
|
|
|
BUG_ON(offset >= mapping->size);
|
|
|
|
phys_addr = mapping->base + offset;
|
2020-11-03 17:27:32 +08:00
|
|
|
preempt_disable();
|
|
|
|
pagefault_disable();
|
|
|
|
return __iomap_local_pfn_prot(PHYS_PFN(phys_addr), mapping->prot);
|
2008-10-31 10:38:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2010-10-27 05:21:51 +08:00
|
|
|
io_mapping_unmap_atomic(void __iomem *vaddr)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
2020-11-03 17:27:32 +08:00
|
|
|
kunmap_local_indexed((void __force *)vaddr);
|
|
|
|
pagefault_enable();
|
|
|
|
preempt_enable();
|
2008-10-31 10:38:18 +08:00
|
|
|
}
|
|
|
|
|
2020-11-19 03:48:45 +08:00
|
|
|
static inline void __iomem *
|
|
|
|
io_mapping_map_local_wc(struct io_mapping *mapping, unsigned long offset)
|
|
|
|
{
|
|
|
|
resource_size_t phys_addr;
|
|
|
|
|
|
|
|
BUG_ON(offset >= mapping->size);
|
|
|
|
phys_addr = mapping->base + offset;
|
|
|
|
return __iomap_local_pfn_prot(PHYS_PFN(phys_addr), mapping->prot);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void io_mapping_unmap_local(void __iomem *vaddr)
|
|
|
|
{
|
|
|
|
kunmap_local_indexed((void __force *)vaddr);
|
|
|
|
}
|
|
|
|
|
2010-09-05 04:56:44 +08:00
|
|
|
static inline void __iomem *
|
2016-04-28 16:56:37 +08:00
|
|
|
io_mapping_map_wc(struct io_mapping *mapping,
|
|
|
|
unsigned long offset,
|
|
|
|
unsigned long size)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
2009-03-02 00:53:27 +08:00
|
|
|
resource_size_t phys_addr;
|
|
|
|
|
2009-02-25 09:35:12 +08:00
|
|
|
BUG_ON(offset >= mapping->size);
|
2009-03-02 00:53:27 +08:00
|
|
|
phys_addr = mapping->base + offset;
|
|
|
|
|
2016-04-28 16:56:37 +08:00
|
|
|
return ioremap_wc(phys_addr, size);
|
2008-10-31 10:38:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2010-09-05 04:56:44 +08:00
|
|
|
io_mapping_unmap(void __iomem *vaddr)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
2008-11-04 01:21:45 +08:00
|
|
|
iounmap(vaddr);
|
2008-10-31 10:38:18 +08:00
|
|
|
}
|
|
|
|
|
2020-11-19 03:48:45 +08:00
|
|
|
#else /* HAVE_ATOMIC_IOMAP */
|
2008-10-31 10:38:18 +08:00
|
|
|
|
2011-09-28 17:57:23 +08:00
|
|
|
#include <linux/uaccess.h>
|
2009-02-25 09:35:12 +08:00
|
|
|
|
2008-11-04 01:21:45 +08:00
|
|
|
/* Create the io_mapping object*/
|
2008-10-31 10:38:18 +08:00
|
|
|
static inline struct io_mapping *
|
2016-08-19 23:54:26 +08:00
|
|
|
io_mapping_init_wc(struct io_mapping *iomap,
|
|
|
|
resource_size_t base,
|
|
|
|
unsigned long size)
|
|
|
|
{
|
2020-07-24 12:15:46 +08:00
|
|
|
iomap->iomem = ioremap_wc(base, size);
|
|
|
|
if (!iomap->iomem)
|
|
|
|
return NULL;
|
|
|
|
|
2016-08-19 23:54:26 +08:00
|
|
|
iomap->base = base;
|
|
|
|
iomap->size = size;
|
2016-08-23 23:50:24 +08:00
|
|
|
iomap->prot = pgprot_writecombine(PAGE_KERNEL);
|
2016-08-19 23:54:26 +08:00
|
|
|
|
|
|
|
return iomap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
io_mapping_fini(struct io_mapping *mapping)
|
|
|
|
{
|
|
|
|
iounmap(mapping->iomem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Non-atomic map/unmap */
|
|
|
|
static inline void __iomem *
|
|
|
|
io_mapping_map_wc(struct io_mapping *mapping,
|
|
|
|
unsigned long offset,
|
|
|
|
unsigned long size)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
2016-08-19 23:54:26 +08:00
|
|
|
return mapping->iomem + offset;
|
2008-10-31 10:38:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2016-08-19 23:54:26 +08:00
|
|
|
io_mapping_unmap(void __iomem *vaddr)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Atomic map/unmap */
|
2010-09-05 04:56:44 +08:00
|
|
|
static inline void __iomem *
|
2010-08-04 21:34:24 +08:00
|
|
|
io_mapping_map_atomic_wc(struct io_mapping *mapping,
|
2010-10-27 05:21:51 +08:00
|
|
|
unsigned long offset)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
2015-05-11 23:52:09 +08:00
|
|
|
preempt_disable();
|
2011-09-28 17:57:23 +08:00
|
|
|
pagefault_disable();
|
2016-08-19 23:54:26 +08:00
|
|
|
return io_mapping_map_wc(mapping, offset, PAGE_SIZE);
|
2008-10-31 10:38:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2010-10-27 05:21:51 +08:00
|
|
|
io_mapping_unmap_atomic(void __iomem *vaddr)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
2016-08-19 23:54:26 +08:00
|
|
|
io_mapping_unmap(vaddr);
|
2011-09-28 17:57:23 +08:00
|
|
|
pagefault_enable();
|
2015-05-11 23:52:09 +08:00
|
|
|
preempt_enable();
|
2008-10-31 10:38:18 +08:00
|
|
|
}
|
|
|
|
|
2020-11-19 03:48:45 +08:00
|
|
|
static inline void __iomem *
|
|
|
|
io_mapping_map_local_wc(struct io_mapping *mapping, unsigned long offset)
|
|
|
|
{
|
|
|
|
return io_mapping_map_wc(mapping, offset, PAGE_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void io_mapping_unmap_local(void __iomem *vaddr)
|
|
|
|
{
|
|
|
|
io_mapping_unmap(vaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !HAVE_ATOMIC_IOMAP */
|
2016-08-19 23:54:26 +08:00
|
|
|
|
|
|
|
static inline struct io_mapping *
|
|
|
|
io_mapping_create_wc(resource_size_t base,
|
|
|
|
unsigned long size)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
2016-08-19 23:54:26 +08:00
|
|
|
struct io_mapping *iomap;
|
|
|
|
|
|
|
|
iomap = kmalloc(sizeof(*iomap), GFP_KERNEL);
|
|
|
|
if (!iomap)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!io_mapping_init_wc(iomap, base, size)) {
|
|
|
|
kfree(iomap);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iomap;
|
2008-10-31 10:38:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2016-08-19 23:54:26 +08:00
|
|
|
io_mapping_free(struct io_mapping *iomap)
|
2008-10-31 10:38:18 +08:00
|
|
|
{
|
2016-08-19 23:54:26 +08:00
|
|
|
io_mapping_fini(iomap);
|
|
|
|
kfree(iomap);
|
2008-10-31 10:38:18 +08:00
|
|
|
}
|
2008-11-04 01:21:45 +08:00
|
|
|
|
2008-10-31 10:38:18 +08:00
|
|
|
#endif /* _LINUX_IO_MAPPING_H */
|
2021-04-30 13:57:32 +08:00
|
|
|
|
|
|
|
int io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma,
|
|
|
|
unsigned long addr, unsigned long pfn, unsigned long size);
|