Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 1 | /* |
| 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 Shaikh | 3929263 | 2014-09-04 15:33:00 -0700 | [diff] [blame] | 32 | #include <arch/mmu.h> |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 33 | |
| 34 | unsigned int main_argc; /**< The argc value to pass to main() */ |
| 35 | |
| 36 | /** The argv value to pass to main() */ |
| 37 | char *main_argv[MAX_ARGC_COUNT]; |
| 38 | |
| 39 | unsigned int test_exc; |
| 40 | |
Furquan Shaikh | 3b1ee03 | 2014-08-27 21:43:36 -0700 | [diff] [blame] | 41 | static int test_exception(void) |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 42 | { |
Furquan Shaikh | 3b1ee03 | 2014-08-27 21:43:36 -0700 | [diff] [blame] | 43 | uint64_t *a = (uint64_t *)0xfffffffff0000000ULL; |
| 44 | |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 45 | test_exc = 1; |
Furquan Shaikh | 3b1ee03 | 2014-08-27 21:43:36 -0700 | [diff] [blame] | 46 | |
| 47 | printf("%llx\n", *a); |
| 48 | |
| 49 | return 0; |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 50 | } |
| 51 | |
Furquan Shaikh | 3929263 | 2014-09-04 15:33:00 -0700 | [diff] [blame] | 52 | /* |
| 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 | */ |
| 58 | static 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 | */ |
| 84 | static 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 Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 110 | /** |
| 111 | * This is our C entry function - set up the system |
| 112 | * and jump into the payload entry point. |
| 113 | */ |
| 114 | void start_main(void); |
| 115 | void start_main(void) |
| 116 | { |
| 117 | extern int main(int argc, char **argv); |
| 118 | |
Furquan Shaikh | 3929263 | 2014-09-04 15:33:00 -0700 | [diff] [blame] | 119 | pre_sysinfo_scan_mmu_setup(); |
| 120 | |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 121 | /* Gather system information. */ |
| 122 | lib_get_sysinfo(); |
| 123 | |
Furquan Shaikh | 8a01eb6 | 2014-10-09 15:59:12 -0700 | [diff] [blame] | 124 | post_sysinfo_scan_mmu_setup(); |
| 125 | |
Stefan Reinauer | 1b4d394 | 2015-06-29 15:47:34 -0700 | [diff] [blame^] | 126 | #if !IS_ENABLED(CONFIG_LP_SKIP_CONSOLE_INIT) |
Furquan Shaikh | 68cb88e | 2014-08-25 15:11:57 -0700 | [diff] [blame] | 127 | console_init(); |
| 128 | #endif |
Furquan Shaikh | 3929263 | 2014-09-04 15:33:00 -0700 | [diff] [blame] | 129 | |
Furquan Shaikh | 68cb88e | 2014-08-25 15:11:57 -0700 | [diff] [blame] | 130 | printf("ARM64: Libpayload %s\n",__func__); |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 131 | 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 | } |