PMC/PUNIT IPC driver cleanup
Subsystems (9)
v5 cover PMC/PUNIT IPC driver cleanup
From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9/[email protected]>
Hi All,
Currently intel_pmc_ipc.c, intel_punit_ipc.c, intel_scu_ipc.c drivers implements the same IPC features. This code duplication could be avoided if we implement the IPC driver as a generic library and let custom device drivers use API provided by generic driver. This patchset mainly addresses this issue.
Along with above code duplication issue, This patchset also addresses following issues in intel_pmc_ipc and intel_punit_ipc drivers.
1. Intel_pmc_ipc.c driver does not use any resource managed (devm_*) calls.
2. In Intel_pmc_ipc.c driver, dependent devices like PUNIT, Telemetry and iTCO are created manually and uses lot of redundant buffer code.
3. Global variable is used to store the IPC device structure and it is used across all functions in intel_pmc_ipc.c and intel_punit_ipc.c.
More info on Intel IPC device library:
-------------------------------------
A generic Intel IPC class driver has been implemented and all common IPC helper functions has been moved to this driver. It exposes APIs to create IPC device channel, send raw IPC command and simple IPC commands. It also creates device attribute to send IPC command from user space.
API for creating a new IPC channel device is,
struct intel_ipc_dev *devm_intel_ipc_dev_create(struct device *dev, const char *devname, struct intel_ipc_dev_cfg *cfg, struct intel_ipc_dev_ops *ops)
The IPC channel drivers (PUNIT/PMC/SCU) when creating a new device can configure their device params like register mapping, irq, irq-mode, channel type,etc using intel_ipc_dev_cfg and intel_ipc_dev_ops arguments. After a new IPC channel device is created, IPC users can use the generic APIs to make IPC calls.
For example, after using this new model, IPC call to PMC device will look like,
pmc_ipc_dev = intel_ipc_dev_get(INTEL_PMC_IPC_DEV); ipc_dev_raw_cmd(pmc_ipc_dev, cmd, PMC_PARAM_LEN, (u32 *)ipc_in, 1, NULL, 0, 0, 0); intel_ipc_dev_put(pmc_ipc_dev);
I am still testing the driver in different products. But posted it to get some early comments. I also welcome any PMC/PUNIT driver users to check these patches in their product.
Changes since v4:
* Pushed "platform/x86: intel_pmc_ipc: Use spin_lock to protect GCR update" patch to the top of the patch list. Also its rebased on top of Andy's review branch.
Changes since v3:
* Rebased on top of Andy's review branch.
* Fixed resource ioremap warning in intel_punit_ipc.c.
* Divided "platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates" patch into two patches. One fixing the existing issue and another to add regmap support.
* Fixed error in resource initalization logic in ipc_create_punit_device.
* Changed PLATFORM_DEVID_AUTO to PLATFORM_DEVID_NONE in mfd device creation.
* Added unique name to PUNIT BIOS, GTD, & ISP regmaps.
* Fixed NULL pointer exception in intel_ipc_dev_get().
* In intel_ipc_dev.c,
* Fixed error in check for duplicate intel_ipc_dev.
* Added custom interrupt handler support.
* Used char array for error string conversion.
* Added put dev support.
Changes since v2:
* Refactored intel_scu_ipc.c to use generic IPC device APIs.
* Fixed intel_pmc_ipc.c to use pcim_* device managed functions.
Changes since v1:
* Merged devm_* changes in pmc_plat_probe and pmc_pci_probe functions into a single patch.
* Addressed Andy's comment about keeping the library generic by not implementing the low level reg access calls in intel_ipc_dev.c. This version will start using the regmap pointer provided by channel drivers instead of fixed memory map.
* Removed custom IPC APIs in intel_pmc_ipc.c and intel_punit_ipc.c.
* Cleaned up IPC driver users to use APIs provided by generic library (intel_ipc_dev.c).
Kuppuswamy Sathyanarayanan (8):
platform/x86: intel_pmc_ipc: Use spin_lock to protect GCR updates platform/x86: intel_pmc_ipc: Use MFD framework to create dependent
devices
platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates
platform: x86: Add generic Intel IPC driver platform/x86: intel_punit_ipc: Fix resource ioremap warning platform/x86: intel_punit_ipc: Use generic intel ipc device calls platform/x86: intel_pmc_ipc: Use generic Intel IPC device calls platform/x86: intel_scu_ipc: Use generic Intel IPC device calls
arch/x86/include/asm/intel_pmc_ipc.h | 37 +- arch/x86/include/asm/intel_punit_ipc.h | 125 ++-- arch/x86/include/asm/intel_scu_ipc.h | 23 +- arch/x86/platform/intel-mid/intel-mid.c | 15 +- drivers/mfd/intel_soc_pmic_bxtwc.c | 21 +- drivers/platform/x86/Kconfig | 11 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_ipc_dev.c | 576 +++++++++++++++ drivers/platform/x86/intel_pmc_ipc.c | 886 +++++++++--------------- drivers/platform/x86/intel_punit_ipc.c | 311 +++------ drivers/platform/x86/intel_scu_ipc.c | 483 ++++++------- drivers/platform/x86/intel_telemetry_pltdrv.c | 212 +++--- drivers/rtc/rtc-mrst.c | 16 +- drivers/watchdog/intel-mid_wdt.c | 12 +- drivers/watchdog/intel_scu_watchdog.c | 18 +- include/linux/mfd/intel_soc_pmic.h | 2 + include/linux/platform_data/x86/intel_ipc_dev.h | 206 ++++++ 17 files changed, 1683 insertions(+), 1272 deletions(-) create mode 100644 drivers/platform/x86/intel_ipc_dev.c create mode 100644 include/linux/platform_data/x86/intel_ipc_dev.h
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC v5 1/8 platform/x86: intel_pmc_ipc: Use spin_lock to protect GCR updates
From: Kuppuswamy Sathyanarayanan <[email protected]>
Currently, update_no_reboot_bit() function implemented in this driver uses mutex_lock() to protect its register updates. But this function is called with in atomic context in iTCO_wdt_start() and iTCO_wdt_stop() functions in iTCO_wdt.c driver, which in turn causes "sleeping into atomic context" issue. This patch fixes this issue by replacing the mutex_lock() with spin_lock() to protect the GCR read/write/update APIs.
--- drivers/platform/x86/intel_pmc_ipc.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
Changes since v4:
* Fixed style issues in commit header.
* Rebased this patch on top of Andy's review branch.
drivers/platform/x86/intel_pmc_ipc.c +13 -8
@@ -33,6 +33,7 @@#include <linux/suspend.h> #include <linux/acpi.h> #include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/spinlock.h> #include <asm/intel_pmc_ipc.h>
@@ -131,6 +132,7 @@ static struct intel_pmc_ipc_dev {/* gcr */ void __iomem *gcr_mem_base;bool has_gcr_regs; +spinlock_t gcr_lock;/* punit */ struct platform_device *punit_dev;
@@ -225,17 +227,17 @@ int intel_pmc_gcr_read(u32 offset, u32 *data) {int ret; -mutex_lock (&ipclock); +spin_lock (&ipcdev.gcr_lock); ret =is_gcr_valid (offset);if (ret <0 ) { -mutex_unlock (&ipclock); +spin_unlock (&ipcdev.gcr_lock);return ret; } *data =readl (ipcdev.gcr_mem_base + offset); -mutex_unlock (&ipclock); +spin_unlock (&ipcdev.gcr_lock);return 0 ; }
@@ -255,17 +257,17 @@ int intel_pmc_gcr_write(u32 offset, u32 data) {int ret; -mutex_lock (&ipclock); +spin_lock (&ipcdev.gcr_lock); ret =is_gcr_valid (offset);if (ret <0 ) { -mutex_unlock (&ipclock); +spin_unlock (&ipcdev.gcr_lock);return ret; }writel (data, ipcdev.gcr_mem_base + offset); -mutex_unlock (&ipclock); +spin_unlock (&ipcdev.gcr_lock);return 0 ; }
@@ -287,7 +289,7 @@ int intel_pmc_gcr_update(u32 offset, u32 mask, u32 val)u32 new_val;int ret =0 ; -mutex_lock (&ipclock); +spin_lock (&ipcdev.gcr_lock); ret =is_gcr_valid (offset);if (ret <0 )
@@ -309,7 +311,7 @@ int intel_pmc_gcr_update(u32 offset, u32 mask, u32 val) } gcr_ipc_unlock: -mutex_unlock (&ipclock); +spin_unlock (&ipcdev.gcr_lock);return ret; }EXPORT_SYMBOL_GPL (intel_pmc_gcr_update);
@@ -489,6 +491,8 @@ static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) pmc->irq_mode =IPC_TRIGGER_MODE_IRQ ; +spin_lock_init (&ipcdev.gcr_lock); + ret =pcim_enable_device (pdev);if (ret)return ret;
@@ -903,6 +907,7 @@ static int ipc_plat_probe(struct platform_device *pdev) ipcdev.dev = &pdev->dev; ipcdev.irq_mode =IPC_TRIGGER_MODE_IRQ ;init_completion (&ipcdev.cmd_complete); +spin_lock_init (&ipcdev.gcr_lock); ipcdev.irq =platform_get_irq (pdev,0 );if (ipcdev.irq <0 ) {
Signature · 1 line
2.7.4
RFC v5 3/8 platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
This patch adds support for regmap based implementation for GCR read/write/update APIs.
--- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_pmc_ipc.c | 120 +++++++++++++---------------------- 2 files changed, 44 insertions(+), 77 deletions(-)
Changes since v4:
* None
drivers/platform/x86/Kconfig +1 -0
@@ -1067,6 +1067,7 @@ config PVPANIC config INTEL_PMC_IPC tristate "Intel PMC IPC Driver" depends on ACPI + select REGMAP_MMIO ---help--- This driver provides support for PMC control on some Intel platforms. The PMC is an ARC processor which defines IPC commands for communication
drivers/platform/x86/intel_pmc_ipc.c +43 -77
205 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC v5 4/8 platform: x86: Add generic Intel IPC driver
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9/[email protected]>
Currently intel_scu_ipc.c, intel_pmc_ipc.c and intel_punit_ipc.c redundantly implements the same IPC features and has lot of code duplication between them. This driver addresses this issue by grouping the common IPC functionalities under the same driver.
--- drivers/platform/x86/Kconfig | 8 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_ipc_dev.c | 576 ++++++++++++++++++++++++ include/linux/platform_data/x86/intel_ipc_dev.h | 206 +++++++++ 4 files changed, 791 insertions(+) create mode 100644 drivers/platform/x86/intel_ipc_dev.c create mode 100644 include/linux/platform_data/x86/intel_ipc_dev.h
Changes since v4:
* None
Changes since v3:
* Fixed NULL pointer exception in intel_ipc_dev_get().
* Fixed error in check for duplicate intel_ipc_dev.
* Added custom interrupt handler support.
* Used char array for error string conversion.
* Added put dev support.
* Added devm_* variant of intel_ipc_dev_get().
Changes since v2:
* Added ipc_dev_cmd API support.
drivers/platform/x86/Kconfig +8 -0
@@ -1153,6 +1153,14 @@ config SILEAD_DMI with the OS-image for the device. This option supplies the missing information. Enable this for x86 tablets with Silead touchscreens. +config INTEL_IPC_DEV + bool "Intel IPC Device Driver" + depends on X86_64 + ---help--- + This driver implements core features of Intel IPC device. Devices + like PMC, SCU, PUNIT, etc can use interfaces provided by this + driver to implement IPC protocol of their respective device. + endif # X86_PLATFORM_DEVICES config PMC_ATOM
drivers/platform/x86/Makefile +1 -0
@@ -84,3 +84,4 @@ obj-$(CONFIG_PMC_ATOM) += pmc_atom.o obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o obj-$(CONFIG_MLX_CPLD_PLATFORM) += mlxcpld-hotplug.o obj-$(CONFIG_INTEL_TURBO_MAX_3) += intel_turbo_max_3.o +obj-$(CONFIG_INTEL_IPC_DEV) += intel_ipc_dev.o
drivers/platform/x86/intel_ipc_dev.c new file +576 -0
576 lines not on this page · raw message
include/linux/platform_data/x86/intel_ipc_dev.h new file +206 -0
206 lines not on this page · raw message
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC v5 5/8 platform/x86: intel_punit_ipc: Fix resource ioremap warning
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
For PUNIT device, ISPDRIVER_IPC and GTDDRIVER_IPC resources are not mandatory. So when PMC IPC driver creates a PUNIT device, if these resources are not available then it creates dummy resource entries for these missing resources. But during PUNIT device probe , doing ioremap on these dummy resources generates following warning messages.
intel_punit_ipc intel_punit_ipc: can't request region for resource [mem 0x00000000]intel_punit_ipc intel_punit_ipc: can't request region for resource [mem 0x00000000]intel_punit_ipc intel_punit_ipc: can't request region for resource [mem 0x00000000]intel_punit_ipc intel_punit_ipc: can't request region for resource [mem 0x00000000]
This patch fixes this issue by adding extra check for resource size before performing ioremap operation.
--- drivers/platform/x86/intel_punit_ipc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Changes since v4:
* None
drivers/platform/x86/intel_punit_ipc.c +4 -4
@@ -252,28 +252,28 @@ static int intel_punit_get_bars(struct platform_device *pdev)* - GTDRIVER_IPC BASE_IFACE */ res =platform_get_resource (pdev,IORESOURCE_MEM ,2 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[ISPDRIVER_IPC ][BASE_DATA ] = addr; } res =platform_get_resource (pdev,IORESOURCE_MEM ,3 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[ISPDRIVER_IPC ][BASE_IFACE ] = addr; } res =platform_get_resource (pdev,IORESOURCE_MEM ,4 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[GTDRIVER_IPC ][BASE_DATA ] = addr; } res =platform_get_resource (pdev,IORESOURCE_MEM ,5 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[GTDRIVER_IPC ][BASE_IFACE ] = addr;
Signature · 1 line
2.7.4
RFC v5 6/8 platform/x86: intel_punit_ipc: Use generic intel ipc device calls
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
Removed redundant IPC helper functions and refactored the driver to use APIs provided by generic IPC driver. This patch also cleans-up PUNIT IPC user drivers(intel_telemetry_pltdrv.c) to use APIs provided by generic IPC driver.
--- arch/x86/include/asm/intel_punit_ipc.h | 125 +++++------ drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_punit_ipc.c | 303 ++++++++++---------------- drivers/platform/x86/intel_telemetry_pltdrv.c | 97 +++++---- 4 files changed, 223 insertions(+), 303 deletions(-)
Changes since v4:
* None
Changes since v2:
* Added unique name to PUNIT BIOS, GTD, & ISP regmaps.
* Added intel_ipc_dev_put() support.
Changes since v1:
* Removed custom APIs.
* Cleaned up PUNIT IPC user drivers to use APIs provided by generic IPC driver.
arch/x86/include/asm/intel_punit_ipc.h +54 -71
@@ -1,10 +1,8 @@ #ifndef _ASM_X86_INTEL_PUNIT_IPC_H_ #define _ASM_X86_INTEL_PUNIT_IPC_H_ -/* - * Three types of 8bit P-Unit IPC commands are supported, - * bit[7:6]: [00]: BIOS; [01]: GTD; [10]: ISPD. - */ +#include <linux/platform_data/x86/intel_ipc_dev.h> + typedef enum { BIOS_IPC = 0, GTDRIVER_IPC,
@@ -12,61 +10,60 @@ typedef enum {RESERVED_IPC , } IPC_TYPE; -#define IPC_TYPE_OFFSET 6 -#define IPC_PUNIT_BIOS_CMD_BASE (BIOS_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_GTD_CMD_BASE (GTDDRIVER_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_ISPD_CMD_BASE (ISPDRIVER_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_CMD_TYPE_MASK (RESERVED_IPC << IPC_TYPE_OFFSET) +#define PUNIT_BIOS_IPC_DEV "punit_bios_ipc" +#define PUNIT_GTD_IPC_DEV "punit_gtd_ipc" +#define PUNIT_ISP_IPC_DEV "punit_isp_ipc" +#define PUNIT_PARAM_LEN 3/* BIOS => Pcode commands */ -#define IPC_PUNIT_BIOS_ZERO (IPC_PUNIT_BIOS_CMD_BASE | 0x00) -#define IPC_PUNIT_BIOS_VR_INTERFACE (IPC_PUNIT_BIOS_CMD_BASE | 0x01) -#define IPC_PUNIT_BIOS_READ_PCS (IPC_PUNIT_BIOS_CMD_BASE | 0x02) -#define IPC_PUNIT_BIOS_WRITE_PCS (IPC_PUNIT_BIOS_CMD_BASE | 0x03) -#define IPC_PUNIT_BIOS_READ_PCU_CONFIG (IPC_PUNIT_BIOS_CMD_BASE | 0x04) -#define IPC_PUNIT_BIOS_WRITE_PCU_CONFIG (IPC_PUNIT_BIOS_CMD_BASE | 0x05) -#define IPC_PUNIT_BIOS_READ_PL1_SETTING (IPC_PUNIT_BIOS_CMD_BASE | 0x06) -#define IPC_PUNIT_BIOS_WRITE_PL1_SETTING (IPC_PUNIT_BIOS_CMD_BASE | 0x07) -#define IPC_PUNIT_BIOS_TRIGGER_VDD_RAM (IPC_PUNIT_BIOS_CMD_BASE | 0x08) -#define IPC_PUNIT_BIOS_READ_TELE_INFO (IPC_PUNIT_BIOS_CMD_BASE | 0x09) -#define IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x0a) -#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x0b) -#define IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x0c) -#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x0d) -#define IPC_PUNIT_BIOS_READ_TELE_TRACE (IPC_PUNIT_BIOS_CMD_BASE | 0x0e) -#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE (IPC_PUNIT_BIOS_CMD_BASE | 0x0f) -#define IPC_PUNIT_BIOS_READ_TELE_EVENT (IPC_PUNIT_BIOS_CMD_BASE | 0x10) -#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT (IPC_PUNIT_BIOS_CMD_BASE | 0x11) -#define IPC_PUNIT_BIOS_READ_MODULE_TEMP (IPC_PUNIT_BIOS_CMD_BASE | 0x12) -#define IPC_PUNIT_BIOS_RESERVED (IPC_PUNIT_BIOS_CMD_BASE | 0x13) -#define IPC_PUNIT_BIOS_READ_VOLTAGE_OVER (IPC_PUNIT_BIOS_CMD_BASE | 0x14) -#define IPC_PUNIT_BIOS_WRITE_VOLTAGE_OVER (IPC_PUNIT_BIOS_CMD_BASE | 0x15) -#define IPC_PUNIT_BIOS_READ_RATIO_OVER (IPC_PUNIT_BIOS_CMD_BASE | 0x16) -#define IPC_PUNIT_BIOS_WRITE_RATIO_OVER (IPC_PUNIT_BIOS_CMD_BASE | 0x17) -#define IPC_PUNIT_BIOS_READ_VF_GL_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x18) -#define IPC_PUNIT_BIOS_WRITE_VF_GL_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x19) -#define IPC_PUNIT_BIOS_READ_FM_SOC_TEMP_THRESH (IPC_PUNIT_BIOS_CMD_BASE | 0x1a) -#define IPC_PUNIT_BIOS_WRITE_FM_SOC_TEMP_THRESH (IPC_PUNIT_BIOS_CMD_BASE | 0x1b) +#define IPC_PUNIT_BIOS_ZERO (0x00) +#define IPC_PUNIT_BIOS_VR_INTERFACE (0x01) +#define IPC_PUNIT_BIOS_READ_PCS (0x02) +#define IPC_PUNIT_BIOS_WRITE_PCS (0x03) +#define IPC_PUNIT_BIOS_READ_PCU_CONFIG (0x04) +#define IPC_PUNIT_BIOS_WRITE_PCU_CONFIG (0x05) +#define IPC_PUNIT_BIOS_READ_PL1_SETTING (0x06) +#define IPC_PUNIT_BIOS_WRITE_PL1_SETTING (0x07) +#define IPC_PUNIT_BIOS_TRIGGER_VDD_RAM (0x08) +#define IPC_PUNIT_BIOS_READ_TELE_INFO (0x09) +#define IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL (0x0a) +#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL (0x0b) +#define IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL (0x0c) +#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL (0x0d) +#define IPC_PUNIT_BIOS_READ_TELE_TRACE (0x0e) +#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE (0x0f) +#define IPC_PUNIT_BIOS_READ_TELE_EVENT (0x10) +#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT (0x11) +#define IPC_PUNIT_BIOS_READ_MODULE_TEMP (0x12) +#define IPC_PUNIT_BIOS_RESERVED (0x13) +#define IPC_PUNIT_BIOS_READ_VOLTAGE_OVER (0x14) +#define IPC_PUNIT_BIOS_WRITE_VOLTAGE_OVER (0x15) +#define IPC_PUNIT_BIOS_READ_RATIO_OVER (0x16) +#define IPC_PUNIT_BIOS_WRITE_RATIO_OVER (0x17) +#define IPC_PUNIT_BIOS_READ_VF_GL_CTRL (0x18) +#define IPC_PUNIT_BIOS_WRITE_VF_GL_CTRL (0x19) +#define IPC_PUNIT_BIOS_READ_FM_SOC_TEMP_THRESH (0x1a) +#define IPC_PUNIT_BIOS_WRITE_FM_SOC_TEMP_THRESH (0x1b)/* GT Driver => Pcode commands */ -#define IPC_PUNIT_GTD_ZERO (IPC_PUNIT_GTD_CMD_BASE | 0x00) -#define IPC_PUNIT_GTD_CONFIG (IPC_PUNIT_GTD_CMD_BASE | 0x01) -#define IPC_PUNIT_GTD_READ_ICCP_LIC_CDYN_SCAL (IPC_PUNIT_GTD_CMD_BASE | 0x02) -#define IPC_PUNIT_GTD_WRITE_ICCP_LIC_CDYN_SCAL (IPC_PUNIT_GTD_CMD_BASE | 0x03) -#define IPC_PUNIT_GTD_GET_WM_VAL (IPC_PUNIT_GTD_CMD_BASE | 0x06) -#define IPC_PUNIT_GTD_WRITE_CONFIG_WISHREQ (IPC_PUNIT_GTD_CMD_BASE | 0x07) -#define IPC_PUNIT_GTD_READ_REQ_DUTY_CYCLE (IPC_PUNIT_GTD_CMD_BASE | 0x16) -#define IPC_PUNIT_GTD_DIS_VOL_FREQ_CHG_REQUEST (IPC_PUNIT_GTD_CMD_BASE | 0x17) -#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_CTRL (IPC_PUNIT_GTD_CMD_BASE | 0x1a) -#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_TUNING (IPC_PUNIT_GTD_CMD_BASE | 0x1c) +#define IPC_PUNIT_GTD_ZERO (0x00) +#define IPC_PUNIT_GTD_CONFIG (0x01) +#define IPC_PUNIT_GTD_READ_ICCP_LIC_CDYN_SCAL (0x02) +#define IPC_PUNIT_GTD_WRITE_ICCP_LIC_CDYN_SCAL (0x03) +#define IPC_PUNIT_GTD_GET_WM_VAL (0x06) +#define IPC_PUNIT_GTD_WRITE_CONFIG_WISHREQ (0x07) +#define IPC_PUNIT_GTD_READ_REQ_DUTY_CYCLE (0x16) +#define IPC_PUNIT_GTD_DIS_VOL_FREQ_CHG_REQUEST (0x17) +#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_CTRL (0x1a) +#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_TUNING (0x1c)/* ISP Driver => Pcode commands */ -#define IPC_PUNIT_ISPD_ZERO (IPC_PUNIT_ISPD_CMD_BASE | 0x00) -#define IPC_PUNIT_ISPD_CONFIG (IPC_PUNIT_ISPD_CMD_BASE | 0x01) -#define IPC_PUNIT_ISPD_GET_ISP_LTR_VAL (IPC_PUNIT_ISPD_CMD_BASE | 0x02) -#define IPC_PUNIT_ISPD_ACCESS_IU_FREQ_BOUNDS (IPC_PUNIT_ISPD_CMD_BASE | 0x03) -#define IPC_PUNIT_ISPD_READ_CDYN_LEVEL (IPC_PUNIT_ISPD_CMD_BASE | 0x04) -#define IPC_PUNIT_ISPD_WRITE_CDYN_LEVEL (IPC_PUNIT_ISPD_CMD_BASE | 0x05) +#define IPC_PUNIT_ISPD_ZERO (0x00) +#define IPC_PUNIT_ISPD_CONFIG (0x01) +#define IPC_PUNIT_ISPD_GET_ISP_LTR_VAL (0x02) +#define IPC_PUNIT_ISPD_ACCESS_IU_FREQ_BOUNDS (0x03) +#define IPC_PUNIT_ISPD_READ_CDYN_LEVEL (0x04) +#define IPC_PUNIT_ISPD_WRITE_CDYN_LEVEL (0x05)/* Error codes */ #define IPC_PUNIT_ERR_SUCCESS 0
@@ -77,25 +74,11 @@ typedef enum {#define IPC_PUNIT_ERR_INVALID_VR_ID 5#define IPC_PUNIT_ERR_VR_ERR 6 -#if IS_ENABLED (CONFIG_INTEL_PUNIT_IPC ) - -int intel_punit_ipc_simple_command (int cmd,int para1,int para2); -int intel_punit_ipc_command (u32 cmd,u32 para1,u32 para2,u32 *in,u32 *out); - -#else - -static inline int intel_punit_ipc_simple_command (int cmd, -int para1,int para2) +static inline void punit_cmd_init (u32 *cmd,u32 param1,u32 param2,u32 param3) { -return -ENODEV ; + cmd[0 ] = param1; + cmd[1 ] = param2; + cmd[2 ] = param3; } -static inline int intel_punit_ipc_command (u32 cmd,u32 para1,u32 para2, -u32 *in,u32 *out) -{ -return -ENODEV ; -} - -#endif /* CONFIG_INTEL_PUNIT_IPC */ -#endif
drivers/platform/x86/Kconfig +1 -0
@@ -1096,6 +1096,7 @@ config SURFACE_3_BUTTON config INTEL_PUNIT_IPC tristate "Intel P-Unit IPC Driver" + select REGMAP_MMIO ---help--- This driver provides support for Intel P-Unit Mailbox IPC mechanism, which is used to bridge the communications between kernel and P-Unit.
drivers/platform/x86/intel_punit_ipc.c +110 -193
366 lines not on this page · raw message
drivers/platform/x86/intel_telemetry_pltdrv.c +58 -39
231 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC v5 7/8 platform/x86: intel_pmc_ipc: Use generic Intel IPC device calls
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
Removed redundant IPC helper functions and refactored the driver to use generic IPC device driver APIs. Also, cleaned up the driver to minimize the usage of global variable ipcdev by propogating the struct intel_pmc_ipc_dev pointer or by getting it from device private data.
This patch also cleans-up PMC IPC user drivers(intel_telemetry_pltdrv.c, intel_soc_pmic_bxtwc.c) to use APIs provided by generic IPC driver.
--- arch/x86/include/asm/intel_pmc_ipc.h | 37 +-- drivers/mfd/intel_soc_pmic_bxtwc.c | 21 +- drivers/platform/x86/intel_pmc_ipc.c | 393 ++++++++++---------------- drivers/platform/x86/intel_telemetry_pltdrv.c | 119 ++++---- include/linux/mfd/intel_soc_pmic.h | 2 + 5 files changed, 238 insertions(+), 334 deletions(-)
Changes since v4:
* None
Changes since v3:
* Added unique name to PMC regmaps.
* Added support to clear interrupt bit.
* Added intel_ipc_dev_put() support.
Changes since v1:
* Removed custom APIs.
* Cleaned up PMC IPC user drivers to use APIs provided by generic IPC driver.
arch/x86/include/asm/intel_pmc_ipc.h +13 -24
@@ -1,10 +1,15 @@#ifndef _ASM_X86_INTEL_PMC_IPC_H_#define _ASM_X86_INTEL_PMC_IPC_H_ +#include <linux/platform_data/x86/intel_ipc_dev.h> + +#define INTEL_PMC_IPC_DEV "intel_pmc_ipc" +#define PMC_PARAM_LEN 2 +/* Commands */ #define PMC_IPC_PMIC_ACCESS 0xFF -#define PMC_IPC_PMIC_ACCESS_READ 0x0 -#define PMC_IPC_PMIC_ACCESS_WRITE 0x1 +#define PMC_IPC_PMIC_ACCESS_READ 0x0 +#define PMC_IPC_PMIC_ACCESS_WRITE 0x1#define PMC_IPC_USB_PWR_CTRL 0xF0#define PMC_IPC_PMIC_BLACKLIST_SEL 0xEF#define PMC_IPC_PHY_CONFIG 0xEE
@@ -28,13 +33,14 @@#define PMC_GCR_TELEM_DEEP_S0IX_REG 0x78#define PMC_GCR_TELEM_SHLW_S0IX_REG 0x80 +static inline void pmc_cmd_init (u32 *cmd,u32 param1,u32 param2) +{ + cmd[0 ] = param1; + cmd[1 ] = param2; +} +#if IS_ENABLED (CONFIG_INTEL_PMC_IPC ) -int intel_pmc_ipc_simple_command (int cmd,int sub); -int intel_pmc_ipc_raw_cmd (u32 cmd,u32 sub,u8 *in,u32 inlen, -u32 *out,u32 outlen,u32 dptr,u32 sptr); -int intel_pmc_ipc_command (u32 cmd,u32 sub,u8 *in,u32 inlen, -u32 *out,u32 outlen);int intel_pmc_s0ix_counter_read (u64 *data);int intel_pmc_gcr_read (u32 offset,u32 *data);int intel_pmc_gcr_write (u32 offset,u32 data);
@@ -42,23 +48,6 @@ int intel_pmc_gcr_update(u32 offset, u32 mask, u32 val);#else -static inline int intel_pmc_ipc_simple_command (int cmd,int sub) -{ -return -EINVAL ; -} - -static inline int intel_pmc_ipc_raw_cmd (u32 cmd,u32 sub,u8 *in,u32 inlen, -u32 *out,u32 outlen,u32 dptr,u32 sptr) -{ -return -EINVAL ; -} - -static inline int intel_pmc_ipc_command (u32 cmd,u32 sub,u8 *in,u32 inlen, -u32 *out,u32 outlen) -{ -return -EINVAL ; -} -static inline int intel_pmc_s0ix_counter_read (u64 *data) {return -EINVAL ;
drivers/mfd/intel_soc_pmic_bxtwc.c +15 -6
@@ -271,6 +271,8 @@ static int regmap_ipc_byte_reg_read(void *context, unsigned int reg,u8 ipc_in[2 ];u8 ipc_out[4 ];struct intel_soc_pmic *pmic = context; +u32 cmd[PMC_PARAM_LEN ] = {PMC_IPC_PMIC_ACCESS , +PMC_IPC_PMIC_ACCESS_READ };if (!pmic)return -EINVAL ;
@@ -284,9 +286,8 @@ static int regmap_ipc_byte_reg_read(void *context, unsigned int reg, ipc_in[0 ] = reg; ipc_in[1 ] = i2c_addr; - ret =intel_pmc_ipc_command (PMC_IPC_PMIC_ACCESS , -PMC_IPC_PMIC_ACCESS_READ , - ipc_in,sizeof (ipc_in), (u32 *)ipc_out,1 ); + ret =ipc_dev_raw_cmd (pmic->ipc_dev, cmd,PMC_PARAM_LEN , ipc_in, +sizeof (ipc_in), (u32 *)ipc_out,1 ,0 ,0 );if (ret) {dev_err (pmic->dev,"Failed to read from PMIC\n" );return ret;
@@ -303,6 +304,8 @@ static int regmap_ipc_byte_reg_write(void *context, unsigned int reg,int i2c_addr;u8 ipc_in[3 ];struct intel_soc_pmic *pmic = context; +u32 cmd[PMC_PARAM_LEN ] = {PMC_IPC_PMIC_ACCESS , +PMC_IPC_PMIC_ACCESS_WRITE };if (!pmic)return -EINVAL ;
@@ -317,9 +320,8 @@ static int regmap_ipc_byte_reg_write(void *context, unsigned int reg, ipc_in[0 ] = reg; ipc_in[1 ] = i2c_addr; ipc_in[2 ] = val; - ret =intel_pmc_ipc_command (PMC_IPC_PMIC_ACCESS , -PMC_IPC_PMIC_ACCESS_WRITE , - ipc_in,sizeof (ipc_in),NULL ,0 ); + ret =ipc_dev_raw_cmd (pmic->ipc_dev, cmd,PMC_PARAM_LEN , ipc_in, +sizeof (ipc_in),NULL ,0 ,0 ,0 );if (ret) {dev_err (pmic->dev,"Failed to write to PMIC\n" );return ret;
@@ -445,6 +447,10 @@ static int bxtwc_probe(struct platform_device *pdev)if (!pmic)return -ENOMEM ; + pmic->ipc_dev =intel_ipc_dev_get (INTEL_PMC_IPC_DEV ); +if (IS_ERR_OR_NULL (pmic->ipc_dev)) +return PTR_ERR (pmic->ipc_dev); + ret =platform_get_irq (pdev,0 );if (ret <0 ) {dev_err (&pdev->dev,"Invalid IRQ\n" );
@@ -562,7 +568,10 @@ static int bxtwc_probe(struct platform_device *pdev)static int bxtwc_remove (struct platform_device *pdev) { +struct intel_soc_pmic *pmic =dev_get_drvdata (&pdev->dev); +sysfs_remove_group (&pdev->dev.kobj, &bxtwc_group); +intel_ipc_dev_put (pmic->ipc_dev);return 0 ; }
drivers/platform/x86/intel_pmc_ipc.c +149 -244
538 lines not on this page · raw message
drivers/platform/x86/intel_telemetry_pltdrv.c +59 -60
239 lines not on this page · raw message
include/linux/mfd/intel_soc_pmic.h +2 -0
@@ -20,6 +20,7 @@#define __INTEL_SOC_PMIC_H__#include <linux/regmap.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> struct intel_soc_pmic {int irq;
@@ -31,6 +32,7 @@ struct intel_soc_pmic {struct regmap_irq_chip_data *irq_chip_data_chgr;struct regmap_irq_chip_data *irq_chip_data_crit;struct device *dev; + struct intel_ipc_dev *ipc_dev; };#endif /* __INTEL_SOC_PMIC_H__ */
Signature · 1 line
2.7.4
RFC v5 8/8 platform/x86: intel_scu_ipc: Use generic Intel IPC device calls
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
Removed redundant IPC helper functions and refactored the driver to use generic IPC device driver APIs.
This patch also cleans-up SCU IPC user drivers(rtc-mrst.c, intel-mid_wdt.c, intel-mid_wdt.c, intel-mid.c) to use APIs provided by generic IPC driver.
--- arch/x86/include/asm/intel_scu_ipc.h | 23 +- arch/x86/platform/intel-mid/intel-mid.c | 15 +- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_scu_ipc.c | 483 +++++++++++++------------------- drivers/rtc/rtc-mrst.c | 16 +- drivers/watchdog/intel-mid_wdt.c | 12 +- drivers/watchdog/intel_scu_watchdog.c | 18 +- 7 files changed, 256 insertions(+), 312 deletions(-)
Changes since v4:
* None
Changes since v3:
* Added intel_ipc_dev_put() support.
arch/x86/include/asm/intel_scu_ipc.h +13 -10
@@ -14,9 +14,19 @@#define IPCMSG_COLD_BOOT 0xF3#define IPCMSG_VRTC 0xFA/* Set vRTC device */ -/* Command id associated with message IPCMSG_VRTC */ -#define IPC_CMD_VRTC_SETTIME 1/* Set time */ -#define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ + +/* Command id associated with message IPCMSG_VRTC */ +#define IPC_CMD_VRTC_SETTIME 1/* Set time */ +#define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ + +#define INTEL_SCU_IPC_DEV "intel_scu_ipc" +#define SCU_PARAM_LEN 2 + +static inline void scu_cmd_init (u32 *cmd,u32 param1,u32 param2) +{ + cmd[0 ] = param1; + cmd[1 ] = param2; +}/* Read single register */ int intel_scu_ipc_ioread8 (u16 addr,u8 *data);
@@ -45,13 +55,6 @@ int intel_scu_ipc_writev(u16 *addr, u8 *data, int len);/* Update single register based on the mask */ int intel_scu_ipc_update_register (u16 addr,u8 data,u8 mask); -/* Issue commands to the SCU with or without data */ -int intel_scu_ipc_simple_command (int cmd,int sub); -int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen, -u32 *out,int outlen); -int intel_scu_ipc_raw_command (int cmd,int sub,u8 *in,int inlen, -u32 *out,int outlen,u32 dptr,u32 sptr); -/* I2C control api */ int intel_scu_ipc_i2c_cntrl (u32 addr,u32 *data);
arch/x86/platform/intel-mid/intel-mid.c +13 -2
@@ -22,6 +22,7 @@#include <linux/irq.h> #include <linux/export.h> #include <linux/notifier.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include <asm/setup.h> #include <asm/mpspec_def.h>
@@ -70,16 +71,26 @@ EXPORT_SYMBOL_GPL(__intel_mid_cpu_chip);static void intel_mid_power_off (void ) { +struct intel_ipc_dev *ipc_dev; +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_OFF ,1 }; +/* Shut down South Complex via PWRMU */ intel_mid_pwr_power_off (); + ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV );/* Only for Tangier, the rest will ignore this command */ -intel_scu_ipc_simple_command (IPCMSG_COLD_OFF ,1 ); +ipc_dev_simple_cmd (ipc_dev, cmds,SCU_PARAM_LEN ); +intel_ipc_dev_put (ipc_dev); };static void intel_mid_reboot (void ) { -intel_scu_ipc_simple_command (IPCMSG_COLD_BOOT ,0 ); +struct intel_ipc_dev *ipc_dev; +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_BOOT ,0 }; + + ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV ); +ipc_dev_simple_cmd (ipc_dev, cmds,SCU_PARAM_LEN ); +intel_ipc_dev_put (ipc_dev); }static unsigned long __init intel_mid_calibrate_tsc (void )
drivers/platform/x86/Kconfig +1 -0
@@ -863,6 +863,7 @@ config INTEL_VBTN config INTEL_SCU_IPC bool "Intel SCU IPC Support" depends on X86_INTEL_MID + select REGMAP_MMIO default y ---help--- IPC is used to bridge the communications between kernel and SCU on
drivers/platform/x86/intel_scu_ipc.c +195 -288
594 lines not on this page · raw message
drivers/rtc/rtc-mrst.c +12 -4
@@ -36,6 +36,7 @@#include <linux/module.h> #include <linux/init.h> #include <linux/sfi.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include <asm/intel_scu_ipc.h> #include <asm/intel-mid.h>
@@ -46,6 +47,7 @@ struct mrst_rtc {struct device *dev;int irq;struct resource *iomem; +struct intel_ipc_dev *ipc_dev;u8 enabled_wake;u8 suspend_ctrl;
@@ -110,10 +112,11 @@ static int mrst_read_time(struct device *dev, struct rtc_time *time)static int mrst_set_time (struct device *dev,struct rtc_time *time) { -int ret;unsigned long flags;unsigned char mon, day, hrs, min, sec;unsigned int yrs; +struct mrst_rtc *mrst =dev_get_drvdata (dev); +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_VRTC ,IPC_CMD_VRTC_SETTIME }; yrs = time->tm_year; mon = time->tm_mon +1 ;/* tm_mon starts at zero */
@@ -137,8 +140,7 @@ static int mrst_set_time(struct device *dev, struct rtc_time *time)spin_unlock_irqrestore (&rtc_lock, flags); - ret =intel_scu_ipc_simple_command (IPCMSG_VRTC ,IPC_CMD_VRTC_SETTIME ); -return ret; +return ipc_dev_simple_cmd (mrst->ipc_dev, cmds,SCU_PARAM_LEN ); }static int mrst_read_alarm (struct device *dev,struct rtc_wkalrm *t)
@@ -210,6 +212,7 @@ static int mrst_set_alarm(struct device *dev, struct rtc_wkalrm *t)struct mrst_rtc *mrst =dev_get_drvdata (dev);unsigned char hrs, min, sec;int ret =0 ; +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_VRTC ,IPC_CMD_VRTC_SETALARM };if (!mrst->irq)return -EIO ;
@@ -229,7 +232,7 @@ static int mrst_set_alarm(struct device *dev, struct rtc_wkalrm *t)spin_unlock_irq (&rtc_lock); - ret =intel_scu_ipc_simple_command (IPCMSG_VRTC ,IPC_CMD_VRTC_SETALARM ); + ret =ipc_dev_simple_cmd (mrst->ipc_dev, cmds,SCU_PARAM_LEN );if (ret)return ret;
@@ -329,6 +332,10 @@ static int vrtc_mrst_do_probe(struct device *dev, struct resource *iomem,if (!iomem)return -ENODEV ; + mrst_rtc.ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV ); +if (IS_ERR_OR_NULL (mrst_rtc.ipc_dev)) +return PTR_ERR (mrst_rtc.ipc_dev); + iomem =request_mem_region (iomem->start,resource_size (iomem), driver_name);if (!iomem) {
@@ -394,6 +401,7 @@ static void rtc_mrst_do_remove(struct device *dev)rtc_mrst_do_shutdown (); +intel_ipc_dev_put (mrst->ipc_dev);if (mrst->irq)free_irq (mrst->irq, mrst->rtc);
drivers/watchdog/intel-mid_wdt.c +11 -1
@@ -18,6 +18,7 @@#include <linux/platform_device.h> #include <linux/watchdog.h> #include <linux/platform_data/intel-mid_wdt.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include <asm/intel_scu_ipc.h> #include <asm/intel-mid.h>
@@ -29,6 +30,8 @@#define MID_WDT_TIMEOUT_MAX 170#define MID_WDT_DEFAULT_TIMEOUT 90 +static struct intel_ipc_dev *scu_ipc_dev; +/* SCU watchdog messages */ enum {SCU_WATCHDOG_START =0 ,
@@ -38,7 +41,10 @@ enum {static inline int wdt_command (int sub,u32 *in,int inlen) { -return intel_scu_ipc_command (IPC_WATCHDOG , sub, in, inlen,NULL ,0 ); +u32 cmds[SCU_PARAM_LEN ] = {IPC_WATCHDOG , sub}; + +return ipc_dev_cmd (scu_ipc_dev, cmds,SCU_PARAM_LEN , in, + inlen,NULL ,0 ); }static int wdt_start (struct watchdog_device *wd)
@@ -129,6 +135,10 @@ static int mid_wdt_probe(struct platform_device *pdev)if (!wdt_dev)return -ENOMEM ; + scu_ipc_dev =devm_intel_ipc_dev_get (&pdev->dev,INTEL_SCU_IPC_DEV ); +if (IS_ERR_OR_NULL (scu_ipc_dev)) +return PTR_ERR (scu_ipc_dev); + wdt_dev->info = &mid_wdt_info; wdt_dev->ops = &mid_wdt_ops; wdt_dev->min_timeout =MID_WDT_TIMEOUT_MIN ;
drivers/watchdog/intel_scu_watchdog.c +11 -7
@@ -49,6 +49,7 @@#include <asm/intel_scu_ipc.h> #include <asm/apb_timer.h> #include <asm/intel-mid.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include "intel_scu_watchdog.h"
@@ -94,6 +95,8 @@ MODULE_PARM_DESC(force_boot,static struct intel_scu_watchdog_dev watchdog_device; +static struct intel_ipc_dev *scu_ipc_dev; +/* Forces restart, if force_reboot is set */ static void watchdog_fire (void ) {
@@ -128,18 +131,14 @@ static int watchdog_set_ipc(int soft_threshold, int threshold)u32 *ipc_wbuf;u8 cbuf[16 ] = {'\0' };int ipc_ret =0 ; +u32 cmds[SCU_PARAM_LEN ] = {IPC_SET_WATCHDOG_TIMER ,0 }; ipc_wbuf = (u32 *)&cbuf; ipc_wbuf[0 ] = soft_threshold; ipc_wbuf[1 ] = threshold; - ipc_ret =intel_scu_ipc_command ( -IPC_SET_WATCHDOG_TIMER , -0 , - ipc_wbuf, -2 , -NULL , -0 ); + ipc_ret =ipc_dev_cmd (scu_ipc_dev, cmds,SCU_PARAM_LEN , ipc_wbuf, +2 ,NULL ,0 );if (ipc_ret !=0 )pr_err ("Error setting SCU watchdog timer: %x\n" , ipc_ret);
@@ -460,6 +459,10 @@ static int __init intel_scu_watchdog_init(void)if (check_timer_margin (timer_margin))return -EINVAL ; + scu_ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV ); +if (IS_ERR_OR_NULL (scu_ipc_dev)) +return PTR_ERR (scu_ipc_dev); + watchdog_device.timer_tbl_ptr =sfi_get_mtmr (sfi_mtimer_num-1 );if (watchdog_device.timer_tbl_ptr ==NULL ) {
@@ -550,6 +553,7 @@ static void __exit intel_scu_watchdog_exit(void) {misc_deregister (&watchdog_device.miscdev); +intel_ipc_dev_put (scu_ipc_dev);unregister_reboot_notifier (&watchdog_device.intel_scu_notifier);/* disable the timer */ iowrite32 (0x00000002 , watchdog_device.timer_control_addr);
Signature · 1 line
2.7.4
RFC v5 2/8 platform/x86: intel_pmc_ipc: Use MFD framework to create dependent devices
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
Currently, we have lot of repetitive code in dependent device resource allocation and device creation handling code. This logic can be improved if we use MFD framework for dependent device creation. This patch adds this support.
--- drivers/platform/x86/intel_pmc_ipc.c | 394 ++++++++++++----------------------- 1 file changed, 137 insertions(+), 257 deletions(-)
Changes since v4:
* Changed the order of patches in this patchlist.
Changes since v3:
* Changed PLATFORM_DEVID_AUTO to PLATFORM_DEVID_NONE in mfd device creation.
* Fixed error in resource initalization logic in ipc_create_punit_device.
* Removed mfd cell id initialization.
drivers/platform/x86/intel_pmc_ipc.c +137 -257
@@ -34,6 +34,7 @@#include <linux/acpi.h> #include <linux/io-64-nonatomic-lo-hi.h> #include <linux/spinlock.h> +#include <linux/mfd/core.h> #include <asm/intel_pmc_ipc.h>
@@ -88,6 +89,7 @@#define PLAT_RESOURCE_ISP_IFACE_INDEX 5#define PLAT_RESOURCE_GTD_DATA_INDEX 6#define PLAT_RESOURCE_GTD_IFACE_INDEX 7 +#define PLAT_RESOURCE_MEM_MAX_INDEX 8#define PLAT_RESOURCE_ACPI_IO_INDEX 0/*
@@ -106,8 +108,6 @@#define TELEM_SSRAM_SIZE 240#define TELEM_PMC_SSRAM_OFFSET 0x1B00#define TELEM_PUNIT_SSRAM_OFFSET 0x1A00 -#define TCO_PMC_OFFSET 0x8 -#define TCO_PMC_SIZE 0x4/* PMC register bit definitions */
@@ -124,26 +124,10 @@ static struct intel_pmc_ipc_dev {int cmd;struct completion cmd_complete; -/* The following PMC BARs share the same ACPI device with the IPC */ -resource_size_t acpi_io_base; -int acpi_io_size; -struct platform_device *tco_dev; -/* gcr */ void __iomem *gcr_mem_base;bool has_gcr_regs;spinlock_t gcr_lock; - -/* punit */ -struct platform_device *punit_dev; - -/* Telemetry */ -resource_size_t telem_pmc_ssram_base; -resource_size_t telem_punit_ssram_base; -int telem_pmc_ssram_size; -int telem_punit_ssram_size; -u8 telem_res_inval; -struct platform_device *telemetry_dev; } ipcdev;static char *ipc_err_sources[] = {
@@ -593,44 +577,6 @@ static const struct attribute_group intel_ipc_group = { .attrs = intel_ipc_attrs, }; -static struct resource punit_res_array[] = { -/* Punit BIOS */ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -/* Punit ISP */ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -/* Punit GTD */ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -}; - -#define TCO_RESOURCE_ACPI_IO 0 -#define TCO_RESOURCE_SMI_EN_IO 1 -#define TCO_RESOURCE_GCR_MEM 2 -static struct resource tco_res[] = { -/* ACPI - TCO */ - { - .flags =IORESOURCE_IO , - }, -/* ACPI - SMI */ - { - .flags =IORESOURCE_IO , - }, -}; -static struct itco_wdt_platform_data tco_info = { .name ="Apollo Lake SoC" , .version =5 ,
@@ -638,234 +584,179 @@ static struct itco_wdt_platform_data tco_info = { .update_no_reboot_bit = update_no_reboot_bit, }; -#define TELEMETRY_RESOURCE_PUNIT_SSRAM 0 -#define TELEMETRY_RESOURCE_PMC_SSRAM 1 -static struct resource telemetry_res[] = { -/*Telemetry*/ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -}; - -static int ipc_create_punit_device (void ) +static int ipc_create_punit_device (struct platform_device *pdev) { -struct platform_device *pdev; -const struct platform_device_info pdevinfo = { - .parent = ipcdev.dev, - .name =PUNIT_DEVICE_NAME , - .id =-1 , - .res = punit_res_array, - .num_res =ARRAY_SIZE (punit_res_array), +struct resource *res; +static struct resource punit_res[PLAT_RESOURCE_MEM_MAX_INDEX ]; +static struct mfd_cell punit_cell; +int mindex, pindex =0 ; + +for (mindex =0 ; mindex <=PLAT_RESOURCE_MEM_MAX_INDEX ; mindex++) { + + res =platform_get_resource (pdev,IORESOURCE_MEM , mindex); + +switch (mindex) { +/* Get PUNIT resources */ +case PLAT_RESOURCE_BIOS_DATA_INDEX : +case PLAT_RESOURCE_BIOS_IFACE_INDEX : +/* BIOS resources are required, so return error if not +* available */ +if (!res) { +dev_err (&pdev->dev, +"Failed to get punit mem resource %d\n" , + pindex); +return -ENXIO ; + } +case PLAT_RESOURCE_ISP_DATA_INDEX : +case PLAT_RESOURCE_ISP_IFACE_INDEX : +case PLAT_RESOURCE_GTD_DATA_INDEX : +case PLAT_RESOURCE_GTD_IFACE_INDEX : +/* if valid resource found, copy the resource to PUNIT +* resource */ +if (res) +memcpy (&punit_res[pindex], res,sizeof (*res)); + punit_res[pindex].flags =IORESOURCE_MEM ; +dev_dbg (&pdev->dev,"PUNIT memory res: %pR\n" , + &punit_res[pindex]); + pindex++; +break ; }; + } - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.punit_dev = pdev; +/* Create PUNIT IPC MFD cell */ + punit_cell.name =PUNIT_DEVICE_NAME ; + punit_cell.num_resources =ARRAY_SIZE (punit_res); + punit_cell.resources = punit_res; + punit_cell.ignore_resource_conflicts =1 ; -return 0 ; +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &punit_cell,1 ,NULL ,0 ,NULL ); } -static int ipc_create_tco_device (void ) +static int ipc_create_wdt_device (struct platform_device *pdev) { -struct platform_device *pdev; +static struct resource wdt_ipc_res[2 ];struct resource *res; -const struct platform_device_info pdevinfo = { - .parent = ipcdev.dev, - .name =TCO_DEVICE_NAME , - .id =-1 , - .res = tco_res, - .num_res =ARRAY_SIZE (tco_res), - .data = &tco_info, - .size_data =sizeof (tco_info), - }; +static struct mfd_cell wdt_cell; - res = tco_res +TCO_RESOURCE_ACPI_IO ; - res->start = ipcdev.acpi_io_base +TCO_BASE_OFFSET ; - res->end = res->start +TCO_REGS_SIZE -1 ; +/* If we have ACPI based watchdog use that instead, othewise create +* a MFD cell for iTCO watchdog*/ +if (acpi_has_watchdog ()) +return 0 ; - res = tco_res +TCO_RESOURCE_SMI_EN_IO ; - res->start = ipcdev.acpi_io_base +SMI_EN_OFFSET ; - res->end = res->start +SMI_EN_SIZE -1 ; - - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.tco_dev = pdev; +/* Get iTCO watchdog resources */ + res =platform_get_resource (pdev,IORESOURCE_IO , +PLAT_RESOURCE_ACPI_IO_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get wdt resource\n" ); +return -ENXIO ; + } -return 0 ; + wdt_ipc_res[0 ].start = res->start +TCO_BASE_OFFSET ; + wdt_ipc_res[0 ].end = res->start +TCO_BASE_OFFSET + +TCO_REGS_SIZE -1 ; + wdt_ipc_res[0 ].flags =IORESOURCE_IO ; + wdt_ipc_res[1 ].start = res->start +SMI_EN_OFFSET ; + wdt_ipc_res[1 ].end = res->start + +SMI_EN_OFFSET +SMI_EN_SIZE -1 ; + wdt_ipc_res[1 ].flags =IORESOURCE_IO ; + +dev_dbg (&pdev->dev,"watchdog res 0: %pR\n" , + &wdt_ipc_res[0 ]); +dev_dbg (&pdev->dev,"watchdog res 1: %pR\n" , + &wdt_ipc_res[1 ]); + + wdt_cell.name =TCO_DEVICE_NAME ; + wdt_cell.platform_data = &tco_info; + wdt_cell.pdata_size =sizeof (tco_info); + wdt_cell.num_resources =ARRAY_SIZE (wdt_ipc_res); + wdt_cell.resources = wdt_ipc_res; + wdt_cell.ignore_resource_conflicts =1 ; + +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &wdt_cell,1 ,NULL ,0 ,NULL ); } -static int ipc_create_telemetry_device (void ) +static int ipc_create_telemetry_device (struct platform_device *pdev) { -struct platform_device *pdev; +static struct resource telemetry_ipc_res[2 ];struct resource *res; -const struct platform_device_info pdevinfo = { - .parent = ipcdev.dev, - .name =TELEMETRY_DEVICE_NAME , - .id =-1 , - .res = telemetry_res, - .num_res =ARRAY_SIZE (telemetry_res), - }; - - res = telemetry_res +TELEMETRY_RESOURCE_PUNIT_SSRAM ; - res->start = ipcdev.telem_punit_ssram_base; - res->end = res->start + ipcdev.telem_punit_ssram_size -1 ; - - res = telemetry_res +TELEMETRY_RESOURCE_PMC_SSRAM ; - res->start = ipcdev.telem_pmc_ssram_base; - res->end = res->start + ipcdev.telem_pmc_ssram_size -1 ; - - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +static struct mfd_cell telemetry_cell; - ipcdev.telemetry_dev = pdev; +/* Get telemetry resources */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_TELEM_SSRAM_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get telemetry resource\n" ); +return -ENXIO ; + } -return 0 ; + telemetry_ipc_res[0 ].start = res->start + +TELEM_PUNIT_SSRAM_OFFSET ; + telemetry_ipc_res[0 ].end = res->start + +TELEM_PUNIT_SSRAM_OFFSET +TELEM_SSRAM_SIZE -1 ; + telemetry_ipc_res[0 ].flags =IORESOURCE_MEM ; + telemetry_ipc_res[1 ].start = res->start +TELEM_PMC_SSRAM_OFFSET ; + telemetry_ipc_res[1 ].end = res->start + +TELEM_PMC_SSRAM_OFFSET +TELEM_SSRAM_SIZE -1 ; + telemetry_ipc_res[1 ].flags =IORESOURCE_MEM ; + +dev_dbg (&pdev->dev,"Telemetry res 0: %pR\n" , + &telemetry_ipc_res[0 ]); +dev_dbg (&pdev->dev,"Telemetry res 1: %pR\n" , + &telemetry_ipc_res[1 ]); + + telemetry_cell.name =TELEMETRY_DEVICE_NAME ; + telemetry_cell.num_resources =ARRAY_SIZE (telemetry_ipc_res); + telemetry_cell.resources = telemetry_ipc_res; + telemetry_cell.ignore_resource_conflicts =1 ; + +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &telemetry_cell,1 ,NULL ,0 ,NULL ); } -static int ipc_create_pmc_devices (void ) +static int ipc_create_pmc_devices (struct platform_device *pdev) {int ret; -/* If we have ACPI based watchdog use that instead */ -if (!acpi_has_watchdog ()) { - ret =ipc_create_tco_device (); -if (ret) { -dev_err (ipcdev.dev,"Failed to add tco platform device\n" ); -return ret; - } - } + ret =ipc_create_punit_device (pdev); +if (ret <0 ) +return ret; - ret =ipc_create_punit_device (); -if (ret) { -dev_err (ipcdev.dev,"Failed to add punit platform device\n" ); -platform_device_unregister (ipcdev.tco_dev); - } + ret =ipc_create_wdt_device (pdev); +if (ret <0 ) +return ret; -if (!ipcdev.telem_res_inval) { - ret =ipc_create_telemetry_device (); -if (ret) -dev_warn (ipcdev.dev, -"Failed to add telemetry platform device\n" ); - } + ret =ipc_create_telemetry_device (pdev); +if (ret <0 ) +return ret; -return ret; +return 0 ; }static int ipc_plat_get_res (struct platform_device *pdev) { -struct resource *res, *punit_res; +struct resource *res;void __iomem *addr; -int size; - - res =platform_get_resource (pdev,IORESOURCE_IO , -PLAT_RESOURCE_ACPI_IO_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get io resource\n" ); -return -ENXIO ; - } - size =resource_size (res); - ipcdev.acpi_io_base = res->start; - ipcdev.acpi_io_size = size; -dev_info (&pdev->dev,"io res: %pR\n" , res); - - punit_res = punit_res_array; -/* This is index 0 to cover BIOS data register */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_BIOS_DATA_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get res of punit BIOS data\n" ); -return -ENXIO ; - } - *punit_res = *res; -dev_info (&pdev->dev,"punit BIOS data res: %pR\n" , res); -/* This is index 1 to cover BIOS interface register */ +/* Get IPC resources */ res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_BIOS_IFACE_INDEX ); +PLAT_RESOURCE_IPC_INDEX );if (!res) { -dev_err (&pdev->dev,"Failed to get res of punit BIOS iface\n" ); +dev_err (&pdev->dev,"Failed to get IPC resources\n" );return -ENXIO ; } - *++punit_res = *res; -dev_info (&pdev->dev,"punit BIOS interface res: %pR\n" , res); - -/* This is index 2 to cover ISP data register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_ISP_DATA_INDEX ); - ++punit_res; -if (res) { - *punit_res = *res; -dev_info (&pdev->dev,"punit ISP data res: %pR\n" , res); - } -/* This is index 3 to cover ISP interface register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_ISP_IFACE_INDEX ); - ++punit_res; -if (res) { - *punit_res = *res; -dev_info (&pdev->dev,"punit ISP interface res: %pR\n" , res); - } - -/* This is index 4 to cover GTD data register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_GTD_DATA_INDEX ); - ++punit_res; -if (res) { - *punit_res = *res; -dev_info (&pdev->dev,"punit GTD data res: %pR\n" , res); - } - -/* This is index 5 to cover GTD interface register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_GTD_IFACE_INDEX ); - ++punit_res; -if (res) { - *punit_res = *res; -dev_info (&pdev->dev,"punit GTD interface res: %pR\n" , res); - } - - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_IPC_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get ipc resource\n" ); -return -ENXIO ; - } - size =PLAT_RESOURCE_IPC_SIZE +PLAT_RESOURCE_GCR_SIZE ; - res->end = res->start + size -1 ; + res->end = (res->start +PLAT_RESOURCE_IPC_SIZE + +PLAT_RESOURCE_GCR_SIZE -1 ); addr =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (addr))return PTR_ERR (addr); ipcdev.ipc_base = addr; - ipcdev.gcr_mem_base = addr +PLAT_RESOURCE_GCR_OFFSET ; -dev_info (&pdev->dev,"ipc res: %pR\n" , res); - - ipcdev.telem_res_inval =0 ; - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_TELEM_SSRAM_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get telemetry ssram resource\n" ); - ipcdev.telem_res_inval =1 ; - }else { - ipcdev.telem_punit_ssram_base = res->start + -TELEM_PUNIT_SSRAM_OFFSET ; - ipcdev.telem_punit_ssram_size =TELEM_SSRAM_SIZE ; - ipcdev.telem_pmc_ssram_base = res->start + -TELEM_PMC_SSRAM_OFFSET ; - ipcdev.telem_pmc_ssram_size =TELEM_SSRAM_SIZE ; -dev_info (&pdev->dev,"telemetry ssram res: %pR\n" , res); - } +dev_dbg (&pdev->dev,"PMC IPC resource %pR\n" , res);return 0 ; }
@@ -921,7 +812,7 @@ static int ipc_plat_probe(struct platform_device *pdev)return ret; } - ret =ipc_create_pmc_devices (); + ret =ipc_create_pmc_devices (pdev);if (ret) {dev_err (&pdev->dev,"Failed to create pmc devices\n" );return ret;
@@ -930,38 +821,27 @@ static int ipc_plat_probe(struct platform_device *pdev)if (devm_request_irq (&pdev->dev, ipcdev.irq, ioc,IRQF_NO_SUSPEND ,"intel_pmc_ipc" , &ipcdev)) {dev_err (&pdev->dev,"Failed to request irq\n" ); - ret = -EBUSY ; - goto err_irq; +return -EBUSY ; } ret =sysfs_create_group (&pdev->dev.kobj, &intel_ipc_group);if (ret) {dev_err (&pdev->dev,"Failed to create sysfs group %d\n" , ret); - goto err_sys; +devm_free_irq (&pdev->dev, ipcdev.irq, &ipcdev); +return ret; } ipcdev.has_gcr_regs = true;return 0 ; -err_sys: -devm_free_irq (&pdev->dev, ipcdev.irq, &ipcdev); -err_irq: -platform_device_unregister (ipcdev.tco_dev); -platform_device_unregister (ipcdev.punit_dev); -platform_device_unregister (ipcdev.telemetry_dev); - -return ret; }static int ipc_plat_remove (struct platform_device *pdev) {sysfs_remove_group (&pdev->dev.kobj, &intel_ipc_group); -devm_free_irq (&pdev->dev, ipcdev.irq, &ipcdev); -platform_device_unregister (ipcdev.tco_dev); -platform_device_unregister (ipcdev.punit_dev); -platform_device_unregister (ipcdev.telemetry_dev); ipcdev.dev =NULL ; +return 0 ; }
Signature · 1 line
2.7.4
Re: [RFC v5 1/8] platform/x86: intel_pmc_ipc: Use spin_lock to protect GCR updates
In reply to [email protected]Quoted 9 lines · On Sun, Oct 8, 2017 at 1:19 AM, <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9…
From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9/[email protected]>
Currently,
update_no_reboot_bit()function implemented in this driver usesmutex_lock()to protect its register updates. But this function is called with in atomic context iniTCO_wdt_start()andiTCO_wdt_stop()functions iniTCO_wdt.cdriver, which in turn causes "sleeping into atomic context" issue. This patch fixes this issue by replacing themutex_lock()withspin_lock()to protect the GCR read/write/update APIs.
Quoted 4 lines
Fixes 9d855d4 ("platform/x86: intel_pmc_ipc: Fix iTCO_wdt GCS memory mapping failure")* Rebased this patch on top of Andy's review branch.
Oh, what I asked you is to use vanilla kernel as a base. Please, be sure (you assured me, though it's not true) that it's applied against vanilla (or our fixes branch) and send just this one patch separately.
No need to resend v5 right now.
Signature · 6 lines
With Best Regards, Andy Shevchenko -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC v5 1/8] platform/x86: intel_pmc_ipc: Use spin_lock to protect GCR updates
Hi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · On Sun, Oct 8, 2017 at 1:19 AM, <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9…
From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9/[email protected]>
Currently,
update_no_reboot_bit()function implemented in this driver usesmutex_lock()to protect its register updates. But this function is called with in atomic context iniTCO_wdt_start()andiTCO_wdt_stop()functions iniTCO_wdt.cdriver, which in turn causes "sleeping into atomic context" issue. This patch fixes this issue by replacing themutex_lock()withspin_lock()to protect the GCR read/write/update APIs.
Quoted 5 lines
Quoted 3 lines
Fixes 9d855d4 ("platform/x86: intel_pmc_ipc: Fix iTCO_wdt GCS memory mapping failure")* Rebased this patch on top of Andy's review branch.
Oh, what I asked you is to use vanilla kernel as a base. Please, be sure (you assured me, though it's not true)
I did test this patch on top of 4.14-rc3, but I have included another patch (""platform/x86: intel_pmc_ipc: Use devm_* calls in driver probe function") from your review branch before testing. I assumed that your will be pushing this patch along with devm_* fixes patch (since you already reviewed it), So I re-based them together on top of 4.14-rc3. Sorry, it looks like my assumption is incorrect.
Quoted 3 lines
that it's
applied against vanilla (or our fixes branch) and send just this one patch separately.
I will send it separately now.
Quoted 3 lines
No need to resend v5 right now.
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [RFC v5 4/8] platform: x86: Add generic Intel IPC driver
In reply to [email protected]Quoted 358 lines
From: [email protected] [mailto:[email protected]]
Sent: Sunday, October 8, 2017 3:50 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zha, Qipeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Chakravarty, Souvik K <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Kuppuswamy Sathyanarayanan <[email protected]>
Subject: [RFC v5 4/8] platform: x86: Add generic Intel IPC driverFrom: Kuppuswamy Sathyanarayanan
<[email protected]>Currently
intel_scu_ipc.c,intel_pmc_ipc.candintel_punit_ipc.credundantly implements the same IPC features and has lot of code duplication between them. This driver addresses this issue by grouping the common IPC functionalities under the same driver.Signed-off-by: Kuppuswamy Sathyanarayanan
<[email protected]>--- drivers/platform/x86/Kconfig | 8 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_ipc_dev.c | 576 ++++++++++++++++++++++++ include/linux/platform_data/x86/intel_ipc_dev.h | 206 +++++++++ 4 files changed, 791 insertions(+) create mode 100644 drivers/platform/x86/intel_ipc_dev.c create mode 100644 include/linux/platform_data/x86/intel_ipc_dev.hChanges since v4:
* NoneChanges since v3:
* Fixed NULL pointer exception inintel_ipc_dev_get().
* Fixed error in check for duplicateintel_ipc_dev.
* Added custom interrupt handler support.
* Used char array for error string conversion.
* Added put dev support.
* Added devm_* variant ofintel_ipc_dev_get().Changes since v2:
* Addedipc_dev_cmdAPI support.drivers/platform/x86/Kconfig +8
-0@@ -1153,6 +1153,14 @@ config SILEAD_DMI with the OS-image for the device. This option supplies the missing information. Enable this for x86 tablets with Silead touchscreens. +config INTEL_IPC_DEV + bool "Intel IPC Device Driver" + depends on X86_64 + ---help--- + This driver implements core features of Intel IPC device. Devices + like PMC, SCU, PUNIT, etc can use interfaces provided by this + driver to implement IPC protocol of their respective device. + endif # X86_PLATFORM_DEVICES config PMC_ATOMdrivers/platform/x86/Makefile +0
-0@@ -84,3 +84,4 @@ obj-$(CONFIG_PMC_ATOM) +=pmc_atom.o
obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o
obj-$(CONFIG_MLX_CPLD_PLATFORM) += mlxcpld-hotplug.o
obj-$(CONFIG_INTEL_TURBO_MAX_3) += intel_turbo_max_3.odrivers/platform/x86/Makefile +1
-0+obj-$(CONFIG_INTEL_IPC_DEV) += intel_ipc_dev.odrivers/platform/x86/intel_ipc_dev.c new file +116
-0@@ -0,0 +1,576 @@ +/* +* intel_ipc_dev.c: Intel IPC device class driver +* +* (C) Copyright 2017 Intel Corporation +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; version 2 +* of the License. +* +*/ + +#include <linux/device.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/export.h> +#include <linux/idr.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/interrupt.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> +#include <linux/regmap.h> + +/* mutex to sync different ipc devices in same channel */ static struct +mutex channel_lock[IPC_CHANNEL_MAX ]; + +static char *ipc_err_sources[] = { + [IPC_DEV_ERR_NONE ] = +"No error" , + [IPC_DEV_ERR_CMD_NOT_SUPPORTED ] = +"Command not-supported/Invalid" , + [IPC_DEV_ERR_CMD_NOT_SERVICED ] = +"Command not-serviced/Invalid param" , + [IPC_DEV_ERR_UNABLE_TO_SERVICE ] = +"Unable-to-service/Cmd-timeout" , + [IPC_DEV_ERR_CMD_INVALID ] = +"Command-invalid/Cmd-locked" , + [IPC_DEV_ERR_CMD_FAILED ] = +"Command-failed/Invalid-VR-id" , + [IPC_DEV_ERR_EMSECURITY ] = +"Invalid Battery/VR-Error" , + [IPC_DEV_ERR_UNSIGNEDKERNEL ] = +"Unsigned kernel" , +}; + +static void ipc_channel_lock_init (void ) { +int i; + +for (i =0 ; i <IPC_CHANNEL_MAX ; i++) +mutex_init (&channel_lock[i]); +} + +static struct class intel_ipc_class = { + .name ="intel_ipc" , + .owner =THIS_MODULE , +}; + +static int ipc_dev_lock (struct intel_ipc_dev *ipc_dev) { +int chan_type; + +if (!ipc_dev || !ipc_dev->cfg) +return -ENODEV ; + + chan_type = ipc_dev->cfg->chan_type; +if (chan_type >IPC_CHANNEL_MAX ) +return -EINVAL ; + +/* acquire channel lock */ +mutex_lock (&channel_lock[chan_type]); + +/* acquire IPC device lock */ +mutex_lock (&ipc_dev->lock); + +return 0 ; +} + +static int ipc_dev_unlock (struct intel_ipc_dev *ipc_dev) { +int chan_type; + +if (!ipc_dev || !ipc_dev->cfg) +return -ENODEV ; + + chan_type = ipc_dev->cfg->chan_type; +if (chan_type >IPC_CHANNEL_MAX ) +return -EINVAL ; + +/* release IPC device lock */ +mutex_unlock (&ipc_dev->lock); + +/* release channel lock */ +mutex_unlock (&channel_lock[chan_type]); + +return 0 ; +} + +static const char *ipc_dev_err_string (struct intel_ipc_dev *ipc_dev, +int error) +{ +if (error <IPC_DEV_ERR_MAX ) +return ipc_err_sources[error]; + +return "Unknown Command" ; +} + +/* Helper function to send given command to IPC device */ static inline +void ipc_dev_send_cmd (struct intel_ipc_dev *ipc_dev,u32 cmd) { + ipc_dev->cmd = cmd; + +if (ipc_dev->cfg->mode ==IPC_DEV_MODE_IRQ ) +reinit_completion (&ipc_dev->cmd_complete); + +if (ipc_dev->ops->enable_msi) + cmd = ipc_dev->ops->enable_msi (cmd); + +regmap_write (ipc_dev->cfg->cmd_regs, ipc_dev->cfg->cmd_reg, cmd);}
drivers/platform/x86/intel_ipc_dev.c new file +33
-0+ +static inline int ipc_dev_status_busy (struct intel_ipc_dev *ipc_dev) { +int status; + +regmap_read (ipc_dev->cfg->cmd_regs, ipc_dev->cfg->status_reg, +&status); + +if (ipc_dev->ops->busy_check) +return ipc_dev->ops->busy_check (status); + +return 0 ; +} + +/* Check the status of IPC command and return err code if failed */ +static int ipc_dev_check_status (struct intel_ipc_dev *ipc_dev) { +int loop_count =IPC_DEV_CMD_LOOP_CNT ; +int status; +int ret =0 ; + +if (ipc_dev->cfg->mode ==IPC_DEV_MODE_IRQ ) { +if (!wait_for_completion_timeout (&ipc_dev->cmd_complete, +IPC_DEV_CMD_TIMEOUT )) + ret = -ETIMEDOUT ; + }else { +while (ipc_dev_status_busy (ipc_dev) && --loop_count) +udelay (1 ); +if (!loop_count) + ret = -ETIMEDOUT ; + } + +if (ret <0 ) { + dev_err(&ipc_dev->dev, + "IPC timed out, CMD=0x%x\n", ipc_dev-Quoted 1 line
cmd);
drivers/platform/x86/intel_ipc_dev.c new file +123
-0+return ret; + } + +regmap_read (ipc_dev->cfg->cmd_regs, ipc_dev->cfg->status_reg, +&status); + +if (ipc_dev->ops->to_err_code) + ret = ipc_dev->ops->to_err_code (status); + +if (ret) { +dev_err (&ipc_dev->dev, +"IPC failed: %s, STS=0x%x, CMD=0x%x\n" , +ipc_dev_err_string (ipc_dev, ret), + status, ipc_dev->cmd); +return -EIO ; + } + +return 0 ; +} + +/** +* ipc_dev_simple_cmd() - Send simple IPC command +* @ipc_dev : Reference to ipc device. +* @cmd_list : IPC command list. +* @cmdlen : Number of cmd/sub-cmds. +* +* Send a simple IPC command to ipc device. +* Use this when don't need to specify input/output data +* and source/dest pointers. +* +* Return: an IPC error code or 0 on success. +*/ + +int ipc_dev_simple_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list, +u32 cmdlen) +{ +int ret; + +if (!cmd_list) +return -EINVAL ; + + ret =ipc_dev_lock (ipc_dev); +if (ret) +return ret; + +/* Call custom pre-processing handler */ +if (ipc_dev->ops->pre_simple_cmd_fn) { + ret = ipc_dev->ops->pre_simple_cmd_fn (cmd_list, cmdlen); +if (ret) + goto unlock_device; + } + +ipc_dev_send_cmd (ipc_dev, cmd_list[0 ]); + + ret =ipc_dev_check_status (ipc_dev); + +unlock_device: +ipc_dev_unlock (ipc_dev); + +return ret; +} +EXPORT_SYMBOL_GPL (ipc_dev_simple_cmd); + +/** +* ipc_dev_cmd() - Send IPC command with data. +* @ipc_dev : Reference to ipc_dev. +* @cmd_list : Array of commands/sub-commands. +* @cmdlen : Number of commands. +* @in : Input data of this IPC command. +* @inlen : Input data length in dwords. +* @out : Output data of this IPC command. +* @outlen : Length of output data in dwords. +* +* Send an IPC command to device with input/output data. +* +* Return: an IPC error code or 0 on success. +*/ +int ipc_dev_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list,u32 cmdlen, +u32 *in,u32 inlen,u32 *out,u32 outlen) { +int ret; + +if (!cmd_list || !in) +return -EINVAL ; + + ret =ipc_dev_lock (ipc_dev); +if (ret) +return ret; + +/* Call custom pre-processing handler. */ +if (ipc_dev->ops->pre_cmd_fn) { + ret = ipc_dev->ops->pre_cmd_fn (cmd_list, cmdlen, in, inlen, + out, outlen); +if (ret) + goto unlock_device; + } + +/* Write inlen dwords of data to wrbuf_reg. */ +if (inlen >0 ) +regmap_bulk_write (ipc_dev->cfg->data_regs, + ipc_dev->cfg->wrbuf_reg, in, inlen); + +ipc_dev_send_cmd (ipc_dev, cmd_list[0 ]); + + ret =ipc_dev_check_status (ipc_dev); + +/* Read outlen dwords of data from rbug_reg. */ +if (!ret && outlen >0 ) +regmap_bulk_read (ipc_dev->cfg->data_regs, + ipc_dev->cfg->rbuf_reg, out, outlen); +unlock_device: +ipc_dev_unlock (ipc_dev); + +return ret; +} +EXPORT_SYMBOL_GPL (ipc_dev_cmd); + +/** +* ipc_dev_raw_cmd() - Send IPC command with data and pointers. +* @ipc_dev : Reference to ipc_dev. +* @cmd_list : Array of commands/sub-commands. +* @cmdlen : Number of commands. +* @in : Input data of this IPC command. +* @inlen : Input data length in bytes.
drivers/platform/x86/intel_ipc_dev.c line 288
Quoted 10 lines
drivers/platform/x86/intel_ipc_dev.c new file +10
-0+* @out : Output data of this IPC command. +* @outlen : Length of output data in dwords. +* @dptr : IPC destination data address. +* @sptr : IPC source data address. +* +* Send an IPC command to device with input/output data and +* source/dest pointers. +* +* Return: an IPC error code or 0 on success. +*/
Sorry for coming in so late but since we are refactoring the API anyways, isn't it better to reduce the signature? Nine parameters is an awful lot and prone to errors and difficult to debug. (We found it out the hard way when we started using this a few years ago.)
This can be consolidated into a few neat structs, e.g.,:
int ipc_dev_raw_cmd(struct intel_ipc_dev *ipc_dev, struct ipc_cmd *cmd,
struct ipc_cmd_data *cmd_data, struct ipc_data_addr *addr)
Same for the ipc_dev_cmd() APIs above as well.
Quoted 499 lines
drivers/platform/x86/intel_ipc_dev.c new file +2
-0+ +int ipc_dev_raw_cmd(struct intel_ipc_dev *ipc_dev, u32 *cmd_list, u32cmdlen,
drivers/platform/x86/intel_ipc_dev.c new file +19
-0+ u8 *in, u32 inlen, u32 *out, u32 outlen, u32 dptr, u32 sptr) { + int ret; +int inbuflen =DIV_ROUND_UP (inlen,4 ); +u32 *inbuf; + +if (!cmd_list || !in) +return -EINVAL ; + + inbuf =kzalloc (inbuflen,GFP_KERNEL ); +if (!inbuf) +return -ENOMEM ; + + ret =ipc_dev_lock (ipc_dev); +if (ret) +return ret; + +/* Call custom pre-processing handler. */ + if (ipc_dev->ops->pre_raw_cmd_fn) { + ret = ipc_dev->ops->pre_raw_cmd_fn(cmd_list, cmdlen, in,inlen,
drivers/platform/x86/intel_ipc_dev.c new file +8
-0+ out, outlen, dptr, sptr); +if (ret) + goto unlock_device; + } + +/* If supported, write DPTR register.*/ +if (ipc_dev->cfg->support_dptr) + regmap_write(ipc_dev->cfg->cmd_regs, ipc_dev->cfg-Quoted 1 line
dptr_reg,drivers/platform/x86/intel_ipc_dev.c new file +5
-0+ dptr); + +/* If supported, write SPTR register. */ +if (ipc_dev->cfg->support_sptr) + regmap_write(ipc_dev->cfg->cmd_regs, ipc_dev->cfg-Quoted 1 line
sptr_reg,drivers/platform/x86/intel_ipc_dev.c new file +105
-0+ sptr); + +memcpy (inbuf, in, inlen); + +/* Write inlen dwords of data to wrbuf_reg. */ +if (inlen >0 ) +regmap_bulk_write (ipc_dev->cfg->data_regs, + ipc_dev->cfg->wrbuf_reg, inbuf, inbuflen); + +ipc_dev_send_cmd (ipc_dev, cmd_list[0 ]); + + ret =ipc_dev_check_status (ipc_dev); + +/* Read outlen dwords of data from rbug_reg. */ +if (!ret && outlen >0 ) +regmap_bulk_read (ipc_dev->cfg->data_regs, + ipc_dev->cfg->rbuf_reg, out, outlen); +unlock_device: +ipc_dev_unlock (ipc_dev); +kfree (inbuf); + +return ret; +} +EXPORT_SYMBOL_GPL (ipc_dev_raw_cmd); + +/* sysfs option to send simple IPC commands from userspace */ static +ssize_t ipc_dev_cmd_reg_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) { +struct intel_ipc_dev *ipc_dev =dev_get_drvdata (dev); +u32 cmd; +int ret; + + ret =sscanf (buf,"%d" , &cmd); +if (ret !=1 ) { +dev_err (dev,"Error args\n" ); +return -EINVAL ; + } + + ret =ipc_dev_simple_cmd (ipc_dev, &cmd,1 ); +if (ret) { +dev_err (dev,"command 0x%x error with %d\n" , cmd, ret); +return ret; + } +return (ssize_t )count; +} + +static DEVICE_ATTR(send_cmd, S_IWUSR, NULL, ipc_dev_cmd_reg_store); + +static struct attribute *ipc_dev_attrs[] = { + &dev_attr_send_cmd.attr, +NULL +}; + +static const struct attribute_group ipc_dev_group = { + .attrs = ipc_dev_attrs, +}; + +static const struct attribute_group *ipc_dev_groups[] = { + &ipc_dev_group, +NULL , +}; + +/* IPC device IRQ handler */ +static irqreturn_t ipc_dev_irq_handler (int irq,void *dev_id) { +struct intel_ipc_dev *ipc_dev = (struct intel_ipc_dev *)dev_id; + +if (ipc_dev->ops->pre_irq_handler_fn) + ipc_dev->ops->pre_irq_handler_fn (ipc_dev, irq); + +complete (&ipc_dev->cmd_complete); + +return IRQ_HANDLED ; +} + +static void devm_intel_ipc_dev_release (struct device *dev,void *res) { +struct intel_ipc_dev *ipc_dev = *(struct intel_ipc_dev **)res; + +if (!ipc_dev) +return ; + +device_del (&ipc_dev->dev); + +kfree (ipc_dev); +} + +static int match_name (struct device *dev,const void *data) { +if (!dev_name (dev)) +return 0 ; + +return !strcmp (dev_name (dev), (char *)data); } + +/** +* intel_ipc_dev_get() - Get Intel IPC device from name. +* @dev_name : Name of the IPC device. +* +* Return : ERR_PTR/NULL or intel_ipc_dev pointer on success. +*/ +struct intel_ipc_dev *intel_ipc_dev_get (const char *dev_name) { +struct device *dev; + +if (!dev_name) +return ERR_PTR (-EINVAL ); + + dev = class_find_device(&intel_ipc_class, NULL, dev_name,
match_name);drivers/platform/x86/intel_ipc_dev.c new file +9
-0+ +return dev ?dev_get_drvdata (dev) :NULL ; } +EXPORT_SYMBOL_GPL (intel_ipc_dev_get); + +static void devm_intel_ipc_dev_put (struct device *dev,void *res) { +intel_ipc_dev_put (*(struct intel_ipc_dev **)res); } + +/** +* devm_intel_ipc_dev_get() - Resource managed version of
intel_ipc_dev_get().
+ * @dev : Device pointer.
+ * @dev_name : Name of the IPC device.
+ *
+ * Return : ERR_PTR/NULL orintel_ipc_devpointer on success.
+ */drivers/platform/x86/intel_ipc_dev.c new file +6
-0+struct intel_ipc_dev *devm_intel_ipc_dev_get (struct device *dev, +const char *dev_name) +{ +struct intel_ipc_dev **ptr, *ipc_dev; + + ptr = devres_alloc(devm_intel_ipc_dev_put, sizeof(*ptr),
GFP_KERNEL);drivers/platform/x86/intel_ipc_dev.c new file +118
-0+if (!ptr) +return ERR_PTR (-ENOMEM ); + + ipc_dev =intel_ipc_dev_get (dev_name); +if (!IS_ERR_OR_NULL (ipc_dev)) { + *ptr = ipc_dev; +devres_add (dev, ptr); + }else { +devres_free (ptr); + } + +return ipc_dev; +} +EXPORT_SYMBOL_GPL (devm_intel_ipc_dev_get); + +/** +* devm_intel_ipc_dev_create() - Create IPC device +* @dev : IPC parent device. +* @devname : Name of the IPC device. +* @cfg : IPC device configuration. +* @ops : IPC device ops. +* +* Resource managed API to create IPC device with +* given configuration. +* +* Return : IPC device pointer or ERR_PTR(error code). +*/ +struct intel_ipc_dev *devm_intel_ipc_dev_create (struct device *dev, +const char *devname, +struct intel_ipc_dev_cfg *cfg, +struct intel_ipc_dev_ops *ops) +{ +struct intel_ipc_dev **ptr, *ipc_dev; +int ret; + +if (!dev && !devname && !cfg) +return ERR_PTR (-EINVAL ); + +if (intel_ipc_dev_get (devname)) { +dev_err (dev,"IPC device %s already exist\n" , devname); +return ERR_PTR (-EINVAL ); + } + + ptr =devres_alloc (devm_intel_ipc_dev_release,sizeof (*ptr), +GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + + ipc_dev =kzalloc (sizeof (*ipc_dev),GFP_KERNEL ); +if (!ipc_dev) { + ret = -ENOMEM ; + goto err_dev_create; + } + + ipc_dev->dev.class = &intel_ipc_class; + ipc_dev->dev.parent = dev; + ipc_dev->dev.groups = ipc_dev_groups; + ipc_dev->cfg = cfg; + ipc_dev->ops = ops; + +mutex_init (&ipc_dev->lock); +init_completion (&ipc_dev->cmd_complete); +dev_set_drvdata (&ipc_dev->dev, ipc_dev); +dev_set_name (&ipc_dev->dev, devname); +device_initialize (&ipc_dev->dev); + + ret =device_add (&ipc_dev->dev); +if (ret <0 ) { +dev_err (&ipc_dev->dev,"%s device create failed\n" , + __func__); + ret = -ENODEV ; + goto err_dev_add; + } + +if (ipc_dev->cfg->mode ==IPC_DEV_MODE_IRQ ) { +if (devm_request_irq (&ipc_dev->dev, + ipc_dev->cfg->irq, + ipc_dev_irq_handler, + ipc_dev->cfg->irqflags, +dev_name (&ipc_dev->dev), + ipc_dev)) { +dev_err (&ipc_dev->dev, +"Failed to request irq\n" ); + goto err_irq_request; + } + } + + *ptr = ipc_dev; + +devres_add (dev, ptr); + +return ipc_dev; + +err_irq_request: +device_del (&ipc_dev->dev); +err_dev_add: +kfree (ipc_dev); +err_dev_create: +devres_free (ptr); +return ERR_PTR (ret); +} +EXPORT_SYMBOL_GPL (devm_intel_ipc_dev_create); + +static int __init intel_ipc_init (void ) +{ +ipc_channel_lock_init (); +return class_register (&intel_ipc_class); } + +static void __exit intel_ipc_exit(void) { +class_unregister (&intel_ipc_class); +} +subsys_initcall (intel_ipc_init); +module_exit (intel_ipc_exit); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR("Kuppuswamy +Sathyanarayanan<[email protected]>"); +MODULE_DESCRIPTION("Intel IPC device class driver");include/linux/platform_data/x86/intel_ipc_dev.h new file +150
-0@@ -0,0 +1,206 @@ +/* +* Intel IPC class device header file. +* +* (C) Copyright 2017 Intel Corporation +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; version 2 +* of the License. +* +*/ + +#ifndef INTEL_IPC_DEV_H +#define INTEL_IPC_DEV_H + +#include <linux/module.h> +#include <linux/device.h> + +/* IPC channel type */ +#define IPC_CHANNEL_IA_PMC 0 +#define IPC_CHANNEL_IA_PUNIT 1 +#define IPC_CHANNEL_PMC_PUNIT 2 +#define IPC_CHANNEL_IA_SCU 3 +#define IPC_CHANNEL_MAX 4 + +/* IPC return code */ +#define IPC_DEV_ERR_NONE 0 +#define IPC_DEV_ERR_CMD_NOT_SUPPORTED 1 +#define IPC_DEV_ERR_CMD_NOT_SERVICED 2 +#define IPC_DEV_ERR_UNABLE_TO_SERVICE 3 +#define IPC_DEV_ERR_CMD_INVALID 4 +#define IPC_DEV_ERR_CMD_FAILED 5 +#define IPC_DEV_ERR_EMSECURITY 6 +#define IPC_DEV_ERR_UNSIGNEDKERNEL 7 +#define IPC_DEV_ERR_MAX 8 + +/* IPC mode */ +#define IPC_DEV_MODE_IRQ 0 +#define IPC_DEV_MODE_POLLING 1 + +/* IPC dev constants */ +#define IPC_DEV_CMD_LOOP_CNT 3000000 +#define IPC_DEV_CMD_TIMEOUT 3 * HZ +#define IPC_DEV_DATA_BUFFER_SIZE 16 + +struct intel_ipc_dev ; +struct intel_ipc_raw_cmd ; + +/** +* struct intel_ipc_dev_cfg - IPC device config structure. +* +* IPC device drivers uses the following config options to +* register new IPC device. +* +* @cmd_regs : IPC device command base regmap. +* @data_regs : IPC device data base regmap. +* @wrbuf_reg : IPC device data write register address. +* @rbuf_reg : IPC device data read register address. +* @sptr_reg : IPC device source data pointer register address. +* @dptr_reg : IPC device destination data pointer register +* address. +* @status_reg : IPC command status register address. +* @cmd_reg : IPC command register address. +* @mode : IRQ/POLLING mode. +* @irq : IPC device IRQ number. +* @irqflags : IPC device IRQ flags. +* @chan_type : IPC device channel type(PMC/PUNIT). +* @msi : Enable/Disable MSI for IPC commands. +* @support_dptr : Support DPTR update. +* @support_sptr : Support SPTR update. +* +*/ +struct intel_ipc_dev_cfg { +struct regmap *cmd_regs; +struct regmap *data_regs; +unsigned int wrbuf_reg; +unsigned int rbuf_reg; +unsigned int sptr_reg; +unsigned int dptr_reg; +unsigned int status_reg; +unsigned int cmd_reg; +int mode; +int irq; +int irqflags; +int chan_type; +bool use_msi; +bool support_dptr; +bool support_sptr; +}; + +/** +* struct intel_ipc_dev_ops - IPC device ops structure. +* +* Call backs for IPC device specific operations. +* +* @to_err_code : Status to error code conversion function. +* @busy_check : Check for IPC busy status. +* @enable_msi : Enable MSI for IPC commands. +* @pre_simple_cmd_fn : Custom pre-processing function for +* ipc_dev_simple_cmd() +* @pre_cmd_fn : Custom pre-processing function for +* ipc_dev_cmd() +* @pre_raw_cmd_fn : Custom pre-processing function for +* ipc_dev_raw_cmd() +* +*/ +struct intel_ipc_dev_ops { +int (*to_err_code)(int status); +int (*busy_check)(int status); +u32 (*enable_msi)(u32 cmd); +int (*pre_simple_cmd_fn)(u32 *cmd_list,u32 cmdlen); +int (*pre_cmd_fn)(u32 *cmd_list,u32 cmdlen,u32 *in,u32 inlen, +u32 *out,u32 outlen); +int (*pre_raw_cmd_fn)(u32 *cmd_list,u32 cmdlen,u8 *in,u32 inlen, +u32 *out,u32 outlen,u32 dptr,u32 sptr); +int (*pre_irq_handler_fn)(struct intel_ipc_dev *ipc_dev,int irq); }; + +/** +* struct intel_ipc_dev - Intel IPC device structure. +* +* Used with devm_intel_ipc_dev_create() to create new IPC device. +* +* @dev : IPC device object. +* @cmd : Current IPC device command. +* @cmd_complete : Command completion object. +* @lock : Lock to protect IPC device structure. +* @ops : IPC device ops pointer. +* @cfg : IPC device cfg pointer. +* +*/ +struct intel_ipc_dev { +struct device dev; +int cmd; +struct completion cmd_complete; +struct mutex lock; +struct intel_ipc_dev_ops *ops; +struct intel_ipc_dev_cfg *cfg; +}; + +#if IS_ENABLED (CONFIG_INTEL_IPC_DEV ) + +/* API to create new IPC device */ +struct intel_ipc_dev *devm_intel_ipc_dev_create (struct device *dev, +const char *devname,struct intel_ipc_dev_cfg *cfg, +struct intel_ipc_dev_ops *ops); + +int ipc_dev_simple_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list, +u32 cmdlen); +int ipc_dev_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list,u32 cmdlen, +u32 *in,u32 inlen,u32 *out,u32 outlen);int ipc_dev_raw_cmd(struct
include/linux/platform_data/x86/intel_ipc_dev.h new file +2
-0+intel_ipc_dev *ipc_dev, u32 *cmd_list, u32 cmdlen, + u8 *in, u32 inlen, u32 *out, u32 outlen, u32 dptr, u32 sptr);struct
include/linux/platform_data/x86/intel_ipc_dev.h new file +28
-0+intel_ipc_dev *intel_ipc_dev_get (const char *dev_name);struct +intel_ipc_dev *devm_intel_ipc_dev_get (struct device *dev, +const char *dev_name); +static inline void intel_ipc_dev_put (struct intel_ipc_dev *ipc_dev) { +put_device (&ipc_dev->dev); +} +#else + +static inline struct intel_ipc_dev *devm_intel_ipc_dev_create ( +struct device *dev, +const char *devname,struct intel_ipc_dev_cfg *cfg, +struct intel_ipc_dev_ops *ops) +{ +return -EINVAL ; +} + +static inline int ipc_dev_simple_cmd (struct intel_ipc_dev *ipc_dev, +u32 *cmd_list,u32 cmdlen) +{ +return -EINVAL ; +} + +static int ipc_dev_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list, +u32 cmdlen,u32 *in,u32 inlen,u32 *out,u32 outlen) { +return -EINVAL ; +} + +static inline int ipc_dev_raw_cmd(struct intel_ipc_dev *ipc_dev, u32
*cmd_list,include/linux/platform_data/x86/intel_ipc_dev.h new file +12
-0+ u32 cmdlen, u8 *in, u32 inlen, u32 *out, u32 outlen, + u32 dptr, u32 sptr); +{ +return -EINVAL ; +} + +static inline struct intel_ipc_dev *intel_ipc_dev_get (const char +*dev_name) { +return NULL ; +} + +static inline struct intel_ipc_dev *devm_intel_ipc_dev_get(struct device*dev,
include/linux/platform_data/x86/intel_ipc_dev.h new file +10
-1+ const char *dev_name); +{ +return NULL ; +} + +static inline void intel_ipc_dev_put (struct intel_ipc_dev *ipc_dev) { +return NULL ; +} +#endif /* CONFIG_INTEL_IPC_DEV */ +#endif /* INTEL_IPC_DEV_H */ --2.7.4
RE: [RFC v5 6/8] platform/x86: intel_punit_ipc: Use generic intel ipc device calls
In reply to [email protected]drivers/platform/x86/intel_telemetry_pltdrv.c
Quoted 646 lines
From: [email protected] [mailto:[email protected]]
Sent: Sunday, October 8, 2017 3:50 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zha, Qipeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Chakravarty, Souvik K <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Kuppuswamy Sathyanarayanan <[email protected]>
Subject: [RFC v5 6/8] platform/x86:intel_punit_ipc: Use generic intel ipc device callsFrom: Kuppuswamy Sathyanarayanan
<[email protected]>Removed redundant IPC helper functions and refactored the driver to use APIs provided by generic IPC driver. This patch also cleans-up PUNIT IPC user
drivers(intel_telemetry_pltdrv.c)to use APIs provided by generic IPC driver.Signed-off-by: Kuppuswamy Sathyanarayanan
<[email protected]>--- arch/x86/include/asm/intel_punit_ipc.h | 125 +++++------ drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_punit_ipc.c | 303 ++++++++++---------------- drivers/platform/x86/intel_telemetry_pltdrv.c | 97 +++++---- 4 files changed, 223 insertions(+), 303 deletions(-)Changes since v4:
* NoneChanges since v2:
* Added unique name to PUNIT BIOS, GTD, & ISP regmaps.
* Addedintel_ipc_dev_put()support.Changes since v1:
* Removed custom APIs.
* Cleaned up PUNIT IPC user drivers to use APIs provided by generic IPC driver.arch/x86/include/asm/intel_punit_ipc.h +6
-33@@ -1,10 +1,8 @@ #ifndef _ASM_X86_INTEL_PUNIT_IPC_H_ #define _ASM_X86_INTEL_PUNIT_IPC_H_ -/* - * Three types of 8bit P-Unit IPC commands are supported, - * bit[7:6]: [00]: BIOS; [01]: GTD; [10]: ISPD. - */ +#include <linux/platform_data/x86/intel_ipc_dev.h> + typedef enum { BIOS_IPC = 0, GTDRIVER_IPC,@@ -12,61 +10,60 @@ typedef enum {RESERVED_IPC , } IPC_TYPE; -#define IPC_TYPE_OFFSET 6 -#define IPC_PUNIT_BIOS_CMD_BASE (BIOS_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_GTD_CMD_BASE (GTDDRIVER_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_ISPD_CMD_BASE (ISPDRIVER_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_CMD_TYPE_MASK (RESERVED_IPC << IPC_TYPE_OFFSET) +#define PUNIT_BIOS_IPC_DEV "punit_bios_ipc" +#define PUNIT_GTD_IPC_DEV "punit_gtd_ipc" +#define PUNIT_ISP_IPC_DEV "punit_isp_ipc" +#define PUNIT_PARAM_LEN 3/* BIOS => Pcode commands */ -#define IPC_PUNIT_BIOS_ZERO (IPC_PUNIT_BIOS_CMD_BASE | 0x00) -#define IPC_PUNIT_BIOS_VR_INTERFACE (IPC_PUNIT_BIOS_CMD_BASE |0x01 ) -#define IPC_PUNIT_BIOS_READ_PCS (IPC_PUNIT_BIOS_CMD_BASE |0x02 ) -#define IPC_PUNIT_BIOS_WRITE_PCS (IPC_PUNIT_BIOS_CMD_BASE | 0x03) -#define IPC_PUNIT_BIOS_READ_PCU_CONFIG (IPC_PUNIT_BIOS_CMD_BASE |0x04 ) -#define IPC_PUNIT_BIOS_WRITE_PCU_CONFIG (IPC_PUNIT_BIOS_CMD_BASE |0x05 ) -#define IPC_PUNIT_BIOS_READ_PL1_SETTING (IPC_PUNIT_BIOS_CMD_BASE |0x06 ) -#define IPC_PUNIT_BIOS_WRITE_PL1_SETTING (IPC_PUNIT_BIOS_CMD_BASE | 0x07) -#define IPC_PUNIT_BIOS_TRIGGER_VDD_RAM (IPC_PUNIT_BIOS_CMD_BASE |0x08 ) -#define IPC_PUNIT_BIOS_READ_TELE_INFO (IPC_PUNIT_BIOS_CMD_BASE |0x09 ) -#define IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0a ) -#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0b ) -#define IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0c ) -#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0d ) -#define IPC_PUNIT_BIOS_READ_TELE_TRACE (IPC_PUNIT_BIOS_CMD_BASE |0x0e ) -#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE (IPC_PUNIT_BIOS_CMD_BASE |0x0f ) -#define IPC_PUNIT_BIOS_READ_TELE_EVENT (IPC_PUNIT_BIOS_CMD_BASE |0x10 ) -#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT (IPC_PUNIT_BIOS_CMD_BASE |0x11 ) -#define IPC_PUNIT_BIOS_READ_MODULE_TEMP (IPC_PUNIT_BIOS_CMD_BASE |0x12 ) -#define IPC_PUNIT_BIOS_RESERVED (IPC_PUNIT_BIOS_CMD_BASE |0x13 ) -#define IPC_PUNIT_BIOS_READ_VOLTAGE_OVER (IPC_PUNIT_BIOS_CMD_BASE |0x14 ) -#define IPC_PUNIT_BIOS_WRITE_VOLTAGE_OVER (IPC_PUNIT_BIOS_CMD_BASE |0x15 ) -#define IPC_PUNIT_BIOS_READ_RATIO_OVER (IPC_PUNIT_BIOS_CMD_BASE |0x16 ) -#define IPC_PUNIT_BIOS_WRITE_RATIO_OVER(IPC_PUNIT_BIOS_CMD_BASE | 0x17) -#define IPC_PUNIT_BIOS_READ_VF_GL_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x18) -#define IPC_PUNIT_BIOS_WRITE_VF_GL_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x19) -#define IPC_PUNIT_BIOS_READ_FM_SOC_TEMP_THRESH (IPC_PUNIT_BIOS_CMD_BASE | 0x1a) -#define IPC_PUNIT_BIOS_WRITE_FM_SOC_TEMP_THRESH (IPC_PUNIT_BIOS_CMD_BASE | 0x1b)arch/x86/include/asm/intel_punit_ipc.h +28
-1+#define IPC_PUNIT_BIOS_ZERO (0x00) +#define IPC_PUNIT_BIOS_VR_INTERFACE (0x01) +#define IPC_PUNIT_BIOS_READ_PCS (0x02) +#define IPC_PUNIT_BIOS_WRITE_PCS (0x03) +#define IPC_PUNIT_BIOS_READ_PCU_CONFIG (0x04) +#define IPC_PUNIT_BIOS_WRITE_PCU_CONFIG (0x05) +#define IPC_PUNIT_BIOS_READ_PL1_SETTING (0x06) +#define IPC_PUNIT_BIOS_WRITE_PL1_SETTING (0x07) +#define IPC_PUNIT_BIOS_TRIGGER_VDD_RAM (0x08) +#define IPC_PUNIT_BIOS_READ_TELE_INFO (0x09) +#define IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL (0x0a) +#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL (0x0b) +#define IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL (0x0c) +#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL (0x0d) +#define IPC_PUNIT_BIOS_READ_TELE_TRACE (0x0e) +#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE (0x0f) +#define IPC_PUNIT_BIOS_READ_TELE_EVENT (0x10) +#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT (0x11) +#define IPC_PUNIT_BIOS_READ_MODULE_TEMP (0x12) +#define IPC_PUNIT_BIOS_RESERVED (0x13) +#define IPC_PUNIT_BIOS_READ_VOLTAGE_OVER (0x14) +#define IPC_PUNIT_BIOS_WRITE_VOLTAGE_OVER (0x15) +#define IPC_PUNIT_BIOS_READ_RATIO_OVER (0x16) +#define IPC_PUNIT_BIOS_WRITE_RATIO_OVER (0x17) +#define IPC_PUNIT_BIOS_READ_VF_GL_CTRL (0x18) +#define IPC_PUNIT_BIOS_WRITE_VF_GL_CTRL (0x19) +#define IPC_PUNIT_BIOS_READ_FM_SOC_TEMP_THRESH (0x1a) +#define IPC_PUNIT_BIOS_WRITE_FM_SOC_TEMP_THRESH (0x1b)/* GT Driver => Pcode commands */ -#define IPC_PUNIT_GTD_ZERO (IPC_PUNIT_GTD_CMD_BASE|
0x00)
-#defineIPC_PUNIT_GTD_CONFIG(IPC_PUNIT_GTD_CMD_BASE | 0x01) -#define IPC_PUNIT_GTD_READ_ICCP_LIC_CDYN_SCAL (IPC_PUNIT_GTD_CMD_BASE | 0x02) -#define IPC_PUNIT_GTD_WRITE_ICCP_LIC_CDYN_SCAL (IPC_PUNIT_GTD_CMD_BASE | 0x03) -#define IPC_PUNIT_GTD_GET_WM_VAL (IPC_PUNIT_GTD_CMD_BASE | 0x06) -#define IPC_PUNIT_GTD_WRITE_CONFIG_WISHREQ (IPC_PUNIT_GTD_CMD_BASE | 0x07) -#define IPC_PUNIT_GTD_READ_REQ_DUTY_CYCLE (IPC_PUNIT_GTD_CMD_BASE | 0x16) -#define IPC_PUNIT_GTD_DIS_VOL_FREQ_CHG_REQUEST (IPC_PUNIT_GTD_CMD_BASE | 0x17) -#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_CTRL (IPC_PUNIT_GTD_CMD_BASE | 0x1a) -#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_TUNING (IPC_PUNIT_GTD_CMD_BASE | 0x1c)arch/x86/include/asm/intel_punit_ipc.h +10
-1+#define IPC_PUNIT_GTD_ZERO (0x00) +#define IPC_PUNIT_GTD_CONFIG (0x01) +#define IPC_PUNIT_GTD_READ_ICCP_LIC_CDYN_SCAL (0x02) +#define IPC_PUNIT_GTD_WRITE_ICCP_LIC_CDYN_SCAL (0x03) +#define IPC_PUNIT_GTD_GET_WM_VAL (0x06) +#define IPC_PUNIT_GTD_WRITE_CONFIG_WISHREQ (0x07) +#define IPC_PUNIT_GTD_READ_REQ_DUTY_CYCLE (0x16) +#define IPC_PUNIT_GTD_DIS_VOL_FREQ_CHG_REQUEST (0x17) +#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_CTRL (0x1a) +#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_TUNING (0x1c)/* ISP Driver => Pcode commands */ -#define IPC_PUNIT_ISPD_ZERO (IPC_PUNIT_ISPD_CMD_BASE|
0x00)
-#defineIPC_PUNIT_ISPD_CONFIG(IPC_PUNIT_ISPD_CMD_BASE | 0x01) -#define IPC_PUNIT_ISPD_GET_ISP_LTR_VAL (IPC_PUNIT_ISPD_CMD_BASE | 0x02) -#define IPC_PUNIT_ISPD_ACCESS_IU_FREQ_BOUNDS (IPC_PUNIT_ISPD_CMD_BASE | 0x03) -#define IPC_PUNIT_ISPD_READ_CDYN_LEVEL (IPC_PUNIT_ISPD_CMD_BASE | 0x04) -#define IPC_PUNIT_ISPD_WRITE_CDYN_LEVEL (IPC_PUNIT_ISPD_CMD_BASE | 0x05)arch/x86/include/asm/intel_punit_ipc.h +6
-3+#define IPC_PUNIT_ISPD_ZERO (0x00) +#define IPC_PUNIT_ISPD_CONFIG (0x01) +#define IPC_PUNIT_ISPD_GET_ISP_LTR_VAL (0x02) +#define IPC_PUNIT_ISPD_ACCESS_IU_FREQ_BOUNDS (0x03) +#define IPC_PUNIT_ISPD_READ_CDYN_LEVEL (0x04) +#define IPC_PUNIT_ISPD_WRITE_CDYN_LEVEL (0x05)/* Error codes */ #define IPC_PUNIT_ERR_SUCCESS 0@@ -77,25 +74,11 @@ typedef enum {#define IPC_PUNIT_ERR_INVALID_VR_ID 5#define IPC_PUNIT_ERR_VR_ERR 6 -#if IS_ENABLED (CONFIG_INTEL_PUNIT_IPC ) - -int intel_punit_ipc_simple_command (int cmd,int para1,int para2); -int
intel_punit_ipc_command(u32 cmd, u32 para1, u32 para2, u32 *in, u32 *out);arch/x86/include/asm/intel_punit_ipc.h +5
-14- -#else - -static inline int intel_punit_ipc_simple_command (int cmd, -int para1,int para2) +static inline void punit_cmd_init (u32 *cmd,u32 param1,u32 param2,u32 +param3) { -return -ENODEV ; + cmd[0 ] = param1; + cmd[1 ] = param2; + cmd[2 ] = param3; } -static inline int intel_punit_ipc_command (u32 cmd,u32 para1,u32 para2, -u32 *in,u32 *out) -{ -return -ENODEV ; -} - -#endif /* CONFIG_INTEL_PUNIT_IPC */ -#endif drivers/platform/x86/Kconfig +1
-0@@ -1096,6 +1096,7 @@ config SURFACE_3_BUTTON config INTEL_PUNIT_IPC tristate "Intel P-Unit IPC Driver" + select REGMAP_MMIO ---help--- This driver provides support for Intel P-Unit Mailbox IPC mechanism,which is used to bridge the communications between kernel and P-
Unit.drivers/platform/x86/intel_punit_ipc.c +5
-5@@ -18,18 +18,18 @@#include <linux/device.h> #include <linux/interrupt.h> #include <linux/platform_device.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> +#include <linux/regmap.h> #include <asm/intel_punit_ipc.h> -/* IPC Mailbox registers */ -#define OFFSET_DATA_LOW 0x0 -#define OFFSET_DATA_HIGH 0x4/* bit field of interface register */ #define CMD_RUN BIT(31) -#define CMD_ERRCODE_MASK GENMASK(7, 0) +#define CMD_ERRCODE_MASK GENMASK(7, 0)#define CMD_PARA1_SHIFT 8#define CMD_PARA2_SHIFT 16 -#define CMD_TIMEOUT_SECONDS 1 +/* IPC PUNIT commands */ +#define IPC_DEV_PUNIT_CMD_STATUS_ERR_MASK GENMASK(7, 0)enum {drivers/platform/x86/intel_punit_ipc.c +16
-108BASE_DATA = 0,@@ -39,187 +39,42 @@ enum {typedef struct {struct device *dev; -struct mutex lock; -int irq; -struct completion cmd_complete;/* base of interface and data registers */ void __iomem *base[RESERVED_IPC ][BASE_MAX ]; +struct intel_ipc_dev *ipc_dev[RESERVED_IPC ];IPC_TYPE type; }IPC_DEV ;static IPC_DEV *punit_ipcdev; -static inline u32 ipc_read_status(IPC_DEV *ipcdev, IPC_TYPE type) -{ -return readl (ipcdev->base[type][BASE_IFACE ]); -} - -static inline void ipc_write_cmd(IPC_DEV *ipcdev, IPC_TYPE type, u32 cmd) - { -writel (cmd, ipcdev->base[type][BASE_IFACE ]); -} - -static inline u32 ipc_read_data_low(IPC_DEV *ipcdev, IPC_TYPE type) -{ -return readl (ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_LOW ); -} - -static inline u32 ipc_read_data_high(IPC_DEV *ipcdev, IPC_TYPE type) -{ -return readl (ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_HIGH ); -} - -static inline void ipc_write_data_low (IPC_DEV *ipcdev,IPC_TYPE type,u32 data) -{ -writel (data, ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_LOW ); -} - -static inline void ipc_write_data_high (IPC_DEV *ipcdev,IPC_TYPE type,u32 data) -{ -writel (data, ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_HIGH ); -} +const char *ipc_dev_name[RESERVED_IPC ] = { +PUNIT_BIOS_IPC_DEV , +PUNIT_GTD_IPC_DEV , +PUNIT_ISP_IPC_DEV +}; -static const char *ipc_err_string(int error) -{ -if (error ==IPC_PUNIT_ERR_SUCCESS ) -return "no error" ; -else if (error ==IPC_PUNIT_ERR_INVALID_CMD ) -return "invalid command" ; -else if (error ==IPC_PUNIT_ERR_INVALID_PARAMETER ) -return "invalid parameter" ; -else if (error ==IPC_PUNIT_ERR_CMD_TIMEOUT ) -return "command timeout" ; -else if (error ==IPC_PUNIT_ERR_CMD_LOCKED ) -return "command locked" ; -else if (error ==IPC_PUNIT_ERR_INVALID_VR_ID ) -return "invalid vr id" ; -else if (error ==IPC_PUNIT_ERR_VR_ERR ) -return "vr error" ; -else -return "unknown error" ; -} +static struct regmap_config punit_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , +}; -static int intel_punit_ipc_check_status (IPC_DEV *ipcdev,IPC_TYPE type) +int pre_simple_cmd_fn (u32 *cmd_list,u32 cmdlen) { -int loops =CMD_TIMEOUT_SECONDS *USEC_PER_SEC ; -int errcode; -int status; - -if (ipcdev->irq) { -if (!wait_for_completion_timeout (&ipcdev->cmd_complete, -CMD_TIMEOUT_SECONDS * HZ)) { -dev_err (ipcdev->dev,"IPC timed out\n" ); -return -ETIMEDOUT ; - } - }else { -while ((ipc_read_status (ipcdev, type) &CMD_RUN ) && -- loops) -udelay (1 ); -if (!loops) { -dev_err (ipcdev->dev,"IPC timed out\n" ); -return -ETIMEDOUT ; - } - } +if (!cmd_list || cmdlen !=PUNIT_PARAM_LEN ) +return -EINVAL ; - status =ipc_read_status (ipcdev, type); - errcode = status &CMD_ERRCODE_MASK ; -if (errcode) { -dev_err (ipcdev->dev,"IPC failed: %s, IPC_STS=0x%x\n" , -ipc_err_string (errcode), status); -return -EIO ; - } + cmd_list[0 ] |=CMD_RUN | cmd_list[1 ] <<CMD_PARA1_SHIFT | + cmd_list[2 ] <<CMD_PARA1_SHIFT ;return 0 ; } -/** -* intel_punit_ipc_simple_command() - Simple IPC command -* @cmd: IPC command code. -* @para1: First 8bit parameter, set 0 if not used. -* @para2: Second 8bit parameter, set 0 if not used. -* -* Send a IPC command to P-Unit when there is no data transaction -* -* Return: IPC error code or 0 on success. -*/ -int intel_punit_ipc_simple_command(int cmd, int para1, int para2) -{ -IPC_DEV *ipcdev = punit_ipcdev; -IPC_TYPE type; -u32 val; -int ret; - -mutex_lock (&ipcdev->lock); - -reinit_completion (&ipcdev->cmd_complete); - type = (cmd &IPC_PUNIT_CMD_TYPE_MASK ) >>IPC_TYPE_OFFSET ; - - val = cmd & ~IPC_PUNIT_CMD_TYPE_MASK ; - val |=CMD_RUN | para2 <<CMD_PARA2_SHIFT | para1 <<CMD_PARA1_SHIFT ; -ipc_write_cmd (ipcdev, type, val); - ret =intel_punit_ipc_check_status (ipcdev, type); - -mutex_unlock (&ipcdev->lock); - -return ret; -} -EXPORT_SYMBOL (intel_punit_ipc_simple_command); - -/** -* intel_punit_ipc_command() - IPC command with data and pointers -* @cmd: IPC command code. -* @para1: First 8bit parameter, set 0 if not used. -* @para2: Second 8bit parameter, set 0 if not used. -* @in: Input data, 32bit for BIOS cmd, two 32bit for GTD and ISPD.
- * @out: Output data.
- *
- * Send a IPC command to P-Unit with data transaction
- *
- * Return: IPC error code or 0 on success.
- */
-intintel_punit_ipc_command(u32 cmd, u32 para1, u32 para2, u32 *in, u32 *out)-{drivers/platform/x86/intel_punit_ipc.c +0
-18-IPC_DEV *ipcdev = punit_ipcdev; -IPC_TYPE type; -u32 val; -int ret; - -mutex_lock (&ipcdev->lock); - -reinit_completion (&ipcdev->cmd_complete); - type = (cmd &IPC_PUNIT_CMD_TYPE_MASK ) >>IPC_TYPE_OFFSET ; - -if (in) { -ipc_write_data_low (ipcdev, type, *in); -if (type ==GTDRIVER_IPC || type ==ISPDRIVER_IPC ) -ipc_write_data_high (ipcdev, type, *++in); - } - - val = cmd & ~IPC_PUNIT_CMD_TYPE_MASK ; - val |= CMD_RUN | para2 << CMD_PARA2_SHIFT | para1 <<
CMD_PARA1_SHIFT;drivers/platform/x86/intel_punit_ipc.c +32
-23-ipc_write_cmd (ipcdev, type, val); - - ret =intel_punit_ipc_check_status (ipcdev, type); -if (ret) - goto out; - -if (out) { - *out =ipc_read_data_low (ipcdev, type); -if (type ==GTDRIVER_IPC || type ==ISPDRIVER_IPC ) - *++out =ipc_read_data_high (ipcdev, type); - } - -out: -mutex_unlock (&ipcdev->lock); -return ret; -} -EXPORT_SYMBOL_GPL (intel_punit_ipc_command); - -static irqreturn_t intel_punit_ioc (int irq,void *dev_id) +/* Input data, 32bit for BIOS cmd, two 32bit for GTD and ISPD. */ int +pre_raw_cmd_fn (u32 *cmd_list,u32 cmdlen,u8 *in,u32 inlen,u32 *out, +u32 outlen,u32 dptr,u32 sptr) { -IPC_DEV *ipcdev = dev_id; - -complete (&ipcdev->cmd_complete); -return IRQ_HANDLED ; +return pre_simple_cmd_fn (cmd_list, cmdlen); } static int intel_punit_get_bars(struct platform_device *pdev) @@ -282,9 +137,77 @@ static int intel_punit_get_bars(struct platform_device *pdev) return 0; } +static int punit_ipc_err_code (int status) { +return (status &CMD_ERRCODE_MASK ); +} + +static int punit_ipc_busy_check (int status) { +return status |CMD_RUN ; +} + +static struct intel_ipc_dev *intel_punit_ipc_dev_create (struct device *dev, +const char *devname, +int irq, +void __iomem *base, +void __iomem *data) +{ +struct intel_ipc_dev_ops *ops; +struct intel_ipc_dev_cfg *cfg; +struct regmap *cmd_regs, *data_regs; + + cfg =devm_kzalloc (dev,sizeof (*cfg),GFP_KERNEL ); +if (!cfg) +return ERR_PTR (-ENOMEM ); + + ops =devm_kzalloc (dev,sizeof (*ops),GFP_KERNEL ); +if (!ops) +return ERR_PTR (-ENOMEM ); + + punit_regmap_config.name = devm_kasprintf(dev, GFP_KERNEL,"%s_%s",
drivers/platform/x86/intel_punit_ipc.c +10
-0+ devname, "base"); + + cmd_regs =devm_regmap_init_mmio_clk (dev,NULL , base, + &punit_regmap_config); +if (IS_ERR (cmd_regs)) { +dev_err (dev,"cmd_regs regmap init failed\n" ); +return ERR_CAST (cmd_regs);; + } + + punit_regmap_config.name = devm_kasprintf(dev, GFP_KERNEL,"%s_%s",
drivers/platform/x86/intel_punit_ipc.c +29
-1+ devname, "data"); + + data_regs =devm_regmap_init_mmio_clk (dev,NULL , data, + &punit_regmap_config); +if (IS_ERR (data_regs)) { +dev_err (dev,"data_regs regmap init failed\n" ); +return ERR_CAST (data_regs);; + } + +/* set IPC dev ops */ + ops->to_err_code = punit_ipc_err_code; + ops->busy_check = punit_ipc_busy_check; + ops->pre_simple_cmd_fn = pre_simple_cmd_fn; + ops->pre_raw_cmd_fn = pre_raw_cmd_fn; + +if (irq >0 ) + cfg->mode =IPC_DEV_MODE_IRQ ; +else + cfg->mode =IPC_DEV_MODE_POLLING ; + + cfg->chan_type =IPC_CHANNEL_IA_PUNIT ; + cfg->irq = irq; + cfg->irqflags =IRQF_NO_SUSPEND |IRQF_SHARED ; + cfg->cmd_regs = cmd_regs; + cfg->data_regs = data_regs; + +return devm_intel_ipc_dev_create (dev, devname, cfg, ops); } +static int intel_punit_ipc_probe (struct platform_device *pdev) { -int irq, ret; +int irq, ret, i; punit_ipcdev =devm_kzalloc (&pdev->dev, sizeof(*punit_ipcdev), GFP_KERNEL); @@ -294,35 +217,30 @@ static int
intel_punit_ipc_probe(struct platform_device *pdev)drivers/platform/x86/intel_punit_ipc.c +0
-9platform_set_drvdata (pdev, punit_ipcdev); irq =platform_get_irq (pdev,0 ); -if (irq <0 ) { - punit_ipcdev->irq =0 ; -dev_warn (&pdev->dev,"Invalid IRQ, using polling mode\n" ); - }else { - ret =devm_request_irq (&pdev->dev, irq, intel_punit_ioc, -IRQF_NO_SUSPEND ,"intel_punit_ipc" , - &punit_ipcdev); -if (ret) { - dev_err(&pdev->dev, "Failed to request irq: %d\n",irq);
drivers/platform/x86/intel_punit_ipc.c +16
-11-return ret; - } - punit_ipcdev->irq = irq; - } ret =intel_punit_get_bars (pdev);if (ret) - goto out; +return ret; + +for (i =0 ; i <RESERVED_IPC ; i++) { + punit_ipcdev->ipc_dev[i] =intel_punit_ipc_dev_create ( + &pdev->dev, + ipc_dev_name[i], + irq, + punit_ipcdev->base[i][BASE_IFACE ], + punit_ipcdev->base[i][BASE_DATA ]); + +if (IS_ERR (punit_ipcdev->ipc_dev[i])) { +dev_err (&pdev->dev,"%s create failed\n" , + ipc_dev_name[i]); +return PTR_ERR (punit_ipcdev->ipc_dev[i]); + } + } punit_ipcdev->dev = &pdev->dev; -mutex_init (&punit_ipcdev->lock); -init_completion (&punit_ipcdev->cmd_complete); -out:return ret; -} -static int intel_punit_ipc_remove(struct platform_device *pdev) -{ -return 0 ; } static const struct acpi_device_id punit_ipc_acpi_ids[] = { @@ -332,7 +250,6@@ static const struct
acpi_device_idpunit_ipc_acpi_ids[] = {static struct
platform_driverintel_punit_ipc_driver= {drivers/platform/x86/intel_punit_ipc.c +0
-1.probe = intel_punit_ipc_probe, - .remove = intel_punit_ipc_remove, .driver = { .name ="intel_punit_ipc" , .acpi_match_table = ACPI_PTR(punit_ipc_acpi_ids), diff --git
a/drivers/platform/x86/intel_telemetry_pltdrv.cb/drivers/platform/x86/intel_telemetry_pltdrv.c
index e0424d5..bf8284a 100644drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0
This is a logical separation and so should be a different patch.
drivers/platform/x86/intel_telemetry_pltdrv.c struct telem_ssram_region { }; · line 100
Quoted 4 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0@@ -98,6 +98,7 @@ struct telem_ssram_region { };static struct telemetry_plt_config *telm_conf; +static struct intel_ipc_dev *punit_bios_ipc_dev;
Simply punit_ipc_dev is good enough.
Quoted 29 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +0
-1/* * The following counters are programmed by default during setup. @@ -127,7 +128,6 @@ static struct telemetry_evtmap {"PMC_S0IX_BLOCK_IPS_CLOCKS", 0x600B}, }; -static struct telemetry_evtmap telemetry_apl_pss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0{"IA_CORE0_C6_RES", 0x0400},@@ -283,13 +283,12 @@ static inline int
telemetry_plt_config_ioss_event(u32 evt_id, int index)static inline inttelemetry_plt_config_pss_event(u32 evt_id, int index){drivers/platform/x86/intel_telemetry_pltdrv.c +1
-2u32 write_buf; -int ret; +u32 cmd[PUNIT_PARAM_LEN ] = {0 }; write_buf = evt_id |TELEM_EVENT_ENABLE ; - ret =intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT,
drivers/platform/x86/intel_telemetry_pltdrv.c +2
-3- index, 0, &write_buf, NULL); - -return ret; +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT , index,0 ); + return ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,
drivers/platform/x86/intel_telemetry_pltdrv.c static inline int telemetry_plt_config_ioss_event(u32 evt_id, int index) · line 292
Quoted 2 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0+ (u8 *)&write_buf, sizeof(write_buf), NULL, 0, 0, 0); }
1) Why use raw_cmd here? It should use ipc_dev_cmd() according to original design. Same everywhere though this file.
2) punit_cmd_init and ipc_dev_raw_cmd are repeated multiple time thoughout the file. They can be made into a separate local API inside telemetry, like telemetry_punit_send_cmd(). Same thoughout
Quoted 266 lines
static int telemetry_setup_iossevtconfig(struct
telemetry_evtconfig
evtconfig, @@ -435,6 +434,7 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfigevtconfig,drivers/platform/x86/intel_telemetry_pltdrv.c +3
-2int ret, index, idx;u32 *pss_evtmap;u32 telem_ctrl; +u32 cmd[PUNIT_PARAM_LEN ] = {0 }; num_pss_evts = evtconfig.num_evts; pss_period = evtconfig.period;@@ -442,8 +442,9 @@ static int telemetry_setup_pssevtconfig(struct telemetry_evtconfig evtconfig, /* PSS Config */ /* Get telemetry EVENT CTL */ - ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL, -0 ,0 ,NULL , &telem_ctrl); + punit_cmd_init(cmd, IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL, 0, 0); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN, NULL,drivers/platform/x86/intel_telemetry_pltdrv.c +3
-2+ 0, &telem_ctrl, 1, 0, 0);if (ret) {pr_err ("PSS TELEM_CTRL Read Failed\n" );return ret;@@ -451,8 +452,9 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,/* Disable Telemetry */ TELEM_DISABLE (telem_ctrl ); - ret =intel_punit_ipc_command (IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , 0); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3+ (u8 *)&telem_ctrl, sizeof(telem_ctrl), NULL, 0, 0, 0);if (ret) {pr_err ("PSS TELEM_CTRL Event Disable Write Failed\n" );return ret;@@ -463,9 +465,10 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,/* Clear All Events */ TELEM_CLEAR_EVENTS (telem_ctrl ); - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0if (ret) { pr_err("PSS TELEM_CTRL Event Disable WriteFailed\n");
drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3return ret;@@ -489,9 +492,10 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,/* Clear All Events */ TELEM_CLEAR_EVENTS (telem_ctrl ); - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0if (ret) { pr_err("PSS TELEM_CTRL Event Disable WriteFailed\n");
drivers/platform/x86/intel_telemetry_pltdrv.c +2
-2return ret;@@ -540,8 +544,9 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,TELEM_ENABLE_PERIODIC (telem_ctrl ); telem_ctrl |= pss_period; - ret =intel_punit_ipc_command (IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , 0); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +2
-0+ (u8 *)&telem_ctrl, sizeof(telem_ctrl), NULL, 0, 0, 0);if (ret) {pr_err ("PSS TELEM_CTRL Event Enable Write Failed\n" );return ret;@@ -601,6 +606,7 @@ static int telemetry_setup(struct platform_device *pdev) {struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;u32 read_buf, events, event_regs; +u32 cmd[PUNIT_PARAM_LEN ] = {0 };int ret; ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
IOSS_TELEM_INFO_READ, @@ -626,8 +632,9 @@ static inttelemetry_setup(struct platform_device *pdev)
telm_conf->ioss_config.max_period=TELEM_MAX_PERIOD(read_buf);drivers/platform/x86/intel_telemetry_pltdrv.c +0
-1/* PUNIT Mailbox Setup */ - ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_INFO,0, 0,
drivers/platform/x86/intel_telemetry_pltdrv.c +2
-1- NULL, &read_buf); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_READ_TELE_INFO ,0 ,0 ); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3+ NULL, 0, &read_buf, 1, 0, 0);if (ret) {dev_err (&pdev->dev,"PSS TELEM_INFO Read Failed\n" );return ret;@@ -695,6 +702,7 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period) {u32 telem_ctrl =0 ;int ret =0 ; +u32 cmd[PUNIT_PARAM_LEN ] = {0 };mutex_lock (&(telm_conf->telem_lock));if (ioss_period) {@@ -752,9 +760,9 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period) }/* Get telemetry EVENT CTL */ - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL , -0 ,0 ,NULL , &telem_ctrl); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , +NULL ,0 , &telem_ctrl,1 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3if (ret) {pr_err ("PSS TELEM_CTRL Read Failed\n" ); goto out;@@ -762,9 +770,11 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period)/* Disable Telemetry */ TELEM_DISABLE (telem_ctrl); - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , +0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0if (ret) { pr_err("PSS TELEM_CTRL Event Disable WriteFailed\n");
drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3goto out;@@ -776,9 +786,11 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period)TELEM_ENABLE_PERIODIC (telem_ctrl); telem_ctrl |= pss_period; - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , +0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0if (ret) { pr_err("PSS TELEM_CTRL Event Enable WriteFailed\n");
drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3goto out;@@ -1013,6 +1025,7 @@ static int telemetry_plt_get_trace_verbosity(enum telemetry_unit telem_unit, {u32 temp =0 ;int ret; +u32 cmd[PUNIT_PARAM_LEN ] = {0 };if (verbosity ==NULL )return -EINVAL ;@@ -1020,9 +1033,9 @@ static int telemetry_plt_get_trace_verbosity(enumtelemetry_unit telem_unit, mutex_lock(&(telm_conf->telem_trace_lock));switch (telem_unit) {case TELEM_PSS : - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL , -0 ,0 ,NULL , &temp); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , +NULL ,0 , &temp,1 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3if (ret) {pr_err ("PSS TRACE_CTRL Read Failed\n" ); goto out;@@ -1058,15 +1071,16 @@ static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit, {u32 temp =0 ;int ret; +u32 cmd[PUNIT_PARAM_LEN ] = {0 }; verbosity &=TELEM_TRC_VERBOSITY_MASK ;mutex_lock (&(telm_conf->telem_trace_lock));switch (telem_unit) {case TELEM_PSS : - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL , -0 ,0 ,NULL , &temp); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , +NULL ,0 , &temp,1 ,0 ,0 );if (ret) {drivers/platform/x86/intel_telemetry_pltdrv.c +4
-4pr_err ("PSS TRACE_CTRL Read Failed\n" ); goto out;@@ -1074,10 +1088,10 @@ static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit,TELEM_CLEAR_VERBOSITY_BITS (temp);TELEM_SET_VERBOSITY_BITS (temp, verbosity); - - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL , -0 ,0 , &temp,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , +0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&temp,sizeof (temp),NULL ,0 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +4
-0if (ret) {pr_err ("PSS TRACE_CTRL Verbosity Set Failed\n" ); goto out;@@ -1139,6 +1153,10 @@ static int telemetry_pltdrv_probe(struct platform_device *pdev)if (!id)return -ENODEV ; + punit_bios_ipc_dev =intel_ipc_dev_get (PUNIT_BIOS_IPC_DEV ); +if (IS_ERR_OR_NULL (punit_bios_ipc_dev)) +return PTR_ERR (punit_bios_ipc_dev); + telm_conf = (struct telemetry_plt_config *)id->driver_data;res0 =
platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -
1218,6 +1236,7 @@ static inttelemetry_pltdrv_probe(struct platform_device *pdev)static inttelemetry_pltdrv_remove(struct platform_device *pdev){drivers/platform/x86/intel_telemetry_pltdrv.c +1
-1telemetry_clear_pltdata (); +intel_ipc_dev_put (punit_bios_ipc_dev);iounmap (telm_conf->pss_config.regmap);iounmap (telm_conf->ioss_config.regmap); --2.7.4
RE: [RFC v5 7/8] platform/x86: intel_pmc_ipc: Use generic Intel IPC device calls
In reply to [email protected]Quoted 713 lines
From: [email protected] [mailto:[email protected]]
Sent: Sunday, October 8, 2017 3:50 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zha, Qipeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Chakravarty, Souvik K <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Kuppuswamy Sathyanarayanan <[email protected]>
Subject: [RFC v5 7/8] platform/x86:intel_pmc_ipc: Use generic Intel IPC device callsFrom: Kuppuswamy Sathyanarayanan
<[email protected]>Removed redundant IPC helper functions and refactored the driver to use generic IPC device driver APIs. Also, cleaned up the driver to minimize the usage of global variable ipcdev by propogating the struct
intel_pmc_ipc_devpointer or by getting it from device private data.This patch also cleans-up PMC IPC user
drivers(intel_telemetry_pltdrv.c, intel_soc_pmic_bxtwc.c)to use APIs provided by generic IPC driver.Signed-off-by: Kuppuswamy Sathyanarayanan
<[email protected]>--- arch/x86/include/asm/intel_pmc_ipc.h | 37 +-- drivers/mfd/intel_soc_pmic_bxtwc.c | 21 +- drivers/platform/x86/intel_pmc_ipc.c | 393 ++++++++++---------------- drivers/platform/x86/intel_telemetry_pltdrv.c | 119 ++++---- include/linux/mfd/intel_soc_pmic.h | 2 + 5 files changed, 238 insertions(+), 334 deletions(-)Changes since v4:
* NoneChanges since v3:
* Added unique name to PMC regmaps.
* Added support to clear interrupt bit.
* Addedintel_ipc_dev_put()support.Changes since v1:
* Removed custom APIs.
* Cleaned up PMC IPC user drivers to use APIs provided by generic IPC driver.arch/x86/include/asm/intel_pmc_ipc.h +12
-6@@ -1,10 +1,15 @@#ifndef _ASM_X86_INTEL_PMC_IPC_H_#define _ASM_X86_INTEL_PMC_IPC_H_ +#include <linux/platform_data/x86/intel_ipc_dev.h> + +#define INTEL_PMC_IPC_DEV "intel_pmc_ipc" +#define PMC_PARAM_LEN 2 +/* Commands */ #define PMC_IPC_PMIC_ACCESS 0xFF -#define PMC_IPC_PMIC_ACCESS_READ 0x0 -#define PMC_IPC_PMIC_ACCESS_WRITE 0x1 +#define PMC_IPC_PMIC_ACCESS_READ 0x0 +#define PMC_IPC_PMIC_ACCESS_WRITE 0x1#define PMC_IPC_USB_PWR_CTRL 0xF0#define PMC_IPC_PMIC_BLACKLIST_SEL 0xEF#define PMC_IPC_PHY_CONFIG 0xEE@@ -28,13 +33,14 @@#define PMC_GCR_TELEM_DEEP_S0IX_REG 0x78#define PMC_GCR_TELEM_SHLW_S0IX_REG 0x80 +static inline void pmc_cmd_init (u32 *cmd,u32 param1,u32 param2) { + cmd[0 ] = param1; + cmd[1 ] = param2; +} +#if IS_ENABLED (CONFIG_INTEL_PMC_IPC ) -int intel_pmc_ipc_simple_command(int cmd, int sub); -int intel_pmc_ipc_raw_cmd(u32 cmd, u32 sub, u8 *in, u32 inlen, - u32 *out, u32 outlen, u32 dptr, u32 sptr); -int intel_pmc_ipc_command (u32 cmd,u32 sub,u8 *in,u32 inlen, -u32 *out,u32 outlen); int intel_pmc_s0ix_counter_read(u64 *data); int intel_pmc_gcr_read(u32offset, u32 *data); int
intel_pmc_gcr_write(u32 offset, u32 data); @@ -42,23 +48,6 @@ intintel_pmc_gcr_update(u32 offset, u32 mask, u32 val);#else
arch/x86/include/asm/intel_pmc_ipc.h +0
-5-static inline int intel_pmc_ipc_simple_command(int cmd, int sub) -{ -return -EINVAL ; -} - -static inline int intel_pmc_ipc_raw_cmd(u32 cmd, u32 sub, u8 *in, u32inlen,
arch/x86/include/asm/intel_pmc_ipc.h +0
-6- u32 *out, u32 outlen, u32 dptr, u32 sptr) -{ - return -EINVAL; -} - -static inline int intel_pmc_ipc_command(u32 cmd, u32 sub, u8 *in, u32inlen,
arch/x86/include/asm/intel_pmc_ipc.h +0
-5- u32 *out, u32 outlen) -{ -return -EINVAL ; -} -static inline int intel_pmc_s0ix_counter_read (u64 *data) {return -EINVAL ;drivers/mfd/intel_soc_pmic_bxtwc.c +2
-0@@ -271,6 +271,8 @@ static int regmap_ipc_byte_reg_read(void *context,unsigned int reg, u8 ipc_in[2];u8 ipc_out[4 ];struct intel_soc_pmic *pmic = context; +u32 cmd[PMC_PARAM_LEN ] = {PMC_IPC_PMIC_ACCESS , +PMC_IPC_PMIC_ACCESS_READ };if (!pmic)drivers/mfd/intel_soc_pmic_bxtwc.c +2
-3return -EINVAL ;@@ -284,9 +286,8 @@ static int regmap_ipc_byte_reg_read(void *context,unsigned int reg, ipc_in[0 ] = reg; ipc_in[1 ] = i2c_addr; - ret =intel_pmc_ipc_command (PMC_IPC_PMIC_ACCESS , -PMC_IPC_PMIC_ACCESS_READ , - ipc_in,sizeof (ipc_in), (u32 *)ipc_out,1 ); + ret =ipc_dev_raw_cmd (pmic->ipc_dev, cmd,PMC_PARAM_LEN , ipc_in, +sizeof (ipc_in), (u32 *)ipc_out,1 ,0 ,0 );if (ret) {drivers/mfd/intel_soc_pmic_bxtwc.c +2
-0dev_err (pmic->dev,"Failed to read from PMIC\n" );return ret;@@ -303,6 +304,8 @@ static int regmap_ipc_byte_reg_write(void *context,unsigned int reg, int i2c_addr;u8 ipc_in[3 ];struct intel_soc_pmic *pmic = context; +u32 cmd[PMC_PARAM_LEN ] = {PMC_IPC_PMIC_ACCESS , +PMC_IPC_PMIC_ACCESS_WRITE };if (!pmic)drivers/mfd/intel_soc_pmic_bxtwc.c +2
-3return -EINVAL ;@@ -317,9 +320,8 @@ static int regmap_ipc_byte_reg_write(void *context,unsigned int reg, ipc_in[0 ] = reg; ipc_in[1 ] = i2c_addr; ipc_in[2 ] = val; - ret =intel_pmc_ipc_command (PMC_IPC_PMIC_ACCESS , -PMC_IPC_PMIC_ACCESS_WRITE , - ipc_in,sizeof (ipc_in),NULL ,0 ); + ret =ipc_dev_raw_cmd (pmic->ipc_dev, cmd,PMC_PARAM_LEN , ipc_in, +sizeof (ipc_in),NULL ,0 ,0 ,0 );if (ret) {drivers/mfd/intel_soc_pmic_bxtwc.c +4
-0dev_err (pmic->dev,"Failed to write to PMIC\n" );return ret;@@ -445,6 +447,10 @@ static int bxtwc_probe(struct platform_device *pdev)if (!pmic)return -ENOMEM ; + pmic->ipc_dev =intel_ipc_dev_get (INTEL_PMC_IPC_DEV ); +if (IS_ERR_OR_NULL (pmic->ipc_dev)) +return PTR_ERR (pmic->ipc_dev); + ret =platform_get_irq (pdev,0 );if (ret <0 ) {
dev_err(&pdev->dev, "Invalid IRQ\n"); @@ -562,7 +568,10
@@ static intbxtwc_probe(struct platform_device *pdev)static int
bxtwc_remove(struct platform_device *pdev){drivers/mfd/intel_soc_pmic_bxtwc.c +3
-0+struct intel_soc_pmic *pmic =dev_get_drvdata (&pdev->dev); +sysfs_remove_group (&pdev->dev.kobj, &bxtwc_group); +intel_ipc_dev_put (pmic->ipc_dev);return 0 ; }drivers/platform/x86/intel_pmc_ipc.c +26
-36@@ -47,18 +47,8 @@* The ARC handles the interrupt and services it, writing optional data to * the IPC1 registers, updates the IPC_STS response register with the status. */ -#define IPC_CMD 0x0 -#define IPC_CMD_MSI 0x100#define IPC_CMD_SIZE 16#define IPC_CMD_SUBCMD 12 -#define IPC_STATUS 0x04 -#define IPC_STATUS_IRQ 0x4 -#define IPC_STATUS_ERR 0x2 -#define IPC_STATUS_BUSY 0x1 -#define IPC_SPTR 0x08 -#define IPC_DPTR 0x0C -#define IPC_WRITE_BUFFER 0x80 -#define IPC_READ_BUFFER 0x90/* Residency with clock rate at 19.2MHz to usecs */ #define S0IX_RESIDENCY_IN_USECS (d, s) \@@ -73,11 +63,6 @@*/ #define IPC_DATA_BUFFER_SIZE 16 -#define IPC_LOOP_CNT 3000000 -#define IPC_MAX_SEC 3 - -#define IPC_TRIGGER_MODE_IRQ true -/* exported resources from IFWI */ #define PLAT_RESOURCE_IPC_INDEX 0#define PLAT_RESOURCE_IPC_SIZE 0x1000@@ -117,36 +102,41 @@#define PMC_CFG_NO_REBOOT_EN (1 << 4)#define PMC_CFG_NO_REBOOT_DIS (0 << 4) +/* IPC PMC commands */ +#define IPC_DEV_PMC_CMD_MSI BIT(8) +#define IPC_DEV_PMC_CMD_SIZE 16 +#define IPC_DEV_PMC_CMD_SUBCMD 12 +#define IPC_DEV_PMC_CMD_STATUS BIT(2) +#define IPC_DEV_PMC_CMD_STATUS_IRQ BIT(2) +#define IPC_DEV_PMC_CMD_STATUS_ERR BIT(1) +#define IPC_DEV_PMC_CMD_STATUS_ERR_MASK GENMASK(7, 0) +#define IPC_DEV_PMC_CMD_STATUS_BUSY BIT(0) + +/*IPC PMC reg offsets */ +#define IPC_DEV_PMC_STATUS_OFFSET 0x04 +#define IPC_DEV_PMC_SPTR_OFFSET 0x08 +#define IPC_DEV_PMC_DPTR_OFFSET 0x0C +#define IPC_DEV_PMC_WRBUF_OFFSET 0x80 +#define IPC_DEV_PMC_RBUF_OFFSET 0x90 +static struct intel_pmc_ipc_dev {struct device *dev; +struct intel_ipc_dev *pmc_ipc_dev; +struct intel_ipc_dev_ops ops; +struct intel_ipc_dev_cfg cfg;void __iomem *ipc_base; -bool irq_mode; -int irq; -int cmd; -struct completion cmd_complete;/* gcr */ void __iomem *gcr_mem_base;struct regmap *gcr_regs; } ipcdev; -static char *ipc_err_sources[] = { - [IPC_ERR_NONE ] = -"no error" , - [IPC_ERR_CMD_NOT_SUPPORTED ] = -"command not supported" , - [IPC_ERR_CMD_NOT_SERVICED ] = -"command not serviced" , - [IPC_ERR_UNABLE_TO_SERVICE ] = -"unable to service" , - [IPC_ERR_CMD_INVALID ] = -"command invalid" , - [IPC_ERR_CMD_FAILED ] = -"command failed" , - [IPC_ERR_EMSECURITY ] = -"Invalid Battery" , - [IPC_ERR_UNSIGNEDKERNEL ] = -"Unsigned kernel" , +static struct regmap_config pmc_regmap_config = { + .name ="intel_pmc_regs" , + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .fast_io = true, };static struct
regmap_configgcr_regmap_config= { @@ -158,40 +148,6 @@
static structregmap_configgcr_regmap_config= {drivers/platform/x86/intel_pmc_ipc.c +12
-103.max_register = PLAT_RESOURCE_GCR_SIZE, }; -/* Prevent concurrent calls to the PMC */ -static DEFINE_MUTEX(ipclock); - -static inline void ipc_send_command(u32 cmd) -{ - ipcdev.cmd = cmd; -if (ipcdev.irq_mode) { -reinit_completion (&ipcdev.cmd_complete); - cmd |=IPC_CMD_MSI ; - } -writel (cmd, ipcdev.ipc_base +IPC_CMD ); -} - -static inline u32 ipc_read_status(void) -{ -return readl (ipcdev.ipc_base +IPC_STATUS ); -} - -static inline void ipc_data_writel(u32 data, u32 offset) -{ -writel (data, ipcdev.ipc_base +IPC_WRITE_BUFFER + offset); -} - -static inline u8 __maybe_unused ipc_data_readb(u32 offset) -{ -return readb (ipcdev.ipc_base +IPC_READ_BUFFER + offset); -} - -static inline u32 ipc_data_readl(u32 offset) -{ -return readl (ipcdev.ipc_base +IPC_READ_BUFFER + offset); -} - -/** * intel_pmc_gcr_read() - Read PMC GCR register * @offset: offset of GCR register from GCR address base @@ -263,160 +219,109 @@ static int update_no_reboot_bit(void *priv, bool set) PMC_CFG_NO_REBOOT_MASK, value); } -static int intel_pmc_ipc_check_status (void ) +static int pre_simple_cmd_fn (u32 *cmd_list,u32 cmdlen) { -int status; -int ret =0 ; - -if (ipcdev.irq_mode) { -if (0 ==wait_for_completion_timeout ( - &ipcdev.cmd_complete,IPC_MAX_SEC *HZ )) - ret = -ETIMEDOUT ; - }else { -int loop_count =IPC_LOOP_CNT ; - -while ((ipc_read_status () &IPC_STATUS_BUSY ) && -- loop_count) -udelay (1 ); -if (loop_count ==0 ) - ret = -ETIMEDOUT ; - } - - status =ipc_read_status (); -if (ret == -ETIMEDOUT ) { -dev_err (ipcdev.dev, -"IPC timed out, TS=0x%x, CMD=0x%x\n" , - status, ipcdev.cmd); -return ret; - } +if (!cmd_list || cmdlen !=PMC_PARAM_LEN ) +return -EINVAL ; -if (status &IPC_STATUS_ERR ) { -int i; - - ret = -EIO ; - i = (status >>IPC_CMD_SIZE ) &0xFF ; -if (i <ARRAY_SIZE (ipc_err_sources)) -dev_err (ipcdev.dev, -"IPC failed: %s, STS=0x%x, CMD=0x%x\n" , - ipc_err_sources[i], status, ipcdev.cmd); -else -dev_err (ipcdev.dev, - "IPC failed: unknown, STS=0x%x, CMD=0x%x\n", - status, ipcdev.cmd); -if ((i ==IPC_ERR_UNSIGNEDKERNEL ) || (i == IPC_ERR_EMSECURITY)) - ret = -EACCES ; - } + cmd_list[0] |= (cmd_list[1] << IPC_CMD_SUBCMD); -return ret; +return 0 ; } -/** -* intel_pmc_ipc_simple_command() - Simple IPC command -* @cmd: IPC command code. -* @sub: IPC command sub type. -* -* Send a simple IPC command to PMC when don't need to specify -* input/output data and source/dest pointers. -* -* Return: an IPC error code or 0 on success. -*/ -int intel_pmc_ipc_simple_command (int cmd,int sub) +static int pre_raw_cmd_fn (u32 *cmd_list,u32 cmdlen,u8 *in,u32 inlen, +u32 *out,u32 outlen,u32 dptr,u32 sptr) {int ret; -mutex_lock (&ipclock); -if (ipcdev.dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } -ipc_send_command (sub <<IPC_CMD_SUBCMD | cmd); - ret =intel_pmc_ipc_check_status (); -mutex_unlock (&ipclock); +if (inlen >IPC_DATA_BUFFER_SIZE || outlen >IPC_DATA_BUFFER_SIZE /4 ) +return -EINVAL ; -return ret; -} -EXPORT_SYMBOL_GPL (intel_pmc_ipc_simple_command); + ret =pre_simple_cmd_fn (cmd_list, cmdlen); +if (ret <0 ) +return ret; -/** -* intel_pmc_ipc_raw_cmd() - IPC command with data and pointers -* @cmd: IPC command code. -* @sub: IPC command sub type. -* @in: input data of this IPC command. -* @inlen: input data length in bytes. -* @out: output data of this IPC command. -* @outlen: output data length in dwords. -* @sptr: data writing to SPTR register. -* @dptr: data writing to DPTR register. -* -* Send an IPC command to PMC with input/output data and source/dest pointers.
- *
- * Return: an IPC error code or 0 on success.
- */drivers/platform/x86/intel_pmc_ipc.c +1
-7-int intel_pmc_ipc_raw_cmd(u32 cmd, u32 sub, u8 *in, u32 inlen, u32 *out, - u32 outlen, u32 dptr, u32 sptr) -{ - u32 wbuf[4] = { 0 }; - int ret; - int i; + cmd_list[0 ] |= (inlen <<IPC_CMD_SIZE ); - if (inlen > IPC_DATA_BUFFER_SIZE || outlen >
IPC_DATA_BUFFER_SIZE/ 4)drivers/platform/x86/intel_pmc_ipc.c +16
-45-return -EINVAL ; +return 0 ; +} -mutex_lock (&ipclock); -if (ipcdev.dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } -memcpy (wbuf, in, inlen); -writel (dptr, ipcdev.ipc_base +IPC_DPTR ); -writel (sptr, ipcdev.ipc_base +IPC_SPTR ); -/* The input data register is 32bit register and inlen is in Byte */ -for (i =0 ; i < ((inlen +3 ) /4 ); i++) -ipc_data_writel (wbuf[i],4 * i); -ipc_send_command ((inlen <<IPC_CMD_SIZE ) | - (sub <<IPC_CMD_SUBCMD ) | cmd); - ret =intel_pmc_ipc_check_status (); -if (!ret) { -/* out is read from 32bit register and outlen is in 32bit */ -for (i =0 ; i < outlen; i++) - *out++ =ipc_data_readl (4 * i); - } -mutex_unlock (&ipclock); +static int pre_irq_handler_fn (struct intel_ipc_dev *ipc_dev,int irq) { +return regmap_write_bits (ipc_dev->cfg->cmd_regs, + ipc_dev->cfg->status_reg, +IPC_DEV_PMC_CMD_STATUS_IRQ , +IPC_DEV_PMC_CMD_STATUS_IRQ ); +} -return ret; +static int pmc_ipc_err_code (int status) { +return ((status >>IPC_DEV_PMC_CMD_SIZE ) & +IPC_DEV_PMC_CMD_STATUS_ERR_MASK ); } -EXPORT_SYMBOL_GPL (intel_pmc_ipc_raw_cmd); -/** -* intel_pmc_ipc_command() - IPC command with input/output data -* @cmd: IPC command code. -* @sub: IPC command sub type. -* @in: input data of this IPC command. -* @inlen: input data length in bytes. -* @out: output data of this IPC command. -* @outlen: output data length in dwords. -* -* Send an IPC command to PMC with input/output data. -* -* Return: an IPC error code or 0 on success. -*/ -int intel_pmc_ipc_command (u32 cmd,u32 sub,u8 *in,u32 inlen, -u32 *out,u32 outlen) +static int pmc_ipc_busy_check (int status) { -return intel_pmc_ipc_raw_cmd (cmd, sub, in, inlen, out, outlen,0 ,0 ); +return status |IPC_DEV_PMC_CMD_STATUS_BUSY ; } -EXPORT_SYMBOL_GPL (intel_pmc_ipc_command); -static irqreturn_t ioc (int irq,void *dev_id) +static u32 pmc_ipc_enable_msi (u32 cmd) { -int status; +return cmd |IPC_DEV_PMC_CMD_MSI ; +} -if (ipcdev.irq_mode) { - status =ipc_read_status (); - writel(status | IPC_STATUS_IRQ, ipcdev.ipc_base +
IPC_STATUS);drivers/platform/x86/intel_pmc_ipc.c +51
-3- } -complete (&ipcdev.cmd_complete); +static struct intel_ipc_dev *intel_pmc_ipc_dev_create ( +struct device *pmc_dev, +void __iomem *base, +int irq) +{ +struct intel_ipc_dev_ops *ops; +struct intel_ipc_dev_cfg *cfg; +struct regmap *cmd_regs; + + cfg =devm_kzalloc (pmc_dev,sizeof (*cfg),GFP_KERNEL ); +if (!cfg) +return ERR_PTR (-ENOMEM ); + + ops =devm_kzalloc (pmc_dev,sizeof (*ops),GFP_KERNEL ); +if (!ops) +return ERR_PTR (-ENOMEM ); + + cmd_regs =devm_regmap_init_mmio_clk (pmc_dev,NULL , base, + &pmc_regmap_config); +if (IS_ERR (cmd_regs)) { +dev_err (pmc_dev,"cmd_regs regmap init failed\n" ); +return ERR_CAST (cmd_regs);; + } -return IRQ_HANDLED ; +/* set IPC dev ops */ + ops->to_err_code = pmc_ipc_err_code; + ops->busy_check = pmc_ipc_busy_check; + ops->enable_msi = pmc_ipc_enable_msi; + ops->pre_raw_cmd_fn = pre_raw_cmd_fn; + ops->pre_simple_cmd_fn = pre_simple_cmd_fn; + ops->pre_irq_handler_fn = pre_irq_handler_fn; + +/* set cfg options */ +if (irq >0 ) + cfg->mode =IPC_DEV_MODE_IRQ ; +else + cfg->mode =IPC_DEV_MODE_POLLING ; + + cfg->chan_type =IPC_CHANNEL_IA_PMC ; + cfg->irq = irq; + cfg->use_msi = true; + cfg->support_sptr = true; + cfg->support_dptr = true; + cfg->cmd_regs = cmd_regs; + cfg->data_regs = cmd_regs; + cfg->wrbuf_reg =IPC_DEV_PMC_WRBUF_OFFSET ; + cfg->rbuf_reg =IPC_DEV_PMC_RBUF_OFFSET ; + cfg->sptr_reg =IPC_DEV_PMC_SPTR_OFFSET ; + cfg->dptr_reg =IPC_DEV_PMC_DPTR_OFFSET ; + cfg->status_reg =IPC_DEV_PMC_STATUS_OFFSET ; + + return devm_intel_ipc_dev_create(pmc_dev, INTEL_PMC_IPC_DEV,cfg,
drivers/platform/x86/intel_pmc_ipc.c +1
-2+ops); }static int ipc_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id)@@ -428,8 +333,6 @@ static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (pmc->dev)return -EBUSY ; - pmc->irq_mode =IPC_TRIGGER_MODE_IRQ ; - ret =pcim_enable_device (pdev);if (ret)drivers/platform/x86/intel_pmc_ipc.c +6
-7return ret;@@ -438,15 +341,14 @@ static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (ret) return ret; - init_completion(&pmc->cmd_complete); - pmc->ipc_base = pcim_iomap_table(pdev)[0]; - ret = devm_request_irq(&pdev->dev, pdev->irq, ioc, 0, "intel_pmc_ipc", - pmc); - if (ret) { -dev_err (&pdev->dev,"Failed to request irq\n" ); -return ret; + pmc->pmc_ipc_dev = intel_pmc_ipc_dev_create(&pdev->dev, + pmc->ipc_base, pdev->irq); + if (IS_ERR(pmc->pmc_ipc_dev)) { +dev_err (&pdev->dev, +"Failed to create PMC IPC device\n" ); +return PTR_ERR (pmc->pmc_ipc_dev); }drivers/platform/x86/intel_pmc_ipc.c +12
-11pmc->dev = &pdev->dev;@@ -474,19 +376,19 @@ static ssize_t intel_pmc_ipc_simple_cmd_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - int subcmd; -int cmd; + struct intel_pmc_ipc_dev *pmc = dev_get_drvdata(dev); +int cmd[2 ];int ret; - ret =sscanf (buf,"%d %d" , &cmd, &subcmd); + ret =sscanf (buf,"%d %d" , &cmd[0 ], &cmd[2 ]);if (ret !=2 ) {dev_err (dev,"Error args\n" );return -EINVAL ; } - ret =intel_pmc_ipc_simple_command (cmd, subcmd); + ret =ipc_dev_simple_cmd (pmc->pmc_ipc_dev, cmd,2 );if (ret) { -dev_err (dev,"command %d error with %d\n" , cmd, ret); +dev_err (dev,"command %d error with %d\n" , cmd[0 ], ret);return ret; }return (ssize_t )count;@@ -496,22 +398,23 @@ static ssize_t intel_pmc_ipc_northpeak_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { + struct intel_pmc_ipc_dev *pmc = dev_get_drvdata(dev);unsigned long val; -int subcmd; +int cmd[2 ] = {PMC_IPC_NORTHPEAK_CTRL ,0 };int ret;if (kstrtoul (buf,0 , &val))return -EINVAL ;if (val) - subcmd =1 ; -else - subcmd =0 ; - ret =intel_pmc_ipc_simple_command (PMC_IPC_NORTHPEAK_CTRL , subcmd); + cmd[1 ] =1 ; + + ret =ipc_dev_simple_cmd (pmc->pmc_ipc_dev, cmd,2 );if (ret) { -dev_err (dev,"command north %d error with %d\n" , subcmd, ret); +dev_err (dev,"command north %d error with %d\n" , cmd[1 ], ret);return ret; } +drivers/platform/x86/intel_pmc_ipc.c +4
-3return (ssize_t )count; }@@ -689,6 +592,7 @@ static int ipc_create_pmc_devices(struct platform_device *pdev)static int ipc_plat_get_res (struct platform_device *pdev) { +struct intel_pmc_ipc_dev *pmc =dev_get_drvdata (&pdev->dev);struct resource *res;void __iomem *addr;@@ -707,9 +611,9 @@ static int ipc_plat_get_res(struct platform_device *pdev)if (IS_ERR (addr))return PTR_ERR (addr); - ipcdev.ipc_base = addr; - ipcdev.gcr_mem_base = addr +PLAT_RESOURCE_GCR_OFFSET ; -dev_dbg (&pdev->dev,"PMC IPC resource %pR\n" , res); + pmc->ipc_base = addr; + pmc->gcr_mem_base = addr +PLAT_RESOURCE_GCR_OFFSET ; +dev_info (&pdev->dev,"PMC IPC resource %pR\n" , res);return 0 ;}
drivers/platform/x86/intel_pmc_ipc.c +7
-6@@ -755,14 +659,15 @@ MODULE_DEVICE_TABLE(acpi, ipc_acpi_ids);static int ipc_plat_probe (struct platform_device *pdev) { -int ret; +int ret, irq; +struct intel_pmc_ipc_dev *pmc = &ipcdev; + + pmc->dev = &pdev->dev; - ipcdev.dev = &pdev->dev; - ipcdev.irq_mode =IPC_TRIGGER_MODE_IRQ ; -init_completion (&ipcdev.cmd_complete); +dev_set_drvdata (&pdev->dev, pmc); - ipcdev.irq =platform_get_irq (pdev,0 ); -if (ipcdev.irq <0 ) { + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) {dev_err (&pdev->dev,"Failed to get irq\n" );return -EINVAL ; }@@ -773,11 +678,11 @@ static int ipc_plat_probe(struct platform_device *pdev)return ret; }
drivers/platform/x86/intel_pmc_ipc.c static int ipc_plat_probe(struct platform_device · line 686
Quoted 10 lines
drivers/platform/x86/intel_pmc_ipc.c +5
-5- ipcdev.gcr_regs =devm_regmap_init_mmio_clk (ipcdev.dev,NULL , - ipcdev.gcr_mem_base, &gcr_regmap_config); -if (IS_ERR (ipcdev.gcr_regs)) { -dev_err (ipcdev.dev,"gcr_regs regmap init failed\n" ); -return PTR_ERR (ipcdev.gcr_regs);; + pmc->gcr_regs =devm_regmap_init_mmio_clk (pmc->dev,NULL , + pmc->gcr_mem_base, &gcr_regmap_config); +if (IS_ERR (pmc->gcr_regs)) { +dev_err (&pdev->dev,"gcr_regs regmap init failed\n" ); +return PTR_ERR (pmc->gcr_regs);;
Extra semicolon on preceding line.
Quoted 31 lines
drivers/platform/x86/intel_pmc_ipc.c +0
-0}drivers/platform/x86/intel_pmc_ipc.c +7
-7ret =ipc_create_pmc_devices (pdev);@@ -786,20 +691,20 @@ static int ipc_plat_probe(struct platform_device *pdev)return ret; } -if (devm_request_irq (&pdev->dev, ipcdev.irq, ioc,IRQF_NO_SUSPEND , -"intel_pmc_ipc" , &ipcdev)) { -dev_err (&pdev->dev,"Failed to request irq\n" ); -return -EBUSY ; - } - ret =sysfs_create_group (&pdev->dev.kobj, &intel_ipc_group);if (ret) {dev_err (&pdev->dev,"Failed to create sysfs group %d\n" , ret); -devm_free_irq (&pdev->dev, ipcdev.irq, &ipcdev);return ret; } + ipcdev.pmc_ipc_dev =intel_pmc_ipc_dev_create (&pdev->dev, + pmc->ipc_base, irq); +if (IS_ERR (pmc->pmc_ipc_dev)) { +dev_err (&pdev->dev,"Failed to create PMC IPC device\n" ); +return PTR_ERR (pmc->pmc_ipc_dev); + } +return 0 ;
Quoted 2 lines
}
This part below can logically be a separate patch (alongwith intel_soc_pmic_bxtwc.c file too)
Quoted 42 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +1
-4@@ -56,10 +56,6 @@#define IOSS_TELEM_TRACE_CTL_WRITE 0x6#define IOSS_TELEM_EVENT_CTL_READ 0x7#define IOSS_TELEM_EVENT_CTL_WRITE 0x8 -#define IOSS_TELEM_EVT_CTRL_WRITE_SIZE 0x4 -#define IOSS_TELEM_READ_WORD 0x1 -#define IOSS_TELEM_WRITE_FOURBYTES 0x4 -#define IOSS_TELEM_EVT_WRITE_SIZE 0x3#define TELEM_INFO_SRAMEVTS_MASK 0xFF00#define TELEM_INFO_SRAMEVTS_SHIFT 0x8@@ -98,7 +94,7 @@ struct telem_ssram_region { }; static struct telemetry_plt_config *telm_conf; -static struct intel_ipc_dev *punit_bios_ipc_dev; +static struct intel_ipc_dev *punit_bios_ipc_dev, *pmc_ipc_dev;/* * The following counters are programmed by default during setup. @@ -267,17 +263,16 @@ static int telemetry_check_evtid(enum
telemetry_unittelem_unit, static inline inttelemetry_plt_config_ioss_event(u32 evt_id, int index){drivers/platform/x86/intel_telemetry_pltdrv.c +1
-3u32 write_buf; -int ret; +u32 cmd[PMC_PARAM_LEN ] = {0 }; write_buf = evt_id |TELEM_EVENT_ENABLE ; write_buf <<=BITS_PER_BYTE ; write_buf |= index; - ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY, - IOSS_TELEM_EVENT_WRITE, (u8*)&write_buf,
drivers/platform/x86/intel_telemetry_pltdrv.c +1
-1- IOSS_TELEM_EVT_WRITE_SIZE, NULL, 0); + pmc_cmd_init(cmd, PMC_IPC_PMC_TELEMTRY,
IOSS_TELEM_EVENT_WRITE);
drivers/platform/x86/intel_telemetry_pltdrv.c static int telemetry_check_evtid(enum telemetry_unit telem_unit, · line 275
Quoted 3 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +2
-1-return ret; +return ipc_dev_raw_cmd (pmc_ipc_dev, cmd,PMC_PARAM_LEN , + (u8 *)&write_buf,sizeof (write_buf),NULL ,0 ,0 ,0 );
1) Why use raw_cmd here? It should use ipc_dev_cmd() according to original design. Same everywhere though this file.
2) pmc_cmd_init and ipc_dev_raw_cmd are repeated multiple time thoughout the file. They can be made into a separate local API inside telemetry, like telemetry_pmc_send_cmd(). Same thoughout.
Quoted 285 lines
}
static inline int
telemetry_plt_config_pss_event(u32 evt_id, int index)@@ -
287,6 +282,7 @@ static inline inttelemetry_plt_config_pss_event(u32 evt_id, int index)drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0write_buf = evt_id |TELEM_EVENT_ENABLE ;punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT , index,0 ); + return ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3(u8 *)&write_buf, sizeof(write_buf), NULL, 0, 0, 0); }@@ -298,15 +294,16 @@ static int telemetry_setup_iossevtconfig(structtelemetry_evtconfig evtconfig, int ret, index, idx;u32 *ioss_evtmap;u32 telem_ctrl; +u32 cmd[PMC_PARAM_LEN ] = {0 }; num_ioss_evts = evtconfig.num_evts; ioss_period = evtconfig.period; ioss_evtmap = evtconfig.evtmap;/* Get telemetry EVENT CTL */ - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY , -IOSS_TELEM_EVENT_CTL_READ ,NULL ,0 , - &telem_ctrl,IOSS_TELEM_READ_WORD ); +pmc_cmd_init (cmd,PMC_IPC_PMC_TELEMTRY ,IOSS_TELEM_EVENT_CTL_READ ); + ret =ipc_dev_raw_cmd (pmc_ipc_dev, cmd,PMC_PARAM_LEN ,NULL ,0 , + &telem_ctrl,1 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +3
-6if (ret) {pr_err ("IOSS TELEM_CTRL Read Failed\n" );return ret;@@ -314,12 +311,9 @@ static int telemetry_setup_iossevtconfig(structtelemetry_evtconfig evtconfig,/* Disable Telemetry */ TELEM_DISABLE (telem_ctrl ); - - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY , -IOSS_TELEM_EVENT_CTL_WRITE , - (u8 *)&telem_ctrl, -IOSS_TELEM_EVT_CTRL_WRITE_SIZE , -NULL ,0 ); +pmc_cmd_init (cmd,PMC_IPC_PMC_TELEMTRY ,IOSS_TELEM_EVENT_CTL_WRITE ); + ret =ipc_dev_raw_cmd (pmc_ipc_dev, cmd,PMC_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL ,0 ,0 ,0 );if (ret) {drivers/platform/x86/intel_telemetry_pltdrv.c +5
-6pr_err ("IOSS TELEM_CTRL Event Disable Write Failed\n" );return ret;@@ -330,12 +324,11 @@ static int telemetry_setup_iossevtconfig(structtelemetry_evtconfig evtconfig, if (action == TELEM_RESET) {/* Clear All Events */ TELEM_CLEAR_EVENTS (telem_ctrl ); - - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY , -IOSS_TELEM_EVENT_CTL_WRITE , - (u8 *)&telem_ctrl, -IOSS_TELEM_EVT_CTRL_WRITE_SIZE , -NULL ,0 ); +pmc_cmd_init (cmd,PMC_IPC_PMC_TELEMTRY , +IOSS_TELEM_EVENT_CTL_WRITE ); + ret =ipc_dev_raw_cmd (pmc_ipc_dev, cmd,PMC_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl), +NULL ,0 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0if (ret) { pr_err("IOSS TELEM_CTRL Event Disable WriteFailed\n");
drivers/platform/x86/intel_telemetry_pltdrv.c +5
-5return ret;@@ -360,11 +353,11 @@ static int telemetry_setup_iossevtconfig(structtelemetry_evtconfig evtconfig,/* Clear All Events */ TELEM_CLEAR_EVENTS (telem_ctrl ); - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY , -IOSS_TELEM_EVENT_CTL_WRITE , - (u8 *)&telem_ctrl, -IOSS_TELEM_EVT_CTRL_WRITE_SIZE , -NULL ,0 ); +pmc_cmd_init (cmd,PMC_IPC_PMC_TELEMTRY , +IOSS_TELEM_EVENT_CTL_WRITE ); + ret =ipc_dev_raw_cmd (pmc_ipc_dev, cmd,PMC_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0if (ret) { pr_err("IOSS TELEM_CTRL Event Disable WriteFailed\n");
drivers/platform/x86/intel_telemetry_pltdrv.c +3
-4return ret;@@ -412,10 +405,9 @@ static int telemetry_setup_iossevtconfig(structtelemetry_evtconfig evtconfig,TELEM_ENABLE_PERIODIC (telem_ctrl ); telem_ctrl |= ioss_period; - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY , -IOSS_TELEM_EVENT_CTL_WRITE , - (u8 *)&telem_ctrl, -IOSS_TELEM_EVT_CTRL_WRITE_SIZE ,NULL , 0); +pmc_cmd_init (cmd,PMC_IPC_PMC_TELEMTRY ,IOSS_TELEM_EVENT_CTL_WRITE ); + ret =ipc_dev_raw_cmd (pmc_ipc_dev, cmd,PMC_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL ,0 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +1
-2if (ret) {pr_err ("IOSS TELEM_CTRL Event Enable Write Failed\n" );return ret;@@ -609,8 +601,9 @@ static int telemetry_setup(struct platform_device *pdev)u32 cmd[PUNIT_PARAM_LEN ] = {0 };int ret; - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY ,IOSS_TELEM_INFO_READ , -NULL ,0 , &read_buf, IOSS_TELEM_READ_WORD); + pmc_cmd_init(cmd, PMC_IPC_PMC_TELEMTRY,
IOSS_TELEM_INFO_READ);drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0+ ret = ipc_dev_raw_cmd(pmc_ipc_dev, cmd, PMC_PARAM_LEN, NULL,0,
drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3+ &read_buf, 1, 0, 0);if (ret) {dev_err (&pdev->dev,"IOSS TELEM_INFO Read Failed\n" );return ret;@@ -713,9 +706,10 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period) }/* Get telemetry EVENT CTL */ - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY , -IOSS_TELEM_EVENT_CTL_READ ,NULL ,0 , - &telem_ctrl, IOSS_TELEM_READ_WORD); +pmc_cmd_init (cmd,PMC_IPC_PMC_TELEMTRY , +IOSS_TELEM_EVENT_CTL_READ ); + ret = ipc_dev_raw_cmd(pmc_ipc_dev, cmd,
PMC_PARAM_LEN, NULL, 0,drivers/platform/x86/intel_telemetry_pltdrv.c +6
-6+ &telem_ctrl, 1, 0, 0);if (ret) {pr_err ("IOSS TELEM_CTRL Read Failed\n" ); goto out;@@ -723,12 +717,11 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period)/* Disable Telemetry */ TELEM_DISABLE (telem_ctrl); - - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY , -IOSS_TELEM_EVENT_CTL_WRITE , - (u8 *)&telem_ctrl, -IOSS_TELEM_EVT_CTRL_WRITE_SIZE , -NULL ,0 ); +pmc_cmd_init (cmd,PMC_IPC_PMC_TELEMTRY , +IOSS_TELEM_EVENT_CTL_WRITE ); + ret =ipc_dev_raw_cmd (pmc_ipc_dev, cmd,PMC_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0if (ret) { pr_err("IOSS TELEM_CTRL Event Disable WriteFailed\n");
drivers/platform/x86/intel_telemetry_pltdrv.c +5
-5goto out;@@ -740,11 +733,11 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period)TELEM_ENABLE_PERIODIC (telem_ctrl); telem_ctrl |= ioss_period; - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY , -IOSS_TELEM_EVENT_CTL_WRITE , - (u8 *)&telem_ctrl, -IOSS_TELEM_EVT_CTRL_WRITE_SIZE , -NULL ,0 ); +pmc_cmd_init (cmd,PMC_IPC_PMC_TELEMTRY , +IOSS_TELEM_EVENT_CTL_WRITE ); + ret =ipc_dev_raw_cmd (pmc_ipc_dev, cmd,PMC_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0if (ret) { pr_err("IOSS TELEM_CTRL Event Enable WriteFailed\n");
drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3goto out;@@ -1044,9 +1037,10 @@ static int telemetry_plt_get_trace_verbosity(enum telemetry_unit telem_unit, break;case TELEM_IOSS : - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY , -IOSS_TELEM_TRACE_CTL_READ ,NULL ,0 , &temp, -IOSS_TELEM_READ_WORD ); +pmc_cmd_init (cmd,PMC_IPC_PMC_TELEMTRY , +IOSS_TELEM_TRACE_CTL_READ ); + ret =ipc_dev_raw_cmd (pmc_ipc_dev, cmd,PMC_PARAM_LEN ,NULL ,0 , + &temp,1 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3if (ret) {pr_err ("IOSS TRACE_CTL Read Failed\n" ); goto out;@@ -1099,9 +1093,10 @@ static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit, break;case TELEM_IOSS : - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY , -IOSS_TELEM_TRACE_CTL_READ ,NULL ,0 , &temp, -IOSS_TELEM_READ_WORD ); +pmc_cmd_init (cmd,PMC_IPC_PMC_TELEMTRY , +IOSS_TELEM_TRACE_CTL_READ ); + ret =ipc_dev_raw_cmd (pmc_ipc_dev, cmd,PMC_PARAM_LEN ,NULL ,0 , + &temp,1 ,0 ,0 );drivers/platform/x86/intel_telemetry_pltdrv.c +2
-4if (ret) {pr_err ("IOSS TRACE_CTL Read Failed\n" ); goto out;@@ -1109,10 +1104,9 @@ static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit,TELEM_CLEAR_VERBOSITY_BITS (temp);TELEM_SET_VERBOSITY_BITS (temp, verbosity); - - ret =intel_pmc_ipc_command (PMC_IPC_PMC_TELEMTRY , -IOSS_TELEM_TRACE_CTL_WRITE , (u8 *)&temp, -IOSS_TELEM_WRITE_FOURBYTES ,NULL ,0 ); +pmc_cmd_init (cmd,PMC_IPC_PMC_TELEMTRY ,IOSS_TELEM_TRACE_CTL_WRITE ); + ret = ipc_dev_raw_cmd(pmc_ipc_dev, cmd,
PMC_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +5
-0+ (u8 *)&temp, sizeof(temp), NULL, 0, 0, 0);if (ret) {pr_err ("IOSS TRACE_CTL Verbosity Set Failed\n" ); goto out;@@ -1157,6 +1151,10 @@ static int telemetry_pltdrv_probe(struct platform_device *pdev)if (IS_ERR_OR_NULL (punit_bios_ipc_dev))return PTR_ERR (punit_bios_ipc_dev); + pmc_ipc_dev =intel_ipc_dev_get (INTEL_PMC_IPC_DEV ); +if (IS_ERR_OR_NULL (pmc_ipc_dev)) +return PTR_ERR (pmc_ipc_dev); + telm_conf = (struct telemetry_plt_config *)id->driver_data;res0 =
platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -
1236,6 +1234,7 @@ static inttelemetry_pltdrv_probe(struct platform_device *pdev)static inttelemetry_pltdrv_remove(struct platform_device *pdev){drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0telemetry_clear_pltdata (); +intel_ipc_dev_put (pmc_ipc_dev);intel_ipc_dev_put (punit_bios_ipc_dev);iounmap (telm_conf->pss_config.regmap);iounmap (telm_conf->ioss_config.regmap);include/linux/mfd/intel_soc_pmic.h +2
-1@@ -20,6 +20,7 @@#define __INTEL_SOC_PMIC_H__#include <linux/regmap.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> struct intel_soc_pmic {int irq;@@ -31,6 +32,7 @@ struct intel_soc_pmic {struct regmap_irq_chip_data *irq_chip_data_chgr;struct regmap_irq_chip_data *irq_chip_data_crit;struct device *dev; + struct intel_ipc_dev *ipc_dev; };#endif /* __INTEL_SOC_PMIC_H__ */ --2.7.4
Re: [RFC v5 4/8] platform: x86: Add generic Intel IPC driver
In reply to Chakravarty, Souvik KWhat does IPC stand for in this device?
Re: [RFC v5 4/8] platform: x86: Add generic Intel IPC driver
Hi,
Quoted 1 line · Christoph Hellwig
What does IPC stand for in this device?
Inter processor communication
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux kernel developer
Re: [RFC v5 4/8] platform: x86: Add generic Intel IPC driver
Quoted 6 lines · sathyanarayanan kuppuswamy
Hi,
Quoted 1 line · Christoph Hellwig
What does IPC stand for in this device?
Inter processor communication
Id would suggest to explain that, as it's not how we usually use the term in Linux?
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC v5 4/8] platform: x86: Add generic Intel IPC driver
In reply to Chakravarty, Souvik KHi,
Quoted 361 lines · Souvik K
Quoted 361 lines
From: [email protected] [mailto:[email protected]]
Sent: Sunday, October 8, 2017 3:50 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zha, Qipeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Chakravarty, Souvik K <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Kuppuswamy Sathyanarayanan <[email protected]>
Subject: [RFC v5 4/8] platform: x86: Add generic Intel IPC driverFrom: Kuppuswamy Sathyanarayanan
<[email protected]>Currently
intel_scu_ipc.c,intel_pmc_ipc.candintel_punit_ipc.credundantly implements the same IPC features and has lot of code duplication between them. This driver addresses this issue by grouping the common IPC functionalities under the same driver.Signed-off-by: Kuppuswamy Sathyanarayanan
<[email protected]>--- drivers/platform/x86/Kconfig | 8 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_ipc_dev.c | 576 ++++++++++++++++++++++++ include/linux/platform_data/x86/intel_ipc_dev.h | 206 +++++++++ 4 files changed, 791 insertions(+)create mode 100644
drivers/platform/x86/intel_ipc_dev.ccreate mode 100644include/linux/platform_data/x86/intel_ipc_dev.hChanges since v4:
* NoneChanges since v3:
* Fixed NULL pointer exception inintel_ipc_dev_get().
* Fixed error in check for duplicateintel_ipc_dev.
* Added custom interrupt handler support.
* Used char array for error string conversion.
* Added put dev support.
* Added devm_* variant ofintel_ipc_dev_get().Changes since v2:
* Addedipc_dev_cmdAPI support.drivers/platform/x86/Kconfig +8
-0@@ -1153,6 +1153,14 @@ config SILEAD_DMI with the OS-image for the device. This option supplies the missing information. Enable this for x86 tablets with Silead touchscreens. +config INTEL_IPC_DEV + bool "Intel IPC Device Driver" + depends on X86_64 + ---help--- + This driver implements core features of Intel IPC device. Devices + like PMC, SCU, PUNIT, etc can use interfaces provided by this + driver to implement IPC protocol of their respective device. + endif # X86_PLATFORM_DEVICES config PMC_ATOMdrivers/platform/x86/Makefile +0
-0@@ -84,3 +84,4 @@ obj-$(CONFIG_PMC_ATOM) +=pmc_atom.o
obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o
obj-$(CONFIG_MLX_CPLD_PLATFORM) += mlxcpld-hotplug.o
obj-$(CONFIG_INTEL_TURBO_MAX_3) += intel_turbo_max_3.odrivers/platform/x86/Makefile +1
-0+obj-$(CONFIG_INTEL_IPC_DEV) += intel_ipc_dev.odrivers/platform/x86/intel_ipc_dev.c new file +116
-0@@ -0,0 +1,576 @@ +/* +* intel_ipc_dev.c: Intel IPC device class driver +* +* (C) Copyright 2017 Intel Corporation +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; version 2 +* of the License. +* +*/ + +#include <linux/device.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/export.h> +#include <linux/idr.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/interrupt.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> +#include <linux/regmap.h> + +/* mutex to sync different ipc devices in same channel */ static struct +mutex channel_lock[IPC_CHANNEL_MAX ]; + +static char *ipc_err_sources[] = { + [IPC_DEV_ERR_NONE ] = +"No error" , + [IPC_DEV_ERR_CMD_NOT_SUPPORTED ] = +"Command not-supported/Invalid" , + [IPC_DEV_ERR_CMD_NOT_SERVICED ] = +"Command not-serviced/Invalid param" , + [IPC_DEV_ERR_UNABLE_TO_SERVICE ] = +"Unable-to-service/Cmd-timeout" , + [IPC_DEV_ERR_CMD_INVALID ] = +"Command-invalid/Cmd-locked" , + [IPC_DEV_ERR_CMD_FAILED ] = +"Command-failed/Invalid-VR-id" , + [IPC_DEV_ERR_EMSECURITY ] = +"Invalid Battery/VR-Error" , + [IPC_DEV_ERR_UNSIGNEDKERNEL ] = +"Unsigned kernel" , +}; + +static void ipc_channel_lock_init (void ) { +int i; + +for (i =0 ; i <IPC_CHANNEL_MAX ; i++) +mutex_init (&channel_lock[i]); +} + +static struct class intel_ipc_class = { + .name ="intel_ipc" , + .owner =THIS_MODULE , +}; + +static int ipc_dev_lock (struct intel_ipc_dev *ipc_dev) { +int chan_type; + +if (!ipc_dev || !ipc_dev->cfg) +return -ENODEV ; + + chan_type = ipc_dev->cfg->chan_type; +if (chan_type >IPC_CHANNEL_MAX ) +return -EINVAL ; + +/* acquire channel lock */ +mutex_lock (&channel_lock[chan_type]); + +/* acquire IPC device lock */ +mutex_lock (&ipc_dev->lock); + +return 0 ; +} + +static int ipc_dev_unlock (struct intel_ipc_dev *ipc_dev) { +int chan_type; + +if (!ipc_dev || !ipc_dev->cfg) +return -ENODEV ; + + chan_type = ipc_dev->cfg->chan_type; +if (chan_type >IPC_CHANNEL_MAX ) +return -EINVAL ; + +/* release IPC device lock */ +mutex_unlock (&ipc_dev->lock); + +/* release channel lock */ +mutex_unlock (&channel_lock[chan_type]); + +return 0 ; +} + +static const char *ipc_dev_err_string (struct intel_ipc_dev *ipc_dev, +int error) +{ +if (error <IPC_DEV_ERR_MAX ) +return ipc_err_sources[error]; + +return "Unknown Command" ; +} + +/* Helper function to send given command to IPC device */ static inline +void ipc_dev_send_cmd (struct intel_ipc_dev *ipc_dev,u32 cmd) { + ipc_dev->cmd = cmd; + +if (ipc_dev->cfg->mode ==IPC_DEV_MODE_IRQ ) +reinit_completion (&ipc_dev->cmd_complete); + +if (ipc_dev->ops->enable_msi) + cmd = ipc_dev->ops->enable_msi (cmd); + +regmap_write (ipc_dev->cfg->cmd_regs, ipc_dev->cfg->cmd_reg, cmd);}
drivers/platform/x86/intel_ipc_dev.c new file +33
-0+ +static inline int ipc_dev_status_busy (struct intel_ipc_dev *ipc_dev) { +int status; + +regmap_read (ipc_dev->cfg->cmd_regs, ipc_dev->cfg->status_reg, +&status); + +if (ipc_dev->ops->busy_check) +return ipc_dev->ops->busy_check (status); + +return 0 ; +} + +/* Check the status of IPC command and return err code if failed */ +static int ipc_dev_check_status (struct intel_ipc_dev *ipc_dev) { +int loop_count =IPC_DEV_CMD_LOOP_CNT ; +int status; +int ret =0 ; + +if (ipc_dev->cfg->mode ==IPC_DEV_MODE_IRQ ) { +if (!wait_for_completion_timeout (&ipc_dev->cmd_complete, +IPC_DEV_CMD_TIMEOUT )) + ret = -ETIMEDOUT ; + }else { +while (ipc_dev_status_busy (ipc_dev) && --loop_count) +udelay (1 ); +if (!loop_count) + ret = -ETIMEDOUT ; + } + +if (ret <0 ) { + dev_err(&ipc_dev->dev, + "IPC timed out, CMD=0x%x\n", ipc_dev-Quoted 1 line
cmd);
drivers/platform/x86/intel_ipc_dev.c new file +126
-0+return ret; + } + +regmap_read (ipc_dev->cfg->cmd_regs, ipc_dev->cfg->status_reg, +&status); + +if (ipc_dev->ops->to_err_code) + ret = ipc_dev->ops->to_err_code (status); + +if (ret) { +dev_err (&ipc_dev->dev, +"IPC failed: %s, STS=0x%x, CMD=0x%x\n" , +ipc_dev_err_string (ipc_dev, ret), + status, ipc_dev->cmd); +return -EIO ; + } + +return 0 ; +} + +/** +* ipc_dev_simple_cmd() - Send simple IPC command +* @ipc_dev : Reference to ipc device. +* @cmd_list : IPC command list. +* @cmdlen : Number of cmd/sub-cmds. +* +* Send a simple IPC command to ipc device. +* Use this when don't need to specify input/output data +* and source/dest pointers. +* +* Return: an IPC error code or 0 on success. +*/ + +int ipc_dev_simple_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list, +u32 cmdlen) +{ +int ret; + +if (!cmd_list) +return -EINVAL ; + + ret =ipc_dev_lock (ipc_dev); +if (ret) +return ret; + +/* Call custom pre-processing handler */ +if (ipc_dev->ops->pre_simple_cmd_fn) { + ret = ipc_dev->ops->pre_simple_cmd_fn (cmd_list, cmdlen); +if (ret) + goto unlock_device; + } + +ipc_dev_send_cmd (ipc_dev, cmd_list[0 ]); + + ret =ipc_dev_check_status (ipc_dev); + +unlock_device: +ipc_dev_unlock (ipc_dev); + +return ret; +} +EXPORT_SYMBOL_GPL (ipc_dev_simple_cmd); + +/** +* ipc_dev_cmd() - Send IPC command with data. +* @ipc_dev : Reference to ipc_dev. +* @cmd_list : Array of commands/sub-commands. +* @cmdlen : Number of commands. +* @in : Input data of this IPC command. +* @inlen : Input data length in dwords. +* @out : Output data of this IPC command. +* @outlen : Length of output data in dwords. +* +* Send an IPC command to device with input/output data. +* +* Return: an IPC error code or 0 on success. +*/ +int ipc_dev_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list,u32 cmdlen, +u32 *in,u32 inlen,u32 *out,u32 outlen) { +int ret; + +if (!cmd_list || !in) +return -EINVAL ; + + ret =ipc_dev_lock (ipc_dev); +if (ret) +return ret; + +/* Call custom pre-processing handler. */ +if (ipc_dev->ops->pre_cmd_fn) { + ret = ipc_dev->ops->pre_cmd_fn (cmd_list, cmdlen, in, inlen, + out, outlen); +if (ret) + goto unlock_device; + } + +/* Write inlen dwords of data to wrbuf_reg. */ +if (inlen >0 ) +regmap_bulk_write (ipc_dev->cfg->data_regs, + ipc_dev->cfg->wrbuf_reg, in, inlen); + +ipc_dev_send_cmd (ipc_dev, cmd_list[0 ]); + + ret =ipc_dev_check_status (ipc_dev); + +/* Read outlen dwords of data from rbug_reg. */ +if (!ret && outlen >0 ) +regmap_bulk_read (ipc_dev->cfg->data_regs, + ipc_dev->cfg->rbuf_reg, out, outlen); +unlock_device: +ipc_dev_unlock (ipc_dev); + +return ret; +} +EXPORT_SYMBOL_GPL (ipc_dev_cmd); + +/** +* ipc_dev_raw_cmd() - Send IPC command with data and pointers. +* @ipc_dev : Reference to ipc_dev. +* @cmd_list : Array of commands/sub-commands. +* @cmdlen : Number of commands. +* @in : Input data of this IPC command. +* @inlen : Input data length in bytes. +* @out : Output data of this IPC command. +* @outlen : Length of output data in dwords. +* @dptr : IPC destination data address.
Quoted 8 lines
Quoted 7 lines
+ * @sptr : IPC source data address.
+ *
+ * Send an IPC command to device with input/output data and
+ * source/dest pointers.
+ *
+ * Return: an IPC error code or 0 on success.
+ */Sorry for coming in so late but since we are refactoring the API anyways, isn't it better to reduce the signature? Nine parameters is an awful lot and prone to errors and difficult to debug. (We found it out the hard way when we started using this a few years ago.)
I agree. Initially I thought of adding a command structure just like you mentioned. But finally decided not to do it because,
1. Not all drivers uses all parameters of this API. Most of them pass 0,0 for DPTR and SPTR pointers. So the last two arguments are almost not used.
2. Adding a new structure requires all users of this API to add buffer code / some additional call to initialize the command structure which in turn makes the code look bit complex.
So I am not really sure whether it add any value. But if its the recommended approach then I will make that modification.
Quoted 506 lines
This can be consolidated into a few neat structs, e.g.,:
int ipc_dev_raw_cmd(structintel_ipc_dev*ipc_dev, structipc_cmd*cmd,
structipc_cmd_data*cmd_data, structipc_data_addr*addr)Same for the
ipc_dev_cmd()APIs above as well.Quoted 499 lines
drivers/platform/x86/intel_ipc_dev.c new file +2
-0+ +int ipc_dev_raw_cmd(struct intel_ipc_dev *ipc_dev, u32 *cmd_list, u32cmdlen,
drivers/platform/x86/intel_ipc_dev.c new file +19
-0+ u8 *in, u32 inlen, u32 *out, u32 outlen, u32 dptr, u32 sptr) { + int ret; +int inbuflen =DIV_ROUND_UP (inlen,4 ); +u32 *inbuf; + +if (!cmd_list || !in) +return -EINVAL ; + + inbuf =kzalloc (inbuflen,GFP_KERNEL ); +if (!inbuf) +return -ENOMEM ; + + ret =ipc_dev_lock (ipc_dev); +if (ret) +return ret; + +/* Call custom pre-processing handler. */ + if (ipc_dev->ops->pre_raw_cmd_fn) { + ret = ipc_dev->ops->pre_raw_cmd_fn(cmd_list, cmdlen, in,inlen,
drivers/platform/x86/intel_ipc_dev.c new file +8
-0+ out, outlen, dptr, sptr); +if (ret) + goto unlock_device; + } + +/* If supported, write DPTR register.*/ +if (ipc_dev->cfg->support_dptr) + regmap_write(ipc_dev->cfg->cmd_regs, ipc_dev->cfg-Quoted 1 line
dptr_reg,drivers/platform/x86/intel_ipc_dev.c new file +5
-0+ dptr); + +/* If supported, write SPTR register. */ +if (ipc_dev->cfg->support_sptr) + regmap_write(ipc_dev->cfg->cmd_regs, ipc_dev->cfg-Quoted 1 line
sptr_reg,drivers/platform/x86/intel_ipc_dev.c new file +105
-0+ sptr); + +memcpy (inbuf, in, inlen); + +/* Write inlen dwords of data to wrbuf_reg. */ +if (inlen >0 ) +regmap_bulk_write (ipc_dev->cfg->data_regs, + ipc_dev->cfg->wrbuf_reg, inbuf, inbuflen); + +ipc_dev_send_cmd (ipc_dev, cmd_list[0 ]); + + ret =ipc_dev_check_status (ipc_dev); + +/* Read outlen dwords of data from rbug_reg. */ +if (!ret && outlen >0 ) +regmap_bulk_read (ipc_dev->cfg->data_regs, + ipc_dev->cfg->rbuf_reg, out, outlen); +unlock_device: +ipc_dev_unlock (ipc_dev); +kfree (inbuf); + +return ret; +} +EXPORT_SYMBOL_GPL (ipc_dev_raw_cmd); + +/* sysfs option to send simple IPC commands from userspace */ static +ssize_t ipc_dev_cmd_reg_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) { +struct intel_ipc_dev *ipc_dev =dev_get_drvdata (dev); +u32 cmd; +int ret; + + ret =sscanf (buf,"%d" , &cmd); +if (ret !=1 ) { +dev_err (dev,"Error args\n" ); +return -EINVAL ; + } + + ret =ipc_dev_simple_cmd (ipc_dev, &cmd,1 ); +if (ret) { +dev_err (dev,"command 0x%x error with %d\n" , cmd, ret); +return ret; + } +return (ssize_t )count; +} + +static DEVICE_ATTR(send_cmd, S_IWUSR, NULL, ipc_dev_cmd_reg_store); + +static struct attribute *ipc_dev_attrs[] = { + &dev_attr_send_cmd.attr, +NULL +}; + +static const struct attribute_group ipc_dev_group = { + .attrs = ipc_dev_attrs, +}; + +static const struct attribute_group *ipc_dev_groups[] = { + &ipc_dev_group, +NULL , +}; + +/* IPC device IRQ handler */ +static irqreturn_t ipc_dev_irq_handler (int irq,void *dev_id) { +struct intel_ipc_dev *ipc_dev = (struct intel_ipc_dev *)dev_id; + +if (ipc_dev->ops->pre_irq_handler_fn) + ipc_dev->ops->pre_irq_handler_fn (ipc_dev, irq); + +complete (&ipc_dev->cmd_complete); + +return IRQ_HANDLED ; +} + +static void devm_intel_ipc_dev_release (struct device *dev,void *res) { +struct intel_ipc_dev *ipc_dev = *(struct intel_ipc_dev **)res; + +if (!ipc_dev) +return ; + +device_del (&ipc_dev->dev); + +kfree (ipc_dev); +} + +static int match_name (struct device *dev,const void *data) { +if (!dev_name (dev)) +return 0 ; + +return !strcmp (dev_name (dev), (char *)data); } + +/** +* intel_ipc_dev_get() - Get Intel IPC device from name. +* @dev_name : Name of the IPC device. +* +* Return : ERR_PTR/NULL or intel_ipc_dev pointer on success. +*/ +struct intel_ipc_dev *intel_ipc_dev_get (const char *dev_name) { +struct device *dev; + +if (!dev_name) +return ERR_PTR (-EINVAL ); + + dev = class_find_device(&intel_ipc_class, NULL, dev_name,
match_name);drivers/platform/x86/intel_ipc_dev.c new file +9
-0+ +return dev ?dev_get_drvdata (dev) :NULL ; } +EXPORT_SYMBOL_GPL (intel_ipc_dev_get); + +static void devm_intel_ipc_dev_put (struct device *dev,void *res) { +intel_ipc_dev_put (*(struct intel_ipc_dev **)res); } + +/** +* devm_intel_ipc_dev_get() - Resource managed version of
intel_ipc_dev_get().
+ * @dev : Device pointer.
+ * @dev_name : Name of the IPC device.
+ *
+ * Return : ERR_PTR/NULL orintel_ipc_devpointer on success.
+ */drivers/platform/x86/intel_ipc_dev.c new file +6
-0+struct intel_ipc_dev *devm_intel_ipc_dev_get (struct device *dev, +const char *dev_name) +{ +struct intel_ipc_dev **ptr, *ipc_dev; + + ptr = devres_alloc(devm_intel_ipc_dev_put, sizeof(*ptr),
GFP_KERNEL);drivers/platform/x86/intel_ipc_dev.c new file +118
-0+if (!ptr) +return ERR_PTR (-ENOMEM ); + + ipc_dev =intel_ipc_dev_get (dev_name); +if (!IS_ERR_OR_NULL (ipc_dev)) { + *ptr = ipc_dev; +devres_add (dev, ptr); + }else { +devres_free (ptr); + } + +return ipc_dev; +} +EXPORT_SYMBOL_GPL (devm_intel_ipc_dev_get); + +/** +* devm_intel_ipc_dev_create() - Create IPC device +* @dev : IPC parent device. +* @devname : Name of the IPC device. +* @cfg : IPC device configuration. +* @ops : IPC device ops. +* +* Resource managed API to create IPC device with +* given configuration. +* +* Return : IPC device pointer or ERR_PTR(error code). +*/ +struct intel_ipc_dev *devm_intel_ipc_dev_create (struct device *dev, +const char *devname, +struct intel_ipc_dev_cfg *cfg, +struct intel_ipc_dev_ops *ops) +{ +struct intel_ipc_dev **ptr, *ipc_dev; +int ret; + +if (!dev && !devname && !cfg) +return ERR_PTR (-EINVAL ); + +if (intel_ipc_dev_get (devname)) { +dev_err (dev,"IPC device %s already exist\n" , devname); +return ERR_PTR (-EINVAL ); + } + + ptr =devres_alloc (devm_intel_ipc_dev_release,sizeof (*ptr), +GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + + ipc_dev =kzalloc (sizeof (*ipc_dev),GFP_KERNEL ); +if (!ipc_dev) { + ret = -ENOMEM ; + goto err_dev_create; + } + + ipc_dev->dev.class = &intel_ipc_class; + ipc_dev->dev.parent = dev; + ipc_dev->dev.groups = ipc_dev_groups; + ipc_dev->cfg = cfg; + ipc_dev->ops = ops; + +mutex_init (&ipc_dev->lock); +init_completion (&ipc_dev->cmd_complete); +dev_set_drvdata (&ipc_dev->dev, ipc_dev); +dev_set_name (&ipc_dev->dev, devname); +device_initialize (&ipc_dev->dev); + + ret =device_add (&ipc_dev->dev); +if (ret <0 ) { +dev_err (&ipc_dev->dev,"%s device create failed\n" , + __func__); + ret = -ENODEV ; + goto err_dev_add; + } + +if (ipc_dev->cfg->mode ==IPC_DEV_MODE_IRQ ) { +if (devm_request_irq (&ipc_dev->dev, + ipc_dev->cfg->irq, + ipc_dev_irq_handler, + ipc_dev->cfg->irqflags, +dev_name (&ipc_dev->dev), + ipc_dev)) { +dev_err (&ipc_dev->dev, +"Failed to request irq\n" ); + goto err_irq_request; + } + } + + *ptr = ipc_dev; + +devres_add (dev, ptr); + +return ipc_dev; + +err_irq_request: +device_del (&ipc_dev->dev); +err_dev_add: +kfree (ipc_dev); +err_dev_create: +devres_free (ptr); +return ERR_PTR (ret); +} +EXPORT_SYMBOL_GPL (devm_intel_ipc_dev_create); + +static int __init intel_ipc_init (void ) +{ +ipc_channel_lock_init (); +return class_register (&intel_ipc_class); } + +static void __exit intel_ipc_exit(void) { +class_unregister (&intel_ipc_class); +} +subsys_initcall (intel_ipc_init); +module_exit (intel_ipc_exit); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR("Kuppuswamy +Sathyanarayanan<[email protected]>"); +MODULE_DESCRIPTION("Intel IPC device class driver");include/linux/platform_data/x86/intel_ipc_dev.h new file +150
-0@@ -0,0 +1,206 @@ +/* +* Intel IPC class device header file. +* +* (C) Copyright 2017 Intel Corporation +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; version 2 +* of the License. +* +*/ + +#ifndef INTEL_IPC_DEV_H +#define INTEL_IPC_DEV_H + +#include <linux/module.h> +#include <linux/device.h> + +/* IPC channel type */ +#define IPC_CHANNEL_IA_PMC 0 +#define IPC_CHANNEL_IA_PUNIT 1 +#define IPC_CHANNEL_PMC_PUNIT 2 +#define IPC_CHANNEL_IA_SCU 3 +#define IPC_CHANNEL_MAX 4 + +/* IPC return code */ +#define IPC_DEV_ERR_NONE 0 +#define IPC_DEV_ERR_CMD_NOT_SUPPORTED 1 +#define IPC_DEV_ERR_CMD_NOT_SERVICED 2 +#define IPC_DEV_ERR_UNABLE_TO_SERVICE 3 +#define IPC_DEV_ERR_CMD_INVALID 4 +#define IPC_DEV_ERR_CMD_FAILED 5 +#define IPC_DEV_ERR_EMSECURITY 6 +#define IPC_DEV_ERR_UNSIGNEDKERNEL 7 +#define IPC_DEV_ERR_MAX 8 + +/* IPC mode */ +#define IPC_DEV_MODE_IRQ 0 +#define IPC_DEV_MODE_POLLING 1 + +/* IPC dev constants */ +#define IPC_DEV_CMD_LOOP_CNT 3000000 +#define IPC_DEV_CMD_TIMEOUT 3 * HZ +#define IPC_DEV_DATA_BUFFER_SIZE 16 + +struct intel_ipc_dev ; +struct intel_ipc_raw_cmd ; + +/** +* struct intel_ipc_dev_cfg - IPC device config structure. +* +* IPC device drivers uses the following config options to +* register new IPC device. +* +* @cmd_regs : IPC device command base regmap. +* @data_regs : IPC device data base regmap. +* @wrbuf_reg : IPC device data write register address. +* @rbuf_reg : IPC device data read register address. +* @sptr_reg : IPC device source data pointer register address. +* @dptr_reg : IPC device destination data pointer register +* address. +* @status_reg : IPC command status register address. +* @cmd_reg : IPC command register address. +* @mode : IRQ/POLLING mode. +* @irq : IPC device IRQ number. +* @irqflags : IPC device IRQ flags. +* @chan_type : IPC device channel type(PMC/PUNIT). +* @msi : Enable/Disable MSI for IPC commands. +* @support_dptr : Support DPTR update. +* @support_sptr : Support SPTR update. +* +*/ +struct intel_ipc_dev_cfg { +struct regmap *cmd_regs; +struct regmap *data_regs; +unsigned int wrbuf_reg; +unsigned int rbuf_reg; +unsigned int sptr_reg; +unsigned int dptr_reg; +unsigned int status_reg; +unsigned int cmd_reg; +int mode; +int irq; +int irqflags; +int chan_type; +bool use_msi; +bool support_dptr; +bool support_sptr; +}; + +/** +* struct intel_ipc_dev_ops - IPC device ops structure. +* +* Call backs for IPC device specific operations. +* +* @to_err_code : Status to error code conversion function. +* @busy_check : Check for IPC busy status. +* @enable_msi : Enable MSI for IPC commands. +* @pre_simple_cmd_fn : Custom pre-processing function for +* ipc_dev_simple_cmd() +* @pre_cmd_fn : Custom pre-processing function for +* ipc_dev_cmd() +* @pre_raw_cmd_fn : Custom pre-processing function for +* ipc_dev_raw_cmd() +* +*/ +struct intel_ipc_dev_ops { +int (*to_err_code)(int status); +int (*busy_check)(int status); +u32 (*enable_msi)(u32 cmd); +int (*pre_simple_cmd_fn)(u32 *cmd_list,u32 cmdlen); +int (*pre_cmd_fn)(u32 *cmd_list,u32 cmdlen,u32 *in,u32 inlen, +u32 *out,u32 outlen); +int (*pre_raw_cmd_fn)(u32 *cmd_list,u32 cmdlen,u8 *in,u32 inlen, +u32 *out,u32 outlen,u32 dptr,u32 sptr); +int (*pre_irq_handler_fn)(struct intel_ipc_dev *ipc_dev,int irq); }; + +/** +* struct intel_ipc_dev - Intel IPC device structure. +* +* Used with devm_intel_ipc_dev_create() to create new IPC device. +* +* @dev : IPC device object. +* @cmd : Current IPC device command. +* @cmd_complete : Command completion object. +* @lock : Lock to protect IPC device structure. +* @ops : IPC device ops pointer. +* @cfg : IPC device cfg pointer. +* +*/ +struct intel_ipc_dev { +struct device dev; +int cmd; +struct completion cmd_complete; +struct mutex lock; +struct intel_ipc_dev_ops *ops; +struct intel_ipc_dev_cfg *cfg; +}; + +#if IS_ENABLED (CONFIG_INTEL_IPC_DEV ) + +/* API to create new IPC device */ +struct intel_ipc_dev *devm_intel_ipc_dev_create (struct device *dev, +const char *devname,struct intel_ipc_dev_cfg *cfg, +struct intel_ipc_dev_ops *ops); + +int ipc_dev_simple_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list, +u32 cmdlen); +int ipc_dev_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list,u32 cmdlen, +u32 *in,u32 inlen,u32 *out,u32 outlen);int ipc_dev_raw_cmd(struct
include/linux/platform_data/x86/intel_ipc_dev.h new file +2
-0+intel_ipc_dev *ipc_dev, u32 *cmd_list, u32 cmdlen, + u8 *in, u32 inlen, u32 *out, u32 outlen, u32 dptr, u32 sptr);struct
include/linux/platform_data/x86/intel_ipc_dev.h new file +28
-0+intel_ipc_dev *intel_ipc_dev_get (const char *dev_name);struct +intel_ipc_dev *devm_intel_ipc_dev_get (struct device *dev, +const char *dev_name); +static inline void intel_ipc_dev_put (struct intel_ipc_dev *ipc_dev) { +put_device (&ipc_dev->dev); +} +#else + +static inline struct intel_ipc_dev *devm_intel_ipc_dev_create ( +struct device *dev, +const char *devname,struct intel_ipc_dev_cfg *cfg, +struct intel_ipc_dev_ops *ops) +{ +return -EINVAL ; +} + +static inline int ipc_dev_simple_cmd (struct intel_ipc_dev *ipc_dev, +u32 *cmd_list,u32 cmdlen) +{ +return -EINVAL ; +} + +static int ipc_dev_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list, +u32 cmdlen,u32 *in,u32 inlen,u32 *out,u32 outlen) { +return -EINVAL ; +} + +static inline int ipc_dev_raw_cmd(struct intel_ipc_dev *ipc_dev, u32
*cmd_list,include/linux/platform_data/x86/intel_ipc_dev.h new file +12
-0+ u32 cmdlen, u8 *in, u32 inlen, u32 *out, u32 outlen, + u32 dptr, u32 sptr); +{ +return -EINVAL ; +} + +static inline struct intel_ipc_dev *intel_ipc_dev_get (const char +*dev_name) { +return NULL ; +} + +static inline struct intel_ipc_dev *devm_intel_ipc_dev_get(struct device*dev,
include/linux/platform_data/x86/intel_ipc_dev.h new file +10
-1+ const char *dev_name); +{ +return NULL ; +} + +static inline void intel_ipc_dev_put (struct intel_ipc_dev *ipc_dev) { +return NULL ; +} +#endif /* CONFIG_INTEL_IPC_DEV */ +#endif /* INTEL_IPC_DEV_H */ --2.7.4
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux kernel developer
Re: [RFC v5 6/8] platform/x86: intel_punit_ipc: Use generic intel ipc device calls
In reply to Chakravarty, Souvik KQuoted 635 lines · Souvik K
Quoted 635 lines
From: [email protected] [mailto:[email protected]]
Sent: Sunday, October 8, 2017 3:50 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zha, Qipeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Chakravarty, Souvik K <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Kuppuswamy Sathyanarayanan <[email protected]>
Subject: [RFC v5 6/8] platform/x86:intel_punit_ipc: Use generic intel ipc device callsFrom: Kuppuswamy Sathyanarayanan
<[email protected]>Removed redundant IPC helper functions and refactored the driver to use APIs provided by generic IPC driver. This patch also cleans-up PUNIT IPC user
drivers(intel_telemetry_pltdrv.c)to use APIs provided by generic IPC driver.Signed-off-by: Kuppuswamy Sathyanarayanan
<[email protected]>--- arch/x86/include/asm/intel_punit_ipc.h | 125 +++++------ drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_punit_ipc.c | 303 ++++++++++---------------- drivers/platform/x86/intel_telemetry_pltdrv.c | 97 +++++---- 4 files changed, 223 insertions(+), 303 deletions(-)Changes since v4:
* NoneChanges since v2:
* Added unique name to PUNIT BIOS, GTD, & ISP regmaps.
* Addedintel_ipc_dev_put()support.Changes since v1:
* Removed custom APIs.
* Cleaned up PUNIT IPC user drivers to use APIs provided by generic IPC driver.arch/x86/include/asm/intel_punit_ipc.h +6
-33@@ -1,10 +1,8 @@ #ifndef _ASM_X86_INTEL_PUNIT_IPC_H_ #define _ASM_X86_INTEL_PUNIT_IPC_H_ -/* - * Three types of 8bit P-Unit IPC commands are supported, - * bit[7:6]: [00]: BIOS; [01]: GTD; [10]: ISPD. - */ +#include <linux/platform_data/x86/intel_ipc_dev.h> + typedef enum { BIOS_IPC = 0, GTDRIVER_IPC,@@ -12,61 +10,60 @@ typedef enum {RESERVED_IPC , } IPC_TYPE; -#define IPC_TYPE_OFFSET 6 -#define IPC_PUNIT_BIOS_CMD_BASE (BIOS_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_GTD_CMD_BASE (GTDDRIVER_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_ISPD_CMD_BASE (ISPDRIVER_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_CMD_TYPE_MASK (RESERVED_IPC << IPC_TYPE_OFFSET) +#define PUNIT_BIOS_IPC_DEV "punit_bios_ipc" +#define PUNIT_GTD_IPC_DEV "punit_gtd_ipc" +#define PUNIT_ISP_IPC_DEV "punit_isp_ipc" +#define PUNIT_PARAM_LEN 3/* BIOS => Pcode commands */ -#define IPC_PUNIT_BIOS_ZERO (IPC_PUNIT_BIOS_CMD_BASE | 0x00) -#define IPC_PUNIT_BIOS_VR_INTERFACE (IPC_PUNIT_BIOS_CMD_BASE |0x01 ) -#define IPC_PUNIT_BIOS_READ_PCS (IPC_PUNIT_BIOS_CMD_BASE |0x02 ) -#define IPC_PUNIT_BIOS_WRITE_PCS (IPC_PUNIT_BIOS_CMD_BASE | 0x03) -#define IPC_PUNIT_BIOS_READ_PCU_CONFIG (IPC_PUNIT_BIOS_CMD_BASE |0x04 ) -#define IPC_PUNIT_BIOS_WRITE_PCU_CONFIG (IPC_PUNIT_BIOS_CMD_BASE |0x05 ) -#define IPC_PUNIT_BIOS_READ_PL1_SETTING (IPC_PUNIT_BIOS_CMD_BASE |0x06 ) -#define IPC_PUNIT_BIOS_WRITE_PL1_SETTING (IPC_PUNIT_BIOS_CMD_BASE | 0x07) -#define IPC_PUNIT_BIOS_TRIGGER_VDD_RAM (IPC_PUNIT_BIOS_CMD_BASE |0x08 ) -#define IPC_PUNIT_BIOS_READ_TELE_INFO (IPC_PUNIT_BIOS_CMD_BASE |0x09 ) -#define IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0a ) -#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0b ) -#define IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0c ) -#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0d ) -#define IPC_PUNIT_BIOS_READ_TELE_TRACE (IPC_PUNIT_BIOS_CMD_BASE |0x0e ) -#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE (IPC_PUNIT_BIOS_CMD_BASE |0x0f ) -#define IPC_PUNIT_BIOS_READ_TELE_EVENT (IPC_PUNIT_BIOS_CMD_BASE |0x10 ) -#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT (IPC_PUNIT_BIOS_CMD_BASE |0x11 ) -#define IPC_PUNIT_BIOS_READ_MODULE_TEMP (IPC_PUNIT_BIOS_CMD_BASE |0x12 ) -#define IPC_PUNIT_BIOS_RESERVED (IPC_PUNIT_BIOS_CMD_BASE |0x13 ) -#define IPC_PUNIT_BIOS_READ_VOLTAGE_OVER (IPC_PUNIT_BIOS_CMD_BASE |0x14 ) -#define IPC_PUNIT_BIOS_WRITE_VOLTAGE_OVER (IPC_PUNIT_BIOS_CMD_BASE |0x15 ) -#define IPC_PUNIT_BIOS_READ_RATIO_OVER (IPC_PUNIT_BIOS_CMD_BASE |0x16 ) -#define IPC_PUNIT_BIOS_WRITE_RATIO_OVER(IPC_PUNIT_BIOS_CMD_BASE | 0x17) -#define IPC_PUNIT_BIOS_READ_VF_GL_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x18) -#define IPC_PUNIT_BIOS_WRITE_VF_GL_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x19) -#define IPC_PUNIT_BIOS_READ_FM_SOC_TEMP_THRESH (IPC_PUNIT_BIOS_CMD_BASE | 0x1a) -#define IPC_PUNIT_BIOS_WRITE_FM_SOC_TEMP_THRESH (IPC_PUNIT_BIOS_CMD_BASE | 0x1b)arch/x86/include/asm/intel_punit_ipc.h +28
-1+#define IPC_PUNIT_BIOS_ZERO (0x00) +#define IPC_PUNIT_BIOS_VR_INTERFACE (0x01) +#define IPC_PUNIT_BIOS_READ_PCS (0x02) +#define IPC_PUNIT_BIOS_WRITE_PCS (0x03) +#define IPC_PUNIT_BIOS_READ_PCU_CONFIG (0x04) +#define IPC_PUNIT_BIOS_WRITE_PCU_CONFIG (0x05) +#define IPC_PUNIT_BIOS_READ_PL1_SETTING (0x06) +#define IPC_PUNIT_BIOS_WRITE_PL1_SETTING (0x07) +#define IPC_PUNIT_BIOS_TRIGGER_VDD_RAM (0x08) +#define IPC_PUNIT_BIOS_READ_TELE_INFO (0x09) +#define IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL (0x0a) +#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL (0x0b) +#define IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL (0x0c) +#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL (0x0d) +#define IPC_PUNIT_BIOS_READ_TELE_TRACE (0x0e) +#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE (0x0f) +#define IPC_PUNIT_BIOS_READ_TELE_EVENT (0x10) +#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT (0x11) +#define IPC_PUNIT_BIOS_READ_MODULE_TEMP (0x12) +#define IPC_PUNIT_BIOS_RESERVED (0x13) +#define IPC_PUNIT_BIOS_READ_VOLTAGE_OVER (0x14) +#define IPC_PUNIT_BIOS_WRITE_VOLTAGE_OVER (0x15) +#define IPC_PUNIT_BIOS_READ_RATIO_OVER (0x16) +#define IPC_PUNIT_BIOS_WRITE_RATIO_OVER (0x17) +#define IPC_PUNIT_BIOS_READ_VF_GL_CTRL (0x18) +#define IPC_PUNIT_BIOS_WRITE_VF_GL_CTRL (0x19) +#define IPC_PUNIT_BIOS_READ_FM_SOC_TEMP_THRESH (0x1a) +#define IPC_PUNIT_BIOS_WRITE_FM_SOC_TEMP_THRESH (0x1b)/* GT Driver => Pcode commands */ -#define IPC_PUNIT_GTD_ZERO (IPC_PUNIT_GTD_CMD_BASE|
0x00)
-#defineIPC_PUNIT_GTD_CONFIG(IPC_PUNIT_GTD_CMD_BASE | 0x01) -#define IPC_PUNIT_GTD_READ_ICCP_LIC_CDYN_SCAL (IPC_PUNIT_GTD_CMD_BASE | 0x02) -#define IPC_PUNIT_GTD_WRITE_ICCP_LIC_CDYN_SCAL (IPC_PUNIT_GTD_CMD_BASE | 0x03) -#define IPC_PUNIT_GTD_GET_WM_VAL (IPC_PUNIT_GTD_CMD_BASE | 0x06) -#define IPC_PUNIT_GTD_WRITE_CONFIG_WISHREQ (IPC_PUNIT_GTD_CMD_BASE | 0x07) -#define IPC_PUNIT_GTD_READ_REQ_DUTY_CYCLE (IPC_PUNIT_GTD_CMD_BASE | 0x16) -#define IPC_PUNIT_GTD_DIS_VOL_FREQ_CHG_REQUEST (IPC_PUNIT_GTD_CMD_BASE | 0x17) -#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_CTRL (IPC_PUNIT_GTD_CMD_BASE | 0x1a) -#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_TUNING (IPC_PUNIT_GTD_CMD_BASE | 0x1c)arch/x86/include/asm/intel_punit_ipc.h +10
-1+#define IPC_PUNIT_GTD_ZERO (0x00) +#define IPC_PUNIT_GTD_CONFIG (0x01) +#define IPC_PUNIT_GTD_READ_ICCP_LIC_CDYN_SCAL (0x02) +#define IPC_PUNIT_GTD_WRITE_ICCP_LIC_CDYN_SCAL (0x03) +#define IPC_PUNIT_GTD_GET_WM_VAL (0x06) +#define IPC_PUNIT_GTD_WRITE_CONFIG_WISHREQ (0x07) +#define IPC_PUNIT_GTD_READ_REQ_DUTY_CYCLE (0x16) +#define IPC_PUNIT_GTD_DIS_VOL_FREQ_CHG_REQUEST (0x17) +#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_CTRL (0x1a) +#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_TUNING (0x1c)/* ISP Driver => Pcode commands */ -#define IPC_PUNIT_ISPD_ZERO (IPC_PUNIT_ISPD_CMD_BASE|
0x00)
-#defineIPC_PUNIT_ISPD_CONFIG(IPC_PUNIT_ISPD_CMD_BASE | 0x01) -#define IPC_PUNIT_ISPD_GET_ISP_LTR_VAL (IPC_PUNIT_ISPD_CMD_BASE | 0x02) -#define IPC_PUNIT_ISPD_ACCESS_IU_FREQ_BOUNDS (IPC_PUNIT_ISPD_CMD_BASE | 0x03) -#define IPC_PUNIT_ISPD_READ_CDYN_LEVEL (IPC_PUNIT_ISPD_CMD_BASE | 0x04) -#define IPC_PUNIT_ISPD_WRITE_CDYN_LEVEL (IPC_PUNIT_ISPD_CMD_BASE | 0x05)arch/x86/include/asm/intel_punit_ipc.h +6
-3+#define IPC_PUNIT_ISPD_ZERO (0x00) +#define IPC_PUNIT_ISPD_CONFIG (0x01) +#define IPC_PUNIT_ISPD_GET_ISP_LTR_VAL (0x02) +#define IPC_PUNIT_ISPD_ACCESS_IU_FREQ_BOUNDS (0x03) +#define IPC_PUNIT_ISPD_READ_CDYN_LEVEL (0x04) +#define IPC_PUNIT_ISPD_WRITE_CDYN_LEVEL (0x05)/* Error codes */ #define IPC_PUNIT_ERR_SUCCESS 0@@ -77,25 +74,11 @@ typedef enum {#define IPC_PUNIT_ERR_INVALID_VR_ID 5#define IPC_PUNIT_ERR_VR_ERR 6 -#if IS_ENABLED (CONFIG_INTEL_PUNIT_IPC ) - -int intel_punit_ipc_simple_command (int cmd,int para1,int para2); -int
intel_punit_ipc_command(u32 cmd, u32 para1, u32 para2, u32 *in, u32 *out);arch/x86/include/asm/intel_punit_ipc.h +5
-14- -#else - -static inline int intel_punit_ipc_simple_command (int cmd, -int para1,int para2) +static inline void punit_cmd_init (u32 *cmd,u32 param1,u32 param2,u32 +param3) { -return -ENODEV ; + cmd[0 ] = param1; + cmd[1 ] = param2; + cmd[2 ] = param3; } -static inline int intel_punit_ipc_command (u32 cmd,u32 para1,u32 para2, -u32 *in,u32 *out) -{ -return -ENODEV ; -} - -#endif /* CONFIG_INTEL_PUNIT_IPC */ -#endif drivers/platform/x86/Kconfig +1
-0@@ -1096,6 +1096,7 @@ config SURFACE_3_BUTTON config INTEL_PUNIT_IPC tristate "Intel P-Unit IPC Driver" + select REGMAP_MMIO ---help--- This driver provides support for Intel P-Unit Mailbox IPC mechanism,which is used to bridge the communications between kernel and P-
Unit.drivers/platform/x86/intel_punit_ipc.c +5
-5@@ -18,18 +18,18 @@#include <linux/device.h> #include <linux/interrupt.h> #include <linux/platform_device.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> +#include <linux/regmap.h> #include <asm/intel_punit_ipc.h> -/* IPC Mailbox registers */ -#define OFFSET_DATA_LOW 0x0 -#define OFFSET_DATA_HIGH 0x4/* bit field of interface register */ #define CMD_RUN BIT(31) -#define CMD_ERRCODE_MASK GENMASK(7, 0) +#define CMD_ERRCODE_MASK GENMASK(7, 0)#define CMD_PARA1_SHIFT 8#define CMD_PARA2_SHIFT 16 -#define CMD_TIMEOUT_SECONDS 1 +/* IPC PUNIT commands */ +#define IPC_DEV_PUNIT_CMD_STATUS_ERR_MASK GENMASK(7, 0)enum {
BASE_DATA= 0,drivers/platform/x86/intel_punit_ipc.c +16
-108@@ -39,187 +39,42 @@ enum {typedef struct {struct device *dev; -struct mutex lock; -int irq; -struct completion cmd_complete;/* base of interface and data registers */ void __iomem *base[RESERVED_IPC ][BASE_MAX ]; +struct intel_ipc_dev *ipc_dev[RESERVED_IPC ];IPC_TYPE type; }IPC_DEV ;static IPC_DEV *punit_ipcdev; -static inline u32 ipc_read_status(IPC_DEV *ipcdev, IPC_TYPE type) -{ -return readl (ipcdev->base[type][BASE_IFACE ]); -} - -static inline void ipc_write_cmd(IPC_DEV *ipcdev, IPC_TYPE type, u32 cmd) - { -writel (cmd, ipcdev->base[type][BASE_IFACE ]); -} - -static inline u32 ipc_read_data_low(IPC_DEV *ipcdev, IPC_TYPE type) -{ -return readl (ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_LOW ); -} - -static inline u32 ipc_read_data_high(IPC_DEV *ipcdev, IPC_TYPE type) -{ -return readl (ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_HIGH ); -} - -static inline void ipc_write_data_low (IPC_DEV *ipcdev,IPC_TYPE type,u32 data) -{ -writel (data, ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_LOW ); -} - -static inline void ipc_write_data_high (IPC_DEV *ipcdev,IPC_TYPE type,u32 data) -{ -writel (data, ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_HIGH ); -} +const char *ipc_dev_name[RESERVED_IPC ] = { +PUNIT_BIOS_IPC_DEV , +PUNIT_GTD_IPC_DEV , +PUNIT_ISP_IPC_DEV +}; -static const char *ipc_err_string(int error) -{ -if (error ==IPC_PUNIT_ERR_SUCCESS ) -return "no error" ; -else if (error ==IPC_PUNIT_ERR_INVALID_CMD ) -return "invalid command" ; -else if (error ==IPC_PUNIT_ERR_INVALID_PARAMETER ) -return "invalid parameter" ; -else if (error ==IPC_PUNIT_ERR_CMD_TIMEOUT ) -return "command timeout" ; -else if (error ==IPC_PUNIT_ERR_CMD_LOCKED ) -return "command locked" ; -else if (error ==IPC_PUNIT_ERR_INVALID_VR_ID ) -return "invalid vr id" ; -else if (error ==IPC_PUNIT_ERR_VR_ERR ) -return "vr error" ; -else -return "unknown error" ; -} +static struct regmap_config punit_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , +}; -static int intel_punit_ipc_check_status (IPC_DEV *ipcdev,IPC_TYPE type) +int pre_simple_cmd_fn (u32 *cmd_list,u32 cmdlen) { -int loops =CMD_TIMEOUT_SECONDS *USEC_PER_SEC ; -int errcode; -int status; - -if (ipcdev->irq) { -if (!wait_for_completion_timeout (&ipcdev->cmd_complete, -CMD_TIMEOUT_SECONDS * HZ)) { -dev_err (ipcdev->dev,"IPC timed out\n" ); -return -ETIMEDOUT ; - } - }else { -while ((ipc_read_status (ipcdev, type) &CMD_RUN ) && -- loops) -udelay (1 ); -if (!loops) { -dev_err (ipcdev->dev,"IPC timed out\n" ); -return -ETIMEDOUT ; - } - } +if (!cmd_list || cmdlen !=PUNIT_PARAM_LEN ) +return -EINVAL ; - status =ipc_read_status (ipcdev, type); - errcode = status &CMD_ERRCODE_MASK ; -if (errcode) { -dev_err (ipcdev->dev,"IPC failed: %s, IPC_STS=0x%x\n" , -ipc_err_string (errcode), status); -return -EIO ; - } + cmd_list[0 ] |=CMD_RUN | cmd_list[1 ] <<CMD_PARA1_SHIFT | + cmd_list[2 ] <<CMD_PARA1_SHIFT ;return 0 ; } -/** -* intel_punit_ipc_simple_command() - Simple IPC command -* @cmd: IPC command code. -* @para1: First 8bit parameter, set 0 if not used. -* @para2: Second 8bit parameter, set 0 if not used. -* -* Send a IPC command to P-Unit when there is no data transaction -* -* Return: IPC error code or 0 on success. -*/ -int intel_punit_ipc_simple_command(int cmd, int para1, int para2) -{ -IPC_DEV *ipcdev = punit_ipcdev; -IPC_TYPE type; -u32 val; -int ret; - -mutex_lock (&ipcdev->lock); - -reinit_completion (&ipcdev->cmd_complete); - type = (cmd &IPC_PUNIT_CMD_TYPE_MASK ) >>IPC_TYPE_OFFSET ; - - val = cmd & ~IPC_PUNIT_CMD_TYPE_MASK ; - val |=CMD_RUN | para2 <<CMD_PARA2_SHIFT | para1 <<CMD_PARA1_SHIFT ; -ipc_write_cmd (ipcdev, type, val); - ret =intel_punit_ipc_check_status (ipcdev, type); - -mutex_unlock (&ipcdev->lock); - -return ret; -} -EXPORT_SYMBOL (intel_punit_ipc_simple_command); - -/** -* intel_punit_ipc_command() - IPC command with data and pointers -* @cmd: IPC command code. -* @para1: First 8bit parameter, set 0 if not used. -* @para2: Second 8bit parameter, set 0 if not used. -* @in: Input data, 32bit for BIOS cmd, two 32bit for GTD and ISPD.
- * @out: Output data.
- *
- * Send a IPC command to P-Unit with data transaction
- *
- * Return: IPC error code or 0 on success.
- */
-intintel_punit_ipc_command(u32 cmd, u32 para1, u32 para2, u32 *in, u32 *out)-{drivers/platform/x86/intel_punit_ipc.c +0
-18-IPC_DEV *ipcdev = punit_ipcdev; -IPC_TYPE type; -u32 val; -int ret; - -mutex_lock (&ipcdev->lock); - -reinit_completion (&ipcdev->cmd_complete); - type = (cmd &IPC_PUNIT_CMD_TYPE_MASK ) >>IPC_TYPE_OFFSET ; - -if (in) { -ipc_write_data_low (ipcdev, type, *in); -if (type ==GTDRIVER_IPC || type ==ISPDRIVER_IPC ) -ipc_write_data_high (ipcdev, type, *++in); - } - - val = cmd & ~IPC_PUNIT_CMD_TYPE_MASK ; - val |= CMD_RUN | para2 << CMD_PARA2_SHIFT | para1 <<
CMD_PARA1_SHIFT;drivers/platform/x86/intel_punit_ipc.c +32
-23-ipc_write_cmd (ipcdev, type, val); - - ret =intel_punit_ipc_check_status (ipcdev, type); -if (ret) - goto out; - -if (out) { - *out =ipc_read_data_low (ipcdev, type); -if (type ==GTDRIVER_IPC || type ==ISPDRIVER_IPC ) - *++out =ipc_read_data_high (ipcdev, type); - } - -out: -mutex_unlock (&ipcdev->lock); -return ret; -} -EXPORT_SYMBOL_GPL (intel_punit_ipc_command); - -static irqreturn_t intel_punit_ioc (int irq,void *dev_id) +/* Input data, 32bit for BIOS cmd, two 32bit for GTD and ISPD. */ int +pre_raw_cmd_fn (u32 *cmd_list,u32 cmdlen,u8 *in,u32 inlen,u32 *out, +u32 outlen,u32 dptr,u32 sptr) { -IPC_DEV *ipcdev = dev_id; - -complete (&ipcdev->cmd_complete); -return IRQ_HANDLED ; +return pre_simple_cmd_fn (cmd_list, cmdlen); } static int intel_punit_get_bars(struct platform_device *pdev) @@ -282,9 +137,77 @@ static int intel_punit_get_bars(struct platform_device *pdev) return 0; } +static int punit_ipc_err_code (int status) { +return (status &CMD_ERRCODE_MASK ); +} + +static int punit_ipc_busy_check (int status) { +return status |CMD_RUN ; +} + +static struct intel_ipc_dev *intel_punit_ipc_dev_create (struct device *dev, +const char *devname, +int irq, +void __iomem *base, +void __iomem *data) +{ +struct intel_ipc_dev_ops *ops; +struct intel_ipc_dev_cfg *cfg; +struct regmap *cmd_regs, *data_regs; + + cfg =devm_kzalloc (dev,sizeof (*cfg),GFP_KERNEL ); +if (!cfg) +return ERR_PTR (-ENOMEM ); + + ops =devm_kzalloc (dev,sizeof (*ops),GFP_KERNEL ); +if (!ops) +return ERR_PTR (-ENOMEM ); + + punit_regmap_config.name = devm_kasprintf(dev, GFP_KERNEL,"%s_%s",
drivers/platform/x86/intel_punit_ipc.c +10
-0+ devname, "base"); + + cmd_regs =devm_regmap_init_mmio_clk (dev,NULL , base, + &punit_regmap_config); +if (IS_ERR (cmd_regs)) { +dev_err (dev,"cmd_regs regmap init failed\n" ); +return ERR_CAST (cmd_regs);; + } + + punit_regmap_config.name = devm_kasprintf(dev, GFP_KERNEL,"%s_%s",
drivers/platform/x86/intel_punit_ipc.c +29
-1+ devname, "data"); + + data_regs =devm_regmap_init_mmio_clk (dev,NULL , data, + &punit_regmap_config); +if (IS_ERR (data_regs)) { +dev_err (dev,"data_regs regmap init failed\n" ); +return ERR_CAST (data_regs);; + } + +/* set IPC dev ops */ + ops->to_err_code = punit_ipc_err_code; + ops->busy_check = punit_ipc_busy_check; + ops->pre_simple_cmd_fn = pre_simple_cmd_fn; + ops->pre_raw_cmd_fn = pre_raw_cmd_fn; + +if (irq >0 ) + cfg->mode =IPC_DEV_MODE_IRQ ; +else + cfg->mode =IPC_DEV_MODE_POLLING ; + + cfg->chan_type =IPC_CHANNEL_IA_PUNIT ; + cfg->irq = irq; + cfg->irqflags =IRQF_NO_SUSPEND |IRQF_SHARED ; + cfg->cmd_regs = cmd_regs; + cfg->data_regs = data_regs; + +return devm_intel_ipc_dev_create (dev, devname, cfg, ops); } +static int intel_punit_ipc_probe (struct platform_device *pdev) { -int irq, ret; +int irq, ret, i; punit_ipcdev =devm_kzalloc (&pdev->dev, sizeof(*punit_ipcdev), GFP_KERNEL); @@ -294,35 +217,30 @@ static int
intel_punit_ipc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, punit_ipcdev);irq = platform_get_irq(pdev, 0);drivers/platform/x86/intel_punit_ipc.c +0
-9-if (irq <0 ) { - punit_ipcdev->irq =0 ; -dev_warn (&pdev->dev,"Invalid IRQ, using polling mode\n" ); - }else { - ret =devm_request_irq (&pdev->dev, irq, intel_punit_ioc, -IRQF_NO_SUSPEND ,"intel_punit_ipc" , - &punit_ipcdev); -if (ret) { - dev_err(&pdev->dev, "Failed to request irq: %d\n",irq);
drivers/platform/x86/intel_punit_ipc.c +16
-11-return ret; - } - punit_ipcdev->irq = irq; - } ret =intel_punit_get_bars (pdev);if (ret) - goto out; +return ret; + +for (i =0 ; i <RESERVED_IPC ; i++) { + punit_ipcdev->ipc_dev[i] =intel_punit_ipc_dev_create ( + &pdev->dev, + ipc_dev_name[i], + irq, + punit_ipcdev->base[i][BASE_IFACE ], + punit_ipcdev->base[i][BASE_DATA ]); + +if (IS_ERR (punit_ipcdev->ipc_dev[i])) { +dev_err (&pdev->dev,"%s create failed\n" , + ipc_dev_name[i]); +return PTR_ERR (punit_ipcdev->ipc_dev[i]); + } + } punit_ipcdev->dev = &pdev->dev; -mutex_init (&punit_ipcdev->lock); -init_completion (&punit_ipcdev->cmd_complete); -out:return ret; -} -static int intel_punit_ipc_remove(struct platform_device *pdev) -{ -return 0 ; } static const struct acpi_device_id punit_ipc_acpi_ids[] = { @@ -332,7 +250,6@@ static const struct
acpi_device_idpunit_ipc_acpi_ids[] = {
Quoted 12 lines
drivers/platform/x86/intel_telemetry_pltdrv.c
Quoted 11 lines
static struct platform_driver intel_punit_ipc_driver = { .probe = intel_punit_ipc_probe,drivers/platform/x86/intel_punit_ipc.c +0
-1- .remove = intel_punit_ipc_remove, .driver = { .name ="intel_punit_ipc" , .acpi_match_table = ACPI_PTR(punit_ipc_acpi_ids), diff --git
a/drivers/platform/x86/intel_telemetry_pltdrv.cb/drivers/platform/x86/intel_telemetry_pltdrv.c
index e0424d5..bf8284a 100644drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0This is a logical separation and so should be a different patch.
But if we split it into two different patches then it will break the bisect-ability of these patches.
Quoted 6 lines
drivers/platform/x86/intel_telemetry_pltdrv.c struct telem_ssram_region { }; · line 100
Quoted 5 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0@@ -98,6 +98,7 @@ struct telem_ssram_region { };static struct telemetry_plt_config *telm_conf; +static struct intel_ipc_dev *punit_bios_ipc_dev;Simply
punit_ipc_devis good enough.
There are three PUNIT IPC devices. So to differentiate between them I added extra string to it.
Quoted 20 lines
Quoted 20 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +0
-1/* * The following counters are programmed by default during setup. @@ -127,7 +128,6 @@ static struct telemetry_evtmap {"PMC_S0IX_BLOCK_IPS_CLOCKS", 0x600B}, }; -static struct telemetry_evtmap telemetry_apl_pss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
{"IA_CORE0_C6_RES",0x0400},drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0@@ -283,13 +283,12 @@ static inline int
telemetry_plt_config_ioss_event(u32 evt_id, int index)static inline inttelemetry_plt_config_pss_event(u32 evt_id, int index){
u32write_buf;drivers/platform/x86/intel_telemetry_pltdrv.c +1
-1-int ret; +u32 cmd[PUNIT_PARAM_LEN ] = {0 };
Quoted 12 lines
drivers/platform/x86/intel_telemetry_pltdrv.c static inline int telemetry_plt_config_ioss_event(u32 evt_id, int index) · line 292
Quoted 11 lines
write_buf = evt_id | TELEM_EVENT_ENABLE;drivers/platform/x86/intel_telemetry_pltdrv.c +0
-1- ret =intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT,
drivers/platform/x86/intel_telemetry_pltdrv.c +2
-3- index, 0, &write_buf, NULL); - -return ret; +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT , index,0 ); + return ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0+ (u8 *)&write_buf, sizeof(write_buf), NULL, 0, 0, 0); }1) Why use
raw_cmdhere? It should useipc_dev_cmd()according to original design. Same everywhere though this file.
In my initial versions of this patch set, I had only exported ipc_dev_raw_cmd() API. Since this driver refactoring work was done during that time, I have used intel_dev_raw_cmd() API in it. I have added ipc_dev_cmd() API only recently to handle some new requirements in intel_scu_ipc.c driver.
I will fix it in next version.
Quoted 2 lines
2)
punit_cmd_initandipc_dev_raw_cmdare repeated multiple time thoughout the file. They can be made into a separate local API inside telemetry, liketelemetry_punit_send_cmd(). Same thoughout
I will make this change in next version.
Quoted 267 lines
Quoted 266 lines
static int telemetry_setup_iossevtconfig(struct
telemetry_evtconfig
evtconfig, @@ -435,6 +434,7 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfigevtconfig,
int ret, index, idx;
u32*pss_evtmap;
u32telem_ctrl;drivers/platform/x86/intel_telemetry_pltdrv.c +3
-2+u32 cmd[PUNIT_PARAM_LEN ] = {0 }; num_pss_evts = evtconfig.num_evts; pss_period = evtconfig.period;@@ -442,8 +442,9 @@ static int telemetry_setup_pssevtconfig(struct telemetry_evtconfig evtconfig, /* PSS Config */ /* Get telemetry EVENT CTL */ - ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL, -0 ,0 ,NULL , &telem_ctrl); + punit_cmd_init(cmd, IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL, 0, 0); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN, NULL,drivers/platform/x86/intel_telemetry_pltdrv.c +3
-2+ 0, &telem_ctrl, 1, 0, 0);if (ret) {pr_err ("PSS TELEM_CTRL Read Failed\n" );return ret;@@ -451,8 +452,9 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,/* Disable Telemetry */ TELEM_DISABLE (telem_ctrl ); - ret =intel_punit_ipc_command (IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , 0); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3+ (u8 *)&telem_ctrl, sizeof(telem_ctrl), NULL, 0, 0, 0);if (ret) {pr_err ("PSS TELEM_CTRL Event Disable Write Failed\n" );return ret;@@ -463,9 +465,10 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,/* Clear All Events */ TELEM_CLEAR_EVENTS (telem_ctrl ); - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );if (ret) {
pr_err("PSSTELEM_CTRLEvent Disable Write
Failed\n");
return ret;drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3@@ -489,9 +492,10 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,/* Clear All Events */ TELEM_CLEAR_EVENTS (telem_ctrl ); - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );if (ret) {
pr_err("PSSTELEM_CTRLEvent Disable Write
Failed\n");
return ret;drivers/platform/x86/intel_telemetry_pltdrv.c +2
-2@@ -540,8 +544,9 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,TELEM_ENABLE_PERIODIC (telem_ctrl ); telem_ctrl |= pss_period; - ret =intel_punit_ipc_command (IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , 0); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +2
-0+ (u8 *)&telem_ctrl, sizeof(telem_ctrl), NULL, 0, 0, 0);if (ret) {pr_err ("PSS TELEM_CTRL Event Enable Write Failed\n" );return ret;@@ -601,6 +606,7 @@ static int telemetry_setup(struct platform_device *pdev) {struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;u32 read_buf, events, event_regs; +u32 cmd[PUNIT_PARAM_LEN ] = {0 };int ret; ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
IOSS_TELEM_INFO_READ, @@ -626,8 +632,9 @@ static inttelemetry_setup(struct platform_device *pdev)
telm_conf->ioss_config.max_period=TELEM_MAX_PERIOD(read_buf);/* PUNIT Mailbox Setup */
drivers/platform/x86/intel_telemetry_pltdrv.c +0
-1- ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_INFO,0, 0,
drivers/platform/x86/intel_telemetry_pltdrv.c +2
-1- NULL, &read_buf); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_READ_TELE_INFO ,0 ,0 ); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3+ NULL, 0, &read_buf, 1, 0, 0);if (ret) {dev_err (&pdev->dev,"PSS TELEM_INFO Read Failed\n" );return ret;@@ -695,6 +702,7 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period) {u32 telem_ctrl =0 ;int ret =0 ; +u32 cmd[PUNIT_PARAM_LEN ] = {0 };mutex_lock (&(telm_conf->telem_lock));if (ioss_period) {@@ -752,9 +760,9 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period) }/* Get telemetry EVENT CTL */ - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL , -0 ,0 ,NULL , &telem_ctrl); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , +NULL ,0 , &telem_ctrl,1 ,0 ,0 );if (ret) { pr_err("PSS TELEM_CTRL Read Failed\n"); goto out;drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3@@ -762,9 +770,11 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period)/* Disable Telemetry */ TELEM_DISABLE (telem_ctrl); - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , +0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );if (ret) {
pr_err("PSSTELEM_CTRLEvent Disable Write
Failed\n");
goto out;drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3@@ -776,9 +786,11 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period)TELEM_ENABLE_PERIODIC (telem_ctrl); telem_ctrl |= pss_period; - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , +0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );if (ret) {
pr_err("PSSTELEM_CTRLEvent Enable Write
Failed\n");
goto out;drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3@@ -1013,6 +1025,7 @@ static int telemetry_plt_get_trace_verbosity(enum telemetry_unit telem_unit, {u32 temp =0 ;int ret; +u32 cmd[PUNIT_PARAM_LEN ] = {0 };if (verbosity ==NULL )return -EINVAL ;@@ -1020,9 +1033,9 @@ static int telemetry_plt_get_trace_verbosity(enumtelemetry_unit telem_unit, mutex_lock(&(telm_conf->telem_trace_lock));switch (telem_unit) {case TELEM_PSS : - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL , -0 ,0 ,NULL , &temp); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , +NULL ,0 , &temp,1 ,0 ,0 );if (ret) { pr_err("PSS TRACE_CTRL Read Failed\n"); goto out;drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3@@ -1058,15 +1071,16 @@ static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit, {u32 temp =0 ;int ret; +u32 cmd[PUNIT_PARAM_LEN ] = {0 }; verbosity &=TELEM_TRC_VERBOSITY_MASK ;mutex_lock (&(telm_conf->telem_trace_lock));switch (telem_unit) {case TELEM_PSS : - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL , -0 ,0 ,NULL , &temp); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , +NULL ,0 , &temp,1 ,0 ,0 );if (ret) {pr_err("PSS TRACE_CTRL Read Failed\n"); goto out;drivers/platform/x86/intel_telemetry_pltdrv.c +4
-4@@ -1074,10 +1088,10 @@ static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit,TELEM_CLEAR_VERBOSITY_BITS (temp);TELEM_SET_VERBOSITY_BITS (temp, verbosity); - - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL , -0 ,0 , &temp,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , +0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&temp,sizeof (temp),NULL ,0 ,0 ,0 );if (ret) { pr_err("PSS TRACE_CTRL Verbosity Set Failed\n"); goto out;drivers/platform/x86/intel_telemetry_pltdrv.c +4
-0@@ -1139,6 +1153,10 @@ static int telemetry_pltdrv_probe(struct platform_device *pdev)if (!id)return -ENODEV ; + punit_bios_ipc_dev =intel_ipc_dev_get (PUNIT_BIOS_IPC_DEV ); +if (IS_ERR_OR_NULL (punit_bios_ipc_dev)) +return PTR_ERR (punit_bios_ipc_dev); + telm_conf = (struct telemetry_plt_config *)id->driver_data;res0 =
platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -
1218,6 +1236,7 @@ static inttelemetry_pltdrv_probe(struct platform_device *pdev)static inttelemetry_pltdrv_remove(struct platform_device *pdev){
telemetry_clear_pltdata();drivers/platform/x86/intel_telemetry_pltdrv.c +1
-1+intel_ipc_dev_put (punit_bios_ipc_dev);iounmap (telm_conf->pss_config.regmap);iounmap (telm_conf->ioss_config.regmap); --2.7.4
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux kernel developer
RE: [RFC v5 6/8] platform/x86: intel_punit_ipc: Use generic intel ipc device calls
Quoted 689 lines
-----Original Message-----
From: [email protected] [mailto:platform-driver- [email protected]] On Behalf Of sathyanarayanan kuppuswamy
Sent: Wednesday, October 11, 2017 3:59 AM
To: Chakravarty, Souvik K <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zha, Qipeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [RFC v5 6/8] platform/x86:intel_punit_ipc: Use generic intel ipc device callsQuoted 15 lines · Souvik K
Quoted 15 lines
From: [email protected] [mailto:[email protected]]
Sent: Sunday, October 8, 2017 3:50 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zha, Qipeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Chakravarty, Souvik K <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Kuppuswamy Sathyanarayanan <[email protected]>
Subject: [RFC v5 6/8] platform/x86:intel_punit_ipc: Use generic intel ipc device callsQuoted 7 lines
Quoted 7 lines
From: Kuppuswamy Sathyanarayanan
<[email protected]>Removed redundant IPC helper functions and refactored the driver to use APIs provided by generic IPC driver. This patch also cleans-up PUNIT IPC user
drivers(intel_telemetry_pltdrv.c)to use APIs provided by generic IPCdriver.
Quoted 58 lines
Quoted 58 lines
Signed-off-by: Kuppuswamy Sathyanarayanan
<[email protected]>--- arch/x86/include/asm/intel_punit_ipc.h | 125 +++++------ drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_punit_ipc.c | 303 ++++++++++---------------- drivers/platform/x86/intel_telemetry_pltdrv.c | 97 +++++---- 4 files changed, 223 insertions(+), 303 deletions(-)Changes since v4:
* NoneChanges since v2:
* Added unique name to PUNIT BIOS, GTD, & ISP regmaps.
* Addedintel_ipc_dev_put()support.Changes since v1:
* Removed custom APIs.
* Cleaned up PUNIT IPC user drivers to use APIs provided by generic IPC driver.arch/x86/include/asm/intel_punit_ipc.h +6
-9@@ -1,10 +1,8 @@ #ifndef _ASM_X86_INTEL_PUNIT_IPC_H_ #define _ASM_X86_INTEL_PUNIT_IPC_H_ -/* - * Three types of 8bit P-Unit IPC commands are supported, - * bit[7:6]: [00]: BIOS; [01]: GTD; [10]: ISPD. - */ +#include <linux/platform_data/x86/intel_ipc_dev.h> + typedef enum { BIOS_IPC = 0, GTDRIVER_IPC,@@ -12,61 +10,60 @@ typedef enum {RESERVED_IPC , } IPC_TYPE; -#define IPC_TYPE_OFFSET 6 -#define IPC_PUNIT_BIOS_CMD_BASE (BIOS_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_GTD_CMD_BASE (GTDDRIVER_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_ISPD_CMD_BASE (ISPDRIVER_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_CMD_TYPE_MASK (RESERVED_IPC << IPC_TYPE_OFFSET) +#define PUNIT_BIOS_IPC_DEV "punit_bios_ipc" +#define PUNIT_GTD_IPC_DEV "punit_gtd_ipc" +#define PUNIT_ISP_IPC_DEV "punit_isp_ipc" +#define PUNIT_PARAM_LEN 3Quoted 2 lines
arch/x86/include/asm/intel_punit_ipc.h typedef enum { · line 26
Quoted 2 lines
arch/x86/include/asm/intel_punit_ipc.h +0
-1/* BIOS => Pcode commands */ -#define IPC_PUNIT_BIOS_ZERO (
IPC_PUNIT_BIOS_CMD_BASEQuoted 6 lines
arch/x86/include/asm/intel_punit_ipc.h typedef enum { · line 32
Quoted 6 lines
arch/x86/include/asm/intel_punit_ipc.h +0
-3| 0x00) -#define IPC_PUNIT_BIOS_VR_INTERFACE (IPC_PUNIT_BIOS_CMD_BASE |0x01 ) -#define IPC_PUNIT_BIOS_READ_PCS (IPC_PUNIT_BIOS_CMD_BASE |0x02 ) -#define IPC_PUNIT_BIOS_WRITE_PCS (
IPC_PUNIT_BIOS_CMD_BASEQuoted 8 lines
arch/x86/include/asm/intel_punit_ipc.h typedef enum { · line 40
Quoted 8 lines
arch/x86/include/asm/intel_punit_ipc.h +0
-4| 0x03) -#define IPC_PUNIT_BIOS_READ_PCU_CONFIG (IPC_PUNIT_BIOS_CMD_BASE |0x04 ) -#define IPC_PUNIT_BIOS_WRITE_PCU_CONFIG (IPC_PUNIT_BIOS_CMD_BASE |0x05 ) -#define IPC_PUNIT_BIOS_READ_PL1_SETTING (IPC_PUNIT_BIOS_CMD_BASE |0x06 ) -#define IPC_PUNIT_BIOS_WRITE_PL1_SETTING (
IPC_PUNIT_BIOS_CMD_BASEQuoted 70 lines
Quoted 70 lines
arch/x86/include/asm/intel_punit_ipc.h +0
-16| 0x07) -#define IPC_PUNIT_BIOS_TRIGGER_VDD_RAM (IPC_PUNIT_BIOS_CMD_BASE |0x08 ) -#define IPC_PUNIT_BIOS_READ_TELE_INFO (IPC_PUNIT_BIOS_CMD_BASE |0x09 ) -#define IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0a ) -#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0b ) -#define IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0c ) -#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL (IPC_PUNIT_BIOS_CMD_BASE |0x0d ) -#define IPC_PUNIT_BIOS_READ_TELE_TRACE (IPC_PUNIT_BIOS_CMD_BASE |0x0e ) -#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE (IPC_PUNIT_BIOS_CMD_BASE |0x0f ) -#define IPC_PUNIT_BIOS_READ_TELE_EVENT (IPC_PUNIT_BIOS_CMD_BASE |0x10 ) -#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT (IPC_PUNIT_BIOS_CMD_BASE |0x11 ) -#define IPC_PUNIT_BIOS_READ_MODULE_TEMP (IPC_PUNIT_BIOS_CMD_BASE |0x12 ) -#define IPC_PUNIT_BIOS_RESERVED (IPC_PUNIT_BIOS_CMD_BASE |0x13 ) -#define IPC_PUNIT_BIOS_READ_VOLTAGE_OVER (IPC_PUNIT_BIOS_CMD_BASE |0x14 ) -#define IPC_PUNIT_BIOS_WRITE_VOLTAGE_OVER (IPC_PUNIT_BIOS_CMD_BASE |0x15 ) -#define IPC_PUNIT_BIOS_READ_RATIO_OVER (IPC_PUNIT_BIOS_CMD_BASE |0x16 ) -#define IPC_PUNIT_BIOS_WRITE_RATIO_OVER (IPC_PUNIT_BIOS_CMD_BASE | 0x17) -#define IPC_PUNIT_BIOS_READ_VF_GL_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x18) -#define IPC_PUNIT_BIOS_WRITE_VF_GL_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x19) -#define IPC_PUNIT_BIOS_READ_FM_SOC_TEMP_THRESH (IPC_PUNIT_BIOS_CMD_BASE | 0x1a) -#define IPC_PUNIT_BIOS_WRITE_FM_SOC_TEMP_THRESH (IPC_PUNIT_BIOS_CMD_BASE | 0x1b)arch/x86/include/asm/intel_punit_ipc.h +28
-0+#define IPC_PUNIT_BIOS_ZERO (0x00) +#define IPC_PUNIT_BIOS_VR_INTERFACE (0x01) +#define IPC_PUNIT_BIOS_READ_PCS (0x02) +#define IPC_PUNIT_BIOS_WRITE_PCS (0x03) +#define IPC_PUNIT_BIOS_READ_PCU_CONFIG (0x04) +#define IPC_PUNIT_BIOS_WRITE_PCU_CONFIG (0x05) +#define IPC_PUNIT_BIOS_READ_PL1_SETTING (0x06) +#define IPC_PUNIT_BIOS_WRITE_PL1_SETTING (0x07) +#define IPC_PUNIT_BIOS_TRIGGER_VDD_RAM (0x08) +#define IPC_PUNIT_BIOS_READ_TELE_INFO (0x09) +#define IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL (0x0a) +#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL (0x0b) +#define IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL (0x0c) +#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL (0x0d) +#define IPC_PUNIT_BIOS_READ_TELE_TRACE (0x0e) +#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE (0x0f) +#define IPC_PUNIT_BIOS_READ_TELE_EVENT (0x10) +#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT (0x11) +#define IPC_PUNIT_BIOS_READ_MODULE_TEMP (0x12) +#define IPC_PUNIT_BIOS_RESERVED (0x13) +#define IPC_PUNIT_BIOS_READ_VOLTAGE_OVER (0x14) +#define IPC_PUNIT_BIOS_WRITE_VOLTAGE_OVER (0x15) +#define IPC_PUNIT_BIOS_READ_RATIO_OVER (0x16) +#define IPC_PUNIT_BIOS_WRITE_RATIO_OVER (0x17) +#define IPC_PUNIT_BIOS_READ_VF_GL_CTRL (0x18) +#define IPC_PUNIT_BIOS_WRITE_VF_GL_CTRL (0x19) +#define IPC_PUNIT_BIOS_READ_FM_SOC_TEMP_THRESH (0x1a) +#define IPC_PUNIT_BIOS_WRITE_FM_SOC_TEMP_THRESH (0x1b)Quoted 2 lines
Quoted 2 lines
/* GT Driver => Pcode commands */
-#defineIPC_PUNIT_GTD_ZERO(
IPC_PUNIT_GTD_CMD_BASEQuoted 30 lines
Quoted 30 lines
|
0x00)
-#defineIPC_PUNIT_GTD_CONFIG(IPC_PUNIT_GTD_CMD_BASE | 0x01) -#define IPC_PUNIT_GTD_READ_ICCP_LIC_CDYN_SCAL (IPC_PUNIT_GTD_CMD_BASE | 0x02) -#define IPC_PUNIT_GTD_WRITE_ICCP_LIC_CDYN_SCAL (IPC_PUNIT_GTD_CMD_BASE | 0x03) -#define IPC_PUNIT_GTD_GET_WM_VAL (IPC_PUNIT_GTD_CMD_BASE | 0x06) -#define IPC_PUNIT_GTD_WRITE_CONFIG_WISHREQ (IPC_PUNIT_GTD_CMD_BASE | 0x07) -#define IPC_PUNIT_GTD_READ_REQ_DUTY_CYCLE (IPC_PUNIT_GTD_CMD_BASE | 0x16) -#define IPC_PUNIT_GTD_DIS_VOL_FREQ_CHG_REQUEST (IPC_PUNIT_GTD_CMD_BASE | 0x17) -#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_CTRL (IPC_PUNIT_GTD_CMD_BASE | 0x1a) -#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_TUNING (IPC_PUNIT_GTD_CMD_BASE | 0x1c)arch/x86/include/asm/intel_punit_ipc.h +10
-0+#define IPC_PUNIT_GTD_ZERO (0x00) +#define IPC_PUNIT_GTD_CONFIG (0x01) +#define IPC_PUNIT_GTD_READ_ICCP_LIC_CDYN_SCAL (0x02) +#define IPC_PUNIT_GTD_WRITE_ICCP_LIC_CDYN_SCAL (0x03) +#define IPC_PUNIT_GTD_GET_WM_VAL (0x06) +#define IPC_PUNIT_GTD_WRITE_CONFIG_WISHREQ (0x07) +#define IPC_PUNIT_GTD_READ_REQ_DUTY_CYCLE (0x16) +#define IPC_PUNIT_GTD_DIS_VOL_FREQ_CHG_REQUEST (0x17) +#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_CTRL (0x1a) +#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_TUNING (0x1c)Quoted 2 lines
Quoted 2 lines
/* ISP Driver => Pcode commands */
-#defineIPC_PUNIT_ISPD_ZERO(
IPC_PUNIT_ISPD_CMD_BASEQuoted 45 lines
Quoted 45 lines
|
0x00)
-#defineIPC_PUNIT_ISPD_CONFIG(IPC_PUNIT_ISPD_CMD_BASE | 0x01) -#define IPC_PUNIT_ISPD_GET_ISP_LTR_VAL (IPC_PUNIT_ISPD_CMD_BASE | 0x02) -#define IPC_PUNIT_ISPD_ACCESS_IU_FREQ_BOUNDS (IPC_PUNIT_ISPD_CMD_BASE | 0x03) -#define IPC_PUNIT_ISPD_READ_CDYN_LEVEL (IPC_PUNIT_ISPD_CMD_BASE | 0x04) -#define IPC_PUNIT_ISPD_WRITE_CDYN_LEVEL (IPC_PUNIT_ISPD_CMD_BASE | 0x05)arch/x86/include/asm/intel_punit_ipc.h +6
-4+#define IPC_PUNIT_ISPD_ZERO (0x00) +#define IPC_PUNIT_ISPD_CONFIG (0x01) +#define IPC_PUNIT_ISPD_GET_ISP_LTR_VAL (0x02) +#define IPC_PUNIT_ISPD_ACCESS_IU_FREQ_BOUNDS (0x03) +#define IPC_PUNIT_ISPD_READ_CDYN_LEVEL (0x04) +#define IPC_PUNIT_ISPD_WRITE_CDYN_LEVEL (0x05)/* Error codes */ #define IPC_PUNIT_ERR_SUCCESS 0@@ -77,25 +74,11 @@ typedef enum {#define IPC_PUNIT_ERR_INVALID_VR_ID 5#define IPC_PUNIT_ERR_VR_ERR 6 -#if IS_ENABLED (CONFIG_INTEL_PUNIT_IPC ) - -int intel_punit_ipc_simple_command (int cmd,int para1,int para2); -int
intel_punit_ipc_command(u32 cmd, u32 para1, u32 para2, u32 *in, u32 *out);arch/x86/include/asm/intel_punit_ipc.h +6
-6- -#else - -static inline int intel_punit_ipc_simple_command (int cmd, -int para1,int para2) +static inline void punit_cmd_init (u32 *cmd,u32 param1,u32 param2, +u32 +param3) { -return -ENODEV ; + cmd[0 ] = param1; + cmd[1 ] = param2; + cmd[2 ] = param3; }Quoted 1 line
Quoted 1 line
-static inline int intel_punit_ipc_command(u32 cmd, u32 para1, u32
para2,
Quoted 271 lines
Quoted 271 lines
arch/x86/include/asm/intel_punit_ipc.h +0
-7- u32 *in, u32 *out) -{ -return -ENODEV ; -} - -#endif /* CONFIG_INTEL_PUNIT_IPC */ -#endif (quoted diff) +0
-0b/drivers/platform/x86/Kconfig index 724ee696..9442c23 100644
drivers/platform/x86/Kconfig +1
-0@@ -1096,6 +1096,7 @@ config SURFACE_3_BUTTON config INTEL_PUNIT_IPC tristate "Intel P-Unit IPC Driver" + select REGMAP_MMIO ---help--- This driver provides support for Intel P-Unit Mailbox IPC mechanism,which is used to bridge the communications between kernel and P-
Unit.drivers/platform/x86/intel_punit_ipc.c +5
-5@@ -18,18 +18,18 @@#include <linux/device.h> #include <linux/interrupt.h> #include <linux/platform_device.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> +#include <linux/regmap.h> #include <asm/intel_punit_ipc.h> -/* IPC Mailbox registers */ -#define OFFSET_DATA_LOW 0x0 -#define OFFSET_DATA_HIGH 0x4/* bit field of interface register */ #define CMD_RUN BIT(31) -#define CMD_ERRCODE_MASK GENMASK(7, 0) +#define CMD_ERRCODE_MASK GENMASK(7, 0)#define CMD_PARA1_SHIFT 8#define CMD_PARA2_SHIFT 16 -#define CMD_TIMEOUT_SECONDS 1 +/* IPC PUNIT commands */ +#define IPC_DEV_PUNIT_CMD_STATUS_ERR_MASK GENMASK(7, 0)enum {
BASE_DATA= 0,drivers/platform/x86/intel_punit_ipc.c +1
-20@@ -39,187 +39,42 @@ enum {typedef struct {struct device *dev; -struct mutex lock; -int irq; -struct completion cmd_complete;/* base of interface and data registers */ void __iomem *base[RESERVED_IPC ][BASE_MAX ]; +struct intel_ipc_dev *ipc_dev[RESERVED_IPC ];IPC_TYPE type; }IPC_DEV ;static IPC_DEV *punit_ipcdev; -static inline u32 ipc_read_status(IPC_DEV *ipcdev, IPC_TYPE type) -{ -return readl (ipcdev->base[type][BASE_IFACE ]); -} - -static inline void ipc_write_cmd (IPC_DEV *ipcdev,IPC_TYPE type,u32 cmd) - { -writel (cmd, ipcdev->base[type][BASE_IFACE ]); -} - -static inline u32 ipc_read_data_low(IPC_DEV *ipcdev, IPC_TYPE type) -{ -return readl (ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_LOW ); -} - -static inline u32 ipc_read_data_high(IPC_DEV *ipcdev, IPC_TYPE type) -{ -return readl (ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_HIGH ); -} - -static inline void ipc_write_data_low(IPC_DEV *ipcdev, IPC_TYPEtype, u32
data) -{drivers/platform/x86/intel_punit_ipc.c +0
-4-writel (data, ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_LOW ); -} - -static inline void ipc_write_data_high(IPC_DEV *ipcdev, IPC_TYPEtype, u32
data) -{drivers/platform/x86/intel_punit_ipc.c +10
-21-writel (data, ipcdev->base[type][BASE_DATA ] +OFFSET_DATA_HIGH ); -} +const char *ipc_dev_name[RESERVED_IPC ] = { +PUNIT_BIOS_IPC_DEV , +PUNIT_GTD_IPC_DEV , +PUNIT_ISP_IPC_DEV +}; -static const char *ipc_err_string(int error) -{ -if (error ==IPC_PUNIT_ERR_SUCCESS ) -return "no error" ; -else if (error ==IPC_PUNIT_ERR_INVALID_CMD ) -return "invalid command" ; -else if (error ==IPC_PUNIT_ERR_INVALID_PARAMETER ) -return "invalid parameter" ; -else if (error ==IPC_PUNIT_ERR_CMD_TIMEOUT ) -return "command timeout" ; -else if (error ==IPC_PUNIT_ERR_CMD_LOCKED ) -return "command locked" ; -else if (error ==IPC_PUNIT_ERR_INVALID_VR_ID ) -return "invalid vr id" ; -else if (error ==IPC_PUNIT_ERR_VR_ERR ) -return "vr error" ; -else -return "unknown error" ; -} +static struct regmap_config punit_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , +}; -static int intel_punit_ipc_check_status(IPC_DEV *ipcdev, IPC_TYPEtype)
drivers/platform/x86/intel_punit_ipc.c +1
-7+int pre_simple_cmd_fn (u32 *cmd_list,u32 cmdlen) { - int loops = CMD_TIMEOUT_SECONDS * USEC_PER_SEC; - int errcode; - int status; - - if (ipcdev->irq) { - if (!wait_for_completion_timeout(&ipcdev->cmd_complete, - CMD_TIMEOUT_SECONDS *HZ)) {
drivers/platform/x86/intel_punit_ipc.c +0
-5-dev_err (ipcdev->dev,"IPC timed out\n" ); -return -ETIMEDOUT ; - } - }else { - while ((ipc_read_status(ipcdev, type) & CMD_RUN) && --loops)
drivers/platform/x86/intel_punit_ipc.c +4
-36-udelay (1 ); -if (!loops) { -dev_err (ipcdev->dev,"IPC timed out\n" ); -return -ETIMEDOUT ; - } - } +if (!cmd_list || cmdlen !=PUNIT_PARAM_LEN ) +return -EINVAL ; - status =ipc_read_status (ipcdev, type); - errcode = status &CMD_ERRCODE_MASK ; -if (errcode) { -dev_err (ipcdev->dev,"IPC failed: %s, IPC_STS=0x%x\n" , -ipc_err_string (errcode), status); -return -EIO ; - } + cmd_list[0 ] |=CMD_RUN | cmd_list[1 ] <<CMD_PARA1_SHIFT | + cmd_list[2 ] <<CMD_PARA1_SHIFT ;return 0 ; } -/** -* intel_punit_ipc_simple_command() - Simple IPC command -* @cmd: IPC command code. -* @para1: First 8bit parameter, set 0 if not used. -* @para2: Second 8bit parameter, set 0 if not used. -* -* Send a IPC command to P-Unit when there is no data transaction -* -* Return: IPC error code or 0 on success. -*/ -int intel_punit_ipc_simple_command(int cmd, int para1, int para2) -{ -IPC_DEV *ipcdev = punit_ipcdev; -IPC_TYPE type; -u32 val; -int ret; - -mutex_lock (&ipcdev->lock); - -reinit_completion (&ipcdev->cmd_complete); - type = (cmd &IPC_PUNIT_CMD_TYPE_MASK ) >>IPC_TYPE_OFFSET ; - - val = cmd & ~IPC_PUNIT_CMD_TYPE_MASK ; - val |= CMD_RUN | para2 << CMD_PARA2_SHIFT | para1 <<
CMD_PARA1_SHIFT;drivers/platform/x86/intel_punit_ipc.c +0
-15-ipc_write_cmd (ipcdev, type, val); - ret =intel_punit_ipc_check_status (ipcdev, type); - -mutex_unlock (&ipcdev->lock); - -return ret; -} -EXPORT_SYMBOL (intel_punit_ipc_simple_command); - -/** -* intel_punit_ipc_command() - IPC command with data and pointers -* @cmd: IPC command code. -* @para1: First 8bit parameter, set 0 if not used. -* @para2: Second 8bit parameter, set 0 if not used. -* @in: Input data, 32bit for BIOS cmd, two 32bit for GTD and ISPD.
- * @out: Output data.
- *
- * Send a IPC command to P-Unit with data transaction
- *
- * Return: IPC error code or 0 on success.
- */
-int intel_punit_ipc_command(u32 cmd, u32 para1, u32 para2, u32 *in, u32
*out) -{drivers/platform/x86/intel_punit_ipc.c +0
-18-IPC_DEV *ipcdev = punit_ipcdev; -IPC_TYPE type; -u32 val; -int ret; - -mutex_lock (&ipcdev->lock); - -reinit_completion (&ipcdev->cmd_complete); - type = (cmd &IPC_PUNIT_CMD_TYPE_MASK ) >>IPC_TYPE_OFFSET ; - -if (in) { -ipc_write_data_low (ipcdev, type, *in); -if (type ==GTDRIVER_IPC || type ==ISPDRIVER_IPC ) -ipc_write_data_high (ipcdev, type, *++in); - } - - val = cmd & ~IPC_PUNIT_CMD_TYPE_MASK ; - val |= CMD_RUN | para2 << CMD_PARA2_SHIFT | para1 <<
CMD_PARA1_SHIFT;drivers/platform/x86/intel_punit_ipc.c +7
-24-ipc_write_cmd (ipcdev, type, val); - - ret =intel_punit_ipc_check_status (ipcdev, type); -if (ret) - goto out; - -if (out) { - *out =ipc_read_data_low (ipcdev, type); -if (type ==GTDRIVER_IPC || type ==ISPDRIVER_IPC ) - *++out =ipc_read_data_high (ipcdev, type); - } - -out: -mutex_unlock (&ipcdev->lock); -return ret; -} -EXPORT_SYMBOL_GPL (intel_punit_ipc_command); - -static irqreturn_t intel_punit_ioc (int irq,void *dev_id) +/* Input data, 32bit for BIOS cmd, two 32bit for GTD and ISPD. */ +int +pre_raw_cmd_fn (u32 *cmd_list,u32 cmdlen,u8 *in,u32 inlen,u32 *out, +u32 outlen,u32 dptr,u32 sptr) { -IPC_DEV *ipcdev = dev_id; - -complete (&ipcdev->cmd_complete); -return IRQ_HANDLED ; +return pre_simple_cmd_fn (cmd_list, cmdlen); } static int intel_punit_get_bars(struct platform_device *pdev) @@ -282,9 +137,77 @@ static int intel_punit_get_bars(struct platform_device +*pdev) return 0; }Quoted 8 lines
drivers/platform/x86/intel_punit_ipc.c static int intel_punit_get_bars(struct platform_device *pdev)
Quoted 8 lines
drivers/platform/x86/intel_punit_ipc.c +8
-0+static int punit_ipc_err_code (int status) { +return (status &CMD_ERRCODE_MASK ); } + +static int punit_ipc_busy_check (int status) { +return status |CMD_RUN ; +} + +static struct intel_ipc_dev *intel_punit_ipc_dev_create(struct device*dev,
Quoted 121 lines
Quoted 121 lines
drivers/platform/x86/intel_punit_ipc.c +18
-0+const char *devname, + int irq, + void __iomem *base, + void __iomem *data) +{ + struct intel_ipc_dev_ops *ops; +struct intel_ipc_dev_cfg *cfg; +struct regmap *cmd_regs, *data_regs; + + cfg =devm_kzalloc (dev,sizeof (*cfg),GFP_KERNEL ); +if (!cfg) +return ERR_PTR (-ENOMEM ); + + ops =devm_kzalloc (dev,sizeof (*ops),GFP_KERNEL ); +if (!ops) +return ERR_PTR (-ENOMEM ); + + punit_regmap_config.name = devm_kasprintf(dev, GFP_KERNEL,"%s_%s",
drivers/platform/x86/intel_punit_ipc.c +10
-0+ devname, "base"); + + cmd_regs =devm_regmap_init_mmio_clk (dev,NULL , base, + &punit_regmap_config); +if (IS_ERR (cmd_regs)) { +dev_err (dev,"cmd_regs regmap init failed\n" ); +return ERR_CAST (cmd_regs);; + } + + punit_regmap_config.name = devm_kasprintf(dev, GFP_KERNEL,"%s_%s",
drivers/platform/x86/intel_punit_ipc.c +29
-1+ devname, "data"); + + data_regs =devm_regmap_init_mmio_clk (dev,NULL , data, + &punit_regmap_config); +if (IS_ERR (data_regs)) { +dev_err (dev,"data_regs regmap init failed\n" ); +return ERR_CAST (data_regs);; + } + +/* set IPC dev ops */ + ops->to_err_code = punit_ipc_err_code; + ops->busy_check = punit_ipc_busy_check; + ops->pre_simple_cmd_fn = pre_simple_cmd_fn; + ops->pre_raw_cmd_fn = pre_raw_cmd_fn; + +if (irq >0 ) + cfg->mode =IPC_DEV_MODE_IRQ ; +else + cfg->mode =IPC_DEV_MODE_POLLING ; + + cfg->chan_type =IPC_CHANNEL_IA_PUNIT ; + cfg->irq = irq; + cfg->irqflags =IRQF_NO_SUSPEND |IRQF_SHARED ; + cfg->cmd_regs = cmd_regs; + cfg->data_regs = data_regs; + +return devm_intel_ipc_dev_create (dev, devname, cfg, ops); } +static int intel_punit_ipc_probe (struct platform_device *pdev) { -int irq, ret; +int irq, ret, i; punit_ipcdev =devm_kzalloc (&pdev->dev, sizeof(*punit_ipcdev), GFP_KERNEL); @@ -294,35 +217,30 @@ static int intel_punit_ipc_probe(struct
platform_device
*pdev)
platform_set_drvdata(pdev, punit_ipcdev);irq = platform_get_irq(pdev, 0);drivers/platform/x86/intel_punit_ipc.c +0
-9-if (irq <0 ) { - punit_ipcdev->irq =0 ; -dev_warn (&pdev->dev,"Invalid IRQ, using polling mode\n" ); - }else { - ret =devm_request_irq (&pdev->dev, irq, intel_punit_ioc, -IRQF_NO_SUSPEND ,"intel_punit_ipc" , - &punit_ipcdev); -if (ret) { - dev_err(&pdev->dev, "Failed to request irq: %d\n",irq);
drivers/platform/x86/intel_punit_ipc.c +16
-12-return ret; - } - punit_ipcdev->irq = irq; - } ret =intel_punit_get_bars (pdev);if (ret) - goto out; +return ret; + +for (i =0 ; i <RESERVED_IPC ; i++) { + punit_ipcdev->ipc_dev[i] =intel_punit_ipc_dev_create ( + &pdev->dev, + ipc_dev_name[i], + irq, + punit_ipcdev->base[i][BASE_IFACE ], + punit_ipcdev->base[i][BASE_DATA ]); + +if (IS_ERR (punit_ipcdev->ipc_dev[i])) { +dev_err (&pdev->dev,"%s create failed\n" , + ipc_dev_name[i]); +return PTR_ERR (punit_ipcdev->ipc_dev[i]); + } + } punit_ipcdev->dev = &pdev->dev; -mutex_init (&punit_ipcdev->lock); -init_completion (&punit_ipcdev->cmd_complete); -out:return ret; -} -static int intel_punit_ipc_remove(struct platform_device *pdev) -{ -return 0 ; } static const struct acpi_device_id punit_ipc_acpi_ids[] = { @@ -332,7 +250,6 @@ static const struct acpi_device_idpunit_ipc_acpi_ids[] = {
Quoted 12 lines
drivers/platform/x86/intel_telemetry_pltdrv.c
Quoted 11 lines
static struct platform_driver intel_punit_ipc_driver = { .probe = intel_punit_ipc_probe,drivers/platform/x86/intel_punit_ipc.c +0
-1- .remove = intel_punit_ipc_remove, .driver = { .name ="intel_punit_ipc" , .acpi_match_table = ACPI_PTR(punit_ipc_acpi_ids), diff --git
a/drivers/platform/x86/intel_telemetry_pltdrv.cb/drivers/platform/x86/intel_telemetry_pltdrv.c
index e0424d5..bf8284a 100644drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0This is a logical separation and so should be a different patch.
But if we split it into two different patches then it will break the bisect- ability of these patches.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
drivers/platform/x86/intel_telemetry_pltdrv.c struct telem_ssram_region { }; · line 100
Quoted 4 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0@@ -98,6 +98,7 @@ struct telem_ssram_region { };static struct telemetry_plt_config *telm_conf; +static struct intel_ipc_dev *punit_bios_ipc_dev;Simply
punit_ipc_devis good enough.There are three PUNIT IPC devices. So to differentiate between them I added extra string to it.
OK that makes sense.
However punit_bios_ipc is neither the actual device type/name nor indicates the usage of it since BIOS has got nothing to do with it (except for exposing the SSRAM base addr). Can we rename this to something that actually denotes what this is, e.g, "punit_telemetry_ipc_dev". Same change needs to be done in intel_punit_ipc.c as well.
Quoted 321 lines
Quoted 21 lines
Quoted 21 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +0
-1/* * The following counters are programmed by default during setup. @@ -127,7 +128,6 @@ static struct telemetry_evtmap {"PMC_S0IX_BLOCK_IPS_CLOCKS", 0x600B}, }; -static struct telemetry_evtmap telemetry_apl_pss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
{"IA_CORE0_C6_RES",0x0400},drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0@@ -283,13 +283,12 @@ static inline int
telemetry_plt_config_ioss_event(u32 evt_id, int index)static inline inttelemetry_plt_config_pss_event(u32 evt_id, int index){
u32write_buf;drivers/platform/x86/intel_telemetry_pltdrv.c +1
-1-int ret; +u32 cmd[PUNIT_PARAM_LEN ] = {0 };Quoted 12 lines
drivers/platform/x86/intel_telemetry_pltdrv.c static inline int telemetry_plt_config_ioss_event(u32 evt_id, int index) · line 292
Quoted 11 lines
write_buf = evt_id | TELEM_EVENT_ENABLE;drivers/platform/x86/intel_telemetry_pltdrv.c +0
-1- ret =intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT,
drivers/platform/x86/intel_telemetry_pltdrv.c +2
-3- index, 0, &write_buf, NULL); - -return ret; +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT , index,0 ); + return ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0+ (u8 *)&write_buf, sizeof(write_buf), NULL, 0, 0, 0); }1) Why use
raw_cmdhere? It should useipc_dev_cmd()according tooriginal design. Same everywhere though this file.
In my initial versions of this patch set, I had only exportedipc_dev_raw_cmd()API. Since this driver refactoring work was done during that time, I have usedintel_dev_raw_cmd()API in it. I have addedipc_dev_cmd()API only recently to handle some new requirements inintel_scu_ipc.cdriver.I will fix it in next version.
Quoted 3 lines
2)
punit_cmd_initandipc_dev_raw_cmdare repeated multiple time thoughout the file. They can be made into a separate local API inside telemetry, liketelemetry_punit_send_cmd(). Same thoughoutI will make this change in next version.
Quoted 48 lines
Quoted 48 lines
static int telemetry_setup_iossevtconfig(struct
telemetry_evtconfig
evtconfig, @@ -435,6 +434,7 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfigevtconfig,
int ret, index, idx;
u32*pss_evtmap;
u32telem_ctrl;drivers/platform/x86/intel_telemetry_pltdrv.c +3
-2+u32 cmd[PUNIT_PARAM_LEN ] = {0 }; num_pss_evts = evtconfig.num_evts; pss_period = evtconfig.period;@@ -442,8 +442,9 @@ static int telemetry_setup_pssevtconfig(struct telemetry_evtconfig evtconfig, /* PSS Config */ /* Get telemetry EVENT CTL */ - ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL, -0 ,0 ,NULL , &telem_ctrl); + punit_cmd_init(cmd, IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL, 0, 0); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN, NULL,drivers/platform/x86/intel_telemetry_pltdrv.c +3
-2+ 0, &telem_ctrl, 1, 0, 0);if (ret) {pr_err ("PSS TELEM_CTRL Read Failed\n" );return ret;@@ -451,8 +452,9 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,/* Disable Telemetry */ TELEM_DISABLE (telem_ctrl ); - ret =intel_punit_ipc_command (IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , 0); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0+ (u8 *)&telem_ctrl, sizeof(telem_ctrl), NULL, 0, 0, 0);if (ret) {pr_err ("PSS TELEM_CTRL Event Disable Write Failed\n" );return ret;@@ -463,9 +465,10 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,/* Clear All Events */ TELEM_CLEAR_EVENTS (telem_ctrl );Quoted 11 lines
Quoted 11 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3- ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );if (ret) { pr_err("PSS TELEM_CTRL Event Disable WriteFailed\n");
Quoted 6 lines
Quoted 6 lines
return ret;
drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0@@ -489,9 +492,10 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,/* Clear All Events */ TELEM_CLEAR_EVENTS (telem_ctrl );Quoted 11 lines
Quoted 11 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +4
-3- ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );if (ret) { pr_err("PSS TELEM_CTRL Event Disable WriteFailed\n");
Quoted 24 lines
Quoted 24 lines
return ret;
drivers/platform/x86/intel_telemetry_pltdrv.c +2
-2@@ -540,8 +544,9 @@ static int telemetry_setup_pssevtconfig(structtelemetry_evtconfig evtconfig,TELEM_ENABLE_PERIODIC (telem_ctrl ); telem_ctrl |= pss_period; - ret =intel_punit_ipc_command (IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , 0); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +2
-0+ (u8 *)&telem_ctrl, sizeof(telem_ctrl), NULL, 0, 0, 0);if (ret) {pr_err ("PSS TELEM_CTRL Event Enable Write Failed\n" );return ret;@@ -601,6 +606,7 @@ static int telemetry_setup(struct platform_device *pdev) {struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;u32 read_buf, events, event_regs; +u32 cmd[PUNIT_PARAM_LEN ] = {0 };int ret;Quoted 4 lines
Quoted 4 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
IOSS_TELEM_INFO_READ, @@ -626,8 +632,9 @@ static inttelemetry_setup(struct platform_device *pdev)
telm_conf->ioss_config.max_period=
TELEM_MAX_PERIOD(read_buf);Quoted 39 lines
Quoted 39 lines
/* PUNIT Mailbox Setup */
drivers/platform/x86/intel_telemetry_pltdrv.c +0
-1- ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_INFO,0, 0,
drivers/platform/x86/intel_telemetry_pltdrv.c +2
-1- NULL, &read_buf); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_READ_TELE_INFO ,0 ,0 ); + ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3+ NULL, 0, &read_buf, 1, 0, 0);if (ret) {dev_err (&pdev->dev,"PSS TELEM_INFO Read Failed\n" );return ret;@@ -695,6 +702,7 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period) {u32 telem_ctrl =0 ;int ret =0 ; +u32 cmd[PUNIT_PARAM_LEN ] = {0 };mutex_lock (&(telm_conf->telem_lock));if (ioss_period) {@@ -752,9 +760,9 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period) }/* Get telemetry EVENT CTL */ - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL , -0 ,0 ,NULL , &telem_ctrl); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , +NULL ,0 , &telem_ctrl,1 ,0 ,0 );if (ret) { pr_err("PSS TELEM_CTRL Read Failed\n"); goto out;drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0@@ -762,9 +770,11 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period)Quoted 14 lines
Quoted 12 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3/* Disable Telemetry */ TELEM_DISABLE (telem_ctrl); - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , +0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );Quoted 2 lines
if (ret) { pr_err("PSS TELEM_CTRL Event Disable WriteFailed\n");
Quoted 6 lines
Quoted 6 lines
goto out;
drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0@@ -776,9 +786,11 @@ static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period)TELEM_ENABLE_PERIODIC (telem_ctrl); telem_ctrl |= pss_period;Quoted 12 lines
Quoted 10 lines
drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3- ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , -0 ,0 , &telem_ctrl,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL ,0 , +0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&telem_ctrl,sizeof (telem_ctrl),NULL , +0 ,0 ,0 );Quoted 2 lines
if (ret) { pr_err("PSS TELEM_CTRL Event Enable WriteFailed\n");
Quoted 78 lines
Quoted 78 lines
goto out;
drivers/platform/x86/intel_telemetry_pltdrv.c +0
-0@@ -1013,6 +1025,7 @@ static inttelemetry_plt_get_trace_verbosity(enum
telemetry_unittelem_unit, {
u32 temp = 0;
int ret;drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0+u32 cmd[PUNIT_PARAM_LEN ] = {0 };if (verbosity ==NULL )return -EINVAL ;@@ -1020,9 +1033,9 @@ static inttelemetry_plt_get_trace_verbosity(enum
telemetry_unittelem_unit,
mutex_lock(&(telm_conf->telem_trace_lock)); switch (telem_unit) {
caseTELEM_PSS:drivers/platform/x86/intel_telemetry_pltdrv.c +1
-3- ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL , -0 ,0 ,NULL , &temp); + punit_cmd_init(cmd,
IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL, 0, 0);drivers/platform/x86/intel_telemetry_pltdrv.c +1
-0+ ret = ipc_dev_raw_cmd(punit_bios_ipc_dev, cmd,
PUNIT_PARAM_LEN,drivers/platform/x86/intel_telemetry_pltdrv.c +5
-3+ NULL, 0, &temp, 1, 0, 0);if (ret) {pr_err ("PSS TRACE_CTRL Read Failed\n" ); goto out;@@ -1058,15 +1071,16 @@ static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit, {u32 temp =0 ;int ret; +u32 cmd[PUNIT_PARAM_LEN ] = {0 }; verbosity &=TELEM_TRC_VERBOSITY_MASK ;mutex_lock (&(telm_conf->telem_trace_lock));switch (telem_unit) {case TELEM_PSS : - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL , -0 ,0 ,NULL , &temp); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL ,0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , +NULL ,0 , &temp,1 ,0 ,0 );if (ret) {pr_err("PSS TRACE_CTRL Read Failed\n"); goto out;drivers/platform/x86/intel_telemetry_pltdrv.c +4
-4@@ -1074,10 +1088,10 @@ static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit,TELEM_CLEAR_VERBOSITY_BITS (temp);TELEM_SET_VERBOSITY_BITS (temp, verbosity); - - ret =intel_punit_ipc_command ( -IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL , -0 ,0 , &temp,NULL ); +punit_cmd_init (cmd,IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL , +0 ,0 ); + ret =ipc_dev_raw_cmd (punit_bios_ipc_dev, cmd,PUNIT_PARAM_LEN , + (u8 *)&temp,sizeof (temp),NULL ,0 ,0 ,0 );if (ret) { pr_err("PSS TRACE_CTRL Verbosity Set Failed\n"); goto out;drivers/platform/x86/intel_telemetry_pltdrv.c +4
-0@@ -1139,6 +1153,10 @@ static int telemetry_pltdrv_probe(struct platform_device *pdev)if (!id)return -ENODEV ; + punit_bios_ipc_dev =intel_ipc_dev_get (PUNIT_BIOS_IPC_DEV ); +if (IS_ERR_OR_NULL (punit_bios_ipc_dev)) +return PTR_ERR (punit_bios_ipc_dev); + telm_conf = (struct telemetry_plt_config *)id->driver_data;Quoted 4 lines
Quoted 4 lines
res0 =
platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -
1218,6 +1236,7 @@ static int telemetry_pltdrv_probe(structplatform_device
*pdev) static inttelemetry_pltdrv_remove(struct platform_device *pdev){
Quoted 8 lines
Quoted 7 lines
telemetry_clear_pltdata();drivers/platform/x86/intel_telemetry_pltdrv.c +1
-1+intel_ipc_dev_put (punit_bios_ipc_dev);iounmap (telm_conf->pss_config.regmap);iounmap (telm_conf->ioss_config.regmap); --2.7.4
--
Sathyanarayanan Kuppuswamy
Linux kernel developer
RE: [RFC v5 4/8] platform: x86: Add generic Intel IPC driver
In reply to sathyanarayanan kuppuswamyQuoted 380 lines · Kuppuswamy Sathyanarayanan
Hi,
Quoted 305 lines · Souvik K
Quoted 305 lines
From: [email protected] [mailto:[email protected]]
Sent: Sunday, October 8, 2017 3:50 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zha, Qipeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Chakravarty, Souvik K <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Kuppuswamy Sathyanarayanan <[email protected]>
Subject: [RFC v5 4/8] platform: x86: Add generic Intel IPC driverFrom: Kuppuswamy Sathyanarayanan
<[email protected]>Currently
intel_scu_ipc.c,intel_pmc_ipc.candintel_punit_ipc.credundantly implements the same IPC features and has lot of code duplication between them. This driver addresses this issue by grouping the common IPC functionalities under the same driver.Signed-off-by: Kuppuswamy Sathyanarayanan
<[email protected]>--- drivers/platform/x86/Kconfig | 8 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_ipc_dev.c | 576 ++++++++++++++++++++++++ include/linux/platform_data/x86/intel_ipc_dev.h | 206 +++++++++ 4 files changed, 791 insertions(+)create mode 100644
drivers/platform/x86/intel_ipc_dev.ccreate mode 100644include/linux/platform_data/x86/intel_ipc_dev.hChanges since v4:
* NoneChanges since v3:
* Fixed NULL pointer exception inintel_ipc_dev_get().
* Fixed error in check for duplicateintel_ipc_dev.
* Added custom interrupt handler support.
* Used char array for error string conversion.
* Added put dev support.
* Added devm_* variant ofintel_ipc_dev_get().Changes since v2:
* Addedipc_dev_cmdAPI support.(quoted diff) +0
-0b/drivers/platform/x86/Kconfig index da2d9ba..724ee696 100644
drivers/platform/x86/Kconfig +8
-0@@ -1153,6 +1153,14 @@ config SILEAD_DMI with the OS-image for the device. This option supplies the missing information. Enable this for x86 tablets with Silead touchscreens. +config INTEL_IPC_DEV + bool "Intel IPC Device Driver" + depends on X86_64 + ---help--- + This driver implements core features of Intel IPC device. Devices + like PMC, SCU, PUNIT, etc can use interfaces provided by this + driver to implement IPC protocol of their respective device. + endif # X86_PLATFORM_DEVICES config PMC_ATOM(quoted diff) +0
-0b/drivers/platform/x86/Makefile index 2b315d0..99a1af1 100644
drivers/platform/x86/Makefile +0
-0@@ -84,3 +84,4 @@ obj-$(CONFIG_PMC_ATOM) +=pmc_atom.o
obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o
obj-$(CONFIG_MLX_CPLD_PLATFORM) += mlxcpld-hotplug.o
obj-$(CONFIG_INTEL_TURBO_MAX_3) += intel_turbo_max_3.odrivers/platform/x86/Makefile +1
-0+obj-$(CONFIG_INTEL_IPC_DEV) += intel_ipc_dev.odrivers/platform/x86/intel_ipc_dev.c new file +116
-0@@ -0,0 +1,576 @@ +/* +* intel_ipc_dev.c: Intel IPC device class driver +* +* (C) Copyright 2017 Intel Corporation +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; version 2 +* of the License. +* +*/ + +#include <linux/device.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/export.h> +#include <linux/idr.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/interrupt.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> +#include <linux/regmap.h> + +/* mutex to sync different ipc devices in same channel */ static +struct mutex channel_lock[IPC_CHANNEL_MAX ]; + +static char *ipc_err_sources[] = { + [IPC_DEV_ERR_NONE ] = +"No error" , + [IPC_DEV_ERR_CMD_NOT_SUPPORTED ] = +"Command not-supported/Invalid" , + [IPC_DEV_ERR_CMD_NOT_SERVICED ] = +"Command not-serviced/Invalid param" , + [IPC_DEV_ERR_UNABLE_TO_SERVICE ] = +"Unable-to-service/Cmd-timeout" , + [IPC_DEV_ERR_CMD_INVALID ] = +"Command-invalid/Cmd-locked" , + [IPC_DEV_ERR_CMD_FAILED ] = +"Command-failed/Invalid-VR-id" , + [IPC_DEV_ERR_EMSECURITY ] = +"Invalid Battery/VR-Error" , + [IPC_DEV_ERR_UNSIGNEDKERNEL ] = +"Unsigned kernel" , +}; + +static void ipc_channel_lock_init (void ) { +int i; + +for (i =0 ; i <IPC_CHANNEL_MAX ; i++) +mutex_init (&channel_lock[i]); +} + +static struct class intel_ipc_class = { + .name ="intel_ipc" , + .owner =THIS_MODULE , +}; + +static int ipc_dev_lock (struct intel_ipc_dev *ipc_dev) { +int chan_type; + +if (!ipc_dev || !ipc_dev->cfg) +return -ENODEV ; + + chan_type = ipc_dev->cfg->chan_type; +if (chan_type >IPC_CHANNEL_MAX ) +return -EINVAL ; + +/* acquire channel lock */ +mutex_lock (&channel_lock[chan_type]); + +/* acquire IPC device lock */ +mutex_lock (&ipc_dev->lock); + +return 0 ; +} + +static int ipc_dev_unlock (struct intel_ipc_dev *ipc_dev) { +int chan_type; + +if (!ipc_dev || !ipc_dev->cfg) +return -ENODEV ; + + chan_type = ipc_dev->cfg->chan_type; +if (chan_type >IPC_CHANNEL_MAX ) +return -EINVAL ; + +/* release IPC device lock */ +mutex_unlock (&ipc_dev->lock); + +/* release channel lock */ +mutex_unlock (&channel_lock[chan_type]); + +return 0 ; +} + +static const char *ipc_dev_err_string (struct intel_ipc_dev *ipc_dev, +int error) +{ +if (error <IPC_DEV_ERR_MAX ) +return ipc_err_sources[error]; + +return "Unknown Command" ; +} + +/* Helper function to send given command to IPC device */ static +inline void ipc_dev_send_cmd (struct intel_ipc_dev *ipc_dev,u32 cmd) { + ipc_dev->cmd = cmd; + +if (ipc_dev->cfg->mode ==IPC_DEV_MODE_IRQ ) +reinit_completion (&ipc_dev->cmd_complete); + +if (ipc_dev->ops->enable_msi) + cmd = ipc_dev->ops->enable_msi (cmd); + +regmap_write (ipc_dev->cfg->cmd_regs, ipc_dev->cfg->cmd_reg, cmd);}
drivers/platform/x86/intel_ipc_dev.c new file +33
-0+ +static inline int ipc_dev_status_busy (struct intel_ipc_dev *ipc_dev) { +int status; + +regmap_read (ipc_dev->cfg->cmd_regs, ipc_dev->cfg->status_reg, +&status); + +if (ipc_dev->ops->busy_check) +return ipc_dev->ops->busy_check (status); + +return 0 ; +} + +/* Check the status of IPC command and return err code if failed */ +static int ipc_dev_check_status (struct intel_ipc_dev *ipc_dev) { +int loop_count =IPC_DEV_CMD_LOOP_CNT ; +int status; +int ret =0 ; + +if (ipc_dev->cfg->mode ==IPC_DEV_MODE_IRQ ) { +if (!wait_for_completion_timeout (&ipc_dev->cmd_complete, +IPC_DEV_CMD_TIMEOUT )) + ret = -ETIMEDOUT ; + }else { +while (ipc_dev_status_busy (ipc_dev) && --loop_count) +udelay (1 ); +if (!loop_count) + ret = -ETIMEDOUT ; + } + +if (ret <0 ) { + dev_err(&ipc_dev->dev, + "IPC timed out, CMD=0x%x\n", ipc_dev-Quoted 1 line
cmd);
drivers/platform/x86/intel_ipc_dev.c new file +70
-0+return ret; + } + +regmap_read (ipc_dev->cfg->cmd_regs, ipc_dev->cfg->status_reg, +&status); + +if (ipc_dev->ops->to_err_code) + ret = ipc_dev->ops->to_err_code (status); + +if (ret) { +dev_err (&ipc_dev->dev, +"IPC failed: %s, STS=0x%x, CMD=0x%x\n" , +ipc_dev_err_string (ipc_dev, ret), + status, ipc_dev->cmd); +return -EIO ; + } + +return 0 ; +} + +/** +* ipc_dev_simple_cmd() - Send simple IPC command +* @ipc_dev : Reference to ipc device. +* @cmd_list : IPC command list. +* @cmdlen : Number of cmd/sub-cmds. +* +* Send a simple IPC command to ipc device. +* Use this when don't need to specify input/output data +* and source/dest pointers. +* +* Return: an IPC error code or 0 on success. +*/ + +int ipc_dev_simple_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list, +u32 cmdlen) +{ +int ret; + +if (!cmd_list) +return -EINVAL ; + + ret =ipc_dev_lock (ipc_dev); +if (ret) +return ret; + +/* Call custom pre-processing handler */ +if (ipc_dev->ops->pre_simple_cmd_fn) { + ret = ipc_dev->ops->pre_simple_cmd_fn (cmd_list, cmdlen); +if (ret) + goto unlock_device; + } + +ipc_dev_send_cmd (ipc_dev, cmd_list[0 ]); + + ret =ipc_dev_check_status (ipc_dev); + +unlock_device: +ipc_dev_unlock (ipc_dev); + +return ret; +} +EXPORT_SYMBOL_GPL (ipc_dev_simple_cmd); + +/** +* ipc_dev_cmd() - Send IPC command with data. +* @ipc_dev : Reference to ipc_dev. +* @cmd_list : Array of commands/sub-commands. +* @cmdlen : Number of commands. +* @in : Input data of this IPC command. +* @inlen : Input data length in dwords. Quoted 8 lines
Quoted 8 lines
+ * @out : Output data of this IPC command.
+ * @outlen : Length of output data in dwords.
+ *
+ * Send an IPC command to device with input/output data.
+ *
+ * Return: an IPC error code or 0 on success.
+ */
+int ipc_dev_cmd(structintel_ipc_dev*ipc_dev, u32*cmd_list, u32cmdlen,
Quoted 51 lines
Quoted 51 lines
drivers/platform/x86/intel_ipc_dev.c new file +51
-0+ u32 *in, u32 inlen, u32 *out, u32 outlen) { + int ret; + +if (!cmd_list || !in) +return -EINVAL ; + + ret =ipc_dev_lock (ipc_dev); +if (ret) +return ret; + +/* Call custom pre-processing handler. */ +if (ipc_dev->ops->pre_cmd_fn) { + ret = ipc_dev->ops->pre_cmd_fn (cmd_list, cmdlen, in, inlen, + out, outlen); +if (ret) + goto unlock_device; + } + +/* Write inlen dwords of data to wrbuf_reg. */ +if (inlen >0 ) +regmap_bulk_write (ipc_dev->cfg->data_regs, + ipc_dev->cfg->wrbuf_reg, in, inlen); + +ipc_dev_send_cmd (ipc_dev, cmd_list[0 ]); + + ret =ipc_dev_check_status (ipc_dev); + +/* Read outlen dwords of data from rbug_reg. */ +if (!ret && outlen >0 ) +regmap_bulk_read (ipc_dev->cfg->data_regs, + ipc_dev->cfg->rbuf_reg, out, outlen); +unlock_device: +ipc_dev_unlock (ipc_dev); + +return ret; +} +EXPORT_SYMBOL_GPL (ipc_dev_cmd); + +/** +* ipc_dev_raw_cmd() - Send IPC command with data and pointers. +* @ipc_dev : Reference to ipc_dev. +* @cmd_list : Array of commands/sub-commands. +* @cmdlen : Number of commands. +* @in : Input data of this IPC command. +* @inlen : Input data length in bytes. +* @out : Output data of this IPC command. +* @outlen : Length of output data in dwords. +* @dptr : IPC destination data address. +* @sptr : IPC source data address. +* +* Send an IPC command to device with input/output data and Quoted 8 lines
Quoted 4 lines
+ * source/dest pointers.
+ *
+ * Return: an IPC error code or 0 on success.
+ */Sorry for coming in so late but since we are refactoring the API anyways, isn't it better to reduce the signature? Nine parameters is an awful lot and prone to errors and difficult to debug. (We found it out the hard way when we started using this a few years ago.)
I agree. Initially I thought of adding a command structure just like you mentioned. But finally decided not to do it because,
Quoted 7 lines
1. Not all drivers uses all parameters of this API. Most of them pass 0,0 for DPTR and SPTR pointers. So the last two arguments are almost not used.
2. Adding a new structure requires all users of this API to add buffer code / some additional call to initialize the command structure which in turn makes the code look bit complex.
One can combine SPTR/DPTR into a separate struct could directly be passed as NULL for users who are not interested. That would take care of some complexity.
For the rest of the parameters, requiring the user to populate a struct for cmd_params could actually be useful. Since the user will be required to specifically initialize each parameter by name, it may prevent accidental jumbling of parameters (like mixing up in/out etc.) vis-a-vis passing all nine parameters in a row. Plus it will be a lot better from the readability perspective.
So from my point of view, the little cmd_param assignment overhead is worth the benefits in readability + preventing accidental bug insertions + ease of debug.
FWIW I have not seen six+ parameters for any API in Linux.
Quoted 515 lines
So I am not really sure whether it add any value. But if its the recommended approach then I will make that modification.
Quoted 439 lines
This can be consolidated into a few neat structs, e.g.,:
int ipc_dev_raw_cmd(structintel_ipc_dev*ipc_dev, structipc_cmd*cmd,
structipc_cmd_data*cmd_data, structipc_data_addr*addr)Same for the
ipc_dev_cmd()APIs above as well.Quoted 433 lines
drivers/platform/x86/intel_ipc_dev.c new file +3
-0+ +int ipc_dev_raw_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list, +u32cmdlen,
drivers/platform/x86/intel_ipc_dev.c new file +19
-0+ u8 *in, u32 inlen, u32 *out, u32 outlen, u32 dptr, u32 sptr) { + int ret; +int inbuflen =DIV_ROUND_UP (inlen,4 ); +u32 *inbuf; + +if (!cmd_list || !in) +return -EINVAL ; + + inbuf =kzalloc (inbuflen,GFP_KERNEL ); +if (!inbuf) +return -ENOMEM ; + + ret =ipc_dev_lock (ipc_dev); +if (ret) +return ret; + +/* Call custom pre-processing handler. */ + if (ipc_dev->ops->pre_raw_cmd_fn) { + ret = ipc_dev->ops->pre_raw_cmd_fn(cmd_list, cmdlen, in,inlen,
drivers/platform/x86/intel_ipc_dev.c new file +8
-0+ out, outlen, dptr, sptr); +if (ret) + goto unlock_device; + } + +/* If supported, write DPTR register.*/ +if (ipc_dev->cfg->support_dptr) + regmap_write(ipc_dev->cfg->cmd_regs, ipc_dev->cfg-Quoted 1 line
dptr_reg,drivers/platform/x86/intel_ipc_dev.c new file +5
-0+ dptr); + +/* If supported, write SPTR register. */ +if (ipc_dev->cfg->support_sptr) + regmap_write(ipc_dev->cfg->cmd_regs, ipc_dev->cfg-Quoted 1 line
sptr_reg,drivers/platform/x86/intel_ipc_dev.c new file +105
-0+ sptr); + +memcpy (inbuf, in, inlen); + +/* Write inlen dwords of data to wrbuf_reg. */ +if (inlen >0 ) +regmap_bulk_write (ipc_dev->cfg->data_regs, + ipc_dev->cfg->wrbuf_reg, inbuf, inbuflen); + +ipc_dev_send_cmd (ipc_dev, cmd_list[0 ]); + + ret =ipc_dev_check_status (ipc_dev); + +/* Read outlen dwords of data from rbug_reg. */ +if (!ret && outlen >0 ) +regmap_bulk_read (ipc_dev->cfg->data_regs, + ipc_dev->cfg->rbuf_reg, out, outlen); +unlock_device: +ipc_dev_unlock (ipc_dev); +kfree (inbuf); + +return ret; +} +EXPORT_SYMBOL_GPL (ipc_dev_raw_cmd); + +/* sysfs option to send simple IPC commands from userspace */ static +ssize_t ipc_dev_cmd_reg_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) { +struct intel_ipc_dev *ipc_dev =dev_get_drvdata (dev); +u32 cmd; +int ret; + + ret =sscanf (buf,"%d" , &cmd); +if (ret !=1 ) { +dev_err (dev,"Error args\n" ); +return -EINVAL ; + } + + ret =ipc_dev_simple_cmd (ipc_dev, &cmd,1 ); +if (ret) { +dev_err (dev,"command 0x%x error with %d\n" , cmd, ret); +return ret; + } +return (ssize_t )count; +} + +static DEVICE_ATTR(send_cmd, S_IWUSR, NULL, ipc_dev_cmd_reg_store); + +static struct attribute *ipc_dev_attrs[] = { + &dev_attr_send_cmd.attr, +NULL +}; + +static const struct attribute_group ipc_dev_group = { + .attrs = ipc_dev_attrs, +}; + +static const struct attribute_group *ipc_dev_groups[] = { + &ipc_dev_group, +NULL , +}; + +/* IPC device IRQ handler */ +static irqreturn_t ipc_dev_irq_handler (int irq,void *dev_id) { +struct intel_ipc_dev *ipc_dev = (struct intel_ipc_dev *)dev_id; + +if (ipc_dev->ops->pre_irq_handler_fn) + ipc_dev->ops->pre_irq_handler_fn (ipc_dev, irq); + +complete (&ipc_dev->cmd_complete); + +return IRQ_HANDLED ; +} + +static void devm_intel_ipc_dev_release (struct device *dev,void *res) { +struct intel_ipc_dev *ipc_dev = *(struct intel_ipc_dev **)res; + +if (!ipc_dev) +return ; + +device_del (&ipc_dev->dev); + +kfree (ipc_dev); +} + +static int match_name (struct device *dev,const void *data) { +if (!dev_name (dev)) +return 0 ; + +return !strcmp (dev_name (dev), (char *)data); } + +/** +* intel_ipc_dev_get() - Get Intel IPC device from name. +* @dev_name : Name of the IPC device. +* +* Return : ERR_PTR/NULL or intel_ipc_dev pointer on success. +*/ +struct intel_ipc_dev *intel_ipc_dev_get (const char *dev_name) { +struct device *dev; + +if (!dev_name) +return ERR_PTR (-EINVAL ); + + dev = class_find_device(&intel_ipc_class, NULL, dev_name,
match_name);drivers/platform/x86/intel_ipc_dev.c new file +9
-0+ +return dev ?dev_get_drvdata (dev) :NULL ; } +EXPORT_SYMBOL_GPL (intel_ipc_dev_get); + +static void devm_intel_ipc_dev_put (struct device *dev,void *res) { +intel_ipc_dev_put (*(struct intel_ipc_dev **)res); } + +/** +* devm_intel_ipc_dev_get() - Resource managed version of
intel_ipc_dev_get().
+ * @dev : Device pointer.
+ * @dev_name : Name of the IPC device.
+ *
+ * Return : ERR_PTR/NULL orintel_ipc_devpointer on success.
+ */drivers/platform/x86/intel_ipc_dev.c new file +6
-0+struct intel_ipc_dev *devm_intel_ipc_dev_get (struct device *dev, +const char *dev_name) +{ +struct intel_ipc_dev **ptr, *ipc_dev; + + ptr = devres_alloc(devm_intel_ipc_dev_put, sizeof(*ptr),
GFP_KERNEL);drivers/platform/x86/intel_ipc_dev.c new file +117
-0+if (!ptr) +return ERR_PTR (-ENOMEM ); + + ipc_dev =intel_ipc_dev_get (dev_name); +if (!IS_ERR_OR_NULL (ipc_dev)) { + *ptr = ipc_dev; +devres_add (dev, ptr); + }else { +devres_free (ptr); + } + +return ipc_dev; +} +EXPORT_SYMBOL_GPL (devm_intel_ipc_dev_get); + +/** +* devm_intel_ipc_dev_create() - Create IPC device +* @dev : IPC parent device. +* @devname : Name of the IPC device. +* @cfg : IPC device configuration. +* @ops : IPC device ops. +* +* Resource managed API to create IPC device with +* given configuration. +* +* Return : IPC device pointer or ERR_PTR(error code). +*/ +struct intel_ipc_dev *devm_intel_ipc_dev_create (struct device *dev, +const char *devname, +struct intel_ipc_dev_cfg *cfg, +struct intel_ipc_dev_ops *ops) +{ +struct intel_ipc_dev **ptr, *ipc_dev; +int ret; + +if (!dev && !devname && !cfg) +return ERR_PTR (-EINVAL ); + +if (intel_ipc_dev_get (devname)) { +dev_err (dev,"IPC device %s already exist\n" , devname); +return ERR_PTR (-EINVAL ); + } + + ptr =devres_alloc (devm_intel_ipc_dev_release,sizeof (*ptr), +GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + + ipc_dev =kzalloc (sizeof (*ipc_dev),GFP_KERNEL ); +if (!ipc_dev) { + ret = -ENOMEM ; + goto err_dev_create; + } + + ipc_dev->dev.class = &intel_ipc_class; + ipc_dev->dev.parent = dev; + ipc_dev->dev.groups = ipc_dev_groups; + ipc_dev->cfg = cfg; + ipc_dev->ops = ops; + +mutex_init (&ipc_dev->lock); +init_completion (&ipc_dev->cmd_complete); +dev_set_drvdata (&ipc_dev->dev, ipc_dev); +dev_set_name (&ipc_dev->dev, devname); +device_initialize (&ipc_dev->dev); + + ret =device_add (&ipc_dev->dev); +if (ret <0 ) { +dev_err (&ipc_dev->dev,"%s device create failed\n" , + __func__); + ret = -ENODEV ; + goto err_dev_add; + } + +if (ipc_dev->cfg->mode ==IPC_DEV_MODE_IRQ ) { +if (devm_request_irq (&ipc_dev->dev, + ipc_dev->cfg->irq, + ipc_dev_irq_handler, + ipc_dev->cfg->irqflags, +dev_name (&ipc_dev->dev), + ipc_dev)) { +dev_err (&ipc_dev->dev, +"Failed to request irq\n" ); + goto err_irq_request; + } + } + + *ptr = ipc_dev; + +devres_add (dev, ptr); + +return ipc_dev; + +err_irq_request: +device_del (&ipc_dev->dev); +err_dev_add: +kfree (ipc_dev); +err_dev_create: +devres_free (ptr); +return ERR_PTR (ret); +} +EXPORT_SYMBOL_GPL (devm_intel_ipc_dev_create); + +static int __init intel_ipc_init (void ) { +ipc_channel_lock_init (); +return class_register (&intel_ipc_class); } + +static void __exit intel_ipc_exit(void) { +class_unregister (&intel_ipc_class); +} +subsys_initcall (intel_ipc_init); +module_exit (intel_ipc_exit); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR("Kuppuswamy +Sathyanarayanan<[email protected]>"); +MODULE_DESCRIPTION("Intel IPC device class driver");include/linux/platform_data/x86/intel_ipc_dev.h new file +142
-0@@ -0,0 +1,206 @@ +/* +* Intel IPC class device header file. +* +* (C) Copyright 2017 Intel Corporation +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; version 2 +* of the License. +* +*/ + +#ifndef INTEL_IPC_DEV_H +#define INTEL_IPC_DEV_H + +#include <linux/module.h> +#include <linux/device.h> + +/* IPC channel type */ +#define IPC_CHANNEL_IA_PMC 0 +#define IPC_CHANNEL_IA_PUNIT 1 +#define IPC_CHANNEL_PMC_PUNIT 2 +#define IPC_CHANNEL_IA_SCU 3 +#define IPC_CHANNEL_MAX 4 + +/* IPC return code */ +#define IPC_DEV_ERR_NONE 0 +#define IPC_DEV_ERR_CMD_NOT_SUPPORTED 1 +#define IPC_DEV_ERR_CMD_NOT_SERVICED 2 +#define IPC_DEV_ERR_UNABLE_TO_SERVICE 3 +#define IPC_DEV_ERR_CMD_INVALID 4 +#define IPC_DEV_ERR_CMD_FAILED 5 +#define IPC_DEV_ERR_EMSECURITY 6 +#define IPC_DEV_ERR_UNSIGNEDKERNEL 7 +#define IPC_DEV_ERR_MAX 8 + +/* IPC mode */ +#define IPC_DEV_MODE_IRQ 0 +#define IPC_DEV_MODE_POLLING 1 + +/* IPC dev constants */ +#define IPC_DEV_CMD_LOOP_CNT 3000000 +#define IPC_DEV_CMD_TIMEOUT 3 * HZ +#define IPC_DEV_DATA_BUFFER_SIZE 16 + +struct intel_ipc_dev ; +struct intel_ipc_raw_cmd ; + +/** +* struct intel_ipc_dev_cfg - IPC device config structure. +* +* IPC device drivers uses the following config options to +* register new IPC device. +* +* @cmd_regs : IPC device command base regmap. +* @data_regs : IPC device data base regmap. +* @wrbuf_reg : IPC device data write register address. +* @rbuf_reg : IPC device data read register address. +* @sptr_reg : IPC device source data pointer register address. +* @dptr_reg : IPC device destination data pointer register +* address. +* @status_reg : IPC command status register address. +* @cmd_reg : IPC command register address. +* @mode : IRQ/POLLING mode. +* @irq : IPC device IRQ number. +* @irqflags : IPC device IRQ flags. +* @chan_type : IPC device channel type(PMC/PUNIT). +* @msi : Enable/Disable MSI for IPC commands. +* @support_dptr : Support DPTR update. +* @support_sptr : Support SPTR update. +* +*/ +struct intel_ipc_dev_cfg { +struct regmap *cmd_regs; +struct regmap *data_regs; +unsigned int wrbuf_reg; +unsigned int rbuf_reg; +unsigned int sptr_reg; +unsigned int dptr_reg; +unsigned int status_reg; +unsigned int cmd_reg; +int mode; +int irq; +int irqflags; +int chan_type; +bool use_msi; +bool support_dptr; +bool support_sptr; +}; + +/** +* struct intel_ipc_dev_ops - IPC device ops structure. +* +* Call backs for IPC device specific operations. +* +* @to_err_code : Status to error code conversion function. +* @busy_check : Check for IPC busy status. +* @enable_msi : Enable MSI for IPC commands. +* @pre_simple_cmd_fn : Custom pre-processing function for +* ipc_dev_simple_cmd() +* @pre_cmd_fn : Custom pre-processing function for +* ipc_dev_cmd() +* @pre_raw_cmd_fn : Custom pre-processing function for +* ipc_dev_raw_cmd() +* +*/ +struct intel_ipc_dev_ops { +int (*to_err_code)(int status); +int (*busy_check)(int status); +u32 (*enable_msi)(u32 cmd); +int (*pre_simple_cmd_fn)(u32 *cmd_list,u32 cmdlen); +int (*pre_cmd_fn)(u32 *cmd_list,u32 cmdlen,u32 *in,u32 inlen, +u32 *out,u32 outlen); +int (*pre_raw_cmd_fn)(u32 *cmd_list,u32 cmdlen,u8 *in,u32 inlen, +u32 *out,u32 outlen,u32 dptr,u32 sptr); +int (*pre_irq_handler_fn)(struct intel_ipc_dev *ipc_dev,int irq); +}; + +/** +* struct intel_ipc_dev - Intel IPC device structure. +* +* Used with devm_intel_ipc_dev_create() to create new IPC device. +* +* @dev : IPC device object. +* @cmd : Current IPC device command. +* @cmd_complete : Command completion object. +* @lock : Lock to protect IPC device structure. +* @ops : IPC device ops pointer. +* @cfg : IPC device cfg pointer. +* +*/ +struct intel_ipc_dev { +struct device dev; +int cmd; +struct completion cmd_complete; +struct mutex lock; +struct intel_ipc_dev_ops *ops; +struct intel_ipc_dev_cfg *cfg; +}; + +#if IS_ENABLED (CONFIG_INTEL_IPC_DEV ) +Quoted 8 lines
include/linux/platform_data/x86/intel_ipc_dev.h
Quoted 8 lines
include/linux/platform_data/x86/intel_ipc_dev.h new file +8
-0+/* API to create new IPC device */ +struct intel_ipc_dev *devm_intel_ipc_dev_create (struct device *dev, +const char *devname,struct intel_ipc_dev_cfg *cfg, +struct intel_ipc_dev_ops *ops); + +int ipc_dev_simple_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list, +u32 cmdlen); +int ipc_dev_cmd(struct intel_ipc_dev *ipc_dev, u32 *cmd_list, u32cmdlen,
Quoted 52 lines
Quoted 52 lines
include/linux/platform_data/x86/intel_ipc_dev.h new file +1
-0+ u32 *in, u32 inlen, u32 *out, u32 outlen); intipc_dev_raw_cmd(struct
include/linux/platform_data/x86/intel_ipc_dev.h new file +2
-0+intel_ipc_dev *ipc_dev, u32 *cmd_list, u32 cmdlen, + u8 *in, u32 inlen, u32 *out, u32 outlen, u32 dptr, u32 sptr);struct
include/linux/platform_data/x86/intel_ipc_dev.h new file +28
-0+intel_ipc_dev *intel_ipc_dev_get (const char *dev_name);struct +intel_ipc_dev *devm_intel_ipc_dev_get (struct device *dev, +const char *dev_name); +static inline void intel_ipc_dev_put (struct intel_ipc_dev *ipc_dev) { +put_device (&ipc_dev->dev); +} +#else + +static inline struct intel_ipc_dev *devm_intel_ipc_dev_create ( +struct device *dev, +const char *devname,struct intel_ipc_dev_cfg *cfg, +struct intel_ipc_dev_ops *ops) +{ +return -EINVAL ; +} + +static inline int ipc_dev_simple_cmd (struct intel_ipc_dev *ipc_dev, +u32 *cmd_list,u32 cmdlen) +{ +return -EINVAL ; +} + +static int ipc_dev_cmd (struct intel_ipc_dev *ipc_dev,u32 *cmd_list, +u32 cmdlen,u32 *in,u32 inlen,u32 *out,u32 outlen) { +return -EINVAL ; +} + +static inline int ipc_dev_raw_cmd(struct intel_ipc_dev *ipc_dev, u32
*cmd_list,include/linux/platform_data/x86/intel_ipc_dev.h new file +13
-0+ u32 cmdlen, u8 *in, u32 inlen, u32 *out, u32 outlen, + u32 dptr, u32 sptr); +{ +return -EINVAL ; +} + +static inline struct intel_ipc_dev *intel_ipc_dev_get (const char +*dev_name) { +return NULL ; +} + +static inline struct intel_ipc_dev *devm_intel_ipc_dev_get (struct +device*dev,
include/linux/platform_data/x86/intel_ipc_dev.h new file +4
-0+ const char *dev_name); +{ +return NULL ; +}Quoted 9 lines
Quoted 8 lines
include/linux/platform_data/x86/intel_ipc_dev.h new file +6
-1+ +static inline void intel_ipc_dev_put (struct intel_ipc_dev *ipc_dev) { +return NULL ; +} +#endif /* CONFIG_INTEL_IPC_DEV */ +#endif /* INTEL_IPC_DEV_H */ --2.7.4
--
Sathyanarayanan Kuppuswamy
Linux kernel developer