2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
** PARISC 1.1 Dynamic DMA mapping support.
|
|
|
|
** This implementation is for PA-RISC platforms that do not support
|
|
|
|
** I/O TLBs (aka DMA address translation hardware).
|
2011-08-15 08:02:26 +08:00
|
|
|
** See Documentation/DMA-API-HOWTO.txt for interface definitions.
|
2005-04-17 06:20:36 +08:00
|
|
|
**
|
|
|
|
** (c) Copyright 1999,2000 Hewlett-Packard Company
|
|
|
|
** (c) Copyright 2000 Grant Grundler
|
|
|
|
** (c) Copyright 2000 Philipp Rumpf <prumpf@tux.org>
|
|
|
|
** (c) Copyright 2000 John Marvin
|
|
|
|
**
|
|
|
|
** "leveraged" from 2.3.47: arch/ia64/kernel/pci-dma.c.
|
|
|
|
** (I assume it's from David Mosberger-Tang but there was no Copyright)
|
|
|
|
**
|
|
|
|
** AFAIK, all PA7100LC and PA7300LC platforms can use this code.
|
|
|
|
**
|
|
|
|
** - ggg
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.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>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/proc_fs.h>
|
2007-03-18 00:28:27 +08:00
|
|
|
#include <linux/seq_file.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/types.h>
|
2007-10-23 15:30:28 +08:00
|
|
|
#include <linux/scatterlist.h>
|
2011-08-02 01:12:26 +08:00
|
|
|
#include <linux/export.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/dma.h> /* for DMA_CHUNK_SIZE */
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/page.h> /* get_order */
|
|
|
|
#include <asm/pgalloc.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-10-22 10:50:48 +08:00
|
|
|
#include <asm/tlbflush.h> /* for purge_tlb_*() macros */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-11 09:35:03 +08:00
|
|
|
static struct proc_dir_entry * proc_gsc_root __read_mostly = NULL;
|
|
|
|
static unsigned long pcxl_used_bytes __read_mostly = 0;
|
|
|
|
static unsigned long pcxl_used_pages __read_mostly = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
extern unsigned long pcxl_dma_start; /* Start of pcxl dma mapping area */
|
2017-08-08 05:28:39 +08:00
|
|
|
static DEFINE_SPINLOCK(pcxl_res_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
static char *pcxl_res_map;
|
|
|
|
static int pcxl_res_hint;
|
|
|
|
static int pcxl_res_size;
|
|
|
|
|
|
|
|
#ifdef DEBUG_PCXL_RESOURCE
|
|
|
|
#define DBG_RES(x...) printk(x)
|
|
|
|
#else
|
|
|
|
#define DBG_RES(x...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Dump a hex representation of the resource map.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef DUMP_RESMAP
|
|
|
|
static
|
|
|
|
void dump_resmap(void)
|
|
|
|
{
|
|
|
|
u_long *res_ptr = (unsigned long *)pcxl_res_map;
|
|
|
|
u_long i = 0;
|
|
|
|
|
|
|
|
printk("res_map: ");
|
|
|
|
for(; i < (pcxl_res_size / sizeof(unsigned long)); ++i, ++res_ptr)
|
|
|
|
printk("%08lx ", *res_ptr);
|
|
|
|
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void dump_resmap(void) {;}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int pa11_dma_supported( struct device *dev, u64 mask)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int map_pte_uncached(pte_t * pte,
|
|
|
|
unsigned long vaddr,
|
|
|
|
unsigned long size, unsigned long *paddr_ptr)
|
|
|
|
{
|
|
|
|
unsigned long end;
|
|
|
|
unsigned long orig_vaddr = vaddr;
|
|
|
|
|
|
|
|
vaddr &= ~PMD_MASK;
|
|
|
|
end = vaddr + size;
|
|
|
|
if (end > PMD_SIZE)
|
|
|
|
end = PMD_SIZE;
|
|
|
|
do {
|
2009-06-17 04:51:48 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!pte_none(*pte))
|
|
|
|
printk(KERN_ERR "map_pte_uncached: page already exists\n");
|
2009-06-17 04:51:48 +08:00
|
|
|
purge_tlb_start(flags);
|
2016-11-25 09:06:32 +08:00
|
|
|
set_pte(pte, __mk_pte(*paddr_ptr, PAGE_KERNEL_UNC));
|
2005-04-17 06:20:36 +08:00
|
|
|
pdtlb_kernel(orig_vaddr);
|
2009-06-17 04:51:48 +08:00
|
|
|
purge_tlb_end(flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
vaddr += PAGE_SIZE;
|
|
|
|
orig_vaddr += PAGE_SIZE;
|
|
|
|
(*paddr_ptr) += PAGE_SIZE;
|
|
|
|
pte++;
|
|
|
|
} while (vaddr < end);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int map_pmd_uncached(pmd_t * pmd, unsigned long vaddr,
|
|
|
|
unsigned long size, unsigned long *paddr_ptr)
|
|
|
|
{
|
|
|
|
unsigned long end;
|
|
|
|
unsigned long orig_vaddr = vaddr;
|
|
|
|
|
|
|
|
vaddr &= ~PGDIR_MASK;
|
|
|
|
end = vaddr + size;
|
|
|
|
if (end > PGDIR_SIZE)
|
|
|
|
end = PGDIR_SIZE;
|
|
|
|
do {
|
[PATCH] mm: init_mm without ptlock
First step in pushing down the page_table_lock. init_mm.page_table_lock has
been used throughout the architectures (usually for ioremap): not to serialize
kernel address space allocation (that's usually vmlist_lock), but because
pud_alloc,pmd_alloc,pte_alloc_kernel expect caller holds it.
Reverse that: don't lock or unlock init_mm.page_table_lock in any of the
architectures; instead rely on pud_alloc,pmd_alloc,pte_alloc_kernel to take
and drop it when allocating a new one, to check lest a racing task already
did. Similarly no page_table_lock in vmalloc's map_vm_area.
Some temporary ugliness in __pud_alloc and __pmd_alloc: since they also handle
user mms, which are converted only by a later patch, for now they have to lock
differently according to whether or not it's init_mm.
If sources get muddled, there's a danger that an arch source taking
init_mm.page_table_lock will be mixed with common source also taking it (or
neither take it). So break the rules and make another change, which should
break the build for such a mismatch: remove the redundant mm arg from
pte_alloc_kernel (ppc64 scrapped its distinct ioremap_mm in 2.6.13).
Exceptions: arm26 used pte_alloc_kernel on user mm, now pte_alloc_map; ia64
used pte_alloc_map on init_mm, now pte_alloc_kernel; parisc had bad args to
pmd_alloc and pte_alloc_kernel in unused USE_HPPA_IOREMAP code; ppc64
map_io_page forgot to unlock on failure; ppc mmu_mapin_ram and ppc64 im_free
took page_table_lock for no good reason.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-10-30 09:16:21 +08:00
|
|
|
pte_t * pte = pte_alloc_kernel(pmd, vaddr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!pte)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (map_pte_uncached(pte, orig_vaddr, end - vaddr, paddr_ptr))
|
|
|
|
return -ENOMEM;
|
|
|
|
vaddr = (vaddr + PMD_SIZE) & PMD_MASK;
|
|
|
|
orig_vaddr += PMD_SIZE;
|
|
|
|
pmd++;
|
|
|
|
} while (vaddr < end);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int map_uncached_pages(unsigned long vaddr, unsigned long size,
|
|
|
|
unsigned long paddr)
|
|
|
|
{
|
|
|
|
pgd_t * dir;
|
|
|
|
unsigned long end = vaddr + size;
|
|
|
|
|
|
|
|
dir = pgd_offset_k(vaddr);
|
|
|
|
do {
|
|
|
|
pmd_t *pmd;
|
|
|
|
|
|
|
|
pmd = pmd_alloc(NULL, dir, vaddr);
|
|
|
|
if (!pmd)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (map_pmd_uncached(pmd, vaddr, end - vaddr, &paddr))
|
|
|
|
return -ENOMEM;
|
|
|
|
vaddr = vaddr + PGDIR_SIZE;
|
|
|
|
dir++;
|
|
|
|
} while (vaddr && (vaddr < end));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void unmap_uncached_pte(pmd_t * pmd, unsigned long vaddr,
|
|
|
|
unsigned long size)
|
|
|
|
{
|
|
|
|
pte_t * pte;
|
|
|
|
unsigned long end;
|
|
|
|
unsigned long orig_vaddr = vaddr;
|
|
|
|
|
|
|
|
if (pmd_none(*pmd))
|
|
|
|
return;
|
|
|
|
if (pmd_bad(*pmd)) {
|
|
|
|
pmd_ERROR(*pmd);
|
|
|
|
pmd_clear(pmd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pte = pte_offset_map(pmd, vaddr);
|
|
|
|
vaddr &= ~PMD_MASK;
|
|
|
|
end = vaddr + size;
|
|
|
|
if (end > PMD_SIZE)
|
|
|
|
end = PMD_SIZE;
|
|
|
|
do {
|
2009-06-17 04:51:48 +08:00
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
pte_t page = *pte;
|
2009-06-17 04:51:48 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
pte_clear(&init_mm, vaddr, pte);
|
2009-06-17 04:51:48 +08:00
|
|
|
purge_tlb_start(flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
pdtlb_kernel(orig_vaddr);
|
2009-06-17 04:51:48 +08:00
|
|
|
purge_tlb_end(flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
vaddr += PAGE_SIZE;
|
|
|
|
orig_vaddr += PAGE_SIZE;
|
|
|
|
pte++;
|
|
|
|
if (pte_none(page) || pte_present(page))
|
|
|
|
continue;
|
|
|
|
printk(KERN_CRIT "Whee.. Swapped out page in kernel page table\n");
|
|
|
|
} while (vaddr < end);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void unmap_uncached_pmd(pgd_t * dir, unsigned long vaddr,
|
|
|
|
unsigned long size)
|
|
|
|
{
|
|
|
|
pmd_t * pmd;
|
|
|
|
unsigned long end;
|
|
|
|
unsigned long orig_vaddr = vaddr;
|
|
|
|
|
|
|
|
if (pgd_none(*dir))
|
|
|
|
return;
|
|
|
|
if (pgd_bad(*dir)) {
|
|
|
|
pgd_ERROR(*dir);
|
|
|
|
pgd_clear(dir);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pmd = pmd_offset(dir, vaddr);
|
|
|
|
vaddr &= ~PGDIR_MASK;
|
|
|
|
end = vaddr + size;
|
|
|
|
if (end > PGDIR_SIZE)
|
|
|
|
end = PGDIR_SIZE;
|
|
|
|
do {
|
|
|
|
unmap_uncached_pte(pmd, orig_vaddr, end - vaddr);
|
|
|
|
vaddr = (vaddr + PMD_SIZE) & PMD_MASK;
|
|
|
|
orig_vaddr += PMD_SIZE;
|
|
|
|
pmd++;
|
|
|
|
} while (vaddr < end);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unmap_uncached_pages(unsigned long vaddr, unsigned long size)
|
|
|
|
{
|
|
|
|
pgd_t * dir;
|
|
|
|
unsigned long end = vaddr + size;
|
|
|
|
|
|
|
|
dir = pgd_offset_k(vaddr);
|
|
|
|
do {
|
|
|
|
unmap_uncached_pmd(dir, vaddr, end - vaddr);
|
|
|
|
vaddr = vaddr + PGDIR_SIZE;
|
|
|
|
dir++;
|
|
|
|
} while (vaddr && (vaddr < end));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PCXL_SEARCH_LOOP(idx, mask, size) \
|
|
|
|
for(; res_ptr < res_end; ++res_ptr) \
|
|
|
|
{ \
|
|
|
|
if(0 == ((*res_ptr) & mask)) { \
|
|
|
|
*res_ptr |= mask; \
|
|
|
|
idx = (int)((u_long)res_ptr - (u_long)pcxl_res_map); \
|
|
|
|
pcxl_res_hint = idx + (size >> 3); \
|
|
|
|
goto resource_found; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PCXL_FIND_FREE_MAPPING(idx, mask, size) { \
|
|
|
|
u##size *res_ptr = (u##size *)&(pcxl_res_map[pcxl_res_hint & ~((size >> 3) - 1)]); \
|
|
|
|
u##size *res_end = (u##size *)&pcxl_res_map[pcxl_res_size]; \
|
|
|
|
PCXL_SEARCH_LOOP(idx, mask, size); \
|
|
|
|
res_ptr = (u##size *)&pcxl_res_map[0]; \
|
|
|
|
PCXL_SEARCH_LOOP(idx, mask, size); \
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long
|
|
|
|
pcxl_alloc_range(size_t size)
|
|
|
|
{
|
|
|
|
int res_idx;
|
|
|
|
u_long mask, flags;
|
|
|
|
unsigned int pages_needed = size >> PAGE_SHIFT;
|
|
|
|
|
|
|
|
mask = (u_long) -1L;
|
|
|
|
mask >>= BITS_PER_LONG - pages_needed;
|
|
|
|
|
|
|
|
DBG_RES("pcxl_alloc_range() size: %d pages_needed %d pages_mask 0x%08lx\n",
|
|
|
|
size, pages_needed, mask);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pcxl_res_lock, flags);
|
|
|
|
|
|
|
|
if(pages_needed <= 8) {
|
|
|
|
PCXL_FIND_FREE_MAPPING(res_idx, mask, 8);
|
|
|
|
} else if(pages_needed <= 16) {
|
|
|
|
PCXL_FIND_FREE_MAPPING(res_idx, mask, 16);
|
|
|
|
} else if(pages_needed <= 32) {
|
|
|
|
PCXL_FIND_FREE_MAPPING(res_idx, mask, 32);
|
|
|
|
} else {
|
|
|
|
panic("%s: pcxl_alloc_range() Too many pages to map.\n",
|
|
|
|
__FILE__);
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_resmap();
|
|
|
|
panic("%s: pcxl_alloc_range() out of dma mapping resources\n",
|
|
|
|
__FILE__);
|
|
|
|
|
|
|
|
resource_found:
|
|
|
|
|
|
|
|
DBG_RES("pcxl_alloc_range() res_idx %d mask 0x%08lx res_hint: %d\n",
|
|
|
|
res_idx, mask, pcxl_res_hint);
|
|
|
|
|
|
|
|
pcxl_used_pages += pages_needed;
|
|
|
|
pcxl_used_bytes += ((pages_needed >> 3) ? (pages_needed >> 3) : 1);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&pcxl_res_lock, flags);
|
|
|
|
|
|
|
|
dump_resmap();
|
|
|
|
|
|
|
|
/*
|
|
|
|
** return the corresponding vaddr in the pcxl dma map
|
|
|
|
*/
|
|
|
|
return (pcxl_dma_start + (res_idx << (PAGE_SHIFT + 3)));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PCXL_FREE_MAPPINGS(idx, m, size) \
|
|
|
|
u##size *res_ptr = (u##size *)&(pcxl_res_map[(idx) + (((size >> 3) - 1) & (~((size >> 3) - 1)))]); \
|
|
|
|
/* BUG_ON((*res_ptr & m) != m); */ \
|
|
|
|
*res_ptr &= ~m;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** clear bits in the pcxl resource map
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pcxl_free_range(unsigned long vaddr, size_t size)
|
|
|
|
{
|
|
|
|
u_long mask, flags;
|
|
|
|
unsigned int res_idx = (vaddr - pcxl_dma_start) >> (PAGE_SHIFT + 3);
|
|
|
|
unsigned int pages_mapped = size >> PAGE_SHIFT;
|
|
|
|
|
|
|
|
mask = (u_long) -1L;
|
|
|
|
mask >>= BITS_PER_LONG - pages_mapped;
|
|
|
|
|
|
|
|
DBG_RES("pcxl_free_range() res_idx: %d size: %d pages_mapped %d mask 0x%08lx\n",
|
|
|
|
res_idx, size, pages_mapped, mask);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pcxl_res_lock, flags);
|
|
|
|
|
|
|
|
if(pages_mapped <= 8) {
|
|
|
|
PCXL_FREE_MAPPINGS(res_idx, mask, 8);
|
|
|
|
} else if(pages_mapped <= 16) {
|
|
|
|
PCXL_FREE_MAPPINGS(res_idx, mask, 16);
|
|
|
|
} else if(pages_mapped <= 32) {
|
|
|
|
PCXL_FREE_MAPPINGS(res_idx, mask, 32);
|
|
|
|
} else {
|
|
|
|
panic("%s: pcxl_free_range() Too many pages to unmap.\n",
|
|
|
|
__FILE__);
|
|
|
|
}
|
|
|
|
|
|
|
|
pcxl_used_pages -= (pages_mapped ? pages_mapped : 1);
|
|
|
|
pcxl_used_bytes -= ((pages_mapped >> 3) ? (pages_mapped >> 3) : 1);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&pcxl_res_lock, flags);
|
|
|
|
|
|
|
|
dump_resmap();
|
|
|
|
}
|
|
|
|
|
2007-03-18 00:28:27 +08:00
|
|
|
static int proc_pcxl_dma_show(struct seq_file *m, void *v)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
u_long i = 0;
|
|
|
|
unsigned long *res_ptr = (u_long *)pcxl_res_map;
|
|
|
|
#endif
|
|
|
|
unsigned long total_pages = pcxl_res_size << 3; /* 8 bits per byte */
|
|
|
|
|
|
|
|
seq_printf(m, "\nDMA Mapping Area size : %d bytes (%ld pages)\n",
|
|
|
|
PCXL_DMA_MAP_SIZE, total_pages);
|
|
|
|
|
|
|
|
seq_printf(m, "Resource bitmap : %d bytes\n", pcxl_res_size);
|
|
|
|
|
|
|
|
seq_puts(m, " total: free: used: % used:\n");
|
|
|
|
seq_printf(m, "blocks %8d %8ld %8ld %8ld%%\n", pcxl_res_size,
|
|
|
|
pcxl_res_size - pcxl_used_bytes, pcxl_used_bytes,
|
|
|
|
(pcxl_used_bytes * 100) / pcxl_res_size);
|
|
|
|
|
|
|
|
seq_printf(m, "pages %8ld %8ld %8ld %8ld%%\n", total_pages,
|
|
|
|
total_pages - pcxl_used_pages, pcxl_used_pages,
|
|
|
|
(pcxl_used_pages * 100 / total_pages));
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
seq_puts(m, "\nResource bitmap:");
|
|
|
|
|
|
|
|
for(; i < (pcxl_res_size / sizeof(u_long)); ++i, ++res_ptr) {
|
|
|
|
if ((i & 7) == 0)
|
|
|
|
seq_puts(m,"\n ");
|
|
|
|
seq_printf(m, "%s %08lx", buf, *res_ptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
seq_putc(m, '\n');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int proc_pcxl_dma_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, proc_pcxl_dma_show, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations proc_pcxl_dma_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = proc_pcxl_dma_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int __init
|
|
|
|
pcxl_dma_init(void)
|
|
|
|
{
|
2005-10-22 10:50:48 +08:00
|
|
|
if (pcxl_dma_start == 0)
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-22 10:50:48 +08:00
|
|
|
pcxl_res_size = PCXL_DMA_MAP_SIZE >> (PAGE_SHIFT + 3);
|
|
|
|
pcxl_res_hint = 0;
|
|
|
|
pcxl_res_map = (char *)__get_free_pages(GFP_KERNEL,
|
2005-04-17 06:20:36 +08:00
|
|
|
get_order(pcxl_res_size));
|
2005-10-22 10:50:48 +08:00
|
|
|
memset(pcxl_res_map, 0, pcxl_res_size);
|
2006-11-06 06:24:48 +08:00
|
|
|
proc_gsc_root = proc_mkdir("gsc", NULL);
|
2005-10-22 10:50:48 +08:00
|
|
|
if (!proc_gsc_root)
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"pcxl_dma_init: Unable to create gsc /proc dir entry\n");
|
|
|
|
else {
|
|
|
|
struct proc_dir_entry* ent;
|
2008-04-29 16:02:25 +08:00
|
|
|
ent = proc_create("pcxl_dma", 0, proc_gsc_root,
|
|
|
|
&proc_pcxl_dma_ops);
|
|
|
|
if (!ent)
|
2005-10-22 10:50:48 +08:00
|
|
|
printk(KERN_WARNING
|
|
|
|
"pci-dma.c: Unable to create pcxl_dma /proc entry.\n");
|
|
|
|
}
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
__initcall(pcxl_dma_init);
|
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
static void *pa11_dma_alloc(struct device *dev, size_t size,
|
2016-08-04 04:46:00 +08:00
|
|
|
dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long vaddr;
|
|
|
|
unsigned long paddr;
|
|
|
|
int order;
|
|
|
|
|
|
|
|
order = get_order(size);
|
|
|
|
size = 1 << (order + PAGE_SHIFT);
|
|
|
|
vaddr = pcxl_alloc_range(size);
|
|
|
|
paddr = __get_free_pages(flag, order);
|
|
|
|
flush_kernel_dcache_range(paddr, size);
|
|
|
|
paddr = __pa(paddr);
|
|
|
|
map_uncached_pages(vaddr, size, paddr);
|
|
|
|
*dma_handle = (dma_addr_t) paddr;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* This probably isn't needed to support EISA cards.
|
|
|
|
** ISA cards will certainly only support 24-bit DMA addressing.
|
|
|
|
** Not clear if we can, want, or need to support ISA.
|
|
|
|
*/
|
|
|
|
if (!dev || *dev->coherent_dma_mask < 0xffffffff)
|
|
|
|
gfp |= GFP_DMA;
|
|
|
|
#endif
|
|
|
|
return (void *)vaddr;
|
|
|
|
}
|
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
static void pa11_dma_free(struct device *dev, size_t size, void *vaddr,
|
2016-08-04 04:46:00 +08:00
|
|
|
dma_addr_t dma_handle, unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int order;
|
|
|
|
|
|
|
|
order = get_order(size);
|
|
|
|
size = 1 << (order + PAGE_SHIFT);
|
|
|
|
unmap_uncached_pages((unsigned long)vaddr, size);
|
|
|
|
pcxl_free_range((unsigned long)vaddr, size);
|
|
|
|
free_pages((unsigned long)__va(dma_handle), order);
|
|
|
|
}
|
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
static dma_addr_t pa11_dma_map_page(struct device *dev, struct page *page,
|
|
|
|
unsigned long offset, size_t size,
|
2016-08-04 04:46:00 +08:00
|
|
|
enum dma_data_direction direction, unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2016-01-21 07:01:47 +08:00
|
|
|
void *addr = page_address(page) + offset;
|
2009-01-06 19:57:01 +08:00
|
|
|
BUG_ON(direction == DMA_NONE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-12-15 07:05:06 +08:00
|
|
|
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
|
|
|
flush_kernel_dcache_range((unsigned long) addr, size);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return virt_to_phys(addr);
|
|
|
|
}
|
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
static void pa11_dma_unmap_page(struct device *dev, dma_addr_t dma_handle,
|
|
|
|
size_t size, enum dma_data_direction direction,
|
2016-08-04 04:46:00 +08:00
|
|
|
unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-01-06 19:57:01 +08:00
|
|
|
BUG_ON(direction == DMA_NONE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-12-15 07:05:06 +08:00
|
|
|
if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
|
|
|
|
return;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (direction == DMA_TO_DEVICE)
|
2016-12-15 07:05:06 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For PCI_DMA_FROMDEVICE this flush is not necessary for the
|
|
|
|
* simple map/unmap case. However, it IS necessary if if
|
|
|
|
* pci_dma_sync_single_* has been called and the buffer reused.
|
|
|
|
*/
|
|
|
|
|
|
|
|
flush_kernel_dcache_range((unsigned long) phys_to_virt(dma_handle), size);
|
|
|
|
}
|
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
static int pa11_dma_map_sg(struct device *dev, struct scatterlist *sglist,
|
|
|
|
int nents, enum dma_data_direction direction,
|
2016-08-04 04:46:00 +08:00
|
|
|
unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
2015-06-25 07:55:37 +08:00
|
|
|
struct scatterlist *sg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-06 19:57:01 +08:00
|
|
|
BUG_ON(direction == DMA_NONE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-06-25 07:55:37 +08:00
|
|
|
for_each_sg(sglist, sg, nents, i) {
|
|
|
|
unsigned long vaddr = (unsigned long)sg_virt(sg);
|
|
|
|
|
|
|
|
sg_dma_address(sg) = (dma_addr_t) virt_to_phys(vaddr);
|
|
|
|
sg_dma_len(sg) = sg->length;
|
2016-12-15 07:05:06 +08:00
|
|
|
|
|
|
|
if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
|
|
|
|
continue;
|
|
|
|
|
2015-06-25 07:55:37 +08:00
|
|
|
flush_kernel_dcache_range(vaddr, sg->length);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return nents;
|
|
|
|
}
|
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
static void pa11_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
|
|
|
|
int nents, enum dma_data_direction direction,
|
2016-08-04 04:46:00 +08:00
|
|
|
unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
2015-06-25 07:55:37 +08:00
|
|
|
struct scatterlist *sg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-06 19:57:01 +08:00
|
|
|
BUG_ON(direction == DMA_NONE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-12-15 07:05:06 +08:00
|
|
|
if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
|
|
|
|
return;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (direction == DMA_TO_DEVICE)
|
2016-12-15 07:05:06 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* once we do combining we'll need to use phys_to_virt(sg_dma_address(sglist)) */
|
|
|
|
|
2015-06-25 07:55:37 +08:00
|
|
|
for_each_sg(sglist, sg, nents, i)
|
|
|
|
flush_kernel_vmap_range(sg_virt(sg), sg->length);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
static void pa11_dma_sync_single_for_cpu(struct device *dev,
|
|
|
|
dma_addr_t dma_handle, size_t size,
|
|
|
|
enum dma_data_direction direction)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-01-06 19:57:01 +08:00
|
|
|
BUG_ON(direction == DMA_NONE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
flush_kernel_dcache_range((unsigned long) phys_to_virt(dma_handle),
|
|
|
|
size);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
static void pa11_dma_sync_single_for_device(struct device *dev,
|
|
|
|
dma_addr_t dma_handle, size_t size,
|
|
|
|
enum dma_data_direction direction)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-01-06 19:57:01 +08:00
|
|
|
BUG_ON(direction == DMA_NONE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
flush_kernel_dcache_range((unsigned long) phys_to_virt(dma_handle),
|
|
|
|
size);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pa11_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sglist, int nents, enum dma_data_direction direction)
|
|
|
|
{
|
|
|
|
int i;
|
2015-06-25 07:55:37 +08:00
|
|
|
struct scatterlist *sg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* once we do combining we'll need to use phys_to_virt(sg_dma_address(sglist)) */
|
|
|
|
|
2015-06-25 07:55:37 +08:00
|
|
|
for_each_sg(sglist, sg, nents, i)
|
|
|
|
flush_kernel_vmap_range(sg_virt(sg), sg->length);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pa11_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sglist, int nents, enum dma_data_direction direction)
|
|
|
|
{
|
|
|
|
int i;
|
2015-06-25 07:55:37 +08:00
|
|
|
struct scatterlist *sg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* once we do combining we'll need to use phys_to_virt(sg_dma_address(sglist)) */
|
|
|
|
|
2015-06-25 07:55:37 +08:00
|
|
|
for_each_sg(sglist, sg, nents, i)
|
|
|
|
flush_kernel_vmap_range(sg_virt(sg), sg->length);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2017-01-21 05:04:01 +08:00
|
|
|
const struct dma_map_ops pcxl_dma_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.dma_supported = pa11_dma_supported,
|
2016-01-21 07:01:47 +08:00
|
|
|
.alloc = pa11_dma_alloc,
|
|
|
|
.free = pa11_dma_free,
|
|
|
|
.map_page = pa11_dma_map_page,
|
|
|
|
.unmap_page = pa11_dma_unmap_page,
|
2005-04-17 06:20:36 +08:00
|
|
|
.map_sg = pa11_dma_map_sg,
|
|
|
|
.unmap_sg = pa11_dma_unmap_sg,
|
2016-01-21 07:01:47 +08:00
|
|
|
.sync_single_for_cpu = pa11_dma_sync_single_for_cpu,
|
|
|
|
.sync_single_for_device = pa11_dma_sync_single_for_device,
|
|
|
|
.sync_sg_for_cpu = pa11_dma_sync_sg_for_cpu,
|
|
|
|
.sync_sg_for_device = pa11_dma_sync_sg_for_device,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
static void *pcx_dma_alloc(struct device *dev, size_t size,
|
2016-08-04 04:46:00 +08:00
|
|
|
dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-10-17 05:24:58 +08:00
|
|
|
void *addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-08-04 04:46:00 +08:00
|
|
|
if ((attrs & DMA_ATTR_NON_CONSISTENT) == 0)
|
2016-01-21 07:01:47 +08:00
|
|
|
return NULL;
|
|
|
|
|
2007-10-17 05:24:58 +08:00
|
|
|
addr = (void *)__get_free_pages(flag, get_order(size));
|
|
|
|
if (addr)
|
2005-04-17 06:20:36 +08:00
|
|
|
*dma_handle = (dma_addr_t)virt_to_phys(addr);
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2016-01-21 07:01:47 +08:00
|
|
|
static void pcx_dma_free(struct device *dev, size_t size, void *vaddr,
|
2016-08-04 04:46:00 +08:00
|
|
|
dma_addr_t iova, unsigned long attrs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-10-17 05:24:58 +08:00
|
|
|
free_pages((unsigned long)vaddr, get_order(size));
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-21 05:04:01 +08:00
|
|
|
const struct dma_map_ops pcx_dma_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.dma_supported = pa11_dma_supported,
|
2016-01-21 07:01:47 +08:00
|
|
|
.alloc = pcx_dma_alloc,
|
|
|
|
.free = pcx_dma_free,
|
|
|
|
.map_page = pa11_dma_map_page,
|
|
|
|
.unmap_page = pa11_dma_unmap_page,
|
2005-04-17 06:20:36 +08:00
|
|
|
.map_sg = pa11_dma_map_sg,
|
|
|
|
.unmap_sg = pa11_dma_unmap_sg,
|
2016-01-21 07:01:47 +08:00
|
|
|
.sync_single_for_cpu = pa11_dma_sync_single_for_cpu,
|
|
|
|
.sync_single_for_device = pa11_dma_sync_single_for_device,
|
|
|
|
.sync_sg_for_cpu = pa11_dma_sync_sg_for_cpu,
|
|
|
|
.sync_sg_for_device = pa11_dma_sync_sg_for_device,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|