From: Cristiano Giuffrida Date: Sat, 1 Mar 2014 21:27:07 +0000 (+0100) Subject: libsys: mark regions allocated for DMA as special X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/already%20found%20%2A/doxygen-warnings.log?a=commitdiff_plain;h=refs%2Fchanges%2F04%2F3104%2F2;p=minix.git libsys: mark regions allocated for DMA as special This ensures that they will not be relocated. Edited by David van Moolenbroek. Change-Id: Ic2a97bc65b94dfcf364c06577aa340a9a5299e74 --- diff --git a/minix/include/minix/sef.h b/minix/include/minix/sef.h index 395bc803f..49202ad9f 100644 --- a/minix/include/minix/sef.h +++ b/minix/include/minix/sef.h @@ -366,6 +366,9 @@ void sef_llvm_stack_refs_restore(char *stack_buff); int sef_llvm_state_transfer(sef_init_info_t *info); int sef_llvm_add_special_mem_region(void *addr, size_t len, const char* name); int sef_llvm_del_special_mem_region_by_addr(void *addr); +void *sef_llvm_ac_mmap(void *buf, size_t len, int prot, int flags, int fd, + off_t offset); +int sef_llvm_ac_munmap(void *buf, size_t len); int sef_llvm_ltckpt_enabled(void); int sef_llvm_get_ltckpt_offset(void); diff --git a/minix/lib/libsys/alloc_util.c b/minix/lib/libsys/alloc_util.c index 6aff23086..e09bb8e76 100644 --- a/minix/lib/libsys/alloc_util.c +++ b/minix/lib/libsys/alloc_util.c @@ -8,7 +8,7 @@ void *alloc_contig(size_t len, int flags, phys_bytes *phys) { - vir_bytes buf; + void* buf; int mmapflags = MAP_PREALLOC|MAP_CONTIG|MAP_ANON; if(flags & AC_LOWER16M) @@ -23,21 +23,21 @@ void *alloc_contig(size_t len, int flags, phys_bytes *phys) * pre-allocated and contiguous. */ errno = 0; - buf = (vir_bytes) mmap(0, len, PROT_READ|PROT_WRITE, mmapflags, -1, 0); - - if(buf == (vir_bytes) MAP_FAILED) { + buf = sef_llvm_ac_mmap(0, len, PROT_READ|PROT_WRITE, mmapflags, -1, 0); + if(buf == MAP_FAILED) { return NULL; } /* Get physical address, if requested. */ - if(phys != NULL && sys_umap(SELF, VM_D, buf, len, phys) != OK) + if(phys != NULL && sys_umap(SELF, VM_D, (vir_bytes)buf, len, + phys) != OK) panic("sys_umap_data_fb failed"); - return (void *) buf; + return buf; } int free_contig(void *addr, size_t len) { - return munmap(addr, len); + return sef_llvm_ac_munmap(addr, len); } diff --git a/minix/lib/libsys/sef_llvm.c b/minix/lib/libsys/sef_llvm.c index 15cf4236e..4f08fd972 100644 --- a/minix/lib/libsys/sef_llvm.c +++ b/minix/lib/libsys/sef_llvm.c @@ -153,6 +153,46 @@ int sef_llvm_del_special_mem_region_by_addr(void *addr) return st_del_special_mmapped_region_by_addr(addr); } +/*===========================================================================* + * sef_llvm_ac_mmap * + *===========================================================================*/ +void* sef_llvm_ac_mmap(void *buf, size_t len, int prot, int flags, int fd, + off_t offset) +{ + int r; + extern void* __attribute__((weak)) + _magic_real_mmap(void*, size_t, int, int, int, off_t); + if (!_magic_real_mmap) + return mmap(buf, len, prot, flags, fd, offset); + + /* Avoid regular dsentries for non-relocatable regions (e.g., DMA buffers). + */ + buf = _magic_real_mmap(buf, len, prot, flags, fd, offset); + if(buf == MAP_FAILED) + return buf; + r = sef_llvm_add_special_mem_region(buf, len, NULL); + if(r < 0) + printf("sef_llvm_add_special_mem_region failed: %d\n", r); + return buf; +} + +/*===========================================================================* + * sef_llvm_ac_munmap * + *===========================================================================*/ +int sef_llvm_ac_munmap(void *buf, size_t len) +{ + int r; + extern int __attribute__((weak)) _magic_real_munmap(void*, size_t); + if (!_magic_real_munmap) + return munmap(buf, len); + + if ((r = _magic_real_munmap(buf, len)) != 0) + return r; + if ((r = sef_llvm_del_special_mem_region_by_addr(buf)) < 0) + printf("sef_llvm_del_special_mem_region_by_addr failed: %d\n", r); + return 0; +} + /*===========================================================================* * sef_llvm_ltckpt_enabled * *===========================================================================*/