[b6b02c0] | 1 | /*
|
---|
| 2 | * Copyright (c) 2013 Jakub Klama
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - 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 | * - 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 ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup sparc32boot
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * @brief Bootstrap.
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <arch/asm.h>
|
---|
| 37 | #include <arch/common.h>
|
---|
| 38 | #include <arch/arch.h>
|
---|
| 39 | #include <arch/mm.h>
|
---|
| 40 | #include <arch/main.h>
|
---|
| 41 | #include <arch/_components.h>
|
---|
| 42 | #include <halt.h>
|
---|
| 43 | #include <printf.h>
|
---|
| 44 | #include <memstr.h>
|
---|
| 45 | #include <version.h>
|
---|
| 46 | #include <macros.h>
|
---|
| 47 | #include <align.h>
|
---|
| 48 | #include <str.h>
|
---|
| 49 | #include <errno.h>
|
---|
| 50 | #include <inflate.h>
|
---|
| 51 |
|
---|
[f6f22cdb] | 52 | #define OFF2SEC(_addr) ((_addr) >> PTL0_SHIFT)
|
---|
| 53 | #define SEC2OFF(_sec) ((_sec) << PTL0_SHIFT)
|
---|
[b6b02c0] | 54 |
|
---|
| 55 | static section_mapping_t mappings[] = {
|
---|
| 56 | { 0x40000000, 0x3fffffff, 0x40000000, 1 },
|
---|
| 57 | { 0x40000000, 0x2fffffff, 0x80000000, 1 },
|
---|
| 58 | { 0x80000000, 0x0fffffff, 0xb0000000, 0 },
|
---|
| 59 | { 0, 0, 0, 0 },
|
---|
| 60 | };
|
---|
| 61 |
|
---|
[f6f22cdb] | 62 | static void mmu_enable(void)
|
---|
[b6b02c0] | 63 | {
|
---|
[f6f22cdb] | 64 | boot_ctx_table = ((uintptr_t) &boot_pt[0] >> 4) | PTE_ET_DESCRIPTOR;
|
---|
| 65 |
|
---|
[b6b02c0] | 66 | /* Set Context Table Pointer register */
|
---|
[f6f22cdb] | 67 | asi_u32_write(ASI_MMUREGS, 0x100, ((uint32_t) &boot_ctx_table) >> 4);
|
---|
| 68 |
|
---|
[b6b02c0] | 69 | /* Select context 0 */
|
---|
| 70 | asi_u32_write(ASI_MMUREGS, 0x200, 0);
|
---|
[f6f22cdb] | 71 |
|
---|
[b6b02c0] | 72 | /* Enable MMU */
|
---|
| 73 | uint32_t cr = asi_u32_read(ASI_MMUREGS, 0x000);
|
---|
| 74 | cr |= 1;
|
---|
| 75 | asi_u32_write(ASI_MMUREGS, 0x000, cr);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | static void mmu_disable()
|
---|
| 79 | {
|
---|
| 80 | uint32_t cr = asi_u32_read(ASI_MMUREGS, 0x000);
|
---|
| 81 | cr &= ~1;
|
---|
| 82 | asi_u32_write(ASI_MMUREGS, 0x000, cr);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[f6f22cdb] | 85 | void mmu_init(void)
|
---|
[b6b02c0] | 86 | {
|
---|
| 87 | mmu_disable();
|
---|
[f6f22cdb] | 88 |
|
---|
| 89 | for (unsigned int i = 0; mappings[i].size != 0; i++) {
|
---|
| 90 | unsigned int ptr = 0;
|
---|
| 91 | for (uint32_t sec = OFF2SEC(mappings[i].va);
|
---|
| 92 | sec < OFF2SEC(mappings[i].va + mappings[i].size);
|
---|
| 93 | sec++) {
|
---|
[b6b02c0] | 94 | boot_pt[sec].ppn = ((mappings[i].pa + SEC2OFF(ptr++)) >> 12) & 0xffffff;
|
---|
| 95 | boot_pt[sec].cacheable = mappings[i].cacheable;
|
---|
| 96 | boot_pt[sec].acc = PTE_ACC_RWX;
|
---|
| 97 | boot_pt[sec].et = PTE_ET_ENTRY;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
[f6f22cdb] | 100 |
|
---|
[b6b02c0] | 101 | mmu_enable();
|
---|
| 102 | }
|
---|