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!).
This commit is contained in:
parent
49284caf2a
commit
f08f2bd88c
6 changed files with 18 additions and 31 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue