5 # SPDX-License-Identifier: BSD-2-Clause
7 # Copyright (c) 2004 Mark Santcroos <marks@ripe.net>
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 OUTPUT="acpi_quirks.h"
39 gsub("\^# ", "", VERSION)
40 gsub("\\$", "", VERSION)
42 printf("/*\n") > OUTPUT;
43 printf(" * THIS FILE IS AUTOMAGICALLY GENERATED. DO NOT EDIT.\n") \
45 printf(" *\n") > OUTPUT;
46 printf(" * Generated from:\n") > OUTPUT;
47 printf(" * %s\n", VERSION) > OUTPUT;
48 printf(" */\n\n") > OUTPUT;
51 # Ignore comments and empty lines
56 # NAME field: this is the first line of every entry
60 printf("const struct acpi_q_rule %s[] = {\n", ENTRY_NAME) > OUTPUT;
69 # Parse table type to match
73 M = match ($0, /\"[^\"]*\"/);
74 OEM_ID = substr($0, M, RLENGTH);
77 ANCHOR = LENGTH - (M + RLENGTH - 1);
78 REMAINDER = substr($0, M + RLENGTH, ANCHOR);
79 M = match (REMAINDER, /\"[^\"]*\"/);
80 OEM_TABLE_ID = substr(REMAINDER, M, RLENGTH);
82 printf("\t{ \"%s\", OEM, {%s}, {%s} },\n",
83 TABLE, OEM_ID, OEM_TABLE_ID) > OUTPUT;
90 # Parse table type to match
93 M = match ($0, /\"[^\"]*\"/);
94 CREATOR = substr($0, M, RLENGTH);
96 printf("\t{ \"%s\", CREATOR, {%s} },\n",
97 TABLE, CREATOR) > OUTPUT;
109 OPERAND = trans_sign(SIGN);
111 printf("\t{ \"%s\", OEM_REV, {.op = %s}, {.rev = %s} },\n",
112 TABLE, OPERAND, VALUE) > OUTPUT;
116 # CREATOR REVISION field
118 $1 == "creator_rev:" {
124 OPERAND = trans_sign(SIGN);
126 printf("\t{ \"%s\", CREATOR_REV, {.op = %s}, {.rev = %s} },\n",
127 TABLE, OPERAND, VALUE) > OUTPUT;
131 # QUIRKS field: This is the last line of every entry
134 printf("\t{ \"\" }\n};\n\n") > OUTPUT;
137 sub(/^quirks:[ ]*/ , "", QUIRKS);
140 QUIRK_LIST[QUIRK_COUNT] = QUIRKS;
141 QUIRK_NAME[QUIRK_COUNT] = ENTRY_NAME;
145 # All information is gathered, now create acpi_quirks_table
149 printf("const struct acpi_q_entry acpi_quirks_table[] = {\n") \
152 # Array of all quirks
153 for (i = 1; i <= QUIRK_COUNT; i++) {
154 printf("\t{ %s, %s },\n", QUIRK_NAME[i], QUIRK_LIST[i]) \
159 printf("\t{ NULL, 0 }\n") > OUTPUT;
160 printf("};\n") > OUTPUT;
166 # Translate math SIGN into verbal OPERAND
168 function trans_sign(TMP_SIGN)
171 TMP_OPERAND = "OP_EQL";
172 else if (TMP_SIGN == "!=")
173 TMP_OPERAND = "OP_NEQ";
174 else if (TMP_SIGN == "<=")
175 TMP_OPERAND = "OP_LEQ";
176 else if (TMP_SIGN == ">=")
177 TMP_OPERAND = "OP_GEQ";
178 else if (TMP_SIGN == ">")
179 TMP_OPERAND = "OP_GTR";
180 else if (TMP_SIGN == "<")
181 TMP_OPERAND = "OP_LES";
183 printf("error: unknown sign: " TMP_SIGN "\n");
187 return (TMP_OPERAND);