2008-10-31 09:38:18 +07:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 Keith Packard <keithp@keithp.com>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of version 2 of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2011-11-24 08:12:59 +07:00
|
|
|
#include <linux/bug.h>
|
2015-08-11 10:07:05 +07:00
|
|
|
#include <linux/io.h>
|
2008-10-31 09:38:18 +07: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.
|
|
|
|
*
|
2011-08-15 07:02:26 +07:00
|
|
|
* See Documentation/io-mapping.txt
|
2008-10-31 09:38:18 +07:00
|
|
|
*/
|
|
|
|
|
2009-02-25 08:35:12 +07:00
|
|
|
struct io_mapping {
|
|
|
|
resource_size_t base;
|
|
|
|
unsigned long size;
|
|
|
|
pgprot_t prot;
|
2016-08-19 22:54:26 +07:00
|
|
|
void __iomem *iomem;
|
2009-02-25 08:35:12 +07:00
|
|
|
};
|
|
|
|
|
2016-08-19 22:54:26 +07:00
|
|
|
#ifdef CONFIG_HAVE_ATOMIC_IOMAP
|
|
|
|
|
|
|
|
#include <asm/iomap.h>
|
2008-11-04 00:21:45 +07: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 09:38:18 +07:00
|
|
|
|
|
|
|
static inline struct io_mapping *
|
2016-08-19 22:54:26 +07:00
|
|
|
io_mapping_init_wc(struct io_mapping *iomap,
|
|
|
|
resource_size_t base,
|
|
|
|
unsigned long size)
|
2008-10-31 09:38:18 +07:00
|
|
|
{
|
2009-07-10 23:57:35 +07:00
|
|
|
pgprot_t prot;
|
2009-02-25 08:35:12 +07:00
|
|
|
|
2009-07-10 23:57:35 +07:00
|
|
|
if (iomap_create_wc(base, size, &prot))
|
2016-08-19 22:54:26 +07:00
|
|
|
return NULL;
|
2009-02-25 08:35:12 +07:00
|
|
|
|
|
|
|
iomap->base = base;
|
|
|
|
iomap->size = size;
|
2009-07-10 23:57:35 +07:00
|
|
|
iomap->prot = prot;
|
2009-02-25 08:35:12 +07:00
|
|
|
return iomap;
|
2008-10-31 09:38:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2016-08-19 22:54:26 +07:00
|
|
|
io_mapping_fini(struct io_mapping *mapping)
|
2008-10-31 09:38:18 +07:00
|
|
|
{
|
2009-07-10 23:57:35 +07:00
|
|
|
iomap_free(mapping->base, mapping->size);
|
2008-10-31 09:38:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Atomic map/unmap */
|
2010-09-05 03:56:44 +07:00
|
|
|
static inline void __iomem *
|
2010-08-04 20:34:24 +07:00
|
|
|
io_mapping_map_atomic_wc(struct io_mapping *mapping,
|
2010-10-27 04:21:51 +07:00
|
|
|
unsigned long offset)
|
2008-10-31 09:38:18 +07:00
|
|
|
{
|
2009-02-25 08:35:12 +07:00
|
|
|
resource_size_t phys_addr;
|
|
|
|
unsigned long pfn;
|
|
|
|
|
|
|
|
BUG_ON(offset >= mapping->size);
|
|
|
|
phys_addr = mapping->base + offset;
|
|
|
|
pfn = (unsigned long) (phys_addr >> PAGE_SHIFT);
|
2010-10-27 04:21:51 +07:00
|
|
|
return iomap_atomic_prot_pfn(pfn, mapping->prot);
|
2008-10-31 09:38:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2010-10-27 04:21:51 +07:00
|
|
|
io_mapping_unmap_atomic(void __iomem *vaddr)
|
2008-10-31 09:38:18 +07:00
|
|
|
{
|
2010-10-27 04:21:51 +07:00
|
|
|
iounmap_atomic(vaddr);
|
2008-10-31 09:38:18 +07:00
|
|
|
}
|
|
|
|
|
2010-09-05 03:56:44 +07:00
|
|
|
static inline void __iomem *
|
2016-04-28 15:56:37 +07:00
|
|
|
io_mapping_map_wc(struct io_mapping *mapping,
|
|
|
|
unsigned long offset,
|
|
|
|
unsigned long size)
|
2008-10-31 09:38:18 +07:00
|
|
|
{
|
2009-03-01 23:53:27 +07:00
|
|
|
resource_size_t phys_addr;
|
|
|
|
|
2009-02-25 08:35:12 +07:00
|
|
|
BUG_ON(offset >= mapping->size);
|
2009-03-01 23:53:27 +07:00
|
|
|
phys_addr = mapping->base + offset;
|
|
|
|
|
2016-04-28 15:56:37 +07:00
|
|
|
return ioremap_wc(phys_addr, size);
|
2008-10-31 09:38:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2010-09-05 03:56:44 +07:00
|
|
|
io_mapping_unmap(void __iomem *vaddr)
|
2008-10-31 09:38:18 +07:00
|
|
|
{
|
2008-11-04 00:21:45 +07:00
|
|
|
iounmap(vaddr);
|
2008-10-31 09:38:18 +07:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:21:45 +07:00
|
|
|
#else
|
2008-10-31 09:38:18 +07:00
|
|
|
|
2011-09-28 16:57:23 +07:00
|
|
|
#include <linux/uaccess.h>
|
2016-08-23 22:50:24 +07:00
|
|
|
#include <asm/pgtable.h>
|
2009-02-25 08:35:12 +07:00
|
|
|
|
2008-11-04 00:21:45 +07:00
|
|
|
/* Create the io_mapping object*/
|
2008-10-31 09:38:18 +07:00
|
|
|
static inline struct io_mapping *
|
2016-08-19 22:54:26 +07:00
|
|
|
io_mapping_init_wc(struct io_mapping *iomap,
|
|
|
|
resource_size_t base,
|
|
|
|
unsigned long size)
|
|
|
|
{
|
|
|
|
iomap->base = base;
|
|
|
|
iomap->size = size;
|
|
|
|
iomap->iomem = ioremap_wc(base, size);
|
2016-08-24 03:15:02 +07:00
|
|
|
#if defined(pgprot_noncached_wc) /* archs can't agree on a name ... */
|
|
|
|
iomap->prot = pgprot_noncached_wc(PAGE_KERNEL);
|
|
|
|
#elif defined(pgprot_writecombine)
|
2016-08-23 22:50:24 +07:00
|
|
|
iomap->prot = pgprot_writecombine(PAGE_KERNEL);
|
2016-08-24 03:15:02 +07:00
|
|
|
#else
|
|
|
|
iomap->prot = pgprot_noncached(PAGE_KERNEL);
|
|
|
|
#endif
|
2016-08-19 22:54:26 +07: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 09:38:18 +07:00
|
|
|
{
|
2016-08-19 22:54:26 +07:00
|
|
|
return mapping->iomem + offset;
|
2008-10-31 09:38:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2016-08-19 22:54:26 +07:00
|
|
|
io_mapping_unmap(void __iomem *vaddr)
|
2008-10-31 09:38:18 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Atomic map/unmap */
|
2010-09-05 03:56:44 +07:00
|
|
|
static inline void __iomem *
|
2010-08-04 20:34:24 +07:00
|
|
|
io_mapping_map_atomic_wc(struct io_mapping *mapping,
|
2010-10-27 04:21:51 +07:00
|
|
|
unsigned long offset)
|
2008-10-31 09:38:18 +07:00
|
|
|
{
|
2015-05-11 22:52:09 +07:00
|
|
|
preempt_disable();
|
2011-09-28 16:57:23 +07:00
|
|
|
pagefault_disable();
|
2016-08-19 22:54:26 +07:00
|
|
|
return io_mapping_map_wc(mapping, offset, PAGE_SIZE);
|
2008-10-31 09:38:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2010-10-27 04:21:51 +07:00
|
|
|
io_mapping_unmap_atomic(void __iomem *vaddr)
|
2008-10-31 09:38:18 +07:00
|
|
|
{
|
2016-08-19 22:54:26 +07:00
|
|
|
io_mapping_unmap(vaddr);
|
2011-09-28 16:57:23 +07:00
|
|
|
pagefault_enable();
|
2015-05-11 22:52:09 +07:00
|
|
|
preempt_enable();
|
2008-10-31 09:38:18 +07:00
|
|
|
}
|
|
|
|
|
2016-08-19 22:54:26 +07:00
|
|
|
#endif /* HAVE_ATOMIC_IOMAP */
|
|
|
|
|
|
|
|
static inline struct io_mapping *
|
|
|
|
io_mapping_create_wc(resource_size_t base,
|
|
|
|
unsigned long size)
|
2008-10-31 09:38:18 +07:00
|
|
|
{
|
2016-08-19 22:54:26 +07: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 09:38:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2016-08-19 22:54:26 +07:00
|
|
|
io_mapping_free(struct io_mapping *iomap)
|
2008-10-31 09:38:18 +07:00
|
|
|
{
|
2016-08-19 22:54:26 +07:00
|
|
|
io_mapping_fini(iomap);
|
|
|
|
kfree(iomap);
|
2008-10-31 09:38:18 +07:00
|
|
|
}
|
2008-11-04 00:21:45 +07:00
|
|
|
|
2008-10-31 09:38:18 +07:00
|
|
|
#endif /* _LINUX_IO_MAPPING_H */
|