hwmon: (acpi_power_meter) Fix acpi_bus_get_device() return value check
[linux-drm-fsl-dcu.git] / drivers / acpi / blacklist.c
1 /*
2  *  blacklist.c
3  *
4  *  Check to see if the given machine has a known bad ACPI BIOS
5  *  or if the BIOS is too old.
6  *  Check given machine against acpi_osi_dmi_table[].
7  *
8  *  Copyright (C) 2004 Len Brown <len.brown@intel.com>
9  *  Copyright (C) 2002 Andy Grover <andrew.grover@intel.com>
10  *
11  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12  *
13  *  This program is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU General Public License as published by
15  *  the Free Software Foundation; either version 2 of the License, or (at
16  *  your option) any later version.
17  *
18  *  This program is distributed in the hope that it will be useful, but
19  *  WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  *  General Public License for more details.
22  *
23  *  You should have received a copy of the GNU General Public License along
24  *  with this program; if not, write to the Free Software Foundation, Inc.,
25  *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26  *
27  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28  */
29
30 #include <linux/kernel.h>
31 #include <linux/init.h>
32 #include <linux/acpi.h>
33 #include <acpi/acpi_bus.h>
34 #include <linux/dmi.h>
35
36 #include "internal.h"
37
38 enum acpi_blacklist_predicates {
39         all_versions,
40         less_than_or_equal,
41         equal,
42         greater_than_or_equal,
43 };
44
45 struct acpi_blacklist_item {
46         char oem_id[7];
47         char oem_table_id[9];
48         u32 oem_revision;
49         char *table;
50         enum acpi_blacklist_predicates oem_revision_predicate;
51         char *reason;
52         u32 is_critical_error;
53 };
54
55 static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
56
57 /*
58  * POLICY: If *anything* doesn't work, put it on the blacklist.
59  *         If they are critical errors, mark it critical, and abort driver load.
60  */
61 static struct acpi_blacklist_item acpi_blacklist[] __initdata = {
62         /* Compaq Presario 1700 */
63         {"PTLTD ", "  DSDT  ", 0x06040000, ACPI_SIG_DSDT, less_than_or_equal,
64          "Multiple problems", 1},
65         /* Sony FX120, FX140, FX150? */
66         {"SONY  ", "U0      ", 0x20010313, ACPI_SIG_DSDT, less_than_or_equal,
67          "ACPI driver problem", 1},
68         /* Compaq Presario 800, Insyde BIOS */
69         {"INT440", "SYSFexxx", 0x00001001, ACPI_SIG_DSDT, less_than_or_equal,
70          "Does not use _REG to protect EC OpRegions", 1},
71         /* IBM 600E - _ADR should return 7, but it returns 1 */
72         {"IBM   ", "TP600E  ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal,
73          "Incorrect _ADR", 1},
74
75         {""}
76 };
77
78 #if     CONFIG_ACPI_BLACKLIST_YEAR
79
80 static int __init blacklist_by_year(void)
81 {
82         int year;
83
84         /* Doesn't exist? Likely an old system */
85         if (!dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL)) {
86                 printk(KERN_ERR PREFIX "no DMI BIOS year, "
87                         "acpi=force is required to enable ACPI\n" );
88                 return 1;
89         }
90         /* 0? Likely a buggy new BIOS */
91         if (year == 0) {
92                 printk(KERN_ERR PREFIX "DMI BIOS year==0, "
93                         "assuming ACPI-capable machine\n" );
94                 return 0;
95         }
96         if (year < CONFIG_ACPI_BLACKLIST_YEAR) {
97                 printk(KERN_ERR PREFIX "BIOS age (%d) fails cutoff (%d), "
98                        "acpi=force is required to enable ACPI\n",
99                        year, CONFIG_ACPI_BLACKLIST_YEAR);
100                 return 1;
101         }
102         return 0;
103 }
104 #else
105 static inline int blacklist_by_year(void)
106 {
107         return 0;
108 }
109 #endif
110
111 int __init acpi_blacklisted(void)
112 {
113         int i = 0;
114         int blacklisted = 0;
115         struct acpi_table_header table_header;
116
117         while (acpi_blacklist[i].oem_id[0] != '\0') {
118                 if (acpi_get_table_header(acpi_blacklist[i].table, 0, &table_header)) {
119                         i++;
120                         continue;
121                 }
122
123                 if (strncmp(acpi_blacklist[i].oem_id, table_header.oem_id, 6)) {
124                         i++;
125                         continue;
126                 }
127
128                 if (strncmp
129                     (acpi_blacklist[i].oem_table_id, table_header.oem_table_id,
130                      8)) {
131                         i++;
132                         continue;
133                 }
134
135                 if ((acpi_blacklist[i].oem_revision_predicate == all_versions)
136                     || (acpi_blacklist[i].oem_revision_predicate ==
137                         less_than_or_equal
138                         && table_header.oem_revision <=
139                         acpi_blacklist[i].oem_revision)
140                     || (acpi_blacklist[i].oem_revision_predicate ==
141                         greater_than_or_equal
142                         && table_header.oem_revision >=
143                         acpi_blacklist[i].oem_revision)
144                     || (acpi_blacklist[i].oem_revision_predicate == equal
145                         && table_header.oem_revision ==
146                         acpi_blacklist[i].oem_revision)) {
147
148                         printk(KERN_ERR PREFIX
149                                "Vendor \"%6.6s\" System \"%8.8s\" "
150                                "Revision 0x%x has a known ACPI BIOS problem.\n",
151                                acpi_blacklist[i].oem_id,
152                                acpi_blacklist[i].oem_table_id,
153                                acpi_blacklist[i].oem_revision);
154
155                         printk(KERN_ERR PREFIX
156                                "Reason: %s. This is a %s error\n",
157                                acpi_blacklist[i].reason,
158                                (acpi_blacklist[i].
159                                 is_critical_error ? "non-recoverable" :
160                                 "recoverable"));
161
162                         blacklisted = acpi_blacklist[i].is_critical_error;
163                         break;
164                 } else {
165                         i++;
166                 }
167         }
168
169         blacklisted += blacklist_by_year();
170
171         dmi_check_system(acpi_osi_dmi_table);
172
173         return blacklisted;
174 }
175 #ifdef CONFIG_DMI
176 static int __init dmi_enable_osi_linux(const struct dmi_system_id *d)
177 {
178         acpi_dmi_osi_linux(1, d);       /* enable */
179         return 0;
180 }
181 static int __init dmi_disable_osi_vista(const struct dmi_system_id *d)
182 {
183         printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
184         acpi_osi_setup("!Windows 2006");
185         acpi_osi_setup("!Windows 2006 SP1");
186         acpi_osi_setup("!Windows 2006 SP2");
187         return 0;
188 }
189 static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
190 {
191         printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
192         acpi_osi_setup("!Windows 2009");
193         return 0;
194 }
195 static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
196 {
197         printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
198         acpi_osi_setup("!Windows 2012");
199         return 0;
200 }
201
202 static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
203         {
204         .callback = dmi_disable_osi_vista,
205         .ident = "Fujitsu Siemens",
206         .matches = {
207                      DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
208                      DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Mobile V5505"),
209                 },
210         },
211         {
212         /*
213          * There have a NVIF method in MSI GX723 DSDT need call by Nvidia
214          * driver (e.g. nouveau) when user press brightness hotkey.
215          * Currently, nouveau driver didn't do the job and it causes there
216          * have a infinite while loop in DSDT when user press hotkey.
217          * We add MSI GX723's dmi information to this table for workaround
218          * this issue.
219          * Will remove MSI GX723 from the table after nouveau grows support.
220          */
221         .callback = dmi_disable_osi_vista,
222         .ident = "MSI GX723",
223         .matches = {
224                      DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
225                      DMI_MATCH(DMI_PRODUCT_NAME, "GX723"),
226                 },
227         },
228         {
229         .callback = dmi_disable_osi_vista,
230         .ident = "Sony VGN-NS10J_S",
231         .matches = {
232                      DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
233                      DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NS10J_S"),
234                 },
235         },
236         {
237         .callback = dmi_disable_osi_vista,
238         .ident = "Sony VGN-SR290J",
239         .matches = {
240                      DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
241                      DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR290J"),
242                 },
243         },
244         {
245         .callback = dmi_disable_osi_vista,
246         .ident = "VGN-NS50B_L",
247         .matches = {
248                      DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
249                      DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NS50B_L"),
250                 },
251         },
252         {
253         .callback = dmi_disable_osi_vista,
254         .ident = "Toshiba Satellite L355",
255         .matches = {
256                      DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
257                      DMI_MATCH(DMI_PRODUCT_VERSION, "Satellite L355"),
258                 },
259         },
260         {
261         .callback = dmi_disable_osi_win7,
262         .ident = "ASUS K50IJ",
263         .matches = {
264                      DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
265                      DMI_MATCH(DMI_PRODUCT_NAME, "K50IJ"),
266                 },
267         },
268         {
269         .callback = dmi_disable_osi_vista,
270         .ident = "Toshiba P305D",
271         .matches = {
272                      DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
273                      DMI_MATCH(DMI_PRODUCT_NAME, "Satellite P305D"),
274                 },
275         },
276         {
277         .callback = dmi_disable_osi_vista,
278         .ident = "Toshiba NB100",
279         .matches = {
280                      DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
281                      DMI_MATCH(DMI_PRODUCT_NAME, "NB100"),
282                 },
283         },
284
285         /*
286          * The following machines have broken backlight support when reporting
287          * the Windows 2012 OSI, so disable it until their support is fixed.
288          */
289         {
290         .callback = dmi_disable_osi_win8,
291         .ident = "ASUS Zenbook Prime UX31A",
292         .matches = {
293                      DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
294                      DMI_MATCH(DMI_PRODUCT_NAME, "UX31A"),
295                 },
296         },
297         {
298         .callback = dmi_disable_osi_win8,
299         .ident = "Dell Inspiron 15R SE",
300         .matches = {
301                      DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
302                      DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7520"),
303                 },
304         },
305         {
306         .callback = dmi_disable_osi_win8,
307         .ident = "ThinkPad Edge E530",
308         .matches = {
309                      DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
310                      DMI_MATCH(DMI_PRODUCT_VERSION, "3259A2G"),
311                 },
312         },
313         {
314         .callback = dmi_disable_osi_win8,
315         .ident = "ThinkPad Edge E530",
316         .matches = {
317                      DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
318                      DMI_MATCH(DMI_PRODUCT_VERSION, "3259CTO"),
319                 },
320         },
321         {
322         .callback = dmi_disable_osi_win8,
323         .ident = "ThinkPad Edge E530",
324         .matches = {
325                      DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
326                      DMI_MATCH(DMI_PRODUCT_VERSION, "3259HJG"),
327                 },
328         },
329         {
330         .callback = dmi_disable_osi_win8,
331         .ident = "Acer Aspire V5-573G",
332         .matches = {
333                      DMI_MATCH(DMI_SYS_VENDOR, "Acer Aspire"),
334                      DMI_MATCH(DMI_PRODUCT_VERSION, "V5-573G/Dazzle_HW"),
335                 },
336         },
337         {
338         .callback = dmi_disable_osi_win8,
339         .ident = "Acer Aspire V5-572G",
340         .matches = {
341                      DMI_MATCH(DMI_SYS_VENDOR, "Acer Aspire"),
342                      DMI_MATCH(DMI_PRODUCT_VERSION, "V5-572G/Dazzle_CX"),
343                 },
344         },
345         {
346         .callback = dmi_disable_osi_win8,
347         .ident = "ThinkPad T431s",
348         .matches = {
349                      DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
350                      DMI_MATCH(DMI_PRODUCT_VERSION, "20AACTO1WW"),
351                 },
352         },
353         {
354         .callback = dmi_disable_osi_win8,
355         .ident = "ThinkPad T430",
356         .matches = {
357                      DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
358                      DMI_MATCH(DMI_PRODUCT_VERSION, "2349D15"),
359                 },
360         },
361
362         /*
363          * BIOS invocation of _OSI(Linux) is almost always a BIOS bug.
364          * Linux ignores it, except for the machines enumerated below.
365          */
366
367         /*
368          * Lenovo has a mix of systems OSI(Linux) situations
369          * and thus we can not wildcard the vendor.
370          *
371          * _OSI(Linux) helps sound
372          * DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad R61"),
373          * DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T61"),
374          * T400, T500
375          * _OSI(Linux) has Linux specific hooks
376          * DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X61"),
377          * _OSI(Linux) is a NOP:
378          * DMI_MATCH(DMI_PRODUCT_VERSION, "3000 N100"),
379          * DMI_MATCH(DMI_PRODUCT_VERSION, "LENOVO3000 V100"),
380          */
381         {
382         .callback = dmi_enable_osi_linux,
383         .ident = "Lenovo ThinkPad R61",
384         .matches = {
385                      DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
386                      DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad R61"),
387                 },
388         },
389         {
390         .callback = dmi_enable_osi_linux,
391         .ident = "Lenovo ThinkPad T61",
392         .matches = {
393                      DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
394                      DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T61"),
395                 },
396         },
397         {
398         .callback = dmi_enable_osi_linux,
399         .ident = "Lenovo ThinkPad X61",
400         .matches = {
401                      DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
402                      DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X61"),
403                 },
404         },
405         {
406         .callback = dmi_enable_osi_linux,
407         .ident = "Lenovo ThinkPad T400",
408         .matches = {
409                      DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
410                      DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T400"),
411                 },
412         },
413         {
414         .callback = dmi_enable_osi_linux,
415         .ident = "Lenovo ThinkPad T500",
416         .matches = {
417                      DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
418                      DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T500"),
419                 },
420         },
421         {}
422 };
423
424 #endif /* CONFIG_DMI */