blob: 12bcd23901dade599c0587cfc6df955b4e98fcc2 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
Channagoud Kadabi70f9c4e2015-06-17 17:29:10 -07004 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
5 *
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07006 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction,
9 * including without limitation the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25#ifndef __ARCH_ARM_MMU_H
26#define __ARCH_ARM_MMU_H
27
28#include <sys/types.h>
29
30#if defined(__cplusplus)
31extern "C" {
32#endif
33
34void arm_mmu_init(void);
35
Amol Jadi9ef9b732011-05-23 16:00:17 -070036#if defined(ARM_ISA_ARMV6) | defined(ARM_ISA_ARMV7)
37
Channagoud Kadabi70f9c4e2015-06-17 17:29:10 -070038#ifndef LPAE
Amol Jadi9ef9b732011-05-23 16:00:17 -070039/* C, B and TEX[2:0] encodings without TEX remap */
40 /* TEX | CB */
41#define MMU_MEMORY_TYPE_STRONGLY_ORDERED ((0x0 << 12) | (0x0 << 2))
42#define MMU_MEMORY_TYPE_DEVICE_SHARED ((0x0 << 12) | (0x1 << 2))
43#define MMU_MEMORY_TYPE_DEVICE_NON_SHARED ((0x2 << 12) | (0x0 << 2))
44#define MMU_MEMORY_TYPE_NORMAL ((0x1 << 12) | (0x0 << 2))
45#define MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH ((0x0 << 12) | (0x2 << 2))
46#define MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_NO_ALLOCATE ((0x0 << 12) | (0x3 << 2))
47#define MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE ((0x1 << 12) | (0x3 << 2))
48
49#define MMU_MEMORY_AP_NO_ACCESS (0x0 << 10)
50#define MMU_MEMORY_AP_READ_ONLY (0x7 << 10)
51#define MMU_MEMORY_AP_READ_WRITE (0x3 << 10)
52
Amol Jadi0228e9f2011-12-19 17:21:36 -080053#define MMU_MEMORY_XN (0x1 << 4)
Channagoud Kadabi70f9c4e2015-06-17 17:29:10 -070054#else /* LPAE */
55
56typedef enum
57{
58 /* Secure L1 section */
59 MMU_L1_SECTION_MAPPING = 0,
60
61 /* Non-secure L1 section */
62 MMU_L1_NS_SECTION_MAPPING,
63
64 /* Secure L2 section */
65 MMU_L2_SECTION_MAPPING,
66
67 /* Non-secure L2 section */
68 MMU_L2_NS_SECTION_MAPPING,
69
70 /* Secure L3 section */
71 MMU_L3_SECTION_MAPPING,
72
73 /* Non-secure L3 section */
74 MMU_L3_NS_SECTION_MAPPING,
75
76}mapping_type;
77
78
79#define ATTR_INDEX(x) (x << 2) /* [4:2] - AttrIndx[2:0] of block descriptor */
80
81/* define the memory attributes for the block descriptors */
82
83#define MMU_MEMORY_TYPE_STRONGLY_ORDERED ATTR_INDEX(0)
84#define MMU_MEMORY_TYPE_DEVICE_SHARED ATTR_INDEX(1) | (3 << 8) /*[9:8] - SH[1:0] - Shareability */
85#define MMU_MEMORY_TYPE_NORMAL ATTR_INDEX(2)
86#define MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH ATTR_INDEX(7)
87#define MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE ATTR_INDEX(4)
88#define MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_NO_ALLOCATE ATTR_INDEX(5)
89
90#define MMU_MEMORY_AP_READ_WRITE (1 << 6) /* Read/Write at any priveledge */
91#define MMU_MEMORY_XN (1ULL << 54)
92#define MMU_MEMORY_PXN (1ULL << 53)
93
94/* define the memory attributes:
95 * For LPAE, the block descriptor contains index into the MAIR registers.
96 * MAIR registers define the memory attributes. Below configuration is arrived based on
97 * the arm v7 manual section B4.1.104
98 */
99/* MAIR is 64 bit, with attrm[0..7], where m is 0..7
100 * Fill attrm[0..7] as below
101 * STRONG ORDERED 0000.0000
102 * DEVICE MEMORY 0000.0100
103 * normal memory, non cacheable 0100.0100
104 * normal memory, WB, RA, nWA 1110.1110
105 * normal memory, WB, RA, WA 1111.1111
106 * normal memory, WB, nRA, nWA 1100.1100
107 * normal memory, WT, RA, nWA 1010.1010
108 * normal memory , WT, RA, WA 1011.1011
109 */
110
111#define MAIR0 0xee440400
112#define MAIR1 0xbbaaccff
113#include <mmu.h>
114void arm_mmu_map_entry(mmu_section_t *entry);
115#endif /* LPAE */
Amol Jadi0228e9f2011-12-19 17:21:36 -0800116
Amol Jadi9ef9b732011-05-23 16:00:17 -0700117#else
118
119#error "MMU implementation needs to be updated for this ARM architecture"
120
121#endif
122
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700123void arm_mmu_map_section(addr_t paddr, addr_t vaddr, uint flags);
Channagoud Kadabi70f9c4e2015-06-17 17:29:10 -0700124uint64_t virtual_to_physical_mapping(uint32_t vaddr);
125uint32_t physical_to_virtual_mapping(uint64_t paddr);
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700126
127#if defined(__cplusplus)
128}
129#endif
130
131#endif