2 * Copyright (c) 2004 Nate Lawson (SDG)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
33 #include <contrib/dev/acpica/acpi.h>
34 #include <dev/acpica/acpivar.h>
50 #define ACPI_TABLE_END (ACPI_TABLE_MAX + 1)
53 int sig; /* Table signature to match */
66 const struct acpi_q_rule *match;
70 #include "acpi_quirks.h"
72 static int aq_revcmp(int revision, enum ops_t op, int value);
73 static int aq_strcmp(char *actual, char *possible);
74 static int aq_match_header(ACPI_TABLE_HEADER *hdr,
75 const struct acpi_q_rule *match);
78 aq_revcmp(int revision, enum ops_t op, int value)
82 if (revision <= value)
86 if (revision >= value)
90 if (revision == value)
96 panic("aq_revcmp: invalid op %d", op);
103 aq_strcmp(char *actual, char *possible)
105 if (actual == NULL || possible == NULL)
107 return (strncmp(actual, possible, strlen(possible)) == 0);
111 aq_match_header(ACPI_TABLE_HEADER *hdr, const struct acpi_q_rule *match)
116 switch (match->val) {
118 if (aq_strcmp(hdr->OemId, match->x.id) &&
119 aq_strcmp(hdr->OemTableId, match->y.tid))
123 if (aq_strcmp(hdr->AslCompilerId, match->x.id))
127 if (aq_revcmp(hdr->OemRevision, match->x.op, match->y.rev))
131 if (aq_revcmp(hdr->AslCompilerRevision, match->x.op, match->y.rev))
140 acpi_table_quirks(int *quirks)
142 const struct acpi_q_entry *entry;
143 const struct acpi_q_rule *match;
144 ACPI_TABLE_HEADER *hdr;
147 /* First, allow the machdep system to set its idea of quirks. */
148 KASSERT(quirks != NULL, ("acpi quirks ptr is NULL"));
149 acpi_machdep_quirks(quirks);
151 /* Then, override the quirks with any matched from table signatures. */
152 for (entry = acpi_quirks_table; entry->match; entry++) {
154 for (match = entry->match; match->sig != ACPI_TABLE_END; match++) {
155 switch (match->sig) {
156 case ACPI_TABLE_FADT:
157 hdr = (ACPI_TABLE_HEADER *)AcpiGbl_FADT;
159 case ACPI_TABLE_DSDT:
160 hdr = (ACPI_TABLE_HEADER *)AcpiGbl_DSDT;
162 case ACPI_TABLE_XSDT:
163 hdr = (ACPI_TABLE_HEADER *)AcpiGbl_XSDT;
166 panic("invalid quirk header\n");
169 /* If we don't match any, skip to the next entry. */
170 if (!aq_match_header(hdr, match)) {
176 /* If all entries matched, update the quirks and return. */
178 *quirks = entry->quirks;