platform:x86: Add PMC Driver for Intel Core SOC
PATCH v4 1/1 platform:x86: Add PMC Driver for Intel Core SOC
This patch adds the Power Management Controller driver as a pci driver for Intel Core SOC architecture.
This driver can utilize debugging capabilities and supported features as exposed by the Power Management Controller.
Please refer to the below specification for more details on PMC features.
http://www.intel.in/content/www/in/en/chipsets/100-series-chipset-datasheet-vol-2.html
The current version of this driver exposes slp_s0_residency counter. This counter can be used for detecting fragile SLP_S0 signal related failures and take corrective actions when PCH SLP_S0 signal is not asserted after kernel freeze as part of suspend to idle flow (echo freeze > /sys/power/state).
Intel Platform Controller Hub (PCH) asserts SLP_S0 signal when it detects favorable conditions to enter its low power mode. As a pre-requisite the SOC should be in deepest possible Package C-State and devices should be in low power mode. For example, on Skylake SOC the deepest Package C-State is Package C10 or PC10. Suspend to idle flow generally leads to PC10 state but PC10 state may not be sufficient for realizing the platform wide power potential which SLP_S0 signal assertion can provide.
SLP_S0 signal is often connected to the Embedded Controller (EC) and the Power Management IC (PMIC) for other platform power management related optimizations.
In general, SLP_S0 assertion == PC10 + PCH low power mode + ModPhy Lanes power gated + PLL Idle.
As part of this driver, a mechanism to read the slp_s0 residency is exposed as an api and also debugfs features are added to indicate slp_s0 signal assertion residency in microseconds.
echo freeze > /sys/power/state
wake the system
cat /sys/kernel/debug/pmc_core/slp_s0_residency_usec
---
Changes in v4:
* Moved the header file to drivers/platform/x86 directory.
* Updated the same in MAINTAINERS.
* Removed 'default y' option from Kconfig.
* Introduced static inline dummy functions for debugfs register and unregister case when CONFIG_DEBUG_FS is not set. Removed #if IS_ENABLED(CONFIG_DEBUG_FS) check from .probe and .remove calls.
* Add CC to LKML ([email protected])
* Earlier review comments till v3 are available at:
- http://www.spinics.net/lists/platform-driver-x86/msg08790.html
- http://www.spinics.net/lists/platform-driver-x86/msg08759.html
- http://www.spinics.net/lists/platform-driver-x86/msg08742.html
Changes in v3:
* Updated the commit message, added reference to the chipset datasheet.
* Renamed the header file to intel_pmc_core.h for consistency.
* Added All rights reserved notification after the Copyright message.
* Improved variable names in the header file. Added SPT prefix.
* Fixed kernel-doc related whitespace and comma issues for struct pmc_dev.
* Changed feature_available to bool has_slp_s0_res.
* Enhanced the Kconfig description as per the review suggestions.
* Added error propagating logic to pmc_core_dev_state_show.
* Streamlined intel_pmc_slp_s0_counter_read as per the review comments.
* Streamlined the use of #if IS_ENABLED(CONFIG_DEBUG_FS) while registering debugfs in the probe call.
* Removed the *duplicate definition* of pmc_core_debugfs_register.
* Added MAINTAINERS related changes.
* Checkpatch warning due to long URL name in the commit message.
Changes in v2:
* Fixed inconsistent spaces in the header file.
* Updated commit message.
* Enhanced acronym SKL CPU to Skylake CPUID Signature.
* Put error check on pci_read_config_dword in probe function.
* Changed goto label (disable) to disable_pci.
* Changed x86_match_cpu error handling for consistency.
MAINTAINERS | 8 ++ drivers/platform/x86/Kconfig | 12 ++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_pmc_core.c | 201 ++++++++++++++++++++++++++++++++++ drivers/platform/x86/intel_pmc_core.h | 54 +++++++++ 5 files changed, 276 insertions(+) create mode 100644 drivers/platform/x86/intel_pmc_core.c create mode 100644 drivers/platform/x86/intel_pmc_core.h
MAINTAINERS +8 -0
@@ -5879,6 +5879,14 @@ S: Maintained F: arch/x86/include/asm/intel_telemetry.h F: drivers/platform/x86/intel_telemetry* +INTEL PMC CORE DRIVER +M: Rajneesh Bhardwaj <[email protected]> +M: Vishwanath Somayaji <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/intel_pmc_core.h +F: drivers/platform/x86/intel_pmc_core.c + IOC3 ETHERNET DRIVER M: Ralf Baechle <[email protected]> L: [email protected]
drivers/platform/x86/Kconfig +12 -0
@@ -821,6 +821,18 @@ config INTEL_IPS functionality. If in doubt, say Y here; it will only load on supported platforms. +config INTEL_PMC_CORE + bool "Intel PMC Core driver" + depends on X86 && PCI + ---help--- + The Intel Platform Controller Hub for Intel Core SoCs provides access + to Power Management Controller registers via a pci interface. This + driver can utilize debugging capabilities and supported features as + exposed by the Power Management Controller. + + Supported features: + - slp_s0_residency counter. + config INTEL_IMR bool "Intel Isolated Memory Region support" default n
drivers/platform/x86/Makefile +1 -0
@@ -69,3 +69,4 @@ obj-$(CONFIG_INTEL_PUNIT_IPC) += intel_punit_ipc.o obj-$(CONFIG_INTEL_TELEMETRY) += intel_telemetry_core.o \ intel_telemetry_pltdrv.o \ intel_telemetry_debugfs.o +obj-$(CONFIG_INTEL_PMC_CORE) += intel_pmc_core.o
drivers/platform/x86/intel_pmc_core.c new file +201 -0
201 lines not on this page · raw message
drivers/platform/x86/intel_pmc_core.h new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
1.9.1
On Thu, May 12, 2016 at 4:50 PM, Rajneesh Bhardwaj <[email protected]> wrote:
Sorry for a bit late review, but I think there are still issues need to be addressed.
Quoted 2 lines
This patch adds the Power Management Controller driver as a pci driver for Intel Core SOC architecture.
SOC -> SoC
Quoted 13 lines
This driver can utilize debugging capabilities and supported features as exposed by the Power Management Controller.
Please refer to the below specification for more details on PMC features.
http://www.intel.in/content/www/in/en/chipsets/100-series-chipset-datasheet-vol-2.htmlThe current version of this driver exposes
slp_s0_residencycounter. This counter can be used for detecting fragileSLP_S0signal related failures and take corrective actions when PCHSLP_S0signal is not asserted after kernel freeze as part of suspend to idle flow (echo freeze >/sys/power/state).
Quoted 4 lines
Intel Platform Controller Hub (PCH) asserts
SLP_S0signal when it detects favorable conditions to enter its low power mode. As a pre-requisite the SOC should be in deepest possible Package C-State and devices should be in low power mode. For example, on Skylake SOC
Ditto.
Check entire code for this.
Quoted 9 lines
the deepest Package C-State is Package C10 or PC10. Suspend to idle flow generally leads to PC10 state but PC10 state may not be sufficient for realizing the platform wide power potential which
SLP_S0signal assertion can provide.
SLP_S0signal is often connected to the Embedded Controller (EC) and the Power Management IC (PMIC) for other platform power management related optimizations.
Quoted 5 lines
In general,
SLP_S0assertion == PC10 + PCH low power mode + ModPhy Lanes power gated + PLL Idle.As part of this driver, a mechanism to read the
slp_s0residency is exposed as an api and also debugfs features are added to indicateslp_s0signal
api -> API
Quoted 8 lines
assertion residency in microseconds.
echo freeze >
/sys/power/state
wake the system
cat/sys/kernel/debug/pmc_core/slp_s0_residency_usecSigned-off-by Rajneesh Bhardwaj <[email protected]>Signed-off-by Vishwanath Somayaji <[email protected]>
Two people (1).
MAINTAINERS S: Maintained · line 5888
Quoted 7 lines
MAINTAINERS +7
-0+INTEL PMC CORE DRIVER +M: Rajneesh Bhardwaj <[email protected]> +M: Vishwanath Somayaji <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/intel_pmc_core.h +F: drivers/platform/x86/intel_pmc_core.c
So, we have arch/x86/platform/atom/pmc_atom.c
This driver looks very similar (by what functional is), so, we have to become clear what our layout is.
Either we go with drivers/platform/x86 or with arch/x86/platform.
drivers/platform/x86/Kconfig config INTEL_IPS · line 824
Quoted 7 lines
drivers/platform/x86/Kconfig +1
-0@@ -821,6 +821,18 @@ config INTEL_IPS functionality. If in doubt, say Y here; it will only load on supported platforms. +config INTEL_PMC_CORE
Better to locate this in alphabetical order.
Quoted 30 lines
drivers/platform/x86/Kconfig +11
-0+ bool "Intel PMC Core driver" + depends on X86 && PCI + ---help--- + The Intel Platform Controller Hub for Intel Core SoCs provides access + to Power Management Controller registers via a pci interface. This + driver can utilize debugging capabilities and supported features as + exposed by the Power Management Controller. + + Supported features: + - slp_s0_residency counter. + config INTEL_IMR bool "Intel Isolated Memory Region support"default n
drivers/platform/x86/Makefile +1
-0@@ -69,3 +69,4 @@ obj-$(CONFIG_INTEL_PUNIT_IPC) += intel_punit_ipc.o obj-$(CONFIG_INTEL_TELEMETRY) += intel_telemetry_core.o \ intel_telemetry_pltdrv.o \ intel_telemetry_debugfs.o +obj-$(CONFIG_INTEL_PMC_CORE) += intel_pmc_core.odrivers/platform/x86/intel_pmc_core.c new file +0
-0
drivers/platform/x86/intel_pmc_core.c line 6
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c new file +6
-0@@ -0,0 +1,201 @@ +/* +* Intel Core SOC Power Management Controller Driver +* +* Copyright (c) 2016, Intel Corporation. +* All Rights Reserved. +* Author: Rajneesh Bhardwaj ([email protected])
(2)
In (1) you put two people, here is one. Please, explain who is the author and why SoB is not in align with Author(s).
Quoted 11 lines
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ */
drivers/platform/x86/intel_pmc_core.c line 25
Quoted 8 lines
drivers/platform/x86/intel_pmc_core.c new file +8
-0+ +#include <linux/init.h> +#include <linux/pci.h> +#include <linux/device.h> +#include <linux/debugfs.h> +#include <linux/seq_file.h> +#include <linux/module.h> +#include <linux/io.h>
Alphabetical order.
+ empty line
Quoted 1 line
+#include <
asm/cpu_device_id.h>
+ empty line
drivers/platform/x86/intel_pmc_core.c line 32
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c new file +6
-0+#include "intel_pmc_core.h" + +static struct pmc_dev pmc; + +static const struct pci_device_id pmc_pci_ids[] = { + {PCI_VDEVICE (INTEL ,SPT_PMC_PCI_DEVICE_ID ), (kernel_ulong_t )NULL },
No need to have an explicit NULL
drivers/platform/x86/intel_pmc_core.c line 42
Quoted 10 lines
drivers/platform/x86/intel_pmc_core.c new file +10
-0+ { 0, }, +}; +MODULE_DEVICE_TABLE (pci, pmc_pci_ids); + +/** +* intel_pmc_slp_s0_counter_read() - Read slp_s0 residency. +* @data: Out param that contains current slp_s0 count. +* +* This API currently supports Intel Skylake SOC and Sunrise +* point Platform Controller Hub. Future platform support
Either Sunrisepoint or Sunrise Point.
SOC -> SoC
Quoted 6 lines
+ * should be added for platforms that support low power modes
+ * beyond Package C10 state.
+ *
+ *SLP_S0_RESIDENCYcounter counts in 100 us granularity per
+ * step hence function populates the multiplied value in out
+ * parameter @data
+ dot at the end of sentence.
drivers/platform/x86/intel_pmc_core.c
Quoted 5 lines
+ *
+ * Return: an error code or 0 on success.
+ */drivers/platform/x86/intel_pmc_core.c new file +2
-0+int intel_pmc_slp_s0_counter_read (u64 *data) +{
struct pmc_dev *pmcdev = &pmc;
Quoted 1 line
+ if (!pmc.has_slp_s0_res)
'pmc.' -> 'pmcdev->'
drivers/platform/x86/intel_pmc_core.c line 57
Quoted 3 lines
drivers/platform/x86/intel_pmc_core.c new file +3
-0+return -EACCES ; + + *data =readl (pmc.regmap +SPT_PMC_SLP_S0_RES_COUNTER_OFFSET );
Ditto.
Quoted 1 line
+ *data *=
SPT_PMC_SLP_S0_RES_COUNTER_STEP;
Use temporary variable.
u64 value;
value = readl();
value *= ;
*data = value;
This makes only one place where you assign returning value.
drivers/platform/x86/intel_pmc_core.c line 62
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+ +return 0 ; +} +EXPORT_SYMBOL_GPL (intel_pmc_slp_s0_counter_read);
Who is going to be a user of that?
drivers/platform/x86/intel_pmc_core.c line 66
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+ +#if IS_ENABLED (CONFIG_DEBUG_FS ) +static int pmc_core_dev_state_show (struct seq_file *s,void *unused) +{
Pointer to pmc, i.e. pmc_dev *, would be supplied in seq_file. Take it from there...
Quoted 1 line
+ u64
counter_val;
u64 value;
drivers/platform/x86/intel_pmc_core.c line 70
Quoted 3 lines
drivers/platform/x86/intel_pmc_core.c new file +3
-0+int err; + + err =intel_pmc_slp_s0_counter_read (&counter_val);
...thus split your function to internal, which takes pmc_dev * as a first parameter and use exported variant for users which takes global variable.
int intel_pmc_slp_s0_counter_read(u64 *data)
{
struct pmc_dev *pmcdev = &pmc;
return do_counter_read(pmcdev, data);
}
drivers/platform/x86/intel_pmc_core.c line 72
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+if (!err) +seq_printf (s,"%lld\n" , counter_val);
Please, use positive check
if (err)
return err;
Quoted 11 lines
drivers/platform/x86/intel_pmc_core.c new file +11
-0+ +return err; +} + +static int pmc_core_dev_state_open (struct inode *inode,struct file *file) +{ +return single_open (file, pmc_core_dev_state_show, inode->i_private); +} + +static const struct file_operations pmc_core_dev_state_ops = { + .open = pmc_core_dev_state_open,
drivers/platform/x86/intel_pmc_core.c line 92
Quoted 10 lines
drivers/platform/x86/intel_pmc_core.c new file +9
-0+ .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static void pmc_core_dbgfs_unregister (struct pmc_dev *pmc) +{ +debugfs_remove_recursive (pmc->dbgfs_dir); +}
No need to keep this under #ifdef.
drivers/platform/x86/intel_pmc_core.c line 97
Quoted 6 lines
drivers/platform/x86/intel_pmc_core.c new file +5
-0+ +static int pmc_core_dbgfs_register (struct pmc_dev *pmc) +{ +struct dentry *dir, *file; +int ret =0 ;
Redundant, see below.
drivers/platform/x86/intel_pmc_core.c line 109
Quoted 12 lines
drivers/platform/x86/intel_pmc_core.c new file +12
-0+ + dir =debugfs_create_dir ("pmc_core" ,NULL ); +if (!dir) +return -ENOMEM ; + + pmc->dbgfs_dir = dir; + file =debugfs_create_file ("slp_s0_residency_usec" ,S_IFREG |S_IRUGO , + dir, pmc, &pmc_core_dev_state_ops); + +if (!file) { +pmc_core_dbgfs_unregister (pmc); + ret = -ENODEV ;
return -ENODEV;
drivers/platform/x86/intel_pmc_core.c line 111
Quoted 3 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+ } +return ret;
return 0;
drivers/platform/x86/intel_pmc_core.c line 122
Quoted 12 lines
drivers/platform/x86/intel_pmc_core.c new file +11
-0+} +#else +static inline int pmc_core_dbgfs_register (struct pmc_dev *pmc) +{ +return 0 ;/* nothing to register */ +} + +static inline void pmc_core_dbgfs_unregister (struct pmc_dev *pmc) +{ +/* nothing to deregister */ +}
Redundant.
drivers/platform/x86/intel_pmc_core.c line 127
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c new file +5
-0+#endif /* CONFIG_DEBUG_FS */ + +static const struct x86_cpu_id intel_pmc_core_ids[] = { + {X86_VENDOR_INTEL ,6 ,0x4e ,X86_FEATURE_MWAIT , + (kernel_ulong_t )NULL },/* Skylake CPUID Signature */
No explicit NULL.
drivers/platform/x86/intel_pmc_core.c line 129
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+ {X86_VENDOR_INTEL ,6 ,0x5e ,X86_FEATURE_MWAIT , + (kernel_ulong_t)NULL}, /* Skylake CPUID Signature */
Ditto.
drivers/platform/x86/intel_pmc_core.c line 137
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c new file +8
-0+ {} +}; +MODULE_DEVICE_TABLE (x86cpu, intel_pmc_core_ids); + +static int pmc_core_probe (struct pci_dev *dev,const struct pci_device_id *id) +{ +int err; +const struct x86_cpu_id *cpu_id;
Swap them.
+ const struct x86_cpu_id *cpu_id;
+ int err;
struct pmc_dev *pmcdev = &pmc;
drivers/platform/x86/intel_pmc_core.c line 145
Quoted 8 lines
drivers/platform/x86/intel_pmc_core.c new file +8
-0+ + cpu_id =x86_match_cpu (intel_pmc_core_ids); +if (!cpu_id) { + err = -EINVAL ; + goto exit; + } + + err =pci_enable_device (dev);
pcim_enable_device();
drivers/platform/x86/intel_pmc_core.c line 147
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+if (err) { +dev_err (&dev->dev,"PMC Core: failed to enable Power Management Controller.\n" );
I doubt this message is useful anyhow.
drivers/platform/x86/intel_pmc_core.c line 153
Quoted 6 lines
drivers/platform/x86/intel_pmc_core.c new file +6
-0+ goto exit; + } + + err =pci_read_config_dword (dev, +SPT_PMC_BASE_ADDR_OFFSET , + &pmc.base_addr);
'pmc.' -> 'pmcdev->'
drivers/platform/x86/intel_pmc_core.c line 157
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+if (err) { +dev_err (&dev->dev,"PMC Core: failed to read pci config space.\n" ); + goto disable_pci; + }
So, and this is not available through BARs?
Quoted 1 line
+
dev_dbg(&dev->dev, "PMC Core: PWRMBASE is 0x%x\n", pmc.base_addr);
%#x will prefix the number.
drivers/platform/x86/intel_pmc_core.c line 162
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+ + pmc.regmap =ioremap_nocache (pmc.base_addr,SPT_PMC_MMIO_REG_LEN ); +if (!pmc.regmap) { +dev_err (&dev->dev,"PMC Core: ioremap failed\n" );
Useful?
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c new file +9
-0+ err = -ENOMEM ; + goto disable_pci; + } + + err =pmc_core_dbgfs_register (&pmc); +if (err) { +dev_err (&dev->dev,"PMC Core: debugfs register failed\n" ); +iounmap (pmc.regmap); + goto disable_pci;
drivers/platform/x86/intel_pmc_core.c line 178
Quoted 10 lines
drivers/platform/x86/intel_pmc_core.c new file +7
-0+ } + + pmc.has_slp_s0_res = true; +return 0 ; + +disable_pci: +pci_disable_device (dev);
Remove after using pcim_*().
Quoted 1 line
+exit:
Redundant. Use return directly.
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c new file +9
-0+return err; +} + +static void intel_pmc_core_remove (struct pci_dev *pdev) +{ +pmc_core_dbgfs_unregister (&pmc); +pci_disable_device (pdev); +iounmap (pmc.regmap); +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
On Thu, May 12, 2016 at 4:50 PM, Rajneesh Bhardwaj <[email protected]> wrote:
Sorry for a bit late review, but I think there are still issues need to be addressed.
Thanks for the detailed review and the feedback. :)
Quoted 5 lines
Quoted 2 lines
This patch adds the Power Management Controller driver as a pci driver for Intel Core SOC architecture.
SOC -> SoC
Sure, will fix this throughout the code.
Quoted 13 lines
Quoted 13 lines
This driver can utilize debugging capabilities and supported features as exposed by the Power Management Controller.
Please refer to the below specification for more details on PMC features.
http://www.intel.in/content/www/in/en/chipsets/100-series-chipset-datasheet-vol-2.htmlThe current version of this driver exposes
slp_s0_residencycounter. This counter can be used for detecting fragileSLP_S0signal related failures and take corrective actions when PCHSLP_S0signal is not asserted after kernel freeze as part of suspend to idle flow (echo freeze >/sys/power/state).
Quoted 8 lines
Quoted 4 lines
Intel Platform Controller Hub (PCH) asserts
SLP_S0signal when it detects favorable conditions to enter its low power mode. As a pre-requisite the SOC should be in deepest possible Package C-State and devices should be in low power mode. For example, on Skylake SOCDitto.
Check entire code for this.
Same as above.
Quoted 9 lines
Quoted 9 lines
the deepest Package C-State is Package C10 or PC10. Suspend to idle flow generally leads to PC10 state but PC10 state may not be sufficient for realizing the platform wide power potential which
SLP_S0signal assertion can provide.
SLP_S0signal is often connected to the Embedded Controller (EC) and the Power Management IC (PMIC) for other platform power management related optimizations.
Quoted 8 lines
Quoted 5 lines
In general,
SLP_S0assertion == PC10 + PCH low power mode + ModPhy Lanes power gated + PLL Idle.As part of this driver, a mechanism to read the
slp_s0residency is exposed as an api and also debugfs features are added to indicateslp_s0signalapi -> API
Sure, will take care of this change.
Quoted 12 lines
Quoted 8 lines
assertion residency in microseconds.
echo freeze >
/sys/power/state
wake the system
cat/sys/kernel/debug/pmc_core/slp_s0_residency_usecSigned-off-by Rajneesh Bhardwaj <[email protected]>Signed-off-by Vishwanath Somayaji <[email protected]>Two people (1).
Ok.
Quoted 10 lines
MAINTAINERS S: Maintained · line 5888
Quoted 7 lines
MAINTAINERS +7
-0+INTEL PMC CORE DRIVER +M: Rajneesh Bhardwaj <[email protected]> +M: Vishwanath Somayaji <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/intel_pmc_core.h +F: drivers/platform/x86/intel_pmc_core.cSo, we have
arch/x86/platform/atom/pmc_atom.c
Quoted 4 lines
This driver looks very similar (by what functional is), so, we have to become clear what our layout is.
Either we go withdrivers/platform/x86or witharch/x86/platform.
IMHO, the functianality provided by this driver is platform specific and not architecture specific.
There are few similar drivers present in this location already i.e. intel_telemetry_core.c, intel_pmc_ipc.c etc.
We had initially put this driver along with pmc_atom.c but later we thought that driver/platform/x86 would be a more apt place for it because of the above mentioned reasons.
Please advise for the right location for this driver if its not placed in the expected location.
Quoted 10 lines
drivers/platform/x86/Kconfig config INTEL_IPS · line 824
Quoted 7 lines
drivers/platform/x86/Kconfig +1
-0@@ -821,6 +821,18 @@ config INTEL_IPS functionality. If in doubt, say Y here; it will only load on supported platforms. +config INTEL_PMC_COREBetter to locate this in alphabetical order.
Agreed, i tried to put it in alphabetical order but there are quite a few entries in Kconfig that are skewed e.g. INTEL_MFLD is placed above INTEL_IPS.
Placing INTEL_PMC_CORE after INTEL_IMR would be ok?
Quoted 36 lines
Quoted 35 lines
drivers/platform/x86/Kconfig +11
-0+ bool "Intel PMC Core driver" + depends on X86 && PCI + ---help--- + The Intel Platform Controller Hub for Intel Core SoCs provides access + to Power Management Controller registers via a pci interface. This + driver can utilize debugging capabilities and supported features as + exposed by the Power Management Controller. + + Supported features: + - slp_s0_residency counter. + config INTEL_IMR bool "Intel Isolated Memory Region support"default n
drivers/platform/x86/Makefile +1
-0@@ -69,3 +69,4 @@ obj-$(CONFIG_INTEL_PUNIT_IPC) += intel_punit_ipc.o obj-$(CONFIG_INTEL_TELEMETRY) += intel_telemetry_core.o \ intel_telemetry_pltdrv.o \ intel_telemetry_debugfs.o +obj-$(CONFIG_INTEL_PMC_CORE) += intel_pmc_core.odrivers/platform/x86/intel_pmc_core.c new file +5
-0@@ -0,0 +1,201 @@ +/* +* Intel Core SOC Power Management Controller Driver +* +* Copyright (c) 2016, Intel Corporation. +* All Rights Reserved.
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c line 6
Quoted 1 line
drivers/platform/x86/intel_pmc_core.c new file +1
-0+* Author: Rajneesh Bhardwaj ([email protected]) (2)
In (1) you put two people, here is one. Please, explain who is the author and why SoB is not in align with Author(s).
Its a miss from our end, will update the Author tag. Thanks for pointing it out.
Quoted 22 lines
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c new file +9
-0+* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. drivers/platform/x86/intel_pmc_core.c line 25
Quoted 10 lines
drivers/platform/x86/intel_pmc_core.c new file +10
-0+* +*/ + +#include <linux/init.h> +#include <linux/pci.h> +#include <linux/device.h> +#include <linux/debugfs.h> +#include <linux/seq_file.h> +#include <linux/module.h> +#include <linux/io.h> Alphabetical order.
Quoted 9 lines
+ empty line
drivers/platform/x86/intel_pmc_core.c line 26
Quoted 1 line
drivers/platform/x86/intel_pmc_core.c new file +1
-0+#include <asm/cpu_device_id.h> + empty line
drivers/platform/x86/intel_pmc_core.c line 28
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+#include "intel_pmc_core.h" +
Ok for above.
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c line 32
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+static struct pmc_dev pmc; + +static const struct pci_device_id pmc_pci_ids[] = { + {PCI_VDEVICE (INTEL ,SPT_PMC_PCI_DEVICE_ID ), (kernel_ulong_t )NULL },No need to have an explicit NULL
There is a precedent in the kernel for such usage and in previous reviews we agreed to stick to this format. I hope thats fine?
Quoted 5 lines
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c new file +5
-0+ { 0, }, +}; +MODULE_DEVICE_TABLE (pci, pmc_pci_ids); + +/**
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c line 42
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c new file +5
-0+* intel_pmc_slp_s0_counter_read() - Read slp_s0 residency. +* @data: Out param that contains current slp_s0 count. +* +* This API currently supports Intel Skylake SOC and Sunrise +* point Platform Controller Hub. Future platform support Either Sunrisepoint or Sunrise Point.
SOC -> SoC
Sure.
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c line 48
Quoted 6 lines
drivers/platform/x86/intel_pmc_core.c new file +6
-0+* should be added for platforms that support low power modes +* beyond Package C10 state. +* +* SLP_S0_RESIDENCY counter counts in 100 us granularity per +* step hence function populates the multiplied value in out +* parameter @data + dot at the end of sentence.
Ok.
Quoted 23 lines
drivers/platform/x86/intel_pmc_core.c line 53
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c new file +5
-0+* +* Return: an error code or 0 on success. +*/ +int intel_pmc_slp_s0_counter_read (u64 *data) +{struct
pmc_dev*pmcdev = &pmc;drivers/platform/x86/intel_pmc_core.c line 54
Quoted 1 line
drivers/platform/x86/intel_pmc_core.c new file +1
-0+if (!pmc.has_slp_s0_res)'pmc.' -> 'pmcdev->'
drivers/platform/x86/intel_pmc_core.c line 57
Quoted 3 lines
drivers/platform/x86/intel_pmc_core.c new file +3
-0+return -EACCES ; + + *data =readl (pmc.regmap +SPT_PMC_SLP_S0_RES_COUNTER_OFFSET );Ditto.
drivers/platform/x86/intel_pmc_core.c line 58
Quoted 1 line
drivers/platform/x86/intel_pmc_core.c new file +1
-0+ *data *=SPT_PMC_SLP_S0_RES_COUNTER_STEP ;Use temporary variable.
Quoted 9 lines
u64 value;
value =
readl();
value *= ;*data = value;
This makes only one place where you assign returning value.
Ok, will rework on the function and split it into two. One for performing read operation and callable from within the module and the other one to be called from outside.
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c line 62
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+ +return 0 ; +} +EXPORT_SYMBOL_GPL (intel_pmc_slp_s0_counter_read);Who is going to be a user of that?
This is expected to be used by a framework (upcoming) for detecting slp_s0 signal assertion related failures.
Quoted 23 lines
drivers/platform/x86/intel_pmc_core.c line 66
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+ +#if IS_ENABLED (CONFIG_DEBUG_FS ) +static int pmc_core_dev_state_show (struct seq_file *s,void *unused) +{Pointer to pmc, i.e.
pmc_dev*, would be supplied inseq_file. Take it from there...Quoted 1 line
+ u64
counter_val;u64 value;
drivers/platform/x86/intel_pmc_core.c line 70
Quoted 3 lines
drivers/platform/x86/intel_pmc_core.c new file +3
-0+int err; + + err =intel_pmc_slp_s0_counter_read (&counter_val);...thus split your function to internal, which takes
pmc_dev* as a first parameter and use exported variant for users which takes global variable.
Quoted 8 lines
int
intel_pmc_slp_s0_counter_read(u64 *data)
{
structpmc_dev*pmcdev = &pmc;return
do_counter_read(pmcdev, data);
}
As explained above, will rework on the function split logic and accomodate these suggestions.
Quoted 8 lines
drivers/platform/x86/intel_pmc_core.c line 72
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+if (!err) +seq_printf (s,"%lld\n" , counter_val);Please, use positive check
if (err)
return err;
Ok, any benefit? readability?
Quoted 17 lines
Quoted 16 lines
drivers/platform/x86/intel_pmc_core.c new file +16
-0+ +return err; +} + +static int pmc_core_dev_state_open (struct inode *inode,struct file *file) +{ +return single_open (file, pmc_core_dev_state_show, inode->i_private); +} + +static const struct file_operations pmc_core_dev_state_ops = { + .open = pmc_core_dev_state_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c line 92
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+static void pmc_core_dbgfs_unregister (struct pmc_dev *pmc) +{ +debugfs_remove_recursive (pmc->dbgfs_dir); +}No need to keep this under #ifdef.
Based on some previus review comments we decided to put the dummy functions for !CONIG_DEBUG_FS case. Can you please elaborate more on this change request?
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c line 97
Quoted 6 lines
drivers/platform/x86/intel_pmc_core.c new file +5
-0+ +static int pmc_core_dbgfs_register (struct pmc_dev *pmc) +{ +struct dentry *dir, *file; +int ret =0 ;Redundant, see below.
Quoted 15 lines
drivers/platform/x86/intel_pmc_core.c line 109
Quoted 12 lines
drivers/platform/x86/intel_pmc_core.c new file +12
-0+ + dir =debugfs_create_dir ("pmc_core" ,NULL ); +if (!dir) +return -ENOMEM ; + + pmc->dbgfs_dir = dir; + file =debugfs_create_file ("slp_s0_residency_usec" ,S_IFREG |S_IRUGO , + dir, pmc, &pmc_core_dev_state_ops); + +if (!file) { +pmc_core_dbgfs_unregister (pmc); + ret = -ENODEV ;return
-ENODEV;
Ok.
Quoted 14 lines
drivers/platform/x86/intel_pmc_core.c line 111
Quoted 3 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+ } +return ret;return 0;
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c new file +7
-0+} +#else +static inline int pmc_core_dbgfs_register (struct pmc_dev *pmc) +{ +return 0 ;/* nothing to register */ +} +
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c line 122
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+static inline void pmc_core_dbgfs_unregister (struct pmc_dev *pmc) +{ +/* nothing to deregister */ +}Redundant.
Same as above.
Quoted 8 lines
drivers/platform/x86/intel_pmc_core.c line 127
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c new file +5
-0+#endif /* CONFIG_DEBUG_FS */ + +static const struct x86_cpu_id intel_pmc_core_ids[] = { + {X86_VENDOR_INTEL ,6 ,0x4e ,X86_FEATURE_MWAIT , + (kernel_ulong_t )NULL },/* Skylake CPUID Signature */ No explicit NULL.
Same as explained above.
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c line 129
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+ {X86_VENDOR_INTEL ,6 ,0x5e ,X86_FEATURE_MWAIT , + (kernel_ulong_t)NULL}, /* Skylake CPUID Signature */Ditto.
Same as explained above.
Quoted 10 lines
drivers/platform/x86/intel_pmc_core.c line 137
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c new file +8
-0+ {} +}; +MODULE_DEVICE_TABLE (x86cpu, intel_pmc_core_ids); + +static int pmc_core_probe (struct pci_dev *dev,const struct pci_device_id *id) +{ +int err; +const struct x86_cpu_id *cpu_id;
Quoted 7 lines
Swap them.
+ const struct
x86_cpu_id*cpu_id;
+ int err;struct
pmc_dev*pmcdev = &pmc;
Ok.
Quoted 11 lines
drivers/platform/x86/intel_pmc_core.c line 145
Quoted 8 lines
drivers/platform/x86/intel_pmc_core.c new file +8
-0+ + cpu_id =x86_match_cpu (intel_pmc_core_ids); +if (!cpu_id) { + err = -EINVAL ; + goto exit; + } + + err =pci_enable_device (dev);
pcim_enable_device();
Thanks for this suggestion.
Quoted 19 lines
drivers/platform/x86/intel_pmc_core.c line 147
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+if (err) { +dev_err (&dev->dev,"PMC Core: failed to enable Power Management Controller.\n" );I doubt this message is useful anyhow.
drivers/platform/x86/intel_pmc_core.c line 153
Quoted 6 lines
drivers/platform/x86/intel_pmc_core.c new file +6
-0+ goto exit; + } + + err =pci_read_config_dword (dev, +SPT_PMC_BASE_ADDR_OFFSET , + &pmc.base_addr);'pmc.' -> 'pmcdev->'
drivers/platform/x86/intel_pmc_core.c line 157
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+if (err) { +dev_err (&dev->dev,"PMC Core: failed to read pci config space.\n" ); + goto disable_pci; + }
Quoted 7 lines
So, and this is not available through BARs?
Quoted 1 line
+
dev_dbg(&dev->dev, "PMC Core: PWRMBASE is 0x%x\n", pmc.base_addr);%#x will prefix the number.
Quoted 1 line
+
Ok.
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c line 162
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +3
-0+ pmc.regmap =ioremap_nocache (pmc.base_addr,SPT_PMC_MMIO_REG_LEN ); +if (!pmc.regmap) { +dev_err (&dev->dev,"PMC Core: ioremap failed\n" );Useful?
Want to keep it for debug purpose.
Do you recommend devm_ioremap_nocache as well?
Quoted 14 lines
Quoted 12 lines
drivers/platform/x86/intel_pmc_core.c new file +12
-0+ err = -ENOMEM ; + goto disable_pci; + } + + err =pmc_core_dbgfs_register (&pmc); +if (err) { +dev_err (&dev->dev,"PMC Core: debugfs register failed\n" ); +iounmap (pmc.regmap); + goto disable_pci;Do you recommend devm_ioremap_nocache as well? + } + + pmc.has_slp_s0_res = true;
Quoted 8 lines
drivers/platform/x86/intel_pmc_core.c line 178
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+return 0 ; + +disable_pci: +pci_disable_device (dev);Remove after using pcim_*().
Ok.
Quoted 4 lines
Quoted 1 line
+exit:
Redundant. Use return directly.
Ok.
Quoted 14 lines
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c new file +9
-0+return err; +} + +static void intel_pmc_core_remove (struct pci_dev *pdev) +{ +pmc_core_dbgfs_unregister (&pmc); +pci_disable_device (pdev); +iounmap (pmc.regmap); +}Signature · 2 lines
With Best Regards, Andy Shevchenko
Signature · 2 lines
Best Regards, Rajneesh
Quoted 98 lines · Rajneesh Bhardwaj
Quoted 6 lines · Andy Shevchenko
On Thu, May 12, 2016 at 4:50 PM, Rajneesh Bhardwaj <[email protected]> wrote:
Sorry for a bit late review, but I think there are still issues need to be addressed.
Thanks for the detailed review and the feedback. :)
Quoted 5 lines
Quoted 2 lines
This patch adds the Power Management Controller driver as a pci driver for Intel Core SOC architecture.
SOC -> SoC
Sure, will fix this throughout the code.
Quoted 13 lines
Quoted 13 lines
This driver can utilize debugging capabilities and supported features as exposed by the Power Management Controller.
Please refer to the below specification for more details on PMC features.
http://www.intel.in/content/www/in/en/chipsets/100-series-chipset-datasheet-vol-2.htmlThe current version of this driver exposes
slp_s0_residencycounter. This counter can be used for detecting fragileSLP_S0signal related failures and take corrective actions when PCHSLP_S0signal is not asserted after kernel freeze as part of suspend to idle flow (echo freeze >/sys/power/state).Quoted 8 lines
Quoted 4 lines
Intel Platform Controller Hub (PCH) asserts
SLP_S0signal when it detects favorable conditions to enter its low power mode. As a pre-requisite the SOC should be in deepest possible Package C-State and devices should be in low power mode. For example, on Skylake SOCDitto.
Check entire code for this.Same as above.
Quoted 9 lines
Quoted 9 lines
the deepest Package C-State is Package C10 or PC10. Suspend to idle flow generally leads to PC10 state but PC10 state may not be sufficient for realizing the platform wide power potential which
SLP_S0signal assertion can provide.
SLP_S0signal is often connected to the Embedded Controller (EC) and the Power Management IC (PMIC) for other platform power management related optimizations.Quoted 8 lines
Quoted 5 lines
In general,
SLP_S0assertion == PC10 + PCH low power mode + ModPhy Lanes power gated + PLL Idle.As part of this driver, a mechanism to read the
slp_s0residency is exposed as an api and also debugfs features are added to indicateslp_s0signalapi -> API
Sure, will take care of this change.
Quoted 12 lines
Quoted 8 lines
assertion residency in microseconds.
echo freeze >
/sys/power/state
wake the system
cat/sys/kernel/debug/pmc_core/slp_s0_residency_usecSigned-off-by Rajneesh Bhardwaj <[email protected]>Signed-off-by Vishwanath Somayaji <[email protected]>Two people (1).
Ok.
Quoted 10 lines
MAINTAINERS S: Maintained · line 5888
Quoted 7 lines
MAINTAINERS +7
-0+INTEL PMC CORE DRIVER +M: Rajneesh Bhardwaj <[email protected]> +M: Vishwanath Somayaji <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/intel_pmc_core.h +F: drivers/platform/x86/intel_pmc_core.cSo, we have
arch/x86/platform/atom/pmc_atom.cQuoted 4 lines
This driver looks very similar (by what functional is), so, we have to become clear what our layout is.
Either we go withdrivers/platform/x86or witharch/x86/platform.IMHO, the functianality provided by this driver is platform specific and not architecture specific.
There are few similar drivers present in this location already i.e.
intel_telemetry_core.c,intel_pmc_ipc.cetc.
Quoted 6 lines
We had initially put this driver along with
pmc_atom.cbut later we thought that driver/platform/x86 would be a more apt place for it because of the above mentioned reasons.Please advise for the right location for this driver if its not placed in the expected location.
We're experiencing some repeat discussion due to some of the reviews having taken place off list. Sorry Andy, I've been trying to steer this back to list, so you're missing some context to no fault of your own.
It's possible some of the existing drivers in arch really shouldn't be there. It's not particularly well defined, however, if it isn't used outside the kernel or by other subsystems within the kernel, it seems that drivers/platform/x86 would be the appropriate location.
Thomas, Peter - do you have a criteria for what you prefer to have in arch/x86/platform versus drivers/platform/x86?
Quoted 105 lines
Quoted 11 lines
drivers/platform/x86/Kconfig config INTEL_IPS · line 824
Quoted 8 lines
drivers/platform/x86/Kconfig +1
-0@@ -821,6 +821,18 @@ config INTEL_IPS functionality. If in doubt, say Y here; it will only load on supported platforms. +config INTEL_PMC_COREBetter to locate this in alphabetical order.
Agreed, i tried to put it in alphabetical order but there are quite a few entries in
Kconfigthat are skewed e.g.INTEL_MFLDis placed aboveINTEL_IPS.Placing
INTEL_PMC_COREafterINTEL_IMRwould be ok?Quoted 36 lines
Quoted 35 lines
drivers/platform/x86/Kconfig +11
-0+ bool "Intel PMC Core driver" + depends on X86 && PCI + ---help--- + The Intel Platform Controller Hub for Intel Core SoCs provides access + to Power Management Controller registers via a pci interface. This + driver can utilize debugging capabilities and supported features as + exposed by the Power Management Controller. + + Supported features: + - slp_s0_residency counter. + config INTEL_IMR bool "Intel Isolated Memory Region support"default n
drivers/platform/x86/Makefile +1
-0@@ -69,3 +69,4 @@ obj-$(CONFIG_INTEL_PUNIT_IPC) += intel_punit_ipc.o obj-$(CONFIG_INTEL_TELEMETRY) += intel_telemetry_core.o \ intel_telemetry_pltdrv.o \ intel_telemetry_debugfs.o +obj-$(CONFIG_INTEL_PMC_CORE) += intel_pmc_core.odrivers/platform/x86/intel_pmc_core.c new file +5
-0@@ -0,0 +1,201 @@ +/* +* Intel Core SOC Power Management Controller Driver +* +* Copyright (c) 2016, Intel Corporation. +* All Rights Reserved. Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c line 6
Quoted 1 line
drivers/platform/x86/intel_pmc_core.c new file +1
-0+* Author: Rajneesh Bhardwaj ([email protected]) (2)
In (1) you put two people, here is one. Please, explain who is the author and why SoB is not in align with Author(s).
Its a miss from our end, will update the Author tag. Thanks for pointing it out.
Quoted 22 lines
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c new file +9
-0+* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. drivers/platform/x86/intel_pmc_core.c line 25
Quoted 10 lines
drivers/platform/x86/intel_pmc_core.c new file +10
-0+* +*/ + +#include <linux/init.h> +#include <linux/pci.h> +#include <linux/device.h> +#include <linux/debugfs.h> +#include <linux/seq_file.h> +#include <linux/module.h> +#include <linux/io.h> Alphabetical order.
Quoted 9 lines
+ empty line
drivers/platform/x86/intel_pmc_core.c line 26
Quoted 1 line
drivers/platform/x86/intel_pmc_core.c new file +1
-0+#include <asm/cpu_device_id.h> + empty line
drivers/platform/x86/intel_pmc_core.c line 28
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+#include "intel_pmc_core.h" +Ok for above.
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c line 32
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+static struct pmc_dev pmc; + +static const struct pci_device_id pmc_pci_ids[] = { + {PCI_VDEVICE (INTEL ,SPT_PMC_PCI_DEVICE_ID ), (kernel_ulong_t )NULL },No need to have an explicit NULL
Quoted 2 lines
There is a precedent in the kernel for such usage and in previous reviews we agreed to stick to this format. I hope thats fine?
I'm fine with this, even if redundant, so long as you are consistent throughout the driver. This is consistent with the other drivers in drivers/platform/x86.
Quoted 116 lines
Quoted 15 lines
drivers/platform/x86/intel_pmc_core.c line 42
Quoted 11 lines
drivers/platform/x86/intel_pmc_core.c new file +10
-0+ { 0, }, +}; +MODULE_DEVICE_TABLE (pci, pmc_pci_ids); + +/** +* intel_pmc_slp_s0_counter_read() - Read slp_s0 residency. +* @data: Out param that contains current slp_s0 count. +* +* This API currently supports Intel Skylake SOC and Sunrise +* point Platform Controller Hub. Future platform support Either Sunrisepoint or Sunrise Point.
SOC -> SoCSure.
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c line 48
Quoted 6 lines
drivers/platform/x86/intel_pmc_core.c new file +6
-0+* should be added for platforms that support low power modes +* beyond Package C10 state. +* +* SLP_S0_RESIDENCY counter counts in 100 us granularity per +* step hence function populates the multiplied value in out +* parameter @data + dot at the end of sentence.
Ok.
Quoted 23 lines
drivers/platform/x86/intel_pmc_core.c line 53
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c new file +5
-0+* +* Return: an error code or 0 on success. +*/ +int intel_pmc_slp_s0_counter_read (u64 *data) +{struct
pmc_dev*pmcdev = &pmc;drivers/platform/x86/intel_pmc_core.c line 54
Quoted 1 line
drivers/platform/x86/intel_pmc_core.c new file +1
-0+if (!pmc.has_slp_s0_res)'pmc.' -> 'pmcdev->'
drivers/platform/x86/intel_pmc_core.c line 57
Quoted 3 lines
drivers/platform/x86/intel_pmc_core.c new file +3
-0+return -EACCES ; + + *data =readl (pmc.regmap +SPT_PMC_SLP_S0_RES_COUNTER_OFFSET );Ditto.
drivers/platform/x86/intel_pmc_core.c line 58
Quoted 1 line
drivers/platform/x86/intel_pmc_core.c new file +1
-0+ *data *=SPT_PMC_SLP_S0_RES_COUNTER_STEP ;Use temporary variable.
Quoted 9 lines
u64 value;
value =
readl();
value *= ;*data = value;
This makes only one place where you assign returning value.
Ok, will rework on the function and split it into two. One for performing read operation and callable from within the module and the other one to be called from outside.
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c line 62
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+ +return 0 ; +} +EXPORT_SYMBOL_GPL (intel_pmc_slp_s0_counter_read);Who is going to be a user of that?
This is expected to be used by a framework (upcoming) for detecting
slp_s0signal assertion related failures.Quoted 23 lines
drivers/platform/x86/intel_pmc_core.c line 66
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+ +#if IS_ENABLED (CONFIG_DEBUG_FS ) +static int pmc_core_dev_state_show (struct seq_file *s,void *unused) +{Pointer to pmc, i.e.
pmc_dev*, would be supplied inseq_file. Take it from there...Quoted 1 line
+ u64
counter_val;u64 value;
drivers/platform/x86/intel_pmc_core.c line 70
Quoted 3 lines
drivers/platform/x86/intel_pmc_core.c new file +3
-0+int err; + + err =intel_pmc_slp_s0_counter_read (&counter_val);...thus split your function to internal, which takes
pmc_dev* as a first parameter and use exported variant for users which takes global variable.Quoted 8 lines
int
intel_pmc_slp_s0_counter_read(u64 *data)
{
structpmc_dev*pmcdev = &pmc;return
do_counter_read(pmcdev, data);
}As explained above, will rework on the function split logic and accomodate these suggestions.
Quoted 3 lines
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+if (!err) +seq_printf (s,"%lld\n" , counter_val);
Quoted 7 lines
Quoted 5 lines
Please, use positive check
if (err)
return err;Ok, any benefit? readability?
Readability and consistency, yes. Check for errors rather than success is the more common model within the kernel in my experience.
Quoted 26 lines
Quoted 18 lines
Quoted 17 lines
drivers/platform/x86/intel_pmc_core.c new file +16
-0+ +return err; +} + +static int pmc_core_dev_state_open (struct inode *inode,struct file *file) +{ +return single_open (file, pmc_core_dev_state_show, inode->i_private); +} + +static const struct file_operations pmc_core_dev_state_ops = { + .open = pmc_core_dev_state_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c line 92
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+static void pmc_core_dbgfs_unregister (struct pmc_dev *pmc) +{ +debugfs_remove_recursive (pmc->dbgfs_dir); +}No need to keep this under #ifdef.
Quoted 3 lines
Based on some previus review comments we decided to put the dummy functions for !CONIG_DEBUG_FS case. Can you please elaborate more on this change request?
I think Andy's point is that there is no reason to specialize this function since debugs_remove_recursive checks for null.
The problem of course is that dbgfs_dir only exists if CONFIG_DEBUG_FS exists. I don't know if that's worth ifdeffing out of the struct, but there is precendent for doing it that way, and I didn't feel strongly one way or the other, so I left it up to you.
If you want to conditionally include the field in the struct, then this is fine as is.
--
Darren
Quoted 136 lines
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c line 97
Quoted 6 lines
drivers/platform/x86/intel_pmc_core.c new file +5
-0+ +static int pmc_core_dbgfs_register (struct pmc_dev *pmc) +{ +struct dentry *dir, *file; +int ret =0 ;Redundant, see below.
Quoted 15 lines
drivers/platform/x86/intel_pmc_core.c line 109
Quoted 12 lines
drivers/platform/x86/intel_pmc_core.c new file +12
-0+ + dir =debugfs_create_dir ("pmc_core" ,NULL ); +if (!dir) +return -ENOMEM ; + + pmc->dbgfs_dir = dir; + file =debugfs_create_file ("slp_s0_residency_usec" ,S_IFREG |S_IRUGO , + dir, pmc, &pmc_core_dev_state_ops); + +if (!file) { +pmc_core_dbgfs_unregister (pmc); + ret = -ENODEV ;return
-ENODEV;Ok.
Quoted 14 lines
drivers/platform/x86/intel_pmc_core.c line 111
Quoted 3 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+ } +return ret;return 0;
Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c new file +7
-0+} +#else +static inline int pmc_core_dbgfs_register (struct pmc_dev *pmc) +{ +return 0 ;/* nothing to register */ +} +Quoted 7 lines
drivers/platform/x86/intel_pmc_core.c line 122
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+static inline void pmc_core_dbgfs_unregister (struct pmc_dev *pmc) +{ +/* nothing to deregister */ +}Redundant.
Same as above.
Quoted 8 lines
drivers/platform/x86/intel_pmc_core.c line 127
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c new file +5
-0+#endif /* CONFIG_DEBUG_FS */ + +static const struct x86_cpu_id intel_pmc_core_ids[] = { + {X86_VENDOR_INTEL ,6 ,0x4e ,X86_FEATURE_MWAIT , + (kernel_ulong_t )NULL },/* Skylake CPUID Signature */ No explicit NULL.
Same as explained above.
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c line 129
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+ {X86_VENDOR_INTEL ,6 ,0x5e ,X86_FEATURE_MWAIT , + (kernel_ulong_t)NULL}, /* Skylake CPUID Signature */Ditto.
Same as explained above.
Quoted 10 lines
drivers/platform/x86/intel_pmc_core.c line 137
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c new file +8
-0+ {} +}; +MODULE_DEVICE_TABLE (x86cpu, intel_pmc_core_ids); + +static int pmc_core_probe (struct pci_dev *dev,const struct pci_device_id *id) +{ +int err; +const struct x86_cpu_id *cpu_id;Quoted 7 lines
Swap them.
+ const struct
x86_cpu_id*cpu_id;
+ int err;struct
pmc_dev*pmcdev = &pmc;Ok.
Quoted 11 lines
drivers/platform/x86/intel_pmc_core.c line 145
Quoted 8 lines
drivers/platform/x86/intel_pmc_core.c new file +8
-0+ + cpu_id =x86_match_cpu (intel_pmc_core_ids); +if (!cpu_id) { + err = -EINVAL ; + goto exit; + } + + err =pci_enable_device (dev);
pcim_enable_device();Thanks for this suggestion.
Quoted 19 lines
drivers/platform/x86/intel_pmc_core.c line 147
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+if (err) { +dev_err (&dev->dev,"PMC Core: failed to enable Power Management Controller.\n" );I doubt this message is useful anyhow.
drivers/platform/x86/intel_pmc_core.c line 153
Quoted 6 lines
drivers/platform/x86/intel_pmc_core.c new file +6
-0+ goto exit; + } + + err =pci_read_config_dword (dev, +SPT_PMC_BASE_ADDR_OFFSET , + &pmc.base_addr);'pmc.' -> 'pmcdev->'
drivers/platform/x86/intel_pmc_core.c line 157
Quoted 4 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+if (err) { +dev_err (&dev->dev,"PMC Core: failed to read pci config space.\n" ); + goto disable_pci; + }Quoted 7 lines
So, and this is not available through BARs?
Quoted 1 line
+
dev_dbg(&dev->dev, "PMC Core: PWRMBASE is 0x%x\n", pmc.base_addr);%#x will prefix the number.
Quoted 1 line
+
Ok.
Quoted 3 lines
Quoted 2 lines
drivers/platform/x86/intel_pmc_core.c new file +2
-0+ pmc.regmap =ioremap_nocache (pmc.base_addr,SPT_PMC_MMIO_REG_LEN ); +if (!pmc.regmap) {
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+
dev_err(&dev->dev, "PMC Core: ioremap failed\n");Useful?
Want to keep it for debug purpose.
If it's really only useful for debug, then use dev_dbg as you did above.
Quoted 53 lines
Do you recommend
devm_ioremap_nocacheas well?Quoted 14 lines
Quoted 12 lines
drivers/platform/x86/intel_pmc_core.c new file +12
-0+ err = -ENOMEM ; + goto disable_pci; + } + + err =pmc_core_dbgfs_register (&pmc); +if (err) { +dev_err (&dev->dev,"PMC Core: debugfs register failed\n" ); +iounmap (pmc.regmap); + goto disable_pci;Do you recommend devm_ioremap_nocache as well? + } + + pmc.has_slp_s0_res = true;Quoted 8 lines
drivers/platform/x86/intel_pmc_core.c line 178
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c new file +4
-0+return 0 ; + +disable_pci: +pci_disable_device (dev);Remove after using pcim_*().
Ok.
Quoted 4 lines
Quoted 1 line
+exit:
Redundant. Use return directly.
Ok.
Quoted 14 lines
Quoted 9 lines
drivers/platform/x86/intel_pmc_core.c new file +9
-0+return err; +} + +static void intel_pmc_core_remove (struct pci_dev *pdev) +{ +pmc_core_dbgfs_unregister (&pmc); +pci_disable_device (pdev); +iounmap (pmc.regmap); +}Signature · 2 lines
With Best Regards, Andy ShevchenkoSignature · 2 lines
Best Regards, Rajneesh
Signature · 2 lines
Darren Hart Intel Open Source Technology Center
Quoted 33 lines · Darren Hart
Quoted 25 lines · Rajneesh Bhardwaj
Quoted 13 lines · Andy Shevchenko
MAINTAINERS S: Maintained · line 5888
Quoted 7 lines · Rajneesh Bhardwaj
MAINTAINERS +7
-0+INTEL PMC CORE DRIVER +M: Rajneesh Bhardwaj <[email protected]> +M: Vishwanath Somayaji <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/intel_pmc_core.h +F: drivers/platform/x86/intel_pmc_core.cSo, we have
arch/x86/platform/atom/pmc_atom.cQuoted 4 lines
This driver looks very similar (by what functional is), so, we have to become clear what our layout is.
Either we go withdrivers/platform/x86or witharch/x86/platform.IMHO, the functianality provided by this driver is platform specific and not architecture specific.
There are few similar drivers present in this location already i.e.
intel_telemetry_core.c,intel_pmc_ipc.cetc.Quoted 6 lines
We had initially put this driver along with
pmc_atom.cbut later we thought that driver/platform/x86 would be a more apt place for it because of the above mentioned reasons.Please advise for the right location for this driver if its not placed in the expected location.
Quoted 8 lines
We're experiencing some repeat discussion due to some of the reviews having taken place off list. Sorry Andy, I've been trying to steer this back to list, so you're missing some context to no fault of your own.
It's possible some of the existing drivers in arch really shouldn't be there. It's not particularly well defined, however, if it isn't used outside the kernel or by other subsystems within the kernel, it seems that
drivers/platform/x86would be the appropriate location.
Roughly it's what I also expected, but here we export function to the users. If they are all be located under pdx86 I'm pretty okay with current approach. Otherwise might be good to think a bit.
Quoted 2 lines
Thomas, Peter - do you have a criteria for what you prefer to have in
arch/x86/platformversusdrivers/platform/x86?
+1 to the question. It would be nice to have a formal criteria to choose a location.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
drivers/platform/x86/Kconfig config INTEL_IPS · line 824
Quoted 7 lines
drivers/platform/x86/Kconfig +1
-0@@ -821,6 +821,18 @@ config INTEL_IPS functionality. If in doubt, say Y here; it will only load on supported platforms. +config INTEL_PMC_COREBetter to locate this in alphabetical order.
Quoted 4 lines
Quoted 4 lines
Agreed, i tried to put it in alphabetical order but there are quite a few entries in
Kconfigthat are skewed e.g.INTEL_MFLDis placed aboveINTEL_IPS.Placing
INTEL_PMC_COREafterINTEL_IMRwould be ok?
At least. At some point we might sort entire file alphabetically.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/platform/x86/Kconfig config INTEL_IPS · line 828
Quoted 4 lines
drivers/platform/x86/Kconfig +4
-0+static struct pmc_dev pmc; + +static const struct pci_device_id pmc_pci_ids[] = { + { PCI_VDEVICE(INTEL, SPT_PMC_PCI_DEVICE_ID), (kernel_ulong_t)NULL },No need to have an explicit NULL
Quoted 5 lines
Quoted 2 lines
There is a precedent in the kernel for such usage and in previous reviews we agreed to stick to this format. I hope thats fine?
I'm fine with this, even if redundant, so long as you are consistent throughout the driver. This is consistent with the other drivers in
drivers/platform/x86.
Yeah, it's minor, so just one format for all entries.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
drivers/platform/x86/Kconfig config INTEL_IPS · line 829
Quoted 1 line
drivers/platform/x86/Kconfig +1
-0+EXPORT_SYMBOL_GPL(intel_pmc_slp_s0_counter_read);Who is going to be a user of that?
This is expected to be used by a framework (upcoming) for detecting
slp_s0signal assertion related failures.
It might be good to put few words in the commit message about expecting user(s).
Quoted 15 lines
Quoted 11 lines
Quoted 7 lines
drivers/platform/x86/Kconfig config INTEL_IPS · line 833
Quoted 4 lines
drivers/platform/x86/Kconfig +4
-0+static void pmc_core_dbgfs_unregister(struct pmc_dev *pmc) +{ + debugfs_remove_recursive(pmc->dbgfs_dir); +}No need to keep this under #ifdef.
Based on some previus review comments we decided to put the dummy functions for !CONIG_DEBUG_FS case. Can you please elaborate more on this change request?
I think Andy's point is that there is no reason to specialize this function since
debugs_remove_recursivechecks for null.
Quoted 7 lines
The problem of course is that
dbgfs_dironly exists ifCONFIG_DEBUG_FSexists. I don't know if that's worth ifdeffing out of the struct, but there is precendent for doing it that way, and I didn't feel strongly one way or the other, so I left it up to you.If you want to conditionally include the field in the struct, then this is fine as is.
Yeah, for the consistency either way is okay. I prefer to have less #ifdef:s, but here it's a not bit burden.
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
drivers/platform/x86/Kconfig config INTEL_IPS · line 834
Quoted 1 line
drivers/platform/x86/Kconfig +1
-0+ pmc.regmap = ioremap_nocache(pmc.base_addr, SPT_PMC_MMIO_REG_LEN);Do you recommend
devm_ioremap_nocacheas well?
Good point.
Signature · 2 lines
With Best Regards, Andy Shevchenko
drivers/platform/x86/intel_pmc_core.h line 50
Quoted 13 lines · Rajneesh Bhardwaj
+ *
pmc_devcontains info about power management controller device.
+ */drivers/platform/x86/intel_pmc_core.h new file +10
-0+struct pmc_dev { +u32 base_addr; +void __iomem *regmap; +#if IS_ENABLED (CONFIG_DEBUG_FS ) +struct dentry *dbgfs_dir; +#endif /* CONFIG_DEBUG_FS */ +bool has_slp_s0_res; +}; + +int intel_pmc_slp_s0_counter_read (u64 *data);
Can this function be split out into another header file? The struct pmc_dev is internal, but this function is needed as an external interface.