xref: /aosp_15_r20/external/ms-tpm-20-ref/TPMCmd/tpm/include/prototypes/NvDynamic_fp.h (revision 5c591343844d1f9da7da26467c4bf7efc8a7a413)
1 /* Microsoft Reference Implementation for TPM 2.0
2  *
3  *  The copyright in this software is being made available under the BSD License,
4  *  included below. This software may be subject to other third party and
5  *  contributor rights, including patent rights, and no such rights are granted
6  *  under this license.
7  *
8  *  Copyright (c) Microsoft Corporation
9  *
10  *  All rights reserved.
11  *
12  *  BSD License
13  *
14  *  Redistribution and use in source and binary forms, with or without modification,
15  *  are permitted provided that the following conditions are met:
16  *
17  *  Redistributions of source code must retain the above copyright notice, this list
18  *  of conditions and the following disclaimer.
19  *
20  *  Redistributions in binary form must reproduce the above copyright notice, this
21  *  list of conditions and the following disclaimer in the documentation and/or
22  *  other materials provided with the distribution.
23  *
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
25  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  *  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 /*(Auto-generated)
36  *  Created by TpmPrototypes; Version 3.0 July 18, 2017
37  *  Date: Mar  7, 2020  Time: 07:15:54PM
38  */
39 
40 #ifndef    _NV_DYNAMIC_FP_H_
41 #define    _NV_DYNAMIC_FP_H_
42 
43 //*** NvWriteNvListEnd()
44 // Function to write the list terminator.
45 NV_REF
46 NvWriteNvListEnd(
47     NV_REF           end
48 );
49 
50 //*** NvUpdateIndexOrderlyData()
51 // This function is used to cause an update of the orderly data to the NV backing
52 // store.
53 void
54 NvUpdateIndexOrderlyData(
55     void
56 );
57 
58 //*** NvReadIndex()
59 // This function is used to read the NV Index NV_INDEX. This is used so that the
60 // index information can be compressed and only this function would be needed
61 // to decompress it. Mostly, compression would only be able to save the space
62 // needed by the policy.
63 void
64 NvReadNvIndexInfo(
65     NV_REF           ref,           // IN: points to NV where index is located
66     NV_INDEX        *nvIndex        // OUT: place to receive index data
67 );
68 
69 //*** NvReadObject()
70 // This function is used to read a persistent object. This is used so that the
71 // object information can be compressed and only this function would be needed
72 // to uncompress it.
73 void
74 NvReadObject(
75     NV_REF           ref,           // IN: points to NV where index is located
76     OBJECT          *object         // OUT: place to receive the object data
77 );
78 
79 //*** NvIndexIsDefined()
80 // See if an index is already defined
81 BOOL
82 NvIndexIsDefined(
83     TPM_HANDLE       nvHandle       // IN: Index to look for
84 );
85 
86 //*** NvIsPlatformPersistentHandle()
87 // This function indicates if a handle references a persistent object in the
88 // range belonging to the platform.
89 //  Return Type: BOOL
90 //      TRUE(1)         handle references a platform persistent object
91 //                      and may reference an owner persistent object either
92 //      FALSE(0)        handle does not reference platform persistent object
93 BOOL
94 NvIsPlatformPersistentHandle(
95     TPM_HANDLE       handle         // IN: handle
96 );
97 
98 //*** NvIsOwnerPersistentHandle()
99 // This function indicates if a handle references a persistent object in the
100 // range belonging to the owner.
101 //  Return Type: BOOL
102 //      TRUE(1)         handle is owner persistent handle
103 //      FALSE(0)        handle is not owner persistent handle and may not be
104 //                      a persistent handle at all
105 BOOL
106 NvIsOwnerPersistentHandle(
107     TPM_HANDLE       handle         // IN: handle
108 );
109 
110 //*** NvIndexIsAccessible()
111 //
112 // This function validates that a handle references a defined NV Index and
113 // that the Index is currently accessible.
114 //  Return Type: TPM_RC
115 //      TPM_RC_HANDLE           the handle points to an undefined NV Index
116 //                              If shEnable is CLEAR, this would include an index
117 //                              created using ownerAuth. If phEnableNV is CLEAR,
118 //                              this would include and index created using
119 //                              platformAuth
120 //      TPM_RC_NV_READLOCKED    Index is present but locked for reading and command
121 //                              does not write to the index
122 //      TPM_RC_NV_WRITELOCKED   Index is present but locked for writing and command
123 //                              writes to the index
124 TPM_RC
125 NvIndexIsAccessible(
126     TPMI_RH_NV_INDEX     handle        // IN: handle
127 );
128 
129 //*** NvGetEvictObject()
130 // This function is used to dereference an evict object handle and get a pointer
131 // to the object.
132 //  Return Type: TPM_RC
133 //      TPM_RC_HANDLE           the handle does not point to an existing
134 //                              persistent object
135 TPM_RC
136 NvGetEvictObject(
137     TPM_HANDLE       handle,        // IN: handle
138     OBJECT          *object         // OUT: object data
139 );
140 
141 //*** NvIndexCacheInit()
142 // Function to initialize the Index cache
143 void
144 NvIndexCacheInit(
145     void
146 );
147 
148 //*** NvGetIndexData()
149 // This function is used to access the data in an NV Index. The data is returned
150 // as a byte sequence.
151 //
152 // This function requires that the NV Index be defined, and that the
153 // required data is within the data range.  It also requires that TPMA_NV_WRITTEN
154 // of the Index is SET.
155 void
156 NvGetIndexData(
157     NV_INDEX            *nvIndex,       // IN: the in RAM index descriptor
158     NV_REF               locator,       // IN: where the data is located
159     UINT32               offset,        // IN: offset of NV data
160     UINT16               size,          // IN: number of octets of NV data to read
161     void                *data           // OUT: data buffer
162 );
163 
164 //*** NvHashIndexData()
165 // This function adds Index data to a hash. It does this in parts to avoid large stack
166 // buffers.
167 void
168 NvHashIndexData(
169     HASH_STATE          *hashState,     // IN: Initialized hash state
170     NV_INDEX            *nvIndex,       // IN: Index
171     NV_REF               locator,       // IN: where the data is located
172     UINT32               offset,        // IN: starting offset
173     UINT16               size           // IN: amount to hash
174 );
175 
176 //*** NvGetUINT64Data()
177 // Get data in integer format of a bit or counter NV Index.
178 //
179 // This function requires that the NV Index is defined and that the NV Index
180 // previously has been written.
181 UINT64
182 NvGetUINT64Data(
183     NV_INDEX            *nvIndex,       // IN: the in RAM index descriptor
184     NV_REF               locator        // IN: where index exists in NV
185 );
186 
187 //*** NvWriteIndexAttributes()
188 // This function is used to write just the attributes of an index.
189 //  Return type: TPM_RC
190 //      TPM_RC_NV_RATE          NV is rate limiting so retry
191 //      TPM_RC_NV_UNAVAILABLE   NV is not available
192 TPM_RC
193 NvWriteIndexAttributes(
194     TPM_HANDLE       handle,
195     NV_REF           locator,       // IN: location of the index
196     TPMA_NV          attributes     // IN: attributes to write
197 );
198 
199 //*** NvWriteIndexAuth()
200 // This function is used to write the authValue of an index. It is used by
201 // TPM2_NV_ChangeAuth()
202 //  Return type: TPM_RC
203 //      TPM_RC_NV_RATE          NV is rate limiting so retry
204 //      TPM_RC_NV_UNAVAILABLE   NV is not available
205 TPM_RC
206 NvWriteIndexAuth(
207     NV_REF           locator,       // IN: location of the index
208     TPM2B_AUTH      *authValue      // IN: the authValue to write
209 );
210 
211 //*** NvGetIndexInfo()
212 // This function loads the nvIndex Info into the NV cache and returns a pointer
213 // to the NV_INDEX. If the returned value is zero, the index was not found.
214 // The 'locator' parameter, if not NULL, will be set to the offset in NV of the
215 // Index (the location of the handle of the Index).
216 //
217 // This function will set the index cache. If the index is orderly, the attributes
218 // from RAM are substituted for the attributes in the cached index
219 NV_INDEX *
220 NvGetIndexInfo(
221     TPM_HANDLE       nvHandle,      // IN: the index handle
222     NV_REF          *locator        // OUT: location of the index
223 );
224 
225 //*** NvWriteIndexData()
226 // This function is used to write NV index data. It is intended to be used to
227 // update the data associated with the default index.
228 //
229 // This function requires that the NV Index is defined, and the data is
230 // within the defined data range for the index.
231 //
232 // Index data is only written due to a command that modifies the data in a single
233 // index. There is no case where changes are made to multiple indexes data at the
234 // same time. Multiple attributes may be change but not multiple index data. This
235 // is important because we will normally be handling the index for which we have
236 // the cached pointer values.
237 //  Return type: TPM_RC
238 //      TPM_RC_NV_RATE          NV is rate limiting so retry
239 //      TPM_RC_NV_UNAVAILABLE   NV is not available
240 TPM_RC
241 NvWriteIndexData(
242     NV_INDEX        *nvIndex,       // IN: the description of the index
243     UINT32           offset,        // IN: offset of NV data
244     UINT32           size,          // IN: size of NV data
245     void            *data           // IN: data buffer
246 );
247 
248 //*** NvWriteUINT64Data()
249 // This function to write back a UINT64 value. The various UINT64 values (bits,
250 // counters, and PINs) are kept in canonical format but manipulate in native
251 // format. This takes a native format value converts it and saves it back as
252 // in canonical format.
253 //
254 // This function will return the value from NV or RAM depending on the type of the
255 // index (orderly or not)
256 //
257 TPM_RC
258 NvWriteUINT64Data(
259     NV_INDEX        *nvIndex,       // IN: the description of the index
260     UINT64           intValue       // IN: the value to write
261 );
262 
263 //*** NvGetIndexName()
264 // This function computes the Name of an index
265 // The 'name' buffer receives the bytes of the Name and the return value
266 // is the number of octets in the Name.
267 //
268 // This function requires that the NV Index is defined.
269 TPM2B_NAME *
270 NvGetIndexName(
271     NV_INDEX        *nvIndex,       // IN: the index over which the name is to be
272                                     //     computed
273     TPM2B_NAME      *name           // OUT: name of the index
274 );
275 
276 //*** NvGetNameByIndexHandle()
277 // This function is used to compute the Name of an NV Index referenced by handle.
278 //
279 // The 'name' buffer receives the bytes of the Name and the return value
280 // is the number of octets in the Name.
281 //
282 // This function requires that the NV Index is defined.
283 TPM2B_NAME *
284 NvGetNameByIndexHandle(
285     TPMI_RH_NV_INDEX     handle,        // IN: handle of the index
286     TPM2B_NAME          *name           // OUT: name of the index
287 );
288 
289 //*** NvDefineIndex()
290 // This function is used to assign NV memory to an NV Index.
291 //
292 //  Return Type: TPM_RC
293 //      TPM_RC_NV_SPACE         insufficient NV space
294 TPM_RC
295 NvDefineIndex(
296     TPMS_NV_PUBLIC  *publicArea,    // IN: A template for an area to create.
297     TPM2B_AUTH      *authValue      // IN: The initial authorization value
298 );
299 
300 //*** NvAddEvictObject()
301 // This function is used to assign NV memory to a persistent object.
302 //  Return Type: TPM_RC
303 //      TPM_RC_NV_HANDLE        the requested handle is already in use
304 //      TPM_RC_NV_SPACE         insufficient NV space
305 TPM_RC
306 NvAddEvictObject(
307     TPMI_DH_OBJECT   evictHandle,   // IN: new evict handle
308     OBJECT          *object         // IN: object to be added
309 );
310 
311 //*** NvDeleteIndex()
312 // This function is used to delete an NV Index.
313 //  Return Type: TPM_RC
314 //      TPM_RC_NV_UNAVAILABLE   NV is not accessible
315 //      TPM_RC_NV_RATE          NV is rate limiting
316 TPM_RC
317 NvDeleteIndex(
318     NV_INDEX        *nvIndex,       // IN: an in RAM index descriptor
319     NV_REF           entityAddr     // IN: location in NV
320 );
321 
322 TPM_RC
323 NvDeleteEvict(
324     TPM_HANDLE       handle         // IN: handle of entity to be deleted
325 );
326 
327 //*** NvFlushHierarchy()
328 // This function will delete persistent objects belonging to the indicated hierarchy.
329 // If the storage hierarchy is selected, the function will also delete any
330 // NV Index defined using ownerAuth.
331 //  Return Type: TPM_RC
332 //      TPM_RC_NV_RATE           NV is unavailable because of rate limit
333 //      TPM_RC_NV_UNAVAILABLE    NV is inaccessible
334 TPM_RC
335 NvFlushHierarchy(
336     TPMI_RH_HIERARCHY    hierarchy      // IN: hierarchy to be flushed.
337 );
338 
339 //*** NvSetGlobalLock()
340 // This function is used to SET the TPMA_NV_WRITELOCKED attribute for all
341 // NV indexes that have TPMA_NV_GLOBALLOCK SET. This function is use by
342 // TPM2_NV_GlobalWriteLock().
343 //  Return Type: TPM_RC
344 //      TPM_RC_NV_RATE           NV is unavailable because of rate limit
345 //      TPM_RC_NV_UNAVAILABLE    NV is inaccessible
346 TPM_RC
347 NvSetGlobalLock(
348     void
349 );
350 
351 //*** NvCapGetPersistent()
352 // This function is used to get a list of handles of the persistent objects,
353 // starting at 'handle'.
354 //
355 // 'Handle' must be in valid persistent object handle range, but does not
356 // have to reference an existing persistent object.
357 //  Return Type: TPMI_YES_NO
358 //      YES         if there are more handles available
359 //      NO          all the available handles has been returned
360 TPMI_YES_NO
361 NvCapGetPersistent(
362     TPMI_DH_OBJECT   handle,        // IN: start handle
363     UINT32           count,         // IN: maximum number of returned handles
364     TPML_HANDLE     *handleList     // OUT: list of handle
365 );
366 
367 //*** NvCapGetIndex()
368 // This function returns a list of handles of NV indexes, starting from 'handle'.
369 // 'Handle' must be in the range of NV indexes, but does not have to reference
370 // an existing NV Index.
371 //  Return Type: TPMI_YES_NO
372 //      YES         if there are more handles to report
373 //      NO          all the available handles has been reported
374 TPMI_YES_NO
375 NvCapGetIndex(
376     TPMI_DH_OBJECT   handle,        // IN: start handle
377     UINT32           count,         // IN: max number of returned handles
378     TPML_HANDLE     *handleList     // OUT: list of handle
379 );
380 
381 //*** NvCapGetIndexNumber()
382 // This function returns the count of NV Indexes currently defined.
383 UINT32
384 NvCapGetIndexNumber(
385     void
386 );
387 
388 //*** NvCapGetPersistentNumber()
389 // Function returns the count of persistent objects currently in NV memory.
390 UINT32
391 NvCapGetPersistentNumber(
392     void
393 );
394 
395 //*** NvCapGetPersistentAvail()
396 // This function returns an estimate of the number of additional persistent
397 // objects that could be loaded into NV memory.
398 UINT32
399 NvCapGetPersistentAvail(
400     void
401 );
402 
403 //*** NvCapGetCounterNumber()
404 // Get the number of defined NV Indexes that are counter indexes.
405 UINT32
406 NvCapGetCounterNumber(
407     void
408 );
409 
410 //*** NvEntityStartup()
411 //  This function is called at TPM_Startup(). If the startup completes
412 //  a TPM Resume cycle, no action is taken. If the startup is a TPM Reset
413 //  or a TPM Restart, then this function will:
414 //  a) clear read/write lock;
415 //  b) reset NV Index data that has TPMA_NV_CLEAR_STCLEAR SET; and
416 //  c) set the lower bits in orderly counters to 1 for a non-orderly startup
417 //
418 //  It is a prerequisite that NV be available for writing before this
419 //  function is called.
420 BOOL
421 NvEntityStartup(
422     STARTUP_TYPE     type           // IN: start up type
423 );
424 
425 //*** NvCapGetCounterAvail()
426 // This function returns an estimate of the number of additional counter type
427 // NV indexes that can be defined.
428 UINT32
429 NvCapGetCounterAvail(
430     void
431 );
432 
433 //*** NvFindHandle()
434 // this function returns the offset in NV memory of the entity associated
435 // with the input handle.  A value of zero indicates that handle does not
436 //  exist reference an existing persistent object or defined NV Index.
437 NV_REF
438 NvFindHandle(
439     TPM_HANDLE       handle
440 );
441 
442 //*** NvReadMaxCount()
443 // This function returns the max NV counter value.
444 //
445 UINT64
446 NvReadMaxCount(
447     void
448 );
449 
450 //*** NvUpdateMaxCount()
451 // This function updates the max counter value to NV memory. This is just staging
452 // for the actual write that will occur when the NV index memory is modified.
453 //
454 void
455 NvUpdateMaxCount(
456     UINT64           count
457 );
458 
459 //*** NvSetMaxCount()
460 // This function is used at NV initialization time to set the initial value of
461 // the maximum counter.
462 void
463 NvSetMaxCount(
464     UINT64          value
465 );
466 
467 //*** NvGetMaxCount()
468 // Function to get the NV max counter value from the end-of-list marker
469 UINT64
470 NvGetMaxCount(
471     void
472 );
473 
474 #endif  // _NV_DYNAMIC_FP_H_
475