Skip to contentSkip to conversation

platform/x86: intel_scu_ipc: Platform data is mandatory

PATCH New Andy Shevchenko 1 participant 5 messages Apr 5, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 platform/x86: intel_scu_ipc: Platform data is mandatory

Fail ->probe() if there is no platform data supplied.

---
 drivers/platform/x86/intel_scu_ipc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/platform/x86/intel_scu_ipc.c +2 -0
index e81daff65f62..d789fe1baf17 100644
@@ -579,6 +579,8 @@ static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		return -EBUSY;
 
 	pdata = (struct intel_scu_ipc_pdata_t *)id->driver_data;
+	if (!pdata)
+		return -ENODEV;
 
 	scu->dev = &pdev->dev;
 	scu->irq_mode = pdata->irq_mode;
Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/5 platform/x86: intel_scu_ipc: Rearrange init sequence

Device pointer is used as a flag that everything is prepared. Nevertheless the assignment happened quite before and there is a window when a caller can get weird results or even crashes since not all fields are initialized yet.

Rearrange initialization sequence in ->probe() to prepare everything before use.

---
 drivers/platform/x86/intel_scu_ipc.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/platform/x86/intel_scu_ipc.c +8 -6
index d789fe1baf17..8a34c1e7536f 100644
@@ -582,7 +582,6 @@ static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (!pdata)
 		return -ENODEV;
 
-	scu->dev = &pdev->dev;
 	scu->irq_mode = pdata->irq_mode;
 
 	err = pcim_enable_device(pdev);
@@ -595,17 +594,20 @@ static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	init_completion(&scu->cmd_complete);
 
-	err = devm_request_irq(&pdev->dev, pdev->irq, ioc, 0, "intel_scu_ipc",
-			       scu);
-	if (err)
-		return err;
-
 	scu->ipc_base = pcim_iomap_table(pdev)[0];
 
 	scu->i2c_base = ioremap_nocache(pdata->i2c_base, pdata->i2c_len);
 	if (!scu->i2c_base)
 		return -ENOMEM;
 
+	err = devm_request_irq(&pdev->dev, pdev->irq, ioc, 0, "intel_scu_ipc",
+			       scu);
+	if (err)
+		return err;
+
+	/* Assign device at last */
+	scu->dev = &pdev->dev;
+
 	intel_scu_devices_create();
 
 	pci_set_drvdata(pdev, scu);
Signature · 1 line
2.11.0
#2 lore raw

PATCH 3/5 platform/x86: intel_scu_ipc: Remove redundant subarch check

In reply to Andy Shevchenko

The driver is bound to the devices based on their PCI IDs.

There is no need to do an additional check.

---
 drivers/platform/x86/intel_scu_ipc.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/platform/x86/intel_scu_ipc.c +0 -5
index 8a34c1e7536f..6d626a8878c7 100644
@@ -566,15 +566,10 @@ static irqreturn_t ioc(int irq, void *dev_id)
  */
 static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
-	int platform;		/* Platform type */
 	int err;
 	struct intel_scu_ipc_dev *scu = &ipcdev;
 	struct intel_scu_ipc_pdata_t *pdata;
 
-	platform = intel_mid_identify_cpu();
-	if (platform == 0)
-		return -ENODEV;
-
 	if (scu->dev)		/* We support only one SCU */
 		return -EBUSY;
 
Signature · 1 line
2.11.0
#3 lore raw

PATCH 4/5 platform/x86: intel_scu_ipc: Introduce SCU_DEVICE() macro

In reply to Andy Shevchenko

For better maintainability and readability introduce a macro for device ID table.

No functional change intended.

---
 drivers/platform/x86/intel_scu_ipc.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/platform/x86/intel_scu_ipc.c +7 -15
index 6d626a8878c7..f9d3eb505a0b 100644
@@ -609,22 +609,14 @@ static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	return 0;
 }
 
+#define SCU_DEVICE(id, pdata)	{PCI_VDEVICE(INTEL, id), (kernel_ulong_t)&pdata}
+
 static const struct pci_device_id pci_ids[] = {
-	{
-		PCI_VDEVICE(INTEL, PCI_DEVICE_ID_LINCROFT),
-		(kernel_ulong_t)&intel_scu_ipc_lincroft_pdata,
-	}, {
-		PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PENWELL),
-		(kernel_ulong_t)&intel_scu_ipc_penwell_pdata,
-	}, {
-		PCI_VDEVICE(INTEL, PCI_DEVICE_ID_CLOVERVIEW),
-		(kernel_ulong_t)&intel_scu_ipc_penwell_pdata,
-	}, {
-		PCI_VDEVICE(INTEL, PCI_DEVICE_ID_TANGIER),
-		(kernel_ulong_t)&intel_scu_ipc_tangier_pdata,
-	}, {
-		0,
-	}
+	SCU_DEVICE(PCI_DEVICE_ID_LINCROFT,	intel_scu_ipc_lincroft_pdata),
+	SCU_DEVICE(PCI_DEVICE_ID_PENWELL,	intel_scu_ipc_penwell_pdata),
+	SCU_DEVICE(PCI_DEVICE_ID_CLOVERVIEW,	intel_scu_ipc_penwell_pdata),
+	SCU_DEVICE(PCI_DEVICE_ID_TANGIER,	intel_scu_ipc_tangier_pdata),
+	{}
 };
 
 static struct pci_driver ipc_driver = {
Signature · 1 line
2.11.0
#4 lore raw

PATCH 5/5 platform/x86: intel_scu_ipc: Introduce intel_scu_ipc_raw_command()

In reply to Andy Shevchenko

A new call to SCU intel_scu_ipc_raw_command() writes SPTR and DPTR registers before sending a command.

---
 arch/x86/include/asm/intel_scu_ipc.h |  8 ++++-
 drivers/platform/x86/intel_scu_ipc.c | 63 ++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 1 deletion(-)
arch/x86/include/asm/intel_scu_ipc.h +7 -1
index 4fb1d0abef95..81d3d8776fd9 100644
@@ -3,6 +3,9 @@
 
 #include <linux/notifier.h>
 
+#define IPCMSG_INDIRECT_READ	0x02
+#define IPCMSG_INDIRECT_WRITE	0x05
+
 #define IPCMSG_COLD_OFF		0x80	/* Only for Tangier */
 
 #define IPCMSG_WARM_RESET	0xF0
@@ -45,7 +48,10 @@ 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);
+			  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);
 
drivers/platform/x86/intel_scu_ipc.c +63 -0

69 lines not on this page · raw message

Signature · 1 line
2.11.0