qualcomm/qbox
Loading...
Searching...
No Matches
smmuv3_memory_attrs.h
1/*
2 * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause-Clear
5 */
6
7#ifndef SMMUV3_MEMORY_ATTRS_H
8#define SMMUV3_MEMORY_ATTRS_H
9
10#include <tlm>
11#include <sstream>
12#include <cstdint>
13
14namespace gs {
15
16// Carries page-table memory attributes (cacheability, shareability, permissions) downstream
17// alongside a translated transaction so the rest of the system can honour them.
18class smmuv3_memory_attrs_extension : public tlm::tlm_extension<smmuv3_memory_attrs_extension>
19{
20public:
21 // Memory type selects how the interconnect/caches are allowed to treat an access.
22 // Naming follows the page-table encoding: "n" = "non", G/R/E = Gathering/Reordering/Early-write-ack;
23 // so DEVICE_nGnRnE is the strictest device type, NORMAL_WB is fully cacheable write-back.
24 enum class MemoryType : uint8_t {
25 DEVICE_nGnRnE = 0, // device, no Gathering, no Reordering, no Early write acknowledge
26 DEVICE_nGnRE = 1, // device, no Gathering, no Reordering, Early write ack allowed
27 DEVICE_nGRE = 2, // device, no Gathering, Reordering allowed, Early write ack allowed
28 DEVICE_GRE = 3, // device, Gathering/Reordering/Early-ack all allowed (loosest device)
29 NORMAL_NC = 4, // normal memory, Non-Cacheable
30 NORMAL_WT = 5, // normal memory, Write-Through cacheable
31 NORMAL_WB = 6, // normal memory, Write-Back cacheable (the default)
32 };
33
34 // How widely a normal-memory access must be observed (which cache scope must agree on its value).
35 enum class Shareability : uint8_t {
36 NON_SHAREABLE = 0,
37 RESERVED = 1,
38 OUTER_SHAREABLE = 2, // visible to "outer" sharers (typically across clusters/system)
39 INNER_SHAREABLE = 3, // visible to "inner" sharers (typically within a cluster)
40 };
41
42 // AccessPerm = Access Permission: read/write rights for privileged (kernel) vs unprivileged (user) accessors.
43 // RW = Read+Write, RO = Read-Only, NONE = no access.
44 enum class AccessPerm : uint8_t {
45 PRIV_RW_USER_NONE = 0,
46 PRIV_RW_USER_RW = 1,
47 PRIV_RO_USER_NONE = 2,
48 PRIV_RO_USER_RO = 3,
49 };
50
51 smmuv3_memory_attrs_extension()
52 : m_memory_type(MemoryType::NORMAL_WB)
53 , m_shareability(Shareability::INNER_SHAREABLE)
54 , m_access_perm(AccessPerm::PRIV_RW_USER_RW)
55 , m_attr_indx(0)
56 , m_non_secure(true)
57 , m_privileged_execute_never(false)
58 , m_unprivileged_execute_never(false)
59 , m_contiguous(false)
60 , m_dirty_bit_modifier(false)
61 {
62 }
63
64 virtual tlm::tlm_extension_base* clone() const override
65 {
66 auto* ext = new smmuv3_memory_attrs_extension();
67 ext->m_memory_type = m_memory_type;
68 ext->m_shareability = m_shareability;
69 ext->m_access_perm = m_access_perm;
70 ext->m_attr_indx = m_attr_indx;
71 ext->m_non_secure = m_non_secure;
72 ext->m_privileged_execute_never = m_privileged_execute_never;
73 ext->m_unprivileged_execute_never = m_unprivileged_execute_never;
74 ext->m_contiguous = m_contiguous;
75 ext->m_dirty_bit_modifier = m_dirty_bit_modifier;
76 return ext;
77 }
78
79 virtual void copy_from(const tlm::tlm_extension_base& ext) override
80 {
81 const auto& other = static_cast<const smmuv3_memory_attrs_extension&>(ext);
82 m_memory_type = other.m_memory_type;
83 m_shareability = other.m_shareability;
84 m_access_perm = other.m_access_perm;
85 m_attr_indx = other.m_attr_indx;
86 m_non_secure = other.m_non_secure;
87 m_privileged_execute_never = other.m_privileged_execute_never;
88 m_unprivileged_execute_never = other.m_unprivileged_execute_never;
89 m_contiguous = other.m_contiguous;
90 m_dirty_bit_modifier = other.m_dirty_bit_modifier;
91 }
92
93 void set_memory_type(MemoryType type) { m_memory_type = type; }
94 void set_shareability(Shareability sh) { m_shareability = sh; }
95 void set_access_perm(AccessPerm ap) { m_access_perm = ap; }
96 void set_attr_indx(uint8_t idx) { m_attr_indx = idx; }
97 void set_non_secure(bool ns) { m_non_secure = ns; }
98 void set_pxn(bool pxn) { m_privileged_execute_never = pxn; }
99 void set_uxn(bool uxn) { m_unprivileged_execute_never = uxn; }
100 void set_contiguous(bool c) { m_contiguous = c; }
101 void set_dbm(bool dbm) { m_dirty_bit_modifier = dbm; }
102
103 MemoryType get_memory_type() const { return m_memory_type; }
104 Shareability get_shareability() const { return m_shareability; }
105 AccessPerm get_access_perm() const { return m_access_perm; }
106 uint8_t get_attr_indx() const { return m_attr_indx; }
107 bool is_non_secure() const { return m_non_secure; }
108 bool is_pxn() const { return m_privileged_execute_never; }
109 bool is_uxn() const { return m_unprivileged_execute_never; }
110 bool is_contiguous() const { return m_contiguous; }
111 bool is_dbm() const { return m_dirty_bit_modifier; }
112
113 void set_from_descriptor(uint64_t desc, uint32_t table_attrs = 0)
114 {
115 m_attr_indx = (desc >> 2) & 0xF;
116 m_shareability = static_cast<Shareability>((desc >> 8) & 0x3);
117 m_access_perm = static_cast<AccessPerm>((desc >> 6) & 0x3);
118 m_non_secure = (desc >> 5) & 0x1;
119 m_privileged_execute_never = ((desc >> 53) & 0x1) || ((table_attrs >> 3) & 0x1);
120 m_unprivileged_execute_never = ((desc >> 54) & 0x1) || ((table_attrs >> 4) & 0x1);
121 m_contiguous = (desc >> 52) & 0x1;
122 m_dirty_bit_modifier = (desc >> 51) & 0x1;
123 m_memory_type = MemoryType::NORMAL_WB;
124 }
125
126 std::string to_string() const
127 {
128 std::ostringstream oss;
129 oss << "MemAttrs{type=";
130 switch (m_memory_type) {
131 case MemoryType::DEVICE_nGnRnE:
132 oss << "Device-nGnRnE";
133 break;
134 case MemoryType::DEVICE_nGnRE:
135 oss << "Device-nGnRE";
136 break;
137 case MemoryType::DEVICE_nGRE:
138 oss << "Device-nGRE";
139 break;
140 case MemoryType::DEVICE_GRE:
141 oss << "Device-GRE";
142 break;
143 case MemoryType::NORMAL_NC:
144 oss << "Normal-NC";
145 break;
146 case MemoryType::NORMAL_WT:
147 oss << "Normal-WT";
148 break;
149 case MemoryType::NORMAL_WB:
150 oss << "Normal-WB";
151 break;
152 default:
153 oss << "Unknown";
154 break;
155 }
156 oss << ", sh=";
157 switch (m_shareability) {
158 case Shareability::NON_SHAREABLE:
159 oss << "Non";
160 break;
161 case Shareability::OUTER_SHAREABLE:
162 oss << "Outer";
163 break;
164 case Shareability::INNER_SHAREABLE:
165 oss << "Inner";
166 break;
167 default:
168 oss << "Reserved";
169 break;
170 }
171 oss << ", ap=" << static_cast<int>(m_access_perm) << ", ns=" << m_non_secure
172 << ", pxn=" << m_privileged_execute_never << ", uxn=" << m_unprivileged_execute_never << "}";
173 return oss.str();
174 }
175
176private:
177 MemoryType m_memory_type;
178 Shareability m_shareability;
179 AccessPerm m_access_perm;
180 uint8_t m_attr_indx; // attr_indx = index into a CPU-side memory-attribute lookup table (MAIR-style)
181 bool m_non_secure; // NS = Non-Secure: when true the access is in the Non-Secure world
182 bool m_privileged_execute_never; // PXN = Privileged eXecute Never: kernel cannot fetch instructions here
183 bool m_unprivileged_execute_never; // UXN = Unprivileged eXecute Never: user cannot fetch instructions here
184 bool m_contiguous; // page-table "contiguous" hint: this entry is part of a run of pages
185 bool m_dirty_bit_modifier; // DBM = Dirty Bit Modifier: lets hardware mark the page dirty on write
186};
187
188} // namespace gs
189
190#endif
Tool which reads a Lua configuration file and sets parameters.
Definition biflow.cc:10