libsys: mark regions allocated for DMA as special

This ensures that they will not be relocated.

Edited by David van Moolenbroek.

Change-Id: Ic2a97bc65b94dfcf364c06577aa340a9a5299e74
This commit is contained in:
Cristiano Giuffrida 2014-03-01 22:27:07 +01:00 committed by David van Moolenbroek
parent 162b8995bb
commit 5c8eb53d49
3 changed files with 50 additions and 7 deletions

View file

@ -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_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_add_special_mem_region(void *addr, size_t len, const char* name);
int sef_llvm_del_special_mem_region_by_addr(void *addr); 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_ltckpt_enabled(void);
int sef_llvm_get_ltckpt_offset(void); int sef_llvm_get_ltckpt_offset(void);

View file

@ -8,7 +8,7 @@
void *alloc_contig(size_t len, int flags, phys_bytes *phys) void *alloc_contig(size_t len, int flags, phys_bytes *phys)
{ {
vir_bytes buf; void* buf;
int mmapflags = MAP_PREALLOC|MAP_CONTIG|MAP_ANON; int mmapflags = MAP_PREALLOC|MAP_CONTIG|MAP_ANON;
if(flags & AC_LOWER16M) if(flags & AC_LOWER16M)
@ -23,21 +23,21 @@ void *alloc_contig(size_t len, int flags, phys_bytes *phys)
* pre-allocated and contiguous. * pre-allocated and contiguous.
*/ */
errno = 0; errno = 0;
buf = (vir_bytes) mmap(0, len, PROT_READ|PROT_WRITE, mmapflags, -1, 0); buf = sef_llvm_ac_mmap(0, len, PROT_READ|PROT_WRITE, mmapflags, -1, 0);
if(buf == MAP_FAILED) {
if(buf == (vir_bytes) MAP_FAILED) {
return NULL; return NULL;
} }
/* Get physical address, if requested. */ /* 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"); panic("sys_umap_data_fb failed");
return (void *) buf; return buf;
} }
int free_contig(void *addr, size_t len) int free_contig(void *addr, size_t len)
{ {
return munmap(addr, len); return sef_llvm_ac_munmap(addr, len);
} }

View file

@ -153,6 +153,46 @@ int sef_llvm_del_special_mem_region_by_addr(void *addr)
return st_del_special_mmapped_region_by_addr(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 * * sef_llvm_ltckpt_enabled *
*===========================================================================*/ *===========================================================================*/