blob: 27ed6280eb6c512dc179489d00845faebeb82ad8 [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>
Channagoud Kadabi736c4962015-08-21 11:56:52 -070032#include <arch/ops.h>
Channagoud Kadabi472c2242015-06-16 10:07:55 -070033#include <mmu.h>
34#include <string.h>
Channagoud Kadabi2922c452015-07-21 21:13:27 -070035#include <smem.h>
Channagoud Kadabi472c2242015-06-16 10:07:55 -070036
37/* COMMON memory - cacheable, write through */
38#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
39 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
40
41#define MB (1024 * 1024)
Channagoud Kadabi2922c452015-07-21 21:13:27 -070042static mmu_section_t ramdump_mmu_section_table_4gb[] =
Channagoud Kadabi472c2242015-06-16 10:07:55 -070043{
44 /* Physical addr, Virtual addr, Mapping type , Size (in MB), Flags */
45 { 0xC0000000, 0xC0000000, MMU_L2_NS_SECTION_MAPPING, 512, COMMON_MEMORY},
46 { 0x100000000, 0xC0000000, MMU_L2_NS_SECTION_MAPPING, 1024, COMMON_MEMORY},
Channagoud Kadabi2922c452015-07-21 21:13:27 -070047 /* This entry is 484 MB because the hyp uses last 28MB for page tables */
Channagoud Kadabi472c2242015-06-16 10:07:55 -070048 { 0x140000000, 0xC0000000, MMU_L2_NS_SECTION_MAPPING, 484, COMMON_MEMORY},
49};
50
Channagoud Kadabi2922c452015-07-21 21:13:27 -070051static mmu_section_t ramdump_mmu_section_table_3gb[] =
52{
53 /* Physical addr, Virtual addr, Mapping type , Size (in MB), Flags */
54 { 0x20000000, 0x20000000, MMU_L2_NS_SECTION_MAPPING, 512, COMMON_MEMORY},
55 { 0xC0000000, 0xC0000000, MMU_L2_NS_SECTION_MAPPING, 484, COMMON_MEMORY},
56};
57uint32_t vaddr_4gb[] = {0xc2300000, 0xcd000000, 0xde000000};
58uint64_t paddr_4gb[] = {0xc2300000, 0x10d000000, 0x15e000000};
59
60uint32_t vaddr_3gb[] = {0x23000000, 0xcd000000, 0xde000000};
61uint64_t paddr_3gb[] = {0x23000000, 0xcd000000, 0xde000000};
Channagoud Kadabi472c2242015-06-16 10:07:55 -070062
63void ramdump_table_map()
64{
65 uint32_t i, j;
Channagoud Kadabi2922c452015-07-21 21:13:27 -070066 uint32_t table_sz = 0;
Channagoud Kadabi472c2242015-06-16 10:07:55 -070067 char *ptr = NULL;
68 bool pass_access = true;
69 bool pass_conversion = true;
70 uint64_t paddr_v;
71 uint32_t vaddr_v;
Channagoud Kadabi2922c452015-07-21 21:13:27 -070072 uint32_t *vaddr = NULL;
73 uint64_t *paddr = NULL;
74 mmu_section_t *ramdump_mmu_section_table = NULL;
Channagoud Kadabi472c2242015-06-16 10:07:55 -070075
Channagoud Kadabi2922c452015-07-21 21:13:27 -070076
77 if (smem_get_ddr_size() == MEM_4GB)
78 {
79 vaddr = vaddr_4gb;
80 paddr = paddr_4gb;
81 ramdump_mmu_section_table = ramdump_mmu_section_table_4gb;
82 table_sz = ARRAY_SIZE(ramdump_mmu_section_table_4gb);
83 }
84 else if (smem_get_ddr_size() == MEM_3GB)
85 {
86 vaddr = vaddr_3gb;
87 paddr = paddr_3gb;
88 ramdump_mmu_section_table = ramdump_mmu_section_table_3gb;
89 table_sz = ARRAY_SIZE(ramdump_mmu_section_table_3gb);
90 }
Channagoud Kadabi472c2242015-06-16 10:07:55 -070091 for (i = 0 ; i < table_sz; i++)
92 {
93 arm_mmu_map_entry(&ramdump_mmu_section_table[i]);
94 vaddr_v = physical_to_virtual_mapping(paddr[i]);
95 if (vaddr_v != vaddr[i])
96 pass_conversion = false;
97 paddr_v = virtual_to_physical_mapping(vaddr[i]);
98 if (paddr_v != paddr[i])
99 pass_conversion = false;
100 ptr = (char *)(uintptr_t)ramdump_mmu_section_table[i].vaddress;
101
Channagoud Kadabi2922c452015-07-21 21:13:27 -0700102 for (j = 0 ; j < (ramdump_mmu_section_table[i].size * MB)/6; j++)
Channagoud Kadabi472c2242015-06-16 10:07:55 -0700103 {
Channagoud Kadabi16e4d2e2015-07-21 21:14:20 -0700104 strlcpy(ptr, "hello", 6);
Channagoud Kadabi2922c452015-07-21 21:13:27 -0700105 ptr+=6;
Channagoud Kadabi472c2242015-06-16 10:07:55 -0700106 }
107
108 ptr = (char *)(uintptr_t)ramdump_mmu_section_table[i].vaddress;
109
Channagoud Kadabi2922c452015-07-21 21:13:27 -0700110 for (j = 0 ; j < (ramdump_mmu_section_table[i].size * MB)/6; j++)
Channagoud Kadabi472c2242015-06-16 10:07:55 -0700111 {
112 if (memcmp((void *)ptr, "hello", 5))
113 {
114 pass_access = false;
115 break;
116 }
Channagoud Kadabi2922c452015-07-21 21:13:27 -0700117 ptr+=6;
Channagoud Kadabi472c2242015-06-16 10:07:55 -0700118 }
119 if (pass_access)
120 dprintf(CRITICAL, "LAPE TEST PASS for addr: 0x%llx\n", ramdump_mmu_section_table[i].paddress);
121 }
122 if (pass_conversion)
123 dprintf(CRITICAL, "Physical to virtual conversion TEST PASS\n");
124}