6 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
8 # Copyright (c) 2004 Mark Santcroos <marks@ripe.net>
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 OUTPUT="acpi_quirks.h"
40 gsub("\^# ", "", VERSION)
41 gsub("\\$", "", VERSION)
43 printf("/*\n") > OUTPUT;
44 printf(" * THIS FILE IS AUTOMAGICALLY GENERATED. DO NOT EDIT.\n") \
46 printf(" *\n") > OUTPUT;
47 printf(" * Generated from:\n") > OUTPUT;
48 printf(" * %s\n", VERSION) > OUTPUT;
49 printf(" */\n\n") > OUTPUT;
52 # Ignore comments and empty lines
57 # NAME field: this is the first line of every entry
61 printf("const struct acpi_q_rule %s[] = {\n", ENTRY_NAME) > OUTPUT;
70 # Parse table type to match
74 M = match ($0, /\"[^\"]*\"/);
75 OEM_ID = substr($0, M, RLENGTH);
78 ANCHOR = LENGTH - (M + RLENGTH - 1);
79 REMAINDER = substr($0, M + RLENGTH, ANCHOR);
80 M = match (REMAINDER, /\"[^\"]*\"/);
81 OEM_TABLE_ID = substr(REMAINDER, M, RLENGTH);
83 printf("\t{ \"%s\", OEM, {%s}, {%s} },\n",
84 TABLE, OEM_ID, OEM_TABLE_ID) > OUTPUT;
91 # Parse table type to match
94 M = match ($0, /\"[^\"]*\"/);
95 CREATOR = substr($0, M, RLENGTH);
97 printf("\t{ \"%s\", CREATOR, {%s} },\n",
98 TABLE, CREATOR) > OUTPUT;
110 OPERAND = trans_sign(SIGN);
112 printf("\t{ \"%s\", OEM_REV, {.op = %s}, {.rev = %s} },\n",
113 TABLE, OPERAND, VALUE) > OUTPUT;
117 # CREATOR REVISION field
119 $1 == "creator_rev:" {
125 OPERAND = trans_sign(SIGN);
127 printf("\t{ \"%s\", CREATOR_REV, {.op = %s}, {.rev = %s} },\n",
128 TABLE, OPERAND, VALUE) > OUTPUT;
132 # QUIRKS field: This is the last line of every entry
135 printf("\t{ \"\" }\n};\n\n") > OUTPUT;
138 sub(/^quirks:[ ]*/ , "", QUIRKS);
141 QUIRK_LIST[QUIRK_COUNT] = QUIRKS;
142 QUIRK_NAME[QUIRK_COUNT] = ENTRY_NAME;
146 # All information is gathered, now create acpi_quirks_table
150 printf("const struct acpi_q_entry acpi_quirks_table[] = {\n") \
153 # Array of all quirks
154 for (i = 1; i <= QUIRK_COUNT; i++) {
155 printf("\t{ %s, %s },\n", QUIRK_NAME[i], QUIRK_LIST[i]) \
160 printf("\t{ NULL, 0 }\n") > OUTPUT;
161 printf("};\n") > OUTPUT;
167 # Translate math SIGN into verbal OPERAND
169 function trans_sign(TMP_SIGN)
172 TMP_OPERAND = "OP_EQL";
173 else if (TMP_SIGN == "!=")
174 TMP_OPERAND = "OP_NEQ";
175 else if (TMP_SIGN == "<=")
176 TMP_OPERAND = "OP_LEQ";
177 else if (TMP_SIGN == ">=")
178 TMP_OPERAND = "OP_GEQ";
179 else if (TMP_SIGN == ">")
180 TMP_OPERAND = "OP_GTR";
181 else if (TMP_SIGN == "<")
182 TMP_OPERAND = "OP_LES";
184 printf("error: unknown sign: " TMP_SIGN "\n");
188 return (TMP_OPERAND);