blob: 849a9e6ab1c3f05cf5c13260d3f561d63ae4f93b [file] [log] [blame]
Channagoud Kadabi472c2242015-06-16 10:07:55 -07001/* 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 Kadabi2922c452015-07-21 21:13:27 -070034#include <smem.h>
Channagoud Kadabi472c2242015-06-16 10:07:55 -070035
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 Kadabi2922c452015-07-21 21:13:27 -070041static mmu_section_t ramdump_mmu_section_table_4gb[] =
Channagoud Kadabi472c2242015-06-16 10:07:55 -070042{
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 Kadabi2922c452015-07-21 21:13:27 -070046 /* This entry is 484 MB because the hyp uses last 28MB for page tables */
Channagoud Kadabi472c2242015-06-16 10:07:55 -070047 { 0x140000000, 0xC0000000, MMU_L2_NS_SECTION_MAPPING, 484, COMMON_MEMORY},
48};
49
Channagoud Kadabi2922c452015-07-21 21:13:27 -070050static 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};
56uint32_t vaddr_4gb[] = {0xc2300000, 0xcd000000, 0xde000000};
57uint64_t paddr_4gb[] = {0xc2300000, 0x10d000000, 0x15e000000};
58
59uint32_t vaddr_3gb[] = {0x23000000, 0xcd000000, 0xde000000};
60uint64_t paddr_3gb[] = {0x23000000, 0xcd000000, 0xde000000};
Channagoud Kadabi472c2242015-06-16 10:07:55 -070061
62void ramdump_table_map()
63{
64 uint32_t i, j;
Channagoud Kadabi2922c452015-07-21 21:13:27 -070065 uint32_t table_sz = 0;
Channagoud Kadabi472c2242015-06-16 10:07:55 -070066 char *ptr = NULL;
67 bool pass_access = true;
68 bool pass_conversion = true;
69 uint64_t paddr_v;
70 uint32_t vaddr_v;
Channagoud Kadabi2922c452015-07-21 21:13:27 -070071 uint32_t *vaddr = NULL;
72 uint64_t *paddr = NULL;
73 mmu_section_t *ramdump_mmu_section_table = NULL;
Channagoud Kadabi472c2242015-06-16 10:07:55 -070074
Channagoud Kadabi2922c452015-07-21 21:13:27 -070075
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 Kadabi472c2242015-06-16 10:07:55 -070090 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 Kadabi2922c452015-07-21 21:13:27 -0700101 for (j = 0 ; j < (ramdump_mmu_section_table[i].size * MB)/6; j++)
Channagoud Kadabi472c2242015-06-16 10:07:55 -0700102 {
Channagoud Kadabi16e4d2e2015-07-21 21:14:20 -0700103 strlcpy(ptr, "hello", 6);
Channagoud Kadabi2922c452015-07-21 21:13:27 -0700104 ptr+=6;
Channagoud Kadabi472c2242015-06-16 10:07:55 -0700105 }
106
107 ptr = (char *)(uintptr_t)ramdump_mmu_section_table[i].vaddress;
108
Channagoud Kadabi2922c452015-07-21 21:13:27 -0700109 for (j = 0 ; j < (ramdump_mmu_section_table[i].size * MB)/6; j++)
Channagoud Kadabi472c2242015-06-16 10:07:55 -0700110 {
111 if (memcmp((void *)ptr, "hello", 5))
112 {
113 pass_access = false;
114 break;
115 }
Channagoud Kadabi2922c452015-07-21 21:13:27 -0700116 ptr+=6;
Channagoud Kadabi472c2242015-06-16 10:07:55 -0700117 }
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}