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
|
|
|
/*
|
|
|
|
* Mips Jazz DMA controller support
|
|
|
|
* Copyright (C) 1995, 1996 by Andreas Busse
|
|
|
|
*
|
|
|
|
* NOTE: Some of the argument checking could be removed when
|
|
|
|
* things have settled down. Also, instead of returning 0xffffffff
|
|
|
|
* on failure of vdma_alloc() one could leave page #0 unused
|
|
|
|
* and return the more usual NULL pointer as logical address.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
2017-01-29 10:05:57 +08:00
|
|
|
#include <linux/export.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/mm.h>
|
2018-10-31 06:09:49 +08:00
|
|
|
#include <linux/memblock.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/spinlock.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-06-15 19:08:50 +08:00
|
|
|
#include <linux/dma-direct.h>
|
|
|
|
#include <linux/dma-noncoherent.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/mipsregs.h>
|
|
|
|
#include <asm/jazz.h>
|
|
|
|
#include <asm/io.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/dma.h>
|
|
|
|
#include <asm/jazzdma.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set this to one to enable additional vdma debug code.
|
|
|
|
*/
|
|
|
|
#define CONF_DEBUG_VDMA 0
|
|
|
|
|
2007-08-25 17:01:50 +08:00
|
|
|
static VDMA_PGTBL_ENTRY *pgtbl;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(vdma_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debug stuff
|
|
|
|
*/
|
|
|
|
#define vdma_debug ((CONF_DEBUG_VDMA) ? debuglvl : 0)
|
|
|
|
|
|
|
|
static int debuglvl = 3;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the pagetable with a one-to-one mapping of
|
|
|
|
* the first 16 Mbytes of main memory and declare all
|
|
|
|
* entries to be unused. Using this method will at least
|
|
|
|
* allow some early device driver operations to work.
|
|
|
|
*/
|
|
|
|
static inline void vdma_pgtbl_init(void)
|
|
|
|
{
|
|
|
|
unsigned long paddr = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < VDMA_PGTBL_ENTRIES; i++) {
|
|
|
|
pgtbl[i].frame = paddr;
|
|
|
|
pgtbl[i].owner = VDMA_PAGE_EMPTY;
|
|
|
|
paddr += VDMA_PAGESIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the Jazz R4030 dma controller
|
|
|
|
*/
|
2007-08-25 17:01:50 +08:00
|
|
|
static int __init vdma_init(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/*
|
2013-01-22 19:59:30 +08:00
|
|
|
* Allocate 32k of memory for DMA page tables. This needs to be page
|
2005-04-17 06:20:36 +08:00
|
|
|
* aligned and should be uncached to avoid cache flushing after every
|
|
|
|
* update.
|
|
|
|
*/
|
2007-08-25 17:01:50 +08:00
|
|
|
pgtbl = (VDMA_PGTBL_ENTRY *)__get_free_pages(GFP_KERNEL | GFP_DMA,
|
|
|
|
get_order(VDMA_PGTBL_SIZE));
|
2009-03-30 20:49:44 +08:00
|
|
|
BUG_ON(!pgtbl);
|
2007-08-25 17:01:50 +08:00
|
|
|
dma_cache_wback_inv((unsigned long)pgtbl, VDMA_PGTBL_SIZE);
|
2019-01-10 01:12:16 +08:00
|
|
|
pgtbl = (VDMA_PGTBL_ENTRY *)CKSEG1ADDR((unsigned long)pgtbl);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the R4030 translation table
|
|
|
|
*/
|
|
|
|
vdma_pgtbl_init();
|
|
|
|
|
2019-01-10 01:12:16 +08:00
|
|
|
r4030_write_reg32(JAZZ_R4030_TRSTBL_BASE,
|
|
|
|
CPHYSADDR((unsigned long)pgtbl));
|
2005-04-17 06:20:36 +08:00
|
|
|
r4030_write_reg32(JAZZ_R4030_TRSTBL_LIM, VDMA_PGTBL_SIZE);
|
|
|
|
r4030_write_reg32(JAZZ_R4030_TRSTBL_INV, 0);
|
|
|
|
|
2007-08-25 17:01:50 +08:00
|
|
|
printk(KERN_INFO "VDMA: R4030 DMA pagetables initialized.\n");
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2018-06-15 19:08:50 +08:00
|
|
|
arch_initcall(vdma_init);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate DMA pagetables using a simple first-fit algorithm
|
|
|
|
*/
|
|
|
|
unsigned long vdma_alloc(unsigned long paddr, unsigned long size)
|
|
|
|
{
|
|
|
|
int first, last, pages, frame, i;
|
|
|
|
unsigned long laddr, flags;
|
|
|
|
|
|
|
|
/* check arguments */
|
|
|
|
|
|
|
|
if (paddr > 0x1fffffff) {
|
|
|
|
if (vdma_debug)
|
|
|
|
printk("vdma_alloc: Invalid physical address: %08lx\n",
|
|
|
|
paddr);
|
2018-11-22 02:18:58 +08:00
|
|
|
return DMA_MAPPING_ERROR; /* invalid physical address */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (size > 0x400000 || size == 0) {
|
|
|
|
if (vdma_debug)
|
|
|
|
printk("vdma_alloc: Invalid size: %08lx\n", size);
|
2018-11-22 02:18:58 +08:00
|
|
|
return DMA_MAPPING_ERROR; /* invalid physical address */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&vdma_lock, flags);
|
|
|
|
/*
|
|
|
|
* Find free chunk
|
|
|
|
*/
|
2007-08-25 17:01:50 +08:00
|
|
|
pages = VDMA_PAGE(paddr + size) - VDMA_PAGE(paddr) + 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
first = 0;
|
|
|
|
while (1) {
|
2007-08-25 17:01:50 +08:00
|
|
|
while (pgtbl[first].owner != VDMA_PAGE_EMPTY &&
|
2005-04-17 06:20:36 +08:00
|
|
|
first < VDMA_PGTBL_ENTRIES) first++;
|
|
|
|
if (first + pages > VDMA_PGTBL_ENTRIES) { /* nothing free */
|
|
|
|
spin_unlock_irqrestore(&vdma_lock, flags);
|
2018-11-22 02:18:58 +08:00
|
|
|
return DMA_MAPPING_ERROR;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
last = first + 1;
|
2007-08-25 17:01:50 +08:00
|
|
|
while (pgtbl[last].owner == VDMA_PAGE_EMPTY
|
2005-04-17 06:20:36 +08:00
|
|
|
&& last - first < pages)
|
|
|
|
last++;
|
|
|
|
|
|
|
|
if (last - first == pages)
|
|
|
|
break; /* found */
|
2007-08-25 17:01:50 +08:00
|
|
|
first = last + 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark pages as allocated
|
|
|
|
*/
|
|
|
|
laddr = (first << 12) + (paddr & (VDMA_PAGESIZE - 1));
|
|
|
|
frame = paddr & ~(VDMA_PAGESIZE - 1);
|
|
|
|
|
|
|
|
for (i = first; i < last; i++) {
|
2007-08-25 17:01:50 +08:00
|
|
|
pgtbl[i].frame = frame;
|
|
|
|
pgtbl[i].owner = laddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
frame += VDMA_PAGESIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update translation table and return logical start address
|
|
|
|
*/
|
|
|
|
r4030_write_reg32(JAZZ_R4030_TRSTBL_INV, 0);
|
|
|
|
|
|
|
|
if (vdma_debug > 1)
|
|
|
|
printk("vdma_alloc: Allocated %d pages starting from %08lx\n",
|
|
|
|
pages, laddr);
|
|
|
|
|
|
|
|
if (vdma_debug > 2) {
|
|
|
|
printk("LADDR: ");
|
|
|
|
for (i = first; i < last; i++)
|
|
|
|
printk("%08x ", i << 12);
|
|
|
|
printk("\nPADDR: ");
|
|
|
|
for (i = first; i < last; i++)
|
2007-08-25 17:01:50 +08:00
|
|
|
printk("%08x ", pgtbl[i].frame);
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("\nOWNER: ");
|
|
|
|
for (i = first; i < last; i++)
|
2007-08-25 17:01:50 +08:00
|
|
|
printk("%08x ", pgtbl[i].owner);
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&vdma_lock, flags);
|
|
|
|
|
|
|
|
return laddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(vdma_alloc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free previously allocated dma translation pages
|
|
|
|
* Note that this does NOT change the translation table,
|
|
|
|
* it just marks the free'd pages as unused!
|
|
|
|
*/
|
|
|
|
int vdma_free(unsigned long laddr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = laddr >> 12;
|
|
|
|
|
|
|
|
if (pgtbl[i].owner != laddr) {
|
|
|
|
printk
|
|
|
|
("vdma_free: trying to free other's dma pages, laddr=%8lx\n",
|
|
|
|
laddr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-07-31 20:52:51 +08:00
|
|
|
while (i < VDMA_PGTBL_ENTRIES && pgtbl[i].owner == laddr) {
|
2005-04-17 06:20:36 +08:00
|
|
|
pgtbl[i].owner = VDMA_PAGE_EMPTY;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vdma_debug > 1)
|
|
|
|
printk("vdma_free: freed %ld pages starting from %08lx\n",
|
|
|
|
i - (laddr >> 12), laddr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(vdma_free);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map certain page(s) to another physical address.
|
|
|
|
* Caller must have allocated the page(s) before.
|
|
|
|
*/
|
|
|
|
int vdma_remap(unsigned long laddr, unsigned long paddr, unsigned long size)
|
|
|
|
{
|
2011-03-29 18:09:51 +08:00
|
|
|
int first, pages;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (laddr > 0xffffff) {
|
|
|
|
if (vdma_debug)
|
|
|
|
printk
|
|
|
|
("vdma_map: Invalid logical address: %08lx\n",
|
|
|
|
laddr);
|
2013-01-22 19:59:30 +08:00
|
|
|
return -EINVAL; /* invalid logical address */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (paddr > 0x1fffffff) {
|
|
|
|
if (vdma_debug)
|
|
|
|
printk
|
|
|
|
("vdma_map: Invalid physical address: %08lx\n",
|
|
|
|
paddr);
|
2013-01-22 19:59:30 +08:00
|
|
|
return -EINVAL; /* invalid physical address */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-03-29 18:09:51 +08:00
|
|
|
pages = (((paddr & (VDMA_PAGESIZE - 1)) + size) >> 12) + 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
first = laddr >> 12;
|
|
|
|
if (vdma_debug)
|
|
|
|
printk("vdma_remap: first=%x, pages=%x\n", first, pages);
|
|
|
|
if (first + pages > VDMA_PGTBL_ENTRIES) {
|
|
|
|
if (vdma_debug)
|
|
|
|
printk("vdma_alloc: Invalid size: %08lx\n", size);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
paddr &= ~(VDMA_PAGESIZE - 1);
|
|
|
|
while (pages > 0 && first < VDMA_PGTBL_ENTRIES) {
|
|
|
|
if (pgtbl[first].owner != laddr) {
|
|
|
|
if (vdma_debug)
|
|
|
|
printk("Trying to remap other's pages.\n");
|
|
|
|
return -EPERM; /* not owner */
|
|
|
|
}
|
|
|
|
pgtbl[first].frame = paddr;
|
|
|
|
paddr += VDMA_PAGESIZE;
|
|
|
|
first++;
|
|
|
|
pages--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update translation table
|
|
|
|
*/
|
|
|
|
r4030_write_reg32(JAZZ_R4030_TRSTBL_INV, 0);
|
|
|
|
|
|
|
|
if (vdma_debug > 2) {
|
|
|
|
int i;
|
|
|
|
pages = (((paddr & (VDMA_PAGESIZE - 1)) + size) >> 12) + 1;
|
|
|
|
first = laddr >> 12;
|
|
|
|
printk("LADDR: ");
|
|
|
|
for (i = first; i < first + pages; i++)
|
|
|
|
printk("%08x ", i << 12);
|
|
|
|
printk("\nPADDR: ");
|
|
|
|
for (i = first; i < first + pages; i++)
|
|
|
|
printk("%08x ", pgtbl[i].frame);
|
|
|
|
printk("\nOWNER: ");
|
|
|
|
for (i = first; i < first + pages; i++)
|
|
|
|
printk("%08x ", pgtbl[i].owner);
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate a physical address to a logical address.
|
|
|
|
* This will return the logical address of the first
|
|
|
|
* match.
|
|
|
|
*/
|
|
|
|
unsigned long vdma_phys2log(unsigned long paddr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int frame;
|
|
|
|
|
|
|
|
frame = paddr & ~(VDMA_PAGESIZE - 1);
|
|
|
|
|
|
|
|
for (i = 0; i < VDMA_PGTBL_ENTRIES; i++) {
|
|
|
|
if (pgtbl[i].frame == frame)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == VDMA_PGTBL_ENTRIES)
|
|
|
|
return ~0UL;
|
|
|
|
|
|
|
|
return (i << 12) + (paddr & (VDMA_PAGESIZE - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(vdma_phys2log);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate a logical DMA address to a physical address
|
|
|
|
*/
|
|
|
|
unsigned long vdma_log2phys(unsigned long laddr)
|
|
|
|
{
|
|
|
|
return pgtbl[laddr >> 12].frame + (laddr & (VDMA_PAGESIZE - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(vdma_log2phys);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print DMA statistics
|
|
|
|
*/
|
|
|
|
void vdma_stats(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printk("vdma_stats: CONFIG: %08x\n",
|
|
|
|
r4030_read_reg32(JAZZ_R4030_CONFIG));
|
|
|
|
printk("R4030 translation table base: %08x\n",
|
|
|
|
r4030_read_reg32(JAZZ_R4030_TRSTBL_BASE));
|
|
|
|
printk("R4030 translation table limit: %08x\n",
|
|
|
|
r4030_read_reg32(JAZZ_R4030_TRSTBL_LIM));
|
|
|
|
printk("vdma_stats: INV_ADDR: %08x\n",
|
|
|
|
r4030_read_reg32(JAZZ_R4030_INV_ADDR));
|
|
|
|
printk("vdma_stats: R_FAIL_ADDR: %08x\n",
|
|
|
|
r4030_read_reg32(JAZZ_R4030_R_FAIL_ADDR));
|
|
|
|
printk("vdma_stats: M_FAIL_ADDR: %08x\n",
|
|
|
|
r4030_read_reg32(JAZZ_R4030_M_FAIL_ADDR));
|
|
|
|
printk("vdma_stats: IRQ_SOURCE: %08x\n",
|
|
|
|
r4030_read_reg32(JAZZ_R4030_IRQ_SOURCE));
|
|
|
|
printk("vdma_stats: I386_ERROR: %08x\n",
|
|
|
|
r4030_read_reg32(JAZZ_R4030_I386_ERROR));
|
|
|
|
printk("vdma_chnl_modes: ");
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
printk("%04x ",
|
|
|
|
(unsigned) r4030_read_reg32(JAZZ_R4030_CHNL_MODE +
|
|
|
|
(i << 5)));
|
|
|
|
printk("\n");
|
|
|
|
printk("vdma_chnl_enables: ");
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
printk("%04x ",
|
|
|
|
(unsigned) r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
|
|
|
|
(i << 5)));
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DMA transfer functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable a DMA channel. Also clear any error conditions.
|
|
|
|
*/
|
|
|
|
void vdma_enable(int channel)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (vdma_debug)
|
|
|
|
printk("vdma_enable: channel %d\n", channel);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check error conditions first
|
|
|
|
*/
|
|
|
|
status = r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5));
|
|
|
|
if (status & 0x400)
|
|
|
|
printk("VDMA: Channel %d: Address error!\n", channel);
|
|
|
|
if (status & 0x200)
|
|
|
|
printk("VDMA: Channel %d: Memory error!\n", channel);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear all interrupt flags
|
|
|
|
*/
|
|
|
|
r4030_write_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5),
|
|
|
|
r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
|
|
|
|
(channel << 5)) | R4030_TC_INTR
|
|
|
|
| R4030_MEM_INTR | R4030_ADDR_INTR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable the desired channel
|
|
|
|
*/
|
|
|
|
r4030_write_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5),
|
|
|
|
r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
|
|
|
|
(channel << 5)) |
|
|
|
|
R4030_CHNL_ENABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(vdma_enable);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable a DMA channel
|
|
|
|
*/
|
|
|
|
void vdma_disable(int channel)
|
|
|
|
{
|
|
|
|
if (vdma_debug) {
|
|
|
|
int status =
|
|
|
|
r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
|
|
|
|
(channel << 5));
|
|
|
|
|
|
|
|
printk("vdma_disable: channel %d\n", channel);
|
|
|
|
printk("VDMA: channel %d status: %04x (%s) mode: "
|
|
|
|
"%02x addr: %06x count: %06x\n",
|
|
|
|
channel, status,
|
|
|
|
((status & 0x600) ? "ERROR" : "OK"),
|
|
|
|
(unsigned) r4030_read_reg32(JAZZ_R4030_CHNL_MODE +
|
|
|
|
(channel << 5)),
|
|
|
|
(unsigned) r4030_read_reg32(JAZZ_R4030_CHNL_ADDR +
|
|
|
|
(channel << 5)),
|
|
|
|
(unsigned) r4030_read_reg32(JAZZ_R4030_CHNL_COUNT +
|
|
|
|
(channel << 5)));
|
|
|
|
}
|
|
|
|
|
|
|
|
r4030_write_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5),
|
|
|
|
r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
|
|
|
|
(channel << 5)) &
|
|
|
|
~R4030_CHNL_ENABLE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* After disabling a DMA channel a remote bus register should be
|
|
|
|
* read to ensure that the current DMA acknowledge cycle is completed.
|
|
|
|
*/
|
|
|
|
*((volatile unsigned int *) JAZZ_DUMMY_DEVICE);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(vdma_disable);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set DMA mode. This function accepts the mode values used
|
|
|
|
* to set a PC-style DMA controller. For the SCSI and FDC
|
|
|
|
* channels, we also set the default modes each time we're
|
|
|
|
* called.
|
|
|
|
* NOTE: The FAST and BURST dma modes are supported by the
|
|
|
|
* R4030 Rev. 2 and PICA chipsets only. I leave them disabled
|
|
|
|
* for now.
|
|
|
|
*/
|
|
|
|
void vdma_set_mode(int channel, int mode)
|
|
|
|
{
|
|
|
|
if (vdma_debug)
|
|
|
|
printk("vdma_set_mode: channel %d, mode 0x%x\n", channel,
|
|
|
|
mode);
|
|
|
|
|
|
|
|
switch (channel) {
|
|
|
|
case JAZZ_SCSI_DMA: /* scsi */
|
|
|
|
r4030_write_reg32(JAZZ_R4030_CHNL_MODE + (channel << 5),
|
|
|
|
/* R4030_MODE_FAST | */
|
|
|
|
/* R4030_MODE_BURST | */
|
|
|
|
R4030_MODE_INTR_EN |
|
|
|
|
R4030_MODE_WIDTH_16 |
|
|
|
|
R4030_MODE_ATIME_80);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JAZZ_FLOPPY_DMA: /* floppy */
|
|
|
|
r4030_write_reg32(JAZZ_R4030_CHNL_MODE + (channel << 5),
|
|
|
|
/* R4030_MODE_FAST | */
|
|
|
|
/* R4030_MODE_BURST | */
|
|
|
|
R4030_MODE_INTR_EN |
|
|
|
|
R4030_MODE_WIDTH_8 |
|
|
|
|
R4030_MODE_ATIME_120);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JAZZ_AUDIOL_DMA:
|
|
|
|
case JAZZ_AUDIOR_DMA:
|
|
|
|
printk("VDMA: Audio DMA not supported yet.\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printk
|
|
|
|
("VDMA: vdma_set_mode() called with unsupported channel %d!\n",
|
|
|
|
channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case DMA_MODE_READ:
|
|
|
|
r4030_write_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5),
|
|
|
|
r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
|
|
|
|
(channel << 5)) &
|
|
|
|
~R4030_CHNL_WRITE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DMA_MODE_WRITE:
|
|
|
|
r4030_write_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5),
|
|
|
|
r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
|
|
|
|
(channel << 5)) |
|
|
|
|
R4030_CHNL_WRITE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printk
|
|
|
|
("VDMA: vdma_set_mode() called with unknown dma mode 0x%x\n",
|
|
|
|
mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(vdma_set_mode);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set Transfer Address
|
|
|
|
*/
|
|
|
|
void vdma_set_addr(int channel, long addr)
|
|
|
|
{
|
|
|
|
if (vdma_debug)
|
|
|
|
printk("vdma_set_addr: channel %d, addr %lx\n", channel,
|
|
|
|
addr);
|
|
|
|
|
|
|
|
r4030_write_reg32(JAZZ_R4030_CHNL_ADDR + (channel << 5), addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(vdma_set_addr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set Transfer Count
|
|
|
|
*/
|
|
|
|
void vdma_set_count(int channel, int count)
|
|
|
|
{
|
|
|
|
if (vdma_debug)
|
|
|
|
printk("vdma_set_count: channel %d, count %08x\n", channel,
|
|
|
|
(unsigned) count);
|
|
|
|
|
|
|
|
r4030_write_reg32(JAZZ_R4030_CHNL_COUNT + (channel << 5), count);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(vdma_set_count);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get Residual
|
|
|
|
*/
|
|
|
|
int vdma_get_residue(int channel)
|
|
|
|
{
|
|
|
|
int residual;
|
|
|
|
|
|
|
|
residual = r4030_read_reg32(JAZZ_R4030_CHNL_COUNT + (channel << 5));
|
|
|
|
|
|
|
|
if (vdma_debug)
|
|
|
|
printk("vdma_get_residual: channel %d: residual=%d\n",
|
|
|
|
channel, residual);
|
|
|
|
|
|
|
|
return residual;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get DMA channel enable register
|
|
|
|
*/
|
|
|
|
int vdma_get_enable(int channel)
|
|
|
|
{
|
|
|
|
int enable;
|
|
|
|
|
|
|
|
enable = r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5));
|
|
|
|
|
|
|
|
if (vdma_debug)
|
|
|
|
printk("vdma_get_enable: channel %d: enable=%d\n", channel,
|
|
|
|
enable);
|
|
|
|
|
|
|
|
return enable;
|
|
|
|
}
|
2007-08-25 17:01:50 +08:00
|
|
|
|
2018-06-15 19:08:50 +08:00
|
|
|
static void *jazz_dma_alloc(struct device *dev, size_t size,
|
|
|
|
dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
|
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
|
2018-09-08 17:22:43 +08:00
|
|
|
ret = dma_direct_alloc_pages(dev, size, dma_handle, gfp, attrs);
|
2018-06-15 19:08:50 +08:00
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*dma_handle = vdma_alloc(virt_to_phys(ret), size);
|
2018-11-22 02:18:58 +08:00
|
|
|
if (*dma_handle == DMA_MAPPING_ERROR) {
|
2018-09-08 17:22:43 +08:00
|
|
|
dma_direct_free_pages(dev, size, ret, *dma_handle, attrs);
|
2018-06-15 19:08:50 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void jazz_dma_free(struct device *dev, size_t size, void *vaddr,
|
|
|
|
dma_addr_t dma_handle, unsigned long attrs)
|
|
|
|
{
|
|
|
|
vdma_free(dma_handle);
|
2018-09-08 17:22:43 +08:00
|
|
|
dma_direct_free_pages(dev, size, vaddr, dma_handle, attrs);
|
2018-06-15 19:08:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static dma_addr_t jazz_dma_map_page(struct device *dev, struct page *page,
|
|
|
|
unsigned long offset, size_t size, enum dma_data_direction dir,
|
|
|
|
unsigned long attrs)
|
|
|
|
{
|
|
|
|
phys_addr_t phys = page_to_phys(page) + offset;
|
|
|
|
|
|
|
|
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
|
|
|
arch_sync_dma_for_device(dev, phys, size, dir);
|
|
|
|
return vdma_alloc(phys, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void jazz_dma_unmap_page(struct device *dev, dma_addr_t dma_addr,
|
|
|
|
size_t size, enum dma_data_direction dir, unsigned long attrs)
|
|
|
|
{
|
|
|
|
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
|
|
|
arch_sync_dma_for_cpu(dev, vdma_log2phys(dma_addr), size, dir);
|
|
|
|
vdma_free(dma_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int jazz_dma_map_sg(struct device *dev, struct scatterlist *sglist,
|
|
|
|
int nents, enum dma_data_direction dir, unsigned long attrs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct scatterlist *sg;
|
|
|
|
|
|
|
|
for_each_sg(sglist, sg, nents, i) {
|
|
|
|
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
|
|
|
arch_sync_dma_for_device(dev, sg_phys(sg), sg->length,
|
|
|
|
dir);
|
|
|
|
sg->dma_address = vdma_alloc(sg_phys(sg), sg->length);
|
2018-11-22 02:18:58 +08:00
|
|
|
if (sg->dma_address == DMA_MAPPING_ERROR)
|
2018-06-15 19:08:50 +08:00
|
|
|
return 0;
|
|
|
|
sg_dma_len(sg) = sg->length;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nents;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void jazz_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
|
|
|
|
int nents, enum dma_data_direction dir, unsigned long attrs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct scatterlist *sg;
|
|
|
|
|
|
|
|
for_each_sg(sglist, sg, nents, i) {
|
|
|
|
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
|
|
|
arch_sync_dma_for_cpu(dev, sg_phys(sg), sg->length,
|
|
|
|
dir);
|
|
|
|
vdma_free(sg->dma_address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void jazz_dma_sync_single_for_device(struct device *dev,
|
|
|
|
dma_addr_t addr, size_t size, enum dma_data_direction dir)
|
|
|
|
{
|
|
|
|
arch_sync_dma_for_device(dev, vdma_log2phys(addr), size, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void jazz_dma_sync_single_for_cpu(struct device *dev,
|
|
|
|
dma_addr_t addr, size_t size, enum dma_data_direction dir)
|
|
|
|
{
|
|
|
|
arch_sync_dma_for_cpu(dev, vdma_log2phys(addr), size, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void jazz_dma_sync_sg_for_device(struct device *dev,
|
|
|
|
struct scatterlist *sgl, int nents, enum dma_data_direction dir)
|
|
|
|
{
|
|
|
|
struct scatterlist *sg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_sg(sgl, sg, nents, i)
|
|
|
|
arch_sync_dma_for_device(dev, sg_phys(sg), sg->length, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void jazz_dma_sync_sg_for_cpu(struct device *dev,
|
|
|
|
struct scatterlist *sgl, int nents, enum dma_data_direction dir)
|
|
|
|
{
|
|
|
|
struct scatterlist *sg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_sg(sgl, sg, nents, i)
|
|
|
|
arch_sync_dma_for_cpu(dev, sg_phys(sg), sg->length, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct dma_map_ops jazz_dma_ops = {
|
|
|
|
.alloc = jazz_dma_alloc,
|
|
|
|
.free = jazz_dma_free,
|
|
|
|
.map_page = jazz_dma_map_page,
|
|
|
|
.unmap_page = jazz_dma_unmap_page,
|
|
|
|
.map_sg = jazz_dma_map_sg,
|
|
|
|
.unmap_sg = jazz_dma_unmap_sg,
|
|
|
|
.sync_single_for_cpu = jazz_dma_sync_single_for_cpu,
|
|
|
|
.sync_single_for_device = jazz_dma_sync_single_for_device,
|
|
|
|
.sync_sg_for_cpu = jazz_dma_sync_sg_for_cpu,
|
|
|
|
.sync_sg_for_device = jazz_dma_sync_sg_for_device,
|
|
|
|
.dma_supported = dma_direct_supported,
|
|
|
|
.cache_sync = arch_dma_cache_sync,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL(jazz_dma_ops);
|