summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-09-05 15:45:03 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-09-05 15:45:03 -0400
commit53ac64aac9af8cd0e5456c8a9bb68c47b571b0a9 (patch)
treea61a7b6dda6a728fd32a2f505010e33b8ae28e65 /drivers
parent439644096c1a6afb9bd9953130f4444a856f76c5 (diff)
parent298bd7fb26cb2797a8b19b66a68389b3f27ae7e2 (diff)
Merge tag 'acpi-4.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull ACPI updates from Rafael Wysocki: "These include a usual ACPICA code update (this time to upstream revision 20170728), a fix for a boot crash on some systems with Thunderbolt devices connected at boot time, a rework of the handling of PCI bridges when setting up device wakeup, new support for Apple device properties, support for DMA configurations reported via ACPI on ARM64, APEI-related updates, ACPI EC driver updates and assorted minor modifications in several places. Specifics: - Update the ACPICA code in the kernel to upstream revision 20170728 including: * Alias operator handling update (Bob Moore). * Deferred resolution of reference package elements (Bob Moore). * Support for the _DMA method in walk resources (Bob Moore). * Tables handling update and support for deferred table verification (Lv Zheng). * Update of SMMU models for IORT (Robin Murphy). * Compiler and disassembler updates (Alex James, Erik Schmauss, Ganapatrao Kulkarni, James Morse). * Tools updates (Erik Schmauss, Lv Zheng). * Assorted minor fixes and cleanups (Bob Moore, Kees Cook, Lv Zheng, Shao Ming). - Rework the initialization of non-wakeup GPEs with method handlers in order to address a boot crash on some systems with Thunderbolt devices connected at boot time where we miss an early hotplug event due to a delay in GPE enabling (Rafael Wysocki). - Rework the handling of PCI bridges when setting up ACPI-based device wakeup in order to avoid disabling wakeup for bridges prematurely (Rafael Wysocki). - Consolidate Apple DMI checks throughout the tree, add support for Apple device properties to the device properties framework and use these properties for the handling of I2C and SPI devices on Apple systems (Lukas Wunner). - Add support for _DMA to the ACPI-based device properties lookup code and make it possible to use the information from there to configure DMA regions on ARM64 systems (Lorenzo Pieralisi). - Fix several issues in the APEI code, add support for exporting the BERT error region over sysfs and update APEI MAINTAINERS entry with reviewers information (Borislav Petkov, Dongjiu Geng, Loc Ho, Punit Agrawal, Tony Luck, Yazen Ghannam). - Fix a potential initialization ordering issue in the ACPI EC driver and clean it up somewhat (Lv Zheng). - Update the ACPI SPCR driver to extend the existing XGENE 8250 workaround in it to a new platform (m400) and to work around an Xgene UART clock issue (Graeme Gregory). - Add a new utility function to the ACPI core to support using ACPI OEM ID / OEM Table ID / Revision for system identification in blacklisting or similar and switch over the existing code already using this information to this new interface (Toshi Kani). - Fix an xpower PMIC issue related to GPADC reads that always return 0 without extra pin manipulations (Hans de Goede). - Add statements to print debug messages in a couple of places in the ACPI core for easier diagnostics (Rafael Wysocki). - Clean up the ACPI processor driver slightly (Colin Ian King, Hanjun Guo). - Clean up the ACPI x86 boot code somewhat (Andy Shevchenko). - Add a quirk for Dell OptiPlex 9020M to the ACPI backlight driver (Alex Hung). - Assorted fixes, cleanups and updates related to ACPI (Amitoj Kaur Chawla, Bhumika Goyal, Frank Rowand, Jean Delvare, Punit Agrawal, Ronald Tschalär, Sumeet Pawnikar)" * tag 'acpi-4.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (75 commits) ACPI / APEI: Suppress message if HEST not present intel_pstate: convert to use acpi_match_platform_list() ACPI / blacklist: add acpi_match_platform_list() ACPI, APEI, EINJ: Subtract any matching Register Region from Trigger resources ACPI: make device_attribute const ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region ACPI: APEI: fix the wrong iteration of generic error status block ACPI / processor: make function acpi_processor_check_duplicates() static ACPI / EC: Clean up EC GPE mask flag ACPI: EC: Fix possible issues related to EC initialization order ACPI / PM: Add debug statements to acpi_pm_notify_handler() ACPI: Add debug statements to acpi_global_event_handler() ACPI / scan: Enable GPEs before scanning the namespace ACPICA: Make it possible to enable runtime GPEs earlier ACPICA: Dispatch active GPEs at init time ACPI: SPCR: work around clock issue on xgene UART ACPI: SPCR: extend XGENE 8250 workaround to m400 ACPI / LPSS: Don't abort ACPI scan on missing mem resource mailbox: pcc: Drop uninformative output during boot ACPI/IORT: Add IORT named component memory address limits ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Makefile1
-rw-r--r--drivers/acpi/acpi_lpat.c6
-rw-r--r--drivers/acpi/acpi_lpss.c3
-rw-r--r--drivers/acpi/acpi_processor.c2
-rw-r--r--drivers/acpi/acpica/Makefile1
-rw-r--r--drivers/acpi/acpica/acapps.h2
-rw-r--r--drivers/acpi/acpica/acdispat.h13
-rw-r--r--drivers/acpi/acpica/aclocal.h7
-rw-r--r--drivers/acpi/acpica/acobject.h15
-rw-r--r--drivers/acpi/acpica/actables.h5
-rw-r--r--drivers/acpi/acpica/acutils.h9
-rw-r--r--drivers/acpi/acpica/dbdisply.c37
-rw-r--r--drivers/acpi/acpica/dsfield.c2
-rw-r--r--drivers/acpi/acpica/dsobject.c398
-rw-r--r--drivers/acpi/acpica/dsopcode.c9
-rw-r--r--drivers/acpi/acpica/dspkginit.c496
-rw-r--r--drivers/acpi/acpica/evgpeblk.c30
-rw-r--r--drivers/acpi/acpica/evxfgpe.c8
-rw-r--r--drivers/acpi/acpica/excreate.c62
-rw-r--r--drivers/acpi/acpica/exdump.c34
-rw-r--r--drivers/acpi/acpica/exmisc.c9
-rw-r--r--drivers/acpi/acpica/exoparg2.c3
-rw-r--r--drivers/acpi/acpica/hwregs.c2
-rw-r--r--drivers/acpi/acpica/hwxfsleep.c9
-rw-r--r--drivers/acpi/acpica/nsaccess.c28
-rw-r--r--drivers/acpi/acpica/nsarguments.c21
-rw-r--r--drivers/acpi/acpica/nsinit.c14
-rw-r--r--drivers/acpi/acpica/nsnames.c9
-rw-r--r--drivers/acpi/acpica/nsprepkg.c2
-rw-r--r--drivers/acpi/acpica/psloop.c14
-rw-r--r--drivers/acpi/acpica/psobject.c26
-rw-r--r--drivers/acpi/acpica/rsxface.c7
-rw-r--r--drivers/acpi/acpica/tbdata.c230
-rw-r--r--drivers/acpi/acpica/tbinstal.c161
-rw-r--r--drivers/acpi/acpica/tbxface.c39
-rw-r--r--drivers/acpi/acpica/tbxfload.c2
-rw-r--r--drivers/acpi/acpica/uthex.c4
-rw-r--r--drivers/acpi/acpica/utmath.c222
-rw-r--r--drivers/acpi/acpica/utmisc.c10
-rw-r--r--drivers/acpi/acpica/utobject.c5
-rw-r--r--drivers/acpi/acpica/utprint.c8
-rw-r--r--drivers/acpi/acpica/utresrc.c7
-rw-r--r--drivers/acpi/acpica/utstate.c2
-rw-r--r--drivers/acpi/acpica/utstrtoul64.c9
-rw-r--r--drivers/acpi/acpica/uttrack.c9
-rw-r--r--drivers/acpi/apei/apei-internal.h5
-rw-r--r--drivers/acpi/apei/einj.c2
-rw-r--r--drivers/acpi/apei/ghes.c10
-rw-r--r--drivers/acpi/apei/hest.c13
-rw-r--r--drivers/acpi/arm64/iort.c57
-rw-r--r--drivers/acpi/battery.c2
-rw-r--r--drivers/acpi/blacklist.c83
-rw-r--r--drivers/acpi/bus.c3
-rw-r--r--drivers/acpi/device_pm.c175
-rw-r--r--drivers/acpi/dock.c2
-rw-r--r--drivers/acpi/ec.c48
-rw-r--r--drivers/acpi/internal.h6
-rw-r--r--drivers/acpi/osi.c37
-rw-r--r--drivers/acpi/pci_root.c4
-rw-r--r--drivers/acpi/pmic/intel_pmic_xpower.c21
-rw-r--r--drivers/acpi/processor_driver.c2
-rw-r--r--drivers/acpi/property.c6
-rw-r--r--drivers/acpi/resource.c82
-rw-r--r--drivers/acpi/sbs.c27
-rw-r--r--drivers/acpi/scan.c104
-rw-r--r--drivers/acpi/sleep.c2
-rw-r--r--drivers/acpi/spcr.c36
-rw-r--r--drivers/acpi/sysfs.c91
-rw-r--r--drivers/acpi/tables.c4
-rw-r--r--drivers/acpi/utils.c36
-rw-r--r--drivers/acpi/video_detect.c14
-rw-r--r--drivers/acpi/x86/apple.c141
-rw-r--r--drivers/cpufreq/intel_pstate.c64
-rw-r--r--drivers/firmware/efi/apple-properties.c5
-rw-r--r--drivers/firmware/efi/cper.c12
-rw-r--r--drivers/mailbox/pcc.c4
-rw-r--r--drivers/pci/pci-acpi.c4
-rw-r--r--drivers/pci/pci-driver.c4
-rw-r--r--drivers/pci/pci.c7
-rw-r--r--drivers/pci/quirks.c5
-rw-r--r--drivers/spi/spi.c32
-rw-r--r--drivers/thunderbolt/icm.c13
-rw-r--r--drivers/thunderbolt/tb.c4
83 files changed, 2193 insertions, 966 deletions
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index b1aacfc62b1f..90265ab4437a 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -50,6 +50,7 @@ acpi-$(CONFIG_ACPI_REDUCED_HARDWARE_ONLY) += evged.o
50acpi-y += sysfs.o 50acpi-y += sysfs.o
51acpi-y += property.o 51acpi-y += property.o
52acpi-$(CONFIG_X86) += acpi_cmos_rtc.o 52acpi-$(CONFIG_X86) += acpi_cmos_rtc.o
53acpi-$(CONFIG_X86) += x86/apple.o
53acpi-$(CONFIG_X86) += x86/utils.o 54acpi-$(CONFIG_X86) += x86/utils.o
54acpi-$(CONFIG_DEBUG_FS) += debugfs.o 55acpi-$(CONFIG_DEBUG_FS) += debugfs.o
55acpi-$(CONFIG_ACPI_NUMA) += numa.o 56acpi-$(CONFIG_ACPI_NUMA) += numa.o
diff --git a/drivers/acpi/acpi_lpat.c b/drivers/acpi/acpi_lpat.c
index c1c4877ca96c..2cd9f738812b 100644
--- a/drivers/acpi/acpi_lpat.c
+++ b/drivers/acpi/acpi_lpat.c
@@ -25,7 +25,7 @@
25 * @raw: the raw value, used as a key to get the temerature from the 25 * @raw: the raw value, used as a key to get the temerature from the
26 * above mapping table 26 * above mapping table
27 * 27 *
28 * A positive converted temperarure value will be returned on success, 28 * A positive converted temperature value will be returned on success,
29 * a negative errno will be returned in error cases. 29 * a negative errno will be returned in error cases.
30 */ 30 */
31int acpi_lpat_raw_to_temp(struct acpi_lpat_conversion_table *lpat_table, 31int acpi_lpat_raw_to_temp(struct acpi_lpat_conversion_table *lpat_table,
@@ -55,11 +55,11 @@ EXPORT_SYMBOL_GPL(acpi_lpat_raw_to_temp);
55 * acpi_lpat_temp_to_raw(): Return raw value from temperature through 55 * acpi_lpat_temp_to_raw(): Return raw value from temperature through
56 * LPAT conversion table 56 * LPAT conversion table
57 * 57 *
58 * @lpat: the temperature_raw mapping table 58 * @lpat_table: the temperature_raw mapping table
59 * @temp: the temperature, used as a key to get the raw value from the 59 * @temp: the temperature, used as a key to get the raw value from the
60 * above mapping table 60 * above mapping table
61 * 61 *
62 * A positive converted temperature value will be returned on success, 62 * The raw value will be returned on success,
63 * a negative errno will be returned in error cases. 63 * a negative errno will be returned in error cases.
64 */ 64 */
65int acpi_lpat_temp_to_raw(struct acpi_lpat_conversion_table *lpat_table, 65int acpi_lpat_temp_to_raw(struct acpi_lpat_conversion_table *lpat_table,
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index f88caf5aab76..032ae44710e5 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -465,7 +465,8 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
465 acpi_dev_free_resource_list(&resource_list); 465 acpi_dev_free_resource_list(&resource_list);
466 466
467 if (!pdata->mmio_base) { 467 if (!pdata->mmio_base) {
468 ret = -ENOMEM; 468 /* Skip the device, but continue the namespace scan. */
469 ret = 0;
469 goto err_out; 470 goto err_out;
470 } 471 }
471 472
diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
index f098e25b6b41..86c10599d9f8 100644
--- a/drivers/acpi/acpi_processor.c
+++ b/drivers/acpi/acpi_processor.c
@@ -670,7 +670,7 @@ err:
670 670
671} 671}
672 672
673void __init acpi_processor_check_duplicates(void) 673static void __init acpi_processor_check_duplicates(void)
674{ 674{
675 /* check the correctness for all processors in ACPI namespace */ 675 /* check the correctness for all processors in ACPI namespace */
676 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, 676 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index b125bdd3d58b..1709551bc4aa 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -18,6 +18,7 @@ acpi-y := \
18 dsmthdat.o \ 18 dsmthdat.o \
19 dsobject.o \ 19 dsobject.o \
20 dsopcode.o \ 20 dsopcode.o \
21 dspkginit.o \
21 dsutils.o \ 22 dsutils.o \
22 dswexec.o \ 23 dswexec.o \
23 dswload.o \ 24 dswload.o \
diff --git a/drivers/acpi/acpica/acapps.h b/drivers/acpi/acpica/acapps.h
index bb6a84b0b4b3..7a1a68b5ac5c 100644
--- a/drivers/acpi/acpica/acapps.h
+++ b/drivers/acpi/acpica/acapps.h
@@ -114,6 +114,8 @@ ac_get_all_tables_from_file(char *filename,
114 u8 get_only_aml_tables, 114 u8 get_only_aml_tables,
115 struct acpi_new_table_desc **return_list_head); 115 struct acpi_new_table_desc **return_list_head);
116 116
117void ac_delete_table_list(struct acpi_new_table_desc *list_head);
118
117u8 ac_is_file_binary(FILE * file); 119u8 ac_is_file_binary(FILE * file);
118 120
119acpi_status ac_validate_table_header(FILE * file, long table_offset); 121acpi_status ac_validate_table_header(FILE * file, long table_offset);
diff --git a/drivers/acpi/acpica/acdispat.h b/drivers/acpi/acpica/acdispat.h
index 0d95c85cce06..f8f3a6e74128 100644
--- a/drivers/acpi/acpica/acdispat.h
+++ b/drivers/acpi/acpica/acdispat.h
@@ -237,6 +237,11 @@ acpi_ds_initialize_objects(u32 table_index,
237 * dsobject - Parser/Interpreter interface - object initialization and conversion 237 * dsobject - Parser/Interpreter interface - object initialization and conversion
238 */ 238 */
239acpi_status 239acpi_status
240acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
241 union acpi_parse_object *op,
242 union acpi_operand_object **obj_desc_ptr);
243
244acpi_status
240acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state, 245acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
241 union acpi_parse_object *op, 246 union acpi_parse_object *op,
242 u32 buffer_length, 247 u32 buffer_length,
@@ -259,6 +264,14 @@ acpi_ds_create_node(struct acpi_walk_state *walk_state,
259 union acpi_parse_object *op); 264 union acpi_parse_object *op);
260 265
261/* 266/*
267 * dspkginit - Package object initialization
268 */
269acpi_status
270acpi_ds_init_package_element(u8 object_type,
271 union acpi_operand_object *source_object,
272 union acpi_generic_state *state, void *context);
273
274/*
262 * dsutils - Parser/Interpreter interface utility routines 275 * dsutils - Parser/Interpreter interface utility routines
263 */ 276 */
264void acpi_ds_clear_implicit_return(struct acpi_walk_state *walk_state); 277void acpi_ds_clear_implicit_return(struct acpi_walk_state *walk_state);
diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h
index 8ddd3b20e0c6..0d45b8bb1678 100644
--- a/drivers/acpi/acpica/aclocal.h
+++ b/drivers/acpi/acpica/aclocal.h
@@ -199,6 +199,7 @@ struct acpi_namespace_node {
199#define ANOBJ_EVALUATED 0x20 /* Set on first evaluation of node */ 199#define ANOBJ_EVALUATED 0x20 /* Set on first evaluation of node */
200#define ANOBJ_ALLOCATED_BUFFER 0x40 /* Method AML buffer is dynamic (install_method) */ 200#define ANOBJ_ALLOCATED_BUFFER 0x40 /* Method AML buffer is dynamic (install_method) */
201 201
202#define IMPLICIT_EXTERNAL 0x02 /* iASL only: This object created implicitly via External */
202#define ANOBJ_IS_EXTERNAL 0x08 /* iASL only: This object created via External() */ 203#define ANOBJ_IS_EXTERNAL 0x08 /* iASL only: This object created via External() */
203#define ANOBJ_METHOD_NO_RETVAL 0x10 /* iASL only: Method has no return value */ 204#define ANOBJ_METHOD_NO_RETVAL 0x10 /* iASL only: Method has no return value */
204#define ANOBJ_METHOD_SOME_NO_RETVAL 0x20 /* iASL only: Method has at least one return value */ 205#define ANOBJ_METHOD_SOME_NO_RETVAL 0x20 /* iASL only: Method has at least one return value */
@@ -604,7 +605,7 @@ struct acpi_update_state {
604 * Pkg state - used to traverse nested package structures 605 * Pkg state - used to traverse nested package structures
605 */ 606 */
606struct acpi_pkg_state { 607struct acpi_pkg_state {
607 ACPI_STATE_COMMON u16 index; 608 ACPI_STATE_COMMON u32 index;
608 union acpi_operand_object *source_object; 609 union acpi_operand_object *source_object;
609 union acpi_operand_object *dest_object; 610 union acpi_operand_object *dest_object;
610 struct acpi_walk_state *walk_state; 611 struct acpi_walk_state *walk_state;
@@ -867,7 +868,7 @@ struct acpi_parse_obj_named {
867 868
868/* This version is used by the iASL compiler only */ 869/* This version is used by the iASL compiler only */
869 870
870#define ACPI_MAX_PARSEOP_NAME 20 871#define ACPI_MAX_PARSEOP_NAME 20
871 872
872struct acpi_parse_obj_asl { 873struct acpi_parse_obj_asl {
873 ACPI_PARSE_COMMON union acpi_parse_object *child; 874 ACPI_PARSE_COMMON union acpi_parse_object *child;
@@ -907,7 +908,7 @@ union acpi_parse_object {
907struct asl_comment_state { 908struct asl_comment_state {
908 u8 comment_type; 909 u8 comment_type;
909 u32 spaces_before; 910 u32 spaces_before;
910 union acpi_parse_object *latest_parse_node; 911 union acpi_parse_object *latest_parse_op;
911 union acpi_parse_object *parsing_paren_brace_node; 912 union acpi_parse_object *parsing_paren_brace_node;
912 u8 capture_comments; 913 u8 capture_comments;
913}; 914};
diff --git a/drivers/acpi/acpica/acobject.h b/drivers/acpi/acpica/acobject.h
index 27c3f982d810..5226146190bf 100644
--- a/drivers/acpi/acpica/acobject.h
+++ b/drivers/acpi/acpica/acobject.h
@@ -122,7 +122,9 @@ struct acpi_object_integer {
122 _type *pointer; \ 122 _type *pointer; \
123 u32 length; 123 u32 length;
124 124
125struct acpi_object_string { /* Null terminated, ASCII characters only */ 125/* Null terminated, ASCII characters only */
126
127struct acpi_object_string {
126 ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_BUFFER_INFO(char) /* String in AML stream or allocated string */ 128 ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_BUFFER_INFO(char) /* String in AML stream or allocated string */
127}; 129};
128 130
@@ -211,7 +213,9 @@ struct acpi_object_method {
211 union acpi_operand_object *notify_list[2]; /* Handlers for system/device notifies */\ 213 union acpi_operand_object *notify_list[2]; /* Handlers for system/device notifies */\
212 union acpi_operand_object *handler; /* Handler for Address space */ 214 union acpi_operand_object *handler; /* Handler for Address space */
213 215
214struct acpi_object_notify_common { /* COMMON NOTIFY for POWER, PROCESSOR, DEVICE, and THERMAL */ 216/* COMMON NOTIFY for POWER, PROCESSOR, DEVICE, and THERMAL */
217
218struct acpi_object_notify_common {
215ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO}; 219ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO};
216 220
217struct acpi_object_device { 221struct acpi_object_device {
@@ -258,7 +262,9 @@ ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO};
258 u8 access_length; /* For serial regions/fields */ 262 u8 access_length; /* For serial regions/fields */
259 263
260 264
261struct acpi_object_field_common { /* COMMON FIELD (for BUFFER, REGION, BANK, and INDEX fields) */ 265/* COMMON FIELD (for BUFFER, REGION, BANK, and INDEX fields) */
266
267struct acpi_object_field_common {
262 ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *region_obj; /* Parent Operation Region object (REGION/BANK fields only) */ 268 ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *region_obj; /* Parent Operation Region object (REGION/BANK fields only) */
263}; 269};
264 270
@@ -333,11 +339,12 @@ struct acpi_object_addr_handler {
333struct acpi_object_reference { 339struct acpi_object_reference {
334 ACPI_OBJECT_COMMON_HEADER u8 class; /* Reference Class */ 340 ACPI_OBJECT_COMMON_HEADER u8 class; /* Reference Class */
335 u8 target_type; /* Used for Index Op */ 341 u8 target_type; /* Used for Index Op */
336 u8 reserved; 342 u8 resolved; /* Reference has been resolved to a value */
337 void *object; /* name_op=>HANDLE to obj, index_op=>union acpi_operand_object */ 343 void *object; /* name_op=>HANDLE to obj, index_op=>union acpi_operand_object */
338 struct acpi_namespace_node *node; /* ref_of or Namepath */ 344 struct acpi_namespace_node *node; /* ref_of or Namepath */
339 union acpi_operand_object **where; /* Target of Index */ 345 union acpi_operand_object **where; /* Target of Index */
340 u8 *index_pointer; /* Used for Buffers and Strings */ 346 u8 *index_pointer; /* Used for Buffers and Strings */
347 u8 *aml; /* Used for deferred resolution of the ref */
341 u32 value; /* Used for Local/Arg/Index/ddb_handle */ 348 u32 value; /* Used for Local/Arg/Index/ddb_handle */
342}; 349};
343 350
diff --git a/drivers/acpi/acpica/actables.h b/drivers/acpi/acpica/actables.h
index c8da453bd960..84a3ceb6e384 100644
--- a/drivers/acpi/acpica/actables.h
+++ b/drivers/acpi/acpica/actables.h
@@ -76,7 +76,8 @@ void acpi_tb_release_temp_table(struct acpi_table_desc *table_desc);
76acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc); 76acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc);
77 77
78acpi_status 78acpi_status
79acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature); 79acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc,
80 char *signature, u32 *table_index);
80 81
81u8 acpi_tb_is_table_loaded(u32 table_index); 82u8 acpi_tb_is_table_loaded(u32 table_index);
82 83
@@ -132,6 +133,8 @@ acpi_tb_install_and_load_table(acpi_physical_address address,
132 133
133acpi_status acpi_tb_unload_table(u32 table_index); 134acpi_status acpi_tb_unload_table(u32 table_index);
134 135
136void acpi_tb_notify_table(u32 event, void *table);
137
135void acpi_tb_terminate(void); 138void acpi_tb_terminate(void);
136 139
137acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index); 140acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index);
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index 2a3cc4296481..745134ade35f 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -516,7 +516,7 @@ union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
516 516
517union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object, 517union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
518 void *external_object, 518 void *external_object,
519 u16 index); 519 u32 index);
520 520
521acpi_status 521acpi_status
522acpi_ut_create_update_state_and_push(union acpi_operand_object *object, 522acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
@@ -538,6 +538,13 @@ acpi_status
538acpi_ut_short_divide(u64 in_dividend, 538acpi_ut_short_divide(u64 in_dividend,
539 u32 divisor, u64 *out_quotient, u32 *out_remainder); 539 u32 divisor, u64 *out_quotient, u32 *out_remainder);
540 540
541acpi_status
542acpi_ut_short_multiply(u64 in_multiplicand, u32 multiplier, u64 *outproduct);
543
544acpi_status acpi_ut_short_shift_left(u64 operand, u32 count, u64 *out_result);
545
546acpi_status acpi_ut_short_shift_right(u64 operand, u32 count, u64 *out_result);
547
541/* 548/*
542 * utmisc 549 * utmisc
543 */ 550 */
diff --git a/drivers/acpi/acpica/dbdisply.c b/drivers/acpi/acpica/dbdisply.c
index 46bf270ac525..5a606eac0c22 100644
--- a/drivers/acpi/acpica/dbdisply.c
+++ b/drivers/acpi/acpica/dbdisply.c
@@ -310,7 +310,7 @@ dump_node:
310 } 310 }
311 311
312 else { 312 else {
313 acpi_os_printf("Object (%p) Pathname: %s\n", 313 acpi_os_printf("Object %p: Namespace Node - Pathname: %s\n",
314 node, (char *)ret_buf.pointer); 314 node, (char *)ret_buf.pointer);
315 } 315 }
316 316
@@ -326,7 +326,7 @@ dump_node:
326 326
327 obj_desc = acpi_ns_get_attached_object(node); 327 obj_desc = acpi_ns_get_attached_object(node);
328 if (obj_desc) { 328 if (obj_desc) {
329 acpi_os_printf("\nAttached Object (%p):\n", obj_desc); 329 acpi_os_printf("\nAttached Object %p:", obj_desc);
330 if (!acpi_os_readable 330 if (!acpi_os_readable
331 (obj_desc, sizeof(union acpi_operand_object))) { 331 (obj_desc, sizeof(union acpi_operand_object))) {
332 acpi_os_printf 332 acpi_os_printf
@@ -335,9 +335,36 @@ dump_node:
335 return; 335 return;
336 } 336 }
337 337
338 acpi_ut_debug_dump_buffer((void *)obj_desc, 338 if (ACPI_GET_DESCRIPTOR_TYPE(((struct acpi_namespace_node *)
339 sizeof(union acpi_operand_object), 339 obj_desc)) ==
340 display, ACPI_UINT32_MAX); 340 ACPI_DESC_TYPE_NAMED) {
341 acpi_os_printf(" Namespace Node - ");
342 status =
343 acpi_get_name((struct acpi_namespace_node *)
344 obj_desc,
345 ACPI_FULL_PATHNAME_NO_TRAILING,
346 &ret_buf);
347 if (ACPI_FAILURE(status)) {
348 acpi_os_printf
349 ("Could not convert name to pathname\n");
350 } else {
351 acpi_os_printf("Pathname: %s",
352 (char *)ret_buf.pointer);
353 }
354
355 acpi_os_printf("\n");
356 acpi_ut_debug_dump_buffer((void *)obj_desc,
357 sizeof(struct
358 acpi_namespace_node),
359 display, ACPI_UINT32_MAX);
360 } else {
361 acpi_os_printf("\n");
362 acpi_ut_debug_dump_buffer((void *)obj_desc,
363 sizeof(union
364 acpi_operand_object),
365 display, ACPI_UINT32_MAX);
366 }
367
341 acpi_ex_dump_object_descriptor(obj_desc, 1); 368 acpi_ex_dump_object_descriptor(obj_desc, 1);
342 } 369 }
343} 370}
diff --git a/drivers/acpi/acpica/dsfield.c b/drivers/acpi/acpica/dsfield.c
index c5dccc54307d..7bcf5f5ea029 100644
--- a/drivers/acpi/acpica/dsfield.c
+++ b/drivers/acpi/acpica/dsfield.c
@@ -184,6 +184,7 @@ acpi_ds_create_buffer_field(union acpi_parse_object *op,
184 /* Execute flag should always be set when this function is entered */ 184 /* Execute flag should always be set when this function is entered */
185 185
186 if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) { 186 if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
187 ACPI_ERROR((AE_INFO, "Parse execute mode is not set"));
187 return_ACPI_STATUS(AE_AML_INTERNAL); 188 return_ACPI_STATUS(AE_AML_INTERNAL);
188 } 189 }
189 190
@@ -556,6 +557,7 @@ acpi_ds_init_field_objects(union acpi_parse_object *op,
556 return_ACPI_STATUS(AE_OK); 557 return_ACPI_STATUS(AE_OK);
557 } 558 }
558 559
560 ACPI_ERROR((AE_INFO, "Parse deferred mode is not set"));
559 return_ACPI_STATUS(AE_AML_INTERNAL); 561 return_ACPI_STATUS(AE_AML_INTERNAL);
560 } 562 }
561 563
diff --git a/drivers/acpi/acpica/dsobject.c b/drivers/acpi/acpica/dsobject.c
index 7df3152ed856..82448551781b 100644
--- a/drivers/acpi/acpica/dsobject.c
+++ b/drivers/acpi/acpica/dsobject.c
@@ -52,12 +52,6 @@
52#define _COMPONENT ACPI_DISPATCHER 52#define _COMPONENT ACPI_DISPATCHER
53ACPI_MODULE_NAME("dsobject") 53ACPI_MODULE_NAME("dsobject")
54 54
55/* Local prototypes */
56static acpi_status
57acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
58 union acpi_parse_object *op,
59 union acpi_operand_object **obj_desc_ptr);
60
61#ifndef ACPI_NO_METHOD_EXECUTION 55#ifndef ACPI_NO_METHOD_EXECUTION
62/******************************************************************************* 56/*******************************************************************************
63 * 57 *
@@ -73,15 +67,13 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
73 * Simple objects are any objects other than a package object! 67 * Simple objects are any objects other than a package object!
74 * 68 *
75 ******************************************************************************/ 69 ******************************************************************************/
76 70acpi_status
77static acpi_status
78acpi_ds_build_internal_object(struct acpi_walk_state *walk_state, 71acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
79 union acpi_parse_object *op, 72 union acpi_parse_object *op,
80 union acpi_operand_object **obj_desc_ptr) 73 union acpi_operand_object **obj_desc_ptr)
81{ 74{
82 union acpi_operand_object *obj_desc; 75 union acpi_operand_object *obj_desc;
83 acpi_status status; 76 acpi_status status;
84 acpi_object_type type;
85 77
86 ACPI_FUNCTION_TRACE(ds_build_internal_object); 78 ACPI_FUNCTION_TRACE(ds_build_internal_object);
87 79
@@ -89,140 +81,47 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
89 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) { 81 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
90 /* 82 /*
91 * This is a named object reference. If this name was 83 * This is a named object reference. If this name was
92 * previously looked up in the namespace, it was stored in this op. 84 * previously looked up in the namespace, it was stored in
93 * Otherwise, go ahead and look it up now 85 * this op. Otherwise, go ahead and look it up now
94 */ 86 */
95 if (!op->common.node) { 87 if (!op->common.node) {
96 status = acpi_ns_lookup(walk_state->scope_info,
97 op->common.value.string,
98 ACPI_TYPE_ANY,
99 ACPI_IMODE_EXECUTE,
100 ACPI_NS_SEARCH_PARENT |
101 ACPI_NS_DONT_OPEN_SCOPE, NULL,
102 ACPI_CAST_INDIRECT_PTR(struct
103 acpi_namespace_node,
104 &(op->
105 common.
106 node)));
107 if (ACPI_FAILURE(status)) {
108
109 /* Check if we are resolving a named reference within a package */
110
111 if ((status == AE_NOT_FOUND)
112 && (acpi_gbl_enable_interpreter_slack)
113 &&
114 ((op->common.parent->common.aml_opcode ==
115 AML_PACKAGE_OP)
116 || (op->common.parent->common.aml_opcode ==
117 AML_VARIABLE_PACKAGE_OP))) {
118 /*
119 * We didn't find the target and we are populating elements
120 * of a package - ignore if slack enabled. Some ASL code
121 * contains dangling invalid references in packages and
122 * expects that no exception will be issued. Leave the
123 * element as a null element. It cannot be used, but it
124 * can be overwritten by subsequent ASL code - this is
125 * typically the case.
126 */
127 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
128 "Ignoring unresolved reference in package [%4.4s]\n",
129 walk_state->
130 scope_info->scope.
131 node->name.ascii));
132
133 return_ACPI_STATUS(AE_OK);
134 } else {
135 ACPI_ERROR_NAMESPACE(op->common.value.
136 string, status);
137 }
138
139 return_ACPI_STATUS(status);
140 }
141 }
142
143 /* Special object resolution for elements of a package */
144
145 if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
146 (op->common.parent->common.aml_opcode ==
147 AML_VARIABLE_PACKAGE_OP)) {
148 /*
149 * Attempt to resolve the node to a value before we insert it into
150 * the package. If this is a reference to a common data type,
151 * resolve it immediately. According to the ACPI spec, package
152 * elements can only be "data objects" or method references.
153 * Attempt to resolve to an Integer, Buffer, String or Package.
154 * If cannot, return the named reference (for things like Devices,
155 * Methods, etc.) Buffer Fields and Fields will resolve to simple
156 * objects (int/buf/str/pkg).
157 *
158 * NOTE: References to things like Devices, Methods, Mutexes, etc.
159 * will remain as named references. This behavior is not described
160 * in the ACPI spec, but it appears to be an oversight.
161 */
162 obj_desc =
163 ACPI_CAST_PTR(union acpi_operand_object,
164 op->common.node);
165
166 status =
167 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
168 (struct
169 acpi_namespace_node,
170 &obj_desc),
171 walk_state);
172 if (ACPI_FAILURE(status)) {
173 return_ACPI_STATUS(status);
174 }
175
176 /*
177 * Special handling for Alias objects. We need to setup the type
178 * and the Op->Common.Node to point to the Alias target. Note,
179 * Alias has at most one level of indirection internally.
180 */
181 type = op->common.node->type;
182 if (type == ACPI_TYPE_LOCAL_ALIAS) {
183 type = obj_desc->common.type;
184 op->common.node =
185 ACPI_CAST_PTR(struct acpi_namespace_node,
186 op->common.node->object);
187 }
188
189 switch (type) {
190 /*
191 * For these types, we need the actual node, not the subobject.
192 * However, the subobject did not get an extra reference count above.
193 *
194 * TBD: should ex_resolve_node_to_value be changed to fix this?
195 */
196 case ACPI_TYPE_DEVICE:
197 case ACPI_TYPE_THERMAL:
198
199 acpi_ut_add_reference(op->common.node->object);
200 88
201 /*lint -fallthrough */ 89 /* Check if we are resolving a named reference within a package */
202 /*
203 * For these types, we need the actual node, not the subobject.
204 * The subobject got an extra reference count in ex_resolve_node_to_value.
205 */
206 case ACPI_TYPE_MUTEX:
207 case ACPI_TYPE_METHOD:
208 case ACPI_TYPE_POWER:
209 case ACPI_TYPE_PROCESSOR:
210 case ACPI_TYPE_EVENT:
211 case ACPI_TYPE_REGION:
212
213 /* We will create a reference object for these types below */
214 break;
215 90
216 default: 91 if ((op->common.parent->common.aml_opcode ==
92 AML_PACKAGE_OP)
93 || (op->common.parent->common.aml_opcode ==
94 AML_VARIABLE_PACKAGE_OP)) {
217 /* 95 /*
218 * All other types - the node was resolved to an actual 96 * We won't resolve package elements here, we will do this
219 * object, we are done. 97 * after all ACPI tables are loaded into the namespace. This
98 * behavior supports both forward references to named objects
99 * and external references to objects in other tables.
220 */ 100 */
221 goto exit; 101 goto create_new_object;
102 } else {
103 status = acpi_ns_lookup(walk_state->scope_info,
104 op->common.value.string,
105 ACPI_TYPE_ANY,
106 ACPI_IMODE_EXECUTE,
107 ACPI_NS_SEARCH_PARENT |
108 ACPI_NS_DONT_OPEN_SCOPE,
109 NULL,
110 ACPI_CAST_INDIRECT_PTR
111 (struct
112 acpi_namespace_node,
113 &(op->common.node)));
114 if (ACPI_FAILURE(status)) {
115 ACPI_ERROR_NAMESPACE(op->common.value.
116 string, status);
117 return_ACPI_STATUS(status);
118 }
222 } 119 }
223 } 120 }
224 } 121 }
225 122
123create_new_object:
124
226 /* Create and init a new internal ACPI object */ 125 /* Create and init a new internal ACPI object */
227 126
228 obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info 127 obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
@@ -240,7 +139,27 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
240 return_ACPI_STATUS(status); 139 return_ACPI_STATUS(status);
241 } 140 }
242 141
243exit: 142 /*
143 * Handling for unresolved package reference elements.
144 * These are elements that are namepaths.
145 */
146 if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
147 (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) {
148 obj_desc->reference.resolved = TRUE;
149
150 if ((op->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
151 !obj_desc->reference.node) {
152 /*
153 * Name was unresolved above.
154 * Get the prefix node for later lookup
155 */
156 obj_desc->reference.node =
157 walk_state->scope_info->scope.node;
158 obj_desc->reference.aml = op->common.aml;
159 obj_desc->reference.resolved = FALSE;
160 }
161 }
162
244 *obj_desc_ptr = obj_desc; 163 *obj_desc_ptr = obj_desc;
245 return_ACPI_STATUS(status); 164 return_ACPI_STATUS(status);
246} 165}
@@ -351,200 +270,6 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
351 270
352/******************************************************************************* 271/*******************************************************************************
353 * 272 *
354 * FUNCTION: acpi_ds_build_internal_package_obj
355 *
356 * PARAMETERS: walk_state - Current walk state
357 * op - Parser object to be translated
358 * element_count - Number of elements in the package - this is
359 * the num_elements argument to Package()
360 * obj_desc_ptr - Where the ACPI internal object is returned
361 *
362 * RETURN: Status
363 *
364 * DESCRIPTION: Translate a parser Op package object to the equivalent
365 * namespace object
366 *
367 * NOTE: The number of elements in the package will be always be the num_elements
368 * count, regardless of the number of elements in the package list. If
369 * num_elements is smaller, only that many package list elements are used.
370 * if num_elements is larger, the Package object is padded out with
371 * objects of type Uninitialized (as per ACPI spec.)
372 *
373 * Even though the ASL compilers do not allow num_elements to be smaller
374 * than the Package list length (for the fixed length package opcode), some
375 * BIOS code modifies the AML on the fly to adjust the num_elements, and
376 * this code compensates for that. This also provides compatibility with
377 * other AML interpreters.
378 *
379 ******************************************************************************/
380
381acpi_status
382acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
383 union acpi_parse_object *op,
384 u32 element_count,
385 union acpi_operand_object **obj_desc_ptr)
386{
387 union acpi_parse_object *arg;
388 union acpi_parse_object *parent;
389 union acpi_operand_object *obj_desc = NULL;
390 acpi_status status = AE_OK;
391 u32 i;
392 u16 index;
393 u16 reference_count;
394
395 ACPI_FUNCTION_TRACE(ds_build_internal_package_obj);
396
397 /* Find the parent of a possibly nested package */
398
399 parent = op->common.parent;
400 while ((parent->common.aml_opcode == AML_PACKAGE_OP) ||
401 (parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) {
402 parent = parent->common.parent;
403 }
404
405 /*
406 * If we are evaluating a Named package object "Name (xxxx, Package)",
407 * the package object already exists, otherwise it must be created.
408 */
409 obj_desc = *obj_desc_ptr;
410 if (!obj_desc) {
411 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE);
412 *obj_desc_ptr = obj_desc;
413 if (!obj_desc) {
414 return_ACPI_STATUS(AE_NO_MEMORY);
415 }
416
417 obj_desc->package.node = parent->common.node;
418 }
419
420 /*
421 * Allocate the element array (array of pointers to the individual
422 * objects) based on the num_elements parameter. Add an extra pointer slot
423 * so that the list is always null terminated.
424 */
425 obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
426 element_count +
427 1) * sizeof(void *));
428
429 if (!obj_desc->package.elements) {
430 acpi_ut_delete_object_desc(obj_desc);
431 return_ACPI_STATUS(AE_NO_MEMORY);
432 }
433
434 obj_desc->package.count = element_count;
435
436 /*
437 * Initialize the elements of the package, up to the num_elements count.
438 * Package is automatically padded with uninitialized (NULL) elements
439 * if num_elements is greater than the package list length. Likewise,
440 * Package is truncated if num_elements is less than the list length.
441 */
442 arg = op->common.value.arg;
443 arg = arg->common.next;
444 for (i = 0; arg && (i < element_count); i++) {
445 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
446 if (arg->common.node->type == ACPI_TYPE_METHOD) {
447 /*
448 * A method reference "looks" to the parser to be a method
449 * invocation, so we special case it here
450 */
451 arg->common.aml_opcode = AML_INT_NAMEPATH_OP;
452 status =
453 acpi_ds_build_internal_object(walk_state,
454 arg,
455 &obj_desc->
456 package.
457 elements[i]);
458 } else {
459 /* This package element is already built, just get it */
460
461 obj_desc->package.elements[i] =
462 ACPI_CAST_PTR(union acpi_operand_object,
463 arg->common.node);
464 }
465 } else {
466 status =
467 acpi_ds_build_internal_object(walk_state, arg,
468 &obj_desc->package.
469 elements[i]);
470 }
471
472 if (*obj_desc_ptr) {
473
474 /* Existing package, get existing reference count */
475
476 reference_count =
477 (*obj_desc_ptr)->common.reference_count;
478 if (reference_count > 1) {
479
480 /* Make new element ref count match original ref count */
481
482 for (index = 0; index < (reference_count - 1);
483 index++) {
484 acpi_ut_add_reference((obj_desc->
485 package.
486 elements[i]));
487 }
488 }
489 }
490
491 arg = arg->common.next;
492 }
493
494 /* Check for match between num_elements and actual length of package_list */
495
496 if (arg) {
497 /*
498 * num_elements was exhausted, but there are remaining elements in the
499 * package_list. Truncate the package to num_elements.
500 *
501 * Note: technically, this is an error, from ACPI spec: "It is an error
502 * for NumElements to be less than the number of elements in the
503 * PackageList". However, we just print a message and
504 * no exception is returned. This provides Windows compatibility. Some
505 * BIOSs will alter the num_elements on the fly, creating this type
506 * of ill-formed package object.
507 */
508 while (arg) {
509 /*
510 * We must delete any package elements that were created earlier
511 * and are not going to be used because of the package truncation.
512 */
513 if (arg->common.node) {
514 acpi_ut_remove_reference(ACPI_CAST_PTR
515 (union
516 acpi_operand_object,
517 arg->common.node));
518 arg->common.node = NULL;
519 }
520
521 /* Find out how many elements there really are */
522
523 i++;
524 arg = arg->common.next;
525 }
526
527 ACPI_INFO(("Actual Package length (%u) is larger than "
528 "NumElements field (%u), truncated",
529 i, element_count));
530 } else if (i < element_count) {
531 /*
532 * Arg list (elements) was exhausted, but we did not reach num_elements count.
533 * Note: this is not an error, the package is padded out with NULLs.
534 */
535 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
536 "Package List length (%u) smaller than NumElements "
537 "count (%u), padded with null elements\n",
538 i, element_count));
539 }
540
541 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
542 op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
543 return_ACPI_STATUS(status);
544}
545
546/*******************************************************************************
547 *
548 * FUNCTION: acpi_ds_create_node 273 * FUNCTION: acpi_ds_create_node
549 * 274 *
550 * PARAMETERS: walk_state - Current walk state 275 * PARAMETERS: walk_state - Current walk state
@@ -662,11 +387,20 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
662 387
663 case ACPI_TYPE_PACKAGE: 388 case ACPI_TYPE_PACKAGE:
664 /* 389 /*
665 * Defer evaluation of Package term_arg operand 390 * Defer evaluation of Package term_arg operand and all
391 * package elements. (01/2017): We defer the element
392 * resolution to allow forward references from the package
393 * in order to provide compatibility with other ACPI
394 * implementations.
666 */ 395 */
667 obj_desc->package.node = 396 obj_desc->package.node =
668 ACPI_CAST_PTR(struct acpi_namespace_node, 397 ACPI_CAST_PTR(struct acpi_namespace_node,
669 walk_state->operands[0]); 398 walk_state->operands[0]);
399
400 if (!op->named.data) {
401 return_ACPI_STATUS(AE_OK);
402 }
403
670 obj_desc->package.aml_start = op->named.data; 404 obj_desc->package.aml_start = op->named.data;
671 obj_desc->package.aml_length = op->named.length; 405 obj_desc->package.aml_length = op->named.length;
672 break; 406 break;
@@ -818,9 +552,11 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
818 /* Node was saved in Op */ 552 /* Node was saved in Op */
819 553
820 obj_desc->reference.node = op->common.node; 554 obj_desc->reference.node = op->common.node;
821 obj_desc->reference.object =
822 op->common.node->object;
823 obj_desc->reference.class = ACPI_REFCLASS_NAME; 555 obj_desc->reference.class = ACPI_REFCLASS_NAME;
556 if (op->common.node) {
557 obj_desc->reference.object =
558 op->common.node->object;
559 }
824 break; 560 break;
825 561
826 case AML_DEBUG_OP: 562 case AML_DEBUG_OP:
diff --git a/drivers/acpi/acpica/dsopcode.c b/drivers/acpi/acpica/dsopcode.c
index dfc3c25a083d..0336df7ac47d 100644
--- a/drivers/acpi/acpica/dsopcode.c
+++ b/drivers/acpi/acpica/dsopcode.c
@@ -599,6 +599,15 @@ acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
599 */ 599 */
600 walk_state->operand_index = walk_state->num_operands; 600 walk_state->operand_index = walk_state->num_operands;
601 601
602 /* Ignore if child is not valid */
603
604 if (!op->common.value.arg) {
605 ACPI_ERROR((AE_INFO,
606 "Dispatch: Missing child while executing TermArg for %X",
607 op->common.aml_opcode));
608 return_ACPI_STATUS(AE_OK);
609 }
610
602 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1); 611 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
603 if (ACPI_FAILURE(status)) { 612 if (ACPI_FAILURE(status)) {
604 return_ACPI_STATUS(status); 613 return_ACPI_STATUS(status);
diff --git a/drivers/acpi/acpica/dspkginit.c b/drivers/acpi/acpica/dspkginit.c
new file mode 100644
index 000000000000..6d487edfe2de
--- /dev/null
+++ b/drivers/acpi/acpica/dspkginit.c
@@ -0,0 +1,496 @@
1/******************************************************************************
2 *
3 * Module Name: dspkginit - Completion of deferred package initialization
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2017, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "acnamesp.h"
47#include "amlcode.h"
48#include "acdispat.h"
49#include "acinterp.h"
50
51#define _COMPONENT ACPI_NAMESPACE
52ACPI_MODULE_NAME("dspkginit")
53
54/* Local prototypes */
55static void
56acpi_ds_resolve_package_element(union acpi_operand_object **element);
57
58/*******************************************************************************
59 *
60 * FUNCTION: acpi_ds_build_internal_package_obj
61 *
62 * PARAMETERS: walk_state - Current walk state
63 * op - Parser object to be translated
64 * element_count - Number of elements in the package - this is
65 * the num_elements argument to Package()
66 * obj_desc_ptr - Where the ACPI internal object is returned
67 *
68 * RETURN: Status
69 *
70 * DESCRIPTION: Translate a parser Op package object to the equivalent
71 * namespace object
72 *
73 * NOTE: The number of elements in the package will be always be the num_elements
74 * count, regardless of the number of elements in the package list. If
75 * num_elements is smaller, only that many package list elements are used.
76 * if num_elements is larger, the Package object is padded out with
77 * objects of type Uninitialized (as per ACPI spec.)
78 *
79 * Even though the ASL compilers do not allow num_elements to be smaller
80 * than the Package list length (for the fixed length package opcode), some
81 * BIOS code modifies the AML on the fly to adjust the num_elements, and
82 * this code compensates for that. This also provides compatibility with
83 * other AML interpreters.
84 *
85 ******************************************************************************/
86
87acpi_status
88acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
89 union acpi_parse_object *op,
90 u32 element_count,
91 union acpi_operand_object **obj_desc_ptr)
92{
93 union acpi_parse_object *arg;
94 union acpi_parse_object *parent;
95 union acpi_operand_object *obj_desc = NULL;
96 acpi_status status = AE_OK;
97 u16 reference_count;
98 u32 index;
99 u32 i;
100
101 ACPI_FUNCTION_TRACE(ds_build_internal_package_obj);
102
103 /* Find the parent of a possibly nested package */
104
105 parent = op->common.parent;
106 while ((parent->common.aml_opcode == AML_PACKAGE_OP) ||
107 (parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) {
108 parent = parent->common.parent;
109 }
110
111 /*
112 * If we are evaluating a Named package object of the form:
113 * Name (xxxx, Package)
114 * the package object already exists, otherwise it must be created.
115 */
116 obj_desc = *obj_desc_ptr;
117 if (!obj_desc) {
118 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE);
119 *obj_desc_ptr = obj_desc;
120 if (!obj_desc) {
121 return_ACPI_STATUS(AE_NO_MEMORY);
122 }
123
124 obj_desc->package.node = parent->common.node;
125 }
126
127 if (obj_desc->package.flags & AOPOBJ_DATA_VALID) { /* Just in case */
128 return_ACPI_STATUS(AE_OK);
129 }
130
131 /*
132 * Allocate the element array (array of pointers to the individual
133 * objects) based on the num_elements parameter. Add an extra pointer slot
134 * so that the list is always null terminated.
135 */
136 obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
137 element_count +
138 1) * sizeof(void *));
139
140 if (!obj_desc->package.elements) {
141 acpi_ut_delete_object_desc(obj_desc);
142 return_ACPI_STATUS(AE_NO_MEMORY);
143 }
144
145 obj_desc->package.count = element_count;
146 arg = op->common.value.arg;
147 arg = arg->common.next;
148
149 if (arg) {
150 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
151 }
152
153 /*
154 * Initialize the elements of the package, up to the num_elements count.
155 * Package is automatically padded with uninitialized (NULL) elements
156 * if num_elements is greater than the package list length. Likewise,
157 * Package is truncated if num_elements is less than the list length.
158 */
159 for (i = 0; arg && (i < element_count); i++) {
160 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
161 if (arg->common.node->type == ACPI_TYPE_METHOD) {
162 /*
163 * A method reference "looks" to the parser to be a method
164 * invocation, so we special case it here
165 */
166 arg->common.aml_opcode = AML_INT_NAMEPATH_OP;
167 status =
168 acpi_ds_build_internal_object(walk_state,
169 arg,
170 &obj_desc->
171 package.
172 elements[i]);
173 } else {
174 /* This package element is already built, just get it */
175
176 obj_desc->package.elements[i] =
177 ACPI_CAST_PTR(union acpi_operand_object,
178 arg->common.node);
179 }
180 } else {
181 status =
182 acpi_ds_build_internal_object(walk_state, arg,
183 &obj_desc->package.
184 elements[i]);
185 if (status == AE_NOT_FOUND) {
186 ACPI_ERROR((AE_INFO, "%-48s",
187 "****DS namepath not found"));
188 }
189
190 /*
191 * Initialize this package element. This function handles the
192 * resolution of named references within the package.
193 */
194 acpi_ds_init_package_element(0,
195 obj_desc->package.
196 elements[i], NULL,
197 &obj_desc->package.
198 elements[i]);
199 }
200
201 if (*obj_desc_ptr) {
202
203 /* Existing package, get existing reference count */
204
205 reference_count =
206 (*obj_desc_ptr)->common.reference_count;
207 if (reference_count > 1) {
208
209 /* Make new element ref count match original ref count */
210 /* TBD: Probably need an acpi_ut_add_references function */
211
212 for (index = 0;
213 index < ((u32)reference_count - 1);
214 index++) {
215 acpi_ut_add_reference((obj_desc->
216 package.
217 elements[i]));
218 }
219 }
220 }
221
222 arg = arg->common.next;
223 }
224
225 /* Check for match between num_elements and actual length of package_list */
226
227 if (arg) {
228 /*
229 * num_elements was exhausted, but there are remaining elements in
230 * the package_list. Truncate the package to num_elements.
231 *
232 * Note: technically, this is an error, from ACPI spec: "It is an
233 * error for NumElements to be less than the number of elements in
234 * the PackageList". However, we just print a message and no
235 * exception is returned. This provides compatibility with other
236 * ACPI implementations. Some firmware implementations will alter
237 * the num_elements on the fly, possibly creating this type of
238 * ill-formed package object.
239 */
240 while (arg) {
241 /*
242 * We must delete any package elements that were created earlier
243 * and are not going to be used because of the package truncation.
244 */
245 if (arg->common.node) {
246 acpi_ut_remove_reference(ACPI_CAST_PTR
247 (union
248 acpi_operand_object,
249 arg->common.node));
250 arg->common.node = NULL;
251 }
252
253 /* Find out how many elements there really are */
254
255 i++;
256 arg = arg->common.next;
257 }
258
259 ACPI_INFO(("Actual Package length (%u) is larger than "
260 "NumElements field (%u), truncated",
261 i, element_count));
262 } else if (i < element_count) {
263 /*
264 * Arg list (elements) was exhausted, but we did not reach
265 * num_elements count.
266 *
267 * Note: this is not an error, the package is padded out
268 * with NULLs.
269 */
270 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
271 "Package List length (%u) smaller than NumElements "
272 "count (%u), padded with null elements\n",
273 i, element_count));
274 }
275
276 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
277 op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
278 return_ACPI_STATUS(status);
279}
280
281/*******************************************************************************
282 *
283 * FUNCTION: acpi_ds_init_package_element
284 *
285 * PARAMETERS: acpi_pkg_callback
286 *
287 * RETURN: Status
288 *
289 * DESCRIPTION: Resolve a named reference element within a package object
290 *
291 ******************************************************************************/
292
293acpi_status
294acpi_ds_init_package_element(u8 object_type,
295 union acpi_operand_object *source_object,
296 union acpi_generic_state *state, void *context)
297{
298 union acpi_operand_object **element_ptr;
299
300 if (!source_object) {
301 return (AE_OK);
302 }
303
304 /*
305 * The following code is a bit of a hack to workaround a (current)
306 * limitation of the acpi_pkg_callback interface. We need a pointer
307 * to the location within the element array because a new object
308 * may be created and stored there.
309 */
310 if (context) {
311
312 /* A direct call was made to this function */
313
314 element_ptr = (union acpi_operand_object **)context;
315 } else {
316 /* Call came from acpi_ut_walk_package_tree */
317
318 element_ptr = state->pkg.this_target_obj;
319 }
320
321 /* We are only interested in reference objects/elements */
322
323 if (source_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
324
325 /* Attempt to resolve the (named) reference to a namespace node */
326
327 acpi_ds_resolve_package_element(element_ptr);
328 } else if (source_object->common.type == ACPI_TYPE_PACKAGE) {
329 source_object->package.flags |= AOPOBJ_DATA_VALID;
330 }
331
332 return (AE_OK);
333}
334
335/*******************************************************************************
336 *
337 * FUNCTION: acpi_ds_resolve_package_element
338 *
339 * PARAMETERS: element_ptr - Pointer to a reference object
340 *
341 * RETURN: Possible new element is stored to the indirect element_ptr
342 *
343 * DESCRIPTION: Resolve a package element that is a reference to a named
344 * object.
345 *
346 ******************************************************************************/
347
348static void
349acpi_ds_resolve_package_element(union acpi_operand_object **element_ptr)
350{
351 acpi_status status;
352 union acpi_generic_state scope_info;
353 union acpi_operand_object *element = *element_ptr;
354 struct acpi_namespace_node *resolved_node;
355 char *external_path = NULL;
356 acpi_object_type type;
357
358 ACPI_FUNCTION_TRACE(ds_resolve_package_element);
359
360 /* Check if reference element is already resolved */
361
362 if (element->reference.resolved) {
363 return_VOID;
364 }
365
366 /* Element must be a reference object of correct type */
367
368 scope_info.scope.node = element->reference.node; /* Prefix node */
369
370 status = acpi_ns_lookup(&scope_info, (char *)element->reference.aml, /* Pointer to AML path */
371 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
372 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
373 NULL, &resolved_node);
374 if (ACPI_FAILURE(status)) {
375 status = acpi_ns_externalize_name(ACPI_UINT32_MAX,
376 (char *)element->reference.
377 aml, NULL, &external_path);
378
379 ACPI_EXCEPTION((AE_INFO, status,
380 "Could not find/resolve named package element: %s",
381 external_path));
382
383 ACPI_FREE(external_path);
384 *element_ptr = NULL;
385 return_VOID;
386 } else if (resolved_node->type == ACPI_TYPE_ANY) {
387
388 /* Named reference not resolved, return a NULL package element */
389
390 ACPI_ERROR((AE_INFO,
391 "Could not resolve named package element [%4.4s] in [%4.4s]",
392 resolved_node->name.ascii,
393 scope_info.scope.node->name.ascii));
394 *element_ptr = NULL;
395 return_VOID;
396 }
397#if 0
398 else if (resolved_node->flags & ANOBJ_TEMPORARY) {
399 /*
400 * A temporary node found here indicates that the reference is
401 * to a node that was created within this method. We are not
402 * going to allow it (especially if the package is returned
403 * from the method) -- the temporary node will be deleted out
404 * from under the method. (05/2017).
405 */
406 ACPI_ERROR((AE_INFO,
407 "Package element refers to a temporary name [%4.4s], "
408 "inserting a NULL element",
409 resolved_node->name.ascii));
410 *element_ptr = NULL;
411 return_VOID;
412 }
413#endif
414
415 /*
416 * Special handling for Alias objects. We need resolved_node to point
417 * to the Alias target. This effectively "resolves" the alias.
418 */
419 if (resolved_node->type == ACPI_TYPE_LOCAL_ALIAS) {
420 resolved_node = ACPI_CAST_PTR(struct acpi_namespace_node,
421 resolved_node->object);
422 }
423
424 /* Update the reference object */
425
426 element->reference.resolved = TRUE;
427 element->reference.node = resolved_node;
428 type = element->reference.node->type;
429
430 /*
431 * Attempt to resolve the node to a value before we insert it into
432 * the package. If this is a reference to a common data type,
433 * resolve it immediately. According to the ACPI spec, package
434 * elements can only be "data objects" or method references.
435 * Attempt to resolve to an Integer, Buffer, String or Package.
436 * If cannot, return the named reference (for things like Devices,
437 * Methods, etc.) Buffer Fields and Fields will resolve to simple
438 * objects (int/buf/str/pkg).
439 *
440 * NOTE: References to things like Devices, Methods, Mutexes, etc.
441 * will remain as named references. This behavior is not described
442 * in the ACPI spec, but it appears to be an oversight.
443 */
444 status = acpi_ex_resolve_node_to_value(&resolved_node, NULL);
445 if (ACPI_FAILURE(status)) {
446 return_VOID;
447 }
448#if 0
449/* TBD - alias support */
450 /*
451 * Special handling for Alias objects. We need to setup the type
452 * and the Op->Common.Node to point to the Alias target. Note,
453 * Alias has at most one level of indirection internally.
454 */
455 type = op->common.node->type;
456 if (type == ACPI_TYPE_LOCAL_ALIAS) {
457 type = obj_desc->common.type;
458 op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node,
459 op->common.node->object);
460 }
461#endif
462
463 switch (type) {
464 /*
465 * These object types are a result of named references, so we will
466 * leave them as reference objects. In other words, these types
467 * have no intrinsic "value".
468 */
469 case ACPI_TYPE_DEVICE:
470 case ACPI_TYPE_THERMAL:
471
472 /* TBD: This may not be necesssary */
473
474 acpi_ut_add_reference(resolved_node->object);
475 break;
476
477 case ACPI_TYPE_MUTEX:
478 case ACPI_TYPE_METHOD:
479 case ACPI_TYPE_POWER:
480 case ACPI_TYPE_PROCESSOR:
481 case ACPI_TYPE_EVENT:
482 case ACPI_TYPE_REGION:
483
484 break;
485
486 default:
487 /*
488 * For all other types - the node was resolved to an actual
489 * operand object with a value, return the object
490 */
491 *element_ptr = (union acpi_operand_object *)resolved_node;
492 break;
493 }
494
495 return_VOID;
496}
diff --git a/drivers/acpi/acpica/evgpeblk.c b/drivers/acpi/acpica/evgpeblk.c
index 9c941947a063..3a3cb8624f41 100644
--- a/drivers/acpi/acpica/evgpeblk.c
+++ b/drivers/acpi/acpica/evgpeblk.c
@@ -440,9 +440,11 @@ acpi_ev_initialize_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
440 void *ignored) 440 void *ignored)
441{ 441{
442 acpi_status status; 442 acpi_status status;
443 acpi_event_status event_status;
443 struct acpi_gpe_event_info *gpe_event_info; 444 struct acpi_gpe_event_info *gpe_event_info;
444 u32 gpe_enabled_count; 445 u32 gpe_enabled_count;
445 u32 gpe_index; 446 u32 gpe_index;
447 u32 gpe_number;
446 u32 i; 448 u32 i;
447 u32 j; 449 u32 j;
448 450
@@ -470,30 +472,40 @@ acpi_ev_initialize_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
470 472
471 gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j; 473 gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j;
472 gpe_event_info = &gpe_block->event_info[gpe_index]; 474 gpe_event_info = &gpe_block->event_info[gpe_index];
475 gpe_number = gpe_block->block_base_number + gpe_index;
473 476
474 /* 477 /*
475 * Ignore GPEs that have no corresponding _Lxx/_Exx method 478 * Ignore GPEs that have no corresponding _Lxx/_Exx method
476 * and GPEs that are used to wake the system 479 * and GPEs that are used for wakeup
477 */ 480 */
478 if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) == 481 if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) !=
479 ACPI_GPE_DISPATCH_NONE) 482 ACPI_GPE_DISPATCH_METHOD)
480 || (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
481 ACPI_GPE_DISPATCH_HANDLER)
482 || (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
483 ACPI_GPE_DISPATCH_RAW_HANDLER)
484 || (gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) { 483 || (gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
485 continue; 484 continue;
486 } 485 }
487 486
487 event_status = 0;
488 (void)acpi_hw_get_gpe_status(gpe_event_info,
489 &event_status);
490
488 status = acpi_ev_add_gpe_reference(gpe_event_info); 491 status = acpi_ev_add_gpe_reference(gpe_event_info);
489 if (ACPI_FAILURE(status)) { 492 if (ACPI_FAILURE(status)) {
490 ACPI_EXCEPTION((AE_INFO, status, 493 ACPI_EXCEPTION((AE_INFO, status,
491 "Could not enable GPE 0x%02X", 494 "Could not enable GPE 0x%02X",
492 gpe_index + 495 gpe_number));
493 gpe_block->block_base_number));
494 continue; 496 continue;
495 } 497 }
496 498
499 gpe_event_info->flags |= ACPI_GPE_AUTO_ENABLED;
500
501 if (event_status & ACPI_EVENT_FLAG_STATUS_SET) {
502 ACPI_INFO(("GPE 0x%02X active on init",
503 gpe_number));
504 (void)acpi_ev_gpe_dispatch(gpe_block->node,
505 gpe_event_info,
506 gpe_number);
507 }
508
497 gpe_enabled_count++; 509 gpe_enabled_count++;
498 } 510 }
499 } 511 }
diff --git a/drivers/acpi/acpica/evxfgpe.c b/drivers/acpi/acpica/evxfgpe.c
index 57718a3e029a..67c7c4ce276c 100644
--- a/drivers/acpi/acpica/evxfgpe.c
+++ b/drivers/acpi/acpica/evxfgpe.c
@@ -435,6 +435,14 @@ acpi_setup_gpe_for_wake(acpi_handle wake_device,
435 */ 435 */
436 gpe_event_info->flags = 436 gpe_event_info->flags =
437 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED); 437 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
438 } else if (gpe_event_info->flags & ACPI_GPE_AUTO_ENABLED) {
439 /*
440 * A reference to this GPE has been added during the GPE block
441 * initialization, so drop it now to prevent the GPE from being
442 * permanently enabled and clear its ACPI_GPE_AUTO_ENABLED flag.
443 */
444 (void)acpi_ev_remove_gpe_reference(gpe_event_info);
445 gpe_event_info->flags &= ~ACPI_GPE_AUTO_ENABLED;
438 } 446 }
439 447
440 /* 448 /*
diff --git a/drivers/acpi/acpica/excreate.c b/drivers/acpi/acpica/excreate.c
index d43d7da4c734..b8adb11f1b07 100644
--- a/drivers/acpi/acpica/excreate.c
+++ b/drivers/acpi/acpica/excreate.c
@@ -87,68 +87,40 @@ acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
87 target_node->object); 87 target_node->object);
88 } 88 }
89 89
90 /* 90 /* Ensure that the target node is valid */
91 * For objects that can never change (i.e., the NS node will
92 * permanently point to the same object), we can simply attach
93 * the object to the new NS node. For other objects (such as
94 * Integers, buffers, etc.), we have to point the Alias node
95 * to the original Node.
96 */
97 switch (target_node->type) {
98 91
99 /* For these types, the sub-object can change dynamically via a Store */ 92 if (!target_node) {
93 return_ACPI_STATUS(AE_NULL_OBJECT);
94 }
100 95
101 case ACPI_TYPE_INTEGER: 96 /* Construct the alias object (a namespace node) */
102 case ACPI_TYPE_STRING:
103 case ACPI_TYPE_BUFFER:
104 case ACPI_TYPE_PACKAGE:
105 case ACPI_TYPE_BUFFER_FIELD:
106 /*
107 * These types open a new scope, so we need the NS node in order to access
108 * any children.
109 */
110 case ACPI_TYPE_DEVICE:
111 case ACPI_TYPE_POWER:
112 case ACPI_TYPE_PROCESSOR:
113 case ACPI_TYPE_THERMAL:
114 case ACPI_TYPE_LOCAL_SCOPE:
115 /*
116 * The new alias has the type ALIAS and points to the original
117 * NS node, not the object itself.
118 */
119 alias_node->type = ACPI_TYPE_LOCAL_ALIAS;
120 alias_node->object =
121 ACPI_CAST_PTR(union acpi_operand_object, target_node);
122 break;
123 97
98 switch (target_node->type) {
124 case ACPI_TYPE_METHOD: 99 case ACPI_TYPE_METHOD:
125 /* 100 /*
126 * Control method aliases need to be differentiated 101 * Control method aliases need to be differentiated with
102 * a special type
127 */ 103 */
128 alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS; 104 alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
129 alias_node->object =
130 ACPI_CAST_PTR(union acpi_operand_object, target_node);
131 break; 105 break;
132 106
133 default: 107 default:
134
135 /* Attach the original source object to the new Alias Node */
136
137 /* 108 /*
138 * The new alias assumes the type of the target, and it points 109 * All other object types.
139 * to the same object. The reference count of the object has an 110 *
140 * additional reference to prevent deletion out from under either the 111 * The new alias has the type ALIAS and points to the original
141 * target node or the alias Node 112 * NS node, not the object itself.
142 */ 113 */
143 status = acpi_ns_attach_object(alias_node, 114 alias_node->type = ACPI_TYPE_LOCAL_ALIAS;
144 acpi_ns_get_attached_object 115 alias_node->object =
145 (target_node), 116 ACPI_CAST_PTR(union acpi_operand_object, target_node);
146 target_node->type);
147 break; 117 break;
148 } 118 }
149 119
150 /* Since both operands are Nodes, we don't need to delete them */ 120 /* Since both operands are Nodes, we don't need to delete them */
151 121
122 alias_node->object =
123 ACPI_CAST_PTR(union acpi_operand_object, target_node);
152 return_ACPI_STATUS(status); 124 return_ACPI_STATUS(status);
153} 125}
154 126
diff --git a/drivers/acpi/acpica/exdump.c b/drivers/acpi/acpica/exdump.c
index 44092f744477..83398dc4b7c2 100644
--- a/drivers/acpi/acpica/exdump.c
+++ b/drivers/acpi/acpica/exdump.c
@@ -102,7 +102,7 @@ static struct acpi_exdump_info acpi_ex_dump_package[6] = {
102 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_package), NULL}, 102 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_package), NULL},
103 {ACPI_EXD_NODE, ACPI_EXD_OFFSET(package.node), "Parent Node"}, 103 {ACPI_EXD_NODE, ACPI_EXD_OFFSET(package.node), "Parent Node"},
104 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(package.flags), "Flags"}, 104 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(package.flags), "Flags"},
105 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(package.count), "Elements"}, 105 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(package.count), "Element Count"},
106 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(package.elements), "Element List"}, 106 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(package.elements), "Element List"},
107 {ACPI_EXD_PACKAGE, 0, NULL} 107 {ACPI_EXD_PACKAGE, 0, NULL}
108}; 108};
@@ -384,6 +384,10 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc,
384 count = info->offset; 384 count = info->offset;
385 385
386 while (count) { 386 while (count) {
387 if (!obj_desc) {
388 return;
389 }
390
387 target = ACPI_ADD_PTR(u8, obj_desc, info->offset); 391 target = ACPI_ADD_PTR(u8, obj_desc, info->offset);
388 name = info->name; 392 name = info->name;
389 393
@@ -469,9 +473,9 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc,
469 start = *ACPI_CAST_PTR(void *, target); 473 start = *ACPI_CAST_PTR(void *, target);
470 next = start; 474 next = start;
471 475
472 acpi_os_printf("%20s : %p", name, next); 476 acpi_os_printf("%20s : %p ", name, next);
473 if (next) { 477 if (next) {
474 acpi_os_printf("(%s %2.2X)", 478 acpi_os_printf("%s (Type %2.2X)",
475 acpi_ut_get_object_type_name 479 acpi_ut_get_object_type_name
476 (next), next->common.type); 480 (next), next->common.type);
477 481
@@ -493,6 +497,8 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc,
493 break; 497 break;
494 } 498 }
495 } 499 }
500 } else {
501 acpi_os_printf("- No attached objects");
496 } 502 }
497 503
498 acpi_os_printf("\n"); 504 acpi_os_printf("\n");
@@ -1129,7 +1135,9 @@ acpi_ex_dump_package_obj(union acpi_operand_object *obj_desc,
1129 1135
1130 default: 1136 default:
1131 1137
1132 acpi_os_printf("[Unknown Type] %X\n", obj_desc->common.type); 1138 acpi_os_printf("[%s] Type: %2.2X\n",
1139 acpi_ut_get_type_name(obj_desc->common.type),
1140 obj_desc->common.type);
1133 break; 1141 break;
1134 } 1142 }
1135} 1143}
@@ -1167,11 +1175,17 @@ acpi_ex_dump_object_descriptor(union acpi_operand_object *obj_desc, u32 flags)
1167 acpi_ex_dump_namespace_node((struct acpi_namespace_node *) 1175 acpi_ex_dump_namespace_node((struct acpi_namespace_node *)
1168 obj_desc, flags); 1176 obj_desc, flags);
1169 1177
1170 acpi_os_printf("\nAttached Object (%p):\n",
1171 ((struct acpi_namespace_node *)obj_desc)->
1172 object);
1173
1174 obj_desc = ((struct acpi_namespace_node *)obj_desc)->object; 1178 obj_desc = ((struct acpi_namespace_node *)obj_desc)->object;
1179 if (!obj_desc) {
1180 return_VOID;
1181 }
1182
1183 acpi_os_printf("\nAttached Object %p", obj_desc);
1184 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_NAMED) {
1185 acpi_os_printf(" - Namespace Node");
1186 }
1187
1188 acpi_os_printf(":\n");
1175 goto dump_object; 1189 goto dump_object;
1176 } 1190 }
1177 1191
@@ -1191,6 +1205,10 @@ acpi_ex_dump_object_descriptor(union acpi_operand_object *obj_desc, u32 flags)
1191 1205
1192dump_object: 1206dump_object:
1193 1207
1208 if (!obj_desc) {
1209 return_VOID;
1210 }
1211
1194 /* Common Fields */ 1212 /* Common Fields */
1195 1213
1196 acpi_ex_dump_object(obj_desc, acpi_ex_dump_common); 1214 acpi_ex_dump_object(obj_desc, acpi_ex_dump_common);
diff --git a/drivers/acpi/acpica/exmisc.c b/drivers/acpi/acpica/exmisc.c
index f222a80ca38e..1e7649ce0a7b 100644
--- a/drivers/acpi/acpica/exmisc.c
+++ b/drivers/acpi/acpica/exmisc.c
@@ -265,6 +265,8 @@ acpi_ex_do_logical_numeric_op(u16 opcode,
265 265
266 default: 266 default:
267 267
268 ACPI_ERROR((AE_INFO,
269 "Invalid numeric logical opcode: %X", opcode));
268 status = AE_AML_INTERNAL; 270 status = AE_AML_INTERNAL;
269 break; 271 break;
270 } 272 }
@@ -345,6 +347,9 @@ acpi_ex_do_logical_op(u16 opcode,
345 347
346 default: 348 default:
347 349
350 ACPI_ERROR((AE_INFO,
351 "Invalid object type for logical operator: %X",
352 operand0->common.type));
348 status = AE_AML_INTERNAL; 353 status = AE_AML_INTERNAL;
349 break; 354 break;
350 } 355 }
@@ -388,6 +393,8 @@ acpi_ex_do_logical_op(u16 opcode,
388 393
389 default: 394 default:
390 395
396 ACPI_ERROR((AE_INFO,
397 "Invalid comparison opcode: %X", opcode));
391 status = AE_AML_INTERNAL; 398 status = AE_AML_INTERNAL;
392 break; 399 break;
393 } 400 }
@@ -456,6 +463,8 @@ acpi_ex_do_logical_op(u16 opcode,
456 463
457 default: 464 default:
458 465
466 ACPI_ERROR((AE_INFO,
467 "Invalid comparison opcode: %X", opcode));
459 status = AE_AML_INTERNAL; 468 status = AE_AML_INTERNAL;
460 break; 469 break;
461 } 470 }
diff --git a/drivers/acpi/acpica/exoparg2.c b/drivers/acpi/acpica/exoparg2.c
index eecb3bff7fd7..57980b7d3594 100644
--- a/drivers/acpi/acpica/exoparg2.c
+++ b/drivers/acpi/acpica/exoparg2.c
@@ -414,6 +414,9 @@ acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state)
414 414
415 default: 415 default:
416 416
417 ACPI_ERROR((AE_INFO,
418 "Invalid object type: %X",
419 (operand[0])->common.type));
417 status = AE_AML_INTERNAL; 420 status = AE_AML_INTERNAL;
418 goto cleanup; 421 goto cleanup;
419 } 422 }
diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c
index de74a4c25085..acb417b58bbb 100644
--- a/drivers/acpi/acpica/hwregs.c
+++ b/drivers/acpi/acpica/hwregs.c
@@ -107,7 +107,7 @@ acpi_hw_get_access_bit_width(u64 address,
107 ACPI_IS_ALIGNED(reg->bit_width, 8)) { 107 ACPI_IS_ALIGNED(reg->bit_width, 8)) {
108 access_bit_width = reg->bit_width; 108 access_bit_width = reg->bit_width;
109 } else if (reg->access_width) { 109 } else if (reg->access_width) {
110 access_bit_width = (1 << (reg->access_width + 2)); 110 access_bit_width = ACPI_ACCESS_BIT_WIDTH(reg->access_width);
111 } else { 111 } else {
112 access_bit_width = 112 access_bit_width =
113 ACPI_ROUND_UP_POWER_OF_TWO_8(reg->bit_offset + 113 ACPI_ROUND_UP_POWER_OF_TWO_8(reg->bit_offset +
diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
index 7ef13934968f..e5c095ca6083 100644
--- a/drivers/acpi/acpica/hwxfsleep.c
+++ b/drivers/acpi/acpica/hwxfsleep.c
@@ -72,13 +72,16 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
72static struct acpi_sleep_functions acpi_sleep_dispatch[] = { 72static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
73 {ACPI_STRUCT_INIT(legacy_function, 73 {ACPI_STRUCT_INIT(legacy_function,
74 ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep)), 74 ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep)),
75 ACPI_STRUCT_INIT(extended_function, acpi_hw_extended_sleep) }, 75 ACPI_STRUCT_INIT(extended_function,
76 acpi_hw_extended_sleep)},
76 {ACPI_STRUCT_INIT(legacy_function, 77 {ACPI_STRUCT_INIT(legacy_function,
77 ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep)), 78 ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep)),
78 ACPI_STRUCT_INIT(extended_function, acpi_hw_extended_wake_prep) }, 79 ACPI_STRUCT_INIT(extended_function,
80 acpi_hw_extended_wake_prep)},
79 {ACPI_STRUCT_INIT(legacy_function, 81 {ACPI_STRUCT_INIT(legacy_function,
80 ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake)), 82 ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake)),
81 ACPI_STRUCT_INIT(extended_function, acpi_hw_extended_wake) } 83 ACPI_STRUCT_INIT(extended_function,
84 acpi_hw_extended_wake)}
82}; 85};
83 86
84/* 87/*
diff --git a/drivers/acpi/acpica/nsaccess.c b/drivers/acpi/acpica/nsaccess.c
index e5f4fa496572..f2733f51ca8d 100644
--- a/drivers/acpi/acpica/nsaccess.c
+++ b/drivers/acpi/acpica/nsaccess.c
@@ -292,6 +292,7 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
292{ 292{
293 acpi_status status; 293 acpi_status status;
294 char *path = pathname; 294 char *path = pathname;
295 char *external_path;
295 struct acpi_namespace_node *prefix_node; 296 struct acpi_namespace_node *prefix_node;
296 struct acpi_namespace_node *current_node = NULL; 297 struct acpi_namespace_node *current_node = NULL;
297 struct acpi_namespace_node *this_node = NULL; 298 struct acpi_namespace_node *this_node = NULL;
@@ -427,13 +428,22 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
427 num_carats++; 428 num_carats++;
428 this_node = this_node->parent; 429 this_node = this_node->parent;
429 if (!this_node) { 430 if (!this_node) {
431 /*
432 * Current scope has no parent scope. Externalize
433 * the internal path for error message.
434 */
435 status =
436 acpi_ns_externalize_name
437 (ACPI_UINT32_MAX, pathname, NULL,
438 &external_path);
439 if (ACPI_SUCCESS(status)) {
440 ACPI_ERROR((AE_INFO,
441 "%s: Path has too many parent prefixes (^)",
442 external_path));
443
444 ACPI_FREE(external_path);
445 }
430 446
431 /* Current scope has no parent scope */
432
433 ACPI_ERROR((AE_INFO,
434 "%s: Path has too many parent prefixes (^) "
435 "- reached beyond root node",
436 pathname));
437 return_ACPI_STATUS(AE_NOT_FOUND); 447 return_ACPI_STATUS(AE_NOT_FOUND);
438 } 448 }
439 } 449 }
@@ -634,6 +644,12 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
634 this_node->object; 644 this_node->object;
635 } 645 }
636 } 646 }
647#ifdef ACPI_ASL_COMPILER
648 if (!acpi_gbl_disasm_flag &&
649 (this_node->flags & ANOBJ_IS_EXTERNAL)) {
650 this_node->flags |= IMPLICIT_EXTERNAL;
651 }
652#endif
637 } 653 }
638 654
639 /* Special handling for the last segment (num_segments == 0) */ 655 /* Special handling for the last segment (num_segments == 0) */
diff --git a/drivers/acpi/acpica/nsarguments.c b/drivers/acpi/acpica/nsarguments.c
index 9095d51f6b37..67b7370dcae5 100644
--- a/drivers/acpi/acpica/nsarguments.c
+++ b/drivers/acpi/acpica/nsarguments.c
@@ -69,9 +69,14 @@ void acpi_ns_check_argument_types(struct acpi_evaluate_info *info)
69 u8 user_arg_type; 69 u8 user_arg_type;
70 u32 i; 70 u32 i;
71 71
72 /* If not a predefined name, cannot typecheck args */ 72 /*
73 73 * If not a predefined name, cannot typecheck args, because
74 if (!info->predefined) { 74 * we have no idea what argument types are expected.
75 * Also, ignore typecheck if warnings/errors if this method
76 * has already been evaluated at least once -- in order
77 * to suppress repetitive messages.
78 */
79 if (!info->predefined || (info->node->flags & ANOBJ_EVALUATED)) {
75 return; 80 return;
76 } 81 }
77 82
@@ -93,6 +98,10 @@ void acpi_ns_check_argument_types(struct acpi_evaluate_info *info)
93 acpi_ut_get_type_name 98 acpi_ut_get_type_name
94 (user_arg_type), 99 (user_arg_type),
95 acpi_ut_get_type_name(arg_type))); 100 acpi_ut_get_type_name(arg_type)));
101
102 /* Prevent any additional typechecking for this method */
103
104 info->node->flags |= ANOBJ_EVALUATED;
96 } 105 }
97 } 106 }
98} 107}
@@ -121,7 +130,7 @@ acpi_ns_check_acpi_compliance(char *pathname,
121 u32 aml_param_count; 130 u32 aml_param_count;
122 u32 required_param_count; 131 u32 required_param_count;
123 132
124 if (!predefined) { 133 if (!predefined || (node->flags & ANOBJ_EVALUATED)) {
125 return; 134 return;
126 } 135 }
127 136
@@ -215,6 +224,10 @@ acpi_ns_check_argument_count(char *pathname,
215 u32 aml_param_count; 224 u32 aml_param_count;
216 u32 required_param_count; 225 u32 required_param_count;
217 226
227 if (node->flags & ANOBJ_EVALUATED) {
228 return;
229 }
230
218 if (!predefined) { 231 if (!predefined) {
219 /* 232 /*
220 * Not a predefined name. Check the incoming user argument count 233 * Not a predefined name. Check the incoming user argument count
diff --git a/drivers/acpi/acpica/nsinit.c b/drivers/acpi/acpica/nsinit.c
index ce33e7297ea7..9c6297949712 100644
--- a/drivers/acpi/acpica/nsinit.c
+++ b/drivers/acpi/acpica/nsinit.c
@@ -396,6 +396,20 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
396 396
397 info->package_init++; 397 info->package_init++;
398 status = acpi_ds_get_package_arguments(obj_desc); 398 status = acpi_ds_get_package_arguments(obj_desc);
399 if (ACPI_FAILURE(status)) {
400 break;
401 }
402
403 /*
404 * Resolve all named references in package objects (and all
405 * sub-packages). This action has been deferred until the entire
406 * namespace has been loaded, in order to support external and
407 * forward references from individual package elements (05/2017).
408 */
409 status = acpi_ut_walk_package_tree(obj_desc, NULL,
410 acpi_ds_init_package_element,
411 NULL);
412 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
399 break; 413 break;
400 414
401 default: 415 default:
diff --git a/drivers/acpi/acpica/nsnames.c b/drivers/acpi/acpica/nsnames.c
index aa16aeaa8937..a410760a0308 100644
--- a/drivers/acpi/acpica/nsnames.c
+++ b/drivers/acpi/acpica/nsnames.c
@@ -89,7 +89,14 @@ acpi_size acpi_ns_get_pathname_length(struct acpi_namespace_node *node)
89{ 89{
90 acpi_size size; 90 acpi_size size;
91 91
92 ACPI_FUNCTION_ENTRY(); 92 /* Validate the Node */
93
94 if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
95 ACPI_ERROR((AE_INFO,
96 "Invalid/cached reference target node: %p, descriptor type %d",
97 node, ACPI_GET_DESCRIPTOR_TYPE(node)));
98 return (0);
99 }
93 100
94 size = acpi_ns_build_normalized_path(node, NULL, 0, FALSE); 101 size = acpi_ns_build_normalized_path(node, NULL, 0, FALSE);
95 return (size); 102 return (size);
diff --git a/drivers/acpi/acpica/nsprepkg.c b/drivers/acpi/acpica/nsprepkg.c
index 4954cb6c9090..a8ea8fb1d299 100644
--- a/drivers/acpi/acpica/nsprepkg.c
+++ b/drivers/acpi/acpica/nsprepkg.c
@@ -614,6 +614,8 @@ acpi_ns_check_package_list(struct acpi_evaluate_info *info,
614 614
615 default: /* Should not get here, type was validated by caller */ 615 default: /* Should not get here, type was validated by caller */
616 616
617 ACPI_ERROR((AE_INFO, "Invalid Package type: %X",
618 package->ret_info.type));
617 return (AE_AML_INTERNAL); 619 return (AE_AML_INTERNAL);
618 } 620 }
619 621
diff --git a/drivers/acpi/acpica/psloop.c b/drivers/acpi/acpica/psloop.c
index b4224005783c..bb04dec168ad 100644
--- a/drivers/acpi/acpica/psloop.c
+++ b/drivers/acpi/acpica/psloop.c
@@ -164,6 +164,11 @@ acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
164 INCREMENT_ARG_LIST(walk_state->arg_types); 164 INCREMENT_ARG_LIST(walk_state->arg_types);
165 } 165 }
166 166
167 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
168 "Final argument count: %u pass %u\n",
169 walk_state->arg_count,
170 walk_state->pass_number));
171
167 /* 172 /*
168 * Handle executable code at "module-level". This refers to 173 * Handle executable code at "module-level". This refers to
169 * executable opcodes that appear outside of any control method. 174 * executable opcodes that appear outside of any control method.
@@ -277,6 +282,11 @@ acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
277 AML_NAME_OP) 282 AML_NAME_OP)
278 && (walk_state->pass_number <= 283 && (walk_state->pass_number <=
279 ACPI_IMODE_LOAD_PASS2)) { 284 ACPI_IMODE_LOAD_PASS2)) {
285 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
286 "Setup Package/Buffer: Pass %u, AML Ptr: %p\n",
287 walk_state->pass_number,
288 aml_op_start));
289
280 /* 290 /*
281 * Skip parsing of Buffers and Packages because we don't have 291 * Skip parsing of Buffers and Packages because we don't have
282 * enough info in the first pass to parse them correctly. 292 * enough info in the first pass to parse them correctly.
@@ -570,6 +580,10 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
570 580
571 /* Check for arguments that need to be processed */ 581 /* Check for arguments that need to be processed */
572 582
583 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
584 "Parseloop: argument count: %u\n",
585 walk_state->arg_count));
586
573 if (walk_state->arg_count) { 587 if (walk_state->arg_count) {
574 /* 588 /*
575 * There are arguments (complex ones), push Op and 589 * There are arguments (complex ones), push Op and
diff --git a/drivers/acpi/acpica/psobject.c b/drivers/acpi/acpica/psobject.c
index ef6384e374fc..0bef6df71bba 100644
--- a/drivers/acpi/acpica/psobject.c
+++ b/drivers/acpi/acpica/psobject.c
@@ -359,6 +359,32 @@ acpi_ps_create_op(struct acpi_walk_state *walk_state,
359 acpi_ps_build_named_op(walk_state, aml_op_start, op, 359 acpi_ps_build_named_op(walk_state, aml_op_start, op,
360 &named_op); 360 &named_op);
361 acpi_ps_free_op(op); 361 acpi_ps_free_op(op);
362
363#ifdef ACPI_ASL_COMPILER
364 if (acpi_gbl_disasm_flag
365 && walk_state->opcode == AML_EXTERNAL_OP
366 && status == AE_NOT_FOUND) {
367 /*
368 * If parsing of AML_EXTERNAL_OP's name path fails, then skip
369 * past this opcode and keep parsing. This is a much better
370 * alternative than to abort the entire disassembler. At this
371 * point, the parser_state is at the end of the namepath of the
372 * external declaration opcode. Setting walk_state->Aml to
373 * walk_state->parser_state.Aml + 2 moves increments the
374 * walk_state->Aml past the object type and the paramcount of the
375 * external opcode. For the error message, only print the AML
376 * offset. We could attempt to print the name but this may cause
377 * a segmentation fault when printing the namepath because the
378 * AML may be incorrect.
379 */
380 acpi_os_printf
381 ("// Invalid external declaration at AML offset 0x%x.\n",
382 walk_state->aml -
383 walk_state->parser_state.aml_start);
384 walk_state->aml = walk_state->parser_state.aml + 2;
385 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
386 }
387#endif
362 if (ACPI_FAILURE(status)) { 388 if (ACPI_FAILURE(status)) {
363 return_ACPI_STATUS(status); 389 return_ACPI_STATUS(status);
364 } 390 }
diff --git a/drivers/acpi/acpica/rsxface.c b/drivers/acpi/acpica/rsxface.c
index 59a4f9ed06a7..be65e65e216e 100644
--- a/drivers/acpi/acpica/rsxface.c
+++ b/drivers/acpi/acpica/rsxface.c
@@ -615,7 +615,7 @@ ACPI_EXPORT_SYMBOL(acpi_walk_resource_buffer)
615 * device we are querying 615 * device we are querying
616 * name - Method name of the resources we want. 616 * name - Method name of the resources we want.
617 * (METHOD_NAME__CRS, METHOD_NAME__PRS, or 617 * (METHOD_NAME__CRS, METHOD_NAME__PRS, or
618 * METHOD_NAME__AEI) 618 * METHOD_NAME__AEI or METHOD_NAME__DMA)
619 * user_function - Called for each resource 619 * user_function - Called for each resource
620 * context - Passed to user_function 620 * context - Passed to user_function
621 * 621 *
@@ -641,11 +641,12 @@ acpi_walk_resources(acpi_handle device_handle,
641 if (!device_handle || !user_function || !name || 641 if (!device_handle || !user_function || !name ||
642 (!ACPI_COMPARE_NAME(name, METHOD_NAME__CRS) && 642 (!ACPI_COMPARE_NAME(name, METHOD_NAME__CRS) &&
643 !ACPI_COMPARE_NAME(name, METHOD_NAME__PRS) && 643 !ACPI_COMPARE_NAME(name, METHOD_NAME__PRS) &&
644 !ACPI_COMPARE_NAME(name, METHOD_NAME__AEI))) { 644 !ACPI_COMPARE_NAME(name, METHOD_NAME__AEI) &&
645 !ACPI_COMPARE_NAME(name, METHOD_NAME__DMA))) {
645 return_ACPI_STATUS(AE_BAD_PARAMETER); 646 return_ACPI_STATUS(AE_BAD_PARAMETER);
646 } 647 }
647 648
648 /* Get the _CRS/_PRS/_AEI resource list */ 649 /* Get the _CRS/_PRS/_AEI/_DMA resource list */
649 650
650 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; 651 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
651 status = acpi_rs_get_method_data(device_handle, name, &buffer); 652 status = acpi_rs_get_method_data(device_handle, name, &buffer);
diff --git a/drivers/acpi/acpica/tbdata.c b/drivers/acpi/acpica/tbdata.c
index c9d6fa6d7cc6..b19a2f0ea331 100644
--- a/drivers/acpi/acpica/tbdata.c
+++ b/drivers/acpi/acpica/tbdata.c
@@ -50,6 +50,57 @@
50#define _COMPONENT ACPI_TABLES 50#define _COMPONENT ACPI_TABLES
51ACPI_MODULE_NAME("tbdata") 51ACPI_MODULE_NAME("tbdata")
52 52
53/* Local prototypes */
54static acpi_status
55acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index);
56
57static u8
58acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index);
59
60/*******************************************************************************
61 *
62 * FUNCTION: acpi_tb_compare_tables
63 *
64 * PARAMETERS: table_desc - Table 1 descriptor to be compared
65 * table_index - Index of table 2 to be compared
66 *
67 * RETURN: TRUE if both tables are identical.
68 *
69 * DESCRIPTION: This function compares a table with another table that has
70 * already been installed in the root table list.
71 *
72 ******************************************************************************/
73
74static u8
75acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index)
76{
77 acpi_status status = AE_OK;
78 u8 is_identical;
79 struct acpi_table_header *table;
80 u32 table_length;
81 u8 table_flags;
82
83 status =
84 acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index],
85 &table, &table_length, &table_flags);
86 if (ACPI_FAILURE(status)) {
87 return (FALSE);
88 }
89
90 /*
91 * Check for a table match on the entire table length,
92 * not just the header.
93 */
94 is_identical = (u8)((table_desc->length != table_length ||
95 memcmp(table_desc->pointer, table, table_length)) ?
96 FALSE : TRUE);
97
98 /* Release the acquired table */
99
100 acpi_tb_release_table(table, table_length, table_flags);
101 return (is_identical);
102}
103
53/******************************************************************************* 104/*******************************************************************************
54 * 105 *
55 * FUNCTION: acpi_tb_init_table_descriptor 106 * FUNCTION: acpi_tb_init_table_descriptor
@@ -64,6 +115,7 @@ ACPI_MODULE_NAME("tbdata")
64 * DESCRIPTION: Initialize a new table descriptor 115 * DESCRIPTION: Initialize a new table descriptor
65 * 116 *
66 ******************************************************************************/ 117 ******************************************************************************/
118
67void 119void
68acpi_tb_init_table_descriptor(struct acpi_table_desc *table_desc, 120acpi_tb_init_table_descriptor(struct acpi_table_desc *table_desc,
69 acpi_physical_address address, 121 acpi_physical_address address,
@@ -338,7 +390,7 @@ void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc)
338acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc) 390acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc)
339{ 391{
340 392
341 if (!table_desc->pointer && !acpi_gbl_verify_table_checksum) { 393 if (!table_desc->pointer && !acpi_gbl_enable_table_validation) {
342 /* 394 /*
343 * Only validates the header of the table. 395 * Only validates the header of the table.
344 * Note that Length contains the size of the mapping after invoking 396 * Note that Length contains the size of the mapping after invoking
@@ -354,22 +406,100 @@ acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc)
354 return (acpi_tb_validate_table(table_desc)); 406 return (acpi_tb_validate_table(table_desc));
355} 407}
356 408
409/*******************************************************************************
410 *
411 * FUNCTION: acpi_tb_check_duplication
412 *
413 * PARAMETERS: table_desc - Table descriptor
414 * table_index - Where the table index is returned
415 *
416 * RETURN: Status
417 *
418 * DESCRIPTION: Avoid installing duplicated tables. However table override and
419 * user aided dynamic table load is allowed, thus comparing the
420 * address of the table is not sufficient, and checking the entire
421 * table content is required.
422 *
423 ******************************************************************************/
424
425static acpi_status
426acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index)
427{
428 u32 i;
429
430 ACPI_FUNCTION_TRACE(tb_check_duplication);
431
432 /* Check if table is already registered */
433
434 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
435
436 /* Do not compare with unverified tables */
437
438 if (!
439 (acpi_gbl_root_table_list.tables[i].
440 flags & ACPI_TABLE_IS_VERIFIED)) {
441 continue;
442 }
443
444 /*
445 * Check for a table match on the entire table length,
446 * not just the header.
447 */
448 if (!acpi_tb_compare_tables(table_desc, i)) {
449 continue;
450 }
451
452 /*
453 * Note: the current mechanism does not unregister a table if it is
454 * dynamically unloaded. The related namespace entries are deleted,
455 * but the table remains in the root table list.
456 *
457 * The assumption here is that the number of different tables that
458 * will be loaded is actually small, and there is minimal overhead
459 * in just keeping the table in case it is needed again.
460 *
461 * If this assumption changes in the future (perhaps on large
462 * machines with many table load/unload operations), tables will
463 * need to be unregistered when they are unloaded, and slots in the
464 * root table list should be reused when empty.
465 */
466 if (acpi_gbl_root_table_list.tables[i].flags &
467 ACPI_TABLE_IS_LOADED) {
468
469 /* Table is still loaded, this is an error */
470
471 return_ACPI_STATUS(AE_ALREADY_EXISTS);
472 } else {
473 *table_index = i;
474 return_ACPI_STATUS(AE_CTRL_TERMINATE);
475 }
476 }
477
478 /* Indicate no duplication to the caller */
479
480 return_ACPI_STATUS(AE_OK);
481}
482
357/****************************************************************************** 483/******************************************************************************
358 * 484 *
359 * FUNCTION: acpi_tb_verify_temp_table 485 * FUNCTION: acpi_tb_verify_temp_table
360 * 486 *
361 * PARAMETERS: table_desc - Table descriptor 487 * PARAMETERS: table_desc - Table descriptor
362 * signature - Table signature to verify 488 * signature - Table signature to verify
489 * table_index - Where the table index is returned
363 * 490 *
364 * RETURN: Status 491 * RETURN: Status
365 * 492 *
366 * DESCRIPTION: This function is called to validate and verify the table, the 493 * DESCRIPTION: This function is called to validate and verify the table, the
367 * returned table descriptor is in "VALIDATED" state. 494 * returned table descriptor is in "VALIDATED" state.
495 * Note that 'TableIndex' is required to be set to !NULL to
496 * enable duplication check.
368 * 497 *
369 *****************************************************************************/ 498 *****************************************************************************/
370 499
371acpi_status 500acpi_status
372acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature) 501acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc,
502 char *signature, u32 *table_index)
373{ 503{
374 acpi_status status = AE_OK; 504 acpi_status status = AE_OK;
375 505
@@ -392,9 +522,10 @@ acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature)
392 goto invalidate_and_exit; 522 goto invalidate_and_exit;
393 } 523 }
394 524
395 /* Verify the checksum */ 525 if (acpi_gbl_enable_table_validation) {
526
527 /* Verify the checksum */
396 528
397 if (acpi_gbl_verify_table_checksum) {
398 status = 529 status =
399 acpi_tb_verify_checksum(table_desc->pointer, 530 acpi_tb_verify_checksum(table_desc->pointer,
400 table_desc->length); 531 table_desc->length);
@@ -411,9 +542,34 @@ acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature)
411 542
412 goto invalidate_and_exit; 543 goto invalidate_and_exit;
413 } 544 }
545
546 /* Avoid duplications */
547
548 if (table_index) {
549 status =
550 acpi_tb_check_duplication(table_desc, table_index);
551 if (ACPI_FAILURE(status)) {
552 if (status != AE_CTRL_TERMINATE) {
553 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
554 "%4.4s 0x%8.8X%8.8X"
555 " Table is duplicated",
556 acpi_ut_valid_nameseg
557 (table_desc->signature.
558 ascii) ? table_desc->
559 signature.
560 ascii : "????",
561 ACPI_FORMAT_UINT64
562 (table_desc->address)));
563 }
564
565 goto invalidate_and_exit;
566 }
567 }
568
569 table_desc->flags |= ACPI_TABLE_IS_VERIFIED;
414 } 570 }
415 571
416 return_ACPI_STATUS(AE_OK); 572 return_ACPI_STATUS(status);
417 573
418invalidate_and_exit: 574invalidate_and_exit:
419 acpi_tb_invalidate_table(table_desc); 575 acpi_tb_invalidate_table(table_desc);
@@ -436,6 +592,8 @@ acpi_status acpi_tb_resize_root_table_list(void)
436{ 592{
437 struct acpi_table_desc *tables; 593 struct acpi_table_desc *tables;
438 u32 table_count; 594 u32 table_count;
595 u32 current_table_count, max_table_count;
596 u32 i;
439 597
440 ACPI_FUNCTION_TRACE(tb_resize_root_table_list); 598 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
441 599
@@ -455,8 +613,8 @@ acpi_status acpi_tb_resize_root_table_list(void)
455 table_count = acpi_gbl_root_table_list.current_table_count; 613 table_count = acpi_gbl_root_table_list.current_table_count;
456 } 614 }
457 615
458 tables = ACPI_ALLOCATE_ZEROED(((acpi_size)table_count + 616 max_table_count = table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT;
459 ACPI_ROOT_TABLE_SIZE_INCREMENT) * 617 tables = ACPI_ALLOCATE_ZEROED(((acpi_size)max_table_count) *
460 sizeof(struct acpi_table_desc)); 618 sizeof(struct acpi_table_desc));
461 if (!tables) { 619 if (!tables) {
462 ACPI_ERROR((AE_INFO, 620 ACPI_ERROR((AE_INFO,
@@ -466,9 +624,16 @@ acpi_status acpi_tb_resize_root_table_list(void)
466 624
467 /* Copy and free the previous table array */ 625 /* Copy and free the previous table array */
468 626
627 current_table_count = 0;
469 if (acpi_gbl_root_table_list.tables) { 628 if (acpi_gbl_root_table_list.tables) {
470 memcpy(tables, acpi_gbl_root_table_list.tables, 629 for (i = 0; i < table_count; i++) {
471 (acpi_size)table_count * sizeof(struct acpi_table_desc)); 630 if (acpi_gbl_root_table_list.tables[i].address) {
631 memcpy(tables + current_table_count,
632 acpi_gbl_root_table_list.tables + i,
633 sizeof(struct acpi_table_desc));
634 current_table_count++;
635 }
636 }
472 637
473 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { 638 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
474 ACPI_FREE(acpi_gbl_root_table_list.tables); 639 ACPI_FREE(acpi_gbl_root_table_list.tables);
@@ -476,8 +641,8 @@ acpi_status acpi_tb_resize_root_table_list(void)
476 } 641 }
477 642
478 acpi_gbl_root_table_list.tables = tables; 643 acpi_gbl_root_table_list.tables = tables;
479 acpi_gbl_root_table_list.max_table_count = 644 acpi_gbl_root_table_list.max_table_count = max_table_count;
480 table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT; 645 acpi_gbl_root_table_list.current_table_count = current_table_count;
481 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED; 646 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
482 647
483 return_ACPI_STATUS(AE_OK); 648 return_ACPI_STATUS(AE_OK);
@@ -818,13 +983,9 @@ acpi_tb_load_table(u32 table_index, struct acpi_namespace_node *parent_node)
818 acpi_ev_update_gpes(owner_id); 983 acpi_ev_update_gpes(owner_id);
819 } 984 }
820 985
821 /* Invoke table handler if present */ 986 /* Invoke table handler */
822
823 if (acpi_gbl_table_handler) {
824 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
825 acpi_gbl_table_handler_context);
826 }
827 987
988 acpi_tb_notify_table(ACPI_TABLE_EVENT_LOAD, table);
828 return_ACPI_STATUS(status); 989 return_ACPI_STATUS(status);
829} 990}
830 991
@@ -894,15 +1055,11 @@ acpi_status acpi_tb_unload_table(u32 table_index)
894 return_ACPI_STATUS(AE_NOT_EXIST); 1055 return_ACPI_STATUS(AE_NOT_EXIST);
895 } 1056 }
896 1057
897 /* Invoke table handler if present */ 1058 /* Invoke table handler */
898 1059
899 if (acpi_gbl_table_handler) { 1060 status = acpi_get_table_by_index(table_index, &table);
900 status = acpi_get_table_by_index(table_index, &table); 1061 if (ACPI_SUCCESS(status)) {
901 if (ACPI_SUCCESS(status)) { 1062 acpi_tb_notify_table(ACPI_TABLE_EVENT_UNLOAD, table);
902 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
903 table,
904 acpi_gbl_table_handler_context);
905 }
906 } 1063 }
907 1064
908 /* Delete the portion of the namespace owned by this table */ 1065 /* Delete the portion of the namespace owned by this table */
@@ -918,3 +1075,26 @@ acpi_status acpi_tb_unload_table(u32 table_index)
918} 1075}
919 1076
920ACPI_EXPORT_SYMBOL(acpi_tb_unload_table) 1077ACPI_EXPORT_SYMBOL(acpi_tb_unload_table)
1078
1079/*******************************************************************************
1080 *
1081 * FUNCTION: acpi_tb_notify_table
1082 *
1083 * PARAMETERS: event - Table event
1084 * table - Validated table pointer
1085 *
1086 * RETURN: None
1087 *
1088 * DESCRIPTION: Notify a table event to the users.
1089 *
1090 ******************************************************************************/
1091
1092void acpi_tb_notify_table(u32 event, void *table)
1093{
1094 /* Invoke table handler if present */
1095
1096 if (acpi_gbl_table_handler) {
1097 (void)acpi_gbl_table_handler(event, table,
1098 acpi_gbl_table_handler_context);
1099 }
1100}
diff --git a/drivers/acpi/acpica/tbinstal.c b/drivers/acpi/acpica/tbinstal.c
index 4620f3c68c13..0dfc0ac3c141 100644
--- a/drivers/acpi/acpica/tbinstal.c
+++ b/drivers/acpi/acpica/tbinstal.c
@@ -48,54 +48,6 @@
48#define _COMPONENT ACPI_TABLES 48#define _COMPONENT ACPI_TABLES
49ACPI_MODULE_NAME("tbinstal") 49ACPI_MODULE_NAME("tbinstal")
50 50
51/* Local prototypes */
52static u8
53acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index);
54
55/*******************************************************************************
56 *
57 * FUNCTION: acpi_tb_compare_tables
58 *
59 * PARAMETERS: table_desc - Table 1 descriptor to be compared
60 * table_index - Index of table 2 to be compared
61 *
62 * RETURN: TRUE if both tables are identical.
63 *
64 * DESCRIPTION: This function compares a table with another table that has
65 * already been installed in the root table list.
66 *
67 ******************************************************************************/
68
69static u8
70acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index)
71{
72 acpi_status status = AE_OK;
73 u8 is_identical;
74 struct acpi_table_header *table;
75 u32 table_length;
76 u8 table_flags;
77
78 status =
79 acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index],
80 &table, &table_length, &table_flags);
81 if (ACPI_FAILURE(status)) {
82 return (FALSE);
83 }
84
85 /*
86 * Check for a table match on the entire table length,
87 * not just the header.
88 */
89 is_identical = (u8)((table_desc->length != table_length ||
90 memcmp(table_desc->pointer, table, table_length)) ?
91 FALSE : TRUE);
92
93 /* Release the acquired table */
94
95 acpi_tb_release_table(table, table_length, table_flags);
96 return (is_identical);
97}
98
99/******************************************************************************* 51/*******************************************************************************
100 * 52 *
101 * FUNCTION: acpi_tb_install_table_with_override 53 * FUNCTION: acpi_tb_install_table_with_override
@@ -112,7 +64,6 @@ acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index)
112 * table array. 64 * table array.
113 * 65 *
114 ******************************************************************************/ 66 ******************************************************************************/
115
116void 67void
117acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc, 68acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc,
118 u8 override, u32 *table_index) 69 u8 override, u32 *table_index)
@@ -210,95 +161,29 @@ acpi_tb_install_standard_table(acpi_physical_address address,
210 goto release_and_exit; 161 goto release_and_exit;
211 } 162 }
212 163
213 /* Validate and verify a table before installation */
214
215 status = acpi_tb_verify_temp_table(&new_table_desc, NULL);
216 if (ACPI_FAILURE(status)) {
217 goto release_and_exit;
218 }
219
220 /* Acquire the table lock */ 164 /* Acquire the table lock */
221 165
222 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); 166 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
223 167
224 if (reload) { 168 /* Validate and verify a table before installation */
225 /*
226 * Validate the incoming table signature.
227 *
228 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
229 * 2) We added support for OEMx tables, signature "OEM".
230 * 3) Valid tables were encountered with a null signature, so we just
231 * gave up on validating the signature, (05/2008).
232 * 4) We encountered non-AML tables such as the MADT, which caused
233 * interpreter errors and kernel faults. So now, we once again allow
234 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
235 */
236 if ((new_table_desc.signature.ascii[0] != 0x00) &&
237 (!ACPI_COMPARE_NAME
238 (&new_table_desc.signature, ACPI_SIG_SSDT))
239 && (strncmp(new_table_desc.signature.ascii, "OEM", 3))) {
240 ACPI_BIOS_ERROR((AE_INFO,
241 "Table has invalid signature [%4.4s] (0x%8.8X), "
242 "must be SSDT or OEMx",
243 acpi_ut_valid_nameseg(new_table_desc.
244 signature.
245 ascii) ?
246 new_table_desc.signature.
247 ascii : "????",
248 new_table_desc.signature.integer));
249
250 status = AE_BAD_SIGNATURE;
251 goto unlock_and_exit;
252 }
253
254 /* Check if table is already registered */
255
256 for (i = 0; i < acpi_gbl_root_table_list.current_table_count;
257 ++i) {
258 /*
259 * Check for a table match on the entire table length,
260 * not just the header.
261 */
262 if (!acpi_tb_compare_tables(&new_table_desc, i)) {
263 continue;
264 }
265 169
170 status = acpi_tb_verify_temp_table(&new_table_desc, NULL, &i);
171 if (ACPI_FAILURE(status)) {
172 if (status == AE_CTRL_TERMINATE) {
266 /* 173 /*
267 * Note: the current mechanism does not unregister a table if it is 174 * Table was unloaded, allow it to be reloaded.
268 * dynamically unloaded. The related namespace entries are deleted, 175 * As we are going to return AE_OK to the caller, we should
269 * but the table remains in the root table list. 176 * take the responsibility of freeing the input descriptor.
270 * 177 * Refill the input descriptor to ensure
271 * The assumption here is that the number of different tables that 178 * acpi_tb_install_table_with_override() can be called again to
272 * will be loaded is actually small, and there is minimal overhead 179 * indicate the re-installation.
273 * in just keeping the table in case it is needed again.
274 *
275 * If this assumption changes in the future (perhaps on large
276 * machines with many table load/unload operations), tables will
277 * need to be unregistered when they are unloaded, and slots in the
278 * root table list should be reused when empty.
279 */ 180 */
280 if (acpi_gbl_root_table_list.tables[i].flags & 181 acpi_tb_uninstall_table(&new_table_desc);
281 ACPI_TABLE_IS_LOADED) { 182 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
282 183 *table_index = i;
283 /* Table is still loaded, this is an error */ 184 return_ACPI_STATUS(AE_OK);
284
285 status = AE_ALREADY_EXISTS;
286 goto unlock_and_exit;
287 } else {
288 /*
289 * Table was unloaded, allow it to be reloaded.
290 * As we are going to return AE_OK to the caller, we should
291 * take the responsibility of freeing the input descriptor.
292 * Refill the input descriptor to ensure
293 * acpi_tb_install_table_with_override() can be called again to
294 * indicate the re-installation.
295 */
296 acpi_tb_uninstall_table(&new_table_desc);
297 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
298 *table_index = i;
299 return_ACPI_STATUS(AE_OK);
300 }
301 } 185 }
186 goto unlock_and_exit;
302 } 187 }
303 188
304 /* Add the table to the global root table list */ 189 /* Add the table to the global root table list */
@@ -306,14 +191,10 @@ acpi_tb_install_standard_table(acpi_physical_address address,
306 acpi_tb_install_table_with_override(&new_table_desc, override, 191 acpi_tb_install_table_with_override(&new_table_desc, override,
307 table_index); 192 table_index);
308 193
309 /* Invoke table handler if present */ 194 /* Invoke table handler */
310 195
311 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 196 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
312 if (acpi_gbl_table_handler) { 197 acpi_tb_notify_table(ACPI_TABLE_EVENT_INSTALL, new_table_desc.pointer);
313 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_INSTALL,
314 new_table_desc.pointer,
315 acpi_gbl_table_handler_context);
316 }
317 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); 198 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
318 199
319unlock_and_exit: 200unlock_and_exit:
@@ -382,9 +263,11 @@ void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
382 263
383finish_override: 264finish_override:
384 265
385 /* Validate and verify a table before overriding */ 266 /*
386 267 * Validate and verify a table before overriding, no nested table
387 status = acpi_tb_verify_temp_table(&new_table_desc, NULL); 268 * duplication check as it's too complicated and unnecessary.
269 */
270 status = acpi_tb_verify_temp_table(&new_table_desc, NULL, NULL);
388 if (ACPI_FAILURE(status)) { 271 if (ACPI_FAILURE(status)) {
389 return; 272 return;
390 } 273 }
diff --git a/drivers/acpi/acpica/tbxface.c b/drivers/acpi/acpica/tbxface.c
index 010b1c43df92..26ad596c973e 100644
--- a/drivers/acpi/acpica/tbxface.c
+++ b/drivers/acpi/acpica/tbxface.c
@@ -167,7 +167,8 @@ ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_tables)
167acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void) 167acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void)
168{ 168{
169 acpi_status status; 169 acpi_status status;
170 u32 i; 170 struct acpi_table_desc *table_desc;
171 u32 i, j;
171 172
172 ACPI_FUNCTION_TRACE(acpi_reallocate_root_table); 173 ACPI_FUNCTION_TRACE(acpi_reallocate_root_table);
173 174
@@ -179,6 +180,8 @@ acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void)
179 return_ACPI_STATUS(AE_SUPPORT); 180 return_ACPI_STATUS(AE_SUPPORT);
180 } 181 }
181 182
183 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
184
182 /* 185 /*
183 * Ensure OS early boot logic, which is required by some hosts. If the 186 * Ensure OS early boot logic, which is required by some hosts. If the
184 * table state is reported to be wrong, developers should fix the 187 * table state is reported to be wrong, developers should fix the
@@ -186,17 +189,39 @@ acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void)
186 * early stage. 189 * early stage.
187 */ 190 */
188 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { 191 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
189 if (acpi_gbl_root_table_list.tables[i].pointer) { 192 table_desc = &acpi_gbl_root_table_list.tables[i];
193 if (table_desc->pointer) {
190 ACPI_ERROR((AE_INFO, 194 ACPI_ERROR((AE_INFO,
191 "Table [%4.4s] is not invalidated during early boot stage", 195 "Table [%4.4s] is not invalidated during early boot stage",
192 acpi_gbl_root_table_list.tables[i]. 196 table_desc->signature.ascii));
193 signature.ascii));
194 } 197 }
195 } 198 }
196 199
197 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ALLOW_RESIZE; 200 if (!acpi_gbl_enable_table_validation) {
201 /*
202 * Now it's safe to do full table validation. We can do deferred
203 * table initilization here once the flag is set.
204 */
205 acpi_gbl_enable_table_validation = TRUE;
206 for (i = 0; i < acpi_gbl_root_table_list.current_table_count;
207 ++i) {
208 table_desc = &acpi_gbl_root_table_list.tables[i];
209 if (!(table_desc->flags & ACPI_TABLE_IS_VERIFIED)) {
210 status =
211 acpi_tb_verify_temp_table(table_desc, NULL,
212 &j);
213 if (ACPI_FAILURE(status)) {
214 acpi_tb_uninstall_table(table_desc);
215 }
216 }
217 }
218 }
198 219
220 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ALLOW_RESIZE;
199 status = acpi_tb_resize_root_table_list(); 221 status = acpi_tb_resize_root_table_list();
222 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
223
224 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
200 return_ACPI_STATUS(status); 225 return_ACPI_STATUS(status);
201} 226}
202 227
@@ -369,6 +394,10 @@ void acpi_put_table(struct acpi_table_header *table)
369 394
370 ACPI_FUNCTION_TRACE(acpi_put_table); 395 ACPI_FUNCTION_TRACE(acpi_put_table);
371 396
397 if (!table) {
398 return_VOID;
399 }
400
372 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); 401 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
373 402
374 /* Walk the root table list */ 403 /* Walk the root table list */
diff --git a/drivers/acpi/acpica/tbxfload.c b/drivers/acpi/acpica/tbxfload.c
index b71ce3b817ea..d81f442228b8 100644
--- a/drivers/acpi/acpica/tbxfload.c
+++ b/drivers/acpi/acpica/tbxfload.c
@@ -206,7 +206,7 @@ acpi_status acpi_tb_load_namespace(void)
206 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { 206 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
207 table = &acpi_gbl_root_table_list.tables[i]; 207 table = &acpi_gbl_root_table_list.tables[i];
208 208
209 if (!acpi_gbl_root_table_list.tables[i].address || 209 if (!table->address ||
210 (!ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_SSDT) 210 (!ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_SSDT)
211 && !ACPI_COMPARE_NAME(table->signature.ascii, 211 && !ACPI_COMPARE_NAME(table->signature.ascii,
212 ACPI_SIG_PSDT) 212 ACPI_SIG_PSDT)
diff --git a/drivers/acpi/acpica/uthex.c b/drivers/acpi/acpica/uthex.c
index 6600bc257516..fb406daf47fa 100644
--- a/drivers/acpi/acpica/uthex.c
+++ b/drivers/acpi/acpica/uthex.c
@@ -69,8 +69,10 @@ static const char acpi_gbl_hex_to_ascii[] = {
69 69
70char acpi_ut_hex_to_ascii_char(u64 integer, u32 position) 70char acpi_ut_hex_to_ascii_char(u64 integer, u32 position)
71{ 71{
72 u64 index;
72 73
73 return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]); 74 acpi_ut_short_shift_right(integer, position, &index);
75 return (acpi_gbl_hex_to_ascii[index & 0xF]);
74} 76}
75 77
76/******************************************************************************* 78/*******************************************************************************
diff --git a/drivers/acpi/acpica/utmath.c b/drivers/acpi/acpica/utmath.c
index aa0502d1d019..5f9c680076c4 100644
--- a/drivers/acpi/acpica/utmath.c
+++ b/drivers/acpi/acpica/utmath.c
@@ -47,15 +47,6 @@
47#define _COMPONENT ACPI_UTILITIES 47#define _COMPONENT ACPI_UTILITIES
48ACPI_MODULE_NAME("utmath") 48ACPI_MODULE_NAME("utmath")
49 49
50/*
51 * Optional support for 64-bit double-precision integer divide. This code
52 * is configurable and is implemented in order to support 32-bit kernel
53 * environments where a 64-bit double-precision math library is not available.
54 *
55 * Support for a more normal 64-bit divide/modulo (with check for a divide-
56 * by-zero) appears after this optional section of code.
57 */
58#ifndef ACPI_USE_NATIVE_DIVIDE
59/* Structures used only for 64-bit divide */ 50/* Structures used only for 64-bit divide */
60typedef struct uint64_struct { 51typedef struct uint64_struct {
61 u32 lo; 52 u32 lo;
@@ -69,6 +60,217 @@ typedef union uint64_overlay {
69 60
70} uint64_overlay; 61} uint64_overlay;
71 62
63/*
64 * Optional support for 64-bit double-precision integer multiply and shift.
65 * This code is configurable and is implemented in order to support 32-bit
66 * kernel environments where a 64-bit double-precision math library is not
67 * available.
68 */
69#ifndef ACPI_USE_NATIVE_MATH64
70
71/*******************************************************************************
72 *
73 * FUNCTION: acpi_ut_short_multiply
74 *
75 * PARAMETERS: multiplicand - 64-bit multiplicand
76 * multiplier - 32-bit multiplier
77 * out_product - Pointer to where the product is returned
78 *
79 * DESCRIPTION: Perform a short multiply.
80 *
81 ******************************************************************************/
82
83acpi_status
84acpi_ut_short_multiply(u64 multiplicand, u32 multiplier, u64 *out_product)
85{
86 union uint64_overlay multiplicand_ovl;
87 union uint64_overlay product;
88 u32 carry32;
89
90 ACPI_FUNCTION_TRACE(ut_short_multiply);
91
92 multiplicand_ovl.full = multiplicand;
93
94 /*
95 * The Product is 64 bits, the carry is always 32 bits,
96 * and is generated by the second multiply.
97 */
98 ACPI_MUL_64_BY_32(0, multiplicand_ovl.part.hi, multiplier,
99 product.part.hi, carry32);
100
101 ACPI_MUL_64_BY_32(0, multiplicand_ovl.part.lo, multiplier,
102 product.part.lo, carry32);
103
104 product.part.hi += carry32;
105
106 /* Return only what was requested */
107
108 if (out_product) {
109 *out_product = product.full;
110 }
111
112 return_ACPI_STATUS(AE_OK);
113}
114
115/*******************************************************************************
116 *
117 * FUNCTION: acpi_ut_short_shift_left
118 *
119 * PARAMETERS: operand - 64-bit shift operand
120 * count - 32-bit shift count
121 * out_result - Pointer to where the result is returned
122 *
123 * DESCRIPTION: Perform a short left shift.
124 *
125 ******************************************************************************/
126
127acpi_status acpi_ut_short_shift_left(u64 operand, u32 count, u64 *out_result)
128{
129 union uint64_overlay operand_ovl;
130
131 ACPI_FUNCTION_TRACE(ut_short_shift_left);
132
133 operand_ovl.full = operand;
134
135 if ((count & 63) >= 32) {
136 operand_ovl.part.hi = operand_ovl.part.lo;
137 operand_ovl.part.lo ^= operand_ovl.part.lo;
138 count = (count & 63) - 32;
139 }
140 ACPI_SHIFT_LEFT_64_BY_32(operand_ovl.part.hi,
141 operand_ovl.part.lo, count);
142
143 /* Return only what was requested */
144
145 if (out_result) {
146 *out_result = operand_ovl.full;
147 }
148
149 return_ACPI_STATUS(AE_OK);
150}
151
152/*******************************************************************************
153 *
154 * FUNCTION: acpi_ut_short_shift_right
155 *
156 * PARAMETERS: operand - 64-bit shift operand
157 * count - 32-bit shift count
158 * out_result - Pointer to where the result is returned
159 *
160 * DESCRIPTION: Perform a short right shift.
161 *
162 ******************************************************************************/
163
164acpi_status acpi_ut_short_shift_right(u64 operand, u32 count, u64 *out_result)
165{
166 union uint64_overlay operand_ovl;
167
168 ACPI_FUNCTION_TRACE(ut_short_shift_right);
169
170 operand_ovl.full = operand;
171
172 if ((count & 63) >= 32) {
173 operand_ovl.part.lo = operand_ovl.part.hi;
174 operand_ovl.part.hi ^= operand_ovl.part.hi;
175 count = (count & 63) - 32;
176 }
177 ACPI_SHIFT_RIGHT_64_BY_32(operand_ovl.part.hi,
178 operand_ovl.part.lo, count);
179
180 /* Return only what was requested */
181
182 if (out_result) {
183 *out_result = operand_ovl.full;
184 }
185
186 return_ACPI_STATUS(AE_OK);
187}
188#else
189
190/*******************************************************************************
191 *
192 * FUNCTION: acpi_ut_short_multiply
193 *
194 * PARAMETERS: See function headers above
195 *
196 * DESCRIPTION: Native version of the ut_short_multiply function.
197 *
198 ******************************************************************************/
199
200acpi_status
201acpi_ut_short_multiply(u64 multiplicand, u32 multiplier, u64 *out_product)
202{
203
204 ACPI_FUNCTION_TRACE(ut_short_multiply);
205
206 /* Return only what was requested */
207
208 if (out_product) {
209 *out_product = multiplicand * multiplier;
210 }
211
212 return_ACPI_STATUS(AE_OK);
213}
214
215/*******************************************************************************
216 *
217 * FUNCTION: acpi_ut_short_shift_left
218 *
219 * PARAMETERS: See function headers above
220 *
221 * DESCRIPTION: Native version of the ut_short_shift_left function.
222 *
223 ******************************************************************************/
224
225acpi_status acpi_ut_short_shift_left(u64 operand, u32 count, u64 *out_result)
226{
227
228 ACPI_FUNCTION_TRACE(ut_short_shift_left);
229
230 /* Return only what was requested */
231
232 if (out_result) {
233 *out_result = operand << count;
234 }
235
236 return_ACPI_STATUS(AE_OK);
237}
238
239/*******************************************************************************
240 *
241 * FUNCTION: acpi_ut_short_shift_right
242 *
243 * PARAMETERS: See function headers above
244 *
245 * DESCRIPTION: Native version of the ut_short_shift_right function.
246 *
247 ******************************************************************************/
248
249acpi_status acpi_ut_short_shift_right(u64 operand, u32 count, u64 *out_result)
250{
251
252 ACPI_FUNCTION_TRACE(ut_short_shift_right);
253
254 /* Return only what was requested */
255
256 if (out_result) {
257 *out_result = operand >> count;
258 }
259
260 return_ACPI_STATUS(AE_OK);
261}
262#endif
263
264/*
265 * Optional support for 64-bit double-precision integer divide. This code
266 * is configurable and is implemented in order to support 32-bit kernel
267 * environments where a 64-bit double-precision math library is not available.
268 *
269 * Support for a more normal 64-bit divide/modulo (with check for a divide-
270 * by-zero) appears after this optional section of code.
271 */
272#ifndef ACPI_USE_NATIVE_DIVIDE
273
72/******************************************************************************* 274/*******************************************************************************
73 * 275 *
74 * FUNCTION: acpi_ut_short_divide 276 * FUNCTION: acpi_ut_short_divide
@@ -258,6 +460,7 @@ acpi_ut_divide(u64 in_dividend,
258} 460}
259 461
260#else 462#else
463
261/******************************************************************************* 464/*******************************************************************************
262 * 465 *
263 * FUNCTION: acpi_ut_short_divide, acpi_ut_divide 466 * FUNCTION: acpi_ut_short_divide, acpi_ut_divide
@@ -272,6 +475,7 @@ acpi_ut_divide(u64 in_dividend,
272 * perform the divide. 475 * perform the divide.
273 * 476 *
274 ******************************************************************************/ 477 ******************************************************************************/
478
275acpi_status 479acpi_status
276acpi_ut_short_divide(u64 in_dividend, 480acpi_ut_short_divide(u64 in_dividend,
277 u32 divisor, u64 *out_quotient, u32 *out_remainder) 481 u32 divisor, u64 *out_quotient, u32 *out_remainder)
diff --git a/drivers/acpi/acpica/utmisc.c b/drivers/acpi/acpica/utmisc.c
index 443ffad01209..45c78c2adbf0 100644
--- a/drivers/acpi/acpica/utmisc.c
+++ b/drivers/acpi/acpica/utmisc.c
@@ -224,7 +224,7 @@ acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
224 * 224 *
225 * RETURN: Status 225 * RETURN: Status
226 * 226 *
227 * DESCRIPTION: Walk through a package 227 * DESCRIPTION: Walk through a package, including subpackages
228 * 228 *
229 ******************************************************************************/ 229 ******************************************************************************/
230 230
@@ -236,8 +236,8 @@ acpi_ut_walk_package_tree(union acpi_operand_object *source_object,
236 acpi_status status = AE_OK; 236 acpi_status status = AE_OK;
237 union acpi_generic_state *state_list = NULL; 237 union acpi_generic_state *state_list = NULL;
238 union acpi_generic_state *state; 238 union acpi_generic_state *state;
239 u32 this_index;
240 union acpi_operand_object *this_source_obj; 239 union acpi_operand_object *this_source_obj;
240 u32 this_index;
241 241
242 ACPI_FUNCTION_TRACE(ut_walk_package_tree); 242 ACPI_FUNCTION_TRACE(ut_walk_package_tree);
243 243
@@ -251,8 +251,10 @@ acpi_ut_walk_package_tree(union acpi_operand_object *source_object,
251 /* Get one element of the package */ 251 /* Get one element of the package */
252 252
253 this_index = state->pkg.index; 253 this_index = state->pkg.index;
254 this_source_obj = (union acpi_operand_object *) 254 this_source_obj =
255 state->pkg.source_object->package.elements[this_index]; 255 state->pkg.source_object->package.elements[this_index];
256 state->pkg.this_target_obj =
257 &state->pkg.source_object->package.elements[this_index];
256 258
257 /* 259 /*
258 * Check for: 260 * Check for:
@@ -339,6 +341,8 @@ acpi_ut_walk_package_tree(union acpi_operand_object *source_object,
339 341
340 /* We should never get here */ 342 /* We should never get here */
341 343
344 ACPI_ERROR((AE_INFO, "State list did not terminate correctly"));
345
342 return_ACPI_STATUS(AE_AML_INTERNAL); 346 return_ACPI_STATUS(AE_AML_INTERNAL);
343} 347}
344 348
diff --git a/drivers/acpi/acpica/utobject.c b/drivers/acpi/acpica/utobject.c
index 64e6641bfe82..cb3db9fed50d 100644
--- a/drivers/acpi/acpica/utobject.c
+++ b/drivers/acpi/acpica/utobject.c
@@ -483,6 +483,11 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
483 483
484 /* A namespace node should never get here */ 484 /* A namespace node should never get here */
485 485
486 ACPI_ERROR((AE_INFO,
487 "Received a namespace node [%4.4s] "
488 "where an operand object is required",
489 ACPI_CAST_PTR(struct acpi_namespace_node,
490 internal_object)->name.ascii));
486 return_ACPI_STATUS(AE_AML_INTERNAL); 491 return_ACPI_STATUS(AE_AML_INTERNAL);
487 } 492 }
488 493
diff --git a/drivers/acpi/acpica/utprint.c b/drivers/acpi/acpica/utprint.c
index 7e6e1ae6140f..c008589b41bd 100644
--- a/drivers/acpi/acpica/utprint.c
+++ b/drivers/acpi/acpica/utprint.c
@@ -176,7 +176,7 @@ const char *acpi_ut_scan_number(const char *string, u64 *number_ptr)
176 u64 number = 0; 176 u64 number = 0;
177 177
178 while (isdigit((int)*string)) { 178 while (isdigit((int)*string)) {
179 number *= 10; 179 acpi_ut_short_multiply(number, 10, &number);
180 number += *(string++) - '0'; 180 number += *(string++) - '0';
181 } 181 }
182 182
@@ -286,7 +286,7 @@ static char *acpi_ut_format_number(char *string,
286 /* Generate full string in reverse order */ 286 /* Generate full string in reverse order */
287 287
288 pos = acpi_ut_put_number(reversed_string, number, base, upper); 288 pos = acpi_ut_put_number(reversed_string, number, base, upper);
289 i = ACPI_PTR_DIFF(pos, reversed_string); 289 i = (s32)ACPI_PTR_DIFF(pos, reversed_string);
290 290
291 /* Printing 100 using %2d gives "100", not "00" */ 291 /* Printing 100 using %2d gives "100", not "00" */
292 292
@@ -475,7 +475,7 @@ int vsnprintf(char *string, acpi_size size, const char *format, va_list args)
475 if (!s) { 475 if (!s) {
476 s = "<NULL>"; 476 s = "<NULL>";
477 } 477 }
478 length = acpi_ut_bound_string_length(s, precision); 478 length = (s32)acpi_ut_bound_string_length(s, precision);
479 if (!(type & ACPI_FORMAT_LEFT)) { 479 if (!(type & ACPI_FORMAT_LEFT)) {
480 while (length < width--) { 480 while (length < width--) {
481 pos = 481 pos =
@@ -579,7 +579,7 @@ int vsnprintf(char *string, acpi_size size, const char *format, va_list args)
579 } 579 }
580 } 580 }
581 581
582 return (ACPI_PTR_DIFF(pos, string)); 582 return ((int)ACPI_PTR_DIFF(pos, string));
583} 583}
584 584
585/******************************************************************************* 585/*******************************************************************************
diff --git a/drivers/acpi/acpica/utresrc.c b/drivers/acpi/acpica/utresrc.c
index 70f78a4bf13b..f9801d13547f 100644
--- a/drivers/acpi/acpica/utresrc.c
+++ b/drivers/acpi/acpica/utresrc.c
@@ -237,6 +237,13 @@ acpi_ut_walk_aml_resources(struct acpi_walk_state *walk_state,
237 return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); 237 return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
238 } 238 }
239 239
240 /*
241 * Don't attempt to perform any validation on the 2nd byte.
242 * Although all known ASL compilers insert a zero for the 2nd
243 * byte, it can also be a checksum (as per the ACPI spec),
244 * and this is occasionally seen in the field. July 2017.
245 */
246
240 /* Return the pointer to the end_tag if requested */ 247 /* Return the pointer to the end_tag if requested */
241 248
242 if (!user_function) { 249 if (!user_function) {
diff --git a/drivers/acpi/acpica/utstate.c b/drivers/acpi/acpica/utstate.c
index 64308c304ade..eafabcd2fada 100644
--- a/drivers/acpi/acpica/utstate.c
+++ b/drivers/acpi/acpica/utstate.c
@@ -226,7 +226,7 @@ union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
226 226
227union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object, 227union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
228 void *external_object, 228 void *external_object,
229 u16 index) 229 u32 index)
230{ 230{
231 union acpi_generic_state *state; 231 union acpi_generic_state *state;
232 232
diff --git a/drivers/acpi/acpica/utstrtoul64.c b/drivers/acpi/acpica/utstrtoul64.c
index f42be01d99fd..9633ee142855 100644
--- a/drivers/acpi/acpica/utstrtoul64.c
+++ b/drivers/acpi/acpica/utstrtoul64.c
@@ -276,8 +276,8 @@ static u64 acpi_ut_strtoul_base10(char *string, u32 flags)
276 276
277 /* Convert and insert (add) the decimal digit */ 277 /* Convert and insert (add) the decimal digit */
278 278
279 next_value = 279 acpi_ut_short_multiply(return_value, 10, &next_value);
280 (return_value * 10) + (ascii_digit - ACPI_ASCII_ZERO); 280 next_value += (ascii_digit - ACPI_ASCII_ZERO);
281 281
282 /* Check for overflow (32 or 64 bit) - return current converted value */ 282 /* Check for overflow (32 or 64 bit) - return current converted value */
283 283
@@ -335,9 +335,8 @@ static u64 acpi_ut_strtoul_base16(char *string, u32 flags)
335 335
336 /* Convert and insert the hex digit */ 336 /* Convert and insert the hex digit */
337 337
338 return_value = 338 acpi_ut_short_shift_left(return_value, 4, &return_value);
339 (return_value << 4) | 339 return_value |= acpi_ut_ascii_char_to_hex(ascii_digit);
340 acpi_ut_ascii_char_to_hex(ascii_digit);
341 340
342 string++; 341 string++;
343 valid_digits++; 342 valid_digits++;
diff --git a/drivers/acpi/acpica/uttrack.c b/drivers/acpi/acpica/uttrack.c
index 9a07a42cae34..3c8de88ecbd5 100644
--- a/drivers/acpi/acpica/uttrack.c
+++ b/drivers/acpi/acpica/uttrack.c
@@ -591,6 +591,10 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
591 return_VOID; 591 return_VOID;
592 } 592 }
593 593
594 if (!acpi_gbl_global_list) {
595 goto exit;
596 }
597
594 element = acpi_gbl_global_list->list_head; 598 element = acpi_gbl_global_list->list_head;
595 while (element) { 599 while (element) {
596 if ((element->component & component) && 600 if ((element->component & component) &&
@@ -602,7 +606,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
602 606
603 if (element->size < 607 if (element->size <
604 sizeof(struct acpi_common_descriptor)) { 608 sizeof(struct acpi_common_descriptor)) {
605 acpi_os_printf("%p Length 0x%04X %9.9s-%u " 609 acpi_os_printf("%p Length 0x%04X %9.9s-%4.4u "
606 "[Not a Descriptor - too small]\n", 610 "[Not a Descriptor - too small]\n",
607 descriptor, element->size, 611 descriptor, element->size,
608 element->module, element->line); 612 element->module, element->line);
@@ -612,7 +616,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
612 if (ACPI_GET_DESCRIPTOR_TYPE(descriptor) != 616 if (ACPI_GET_DESCRIPTOR_TYPE(descriptor) !=
613 ACPI_DESC_TYPE_CACHED) { 617 ACPI_DESC_TYPE_CACHED) {
614 acpi_os_printf 618 acpi_os_printf
615 ("%p Length 0x%04X %9.9s-%u [%s] ", 619 ("%p Length 0x%04X %9.9s-%4.4u [%s] ",
616 descriptor, element->size, 620 descriptor, element->size,
617 element->module, element->line, 621 element->module, element->line,
618 acpi_ut_get_descriptor_name 622 acpi_ut_get_descriptor_name
@@ -705,6 +709,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
705 element = element->next; 709 element = element->next;
706 } 710 }
707 711
712exit:
708 (void)acpi_ut_release_mutex(ACPI_MTX_MEMORY); 713 (void)acpi_ut_release_mutex(ACPI_MTX_MEMORY);
709 714
710 /* Print summary */ 715 /* Print summary */
diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
index 6e9f14c0a71b..cb4126051f62 100644
--- a/drivers/acpi/apei/apei-internal.h
+++ b/drivers/acpi/apei/apei-internal.h
@@ -120,11 +120,6 @@ int apei_exec_collect_resources(struct apei_exec_context *ctx,
120struct dentry; 120struct dentry;
121struct dentry *apei_get_debugfs_dir(void); 121struct dentry *apei_get_debugfs_dir(void);
122 122
123#define apei_estatus_for_each_section(estatus, section) \
124 for (section = (struct acpi_hest_generic_data *)(estatus + 1); \
125 (void *)section - (void *)estatus < estatus->data_length; \
126 section = (void *)(section+1) + section->error_data_length)
127
128static inline u32 cper_estatus_len(struct acpi_hest_generic_status *estatus) 123static inline u32 cper_estatus_len(struct acpi_hest_generic_status *estatus)
129{ 124{
130 if (estatus->raw_data_length) 125 if (estatus->raw_data_length)
diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c
index ec50c32ea3da..b38737c83a24 100644
--- a/drivers/acpi/apei/einj.c
+++ b/drivers/acpi/apei/einj.c
@@ -281,7 +281,7 @@ static struct acpi_generic_address *einj_get_trigger_parameter_region(
281 ((char *)trigger_tab + sizeof(struct acpi_einj_trigger)); 281 ((char *)trigger_tab + sizeof(struct acpi_einj_trigger));
282 for (i = 0; i < trigger_tab->entry_count; i++) { 282 for (i = 0; i < trigger_tab->entry_count; i++) {
283 if (entry->action == ACPI_EINJ_TRIGGER_ERROR && 283 if (entry->action == ACPI_EINJ_TRIGGER_ERROR &&
284 entry->instruction == ACPI_EINJ_WRITE_REGISTER_VALUE && 284 entry->instruction <= ACPI_EINJ_WRITE_REGISTER_VALUE &&
285 entry->register_region.space_id == 285 entry->register_region.space_id ==
286 ACPI_ADR_SPACE_SYSTEM_MEMORY && 286 ACPI_ADR_SPACE_SYSTEM_MEMORY &&
287 (entry->register_region.address & param2) == (param1 & param2)) 287 (entry->register_region.address & param2) == (param1 & param2))
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index d661d452b238..077f9bad6f44 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -1157,7 +1157,8 @@ static int ghes_probe(struct platform_device *ghes_dev)
1157 generic->header.source_id); 1157 generic->header.source_id);
1158 goto err_edac_unreg; 1158 goto err_edac_unreg;
1159 } 1159 }
1160 rc = request_irq(ghes->irq, ghes_irq_func, 0, "GHES IRQ", ghes); 1160 rc = request_irq(ghes->irq, ghes_irq_func, IRQF_SHARED,
1161 "GHES IRQ", ghes);
1161 if (rc) { 1162 if (rc) {
1162 pr_err(GHES_PFX "Failed to register IRQ for generic hardware error source: %d\n", 1163 pr_err(GHES_PFX "Failed to register IRQ for generic hardware error source: %d\n",
1163 generic->header.source_id); 1164 generic->header.source_id);
@@ -1265,9 +1266,14 @@ static int __init ghes_init(void)
1265 if (acpi_disabled) 1266 if (acpi_disabled)
1266 return -ENODEV; 1267 return -ENODEV;
1267 1268
1268 if (hest_disable) { 1269 switch (hest_disable) {
1270 case HEST_NOT_FOUND:
1271 return -ENODEV;
1272 case HEST_DISABLED:
1269 pr_info(GHES_PFX "HEST is not enabled!\n"); 1273 pr_info(GHES_PFX "HEST is not enabled!\n");
1270 return -EINVAL; 1274 return -EINVAL;
1275 default:
1276 break;
1271 } 1277 }
1272 1278
1273 if (ghes_disable) { 1279 if (ghes_disable) {
diff --git a/drivers/acpi/apei/hest.c b/drivers/acpi/apei/hest.c
index 456b488eb1df..9cb74115a43d 100644
--- a/drivers/acpi/apei/hest.c
+++ b/drivers/acpi/apei/hest.c
@@ -37,7 +37,7 @@
37 37
38#define HEST_PFX "HEST: " 38#define HEST_PFX "HEST: "
39 39
40bool hest_disable; 40int hest_disable;
41EXPORT_SYMBOL_GPL(hest_disable); 41EXPORT_SYMBOL_GPL(hest_disable);
42 42
43/* HEST table parsing */ 43/* HEST table parsing */
@@ -213,7 +213,7 @@ err:
213 213
214static int __init setup_hest_disable(char *str) 214static int __init setup_hest_disable(char *str)
215{ 215{
216 hest_disable = 1; 216 hest_disable = HEST_DISABLED;
217 return 0; 217 return 0;
218} 218}
219 219
@@ -232,9 +232,10 @@ void __init acpi_hest_init(void)
232 232
233 status = acpi_get_table(ACPI_SIG_HEST, 0, 233 status = acpi_get_table(ACPI_SIG_HEST, 0,
234 (struct acpi_table_header **)&hest_tab); 234 (struct acpi_table_header **)&hest_tab);
235 if (status == AE_NOT_FOUND) 235 if (status == AE_NOT_FOUND) {
236 goto err; 236 hest_disable = HEST_NOT_FOUND;
237 else if (ACPI_FAILURE(status)) { 237 return;
238 } else if (ACPI_FAILURE(status)) {
238 const char *msg = acpi_format_exception(status); 239 const char *msg = acpi_format_exception(status);
239 pr_err(HEST_PFX "Failed to get table, %s\n", msg); 240 pr_err(HEST_PFX "Failed to get table, %s\n", msg);
240 rc = -EINVAL; 241 rc = -EINVAL;
@@ -257,5 +258,5 @@ void __init acpi_hest_init(void)
257 pr_info(HEST_PFX "Table parsing has been initialized.\n"); 258 pr_info(HEST_PFX "Table parsing has been initialized.\n");
258 return; 259 return;
259err: 260err:
260 hest_disable = 1; 261 hest_disable = HEST_DISABLED;
261} 262}
diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index 736783c67ea0..9565d572f8dd 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -693,13 +693,36 @@ static int iort_pci_iommu_init(struct pci_dev *pdev, u16 alias, void *data)
693 return iort_iommu_xlate(info->dev, parent, streamid); 693 return iort_iommu_xlate(info->dev, parent, streamid);
694} 694}
695 695
696static int nc_dma_get_range(struct device *dev, u64 *size)
697{
698 struct acpi_iort_node *node;
699 struct acpi_iort_named_component *ncomp;
700
701 node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT,
702 iort_match_node_callback, dev);
703 if (!node)
704 return -ENODEV;
705
706 ncomp = (struct acpi_iort_named_component *)node->node_data;
707
708 *size = ncomp->memory_address_limit >= 64 ? U64_MAX :
709 1ULL<<ncomp->memory_address_limit;
710
711 return 0;
712}
713
696/** 714/**
697 * iort_set_dma_mask - Set-up dma mask for a device. 715 * iort_dma_setup() - Set-up device DMA parameters.
698 * 716 *
699 * @dev: device to configure 717 * @dev: device to configure
718 * @dma_addr: device DMA address result pointer
719 * @size: DMA range size result pointer
700 */ 720 */
701void iort_set_dma_mask(struct device *dev) 721void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
702{ 722{
723 u64 mask, dmaaddr = 0, size = 0, offset = 0;
724 int ret, msb;
725
703 /* 726 /*
704 * Set default coherent_dma_mask to 32 bit. Drivers are expected to 727 * Set default coherent_dma_mask to 32 bit. Drivers are expected to
705 * setup the correct supported mask. 728 * setup the correct supported mask.
@@ -713,6 +736,36 @@ void iort_set_dma_mask(struct device *dev)
713 */ 736 */
714 if (!dev->dma_mask) 737 if (!dev->dma_mask)
715 dev->dma_mask = &dev->coherent_dma_mask; 738 dev->dma_mask = &dev->coherent_dma_mask;
739
740 size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
741
742 if (dev_is_pci(dev))
743 ret = acpi_dma_get_range(dev, &dmaaddr, &offset, &size);
744 else
745 ret = nc_dma_get_range(dev, &size);
746
747 if (!ret) {
748 msb = fls64(dmaaddr + size - 1);
749 /*
750 * Round-up to the power-of-two mask or set
751 * the mask to the whole 64-bit address space
752 * in case the DMA region covers the full
753 * memory window.
754 */
755 mask = msb == 64 ? U64_MAX : (1ULL << msb) - 1;
756 /*
757 * Limit coherent and dma mask based on size
758 * retrieved from firmware.
759 */
760 dev->coherent_dma_mask = mask;
761 *dev->dma_mask = mask;
762 }
763
764 *dma_addr = dmaaddr;
765 *dma_size = size;
766
767 dev->dma_pfn_offset = PFN_DOWN(offset);
768 dev_dbg(dev, "dma_pfn_offset(%#08llx)\n", offset);
716} 769}
717 770
718/** 771/**
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 1cbb88d938e5..13e7b56e33ae 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -620,7 +620,7 @@ static ssize_t acpi_battery_alarm_store(struct device *dev,
620 return count; 620 return count;
621} 621}
622 622
623static struct device_attribute alarm_attr = { 623static const struct device_attribute alarm_attr = {
624 .attr = {.name = "alarm", .mode = 0644}, 624 .attr = {.name = "alarm", .mode = 0644},
625 .show = acpi_battery_alarm_show, 625 .show = acpi_battery_alarm_show,
626 .store = acpi_battery_alarm_store, 626 .store = acpi_battery_alarm_store,
diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
index bb542acc0574..037fd537bbf6 100644
--- a/drivers/acpi/blacklist.c
+++ b/drivers/acpi/blacklist.c
@@ -30,30 +30,13 @@
30 30
31#include "internal.h" 31#include "internal.h"
32 32
33enum acpi_blacklist_predicates {
34 all_versions,
35 less_than_or_equal,
36 equal,
37 greater_than_or_equal,
38};
39
40struct acpi_blacklist_item {
41 char oem_id[7];
42 char oem_table_id[9];
43 u32 oem_revision;
44 char *table;
45 enum acpi_blacklist_predicates oem_revision_predicate;
46 char *reason;
47 u32 is_critical_error;
48};
49
50static struct dmi_system_id acpi_rev_dmi_table[] __initdata; 33static struct dmi_system_id acpi_rev_dmi_table[] __initdata;
51 34
52/* 35/*
53 * POLICY: If *anything* doesn't work, put it on the blacklist. 36 * POLICY: If *anything* doesn't work, put it on the blacklist.
54 * If they are critical errors, mark it critical, and abort driver load. 37 * If they are critical errors, mark it critical, and abort driver load.
55 */ 38 */
56static struct acpi_blacklist_item acpi_blacklist[] __initdata = { 39static struct acpi_platform_list acpi_blacklist[] __initdata = {
57 /* Compaq Presario 1700 */ 40 /* Compaq Presario 1700 */
58 {"PTLTD ", " DSDT ", 0x06040000, ACPI_SIG_DSDT, less_than_or_equal, 41 {"PTLTD ", " DSDT ", 0x06040000, ACPI_SIG_DSDT, less_than_or_equal,
59 "Multiple problems", 1}, 42 "Multiple problems", 1},
@@ -67,65 +50,27 @@ static struct acpi_blacklist_item acpi_blacklist[] __initdata = {
67 {"IBM ", "TP600E ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal, 50 {"IBM ", "TP600E ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal,
68 "Incorrect _ADR", 1}, 51 "Incorrect _ADR", 1},
69 52
70 {""} 53 { }
71}; 54};
72 55
73int __init acpi_blacklisted(void) 56int __init acpi_blacklisted(void)
74{ 57{
75 int i = 0; 58 int i;
76 int blacklisted = 0; 59 int blacklisted = 0;
77 struct acpi_table_header table_header;
78
79 while (acpi_blacklist[i].oem_id[0] != '\0') {
80 if (acpi_get_table_header(acpi_blacklist[i].table, 0, &table_header)) {
81 i++;
82 continue;
83 }
84
85 if (strncmp(acpi_blacklist[i].oem_id, table_header.oem_id, 6)) {
86 i++;
87 continue;
88 }
89
90 if (strncmp
91 (acpi_blacklist[i].oem_table_id, table_header.oem_table_id,
92 8)) {
93 i++;
94 continue;
95 }
96
97 if ((acpi_blacklist[i].oem_revision_predicate == all_versions)
98 || (acpi_blacklist[i].oem_revision_predicate ==
99 less_than_or_equal
100 && table_header.oem_revision <=
101 acpi_blacklist[i].oem_revision)
102 || (acpi_blacklist[i].oem_revision_predicate ==
103 greater_than_or_equal
104 && table_header.oem_revision >=
105 acpi_blacklist[i].oem_revision)
106 || (acpi_blacklist[i].oem_revision_predicate == equal
107 && table_header.oem_revision ==
108 acpi_blacklist[i].oem_revision)) {
109 60
110 printk(KERN_ERR PREFIX 61 i = acpi_match_platform_list(acpi_blacklist);
111 "Vendor \"%6.6s\" System \"%8.8s\" " 62 if (i >= 0) {
112 "Revision 0x%x has a known ACPI BIOS problem.\n", 63 pr_err(PREFIX "Vendor \"%6.6s\" System \"%8.8s\" Revision 0x%x has a known ACPI BIOS problem.\n",
113 acpi_blacklist[i].oem_id, 64 acpi_blacklist[i].oem_id,
114 acpi_blacklist[i].oem_table_id, 65 acpi_blacklist[i].oem_table_id,
115 acpi_blacklist[i].oem_revision); 66 acpi_blacklist[i].oem_revision);
116 67
117 printk(KERN_ERR PREFIX 68 pr_err(PREFIX "Reason: %s. This is a %s error\n",
118 "Reason: %s. This is a %s error\n", 69 acpi_blacklist[i].reason,
119 acpi_blacklist[i].reason, 70 (acpi_blacklist[i].data ?
120 (acpi_blacklist[i]. 71 "non-recoverable" : "recoverable"));
121 is_critical_error ? "non-recoverable" :
122 "recoverable"));
123 72
124 blacklisted = acpi_blacklist[i].is_critical_error; 73 blacklisted = acpi_blacklist[i].data;
125 break;
126 } else {
127 i++;
128 }
129 } 74 }
130 75
131 (void)early_acpi_osi_init(); 76 (void)early_acpi_osi_init();
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index af74b420ec83..59f2f96fdb7e 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -995,9 +995,6 @@ void __init acpi_early_init(void)
995 995
996 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION); 996 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
997 997
998 /* It's safe to verify table checksums during late stage */
999 acpi_gbl_verify_table_checksum = TRUE;
1000
1001 /* enable workarounds, unless strict ACPI spec. compliance */ 998 /* enable workarounds, unless strict ACPI spec. compliance */
1002 if (!acpi_strict) 999 if (!acpi_strict)
1003 acpi_gbl_enable_interpreter_slack = TRUE; 1000 acpi_gbl_enable_interpreter_slack = TRUE;
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 2ed6935d4483..fbcc73f7a099 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -401,6 +401,8 @@ static void acpi_pm_notify_handler(acpi_handle handle, u32 val, void *not_used)
401 if (val != ACPI_NOTIFY_DEVICE_WAKE) 401 if (val != ACPI_NOTIFY_DEVICE_WAKE)
402 return; 402 return;
403 403
404 acpi_handle_debug(handle, "Wake notify\n");
405
404 adev = acpi_bus_get_acpi_device(handle); 406 adev = acpi_bus_get_acpi_device(handle);
405 if (!adev) 407 if (!adev)
406 return; 408 return;
@@ -409,8 +411,12 @@ static void acpi_pm_notify_handler(acpi_handle handle, u32 val, void *not_used)
409 411
410 if (adev->wakeup.flags.notifier_present) { 412 if (adev->wakeup.flags.notifier_present) {
411 pm_wakeup_ws_event(adev->wakeup.ws, 0, acpi_s2idle_wakeup()); 413 pm_wakeup_ws_event(adev->wakeup.ws, 0, acpi_s2idle_wakeup());
412 if (adev->wakeup.context.func) 414 if (adev->wakeup.context.func) {
415 acpi_handle_debug(handle, "Running %pF for %s\n",
416 adev->wakeup.context.func,
417 dev_name(adev->wakeup.context.dev));
413 adev->wakeup.context.func(&adev->wakeup.context); 418 adev->wakeup.context.func(&adev->wakeup.context);
419 }
414 } 420 }
415 421
416 mutex_unlock(&acpi_pm_notifier_lock); 422 mutex_unlock(&acpi_pm_notifier_lock);
@@ -682,55 +688,88 @@ static void acpi_pm_notify_work_func(struct acpi_device_wakeup_context *context)
682 } 688 }
683} 689}
684 690
691static DEFINE_MUTEX(acpi_wakeup_lock);
692
693static int __acpi_device_wakeup_enable(struct acpi_device *adev,
694 u32 target_state, int max_count)
695{
696 struct acpi_device_wakeup *wakeup = &adev->wakeup;
697 acpi_status status;
698 int error = 0;
699
700 mutex_lock(&acpi_wakeup_lock);
701
702 if (wakeup->enable_count >= max_count)
703 goto out;
704
705 if (wakeup->enable_count > 0)
706 goto inc;
707
708 error = acpi_enable_wakeup_device_power(adev, target_state);
709 if (error)
710 goto out;
711
712 status = acpi_enable_gpe(wakeup->gpe_device, wakeup->gpe_number);
713 if (ACPI_FAILURE(status)) {
714 acpi_disable_wakeup_device_power(adev);
715 error = -EIO;
716 goto out;
717 }
718
719inc:
720 wakeup->enable_count++;
721
722out:
723 mutex_unlock(&acpi_wakeup_lock);
724 return error;
725}
726
685/** 727/**
686 * acpi_device_wakeup - Enable/disable wakeup functionality for device. 728 * acpi_device_wakeup_enable - Enable wakeup functionality for device.
687 * @adev: ACPI device to enable/disable wakeup functionality for. 729 * @adev: ACPI device to enable wakeup functionality for.
688 * @target_state: State the system is transitioning into. 730 * @target_state: State the system is transitioning into.
689 * @enable: Whether to enable or disable the wakeup functionality.
690 * 731 *
691 * Enable/disable the GPE associated with @adev so that it can generate 732 * Enable the GPE associated with @adev so that it can generate wakeup signals
692 * wakeup signals for the device in response to external (remote) events and 733 * for the device in response to external (remote) events and enable wakeup
693 * enable/disable device wakeup power. 734 * power for it.
735 *
736 * Callers must ensure that @adev is a valid ACPI device node before executing
737 * this function.
738 */
739static int acpi_device_wakeup_enable(struct acpi_device *adev, u32 target_state)
740{
741 return __acpi_device_wakeup_enable(adev, target_state, 1);
742}
743
744/**
745 * acpi_device_wakeup_disable - Disable wakeup functionality for device.
746 * @adev: ACPI device to disable wakeup functionality for.
747 *
748 * Disable the GPE associated with @adev and disable wakeup power for it.
694 * 749 *
695 * Callers must ensure that @adev is a valid ACPI device node before executing 750 * Callers must ensure that @adev is a valid ACPI device node before executing
696 * this function. 751 * this function.
697 */ 752 */
698static int acpi_device_wakeup(struct acpi_device *adev, u32 target_state, 753static void acpi_device_wakeup_disable(struct acpi_device *adev)
699 bool enable)
700{ 754{
701 struct acpi_device_wakeup *wakeup = &adev->wakeup; 755 struct acpi_device_wakeup *wakeup = &adev->wakeup;
702 756
703 if (enable) { 757 mutex_lock(&acpi_wakeup_lock);
704 acpi_status res;
705 int error;
706 758
707 if (adev->wakeup.flags.enabled) 759 if (!wakeup->enable_count)
708 return 0; 760 goto out;
709 761
710 error = acpi_enable_wakeup_device_power(adev, target_state); 762 acpi_disable_gpe(wakeup->gpe_device, wakeup->gpe_number);
711 if (error) 763 acpi_disable_wakeup_device_power(adev);
712 return error;
713 764
714 res = acpi_enable_gpe(wakeup->gpe_device, wakeup->gpe_number); 765 wakeup->enable_count--;
715 if (ACPI_FAILURE(res)) { 766
716 acpi_disable_wakeup_device_power(adev); 767out:
717 return -EIO; 768 mutex_unlock(&acpi_wakeup_lock);
718 }
719 adev->wakeup.flags.enabled = 1;
720 } else if (adev->wakeup.flags.enabled) {
721 acpi_disable_gpe(wakeup->gpe_device, wakeup->gpe_number);
722 acpi_disable_wakeup_device_power(adev);
723 adev->wakeup.flags.enabled = 0;
724 }
725 return 0;
726} 769}
727 770
728/** 771static int __acpi_pm_set_device_wakeup(struct device *dev, bool enable,
729 * acpi_pm_set_device_wakeup - Enable/disable remote wakeup for given device. 772 int max_count)
730 * @dev: Device to enable/disable to generate wakeup events.
731 * @enable: Whether to enable or disable the wakeup functionality.
732 */
733int acpi_pm_set_device_wakeup(struct device *dev, bool enable)
734{ 773{
735 struct acpi_device *adev; 774 struct acpi_device *adev;
736 int error; 775 int error;
@@ -744,13 +783,41 @@ int acpi_pm_set_device_wakeup(struct device *dev, bool enable)
744 if (!acpi_device_can_wakeup(adev)) 783 if (!acpi_device_can_wakeup(adev))
745 return -EINVAL; 784 return -EINVAL;
746 785
747 error = acpi_device_wakeup(adev, acpi_target_system_state(), enable); 786 if (!enable) {
787 acpi_device_wakeup_disable(adev);
788 dev_dbg(dev, "Wakeup disabled by ACPI\n");
789 return 0;
790 }
791
792 error = __acpi_device_wakeup_enable(adev, acpi_target_system_state(),
793 max_count);
748 if (!error) 794 if (!error)
749 dev_dbg(dev, "Wakeup %s by ACPI\n", enable ? "enabled" : "disabled"); 795 dev_dbg(dev, "Wakeup enabled by ACPI\n");
750 796
751 return error; 797 return error;
752} 798}
753EXPORT_SYMBOL(acpi_pm_set_device_wakeup); 799
800/**
801 * acpi_pm_set_device_wakeup - Enable/disable remote wakeup for given device.
802 * @dev: Device to enable/disable to generate wakeup events.
803 * @enable: Whether to enable or disable the wakeup functionality.
804 */
805int acpi_pm_set_device_wakeup(struct device *dev, bool enable)
806{
807 return __acpi_pm_set_device_wakeup(dev, enable, 1);
808}
809EXPORT_SYMBOL_GPL(acpi_pm_set_device_wakeup);
810
811/**
812 * acpi_pm_set_bridge_wakeup - Enable/disable remote wakeup for given bridge.
813 * @dev: Bridge device to enable/disable to generate wakeup events.
814 * @enable: Whether to enable or disable the wakeup functionality.
815 */
816int acpi_pm_set_bridge_wakeup(struct device *dev, bool enable)
817{
818 return __acpi_pm_set_device_wakeup(dev, enable, INT_MAX);
819}
820EXPORT_SYMBOL_GPL(acpi_pm_set_bridge_wakeup);
754 821
755/** 822/**
756 * acpi_dev_pm_low_power - Put ACPI device into a low-power state. 823 * acpi_dev_pm_low_power - Put ACPI device into a low-power state.
@@ -800,13 +867,15 @@ int acpi_dev_runtime_suspend(struct device *dev)
800 867
801 remote_wakeup = dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) > 868 remote_wakeup = dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) >
802 PM_QOS_FLAGS_NONE; 869 PM_QOS_FLAGS_NONE;
803 error = acpi_device_wakeup(adev, ACPI_STATE_S0, remote_wakeup); 870 if (remote_wakeup) {
804 if (remote_wakeup && error) 871 error = acpi_device_wakeup_enable(adev, ACPI_STATE_S0);
805 return -EAGAIN; 872 if (error)
873 return -EAGAIN;
874 }
806 875
807 error = acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0); 876 error = acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
808 if (error) 877 if (error && remote_wakeup)
809 acpi_device_wakeup(adev, ACPI_STATE_S0, false); 878 acpi_device_wakeup_disable(adev);
810 879
811 return error; 880 return error;
812} 881}
@@ -829,7 +898,7 @@ int acpi_dev_runtime_resume(struct device *dev)
829 return 0; 898 return 0;
830 899
831 error = acpi_dev_pm_full_power(adev); 900 error = acpi_dev_pm_full_power(adev);
832 acpi_device_wakeup(adev, ACPI_STATE_S0, false); 901 acpi_device_wakeup_disable(adev);
833 return error; 902 return error;
834} 903}
835EXPORT_SYMBOL_GPL(acpi_dev_runtime_resume); 904EXPORT_SYMBOL_GPL(acpi_dev_runtime_resume);
@@ -884,13 +953,15 @@ int acpi_dev_suspend_late(struct device *dev)
884 953
885 target_state = acpi_target_system_state(); 954 target_state = acpi_target_system_state();
886 wakeup = device_may_wakeup(dev) && acpi_device_can_wakeup(adev); 955 wakeup = device_may_wakeup(dev) && acpi_device_can_wakeup(adev);
887 error = acpi_device_wakeup(adev, target_state, wakeup); 956 if (wakeup) {
888 if (wakeup && error) 957 error = acpi_device_wakeup_enable(adev, target_state);
889 return error; 958 if (error)
959 return error;
960 }
890 961
891 error = acpi_dev_pm_low_power(dev, adev, target_state); 962 error = acpi_dev_pm_low_power(dev, adev, target_state);
892 if (error) 963 if (error && wakeup)
893 acpi_device_wakeup(adev, ACPI_STATE_UNKNOWN, false); 964 acpi_device_wakeup_disable(adev);
894 965
895 return error; 966 return error;
896} 967}
@@ -913,7 +984,7 @@ int acpi_dev_resume_early(struct device *dev)
913 return 0; 984 return 0;
914 985
915 error = acpi_dev_pm_full_power(adev); 986 error = acpi_dev_pm_full_power(adev);
916 acpi_device_wakeup(adev, ACPI_STATE_UNKNOWN, false); 987 acpi_device_wakeup_disable(adev);
917 return error; 988 return error;
918} 989}
919EXPORT_SYMBOL_GPL(acpi_dev_resume_early); 990EXPORT_SYMBOL_GPL(acpi_dev_resume_early);
@@ -1056,7 +1127,7 @@ static void acpi_dev_pm_detach(struct device *dev, bool power_off)
1056 */ 1127 */
1057 dev_pm_qos_hide_latency_limit(dev); 1128 dev_pm_qos_hide_latency_limit(dev);
1058 dev_pm_qos_hide_flags(dev); 1129 dev_pm_qos_hide_flags(dev);
1059 acpi_device_wakeup(adev, ACPI_STATE_S0, false); 1130 acpi_device_wakeup_disable(adev);
1060 acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0); 1131 acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
1061 } 1132 }
1062 } 1133 }
@@ -1100,7 +1171,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
1100 dev_pm_domain_set(dev, &acpi_general_pm_domain); 1171 dev_pm_domain_set(dev, &acpi_general_pm_domain);
1101 if (power_on) { 1172 if (power_on) {
1102 acpi_dev_pm_full_power(adev); 1173 acpi_dev_pm_full_power(adev);
1103 acpi_device_wakeup(adev, ACPI_STATE_S0, false); 1174 acpi_device_wakeup_disable(adev);
1104 } 1175 }
1105 1176
1106 dev->pm_domain->detach = acpi_dev_pm_detach; 1177 dev->pm_domain->detach = acpi_dev_pm_detach;
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 0c00208b423e..2305e1ab978e 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -585,7 +585,7 @@ static struct attribute *dock_attributes[] = {
585 NULL 585 NULL
586}; 586};
587 587
588static struct attribute_group dock_attribute_group = { 588static const struct attribute_group dock_attribute_group = {
589 .attrs = dock_attributes 589 .attrs = dock_attributes
590}; 590};
591 591
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index ae3d6d152633..fdfae6f3c0b1 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -112,8 +112,7 @@ enum {
112 EC_FLAGS_EVT_HANDLER_INSTALLED, /* _Qxx handlers installed */ 112 EC_FLAGS_EVT_HANDLER_INSTALLED, /* _Qxx handlers installed */
113 EC_FLAGS_STARTED, /* Driver is started */ 113 EC_FLAGS_STARTED, /* Driver is started */
114 EC_FLAGS_STOPPED, /* Driver is stopped */ 114 EC_FLAGS_STOPPED, /* Driver is stopped */
115 EC_FLAGS_COMMAND_STORM, /* GPE storms occurred to the 115 EC_FLAGS_GPE_MASKED, /* GPE masked */
116 * current command processing */
117}; 116};
118 117
119#define ACPI_EC_COMMAND_POLL 0x01 /* Available for command byte */ 118#define ACPI_EC_COMMAND_POLL 0x01 /* Available for command byte */
@@ -425,19 +424,19 @@ static void acpi_ec_complete_request(struct acpi_ec *ec)
425 wake_up(&ec->wait); 424 wake_up(&ec->wait);
426} 425}
427 426
428static void acpi_ec_set_storm(struct acpi_ec *ec, u8 flag) 427static void acpi_ec_mask_gpe(struct acpi_ec *ec)
429{ 428{
430 if (!test_bit(flag, &ec->flags)) { 429 if (!test_bit(EC_FLAGS_GPE_MASKED, &ec->flags)) {
431 acpi_ec_disable_gpe(ec, false); 430 acpi_ec_disable_gpe(ec, false);
432 ec_dbg_drv("Polling enabled"); 431 ec_dbg_drv("Polling enabled");
433 set_bit(flag, &ec->flags); 432 set_bit(EC_FLAGS_GPE_MASKED, &ec->flags);
434 } 433 }
435} 434}
436 435
437static void acpi_ec_clear_storm(struct acpi_ec *ec, u8 flag) 436static void acpi_ec_unmask_gpe(struct acpi_ec *ec)
438{ 437{
439 if (test_bit(flag, &ec->flags)) { 438 if (test_bit(EC_FLAGS_GPE_MASKED, &ec->flags)) {
440 clear_bit(flag, &ec->flags); 439 clear_bit(EC_FLAGS_GPE_MASKED, &ec->flags);
441 acpi_ec_enable_gpe(ec, false); 440 acpi_ec_enable_gpe(ec, false);
442 ec_dbg_drv("Polling disabled"); 441 ec_dbg_drv("Polling disabled");
443 } 442 }
@@ -464,7 +463,7 @@ static bool acpi_ec_submit_flushable_request(struct acpi_ec *ec)
464 463
465static void acpi_ec_submit_query(struct acpi_ec *ec) 464static void acpi_ec_submit_query(struct acpi_ec *ec)
466{ 465{
467 acpi_ec_set_storm(ec, EC_FLAGS_COMMAND_STORM); 466 acpi_ec_mask_gpe(ec);
468 if (!acpi_ec_event_enabled(ec)) 467 if (!acpi_ec_event_enabled(ec))
469 return; 468 return;
470 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) { 469 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) {
@@ -480,7 +479,7 @@ static void acpi_ec_complete_query(struct acpi_ec *ec)
480 if (test_and_clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) 479 if (test_and_clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
481 ec_dbg_evt("Command(%s) unblocked", 480 ec_dbg_evt("Command(%s) unblocked",
482 acpi_ec_cmd_string(ACPI_EC_COMMAND_QUERY)); 481 acpi_ec_cmd_string(ACPI_EC_COMMAND_QUERY));
483 acpi_ec_clear_storm(ec, EC_FLAGS_COMMAND_STORM); 482 acpi_ec_unmask_gpe(ec);
484} 483}
485 484
486static inline void __acpi_ec_enable_event(struct acpi_ec *ec) 485static inline void __acpi_ec_enable_event(struct acpi_ec *ec)
@@ -700,7 +699,7 @@ err:
700 ++t->irq_count; 699 ++t->irq_count;
701 /* Allow triggering on 0 threshold */ 700 /* Allow triggering on 0 threshold */
702 if (t->irq_count == ec_storm_threshold) 701 if (t->irq_count == ec_storm_threshold)
703 acpi_ec_set_storm(ec, EC_FLAGS_COMMAND_STORM); 702 acpi_ec_mask_gpe(ec);
704 } 703 }
705 } 704 }
706out: 705out:
@@ -798,7 +797,7 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
798 797
799 spin_lock_irqsave(&ec->lock, tmp); 798 spin_lock_irqsave(&ec->lock, tmp);
800 if (t->irq_count == ec_storm_threshold) 799 if (t->irq_count == ec_storm_threshold)
801 acpi_ec_clear_storm(ec, EC_FLAGS_COMMAND_STORM); 800 acpi_ec_unmask_gpe(ec);
802 ec_dbg_req("Command(%s) stopped", acpi_ec_cmd_string(t->command)); 801 ec_dbg_req("Command(%s) stopped", acpi_ec_cmd_string(t->command));
803 ec->curr = NULL; 802 ec->curr = NULL;
804 /* Disable GPE for command processing (IBF=0/OBF=1) */ 803 /* Disable GPE for command processing (IBF=0/OBF=1) */
@@ -1586,9 +1585,7 @@ static bool acpi_is_boot_ec(struct acpi_ec *ec)
1586{ 1585{
1587 if (!boot_ec) 1586 if (!boot_ec)
1588 return false; 1587 return false;
1589 if (ec->handle == boot_ec->handle && 1588 if (ec->command_addr == boot_ec->command_addr &&
1590 ec->gpe == boot_ec->gpe &&
1591 ec->command_addr == boot_ec->command_addr &&
1592 ec->data_addr == boot_ec->data_addr) 1589 ec->data_addr == boot_ec->data_addr)
1593 return true; 1590 return true;
1594 return false; 1591 return false;
@@ -1613,6 +1610,13 @@ static int acpi_ec_add(struct acpi_device *device)
1613 1610
1614 if (acpi_is_boot_ec(ec)) { 1611 if (acpi_is_boot_ec(ec)) {
1615 boot_ec_is_ecdt = false; 1612 boot_ec_is_ecdt = false;
1613 /*
1614 * Trust PNP0C09 namespace location rather than ECDT ID.
1615 *
1616 * But trust ECDT GPE rather than _GPE because of ASUS quirks,
1617 * so do not change boot_ec->gpe to ec->gpe.
1618 */
1619 boot_ec->handle = ec->handle;
1616 acpi_handle_debug(ec->handle, "duplicated.\n"); 1620 acpi_handle_debug(ec->handle, "duplicated.\n");
1617 acpi_ec_free(ec); 1621 acpi_ec_free(ec);
1618 ec = boot_ec; 1622 ec = boot_ec;
@@ -1747,18 +1751,20 @@ static int __init acpi_ec_ecdt_start(void)
1747 1751
1748 if (!boot_ec) 1752 if (!boot_ec)
1749 return -ENODEV; 1753 return -ENODEV;
1750 /* 1754 /* In case acpi_ec_ecdt_start() is called after acpi_ec_add() */
1751 * The DSDT EC should have already been started in
1752 * acpi_ec_add().
1753 */
1754 if (!boot_ec_is_ecdt) 1755 if (!boot_ec_is_ecdt)
1755 return -ENODEV; 1756 return -ENODEV;
1756 1757
1757 /* 1758 /*
1758 * At this point, the namespace and the GPE is initialized, so 1759 * At this point, the namespace and the GPE is initialized, so
1759 * start to find the namespace objects and handle the events. 1760 * start to find the namespace objects and handle the events.
1761 *
1762 * Note: ec->handle can be valid if this function is called after
1763 * acpi_ec_add(), hence the fast path.
1760 */ 1764 */
1761 if (!acpi_ec_ecdt_get_handle(&handle)) 1765 if (boot_ec->handle != ACPI_ROOT_OBJECT)
1766 handle = boot_ec->handle;
1767 else if (!acpi_ec_ecdt_get_handle(&handle))
1762 return -ENODEV; 1768 return -ENODEV;
1763 return acpi_config_boot_ec(boot_ec, handle, true, true); 1769 return acpi_config_boot_ec(boot_ec, handle, true, true);
1764} 1770}
@@ -2011,8 +2017,8 @@ int __init acpi_ec_init(void)
2011 return result; 2017 return result;
2012 2018
2013 /* Drivers must be started after acpi_ec_query_init() */ 2019 /* Drivers must be started after acpi_ec_query_init() */
2014 ecdt_fail = acpi_ec_ecdt_start();
2015 dsdt_fail = acpi_bus_register_driver(&acpi_ec_driver); 2020 dsdt_fail = acpi_bus_register_driver(&acpi_ec_driver);
2021 ecdt_fail = acpi_ec_ecdt_start();
2016 return ecdt_fail && dsdt_fail ? -ENODEV : 0; 2022 return ecdt_fail && dsdt_fail ? -ENODEV : 0;
2017} 2023}
2018 2024
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 3f5af4d7a739..4361c4415b4f 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -232,6 +232,12 @@ static inline void suspend_nvs_restore(void) {}
232void acpi_init_properties(struct acpi_device *adev); 232void acpi_init_properties(struct acpi_device *adev);
233void acpi_free_properties(struct acpi_device *adev); 233void acpi_free_properties(struct acpi_device *adev);
234 234
235#ifdef CONFIG_X86
236void acpi_extract_apple_properties(struct acpi_device *adev);
237#else
238static inline void acpi_extract_apple_properties(struct acpi_device *adev) {}
239#endif
240
235/*-------------------------------------------------------------------------- 241/*--------------------------------------------------------------------------
236 Watchdog 242 Watchdog
237 -------------------------------------------------------------------------- */ 243 -------------------------------------------------------------------------- */
diff --git a/drivers/acpi/osi.c b/drivers/acpi/osi.c
index 723bee58bbcf..19cdd8a783a9 100644
--- a/drivers/acpi/osi.c
+++ b/drivers/acpi/osi.c
@@ -27,6 +27,7 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/acpi.h> 28#include <linux/acpi.h>
29#include <linux/dmi.h> 29#include <linux/dmi.h>
30#include <linux/platform_data/x86/apple.h>
30 31
31#include "internal.h" 32#include "internal.h"
32 33
@@ -257,12 +258,11 @@ bool acpi_osi_is_win8(void)
257} 258}
258EXPORT_SYMBOL(acpi_osi_is_win8); 259EXPORT_SYMBOL(acpi_osi_is_win8);
259 260
260static void __init acpi_osi_dmi_darwin(bool enable, 261static void __init acpi_osi_dmi_darwin(void)
261 const struct dmi_system_id *d)
262{ 262{
263 pr_notice("DMI detected to setup _OSI(\"Darwin\"): %s\n", d->ident); 263 pr_notice("DMI detected to setup _OSI(\"Darwin\"): Apple hardware\n");
264 osi_config.darwin_dmi = 1; 264 osi_config.darwin_dmi = 1;
265 __acpi_osi_setup_darwin(enable); 265 __acpi_osi_setup_darwin(true);
266} 266}
267 267
268static void __init acpi_osi_dmi_linux(bool enable, 268static void __init acpi_osi_dmi_linux(bool enable,
@@ -273,13 +273,6 @@ static void __init acpi_osi_dmi_linux(bool enable,
273 __acpi_osi_setup_linux(enable); 273 __acpi_osi_setup_linux(enable);
274} 274}
275 275
276static int __init dmi_enable_osi_darwin(const struct dmi_system_id *d)
277{
278 acpi_osi_dmi_darwin(true, d);
279
280 return 0;
281}
282
283static int __init dmi_enable_osi_linux(const struct dmi_system_id *d) 276static int __init dmi_enable_osi_linux(const struct dmi_system_id *d)
284{ 277{
285 acpi_osi_dmi_linux(true, d); 278 acpi_osi_dmi_linux(true, d);
@@ -481,30 +474,16 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
481 DMI_MATCH(DMI_PRODUCT_NAME, "1015PX"), 474 DMI_MATCH(DMI_PRODUCT_NAME, "1015PX"),
482 }, 475 },
483 }, 476 },
484
485 /*
486 * Enable _OSI("Darwin") for all apple platforms.
487 */
488 {
489 .callback = dmi_enable_osi_darwin,
490 .ident = "Apple hardware",
491 .matches = {
492 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
493 },
494 },
495 {
496 .callback = dmi_enable_osi_darwin,
497 .ident = "Apple hardware",
498 .matches = {
499 DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."),
500 },
501 },
502 {} 477 {}
503}; 478};
504 479
505static __init void acpi_osi_dmi_blacklisted(void) 480static __init void acpi_osi_dmi_blacklisted(void)
506{ 481{
507 dmi_check_system(acpi_osi_dmi_table); 482 dmi_check_system(acpi_osi_dmi_table);
483
484 /* Enable _OSI("Darwin") for Apple platforms. */
485 if (x86_apple_machine)
486 acpi_osi_dmi_darwin();
508} 487}
509 488
510int __init early_acpi_osi_init(void) 489int __init early_acpi_osi_init(void)
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 9eec3095e6c3..6fc204a52493 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -33,6 +33,7 @@
33#include <linux/acpi.h> 33#include <linux/acpi.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/dmi.h> 35#include <linux/dmi.h>
36#include <linux/platform_data/x86/apple.h>
36#include <acpi/apei.h> /* for acpi_hest_init() */ 37#include <acpi/apei.h> /* for acpi_hest_init() */
37 38
38#include "internal.h" 39#include "internal.h"
@@ -431,8 +432,7 @@ static void negotiate_os_control(struct acpi_pci_root *root, int *no_aspm)
431 * been called successfully. We know the feature set supported by the 432 * been called successfully. We know the feature set supported by the
432 * platform, so avoid calling _OSC at all 433 * platform, so avoid calling _OSC at all
433 */ 434 */
434 435 if (x86_apple_machine) {
435 if (dmi_match(DMI_SYS_VENDOR, "Apple Inc.")) {
436 root->osc_control_set = ~OSC_PCI_EXPRESS_PME_CONTROL; 436 root->osc_control_set = ~OSC_PCI_EXPRESS_PME_CONTROL;
437 decode_osc_control(root, "OS assumes control of", 437 decode_osc_control(root, "OS assumes control of",
438 root->osc_control_set); 438 root->osc_control_set);
diff --git a/drivers/acpi/pmic/intel_pmic_xpower.c b/drivers/acpi/pmic/intel_pmic_xpower.c
index 3b7d5be5b7ed..6c99d3f81095 100644
--- a/drivers/acpi/pmic/intel_pmic_xpower.c
+++ b/drivers/acpi/pmic/intel_pmic_xpower.c
@@ -27,6 +27,9 @@
27#define GPI1_LDO_ON (3 << 0) 27#define GPI1_LDO_ON (3 << 0)
28#define GPI1_LDO_OFF (4 << 0) 28#define GPI1_LDO_OFF (4 << 0)
29 29
30#define AXP288_ADC_TS_PIN_GPADC 0xf2
31#define AXP288_ADC_TS_PIN_ON 0xf3
32
30static struct pmic_table power_table[] = { 33static struct pmic_table power_table[] = {
31 { 34 {
32 .address = 0x00, 35 .address = 0x00,
@@ -209,11 +212,23 @@ static int intel_xpower_pmic_update_power(struct regmap *regmap, int reg,
209static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg) 212static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg)
210{ 213{
211 u8 buf[2]; 214 u8 buf[2];
215 int ret;
212 216
213 if (regmap_bulk_read(regmap, AXP288_GP_ADC_H, buf, 2)) 217 ret = regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL,
214 return -EIO; 218 AXP288_ADC_TS_PIN_GPADC);
219 if (ret)
220 return ret;
221
222 /* After switching to the GPADC pin give things some time to settle */
223 usleep_range(6000, 10000);
224
225 ret = regmap_bulk_read(regmap, AXP288_GP_ADC_H, buf, 2);
226 if (ret == 0)
227 ret = (buf[0] << 4) + ((buf[1] >> 4) & 0x0f);
228
229 regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, AXP288_ADC_TS_PIN_ON);
215 230
216 return (buf[0] << 4) + ((buf[1] >> 4) & 0x0F); 231 return ret;
217} 232}
218 233
219static struct intel_pmic_opregion_data intel_xpower_pmic_opregion_data = { 234static struct intel_pmic_opregion_data intel_xpower_pmic_opregion_data = {
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 591d1dd3f04e..9d6aff22684e 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -237,7 +237,7 @@ static int __acpi_processor_start(struct acpi_device *device)
237 237
238 result = acpi_cppc_processor_probe(pr); 238 result = acpi_cppc_processor_probe(pr);
239 if (result && !IS_ENABLED(CONFIG_ACPI_CPU_FREQ_PSS)) 239 if (result && !IS_ENABLED(CONFIG_ACPI_CPU_FREQ_PSS))
240 dev_warn(&device->dev, "CPPC data invalid or not present\n"); 240 dev_dbg(&device->dev, "CPPC data invalid or not present\n");
241 241
242 if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver) 242 if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
243 acpi_processor_power_init(pr); 243 acpi_processor_power_init(pr);
diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 476a52c60cf3..09b7974b6c62 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -339,6 +339,9 @@ void acpi_init_properties(struct acpi_device *adev)
339 339
340 INIT_LIST_HEAD(&adev->data.subnodes); 340 INIT_LIST_HEAD(&adev->data.subnodes);
341 341
342 if (!adev->handle)
343 return;
344
342 /* 345 /*
343 * Check if ACPI_DT_NAMESPACE_HID is present and inthat case we fill in 346 * Check if ACPI_DT_NAMESPACE_HID is present and inthat case we fill in
344 * Device Tree compatible properties for this device. 347 * Device Tree compatible properties for this device.
@@ -373,6 +376,9 @@ void acpi_init_properties(struct acpi_device *adev)
373 if (acpi_of && !adev->flags.of_compatible_ok) 376 if (acpi_of && !adev->flags.of_compatible_ok)
374 acpi_handle_info(adev->handle, 377 acpi_handle_info(adev->handle,
375 ACPI_DT_NAMESPACE_HID " requires 'compatible' property\n"); 378 ACPI_DT_NAMESPACE_HID " requires 'compatible' property\n");
379
380 if (!adev->data.pointer)
381 acpi_extract_apple_properties(adev);
376} 382}
377 383
378static void acpi_destroy_nondev_subnodes(struct list_head *list) 384static void acpi_destroy_nondev_subnodes(struct list_head *list)
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index cd4c4271dc4c..d85e010ee2cc 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -573,6 +573,35 @@ static acpi_status acpi_dev_process_resource(struct acpi_resource *ares,
573 return AE_OK; 573 return AE_OK;
574} 574}
575 575
576static int __acpi_dev_get_resources(struct acpi_device *adev,
577 struct list_head *list,
578 int (*preproc)(struct acpi_resource *, void *),
579 void *preproc_data, char *method)
580{
581 struct res_proc_context c;
582 acpi_status status;
583
584 if (!adev || !adev->handle || !list_empty(list))
585 return -EINVAL;
586
587 if (!acpi_has_method(adev->handle, method))
588 return 0;
589
590 c.list = list;
591 c.preproc = preproc;
592 c.preproc_data = preproc_data;
593 c.count = 0;
594 c.error = 0;
595 status = acpi_walk_resources(adev->handle, method,
596 acpi_dev_process_resource, &c);
597 if (ACPI_FAILURE(status)) {
598 acpi_dev_free_resource_list(list);
599 return c.error ? c.error : -EIO;
600 }
601
602 return c.count;
603}
604
576/** 605/**
577 * acpi_dev_get_resources - Get current resources of a device. 606 * acpi_dev_get_resources - Get current resources of a device.
578 * @adev: ACPI device node to get the resources for. 607 * @adev: ACPI device node to get the resources for.
@@ -601,30 +630,45 @@ int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list,
601 int (*preproc)(struct acpi_resource *, void *), 630 int (*preproc)(struct acpi_resource *, void *),
602 void *preproc_data) 631 void *preproc_data)
603{ 632{
604 struct res_proc_context c; 633 return __acpi_dev_get_resources(adev, list, preproc, preproc_data,
605 acpi_status status; 634 METHOD_NAME__CRS);
635}
636EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
606 637
607 if (!adev || !adev->handle || !list_empty(list)) 638static int is_memory(struct acpi_resource *ares, void *not_used)
608 return -EINVAL; 639{
640 struct resource_win win;
641 struct resource *res = &win.res;
609 642
610 if (!acpi_has_method(adev->handle, METHOD_NAME__CRS)) 643 memset(&win, 0, sizeof(win));
611 return 0;
612 644
613 c.list = list; 645 return !(acpi_dev_resource_memory(ares, res)
614 c.preproc = preproc; 646 || acpi_dev_resource_address_space(ares, &win)
615 c.preproc_data = preproc_data; 647 || acpi_dev_resource_ext_address_space(ares, &win));
616 c.count = 0; 648}
617 c.error = 0;
618 status = acpi_walk_resources(adev->handle, METHOD_NAME__CRS,
619 acpi_dev_process_resource, &c);
620 if (ACPI_FAILURE(status)) {
621 acpi_dev_free_resource_list(list);
622 return c.error ? c.error : -EIO;
623 }
624 649
625 return c.count; 650/**
651 * acpi_dev_get_dma_resources - Get current DMA resources of a device.
652 * @adev: ACPI device node to get the resources for.
653 * @list: Head of the resultant list of resources (must be empty).
654 *
655 * Evaluate the _DMA method for the given device node and process its
656 * output.
657 *
658 * The resultant struct resource objects are put on the list pointed to
659 * by @list, that must be empty initially, as members of struct
660 * resource_entry objects. Callers of this routine should use
661 * %acpi_dev_free_resource_list() to free that list.
662 *
663 * The number of resources in the output list is returned on success,
664 * an error code reflecting the error condition is returned otherwise.
665 */
666int acpi_dev_get_dma_resources(struct acpi_device *adev, struct list_head *list)
667{
668 return __acpi_dev_get_resources(adev, list, is_memory, NULL,
669 METHOD_NAME__DMA);
626} 670}
627EXPORT_SYMBOL_GPL(acpi_dev_get_resources); 671EXPORT_SYMBOL_GPL(acpi_dev_get_dma_resources);
628 672
629/** 673/**
630 * acpi_dev_filter_resource_type - Filter ACPI resource according to resource 674 * acpi_dev_filter_resource_type - Filter ACPI resource according to resource
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index ad0b13ad4bbb..a2428e9462dd 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -31,7 +31,7 @@
31#include <linux/jiffies.h> 31#include <linux/jiffies.h>
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/power_supply.h> 33#include <linux/power_supply.h>
34#include <linux/dmi.h> 34#include <linux/platform_data/x86/apple.h>
35 35
36#include "sbshc.h" 36#include "sbshc.h"
37#include "battery.h" 37#include "battery.h"
@@ -58,8 +58,6 @@ static unsigned int cache_time = 1000;
58module_param(cache_time, uint, 0644); 58module_param(cache_time, uint, 0644);
59MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); 59MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
60 60
61static bool sbs_manager_broken;
62
63#define MAX_SBS_BAT 4 61#define MAX_SBS_BAT 4
64#define ACPI_SBS_BLOCK_MAX 32 62#define ACPI_SBS_BLOCK_MAX 32
65 63
@@ -476,7 +474,7 @@ static ssize_t acpi_battery_alarm_store(struct device *dev,
476 return count; 474 return count;
477} 475}
478 476
479static struct device_attribute alarm_attr = { 477static const struct device_attribute alarm_attr = {
480 .attr = {.name = "alarm", .mode = 0644}, 478 .attr = {.name = "alarm", .mode = 0644},
481 .show = acpi_battery_alarm_show, 479 .show = acpi_battery_alarm_show,
482 .store = acpi_battery_alarm_store, 480 .store = acpi_battery_alarm_store,
@@ -632,31 +630,12 @@ static void acpi_sbs_callback(void *context)
632 } 630 }
633} 631}
634 632
635static int disable_sbs_manager(const struct dmi_system_id *d)
636{
637 sbs_manager_broken = true;
638 return 0;
639}
640
641static struct dmi_system_id acpi_sbs_dmi_table[] = {
642 {
643 .callback = disable_sbs_manager,
644 .ident = "Apple",
645 .matches = {
646 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc.")
647 },
648 },
649 { },
650};
651
652static int acpi_sbs_add(struct acpi_device *device) 633static int acpi_sbs_add(struct acpi_device *device)
653{ 634{
654 struct acpi_sbs *sbs; 635 struct acpi_sbs *sbs;
655 int result = 0; 636 int result = 0;
656 int id; 637 int id;
657 638
658 dmi_check_system(acpi_sbs_dmi_table);
659
660 sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); 639 sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL);
661 if (!sbs) { 640 if (!sbs) {
662 result = -ENOMEM; 641 result = -ENOMEM;
@@ -677,7 +656,7 @@ static int acpi_sbs_add(struct acpi_device *device)
677 656
678 result = 0; 657 result = 0;
679 658
680 if (!sbs_manager_broken) { 659 if (!x86_apple_machine) {
681 result = acpi_manager_get_info(sbs); 660 result = acpi_manager_get_info(sbs);
682 if (!result) { 661 if (!result) {
683 sbs->manager_present = 1; 662 sbs->manager_present = 1;
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 70fd5502c284..ac8a8a52ee4a 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -13,6 +13,7 @@
13#include <linux/dmi.h> 13#include <linux/dmi.h>
14#include <linux/nls.h> 14#include <linux/nls.h>
15#include <linux/dma-mapping.h> 15#include <linux/dma-mapping.h>
16#include <linux/platform_data/x86/apple.h>
16 17
17#include <asm/pgtable.h> 18#include <asm/pgtable.h>
18 19
@@ -1360,6 +1361,85 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
1360} 1361}
1361 1362
1362/** 1363/**
1364 * acpi_dma_get_range() - Get device DMA parameters.
1365 *
1366 * @dev: device to configure
1367 * @dma_addr: pointer device DMA address result
1368 * @offset: pointer to the DMA offset result
1369 * @size: pointer to DMA range size result
1370 *
1371 * Evaluate DMA regions and return respectively DMA region start, offset
1372 * and size in dma_addr, offset and size on parsing success; it does not
1373 * update the passed in values on failure.
1374 *
1375 * Return 0 on success, < 0 on failure.
1376 */
1377int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
1378 u64 *size)
1379{
1380 struct acpi_device *adev;
1381 LIST_HEAD(list);
1382 struct resource_entry *rentry;
1383 int ret;
1384 struct device *dma_dev = dev;
1385 u64 len, dma_start = U64_MAX, dma_end = 0, dma_offset = 0;
1386
1387 /*
1388 * Walk the device tree chasing an ACPI companion with a _DMA
1389 * object while we go. Stop if we find a device with an ACPI
1390 * companion containing a _DMA method.
1391 */
1392 do {
1393 adev = ACPI_COMPANION(dma_dev);
1394 if (adev && acpi_has_method(adev->handle, METHOD_NAME__DMA))
1395 break;
1396
1397 dma_dev = dma_dev->parent;
1398 } while (dma_dev);
1399
1400 if (!dma_dev)
1401 return -ENODEV;
1402
1403 if (!acpi_has_method(adev->handle, METHOD_NAME__CRS)) {
1404 acpi_handle_warn(adev->handle, "_DMA is valid only if _CRS is present\n");
1405 return -EINVAL;
1406 }
1407
1408 ret = acpi_dev_get_dma_resources(adev, &list);
1409 if (ret > 0) {
1410 list_for_each_entry(rentry, &list, node) {
1411 if (dma_offset && rentry->offset != dma_offset) {
1412 ret = -EINVAL;
1413 dev_warn(dma_dev, "Can't handle multiple windows with different offsets\n");
1414 goto out;
1415 }
1416 dma_offset = rentry->offset;
1417
1418 /* Take lower and upper limits */
1419 if (rentry->res->start < dma_start)
1420 dma_start = rentry->res->start;
1421 if (rentry->res->end > dma_end)
1422 dma_end = rentry->res->end;
1423 }
1424
1425 if (dma_start >= dma_end) {
1426 ret = -EINVAL;
1427 dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
1428 goto out;
1429 }
1430
1431 *dma_addr = dma_start - dma_offset;
1432 len = dma_end - dma_start;
1433 *size = max(len, len + 1);
1434 *offset = dma_offset;
1435 }
1436 out:
1437 acpi_dev_free_resource_list(&list);
1438
1439 return ret >= 0 ? 0 : ret;
1440}
1441
1442/**
1363 * acpi_dma_configure - Set-up DMA configuration for the device. 1443 * acpi_dma_configure - Set-up DMA configuration for the device.
1364 * @dev: The pointer to the device 1444 * @dev: The pointer to the device
1365 * @attr: device dma attributes 1445 * @attr: device dma attributes
@@ -1367,20 +1447,16 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
1367int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr) 1447int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr)
1368{ 1448{
1369 const struct iommu_ops *iommu; 1449 const struct iommu_ops *iommu;
1370 u64 size; 1450 u64 dma_addr = 0, size = 0;
1371 1451
1372 iort_set_dma_mask(dev); 1452 iort_dma_setup(dev, &dma_addr, &size);
1373 1453
1374 iommu = iort_iommu_configure(dev); 1454 iommu = iort_iommu_configure(dev);
1375 if (IS_ERR(iommu) && PTR_ERR(iommu) == -EPROBE_DEFER) 1455 if (IS_ERR(iommu) && PTR_ERR(iommu) == -EPROBE_DEFER)
1376 return -EPROBE_DEFER; 1456 return -EPROBE_DEFER;
1377 1457
1378 size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); 1458 arch_setup_dma_ops(dev, dma_addr, size,
1379 /* 1459 iommu, attr == DEV_DMA_COHERENT);
1380 * Assume dma valid range starts at 0 and covers the whole
1381 * coherent_dma_mask.
1382 */
1383 arch_setup_dma_ops(dev, 0, size, iommu, attr == DEV_DMA_COHERENT);
1384 1460
1385 return 0; 1461 return 0;
1386} 1462}
@@ -1452,6 +1528,12 @@ static bool acpi_is_spi_i2c_slave(struct acpi_device *device)
1452 struct list_head resource_list; 1528 struct list_head resource_list;
1453 bool is_spi_i2c_slave = false; 1529 bool is_spi_i2c_slave = false;
1454 1530
1531 /* Macs use device properties in lieu of _CRS resources */
1532 if (x86_apple_machine &&
1533 (fwnode_property_present(&device->fwnode, "spiSclkPeriod") ||
1534 fwnode_property_present(&device->fwnode, "i2cAddress")))
1535 return true;
1536
1455 INIT_LIST_HEAD(&resource_list); 1537 INIT_LIST_HEAD(&resource_list);
1456 acpi_dev_get_resources(device, &resource_list, acpi_check_spi_i2c_slave, 1538 acpi_dev_get_resources(device, &resource_list, acpi_check_spi_i2c_slave,
1457 &is_spi_i2c_slave); 1539 &is_spi_i2c_slave);
@@ -2058,6 +2140,9 @@ int __init acpi_scan_init(void)
2058 acpi_get_spcr_uart_addr(); 2140 acpi_get_spcr_uart_addr();
2059 } 2141 }
2060 2142
2143 acpi_gpe_apply_masked_gpes();
2144 acpi_update_all_gpes();
2145
2061 mutex_lock(&acpi_scan_lock); 2146 mutex_lock(&acpi_scan_lock);
2062 /* 2147 /*
2063 * Enumerate devices in the ACPI namespace. 2148 * Enumerate devices in the ACPI namespace.
@@ -2082,9 +2167,6 @@ int __init acpi_scan_init(void)
2082 } 2167 }
2083 } 2168 }
2084 2169
2085 acpi_gpe_apply_masked_gpes();
2086 acpi_update_all_gpes();
2087
2088 acpi_scan_initialized = true; 2170 acpi_scan_initialized = true;
2089 2171
2090 out: 2172 out:
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 09460d9f9208..9fdd014759f8 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -1044,7 +1044,7 @@ static struct syscore_ops acpi_sleep_syscore_ops = {
1044 .resume = acpi_restore_bm_rld, 1044 .resume = acpi_restore_bm_rld,
1045}; 1045};
1046 1046
1047void acpi_sleep_syscore_init(void) 1047static void acpi_sleep_syscore_init(void)
1048{ 1048{
1049 register_syscore_ops(&acpi_sleep_syscore_ops); 1049 register_syscore_ops(&acpi_sleep_syscore_ops);
1050} 1050}
diff --git a/drivers/acpi/spcr.c b/drivers/acpi/spcr.c
index 98aa8c808a33..324b35bfe781 100644
--- a/drivers/acpi/spcr.c
+++ b/drivers/acpi/spcr.c
@@ -53,17 +53,24 @@ static bool qdf2400_erratum_44_present(struct acpi_table_header *h)
53 */ 53 */
54static bool xgene_8250_erratum_present(struct acpi_table_spcr *tb) 54static bool xgene_8250_erratum_present(struct acpi_table_spcr *tb)
55{ 55{
56 bool xgene_8250 = false;
57
56 if (tb->interface_type != ACPI_DBG2_16550_COMPATIBLE) 58 if (tb->interface_type != ACPI_DBG2_16550_COMPATIBLE)
57 return false; 59 return false;
58 60
59 if (memcmp(tb->header.oem_id, "APMC0D", ACPI_OEM_ID_SIZE)) 61 if (memcmp(tb->header.oem_id, "APMC0D", ACPI_OEM_ID_SIZE) &&
62 memcmp(tb->header.oem_id, "HPE ", ACPI_OEM_ID_SIZE))
60 return false; 63 return false;
61 64
62 if (!memcmp(tb->header.oem_table_id, "XGENESPC", 65 if (!memcmp(tb->header.oem_table_id, "XGENESPC",
63 ACPI_OEM_TABLE_ID_SIZE) && tb->header.oem_revision == 0) 66 ACPI_OEM_TABLE_ID_SIZE) && tb->header.oem_revision == 0)
64 return true; 67 xgene_8250 = true;
65 68
66 return false; 69 if (!memcmp(tb->header.oem_table_id, "ProLiant",
70 ACPI_OEM_TABLE_ID_SIZE) && tb->header.oem_revision == 1)
71 xgene_8250 = true;
72
73 return xgene_8250;
67} 74}
68 75
69/** 76/**
@@ -105,16 +112,17 @@ int __init parse_spcr(bool earlycon)
105 } 112 }
106 113
107 if (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 114 if (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
108 switch (table->serial_port.access_width) { 115 switch (ACPI_ACCESS_BIT_WIDTH((
116 table->serial_port.access_width))) {
109 default: 117 default:
110 pr_err("Unexpected SPCR Access Width. Defaulting to byte size\n"); 118 pr_err("Unexpected SPCR Access Width. Defaulting to byte size\n");
111 case ACPI_ACCESS_SIZE_BYTE: 119 case 8:
112 iotype = "mmio"; 120 iotype = "mmio";
113 break; 121 break;
114 case ACPI_ACCESS_SIZE_WORD: 122 case 16:
115 iotype = "mmio16"; 123 iotype = "mmio16";
116 break; 124 break;
117 case ACPI_ACCESS_SIZE_DWORD: 125 case 32:
118 iotype = "mmio32"; 126 iotype = "mmio32";
119 break; 127 break;
120 } 128 }
@@ -181,11 +189,19 @@ int __init parse_spcr(bool earlycon)
181 uart = "qdf2400_e44"; 189 uart = "qdf2400_e44";
182 } 190 }
183 191
184 if (xgene_8250_erratum_present(table)) 192 if (xgene_8250_erratum_present(table)) {
185 iotype = "mmio32"; 193 iotype = "mmio32";
186 194
187 snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype, 195 /* for xgene v1 and v2 we don't know the clock rate of the
188 table->serial_port.address, baud_rate); 196 * UART so don't attempt to change to the baud rate state
197 * in the table because driver cannot calculate the dividers
198 */
199 snprintf(opts, sizeof(opts), "%s,%s,0x%llx", uart, iotype,
200 table->serial_port.address);
201 } else {
202 snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype,
203 table->serial_port.address, baud_rate);
204 }
189 205
190 pr_info("console: %s\n", opts); 206 pr_info("console: %s\n", opts);
191 207
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index e414fabf7315..78a5a23010ab 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -2,6 +2,8 @@
2 * sysfs.c - ACPI sysfs interface to userspace. 2 * sysfs.c - ACPI sysfs interface to userspace.
3 */ 3 */
4 4
5#define pr_fmt(fmt) "ACPI: " fmt
6
5#include <linux/init.h> 7#include <linux/init.h>
6#include <linux/kernel.h> 8#include <linux/kernel.h>
7#include <linux/moduleparam.h> 9#include <linux/moduleparam.h>
@@ -306,11 +308,13 @@ module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
306/* 308/*
307 * ACPI table sysfs I/F: 309 * ACPI table sysfs I/F:
308 * /sys/firmware/acpi/tables/ 310 * /sys/firmware/acpi/tables/
311 * /sys/firmware/acpi/tables/data/
309 * /sys/firmware/acpi/tables/dynamic/ 312 * /sys/firmware/acpi/tables/dynamic/
310 */ 313 */
311 314
312static LIST_HEAD(acpi_table_attr_list); 315static LIST_HEAD(acpi_table_attr_list);
313static struct kobject *tables_kobj; 316static struct kobject *tables_kobj;
317static struct kobject *tables_data_kobj;
314static struct kobject *dynamic_tables_kobj; 318static struct kobject *dynamic_tables_kobj;
315static struct kobject *hotplug_kobj; 319static struct kobject *hotplug_kobj;
316 320
@@ -325,6 +329,11 @@ struct acpi_table_attr {
325 struct list_head node; 329 struct list_head node;
326}; 330};
327 331
332struct acpi_data_attr {
333 struct bin_attribute attr;
334 u64 addr;
335};
336
328static ssize_t acpi_table_show(struct file *filp, struct kobject *kobj, 337static ssize_t acpi_table_show(struct file *filp, struct kobject *kobj,
329 struct bin_attribute *bin_attr, char *buf, 338 struct bin_attribute *bin_attr, char *buf,
330 loff_t offset, size_t count) 339 loff_t offset, size_t count)
@@ -420,6 +429,70 @@ acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context)
420 return AE_OK; 429 return AE_OK;
421} 430}
422 431
432static ssize_t acpi_data_show(struct file *filp, struct kobject *kobj,
433 struct bin_attribute *bin_attr, char *buf,
434 loff_t offset, size_t count)
435{
436 struct acpi_data_attr *data_attr;
437 void __iomem *base;
438 ssize_t rc;
439
440 data_attr = container_of(bin_attr, struct acpi_data_attr, attr);
441
442 base = acpi_os_map_memory(data_attr->addr, data_attr->attr.size);
443 if (!base)
444 return -ENOMEM;
445 rc = memory_read_from_buffer(buf, count, &offset, base,
446 data_attr->attr.size);
447 acpi_os_unmap_memory(base, data_attr->attr.size);
448
449 return rc;
450}
451
452static int acpi_bert_data_init(void *th, struct acpi_data_attr *data_attr)
453{
454 struct acpi_table_bert *bert = th;
455
456 if (bert->header.length < sizeof(struct acpi_table_bert) ||
457 bert->region_length < sizeof(struct acpi_hest_generic_status)) {
458 kfree(data_attr);
459 return -EINVAL;
460 }
461 data_attr->addr = bert->address;
462 data_attr->attr.size = bert->region_length;
463 data_attr->attr.attr.name = "BERT";
464
465 return sysfs_create_bin_file(tables_data_kobj, &data_attr->attr);
466}
467
468static struct acpi_data_obj {
469 char *name;
470 int (*fn)(void *, struct acpi_data_attr *);
471} acpi_data_objs[] = {
472 { ACPI_SIG_BERT, acpi_bert_data_init },
473};
474
475#define NUM_ACPI_DATA_OBJS ARRAY_SIZE(acpi_data_objs)
476
477static int acpi_table_data_init(struct acpi_table_header *th)
478{
479 struct acpi_data_attr *data_attr;
480 int i;
481
482 for (i = 0; i < NUM_ACPI_DATA_OBJS; i++) {
483 if (ACPI_COMPARE_NAME(th->signature, acpi_data_objs[i].name)) {
484 data_attr = kzalloc(sizeof(*data_attr), GFP_KERNEL);
485 if (!data_attr)
486 return -ENOMEM;
487 sysfs_attr_init(&data_attr->attr.attr);
488 data_attr->attr.read = acpi_data_show;
489 data_attr->attr.attr.mode = 0400;
490 return acpi_data_objs[i].fn(th, data_attr);
491 }
492 }
493 return 0;
494}
495
423static int acpi_tables_sysfs_init(void) 496static int acpi_tables_sysfs_init(void)
424{ 497{
425 struct acpi_table_attr *table_attr; 498 struct acpi_table_attr *table_attr;
@@ -432,6 +505,10 @@ static int acpi_tables_sysfs_init(void)
432 if (!tables_kobj) 505 if (!tables_kobj)
433 goto err; 506 goto err;
434 507
508 tables_data_kobj = kobject_create_and_add("data", tables_kobj);
509 if (!tables_data_kobj)
510 goto err_tables_data;
511
435 dynamic_tables_kobj = kobject_create_and_add("dynamic", tables_kobj); 512 dynamic_tables_kobj = kobject_create_and_add("dynamic", tables_kobj);
436 if (!dynamic_tables_kobj) 513 if (!dynamic_tables_kobj)
437 goto err_dynamic_tables; 514 goto err_dynamic_tables;
@@ -456,13 +533,17 @@ static int acpi_tables_sysfs_init(void)
456 return ret; 533 return ret;
457 } 534 }
458 list_add_tail(&table_attr->node, &acpi_table_attr_list); 535 list_add_tail(&table_attr->node, &acpi_table_attr_list);
536 acpi_table_data_init(table_header);
459 } 537 }
460 538
461 kobject_uevent(tables_kobj, KOBJ_ADD); 539 kobject_uevent(tables_kobj, KOBJ_ADD);
540 kobject_uevent(tables_data_kobj, KOBJ_ADD);
462 kobject_uevent(dynamic_tables_kobj, KOBJ_ADD); 541 kobject_uevent(dynamic_tables_kobj, KOBJ_ADD);
463 542
464 return 0; 543 return 0;
465err_dynamic_tables: 544err_dynamic_tables:
545 kobject_put(tables_data_kobj);
546err_tables_data:
466 kobject_put(tables_kobj); 547 kobject_put(tables_kobj);
467err: 548err:
468 return -ENOMEM; 549 return -ENOMEM;
@@ -552,11 +633,15 @@ static void fixed_event_count(u32 event_number)
552static void acpi_global_event_handler(u32 event_type, acpi_handle device, 633static void acpi_global_event_handler(u32 event_type, acpi_handle device,
553 u32 event_number, void *context) 634 u32 event_number, void *context)
554{ 635{
555 if (event_type == ACPI_EVENT_TYPE_GPE) 636 if (event_type == ACPI_EVENT_TYPE_GPE) {
556 gpe_count(event_number); 637 gpe_count(event_number);
557 638 pr_debug("GPE event 0x%02x\n", event_number);
558 if (event_type == ACPI_EVENT_TYPE_FIXED) 639 } else if (event_type == ACPI_EVENT_TYPE_FIXED) {
559 fixed_event_count(event_number); 640 fixed_event_count(event_number);
641 pr_debug("Fixed event 0x%02x\n", event_number);
642 } else {
643 pr_debug("Other event 0x%02x\n", event_number);
644 }
560} 645}
561 646
562static int get_status(u32 index, acpi_event_status *status, 647static int get_status(u32 index, acpi_event_status *status,
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index ff425390bfa8..80ce2a7d224b 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -740,10 +740,10 @@ int __init acpi_table_init(void)
740 740
741 if (acpi_verify_table_checksum) { 741 if (acpi_verify_table_checksum) {
742 pr_info("Early table checksum verification enabled\n"); 742 pr_info("Early table checksum verification enabled\n");
743 acpi_gbl_verify_table_checksum = TRUE; 743 acpi_gbl_enable_table_validation = TRUE;
744 } else { 744 } else {
745 pr_info("Early table checksum verification disabled\n"); 745 pr_info("Early table checksum verification disabled\n");
746 acpi_gbl_verify_table_checksum = FALSE; 746 acpi_gbl_enable_table_validation = FALSE;
747 } 747 }
748 748
749 status = acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0); 749 status = acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index b9d956c916f5..0a9e5979aaa9 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -816,3 +816,39 @@ static int __init acpi_backlight(char *str)
816 return 1; 816 return 1;
817} 817}
818__setup("acpi_backlight=", acpi_backlight); 818__setup("acpi_backlight=", acpi_backlight);
819
820/**
821 * acpi_match_platform_list - Check if the system matches with a given list
822 * @plat: pointer to acpi_platform_list table terminated by a NULL entry
823 *
824 * Return the matched index if the system is found in the platform list.
825 * Otherwise, return a negative error code.
826 */
827int acpi_match_platform_list(const struct acpi_platform_list *plat)
828{
829 struct acpi_table_header hdr;
830 int idx = 0;
831
832 if (acpi_disabled)
833 return -ENODEV;
834
835 for (; plat->oem_id[0]; plat++, idx++) {
836 if (ACPI_FAILURE(acpi_get_table_header(plat->table, 0, &hdr)))
837 continue;
838
839 if (strncmp(plat->oem_id, hdr.oem_id, ACPI_OEM_ID_SIZE))
840 continue;
841
842 if (strncmp(plat->oem_table_id, hdr.oem_table_id, ACPI_OEM_TABLE_ID_SIZE))
843 continue;
844
845 if ((plat->pred == all_versions) ||
846 (plat->pred == less_than_or_equal && hdr.oem_revision <= plat->oem_revision) ||
847 (plat->pred == greater_than_or_equal && hdr.oem_revision >= plat->oem_revision) ||
848 (plat->pred == equal && hdr.oem_revision == plat->oem_revision))
849 return idx;
850 }
851
852 return -ENODEV;
853}
854EXPORT_SYMBOL(acpi_match_platform_list);
diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
index d179e8d9177d..601e5d372887 100644
--- a/drivers/acpi/video_detect.c
+++ b/drivers/acpi/video_detect.c
@@ -103,6 +103,12 @@ static int video_detect_force_native(const struct dmi_system_id *d)
103 return 0; 103 return 0;
104} 104}
105 105
106static int video_detect_force_none(const struct dmi_system_id *d)
107{
108 acpi_backlight_dmi = acpi_backlight_none;
109 return 0;
110}
111
106static const struct dmi_system_id video_detect_dmi_table[] = { 112static const struct dmi_system_id video_detect_dmi_table[] = {
107 /* On Samsung X360, the BIOS will set a flag (VDRV) if generic 113 /* On Samsung X360, the BIOS will set a flag (VDRV) if generic
108 * ACPI backlight device is used. This flag will definitively break 114 * ACPI backlight device is used. This flag will definitively break
@@ -313,6 +319,14 @@ static const struct dmi_system_id video_detect_dmi_table[] = {
313 DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"), 319 DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
314 }, 320 },
315 }, 321 },
322 {
323 .callback = video_detect_force_none,
324 .ident = "Dell OptiPlex 9020M",
325 .matches = {
326 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
327 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 9020M"),
328 },
329 },
316 { }, 330 { },
317}; 331};
318 332
diff --git a/drivers/acpi/x86/apple.c b/drivers/acpi/x86/apple.c
new file mode 100644
index 000000000000..51b4cf9f25da
--- /dev/null
+++ b/drivers/acpi/x86/apple.c
@@ -0,0 +1,141 @@
1/*
2 * apple.c - Apple ACPI quirks
3 * Copyright (C) 2017 Lukas Wunner <lukas@wunner.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License (version 2) as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/acpi.h>
11#include <linux/bitmap.h>
12#include <linux/platform_data/x86/apple.h>
13#include <linux/uuid.h>
14
15/* Apple _DSM device properties GUID */
16static const guid_t apple_prp_guid =
17 GUID_INIT(0xa0b5b7c6, 0x1318, 0x441c,
18 0xb0, 0xc9, 0xfe, 0x69, 0x5e, 0xaf, 0x94, 0x9b);
19
20/**
21 * acpi_extract_apple_properties - retrieve and convert Apple _DSM properties
22 * @adev: ACPI device for which to retrieve the properties
23 *
24 * Invoke Apple's custom _DSM once to check the protocol version and once more
25 * to retrieve the properties. They are marshalled up in a single package as
26 * alternating key/value elements, unlike _DSD which stores them as a package
27 * of 2-element packages. Convert to _DSD format and make them available under
28 * the primary fwnode.
29 */
30void acpi_extract_apple_properties(struct acpi_device *adev)
31{
32 unsigned int i, j = 0, newsize = 0, numprops, numvalid;
33 union acpi_object *props, *newprops;
34 unsigned long *valid = NULL;
35 void *free_space;
36
37 if (!x86_apple_machine)
38 return;
39
40 props = acpi_evaluate_dsm_typed(adev->handle, &apple_prp_guid, 1, 0,
41 NULL, ACPI_TYPE_BUFFER);
42 if (!props)
43 return;
44
45 if (!props->buffer.length)
46 goto out_free;
47
48 if (props->buffer.pointer[0] != 3) {
49 acpi_handle_info(adev->handle, FW_INFO
50 "unsupported properties version %*ph\n",
51 props->buffer.length, props->buffer.pointer);
52 goto out_free;
53 }
54
55 ACPI_FREE(props);
56 props = acpi_evaluate_dsm_typed(adev->handle, &apple_prp_guid, 1, 1,
57 NULL, ACPI_TYPE_PACKAGE);
58 if (!props)
59 return;
60
61 numprops = props->package.count / 2;
62 if (!numprops)
63 goto out_free;
64
65 valid = kcalloc(BITS_TO_LONGS(numprops), sizeof(long), GFP_KERNEL);
66 if (!valid)
67 goto out_free;
68
69 /* newsize = key length + value length of each tuple */
70 for (i = 0; i < numprops; i++) {
71 union acpi_object *key = &props->package.elements[i * 2];
72 union acpi_object *val = &props->package.elements[i * 2 + 1];
73
74 if ( key->type != ACPI_TYPE_STRING ||
75 (val->type != ACPI_TYPE_INTEGER &&
76 val->type != ACPI_TYPE_BUFFER))
77 continue; /* skip invalid properties */
78
79 __set_bit(i, valid);
80 newsize += key->string.length + 1;
81 if ( val->type == ACPI_TYPE_BUFFER)
82 newsize += val->buffer.length;
83 }
84
85 numvalid = bitmap_weight(valid, numprops);
86 if (numprops > numvalid)
87 acpi_handle_info(adev->handle, FW_INFO
88 "skipped %u properties: wrong type\n",
89 numprops - numvalid);
90 if (numvalid == 0)
91 goto out_free;
92
93 /* newsize += top-level package + 3 objects for each key/value tuple */
94 newsize += (1 + 3 * numvalid) * sizeof(union acpi_object);
95 newprops = ACPI_ALLOCATE_ZEROED(newsize);
96 if (!newprops)
97 goto out_free;
98
99 /* layout: top-level package | packages | key/value tuples | strings */
100 newprops->type = ACPI_TYPE_PACKAGE;
101 newprops->package.count = numvalid;
102 newprops->package.elements = &newprops[1];
103 free_space = &newprops[1 + 3 * numvalid];
104
105 for_each_set_bit(i, valid, numprops) {
106 union acpi_object *key = &props->package.elements[i * 2];
107 union acpi_object *val = &props->package.elements[i * 2 + 1];
108 unsigned int k = 1 + numvalid + j * 2; /* index into newprops */
109 unsigned int v = k + 1;
110
111 newprops[1 + j].type = ACPI_TYPE_PACKAGE;
112 newprops[1 + j].package.count = 2;
113 newprops[1 + j].package.elements = &newprops[k];
114
115 newprops[k].type = ACPI_TYPE_STRING;
116 newprops[k].string.length = key->string.length;
117 newprops[k].string.pointer = free_space;
118 memcpy(free_space, key->string.pointer, key->string.length);
119 free_space += key->string.length + 1;
120
121 newprops[v].type = val->type;
122 if (val->type == ACPI_TYPE_INTEGER) {
123 newprops[v].integer.value = val->integer.value;
124 } else {
125 newprops[v].buffer.length = val->buffer.length;
126 newprops[v].buffer.pointer = free_space;
127 memcpy(free_space, val->buffer.pointer,
128 val->buffer.length);
129 free_space += val->buffer.length;
130 }
131 j++; /* count valid properties */
132 }
133 WARN_ON(free_space != (void *)newprops + newsize);
134
135 adev->data.properties = newprops;
136 adev->data.pointer = newprops;
137
138out_free:
139 ACPI_FREE(props);
140 kfree(valid);
141}
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 8f95265d5f52..93a0e88bef76 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -2194,39 +2194,31 @@ enum {
2194 PPC, 2194 PPC,
2195}; 2195};
2196 2196
2197struct hw_vendor_info {
2198 u16 valid;
2199 char oem_id[ACPI_OEM_ID_SIZE];
2200 char oem_table_id[ACPI_OEM_TABLE_ID_SIZE];
2201 int oem_pwr_table;
2202};
2203
2204/* Hardware vendor-specific info that has its own power management modes */ 2197/* Hardware vendor-specific info that has its own power management modes */
2205static struct hw_vendor_info vendor_info[] __initdata = { 2198static struct acpi_platform_list plat_info[] __initdata = {
2206 {1, "HP ", "ProLiant", PSS}, 2199 {"HP ", "ProLiant", 0, ACPI_SIG_FADT, all_versions, 0, PSS},
2207 {1, "ORACLE", "X4-2 ", PPC}, 2200 {"ORACLE", "X4-2 ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2208 {1, "ORACLE", "X4-2L ", PPC}, 2201 {"ORACLE", "X4-2L ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2209 {1, "ORACLE", "X4-2B ", PPC}, 2202 {"ORACLE", "X4-2B ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2210 {1, "ORACLE", "X3-2 ", PPC}, 2203 {"ORACLE", "X3-2 ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2211 {1, "ORACLE", "X3-2L ", PPC}, 2204 {"ORACLE", "X3-2L ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2212 {1, "ORACLE", "X3-2B ", PPC}, 2205 {"ORACLE", "X3-2B ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2213 {1, "ORACLE", "X4470M2 ", PPC}, 2206 {"ORACLE", "X4470M2 ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2214 {1, "ORACLE", "X4270M3 ", PPC}, 2207 {"ORACLE", "X4270M3 ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2215 {1, "ORACLE", "X4270M2 ", PPC}, 2208 {"ORACLE", "X4270M2 ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2216 {1, "ORACLE", "X4170M2 ", PPC}, 2209 {"ORACLE", "X4170M2 ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2217 {1, "ORACLE", "X4170 M3", PPC}, 2210 {"ORACLE", "X4170 M3", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2218 {1, "ORACLE", "X4275 M3", PPC}, 2211 {"ORACLE", "X4275 M3", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2219 {1, "ORACLE", "X6-2 ", PPC}, 2212 {"ORACLE", "X6-2 ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2220 {1, "ORACLE", "Sudbury ", PPC}, 2213 {"ORACLE", "Sudbury ", 0, ACPI_SIG_FADT, all_versions, 0, PPC},
2221 {0, "", ""}, 2214 { } /* End */
2222}; 2215};
2223 2216
2224static bool __init intel_pstate_platform_pwr_mgmt_exists(void) 2217static bool __init intel_pstate_platform_pwr_mgmt_exists(void)
2225{ 2218{
2226 struct acpi_table_header hdr;
2227 struct hw_vendor_info *v_info;
2228 const struct x86_cpu_id *id; 2219 const struct x86_cpu_id *id;
2229 u64 misc_pwr; 2220 u64 misc_pwr;
2221 int idx;
2230 2222
2231 id = x86_match_cpu(intel_pstate_cpu_oob_ids); 2223 id = x86_match_cpu(intel_pstate_cpu_oob_ids);
2232 if (id) { 2224 if (id) {
@@ -2235,21 +2227,15 @@ static bool __init intel_pstate_platform_pwr_mgmt_exists(void)
2235 return true; 2227 return true;
2236 } 2228 }
2237 2229
2238 if (acpi_disabled || 2230 idx = acpi_match_platform_list(plat_info);
2239 ACPI_FAILURE(acpi_get_table_header(ACPI_SIG_FADT, 0, &hdr))) 2231 if (idx < 0)
2240 return false; 2232 return false;
2241 2233
2242 for (v_info = vendor_info; v_info->valid; v_info++) { 2234 switch (plat_info[idx].data) {
2243 if (!strncmp(hdr.oem_id, v_info->oem_id, ACPI_OEM_ID_SIZE) && 2235 case PSS:
2244 !strncmp(hdr.oem_table_id, v_info->oem_table_id, 2236 return intel_pstate_no_acpi_pss();
2245 ACPI_OEM_TABLE_ID_SIZE)) 2237 case PPC:
2246 switch (v_info->oem_pwr_table) { 2238 return intel_pstate_has_acpi_ppc() && !force_load;
2247 case PSS:
2248 return intel_pstate_no_acpi_pss();
2249 case PPC:
2250 return intel_pstate_has_acpi_ppc() &&
2251 (!force_load);
2252 }
2253 } 2239 }
2254 2240
2255 return false; 2241 return false;
diff --git a/drivers/firmware/efi/apple-properties.c b/drivers/firmware/efi/apple-properties.c
index c473f4c5ca34..9f6bcf173b0e 100644
--- a/drivers/firmware/efi/apple-properties.c
+++ b/drivers/firmware/efi/apple-properties.c
@@ -18,8 +18,8 @@
18#define pr_fmt(fmt) "apple-properties: " fmt 18#define pr_fmt(fmt) "apple-properties: " fmt
19 19
20#include <linux/bootmem.h> 20#include <linux/bootmem.h>
21#include <linux/dmi.h>
22#include <linux/efi.h> 21#include <linux/efi.h>
22#include <linux/platform_data/x86/apple.h>
23#include <linux/property.h> 23#include <linux/property.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/ucs2_string.h> 25#include <linux/ucs2_string.h>
@@ -191,8 +191,7 @@ static int __init map_properties(void)
191 u64 pa_data; 191 u64 pa_data;
192 int ret; 192 int ret;
193 193
194 if (!dmi_match(DMI_SYS_VENDOR, "Apple Inc.") && 194 if (!x86_apple_machine)
195 !dmi_match(DMI_SYS_VENDOR, "Apple Computer, Inc."))
196 return 0; 195 return 0;
197 196
198 pa_data = boot_params.hdr.setup_data; 197 pa_data = boot_params.hdr.setup_data;
diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
index 48a8f69da42a..bf3672a81e49 100644
--- a/drivers/firmware/efi/cper.c
+++ b/drivers/firmware/efi/cper.c
@@ -606,7 +606,6 @@ void cper_estatus_print(const char *pfx,
606 const struct acpi_hest_generic_status *estatus) 606 const struct acpi_hest_generic_status *estatus)
607{ 607{
608 struct acpi_hest_generic_data *gdata; 608 struct acpi_hest_generic_data *gdata;
609 unsigned int data_len;
610 int sec_no = 0; 609 int sec_no = 0;
611 char newpfx[64]; 610 char newpfx[64];
612 __u16 severity; 611 __u16 severity;
@@ -617,14 +616,10 @@ void cper_estatus_print(const char *pfx,
617 "It has been corrected by h/w " 616 "It has been corrected by h/w "
618 "and requires no further action"); 617 "and requires no further action");
619 printk("%s""event severity: %s\n", pfx, cper_severity_str(severity)); 618 printk("%s""event severity: %s\n", pfx, cper_severity_str(severity));
620 data_len = estatus->data_length;
621 gdata = (struct acpi_hest_generic_data *)(estatus + 1);
622 snprintf(newpfx, sizeof(newpfx), "%s%s", pfx, INDENT_SP); 619 snprintf(newpfx, sizeof(newpfx), "%s%s", pfx, INDENT_SP);
623 620
624 while (data_len >= acpi_hest_get_size(gdata)) { 621 apei_estatus_for_each_section(estatus, gdata) {
625 cper_estatus_print_section(newpfx, gdata, sec_no); 622 cper_estatus_print_section(newpfx, gdata, sec_no);
626 data_len -= acpi_hest_get_record_size(gdata);
627 gdata = acpi_hest_get_next(gdata);
628 sec_no++; 623 sec_no++;
629 } 624 }
630} 625}
@@ -653,15 +648,12 @@ int cper_estatus_check(const struct acpi_hest_generic_status *estatus)
653 if (rc) 648 if (rc)
654 return rc; 649 return rc;
655 data_len = estatus->data_length; 650 data_len = estatus->data_length;
656 gdata = (struct acpi_hest_generic_data *)(estatus + 1);
657 651
658 while (data_len >= acpi_hest_get_size(gdata)) { 652 apei_estatus_for_each_section(estatus, gdata) {
659 gedata_len = acpi_hest_get_error_length(gdata); 653 gedata_len = acpi_hest_get_error_length(gdata);
660 if (gedata_len > data_len - acpi_hest_get_size(gdata)) 654 if (gedata_len > data_len - acpi_hest_get_size(gdata))
661 return -EINVAL; 655 return -EINVAL;
662
663 data_len -= acpi_hest_get_record_size(gdata); 656 data_len -= acpi_hest_get_record_size(gdata);
664 gdata = acpi_hest_get_next(gdata);
665 } 657 }
666 if (data_len) 658 if (data_len)
667 return -EINVAL; 659 return -EINVAL;
diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c
index cbca5e51b975..9b7005e1345e 100644
--- a/drivers/mailbox/pcc.c
+++ b/drivers/mailbox/pcc.c
@@ -457,10 +457,8 @@ static int __init acpi_pcc_probe(void)
457 /* Search for PCCT */ 457 /* Search for PCCT */
458 status = acpi_get_table(ACPI_SIG_PCCT, 0, &pcct_tbl); 458 status = acpi_get_table(ACPI_SIG_PCCT, 0, &pcct_tbl);
459 459
460 if (ACPI_FAILURE(status) || !pcct_tbl) { 460 if (ACPI_FAILURE(status) || !pcct_tbl)
461 pr_warn("PCCT header not found.\n");
462 return -ENODEV; 461 return -ENODEV;
463 }
464 462
465 count = acpi_table_parse_entries(ACPI_SIG_PCCT, 463 count = acpi_table_parse_entries(ACPI_SIG_PCCT,
466 sizeof(struct acpi_table_pcct), 464 sizeof(struct acpi_table_pcct),
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index e70c1c7ba1bf..a8da543b3814 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -573,7 +573,7 @@ static int acpi_pci_propagate_wakeup(struct pci_bus *bus, bool enable)
573{ 573{
574 while (bus->parent) { 574 while (bus->parent) {
575 if (acpi_pm_device_can_wakeup(&bus->self->dev)) 575 if (acpi_pm_device_can_wakeup(&bus->self->dev))
576 return acpi_pm_set_device_wakeup(&bus->self->dev, enable); 576 return acpi_pm_set_bridge_wakeup(&bus->self->dev, enable);
577 577
578 bus = bus->parent; 578 bus = bus->parent;
579 } 579 }
@@ -581,7 +581,7 @@ static int acpi_pci_propagate_wakeup(struct pci_bus *bus, bool enable)
581 /* We have reached the root bus. */ 581 /* We have reached the root bus. */
582 if (bus->bridge) { 582 if (bus->bridge) {
583 if (acpi_pm_device_can_wakeup(bus->bridge)) 583 if (acpi_pm_device_can_wakeup(bus->bridge))
584 return acpi_pm_set_device_wakeup(bus->bridge, enable); 584 return acpi_pm_set_bridge_wakeup(bus->bridge, enable);
585 } 585 }
586 return 0; 586 return 0;
587} 587}
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 4450feaf5c00..11bd267fc137 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -647,9 +647,7 @@ static int pci_legacy_resume(struct device *dev)
647static void pci_pm_default_resume(struct pci_dev *pci_dev) 647static void pci_pm_default_resume(struct pci_dev *pci_dev)
648{ 648{
649 pci_fixup_device(pci_fixup_resume, pci_dev); 649 pci_fixup_device(pci_fixup_resume, pci_dev);
650 650 pci_enable_wake(pci_dev, PCI_D0, false);
651 if (!pci_has_subordinate(pci_dev))
652 pci_enable_wake(pci_dev, PCI_D0, false);
653} 651}
654 652
655static void pci_pm_default_suspend(struct pci_dev *pci_dev) 653static void pci_pm_default_suspend(struct pci_dev *pci_dev)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index fdf65a6c13f6..68e3b2b0da93 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1912,6 +1912,13 @@ int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable)
1912{ 1912{
1913 int ret = 0; 1913 int ret = 0;
1914 1914
1915 /*
1916 * Bridges can only signal wakeup on behalf of subordinate devices,
1917 * but that is set up elsewhere, so skip them.
1918 */
1919 if (pci_has_subordinate(dev))
1920 return 0;
1921
1915 /* Don't do the same thing twice in a row for one device. */ 1922 /* Don't do the same thing twice in a row for one device. */
1916 if (!!enable == !!dev->wakeup_prepared) 1923 if (!!enable == !!dev->wakeup_prepared)
1917 return 0; 1924 return 0;
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 140760403f36..a346487a9532 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -25,6 +25,7 @@
25#include <linux/sched.h> 25#include <linux/sched.h>
26#include <linux/ktime.h> 26#include <linux/ktime.h>
27#include <linux/mm.h> 27#include <linux/mm.h>
28#include <linux/platform_data/x86/apple.h>
28#include <asm/dma.h> /* isa_dma_bridge_buggy */ 29#include <asm/dma.h> /* isa_dma_bridge_buggy */
29#include "pci.h" 30#include "pci.h"
30 31
@@ -3447,7 +3448,7 @@ static void quirk_apple_poweroff_thunderbolt(struct pci_dev *dev)
3447{ 3448{
3448 acpi_handle bridge, SXIO, SXFP, SXLV; 3449 acpi_handle bridge, SXIO, SXFP, SXLV;
3449 3450
3450 if (!dmi_match(DMI_BOARD_VENDOR, "Apple Inc.")) 3451 if (!x86_apple_machine)
3451 return; 3452 return;
3452 if (pci_pcie_type(dev) != PCI_EXP_TYPE_UPSTREAM) 3453 if (pci_pcie_type(dev) != PCI_EXP_TYPE_UPSTREAM)
3453 return; 3454 return;
@@ -3492,7 +3493,7 @@ static void quirk_apple_wait_for_thunderbolt(struct pci_dev *dev)
3492 struct pci_dev *sibling = NULL; 3493 struct pci_dev *sibling = NULL;
3493 struct pci_dev *nhi = NULL; 3494 struct pci_dev *nhi = NULL;
3494 3495
3495 if (!dmi_match(DMI_BOARD_VENDOR, "Apple Inc.")) 3496 if (!x86_apple_machine)
3496 return; 3497 return;
3497 if (pci_pcie_type(dev) != PCI_EXP_TYPE_DOWNSTREAM) 3498 if (pci_pcie_type(dev) != PCI_EXP_TYPE_DOWNSTREAM)
3498 return; 3499 return;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index cf8ee5e48f73..6e65524cbfd9 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -41,6 +41,7 @@
41#include <linux/acpi.h> 41#include <linux/acpi.h>
42#include <linux/highmem.h> 42#include <linux/highmem.h>
43#include <linux/idr.h> 43#include <linux/idr.h>
44#include <linux/platform_data/x86/apple.h>
44 45
45#define CREATE_TRACE_POINTS 46#define CREATE_TRACE_POINTS
46#include <trace/events/spi.h> 47#include <trace/events/spi.h>
@@ -1692,6 +1693,35 @@ static void of_register_spi_devices(struct spi_controller *ctlr) { }
1692#endif 1693#endif
1693 1694
1694#ifdef CONFIG_ACPI 1695#ifdef CONFIG_ACPI
1696static void acpi_spi_parse_apple_properties(struct spi_device *spi)
1697{
1698 struct acpi_device *dev = ACPI_COMPANION(&spi->dev);
1699 const union acpi_object *obj;
1700
1701 if (!x86_apple_machine)
1702 return;
1703
1704 if (!acpi_dev_get_property(dev, "spiSclkPeriod", ACPI_TYPE_BUFFER, &obj)
1705 && obj->buffer.length >= 4)
1706 spi->max_speed_hz = NSEC_PER_SEC / *(u32 *)obj->buffer.pointer;
1707
1708 if (!acpi_dev_get_property(dev, "spiWordSize", ACPI_TYPE_BUFFER, &obj)
1709 && obj->buffer.length == 8)
1710 spi->bits_per_word = *(u64 *)obj->buffer.pointer;
1711
1712 if (!acpi_dev_get_property(dev, "spiBitOrder", ACPI_TYPE_BUFFER, &obj)
1713 && obj->buffer.length == 8 && !*(u64 *)obj->buffer.pointer)
1714 spi->mode |= SPI_LSB_FIRST;
1715
1716 if (!acpi_dev_get_property(dev, "spiSPO", ACPI_TYPE_BUFFER, &obj)
1717 && obj->buffer.length == 8 && *(u64 *)obj->buffer.pointer)
1718 spi->mode |= SPI_CPOL;
1719
1720 if (!acpi_dev_get_property(dev, "spiSPH", ACPI_TYPE_BUFFER, &obj)
1721 && obj->buffer.length == 8 && *(u64 *)obj->buffer.pointer)
1722 spi->mode |= SPI_CPHA;
1723}
1724
1695static int acpi_spi_add_resource(struct acpi_resource *ares, void *data) 1725static int acpi_spi_add_resource(struct acpi_resource *ares, void *data)
1696{ 1726{
1697 struct spi_device *spi = data; 1727 struct spi_device *spi = data;
@@ -1765,6 +1795,8 @@ static acpi_status acpi_register_spi_device(struct spi_controller *ctlr,
1765 acpi_spi_add_resource, spi); 1795 acpi_spi_add_resource, spi);
1766 acpi_dev_free_resource_list(&resource_list); 1796 acpi_dev_free_resource_list(&resource_list);
1767 1797
1798 acpi_spi_parse_apple_properties(spi);
1799
1768 if (ret < 0 || !spi->max_speed_hz) { 1800 if (ret < 0 || !spi->max_speed_hz) {
1769 spi_dev_put(spi); 1801 spi_dev_put(spi);
1770 return AE_OK; 1802 return AE_OK;
diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c
index bdaac1ff00a5..53250fc057e1 100644
--- a/drivers/thunderbolt/icm.c
+++ b/drivers/thunderbolt/icm.c
@@ -13,9 +13,9 @@
13 */ 13 */
14 14
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/dmi.h>
17#include <linux/mutex.h> 16#include <linux/mutex.h>
18#include <linux/pci.h> 17#include <linux/pci.h>
18#include <linux/platform_data/x86/apple.h>
19#include <linux/sizes.h> 19#include <linux/sizes.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/workqueue.h> 21#include <linux/workqueue.h>
@@ -102,11 +102,6 @@ static inline u64 get_route(u32 route_hi, u32 route_lo)
102 return (u64)route_hi << 32 | route_lo; 102 return (u64)route_hi << 32 | route_lo;
103} 103}
104 104
105static inline bool is_apple(void)
106{
107 return dmi_match(DMI_BOARD_VENDOR, "Apple Inc.");
108}
109
110static bool icm_match(const struct tb_cfg_request *req, 105static bool icm_match(const struct tb_cfg_request *req,
111 const struct ctl_pkg *pkg) 106 const struct ctl_pkg *pkg)
112{ 107{
@@ -176,7 +171,7 @@ static int icm_request(struct tb *tb, const void *request, size_t request_size,
176 171
177static bool icm_fr_is_supported(struct tb *tb) 172static bool icm_fr_is_supported(struct tb *tb)
178{ 173{
179 return !is_apple(); 174 return !x86_apple_machine;
180} 175}
181 176
182static inline int icm_fr_get_switch_index(u32 port) 177static inline int icm_fr_get_switch_index(u32 port)
@@ -517,7 +512,7 @@ static bool icm_ar_is_supported(struct tb *tb)
517 * Starting from Alpine Ridge we can use ICM on Apple machines 512 * Starting from Alpine Ridge we can use ICM on Apple machines
518 * as well. We just need to reset and re-enable it first. 513 * as well. We just need to reset and re-enable it first.
519 */ 514 */
520 if (!is_apple()) 515 if (!x86_apple_machine)
521 return true; 516 return true;
522 517
523 /* 518 /*
@@ -1011,7 +1006,7 @@ static int icm_start(struct tb *tb)
1011 * don't provide images publicly either. To be on the safe side 1006 * don't provide images publicly either. To be on the safe side
1012 * prevent root switch NVM upgrade on Macs for now. 1007 * prevent root switch NVM upgrade on Macs for now.
1013 */ 1008 */
1014 tb->root_switch->no_nvm_upgrade = is_apple(); 1009 tb->root_switch->no_nvm_upgrade = x86_apple_machine;
1015 1010
1016 ret = tb_switch_add(tb->root_switch); 1011 ret = tb_switch_add(tb->root_switch);
1017 if (ret) 1012 if (ret)
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 1b02ca0b6129..0b22ad9d68b4 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -7,7 +7,7 @@
7#include <linux/slab.h> 7#include <linux/slab.h>
8#include <linux/errno.h> 8#include <linux/errno.h>
9#include <linux/delay.h> 9#include <linux/delay.h>
10#include <linux/dmi.h> 10#include <linux/platform_data/x86/apple.h>
11 11
12#include "tb.h" 12#include "tb.h"
13#include "tb_regs.h" 13#include "tb_regs.h"
@@ -453,7 +453,7 @@ struct tb *tb_probe(struct tb_nhi *nhi)
453 struct tb_cm *tcm; 453 struct tb_cm *tcm;
454 struct tb *tb; 454 struct tb *tb;
455 455
456 if (!dmi_match(DMI_BOARD_VENDOR, "Apple Inc.")) 456 if (!x86_apple_machine)
457 return NULL; 457 return NULL;
458 458
459 tb = tb_domain_alloc(nhi, sizeof(*tcm)); 459 tb = tb_domain_alloc(nhi, sizeof(*tcm));