White space fixes, detab.
[AROS.git] / rom / kernel / allocpages.c
blob14c10e4d1697bc2c074bbe6a4aba40cf3cb35ce3
1 #include <aros/config.h>
3 #include <kernel_base.h>
4 #include <kernel_mm.h>
6 /*****************************************************************************
8 NAME */
9 #include <proto/kernel.h>
11 AROS_LH3(void *, KrnAllocPages,
13 /* SYNOPSIS */
14 AROS_LHA(void *, addr, A0),
15 AROS_LHA(uintptr_t, length, D0),
16 AROS_LHA(uint32_t, flags, D1),
18 /* LOCATION */
19 struct KernelBase *, KernelBase, 27, Kernel)
21 /* FUNCTION
22 Allocate physical memory pages
24 INPUTS
25 addr - Starting address of region which must be included in the
26 allocated region or NULL for the system to choose the
27 starting address. Normally you will supply NULL here.
28 length - Length of the memory region to allocate
29 flags - Flags describing type of needed memory. These are the same
30 flags as passed to exec.library/AllocMem().
32 RESULT
33 Real starting address of the allocated region.
35 NOTES
36 Since this allocator is page-based, length will always be round up
37 to system's memory page size. The same applies to starting address
38 (if specified), it will be rounded down to page boundary.
40 This function works only on systems with MMU support. Without MMU
41 it will always return NULL.
43 EXAMPLE
45 BUGS
47 SEE ALSO
48 KrnFreePages()
50 INTERNALS
52 ******************************************************************************/
54 AROS_LIBFUNC_INIT
56 APTR res = NULL;
57 #if USE_MMU
58 KRN_MapAttr protection;
60 /* We can't work if MMU is not up */
61 if (!KernelBase->kb_PageSize)
62 return NULL;
64 /* Get permissions */
65 protection = MAP_Readable|MAP_Writable;
66 if (flags & MEMF_EXECUTABLE)
67 protection |= MAP_Executable;
69 res = mm_AllocPages(addr, length, flags, KernelBase);
72 * The pages we've just allocated have no access rights at all.
73 * Now we need to set requested access rights.
75 if (res)
76 KrnSetProtection(res, length, protection);
77 #endif
79 return res;
81 AROS_LIBFUNC_EXIT