]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/bootstrap/server/src/support.h
update
[l4.git] / l4 / pkg / bootstrap / server / src / support.h
1 /*!
2  * \file   support.h
3  * \brief  Support header file
4  *
5  * \date   2008-01-02
6  * \author Adam Lackorznynski <adam@os.inf.tu-dresden.de>
7  *
8  */
9 /*
10  * (c) 2008-2009 Author(s)
11  *     economic rights: Technische Universität Dresden (Germany)
12  *
13  * This file is part of TUD:OS and distributed under the terms of the
14  * GNU General Public License 2.
15  * Please see the COPYING-GPL-2 file for details.
16  */
17 #ifndef __BOOTSTRAP__SUPPORT_H__
18 #define __BOOTSTRAP__SUPPORT_H__
19
20 #include <l4/drivers/uart_base.h>
21 #include <l4/util/mb_info.h>
22 #include <stdio.h>
23 #include "region.h"
24
25 L4::Uart *uart();
26 void set_stdio_uart(L4::Uart *uart);
27
28 void platform_init();
29 unsigned long scan_ram_size(unsigned long base_addr, unsigned long max_scan_size_mb);
30
31
32 class Platform_base
33 {
34 public:
35   virtual void init() = 0;
36   virtual void setup_memory_map(l4util_mb_info_t *mbi,
37                                 Region_list *ram, Region_list *regions) = 0;
38   virtual bool probe() = 0;
39
40   virtual void reboot()
41   {
42     while (1)
43       ;
44   }
45
46   // remember the chosen platform
47   static Platform_base *platform;
48
49   // find a platform
50   static void iterate_platforms()
51   {
52     extern Platform_base *__PLATFORMS_BEGIN[];
53     extern Platform_base *__PLATFORMS_END[];
54     for (Platform_base **p = __PLATFORMS_BEGIN; p < __PLATFORMS_END; ++p)
55       if (*p && (*p)->probe())
56         {
57           platform = *p;
58           platform->init();
59           break;
60         }
61   }
62 };
63
64 #define REGISTER_PLATFORM(type) \
65       static type type##_inst; \
66       static type * const __attribute__((section(".platformdata"),used)) type##_inst_p = &type##_inst
67
68 #ifdef RAM_SIZE_MB
69 class Platform_single_region_ram : public Platform_base
70 {
71 public:
72   void setup_memory_map(l4util_mb_info_t *,
73                         Region_list *ram, Region_list *)
74   {
75     unsigned long ram_size_mb = scan_ram_size(RAM_BASE, RAM_SIZE_MB);
76     printf("  Memory size is %ldMB%s (%08lx - %08lx)\n",
77            ram_size_mb, ram_size_mb != RAM_SIZE_MB ? " (Limited by Scan)" : "",
78            (unsigned long)RAM_BASE, RAM_BASE + (ram_size_mb << 20) - 1);
79     ram->add(Region::n(RAM_BASE,
80                        (unsigned long long)RAM_BASE + (ram_size_mb << 20),
81                        ".ram", Region::Ram));
82   }
83 };
84 #endif
85
86 #endif /* __BOOTSTRAP__SUPPORT_H__ */