License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
|
/*
|
|
|
|
|
* linux/arch/alpha/kernel/pci_iommu.c
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
|
#include <linux/mm.h>
|
|
|
|
|
#include <linux/pci.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/gfp.h>
|
2018-10-31 06:09:49 +08:00
|
|
|
|
#include <linux/memblock.h>
|
2011-08-02 01:50:15 +08:00
|
|
|
|
#include <linux/export.h>
|
2007-10-23 18:31:05 +08:00
|
|
|
|
#include <linux/scatterlist.h>
|
2007-05-30 07:01:35 +08:00
|
|
|
|
#include <linux/log2.h>
|
2008-02-05 14:27:58 +08:00
|
|
|
|
#include <linux/dma-mapping.h>
|
2008-03-14 03:32:40 +08:00
|
|
|
|
#include <linux/iommu-helper.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
#include <asm/hwrpb.h>
|
|
|
|
|
|
|
|
|
|
#include "proto.h"
|
|
|
|
|
#include "pci_impl.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define DEBUG_ALLOC 0
|
|
|
|
|
#if DEBUG_ALLOC > 0
|
|
|
|
|
# define DBGA(args...) printk(KERN_DEBUG args)
|
|
|
|
|
#else
|
|
|
|
|
# define DBGA(args...)
|
|
|
|
|
#endif
|
|
|
|
|
#if DEBUG_ALLOC > 1
|
|
|
|
|
# define DBGA2(args...) printk(KERN_DEBUG args)
|
|
|
|
|
#else
|
|
|
|
|
# define DBGA2(args...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define DEBUG_NODIRECT 0
|
|
|
|
|
|
|
|
|
|
#define ISA_DMA_MASK 0x00ffffff
|
|
|
|
|
|
|
|
|
|
static inline unsigned long
|
|
|
|
|
mk_iommu_pte(unsigned long paddr)
|
|
|
|
|
{
|
|
|
|
|
return (paddr >> (PAGE_SHIFT-1)) | 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return the minimum of MAX or the first power of two larger
|
|
|
|
|
than main memory. */
|
|
|
|
|
|
|
|
|
|
unsigned long
|
|
|
|
|
size_for_memory(unsigned long max)
|
|
|
|
|
{
|
|
|
|
|
unsigned long mem = max_low_pfn << PAGE_SHIFT;
|
|
|
|
|
if (mem < max)
|
2007-05-30 07:01:35 +08:00
|
|
|
|
max = roundup_pow_of_two(mem);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-27 00:34:19 +08:00
|
|
|
|
struct pci_iommu_arena * __init
|
2005-04-17 06:20:36 +08:00
|
|
|
|
iommu_arena_new_node(int nid, struct pci_controller *hose, dma_addr_t base,
|
|
|
|
|
unsigned long window_size, unsigned long align)
|
|
|
|
|
{
|
|
|
|
|
unsigned long mem_size;
|
|
|
|
|
struct pci_iommu_arena *arena;
|
|
|
|
|
|
|
|
|
|
mem_size = window_size / (PAGE_SIZE / sizeof(unsigned long));
|
|
|
|
|
|
|
|
|
|
/* Note that the TLB lookup logic uses bitwise concatenation,
|
|
|
|
|
not addition, so the required arena alignment is based on
|
|
|
|
|
the size of the window. Retain the align parameter so that
|
|
|
|
|
particular systems can over-align the arena. */
|
|
|
|
|
if (align < mem_size)
|
|
|
|
|
align = mem_size;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_DISCONTIGMEM
|
|
|
|
|
|
2018-10-31 06:08:49 +08:00
|
|
|
|
arena = memblock_alloc_node(sizeof(*arena), align, nid);
|
2008-04-28 17:13:46 +08:00
|
|
|
|
if (!NODE_DATA(nid) || !arena) {
|
|
|
|
|
printk("%s: couldn't allocate arena from node %d\n"
|
|
|
|
|
" falling back to system-wide allocation\n",
|
|
|
|
|
__func__, nid);
|
memblock: stop using implicit alignment to SMP_CACHE_BYTES
When a memblock allocation APIs are called with align = 0, the alignment
is implicitly set to SMP_CACHE_BYTES.
Implicit alignment is done deep in the memblock allocator and it can
come as a surprise. Not that such an alignment would be wrong even
when used incorrectly but it is better to be explicit for the sake of
clarity and the prinicple of the least surprise.
Replace all such uses of memblock APIs with the 'align' parameter
explicitly set to SMP_CACHE_BYTES and stop implicit alignment assignment
in the memblock internal allocation functions.
For the case when memblock APIs are used via helper functions, e.g. like
iommu_arena_new_node() in Alpha, the helper functions were detected with
Coccinelle's help and then manually examined and updated where
appropriate.
The direct memblock APIs users were updated using the semantic patch below:
@@
expression size, min_addr, max_addr, nid;
@@
(
|
- memblock_alloc_try_nid_raw(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_raw(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid_nopanic(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_nopanic(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, nid)
|
- memblock_alloc(size, 0)
+ memblock_alloc(size, SMP_CACHE_BYTES)
|
- memblock_alloc_raw(size, 0)
+ memblock_alloc_raw(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from(size, 0, min_addr)
+ memblock_alloc_from(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_nopanic(size, 0)
+ memblock_alloc_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low(size, 0)
+ memblock_alloc_low(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low_nopanic(size, 0)
+ memblock_alloc_low_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from_nopanic(size, 0, min_addr)
+ memblock_alloc_from_nopanic(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_node(size, 0, nid)
+ memblock_alloc_node(size, SMP_CACHE_BYTES, nid)
)
[mhocko@suse.com: changelog update]
[akpm@linux-foundation.org: coding-style fixes]
[rppt@linux.ibm.com: fix missed uses of implicit alignment]
Link: http://lkml.kernel.org/r/20181016133656.GA10925@rapoport-lnx
Link: http://lkml.kernel.org/r/1538687224-17535-1-git-send-email-rppt@linux.vnet.ibm.com
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Suggested-by: Michal Hocko <mhocko@suse.com>
Acked-by: Paul Burton <paul.burton@mips.com> [MIPS]
Acked-by: Michael Ellerman <mpe@ellerman.id.au> [powerpc]
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Richard Weinberger <richard@nod.at>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-31 06:09:57 +08:00
|
|
|
|
arena = memblock_alloc(sizeof(*arena), SMP_CACHE_BYTES);
|
2019-03-12 14:30:31 +08:00
|
|
|
|
if (!arena)
|
|
|
|
|
panic("%s: Failed to allocate %zu bytes\n", __func__,
|
|
|
|
|
sizeof(*arena));
|
2008-04-28 17:13:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 06:08:49 +08:00
|
|
|
|
arena->ptes = memblock_alloc_node(sizeof(*arena), align, nid);
|
2008-04-28 17:13:46 +08:00
|
|
|
|
if (!NODE_DATA(nid) || !arena->ptes) {
|
|
|
|
|
printk("%s: couldn't allocate arena ptes from node %d\n"
|
|
|
|
|
" falling back to system-wide allocation\n",
|
|
|
|
|
__func__, nid);
|
2019-03-12 14:29:50 +08:00
|
|
|
|
arena->ptes = memblock_alloc(mem_size, align);
|
2019-03-12 14:30:31 +08:00
|
|
|
|
if (!arena->ptes)
|
|
|
|
|
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
|
|
|
|
|
__func__, mem_size, align);
|
2008-04-28 17:13:46 +08:00
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
#else /* CONFIG_DISCONTIGMEM */
|
|
|
|
|
|
memblock: stop using implicit alignment to SMP_CACHE_BYTES
When a memblock allocation APIs are called with align = 0, the alignment
is implicitly set to SMP_CACHE_BYTES.
Implicit alignment is done deep in the memblock allocator and it can
come as a surprise. Not that such an alignment would be wrong even
when used incorrectly but it is better to be explicit for the sake of
clarity and the prinicple of the least surprise.
Replace all such uses of memblock APIs with the 'align' parameter
explicitly set to SMP_CACHE_BYTES and stop implicit alignment assignment
in the memblock internal allocation functions.
For the case when memblock APIs are used via helper functions, e.g. like
iommu_arena_new_node() in Alpha, the helper functions were detected with
Coccinelle's help and then manually examined and updated where
appropriate.
The direct memblock APIs users were updated using the semantic patch below:
@@
expression size, min_addr, max_addr, nid;
@@
(
|
- memblock_alloc_try_nid_raw(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_raw(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid_nopanic(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_nopanic(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, nid)
|
- memblock_alloc(size, 0)
+ memblock_alloc(size, SMP_CACHE_BYTES)
|
- memblock_alloc_raw(size, 0)
+ memblock_alloc_raw(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from(size, 0, min_addr)
+ memblock_alloc_from(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_nopanic(size, 0)
+ memblock_alloc_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low(size, 0)
+ memblock_alloc_low(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low_nopanic(size, 0)
+ memblock_alloc_low_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from_nopanic(size, 0, min_addr)
+ memblock_alloc_from_nopanic(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_node(size, 0, nid)
+ memblock_alloc_node(size, SMP_CACHE_BYTES, nid)
)
[mhocko@suse.com: changelog update]
[akpm@linux-foundation.org: coding-style fixes]
[rppt@linux.ibm.com: fix missed uses of implicit alignment]
Link: http://lkml.kernel.org/r/20181016133656.GA10925@rapoport-lnx
Link: http://lkml.kernel.org/r/1538687224-17535-1-git-send-email-rppt@linux.vnet.ibm.com
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Suggested-by: Michal Hocko <mhocko@suse.com>
Acked-by: Paul Burton <paul.burton@mips.com> [MIPS]
Acked-by: Michael Ellerman <mpe@ellerman.id.au> [powerpc]
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Richard Weinberger <richard@nod.at>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-31 06:09:57 +08:00
|
|
|
|
arena = memblock_alloc(sizeof(*arena), SMP_CACHE_BYTES);
|
2019-03-12 14:30:31 +08:00
|
|
|
|
if (!arena)
|
|
|
|
|
panic("%s: Failed to allocate %zu bytes\n", __func__,
|
|
|
|
|
sizeof(*arena));
|
2019-03-12 14:29:50 +08:00
|
|
|
|
arena->ptes = memblock_alloc(mem_size, align);
|
2019-03-12 14:30:31 +08:00
|
|
|
|
if (!arena->ptes)
|
|
|
|
|
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
|
|
|
|
|
__func__, mem_size, align);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
#endif /* CONFIG_DISCONTIGMEM */
|
|
|
|
|
|
|
|
|
|
spin_lock_init(&arena->lock);
|
|
|
|
|
arena->hose = hose;
|
|
|
|
|
arena->dma_base = base;
|
|
|
|
|
arena->size = window_size;
|
|
|
|
|
arena->next_entry = 0;
|
|
|
|
|
|
|
|
|
|
/* Align allocations to a multiple of a page size. Not needed
|
|
|
|
|
unless there are chip bugs. */
|
|
|
|
|
arena->align_entry = 1;
|
|
|
|
|
|
|
|
|
|
return arena;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-27 00:34:19 +08:00
|
|
|
|
struct pci_iommu_arena * __init
|
2005-04-17 06:20:36 +08:00
|
|
|
|
iommu_arena_new(struct pci_controller *hose, dma_addr_t base,
|
|
|
|
|
unsigned long window_size, unsigned long align)
|
|
|
|
|
{
|
|
|
|
|
return iommu_arena_new_node(0, hose, base, window_size, align);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Must be called with the arena lock held */
|
|
|
|
|
static long
|
2008-03-05 06:28:57 +08:00
|
|
|
|
iommu_arena_find_pages(struct device *dev, struct pci_iommu_arena *arena,
|
|
|
|
|
long n, long mask)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned long *ptes;
|
|
|
|
|
long i, p, nent;
|
2008-03-05 06:28:57 +08:00
|
|
|
|
int pass = 0;
|
2008-03-05 06:28:57 +08:00
|
|
|
|
unsigned long base;
|
|
|
|
|
unsigned long boundary_size;
|
|
|
|
|
|
|
|
|
|
base = arena->dma_base >> PAGE_SHIFT;
|
2008-03-09 21:31:17 +08:00
|
|
|
|
if (dev) {
|
|
|
|
|
boundary_size = dma_get_seg_boundary(dev) + 1;
|
|
|
|
|
boundary_size >>= PAGE_SHIFT;
|
|
|
|
|
} else {
|
|
|
|
|
boundary_size = 1UL << (32 - PAGE_SHIFT);
|
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
/* Search forward for the first mask-aligned sequence of N free ptes */
|
|
|
|
|
ptes = arena->ptes;
|
|
|
|
|
nent = arena->size >> PAGE_SHIFT;
|
2008-03-05 06:28:54 +08:00
|
|
|
|
p = ALIGN(arena->next_entry, mask + 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
i = 0;
|
2008-03-05 06:28:57 +08:00
|
|
|
|
|
|
|
|
|
again:
|
2005-04-17 06:20:36 +08:00
|
|
|
|
while (i < n && p+i < nent) {
|
2008-03-14 03:32:40 +08:00
|
|
|
|
if (!i && iommu_is_span_boundary(p, n, base, boundary_size)) {
|
2008-03-05 06:28:57 +08:00
|
|
|
|
p = ALIGN(p + 1, mask + 1);
|
|
|
|
|
goto again;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (ptes[p+i])
|
2008-03-05 06:28:54 +08:00
|
|
|
|
p = ALIGN(p + i + 1, mask + 1), i = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
else
|
|
|
|
|
i = i + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i < n) {
|
2008-03-05 06:28:57 +08:00
|
|
|
|
if (pass < 1) {
|
|
|
|
|
/*
|
|
|
|
|
* Reached the end. Flush the TLB and restart
|
|
|
|
|
* the search from the beginning.
|
|
|
|
|
*/
|
|
|
|
|
alpha_mv.mv_pci_tbi(arena->hose, 0, -1);
|
|
|
|
|
|
|
|
|
|
pass++;
|
|
|
|
|
p = 0;
|
|
|
|
|
i = 0;
|
|
|
|
|
goto again;
|
|
|
|
|
} else
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Success. It's the responsibility of the caller to mark them
|
|
|
|
|
in use before releasing the lock */
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static long
|
2008-03-05 06:28:57 +08:00
|
|
|
|
iommu_arena_alloc(struct device *dev, struct pci_iommu_arena *arena, long n,
|
|
|
|
|
unsigned int align)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
unsigned long *ptes;
|
|
|
|
|
long i, p, mask;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&arena->lock, flags);
|
|
|
|
|
|
|
|
|
|
/* Search for N empty ptes */
|
|
|
|
|
ptes = arena->ptes;
|
|
|
|
|
mask = max(align, arena->align_entry) - 1;
|
2008-03-05 06:28:57 +08:00
|
|
|
|
p = iommu_arena_find_pages(dev, arena, n, mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (p < 0) {
|
|
|
|
|
spin_unlock_irqrestore(&arena->lock, flags);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Success. Mark them all in use, ie not zero and invalid
|
|
|
|
|
for the iommu tlb that could load them from under us.
|
|
|
|
|
The chip specific bits will fill this in with something
|
|
|
|
|
kosher when we return. */
|
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
|
ptes[p+i] = IOMMU_INVALID_PTE;
|
|
|
|
|
|
|
|
|
|
arena->next_entry = p + n;
|
|
|
|
|
spin_unlock_irqrestore(&arena->lock, flags);
|
|
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
iommu_arena_free(struct pci_iommu_arena *arena, long ofs, long n)
|
|
|
|
|
{
|
|
|
|
|
unsigned long *p;
|
|
|
|
|
long i;
|
|
|
|
|
|
|
|
|
|
p = arena->ptes + ofs;
|
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
|
p[i] = 0;
|
|
|
|
|
}
|
2010-03-11 07:23:37 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* True if the machine supports DAC addressing, and DEV can
|
|
|
|
|
* make use of it given MASK.
|
|
|
|
|
*/
|
|
|
|
|
static int pci_dac_dma_supported(struct pci_dev *dev, u64 mask)
|
|
|
|
|
{
|
2010-10-28 06:34:48 +08:00
|
|
|
|
dma_addr_t dac_offset = alpha_mv.pci_dac_offset;
|
2010-03-11 07:23:37 +08:00
|
|
|
|
int ok = 1;
|
|
|
|
|
|
|
|
|
|
/* If this is not set, the machine doesn't support DAC at all. */
|
|
|
|
|
if (dac_offset == 0)
|
|
|
|
|
ok = 0;
|
|
|
|
|
|
|
|
|
|
/* The device has to be able to address our DAC bit. */
|
|
|
|
|
if ((dac_offset & dev->dma_mask) != dac_offset)
|
|
|
|
|
ok = 0;
|
|
|
|
|
|
|
|
|
|
/* If both conditions above are met, we are fine. */
|
2012-02-29 02:49:31 +08:00
|
|
|
|
DBGA("pci_dac_dma_supported %s from %pf\n",
|
2010-03-11 07:23:37 +08:00
|
|
|
|
ok ? "yes" : "no", __builtin_return_address(0));
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
2007-07-10 02:55:51 +08:00
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
/* Map a single buffer of the indicated size for PCI DMA in streaming
|
|
|
|
|
mode. The 32-bit PCI bus mastering address to use is returned.
|
|
|
|
|
Once the device is given the dma address, the device owns this memory
|
|
|
|
|
until either pci_unmap_single or pci_dma_sync_single is performed. */
|
|
|
|
|
|
|
|
|
|
static dma_addr_t
|
|
|
|
|
pci_map_single_1(struct pci_dev *pdev, void *cpu_addr, size_t size,
|
|
|
|
|
int dac_allowed)
|
|
|
|
|
{
|
|
|
|
|
struct pci_controller *hose = pdev ? pdev->sysdata : pci_isa_hose;
|
|
|
|
|
dma_addr_t max_dma = pdev ? pdev->dma_mask : ISA_DMA_MASK;
|
|
|
|
|
struct pci_iommu_arena *arena;
|
|
|
|
|
long npages, dma_ofs, i;
|
|
|
|
|
unsigned long paddr;
|
|
|
|
|
dma_addr_t ret;
|
|
|
|
|
unsigned int align = 0;
|
2008-03-05 06:28:57 +08:00
|
|
|
|
struct device *dev = pdev ? &pdev->dev : NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
paddr = __pa(cpu_addr);
|
|
|
|
|
|
|
|
|
|
#if !DEBUG_NODIRECT
|
|
|
|
|
/* First check to see if we can use the direct map window. */
|
|
|
|
|
if (paddr + size + __direct_map_base - 1 <= max_dma
|
|
|
|
|
&& paddr + size <= __direct_map_size) {
|
|
|
|
|
ret = paddr + __direct_map_base;
|
|
|
|
|
|
2012-02-29 02:49:31 +08:00
|
|
|
|
DBGA2("pci_map_single: [%p,%zx] -> direct %llx from %pf\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cpu_addr, size, ret, __builtin_return_address(0));
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Next, use DAC if selected earlier. */
|
|
|
|
|
if (dac_allowed) {
|
|
|
|
|
ret = paddr + alpha_mv.pci_dac_offset;
|
|
|
|
|
|
2012-02-29 02:49:31 +08:00
|
|
|
|
DBGA2("pci_map_single: [%p,%zx] -> DAC %llx from %pf\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cpu_addr, size, ret, __builtin_return_address(0));
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If the machine doesn't define a pci_tbi routine, we have to
|
|
|
|
|
assume it doesn't support sg mapping, and, since we tried to
|
|
|
|
|
use direct_map above, it now must be considered an error. */
|
|
|
|
|
if (! alpha_mv.mv_pci_tbi) {
|
2009-09-22 08:04:01 +08:00
|
|
|
|
printk_once(KERN_WARNING "pci_map_single: no HW sg\n");
|
2018-11-22 02:04:03 +08:00
|
|
|
|
return DMA_MAPPING_ERROR;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
arena = hose->sg_pci;
|
|
|
|
|
if (!arena || arena->dma_base + arena->size - 1 > max_dma)
|
|
|
|
|
arena = hose->sg_isa;
|
|
|
|
|
|
2008-10-16 13:02:13 +08:00
|
|
|
|
npages = iommu_num_pages(paddr, size, PAGE_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
/* Force allocation to 64KB boundary for ISA bridges. */
|
|
|
|
|
if (pdev && pdev == isa_bridge)
|
|
|
|
|
align = 8;
|
2008-03-05 06:28:57 +08:00
|
|
|
|
dma_ofs = iommu_arena_alloc(dev, arena, npages, align);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (dma_ofs < 0) {
|
|
|
|
|
printk(KERN_WARNING "pci_map_single failed: "
|
|
|
|
|
"could not allocate dma page tables\n");
|
2018-11-22 02:04:03 +08:00
|
|
|
|
return DMA_MAPPING_ERROR;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paddr &= PAGE_MASK;
|
|
|
|
|
for (i = 0; i < npages; ++i, paddr += PAGE_SIZE)
|
|
|
|
|
arena->ptes[i + dma_ofs] = mk_iommu_pte(paddr);
|
|
|
|
|
|
|
|
|
|
ret = arena->dma_base + dma_ofs * PAGE_SIZE;
|
|
|
|
|
ret += (unsigned long)cpu_addr & ~PAGE_MASK;
|
|
|
|
|
|
2012-02-29 02:49:31 +08:00
|
|
|
|
DBGA2("pci_map_single: [%p,%zx] np %ld -> sg %llx from %pf\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cpu_addr, size, npages, ret, __builtin_return_address(0));
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-11 07:23:37 +08:00
|
|
|
|
/* Helper for generic DMA-mapping functions. */
|
|
|
|
|
static struct pci_dev *alpha_gendev_to_pci(struct device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2013-12-05 20:04:41 +08:00
|
|
|
|
if (dev && dev_is_pci(dev))
|
2010-03-11 07:23:37 +08:00
|
|
|
|
return to_pci_dev(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
2010-03-11 07:23:37 +08:00
|
|
|
|
/* Assume that non-PCI devices asking for DMA are either ISA or EISA,
|
|
|
|
|
BUG() otherwise. */
|
|
|
|
|
BUG_ON(!isa_bridge);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
2010-03-11 07:23:37 +08:00
|
|
|
|
/* Assume non-busmaster ISA DMA when dma_mask is not set (the ISA
|
|
|
|
|
bridge is bus master then). */
|
|
|
|
|
if (!dev || !dev->dma_mask || !*dev->dma_mask)
|
|
|
|
|
return isa_bridge;
|
|
|
|
|
|
|
|
|
|
/* For EISA bus masters, return isa_bridge (it might have smaller
|
|
|
|
|
dma_mask due to wiring limitations). */
|
|
|
|
|
if (*dev->dma_mask >= isa_bridge->dma_mask)
|
|
|
|
|
return isa_bridge;
|
|
|
|
|
|
|
|
|
|
/* This assumes ISA bus master with dma_mask 0xffffff. */
|
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-11 07:23:37 +08:00
|
|
|
|
static dma_addr_t alpha_pci_map_page(struct device *dev, struct page *page,
|
|
|
|
|
unsigned long offset, size_t size,
|
|
|
|
|
enum dma_data_direction dir,
|
2016-08-04 04:46:00 +08:00
|
|
|
|
unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2010-03-11 07:23:37 +08:00
|
|
|
|
struct pci_dev *pdev = alpha_gendev_to_pci(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
int dac_allowed;
|
|
|
|
|
|
2012-11-09 04:23:04 +08:00
|
|
|
|
BUG_ON(dir == PCI_DMA_NONE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
dac_allowed = pdev ? pci_dac_dma_supported(pdev, pdev->dma_mask) : 0;
|
|
|
|
|
return pci_map_single_1(pdev, (char *)page_address(page) + offset,
|
|
|
|
|
size, dac_allowed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Unmap a single streaming mode DMA translation. The DMA_ADDR and
|
|
|
|
|
SIZE must match what was provided for in a previous pci_map_single
|
|
|
|
|
call. All other usages are undefined. After this call, reads by
|
|
|
|
|
the cpu to the buffer are guaranteed to see whatever the device
|
|
|
|
|
wrote there. */
|
|
|
|
|
|
2010-03-11 07:23:37 +08:00
|
|
|
|
static void alpha_pci_unmap_page(struct device *dev, dma_addr_t dma_addr,
|
|
|
|
|
size_t size, enum dma_data_direction dir,
|
2016-08-04 04:46:00 +08:00
|
|
|
|
unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned long flags;
|
2010-03-11 07:23:37 +08:00
|
|
|
|
struct pci_dev *pdev = alpha_gendev_to_pci(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
struct pci_controller *hose = pdev ? pdev->sysdata : pci_isa_hose;
|
|
|
|
|
struct pci_iommu_arena *arena;
|
|
|
|
|
long dma_ofs, npages;
|
|
|
|
|
|
2012-11-09 04:23:04 +08:00
|
|
|
|
BUG_ON(dir == PCI_DMA_NONE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
if (dma_addr >= __direct_map_base
|
|
|
|
|
&& dma_addr < __direct_map_base + __direct_map_size) {
|
|
|
|
|
/* Nothing to do. */
|
|
|
|
|
|
2012-02-29 02:49:31 +08:00
|
|
|
|
DBGA2("pci_unmap_single: direct [%llx,%zx] from %pf\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
dma_addr, size, __builtin_return_address(0));
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dma_addr > 0xffffffff) {
|
2012-02-29 02:49:31 +08:00
|
|
|
|
DBGA2("pci64_unmap_single: DAC [%llx,%zx] from %pf\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
dma_addr, size, __builtin_return_address(0));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
arena = hose->sg_pci;
|
|
|
|
|
if (!arena || dma_addr < arena->dma_base)
|
|
|
|
|
arena = hose->sg_isa;
|
|
|
|
|
|
|
|
|
|
dma_ofs = (dma_addr - arena->dma_base) >> PAGE_SHIFT;
|
|
|
|
|
if (dma_ofs * PAGE_SIZE >= arena->size) {
|
2009-04-01 06:23:36 +08:00
|
|
|
|
printk(KERN_ERR "Bogus pci_unmap_single: dma_addr %llx "
|
|
|
|
|
" base %llx size %x\n",
|
|
|
|
|
dma_addr, arena->dma_base, arena->size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return;
|
|
|
|
|
BUG();
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 13:02:13 +08:00
|
|
|
|
npages = iommu_num_pages(dma_addr, size, PAGE_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&arena->lock, flags);
|
|
|
|
|
|
|
|
|
|
iommu_arena_free(arena, dma_ofs, npages);
|
|
|
|
|
|
|
|
|
|
/* If we're freeing ptes above the `next_entry' pointer (they
|
|
|
|
|
may have snuck back into the TLB since the last wrap flush),
|
|
|
|
|
we need to flush the TLB before reallocating the latter. */
|
|
|
|
|
if (dma_ofs >= arena->next_entry)
|
|
|
|
|
alpha_mv.mv_pci_tbi(hose, dma_addr, dma_addr + size - 1);
|
|
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&arena->lock, flags);
|
|
|
|
|
|
2012-02-29 02:49:31 +08:00
|
|
|
|
DBGA2("pci_unmap_single: sg [%llx,%zx] np %ld from %pf\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
dma_addr, size, npages, __builtin_return_address(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Allocate and map kernel buffer using consistent mode DMA for PCI
|
|
|
|
|
device. Returns non-NULL cpu-view pointer to the buffer if
|
|
|
|
|
successful and sets *DMA_ADDRP to the pci side dma address as well,
|
|
|
|
|
else DMA_ADDRP is undefined. */
|
|
|
|
|
|
2010-03-11 07:23:37 +08:00
|
|
|
|
static void *alpha_pci_alloc_coherent(struct device *dev, size_t size,
|
2011-12-22 20:58:21 +08:00
|
|
|
|
dma_addr_t *dma_addrp, gfp_t gfp,
|
2016-08-04 04:46:00 +08:00
|
|
|
|
unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2010-03-11 07:23:37 +08:00
|
|
|
|
struct pci_dev *pdev = alpha_gendev_to_pci(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
void *cpu_addr;
|
|
|
|
|
long order = get_order(size);
|
2008-04-03 04:04:43 +08:00
|
|
|
|
|
|
|
|
|
gfp &= ~GFP_DMA;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
try_again:
|
2018-12-14 16:00:40 +08:00
|
|
|
|
cpu_addr = (void *)__get_free_pages(gfp | __GFP_ZERO, order);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (! cpu_addr) {
|
|
|
|
|
printk(KERN_INFO "pci_alloc_consistent: "
|
2012-02-29 02:49:31 +08:00
|
|
|
|
"get_free_pages failed from %pf\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
__builtin_return_address(0));
|
|
|
|
|
/* ??? Really atomic allocation? Otherwise we could play
|
|
|
|
|
with vmalloc and sg if we can't find contiguous memory. */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
memset(cpu_addr, 0, size);
|
|
|
|
|
|
|
|
|
|
*dma_addrp = pci_map_single_1(pdev, cpu_addr, size, 0);
|
2018-11-22 02:04:03 +08:00
|
|
|
|
if (*dma_addrp == DMA_MAPPING_ERROR) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
free_pages((unsigned long)cpu_addr, order);
|
|
|
|
|
if (alpha_mv.mv_pci_tbi || (gfp & GFP_DMA))
|
|
|
|
|
return NULL;
|
|
|
|
|
/* The address doesn't fit required mask and we
|
|
|
|
|
do not have iommu. Try again with GFP_DMA. */
|
|
|
|
|
gfp |= GFP_DMA;
|
|
|
|
|
goto try_again;
|
|
|
|
|
}
|
2010-03-11 07:23:37 +08:00
|
|
|
|
|
2012-02-29 02:49:31 +08:00
|
|
|
|
DBGA2("pci_alloc_consistent: %zx -> [%p,%llx] from %pf\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
size, cpu_addr, *dma_addrp, __builtin_return_address(0));
|
|
|
|
|
|
|
|
|
|
return cpu_addr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free and unmap a consistent DMA buffer. CPU_ADDR and DMA_ADDR must
|
|
|
|
|
be values that were returned from pci_alloc_consistent. SIZE must
|
|
|
|
|
be the same as what as passed into pci_alloc_consistent.
|
|
|
|
|
References to the memory and mappings associated with CPU_ADDR or
|
|
|
|
|
DMA_ADDR past this call are illegal. */
|
|
|
|
|
|
2010-03-11 07:23:37 +08:00
|
|
|
|
static void alpha_pci_free_coherent(struct device *dev, size_t size,
|
2011-12-22 20:58:21 +08:00
|
|
|
|
void *cpu_addr, dma_addr_t dma_addr,
|
2016-08-04 04:46:00 +08:00
|
|
|
|
unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2010-03-11 07:23:37 +08:00
|
|
|
|
struct pci_dev *pdev = alpha_gendev_to_pci(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
pci_unmap_single(pdev, dma_addr, size, PCI_DMA_BIDIRECTIONAL);
|
|
|
|
|
free_pages((unsigned long)cpu_addr, get_order(size));
|
|
|
|
|
|
2012-02-29 02:49:31 +08:00
|
|
|
|
DBGA2("pci_free_consistent: [%llx,%zx] from %pf\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
dma_addr, size, __builtin_return_address(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Classify the elements of the scatterlist. Write dma_address
|
|
|
|
|
of each element with:
|
|
|
|
|
0 : Followers all physically adjacent.
|
|
|
|
|
1 : Followers all virtually adjacent.
|
|
|
|
|
-1 : Not leader, physically adjacent to previous.
|
|
|
|
|
-2 : Not leader, virtually adjacent to previous.
|
|
|
|
|
Write dma_length of each leader with the combined lengths of
|
|
|
|
|
the mergable followers. */
|
|
|
|
|
|
2007-10-23 02:02:46 +08:00
|
|
|
|
#define SG_ENT_VIRT_ADDRESS(SG) (sg_virt((SG)))
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#define SG_ENT_PHYS_ADDRESS(SG) __pa(SG_ENT_VIRT_ADDRESS(SG))
|
|
|
|
|
|
|
|
|
|
static void
|
2008-02-05 14:27:58 +08:00
|
|
|
|
sg_classify(struct device *dev, struct scatterlist *sg, struct scatterlist *end,
|
|
|
|
|
int virt_ok)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned long next_paddr;
|
|
|
|
|
struct scatterlist *leader;
|
|
|
|
|
long leader_flag, leader_length;
|
2008-02-05 14:27:58 +08:00
|
|
|
|
unsigned int max_seg_size;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
leader = sg;
|
|
|
|
|
leader_flag = 0;
|
|
|
|
|
leader_length = leader->length;
|
|
|
|
|
next_paddr = SG_ENT_PHYS_ADDRESS(leader) + leader_length;
|
|
|
|
|
|
2008-02-05 14:27:58 +08:00
|
|
|
|
/* we will not marge sg without device. */
|
|
|
|
|
max_seg_size = dev ? dma_get_max_seg_size(dev) : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
for (++sg; sg < end; ++sg) {
|
|
|
|
|
unsigned long addr, len;
|
|
|
|
|
addr = SG_ENT_PHYS_ADDRESS(sg);
|
|
|
|
|
len = sg->length;
|
|
|
|
|
|
2008-02-05 14:27:58 +08:00
|
|
|
|
if (leader_length + len > max_seg_size)
|
|
|
|
|
goto new_segment;
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (next_paddr == addr) {
|
|
|
|
|
sg->dma_address = -1;
|
|
|
|
|
leader_length += len;
|
|
|
|
|
} else if (((next_paddr | addr) & ~PAGE_MASK) == 0 && virt_ok) {
|
|
|
|
|
sg->dma_address = -2;
|
|
|
|
|
leader_flag = 1;
|
|
|
|
|
leader_length += len;
|
|
|
|
|
} else {
|
2008-02-05 14:27:58 +08:00
|
|
|
|
new_segment:
|
2005-04-17 06:20:36 +08:00
|
|
|
|
leader->dma_address = leader_flag;
|
|
|
|
|
leader->dma_length = leader_length;
|
|
|
|
|
leader = sg;
|
|
|
|
|
leader_flag = 0;
|
|
|
|
|
leader_length = len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next_paddr = addr + len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
leader->dma_address = leader_flag;
|
|
|
|
|
leader->dma_length = leader_length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Given a scatterlist leader, choose an allocation method and fill
|
|
|
|
|
in the blanks. */
|
|
|
|
|
|
|
|
|
|
static int
|
2008-02-05 14:27:58 +08:00
|
|
|
|
sg_fill(struct device *dev, struct scatterlist *leader, struct scatterlist *end,
|
2005-04-17 06:20:36 +08:00
|
|
|
|
struct scatterlist *out, struct pci_iommu_arena *arena,
|
|
|
|
|
dma_addr_t max_dma, int dac_allowed)
|
|
|
|
|
{
|
|
|
|
|
unsigned long paddr = SG_ENT_PHYS_ADDRESS(leader);
|
|
|
|
|
long size = leader->dma_length;
|
|
|
|
|
struct scatterlist *sg;
|
|
|
|
|
unsigned long *ptes;
|
|
|
|
|
long npages, dma_ofs, i;
|
|
|
|
|
|
|
|
|
|
#if !DEBUG_NODIRECT
|
|
|
|
|
/* If everything is physically contiguous, and the addresses
|
|
|
|
|
fall into the direct-map window, use it. */
|
|
|
|
|
if (leader->dma_address == 0
|
|
|
|
|
&& paddr + size + __direct_map_base - 1 <= max_dma
|
|
|
|
|
&& paddr + size <= __direct_map_size) {
|
|
|
|
|
out->dma_address = paddr + __direct_map_base;
|
|
|
|
|
out->dma_length = size;
|
|
|
|
|
|
2009-04-01 06:23:36 +08:00
|
|
|
|
DBGA(" sg_fill: [%p,%lx] -> direct %llx\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
__va(paddr), size, out->dma_address);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* If physically contiguous and DAC is available, use it. */
|
|
|
|
|
if (leader->dma_address == 0 && dac_allowed) {
|
|
|
|
|
out->dma_address = paddr + alpha_mv.pci_dac_offset;
|
|
|
|
|
out->dma_length = size;
|
|
|
|
|
|
2009-04-01 06:23:36 +08:00
|
|
|
|
DBGA(" sg_fill: [%p,%lx] -> DAC %llx\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
__va(paddr), size, out->dma_address);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Otherwise, we'll use the iommu to make the pages virtually
|
|
|
|
|
contiguous. */
|
|
|
|
|
|
|
|
|
|
paddr &= ~PAGE_MASK;
|
2008-10-16 13:02:13 +08:00
|
|
|
|
npages = iommu_num_pages(paddr, size, PAGE_SIZE);
|
2008-03-05 06:28:57 +08:00
|
|
|
|
dma_ofs = iommu_arena_alloc(dev, arena, npages, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (dma_ofs < 0) {
|
|
|
|
|
/* If we attempted a direct map above but failed, die. */
|
|
|
|
|
if (leader->dma_address == 0)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
/* Otherwise, break up the remaining virtually contiguous
|
|
|
|
|
hunks into individual direct maps and retry. */
|
2008-02-05 14:27:58 +08:00
|
|
|
|
sg_classify(dev, leader, end, 0);
|
|
|
|
|
return sg_fill(dev, leader, end, out, arena, max_dma, dac_allowed);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out->dma_address = arena->dma_base + dma_ofs*PAGE_SIZE + paddr;
|
|
|
|
|
out->dma_length = size;
|
|
|
|
|
|
2009-04-01 06:23:36 +08:00
|
|
|
|
DBGA(" sg_fill: [%p,%lx] -> sg %llx np %ld\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
__va(paddr), size, out->dma_address, npages);
|
|
|
|
|
|
|
|
|
|
/* All virtually contiguous. We need to find the length of each
|
|
|
|
|
physically contiguous subsegment to fill in the ptes. */
|
|
|
|
|
ptes = &arena->ptes[dma_ofs];
|
|
|
|
|
sg = leader;
|
|
|
|
|
do {
|
|
|
|
|
#if DEBUG_ALLOC > 0
|
|
|
|
|
struct scatterlist *last_sg = sg;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
size = sg->length;
|
|
|
|
|
paddr = SG_ENT_PHYS_ADDRESS(sg);
|
|
|
|
|
|
|
|
|
|
while (sg+1 < end && (int) sg[1].dma_address == -1) {
|
|
|
|
|
size += sg[1].length;
|
|
|
|
|
sg++;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 13:02:13 +08:00
|
|
|
|
npages = iommu_num_pages(paddr, size, PAGE_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
paddr &= PAGE_MASK;
|
|
|
|
|
for (i = 0; i < npages; ++i, paddr += PAGE_SIZE)
|
|
|
|
|
*ptes++ = mk_iommu_pte(paddr);
|
|
|
|
|
|
|
|
|
|
#if DEBUG_ALLOC > 0
|
|
|
|
|
DBGA(" (%ld) [%p,%x] np %ld\n",
|
|
|
|
|
last_sg - leader, SG_ENT_VIRT_ADDRESS(last_sg),
|
|
|
|
|
last_sg->length, npages);
|
|
|
|
|
while (++last_sg <= sg) {
|
|
|
|
|
DBGA(" (%ld) [%p,%x] cont\n",
|
|
|
|
|
last_sg - leader, SG_ENT_VIRT_ADDRESS(last_sg),
|
|
|
|
|
last_sg->length);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
} while (++sg < end && (int) sg->dma_address < 0);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-11 07:23:37 +08:00
|
|
|
|
static int alpha_pci_map_sg(struct device *dev, struct scatterlist *sg,
|
|
|
|
|
int nents, enum dma_data_direction dir,
|
2016-08-04 04:46:00 +08:00
|
|
|
|
unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2010-03-11 07:23:37 +08:00
|
|
|
|
struct pci_dev *pdev = alpha_gendev_to_pci(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
struct scatterlist *start, *end, *out;
|
|
|
|
|
struct pci_controller *hose;
|
|
|
|
|
struct pci_iommu_arena *arena;
|
|
|
|
|
dma_addr_t max_dma;
|
|
|
|
|
int dac_allowed;
|
|
|
|
|
|
2012-11-09 04:23:04 +08:00
|
|
|
|
BUG_ON(dir == PCI_DMA_NONE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
2010-03-11 07:23:37 +08:00
|
|
|
|
dac_allowed = dev ? pci_dac_dma_supported(pdev, pdev->dma_mask) : 0;
|
2008-02-05 14:27:58 +08:00
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
/* Fast path single entry scatterlists. */
|
|
|
|
|
if (nents == 1) {
|
|
|
|
|
sg->dma_length = sg->length;
|
|
|
|
|
sg->dma_address
|
|
|
|
|
= pci_map_single_1(pdev, SG_ENT_VIRT_ADDRESS(sg),
|
|
|
|
|
sg->length, dac_allowed);
|
2018-11-22 02:04:03 +08:00
|
|
|
|
return sg->dma_address != DMA_MAPPING_ERROR;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start = sg;
|
|
|
|
|
end = sg + nents;
|
|
|
|
|
|
|
|
|
|
/* First, prepare information about the entries. */
|
2008-02-05 14:27:58 +08:00
|
|
|
|
sg_classify(dev, sg, end, alpha_mv.mv_pci_tbi != 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
/* Second, figure out where we're going to map things. */
|
|
|
|
|
if (alpha_mv.mv_pci_tbi) {
|
|
|
|
|
hose = pdev ? pdev->sysdata : pci_isa_hose;
|
|
|
|
|
max_dma = pdev ? pdev->dma_mask : ISA_DMA_MASK;
|
|
|
|
|
arena = hose->sg_pci;
|
|
|
|
|
if (!arena || arena->dma_base + arena->size - 1 > max_dma)
|
|
|
|
|
arena = hose->sg_isa;
|
|
|
|
|
} else {
|
|
|
|
|
max_dma = -1;
|
|
|
|
|
arena = NULL;
|
|
|
|
|
hose = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Third, iterate over the scatterlist leaders and allocate
|
|
|
|
|
dma space as needed. */
|
|
|
|
|
for (out = sg; sg < end; ++sg) {
|
|
|
|
|
if ((int) sg->dma_address < 0)
|
|
|
|
|
continue;
|
2008-02-05 14:27:58 +08:00
|
|
|
|
if (sg_fill(dev, sg, end, out, arena, max_dma, dac_allowed) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
goto error;
|
|
|
|
|
out++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Mark the end of the list for pci_unmap_sg. */
|
|
|
|
|
if (out < end)
|
|
|
|
|
out->dma_length = 0;
|
|
|
|
|
|
|
|
|
|
if (out - start == 0)
|
|
|
|
|
printk(KERN_WARNING "pci_map_sg failed: no entries?\n");
|
|
|
|
|
DBGA("pci_map_sg: %ld entries\n", out - start);
|
|
|
|
|
|
|
|
|
|
return out - start;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
printk(KERN_WARNING "pci_map_sg failed: "
|
|
|
|
|
"could not allocate dma page tables\n");
|
|
|
|
|
|
|
|
|
|
/* Some allocation failed while mapping the scatterlist
|
|
|
|
|
entries. Unmap them now. */
|
|
|
|
|
if (out > start)
|
2010-03-11 07:23:37 +08:00
|
|
|
|
pci_unmap_sg(pdev, start, out - start, dir);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Unmap a set of streaming mode DMA translations. Again, cpu read
|
|
|
|
|
rules concerning calls here are the same as for pci_unmap_single()
|
|
|
|
|
above. */
|
|
|
|
|
|
2010-03-11 07:23:37 +08:00
|
|
|
|
static void alpha_pci_unmap_sg(struct device *dev, struct scatterlist *sg,
|
|
|
|
|
int nents, enum dma_data_direction dir,
|
2016-08-04 04:46:00 +08:00
|
|
|
|
unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2010-03-11 07:23:37 +08:00
|
|
|
|
struct pci_dev *pdev = alpha_gendev_to_pci(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
unsigned long flags;
|
|
|
|
|
struct pci_controller *hose;
|
|
|
|
|
struct pci_iommu_arena *arena;
|
|
|
|
|
struct scatterlist *end;
|
|
|
|
|
dma_addr_t max_dma;
|
|
|
|
|
dma_addr_t fbeg, fend;
|
|
|
|
|
|
2012-11-09 04:23:04 +08:00
|
|
|
|
BUG_ON(dir == PCI_DMA_NONE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
if (! alpha_mv.mv_pci_tbi)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
hose = pdev ? pdev->sysdata : pci_isa_hose;
|
|
|
|
|
max_dma = pdev ? pdev->dma_mask : ISA_DMA_MASK;
|
|
|
|
|
arena = hose->sg_pci;
|
|
|
|
|
if (!arena || arena->dma_base + arena->size - 1 > max_dma)
|
|
|
|
|
arena = hose->sg_isa;
|
|
|
|
|
|
|
|
|
|
fbeg = -1, fend = 0;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&arena->lock, flags);
|
|
|
|
|
|
|
|
|
|
for (end = sg + nents; sg < end; ++sg) {
|
2010-10-28 06:34:48 +08:00
|
|
|
|
dma_addr_t addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
size_t size;
|
|
|
|
|
long npages, ofs;
|
|
|
|
|
dma_addr_t tend;
|
|
|
|
|
|
|
|
|
|
addr = sg->dma_address;
|
|
|
|
|
size = sg->dma_length;
|
|
|
|
|
if (!size)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (addr > 0xffffffff) {
|
|
|
|
|
/* It's a DAC address -- nothing to do. */
|
2009-04-01 06:23:36 +08:00
|
|
|
|
DBGA(" (%ld) DAC [%llx,%zx]\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
sg - end + nents, addr, size);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (addr >= __direct_map_base
|
|
|
|
|
&& addr < __direct_map_base + __direct_map_size) {
|
|
|
|
|
/* Nothing to do. */
|
2009-04-01 06:23:36 +08:00
|
|
|
|
DBGA(" (%ld) direct [%llx,%zx]\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
sg - end + nents, addr, size);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-01 06:23:36 +08:00
|
|
|
|
DBGA(" (%ld) sg [%llx,%zx]\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
sg - end + nents, addr, size);
|
|
|
|
|
|
2008-10-16 13:02:13 +08:00
|
|
|
|
npages = iommu_num_pages(addr, size, PAGE_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
ofs = (addr - arena->dma_base) >> PAGE_SHIFT;
|
|
|
|
|
iommu_arena_free(arena, ofs, npages);
|
|
|
|
|
|
|
|
|
|
tend = addr + size - 1;
|
|
|
|
|
if (fbeg > addr) fbeg = addr;
|
|
|
|
|
if (fend < tend) fend = tend;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we're freeing ptes above the `next_entry' pointer (they
|
|
|
|
|
may have snuck back into the TLB since the last wrap flush),
|
|
|
|
|
we need to flush the TLB before reallocating the latter. */
|
|
|
|
|
if ((fend - arena->dma_base) >> PAGE_SHIFT >= arena->next_entry)
|
|
|
|
|
alpha_mv.mv_pci_tbi(hose, fbeg, fend);
|
|
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&arena->lock, flags);
|
|
|
|
|
|
|
|
|
|
DBGA("pci_unmap_sg: %ld entries\n", nents - (end - sg));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return whether the given PCI device DMA address mask can be
|
|
|
|
|
supported properly. */
|
|
|
|
|
|
2010-03-11 07:23:37 +08:00
|
|
|
|
static int alpha_pci_supported(struct device *dev, u64 mask)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2010-03-11 07:23:37 +08:00
|
|
|
|
struct pci_dev *pdev = alpha_gendev_to_pci(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
struct pci_controller *hose;
|
|
|
|
|
struct pci_iommu_arena *arena;
|
|
|
|
|
|
|
|
|
|
/* If there exists a direct map, and the mask fits either
|
|
|
|
|
the entire direct mapped space or the total system memory as
|
|
|
|
|
shifted by the map base */
|
|
|
|
|
if (__direct_map_size != 0
|
|
|
|
|
&& (__direct_map_base + __direct_map_size - 1 <= mask ||
|
|
|
|
|
__direct_map_base + (max_low_pfn << PAGE_SHIFT) - 1 <= mask))
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
/* Check that we have a scatter-gather arena that fits. */
|
|
|
|
|
hose = pdev ? pdev->sysdata : pci_isa_hose;
|
|
|
|
|
arena = hose->sg_isa;
|
|
|
|
|
if (arena && arena->dma_base + arena->size - 1 <= mask)
|
|
|
|
|
return 1;
|
|
|
|
|
arena = hose->sg_pci;
|
|
|
|
|
if (arena && arena->dma_base + arena->size - 1 <= mask)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
/* As last resort try ZONE_DMA. */
|
|
|
|
|
if (!__direct_map_base && MAX_DMA_ADDRESS - IDENT_ADDR - 1 <= mask)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* AGP GART extensions to the IOMMU
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
iommu_reserve(struct pci_iommu_arena *arena, long pg_count, long align_mask)
|
|
|
|
|
{
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
unsigned long *ptes;
|
|
|
|
|
long i, p;
|
|
|
|
|
|
|
|
|
|
if (!arena) return -EINVAL;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&arena->lock, flags);
|
|
|
|
|
|
|
|
|
|
/* Search for N empty ptes. */
|
|
|
|
|
ptes = arena->ptes;
|
2008-03-05 06:28:57 +08:00
|
|
|
|
p = iommu_arena_find_pages(NULL, arena, pg_count, align_mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (p < 0) {
|
|
|
|
|
spin_unlock_irqrestore(&arena->lock, flags);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Success. Mark them all reserved (ie not zero and invalid)
|
|
|
|
|
for the iommu tlb that could load them from under us.
|
|
|
|
|
They will be filled in with valid bits by _bind() */
|
|
|
|
|
for (i = 0; i < pg_count; ++i)
|
|
|
|
|
ptes[p+i] = IOMMU_RESERVED_PTE;
|
|
|
|
|
|
|
|
|
|
arena->next_entry = p + pg_count;
|
|
|
|
|
spin_unlock_irqrestore(&arena->lock, flags);
|
|
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
iommu_release(struct pci_iommu_arena *arena, long pg_start, long pg_count)
|
|
|
|
|
{
|
|
|
|
|
unsigned long *ptes;
|
|
|
|
|
long i;
|
|
|
|
|
|
|
|
|
|
if (!arena) return -EINVAL;
|
|
|
|
|
|
|
|
|
|
ptes = arena->ptes;
|
|
|
|
|
|
|
|
|
|
/* Make sure they're all reserved first... */
|
|
|
|
|
for(i = pg_start; i < pg_start + pg_count; i++)
|
|
|
|
|
if (ptes[i] != IOMMU_RESERVED_PTE)
|
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
|
|
iommu_arena_free(arena, pg_start, pg_count);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
iommu_bind(struct pci_iommu_arena *arena, long pg_start, long pg_count,
|
2009-09-24 06:57:42 +08:00
|
|
|
|
struct page **pages)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
unsigned long *ptes;
|
|
|
|
|
long i, j;
|
|
|
|
|
|
|
|
|
|
if (!arena) return -EINVAL;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&arena->lock, flags);
|
|
|
|
|
|
|
|
|
|
ptes = arena->ptes;
|
|
|
|
|
|
|
|
|
|
for(j = pg_start; j < pg_start + pg_count; j++) {
|
|
|
|
|
if (ptes[j] != IOMMU_RESERVED_PTE) {
|
|
|
|
|
spin_unlock_irqrestore(&arena->lock, flags);
|
|
|
|
|
return -EBUSY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(i = 0, j = pg_start; i < pg_count; i++, j++)
|
2009-09-24 06:57:42 +08:00
|
|
|
|
ptes[j] = mk_iommu_pte(page_to_phys(pages[i]));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&arena->lock, flags);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
iommu_unbind(struct pci_iommu_arena *arena, long pg_start, long pg_count)
|
|
|
|
|
{
|
|
|
|
|
unsigned long *p;
|
|
|
|
|
long i;
|
|
|
|
|
|
|
|
|
|
if (!arena) return -EINVAL;
|
|
|
|
|
|
|
|
|
|
p = arena->ptes + pg_start;
|
|
|
|
|
for(i = 0; i < pg_count; i++)
|
|
|
|
|
p[i] = IOMMU_RESERVED_PTE;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-21 05:04:01 +08:00
|
|
|
|
const struct dma_map_ops alpha_pci_ops = {
|
2011-12-22 20:58:21 +08:00
|
|
|
|
.alloc = alpha_pci_alloc_coherent,
|
|
|
|
|
.free = alpha_pci_free_coherent,
|
2010-03-11 07:23:37 +08:00
|
|
|
|
.map_page = alpha_pci_map_page,
|
|
|
|
|
.unmap_page = alpha_pci_unmap_page,
|
|
|
|
|
.map_sg = alpha_pci_map_sg,
|
|
|
|
|
.unmap_sg = alpha_pci_unmap_sg,
|
|
|
|
|
.dma_supported = alpha_pci_supported,
|
|
|
|
|
};
|
2018-05-09 22:04:52 +08:00
|
|
|
|
EXPORT_SYMBOL(alpha_pci_ops);
|