blob: e616956b10f9b86063629d1b727784cd28ebd40a [file] [log] [blame]
Furquan Shaikh8c8c3772014-02-19 11:35:30 -08001/*
2 * This file is part of the libpayload project.
3 *
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <exception.h>
31#include <libpayload.h>
Furquan Shaikh39292632014-09-04 15:33:00 -070032#include <arch/mmu.h>
Furquan Shaikh8c8c3772014-02-19 11:35:30 -080033
34unsigned int main_argc; /**< The argc value to pass to main() */
35
36/** The argv value to pass to main() */
37char *main_argv[MAX_ARGC_COUNT];
38
39unsigned int test_exc;
40
Furquan Shaikh3b1ee032014-08-27 21:43:36 -070041static int test_exception(void)
Furquan Shaikh8c8c3772014-02-19 11:35:30 -080042{
Furquan Shaikh3b1ee032014-08-27 21:43:36 -070043 uint64_t *a = (uint64_t *)0xfffffffff0000000ULL;
44
Furquan Shaikh8c8c3772014-02-19 11:35:30 -080045 test_exc = 1;
Furquan Shaikh3b1ee032014-08-27 21:43:36 -070046
47 printf("%llx\n", *a);
48
49 return 0;
Furquan Shaikh8c8c3772014-02-19 11:35:30 -080050}
51
Furquan Shaikh39292632014-09-04 15:33:00 -070052/*
53 * Func: pre_sysinfo_scan_mmu_setup
54 * Desc: We need to setup and enable MMU before we can go to scan coreboot
55 * tables. However, we are not sure what all memory regions to map. Thus,
56 * initializing minimum required memory ranges
57 */
58static void pre_sysinfo_scan_mmu_setup(void)
59{
60 uint64_t start = (uint64_t)&_start;
61 uint64_t end = (uint64_t)&_end;
62
63 /* Memory range 1: Covers the area occupied by payload */
64 mmu_presysinfo_memory_used(start, end - start);
65
66 /*
67 * Memory range 2: Coreboot tables
68 *
69 * Maximum size is assumed 2 pages in case it crosses the GRANULE_SIZE
70 * boundary
71 */
72 mmu_presysinfo_memory_used((uint64_t)get_cb_header_ptr(),
73 2 * GRANULE_SIZE);
74
75 mmu_presysinfo_enable();
76}
77
78/*
79 * Func: post_sysinfo_scan_mmu_setup
80 * Desc: Once we have scanned coreboot tables, we have complete information
81 * about different memory ranges. Thus, we can perform a complete mmu
82 * initialization. Also, this takes care of DMA area setup
83 */
84static void post_sysinfo_scan_mmu_setup(void)
85{
86 struct memrange *ranges;
87 uint64_t nranges;
88 struct mmu_ranges mmu_ranges;
89 struct mmu_memrange *dma_range;
90
91 /* Get memrange info from lib_sysinfo */
92 lib_sysinfo_get_memranges(&ranges, &nranges);
93
94 /* Get memory ranges for mmu init from lib_sysinfo memrange */
95 dma_range = mmu_init_ranges_from_sysinfo(ranges, nranges, &mmu_ranges);
96
97 /* Disable mmu */
98 mmu_disable();
99
100 /* Init mmu */
101 mmu_init(&mmu_ranges);
102
103 /* Enable mmu */
104 mmu_enable();
105
106 /* Init dma memory */
107 init_dma_memory((void *)dma_range->base, dma_range->size);
108}
109
Furquan Shaikh8c8c3772014-02-19 11:35:30 -0800110/**
111 * This is our C entry function - set up the system
112 * and jump into the payload entry point.
113 */
114void start_main(void);
115void start_main(void)
116{
117 extern int main(int argc, char **argv);
118
Furquan Shaikh39292632014-09-04 15:33:00 -0700119 pre_sysinfo_scan_mmu_setup();
120
Furquan Shaikh8c8c3772014-02-19 11:35:30 -0800121 /* Gather system information. */
122 lib_get_sysinfo();
123
Furquan Shaikh8a01eb62014-10-09 15:59:12 -0700124 post_sysinfo_scan_mmu_setup();
125
Stefan Reinauer1b4d3942015-06-29 15:47:34 -0700126#if !IS_ENABLED(CONFIG_LP_SKIP_CONSOLE_INIT)
Furquan Shaikh68cb88e2014-08-25 15:11:57 -0700127 console_init();
128#endif
Furquan Shaikh39292632014-09-04 15:33:00 -0700129
Furquan Shaikh68cb88e2014-08-25 15:11:57 -0700130 printf("ARM64: Libpayload %s\n",__func__);
Furquan Shaikh8c8c3772014-02-19 11:35:30 -0800131 exception_init();
132
133 test_exception();
134 /*
135 * Any other system init that has to happen before the
136 * user gets control goes here.
137 */
138
139 /*
140 * Go to the entry point.
141 * In the future we may care about the return value.
142 */
143
144 (void) main(main_argc, (main_argc != 0) ? main_argv : NULL);
145
146 /*
147 * Returning here will go to the _leave function to return
148 * us to the original context.
149 */
150}