Minor cleanups
[lightOS.git] / trunk / kernel / include / kernel / page_allocator.hpp
blobe4acd71d92357fb0dc83589daa5731a3fb46b5ef
1 /*
2 lightOS kernel
3 Copyright (C) 2006-2009 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef LIGHTOS_KERNEL_PAGEALLOCATOR_HPP
20 #define LIGHTOS_KERNEL_PAGEALLOCATOR_HPP
22 /*! \addtogroup kernel kernel */
23 /*@{*/
25 #include <cstddef>
26 #include <cstdint>
27 #include <kernel/utils/macros.hpp>
28 #include <kernel/spinlock.hpp>
30 namespace kernel
32 /*! page_allocator class for the management of pages above the 16mb barrier
33 *\note Not neccessarily every page above the 16mb barrier is manged by this allocator. The amount is calculated
34 * based on the total amount of RAM (see x86-shared/multiboot.cpp) */
35 class page_allocator
37 SINGLETON(page_allocator);
39 public:
40 /*! Allocate a new page
41 *\return physical address of the page */
42 void *allocate();
43 /*! Free a previously allocated page
44 *\param[in] physical address of the page */
45 void free(void *page);
47 /*! Get the page size
48 *\return the page size in byte */
49 inline static size_t page_size(){return mPageSize;}
50 /*! Number of free pages
51 *\return the number of free pages */
52 inline size_t size(){return mSize;}
53 /*! Total number of pages (userfriendly version)
54 *\return the total number of pages (userfriendly version) */
55 inline size_t capacity(){return mPageCount;}
56 /*! Set the total number of pages (userfriendly version)
57 *\param[in] the number of pages (userfriendly version) */
58 inline void capacity(size_t i){mPageCount = i;}
60 private:
61 /*! Size of one page */
62 static size_t mPageSize;
63 /*! The number of pages */
64 size_t mCapacity;
65 /*! The number of free pages */
66 size_t mSize;
67 /*! The number of total pages (userfriendly version) */
68 size_t mPageCount;
69 /*! Pointer to the stack */
70 uintptr_t *mStack;
71 #ifdef _LIGHTOS_SMP
72 /*! Spinlock to protect the page_allocator in a multiprocessor environment */
73 lightOS::spinlock mLock;
74 #endif
78 /*@}*/
80 #endif