acpisrc.h revision 1.1.1.13 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: acpisrc.h - Include file for AcpiSrc utility
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.13 christos * Copyright (C) 2000 - 2018, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1.1.2 jruoho #include "acpi.h"
45 1.1.1.2 jruoho #include "accommon.h"
46 1.1.1.9 christos #include "acapps.h"
47 1.1 jruoho
48 1.1.1.4 christos /* mkdir support */
49 1.1 jruoho
50 1.1.1.4 christos #ifdef WIN32
51 1.1.1.4 christos #include <direct.h>
52 1.1.1.4 christos #else
53 1.1 jruoho #define mkdir(x) mkdir(x, 0770)
54 1.1 jruoho #endif
55 1.1 jruoho
56 1.1 jruoho
57 1.1 jruoho /* Constants */
58 1.1 jruoho
59 1.1.1.11 christos #define LINES_IN_LEGAL_HEADER 115+36 /* intel+dual license. See legal header above at module start */
60 1.1.1.4 christos #define LEGAL_HEADER_SIGNATURE " * 2.1. This is your license from Intel Corp. under its intellectual property"
61 1.1.1.13 christos #define LINES_IN_LINUX_HEADER 2 /* SPDX header is 1 line Intel copyright is another line */
62 1.1.1.4 christos #define LINUX_HEADER_SIGNATURE " * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"
63 1.1.1.4 christos #define LINES_IN_ASL_HEADER 29 /* Header as output from disassembler */
64 1.1.1.4 christos
65 1.1 jruoho #define ASRC_MAX_FILE_SIZE (1024 * 100)
66 1.1 jruoho
67 1.1 jruoho #define FILE_TYPE_SOURCE 1
68 1.1 jruoho #define FILE_TYPE_HEADER 2
69 1.1 jruoho #define FILE_TYPE_DIRECTORY 3
70 1.1.1.5 christos #define FILE_TYPE_PATCH 4
71 1.1 jruoho
72 1.1 jruoho #define CVT_COUNT_TABS 0x00000001
73 1.1 jruoho #define CVT_COUNT_NON_ANSI_COMMENTS 0x00000002
74 1.1 jruoho #define CVT_TRIM_LINES 0x00000004
75 1.1 jruoho #define CVT_CHECK_BRACES 0x00000008
76 1.1 jruoho #define CVT_COUNT_LINES 0x00000010
77 1.1 jruoho #define CVT_BRACES_ON_SAME_LINE 0x00000020
78 1.1 jruoho #define CVT_MIXED_CASE_TO_UNDERSCORES 0x00000040
79 1.1 jruoho #define CVT_LOWER_CASE_IDENTIFIERS 0x00000080
80 1.1 jruoho #define CVT_REMOVE_DEBUG_MACROS 0x00000100
81 1.1 jruoho #define CVT_TRIM_WHITESPACE 0x00000200 /* Should be after all line removal */
82 1.1 jruoho #define CVT_REMOVE_EMPTY_BLOCKS 0x00000400 /* Should be after trimming lines */
83 1.1 jruoho #define CVT_REDUCE_TYPEDEFS 0x00000800
84 1.1 jruoho #define CVT_COUNT_SHORTMULTILINE_COMMENTS 0x00001000
85 1.1 jruoho #define CVT_SPACES_TO_TABS4 0x40000000 /* Tab conversion should be last */
86 1.1 jruoho #define CVT_SPACES_TO_TABS8 0x80000000 /* Tab conversion should be last */
87 1.1 jruoho
88 1.1 jruoho #define FLG_DEFAULT_FLAGS 0x00000000
89 1.1 jruoho #define FLG_NO_CARRIAGE_RETURNS 0x00000001
90 1.1 jruoho #define FLG_NO_FILE_OUTPUT 0x00000002
91 1.1 jruoho #define FLG_LOWERCASE_DIRNAMES 0x00000004
92 1.1 jruoho
93 1.1 jruoho #define AS_START_IGNORE "/*!"
94 1.1 jruoho #define AS_STOP_IGNORE "!*/"
95 1.1 jruoho
96 1.1 jruoho
97 1.1 jruoho /* Globals */
98 1.1 jruoho
99 1.1 jruoho extern UINT32 Gbl_Files;
100 1.1 jruoho extern UINT32 Gbl_MissingBraces;
101 1.1 jruoho extern UINT32 Gbl_Tabs;
102 1.1 jruoho extern UINT32 Gbl_NonAnsiComments;
103 1.1 jruoho extern UINT32 Gbl_SourceLines;
104 1.1 jruoho extern UINT32 Gbl_WhiteLines;
105 1.1 jruoho extern UINT32 Gbl_CommentLines;
106 1.1 jruoho extern UINT32 Gbl_LongLines;
107 1.1 jruoho extern UINT32 Gbl_TotalLines;
108 1.1 jruoho extern UINT32 Gbl_HeaderSize;
109 1.1 jruoho extern UINT32 Gbl_HeaderLines;
110 1.1 jruoho extern struct stat Gbl_StatBuf;
111 1.1 jruoho extern char *Gbl_FileBuffer;
112 1.1 jruoho extern UINT32 Gbl_TotalSize;
113 1.1 jruoho extern UINT32 Gbl_FileSize;
114 1.1 jruoho extern UINT32 Gbl_FileType;
115 1.1 jruoho extern BOOLEAN Gbl_VerboseMode;
116 1.1 jruoho extern BOOLEAN Gbl_QuietMode;
117 1.1 jruoho extern BOOLEAN Gbl_BatchMode;
118 1.1 jruoho extern BOOLEAN Gbl_MadeChanges;
119 1.1 jruoho extern BOOLEAN Gbl_Overwrite;
120 1.1 jruoho extern BOOLEAN Gbl_WidenDeclarations;
121 1.1 jruoho extern BOOLEAN Gbl_IgnoreLoneLineFeeds;
122 1.1 jruoho extern BOOLEAN Gbl_HasLoneLineFeeds;
123 1.1.1.4 christos extern BOOLEAN Gbl_Cleanup;
124 1.1.1.4 christos extern BOOLEAN Gbl_IgnoreTranslationEscapes;
125 1.1.1.12 christos extern BOOLEAN Gbl_CheckAscii;
126 1.1 jruoho extern void *Gbl_StructDefs;
127 1.1 jruoho
128 1.1 jruoho #define PARAM_LIST(pl) pl
129 1.1 jruoho #define TERSE_PRINT(a) if (!Gbl_VerboseMode) printf PARAM_LIST(a)
130 1.1 jruoho #define VERBOSE_PRINT(a) if (Gbl_VerboseMode) printf PARAM_LIST(a)
131 1.1 jruoho
132 1.1 jruoho #define REPLACE_WHOLE_WORD 0x00
133 1.1 jruoho #define REPLACE_SUBSTRINGS 0x01
134 1.1 jruoho #define REPLACE_MASK 0x01
135 1.1 jruoho
136 1.1 jruoho #define EXTRA_INDENT_C 0x02
137 1.1 jruoho
138 1.1 jruoho
139 1.1 jruoho /* Conversion table structs */
140 1.1 jruoho
141 1.1 jruoho typedef struct acpi_string_table
142 1.1 jruoho {
143 1.1 jruoho char *Target;
144 1.1 jruoho char *Replacement;
145 1.1 jruoho UINT8 Type;
146 1.1 jruoho
147 1.1 jruoho } ACPI_STRING_TABLE;
148 1.1 jruoho
149 1.1 jruoho
150 1.1 jruoho typedef struct acpi_typed_identifier_table
151 1.1 jruoho {
152 1.1 jruoho char *Identifier;
153 1.1 jruoho UINT8 Type;
154 1.1 jruoho
155 1.1 jruoho } ACPI_TYPED_IDENTIFIER_TABLE;
156 1.1 jruoho
157 1.1 jruoho #define SRC_TYPE_SIMPLE 0
158 1.1 jruoho #define SRC_TYPE_STRUCT 1
159 1.1 jruoho #define SRC_TYPE_UNION 2
160 1.1 jruoho
161 1.1 jruoho
162 1.1 jruoho typedef struct acpi_identifier_table
163 1.1 jruoho {
164 1.1 jruoho char *Identifier;
165 1.1 jruoho
166 1.1 jruoho } ACPI_IDENTIFIER_TABLE;
167 1.1 jruoho
168 1.1 jruoho typedef struct acpi_conversion_table
169 1.1 jruoho {
170 1.1 jruoho char *NewHeader;
171 1.1 jruoho UINT32 Flags;
172 1.1 jruoho
173 1.1 jruoho ACPI_TYPED_IDENTIFIER_TABLE *LowerCaseTable;
174 1.1 jruoho
175 1.1.1.13 christos char *SourceSpdxHeader;
176 1.1 jruoho ACPI_STRING_TABLE *SourceStringTable;
177 1.1 jruoho ACPI_IDENTIFIER_TABLE *SourceLineTable;
178 1.1 jruoho ACPI_IDENTIFIER_TABLE *SourceConditionalTable;
179 1.1 jruoho ACPI_IDENTIFIER_TABLE *SourceMacroTable;
180 1.1 jruoho ACPI_TYPED_IDENTIFIER_TABLE *SourceStructTable;
181 1.1.1.4 christos ACPI_IDENTIFIER_TABLE *SourceSpecialMacroTable;
182 1.1 jruoho UINT32 SourceFunctions;
183 1.1 jruoho
184 1.1.1.13 christos char *HeaderSpdxHeader;
185 1.1 jruoho ACPI_STRING_TABLE *HeaderStringTable;
186 1.1 jruoho ACPI_IDENTIFIER_TABLE *HeaderLineTable;
187 1.1 jruoho ACPI_IDENTIFIER_TABLE *HeaderConditionalTable;
188 1.1 jruoho ACPI_IDENTIFIER_TABLE *HeaderMacroTable;
189 1.1 jruoho ACPI_TYPED_IDENTIFIER_TABLE *HeaderStructTable;
190 1.1.1.4 christos ACPI_IDENTIFIER_TABLE *HeaderSpecialMacroTable;
191 1.1 jruoho UINT32 HeaderFunctions;
192 1.1 jruoho
193 1.1.1.13 christos /* SPDX header conversion for patches is not supported */
194 1.1.1.5 christos ACPI_STRING_TABLE *PatchStringTable;
195 1.1.1.5 christos ACPI_IDENTIFIER_TABLE *PatchLineTable;
196 1.1.1.5 christos ACPI_IDENTIFIER_TABLE *PatchConditionalTable;
197 1.1.1.5 christos ACPI_IDENTIFIER_TABLE *PatchMacroTable;
198 1.1.1.5 christos ACPI_TYPED_IDENTIFIER_TABLE *PatchStructTable;
199 1.1.1.5 christos ACPI_IDENTIFIER_TABLE *PatchSpecialMacroTable;
200 1.1.1.5 christos UINT32 PatchFunctions;
201 1.1.1.5 christos
202 1.1 jruoho } ACPI_CONVERSION_TABLE;
203 1.1 jruoho
204 1.1 jruoho
205 1.1 jruoho /* Conversion tables */
206 1.1 jruoho
207 1.1 jruoho extern ACPI_CONVERSION_TABLE LinuxConversionTable;
208 1.1 jruoho extern ACPI_CONVERSION_TABLE CleanupConversionTable;
209 1.1 jruoho extern ACPI_CONVERSION_TABLE StatsConversionTable;
210 1.1 jruoho extern ACPI_CONVERSION_TABLE CustomConversionTable;
211 1.1.1.2 jruoho extern ACPI_CONVERSION_TABLE LicenseConversionTable;
212 1.1.1.4 christos extern ACPI_CONVERSION_TABLE IndentConversionTable;
213 1.1 jruoho
214 1.1.1.5 christos typedef
215 1.1.1.5 christos char * (*AS_SCAN_CALLBACK) (
216 1.1.1.5 christos char *Buffer,
217 1.1.1.5 christos char *Filename,
218 1.1.1.5 christos UINT32 LineNumber);
219 1.1.1.5 christos
220 1.1.1.5 christos typedef struct as_brace_info
221 1.1.1.5 christos {
222 1.1.1.5 christos char *Operator;
223 1.1.1.5 christos UINT32 Length;
224 1.1.1.5 christos
225 1.1.1.5 christos } AS_BRACE_INFO;
226 1.1.1.5 christos
227 1.1 jruoho
228 1.1 jruoho /* Prototypes */
229 1.1 jruoho
230 1.1 jruoho char *
231 1.1 jruoho AsSkipUntilChar (
232 1.1 jruoho char *Buffer,
233 1.1 jruoho char Target);
234 1.1 jruoho
235 1.1 jruoho char *
236 1.1 jruoho AsSkipPastChar (
237 1.1 jruoho char *Buffer,
238 1.1 jruoho char Target);
239 1.1 jruoho
240 1.1 jruoho char *
241 1.1 jruoho AsReplaceData (
242 1.1 jruoho char *Buffer,
243 1.1 jruoho UINT32 LengthToRemove,
244 1.1 jruoho char *BufferToAdd,
245 1.1 jruoho UINT32 LengthToAdd);
246 1.1 jruoho
247 1.1 jruoho int
248 1.1 jruoho AsReplaceString (
249 1.1 jruoho char *Target,
250 1.1 jruoho char *Replacement,
251 1.1 jruoho UINT8 Type,
252 1.1 jruoho char *Buffer);
253 1.1 jruoho
254 1.1 jruoho int
255 1.1 jruoho AsLowerCaseString (
256 1.1 jruoho char *Target,
257 1.1 jruoho char *Buffer);
258 1.1 jruoho
259 1.1 jruoho void
260 1.1 jruoho AsRemoveLine (
261 1.1 jruoho char *Buffer,
262 1.1 jruoho char *Keyword);
263 1.1 jruoho
264 1.1 jruoho void
265 1.1 jruoho AsCheckForBraces (
266 1.1 jruoho char *Buffer,
267 1.1 jruoho char *Filename);
268 1.1 jruoho
269 1.1 jruoho void
270 1.1 jruoho AsTrimLines (
271 1.1 jruoho char *Buffer,
272 1.1 jruoho char *Filename);
273 1.1 jruoho
274 1.1 jruoho void
275 1.1 jruoho AsMixedCaseToUnderscores (
276 1.1.1.4 christos char *Buffer,
277 1.1.1.4 christos char *Filename);
278 1.1 jruoho
279 1.1 jruoho void
280 1.1 jruoho AsCountTabs (
281 1.1 jruoho char *Buffer,
282 1.1 jruoho char *Filename);
283 1.1 jruoho
284 1.1 jruoho void
285 1.1 jruoho AsBracesOnSameLine (
286 1.1 jruoho char *Buffer);
287 1.1 jruoho
288 1.1 jruoho void
289 1.1 jruoho AsLowerCaseIdentifiers (
290 1.1 jruoho char *Buffer);
291 1.1 jruoho
292 1.1 jruoho void
293 1.1 jruoho AsReduceTypedefs (
294 1.1 jruoho char *Buffer,
295 1.1 jruoho char *Keyword);
296 1.1 jruoho
297 1.1 jruoho void
298 1.1 jruoho AsRemoveDebugMacros (
299 1.1 jruoho char *Buffer);
300 1.1 jruoho
301 1.1 jruoho void
302 1.1 jruoho AsRemoveEmptyBlocks (
303 1.1 jruoho char *Buffer,
304 1.1 jruoho char *Filename);
305 1.1 jruoho
306 1.1 jruoho void
307 1.1.1.4 christos AsCleanupSpecialMacro (
308 1.1.1.4 christos char *Buffer,
309 1.1.1.4 christos char *Keyword);
310 1.1.1.4 christos
311 1.1.1.4 christos void
312 1.1 jruoho AsCountSourceLines (
313 1.1 jruoho char *Buffer,
314 1.1 jruoho char *Filename);
315 1.1 jruoho
316 1.1 jruoho void
317 1.1 jruoho AsCountNonAnsiComments (
318 1.1 jruoho char *Buffer,
319 1.1 jruoho char *Filename);
320 1.1 jruoho
321 1.1 jruoho void
322 1.1 jruoho AsTrimWhitespace (
323 1.1 jruoho char *Buffer);
324 1.1 jruoho
325 1.1 jruoho void
326 1.1 jruoho AsTabify4 (
327 1.1 jruoho char *Buffer);
328 1.1 jruoho
329 1.1 jruoho void
330 1.1 jruoho AsTabify8 (
331 1.1 jruoho char *Buffer);
332 1.1 jruoho
333 1.1 jruoho void
334 1.1 jruoho AsRemoveConditionalCompile (
335 1.1 jruoho char *Buffer,
336 1.1 jruoho char *Keyword);
337 1.1 jruoho
338 1.1 jruoho ACPI_NATIVE_INT
339 1.1 jruoho AsProcessTree (
340 1.1 jruoho ACPI_CONVERSION_TABLE *ConversionTable,
341 1.1 jruoho char *SourcePath,
342 1.1 jruoho char *TargetPath);
343 1.1 jruoho
344 1.1 jruoho int
345 1.1 jruoho AsGetFile (
346 1.1 jruoho char *FileName,
347 1.1 jruoho char **FileBuffer,
348 1.1 jruoho UINT32 *FileSize);
349 1.1 jruoho
350 1.1 jruoho int
351 1.1 jruoho AsPutFile (
352 1.1 jruoho char *Pathname,
353 1.1 jruoho char *FileBuffer,
354 1.1 jruoho UINT32 SystemFlags);
355 1.1 jruoho
356 1.1 jruoho void
357 1.1 jruoho AsReplaceHeader (
358 1.1 jruoho char *Buffer,
359 1.1 jruoho char *NewHeader);
360 1.1 jruoho
361 1.1 jruoho void
362 1.1.1.13 christos AsDoSpdxHeader (
363 1.1.1.13 christos char *Buffer,
364 1.1.1.13 christos char *SpdxHeader);
365 1.1.1.13 christos
366 1.1.1.13 christos void
367 1.1 jruoho AsConvertFile (
368 1.1 jruoho ACPI_CONVERSION_TABLE *ConversionTable,
369 1.1 jruoho char *FileBuffer,
370 1.1 jruoho char *Filename,
371 1.1 jruoho ACPI_NATIVE_INT FileType);
372 1.1 jruoho
373 1.1 jruoho ACPI_NATIVE_INT
374 1.1 jruoho AsProcessOneFile (
375 1.1 jruoho ACPI_CONVERSION_TABLE *ConversionTable,
376 1.1 jruoho char *SourcePath,
377 1.1 jruoho char *TargetPath,
378 1.1 jruoho int MaxPathLength,
379 1.1 jruoho char *Filename,
380 1.1 jruoho ACPI_NATIVE_INT FileType);
381 1.1 jruoho
382 1.1 jruoho ACPI_NATIVE_INT
383 1.1 jruoho AsCheckForDirectory (
384 1.1 jruoho char *SourceDirPath,
385 1.1 jruoho char *TargetDirPath,
386 1.1 jruoho char *Filename,
387 1.1 jruoho char **SourcePath,
388 1.1 jruoho char **TargetPath);
389 1.1 jruoho
390 1.1.1.4 christos void
391 1.1.1.4 christos AsRemoveExtraLines (
392 1.1.1.4 christos char *FileBuffer,
393 1.1.1.4 christos char *Filename);
394 1.1.1.4 christos
395 1.1.1.4 christos void
396 1.1.1.4 christos AsRemoveSpacesAfterPeriod (
397 1.1.1.4 christos char *FileBuffer,
398 1.1.1.4 christos char *Filename);
399 1.1.1.4 christos
400 1.1 jruoho BOOLEAN
401 1.1 jruoho AsMatchExactWord (
402 1.1 jruoho char *Word,
403 1.1 jruoho UINT32 WordLength);
404 1.1 jruoho
405 1.1 jruoho void
406 1.1 jruoho AsPrint (
407 1.1 jruoho char *Message,
408 1.1 jruoho UINT32 Count,
409 1.1 jruoho char *Filename);
410 1.1 jruoho
411 1.1 jruoho void
412 1.1 jruoho AsInsertPrefix (
413 1.1 jruoho char *Buffer,
414 1.1 jruoho char *Keyword,
415 1.1 jruoho UINT8 Type);
416 1.1 jruoho
417 1.1 jruoho char *
418 1.1 jruoho AsInsertData (
419 1.1 jruoho char *Buffer,
420 1.1 jruoho char *BufferToAdd,
421 1.1 jruoho UINT32 LengthToAdd);
422 1.1 jruoho
423 1.1 jruoho char *
424 1.1 jruoho AsRemoveData (
425 1.1 jruoho char *StartPointer,
426 1.1 jruoho char *EndPointer);
427 1.1 jruoho
428 1.1 jruoho void
429 1.1 jruoho AsInsertCarriageReturns (
430 1.1 jruoho char *Buffer);
431 1.1 jruoho
432 1.1 jruoho void
433 1.1 jruoho AsConvertToLineFeeds (
434 1.1 jruoho char *Buffer);
435