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
}
}
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);
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;
*/
if(buf != sbuf)
- munmap(buf, size);
+ free_contig(buf, size);
}
/*===========================================================================*
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;
}
#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;
_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
return (void *) buf;
}
+int free_contig(void *addr, size_t len)
+{
+ return munmap(addr, len);
+}
+