From 8f5ef79d0f34211759b6c70325f7fafc18bcddbe Mon Sep 17 00:00:00 2001 From: takemura Date: Sun, 6 Jan 2002 12:39:55 +0000 Subject: [PATCH] Added _hpcmips_bd_mem_alloc_range, which was written by Katsuomi Hamajima. --- sys/arch/hpcmips/hpcmips/bus_dma.c | 32 ++++++++++++++++++---- sys/arch/hpcmips/include/bus_dma_hpcmips.h | 7 ++++- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/sys/arch/hpcmips/hpcmips/bus_dma.c b/sys/arch/hpcmips/hpcmips/bus_dma.c index bd6e14c76eb3..d1a63fba4e1c 100644 --- a/sys/arch/hpcmips/hpcmips/bus_dma.c +++ b/sys/arch/hpcmips/hpcmips/bus_dma.c @@ -1,4 +1,4 @@ -/* $NetBSD: bus_dma.c,v 1.14 2001/11/18 08:19:39 takemura Exp $ */ +/* $NetBSD: bus_dma.c,v 1.15 2002/01/06 12:39:55 takemura Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -512,22 +512,42 @@ _hpcmips_bd_mem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, int flags) { extern paddr_t avail_start, avail_end; /* XXX */ - vaddr_t curaddr, lastaddr; psize_t high; + + high = avail_end - PAGE_SIZE; + + return (_hpcmips_bd_mem_alloc_range(t, size, alignment, boundary, + segs, nsegs, rsegs, flags, avail_start, high)); +} + +/* + * Allocate physical memory from the given physical address range. + * Called by DMA-safe memory allocation methods. + */ +int +_hpcmips_bd_mem_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) +{ + vaddr_t curaddr, lastaddr; struct vm_page *m; struct pglist mlist; int curseg, error; +#ifdef DIAGNOSTIC + extern paddr_t avail_start, avail_end; /* XXX */ + high = high<(avail_end - PAGE_SIZE)? high: (avail_end - PAGE_SIZE); + low = low>avail_start? low: avail_start; +#endif /* Always round the size. */ size = round_page(size); - high = avail_end - PAGE_SIZE; - /* * Allocate pages from the VM system. */ TAILQ_INIT(&mlist); - error = uvm_pglistalloc(size, avail_start, high, alignment, boundary, + error = uvm_pglistalloc(size, low, high, alignment, boundary, &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0); if (error) return (error); @@ -545,7 +565,7 @@ _hpcmips_bd_mem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, for (; m != NULL; m = m->pageq.tqe_next) { curaddr = VM_PAGE_TO_PHYS(m); #ifdef DIAGNOSTIC - if (curaddr < avail_start || curaddr >= high) { + if (curaddr < low || curaddr >= high) { printf("uvm_pglistalloc returned non-sensical" " address 0x%lx\n", curaddr); panic("_hpcmips_bd_mem_alloc"); diff --git a/sys/arch/hpcmips/include/bus_dma_hpcmips.h b/sys/arch/hpcmips/include/bus_dma_hpcmips.h index 279421608259..7d8088d10b74 100644 --- a/sys/arch/hpcmips/include/bus_dma_hpcmips.h +++ b/sys/arch/hpcmips/include/bus_dma_hpcmips.h @@ -1,4 +1,4 @@ -/* $NetBSD: bus_dma_hpcmips.h,v 1.1 2001/11/18 08:19:40 takemura Exp $ */ +/* $NetBSD: bus_dma_hpcmips.h,v 1.2 2002/01/06 12:39:55 takemura Exp $ */ /*- * Copyright (c) 2001 TAKEMRUA Shin. All rights reserved. @@ -73,4 +73,9 @@ struct bus_dmamap_hpcmips { extern struct bus_dma_tag_hpcmips hpcmips_default_bus_dma_tag; bus_dma_protos(_hpcmips) +int _hpcmips_bd_mem_alloc_range __P((bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, + bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags, + vaddr_t low, vaddr_t high)); + #endif /* _BUS_DMA_HPCMIPS_H_ */