xref: /aosp_15_r20/external/intel-media-driver/media_softlet/agnostic/common/vp/cm_fc_ld/PatchInfo.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2019, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 // CM FC patch info
23 //
24 
25 #pragma once
26 
27 #ifndef __CM_FC_PATCHINFO_H__
28 #define __CM_FC_PATCHINFO_H__
29 
30 #include <cstddef>
31 #include <cstdint>
32 
33 namespace cm {
34 namespace patch {
35 
36 typedef uint32_t PInfo_Offset;  // File offset
37 typedef uint32_t PInfo_Addr;    // Virtual address.
38 typedef uint32_t PInfo_U32;
39 typedef uint16_t PInfo_U16;
40 
41 const PInfo_U32 MAGIC = 0x49504D43U;   // 'I', 'P', 'M', 'C', i.e. 'CMPI'
42 
43 /// Version of patch info.
44 enum {
45   PV_0    = 0,  ///< Revision 0.
46 };
47 
48 /// Platform of patch info.
49 enum {
50   PP_NONE   = 0,  ///< Placeholder for invalid platform
51   PP_SNB    = 1,  ///< Sandybridge
52   PP_IVB    = 2,  ///< Ivybridge
53   PP_HSW    = 3,  ///< Haswell
54   PP_BDW    = 4,  ///< Broadwell
55   PP_CHV    = 5,  ///< CherryView
56   PP_SKL    = 6,  ///< Skylake
57   PP_BXT    = 7,  ///< Broxton
58   PP_CNL    = 9,  ///< CannonLake
59   PP_ICL    = 10, ///< IceLake
60   PP_ICLLP  = 11, ///< IceLake LP
61   PP_TGL  = 13, ///< TigerLake LP
62   PP_DG2    = 14,
63   PP_PVC    = 15,
64   PP_ELF    = 16,
65 };
66 
67 /// Patch info header.
68 struct PInfoHdr {
69   PInfo_U32     Magic;      ///< Magic word.
70   PInfo_U16     Version;    ///< Patch info version.
71   PInfo_U16     Platform;   ///< Platform, e.g. BDW, SKL, and etc.
72   PInfo_U16     ShNum;      ///< Number of entries of section header.
73   PInfo_U16     PgNum;      ///< Number of entries of program header.
74   PInfo_Offset  ShOffset;   ///< File offset to section header.
75   PInfo_Offset  PgOffset;   ///< File offset to program header.
76 
checkMagicPInfoHdr77   bool checkMagic() const {
78     return Magic == MAGIC;
79   }
80 
isValidPlatformPInfoHdr81   bool isValidPlatform() const {
82     switch (Platform) {
83     case PP_SNB:
84     case PP_IVB:
85     case PP_HSW:
86     case PP_BDW:
87     case PP_CHV:
88     case PP_SKL:
89     case PP_BXT:
90     case PP_CNL:
91     case PP_ICL:
92     case PP_ICLLP:
93     case PP_TGL:
94     case PP_DG2:
95     case PP_PVC:
96     case PP_ELF:
97       return true;
98     default: break;
99     }
100     return false;
101   }
102 };
103 
104 /// Patch info section header.
105 struct PInfoSectionHdr {
106   PInfo_U16     ShType;     ///< Section type.
107   PInfo_U16     ShLink;     ///< Link to section referenced by this section,
108                             ///  e.g., relocation links to its symbol table,
109                             //   symbol table links to its string table.
110   PInfo_U16     ShLink2;    ///< Another link to section referenced by this
111                             ///  section, e.g., symbol table links to its
112                             //   binary table, register access table links to
113                             //   its binary table, token table links to is
114                             //   binary table.
115   PInfo_U16     ShPadding;
116   PInfo_Offset  ShOffset;   ///< File offset to the section data.
117   PInfo_U32     ShSize;     ///< Size of section in bytes.
118 };
119 
120 /// Patch info section type.
121 enum {
122   PSHT_NONE     = 0,    ///< Invalid section type.
123   PSHT_BINARY   = 1,    ///< Binary machine code.
124   PSHT_REL      = 2,    ///< Relocation entries.
125   PSHT_SYMTAB   = 3,    ///< Symbol table.
126   PSHT_STRTAB   = 4,    ///< String table.
127   PSHT_INITREGTAB = 5,  ///< Initial register access table.
128   PSHT_FINIREGTAB = 6,  ///< Terminal register access table.
129   PSHT_TOKTAB   = 7,    ///< Token allocation table.
130 };
131 
132 /// Entry of symbol table.
133 struct PInfoSymbol {
134   PInfo_U32   SymName;  ///< Symbol name, index to string table.
135   PInfo_Addr  SymValue; ///< Symbol value, the relative address from the
136                         ///  section.
137   PInfo_U16   SymShndx; ///< Which section it's defined.
138   PInfo_U16   SymExtra; ///< Extra information.
139 };
140 
141 enum {
142   PSHN_UNDEF = 0, ///< Undefined section.
143 };
144 
145 /// Entry of relocation table.
146 struct PInfoRelocation {
147   PInfo_Addr  RelAddr;  ///< Location.
148   PInfo_U32   RelSym;   ///< Symbol table index.
149 };
150 
151 enum {
152   REG_NONE     = 0xFFFF,  ///< Invalid register number.
153   RDUT_DUMASK  = 0xC000,  ///< Def/Use mask.
154   RDUT_FULLUSE = 0 << 14, ///< Used fully.
155   RDUT_PARTUSE = 1 << 14, ///< Used partially.
156   RDUT_FULLDEF = 2 << 14, ///< Defined fully.
157   RDUT_PARTDEF = 3 << 14, ///< Defined partially.
158   RDUT_TOKMASK = 0x3FFF,  ///< Token mask.
159 };
160 
161 struct PInfoRegAccess {
162   PInfo_Addr  RegAccAddr;   ///< Location.
163   PInfo_U16   RegAccRegNo;  ///< Register number.
164   PInfo_U16   RegAccDUT;    ///< Register access (def/use/token).
165 };
166 
167 struct PInfoToken {
168   PInfo_U16   TokenNo;  ///< Token number.
169 };
170 
171 } // End patch namespace
172 } // End cm namespace
173 
174 #endif // __CM_FC_PATCHINFO_H__
175