blob: d21100e3f005223a15eef389ada1e98fa2d00881 [file] [log] [blame]
Jon Medhurstbb1fe202014-01-24 15:41:33 +00001/*
2 * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
Sandrine Bailleux82a6e1a2014-04-03 13:48:04 +010031#ifndef __XLAT_TABLES_H__
32#define __XLAT_TABLES_H__
33
Achin Guptae9982542014-06-26 08:59:07 +010034
35/*
36 * Flags to override default values used to program system registers while
37 * enabling the MMU.
38 */
39#define DISABLE_DCACHE (1 << 0)
40
41#ifndef __ASSEMBLY__
Jon Medhurstbb1fe202014-01-24 15:41:33 +000042#include <stdint.h>
43
Soby Mathewb08bc042014-09-03 17:48:44 +010044/* Helper macro to define entries for mmap_region_t. It creates
45 * identity mappings for each region.
46 */
47#define MAP_REGION_FLAT(adr, sz, attr) MAP_REGION(adr, adr, sz, attr)
48
49/* Helper macro to define entries for mmap_region_t. It allows to
50 * re-map address mappings from 'pa' to 'va' for each region.
51 */
52#define MAP_REGION(pa, va, sz, attr) {(pa), (va), (sz), (attr)}
53
Jon Medhurstbb1fe202014-01-24 15:41:33 +000054/*
Sandrine Bailleux52b1ba62016-03-01 14:01:03 +000055 * Shifts and masks to access fields of an mmap_attr_t
56 */
57#define MT_TYPE_MASK 0x7
58#define MT_TYPE(_attr) ((_attr) & MT_TYPE_MASK)
59/* Access permissions (RO/RW) */
60#define MT_PERM_SHIFT 3
61/* Security state (SECURE/NS) */
62#define MT_SEC_SHIFT 4
63
64/*
65 * Memory mapping attributes
Jon Medhurstbb1fe202014-01-24 15:41:33 +000066 */
67typedef enum {
Sandrine Bailleux52b1ba62016-03-01 14:01:03 +000068 /*
69 * Memory types supported.
70 * These are organised so that, going down the list, the memory types
71 * are getting weaker; conversely going up the list the memory types are
72 * getting stronger.
73 */
74 MT_DEVICE,
75 MT_NON_CACHEABLE,
76 MT_MEMORY,
77 /* Values up to 7 are reserved to add new memory types in the future */
Jon Medhurstbb1fe202014-01-24 15:41:33 +000078
Sandrine Bailleux52b1ba62016-03-01 14:01:03 +000079 /*
80 * The following values are organised so that a clear bit gives a more
81 * restrictive mapping than a set bit, that way a bitwise-and of two
82 * sets of attributes will never give an attribute which has greater
83 * access rights than any of the original attributes.
84 */
85 MT_RO = 0 << MT_PERM_SHIFT,
86 MT_RW = 1 << MT_PERM_SHIFT,
Jon Medhurstbb1fe202014-01-24 15:41:33 +000087
Sandrine Bailleux52b1ba62016-03-01 14:01:03 +000088 MT_SECURE = 0 << MT_SEC_SHIFT,
89 MT_NS = 1 << MT_SEC_SHIFT,
Dan Handleye2712bc2014-04-10 15:37:22 +010090} mmap_attr_t;
Jon Medhurstbb1fe202014-01-24 15:41:33 +000091
92/*
93 * Structure for specifying a single region of memory.
94 */
Dan Handleye2712bc2014-04-10 15:37:22 +010095typedef struct mmap_region {
Lin Ma13592362014-06-02 11:45:36 -070096 unsigned long base_pa;
97 unsigned long base_va;
Jon Medhurstbb1fe202014-01-24 15:41:33 +000098 unsigned long size;
Dan Handleye2712bc2014-04-10 15:37:22 +010099 mmap_attr_t attr;
100} mmap_region_t;
Jon Medhurstbb1fe202014-01-24 15:41:33 +0000101
Lin Ma13592362014-06-02 11:45:36 -0700102void mmap_add_region(unsigned long base_pa, unsigned long base_va,
103 unsigned long size, unsigned attr);
Dan Handleya17fefa2014-05-14 12:38:32 +0100104void mmap_add(const mmap_region_t *mm);
Jon Medhurstbb1fe202014-01-24 15:41:33 +0000105
Dan Handleya17fefa2014-05-14 12:38:32 +0100106void init_xlat_tables(void);
Jon Medhurstbb1fe202014-01-24 15:41:33 +0000107
Achin Guptae9982542014-06-26 08:59:07 +0100108void enable_mmu_el1(uint32_t flags);
109void enable_mmu_el3(uint32_t flags);
Sandrine Bailleux82a6e1a2014-04-03 13:48:04 +0100110
Achin Guptae9982542014-06-26 08:59:07 +0100111#endif /*__ASSEMBLY__*/
Sandrine Bailleux82a6e1a2014-04-03 13:48:04 +0100112#endif /* __XLAT_TABLES_H__ */