aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi')
-rw-r--r--drivers/acpi/Kconfig3
-rw-r--r--drivers/acpi/Makefile1
-rw-r--r--drivers/acpi/ac.c69
-rw-r--r--drivers/acpi/acpi_apd.c47
-rw-r--r--drivers/acpi/acpi_lpss.c6
-rw-r--r--drivers/acpi/acpi_platform.c2
-rw-r--r--drivers/acpi/acpi_video.c5
-rw-r--r--drivers/acpi/acpi_watchdog.c72
-rw-r--r--drivers/acpi/acpica/acapps.h2
-rw-r--r--drivers/acpi/acpica/acglobal.h2
-rw-r--r--drivers/acpi/acpica/acnamesp.h4
-rw-r--r--drivers/acpi/acpica/dbnames.c13
-rw-r--r--drivers/acpi/acpica/dbobject.c23
-rw-r--r--drivers/acpi/acpica/dbtest.c59
-rw-r--r--drivers/acpi/acpica/dsdebug.c12
-rw-r--r--drivers/acpi/acpica/dswscope.c8
-rw-r--r--drivers/acpi/acpica/evgpe.c6
-rw-r--r--drivers/acpi/acpica/evxfgpe.c22
-rw-r--r--drivers/acpi/acpica/exconfig.c25
-rw-r--r--drivers/acpi/acpica/hwregs.c4
-rw-r--r--drivers/acpi/acpica/hwxface.c4
-rw-r--r--drivers/acpi/acpica/nsdump.c3
-rw-r--r--drivers/acpi/acpica/nsinit.c76
-rw-r--r--drivers/acpi/acpica/psloop.c51
-rw-r--r--drivers/acpi/acpica/psobject.c30
-rw-r--r--drivers/acpi/acpica/pswalk.c34
-rw-r--r--drivers/acpi/acpica/rsdump.c2
-rw-r--r--drivers/acpi/acpica/tbinstal.c2
-rw-r--r--drivers/acpi/acpica/utbuffer.c4
-rw-r--r--drivers/acpi/acpica/uterror.c10
-rw-r--r--drivers/acpi/acpica/utmutex.c4
-rw-r--r--drivers/acpi/acpica/utobject.c2
-rw-r--r--drivers/acpi/acpica/utosi.c1
-rw-r--r--drivers/acpi/acpica/utprint.c1
-rw-r--r--drivers/acpi/acpica/utstring.c2
-rw-r--r--drivers/acpi/apei/erst.c3
-rw-r--r--drivers/acpi/apei/ghes.c16
-rw-r--r--drivers/acpi/apei/hest.c3
-rw-r--r--drivers/acpi/battery.c202
-rw-r--r--drivers/acpi/button.c19
-rw-r--r--drivers/acpi/cppc_acpi.c159
-rw-r--r--drivers/acpi/device_pm.c9
-rw-r--r--drivers/acpi/ec.c6
-rw-r--r--drivers/acpi/fan.c4
-rw-r--r--drivers/acpi/internal.h1
-rw-r--r--drivers/acpi/nfit/core.c18
-rw-r--r--drivers/acpi/pci_root.c17
-rw-r--r--drivers/acpi/pptt.c655
-rw-r--r--drivers/acpi/processor_perflib.c5
-rw-r--r--drivers/acpi/processor_throttling.c5
-rw-r--r--drivers/acpi/reboot.c4
-rw-r--r--drivers/acpi/sleep.c7
-rw-r--r--drivers/acpi/sysfs.c6
-rw-r--r--drivers/acpi/tables.c11
54 files changed, 1421 insertions, 340 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 516d7b36d6fb..b533eeb6139d 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -547,6 +547,9 @@ config ACPI_CONFIGFS
547 547
548if ARM64 548if ARM64
549source "drivers/acpi/arm64/Kconfig" 549source "drivers/acpi/arm64/Kconfig"
550
551config ACPI_PPTT
552 bool
550endif 553endif
551 554
552config TPS68470_PMIC_OPREGION 555config TPS68470_PMIC_OPREGION
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 48e202752754..6d59aa109a91 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -88,6 +88,7 @@ obj-$(CONFIG_ACPI_BGRT) += bgrt.o
88obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o 88obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o
89obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o 89obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o
90obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o 90obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o
91obj-$(CONFIG_ACPI_PPTT) += pptt.o
91 92
92# processor has its own "processor." module_param namespace 93# processor has its own "processor." module_param namespace
93processor-y := processor_driver.o 94processor-y := processor_driver.o
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 2d8de2f8c1ed..cdd3136829f1 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -82,11 +82,11 @@ static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
82#ifdef CONFIG_ACPI_PROCFS_POWER 82#ifdef CONFIG_ACPI_PROCFS_POWER
83extern struct proc_dir_entry *acpi_lock_ac_dir(void); 83extern struct proc_dir_entry *acpi_lock_ac_dir(void);
84extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); 84extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
85static int acpi_ac_open_fs(struct inode *inode, struct file *file);
86#endif 85#endif
87 86
88 87
89static int ac_sleep_before_get_state_ms; 88static int ac_sleep_before_get_state_ms;
89static int ac_check_pmic = 1;
90 90
91static struct acpi_driver acpi_ac_driver = { 91static struct acpi_driver acpi_ac_driver = {
92 .name = "ac", 92 .name = "ac",
@@ -111,16 +111,6 @@ struct acpi_ac {
111 111
112#define to_acpi_ac(x) power_supply_get_drvdata(x) 112#define to_acpi_ac(x) power_supply_get_drvdata(x)
113 113
114#ifdef CONFIG_ACPI_PROCFS_POWER
115static const struct file_operations acpi_ac_fops = {
116 .owner = THIS_MODULE,
117 .open = acpi_ac_open_fs,
118 .read = seq_read,
119 .llseek = seq_lseek,
120 .release = single_release,
121};
122#endif
123
124/* -------------------------------------------------------------------------- 114/* --------------------------------------------------------------------------
125 AC Adapter Management 115 AC Adapter Management
126 -------------------------------------------------------------------------- */ 116 -------------------------------------------------------------------------- */
@@ -209,11 +199,6 @@ static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
209 return 0; 199 return 0;
210} 200}
211 201
212static int acpi_ac_open_fs(struct inode *inode, struct file *file)
213{
214 return single_open(file, acpi_ac_seq_show, PDE_DATA(inode));
215}
216
217static int acpi_ac_add_fs(struct acpi_ac *ac) 202static int acpi_ac_add_fs(struct acpi_ac *ac)
218{ 203{
219 struct proc_dir_entry *entry = NULL; 204 struct proc_dir_entry *entry = NULL;
@@ -228,9 +213,8 @@ static int acpi_ac_add_fs(struct acpi_ac *ac)
228 } 213 }
229 214
230 /* 'state' [R] */ 215 /* 'state' [R] */
231 entry = proc_create_data(ACPI_AC_FILE_STATE, 216 entry = proc_create_single_data(ACPI_AC_FILE_STATE, S_IRUGO,
232 S_IRUGO, acpi_device_dir(ac->device), 217 acpi_device_dir(ac->device), acpi_ac_seq_show, ac);
233 &acpi_ac_fops, ac);
234 if (!entry) 218 if (!entry)
235 return -ENODEV; 219 return -ENODEV;
236 return 0; 220 return 0;
@@ -310,21 +294,43 @@ static int acpi_ac_battery_notify(struct notifier_block *nb,
310 return NOTIFY_OK; 294 return NOTIFY_OK;
311} 295}
312 296
313static int thinkpad_e530_quirk(const struct dmi_system_id *d) 297static int __init thinkpad_e530_quirk(const struct dmi_system_id *d)
314{ 298{
315 ac_sleep_before_get_state_ms = 1000; 299 ac_sleep_before_get_state_ms = 1000;
316 return 0; 300 return 0;
317} 301}
318 302
319static const struct dmi_system_id ac_dmi_table[] = { 303static int __init ac_do_not_check_pmic_quirk(const struct dmi_system_id *d)
304{
305 ac_check_pmic = 0;
306 return 0;
307}
308
309static const struct dmi_system_id ac_dmi_table[] __initconst = {
320 { 310 {
311 /* Thinkpad e530 */
321 .callback = thinkpad_e530_quirk, 312 .callback = thinkpad_e530_quirk,
322 .ident = "thinkpad e530",
323 .matches = { 313 .matches = {
324 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 314 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
325 DMI_MATCH(DMI_PRODUCT_NAME, "32597CG"), 315 DMI_MATCH(DMI_PRODUCT_NAME, "32597CG"),
326 }, 316 },
327 }, 317 },
318 {
319 /* ECS EF20EA */
320 .callback = ac_do_not_check_pmic_quirk,
321 .matches = {
322 DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
323 },
324 },
325 {
326 /* Lenovo Ideapad Miix 320 */
327 .callback = ac_do_not_check_pmic_quirk,
328 .matches = {
329 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
330 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "80XF"),
331 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
332 },
333 },
328 {}, 334 {},
329}; 335};
330 336
@@ -384,7 +390,6 @@ end:
384 kfree(ac); 390 kfree(ac);
385 } 391 }
386 392
387 dmi_check_system(ac_dmi_table);
388 return result; 393 return result;
389} 394}
390 395
@@ -442,13 +447,17 @@ static int __init acpi_ac_init(void)
442 if (acpi_disabled) 447 if (acpi_disabled)
443 return -ENODEV; 448 return -ENODEV;
444 449
445 for (i = 0; i < ARRAY_SIZE(acpi_ac_blacklist); i++) 450 dmi_check_system(ac_dmi_table);
446 if (acpi_dev_present(acpi_ac_blacklist[i].hid, "1", 451
447 acpi_ac_blacklist[i].hrv)) { 452 if (ac_check_pmic) {
448 pr_info(PREFIX "AC: found native %s PMIC, not loading\n", 453 for (i = 0; i < ARRAY_SIZE(acpi_ac_blacklist); i++)
449 acpi_ac_blacklist[i].hid); 454 if (acpi_dev_present(acpi_ac_blacklist[i].hid, "1",
450 return -ENODEV; 455 acpi_ac_blacklist[i].hrv)) {
451 } 456 pr_info(PREFIX "AC: found native %s PMIC, not loading\n",
457 acpi_ac_blacklist[i].hid);
458 return -ENODEV;
459 }
460 }
452 461
453#ifdef CONFIG_ACPI_PROCFS_POWER 462#ifdef CONFIG_ACPI_PROCFS_POWER
454 acpi_ac_dir = acpi_lock_ac_dir(); 463 acpi_ac_dir = acpi_lock_ac_dir();
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
index d553b0087947..2664452fa112 100644
--- a/drivers/acpi/acpi_apd.c
+++ b/drivers/acpi/acpi_apd.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <linux/clk-provider.h> 13#include <linux/clk-provider.h>
14#include <linux/platform_data/clk-st.h>
14#include <linux/platform_device.h> 15#include <linux/platform_device.h>
15#include <linux/pm_domain.h> 16#include <linux/pm_domain.h>
16#include <linux/clkdev.h> 17#include <linux/clkdev.h>
@@ -72,6 +73,47 @@ static int acpi_apd_setup(struct apd_private_data *pdata)
72} 73}
73 74
74#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE 75#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
76
77static int misc_check_res(struct acpi_resource *ares, void *data)
78{
79 struct resource res;
80
81 return !acpi_dev_resource_memory(ares, &res);
82}
83
84static int st_misc_setup(struct apd_private_data *pdata)
85{
86 struct acpi_device *adev = pdata->adev;
87 struct platform_device *clkdev;
88 struct st_clk_data *clk_data;
89 struct resource_entry *rentry;
90 struct list_head resource_list;
91 int ret;
92
93 clk_data = devm_kzalloc(&adev->dev, sizeof(*clk_data), GFP_KERNEL);
94 if (!clk_data)
95 return -ENOMEM;
96
97 INIT_LIST_HEAD(&resource_list);
98 ret = acpi_dev_get_resources(adev, &resource_list, misc_check_res,
99 NULL);
100 if (ret < 0)
101 return -ENOENT;
102
103 list_for_each_entry(rentry, &resource_list, node) {
104 clk_data->base = devm_ioremap(&adev->dev, rentry->res->start,
105 resource_size(rentry->res));
106 break;
107 }
108
109 acpi_dev_free_resource_list(&resource_list);
110
111 clkdev = platform_device_register_data(&adev->dev, "clk-st",
112 PLATFORM_DEVID_NONE, clk_data,
113 sizeof(*clk_data));
114 return PTR_ERR_OR_ZERO(clkdev);
115}
116
75static const struct apd_device_desc cz_i2c_desc = { 117static const struct apd_device_desc cz_i2c_desc = {
76 .setup = acpi_apd_setup, 118 .setup = acpi_apd_setup,
77 .fixed_clk_rate = 133000000, 119 .fixed_clk_rate = 133000000,
@@ -94,6 +136,10 @@ static const struct apd_device_desc cz_uart_desc = {
94 .fixed_clk_rate = 48000000, 136 .fixed_clk_rate = 48000000,
95 .properties = uart_properties, 137 .properties = uart_properties,
96}; 138};
139
140static const struct apd_device_desc st_misc_desc = {
141 .setup = st_misc_setup,
142};
97#endif 143#endif
98 144
99#ifdef CONFIG_ARM64 145#ifdef CONFIG_ARM64
@@ -179,6 +225,7 @@ static const struct acpi_device_id acpi_apd_device_ids[] = {
179 { "AMD0020", APD_ADDR(cz_uart_desc) }, 225 { "AMD0020", APD_ADDR(cz_uart_desc) },
180 { "AMDI0020", APD_ADDR(cz_uart_desc) }, 226 { "AMDI0020", APD_ADDR(cz_uart_desc) },
181 { "AMD0030", }, 227 { "AMD0030", },
228 { "AMD0040", APD_ADDR(st_misc_desc)},
182#endif 229#endif
183#ifdef CONFIG_ARM64 230#ifdef CONFIG_ARM64
184 { "APMC0D0F", APD_ADDR(xgene_i2c_desc) }, 231 { "APMC0D0F", APD_ADDR(xgene_i2c_desc) },
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 2bcffec8dbf0..cb6ac5c65c2e 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -69,6 +69,10 @@ ACPI_MODULE_NAME("acpi_lpss");
69#define LPSS_SAVE_CTX BIT(4) 69#define LPSS_SAVE_CTX BIT(4)
70#define LPSS_NO_D3_DELAY BIT(5) 70#define LPSS_NO_D3_DELAY BIT(5)
71 71
72/* Crystal Cove PMIC shares same ACPI ID between different platforms */
73#define BYT_CRC_HRV 2
74#define CHT_CRC_HRV 3
75
72struct lpss_private_data; 76struct lpss_private_data;
73 77
74struct lpss_device_desc { 78struct lpss_device_desc {
@@ -162,7 +166,7 @@ static void byt_pwm_setup(struct lpss_private_data *pdata)
162 if (!adev->pnp.unique_id || strcmp(adev->pnp.unique_id, "1")) 166 if (!adev->pnp.unique_id || strcmp(adev->pnp.unique_id, "1"))
163 return; 167 return;
164 168
165 if (!acpi_dev_present("INT33FD", NULL, -1)) 169 if (!acpi_dev_present("INT33FD", NULL, BYT_CRC_HRV))
166 pwm_add_table(byt_pwm_lookup, ARRAY_SIZE(byt_pwm_lookup)); 170 pwm_add_table(byt_pwm_lookup, ARRAY_SIZE(byt_pwm_lookup));
167} 171}
168 172
diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
index 88cd949003f3..eaa60c94205a 100644
--- a/drivers/acpi/acpi_platform.c
+++ b/drivers/acpi/acpi_platform.c
@@ -82,7 +82,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
82 if (count < 0) { 82 if (count < 0) {
83 return NULL; 83 return NULL;
84 } else if (count > 0) { 84 } else if (count > 0) {
85 resources = kzalloc(count * sizeof(struct resource), 85 resources = kcalloc(count, sizeof(struct resource),
86 GFP_KERNEL); 86 GFP_KERNEL);
87 if (!resources) { 87 if (!resources) {
88 dev_err(&adev->dev, "No memory for resources\n"); 88 dev_err(&adev->dev, "No memory for resources\n");
diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index 2f2e737be0f8..f0b52266b3ac 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -832,8 +832,9 @@ int acpi_video_get_levels(struct acpi_device *device,
832 * in order to account for buggy BIOS which don't export the first two 832 * in order to account for buggy BIOS which don't export the first two
833 * special levels (see below) 833 * special levels (see below)
834 */ 834 */
835 br->levels = kmalloc((obj->package.count + ACPI_VIDEO_FIRST_LEVEL) * 835 br->levels = kmalloc_array(obj->package.count + ACPI_VIDEO_FIRST_LEVEL,
836 sizeof(*br->levels), GFP_KERNEL); 836 sizeof(*br->levels),
837 GFP_KERNEL);
837 if (!br->levels) { 838 if (!br->levels) {
838 result = -ENOMEM; 839 result = -ENOMEM;
839 goto out_free; 840 goto out_free;
diff --git a/drivers/acpi/acpi_watchdog.c b/drivers/acpi/acpi_watchdog.c
index 4bde16fb97d8..95600309ce42 100644
--- a/drivers/acpi/acpi_watchdog.c
+++ b/drivers/acpi/acpi_watchdog.c
@@ -12,35 +12,51 @@
12#define pr_fmt(fmt) "ACPI: watchdog: " fmt 12#define pr_fmt(fmt) "ACPI: watchdog: " fmt
13 13
14#include <linux/acpi.h> 14#include <linux/acpi.h>
15#include <linux/dmi.h>
16#include <linux/ioport.h> 15#include <linux/ioport.h>
17#include <linux/platform_device.h> 16#include <linux/platform_device.h>
18 17
19#include "internal.h" 18#include "internal.h"
20 19
21static const struct dmi_system_id acpi_watchdog_skip[] = { 20#ifdef CONFIG_RTC_MC146818_LIB
22 { 21#include <linux/mc146818rtc.h>
23 /* 22
24 * On Lenovo Z50-70 there are two issues with the WDAT 23/*
25 * table. First some of the instructions use RTC SRAM 24 * There are several systems where the WDAT table is accessing RTC SRAM to
26 * to store persistent information. This does not work well 25 * store persistent information. This does not work well with the Linux RTC
27 * with Linux RTC driver. Second, more important thing is 26 * driver so on those systems we skip WDAT driver and prefer iTCO_wdt
28 * that the instructions do not actually reset the system. 27 * instead.
29 * 28 *
30 * On this particular system iTCO_wdt seems to work just 29 * See also https://bugzilla.kernel.org/show_bug.cgi?id=199033.
31 * fine so we prefer that over WDAT for now. 30 */
32 * 31static bool acpi_watchdog_uses_rtc(const struct acpi_table_wdat *wdat)
33 * See also https://bugzilla.kernel.org/show_bug.cgi?id=199033. 32{
34 */ 33 const struct acpi_wdat_entry *entries;
35 .ident = "Lenovo Z50-70", 34 int i;
36 .matches = { 35
37 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 36 entries = (struct acpi_wdat_entry *)(wdat + 1);
38 DMI_MATCH(DMI_PRODUCT_NAME, "20354"), 37 for (i = 0; i < wdat->entries; i++) {
39 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Z50-70"), 38 const struct acpi_generic_address *gas;
40 }, 39
41 }, 40 gas = &entries[i].register_region;
42 {} 41 if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
43}; 42 switch (gas->address) {
43 case RTC_PORT(0):
44 case RTC_PORT(1):
45 case RTC_PORT(2):
46 case RTC_PORT(3):
47 return true;
48 }
49 }
50 }
51
52 return false;
53}
54#else
55static bool acpi_watchdog_uses_rtc(const struct acpi_table_wdat *wdat)
56{
57 return false;
58}
59#endif
44 60
45static const struct acpi_table_wdat *acpi_watchdog_get_wdat(void) 61static const struct acpi_table_wdat *acpi_watchdog_get_wdat(void)
46{ 62{
@@ -50,9 +66,6 @@ static const struct acpi_table_wdat *acpi_watchdog_get_wdat(void)
50 if (acpi_disabled) 66 if (acpi_disabled)
51 return NULL; 67 return NULL;
52 68
53 if (dmi_check_system(acpi_watchdog_skip))
54 return NULL;
55
56 status = acpi_get_table(ACPI_SIG_WDAT, 0, 69 status = acpi_get_table(ACPI_SIG_WDAT, 0,
57 (struct acpi_table_header **)&wdat); 70 (struct acpi_table_header **)&wdat);
58 if (ACPI_FAILURE(status)) { 71 if (ACPI_FAILURE(status)) {
@@ -60,6 +73,11 @@ static const struct acpi_table_wdat *acpi_watchdog_get_wdat(void)
60 return NULL; 73 return NULL;
61 } 74 }
62 75
76 if (acpi_watchdog_uses_rtc(wdat)) {
77 pr_info("Skipping WDAT on this system because it uses RTC SRAM\n");
78 return NULL;
79 }
80
63 return wdat; 81 return wdat;
64} 82}
65 83
diff --git a/drivers/acpi/acpica/acapps.h b/drivers/acpi/acpica/acapps.h
index a2a85122fafe..5a9c2febc0fb 100644
--- a/drivers/acpi/acpica/acapps.h
+++ b/drivers/acpi/acpica/acapps.h
@@ -143,6 +143,8 @@ acpi_status
143fl_split_input_pathname(char *input_path, 143fl_split_input_pathname(char *input_path,
144 char **out_directory_path, char **out_filename); 144 char **out_directory_path, char **out_filename);
145 145
146char *fl_get_file_basename(char *file_pathname);
147
146char *ad_generate_filename(char *prefix, char *table_id); 148char *ad_generate_filename(char *prefix, char *table_id);
147 149
148void 150void
diff --git a/drivers/acpi/acpica/acglobal.h b/drivers/acpi/acpica/acglobal.h
index 0bc550072a21..1e6204518496 100644
--- a/drivers/acpi/acpica/acglobal.h
+++ b/drivers/acpi/acpica/acglobal.h
@@ -82,7 +82,7 @@ ACPI_GLOBAL(u8, acpi_gbl_global_lock_pending);
82 * interrupt level 82 * interrupt level
83 */ 83 */
84ACPI_GLOBAL(acpi_spinlock, acpi_gbl_gpe_lock); /* For GPE data structs and registers */ 84ACPI_GLOBAL(acpi_spinlock, acpi_gbl_gpe_lock); /* For GPE data structs and registers */
85ACPI_GLOBAL(acpi_spinlock, acpi_gbl_hardware_lock); /* For ACPI H/W except GPE registers */ 85ACPI_GLOBAL(acpi_raw_spinlock, acpi_gbl_hardware_lock); /* For ACPI H/W except GPE registers */
86ACPI_GLOBAL(acpi_spinlock, acpi_gbl_reference_count_lock); 86ACPI_GLOBAL(acpi_spinlock, acpi_gbl_reference_count_lock);
87 87
88/* Mutex for _OSI support */ 88/* Mutex for _OSI support */
diff --git a/drivers/acpi/acpica/acnamesp.h b/drivers/acpi/acpica/acnamesp.h
index 514aaf948ea9..3825df923480 100644
--- a/drivers/acpi/acpica/acnamesp.h
+++ b/drivers/acpi/acpica/acnamesp.h
@@ -56,6 +56,10 @@ acpi_status acpi_ns_initialize_objects(void);
56 56
57acpi_status acpi_ns_initialize_devices(u32 flags); 57acpi_status acpi_ns_initialize_devices(u32 flags);
58 58
59acpi_status
60acpi_ns_init_one_package(acpi_handle obj_handle,
61 u32 level, void *context, void **return_value);
62
59/* 63/*
60 * nsload - Namespace loading 64 * nsload - Namespace loading
61 */ 65 */
diff --git a/drivers/acpi/acpica/dbnames.c b/drivers/acpi/acpica/dbnames.c
index 170802c62179..992bd7b92540 100644
--- a/drivers/acpi/acpica/dbnames.c
+++ b/drivers/acpi/acpica/dbnames.c
@@ -189,9 +189,15 @@ void acpi_db_dump_namespace(char *start_arg, char *depth_arg)
189 } 189 }
190 190
191 acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT); 191 acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
192 acpi_os_printf("ACPI Namespace (from %4.4s (%p) subtree):\n", 192
193 ((struct acpi_namespace_node *)subtree_entry)->name. 193 if (((struct acpi_namespace_node *)subtree_entry)->parent) {
194 ascii, subtree_entry); 194 acpi_os_printf("ACPI Namespace (from %4.4s (%p) subtree):\n",
195 ((struct acpi_namespace_node *)subtree_entry)->
196 name.ascii, subtree_entry);
197 } else {
198 acpi_os_printf("ACPI Namespace (from %s):\n",
199 ACPI_NAMESPACE_ROOT);
200 }
195 201
196 /* Display the subtree */ 202 /* Display the subtree */
197 203
@@ -316,6 +322,7 @@ acpi_db_walk_and_match_name(acpi_handle obj_handle,
316 acpi_os_printf("Could Not get pathname for object %p\n", 322 acpi_os_printf("Could Not get pathname for object %p\n",
317 obj_handle); 323 obj_handle);
318 } else { 324 } else {
325 info.count = 0;
319 info.owner_id = ACPI_OWNER_ID_MAX; 326 info.owner_id = ACPI_OWNER_ID_MAX;
320 info.debug_level = ACPI_UINT32_MAX; 327 info.debug_level = ACPI_UINT32_MAX;
321 info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT; 328 info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
diff --git a/drivers/acpi/acpica/dbobject.c b/drivers/acpi/acpica/dbobject.c
index 58c3253b533a..a1c76bf21122 100644
--- a/drivers/acpi/acpica/dbobject.c
+++ b/drivers/acpi/acpica/dbobject.c
@@ -35,6 +35,15 @@ void
35acpi_db_dump_method_info(acpi_status status, struct acpi_walk_state *walk_state) 35acpi_db_dump_method_info(acpi_status status, struct acpi_walk_state *walk_state)
36{ 36{
37 struct acpi_thread_state *thread; 37 struct acpi_thread_state *thread;
38 struct acpi_namespace_node *node;
39
40 node = walk_state->method_node;
41
42 /* There are no locals or arguments for the module-level code case */
43
44 if (node == acpi_gbl_root_node) {
45 return;
46 }
38 47
39 /* Ignore control codes, they are not errors */ 48 /* Ignore control codes, they are not errors */
40 49
@@ -384,8 +393,14 @@ void acpi_db_decode_locals(struct acpi_walk_state *walk_state)
384 struct acpi_namespace_node *node; 393 struct acpi_namespace_node *node;
385 u8 display_locals = FALSE; 394 u8 display_locals = FALSE;
386 395
387 obj_desc = walk_state->method_desc;
388 node = walk_state->method_node; 396 node = walk_state->method_node;
397 obj_desc = walk_state->method_desc;
398
399 /* There are no locals for the module-level code case */
400
401 if (node == acpi_gbl_root_node) {
402 return;
403 }
389 404
390 if (!node) { 405 if (!node) {
391 acpi_os_printf 406 acpi_os_printf
@@ -452,6 +467,12 @@ void acpi_db_decode_arguments(struct acpi_walk_state *walk_state)
452 node = walk_state->method_node; 467 node = walk_state->method_node;
453 obj_desc = walk_state->method_desc; 468 obj_desc = walk_state->method_desc;
454 469
470 /* There are no arguments for the module-level code case */
471
472 if (node == acpi_gbl_root_node) {
473 return;
474 }
475
455 if (!node) { 476 if (!node) {
456 acpi_os_printf 477 acpi_os_printf
457 ("No method node (Executing subtree for buffer or opregion)\n"); 478 ("No method node (Executing subtree for buffer or opregion)\n");
diff --git a/drivers/acpi/acpica/dbtest.c b/drivers/acpi/acpica/dbtest.c
index 3892680a5258..8a5462439a97 100644
--- a/drivers/acpi/acpica/dbtest.c
+++ b/drivers/acpi/acpica/dbtest.c
@@ -30,6 +30,8 @@ acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length);
30static acpi_status 30static acpi_status
31acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length); 31acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length);
32 32
33static acpi_status acpi_db_test_package_type(struct acpi_namespace_node *node);
34
33static acpi_status 35static acpi_status
34acpi_db_read_from_object(struct acpi_namespace_node *node, 36acpi_db_read_from_object(struct acpi_namespace_node *node,
35 acpi_object_type expected_type, 37 acpi_object_type expected_type,
@@ -273,6 +275,11 @@ acpi_db_test_one_object(acpi_handle obj_handle,
273 bit_length = byte_length * 8; 275 bit_length = byte_length * 8;
274 break; 276 break;
275 277
278 case ACPI_TYPE_PACKAGE:
279
280 local_type = ACPI_TYPE_PACKAGE;
281 break;
282
276 case ACPI_TYPE_FIELD_UNIT: 283 case ACPI_TYPE_FIELD_UNIT:
277 case ACPI_TYPE_BUFFER_FIELD: 284 case ACPI_TYPE_BUFFER_FIELD:
278 case ACPI_TYPE_LOCAL_REGION_FIELD: 285 case ACPI_TYPE_LOCAL_REGION_FIELD:
@@ -305,6 +312,7 @@ acpi_db_test_one_object(acpi_handle obj_handle,
305 312
306 acpi_os_printf("%14s: %4.4s", 313 acpi_os_printf("%14s: %4.4s",
307 acpi_ut_get_type_name(node->type), node->name.ascii); 314 acpi_ut_get_type_name(node->type), node->name.ascii);
315
308 if (!obj_desc) { 316 if (!obj_desc) {
309 acpi_os_printf(" Ignoring, no attached object\n"); 317 acpi_os_printf(" Ignoring, no attached object\n");
310 return (AE_OK); 318 return (AE_OK);
@@ -322,14 +330,13 @@ acpi_db_test_one_object(acpi_handle obj_handle,
322 case ACPI_ADR_SPACE_SYSTEM_MEMORY: 330 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
323 case ACPI_ADR_SPACE_SYSTEM_IO: 331 case ACPI_ADR_SPACE_SYSTEM_IO:
324 case ACPI_ADR_SPACE_PCI_CONFIG: 332 case ACPI_ADR_SPACE_PCI_CONFIG:
325 case ACPI_ADR_SPACE_EC:
326 333
327 break; 334 break;
328 335
329 default: 336 default:
330 337
331 acpi_os_printf 338 acpi_os_printf
332 (" %s space is not supported [%4.4s]\n", 339 (" %s space is not supported in this command [%4.4s]\n",
333 acpi_ut_get_region_name(region_obj->region. 340 acpi_ut_get_region_name(region_obj->region.
334 space_id), 341 space_id),
335 region_obj->region.node->name.ascii); 342 region_obj->region.node->name.ascii);
@@ -359,6 +366,11 @@ acpi_db_test_one_object(acpi_handle obj_handle,
359 status = acpi_db_test_buffer_type(node, bit_length); 366 status = acpi_db_test_buffer_type(node, bit_length);
360 break; 367 break;
361 368
369 case ACPI_TYPE_PACKAGE:
370
371 status = acpi_db_test_package_type(node);
372 break;
373
362 default: 374 default:
363 375
364 acpi_os_printf(" Ignoring, type not implemented (%2.2X)", 376 acpi_os_printf(" Ignoring, type not implemented (%2.2X)",
@@ -366,6 +378,13 @@ acpi_db_test_one_object(acpi_handle obj_handle,
366 break; 378 break;
367 } 379 }
368 380
381 /* Exit on error, but don't abort the namespace walk */
382
383 if (ACPI_FAILURE(status)) {
384 status = AE_OK;
385 goto exit;
386 }
387
369 switch (node->type) { 388 switch (node->type) {
370 case ACPI_TYPE_LOCAL_REGION_FIELD: 389 case ACPI_TYPE_LOCAL_REGION_FIELD:
371 390
@@ -373,12 +392,14 @@ acpi_db_test_one_object(acpi_handle obj_handle,
373 acpi_os_printf(" (%s)", 392 acpi_os_printf(" (%s)",
374 acpi_ut_get_region_name(region_obj->region. 393 acpi_ut_get_region_name(region_obj->region.
375 space_id)); 394 space_id));
395
376 break; 396 break;
377 397
378 default: 398 default:
379 break; 399 break;
380 } 400 }
381 401
402exit:
382 acpi_os_printf("\n"); 403 acpi_os_printf("\n");
383 return (status); 404 return (status);
384} 405}
@@ -431,7 +452,6 @@ acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length)
431 if (temp1->integer.value == value_to_write) { 452 if (temp1->integer.value == value_to_write) {
432 value_to_write = 0; 453 value_to_write = 0;
433 } 454 }
434
435 /* Write a new value */ 455 /* Write a new value */
436 456
437 write_value.type = ACPI_TYPE_INTEGER; 457 write_value.type = ACPI_TYPE_INTEGER;
@@ -708,6 +728,35 @@ exit:
708 728
709/******************************************************************************* 729/*******************************************************************************
710 * 730 *
731 * FUNCTION: acpi_db_test_package_type
732 *
733 * PARAMETERS: node - Parent NS node for the object
734 *
735 * RETURN: Status
736 *
737 * DESCRIPTION: Test read for a Package object.
738 *
739 ******************************************************************************/
740
741static acpi_status acpi_db_test_package_type(struct acpi_namespace_node *node)
742{
743 union acpi_object *temp1 = NULL;
744 acpi_status status;
745
746 /* Read the original value */
747
748 status = acpi_db_read_from_object(node, ACPI_TYPE_PACKAGE, &temp1);
749 if (ACPI_FAILURE(status)) {
750 return (status);
751 }
752
753 acpi_os_printf(" %8.8X Elements", temp1->package.count);
754 acpi_os_free(temp1);
755 return (status);
756}
757
758/*******************************************************************************
759 *
711 * FUNCTION: acpi_db_read_from_object 760 * FUNCTION: acpi_db_read_from_object
712 * 761 *
713 * PARAMETERS: node - Parent NS node for the object 762 * PARAMETERS: node - Parent NS node for the object
@@ -746,8 +795,8 @@ acpi_db_read_from_object(struct acpi_namespace_node *node,
746 acpi_gbl_method_executing = TRUE; 795 acpi_gbl_method_executing = TRUE;
747 status = acpi_evaluate_object(read_handle, NULL, 796 status = acpi_evaluate_object(read_handle, NULL,
748 &param_objects, &return_obj); 797 &param_objects, &return_obj);
749 acpi_gbl_method_executing = FALSE;
750 798
799 acpi_gbl_method_executing = FALSE;
751 if (ACPI_FAILURE(status)) { 800 if (ACPI_FAILURE(status)) {
752 acpi_os_printf("Could not read from object, %s", 801 acpi_os_printf("Could not read from object, %s",
753 acpi_format_exception(status)); 802 acpi_format_exception(status));
@@ -760,6 +809,7 @@ acpi_db_read_from_object(struct acpi_namespace_node *node,
760 case ACPI_TYPE_INTEGER: 809 case ACPI_TYPE_INTEGER:
761 case ACPI_TYPE_BUFFER: 810 case ACPI_TYPE_BUFFER:
762 case ACPI_TYPE_STRING: 811 case ACPI_TYPE_STRING:
812 case ACPI_TYPE_PACKAGE:
763 /* 813 /*
764 * Did we receive the type we wanted? Most important for the 814 * Did we receive the type we wanted? Most important for the
765 * Integer/Buffer case (when a field is larger than an Integer, 815 * Integer/Buffer case (when a field is larger than an Integer,
@@ -771,6 +821,7 @@ acpi_db_read_from_object(struct acpi_namespace_node *node,
771 acpi_ut_get_type_name(expected_type), 821 acpi_ut_get_type_name(expected_type),
772 acpi_ut_get_type_name(ret_value->type)); 822 acpi_ut_get_type_name(ret_value->type));
773 823
824 acpi_os_free(return_obj.pointer);
774 return (AE_TYPE); 825 return (AE_TYPE);
775 } 826 }
776 827
diff --git a/drivers/acpi/acpica/dsdebug.c b/drivers/acpi/acpica/dsdebug.c
index 70a2fca60306..9d33f0bb2885 100644
--- a/drivers/acpi/acpica/dsdebug.c
+++ b/drivers/acpi/acpica/dsdebug.c
@@ -162,9 +162,15 @@ acpi_ds_dump_method_stack(acpi_status status,
162 op->common.next = NULL; 162 op->common.next = NULL;
163 163
164#ifdef ACPI_DISASSEMBLER 164#ifdef ACPI_DISASSEMBLER
165 acpi_os_printf("Failed at "); 165 if (walk_state->method_node !=
166 acpi_dm_disassemble(next_walk_state, op, 166 acpi_gbl_root_node) {
167 ACPI_UINT32_MAX); 167
168 /* More verbose if not module-level code */
169
170 acpi_os_printf("Failed at ");
171 acpi_dm_disassemble(next_walk_state, op,
172 ACPI_UINT32_MAX);
173 }
168#endif 174#endif
169 op->common.next = next; 175 op->common.next = next;
170 } 176 }
diff --git a/drivers/acpi/acpica/dswscope.c b/drivers/acpi/acpica/dswscope.c
index d1422f984f6e..7592176a8fa2 100644
--- a/drivers/acpi/acpica/dswscope.c
+++ b/drivers/acpi/acpica/dswscope.c
@@ -115,7 +115,7 @@ acpi_ds_scope_stack_push(struct acpi_namespace_node *node,
115 acpi_ut_get_type_name(old_scope_info-> 115 acpi_ut_get_type_name(old_scope_info->
116 common.value))); 116 common.value)));
117 } else { 117 } else {
118 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (%s)", "ROOT")); 118 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, ACPI_NAMESPACE_ROOT));
119 } 119 }
120 120
121 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, 121 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
@@ -166,14 +166,14 @@ acpi_status acpi_ds_scope_stack_pop(struct acpi_walk_state *walk_state)
166 166
167 new_scope_info = walk_state->scope_info; 167 new_scope_info = walk_state->scope_info;
168 if (new_scope_info) { 168 if (new_scope_info) {
169 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, 169 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[%4.4s] (%s)\n",
170 "[%4.4s] (%s)\n",
171 acpi_ut_get_node_name(new_scope_info-> 170 acpi_ut_get_node_name(new_scope_info->
172 scope.node), 171 scope.node),
173 acpi_ut_get_type_name(new_scope_info-> 172 acpi_ut_get_type_name(new_scope_info->
174 common.value))); 173 common.value)));
175 } else { 174 } else {
176 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (ROOT)\n")); 175 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "%s\n",
176 ACPI_NAMESPACE_ROOT));
177 } 177 }
178 178
179 acpi_ut_delete_generic_state(scope_info); 179 acpi_ut_delete_generic_state(scope_info);
diff --git a/drivers/acpi/acpica/evgpe.c b/drivers/acpi/acpica/evgpe.c
index abbd59063906..e10fec99a182 100644
--- a/drivers/acpi/acpica/evgpe.c
+++ b/drivers/acpi/acpica/evgpe.c
@@ -634,6 +634,12 @@ acpi_ev_detect_gpe(struct acpi_namespace_node *gpe_device,
634 634
635 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); 635 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
636 636
637 if (!gpe_event_info) {
638 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
639 if (!gpe_event_info)
640 goto error_exit;
641 }
642
637 /* Get the info block for the entire GPE register */ 643 /* Get the info block for the entire GPE register */
638 644
639 gpe_register_info = gpe_event_info->register_info; 645 gpe_register_info = gpe_event_info->register_info;
diff --git a/drivers/acpi/acpica/evxfgpe.c b/drivers/acpi/acpica/evxfgpe.c
index c80e3bdf4805..b2d5f66cc1b0 100644
--- a/drivers/acpi/acpica/evxfgpe.c
+++ b/drivers/acpi/acpica/evxfgpe.c
@@ -639,6 +639,28 @@ ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
639 639
640/******************************************************************************* 640/*******************************************************************************
641 * 641 *
642 * FUNCTION: acpi_gispatch_gpe
643 *
644 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
645 * gpe_number - GPE level within the GPE block
646 *
647 * RETURN: None
648 *
649 * DESCRIPTION: Detect and dispatch a General Purpose Event to either a function
650 * (e.g. EC) or method (e.g. _Lxx/_Exx) handler.
651 *
652 ******************************************************************************/
653void acpi_dispatch_gpe(acpi_handle gpe_device, u32 gpe_number)
654{
655 ACPI_FUNCTION_TRACE(acpi_dispatch_gpe);
656
657 acpi_ev_detect_gpe(gpe_device, NULL, gpe_number);
658}
659
660ACPI_EXPORT_SYMBOL(acpi_dispatch_gpe)
661
662/*******************************************************************************
663 *
642 * FUNCTION: acpi_finish_gpe 664 * FUNCTION: acpi_finish_gpe
643 * 665 *
644 * PARAMETERS: gpe_device - Namespace node for the GPE Block 666 * PARAMETERS: gpe_device - Namespace node for the GPE Block
diff --git a/drivers/acpi/acpica/exconfig.c b/drivers/acpi/acpica/exconfig.c
index 99d92cb32803..2373a7492151 100644
--- a/drivers/acpi/acpica/exconfig.c
+++ b/drivers/acpi/acpica/exconfig.c
@@ -174,6 +174,13 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
174 return_ACPI_STATUS(status); 174 return_ACPI_STATUS(status);
175 } 175 }
176 176
177 /* Complete the initialization/resolution of package objects */
178
179 status = acpi_ns_walk_namespace(ACPI_TYPE_PACKAGE, ACPI_ROOT_OBJECT,
180 ACPI_UINT32_MAX, 0,
181 acpi_ns_init_one_package, NULL, NULL,
182 NULL);
183
177 /* Parameter Data (optional) */ 184 /* Parameter Data (optional) */
178 185
179 if (parameter_node) { 186 if (parameter_node) {
@@ -430,6 +437,13 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
430 return_ACPI_STATUS(status); 437 return_ACPI_STATUS(status);
431 } 438 }
432 439
440 /* Complete the initialization/resolution of package objects */
441
442 status = acpi_ns_walk_namespace(ACPI_TYPE_PACKAGE, ACPI_ROOT_OBJECT,
443 ACPI_UINT32_MAX, 0,
444 acpi_ns_init_one_package, NULL, NULL,
445 NULL);
446
433 /* Store the ddb_handle into the Target operand */ 447 /* Store the ddb_handle into the Target operand */
434 448
435 status = acpi_ex_store(ddb_handle, target, walk_state); 449 status = acpi_ex_store(ddb_handle, target, walk_state);
@@ -476,6 +490,17 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
476 ACPI_WARNING((AE_INFO, "Received request to unload an ACPI table")); 490 ACPI_WARNING((AE_INFO, "Received request to unload an ACPI table"));
477 491
478 /* 492 /*
493 * May 2018: Unload is no longer supported for the following reasons:
494 * 1) A correct implementation on some hosts may not be possible.
495 * 2) Other ACPI implementations do not correctly/fully support it.
496 * 3) It requires host device driver support which does not exist.
497 * (To properly support namespace unload out from underneath.)
498 * 4) This AML operator has never been seen in the field.
499 */
500 ACPI_EXCEPTION((AE_INFO, AE_NOT_IMPLEMENTED,
501 "AML Unload operator is not supported"));
502
503 /*
479 * Validate the handle 504 * Validate the handle
480 * Although the handle is partially validated in acpi_ex_reconfiguration() 505 * Although the handle is partially validated in acpi_ex_reconfiguration()
481 * when it calls acpi_ex_resolve_operands(), the handle is more completely 506 * when it calls acpi_ex_resolve_operands(), the handle is more completely
diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c
index 27a86ad55b58..3de794bcf8fa 100644
--- a/drivers/acpi/acpica/hwregs.c
+++ b/drivers/acpi/acpica/hwregs.c
@@ -390,14 +390,14 @@ acpi_status acpi_hw_clear_acpi_status(void)
390 ACPI_BITMASK_ALL_FIXED_STATUS, 390 ACPI_BITMASK_ALL_FIXED_STATUS,
391 ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address))); 391 ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address)));
392 392
393 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); 393 lock_flags = acpi_os_acquire_raw_lock(acpi_gbl_hardware_lock);
394 394
395 /* Clear the fixed events in PM1 A/B */ 395 /* Clear the fixed events in PM1 A/B */
396 396
397 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, 397 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
398 ACPI_BITMASK_ALL_FIXED_STATUS); 398 ACPI_BITMASK_ALL_FIXED_STATUS);
399 399
400 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); 400 acpi_os_release_raw_lock(acpi_gbl_hardware_lock, lock_flags);
401 401
402 if (ACPI_FAILURE(status)) { 402 if (ACPI_FAILURE(status)) {
403 goto exit; 403 goto exit;
diff --git a/drivers/acpi/acpica/hwxface.c b/drivers/acpi/acpica/hwxface.c
index 5d1396870bd0..6e39a771a56e 100644
--- a/drivers/acpi/acpica/hwxface.c
+++ b/drivers/acpi/acpica/hwxface.c
@@ -227,7 +227,7 @@ acpi_status acpi_write_bit_register(u32 register_id, u32 value)
227 return_ACPI_STATUS(AE_BAD_PARAMETER); 227 return_ACPI_STATUS(AE_BAD_PARAMETER);
228 } 228 }
229 229
230 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); 230 lock_flags = acpi_os_acquire_raw_lock(acpi_gbl_hardware_lock);
231 231
232 /* 232 /*
233 * At this point, we know that the parent register is one of the 233 * At this point, we know that the parent register is one of the
@@ -288,7 +288,7 @@ acpi_status acpi_write_bit_register(u32 register_id, u32 value)
288 288
289unlock_and_exit: 289unlock_and_exit:
290 290
291 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); 291 acpi_os_release_raw_lock(acpi_gbl_hardware_lock, lock_flags);
292 return_ACPI_STATUS(status); 292 return_ACPI_STATUS(status);
293} 293}
294 294
diff --git a/drivers/acpi/acpica/nsdump.c b/drivers/acpi/acpica/nsdump.c
index 4bdbd1d8431b..90ccffcd770b 100644
--- a/drivers/acpi/acpica/nsdump.c
+++ b/drivers/acpi/acpica/nsdump.c
@@ -170,6 +170,7 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
170 } 170 }
171 171
172 type = this_node->type; 172 type = this_node->type;
173 info->count++;
173 174
174 /* Check if the owner matches */ 175 /* Check if the owner matches */
175 176
@@ -639,6 +640,7 @@ acpi_ns_dump_objects(acpi_object_type type,
639 return; 640 return;
640 } 641 }
641 642
643 info.count = 0;
642 info.debug_level = ACPI_LV_TABLES; 644 info.debug_level = ACPI_LV_TABLES;
643 info.owner_id = owner_id; 645 info.owner_id = owner_id;
644 info.display_type = display_type; 646 info.display_type = display_type;
@@ -649,6 +651,7 @@ acpi_ns_dump_objects(acpi_object_type type,
649 acpi_ns_dump_one_object, NULL, 651 acpi_ns_dump_one_object, NULL,
650 (void *)&info, NULL); 652 (void *)&info, NULL);
651 653
654 acpi_os_printf("\nNamespace node count: %u\n\n", info.count);
652 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 655 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
653} 656}
654 657
diff --git a/drivers/acpi/acpica/nsinit.c b/drivers/acpi/acpica/nsinit.c
index 77f2b5f4948a..d77257d1c827 100644
--- a/drivers/acpi/acpica/nsinit.c
+++ b/drivers/acpi/acpica/nsinit.c
@@ -242,6 +242,58 @@ error_exit:
242 242
243/******************************************************************************* 243/*******************************************************************************
244 * 244 *
245 * FUNCTION: acpi_ns_init_one_package
246 *
247 * PARAMETERS: obj_handle - Node
248 * level - Current nesting level
249 * context - Not used
250 * return_value - Not used
251 *
252 * RETURN: Status
253 *
254 * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every package
255 * within the namespace. Used during dynamic load of an SSDT.
256 *
257 ******************************************************************************/
258
259acpi_status
260acpi_ns_init_one_package(acpi_handle obj_handle,
261 u32 level, void *context, void **return_value)
262{
263 acpi_status status;
264 union acpi_operand_object *obj_desc;
265 struct acpi_namespace_node *node =
266 (struct acpi_namespace_node *)obj_handle;
267
268 obj_desc = acpi_ns_get_attached_object(node);
269 if (!obj_desc) {
270 return (AE_OK);
271 }
272
273 /* Exit if package is already initialized */
274
275 if (obj_desc->package.flags & AOPOBJ_DATA_VALID) {
276 return (AE_OK);
277 }
278
279 status = acpi_ds_get_package_arguments(obj_desc);
280 if (ACPI_FAILURE(status)) {
281 return (AE_OK);
282 }
283
284 status =
285 acpi_ut_walk_package_tree(obj_desc, NULL,
286 acpi_ds_init_package_element, NULL);
287 if (ACPI_FAILURE(status)) {
288 return (AE_OK);
289 }
290
291 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
292 return (AE_OK);
293}
294
295/*******************************************************************************
296 *
245 * FUNCTION: acpi_ns_init_one_object 297 * FUNCTION: acpi_ns_init_one_object
246 * 298 *
247 * PARAMETERS: obj_handle - Node 299 * PARAMETERS: obj_handle - Node
@@ -360,27 +412,11 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
360 412
361 case ACPI_TYPE_PACKAGE: 413 case ACPI_TYPE_PACKAGE:
362 414
363 info->package_init++; 415 /* Complete the initialization/resolution of the package object */
364 status = acpi_ds_get_package_arguments(obj_desc);
365 if (ACPI_FAILURE(status)) {
366 break;
367 }
368
369 ACPI_DEBUG_PRINT_RAW((ACPI_DB_PARSE,
370 "%s: Completing resolution of Package elements\n",
371 ACPI_GET_FUNCTION_NAME));
372 416
373 /* 417 info->package_init++;
374 * Resolve all named references in package objects (and all 418 status =
375 * sub-packages). This action has been deferred until the entire 419 acpi_ns_init_one_package(obj_handle, level, NULL, NULL);
376 * namespace has been loaded, in order to support external and
377 * forward references from individual package elements (05/2017).
378 */
379 status = acpi_ut_walk_package_tree(obj_desc, NULL,
380 acpi_ds_init_package_element,
381 NULL);
382
383 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
384 break; 420 break;
385 421
386 default: 422 default:
diff --git a/drivers/acpi/acpica/psloop.c b/drivers/acpi/acpica/psloop.c
index 68422afc365f..bc5f05906bd1 100644
--- a/drivers/acpi/acpica/psloop.c
+++ b/drivers/acpi/acpica/psloop.c
@@ -515,6 +515,22 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
515 if (ACPI_FAILURE(status)) { 515 if (ACPI_FAILURE(status)) {
516 return_ACPI_STATUS(status); 516 return_ACPI_STATUS(status);
517 } 517 }
518 if (walk_state->opcode == AML_SCOPE_OP) {
519 /*
520 * If the scope op fails to parse, skip the body of the
521 * scope op because the parse failure indicates that the
522 * device may not exist.
523 */
524 walk_state->parser_state.aml =
525 walk_state->aml + 1;
526 walk_state->parser_state.aml =
527 acpi_ps_get_next_package_end
528 (&walk_state->parser_state);
529 walk_state->aml =
530 walk_state->parser_state.aml;
531 ACPI_ERROR((AE_INFO,
532 "Skipping Scope block"));
533 }
518 534
519 continue; 535 continue;
520 } 536 }
@@ -557,7 +573,40 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
557 if (ACPI_FAILURE(status)) { 573 if (ACPI_FAILURE(status)) {
558 return_ACPI_STATUS(status); 574 return_ACPI_STATUS(status);
559 } 575 }
560 576 if ((walk_state->control_state) &&
577 ((walk_state->control_state->control.
578 opcode == AML_IF_OP)
579 || (walk_state->control_state->control.
580 opcode == AML_WHILE_OP))) {
581 /*
582 * If the if/while op fails to parse, we will skip parsing
583 * the body of the op.
584 */
585 parser_state->aml =
586 walk_state->control_state->control.
587 aml_predicate_start + 1;
588 parser_state->aml =
589 acpi_ps_get_next_package_end
590 (parser_state);
591 walk_state->aml = parser_state->aml;
592
593 ACPI_ERROR((AE_INFO,
594 "Skipping While/If block"));
595 if (*walk_state->aml == AML_ELSE_OP) {
596 ACPI_ERROR((AE_INFO,
597 "Skipping Else block"));
598 walk_state->parser_state.aml =
599 walk_state->aml + 1;
600 walk_state->parser_state.aml =
601 acpi_ps_get_next_package_end
602 (parser_state);
603 walk_state->aml =
604 parser_state->aml;
605 }
606 ACPI_FREE(acpi_ut_pop_generic_state
607 (&walk_state->control_state));
608 }
609 op = NULL;
561 continue; 610 continue;
562 } 611 }
563 } 612 }
diff --git a/drivers/acpi/acpica/psobject.c b/drivers/acpi/acpica/psobject.c
index 7d9d0151ee54..3138e7a00da8 100644
--- a/drivers/acpi/acpica/psobject.c
+++ b/drivers/acpi/acpica/psobject.c
@@ -12,6 +12,7 @@
12#include "acparser.h" 12#include "acparser.h"
13#include "amlcode.h" 13#include "amlcode.h"
14#include "acconvert.h" 14#include "acconvert.h"
15#include "acnamesp.h"
15 16
16#define _COMPONENT ACPI_PARSER 17#define _COMPONENT ACPI_PARSER
17ACPI_MODULE_NAME("psobject") 18ACPI_MODULE_NAME("psobject")
@@ -549,6 +550,21 @@ acpi_ps_complete_op(struct acpi_walk_state *walk_state,
549 550
550 do { 551 do {
551 if (*op) { 552 if (*op) {
553 /*
554 * These Opcodes need to be removed from the namespace because they
555 * get created even if these opcodes cannot be created due to
556 * errors.
557 */
558 if (((*op)->common.aml_opcode == AML_REGION_OP)
559 || ((*op)->common.aml_opcode ==
560 AML_DATA_REGION_OP)) {
561 acpi_ns_delete_children((*op)->common.
562 node);
563 acpi_ns_remove_node((*op)->common.node);
564 (*op)->common.node = NULL;
565 acpi_ps_delete_parse_tree(*op);
566 }
567
552 status2 = 568 status2 =
553 acpi_ps_complete_this_op(walk_state, *op); 569 acpi_ps_complete_this_op(walk_state, *op);
554 if (ACPI_FAILURE(status2)) { 570 if (ACPI_FAILURE(status2)) {
@@ -574,6 +590,20 @@ acpi_ps_complete_op(struct acpi_walk_state *walk_state,
574#endif 590#endif
575 walk_state->prev_op = NULL; 591 walk_state->prev_op = NULL;
576 walk_state->prev_arg_types = walk_state->arg_types; 592 walk_state->prev_arg_types = walk_state->arg_types;
593
594 if (walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL) {
595 /*
596 * There was something that went wrong while executing code at the
597 * module-level. We need to skip parsing whatever caused the
598 * error and keep going. One runtime error during the table load
599 * should not cause the entire table to not be loaded. This is
600 * because there could be correct AML beyond the parts that caused
601 * the runtime error.
602 */
603 ACPI_ERROR((AE_INFO,
604 "Ignore error and continue table load"));
605 return_ACPI_STATUS(AE_OK);
606 }
577 return_ACPI_STATUS(status); 607 return_ACPI_STATUS(status);
578 } 608 }
579 609
diff --git a/drivers/acpi/acpica/pswalk.c b/drivers/acpi/acpica/pswalk.c
index e0a442b8648b..bd6af8c87d48 100644
--- a/drivers/acpi/acpica/pswalk.c
+++ b/drivers/acpi/acpica/pswalk.c
@@ -25,22 +25,48 @@ ACPI_MODULE_NAME("pswalk")
25 * DESCRIPTION: Delete a portion of or an entire parse tree. 25 * DESCRIPTION: Delete a portion of or an entire parse tree.
26 * 26 *
27 ******************************************************************************/ 27 ******************************************************************************/
28#include "amlcode.h"
28void acpi_ps_delete_parse_tree(union acpi_parse_object *subtree_root) 29void acpi_ps_delete_parse_tree(union acpi_parse_object *subtree_root)
29{ 30{
30 union acpi_parse_object *op = subtree_root; 31 union acpi_parse_object *op = subtree_root;
31 union acpi_parse_object *next = NULL; 32 union acpi_parse_object *next = NULL;
32 union acpi_parse_object *parent = NULL; 33 union acpi_parse_object *parent = NULL;
34 u32 level = 0;
33 35
34 ACPI_FUNCTION_TRACE_PTR(ps_delete_parse_tree, subtree_root); 36 ACPI_FUNCTION_TRACE_PTR(ps_delete_parse_tree, subtree_root);
35 37
38 ACPI_DEBUG_PRINT((ACPI_DB_PARSE_TREES, " root %p\n", subtree_root));
39
36 /* Visit all nodes in the subtree */ 40 /* Visit all nodes in the subtree */
37 41
38 while (op) { 42 while (op) {
39
40 /* Check if we are not ascending */
41
42 if (op != parent) { 43 if (op != parent) {
43 44
45 /* This is the descending case */
46
47 if (ACPI_IS_DEBUG_ENABLED
48 (ACPI_LV_PARSE_TREES, _COMPONENT)) {
49
50 /* This debug option will print the entire parse tree */
51
52 acpi_os_printf(" %*.s%s %p", (level * 4),
53 " ",
54 acpi_ps_get_opcode_name(op->
55 common.
56 aml_opcode),
57 op);
58
59 if (op->named.aml_opcode == AML_INT_NAMEPATH_OP) {
60 acpi_os_printf(" %4.4s",
61 op->common.value.string);
62 }
63 if (op->named.aml_opcode == AML_STRING_OP) {
64 acpi_os_printf(" %s",
65 op->common.value.string);
66 }
67 acpi_os_printf("\n");
68 }
69
44 /* Look for an argument or child of the current op */ 70 /* Look for an argument or child of the current op */
45 71
46 next = acpi_ps_get_arg(op, 0); 72 next = acpi_ps_get_arg(op, 0);
@@ -49,6 +75,7 @@ void acpi_ps_delete_parse_tree(union acpi_parse_object *subtree_root)
49 /* Still going downward in tree (Op is not completed yet) */ 75 /* Still going downward in tree (Op is not completed yet) */
50 76
51 op = next; 77 op = next;
78 level++;
52 continue; 79 continue;
53 } 80 }
54 } 81 }
@@ -69,6 +96,7 @@ void acpi_ps_delete_parse_tree(union acpi_parse_object *subtree_root)
69 if (next) { 96 if (next) {
70 op = next; 97 op = next;
71 } else { 98 } else {
99 level--;
72 op = parent; 100 op = parent;
73 } 101 }
74 } 102 }
diff --git a/drivers/acpi/acpica/rsdump.c b/drivers/acpi/acpica/rsdump.c
index b12a0b1cd9ce..6601e71b45e3 100644
--- a/drivers/acpi/acpica/rsdump.c
+++ b/drivers/acpi/acpica/rsdump.c
@@ -539,7 +539,7 @@ static void acpi_rs_out_title(const char *title)
539 539
540static void acpi_rs_dump_byte_list(u16 length, u8 * data) 540static void acpi_rs_dump_byte_list(u16 length, u8 * data)
541{ 541{
542 u8 i; 542 u16 i;
543 543
544 for (i = 0; i < length; i++) { 544 for (i = 0; i < length; i++) {
545 acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]); 545 acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
diff --git a/drivers/acpi/acpica/tbinstal.c b/drivers/acpi/acpica/tbinstal.c
index c5085b7ae8c9..5f8e7b561c90 100644
--- a/drivers/acpi/acpica/tbinstal.c
+++ b/drivers/acpi/acpica/tbinstal.c
@@ -88,7 +88,7 @@ acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc,
88 * DESCRIPTION: This function is called to verify and install an ACPI table. 88 * DESCRIPTION: This function is called to verify and install an ACPI table.
89 * When this function is called by "Load" or "LoadTable" opcodes, 89 * When this function is called by "Load" or "LoadTable" opcodes,
90 * or by acpi_load_table() API, the "Reload" parameter is set. 90 * or by acpi_load_table() API, the "Reload" parameter is set.
91 * After sucessfully returning from this function, table is 91 * After successfully returning from this function, table is
92 * "INSTALLED" but not "VALIDATED". 92 * "INSTALLED" but not "VALIDATED".
93 * 93 *
94 ******************************************************************************/ 94 ******************************************************************************/
diff --git a/drivers/acpi/acpica/utbuffer.c b/drivers/acpi/acpica/utbuffer.c
index 148aeb84e561..fffa6f5ae59e 100644
--- a/drivers/acpi/acpica/utbuffer.c
+++ b/drivers/acpi/acpica/utbuffer.c
@@ -53,7 +53,7 @@ void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 base_offset)
53 53
54 /* Print current offset */ 54 /* Print current offset */
55 55
56 acpi_os_printf("%6.4X: ", (base_offset + i)); 56 acpi_os_printf("%8.4X: ", (base_offset + i));
57 57
58 /* Print 16 hex chars */ 58 /* Print 16 hex chars */
59 59
@@ -219,7 +219,7 @@ acpi_ut_dump_buffer_to_file(ACPI_FILE file,
219 219
220 /* Print current offset */ 220 /* Print current offset */
221 221
222 fprintf(file, "%6.4X: ", (base_offset + i)); 222 fprintf(file, "%8.4X: ", (base_offset + i));
223 223
224 /* Print 16 hex chars */ 224 /* Print 16 hex chars */
225 225
diff --git a/drivers/acpi/acpica/uterror.c b/drivers/acpi/acpica/uterror.c
index 12d4a0f6b8d2..5a64ddaed8a3 100644
--- a/drivers/acpi/acpica/uterror.c
+++ b/drivers/acpi/acpica/uterror.c
@@ -182,20 +182,20 @@ acpi_ut_prefixed_namespace_error(const char *module_name,
182 switch (lookup_status) { 182 switch (lookup_status) {
183 case AE_ALREADY_EXISTS: 183 case AE_ALREADY_EXISTS:
184 184
185 acpi_os_printf(ACPI_MSG_BIOS_ERROR); 185 acpi_os_printf("\n" ACPI_MSG_BIOS_ERROR);
186 message = "Failure creating"; 186 message = "Failure creating";
187 break; 187 break;
188 188
189 case AE_NOT_FOUND: 189 case AE_NOT_FOUND:
190 190
191 acpi_os_printf(ACPI_MSG_BIOS_ERROR); 191 acpi_os_printf("\n" ACPI_MSG_BIOS_ERROR);
192 message = "Failure looking up"; 192 message = "Could not resolve";
193 break; 193 break;
194 194
195 default: 195 default:
196 196
197 acpi_os_printf(ACPI_MSG_ERROR); 197 acpi_os_printf("\n" ACPI_MSG_ERROR);
198 message = "Failure looking up"; 198 message = "Failure resolving";
199 break; 199 break;
200 } 200 }
201 201
diff --git a/drivers/acpi/acpica/utmutex.c b/drivers/acpi/acpica/utmutex.c
index d2d93e388f40..2e465e6a0ab6 100644
--- a/drivers/acpi/acpica/utmutex.c
+++ b/drivers/acpi/acpica/utmutex.c
@@ -52,7 +52,7 @@ acpi_status acpi_ut_mutex_initialize(void)
52 return_ACPI_STATUS (status); 52 return_ACPI_STATUS (status);
53 } 53 }
54 54
55 status = acpi_os_create_lock (&acpi_gbl_hardware_lock); 55 status = acpi_os_create_raw_lock(&acpi_gbl_hardware_lock);
56 if (ACPI_FAILURE (status)) { 56 if (ACPI_FAILURE (status)) {
57 return_ACPI_STATUS (status); 57 return_ACPI_STATUS (status);
58 } 58 }
@@ -109,7 +109,7 @@ void acpi_ut_mutex_terminate(void)
109 /* Delete the spinlocks */ 109 /* Delete the spinlocks */
110 110
111 acpi_os_delete_lock(acpi_gbl_gpe_lock); 111 acpi_os_delete_lock(acpi_gbl_gpe_lock);
112 acpi_os_delete_lock(acpi_gbl_hardware_lock); 112 acpi_os_delete_raw_lock(acpi_gbl_hardware_lock);
113 acpi_os_delete_lock(acpi_gbl_reference_count_lock); 113 acpi_os_delete_lock(acpi_gbl_reference_count_lock);
114 114
115 /* Delete the reader/writer lock */ 115 /* Delete the reader/writer lock */
diff --git a/drivers/acpi/acpica/utobject.c b/drivers/acpi/acpica/utobject.c
index 5b78fe08d7d7..ae6d8cc18cec 100644
--- a/drivers/acpi/acpica/utobject.c
+++ b/drivers/acpi/acpica/utobject.c
@@ -8,6 +8,7 @@
8 *****************************************************************************/ 8 *****************************************************************************/
9 9
10#include <acpi/acpi.h> 10#include <acpi/acpi.h>
11#include <linux/kmemleak.h>
11#include "accommon.h" 12#include "accommon.h"
12#include "acnamesp.h" 13#include "acnamesp.h"
13 14
@@ -70,6 +71,7 @@ union acpi_operand_object *acpi_ut_create_internal_object_dbg(const char
70 if (!object) { 71 if (!object) {
71 return_PTR(NULL); 72 return_PTR(NULL);
72 } 73 }
74 kmemleak_not_leak(object);
73 75
74 switch (type) { 76 switch (type) {
75 case ACPI_TYPE_REGION: 77 case ACPI_TYPE_REGION:
diff --git a/drivers/acpi/acpica/utosi.c b/drivers/acpi/acpica/utosi.c
index 1b415fa90cf8..64b63c81994b 100644
--- a/drivers/acpi/acpica/utosi.c
+++ b/drivers/acpi/acpica/utosi.c
@@ -69,6 +69,7 @@ static struct acpi_interface_info acpi_default_supported_interfaces[] = {
69 {"Windows 2015", NULL, 0, ACPI_OSI_WIN_10}, /* Windows 10 - Added 03/2015 */ 69 {"Windows 2015", NULL, 0, ACPI_OSI_WIN_10}, /* Windows 10 - Added 03/2015 */
70 {"Windows 2016", NULL, 0, ACPI_OSI_WIN_10_RS1}, /* Windows 10 version 1607 - Added 12/2017 */ 70 {"Windows 2016", NULL, 0, ACPI_OSI_WIN_10_RS1}, /* Windows 10 version 1607 - Added 12/2017 */
71 {"Windows 2017", NULL, 0, ACPI_OSI_WIN_10_RS2}, /* Windows 10 version 1703 - Added 12/2017 */ 71 {"Windows 2017", NULL, 0, ACPI_OSI_WIN_10_RS2}, /* Windows 10 version 1703 - Added 12/2017 */
72 {"Windows 2017.2", NULL, 0, ACPI_OSI_WIN_10_RS3}, /* Windows 10 version 1709 - Added 02/2018 */
72 73
73 /* Feature Group Strings */ 74 /* Feature Group Strings */
74 75
diff --git a/drivers/acpi/acpica/utprint.c b/drivers/acpi/acpica/utprint.c
index 35ffd8d51c65..a98c334c3bb7 100644
--- a/drivers/acpi/acpica/utprint.c
+++ b/drivers/acpi/acpica/utprint.c
@@ -470,6 +470,7 @@ int vsnprintf(char *string, acpi_size size, const char *format, va_list args)
470 case 'X': 470 case 'X':
471 471
472 type |= ACPI_FORMAT_UPPER; 472 type |= ACPI_FORMAT_UPPER;
473 /* FALLTHROUGH */
473 474
474 case 'x': 475 case 'x':
475 476
diff --git a/drivers/acpi/acpica/utstring.c b/drivers/acpi/acpica/utstring.c
index bd57a77bbcb2..5bef0b059406 100644
--- a/drivers/acpi/acpica/utstring.c
+++ b/drivers/acpi/acpica/utstring.c
@@ -141,7 +141,7 @@ void acpi_ut_repair_name(char *name)
141 * Special case for the root node. This can happen if we get an 141 * Special case for the root node. This can happen if we get an
142 * error during the execution of module-level code. 142 * error during the execution of module-level code.
143 */ 143 */
144 if (ACPI_COMPARE_NAME(name, "\\___")) { 144 if (ACPI_COMPARE_NAME(name, ACPI_ROOT_PATHNAME)) {
145 return; 145 return;
146 } 146 }
147 147
diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
index 9bff853e85f3..3c5ea7cb693e 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -524,7 +524,8 @@ retry:
524 pr_warn(FW_WARN "too many record IDs!\n"); 524 pr_warn(FW_WARN "too many record IDs!\n");
525 return 0; 525 return 0;
526 } 526 }
527 new_entries = kvmalloc(new_size * sizeof(entries[0]), GFP_KERNEL); 527 new_entries = kvmalloc_array(new_size, sizeof(entries[0]),
528 GFP_KERNEL);
528 if (!new_entries) 529 if (!new_entries)
529 return -ENOMEM; 530 return -ENOMEM;
530 memcpy(new_entries, entries, 531 memcpy(new_entries, entries,
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index 1efefe919555..02c6fd9caff7 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -481,7 +481,7 @@ static void ghes_do_proc(struct ghes *ghes,
481 if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM)) { 481 if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM)) {
482 struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata); 482 struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata);
483 483
484 ghes_edac_report_mem_error(ghes, sev, mem_err); 484 ghes_edac_report_mem_error(sev, mem_err);
485 485
486 arch_apei_report_mem_error(sev, mem_err); 486 arch_apei_report_mem_error(sev, mem_err);
487 ghes_handle_memory_failure(gdata, sev); 487 ghes_handle_memory_failure(gdata, sev);
@@ -1087,10 +1087,6 @@ static int ghes_probe(struct platform_device *ghes_dev)
1087 goto err; 1087 goto err;
1088 } 1088 }
1089 1089
1090 rc = ghes_edac_register(ghes, &ghes_dev->dev);
1091 if (rc < 0)
1092 goto err;
1093
1094 switch (generic->notify.type) { 1090 switch (generic->notify.type) {
1095 case ACPI_HEST_NOTIFY_POLLED: 1091 case ACPI_HEST_NOTIFY_POLLED:
1096 timer_setup(&ghes->timer, ghes_poll_func, TIMER_DEFERRABLE); 1092 timer_setup(&ghes->timer, ghes_poll_func, TIMER_DEFERRABLE);
@@ -1102,14 +1098,14 @@ static int ghes_probe(struct platform_device *ghes_dev)
1102 if (rc) { 1098 if (rc) {
1103 pr_err(GHES_PFX "Failed to map GSI to IRQ for generic hardware error source: %d\n", 1099 pr_err(GHES_PFX "Failed to map GSI to IRQ for generic hardware error source: %d\n",
1104 generic->header.source_id); 1100 generic->header.source_id);
1105 goto err_edac_unreg; 1101 goto err;
1106 } 1102 }
1107 rc = request_irq(ghes->irq, ghes_irq_func, IRQF_SHARED, 1103 rc = request_irq(ghes->irq, ghes_irq_func, IRQF_SHARED,
1108 "GHES IRQ", ghes); 1104 "GHES IRQ", ghes);
1109 if (rc) { 1105 if (rc) {
1110 pr_err(GHES_PFX "Failed to register IRQ for generic hardware error source: %d\n", 1106 pr_err(GHES_PFX "Failed to register IRQ for generic hardware error source: %d\n",
1111 generic->header.source_id); 1107 generic->header.source_id);
1112 goto err_edac_unreg; 1108 goto err;
1113 } 1109 }
1114 break; 1110 break;
1115 1111
@@ -1132,14 +1128,16 @@ static int ghes_probe(struct platform_device *ghes_dev)
1132 default: 1128 default:
1133 BUG(); 1129 BUG();
1134 } 1130 }
1131
1135 platform_set_drvdata(ghes_dev, ghes); 1132 platform_set_drvdata(ghes_dev, ghes);
1136 1133
1134 ghes_edac_register(ghes, &ghes_dev->dev);
1135
1137 /* Handle any pending errors right away */ 1136 /* Handle any pending errors right away */
1138 ghes_proc(ghes); 1137 ghes_proc(ghes);
1139 1138
1140 return 0; 1139 return 0;
1141err_edac_unreg: 1140
1142 ghes_edac_unregister(ghes);
1143err: 1141err:
1144 if (ghes) { 1142 if (ghes) {
1145 ghes_fini(ghes); 1143 ghes_fini(ghes);
diff --git a/drivers/acpi/apei/hest.c b/drivers/acpi/apei/hest.c
index 9cb74115a43d..b1e9f81ebeea 100644
--- a/drivers/acpi/apei/hest.c
+++ b/drivers/acpi/apei/hest.c
@@ -195,7 +195,8 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count)
195 struct ghes_arr ghes_arr; 195 struct ghes_arr ghes_arr;
196 196
197 ghes_arr.count = 0; 197 ghes_arr.count = 0;
198 ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL); 198 ghes_arr.ghes_devs = kmalloc_array(ghes_count, sizeof(void *),
199 GFP_KERNEL);
199 if (!ghes_arr.ghes_devs) 200 if (!ghes_arr.ghes_devs)
200 return -ENOMEM; 201 return -ENOMEM;
201 202
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index bdb24d636d9a..b0113a5802a3 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -74,6 +74,8 @@ static async_cookie_t async_cookie;
74static bool battery_driver_registered; 74static bool battery_driver_registered;
75static int battery_bix_broken_package; 75static int battery_bix_broken_package;
76static int battery_notification_delay_ms; 76static int battery_notification_delay_ms;
77static int battery_ac_is_broken;
78static int battery_check_pmic = 1;
77static unsigned int cache_time = 1000; 79static unsigned int cache_time = 1000;
78module_param(cache_time, uint, 0644); 80module_param(cache_time, uint, 0644);
79MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); 81MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
@@ -81,14 +83,6 @@ MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
81#ifdef CONFIG_ACPI_PROCFS_POWER 83#ifdef CONFIG_ACPI_PROCFS_POWER
82extern struct proc_dir_entry *acpi_lock_battery_dir(void); 84extern struct proc_dir_entry *acpi_lock_battery_dir(void);
83extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); 85extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
84
85enum acpi_battery_files {
86 info_tag = 0,
87 state_tag,
88 alarm_tag,
89 ACPI_BATTERY_NUMFILES,
90};
91
92#endif 86#endif
93 87
94static const struct acpi_device_id battery_device_ids[] = { 88static const struct acpi_device_id battery_device_ids[] = {
@@ -215,6 +209,20 @@ static bool acpi_battery_is_degraded(struct acpi_battery *battery)
215 battery->full_charge_capacity < battery->design_capacity; 209 battery->full_charge_capacity < battery->design_capacity;
216} 210}
217 211
212static int acpi_battery_handle_discharging(struct acpi_battery *battery)
213{
214 /*
215 * Some devices wrongly report discharging if the battery's charge level
216 * was above the device's start charging threshold atm the AC adapter
217 * was plugged in and the device thus did not start a new charge cycle.
218 */
219 if ((battery_ac_is_broken || power_supply_is_system_supplied()) &&
220 battery->rate_now == 0)
221 return POWER_SUPPLY_STATUS_NOT_CHARGING;
222
223 return POWER_SUPPLY_STATUS_DISCHARGING;
224}
225
218static int acpi_battery_get_property(struct power_supply *psy, 226static int acpi_battery_get_property(struct power_supply *psy,
219 enum power_supply_property psp, 227 enum power_supply_property psp,
220 union power_supply_propval *val) 228 union power_supply_propval *val)
@@ -230,7 +238,7 @@ static int acpi_battery_get_property(struct power_supply *psy,
230 switch (psp) { 238 switch (psp) {
231 case POWER_SUPPLY_PROP_STATUS: 239 case POWER_SUPPLY_PROP_STATUS:
232 if (battery->state & ACPI_BATTERY_STATE_DISCHARGING) 240 if (battery->state & ACPI_BATTERY_STATE_DISCHARGING)
233 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; 241 val->intval = acpi_battery_handle_discharging(battery);
234 else if (battery->state & ACPI_BATTERY_STATE_CHARGING) 242 else if (battery->state & ACPI_BATTERY_STATE_CHARGING)
235 val->intval = POWER_SUPPLY_STATUS_CHARGING; 243 val->intval = POWER_SUPPLY_STATUS_CHARGING;
236 else if (acpi_battery_is_charged(battery)) 244 else if (acpi_battery_is_charged(battery))
@@ -985,9 +993,10 @@ static const char *acpi_battery_units(const struct acpi_battery *battery)
985 "mA" : "mW"; 993 "mA" : "mW";
986} 994}
987 995
988static int acpi_battery_print_info(struct seq_file *seq, int result) 996static int acpi_battery_info_proc_show(struct seq_file *seq, void *offset)
989{ 997{
990 struct acpi_battery *battery = seq->private; 998 struct acpi_battery *battery = seq->private;
999 int result = acpi_battery_update(battery, false);
991 1000
992 if (result) 1001 if (result)
993 goto end; 1002 goto end;
@@ -1041,9 +1050,10 @@ static int acpi_battery_print_info(struct seq_file *seq, int result)
1041 return result; 1050 return result;
1042} 1051}
1043 1052
1044static int acpi_battery_print_state(struct seq_file *seq, int result) 1053static int acpi_battery_state_proc_show(struct seq_file *seq, void *offset)
1045{ 1054{
1046 struct acpi_battery *battery = seq->private; 1055 struct acpi_battery *battery = seq->private;
1056 int result = acpi_battery_update(battery, false);
1047 1057
1048 if (result) 1058 if (result)
1049 goto end; 1059 goto end;
@@ -1088,9 +1098,10 @@ static int acpi_battery_print_state(struct seq_file *seq, int result)
1088 return result; 1098 return result;
1089} 1099}
1090 1100
1091static int acpi_battery_print_alarm(struct seq_file *seq, int result) 1101static int acpi_battery_alarm_proc_show(struct seq_file *seq, void *offset)
1092{ 1102{
1093 struct acpi_battery *battery = seq->private; 1103 struct acpi_battery *battery = seq->private;
1104 int result = acpi_battery_update(battery, false);
1094 1105
1095 if (result) 1106 if (result)
1096 goto end; 1107 goto end;
@@ -1142,82 +1153,22 @@ static ssize_t acpi_battery_write_alarm(struct file *file,
1142 return result; 1153 return result;
1143} 1154}
1144 1155
1145typedef int(*print_func)(struct seq_file *seq, int result); 1156static int acpi_battery_alarm_proc_open(struct inode *inode, struct file *file)
1146
1147static print_func acpi_print_funcs[ACPI_BATTERY_NUMFILES] = {
1148 acpi_battery_print_info,
1149 acpi_battery_print_state,
1150 acpi_battery_print_alarm,
1151};
1152
1153static int acpi_battery_read(int fid, struct seq_file *seq)
1154{ 1157{
1155 struct acpi_battery *battery = seq->private; 1158 return single_open(file, acpi_battery_alarm_proc_show, PDE_DATA(inode));
1156 int result = acpi_battery_update(battery, false);
1157 return acpi_print_funcs[fid](seq, result);
1158}
1159
1160#define DECLARE_FILE_FUNCTIONS(_name) \
1161static int acpi_battery_read_##_name(struct seq_file *seq, void *offset) \
1162{ \
1163 return acpi_battery_read(_name##_tag, seq); \
1164} \
1165static int acpi_battery_##_name##_open_fs(struct inode *inode, struct file *file) \
1166{ \
1167 return single_open(file, acpi_battery_read_##_name, PDE_DATA(inode)); \
1168} 1159}
1169 1160
1170DECLARE_FILE_FUNCTIONS(info); 1161static const struct file_operations acpi_battery_alarm_fops = {
1171DECLARE_FILE_FUNCTIONS(state); 1162 .owner = THIS_MODULE,
1172DECLARE_FILE_FUNCTIONS(alarm); 1163 .open = acpi_battery_alarm_proc_open,
1173 1164 .read = seq_read,
1174#undef DECLARE_FILE_FUNCTIONS 1165 .write = acpi_battery_write_alarm,
1175 1166 .llseek = seq_lseek,
1176#define FILE_DESCRIPTION_RO(_name) \ 1167 .release = single_release,
1177 { \
1178 .name = __stringify(_name), \
1179 .mode = S_IRUGO, \
1180 .ops = { \
1181 .open = acpi_battery_##_name##_open_fs, \
1182 .read = seq_read, \
1183 .llseek = seq_lseek, \
1184 .release = single_release, \
1185 .owner = THIS_MODULE, \
1186 }, \
1187 }
1188
1189#define FILE_DESCRIPTION_RW(_name) \
1190 { \
1191 .name = __stringify(_name), \
1192 .mode = S_IFREG | S_IRUGO | S_IWUSR, \
1193 .ops = { \
1194 .open = acpi_battery_##_name##_open_fs, \
1195 .read = seq_read, \
1196 .llseek = seq_lseek, \
1197 .write = acpi_battery_write_##_name, \
1198 .release = single_release, \
1199 .owner = THIS_MODULE, \
1200 }, \
1201 }
1202
1203static const struct battery_file {
1204 struct file_operations ops;
1205 umode_t mode;
1206 const char *name;
1207} acpi_battery_file[] = {
1208 FILE_DESCRIPTION_RO(info),
1209 FILE_DESCRIPTION_RO(state),
1210 FILE_DESCRIPTION_RW(alarm),
1211}; 1168};
1212 1169
1213#undef FILE_DESCRIPTION_RO
1214#undef FILE_DESCRIPTION_RW
1215
1216static int acpi_battery_add_fs(struct acpi_device *device) 1170static int acpi_battery_add_fs(struct acpi_device *device)
1217{ 1171{
1218 struct proc_dir_entry *entry = NULL;
1219 int i;
1220
1221 printk(KERN_WARNING PREFIX "Deprecated procfs I/F for battery is loaded," 1172 printk(KERN_WARNING PREFIX "Deprecated procfs I/F for battery is loaded,"
1222 " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n"); 1173 " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
1223 if (!acpi_device_dir(device)) { 1174 if (!acpi_device_dir(device)) {
@@ -1227,28 +1178,24 @@ static int acpi_battery_add_fs(struct acpi_device *device)
1227 return -ENODEV; 1178 return -ENODEV;
1228 } 1179 }
1229 1180
1230 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) { 1181 if (!proc_create_single_data("info", S_IRUGO, acpi_device_dir(device),
1231 entry = proc_create_data(acpi_battery_file[i].name, 1182 acpi_battery_info_proc_show, acpi_driver_data(device)))
1232 acpi_battery_file[i].mode, 1183 return -ENODEV;
1233 acpi_device_dir(device), 1184 if (!proc_create_single_data("state", S_IRUGO, acpi_device_dir(device),
1234 &acpi_battery_file[i].ops, 1185 acpi_battery_state_proc_show, acpi_driver_data(device)))
1235 acpi_driver_data(device)); 1186 return -ENODEV;
1236 if (!entry) 1187 if (!proc_create_data("alarm", S_IFREG | S_IRUGO | S_IWUSR,
1237 return -ENODEV; 1188 acpi_device_dir(device), &acpi_battery_alarm_fops,
1238 } 1189 acpi_driver_data(device)))
1190 return -ENODEV;
1239 return 0; 1191 return 0;
1240} 1192}
1241 1193
1242static void acpi_battery_remove_fs(struct acpi_device *device) 1194static void acpi_battery_remove_fs(struct acpi_device *device)
1243{ 1195{
1244 int i;
1245 if (!acpi_device_dir(device)) 1196 if (!acpi_device_dir(device))
1246 return; 1197 return;
1247 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) 1198 remove_proc_subtree(acpi_device_bid(device), acpi_battery_dir);
1248 remove_proc_entry(acpi_battery_file[i].name,
1249 acpi_device_dir(device));
1250
1251 remove_proc_entry(acpi_device_bid(device), acpi_battery_dir);
1252 acpi_device_dir(device) = NULL; 1199 acpi_device_dir(device) = NULL;
1253} 1200}
1254 1201
@@ -1332,23 +1279,64 @@ battery_notification_delay_quirk(const struct dmi_system_id *d)
1332 return 0; 1279 return 0;
1333} 1280}
1334 1281
1282static int __init
1283battery_ac_is_broken_quirk(const struct dmi_system_id *d)
1284{
1285 battery_ac_is_broken = 1;
1286 return 0;
1287}
1288
1289static int __init
1290battery_do_not_check_pmic_quirk(const struct dmi_system_id *d)
1291{
1292 battery_check_pmic = 0;
1293 return 0;
1294}
1295
1335static const struct dmi_system_id bat_dmi_table[] __initconst = { 1296static const struct dmi_system_id bat_dmi_table[] __initconst = {
1336 { 1297 {
1298 /* NEC LZ750/LS */
1337 .callback = battery_bix_broken_package_quirk, 1299 .callback = battery_bix_broken_package_quirk,
1338 .ident = "NEC LZ750/LS",
1339 .matches = { 1300 .matches = {
1340 DMI_MATCH(DMI_SYS_VENDOR, "NEC"), 1301 DMI_MATCH(DMI_SYS_VENDOR, "NEC"),
1341 DMI_MATCH(DMI_PRODUCT_NAME, "PC-LZ750LS"), 1302 DMI_MATCH(DMI_PRODUCT_NAME, "PC-LZ750LS"),
1342 }, 1303 },
1343 }, 1304 },
1344 { 1305 {
1306 /* Acer Aspire V5-573G */
1345 .callback = battery_notification_delay_quirk, 1307 .callback = battery_notification_delay_quirk,
1346 .ident = "Acer Aspire V5-573G",
1347 .matches = { 1308 .matches = {
1348 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 1309 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1349 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire V5-573G"), 1310 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire V5-573G"),
1350 }, 1311 },
1351 }, 1312 },
1313 {
1314 /* Point of View mobii wintab p800w */
1315 .callback = battery_ac_is_broken_quirk,
1316 .matches = {
1317 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
1318 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
1319 DMI_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
1320 /* Above matches are too generic, add bios-date match */
1321 DMI_MATCH(DMI_BIOS_DATE, "08/22/2014"),
1322 },
1323 },
1324 {
1325 /* ECS EF20EA */
1326 .callback = battery_do_not_check_pmic_quirk,
1327 .matches = {
1328 DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
1329 },
1330 },
1331 {
1332 /* Lenovo Ideapad Miix 320 */
1333 .callback = battery_do_not_check_pmic_quirk,
1334 .matches = {
1335 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1336 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "80XF"),
1337 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
1338 },
1339 },
1352 {}, 1340 {},
1353}; 1341};
1354 1342
@@ -1488,16 +1476,18 @@ static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie)
1488 unsigned int i; 1476 unsigned int i;
1489 int result; 1477 int result;
1490 1478
1491 for (i = 0; i < ARRAY_SIZE(acpi_battery_blacklist); i++)
1492 if (acpi_dev_present(acpi_battery_blacklist[i], "1", -1)) {
1493 pr_info(PREFIX ACPI_BATTERY_DEVICE_NAME
1494 ": found native %s PMIC, not loading\n",
1495 acpi_battery_blacklist[i]);
1496 return;
1497 }
1498
1499 dmi_check_system(bat_dmi_table); 1479 dmi_check_system(bat_dmi_table);
1500 1480
1481 if (battery_check_pmic) {
1482 for (i = 0; i < ARRAY_SIZE(acpi_battery_blacklist); i++)
1483 if (acpi_dev_present(acpi_battery_blacklist[i], "1", -1)) {
1484 pr_info(PREFIX ACPI_BATTERY_DEVICE_NAME
1485 ": found native %s PMIC, not loading\n",
1486 acpi_battery_blacklist[i]);
1487 return;
1488 }
1489 }
1490
1501#ifdef CONFIG_ACPI_PROCFS_POWER 1491#ifdef CONFIG_ACPI_PROCFS_POWER
1502 acpi_battery_dir = acpi_lock_battery_dir(); 1492 acpi_battery_dir = acpi_lock_battery_dir();
1503 if (!acpi_battery_dir) 1493 if (!acpi_battery_dir)
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index f1cc4f9d31cd..2345a5ee2dbb 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -263,19 +263,6 @@ static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
263 return 0; 263 return 0;
264} 264}
265 265
266static int acpi_button_state_open_fs(struct inode *inode, struct file *file)
267{
268 return single_open(file, acpi_button_state_seq_show, PDE_DATA(inode));
269}
270
271static const struct file_operations acpi_button_state_fops = {
272 .owner = THIS_MODULE,
273 .open = acpi_button_state_open_fs,
274 .read = seq_read,
275 .llseek = seq_lseek,
276 .release = single_release,
277};
278
279static int acpi_button_add_fs(struct acpi_device *device) 266static int acpi_button_add_fs(struct acpi_device *device)
280{ 267{
281 struct acpi_button *button = acpi_driver_data(device); 268 struct acpi_button *button = acpi_driver_data(device);
@@ -311,9 +298,9 @@ static int acpi_button_add_fs(struct acpi_device *device)
311 } 298 }
312 299
313 /* create /proc/acpi/button/lid/LID/state */ 300 /* create /proc/acpi/button/lid/LID/state */
314 entry = proc_create_data(ACPI_BUTTON_FILE_STATE, 301 entry = proc_create_single_data(ACPI_BUTTON_FILE_STATE, S_IRUGO,
315 S_IRUGO, acpi_device_dir(device), 302 acpi_device_dir(device), acpi_button_state_seq_show,
316 &acpi_button_state_fops, device); 303 device);
317 if (!entry) { 304 if (!entry) {
318 ret = -ENODEV; 305 ret = -ENODEV;
319 goto remove_dev_dir; 306 goto remove_dev_dir;
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 735c74a4cbdb..d9ce4b162e2c 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -39,6 +39,7 @@
39 39
40#include <linux/cpufreq.h> 40#include <linux/cpufreq.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/iopoll.h>
42#include <linux/ktime.h> 43#include <linux/ktime.h>
43#include <linux/rwsem.h> 44#include <linux/rwsem.h>
44#include <linux/wait.h> 45#include <linux/wait.h>
@@ -49,7 +50,7 @@ struct cppc_pcc_data {
49 struct mbox_chan *pcc_channel; 50 struct mbox_chan *pcc_channel;
50 void __iomem *pcc_comm_addr; 51 void __iomem *pcc_comm_addr;
51 bool pcc_channel_acquired; 52 bool pcc_channel_acquired;
52 ktime_t deadline; 53 unsigned int deadline_us;
53 unsigned int pcc_mpar, pcc_mrtt, pcc_nominal; 54 unsigned int pcc_mpar, pcc_mrtt, pcc_nominal;
54 55
55 bool pending_pcc_write_cmd; /* Any pending/batched PCC write cmds? */ 56 bool pending_pcc_write_cmd; /* Any pending/batched PCC write cmds? */
@@ -156,6 +157,9 @@ show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, highest_perf);
156show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, lowest_perf); 157show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, lowest_perf);
157show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, nominal_perf); 158show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, nominal_perf);
158show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, lowest_nonlinear_perf); 159show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, lowest_nonlinear_perf);
160show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, lowest_freq);
161show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, nominal_freq);
162
159show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, reference_perf); 163show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, reference_perf);
160show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time); 164show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time);
161 165
@@ -183,6 +187,8 @@ static struct attribute *cppc_attrs[] = {
183 &lowest_perf.attr, 187 &lowest_perf.attr,
184 &lowest_nonlinear_perf.attr, 188 &lowest_nonlinear_perf.attr,
185 &nominal_perf.attr, 189 &nominal_perf.attr,
190 &nominal_freq.attr,
191 &lowest_freq.attr,
186 NULL 192 NULL
187}; 193};
188 194
@@ -193,42 +199,31 @@ static struct kobj_type cppc_ktype = {
193 199
194static int check_pcc_chan(int pcc_ss_id, bool chk_err_bit) 200static int check_pcc_chan(int pcc_ss_id, bool chk_err_bit)
195{ 201{
196 int ret = -EIO, status = 0; 202 int ret, status;
197 struct cppc_pcc_data *pcc_ss_data = pcc_data[pcc_ss_id]; 203 struct cppc_pcc_data *pcc_ss_data = pcc_data[pcc_ss_id];
198 struct acpi_pcct_shared_memory __iomem *generic_comm_base = 204 struct acpi_pcct_shared_memory __iomem *generic_comm_base =
199 pcc_ss_data->pcc_comm_addr; 205 pcc_ss_data->pcc_comm_addr;
200 ktime_t next_deadline = ktime_add(ktime_get(),
201 pcc_ss_data->deadline);
202 206
203 if (!pcc_ss_data->platform_owns_pcc) 207 if (!pcc_ss_data->platform_owns_pcc)
204 return 0; 208 return 0;
205 209
206 /* Retry in case the remote processor was too slow to catch up. */ 210 /*
207 while (!ktime_after(ktime_get(), next_deadline)) { 211 * Poll PCC status register every 3us(delay_us) for maximum of
208 /* 212 * deadline_us(timeout_us) until PCC command complete bit is set(cond)
209 * Per spec, prior to boot the PCC space wil be initialized by 213 */
210 * platform and should have set the command completion bit when 214 ret = readw_relaxed_poll_timeout(&generic_comm_base->status, status,
211 * PCC can be used by OSPM 215 status & PCC_CMD_COMPLETE_MASK, 3,
212 */ 216 pcc_ss_data->deadline_us);
213 status = readw_relaxed(&generic_comm_base->status);
214 if (status & PCC_CMD_COMPLETE_MASK) {
215 ret = 0;
216 if (chk_err_bit && (status & PCC_ERROR_MASK))
217 ret = -EIO;
218 break;
219 }
220 /*
221 * Reducing the bus traffic in case this loop takes longer than
222 * a few retries.
223 */
224 udelay(3);
225 }
226 217
227 if (likely(!ret)) 218 if (likely(!ret)) {
228 pcc_ss_data->platform_owns_pcc = false; 219 pcc_ss_data->platform_owns_pcc = false;
229 else 220 if (chk_err_bit && (status & PCC_ERROR_MASK))
230 pr_err("PCC check channel failed for ss: %d. Status=%x\n", 221 ret = -EIO;
231 pcc_ss_id, status); 222 }
223
224 if (unlikely(ret))
225 pr_err("PCC check channel failed for ss: %d. ret=%d\n",
226 pcc_ss_id, ret);
232 227
233 return ret; 228 return ret;
234} 229}
@@ -580,7 +575,7 @@ static int register_pcc_channel(int pcc_ss_idx)
580 * So add an arbitrary amount of wait on top of Nominal. 575 * So add an arbitrary amount of wait on top of Nominal.
581 */ 576 */
582 usecs_lat = NUM_RETRIES * cppc_ss->latency; 577 usecs_lat = NUM_RETRIES * cppc_ss->latency;
583 pcc_data[pcc_ss_idx]->deadline = ns_to_ktime(usecs_lat * NSEC_PER_USEC); 578 pcc_data[pcc_ss_idx]->deadline_us = usecs_lat;
584 pcc_data[pcc_ss_idx]->pcc_mrtt = cppc_ss->min_turnaround_time; 579 pcc_data[pcc_ss_idx]->pcc_mrtt = cppc_ss->min_turnaround_time;
585 pcc_data[pcc_ss_idx]->pcc_mpar = cppc_ss->max_access_rate; 580 pcc_data[pcc_ss_idx]->pcc_mpar = cppc_ss->max_access_rate;
586 pcc_data[pcc_ss_idx]->pcc_nominal = cppc_ss->latency; 581 pcc_data[pcc_ss_idx]->pcc_nominal = cppc_ss->latency;
@@ -613,7 +608,6 @@ bool __weak cpc_ffh_supported(void)
613 return false; 608 return false;
614} 609}
615 610
616
617/** 611/**
618 * pcc_data_alloc() - Allocate the pcc_data memory for pcc subspace 612 * pcc_data_alloc() - Allocate the pcc_data memory for pcc subspace
619 * 613 *
@@ -641,6 +635,34 @@ int pcc_data_alloc(int pcc_ss_id)
641 635
642 return 0; 636 return 0;
643} 637}
638
639/* Check if CPPC revision + num_ent combination is supported */
640static bool is_cppc_supported(int revision, int num_ent)
641{
642 int expected_num_ent;
643
644 switch (revision) {
645 case CPPC_V2_REV:
646 expected_num_ent = CPPC_V2_NUM_ENT;
647 break;
648 case CPPC_V3_REV:
649 expected_num_ent = CPPC_V3_NUM_ENT;
650 break;
651 default:
652 pr_debug("Firmware exports unsupported CPPC revision: %d\n",
653 revision);
654 return false;
655 }
656
657 if (expected_num_ent != num_ent) {
658 pr_debug("Firmware exports %d entries. Expected: %d for CPPC rev:%d\n",
659 num_ent, expected_num_ent, revision);
660 return false;
661 }
662
663 return true;
664}
665
644/* 666/*
645 * An example CPC table looks like the following. 667 * An example CPC table looks like the following.
646 * 668 *
@@ -731,14 +753,6 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
731 cpc_obj->type); 753 cpc_obj->type);
732 goto out_free; 754 goto out_free;
733 } 755 }
734
735 /* Only support CPPCv2. Bail otherwise. */
736 if (num_ent != CPPC_NUM_ENT) {
737 pr_debug("Firmware exports %d entries. Expected: %d\n",
738 num_ent, CPPC_NUM_ENT);
739 goto out_free;
740 }
741
742 cpc_ptr->num_entries = num_ent; 756 cpc_ptr->num_entries = num_ent;
743 757
744 /* Second entry should be revision. */ 758 /* Second entry should be revision. */
@@ -750,12 +764,10 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
750 cpc_obj->type); 764 cpc_obj->type);
751 goto out_free; 765 goto out_free;
752 } 766 }
767 cpc_ptr->version = cpc_rev;
753 768
754 if (cpc_rev != CPPC_REV) { 769 if (!is_cppc_supported(cpc_rev, num_ent))
755 pr_debug("Firmware exports revision:%d. Expected:%d\n",
756 cpc_rev, CPPC_REV);
757 goto out_free; 770 goto out_free;
758 }
759 771
760 /* Iterate through remaining entries in _CPC */ 772 /* Iterate through remaining entries in _CPC */
761 for (i = 2; i < num_ent; i++) { 773 for (i = 2; i < num_ent; i++) {
@@ -808,6 +820,18 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
808 } 820 }
809 } 821 }
810 per_cpu(cpu_pcc_subspace_idx, pr->id) = pcc_subspace_id; 822 per_cpu(cpu_pcc_subspace_idx, pr->id) = pcc_subspace_id;
823
824 /*
825 * Initialize the remaining cpc_regs as unsupported.
826 * Example: In case FW exposes CPPC v2, the below loop will initialize
827 * LOWEST_FREQ and NOMINAL_FREQ regs as unsupported
828 */
829 for (i = num_ent - 2; i < MAX_CPC_REG_ENT; i++) {
830 cpc_ptr->cpc_regs[i].type = ACPI_TYPE_INTEGER;
831 cpc_ptr->cpc_regs[i].cpc_entry.int_value = 0;
832 }
833
834
811 /* Store CPU Logical ID */ 835 /* Store CPU Logical ID */
812 cpc_ptr->cpu_id = pr->id; 836 cpc_ptr->cpu_id = pr->id;
813 837
@@ -1037,26 +1061,34 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_caps *perf_caps)
1037{ 1061{
1038 struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpunum); 1062 struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpunum);
1039 struct cpc_register_resource *highest_reg, *lowest_reg, 1063 struct cpc_register_resource *highest_reg, *lowest_reg,
1040 *lowest_non_linear_reg, *nominal_reg; 1064 *lowest_non_linear_reg, *nominal_reg,
1041 u64 high, low, nom, min_nonlinear; 1065 *low_freq_reg = NULL, *nom_freq_reg = NULL;
1066 u64 high, low, nom, min_nonlinear, low_f = 0, nom_f = 0;
1042 int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum); 1067 int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum);
1043 struct cppc_pcc_data *pcc_ss_data; 1068 struct cppc_pcc_data *pcc_ss_data = NULL;
1044 int ret = 0, regs_in_pcc = 0; 1069 int ret = 0, regs_in_pcc = 0;
1045 1070
1046 if (!cpc_desc || pcc_ss_id < 0) { 1071 if (!cpc_desc) {
1047 pr_debug("No CPC descriptor for CPU:%d\n", cpunum); 1072 pr_debug("No CPC descriptor for CPU:%d\n", cpunum);
1048 return -ENODEV; 1073 return -ENODEV;
1049 } 1074 }
1050 1075
1051 pcc_ss_data = pcc_data[pcc_ss_id];
1052 highest_reg = &cpc_desc->cpc_regs[HIGHEST_PERF]; 1076 highest_reg = &cpc_desc->cpc_regs[HIGHEST_PERF];
1053 lowest_reg = &cpc_desc->cpc_regs[LOWEST_PERF]; 1077 lowest_reg = &cpc_desc->cpc_regs[LOWEST_PERF];
1054 lowest_non_linear_reg = &cpc_desc->cpc_regs[LOW_NON_LINEAR_PERF]; 1078 lowest_non_linear_reg = &cpc_desc->cpc_regs[LOW_NON_LINEAR_PERF];
1055 nominal_reg = &cpc_desc->cpc_regs[NOMINAL_PERF]; 1079 nominal_reg = &cpc_desc->cpc_regs[NOMINAL_PERF];
1080 low_freq_reg = &cpc_desc->cpc_regs[LOWEST_FREQ];
1081 nom_freq_reg = &cpc_desc->cpc_regs[NOMINAL_FREQ];
1056 1082
1057 /* Are any of the regs PCC ?*/ 1083 /* Are any of the regs PCC ?*/
1058 if (CPC_IN_PCC(highest_reg) || CPC_IN_PCC(lowest_reg) || 1084 if (CPC_IN_PCC(highest_reg) || CPC_IN_PCC(lowest_reg) ||
1059 CPC_IN_PCC(lowest_non_linear_reg) || CPC_IN_PCC(nominal_reg)) { 1085 CPC_IN_PCC(lowest_non_linear_reg) || CPC_IN_PCC(nominal_reg) ||
1086 CPC_IN_PCC(low_freq_reg) || CPC_IN_PCC(nom_freq_reg)) {
1087 if (pcc_ss_id < 0) {
1088 pr_debug("Invalid pcc_ss_id\n");
1089 return -ENODEV;
1090 }
1091 pcc_ss_data = pcc_data[pcc_ss_id];
1060 regs_in_pcc = 1; 1092 regs_in_pcc = 1;
1061 down_write(&pcc_ss_data->pcc_lock); 1093 down_write(&pcc_ss_data->pcc_lock);
1062 /* Ring doorbell once to update PCC subspace */ 1094 /* Ring doorbell once to update PCC subspace */
@@ -1081,6 +1113,17 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_caps *perf_caps)
1081 if (!high || !low || !nom || !min_nonlinear) 1113 if (!high || !low || !nom || !min_nonlinear)
1082 ret = -EFAULT; 1114 ret = -EFAULT;
1083 1115
1116 /* Read optional lowest and nominal frequencies if present */
1117 if (CPC_SUPPORTED(low_freq_reg))
1118 cpc_read(cpunum, low_freq_reg, &low_f);
1119
1120 if (CPC_SUPPORTED(nom_freq_reg))
1121 cpc_read(cpunum, nom_freq_reg, &nom_f);
1122
1123 perf_caps->lowest_freq = low_f;
1124 perf_caps->nominal_freq = nom_f;
1125
1126
1084out_err: 1127out_err:
1085 if (regs_in_pcc) 1128 if (regs_in_pcc)
1086 up_write(&pcc_ss_data->pcc_lock); 1129 up_write(&pcc_ss_data->pcc_lock);
@@ -1101,16 +1144,15 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
1101 struct cpc_register_resource *delivered_reg, *reference_reg, 1144 struct cpc_register_resource *delivered_reg, *reference_reg,
1102 *ref_perf_reg, *ctr_wrap_reg; 1145 *ref_perf_reg, *ctr_wrap_reg;
1103 int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum); 1146 int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum);
1104 struct cppc_pcc_data *pcc_ss_data; 1147 struct cppc_pcc_data *pcc_ss_data = NULL;
1105 u64 delivered, reference, ref_perf, ctr_wrap_time; 1148 u64 delivered, reference, ref_perf, ctr_wrap_time;
1106 int ret = 0, regs_in_pcc = 0; 1149 int ret = 0, regs_in_pcc = 0;
1107 1150
1108 if (!cpc_desc || pcc_ss_id < 0) { 1151 if (!cpc_desc) {
1109 pr_debug("No CPC descriptor for CPU:%d\n", cpunum); 1152 pr_debug("No CPC descriptor for CPU:%d\n", cpunum);
1110 return -ENODEV; 1153 return -ENODEV;
1111 } 1154 }
1112 1155
1113 pcc_ss_data = pcc_data[pcc_ss_id];
1114 delivered_reg = &cpc_desc->cpc_regs[DELIVERED_CTR]; 1156 delivered_reg = &cpc_desc->cpc_regs[DELIVERED_CTR];
1115 reference_reg = &cpc_desc->cpc_regs[REFERENCE_CTR]; 1157 reference_reg = &cpc_desc->cpc_regs[REFERENCE_CTR];
1116 ref_perf_reg = &cpc_desc->cpc_regs[REFERENCE_PERF]; 1158 ref_perf_reg = &cpc_desc->cpc_regs[REFERENCE_PERF];
@@ -1126,6 +1168,11 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
1126 /* Are any of the regs PCC ?*/ 1168 /* Are any of the regs PCC ?*/
1127 if (CPC_IN_PCC(delivered_reg) || CPC_IN_PCC(reference_reg) || 1169 if (CPC_IN_PCC(delivered_reg) || CPC_IN_PCC(reference_reg) ||
1128 CPC_IN_PCC(ctr_wrap_reg) || CPC_IN_PCC(ref_perf_reg)) { 1170 CPC_IN_PCC(ctr_wrap_reg) || CPC_IN_PCC(ref_perf_reg)) {
1171 if (pcc_ss_id < 0) {
1172 pr_debug("Invalid pcc_ss_id\n");
1173 return -ENODEV;
1174 }
1175 pcc_ss_data = pcc_data[pcc_ss_id];
1129 down_write(&pcc_ss_data->pcc_lock); 1176 down_write(&pcc_ss_data->pcc_lock);
1130 regs_in_pcc = 1; 1177 regs_in_pcc = 1;
1131 /* Ring doorbell once to update PCC subspace */ 1178 /* Ring doorbell once to update PCC subspace */
@@ -1176,15 +1223,14 @@ int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
1176 struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu); 1223 struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu);
1177 struct cpc_register_resource *desired_reg; 1224 struct cpc_register_resource *desired_reg;
1178 int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu); 1225 int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
1179 struct cppc_pcc_data *pcc_ss_data; 1226 struct cppc_pcc_data *pcc_ss_data = NULL;
1180 int ret = 0; 1227 int ret = 0;
1181 1228
1182 if (!cpc_desc || pcc_ss_id < 0) { 1229 if (!cpc_desc) {
1183 pr_debug("No CPC descriptor for CPU:%d\n", cpu); 1230 pr_debug("No CPC descriptor for CPU:%d\n", cpu);
1184 return -ENODEV; 1231 return -ENODEV;
1185 } 1232 }
1186 1233
1187 pcc_ss_data = pcc_data[pcc_ss_id];
1188 desired_reg = &cpc_desc->cpc_regs[DESIRED_PERF]; 1234 desired_reg = &cpc_desc->cpc_regs[DESIRED_PERF];
1189 1235
1190 /* 1236 /*
@@ -1195,6 +1241,11 @@ int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
1195 * achieve that goal here 1241 * achieve that goal here
1196 */ 1242 */
1197 if (CPC_IN_PCC(desired_reg)) { 1243 if (CPC_IN_PCC(desired_reg)) {
1244 if (pcc_ss_id < 0) {
1245 pr_debug("Invalid pcc_ss_id\n");
1246 return -ENODEV;
1247 }
1248 pcc_ss_data = pcc_data[pcc_ss_id];
1198 down_read(&pcc_ss_data->pcc_lock); /* BEGIN Phase-I */ 1249 down_read(&pcc_ss_data->pcc_lock); /* BEGIN Phase-I */
1199 if (pcc_ss_data->platform_owns_pcc) { 1250 if (pcc_ss_data->platform_owns_pcc) {
1200 ret = check_pcc_chan(pcc_ss_id, false); 1251 ret = check_pcc_chan(pcc_ss_id, false);
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 3d96e4da2d98..a7c2673ffd36 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -1257,10 +1257,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
1257 struct acpi_device *adev = ACPI_COMPANION(dev); 1257 struct acpi_device *adev = ACPI_COMPANION(dev);
1258 1258
1259 if (!adev) 1259 if (!adev)
1260 return -ENODEV; 1260 return 0;
1261
1262 if (dev->pm_domain)
1263 return -EEXIST;
1264 1261
1265 /* 1262 /*
1266 * Only attach the power domain to the first device if the 1263 * Only attach the power domain to the first device if the
@@ -1268,7 +1265,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
1268 * management twice. 1265 * management twice.
1269 */ 1266 */
1270 if (!acpi_device_is_first_physical_node(adev, dev)) 1267 if (!acpi_device_is_first_physical_node(adev, dev))
1271 return -EBUSY; 1268 return 0;
1272 1269
1273 acpi_add_pm_notifier(adev, dev, acpi_pm_notify_work_func); 1270 acpi_add_pm_notifier(adev, dev, acpi_pm_notify_work_func);
1274 dev_pm_domain_set(dev, &acpi_general_pm_domain); 1271 dev_pm_domain_set(dev, &acpi_general_pm_domain);
@@ -1278,7 +1275,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
1278 } 1275 }
1279 1276
1280 dev->pm_domain->detach = acpi_dev_pm_detach; 1277 dev->pm_domain->detach = acpi_dev_pm_detach;
1281 return 0; 1278 return 1;
1282} 1279}
1283EXPORT_SYMBOL_GPL(acpi_dev_pm_attach); 1280EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
1284#endif /* CONFIG_PM */ 1281#endif /* CONFIG_PM */
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 30a572956557..bb94cf0731fe 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -1034,6 +1034,12 @@ void acpi_ec_unblock_transactions(void)
1034 acpi_ec_start(first_ec, true); 1034 acpi_ec_start(first_ec, true);
1035} 1035}
1036 1036
1037void acpi_ec_dispatch_gpe(void)
1038{
1039 if (first_ec)
1040 acpi_dispatch_gpe(NULL, first_ec->gpe);
1041}
1042
1037/* -------------------------------------------------------------------------- 1043/* --------------------------------------------------------------------------
1038 Event Management 1044 Event Management
1039 -------------------------------------------------------------------------- */ 1045 -------------------------------------------------------------------------- */
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 3563103590c6..fe0183d48dcd 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -298,8 +298,8 @@ static int acpi_fan_get_fps(struct acpi_device *device)
298 } 298 }
299 299
300 fan->fps_count = obj->package.count - 1; /* minus revision field */ 300 fan->fps_count = obj->package.count - 1; /* minus revision field */
301 fan->fps = devm_kzalloc(&device->dev, 301 fan->fps = devm_kcalloc(&device->dev,
302 fan->fps_count * sizeof(struct acpi_fan_fps), 302 fan->fps_count, sizeof(struct acpi_fan_fps),
303 GFP_KERNEL); 303 GFP_KERNEL);
304 if (!fan->fps) { 304 if (!fan->fps) {
305 dev_err(&device->dev, "Not enough memory\n"); 305 dev_err(&device->dev, "Not enough memory\n");
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 1d0a501bc7f0..530a3f675490 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -188,6 +188,7 @@ int acpi_ec_ecdt_probe(void);
188int acpi_ec_dsdt_probe(void); 188int acpi_ec_dsdt_probe(void);
189void acpi_ec_block_transactions(void); 189void acpi_ec_block_transactions(void);
190void acpi_ec_unblock_transactions(void); 190void acpi_ec_unblock_transactions(void);
191void acpi_ec_dispatch_gpe(void);
191int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, 192int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
192 acpi_handle handle, acpi_ec_query_func func, 193 acpi_handle handle, acpi_ec_query_func func,
193 void *data); 194 void *data);
diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index e2235ed3e4be..d15814e1727f 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -1082,9 +1082,10 @@ static int __nfit_mem_init(struct acpi_nfit_desc *acpi_desc,
1082 continue; 1082 continue;
1083 nfit_mem->nfit_flush = nfit_flush; 1083 nfit_mem->nfit_flush = nfit_flush;
1084 flush = nfit_flush->flush; 1084 flush = nfit_flush->flush;
1085 nfit_mem->flush_wpq = devm_kzalloc(acpi_desc->dev, 1085 nfit_mem->flush_wpq = devm_kcalloc(acpi_desc->dev,
1086 flush->hint_count 1086 flush->hint_count,
1087 * sizeof(struct resource), GFP_KERNEL); 1087 sizeof(struct resource),
1088 GFP_KERNEL);
1088 if (!nfit_mem->flush_wpq) 1089 if (!nfit_mem->flush_wpq)
1089 return -ENOMEM; 1090 return -ENOMEM;
1090 for (i = 0; i < flush->hint_count; i++) { 1091 for (i = 0; i < flush->hint_count; i++) {
@@ -1978,19 +1979,8 @@ static ssize_t range_index_show(struct device *dev,
1978} 1979}
1979static DEVICE_ATTR_RO(range_index); 1980static DEVICE_ATTR_RO(range_index);
1980 1981
1981static ssize_t ecc_unit_size_show(struct device *dev,
1982 struct device_attribute *attr, char *buf)
1983{
1984 struct nd_region *nd_region = to_nd_region(dev);
1985 struct nfit_spa *nfit_spa = nd_region_provider_data(nd_region);
1986
1987 return sprintf(buf, "%d\n", nfit_spa->clear_err_unit);
1988}
1989static DEVICE_ATTR_RO(ecc_unit_size);
1990
1991static struct attribute *acpi_nfit_region_attributes[] = { 1982static struct attribute *acpi_nfit_region_attributes[] = {
1992 &dev_attr_range_index.attr, 1983 &dev_attr_range_index.attr,
1993 &dev_attr_ecc_unit_size.attr,
1994 NULL, 1984 NULL,
1995}; 1985};
1996 1986
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 0da18bde6a16..7433035ded95 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -153,6 +153,7 @@ static struct pci_osc_bit_struct pci_osc_control_bit[] = {
153 { OSC_PCI_EXPRESS_PME_CONTROL, "PME" }, 153 { OSC_PCI_EXPRESS_PME_CONTROL, "PME" },
154 { OSC_PCI_EXPRESS_AER_CONTROL, "AER" }, 154 { OSC_PCI_EXPRESS_AER_CONTROL, "AER" },
155 { OSC_PCI_EXPRESS_CAPABILITY_CONTROL, "PCIeCapability" }, 155 { OSC_PCI_EXPRESS_CAPABILITY_CONTROL, "PCIeCapability" },
156 { OSC_PCI_EXPRESS_LTR_CONTROL, "LTR" },
156}; 157};
157 158
158static void decode_osc_bits(struct acpi_pci_root *root, char *msg, u32 word, 159static void decode_osc_bits(struct acpi_pci_root *root, char *msg, u32 word,
@@ -472,9 +473,17 @@ static void negotiate_os_control(struct acpi_pci_root *root, int *no_aspm)
472 } 473 }
473 474
474 control = OSC_PCI_EXPRESS_CAPABILITY_CONTROL 475 control = OSC_PCI_EXPRESS_CAPABILITY_CONTROL
475 | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
476 | OSC_PCI_EXPRESS_PME_CONTROL; 476 | OSC_PCI_EXPRESS_PME_CONTROL;
477 477
478 if (IS_ENABLED(CONFIG_PCIEASPM))
479 control |= OSC_PCI_EXPRESS_LTR_CONTROL;
480
481 if (IS_ENABLED(CONFIG_HOTPLUG_PCI_PCIE))
482 control |= OSC_PCI_EXPRESS_NATIVE_HP_CONTROL;
483
484 if (IS_ENABLED(CONFIG_HOTPLUG_PCI_SHPC))
485 control |= OSC_PCI_SHPC_NATIVE_HP_CONTROL;
486
478 if (pci_aer_available()) { 487 if (pci_aer_available()) {
479 if (aer_acpi_firmware_first()) 488 if (aer_acpi_firmware_first())
480 dev_info(&device->dev, 489 dev_info(&device->dev,
@@ -900,11 +909,15 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,
900 909
901 host_bridge = to_pci_host_bridge(bus->bridge); 910 host_bridge = to_pci_host_bridge(bus->bridge);
902 if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL)) 911 if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL))
903 host_bridge->native_hotplug = 0; 912 host_bridge->native_pcie_hotplug = 0;
913 if (!(root->osc_control_set & OSC_PCI_SHPC_NATIVE_HP_CONTROL))
914 host_bridge->native_shpc_hotplug = 0;
904 if (!(root->osc_control_set & OSC_PCI_EXPRESS_AER_CONTROL)) 915 if (!(root->osc_control_set & OSC_PCI_EXPRESS_AER_CONTROL))
905 host_bridge->native_aer = 0; 916 host_bridge->native_aer = 0;
906 if (!(root->osc_control_set & OSC_PCI_EXPRESS_PME_CONTROL)) 917 if (!(root->osc_control_set & OSC_PCI_EXPRESS_PME_CONTROL))
907 host_bridge->native_pme = 0; 918 host_bridge->native_pme = 0;
919 if (!(root->osc_control_set & OSC_PCI_EXPRESS_LTR_CONTROL))
920 host_bridge->native_ltr = 0;
908 921
909 pci_scan_child_bus(bus); 922 pci_scan_child_bus(bus);
910 pci_set_host_bridge_release(host_bridge, acpi_pci_root_release_info, 923 pci_set_host_bridge_release(host_bridge, acpi_pci_root_release_info,
diff --git a/drivers/acpi/pptt.c b/drivers/acpi/pptt.c
new file mode 100644
index 000000000000..e5ea1974d1e3
--- /dev/null
+++ b/drivers/acpi/pptt.c
@@ -0,0 +1,655 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * pptt.c - parsing of Processor Properties Topology Table (PPTT)
4 *
5 * Copyright (C) 2018, ARM
6 *
7 * This file implements parsing of the Processor Properties Topology Table
8 * which is optionally used to describe the processor and cache topology.
9 * Due to the relative pointers used throughout the table, this doesn't
10 * leverage the existing subtable parsing in the kernel.
11 *
12 * The PPTT structure is an inverted tree, with each node potentially
13 * holding one or two inverted tree data structures describing
14 * the caches available at that level. Each cache structure optionally
15 * contains properties describing the cache at a given level which can be
16 * used to override hardware probed values.
17 */
18#define pr_fmt(fmt) "ACPI PPTT: " fmt
19
20#include <linux/acpi.h>
21#include <linux/cacheinfo.h>
22#include <acpi/processor.h>
23
24static struct acpi_subtable_header *fetch_pptt_subtable(struct acpi_table_header *table_hdr,
25 u32 pptt_ref)
26{
27 struct acpi_subtable_header *entry;
28
29 /* there isn't a subtable at reference 0 */
30 if (pptt_ref < sizeof(struct acpi_subtable_header))
31 return NULL;
32
33 if (pptt_ref + sizeof(struct acpi_subtable_header) > table_hdr->length)
34 return NULL;
35
36 entry = ACPI_ADD_PTR(struct acpi_subtable_header, table_hdr, pptt_ref);
37
38 if (entry->length == 0)
39 return NULL;
40
41 if (pptt_ref + entry->length > table_hdr->length)
42 return NULL;
43
44 return entry;
45}
46
47static struct acpi_pptt_processor *fetch_pptt_node(struct acpi_table_header *table_hdr,
48 u32 pptt_ref)
49{
50 return (struct acpi_pptt_processor *)fetch_pptt_subtable(table_hdr, pptt_ref);
51}
52
53static struct acpi_pptt_cache *fetch_pptt_cache(struct acpi_table_header *table_hdr,
54 u32 pptt_ref)
55{
56 return (struct acpi_pptt_cache *)fetch_pptt_subtable(table_hdr, pptt_ref);
57}
58
59static struct acpi_subtable_header *acpi_get_pptt_resource(struct acpi_table_header *table_hdr,
60 struct acpi_pptt_processor *node,
61 int resource)
62{
63 u32 *ref;
64
65 if (resource >= node->number_of_priv_resources)
66 return NULL;
67
68 ref = ACPI_ADD_PTR(u32, node, sizeof(struct acpi_pptt_processor));
69 ref += resource;
70
71 return fetch_pptt_subtable(table_hdr, *ref);
72}
73
74static inline bool acpi_pptt_match_type(int table_type, int type)
75{
76 return ((table_type & ACPI_PPTT_MASK_CACHE_TYPE) == type ||
77 table_type & ACPI_PPTT_CACHE_TYPE_UNIFIED & type);
78}
79
80/**
81 * acpi_pptt_walk_cache() - Attempt to find the requested acpi_pptt_cache
82 * @table_hdr: Pointer to the head of the PPTT table
83 * @local_level: passed res reflects this cache level
84 * @res: cache resource in the PPTT we want to walk
85 * @found: returns a pointer to the requested level if found
86 * @level: the requested cache level
87 * @type: the requested cache type
88 *
89 * Attempt to find a given cache level, while counting the max number
90 * of cache levels for the cache node.
91 *
92 * Given a pptt resource, verify that it is a cache node, then walk
93 * down each level of caches, counting how many levels are found
94 * as well as checking the cache type (icache, dcache, unified). If a
95 * level & type match, then we set found, and continue the search.
96 * Once the entire cache branch has been walked return its max
97 * depth.
98 *
99 * Return: The cache structure and the level we terminated with.
100 */
101static int acpi_pptt_walk_cache(struct acpi_table_header *table_hdr,
102 int local_level,
103 struct acpi_subtable_header *res,
104 struct acpi_pptt_cache **found,
105 int level, int type)
106{
107 struct acpi_pptt_cache *cache;
108
109 if (res->type != ACPI_PPTT_TYPE_CACHE)
110 return 0;
111
112 cache = (struct acpi_pptt_cache *) res;
113 while (cache) {
114 local_level++;
115
116 if (local_level == level &&
117 cache->flags & ACPI_PPTT_CACHE_TYPE_VALID &&
118 acpi_pptt_match_type(cache->attributes, type)) {
119 if (*found != NULL && cache != *found)
120 pr_warn("Found duplicate cache level/type unable to determine uniqueness\n");
121
122 pr_debug("Found cache @ level %d\n", level);
123 *found = cache;
124 /*
125 * continue looking at this node's resource list
126 * to verify that we don't find a duplicate
127 * cache node.
128 */
129 }
130 cache = fetch_pptt_cache(table_hdr, cache->next_level_of_cache);
131 }
132 return local_level;
133}
134
135static struct acpi_pptt_cache *acpi_find_cache_level(struct acpi_table_header *table_hdr,
136 struct acpi_pptt_processor *cpu_node,
137 int *starting_level, int level,
138 int type)
139{
140 struct acpi_subtable_header *res;
141 int number_of_levels = *starting_level;
142 int resource = 0;
143 struct acpi_pptt_cache *ret = NULL;
144 int local_level;
145
146 /* walk down from processor node */
147 while ((res = acpi_get_pptt_resource(table_hdr, cpu_node, resource))) {
148 resource++;
149
150 local_level = acpi_pptt_walk_cache(table_hdr, *starting_level,
151 res, &ret, level, type);
152 /*
153 * we are looking for the max depth. Since its potentially
154 * possible for a given node to have resources with differing
155 * depths verify that the depth we have found is the largest.
156 */
157 if (number_of_levels < local_level)
158 number_of_levels = local_level;
159 }
160 if (number_of_levels > *starting_level)
161 *starting_level = number_of_levels;
162
163 return ret;
164}
165
166/**
167 * acpi_count_levels() - Given a PPTT table, and a cpu node, count the caches
168 * @table_hdr: Pointer to the head of the PPTT table
169 * @cpu_node: processor node we wish to count caches for
170 *
171 * Given a processor node containing a processing unit, walk into it and count
172 * how many levels exist solely for it, and then walk up each level until we hit
173 * the root node (ignore the package level because it may be possible to have
174 * caches that exist across packages). Count the number of cache levels that
175 * exist at each level on the way up.
176 *
177 * Return: Total number of levels found.
178 */
179static int acpi_count_levels(struct acpi_table_header *table_hdr,
180 struct acpi_pptt_processor *cpu_node)
181{
182 int total_levels = 0;
183
184 do {
185 acpi_find_cache_level(table_hdr, cpu_node, &total_levels, 0, 0);
186 cpu_node = fetch_pptt_node(table_hdr, cpu_node->parent);
187 } while (cpu_node);
188
189 return total_levels;
190}
191
192/**
193 * acpi_pptt_leaf_node() - Given a processor node, determine if its a leaf
194 * @table_hdr: Pointer to the head of the PPTT table
195 * @node: passed node is checked to see if its a leaf
196 *
197 * Determine if the *node parameter is a leaf node by iterating the
198 * PPTT table, looking for nodes which reference it.
199 *
200 * Return: 0 if we find a node referencing the passed node (or table error),
201 * or 1 if we don't.
202 */
203static int acpi_pptt_leaf_node(struct acpi_table_header *table_hdr,
204 struct acpi_pptt_processor *node)
205{
206 struct acpi_subtable_header *entry;
207 unsigned long table_end;
208 u32 node_entry;
209 struct acpi_pptt_processor *cpu_node;
210 u32 proc_sz;
211
212 table_end = (unsigned long)table_hdr + table_hdr->length;
213 node_entry = ACPI_PTR_DIFF(node, table_hdr);
214 entry = ACPI_ADD_PTR(struct acpi_subtable_header, table_hdr,
215 sizeof(struct acpi_table_pptt));
216 proc_sz = sizeof(struct acpi_pptt_processor *);
217
218 while ((unsigned long)entry + proc_sz < table_end) {
219 cpu_node = (struct acpi_pptt_processor *)entry;
220 if (entry->type == ACPI_PPTT_TYPE_PROCESSOR &&
221 cpu_node->parent == node_entry)
222 return 0;
223 if (entry->length == 0)
224 return 0;
225 entry = ACPI_ADD_PTR(struct acpi_subtable_header, entry,
226 entry->length);
227
228 }
229 return 1;
230}
231
232/**
233 * acpi_find_processor_node() - Given a PPTT table find the requested processor
234 * @table_hdr: Pointer to the head of the PPTT table
235 * @acpi_cpu_id: cpu we are searching for
236 *
237 * Find the subtable entry describing the provided processor.
238 * This is done by iterating the PPTT table looking for processor nodes
239 * which have an acpi_processor_id that matches the acpi_cpu_id parameter
240 * passed into the function. If we find a node that matches this criteria
241 * we verify that its a leaf node in the topology rather than depending
242 * on the valid flag, which doesn't need to be set for leaf nodes.
243 *
244 * Return: NULL, or the processors acpi_pptt_processor*
245 */
246static struct acpi_pptt_processor *acpi_find_processor_node(struct acpi_table_header *table_hdr,
247 u32 acpi_cpu_id)
248{
249 struct acpi_subtable_header *entry;
250 unsigned long table_end;
251 struct acpi_pptt_processor *cpu_node;
252 u32 proc_sz;
253
254 table_end = (unsigned long)table_hdr + table_hdr->length;
255 entry = ACPI_ADD_PTR(struct acpi_subtable_header, table_hdr,
256 sizeof(struct acpi_table_pptt));
257 proc_sz = sizeof(struct acpi_pptt_processor *);
258
259 /* find the processor structure associated with this cpuid */
260 while ((unsigned long)entry + proc_sz < table_end) {
261 cpu_node = (struct acpi_pptt_processor *)entry;
262
263 if (entry->length == 0) {
264 pr_warn("Invalid zero length subtable\n");
265 break;
266 }
267 if (entry->type == ACPI_PPTT_TYPE_PROCESSOR &&
268 acpi_cpu_id == cpu_node->acpi_processor_id &&
269 acpi_pptt_leaf_node(table_hdr, cpu_node)) {
270 return (struct acpi_pptt_processor *)entry;
271 }
272
273 entry = ACPI_ADD_PTR(struct acpi_subtable_header, entry,
274 entry->length);
275 }
276
277 return NULL;
278}
279
280static int acpi_find_cache_levels(struct acpi_table_header *table_hdr,
281 u32 acpi_cpu_id)
282{
283 int number_of_levels = 0;
284 struct acpi_pptt_processor *cpu;
285
286 cpu = acpi_find_processor_node(table_hdr, acpi_cpu_id);
287 if (cpu)
288 number_of_levels = acpi_count_levels(table_hdr, cpu);
289
290 return number_of_levels;
291}
292
293static u8 acpi_cache_type(enum cache_type type)
294{
295 switch (type) {
296 case CACHE_TYPE_DATA:
297 pr_debug("Looking for data cache\n");
298 return ACPI_PPTT_CACHE_TYPE_DATA;
299 case CACHE_TYPE_INST:
300 pr_debug("Looking for instruction cache\n");
301 return ACPI_PPTT_CACHE_TYPE_INSTR;
302 default:
303 case CACHE_TYPE_UNIFIED:
304 pr_debug("Looking for unified cache\n");
305 /*
306 * It is important that ACPI_PPTT_CACHE_TYPE_UNIFIED
307 * contains the bit pattern that will match both
308 * ACPI unified bit patterns because we use it later
309 * to match both cases.
310 */
311 return ACPI_PPTT_CACHE_TYPE_UNIFIED;
312 }
313}
314
315static struct acpi_pptt_cache *acpi_find_cache_node(struct acpi_table_header *table_hdr,
316 u32 acpi_cpu_id,
317 enum cache_type type,
318 unsigned int level,
319 struct acpi_pptt_processor **node)
320{
321 int total_levels = 0;
322 struct acpi_pptt_cache *found = NULL;
323 struct acpi_pptt_processor *cpu_node;
324 u8 acpi_type = acpi_cache_type(type);
325
326 pr_debug("Looking for CPU %d's level %d cache type %d\n",
327 acpi_cpu_id, level, acpi_type);
328
329 cpu_node = acpi_find_processor_node(table_hdr, acpi_cpu_id);
330
331 while (cpu_node && !found) {
332 found = acpi_find_cache_level(table_hdr, cpu_node,
333 &total_levels, level, acpi_type);
334 *node = cpu_node;
335 cpu_node = fetch_pptt_node(table_hdr, cpu_node->parent);
336 }
337
338 return found;
339}
340
341/* total number of attributes checked by the properties code */
342#define PPTT_CHECKED_ATTRIBUTES 4
343
344/**
345 * update_cache_properties() - Update cacheinfo for the given processor
346 * @this_leaf: Kernel cache info structure being updated
347 * @found_cache: The PPTT node describing this cache instance
348 * @cpu_node: A unique reference to describe this cache instance
349 *
350 * The ACPI spec implies that the fields in the cache structures are used to
351 * extend and correct the information probed from the hardware. Lets only
352 * set fields that we determine are VALID.
353 *
354 * Return: nothing. Side effect of updating the global cacheinfo
355 */
356static void update_cache_properties(struct cacheinfo *this_leaf,
357 struct acpi_pptt_cache *found_cache,
358 struct acpi_pptt_processor *cpu_node)
359{
360 int valid_flags = 0;
361
362 this_leaf->fw_token = cpu_node;
363 if (found_cache->flags & ACPI_PPTT_SIZE_PROPERTY_VALID) {
364 this_leaf->size = found_cache->size;
365 valid_flags++;
366 }
367 if (found_cache->flags & ACPI_PPTT_LINE_SIZE_VALID) {
368 this_leaf->coherency_line_size = found_cache->line_size;
369 valid_flags++;
370 }
371 if (found_cache->flags & ACPI_PPTT_NUMBER_OF_SETS_VALID) {
372 this_leaf->number_of_sets = found_cache->number_of_sets;
373 valid_flags++;
374 }
375 if (found_cache->flags & ACPI_PPTT_ASSOCIATIVITY_VALID) {
376 this_leaf->ways_of_associativity = found_cache->associativity;
377 valid_flags++;
378 }
379 if (found_cache->flags & ACPI_PPTT_WRITE_POLICY_VALID) {
380 switch (found_cache->attributes & ACPI_PPTT_MASK_WRITE_POLICY) {
381 case ACPI_PPTT_CACHE_POLICY_WT:
382 this_leaf->attributes = CACHE_WRITE_THROUGH;
383 break;
384 case ACPI_PPTT_CACHE_POLICY_WB:
385 this_leaf->attributes = CACHE_WRITE_BACK;
386 break;
387 }
388 }
389 if (found_cache->flags & ACPI_PPTT_ALLOCATION_TYPE_VALID) {
390 switch (found_cache->attributes & ACPI_PPTT_MASK_ALLOCATION_TYPE) {
391 case ACPI_PPTT_CACHE_READ_ALLOCATE:
392 this_leaf->attributes |= CACHE_READ_ALLOCATE;
393 break;
394 case ACPI_PPTT_CACHE_WRITE_ALLOCATE:
395 this_leaf->attributes |= CACHE_WRITE_ALLOCATE;
396 break;
397 case ACPI_PPTT_CACHE_RW_ALLOCATE:
398 case ACPI_PPTT_CACHE_RW_ALLOCATE_ALT:
399 this_leaf->attributes |=
400 CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE;
401 break;
402 }
403 }
404 /*
405 * If the above flags are valid, and the cache type is NOCACHE
406 * update the cache type as well.
407 */
408 if (this_leaf->type == CACHE_TYPE_NOCACHE &&
409 valid_flags == PPTT_CHECKED_ATTRIBUTES)
410 this_leaf->type = CACHE_TYPE_UNIFIED;
411}
412
413static void cache_setup_acpi_cpu(struct acpi_table_header *table,
414 unsigned int cpu)
415{
416 struct acpi_pptt_cache *found_cache;
417 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
418 u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
419 struct cacheinfo *this_leaf;
420 unsigned int index = 0;
421 struct acpi_pptt_processor *cpu_node = NULL;
422
423 while (index < get_cpu_cacheinfo(cpu)->num_leaves) {
424 this_leaf = this_cpu_ci->info_list + index;
425 found_cache = acpi_find_cache_node(table, acpi_cpu_id,
426 this_leaf->type,
427 this_leaf->level,
428 &cpu_node);
429 pr_debug("found = %p %p\n", found_cache, cpu_node);
430 if (found_cache)
431 update_cache_properties(this_leaf,
432 found_cache,
433 cpu_node);
434
435 index++;
436 }
437}
438
439/* Passing level values greater than this will result in search termination */
440#define PPTT_ABORT_PACKAGE 0xFF
441
442static struct acpi_pptt_processor *acpi_find_processor_package_id(struct acpi_table_header *table_hdr,
443 struct acpi_pptt_processor *cpu,
444 int level, int flag)
445{
446 struct acpi_pptt_processor *prev_node;
447
448 while (cpu && level) {
449 if (cpu->flags & flag)
450 break;
451 pr_debug("level %d\n", level);
452 prev_node = fetch_pptt_node(table_hdr, cpu->parent);
453 if (prev_node == NULL)
454 break;
455 cpu = prev_node;
456 level--;
457 }
458 return cpu;
459}
460
461/**
462 * topology_get_acpi_cpu_tag() - Find a unique topology value for a feature
463 * @table: Pointer to the head of the PPTT table
464 * @cpu: Kernel logical cpu number
465 * @level: A level that terminates the search
466 * @flag: A flag which terminates the search
467 *
468 * Get a unique value given a cpu, and a topology level, that can be
469 * matched to determine which cpus share common topological features
470 * at that level.
471 *
472 * Return: Unique value, or -ENOENT if unable to locate cpu
473 */
474static int topology_get_acpi_cpu_tag(struct acpi_table_header *table,
475 unsigned int cpu, int level, int flag)
476{
477 struct acpi_pptt_processor *cpu_node;
478 u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
479
480 cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
481 if (cpu_node) {
482 cpu_node = acpi_find_processor_package_id(table, cpu_node,
483 level, flag);
484 /* Only the first level has a guaranteed id */
485 if (level == 0)
486 return cpu_node->acpi_processor_id;
487 return ACPI_PTR_DIFF(cpu_node, table);
488 }
489 pr_warn_once("PPTT table found, but unable to locate core %d (%d)\n",
490 cpu, acpi_cpu_id);
491 return -ENOENT;
492}
493
494static int find_acpi_cpu_topology_tag(unsigned int cpu, int level, int flag)
495{
496 struct acpi_table_header *table;
497 acpi_status status;
498 int retval;
499
500 status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
501 if (ACPI_FAILURE(status)) {
502 pr_warn_once("No PPTT table found, cpu topology may be inaccurate\n");
503 return -ENOENT;
504 }
505 retval = topology_get_acpi_cpu_tag(table, cpu, level, flag);
506 pr_debug("Topology Setup ACPI cpu %d, level %d ret = %d\n",
507 cpu, level, retval);
508 acpi_put_table(table);
509
510 return retval;
511}
512
513/**
514 * acpi_find_last_cache_level() - Determines the number of cache levels for a PE
515 * @cpu: Kernel logical cpu number
516 *
517 * Given a logical cpu number, returns the number of levels of cache represented
518 * in the PPTT. Errors caused by lack of a PPTT table, or otherwise, return 0
519 * indicating we didn't find any cache levels.
520 *
521 * Return: Cache levels visible to this core.
522 */
523int acpi_find_last_cache_level(unsigned int cpu)
524{
525 u32 acpi_cpu_id;
526 struct acpi_table_header *table;
527 int number_of_levels = 0;
528 acpi_status status;
529
530 pr_debug("Cache Setup find last level cpu=%d\n", cpu);
531
532 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
533 status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
534 if (ACPI_FAILURE(status)) {
535 pr_warn_once("No PPTT table found, cache topology may be inaccurate\n");
536 } else {
537 number_of_levels = acpi_find_cache_levels(table, acpi_cpu_id);
538 acpi_put_table(table);
539 }
540 pr_debug("Cache Setup find last level level=%d\n", number_of_levels);
541
542 return number_of_levels;
543}
544
545/**
546 * cache_setup_acpi() - Override CPU cache topology with data from the PPTT
547 * @cpu: Kernel logical cpu number
548 *
549 * Updates the global cache info provided by cpu_get_cacheinfo()
550 * when there are valid properties in the acpi_pptt_cache nodes. A
551 * successful parse may not result in any updates if none of the
552 * cache levels have any valid flags set. Futher, a unique value is
553 * associated with each known CPU cache entry. This unique value
554 * can be used to determine whether caches are shared between cpus.
555 *
556 * Return: -ENOENT on failure to find table, or 0 on success
557 */
558int cache_setup_acpi(unsigned int cpu)
559{
560 struct acpi_table_header *table;
561 acpi_status status;
562
563 pr_debug("Cache Setup ACPI cpu %d\n", cpu);
564
565 status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
566 if (ACPI_FAILURE(status)) {
567 pr_warn_once("No PPTT table found, cache topology may be inaccurate\n");
568 return -ENOENT;
569 }
570
571 cache_setup_acpi_cpu(table, cpu);
572 acpi_put_table(table);
573
574 return status;
575}
576
577/**
578 * find_acpi_cpu_topology() - Determine a unique topology value for a given cpu
579 * @cpu: Kernel logical cpu number
580 * @level: The topological level for which we would like a unique ID
581 *
582 * Determine a topology unique ID for each thread/core/cluster/mc_grouping
583 * /socket/etc. This ID can then be used to group peers, which will have
584 * matching ids.
585 *
586 * The search terminates when either the requested level is found or
587 * we reach a root node. Levels beyond the termination point will return the
588 * same unique ID. The unique id for level 0 is the acpi processor id. All
589 * other levels beyond this use a generated value to uniquely identify
590 * a topological feature.
591 *
592 * Return: -ENOENT if the PPTT doesn't exist, or the cpu cannot be found.
593 * Otherwise returns a value which represents a unique topological feature.
594 */
595int find_acpi_cpu_topology(unsigned int cpu, int level)
596{
597 return find_acpi_cpu_topology_tag(cpu, level, 0);
598}
599
600/**
601 * find_acpi_cpu_cache_topology() - Determine a unique cache topology value
602 * @cpu: Kernel logical cpu number
603 * @level: The cache level for which we would like a unique ID
604 *
605 * Determine a unique ID for each unified cache in the system
606 *
607 * Return: -ENOENT if the PPTT doesn't exist, or the cpu cannot be found.
608 * Otherwise returns a value which represents a unique topological feature.
609 */
610int find_acpi_cpu_cache_topology(unsigned int cpu, int level)
611{
612 struct acpi_table_header *table;
613 struct acpi_pptt_cache *found_cache;
614 acpi_status status;
615 u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
616 struct acpi_pptt_processor *cpu_node = NULL;
617 int ret = -1;
618
619 status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
620 if (ACPI_FAILURE(status)) {
621 pr_warn_once("No PPTT table found, topology may be inaccurate\n");
622 return -ENOENT;
623 }
624
625 found_cache = acpi_find_cache_node(table, acpi_cpu_id,
626 CACHE_TYPE_UNIFIED,
627 level,
628 &cpu_node);
629 if (found_cache)
630 ret = ACPI_PTR_DIFF(cpu_node, table);
631
632 acpi_put_table(table);
633
634 return ret;
635}
636
637
638/**
639 * find_acpi_cpu_topology_package() - Determine a unique cpu package value
640 * @cpu: Kernel logical cpu number
641 *
642 * Determine a topology unique package ID for the given cpu.
643 * This ID can then be used to group peers, which will have matching ids.
644 *
645 * The search terminates when either a level is found with the PHYSICAL_PACKAGE
646 * flag set or we reach a root node.
647 *
648 * Return: -ENOENT if the PPTT doesn't exist, or the cpu cannot be found.
649 * Otherwise returns a value which represents the package for this cpu.
650 */
651int find_acpi_cpu_topology_package(unsigned int cpu)
652{
653 return find_acpi_cpu_topology_tag(cpu, PPTT_ABORT_PACKAGE,
654 ACPI_PPTT_PHYSICAL_PACKAGE);
655}
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index a651ab3490d8..a303fd0e108c 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -343,8 +343,9 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
343 343
344 pr->performance->state_count = pss->package.count; 344 pr->performance->state_count = pss->package.count;
345 pr->performance->states = 345 pr->performance->states =
346 kmalloc(sizeof(struct acpi_processor_px) * pss->package.count, 346 kmalloc_array(pss->package.count,
347 GFP_KERNEL); 347 sizeof(struct acpi_processor_px),
348 GFP_KERNEL);
348 if (!pr->performance->states) { 349 if (!pr->performance->states) {
349 result = -ENOMEM; 350 result = -ENOMEM;
350 goto end; 351 goto end;
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index 7f9aff4b8d62..fbc936cf2025 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -534,8 +534,9 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
534 534
535 pr->throttling.state_count = tss->package.count; 535 pr->throttling.state_count = tss->package.count;
536 pr->throttling.states_tss = 536 pr->throttling.states_tss =
537 kmalloc(sizeof(struct acpi_processor_tx_tss) * tss->package.count, 537 kmalloc_array(tss->package.count,
538 GFP_KERNEL); 538 sizeof(struct acpi_processor_tx_tss),
539 GFP_KERNEL);
539 if (!pr->throttling.states_tss) { 540 if (!pr->throttling.states_tss) {
540 result = -ENOMEM; 541 result = -ENOMEM;
541 goto end; 542 goto end;
diff --git a/drivers/acpi/reboot.c b/drivers/acpi/reboot.c
index 71769fd687b2..6fa9c2a4cfe9 100644
--- a/drivers/acpi/reboot.c
+++ b/drivers/acpi/reboot.c
@@ -8,8 +8,8 @@ void acpi_reboot(void)
8{ 8{
9 struct acpi_generic_address *rr; 9 struct acpi_generic_address *rr;
10 struct pci_bus *bus0; 10 struct pci_bus *bus0;
11 u8 reset_value;
12 unsigned int devfn; 11 unsigned int devfn;
12 u8 reset_value;
13 13
14 if (acpi_disabled) 14 if (acpi_disabled)
15 return; 15 return;
@@ -40,7 +40,7 @@ void acpi_reboot(void)
40 /* Form PCI device/function pair. */ 40 /* Form PCI device/function pair. */
41 devfn = PCI_DEVFN((rr->address >> 32) & 0xffff, 41 devfn = PCI_DEVFN((rr->address >> 32) & 0xffff,
42 (rr->address >> 16) & 0xffff); 42 (rr->address >> 16) & 0xffff);
43 printk(KERN_DEBUG "Resetting with ACPI PCI RESET_REG."); 43 printk(KERN_DEBUG "Resetting with ACPI PCI RESET_REG.\n");
44 /* Write the value that resets us. */ 44 /* Write the value that resets us. */
45 pci_bus_write_config_byte(bus0, devfn, 45 pci_bus_write_config_byte(bus0, devfn,
46 (rr->address & 0xffff), reset_value); 46 (rr->address & 0xffff), reset_value);
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 974e58457697..5d0486f1cfcd 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -989,6 +989,13 @@ static void acpi_s2idle_wake(void)
989 !irqd_is_wakeup_armed(irq_get_irq_data(acpi_sci_irq))) { 989 !irqd_is_wakeup_armed(irq_get_irq_data(acpi_sci_irq))) {
990 pm_system_cancel_wakeup(); 990 pm_system_cancel_wakeup();
991 s2idle_wakeup = true; 991 s2idle_wakeup = true;
992 /*
993 * On some platforms with the LPS0 _DSM device noirq resume
994 * takes too much time for EC wakeup events to survive, so look
995 * for them now.
996 */
997 if (lps0_device_handle)
998 acpi_ec_dispatch_gpe();
992 } 999 }
993} 1000}
994 1001
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index 4fc59c3bc673..41324f0b1bee 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -857,12 +857,12 @@ void acpi_irq_stats_init(void)
857 num_gpes = acpi_current_gpe_count; 857 num_gpes = acpi_current_gpe_count;
858 num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA; 858 num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA;
859 859
860 all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1), 860 all_attrs = kcalloc(num_counters + 1, sizeof(struct attribute *),
861 GFP_KERNEL); 861 GFP_KERNEL);
862 if (all_attrs == NULL) 862 if (all_attrs == NULL)
863 return; 863 return;
864 864
865 all_counters = kzalloc(sizeof(struct event_counter) * (num_counters), 865 all_counters = kcalloc(num_counters, sizeof(struct event_counter),
866 GFP_KERNEL); 866 GFP_KERNEL);
867 if (all_counters == NULL) 867 if (all_counters == NULL)
868 goto fail; 868 goto fail;
@@ -871,7 +871,7 @@ void acpi_irq_stats_init(void)
871 if (ACPI_FAILURE(status)) 871 if (ACPI_FAILURE(status))
872 goto fail; 872 goto fail;
873 873
874 counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters), 874 counter_attrs = kcalloc(num_counters, sizeof(struct kobj_attribute),
875 GFP_KERNEL); 875 GFP_KERNEL);
876 if (counter_attrs == NULL) 876 if (counter_attrs == NULL)
877 goto fail; 877 goto fail;
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 849c4fb19b03..a3d012b08fc5 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -222,7 +222,7 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
222 * acpi_parse_entries_array - for each proc_num find a suitable subtable 222 * acpi_parse_entries_array - for each proc_num find a suitable subtable
223 * 223 *
224 * @id: table id (for debugging purposes) 224 * @id: table id (for debugging purposes)
225 * @table_size: single entry size 225 * @table_size: size of the root table
226 * @table_header: where does the table start? 226 * @table_header: where does the table start?
227 * @proc: array of acpi_subtable_proc struct containing entry id 227 * @proc: array of acpi_subtable_proc struct containing entry id
228 * and associated handler with it 228 * and associated handler with it
@@ -233,6 +233,11 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
233 * on it. Assumption is that there's only single handler for particular 233 * on it. Assumption is that there's only single handler for particular
234 * entry id. 234 * entry id.
235 * 235 *
236 * The table_size is not the size of the complete ACPI table (the length
237 * field in the header struct), but only the size of the root table; i.e.,
238 * the offset from the very first byte of the complete ACPI table, to the
239 * first byte of the very first subtable.
240 *
236 * On success returns sum of all matching entries for all proc handlers. 241 * On success returns sum of all matching entries for all proc handlers.
237 * Otherwise, -ENODEV or -EINVAL is returned. 242 * Otherwise, -ENODEV or -EINVAL is returned.
238 */ 243 */
@@ -400,7 +405,7 @@ int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler)
400 return -ENODEV; 405 return -ENODEV;
401} 406}
402 407
403/* 408/*
404 * The BIOS is supposed to supply a single APIC/MADT, 409 * The BIOS is supposed to supply a single APIC/MADT,
405 * but some report two. Provide a knob to use either. 410 * but some report two. Provide a knob to use either.
406 * (don't you wish instance 0 and 1 were not the same?) 411 * (don't you wish instance 0 and 1 were not the same?)
@@ -457,7 +462,7 @@ static const char * const table_sigs[] = {
457 ACPI_SIG_UEFI, ACPI_SIG_WAET, ACPI_SIG_WDAT, ACPI_SIG_WDDT, 462 ACPI_SIG_UEFI, ACPI_SIG_WAET, ACPI_SIG_WDAT, ACPI_SIG_WDDT,
458 ACPI_SIG_WDRT, ACPI_SIG_DSDT, ACPI_SIG_FADT, ACPI_SIG_PSDT, 463 ACPI_SIG_WDRT, ACPI_SIG_DSDT, ACPI_SIG_FADT, ACPI_SIG_PSDT,
459 ACPI_SIG_RSDT, ACPI_SIG_XSDT, ACPI_SIG_SSDT, ACPI_SIG_IORT, 464 ACPI_SIG_RSDT, ACPI_SIG_XSDT, ACPI_SIG_SSDT, ACPI_SIG_IORT,
460 ACPI_SIG_NFIT, ACPI_SIG_HMAT, NULL }; 465 ACPI_SIG_NFIT, ACPI_SIG_HMAT, ACPI_SIG_PPTT, NULL };
461 466
462#define ACPI_HEADER_SIZE sizeof(struct acpi_table_header) 467#define ACPI_HEADER_SIZE sizeof(struct acpi_table_header)
463 468