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
|
2008-05-20 07:53:02 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* ioport.c: Simple io mapping allocator.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
|
|
|
|
* Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
|
|
|
|
*
|
|
|
|
* 1996: sparc_free_io, 1999: ioremap()/iounmap() by Pete Zaitcev.
|
|
|
|
*
|
|
|
|
* 2000/01/29
|
|
|
|
* <rth> zait: as long as pci_alloc_consistent produces something addressable,
|
|
|
|
* things are ok.
|
|
|
|
* <zaitcev> rth: no, it is relevant, because get_free_pages returns you a
|
|
|
|
* pointer into the big page mapping
|
|
|
|
* <rth> zait: so what?
|
|
|
|
* <rth> zait: remap_it_my_way(virt_to_phys(get_free_page()))
|
|
|
|
* <zaitcev> Hmm
|
|
|
|
* <zaitcev> Suppose I did this remap_it_my_way(virt_to_phys(get_free_page())).
|
|
|
|
* So far so good.
|
|
|
|
* <zaitcev> Now, driver calls pci_free_consistent(with result of
|
|
|
|
* remap_it_my_way()).
|
|
|
|
* <zaitcev> How do you find the address to pass to free_pages()?
|
|
|
|
* <rth> zait: walk the page tables? It's only two or three level after all.
|
|
|
|
* <rth> zait: you have to walk them anyway to remove the mapping.
|
|
|
|
* <zaitcev> Hmm
|
|
|
|
* <zaitcev> Sounds reasonable
|
|
|
|
*/
|
|
|
|
|
2006-06-30 05:35:33 +08:00
|
|
|
#include <linux/module.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/pci.h> /* struct pci_dev */
|
|
|
|
#include <linux/proc_fs.h>
|
2009-09-02 08:54:07 +08:00
|
|
|
#include <linux/seq_file.h>
|
2007-05-14 21:44:38 +08:00
|
|
|
#include <linux/scatterlist.h>
|
2018-07-31 16:02:04 +08:00
|
|
|
#include <linux/dma-noncoherent.h>
|
2008-08-08 06:33:36 +08:00
|
|
|
#include <linux/of_device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/vaddrs.h>
|
|
|
|
#include <asm/oplib.h>
|
2006-06-24 06:55:45 +08:00
|
|
|
#include <asm/prom.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/dma.h>
|
2008-08-26 13:47:20 +08:00
|
|
|
#include <asm/iommu.h>
|
|
|
|
#include <asm/io-unit.h>
|
2009-09-01 06:08:13 +08:00
|
|
|
#include <asm/leon.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-04-29 06:17:00 +08:00
|
|
|
/* This function must make sure that caches and memory are coherent after DMA
|
|
|
|
* On LEON systems without cache snooping it flushes the entire D-CACHE.
|
|
|
|
*/
|
|
|
|
static inline void dma_make_coherent(unsigned long pa, unsigned long len)
|
|
|
|
{
|
2012-05-26 12:43:29 +08:00
|
|
|
if (sparc_cpu_model == sparc_leon) {
|
|
|
|
if (!sparc_leon3_snooping_enabled())
|
|
|
|
leon_flush_dcache_all();
|
|
|
|
}
|
2011-04-29 06:17:00 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static void __iomem *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz);
|
|
|
|
static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys,
|
|
|
|
unsigned long size, char *name);
|
|
|
|
static void _sparc_free_io(struct resource *res);
|
|
|
|
|
2008-06-06 02:40:58 +08:00
|
|
|
static void register_proc_sparc_ioport(void);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* This points to the next to use virtual memory for DVMA mappings */
|
|
|
|
static struct resource _sparc_dvma = {
|
|
|
|
.name = "sparc_dvma", .start = DVMA_VADDR, .end = DVMA_END - 1
|
|
|
|
};
|
|
|
|
/* This points to the start of I/O mappings, cluable from outside. */
|
|
|
|
/*ext*/ struct resource sparc_iomap = {
|
|
|
|
.name = "sparc_iomap", .start = IOBASE_VADDR, .end = IOBASE_END - 1
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our mini-allocator...
|
|
|
|
* Boy this is gross! We need it because we must map I/O for
|
|
|
|
* timers and interrupt controller before the kmalloc is available.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define XNMLN 15
|
|
|
|
#define XNRES 10 /* SS-10 uses 8 */
|
|
|
|
|
|
|
|
struct xresource {
|
|
|
|
struct resource xres; /* Must be first */
|
|
|
|
int xflag; /* 1 == used */
|
|
|
|
char xname[XNMLN+1];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct xresource xresv[XNRES];
|
|
|
|
|
|
|
|
static struct xresource *xres_alloc(void) {
|
|
|
|
struct xresource *xrp;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
xrp = xresv;
|
|
|
|
for (n = 0; n < XNRES; n++) {
|
|
|
|
if (xrp->xflag == 0) {
|
|
|
|
xrp->xflag = 1;
|
|
|
|
return xrp;
|
|
|
|
}
|
|
|
|
xrp++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xres_free(struct xresource *xrp) {
|
|
|
|
xrp->xflag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are typically used in PCI drivers
|
|
|
|
* which are trying to be cross-platform.
|
|
|
|
*
|
|
|
|
* Bus type is always zero on IIep.
|
|
|
|
*/
|
2017-11-22 18:57:46 +08:00
|
|
|
void __iomem *ioremap(phys_addr_t offset, size_t size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
char name[14];
|
|
|
|
|
|
|
|
sprintf(name, "phys_%08x", (u32)offset);
|
2017-11-22 18:57:46 +08:00
|
|
|
return _sparc_alloc_io(0, (unsigned long)offset, size, name);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-01-09 08:58:05 +08:00
|
|
|
EXPORT_SYMBOL(ioremap);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2016-03-05 03:21:18 +08:00
|
|
|
* Complementary to ioremap().
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
void iounmap(volatile void __iomem *virtual)
|
|
|
|
{
|
|
|
|
unsigned long vaddr = (unsigned long) virtual & PAGE_MASK;
|
|
|
|
struct resource *res;
|
|
|
|
|
2011-05-08 02:58:02 +08:00
|
|
|
/*
|
|
|
|
* XXX Too slow. Can have 8192 DVMA pages on sun4m in the worst case.
|
|
|
|
* This probably warrants some sort of hashing.
|
|
|
|
*/
|
|
|
|
if ((res = lookup_resource(&sparc_iomap, vaddr)) == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("free_io/iounmap: cannot free %lx\n", vaddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_sparc_free_io(res);
|
|
|
|
|
|
|
|
if ((char *)res >= (char*)xresv && (char *)res < (char *)&xresv[XNRES]) {
|
|
|
|
xres_free((struct xresource *)res);
|
|
|
|
} else {
|
|
|
|
kfree(res);
|
|
|
|
}
|
|
|
|
}
|
2009-01-09 08:58:05 +08:00
|
|
|
EXPORT_SYMBOL(iounmap);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 05:35:33 +08:00
|
|
|
void __iomem *of_ioremap(struct resource *res, unsigned long offset,
|
|
|
|
unsigned long size, char *name)
|
|
|
|
{
|
|
|
|
return _sparc_alloc_io(res->flags & 0xF,
|
|
|
|
res->start + offset,
|
|
|
|
size, name);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(of_ioremap);
|
|
|
|
|
2006-12-29 13:01:32 +08:00
|
|
|
void of_iounmap(struct resource *res, void __iomem *base, unsigned long size)
|
2006-06-30 05:35:33 +08:00
|
|
|
{
|
|
|
|
iounmap(base);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(of_iounmap);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Meat of mapping
|
|
|
|
*/
|
|
|
|
static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys,
|
|
|
|
unsigned long size, char *name)
|
|
|
|
{
|
|
|
|
static int printed_full;
|
|
|
|
struct xresource *xres;
|
|
|
|
struct resource *res;
|
|
|
|
char *tack;
|
|
|
|
int tlen;
|
|
|
|
void __iomem *va; /* P3 diag */
|
|
|
|
|
|
|
|
if (name == NULL) name = "???";
|
|
|
|
|
2014-04-22 03:39:27 +08:00
|
|
|
if ((xres = xres_alloc()) != NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
tack = xres->xname;
|
|
|
|
res = &xres->xres;
|
|
|
|
} else {
|
|
|
|
if (!printed_full) {
|
|
|
|
printk("ioremap: done with statics, switching to malloc\n");
|
|
|
|
printed_full = 1;
|
|
|
|
}
|
|
|
|
tlen = strlen(name);
|
|
|
|
tack = kmalloc(sizeof (struct resource) + tlen + 1, GFP_KERNEL);
|
|
|
|
if (tack == NULL) return NULL;
|
|
|
|
memset(tack, 0, sizeof(struct resource));
|
|
|
|
res = (struct resource *) tack;
|
|
|
|
tack += sizeof (struct resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
strlcpy(tack, name, XNMLN+1);
|
|
|
|
res->name = tack;
|
|
|
|
|
|
|
|
va = _sparc_ioremap(res, busno, phys, size);
|
|
|
|
/* printk("ioremap(0x%x:%08lx[0x%lx])=%p\n", busno, phys, size, va); */ /* P3 diag */
|
|
|
|
return va;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
static void __iomem *
|
|
|
|
_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz)
|
|
|
|
{
|
|
|
|
unsigned long offset = ((unsigned long) pa) & (~PAGE_MASK);
|
|
|
|
|
|
|
|
if (allocate_resource(&sparc_iomap, res,
|
|
|
|
(offset + sz + PAGE_SIZE-1) & PAGE_MASK,
|
|
|
|
sparc_iomap.start, sparc_iomap.end, PAGE_SIZE, NULL, NULL) != 0) {
|
|
|
|
/* Usually we cannot see printks in this case. */
|
|
|
|
prom_printf("alloc_io_res(%s): cannot occupy\n",
|
|
|
|
(res->name != NULL)? res->name: "???");
|
|
|
|
prom_halt();
|
|
|
|
}
|
|
|
|
|
|
|
|
pa &= PAGE_MASK;
|
2012-05-13 16:21:25 +08:00
|
|
|
srmmu_mapiorange(bus, pa, res->start, resource_size(res));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-13 07:09:23 +08:00
|
|
|
return (void __iomem *)(unsigned long)(res->start + offset);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-03-05 03:21:18 +08:00
|
|
|
* Complementary to _sparc_ioremap().
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static void _sparc_free_io(struct resource *res)
|
|
|
|
{
|
|
|
|
unsigned long plen;
|
|
|
|
|
2011-06-10 00:13:32 +08:00
|
|
|
plen = resource_size(res);
|
2006-03-10 18:55:20 +08:00
|
|
|
BUG_ON((plen & (PAGE_SIZE-1)) != 0);
|
2012-05-13 16:21:25 +08:00
|
|
|
srmmu_unmapiorange(res->start, plen);
|
2005-04-17 06:20:36 +08:00
|
|
|
release_resource(res);
|
|
|
|
}
|
|
|
|
|
2018-12-03 21:04:32 +08:00
|
|
|
unsigned long sparc_dma_alloc_resource(struct device *dev, size_t len)
|
2018-12-03 21:02:26 +08:00
|
|
|
{
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
res = kzalloc(sizeof(*res), GFP_KERNEL);
|
|
|
|
if (!res)
|
|
|
|
return 0;
|
|
|
|
res->name = dev->of_node->name;
|
|
|
|
|
|
|
|
if (allocate_resource(&_sparc_dvma, res, len, _sparc_dvma.start,
|
|
|
|
_sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
|
|
|
|
printk("%s: cannot occupy 0x%zx", __func__, len);
|
|
|
|
kfree(res);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res->start;
|
|
|
|
}
|
|
|
|
|
2018-12-03 21:04:32 +08:00
|
|
|
bool sparc_dma_free_resource(void *cpu_addr, size_t size)
|
2018-12-03 21:02:26 +08:00
|
|
|
{
|
|
|
|
unsigned long addr = (unsigned long)cpu_addr;
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
res = lookup_resource(&_sparc_dvma, addr);
|
|
|
|
if (!res) {
|
|
|
|
printk("%s: cannot free %p\n", __func__, cpu_addr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((addr & (PAGE_SIZE - 1)) != 0) {
|
|
|
|
printk("%s: unaligned va %p\n", __func__, cpu_addr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = PAGE_ALIGN(size);
|
|
|
|
if (resource_size(res) != size) {
|
|
|
|
printk("%s: region 0x%lx asked 0x%zx\n",
|
|
|
|
__func__, (long)resource_size(res), size);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
release_resource(res);
|
|
|
|
kfree(res);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_SBUS
|
|
|
|
|
2008-08-27 14:33:42 +08:00
|
|
|
void sbus_set_sbus64(struct device *dev, int x)
|
2006-06-21 06:23:28 +08:00
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("sbus_set_sbus64: unsupported\n");
|
|
|
|
}
|
2009-01-09 08:58:05 +08:00
|
|
|
EXPORT_SYMBOL(sbus_set_sbus64);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-27 19:20:14 +08:00
|
|
|
static int __init sparc_register_ioport(void)
|
2006-06-24 06:55:45 +08:00
|
|
|
{
|
|
|
|
register_proc_sparc_ioport();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-27 19:20:14 +08:00
|
|
|
arch_initcall(sparc_register_ioport);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* CONFIG_SBUS */
|
|
|
|
|
2011-01-18 12:10:26 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Allocate and map kernel buffer using consistent mode DMA for a device.
|
|
|
|
* hwdev should be valid struct pci_dev pointer for PCI devices.
|
|
|
|
*/
|
2018-07-31 16:02:04 +08:00
|
|
|
void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
|
|
|
|
gfp_t gfp, unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-12-03 21:02:26 +08:00
|
|
|
unsigned long addr;
|
2011-01-18 12:10:28 +08:00
|
|
|
void *va;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-12-03 21:02:26 +08:00
|
|
|
if (!size || size > 256 * 1024) /* __get_free_pages() limit */
|
2005-04-17 06:20:36 +08:00
|
|
|
return NULL;
|
|
|
|
|
2018-12-03 21:02:26 +08:00
|
|
|
size = PAGE_ALIGN(size);
|
|
|
|
va = (void *) __get_free_pages(gfp, get_order(size));
|
|
|
|
if (!va) {
|
|
|
|
printk("%s: no %zd pages\n", __func__, size >> PAGE_SHIFT);
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-12-03 21:02:26 +08:00
|
|
|
addr = sparc_dma_alloc_resource(dev, size);
|
|
|
|
if (!addr)
|
2011-01-18 12:10:28 +08:00
|
|
|
goto err_nomem;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-12-03 21:02:26 +08:00
|
|
|
srmmu_mapiorange(0, virt_to_phys(va), addr, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-07-31 16:02:04 +08:00
|
|
|
*dma_handle = virt_to_phys(va);
|
2018-12-03 21:02:26 +08:00
|
|
|
return (void *)addr;
|
2011-01-18 12:10:28 +08:00
|
|
|
|
|
|
|
err_nomem:
|
2018-12-03 21:02:26 +08:00
|
|
|
free_pages((unsigned long)va, get_order(size));
|
2011-01-18 12:10:28 +08:00
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free and unmap a consistent DMA buffer.
|
2018-07-31 16:02:04 +08:00
|
|
|
* cpu_addr is what was returned arch_dma_alloc, size must be the same as what
|
|
|
|
* was passed into arch_dma_alloc, and likewise dma_addr must be the same as
|
|
|
|
* what *dma_ndler was set to.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2007-05-12 04:51:23 +08:00
|
|
|
* References to the memory and mappings associated with cpu_addr/dma_addr
|
2005-04-17 06:20:36 +08:00
|
|
|
* past this call are illegal.
|
|
|
|
*/
|
2018-07-31 16:02:04 +08:00
|
|
|
void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
|
|
|
|
dma_addr_t dma_addr, unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-12-03 21:02:26 +08:00
|
|
|
if (!sparc_dma_free_resource(cpu_addr, PAGE_ALIGN(size)))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2018-07-31 16:02:04 +08:00
|
|
|
dma_make_coherent(dma_addr, size);
|
|
|
|
srmmu_unmapiorange((unsigned long)cpu_addr, size);
|
|
|
|
free_pages((unsigned long)phys_to_virt(dma_addr), get_order(size));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-07-31 16:02:04 +08:00
|
|
|
/* IIep is write-through, not flushing on cpu to device transfer. */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-07-31 16:02:04 +08:00
|
|
|
void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
|
|
|
|
size_t size, enum dma_data_direction dir)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-07-31 16:02:04 +08:00
|
|
|
if (dir != PCI_DMA_TODEVICE)
|
|
|
|
dma_make_coherent(paddr, PAGE_ALIGN(size));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-08-10 10:53:16 +08:00
|
|
|
|
2018-12-03 21:04:32 +08:00
|
|
|
const struct dma_map_ops *dma_ops;
|
2011-01-18 12:10:26 +08:00
|
|
|
EXPORT_SYMBOL(dma_ops);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
|
2009-09-02 08:54:07 +08:00
|
|
|
static int sparc_io_proc_show(struct seq_file *m, void *v)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-09-02 08:54:07 +08:00
|
|
|
struct resource *root = m->private, *r;
|
2005-04-17 06:20:36 +08:00
|
|
|
const char *nm;
|
|
|
|
|
2009-09-02 08:54:07 +08:00
|
|
|
for (r = root->child; r != NULL; r = r->sibling) {
|
2014-04-22 03:39:27 +08:00
|
|
|
if ((nm = r->name) == NULL) nm = "???";
|
2009-09-02 08:54:07 +08:00
|
|
|
seq_printf(m, "%016llx-%016llx: %s\n",
|
2006-06-13 06:18:31 +08:00
|
|
|
(unsigned long long)r->start,
|
|
|
|
(unsigned long long)r->end, nm);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-09-02 08:54:07 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
|
2008-06-06 02:40:58 +08:00
|
|
|
static void register_proc_sparc_ioport(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2018-05-15 21:57:23 +08:00
|
|
|
proc_create_single_data("io_map", 0, NULL, sparc_io_proc_show,
|
|
|
|
&sparc_iomap);
|
|
|
|
proc_create_single_data("dvma_map", 0, NULL, sparc_io_proc_show,
|
|
|
|
&_sparc_dvma);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
}
|