Use bus_dmamem common.

This commit is contained in:
thorpej 2009-08-21 03:39:41 +00:00
parent 5e0605242c
commit 4f976b9bb1
2 changed files with 18 additions and 125 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus_dma.c,v 1.66 2008/06/04 12:41:40 ad Exp $ */
/* $NetBSD: bus_dma.c,v 1.67 2009/08/21 03:39:41 thorpej Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.66 2008/06/04 12:41:40 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.67 2009/08/21 03:39:41 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -48,6 +48,8 @@ __KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.66 2008/06/04 12:41:40 ad Exp $");
#include <machine/bus.h>
#include <machine/intr.h>
#include <common/bus_dma/bus_dmamem_common.h>
int _bus_dmamap_load_buffer_direct(bus_dma_tag_t,
bus_dmamap_t, void *, bus_size_t, struct vmspace *, int,
paddr_t *, int *, int);
@ -476,54 +478,10 @@ _bus_dmamem_alloc_range(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment,
bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs,
int flags, paddr_t low, paddr_t high)
{
paddr_t curaddr, lastaddr;
struct vm_page *m;
struct pglist mlist;
int curseg, error;
/* Always round the size. */
size = round_page(size);
/*
* Allocate pages from the VM system.
*/
error = uvm_pglistalloc(size, low, high, alignment, boundary,
&mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
if (error)
return (error);
/*
* Compute the location, size, and number of segments actually
* returned by the VM code.
*/
m = mlist.tqh_first;
curseg = 0;
lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
segs[curseg].ds_len = PAGE_SIZE;
m = m->pageq.queue.tqe_next;
for (; m != NULL; m = m->pageq.queue.tqe_next) {
curaddr = VM_PAGE_TO_PHYS(m);
#ifdef DIAGNOSTIC
if (curaddr < avail_start || curaddr >= high) {
printf("uvm_pglistalloc returned non-sensical"
" address 0x%lx\n", curaddr);
panic("_bus_dmamem_alloc");
}
#endif
if (curaddr == (lastaddr + PAGE_SIZE))
segs[curseg].ds_len += PAGE_SIZE;
else {
curseg++;
segs[curseg].ds_addr = curaddr;
segs[curseg].ds_len = PAGE_SIZE;
}
lastaddr = curaddr;
}
*rsegs = curseg + 1;
return (0);
return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
segs, nsegs, rsegs, flags,
low, high));
}
/*
@ -533,25 +491,8 @@ _bus_dmamem_alloc_range(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment,
void
_bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
{
struct vm_page *m;
bus_addr_t addr;
struct pglist mlist;
int curseg;
/*
* Build a list of pages to free back to the VM system.
*/
TAILQ_INIT(&mlist);
for (curseg = 0; curseg < nsegs; curseg++) {
for (addr = segs[curseg].ds_addr;
addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
addr += PAGE_SIZE) {
m = PHYS_TO_VM_PAGE(addr);
TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
}
}
uvm_pglistfree(&mlist);
_bus_dmamem_free_common(t, segs, nsegs);
}
/*
@ -562,11 +503,6 @@ int
_bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
size_t size, void **kvap, int flags)
{
vaddr_t va;
bus_addr_t addr;
int curseg;
const uvm_flag_t kmflags =
(flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
/*
* If we're only mapping 1 segment, use K0SEG, to avoid
@ -577,29 +513,7 @@ _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
return (0);
}
size = round_page(size);
va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
if (va == 0)
return (ENOMEM);
*kvap = (void *)va;
for (curseg = 0; curseg < nsegs; curseg++) {
for (addr = segs[curseg].ds_addr;
addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
if (size == 0)
panic("_bus_dmamem_map: size botch");
pmap_enter(pmap_kernel(), va, addr,
VM_PROT_READ | VM_PROT_WRITE,
PMAP_WIRED | VM_PROT_READ | VM_PROT_WRITE);
}
}
pmap_update(pmap_kernel());
return (0);
return (_bus_dmamem_map_common(t, segs, nsegs, size, kvap, flags, 0));
}
/*
@ -610,11 +524,6 @@ void
_bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
{
#ifdef DIAGNOSTIC
if ((u_long)kva & PGOFSET)
panic("_bus_dmamem_unmap");
#endif
/*
* Nothing to do if we mapped it with K0SEG.
*/
@ -622,10 +531,7 @@ _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
kva <= (void *)ALPHA_K0SEG_END)
return;
size = round_page(size);
pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
pmap_update(pmap_kernel());
uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
_bus_dmamem_unmap_common(t, kva, size);
}
/*
@ -636,26 +542,11 @@ paddr_t
_bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
off_t off, int prot, int flags)
{
int i;
bus_addr_t rv;
for (i = 0; i < nsegs; i++) {
#ifdef DIAGNOSTIC
if (off & PGOFSET)
panic("_bus_dmamem_mmap: offset unaligned");
if (segs[i].ds_addr & PGOFSET)
panic("_bus_dmamem_mmap: segment unaligned");
if (segs[i].ds_len & PGOFSET)
panic("_bus_dmamem_mmap: segment size not multiple"
" of page size");
#endif
if (off >= segs[i].ds_len) {
off -= segs[i].ds_len;
continue;
}
return (alpha_btop((char *)segs[i].ds_addr + off));
}
/* Page not found. */
rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
if (rv == (bus_addr_t)-1)
return (-1);
return (alpha_btop((char *)rv));
}

View File

@ -1,4 +1,4 @@
# $NetBSD: files.alpha,v 1.180 2008/11/19 18:35:57 ad Exp $
# $NetBSD: files.alpha,v 1.181 2009/08/21 03:39:41 thorpej Exp $
#
# alpha-specific configuration info
@ -422,6 +422,8 @@ file arch/alpha/common/comlogout.c
file dev/cons.c
file kern/kern_cctr.c
file common/bus_dma/bus_dmamem_common.c
# PROM console support (for ports that don't have native console support)
file arch/alpha/alpha/promcons.c