7 #include <minix/sysutil.h>
9 int sys_umap_data_fb(endpoint_t ep
, vir_bytes buf
, vir_bytes len
, phys_bytes
*phys
)
13 if((r
=sys_umap(ep
, VM_D
, buf
, len
, phys
)) != OK
) {
16 r
= sys_umap(ep
, D
, buf
, len
, phys
);
24 void *alloc_contig(size_t len
, int flags
, phys_bytes
*phys
)
27 int mmapflags
= MAP_PREALLOC
|MAP_CONTIG
|MAP_ANON
;
29 if(flags
& AC_LOWER16M
)
30 mmapflags
|= MAP_LOWER16M
;
31 if(flags
& AC_LOWER1M
)
32 mmapflags
|= MAP_LOWER1M
;
33 if(flags
& AC_ALIGN64K
)
34 mmapflags
|= MAP_ALIGN64K
;
36 /* First try to get memory with mmap. This is gauranteed
37 * to be page-aligned, and we can tell VM it has to be
38 * pre-allocated and contiguous.
41 buf
= (vir_bytes
) mmap(0, len
, PROT_READ
|PROT_WRITE
, mmapflags
, -1, 0);
43 /* If that failed, maybe we're not running in paged mode.
44 * If that's the case, ENXIO will be returned.
45 * Memory returned with malloc() will be preallocated and
46 * contiguous, so fallback on that, and ask for a little extra
47 * so we can page align it ourselves.
49 if(buf
== (vir_bytes
) MAP_FAILED
) {
51 if(errno
!= (_SIGN ENXIO
)) {
54 if(flags
& AC_ALIGN4K
)
56 if(flags
& AC_ALIGN64K
)
61 if(!(buf
= (vir_bytes
) malloc(len
))) {
65 buf
+= align
- (buf
% align
);
68 /* Get physical address, if requested. */
69 if(phys
!= NULL
&& sys_umap_data_fb(SELF
, buf
, len
, phys
) != OK
)
70 panic("sys_umap_data_fb failed");
75 int free_contig(void *addr
, size_t len
)
77 return munmap(addr
, len
);