0126ff6381a5d7c8bf1b4836efebe758217e1c8c
[grub.git] / grub-core / kern / arm / coreboot / init.c
1 /*
2  *  GRUB  --  GRand Unified Bootloader
3  *  Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2013  Free Software Foundation, Inc.
4  *
5  *  GRUB is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  GRUB 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.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <grub/kernel.h>
20 #include <grub/mm.h>
21 #include <grub/memory.h>
22 #include <grub/machine/console.h>
23 #include <grub/machine/kernel.h>
24 #include <grub/offsets.h>
25 #include <grub/types.h>
26 #include <grub/err.h>
27 #include <grub/dl.h>
28 #include <grub/misc.h>
29 #include <grub/loader.h>
30 #include <grub/env.h>
31 #include <grub/cache.h>
32 #include <grub/time.h>
33 #include <grub/symbol.h>
34 #include <grub/video.h>
35 #include <grub/coreboot/lbio.h>
36 #include <grub/fdtbus.h>
37
38 extern grub_uint8_t _start[];
39 extern grub_uint8_t _end[];
40 extern grub_uint8_t _edata[];
41 grub_addr_t start_of_ram = ~(grub_addr_t)0;
42
43 void  __attribute__ ((noreturn))
44 grub_exit (void)
45 {
46   /* We can't use grub_fatal() in this function.  This would create an infinite
47      loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit().  */
48   while (1)
49     grub_cpu_idle ();
50 }
51
52 static grub_uint64_t modend;
53 static int have_memory = 0;
54
55 /* Helper for grub_machine_init.  */
56 static int
57 heap_init (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
58            void *data __attribute__ ((unused)))
59 {
60   grub_uint64_t begin = addr, end = addr + size;
61
62 #if GRUB_CPU_SIZEOF_VOID_P == 4
63   /* Restrict ourselves to 32-bit memory space.  */
64   if (begin > GRUB_ULONG_MAX)
65     return 0;
66   if (end > GRUB_ULONG_MAX)
67     end = GRUB_ULONG_MAX;
68 #endif
69
70   if (start_of_ram > begin)
71     start_of_ram = begin;
72
73   if (type != GRUB_MEMORY_AVAILABLE)
74     return 0;
75
76   if (modend && begin < modend)
77     {
78       if (begin < (grub_addr_t)_start)
79         {
80           grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) ((grub_addr_t)_start - begin));
81           have_memory = 1;
82         }
83       begin = modend;
84     }
85
86   /* Avoid DMA problems.  */
87   if (end >= 0xfe000000)
88     end = 0xfe000000;
89
90   if (end <= begin)
91     return 0;
92
93   grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) (end - begin));
94
95   have_memory = 1;
96
97   return 0;
98 }
99
100 void
101 grub_machine_init (void)
102 {
103   struct grub_module_header *header;
104   void *dtb = 0;
105   grub_size_t dtb_size = 0;
106
107   modend = grub_modules_get_end ();
108
109   grub_video_coreboot_fb_early_init ();
110
111   grub_machine_mmap_iterate (heap_init, NULL);
112   if (!have_memory)
113     grub_fatal ("No memory found");
114
115   grub_video_coreboot_fb_late_init ();
116
117   grub_font_init ();
118   grub_gfxterm_init ();
119
120   FOR_MODULES (header)
121     if (header->type == OBJ_TYPE_DTB)
122       {
123         char *dtb_orig_addr, *dtb_copy;
124         dtb_orig_addr = (char *) header + sizeof (struct grub_module_header);
125
126         dtb_size = header->size - sizeof (struct grub_module_header);
127         dtb = dtb_copy = grub_malloc (dtb_size);
128         grub_memmove (dtb_copy, dtb_orig_addr, dtb_size);
129         break;
130       }
131   if (!dtb)
132     grub_fatal ("No DTB found");
133   grub_fdtbus_init (dtb, dtb_size);
134
135   grub_rk3288_spi_init ();
136
137   grub_machine_timer_init ();
138   grub_pl050_init ();
139 }
140
141 void
142 grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
143                                char **path __attribute__ ((unused)))
144 {
145 }
146
147 void
148 grub_machine_fini (int flags __attribute__ ((unused)))
149 {
150 }