From 60438d9a1ef4176d79739efadee122afe92904b8 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Thu, 24 Mar 2016 13:01:28 +0800 Subject: tools/power/acpi: close file only if it is open The logic on the test for a valid fd to close is incorrect. This was just a mistake and was pointed out by Colin Ian King. Link: https://patchwork.kernel.org/patch/8620201/ Original-by: Colin Ian King Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki diff --git a/tools/power/acpi/tools/acpidbg/acpidbg.c b/tools/power/acpi/tools/acpidbg/acpidbg.c index d070fcc..a88ac45 100644 --- a/tools/power/acpi/tools/acpidbg/acpidbg.c +++ b/tools/power/acpi/tools/acpidbg/acpidbg.c @@ -375,7 +375,7 @@ void usage(FILE *file, char *progname) int main(int argc, char **argv) { - int fd = 0; + int fd = -1; int ch; int len; int ret = EXIT_SUCCESS; @@ -430,7 +430,7 @@ int main(int argc, char **argv) acpi_aml_loop(fd); exit: - if (fd < 0) + if (fd >= 0) close(fd); if (acpi_aml_batch_cmd) free(acpi_aml_batch_cmd); -- cgit v0.10.2 From c68ae33e7fb4a010f9a48af3e4b87089dca96551 Mon Sep 17 00:00:00 2001 From: Lukas Wunner Date: Thu, 24 Mar 2016 13:15:20 +0100 Subject: ACPI / utils: Rename acpi_dev_present() acpi_dev_present() was originally named after pci_dev_present() to signify the similarity of the two functions. However Rafael J. Wysocki pointed out that the exported function acpi_dev_present() is easily confused with the non-exported acpi_device_is_present(). Additionally in ACPI parlance the term "present" usually refers to the "device is present" bit returned by the _STA control method, yet acpi_dev_present() merely checks presence in the namespace. It does not invoke _STA at all, let alone check the "device is present" bit. As suggested by Rafael, rename the function to acpi_dev_found() and adjust all existing call sites. Signed-off-by: Lukas Wunner Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 050673f..ac832bf 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -707,7 +707,7 @@ bool acpi_check_dsm(acpi_handle handle, const u8 *uuid, int rev, u64 funcs) EXPORT_SYMBOL(acpi_check_dsm); /** - * acpi_dev_present - Detect presence of a given ACPI device in the system. + * acpi_dev_found - Detect presence of a given ACPI device in the namespace. * @hid: Hardware ID of the device. * * Return %true if the device was present at the moment of invocation. @@ -719,7 +719,7 @@ EXPORT_SYMBOL(acpi_check_dsm); * instead). Calling from module_init() is fine (which is synonymous * with device_initcall()). */ -bool acpi_dev_present(const char *hid) +bool acpi_dev_found(const char *hid) { struct acpi_device_bus_id *acpi_device_bus_id; bool found = false; @@ -734,7 +734,7 @@ bool acpi_dev_present(const char *hid) return found; } -EXPORT_SYMBOL(acpi_dev_present); +EXPORT_SYMBOL(acpi_dev_found); /* * acpi_backlight= handling, this is done here rather then in video_detect.c diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 14362a8..a84fd15 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -87,7 +87,7 @@ acpi_evaluate_dsm_typed(acpi_handle handle, const u8 *uuid, int rev, int func, .package.elements = (eles) \ } -bool acpi_dev_present(const char *hid); +bool acpi_dev_found(const char *hid); #ifdef CONFIG_ACPI diff --git a/include/linux/apple-gmux.h b/include/linux/apple-gmux.h index b2d32e0..714186d 100644 --- a/include/linux/apple-gmux.h +++ b/include/linux/apple-gmux.h @@ -35,7 +35,7 @@ */ static inline bool apple_gmux_present(void) { - return acpi_dev_present(GMUX_ACPI_HID); + return acpi_dev_found(GMUX_ACPI_HID); } #else /* !CONFIG_APPLE_GMUX */ diff --git a/sound/pci/hda/thinkpad_helper.c b/sound/pci/hda/thinkpad_helper.c index 59ab6ce..f0955fd 100644 --- a/sound/pci/hda/thinkpad_helper.c +++ b/sound/pci/hda/thinkpad_helper.c @@ -13,7 +13,7 @@ static void (*old_vmaster_hook)(void *, int); static bool is_thinkpad(struct hda_codec *codec) { return (codec->core.subsystem_id >> 16 == 0x17aa) && - (acpi_dev_present("LEN0068") || acpi_dev_present("IBM0068")); + (acpi_dev_found("LEN0068") || acpi_dev_found("IBM0068")); } static void update_tpacpi_mute_led(void *private_data, int enabled) diff --git a/sound/soc/intel/boards/cht_bsw_max98090_ti.c b/sound/soc/intel/boards/cht_bsw_max98090_ti.c index e609f08..ac60b04 100644 --- a/sound/soc/intel/boards/cht_bsw_max98090_ti.c +++ b/sound/soc/intel/boards/cht_bsw_max98090_ti.c @@ -296,7 +296,7 @@ static int snd_cht_mc_probe(struct platform_device *pdev) if (!drv) return -ENOMEM; - drv->ts3a227e_present = acpi_dev_present("104C227E"); + drv->ts3a227e_present = acpi_dev_found("104C227E"); if (!drv->ts3a227e_present) { /* no need probe TI jack detection chip */ snd_soc_card_cht.aux_dev = NULL; diff --git a/sound/soc/intel/boards/cht_bsw_rt5645.c b/sound/soc/intel/boards/cht_bsw_rt5645.c index 2a6f808..3f2c1ea 100644 --- a/sound/soc/intel/boards/cht_bsw_rt5645.c +++ b/sound/soc/intel/boards/cht_bsw_rt5645.c @@ -357,7 +357,7 @@ static int snd_cht_mc_probe(struct platform_device *pdev) return -ENOMEM; for (i = 0; i < ARRAY_SIZE(snd_soc_cards); i++) { - if (acpi_dev_present(snd_soc_cards[i].codec_id)) { + if (acpi_dev_found(snd_soc_cards[i].codec_id)) { dev_dbg(&pdev->dev, "found codec %s\n", snd_soc_cards[i].codec_id); card = snd_soc_cards[i].soc_card; -- cgit v0.10.2 From 9f9de69d754cc9f8f2d8c21bb92275d95ddb3c77 Mon Sep 17 00:00:00 2001 From: Lukas Wunner Date: Thu, 24 Mar 2016 13:15:20 +0100 Subject: eeepc-wmi: Use acpi_dev_found() Use shiny new acpi_dev_found() and remove all the boilerplate to search for a particular ACPI device. No functional change. Signed-off-by: Lukas Wunner Acked-by: Darren Hart Signed-off-by: Rafael J. Wysocki diff --git a/drivers/platform/x86/eeepc-wmi.c b/drivers/platform/x86/eeepc-wmi.c index 14fd2ec..17b365f 100644 --- a/drivers/platform/x86/eeepc-wmi.c +++ b/drivers/platform/x86/eeepc-wmi.c @@ -204,30 +204,10 @@ static void eeepc_wmi_key_filter(struct asus_wmi_driver *asus_wmi, int *code, } } -static acpi_status eeepc_wmi_parse_device(acpi_handle handle, u32 level, - void *context, void **retval) -{ - pr_warn("Found legacy ATKD device (%s)\n", EEEPC_ACPI_HID); - *(bool *)context = true; - return AE_CTRL_TERMINATE; -} - -static int eeepc_wmi_check_atkd(void) -{ - acpi_status status; - bool found = false; - - status = acpi_get_devices(EEEPC_ACPI_HID, eeepc_wmi_parse_device, - &found, NULL); - - if (ACPI_FAILURE(status) || !found) - return 0; - return -1; -} - static int eeepc_wmi_probe(struct platform_device *pdev) { - if (eeepc_wmi_check_atkd()) { + if (acpi_dev_found(EEEPC_ACPI_HID)) { + pr_warn("Found legacy ATKD device (%s)\n", EEEPC_ACPI_HID); pr_warn("WMI device present, but legacy ATKD device is also " "present and enabled\n"); pr_warn("You probably booted with acpi_osi=\"Linux\" or " -- cgit v0.10.2 From 8c92a75e5086e85000deeb05f6f852446c8f758a Mon Sep 17 00:00:00 2001 From: Lukas Wunner Date: Thu, 24 Mar 2016 13:15:20 +0100 Subject: acer-wmi: Use acpi_dev_found() Use shiny new acpi_dev_found() and remove all the boilerplate to search for a particular ACPI device. No functional change. Signed-off-by: Lukas Wunner Reviewed-by: Lee, Chun-Yi Acked-by: Darren Hart Signed-off-by: Rafael J. Wysocki diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c index 1062fa4..79d64ea 100644 --- a/drivers/platform/x86/acer-wmi.c +++ b/drivers/platform/x86/acer-wmi.c @@ -793,15 +793,6 @@ static acpi_status __init AMW0_find_mailled(void) return AE_OK; } -static int AMW0_set_cap_acpi_check_device_found __initdata; - -static acpi_status __init AMW0_set_cap_acpi_check_device_cb(acpi_handle handle, - u32 level, void *context, void **retval) -{ - AMW0_set_cap_acpi_check_device_found = 1; - return AE_OK; -} - static const struct acpi_device_id norfkill_ids[] __initconst = { { "VPC2004", 0}, { "IBM0068", 0}, @@ -816,9 +807,10 @@ static int __init AMW0_set_cap_acpi_check_device(void) const struct acpi_device_id *id; for (id = norfkill_ids; id->id[0]; id++) - acpi_get_devices(id->id, AMW0_set_cap_acpi_check_device_cb, - NULL, NULL); - return AMW0_set_cap_acpi_check_device_found; + if (acpi_dev_found(id->id)) + return true; + + return false; } static acpi_status __init AMW0_set_capabilities(void) -- cgit v0.10.2 From 6df795ff139a85eba8767a1504414c41e8814a1a Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 15 Apr 2016 08:53:41 +0100 Subject: ACPI / ARM64: Don't enable ACPI by default on ARM64 If ACPI is selectable it is enabled by default. This is a good choice for architectures where the overwhelming majority of systems use ACPI like x86 and IA-64 but is less clear for architectures where it's less common like ARM64. Change the default selection so that it's only done explicitly on those architectures where ACPI is universally used. Signed-off-by: Mark Brown Acked-by: Catalin Marinas Acked-by: Hanjun Guo Acked-by: Olof Johansson Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 82b96ee..2fcf87a 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -8,7 +8,7 @@ menuconfig ACPI depends on IA64 || X86 || (ARM64 && EXPERT) depends on PCI select PNP - default y + default y if (IA64 || X86) help Advanced Configuration and Power Interface (ACPI) support for Linux requires an ACPI-compliant platform (hardware/firmware), -- cgit v0.10.2 From 46bcc6b1f3f77ff0a5b88b87a6be5954ed0c3ce6 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 15 Apr 2016 08:53:42 +0100 Subject: ACPI / ARM64: Remove EXPERT dependency for ACPI on ARM64 When ACPI was originally merged for arm64 it had only been tested on emulators and not on real physical platforms and no platforms were relying on it. This meant that there were concerns that there might be serious issues attempting to use it on practical systems so it had a dependency on EXPERT added to warn people that it was in an early stage of development with very little practical testing. Since then things have moved on a bit. We have seen people testing on real hardware and now have people starting to produce some platforms (the most prominent being the 96boards Cello) which only have ACPI support and which build and run to some useful extent with mainline. This is not to say that ACPI support or support for these systems is completely done, there are still areas being worked on such as PCI, but at this point it seems that we can be reasonably sure that ACPI will be viable for use on ARM64 and that the already merged support works for the cases it handles. For the AMD Seattle based platforms support outside of PCI has been fairly complete in mainline a few releases now. This is also not to say that we don't have vendors working with ACPI who are trying do things that we would not consider optimal but it does not appear that the EXPERT dependency is having a substantial impact on these vendors. Given all this it seems that at this point the EXPERT dependency mainly creates inconvenience for users with systems that are doing the right thing and gets in the way of including the ACPI code in the testing that people are doing on mainline. Removing it should help our ongoing testing cover those platforms with only ACPI support and help ensure that when ACPI code is merged any problems it causes for other users are more easily discovered. Signed-off-by: Mark Brown Acked-by: Graeme Gregory Acked-by: Ard Biesheuvel Reviewed-by: Al Stone Acked-by: Hanjun Guo Acked-by: Catalin Marinas Acked-by: Roy Franz Acked-by: Olof Johansson Acked-by: Timur Tabi Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 2fcf87a..fa0d319 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -5,7 +5,7 @@ menuconfig ACPI bool "ACPI (Advanced Configuration and Power Interface) Support" depends on !IA64_HP_SIM - depends on IA64 || X86 || (ARM64 && EXPERT) + depends on IA64 || X86 || ARM64 depends on PCI select PNP default y if (IA64 || X86) -- cgit v0.10.2 From 2b13f01b90fc07334911b424709901bb88517746 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 15 Apr 2016 08:53:43 +0100 Subject: arm64: defconfig: Enable ACPI Enable ACPI by default to support testing of ACPI only systems and ensure that defconfig will boot on anything, for arm64 this is not done in Kconfig since a very large proportion of arm64 systems have no ACPI at all. Signed-off-by: Mark Brown Acked-by: Catalin Marinas Acked-by: Hanjun Guo Acked-by: Roy Franz Signed-off-by: Rafael J. Wysocki diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig index a44ef99..c5e0132 100644 --- a/arch/arm64/configs/defconfig +++ b/arch/arm64/configs/defconfig @@ -264,6 +264,7 @@ CONFIG_PHY_RCAR_GEN3_USB2=y CONFIG_PHY_HI6220_USB=y CONFIG_PHY_XGENE=y CONFIG_ARM_SCPI_PROTOCOL=y +CONFIG_ACPI=y CONFIG_EXT2_FS=y CONFIG_EXT3_FS=y CONFIG_FANOTIFY=y -- cgit v0.10.2 From 6283f97d5fbfdd1e31694d7f6000eb728cdfba77 Mon Sep 17 00:00:00 2001 From: Betty Dall Date: Sat, 30 Apr 2016 10:03:37 -0600 Subject: ACPI / device_sysfs: Add sysfs support for _HRV hardware revision The ACPI _HRV object on the device is used to supply Linux with the device's hardware revision. This is an optional object. Add sysfs support for the _HRV object if it exists on the device. This change allows users to easily find the hardware version of non-PCI hardware by looking at the sysfs 'hrv' file. It is most useful for non-PCI devices because lspci can list the hardware version for PCI devices. Signed-off-by: Betty Dall Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index b9afb47..49cc0cb 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -473,6 +473,21 @@ acpi_device_sun_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR(sun, 0444, acpi_device_sun_show, NULL); +static ssize_t +acpi_device_hrv_show(struct device *dev, struct device_attribute *attr, + char *buf) { + struct acpi_device *acpi_dev = to_acpi_device(dev); + acpi_status status; + unsigned long long hrv; + + status = acpi_evaluate_integer(acpi_dev->handle, "_HRV", NULL, &hrv); + if (ACPI_FAILURE(status)) + return -EIO; + + return sprintf(buf, "%llu\n", hrv); +} +static DEVICE_ATTR(hrv, 0444, acpi_device_hrv_show, NULL); + static ssize_t status_show(struct device *dev, struct device_attribute *attr, char *buf) { struct acpi_device *acpi_dev = to_acpi_device(dev); @@ -541,6 +556,12 @@ int acpi_device_setup_files(struct acpi_device *dev) goto end; } + if (acpi_has_method(dev->handle, "_HRV")) { + result = device_create_file(&dev->dev, &dev_attr_hrv); + if (result) + goto end; + } + if (acpi_has_method(dev->handle, "_STA")) { result = device_create_file(&dev->dev, &dev_attr_status); if (result) @@ -604,6 +625,9 @@ void acpi_device_remove_files(struct acpi_device *dev) if (acpi_has_method(dev->handle, "_SUN")) device_remove_file(&dev->dev, &dev_attr_sun); + if (acpi_has_method(dev->handle, "_HRV")) + device_remove_file(&dev->dev, &dev_attr_hrv); + if (dev->pnp.unique_id) device_remove_file(&dev->dev, &dev_attr_uid); if (dev->pnp.type.bus_address) -- cgit v0.10.2 From 6c0244091e8aa98e7977bdddeab2bb864cff9d91 Mon Sep 17 00:00:00 2001 From: Betty Dall Date: Sat, 30 Apr 2016 10:03:38 -0600 Subject: ACPI / device_sysfs: Change _SUN and _STA show functions error return to EIO The error return from a sysfs show function is passed up through the call chain and visible as the return from the read system call. The show functions for the _STA and _SUN object currently return -ENODEV. This patch changes the return to -EIO. ENODEV makes less sense since the "device' exists or there wouldn't be a sysfs file. Signed-off-by: Betty Dall Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 49cc0cb..e556a3e 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -467,7 +467,7 @@ acpi_device_sun_show(struct device *dev, struct device_attribute *attr, status = acpi_evaluate_integer(acpi_dev->handle, "_SUN", NULL, &sun); if (ACPI_FAILURE(status)) - return -ENODEV; + return -EIO; return sprintf(buf, "%llu\n", sun); } @@ -496,7 +496,7 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr, status = acpi_evaluate_integer(acpi_dev->handle, "_STA", NULL, &sta); if (ACPI_FAILURE(status)) - return -ENODEV; + return -EIO; return sprintf(buf, "%llu\n", sta); } -- cgit v0.10.2 From a508d954af748bc1f5f1d9174f167a8650fca923 Mon Sep 17 00:00:00 2001 From: Betty Dall Date: Sat, 30 Apr 2016 10:03:39 -0600 Subject: ACPI / device_sysfs: Clean up checkpatch errors Cleaning up two existing checkpatch errors (and 2 warnings) in device_sysfs.c since the file is being changed. The change in acpi_device_setup_files() is changing spaces to a tab. Signed-off-by: Betty Dall Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index e556a3e..7b2c48f 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -35,7 +35,7 @@ static ssize_t acpi_object_path(acpi_handle handle, char *buf) if (result) return result; - result = sprintf(buf, "%s\n", (char*)path.pointer); + result = sprintf(buf, "%s\n", (char *)path.pointer); kfree(path.pointer); return result; } @@ -333,7 +333,8 @@ int acpi_device_modalias(struct device *dev, char *buf, int size) EXPORT_SYMBOL_GPL(acpi_device_modalias); static ssize_t -acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) { +acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) +{ return __acpi_device_modalias(to_acpi_device(dev), buf, 1024); } static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL); @@ -397,7 +398,8 @@ acpi_eject_store(struct device *d, struct device_attribute *attr, static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store); static ssize_t -acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) { +acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) +{ struct acpi_device *acpi_dev = to_acpi_device(dev); return sprintf(buf, "%s\n", acpi_device_hid(acpi_dev)); @@ -568,10 +570,10 @@ int acpi_device_setup_files(struct acpi_device *dev) goto end; } - /* - * If device has _EJ0, 'eject' file is created that is used to trigger - * hot-removal function from userland. - */ + /* + * If device has _EJ0, 'eject' file is created that is used to trigger + * hot-removal function from userland. + */ if (acpi_has_method(dev->handle, "_EJ0")) { result = device_create_file(&dev->dev, &dev_attr_eject); if (result) -- cgit v0.10.2 From 103544d86976338057d6a91f721b49d3acc7df7f Mon Sep 17 00:00:00 2001 From: Sinan Kaya Date: Sun, 17 Apr 2016 13:36:53 -0400 Subject: ACPI,PCI,IRQ: reduce resource requirements Code has been redesigned to calculate penalty requirements on the fly. This significantly simplifies the implementation and removes some of the init calls from x86 architecture. Signed-off-by: Sinan Kaya Acked-by: Bjorn Helgaas Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c index ededa90..cc0ba16 100644 --- a/drivers/acpi/pci_link.c +++ b/drivers/acpi/pci_link.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "internal.h" @@ -440,7 +441,6 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq) #define ACPI_MAX_IRQS 256 #define ACPI_MAX_ISA_IRQ 16 -#define PIRQ_PENALTY_PCI_AVAILABLE (0) #define PIRQ_PENALTY_PCI_POSSIBLE (16*16) #define PIRQ_PENALTY_PCI_USING (16*16*16) #define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16) @@ -457,9 +457,9 @@ static int acpi_irq_penalty[ACPI_MAX_IRQS] = { PIRQ_PENALTY_ISA_TYPICAL, /* IRQ6 */ PIRQ_PENALTY_ISA_TYPICAL, /* IRQ7 parallel, spurious */ PIRQ_PENALTY_ISA_TYPICAL, /* IRQ8 rtc, sometimes */ - PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */ - PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */ - PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */ + 0, /* IRQ9 PCI, often acpi */ + 0, /* IRQ10 PCI */ + 0, /* IRQ11 PCI */ PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */ PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */ PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */ @@ -467,6 +467,60 @@ static int acpi_irq_penalty[ACPI_MAX_IRQS] = { /* >IRQ15 */ }; +static int acpi_irq_pci_sharing_penalty(int irq) +{ + struct acpi_pci_link *link; + int penalty = 0; + + list_for_each_entry(link, &acpi_link_list, list) { + /* + * If a link is active, penalize its IRQ heavily + * so we try to choose a different IRQ. + */ + if (link->irq.active && link->irq.active == irq) + penalty += PIRQ_PENALTY_PCI_USING; + else { + int i; + + /* + * If a link is inactive, penalize the IRQs it + * might use, but not as severely. + */ + for (i = 0; i < link->irq.possible_count; i++) + if (link->irq.possible[i] == irq) + penalty += PIRQ_PENALTY_PCI_POSSIBLE / + link->irq.possible_count; + } + } + + return penalty; +} + +static int acpi_irq_get_penalty(int irq) +{ + int penalty = 0; + + if (irq < ACPI_MAX_ISA_IRQ) + penalty += acpi_irq_penalty[irq]; + + /* + * Penalize IRQ used by ACPI SCI. If ACPI SCI pin attributes conflict + * with PCI IRQ attributes, mark ACPI SCI as ISA_ALWAYS so it won't be + * use for PCI IRQs. + */ + if (irq == acpi_gbl_FADT.sci_interrupt) { + u32 type = irq_get_trigger_type(irq) & IRQ_TYPE_SENSE_MASK; + + if (type != IRQ_TYPE_LEVEL_LOW) + penalty += PIRQ_PENALTY_ISA_ALWAYS; + else + penalty += PIRQ_PENALTY_PCI_USING; + } + + penalty += acpi_irq_pci_sharing_penalty(irq); + return penalty; +} + int __init acpi_irq_penalty_init(void) { struct acpi_pci_link *link; @@ -547,12 +601,12 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link) * the use of IRQs 9, 10, 11, and >15. */ for (i = (link->irq.possible_count - 1); i >= 0; i--) { - if (acpi_irq_penalty[irq] > - acpi_irq_penalty[link->irq.possible[i]]) + if (acpi_irq_get_penalty(irq) > + acpi_irq_get_penalty(link->irq.possible[i])) irq = link->irq.possible[i]; } } - if (acpi_irq_penalty[irq] >= PIRQ_PENALTY_ISA_ALWAYS) { + if (acpi_irq_get_penalty(irq) >= PIRQ_PENALTY_ISA_ALWAYS) { printk(KERN_ERR PREFIX "No IRQ available for %s [%s]. " "Try pci=noacpi or acpi=off\n", acpi_device_name(link->device), @@ -568,7 +622,6 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link) acpi_device_bid(link->device)); return -ENODEV; } else { - acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING; printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n", acpi_device_name(link->device), acpi_device_bid(link->device), link->irq.active); @@ -800,9 +853,10 @@ static int __init acpi_irq_penalty_update(char *str, int used) continue; if (used) - acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED; + acpi_irq_penalty[irq] = acpi_irq_get_penalty(irq) + + PIRQ_PENALTY_ISA_USED; else - acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE; + acpi_irq_penalty[irq] = 0; if (retval != 2) /* no next number */ break; @@ -819,34 +873,19 @@ static int __init acpi_irq_penalty_update(char *str, int used) */ void acpi_penalize_isa_irq(int irq, int active) { - if (irq >= 0 && irq < ARRAY_SIZE(acpi_irq_penalty)) { - if (active) - acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED; - else - acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING; - } + if (irq >= 0 && irq < ARRAY_SIZE(acpi_irq_penalty)) + acpi_irq_penalty[irq] = acpi_irq_get_penalty(irq) + + active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING; } bool acpi_isa_irq_available(int irq) { return irq >= 0 && (irq >= ARRAY_SIZE(acpi_irq_penalty) || - acpi_irq_penalty[irq] < PIRQ_PENALTY_ISA_ALWAYS); + acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS); } -/* - * Penalize IRQ used by ACPI SCI. If ACPI SCI pin attributes conflict with - * PCI IRQ attributes, mark ACPI SCI as ISA_ALWAYS so it won't be use for - * PCI IRQs. - */ void acpi_penalize_sci_irq(int irq, int trigger, int polarity) { - if (irq >= 0 && irq < ARRAY_SIZE(acpi_irq_penalty)) { - if (trigger != ACPI_MADT_TRIGGER_LEVEL || - polarity != ACPI_MADT_POLARITY_ACTIVE_LOW) - acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_ALWAYS; - else - acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING; - } } /* -- cgit v0.10.2 From 5c5087a5539083305f1199f09ac2e7f14d855ff3 Mon Sep 17 00:00:00 2001 From: Sinan Kaya Date: Sun, 17 Apr 2016 13:36:54 -0400 Subject: ACPI,PCI,IRQ: reduce static IRQ array size to 16 Now that the supported number of PCI IRQs are no longer capped with 256, renaming the static array to support ISA IRQs only and removing the MAX_IRQS constant. Signed-off-by: Sinan Kaya Acked-by: Bjorn Helgaas Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c index cc0ba16..12ea784 100644 --- a/drivers/acpi/pci_link.c +++ b/drivers/acpi/pci_link.c @@ -438,8 +438,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq) * enabled system. */ -#define ACPI_MAX_IRQS 256 -#define ACPI_MAX_ISA_IRQ 16 +#define ACPI_MAX_ISA_IRQS 16 #define PIRQ_PENALTY_PCI_POSSIBLE (16*16) #define PIRQ_PENALTY_PCI_USING (16*16*16) @@ -447,7 +446,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq) #define PIRQ_PENALTY_ISA_USED (16*16*16*16*16) #define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16) -static int acpi_irq_penalty[ACPI_MAX_IRQS] = { +static int acpi_isa_irq_penalty[ACPI_MAX_ISA_IRQS] = { PIRQ_PENALTY_ISA_ALWAYS, /* IRQ0 timer */ PIRQ_PENALTY_ISA_ALWAYS, /* IRQ1 keyboard */ PIRQ_PENALTY_ISA_ALWAYS, /* IRQ2 cascade */ @@ -500,8 +499,8 @@ static int acpi_irq_get_penalty(int irq) { int penalty = 0; - if (irq < ACPI_MAX_ISA_IRQ) - penalty += acpi_irq_penalty[irq]; + if (irq < ACPI_MAX_ISA_IRQS) + penalty += acpi_isa_irq_penalty[irq]; /* * Penalize IRQ used by ACPI SCI. If ACPI SCI pin attributes conflict @@ -541,14 +540,15 @@ int __init acpi_irq_penalty_init(void) link->irq.possible_count; for (i = 0; i < link->irq.possible_count; i++) { - if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ) - acpi_irq_penalty[link->irq. + if (link->irq.possible[i] < ACPI_MAX_ISA_IRQS) + acpi_isa_irq_penalty[link->irq. possible[i]] += penalty; } - } else if (link->irq.active) { - acpi_irq_penalty[link->irq.active] += + } else if (link->irq.active && + (link->irq.active < ACPI_MAX_ISA_IRQS)) { + acpi_isa_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_POSSIBLE; } } @@ -831,7 +831,7 @@ static void acpi_pci_link_remove(struct acpi_device *device) } /* - * modify acpi_irq_penalty[] from cmdline + * modify acpi_isa_irq_penalty[] from cmdline */ static int __init acpi_irq_penalty_update(char *str, int used) { @@ -840,24 +840,24 @@ static int __init acpi_irq_penalty_update(char *str, int used) for (i = 0; i < 16; i++) { int retval; int irq; + int new_penalty; retval = get_option(&str, &irq); if (!retval) break; /* no number found */ - if (irq < 0) - continue; - - if (irq >= ARRAY_SIZE(acpi_irq_penalty)) + /* see if this is a ISA IRQ */ + if ((irq < 0) || (irq >= ACPI_MAX_ISA_IRQS)) continue; if (used) - acpi_irq_penalty[irq] = acpi_irq_get_penalty(irq) + - PIRQ_PENALTY_ISA_USED; + new_penalty = acpi_irq_get_penalty(irq) + + PIRQ_PENALTY_ISA_USED; else - acpi_irq_penalty[irq] = 0; + new_penalty = 0; + acpi_isa_irq_penalty[irq] = new_penalty; if (retval != 2) /* no next number */ break; } @@ -873,14 +873,14 @@ static int __init acpi_irq_penalty_update(char *str, int used) */ void acpi_penalize_isa_irq(int irq, int active) { - if (irq >= 0 && irq < ARRAY_SIZE(acpi_irq_penalty)) - acpi_irq_penalty[irq] = acpi_irq_get_penalty(irq) + + if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty))) + acpi_isa_irq_penalty[irq] = acpi_irq_get_penalty(irq) + active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING; } bool acpi_isa_irq_available(int irq) { - return irq >= 0 && (irq >= ARRAY_SIZE(acpi_irq_penalty) || + return irq >= 0 && (irq >= ARRAY_SIZE(acpi_isa_irq_penalty) || acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS); } -- cgit v0.10.2 From 1fcb6a813c4f67a0ba189b0d057b70ba084f6e1a Mon Sep 17 00:00:00 2001 From: Sinan Kaya Date: Sun, 17 Apr 2016 13:36:55 -0400 Subject: ACPI,PCI,IRQ: remove redundant code in acpi_irq_penalty_init() acpi_irq_get_penalty is now calculating the penalty on the fly now. No need to maintain global list of penalties or calculate them at the init time. Removing duplicate code in acpi_irq_penalty_init. Signed-off-by: Sinan Kaya Acked-by: Bjorn Helgaas Signed-off-by: Rafael J. Wysocki diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c index 3cd6983..b2a4e2a 100644 --- a/arch/x86/pci/acpi.c +++ b/arch/x86/pci/acpi.c @@ -396,7 +396,6 @@ int __init pci_acpi_init(void) return -ENODEV; printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n"); - acpi_irq_penalty_init(); pcibios_enable_irq = acpi_pci_irq_enable; pcibios_disable_irq = acpi_pci_irq_disable; x86_init.pci.init_irq = x86_init_noop; diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c index 12ea784..ab39208 100644 --- a/drivers/acpi/pci_link.c +++ b/drivers/acpi/pci_link.c @@ -520,42 +520,6 @@ static int acpi_irq_get_penalty(int irq) return penalty; } -int __init acpi_irq_penalty_init(void) -{ - struct acpi_pci_link *link; - int i; - - /* - * Update penalties to facilitate IRQ balancing. - */ - list_for_each_entry(link, &acpi_link_list, list) { - - /* - * reflect the possible and active irqs in the penalty table -- - * useful for breaking ties. - */ - if (link->irq.possible_count) { - int penalty = - PIRQ_PENALTY_PCI_POSSIBLE / - link->irq.possible_count; - - for (i = 0; i < link->irq.possible_count; i++) { - if (link->irq.possible[i] < ACPI_MAX_ISA_IRQS) - acpi_isa_irq_penalty[link->irq. - possible[i]] += - penalty; - } - - } else if (link->irq.active && - (link->irq.active < ACPI_MAX_ISA_IRQS)) { - acpi_isa_irq_penalty[link->irq.active] += - PIRQ_PENALTY_PCI_POSSIBLE; - } - } - - return 0; -} - static int acpi_irq_balance = -1; /* 0: static, 1: balance */ static int acpi_pci_link_allocate(struct acpi_pci_link *link) diff --git a/include/acpi/acpi_drivers.h b/include/acpi/acpi_drivers.h index 29c6912..797ae2e 100644 --- a/include/acpi/acpi_drivers.h +++ b/include/acpi/acpi_drivers.h @@ -78,7 +78,6 @@ /* ACPI PCI Interrupt Link (pci_link.c) */ -int acpi_irq_penalty_init(void); int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering, int *polarity, char **name); int acpi_pci_link_free_irq(acpi_handle handle); -- cgit v0.10.2 From 9e5ed6d1fb87dc3ff0c2a94ed75fe82027a9f597 Mon Sep 17 00:00:00 2001 From: Sinan Kaya Date: Sun, 17 Apr 2016 13:36:56 -0400 Subject: ACPI,PCI,IRQ: remove SCI penalize function Removing the SCI penalize function as the penalty is now calculated on the fly. Signed-off-by: Sinan Kaya Acked-by: Bjorn Helgaas Signed-off-by: Rafael J. Wysocki diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c index 8c2f1ef..edf4840 100644 --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -445,7 +445,6 @@ static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK; mp_override_legacy_irq(bus_irq, polarity, trigger, gsi); - acpi_penalize_sci_irq(bus_irq, trigger, polarity); /* * stash over-ride to indicate we've been here diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c index ab39208..8fc7323 100644 --- a/drivers/acpi/pci_link.c +++ b/drivers/acpi/pci_link.c @@ -848,10 +848,6 @@ bool acpi_isa_irq_available(int irq) acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS); } -void acpi_penalize_sci_irq(int irq, int trigger, int polarity) -{ -} - /* * Over-ride default table to reserve additional IRQs for use by ISA * e.g. acpi_irq_isa=5 diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 06ed7e5..0f41317 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -311,7 +311,6 @@ struct pci_dev; int acpi_pci_irq_enable (struct pci_dev *dev); void acpi_penalize_isa_irq(int irq, int active); bool acpi_isa_irq_available(int irq); -void acpi_penalize_sci_irq(int irq, int trigger, int polarity); void acpi_pci_irq_disable (struct pci_dev *dev); extern int ec_read(u8 addr, u8 *val); -- cgit v0.10.2 From f18ebc211e259d4f591e39e74b2aa2de226c9a1d Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 5 May 2016 16:23:04 +0300 Subject: ACPI / sysfs: fix error code in get_status() The problem with ornamental, do-nothing gotos is that they lead to "forgot to set the error code" bugs. We should be returning -EINVAL here but we don't. It leads to an uninitalized variable in counter_show(): drivers/acpi/sysfs.c:603 counter_show() error: uninitialized symbol 'status'. Fixes: 1c8fce27e275 (ACPI: introduce drivers/acpi/sysfs.c) Signed-off-by: Dan Carpenter Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c index 0243d37..4b3a9e2 100644 --- a/drivers/acpi/sysfs.c +++ b/drivers/acpi/sysfs.c @@ -555,23 +555,22 @@ static void acpi_global_event_handler(u32 event_type, acpi_handle device, static int get_status(u32 index, acpi_event_status *status, acpi_handle *handle) { - int result = 0; + int result; if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS) - goto end; + return -EINVAL; if (index < num_gpes) { result = acpi_get_gpe_device(index, handle); if (result) { ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND, "Invalid GPE 0x%x", index)); - goto end; + return result; } result = acpi_get_gpe_status(*handle, index, status); } else if (index < (num_gpes + ACPI_NUM_FIXED_EVENTS)) result = acpi_get_event_status(index - num_gpes, status); -end: return result; } -- cgit v0.10.2