platform/x86: intel_pmc_core: export platform global_reset via sysfs.
Subsystems (2)
PATCH 1/1 platform/x86: intel_pmc_core: export platform global_reset via sysfs.
From: Tamar Mashiah <[email protected]>
During PCH manufacturing a global reset has to be induced in order for configuration changes take affect upon following platform reset. This setting was commonly done by accessing PMC registers via /dev/mem but due to security concern /dev/mem access is much restricted, hence the reason for exposing this setting via dedicated sysfs interface. To prevent post manufacturing abuse the register is protected by hardware locking.
The register in MMIO space is defined for Cannon Lake and newer PCHs.
--- .../ABI/testing/sysfs-platform-intel-pmc | 11 +++ MAINTAINERS | 1 + drivers/platform/x86/intel_pmc_core.c | 95 +++++++++++++++++++ drivers/platform/x86/intel_pmc_core.h | 6 ++ 4 files changed, 113 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-pmc
Documentation/ABI/testing/sysfs-platform-intel-pmc new file +11 -0
@@ -0,0 +1,11 @@ +What: /sys/devices/platform/<platform>/global_reset +Date: Apr 2021 +KernelVersion: 5.13 +Contact: "Tomas Winkler" <[email protected]> +Description: + Display global reset setting bits for PMC. + * bit 31 - global reset is locked + * bit 20 - global reset is set + Writing bit 20 value to the global_reset will induce + a platform global reset upon consequent platform reset. + in case the register is not locked.
MAINTAINERS +1 -0
@@ -9166,6 +9166,7 @@ M: Rajneesh Bhardwaj <[email protected]> M: David E Box <[email protected]> L: [email protected] S: Maintained +F: Documentation/ABI/testing/sysfs-platform-intel-pmc F: drivers/platform/x86/intel_pmc_core* INTEL PMIC GPIO DRIVERS
drivers/platform/x86/intel_pmc_core.c +95 -0
125 lines not on this page · raw message
drivers/platform/x86/intel_pmc_core.h +6 -0
@@ -200,6 +200,11 @@ enum ppfear_regs {#define TGL_LPM_STATUS_OFFSET 0x1C3C#define TGL_LPM_LIVE_STATUS_OFFSET 0x1C5C +/* Extended Test Mode Register 3 (CNL and later) */ +#define ETR3_OFFSET 0x1048 +#define ETR3_CF9GR BIT(20) +#define ETR3_CF9LOCK BIT(31) +const char *tgl_lpm_modes[] = {"S0i2.0" ,"S0i2.1" ,
@@ -263,6 +268,7 @@ struct pmc_reg_map {const u32 lpm_residency_offset;const u32 lpm_status_offset;const u32 lpm_live_status_offset; +const u32 etr3_offset; };/**
Signature · 1 line
2.26.3
Quoted 5 lines · Tomas Winkler
From: Tamar Mashiah <[email protected]>
During PCH manufacturing a global reset has to be induced in order for configuration changes take affect upon following platform reset.
effect upon the following ?
Quoted 11 lines
This setting was commonly done by accessing PMC registers via
/dev/membut due to security concern/dev/memaccess is much restricted, hence the reason for exposing this setting via dedicated sysfs interface. To prevent post manufacturing abuse the register is protected by hardware locking.The register in MMIO space is defined for Cannon Lake and newer PCHs.
Cc David E Box <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>
Hmm... okay, I forgot this, so my additional comments above and below.
...
drivers/platform/x86/intel_pmc_core.c static inline u64 pmc_core_adjust_slp_s0_step(struct pmc_dev *pmcdev, u32 value) · line 620
Quoted 12 lines
drivers/platform/x86/intel_pmc_core.c +11
-0+static int set_global_reset (struct pmc_dev *pmcdev) +{ +const struct pmc_reg_map *map = pmcdev->map; +u32 reg; +int err; + +mutex_lock (&pmcdev->lock); +if (!map->etr3_offset) { + err = -EOPNOTSUPP ; + goto out_unlock; + }
Do we really need this check under the lock?
drivers/platform/x86/intel_pmc_core.c static inline u64 pmc_core_adjust_slp_s0_step(struct pmc_dev *pmcdev, u32 value) · line 629
Quoted 8 lines
drivers/platform/x86/intel_pmc_core.c +8
-0+/* check if CF9 is locked */ + reg =pmc_core_reg_read (pmcdev, map->etr3_offset); +if (reg &ETR3_CF9LOCK ) { + err = -EACCES ; + goto out_unlock; + } + +/* write CF9 global reset bit */
Somewhere you use cf9 (small letters) I suggest to be consistent and use the capitalized version everywhere.
drivers/platform/x86/intel_pmc_core.c static inline u64 pmc_core_adjust_slp_s0_step(struct pmc_dev *pmcdev, u32 value) · line 634
Quoted 5 lines
drivers/platform/x86/intel_pmc_core.c +5
-0+ reg |=ETR3_CF9GR ; +pmc_core_reg_write (pmcdev, map->etr3_offset, reg); + + reg =pmc_core_reg_read (pmcdev, map->etr3_offset); +if ((reg &ETR3_CF9GR ) ==0 ) {
Can be written in a form of !(reg & ETR3_CF9GR).
Quoted 13 lines
drivers/platform/x86/intel_pmc_core.c +13
-0+ err = -EIO ; + goto out_unlock; + } + + err =0 ; + +out_unlock: +mutex_unlock (&pmcdev->lock); +return err; +} + +static ssize_t global_reset_show (struct device *dev, +struct device_attribute *attr,char *buf)
drivers/platform/x86/intel_pmc_core.c static inline u64 pmc_core_adjust_slp_s0_step(struct pmc_dev *pmcdev, u32 value) · line 657
Quoted 10 lines
drivers/platform/x86/intel_pmc_core.c +9
-0+{ +struct pmc_dev *pmcdev =dev_get_drvdata (dev); +const struct pmc_reg_map *map = pmcdev->map; +u32 reg; + +if (!map->etr3_offset) +return -EOPNOTSUPP ; + reg =pmc_core_reg_read (pmcdev, map->etr3_offset); + reg &=ETR3_CF9GR |ETR3_CF9LOCK ;
And why no lock here?
Quoted 2 lines
(quoted diff) +2
-0+ return sysfs_emit(buf, "0x%08x", reg); +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
On 01.04.21 23:31, Tomas Winkler wrote:
Hi,
Quoted 7 lines
During PCH manufacturing a global reset has to be induced in order for configuration changes take affect upon following platform reset. This setting was commonly done by accessing PMC registers via
/dev/membut due to security concern/dev/memaccess is much restricted, hence the reason for exposing this setting via dedicated sysfs interface. To prevent post manufacturing abuse the register is protected by hardware locking.
could you please define "manufacturing" ? The chip or board ?
Is there any use for this, after the machine left the factory ?
--mtx
Signature · 8 lines
--- Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren GPG/PGP-Schlüssel zu. --- Enrico Weigelt, metux IT consult Free software and Linux embedded engineering [email protected] -- +49-151-27565287
Quoted 26 lines
-----Original Message-----
From: Enrico Weigelt, metux IT consult <[email protected]>
Sent: Friday, April 02, 2021 16:32
To: Winkler, Tomas <[email protected]>; Rajneesh Bhardwaj <[email protected]>; Box, David E <[email protected]>; Hans de Goede <[email protected]>; Mark Gross <[email protected]>
Cc: [email protected]; [email protected]; Mashiah, Tamar <[email protected]>; Andy Shevchenko <[email protected]>
Subject: Re: [PATCH] platform/x86:intel_pmc_core: export platformglobal_resetvia sysfs.On 01.04.21 23:31, Tomas Winkler wrote:
Hi,
Quoted 7 lines
During PCH manufacturing a global reset has to be induced in order for configuration changes take affect upon following platform reset. This setting was commonly done by accessing PMC registers via
/dev/membut due to security concern/dev/memaccess is much restricted, hence the reason for exposing this setting via dedicated sysfs interface. To prevent post manufacturing abuse the register is protected by hardware locking.
Quoted 1 line
could you please define "manufacturing" ? The chip or board ?
Board
Quoted 2 lines
Is there any use for this, after the machine left the factory ?
Refurbishing, mostly, the register is hw locked after that.
Quoted 13 lines
--mtx
--
---
Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren GPG/PGP-Schlüssel zu.
---
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering [email protected] -- +49-151- 27565287