Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1601914

[PATCH v1 1/1] platform/x86: intel_pmc_ipc: fix io mem mapping size

From Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Newsgroups linux.kernel
Subject [PATCH v1 1/1] platform/x86: intel_pmc_ipc: fix io mem mapping size
Date 2017-03-16 04:40 +0100
Message-ID <tluqB-H1-5@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


Mapping entire GCR mem region in this driver creates
mem region request conflict in sub devices that depend
on PMC. This creates driver probe failure in devices like
iTC0_wdt and telemetry device.

Currently this driver only need memory mapping for
s0ix counter registers. So this patch fixes this issue
by requesting memory mapping for only the s0ix counter mem
region.

Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
---
 drivers/platform/x86/intel_pmc_ipc.c | 59 +++++++++++++++++++++++++++++-------
 1 file changed, 48 insertions(+), 11 deletions(-)

diff --git a/drivers/platform/x86/intel_pmc_ipc.c b/drivers/platform/x86/intel_pmc_ipc.c
index 0651d47..2b8a090 100644
--- a/drivers/platform/x86/intel_pmc_ipc.c
+++ b/drivers/platform/x86/intel_pmc_ipc.c
@@ -58,8 +58,8 @@
 #define IPC_READ_BUFFER		0x90
 
 /* PMC Global Control Registers */
-#define GCR_TELEM_DEEP_S0IX_OFFSET	0x1078
-#define GCR_TELEM_SHLW_S0IX_OFFSET	0x1080
+#define GCR_TELEM_DEEP_S0IX_OFFSET	0x0
+#define GCR_TELEM_SHLW_S0IX_OFFSET	0x8
 
 /* Residency with clock rate at 19.2MHz to usecs */
 #define S0IX_RESIDENCY_IN_USECS(d, s)		\
@@ -84,6 +84,8 @@
 #define PLAT_RESOURCE_IPC_SIZE		0x1000
 #define PLAT_RESOURCE_GCR_OFFSET	0x1008
 #define PLAT_RESOURCE_GCR_SIZE		0x1000
+#define PLAT_RESOURCE_GCR_S0IX_OFFSET	0x1078
+#define PLAT_RESOURCE_GCR_S0IX_SIZE	12
 #define PLAT_RESOURCE_BIOS_DATA_INDEX	1
 #define PLAT_RESOURCE_BIOS_IFACE_INDEX	2
 #define PLAT_RESOURCE_TELEM_SSRAM_INDEX	3
@@ -130,6 +132,11 @@ static struct intel_pmc_ipc_dev {
 	int gcr_size;
 	bool has_gcr_regs;
 
+	/* s0ix counters */
+	resource_size_t gcr_s0ix_start;
+	int gcr_s0ix_size;
+	void __iomem *gcr_s0ix_base;
+
 	/* punit */
 	struct platform_device *punit_dev;
 
@@ -194,9 +201,9 @@ static inline u32 ipc_data_readl(u32 offset)
 	return readl(ipcdev.ipc_base + IPC_READ_BUFFER + offset);
 }
 
-static inline u64 gcr_data_readq(u32 offset)
+static inline u64 gcr_s0ix_data_readq(u32 offset)
 {
-	return readq(ipcdev.ipc_base + offset);
+	return readq(ipcdev.gcr_s0ix_base + offset);
 }
 
 static int intel_pmc_ipc_check_status(void)
@@ -732,7 +739,7 @@ static int ipc_plat_get_res(struct platform_device *pdev)
 		dev_err(&pdev->dev, "Failed to get ipc resource\n");
 		return -ENXIO;
 	}
-	size = PLAT_RESOURCE_IPC_SIZE + PLAT_RESOURCE_GCR_SIZE;
+	size = PLAT_RESOURCE_IPC_SIZE;
 
 	if (!request_mem_region(res->start, size, pdev->name)) {
 		dev_err(&pdev->dev, "Failed to request ipc resource\n");
@@ -748,8 +755,36 @@ static int ipc_plat_get_res(struct platform_device *pdev)
 
 	ipcdev.gcr_base = res->start + PLAT_RESOURCE_GCR_OFFSET;
 	ipcdev.gcr_size = PLAT_RESOURCE_GCR_SIZE;
+
 	dev_info(&pdev->dev, "ipc res: %pR\n", res);
 
+	/* request s0ix counter reg memory */
+	ipcdev.gcr_s0ix_start = res->start + PLAT_RESOURCE_GCR_S0IX_OFFSET;
+	ipcdev.gcr_s0ix_size = PLAT_RESOURCE_GCR_S0IX_SIZE;
+
+	if (!request_mem_region(ipcdev.gcr_s0ix_start, ipcdev.gcr_s0ix_size,
+				"ipc_gcr_s0ix")) {
+		dev_err(&pdev->dev, "Failed to request s0ix mem region\n");
+		iounmap(ipcdev.ipc_base);
+		release_mem_region(res->start, size);
+		return -EBUSY;
+	}
+
+	addr = ioremap_nocache(ipcdev.gcr_s0ix_start, ipcdev.gcr_s0ix_size);
+	if (!addr) {
+		dev_err(&pdev->dev, "s0ix I/O memory remapping failed\n");
+		release_mem_region(ipcdev.gcr_s0ix_start, ipcdev.gcr_s0ix_size);
+		iounmap(ipcdev.ipc_base);
+		release_mem_region(res->start, size);
+		return -ENOMEM;
+	}
+
+	ipcdev.gcr_s0ix_base = addr;
+
+	dev_info(&pdev->dev, "s0ix mem region 0x%llx-0x%llx\n",
+		 ipcdev.gcr_s0ix_start,
+		 (ipcdev.gcr_s0ix_start + ipcdev.gcr_s0ix_size - 1));
+
 	ipcdev.telem_res_inval = 0;
 	res = platform_get_resource(pdev, IORESOURCE_MEM,
 				    PLAT_RESOURCE_TELEM_SSRAM_INDEX);
@@ -782,8 +817,8 @@ int intel_pmc_s0ix_counter_read(u64 *data)
 	if (!ipcdev.has_gcr_regs)
 		return -EACCES;
 
-	deep = gcr_data_readq(GCR_TELEM_DEEP_S0IX_OFFSET);
-	shlw = gcr_data_readq(GCR_TELEM_SHLW_S0IX_OFFSET);
+	deep = gcr_s0ix_data_readq(GCR_TELEM_DEEP_S0IX_OFFSET);
+	shlw = gcr_s0ix_data_readq(GCR_TELEM_SHLW_S0IX_OFFSET);
 
 	*data = S0IX_RESIDENCY_IN_USECS(deep, shlw);
 
@@ -851,12 +886,13 @@ static int ipc_plat_probe(struct platform_device *pdev)
 	platform_device_unregister(ipcdev.telemetry_dev);
 err_device:
 	iounmap(ipcdev.ipc_base);
+	iounmap(ipcdev.gcr_s0ix_base);
 	res = platform_get_resource(pdev, IORESOURCE_MEM,
 				    PLAT_RESOURCE_IPC_INDEX);
 	if (res) {
+		release_mem_region(ipcdev.gcr_s0ix_start, ipcdev.gcr_s0ix_size);
 		release_mem_region(res->start,
-				   PLAT_RESOURCE_IPC_SIZE +
-				   PLAT_RESOURCE_GCR_SIZE);
+				   PLAT_RESOURCE_IPC_SIZE);
 	}
 	return ret;
 }
@@ -871,12 +907,13 @@ static int ipc_plat_remove(struct platform_device *pdev)
 	platform_device_unregister(ipcdev.punit_dev);
 	platform_device_unregister(ipcdev.telemetry_dev);
 	iounmap(ipcdev.ipc_base);
+	iounmap(ipcdev.gcr_s0ix_base);
 	res = platform_get_resource(pdev, IORESOURCE_MEM,
 				    PLAT_RESOURCE_IPC_INDEX);
 	if (res) {
+		release_mem_region(ipcdev.gcr_s0ix_start, ipcdev.gcr_s0ix_size);
 		release_mem_region(res->start,
-				   PLAT_RESOURCE_IPC_SIZE +
-				   PLAT_RESOURCE_GCR_SIZE);
+				   PLAT_RESOURCE_IPC_SIZE);
 	}
 	ipcdev.dev = NULL;
 	return 0;
-- 
2.7.4

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH v1 1/1] platform/x86: intel_pmc_ipc: fix io mem mapping size Kuppuswamy Sathyanarayanan          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-16 04:40 +0100
  Re: [PATCH v1 1/1] platform/x86: intel_pmc_ipc: fix io mem mapping  size Rajneesh Bhardwaj <rajneesh.bhardwaj@intel.com> - 2017-03-16 16:00 +0100
    Re: [PATCH v1 1/1] platform/x86: intel_pmc_ipc: fix io mem mapping size Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-03-16 17:10 +0100
      Re: [PATCH v1 1/1] platform/x86: intel_pmc_ipc: fix io mem mapping  size Rajneesh Bhardwaj <rajneesh.bhardwaj@intel.com> - 2017-03-16 19:20 +0100
        Re: [PATCH v1 1/1] platform/x86: intel_pmc_ipc: fix io mem mapping size Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-03-16 21:20 +0100
          Re: [PATCH v1 1/1] platform/x86: intel_pmc_ipc: fix io mem mapping  size sathyanarayanan kuppuswamy          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-16 22:20 +0100
    Re: [PATCH v1 1/1] platform/x86: intel_pmc_ipc: fix io mem mapping  size sathyanarayanan kuppuswamy          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-16 20:00 +0100
      Re: [PATCH v1 1/1] platform/x86: intel_pmc_ipc: fix io mem mapping  size Rajneesh Bhardwaj <rajneesh.bhardwaj@intel.com> - 2017-03-16 20:30 +0100
        Re: [PATCH v1 1/1] platform/x86: intel_pmc_ipc: fix io mem mapping  size sathyanarayanan kuppuswamy          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-16 22:30 +0100
        [PATCH v2 2/4] platform/x86: intel_pmc_ipc: Add pmc gcr read/write api's Kuppuswamy Sathyanarayanan          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-17 01:50 +0100
          Re: [PATCH v2 2/4] platform/x86: intel_pmc_ipc: Add pmc gcr  read/write api's Rajneesh Bhardwaj <rajneesh.bhardwaj@intel.com> - 2017-03-17 12:30 +0100
            Re: [PATCH v2 2/4] platform/x86: intel_pmc_ipc: Add pmc gcr  read/write api's sathyanarayanan kuppuswamy          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-17 18:40 +0100
        [PATCH v2 4/4] platform/x86: intel_pmc_ipc: remove iTCO GCR mem resource Kuppuswamy Sathyanarayanan          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-17 01:50 +0100
          Re: [PATCH v2 4/4] platform/x86: intel_pmc_ipc: remove iTCO GCR mem  resource Rajneesh Bhardwaj <rajneesh.bhardwaj@intel.com> - 2017-03-17 12:50 +0100
        [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping failure Kuppuswamy Sathyanarayanan          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-17 01:50 +0100
          Re: [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping  failure Rajneesh Bhardwaj <rajneesh.bhardwaj@intel.com> - 2017-03-17 12:50 +0100
            Re: [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping  failure Guenter Roeck <linux@roeck-us.net> - 2017-03-17 14:50 +0100
              Re: [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping  failure Rajneesh Bhardwaj <rajneesh.bhardwaj@intel.com> - 2017-03-17 15:10 +0100
              Re: [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping failure Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-03-17 15:30 +0100
                Re: [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping  failure sathyanarayanan kuppuswamy          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-17 18:50 +0100
                Re: [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping failure Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-03-17 19:40 +0100
                Re: [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping  failure sathyanarayanan kuppuswamy          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-17 20:00 +0100
              Re: [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping  failure Guenter Roeck <linux@roeck-us.net> - 2017-03-17 19:00 +0100
                Re: [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping  failure sathyanarayanan kuppuswamy          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-17 19:50 +0100
              Re: [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping  failure sathyanarayanan kuppuswamy          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-17 21:50 +0100
            Re: [PATCH v2 3/4] watchdog: iTCO_wdt: Fix PMC GCR memory mapping  failure sathyanarayanan kuppuswamy          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-17 18:30 +0100
        [PATCH v2 1/4] platform/x86: intel_pmc_ipc: fix gcr offset Kuppuswamy Sathyanarayanan          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-17 02:00 +0100
          Re: [PATCH v2 1/4] platform/x86: intel_pmc_ipc: fix gcr offset Rajneesh Bhardwaj <rajneesh.bhardwaj@intel.com> - 2017-03-17 12:20 +0100
            Re: [PATCH v2 1/4] platform/x86: intel_pmc_ipc: fix gcr offset sathyanarayanan kuppuswamy          <sathyanarayanan.kuppuswamy@linux.intel.com> - 2017-03-17 18:20 +0100

csiph-web