ZXFoundation™ 26h2
Loading...
Searching...
No Matches
types.cxxm
Go to the documentation of this file.
1/// SPDX-License-Identifier: Apache-2.0
2/// @file zxfoundation/dgp/isolation.zcomponent/types.cxxm
3/// @brief Hardware-first DGP isolation policy and lifecycle types.
4
5export module zxfoundation.dgp.isolation.types;
6import zxfoundation.base.types;
7import zxfoundation.base.typestate;
8import arch.s390x.mmu.types;
9
10export {
11
12namespace zxfoundation::dgp::isolation {
13
14 /// @brief Storage key value requesting automatic allocation by DGP policy.
15 inline constexpr u8 STORAGE_KEY_AUTO = 0xFFU;
16
17 /// @brief Number of architected storage-key access-control values.
18 inline constexpr u8 STORAGE_KEY_COUNT = 16U;
19
20 /// @brief First user-domain storage key retained for non-nucleus domains.
21 inline constexpr u8 STORAGE_KEY_USER_BASE = 8U;
22
23 /// @brief Last user-domain storage key retained for non-nucleus domains.
24 inline constexpr u8 STORAGE_KEY_USER_MAX = 15U;
25
26 /// @brief Hardware isolation facilities required by a DGP policy.
27 enum class isolation_feature : u64 {
28 none = 0ULL,
29 dat_asce = 1ULL << 0,
30 storage_key = 1ULL << 1,
31 program_call = 1ULL << 2,
32 access_register = 1ULL << 3,
33 edat_large_page = 1ULL << 4,
34 numa_policy = 1ULL << 5,
35 transactional_vm = 1ULL << 6,
36 smp_invalidation = 1ULL << 7,
37 };
38
39 /// @brief Revocation phase for a storage key held by a DGP domain.
40 enum class skey_revocation_state : u8 {
41 none = 0,
42 active = 1,
43 draining = 2,
44 reusable = 3,
45 };
46
47 /// @brief Authority bits interpreted by the DGP policy plane.
48 enum class isolation_rights : u32 {
49 none = 0U,
50 enter = 1U << 0, ///< Cross-domain gate entry.
51 map = 1U << 1, ///< Map physical memory into own address space.
52 share = 1U << 2, ///< Share memory across domain boundaries.
53 signal = 1U << 3, ///< Send/receive cross-domain signals.
54 io = 1U << 4, ///< Bind and operate I/O devices.
55 lifecycle = 1U << 5, ///< Create/destroy sub-domains, gates, portals.
56 delegate = 1U << 6, ///< Delegate capabilities to other domains.
57 quota = 1U << 7, ///< Allocate physical pages, DMA pools, I/O slots.
58 debug = 1U << 8, ///< Inspect other domains' state (query, info).
59 sched = 1U << 9, ///< Create strands, set scheduling parameters.
60 console = 1U << 10, ///< Write to system console.
61 service = 1U << 11, ///< Register/lookup/unregister named services.
62 all = 0x0000'FFFFU, ///< All rights (nucleus only).
63 };
64
65 /// @brief Combine two feature masks.
66 /// @param[in] lhs Left-hand feature mask.
67 /// @param[in] rhs Right-hand feature mask.
68 /// @return Combined feature mask.
69 [[nodiscard]] constexpr auto operator|(
70 isolation_feature lhs,
71 isolation_feature rhs
72 ) noexcept -> isolation_feature {
73 return static_cast<isolation_feature>(
74 static_cast<u64>(lhs) | static_cast<u64>(rhs));
75 }
76
77 /// @brief Intersect two feature masks.
78 /// @param[in] lhs Left-hand feature mask.
79 /// @param[in] rhs Right-hand feature mask.
80 /// @return Common feature mask.
81 [[nodiscard]] constexpr auto operator&(
82 isolation_feature lhs,
83 isolation_feature rhs
84 ) noexcept -> isolation_feature {
85 return static_cast<isolation_feature>(
86 static_cast<u64>(lhs) & static_cast<u64>(rhs));
87 }
88
89 /// @brief Combine two right masks.
90 /// @param[in] lhs Left-hand right mask.
91 /// @param[in] rhs Right-hand right mask.
92 /// @return Combined right mask.
93 [[nodiscard]] constexpr auto operator|(
94 dgp::isolation::isolation_rights lhs,
95 dgp::isolation::isolation_rights rhs
96 ) noexcept -> dgp::isolation::isolation_rights {
97 return static_cast<dgp::isolation::isolation_rights>(
98 static_cast<u32>(lhs) | static_cast<u32>(rhs));
99 }
100
101 /// @brief Intersect two right masks.
102 /// @param[in] lhs Left-hand right mask.
103 /// @param[in] rhs Right-hand right mask.
104 /// @return Common right mask.
105 [[nodiscard]] constexpr auto operator&(
106 dgp::isolation::isolation_rights lhs,
107 dgp::isolation::isolation_rights rhs
108 ) noexcept -> dgp::isolation::isolation_rights {
109 return static_cast<dgp::isolation::isolation_rights>(
110 static_cast<u32>(lhs) & static_cast<u32>(rhs));
111 }
112
113 /// @brief Test that all requested features are present.
114 /// @param[in] available Available feature mask.
115 /// @param[in] requested Required feature mask.
116 /// @return true when every requested feature is present.
117 [[nodiscard]] constexpr auto has_all_features(
118 isolation_feature available,
119 isolation_feature requested
120 ) noexcept -> bool {
121 return (static_cast<u64>(available & requested) == static_cast<u64>(requested));
122 }
123
124 /// @brief Test that all requested rights are present.
125 /// @param[in] available Available right mask.
126 /// @param[in] requested Required right mask.
127 /// @return true when every requested right is present.
128 [[nodiscard]] constexpr auto has_all_rights(
129 dgp::isolation::isolation_rights available,
130 dgp::isolation::isolation_rights requested
131 ) noexcept -> bool {
132 return (static_cast<u32>(available & requested) == static_cast<u32>(requested));
133 }
134
135 /// @brief Domain policy supplied to the DGP isolation core.
136 struct isolation_policy {
137 isolation_feature required_features{isolation_feature::none};
138 dgp::isolation::isolation_rights default_rights{dgp::isolation::isolation_rights::none};
139 u8 storage_key{STORAGE_KEY_AUTO};
140 u8 numa_node{0};
141 bool allow_portals{false};
142 bool allow_user_execute{false};
143 bool bootstrap_admin{false};
144 };
145
146 /// @brief Hardware-backed state recorded for one DGP isolation domain.
147 struct isolation_domain_state {
148 u32 domain_id{0};
149 arch::s390x::mmu::typed_asce<arch::s390x::mmu::dat_level::region_1> asce{};
150 u64 root_phys{0};
151 u8 storage_key{0};
152 u8 numa_node{0};
153 u16 revocation_epoch{0};
154 u32 storage_key_generation{0};
155 skey_revocation_state storage_key_state{skey_revocation_state::none};
156 dgp::isolation::isolation_rights granted_rights{dgp::isolation::isolation_rights::none};
157 };
158
159 static_assert(sizeof(isolation_feature) == sizeof(u64), "DGP feature mask must remain 64-bit");
160 static_assert(sizeof(dgp::isolation::isolation_rights) == sizeof(u32), "DGP rights mask must remain 32-bit");
161 static_assert(sizeof(zxfoundation::base::lifecycle_state) == sizeof(u8), "DGP lifecycle state must remain byte-sized");
162 static_assert(sizeof(skey_revocation_state) == sizeof(u8), "DGP storage-key revocation state must remain byte-sized");
163 static_assert(static_cast<u8>(zxfoundation::base::lifecycle_state::embryo) == 0U, "Embryo must be the zero state");
164 static_assert(static_cast<u8>(skey_revocation_state::none) == 0U, "Storage-key revocation none state must be zero");
165 static_assert(static_cast<u32>(dgp::isolation::isolation_rights::all) == 0x0000'FFFFU, "all rights must be the low 16 bits");
166 static_assert(STORAGE_KEY_USER_MAX < STORAGE_KEY_COUNT, "User storage-key range exceeds architected key count");
167
168} // namespace zxfoundation::dgp
169
170} // end export