1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #ifndef SIGMA0_PAGE_ALLOC_H__
11 #define SIGMA0_PAGE_ALLOC_H__
12 
13 #include <l4/sys/consts.h>
14 
15 #include <l4/cxx/list_alloc>
16 #include <l4/cxx/slab_alloc>
17 
18 class Page_alloc_base
19 {
20 public:
21   typedef cxx::List_alloc Alloc;
22 
23 protected:
24   static Alloc _alloc;
25   static unsigned long _total;
26 
27 public:
28   static void init();
free(void * m)29   static void free(void *m)
30   {
31     allocator()->free(m, L4_PAGESIZE);
32     _total += L4_PAGESIZE;
33   }
34 
allocator()35   static Alloc *allocator() { return &_alloc; }
total()36   static unsigned long total() { return _total; }
37 };
38 
39 template< typename T >
40 class Page_alloc : public Page_alloc_base
41 {
42 public:
43   enum { can_free = 1 };
alloc()44   T *alloc()
45   { return (T *)_alloc.alloc(L4_PAGESIZE,L4_PAGESIZE); }
46 
free(T * b)47   void free(T *b)
48   { _alloc.free(b, L4_PAGESIZE); }
49 };
50 
51 template< typename Type >
52 class Slab_alloc
53 : public cxx::Slab_static<Type, L4_PAGESIZE, 2, Page_alloc>
54 {};
55 
56 #endif
57