summary refs log tree commit diff
AgeCommit message (Collapse)Author
2020-03-28platform/x86: surface3_power: Add missed headersAndy Shevchenko
We obviously are users of bits.h and types.h. Add them to the list. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-28platform/x86: surface3_power: Reformat GUID assignmentAndy Shevchenko
For better readability reformat GUID assignment. While here, add the comment how this GUID looks in a string representation. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-28platform/x86: surface3_power: Drop useless macro ACPI_PTR()Andy Shevchenko
Driver depends to ACPI, this marco always is evaluated to the parameter, thus useless. Drop it for good. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-28platform/x86: surface3_power: Prefix POLL_INTERVAL with SURFACE_3Andy Shevchenko
For better namespace maintenance prefix POLL_INTERVAL macro with SURFACE_3. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-28platform/x86: surface3_power: Simplify mshw0011_adp_psr() to one linerAndy Shevchenko
Refactor mshw0011_adp_psr() to be one liner. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-28platform/x86: surface3_power: Use dev_err() instead of pr_err()Andy Shevchenko
We have device and we may use it to print messages. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-28platform/x86: surface3_power: Drop unused structure definitionAndy Shevchenko
As reported by kbuild bot the struct mshw0011_lookup in never used. Drop its definition for good. Reported-by: kbuild test robot <lkp@intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-26platform/x86: surface3_power: MSHW0011 rev-eng implementationBlaž Hrastnik
Patch was rebased on top of for-next. Thanks for your patience! Blaž I'm resubmitting this patch with review feedback addressed: https://patchwork.kernel.org/patch/10584079/ The patch was previously not resubmitted because it required a change that was reverted in the ACPICA. That has since been corrected: https://github.com/acpica/acpica/commit/9159c09a2a5897a43f78c95cdffc160d399722c3 We've been using this patch for a while and user reports confirm that it works: https://github.com/linux-surface/linux-surface Previous description follows. >8------------------------------------------------------8< The MSHW0011 device is a chip that replaces the battery firmware by using ACPI operation regions on the Surface 3. It is unclear whether or not the chip will be reused somewhere else (under Windows, the chip is called "Surface Platform Power Driver" and the driver is provided by Microsoft). The values have been obtained by reverse engineering, and are subject to errors. Looks like it works on overall pretty well. I couldn't manage to get the IRQ correctly triggered, so I am using a good old polling thread to check for changes. This is something to be fixed in a later version. Link: https://bugzilla.kernel.org/show_bug.cgi?id=106231 Signed-off-by: Blaž Hrastnik <blaz@mxxn.io> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Stephen Just <stephenjust@gmail.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20platform/x86: intel_pmc_core: Make pmc_core_substate_res_show() genericGayatri Kammela
Currently pmc_core_substate_res_show() uses array of char pointers i.e., lpm_modes for Tiger Lake directly to iterate through and to get the number of low power modes which is hardcoded and cannot be re-used for future platforms that support sub-states. To maintain readability, make pmc_core_substate_res_show() generic, so that it can re-used for future platforms. Cc: Chen Zhou <chenzhou10@huawei.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: David E. Box <david.e.box@intel.com> Signed-off-by: Gayatri Kammela <gayatri.kammela@intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20platform/x86: intel_pmc_core: Make pmc_core_lpm_display() generic for ↵Gayatri Kammela
platforms that support sub-states Currently pmc_core_lpm_display() uses an array of the struct pointers, i.e. tgl_lpm_maps for Tiger Lake directly to iterate through and to get the number of (live) status registers which is hard coded and can not be re-used for the future platforms that support sub-states. To maintain readability, make pmc_core_lpm_display() generic, so that it can be re-used for future platforms. Cc: Chen Zhou <chenzhou10@huawei.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: David E. Box <david.e.box@intel.com> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Gayatri Kammela <gayatri.kammela@intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Fix a typo in error messageMasanari Iida
This patch fix a spelling typo in error message. Signed-off-by: Masanari Iida <standby24x7@gmail.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Update versionSrinivas Pandruvada
Fair number of changes including bug fixes done to change version. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Avoid duplicate Package strings for jsonSrinivas Pandruvada
For platforms where multiple packages/die, this makes "Package-" key duplicate. To make unique, add die and cpu id to key name. So "Package-0" key name will change to "Package-0-die-x:cpu-x". For example: $sudo ./intel-speed-select -f json perf-profile info Intel(R) Speed Select Technology Executing on CPU model:106[0x6a] { "package-0:die-0:cpu-0": { "perf-profile-level-0": { "cpu-count": "32", "enable-cpu-count": "32", ... ... "package-1:die-0:cpu-16": { "perf-profile-level-0": { "cpu-count": "32", "enable-cpu-count": "32", "enable-cpu-mask": "ffff0000,ffff0000", ... ... For non json format, there is no change. Here when print_package_info() is called, it will return the level to print for other information. This level is used formatting. Also in some function duplicate code was there to print package,die and CPU information. Replace all that code with a call to print_package_info(). Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Add display for enabled cpus countSrinivas Pandruvada
In addition to total CPU count also display "enabled-cpu-count" for perf-profile info command. This will show number of CPUs in the "enable-cpu-mask". For example: perf-profile-level-4 cpu-count:32 enable-cpu-count:16 enable-cpu-mask:e42d0000,e42d0000 Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Print friendly warning for bad command lineSrinivas Pandruvada
When user specifies invalid option, display "Unknown Option: ignore", instead of "no match". Also display error for garbage on the command line. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Fix avx options for turbo-freq featureSrinivas Pandruvada
Specifying "avx2" and "avx512" option for display filter doesn't work with short option "-r", only works with --try-type. Also compare full 6 characters for "avx512" string. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Improve CLX commandsSrinivas Pandruvada
CLX doesn't have capability to change the feature in the hardware, but this acts as "--auto | -a" option. So even if user didn't specify the option, use this as --auto | -a to set cpufreq scaling frequency limits. Also remove perror with debug_printf as they don't bring any value. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Show error for invalid CPUs in the optionsSrinivas Pandruvada
When --cpu or -c is used to specify target CPUs and non of them are valid, display error. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Improve core-power result and error displaySrinivas Pandruvada
This change adds improved error display and handling for commands related to core-power feature. The changes include: - Replace perror with helpful error message - Use ordered priority for SKX based platform by default as the proportional priority is not supported - Don't show weight and epp in help and also give error when user tries to set them in SKX based platforms - Range check for epp and weights and display error Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Kernel interface error handlingSrinivas Pandruvada
Treat a case when mailbox/mmio command can't be handled by the kernel drivers when the module is removed or send a command which no driver can handle. In this case ENOTTY result is returned, so print error. Also when the isst_if_mmio module is removed, we can't send CLOS message messages via Mailbox on non SKX based platforms. When this module is removed, isst_platform_info.mmio_supported is set to 0. So it can't be used as a condition to send via mailbox. Here replace check for Skylake based platform to send via mailbox, other platforms can't use mailbox in lieu of MMIO. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Improve error display for turbo-freq featureSrinivas Pandruvada
This change adds improved error display and handling for commands related to turbo-freq feature. The changes include: - Replace perror/fprintf with helpful error message - Error for not specifying TDP level when required - Show error for invalid bucket number - Show message to enable core-power before enabling turbo-freq feature Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Improve error display for base-freq featureSrinivas Pandruvada
This change adds improved error display and handling for commands related to base-freq feature. The changes include: - Replace perror/fprintf with helpful error message - Error for not specifying TDP level when required - For CLX show help which shows limitation Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Improve output of perf-profile commandsSrinivas Pandruvada
Improve output of perf-profile commands: get-config-enabled get-lock-status Instead of showing 0/1, show meaningful strings. Also show error when command is failed. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Enhance help for core-power assocSrinivas Pandruvada
Enhance help to specify CPU and clos by an example. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Display error for invalid priority typeSrinivas Pandruvada
When priority type for core-power enable command is anything more than 1 display error before change to 1, which is ordered priority. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Check feature status firstSrinivas Pandruvada
Before looking for information about the base-freq or turbo-freq details, first check if the feature is supported at that level. If not print error and return. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Improve error display for perf-profile ↵Srinivas Pandruvada
feature This change adds improved error display and handling for commands related to perf-profile feature. The changes include: - When invalid TDP level is passed. display error and exit - Replace perror with helpful error message - Show error when TDP level can't be set - Print error when information can't be read for a level - Validate user options for invalid level - Display error for TDP lock status Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Add an API for error/information printSrinivas Pandruvada
Add a common API which can be used to print all error and information messages. In this way a common format can be used. For json output an error index in suffixed to make unique error key. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Enhance --info optionSrinivas Pandruvada
Add additional information, which will allow user to detect available features. This will allow users to check presence of features before continue to test. A sample output: $sudo ./intel-speed-select --info Intel(R) Speed Select Technology Executing on CPU model:85[0x55] Platform: API version : 1 Platform: Driver version : 1 Platform: mbox supported : 1 Platform: mmio supported : 0 Intel(R) SST-PP (feature perf-profile) is not supported Only performance level 0 (base level) is present TDP level change control is locked Intel(R) SST-TF (feature turbo-freq) is supported Intel(R) SST-BF (feature base-freq) is supported Intel(R) SST-CP (feature core-power) is supported Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Enhance helpSrinivas Pandruvada
Enhance help message which adds some example. The changes include: - Print help when options are not recognized. - For CLX, display only options which are applicable. - Sort options in alphatical order. - Disply help() instead of error: "Feature name and|or command not specified" - Remove duplicate display of Intel(R) Speed Select Technology Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Helpful warning for missing kernel interfaceSrinivas Pandruvada
When the device file "/dev/isst_interface" is not present, instead of failing on access, check at the start and print a helpful warning. Here CLX platform is an exception, which doesn't depend on the device file. So continue for CLX platform. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Store topology informationSrinivas Pandruvada
Once the CPU is offline, the topology information (core-id, package-id, die-id) is not accessible via sysfs. So when user selects a config level more than base config 0 and offlined CPUs to match the config level, to return to base config he has to manually online CPUs before. Without this CPUs information mapping from Punit CPU numbering will lot work as it needs atlest package id for each CPU. To avoid this additional steps store the topology information in a file , which is created on the very first run after boot. Since system boots in base config and all CPUs are online, we can get information about every CPU. Once any of the APIs like get_physical_package_id(), get_physical_core_id() or get_physical_die_id() fails to read from sysfs, read from the stored mapping file. This mapping file is stored in /tmp file system. so on every boot it is recreated to make sure that any new CPUs are added to the system before boot are taken into account. But don't use the stored physical device id when trying to get information for CPU to send message in for_each_online_package_in_set(). Here use the real value from syfs and in case fails try the next CPU. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Max CPU count calculation when CPU0 is ↵Srinivas Pandruvada
offline Currently /sys/devices/system/cpu/cpu0/topology/thread_siblings is used to get the max CPU count. But when CPU0 is offline, then this file will be absent. So add processing so that we can get count from any first CPU in the system. which is online. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Special handling for CPU 0 online/offlineSrinivas Pandruvada
When "-o" option for force online/offline is used with command: perf-profile set-config-level If the config level calls for CPU 0 online/offline, then call fails as there is special kernel setup required for CPU 0 online/offline and the currently not setup for that. But when call is for online CPU 0, then don't fail. Just warn that this system is not setup for CPU 0 online/offline. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Use more verbiage for clos informationSrinivas Pandruvada
Instead of displaying 0 and 1 for enable status, display "disabled" and "enabled" respectively. Similarly for priority type, display "ordered or proportional" instead of 0 and 1. An example display: $intel-speed-select -c 1 core-power info Intel(R) Speed Select Technology .. package-0 die-0 cpu-1 core-power support-status:supported enable-status:enabled clos-enable-status:enabled priority-type:proportional Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Enhance core-power info commandSrinivas Pandruvada
In addition to CLOS enable status, also show the core-power feature status. This will help why clos enable status didn't give desired results as the core-power feature may be disabled or unsupported. The new display looks as follows: $intel-speed-select core-power info Intel(R) Speed Select Technology .. package-0 die-0 cpu-0 core-power support-status:supported enable-status:enabled clos-enable-status:1 priority-type:0 In the above display "support-status" and "enable-status", shows the status of the core-power feature and "clos-enable-status", shows the status of the clos. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Make target CPU optional for core-power infoSrinivas Pandruvada
Currently "-c" is a mandatory option for "core-power info" command. Make this optional as this is a per package/die property. When not specified, it will print info for every package/die. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Warn for invalid package idSrinivas Pandruvada
When CPU is offline, we can't get package id. So print error for this and don't use output. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Fix last cpu numberSrinivas Pandruvada
Here topology_max_cpus is used for total CPU count, not the last CPU number. So remove "-1". Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20tools/power/x86/intel-speed-select: Fix mailbox usage for CLOS_PM_QOS_CONFIGSrinivas Pandruvada
Even for the products using MMIO, this message needs to be sent via mail box. The previous fix done for this didn't properly address this. That fix simply removed sending command via MMIO, but still didn't trigger sending via mailbox. Add additional condition to check for CLOS_PM_QOS_CONFIG, when MMIO is supported on a platform. Fixes: cd0e63706549 (tools/power/x86/intel-speed-select: Use mailbox for CLOS_PM_QOS_CONFIG) Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20platform/x86: sony-laptop: Use scnprintf() for avoiding potential buffer ↵Takashi Iwai
overflow Since snprintf() returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing with scnprintf(). Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20platform/x86: GPD pocket fan: Fix error message when temp-limits are out of ↵Hans de Goede
range Commit 1f27dbd8265d ("platform/x86: GPD pocket fan: Allow somewhat lower/higher temperature limits") changed the module-param sanity check to accept temperature limits between 20 and 90 degrees celcius. But the error message printed when the module params are outside this range was not updated. This commit updates the error message to match the new min and max value for the temp-limits. Reported-by: Pavel Machek <pavel@denx.de> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Pavel Machek <pavel@denx.de> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20platform/x86: ISST: Fix wrong unregister typeSrinivas Pandruvada
The MMIO driver is not unregistering with the correct type with the ISST common core during module removal. This should be unregistered with ISST_IF_DEV_MMIO instead of ISST_IF_DEV_MBOX. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20platform/x86: asus_wmi: Fix return value of fan_boost_mode_storeLeonid Maksymchuk
Function fan_boost_mode_store returns 0 if store is successful, this leads to infinite loop after any write to it's sysfs entry: # echo 0 >/sys/devices/platform/asus-nb-wmi/fan_boost_mode This command never ends, one CPU core is at 100% utilization. This patch fixes this by returning size of written data. Fixes: b096f626a682 ("platform/x86: asus-wmi: Switch fan boost mode") Signed-off-by: Leonid Maksymchuk <leonmaxx@gmail.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-03-20platform/x86: asus-wmi: Support laptops where the first battery is named BATTKristian Klausen
The WMI method to set the charge threshold does not provide a way to specific a battery, so we assume it is the first/primary battery (by checking if the name is BAT0). On some newer ASUS laptops (Zenbook UM431DA) though, the primary/first battery isn't named BAT0 but BATT, so we need to support that case. Fixes: 7973353e92ee ("platform/x86: asus-wmi: Refactor charge threshold to use the battery hooking API") Cc: stable@vger.kernel.org Signed-off-by: Kristian Klausen <kristian@klausen.dk> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-02-28platform/x86: Kconfig: Fix a typoChristophe JAILLET
'paramaters' should be 'parameters' Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-02-28platform/x86: i2c-multi-instantiate: Replace zero-length array with ↵Gustavo A. R. Silva
flexible-array member The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] https://github.com/KSPP/linux/issues/21 [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-02-28platform/x86/intel-uncore-freq: Add release callbackSrinivas Pandruvada
On module unload wait for relese callback for each packag_die entry and then free the memory. This is done by waiting on a completion object, till release() callback. While here, also change to kobject_init_and_add() to kobject_create_and_add() to simplify. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-02-28platform/x86/intel-uncore-freq: Fix static checker issue and potential race ↵Srinivas Pandruvada
condition There is a possible race condition when: All CPUs in a package is offlined and just before the last CPU offline, user tries to read sysfs entry and read happens while offline callback is about to delete the sysfs entry. Although not reproduced but this is possible scenerio and can be reproduced by adding a msleep() in the show_min_max_freq_khz() before mutex_lock() and read min_freq attribute from user space. Before msleep() finishes, force every CPUs in a package offline. This will cause deadlock, with offline and sysfs read/write operation because of mutex_lock. The uncore_remove_die_entry() will not release mutex till read/write callback returns because of kobject_put() and read/write callback waiting on mutex. We don't have to remove the sysfs folder when the package is offline. While there is no CPU present, we can fail the read/write calls by returning ENXIO error. So remove the kobject_put() call in offline path. This also address the warning from static checker, as there is no access to "data" variable after kobject_put: "The patch 49a474c7ba51: "platform/x86: Add support for Uncore frequency control" from Jan 13, 2020, leads to the following static checker warning: drivers/platform/x86/intel-uncore-frequency.c:285 uncore_remove_die_entry() error: dereferencing freed memory 'data' " Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-02-28platform/x86: intel_pmc_core: Add slp_s0_offset attribute back to tgl_reg_mapGayatri Kammela
If platforms such as Tiger Lake has sub-states of S0ix, then attributes such as slps0_dbg_offset become invalid. But slp_s0_offset is still valid as it is used to get the pmcdev_base_addr. Hence, add back slp_s0_offset and remove slps0_dbg_offset attributes. Cc: Chen Zhou <chenzhou10@huawei.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: David E. Box <david.e.box@intel.com> Signed-off-by: Gayatri Kammela <gayatri.kammela@intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>