blob: ca5a946cdaf093aeb373f5b46ea61e988ff5e664 [file] [log] [blame]
Corey Tabaka84697242009-03-26 02:32:01 -04001/*
2 * Copyright (c) 2009 Corey Tabaka
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <err.h>
24#include <debug.h>
25#include <arch/x86/mmu.h>
26#include <platform.h>
27#include "platform_p.h"
Corey Tabakab3f6cac2009-04-01 17:35:12 -040028#include <platform/pc.h>
Corey Tabaka84697242009-03-26 02:32:01 -040029#include <platform/multiboot.h>
30#include <platform/console.h>
31#include <platform/keyboard.h>
Corey Tabakab0bd1832009-04-03 01:17:52 -040032#include <dev/pci.h>
Corey Tabaka84697242009-03-26 02:32:01 -040033
34extern multiboot_info_t *_multiboot_info;
35extern unsigned int _heap_end;
36
37void platform_init_mmu_mappings(void)
38{
39 /* do some memory map initialization */
40}
41
42
43void platform_init_multiboot_info(void)
44{
45 unsigned int i;
46
47 if (_multiboot_info) {
48 if (_multiboot_info->flags & MB_INFO_MEM_SIZE) {
49 _heap_end = _multiboot_info->mem_upper * 1024;
50 }
51
52 if (_multiboot_info->flags & MB_INFO_MMAP) {
53 memory_map_t *mmap = (memory_map_t *) (_multiboot_info->mmap_addr - 4);
54
55 dprintf(DEBUG, "mmap length: %u\n", _multiboot_info->mmap_length);
56
57 for (i=0; i < _multiboot_info->mmap_length / sizeof(memory_map_t); i++) {
58 dprintf(DEBUG, "base=%08x, length=%08x, type=%02x\n",
59 mmap[i].base_addr_low, mmap[i].length_low, mmap[i].type);
60
61 if (mmap[i].type == MB_MMAP_TYPE_AVAILABLE && mmap[i].base_addr_low >= _heap_end) {
62 _heap_end = mmap[i].base_addr_low + mmap[i].length_low;
63 } else if (mmap[i].type != MB_MMAP_TYPE_AVAILABLE && mmap[i].base_addr_low >= _heap_end) {
64 /*
65 * break on first memory hole above default heap end for now.
66 * later we can add facilities for adding free chunks to the
67 * heap for each segregated memory region.
68 */
69 break;
70 }
71 }
72 }
73 }
74}
75
76void platform_early_init(void)
77{
78 /* update the heap end so we can take advantage of more ram */
79 platform_init_multiboot_info();
80
81 /* get the text console working */
82 platform_init_console();
83
84 /* initialize the interrupt controller */
85 platform_init_interrupts();
86
87 /* initialize the timer */
88 platform_init_timer();
89}
90
91void platform_init(void)
92{
93 platform_init_keyboard();
94
Corey Tabakab0bd1832009-04-03 01:17:52 -040095 pci_init();
Corey Tabaka84697242009-03-26 02:32:01 -040096}
97