1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 1993-2022 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 
24 #ifndef NBSI_READ_H
25 #define NBSI_READ_H
26 
27 #include "platform/nbsi/nbsi_table.h"
28 
29 typedef enum _NBSI_VALIDATE
30 {
31     NBSI_VALIDATE_ALL        = 0,          // do CRC and all normal tests
32     NBSI_VALIDATE_IGNORE_CRC               // normal tests, skip CRC
33 } NBSI_VALIDATE;
34 
35 typedef struct OBJGPU OBJGPU;
36 
37 NvU16 fnv1Hash16(const NvU8 * data, NvU32 dataLen);
38 NvU16 fnv1Hash16Unicode(const NvU16 * data, NvU32 dataLen);
39 NvU32 fnv32buf(const void *buf, NvU32 len, NvU32 hval, NvU32 prevPartHashLen);
40 NvU32 fnv32bufUnicode(const void *buf, NvU32 len, NvU32 hval, NvU32 prevPartHashLen);
41 void fnv1Hash20Array(const NvU8 *, NvU32, NvU32 * , NvU8);
42 void fnv1Hash20ArrayUnicode(const NvU16 *, NvU32, NvU32 * , NvU8);
43 NvU64 fnv1Hash64(const NvU8 * data, NvU32 dataLen);
44 NvU32 getNbsiValue (OBJGPU *, NvU32, NvU16, NvU8, NvU32*, NvU8*, NvU32*, NvU32*);
45 NV_STATUS initNbsiTable(OBJGPU *);
46 void freeNbsiTable(OBJGPU *);
47 NV_STATUS nbsiReadRegistryDword(OBJGPU *, const char *, NvU32 *);
48 NV_STATUS nbsiReadRegistryString(OBJGPU *, const char *, NvU8 *, NvU32 *);
49 NV_STATUS getNbsiObjByType(OBJGPU *, NvU16, NBSI_SOURCE_LOC *, NvU8 *, NvU32, NvU8 *, NvU32*, NvU32*, NvU32*, ACPI_DSM_FUNCTION, NBSI_VALIDATE);
50 void initNbsiObject(NBSI_OBJ *pNbsiObj);
51 NBSI_OBJ *getNbsiObject(void);
52 
53 
54 /*
55  * 32 bit magic FNV-0 and FNV-1 prime
56  */
57 #define FNV_32_PRIME 0x01000193 // is 16777619.
58 #define MASK_20 0xfffff
59 #define MASK_16 0xffff
60 #define FNV1_32_INIT 0x811C9DC5 // is 2166136261.
61 
62 // State (undefined, open, bad or not present) of the nbsiTable
63 #define NBSI_TABLE_UNDEFINED 0  // nbsi table initialization not called so
64                                 // nbsiTableptr unallocated
65 #define NBSI_TABLE_INIT 1       // nbsi table being opened not yet ready
66 #define NBSI_TABLE_OPEN 2       // nbsi table ready for business
67 #define NBSI_TABLE_BAD 3        // nbsi table structure bad
68 #define NBSI_TABLE_NOTPRESENT 4 // nbsi table is not present
69 
70 #define NBSI_TABLE_FMT_UNKNOWN 0xff  // Unknown format for NBSI table
71 
72 #define NBSI_REVISION_ID   0x00000101
73 #define NVHG_NBSI_REVISION_ID   0x00000101
74 
75 #define NBSI_FUNC_PLATCAPS      0x00000001    // Platform NBSI capabilities
76 #define NBSI_FUNC_PLATPOLICY    0x00000002    // Query/Set Platform Policy
77 #define NBSI_FUNC_DISPLAYSTATUS 0x00000003    // Query the Display Hot-Key
78 #define NBSI_FUNC_MDTL          0x00000004    //
79 #define NBSI_FUNC_CALLBACKS     0x00000005    // Get Callbacks
80 #define NBSI_FUNC_GETOBJBYTYPE  0x00000006    // Get an Object by Type
81 #define NBSI_FUNC_GETALLOBJS    0x00000007    // Get Driver Object
82 
83 // Return values for NBSI_FUNC_SUPPORT call.
84 #define NBSI_FUNC_PLATCAPS_SUPPORTED      NVBIT(1) // Platform NBSI capabilities
85 #define NBSI_FUNC_PLATPOLICY_SUPPORTED    NVBIT(2) // Query/Set Platform Policy
86 #define NBSI_FUNC_DISPLAYSTATUS_SUPPORTED NVBIT(3) // Query the Display Hot-Key
87 #define NBSI_FUNC_MDTL_SUPPORTED          NVBIT(4) //
88 #define NBSI_FUNC_CALLBACKS_SUPPORTED     NVBIT(5) // Get Callbacks
89 #define NBSI_FUNC_GETOBJBYTYPE_SUPPORTED  NVBIT(6) // Get an Object by Type
90 #define NBSI_FUNC_GETALLOBJS_SUPPORTED    NVBIT(7) // Get Driver Object
91 
92 #define NBSI_READ_SIZE          (4*1024)      // 4K as per spec
93 #define NBSI_INIT_TABLE_ALLOC_SIZE  NBSI_READ_SIZE // must be larger than
94                                               // NBSI_READ_SIZE
95 
96 #define NBPB_FUNC_SUPPORT           0x00000000  // Function is supported?
97 #define NBPB_FUNC_GETOBJBYTYPE      0x00000010  // Fetch any specific Object by Type
98 #define NBPB_FUNC_GETALLOBJS        0x00000011  // Fetch all Objects
99 #define NBPB_FUNC_GETTHERMALBUDGET  0x00000020  // Get the current thermal budget
100 #define NBPB_FUNC_GETPSS            0x00000021  // Get the PSS table
101 #define NBPB_FUNC_SETPPC            0x00000022  // Set p-State Cap
102 #define NBPB_FUNC_GETPPC            0x00000023  // Get the last p-State cap set with _FUNC_SETPPC
103 
104 #endif // NBSI_READ_H
105