Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <sys/types.h> |
| 30 | #include <debug.h> |
| 31 | #include <arch/arm/mmu.h> |
| 32 | #include <mmu.h> |
| 33 | #include <string.h> |
Channagoud Kadabi | 2922c45 | 2015-07-21 21:13:27 -0700 | [diff] [blame] | 34 | #include <smem.h> |
Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 35 | |
| 36 | /* COMMON memory - cacheable, write through */ |
| 37 | #define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 38 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 39 | |
| 40 | #define MB (1024 * 1024) |
Channagoud Kadabi | 2922c45 | 2015-07-21 21:13:27 -0700 | [diff] [blame] | 41 | static mmu_section_t ramdump_mmu_section_table_4gb[] = |
Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 42 | { |
| 43 | /* Physical addr, Virtual addr, Mapping type , Size (in MB), Flags */ |
| 44 | { 0xC0000000, 0xC0000000, MMU_L2_NS_SECTION_MAPPING, 512, COMMON_MEMORY}, |
| 45 | { 0x100000000, 0xC0000000, MMU_L2_NS_SECTION_MAPPING, 1024, COMMON_MEMORY}, |
Channagoud Kadabi | 2922c45 | 2015-07-21 21:13:27 -0700 | [diff] [blame] | 46 | /* This entry is 484 MB because the hyp uses last 28MB for page tables */ |
Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 47 | { 0x140000000, 0xC0000000, MMU_L2_NS_SECTION_MAPPING, 484, COMMON_MEMORY}, |
| 48 | }; |
| 49 | |
Channagoud Kadabi | 2922c45 | 2015-07-21 21:13:27 -0700 | [diff] [blame] | 50 | static mmu_section_t ramdump_mmu_section_table_3gb[] = |
| 51 | { |
| 52 | /* Physical addr, Virtual addr, Mapping type , Size (in MB), Flags */ |
| 53 | { 0x20000000, 0x20000000, MMU_L2_NS_SECTION_MAPPING, 512, COMMON_MEMORY}, |
| 54 | { 0xC0000000, 0xC0000000, MMU_L2_NS_SECTION_MAPPING, 484, COMMON_MEMORY}, |
| 55 | }; |
| 56 | uint32_t vaddr_4gb[] = {0xc2300000, 0xcd000000, 0xde000000}; |
| 57 | uint64_t paddr_4gb[] = {0xc2300000, 0x10d000000, 0x15e000000}; |
| 58 | |
| 59 | uint32_t vaddr_3gb[] = {0x23000000, 0xcd000000, 0xde000000}; |
| 60 | uint64_t paddr_3gb[] = {0x23000000, 0xcd000000, 0xde000000}; |
Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 61 | |
| 62 | void ramdump_table_map() |
| 63 | { |
| 64 | uint32_t i, j; |
Channagoud Kadabi | 2922c45 | 2015-07-21 21:13:27 -0700 | [diff] [blame] | 65 | uint32_t table_sz = 0; |
Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 66 | char *ptr = NULL; |
| 67 | bool pass_access = true; |
| 68 | bool pass_conversion = true; |
| 69 | uint64_t paddr_v; |
| 70 | uint32_t vaddr_v; |
Channagoud Kadabi | 2922c45 | 2015-07-21 21:13:27 -0700 | [diff] [blame] | 71 | uint32_t *vaddr = NULL; |
| 72 | uint64_t *paddr = NULL; |
| 73 | mmu_section_t *ramdump_mmu_section_table = NULL; |
Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 74 | |
Channagoud Kadabi | 2922c45 | 2015-07-21 21:13:27 -0700 | [diff] [blame] | 75 | |
| 76 | if (smem_get_ddr_size() == MEM_4GB) |
| 77 | { |
| 78 | vaddr = vaddr_4gb; |
| 79 | paddr = paddr_4gb; |
| 80 | ramdump_mmu_section_table = ramdump_mmu_section_table_4gb; |
| 81 | table_sz = ARRAY_SIZE(ramdump_mmu_section_table_4gb); |
| 82 | } |
| 83 | else if (smem_get_ddr_size() == MEM_3GB) |
| 84 | { |
| 85 | vaddr = vaddr_3gb; |
| 86 | paddr = paddr_3gb; |
| 87 | ramdump_mmu_section_table = ramdump_mmu_section_table_3gb; |
| 88 | table_sz = ARRAY_SIZE(ramdump_mmu_section_table_3gb); |
| 89 | } |
Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 90 | for (i = 0 ; i < table_sz; i++) |
| 91 | { |
| 92 | arm_mmu_map_entry(&ramdump_mmu_section_table[i]); |
| 93 | vaddr_v = physical_to_virtual_mapping(paddr[i]); |
| 94 | if (vaddr_v != vaddr[i]) |
| 95 | pass_conversion = false; |
| 96 | paddr_v = virtual_to_physical_mapping(vaddr[i]); |
| 97 | if (paddr_v != paddr[i]) |
| 98 | pass_conversion = false; |
| 99 | ptr = (char *)(uintptr_t)ramdump_mmu_section_table[i].vaddress; |
| 100 | |
Channagoud Kadabi | 2922c45 | 2015-07-21 21:13:27 -0700 | [diff] [blame] | 101 | for (j = 0 ; j < (ramdump_mmu_section_table[i].size * MB)/6; j++) |
Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 102 | { |
Channagoud Kadabi | 16e4d2e | 2015-07-21 21:14:20 -0700 | [diff] [blame] | 103 | strlcpy(ptr, "hello", 6); |
Channagoud Kadabi | 2922c45 | 2015-07-21 21:13:27 -0700 | [diff] [blame] | 104 | ptr+=6; |
Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | ptr = (char *)(uintptr_t)ramdump_mmu_section_table[i].vaddress; |
| 108 | |
Channagoud Kadabi | 2922c45 | 2015-07-21 21:13:27 -0700 | [diff] [blame] | 109 | for (j = 0 ; j < (ramdump_mmu_section_table[i].size * MB)/6; j++) |
Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 110 | { |
| 111 | if (memcmp((void *)ptr, "hello", 5)) |
| 112 | { |
| 113 | pass_access = false; |
| 114 | break; |
| 115 | } |
Channagoud Kadabi | 2922c45 | 2015-07-21 21:13:27 -0700 | [diff] [blame] | 116 | ptr+=6; |
Channagoud Kadabi | 472c224 | 2015-06-16 10:07:55 -0700 | [diff] [blame] | 117 | } |
| 118 | if (pass_access) |
| 119 | dprintf(CRITICAL, "LAPE TEST PASS for addr: 0x%llx\n", ramdump_mmu_section_table[i].paddress); |
| 120 | } |
| 121 | if (pass_conversion) |
| 122 | dprintf(CRITICAL, "Physical to virtual conversion TEST PASS\n"); |
| 123 | } |