From: Ben Gras Date: Wed, 10 Feb 2010 13:56:26 +0000 (+0000) Subject: new free_contig() and changes to make drivers use it; so now we X-Git-Tag: v3.1.7~293 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/mult.png?a=commitdiff_plain;h=f08f2bd88c09f087a8ef19a827ce9e4f421d2eb8;p=minix.git new free_contig() and changes to make drivers use it; so now we have malloc/free, alloc_contig/free_contig and mmap/munmap nicely paired up. memory uses malloc/free instead of mmap/munmap as it doesn't have to be contiguous for the ramdisks (and it might help if it doesn't!). --- diff --git a/drivers/at_wini/at_wini.c b/drivers/at_wini/at_wini.c index 274476ab9..9c97c6d51 100644 --- a/drivers/at_wini/at_wini.c +++ b/drivers/at_wini/at_wini.c @@ -318,29 +318,11 @@ PRIVATE void init_params() printf("at_wini%d: DMA for ATA devices is disabled.\n", w_instance); } else { /* Ask for anonymous memory for DMA, that is physically contiguous. */ - dma_buf = mmap(0, ATA_DMA_BUF_SIZE, PROT_READ|PROT_WRITE, - MAP_PREALLOC | MAP_CONTIG | MAP_ANON, -1, 0); - prdt = mmap(0, PRDT_BYTES, - PROT_READ|PROT_WRITE, - MAP_PREALLOC | MAP_CONTIG | MAP_ANON, -1, 0); - if(dma_buf == MAP_FAILED || prdt == MAP_FAILED) { + dma_buf = alloc_contig(ATA_DMA_BUF_SIZE, 0, &dma_buf_phys); + prdt = alloc_contig(PRDT_BYTES, 0, &prdt_phys); + if(!dma_buf || !prdt) { disable_dma = 1; printf("at_wini%d: no dma\n", w_instance); - } else { - s= sys_umap(SELF, VM_D, (vir_bytes)dma_buf, - ATA_DMA_BUF_SIZE, &dma_buf_phys); - if (s != 0) - panic("at_wini", "can't map dma buffer", s); - - s= sys_umap(SELF, VM_D, (vir_bytes)prdt, - PRDT_BYTES, &prdt_phys); - if (s != 0) - panic("at_wini", "can't map prd table", s); -#if 0 - printf("at_wini%d: physical dma_buf: 0x%lx, " - "prdt tab: 0x%lx\n", - w_instance, dma_buf_phys, prdt_phys); -#endif } } diff --git a/drivers/atl2/atl2.c b/drivers/atl2/atl2.c index 33963d56b..48d5e9a38 100644 --- a/drivers/atl2/atl2.c +++ b/drivers/atl2/atl2.c @@ -1137,9 +1137,9 @@ PRIVATE void atl2_shutdown(void) if ((r = sys_irqrmpolicy(&state.hook_id)) != OK) panic("atl2", "unable to deregister IRQ", r); - munmap(state.txd_base, ATL2_TXD_BUFSIZE); - munmap(state.txs_base, ATL2_TXS_COUNT * sizeof(u32_t)); - munmap(state.rxd_base_u, + free_contig(state.txd_base, ATL2_TXD_BUFSIZE); + free_contig(state.txs_base, ATL2_TXS_COUNT * sizeof(u32_t)); + free_contig(state.rxd_base_u, state.rxd_align + ATL2_RXD_COUNT * ATL2_RXD_SIZE); vm_unmap_phys(SELF, state.base, ATL2_MMAP_SIZE); diff --git a/drivers/filter/util.c b/drivers/filter/util.c index 7f476de39..3e3274093 100644 --- a/drivers/filter/util.c +++ b/drivers/filter/util.c @@ -20,9 +20,7 @@ char *flt_malloc(size_t size, char *sbuf, size_t ssize) if (size <= ssize) return sbuf; - p = mmap(NULL, size, PROT_READ | PROT_WRITE, - MAP_PREALLOC | MAP_CONTIG | MAP_ANON, -1, 0); - if (p == MAP_FAILED) + if(!(p = alloc_contig(size, 0, NULL))) panic(__FILE__, "out of memory", size); return p; @@ -37,7 +35,7 @@ void flt_free(char *buf, size_t size, char *sbuf) */ if(buf != sbuf) - munmap(buf, size); + free_contig(buf, size); } /*===========================================================================* diff --git a/drivers/memory/memory.c b/drivers/memory/memory.c index 736fe4ba7..3467b0a2b 100644 --- a/drivers/memory/memory.c +++ b/drivers/memory/memory.c @@ -452,7 +452,7 @@ message *m_ptr; /* pointer to control message */ panic("MEM","huge old ramdisk", NO_NUM); } size = ex64lo(dv->dv_size); - munmap((void *) m_vaddrs[dev], size); + free((void *) m_vaddrs[dev]); m_vaddrs[dev] = (vir_bytes) NULL; } @@ -461,11 +461,11 @@ message *m_ptr; /* pointer to control message */ #endif /* Try to allocate a piece of memory for the RAM disk. */ - if((mem = mmap(0, ramdev_size, PROT_READ|PROT_WRITE, - MAP_PREALLOC|MAP_ANON, -1, 0)) == MAP_FAILED) { + if(!(mem = malloc(ramdev_size))) { printf("MEM: failed to get memory for ramdisk\n"); return(ENOMEM); } + memset(mem, 0, ramdev_size); m_vaddrs[dev] = (vir_bytes) mem; diff --git a/include/minix/syslib.h b/include/minix/syslib.h index 8b89af9ef..4bb08288a 100644 --- a/include/minix/syslib.h +++ b/include/minix/syslib.h @@ -95,6 +95,8 @@ _PROTOTYPE( int sys_vmctl_reply_mapping, (int index, vir_bytes addr)); _PROTOTYPE( int sys_sdevio, (int req, long port, endpoint_t proc_ep, void *buffer, int count, vir_bytes offset)); _PROTOTYPE(void *alloc_contig, (size_t len, int flags, phys_bytes *phys)); +_PROTOTYPE(int free_contig, (void *addr, size_t len)); + #define AC_ALIGN4K 0x01 #define AC_LOWER16M 0x02 #define AC_ALIGN64K 0x04 diff --git a/lib/syslib/alloc_util.c b/lib/syslib/alloc_util.c index 1fe2e2ec9..217d1a793 100644 --- a/lib/syslib/alloc_util.c +++ b/lib/syslib/alloc_util.c @@ -73,3 +73,8 @@ void *alloc_contig(size_t len, int flags, phys_bytes *phys) return (void *) buf; } +int free_contig(void *addr, size_t len) +{ + return munmap(addr, len); +} +