]> Zhao Yanbai Git Server - minix.git/commitdiff
new free_contig() and changes to make drivers use it; so now we
authorBen Gras <ben@minix3.org>
Wed, 10 Feb 2010 13:56:26 +0000 (13:56 +0000)
committerBen Gras <ben@minix3.org>
Wed, 10 Feb 2010 13:56:26 +0000 (13:56 +0000)
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!).

drivers/at_wini/at_wini.c
drivers/atl2/atl2.c
drivers/filter/util.c
drivers/memory/memory.c
include/minix/syslib.h
lib/syslib/alloc_util.c

index 274476ab9b53bcaf63b3803d636c7a6ad251ff25..9c97c6d510aceb72cc95c518ae84bdcdc491f751 100644 (file)
@@ -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
        }
   }
 
index 33963d56bed96a99a9cdf96570aea55efb5548a4..48d5e9a3813f828e513c055d7a3aa880ef3749b4 100644 (file)
@@ -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);
index 7f476de39f53524d25370bb4cef607a0840c2c46..3e3274093f1402a5d6f0994566006e8819d02204 100644 (file)
@@ -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);
 }
 
 /*===========================================================================*
index 736fe4ba79f7fe6308abab6d0d9ce548256a6558..3467b0a2bfad83de2f67758095d7026b002920c8 100644 (file)
@@ -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;
 
index 8b89af9efda000f8421d95fad1ef4a55bb9a452a..4bb08288a7ac350d270cb9b425b555e168cba22c 100644 (file)
@@ -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
index 1fe2e2ec9f949f7af43b5b9832bc8597a7c33971..217d1a7939d111a0eb963e486ac1a12a2aa89ae6 100644 (file)
@@ -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);
+}
+