Skip to contentSkip to conversation

platform/x86/intel_pmc_core: Convert to DEFINE_DEBUGFS_ATTRIBUTE

PATCH Applied Andy Shevchenko 3 participants 4 messages Jul 4, 2016 – Jul 6, 2016 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 platform/x86/intel_pmc_core: Convert to DEFINE_DEBUGFS_ATTRIBUTE

This patch does the following:
- refactors code to use recently introduced DEFINE_DEBUGFS_ATTRIBUTE() macro
- makes absence of DEBUG_FS non-fatal error

---
In v2:
- address Rajneesh's comments

 drivers/platform/x86/intel_pmc_core.c | 45 ++++++++---------------------------
 drivers/platform/x86/intel_pmc_core.h |  3 +--
 2 files changed, 11 insertions(+), 37 deletions(-)
drivers/platform/x86/intel_pmc_core.c +10 -35
index 2776bec..d8379cd 100644
@@ -23,7 +23,6 @@
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/pci.h>
-#include <linux/seq_file.h>
 
 #include <asm/cpu_device_id.h>
 #include <asm/pmc_core.h>
@@ -77,30 +76,18 @@ int intel_pmc_slp_s0_counter_read(u32 *data)
 }
 EXPORT_SYMBOL_GPL(intel_pmc_slp_s0_counter_read);
 
-#if IS_ENABLED(CONFIG_DEBUG_FS)
-static int pmc_core_dev_state_show(struct seq_file *s, void *unused)
+static int pmc_core_dev_state_get(void *data, u64 *val)
 {
-	struct pmc_dev *pmcdev = s->private;
-	u32 counter_val;
+	struct pmc_dev *pmcdev = data;
+	u32 value;
 
-	counter_val = pmc_core_reg_read(pmcdev,
-					SPT_PMC_SLP_S0_RES_COUNTER_OFFSET);
-	seq_printf(s, "%u\n", pmc_core_adjust_slp_s0_step(counter_val));
+	value = pmc_core_reg_read(pmcdev, SPT_PMC_SLP_S0_RES_COUNTER_OFFSET);
+	*val = pmc_core_adjust_slp_s0_step(value);
 
 	return 0;
 }
 
-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,
-};
+DEFINE_DEBUGFS_ATTRIBUTE(pmc_core_dev_state, pmc_core_dev_state_get, NULL, "%llu\n");
 
 static void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev)
 {
@@ -112,12 +99,12 @@ static int pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
 	struct dentry *dir, *file;
 
 	dir = debugfs_create_dir("pmc_core", NULL);
-	if (!dir)
+	if (IS_ERR_OR_NULL(dir))
 		return -ENOMEM;
 
 	pmcdev->dbgfs_dir = dir;
 	file = debugfs_create_file("slp_s0_residency_usec", S_IFREG | S_IRUGO,
-				   dir, pmcdev, &pmc_core_dev_state_ops);
+				   dir, pmcdev, &pmc_core_dev_state);
 
 	if (!file) {
 		pmc_core_dbgfs_unregister(pmcdev);
@@ -126,16 +113,6 @@ static int pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
 
 	return 0;
 }
-#else
-static inline int pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
-{
-	return 0;
-}
-
-static inline void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev)
-{
-}
-#endif /* CONFIG_DEBUG_FS */
 
 static const struct x86_cpu_id intel_pmc_core_ids[] = {
 	{ X86_VENDOR_INTEL, 6, 0x4e, X86_FEATURE_MWAIT,
@@ -182,10 +159,8 @@ static int pmc_core_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	}
 
 	err = pmc_core_dbgfs_register(pmcdev);
-	if (err < 0) {
-		dev_err(&dev->dev, "PMC Core: debugfs register failed.\n");
-		return err;
-	}
+	if (err < 0)
+		dev_warn(&dev->dev, "PMC Core: debugfs register failed.\n");
 
 	pmc.has_slp_s0_res = true;
 	return 0;
drivers/platform/x86/intel_pmc_core.h +1 -2
index a9dadaf..e3f671f 100644
@@ -23,6 +23,7 @@
 
 /* Sunrise Point Power Management Controller PCI Device ID */
 #define SPT_PMC_PCI_DEVICE_ID			0x9d21
+
 #define SPT_PMC_BASE_ADDR_OFFSET		0x48
 #define SPT_PMC_SLP_S0_RES_COUNTER_OFFSET	0x13c
 #define SPT_PMC_MMIO_REG_LEN			0x100
@@ -42,9 +43,7 @@
 struct pmc_dev {
 	u32 base_addr;
 	void __iomem *regbase;
-#if IS_ENABLED(CONFIG_DEBUG_FS)
 	struct dentry *dbgfs_dir;
-#endif /* CONFIG_DEBUG_FS */
 	bool has_slp_s0_res;
 };
 
Signature · 1 line
2.8.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Andy Shevchenko

This patch does the following:
- refactors code to use recently introduced DEFINE_DEBUGFS_ATTRIBUTE() macro
- makes absence of DEBUG_FS non-fatal error

Compiled & tested this on Ubuntu 16.04.
Kernel: 4.7.0-rc6
Hardware: Skylake based reference board

Quoted 126 lines

---
In v2:
- address Rajneesh's comments

 drivers/platform/x86/intel_pmc_core.c | 45 ++++++++---------------------------
 drivers/platform/x86/intel_pmc_core.h |  3 +--
 2 files changed, 11 insertions(+), 37 deletions(-)
drivers/platform/x86/intel_pmc_core.c +10 -35
index 2776bec..d8379cd 100644
@@ -23,7 +23,6 @@
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/pci.h>
-#include <linux/seq_file.h>
 
 #include <asm/cpu_device_id.h>
 #include <asm/pmc_core.h>
@@ -77,30 +76,18 @@ int intel_pmc_slp_s0_counter_read(u32 *data)
 }
 EXPORT_SYMBOL_GPL(intel_pmc_slp_s0_counter_read);
 
-#if IS_ENABLED(CONFIG_DEBUG_FS)
-static int pmc_core_dev_state_show(struct seq_file *s, void *unused)
+static int pmc_core_dev_state_get(void *data, u64 *val)
 {
-	struct pmc_dev *pmcdev = s->private;
-	u32 counter_val;
+	struct pmc_dev *pmcdev = data;
+	u32 value;
 
-	counter_val = pmc_core_reg_read(pmcdev,
-					SPT_PMC_SLP_S0_RES_COUNTER_OFFSET);
-	seq_printf(s, "%u\n", pmc_core_adjust_slp_s0_step(counter_val));
+	value = pmc_core_reg_read(pmcdev, SPT_PMC_SLP_S0_RES_COUNTER_OFFSET);
+	*val = pmc_core_adjust_slp_s0_step(value);
 
 	return 0;
 }
 
-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,
-};
+DEFINE_DEBUGFS_ATTRIBUTE(pmc_core_dev_state, pmc_core_dev_state_get, NULL, "%llu\n");
 
 static void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev)
 {
@@ -112,12 +99,12 @@ static int pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
 	struct dentry *dir, *file;
 
 	dir = debugfs_create_dir("pmc_core", NULL);
-	if (!dir)
+	if (IS_ERR_OR_NULL(dir))
 		return -ENOMEM;
 
 	pmcdev->dbgfs_dir = dir;
 	file = debugfs_create_file("slp_s0_residency_usec", S_IFREG | S_IRUGO,
-				   dir, pmcdev, &pmc_core_dev_state_ops);
+				   dir, pmcdev, &pmc_core_dev_state);
 
 	if (!file) {
 		pmc_core_dbgfs_unregister(pmcdev);
@@ -126,16 +113,6 @@ static int pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
 
 	return 0;
 }
-#else
-static inline int pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
-{
-	return 0;
-}
-
-static inline void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev)
-{
-}
-#endif /* CONFIG_DEBUG_FS */
 
 static const struct x86_cpu_id intel_pmc_core_ids[] = {
 	{ X86_VENDOR_INTEL, 6, 0x4e, X86_FEATURE_MWAIT,
@@ -182,10 +159,8 @@ static int pmc_core_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	}
 
 	err = pmc_core_dbgfs_register(pmcdev);
-	if (err < 0) {
-		dev_err(&dev->dev, "PMC Core: debugfs register failed.\n");
-		return err;
-	}
+	if (err < 0)
+		dev_warn(&dev->dev, "PMC Core: debugfs register failed.\n");
 
 	pmc.has_slp_s0_res = true;
 	return 0;
drivers/platform/x86/intel_pmc_core.h +1 -2
index a9dadaf..e3f671f 100644
@@ -23,6 +23,7 @@
 
 /* Sunrise Point Power Management Controller PCI Device ID */
 #define SPT_PMC_PCI_DEVICE_ID			0x9d21
+
 #define SPT_PMC_BASE_ADDR_OFFSET		0x48
 #define SPT_PMC_SLP_S0_RES_COUNTER_OFFSET	0x13c
 #define SPT_PMC_MMIO_REG_LEN			0x100
@@ -42,9 +43,7 @@
 struct pmc_dev {
 	u32 base_addr;
 	void __iomem *regbase;
-#if IS_ENABLED(CONFIG_DEBUG_FS)
 	struct dentry *dbgfs_dir;
-#endif /* CONFIG_DEBUG_FS */
 	bool has_slp_s0_res;
 };
 
Signature · 1 line
2.8.1
Signature · 2 lines
Best Regards,
Rajneesh
#2 lore raw
Quoted 6 lines · Rajneesh Bhardwaj
Quoted 5 lines · Andy Shevchenko

This patch does the following:
- refactors code to use recently introduced
DEFINE_DEBUGFS_ATTRIBUTE() macro
- makes absence of DEBUG_FS non-fatal error

Quoted 7 lines
Quoted 1 line

Compiled & tested this on Ubuntu 16.04.
Kernel: 4.7.0-rc6
Hardware: Skylake based reference board

Thanks!

Darren, I think we may use Reviewed-and-tested-by tag.

Quoted 147 lines
Quoted 146 lines

---
In v2:
- address Rajneesh's comments drivers/platform/x86/intel_pmc_core.c | 45 ++++++++--------------
-------------
 drivers/platform/x86/intel_pmc_core.h |  3 +--

 2 files changed, 11 insertions(+), 37 deletions(-)
drivers/platform/x86/intel_pmc_core.c +0 -1
index 2776bec..d8379cd 100644
@@ -23,7 +23,6 @@
  #include <linux/init.h>
  #include <linux/io.h>
  #include <linux/pci.h>
-#include <linux/seq_file.h>


 #include <asm/cpu_device_id.h>
 #include <asm/pmc_core.h>

drivers/platform/x86/intel_pmc_core.c +0 -0
@@ -77,30 +76,18 @@ int intel_pmc_slp_s0_counter_read(u32 *data)
  }
  EXPORT_SYMBOL_GPL(intel_pmc_slp_s0_counter_read);

drivers/platform/x86/intel_pmc_core.c +0 -2
-#if IS_ENABLED(CONFIG_DEBUG_FS)
-static int pmc_core_dev_state_show(struct seq_file *s, void

*unused)
+static int pmc_core_dev_state_get(void *data, u64 *val) {

drivers/platform/x86/intel_pmc_core.c +2 -2
-	struct pmc_dev *pmcdev = s->private;
-	u32 counter_val;
+	struct pmc_dev *pmcdev = data;
+	u32 value;

drivers/platform/x86/intel_pmc_core.c +0 -2
-	counter_val = pmc_core_reg_read(pmcdev,
-					SPT_PMC_SLP_S0_RES_COUNTER_

OFFSET);

drivers/platform/x86/intel_pmc_core.c +0 -1
-	seq_printf(s, "%u\n",

pmc_core_adjust_slp_s0_step(counter_val));

drivers/platform/x86/intel_pmc_core.c +1 -0
+	value = pmc_core_reg_read(pmcdev,

SPT_PMC_SLP_S0_RES_COUNTER_OFFSET);

drivers/platform/x86/intel_pmc_core.c +1 -0
+	*val = pmc_core_adjust_slp_s0_step(value);


  return 0;
 }

-static int pmc_core_dev_state_open(struct inode *inode, struct file *file)

drivers/platform/x86/intel_pmc_core.c +0 -2
-{
-	return single_open(file, pmc_core_dev_state_show, inode-
Quoted 1 line

i_private);

drivers/platform/x86/intel_pmc_core.c +1 -8
-}
-
-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,
-};
+DEFINE_DEBUGFS_ATTRIBUTE(pmc_core_dev_state,

pmc_core_dev_state_get, NULL, "%llu\n");

 static void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev) {

drivers/platform/x86/intel_pmc_core.c +0 -0
@@ -112,12 +99,12 @@ static int pmc_core_dbgfs_register(struct
 pmc_dev *pmcdev)
  	struct dentry *dir, *file;


  dir = debugfs_create_dir("pmc_core", NULL);

drivers/platform/x86/intel_pmc_core.c +1 -1
-	if (!dir)
+	if (IS_ERR_OR_NULL(dir))

  return -ENOMEM;

  pmcdev->dbgfs_dir = dir;
  file = debugfs_create_file("slp_s0_residency_usec", S_IFREG | S_IRUGO,

drivers/platform/x86/intel_pmc_core.c +0 -1
-				   dir, pmcdev,

&pmc_core_dev_state_ops);

drivers/platform/x86/intel_pmc_core.c +1 -0
+				   dir, pmcdev,

&pmc_core_dev_state);

  if (!file) { pmc_core_dbgfs_unregister(pmcdev);

drivers/platform/x86/intel_pmc_core.c +0 -0
@@ -126,16 +113,6 @@ static int pmc_core_dbgfs_register(struct
 pmc_dev *pmcdev)


  return 0;
 }

drivers/platform/x86/intel_pmc_core.c +0 -7
-#else
-static inline int pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
-{
-	return 0;
-}
-
-static inline void pmc_core_dbgfs_unregister(struct pmc_dev

*pmcdev)

drivers/platform/x86/intel_pmc_core.c +0 -3
-{
-}
-#endif /* CONFIG_DEBUG_FS */


 static const struct x86_cpu_id intel_pmc_core_ids[] = { { X86_VENDOR_INTEL, 6, 0x4e, X86_FEATURE_MWAIT,

drivers/platform/x86/intel_pmc_core.c +0 -0
@@ -182,10 +159,8 @@ static int pmc_core_probe(struct pci_dev *dev,
 const struct pci_device_id *id)
  	}


  err = pmc_core_dbgfs_register(pmcdev);

drivers/platform/x86/intel_pmc_core.c +0 -2
-	if (err < 0) {
-		dev_err(&dev->dev, "PMC Core: debugfs register

failed.\n");

drivers/platform/x86/intel_pmc_core.c +2 -2
-		return err;
-	}
+	if (err < 0)
+		dev_warn(&dev->dev, "PMC Core: debugfs register

failed.\n");

  pmc.has_slp_s0_res = true;
  return 0;

drivers/platform/x86/intel_pmc_core.h +0 -0
index a9dadaf..e3f671f 100644
@@ -23,6 +23,7 @@


 /* Sunrise Point Power Management Controller PCI Device ID */
 #define SPT_PMC_PCI_DEVICE_ID 0x9d21
+
 #define SPT_PMC_BASE_ADDR_OFFSET 0x48
 #define SPT_PMC_SLP_S0_RES_COUNTER_OFFSET 0x13c
 #define SPT_PMC_MMIO_REG_LEN 0x100

drivers/platform/x86/intel_pmc_core.h +0 -2
@@ -42,9 +43,7 @@
  struct pmc_dev {
  	u32 base_addr;
  	void __iomem *regbase;
-#if IS_ENABLED(CONFIG_DEBUG_FS)
  	struct dentry *dbgfs_dir;
-#endif /* CONFIG_DEBUG_FS */
  	bool has_slp_s0_res;
  };


--
2.8.1

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
Applied
#3 lore raw
Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Rajneesh Bhardwaj
Quoted 6 lines · Andy Shevchenko

This patch does the following:
- refactors code to use recently introduced
DEFINE_DEBUGFS_ATTRIBUTE() macro
- makes absence of DEBUG_FS non-fatal error

Quoted 7 lines
Quoted 3 lines

Compiled & tested this on Ubuntu 16.04.
Kernel: 4.7.0-rc6
Hardware: Skylake based reference board

Thanks!

Darren, I think we may use Reviewed-and-tested-by tag.

Queued to for-next, thanks.

I reworded the commit message to be more in keeping with the subject line format we use in this subsystem for changes to existing drivers and to include the justification for the change. It now reads as follows, let me know if you disagree with the change.

$ git log -1
commit df2294fb64285d2d793cf50c682ac4bfddf56c4c (HEAD -> refs/heads/for-next, refs/remotes/pdx86/for-next)
Author: Andy Shevchenko <[email protected]>
Date:   2016-07-04

intel_pmc_core: Convert to DEFINE_DEBUGFS_ATTRIBUTE

Refactor the code to use the recently introduced DEFINE_DEBUGFS_ATTRIBUTE() macro to eliminate boilerplate code. Make the absence of DEBUG_FS a non-fatal error.

Thanks,

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center