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
)
28 int mmapflags
= MAP_PREALLOC
|MAP_CONTIG
|MAP_ANON
;
30 if(flags
& AC_LOWER16M
)
31 mmapflags
|= MAP_LOWER16M
;
32 if(flags
& AC_LOWER1M
)
33 mmapflags
|= MAP_LOWER1M
;
34 if(flags
& AC_ALIGN64K
)
35 mmapflags
|= MAP_ALIGN64K
;
37 /* First try to get memory with mmap. This is gauranteed
38 * to be page-aligned, and we can tell VM it has to be
39 * pre-allocated and contiguous.
42 buf
= (vir_bytes
) mmap(0, len
, PROT_READ
|PROT_WRITE
, mmapflags
, -1, 0);
44 /* If that failed, maybe we're not running in paged mode.
45 * If that's the case, ENXIO will be returned.
46 * Memory returned with malloc() will be preallocated and
47 * contiguous, so fallback on that, and ask for a little extra
48 * so we can page align it ourselves.
50 if(buf
== (vir_bytes
) MAP_FAILED
) {
52 if(errno
!= (_SIGN ENXIO
)) {
55 if(flags
& AC_ALIGN4K
)
57 if(flags
& AC_ALIGN64K
)
62 if(!(buf
= (vir_bytes
) malloc(len
))) {
66 buf
+= align
- (buf
% align
);
69 /* Get physical address, if requested. */
70 if(phys
!= NULL
&& sys_umap_data_fb(SELF
, buf
, len
, phys
) != OK
)
71 panic("alloc_contig.c", "sys_umap_data_fb failed", NO_NUM
);
76 int free_contig(void *addr
, size_t len
)
78 return munmap(addr
, len
);