interplane.Get Omega
Read in your language

physics-mv

FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.

Brought by drakestapleton

branch main Branches Tags History

physics-mv / third_party / nvidia-open-580.173.02 / src / common / sdk / nvidia / inc / rs_access.h

273 lines · 9561 bytes Raw Blame History
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: MIT
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23#pragma once
24
25#include <nvtypes.h>
26
27//
28// This file was generated with FINN, an NVIDIA coding tool.
29// Source file: rs_access.finn
30//
31
32
33
34
35#include "nvtypes.h"
36#include "nvmisc.h"
37
38
39/****************************************************************************/
40/* Access right definitions */
41/****************************************************************************/
42
43//
44// The meaning of each access right is documented in
45// resman/docs/rmapi/resource_server/rm_capabilities.adoc
46//
47// RS_ACCESS_COUNT is the number of access rights that have been defined
48// and are in use. All integers in the range [0, RS_ACCESS_COUNT) should
49// represent valid access rights.
50//
51// When adding a new access right, don't forget to update
52// 1) The descriptions in the resman/docs/rmapi/resource_server/rm_capabilities.adoc
53// 2) RS_ACCESS_COUNT, defined below
54// 3) The declaration of g_rsAccessMetadata in rs_access_rights.c
55// 4) The list of access rights in drivers/common/chip-config/Chipcontrols.pm
56// 5) Any relevant access right callbacks
57//
58
59#define RS_ACCESS_DUP_OBJECT 0U
60#define RS_ACCESS_NICE 1U
61#define RS_ACCESS_DEBUG 2U
62#define RS_ACCESS_PERFMON 3U
63#define RS_ACCESS_COUNT 4U
64
65
66/****************************************************************************/
67/* Access right data structures */
68/****************************************************************************/
69
70/*!
71 * @brief A type that can be used to represent any access right.
72 */
73typedef NvU16 RsAccessRight;
74
75/*!
76 * @brief An internal type used to represent one limb in an access right mask.
77 */
78typedef NvU32 RsAccessLimb;
79#define SDK_RS_ACCESS_LIMB_BITS 32
80
81/*!
82 * @brief The number of limbs in the RS_ACCESS_MASK struct.
83 */
84#define SDK_RS_ACCESS_MAX_LIMBS 1
85
86/*!
87 * @brief The maximum number of possible access rights supported by the
88 * current data structure definition.
89 *
90 * You probably want RS_ACCESS_COUNT instead, which is the number of actual
91 * access rights defined.
92 */
93#define SDK_RS_ACCESS_MAX_COUNT (0x20) /* finn: Evaluated from "(SDK_RS_ACCESS_LIMB_BITS * SDK_RS_ACCESS_MAX_LIMBS)" */
94
95/**
96 * @brief A struct representing a set of access rights.
97 *
98 * Note that the values of bit positions larger than RS_ACCESS_COUNT is
99 * undefined, and should not be assumed to be 0 (see RS_ACCESS_MASK_FILL).
100 */
101typedef struct RS_ACCESS_MASK {
102 RsAccessLimb limbs[SDK_RS_ACCESS_MAX_LIMBS];
103} RS_ACCESS_MASK;
104
105/**
106 * @brief A struct representing auxiliary information about each access right.
107 */
108typedef struct RS_ACCESS_INFO {
109 NvU32 flags;
110} RS_ACCESS_INFO;
111
112
113/****************************************************************************/
114/* Access right macros */
115/****************************************************************************/
116
117#define SDK_RS_ACCESS_LIMB_INDEX(index) ((index) / SDK_RS_ACCESS_LIMB_BITS)
118#define SDK_RS_ACCESS_LIMB_POS(index) ((index) % SDK_RS_ACCESS_LIMB_BITS)
119
120#define SDK_RS_ACCESS_LIMB_ELT(pAccessMask, index) \
121 ((pAccessMask)->limbs[SDK_RS_ACCESS_LIMB_INDEX(index)])
122#define SDK_RS_ACCESS_OFFSET_MASK(index) \
123 NVBIT_TYPE(SDK_RS_ACCESS_LIMB_POS(index), RsAccessLimb)
124
125/*!
126 * @brief Checks that accessRight represents a valid access right.
127 *
128 * The valid range of access rights is [0, RS_ACCESS_COUNT).
129 *
130 * @param[in] accessRight The access right value to check
131 *
132 * @return true if accessRight is valid
133 * @return false otherwise
134 */
135#define RS_ACCESS_BOUNDS_CHECK(accessRight) \
136 (accessRight < RS_ACCESS_COUNT)
137
138/*!
139 * @brief Test whether an access right is present in a set
140 *
141 * @param[in] pAccessMask The set of access rights to read
142 * @param[in] index The access right to examine
143 *
144 * @return NV_TRUE if the access right specified by index was present in the set,
145 * and NV_FALSE otherwise
146 */
147#define RS_ACCESS_MASK_TEST(pAccessMask, index) \
148 (RS_ACCESS_BOUNDS_CHECK(index) && \
149 (SDK_RS_ACCESS_LIMB_ELT(pAccessMask, index) & SDK_RS_ACCESS_OFFSET_MASK(index)) != 0)
150
151/*!
152 * @brief Add an access right to a mask
153 *
154 * @param[in] pAccessMask The set of access rights to modify
155 * @param[in] index The access right to set
156 */
157#define RS_ACCESS_MASK_ADD(pAccessMask, index) \
158 do \
159 { \
160 if (RS_ACCESS_BOUNDS_CHECK(index)) { \
161 SDK_RS_ACCESS_LIMB_ELT(pAccessMask, index) |= SDK_RS_ACCESS_OFFSET_MASK(index); \
162 } \
163 } while (NV_FALSE)
164
165/*!
166 * @brief Remove an access right from a mask
167 *
168 * @param[in] pAccessMask The set of access rights to modify
169 * @param[in] index The access right to unset
170 */
171#define RS_ACCESS_MASK_REMOVE(pAccessMask, index) \
172 do \
173 { \
174 if (RS_ACCESS_BOUNDS_CHECK(index)) { \
175 SDK_RS_ACCESS_LIMB_ELT(pAccessMask, index) &= ~SDK_RS_ACCESS_OFFSET_MASK(index); \
176 } \
177 } while (NV_FALSE)
178
179/*!
180 * @brief Performs an in-place union between two access right masks
181 *
182 * @param[in,out] pMaskOut The access rights mask to be updated
183 * @param[in] pMaskIn The set of access rights to be added to pMaskOut
184 */
185#define RS_ACCESS_MASK_UNION(pMaskOut, pMaskIn) \
186 do \
187 { \
188 NvLength limb; \
189 for (limb = 0; limb < SDK_RS_ACCESS_MAX_LIMBS; limb++) \
190 { \
191 SDK_RS_ACCESS_LIMB_ELT(pMaskOut, limb) |= SDK_RS_ACCESS_LIMB_ELT(pMaskIn, limb); \
192 } \
193 } while (NV_FALSE)
194
195/*!
196 * @brief Performs an in-place subtract of one mask's rights from another
197 *
198 * @param[in,out] pMaskOut The access rights mask to be updated
199 * @param[in] pMaskIn The set of access rights to be removed from pMaskOut
200 */
201#define RS_ACCESS_MASK_SUBTRACT(pMaskOut, pMaskIn) \
202 do \
203 { \
204 NvLength limb; \
205 for (limb = 0; limb < SDK_RS_ACCESS_MAX_LIMBS; limb++) \
206 { \
207 SDK_RS_ACCESS_LIMB_ELT(pMaskOut, limb) &= ~SDK_RS_ACCESS_LIMB_ELT(pMaskIn, limb); \
208 } \
209 } while (NV_FALSE)
210
211/*!
212 * @brief Removes all rights from an access rights mask
213 *
214 * @param[in,out] pAccessMask The access rights mask to be updated
215 */
216#define RS_ACCESS_MASK_CLEAR(pAccessMask) \
217 do \
218 { \
219 portMemSet(pAccessMask, 0, sizeof(*pAccessMask)); \
220 } while (NV_FALSE)
221
222/*!
223 * @brief Adds all rights to an access rights mask
224 *
225 * @param[in,out] pAccessMask The access rights mask to be updated
226 */
227#define RS_ACCESS_MASK_FILL(pAccessMask) \
228 do \
229 { \
230 portMemSet(pAccessMask, 0xff, sizeof(*pAccessMask)); \
231 } while (NV_FALSE)
232
233
234/****************************************************************************/
235/* Share definitions */
236/****************************************************************************/
237
238//
239// The usage of Share Policy and the meaning of each share type is documented in
240// resman/docs/rmapi/resource_server/rm_capabilities.adoc
241//
242#define RS_SHARE_TYPE_NONE (0U)
243#define RS_SHARE_TYPE_ALL (1U)
244#define RS_SHARE_TYPE_OS_SECURITY_TOKEN (2U)
245#define RS_SHARE_TYPE_CLIENT (3U)
246#define RS_SHARE_TYPE_PID (4U)
247#define RS_SHARE_TYPE_SMC_PARTITION (5U)
248#define RS_SHARE_TYPE_GPU (6U)
249#define RS_SHARE_TYPE_FM_CLIENT (7U)
250// Must be last. Update when a new SHARE_TYPE is added
251#define RS_SHARE_TYPE_MAX (8U)
252
253
254//
255// Use Revoke to remove an existing policy from the list.
256// Allow is based on OR logic, Require is based on AND logic.
257// To share a right, at least one Allow (non-Require) must match, and all Require must pass.
258// If Compose is specified, policies will be added to the list. Otherwise, they will replace the list.
259//
260#define RS_SHARE_ACTION_FLAG_REVOKE NVBIT(0)
261#define RS_SHARE_ACTION_FLAG_REQUIRE NVBIT(1)
262#define RS_SHARE_ACTION_FLAG_COMPOSE NVBIT(2)
263
264/****************************************************************************/
265/* Share flag data structures */
266/****************************************************************************/
267
268typedef struct RS_SHARE_POLICY {
269 NvU32 target;
270 RS_ACCESS_MASK accessMask;
271 NvU16 type; ///< RS_SHARE_TYPE_
272 NvU8 action; ///< RS_SHARE_ACTION_
273} RS_SHARE_POLICY;