All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] intel_scu_ipc: Utility driver for intel scu ipc
@ 2010-10-22 14:43 Alan Cox
  2010-11-24 16:48 ` Matthew Garrett
  2011-01-03  9:17 ` Thomas Renninger
  0 siblings, 2 replies; 4+ messages in thread
From: Alan Cox @ 2010-10-22 14:43 UTC (permalink / raw)
  To: mjg, platform-driver-x86

From: Sreedhara DS <sreedhara.ds@intel.com>

This driver implements ioctl and interfaces with intel scu ipc driver. It
is used to access pmic/msic registers from user space and firmware update
utility.

Signed-off-by: Sreedhara DS <sreedhara.ds@intel.com>
[Extensive clean up and debug]
Signed-off-by: Alan Cox <alan@linux.intel.com>
---

 drivers/platform/x86/Kconfig             |    9 ++
 drivers/platform/x86/Makefile            |    1 
 drivers/platform/x86/intel_scu_ipc.c     |    4 -
 drivers/platform/x86/intel_scu_ipcutil.c |  133 ++++++++++++++++++++++++++++++
 4 files changed, 145 insertions(+), 2 deletions(-)
 create mode 100644 drivers/platform/x86/intel_scu_ipcutil.c


diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index d2d1510..8bc44c3 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -576,6 +576,15 @@ config INTEL_SCU_IPC
 	  some embedded Intel x86 platforms. This is not needed for PC-type
 	  machines.
 
+config INTEL_SCU_IPC_UTIL
+	tristate "Intel SCU IPC utility driver"
+	depends on INTEL_SCU_IPC
+	default y
+	---help---
+	  The IPC Util driver provides an interface with the SCU enabling
+	  low level access for debug work and updating the firmware. Say
+	  N unless you will be doing this on an Intel MID platform.
+
 config GPIO_INTEL_PMIC
 	bool "Intel PMIC GPIO support"
 	depends on INTEL_SCU_IPC && GPIOLIB
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index c97ac2a..deefa4f 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_TOPSTAR_LAPTOP)	+= topstar-laptop.o
 obj-$(CONFIG_ACPI_TOSHIBA)	+= toshiba_acpi.o
 obj-$(CONFIG_TOSHIBA_BT_RFKILL)	+= toshiba_bluetooth.o
 obj-$(CONFIG_INTEL_SCU_IPC)	+= intel_scu_ipc.o
+obj-$(CONFIG_INTEL_SCU_IPC_UTIL)+= intel_scu_ipcutil.o
 obj-$(CONFIG_RAR_REGISTER)	+= intel_rar_register.o
 obj-$(CONFIG_INTEL_IPS)		+= intel_ips.o
 obj-$(CONFIG_GPIO_INTEL_PMIC)	+= intel_pmic_gpio.o
diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c
index 41a9e34..37128c6 100644
--- a/drivers/platform/x86/intel_scu_ipc.c
+++ b/drivers/platform/x86/intel_scu_ipc.c
@@ -496,7 +496,7 @@ int intel_scu_ipc_i2c_cntrl(u32 addr, u32 *data)
 			"intel_scu_ipc: I2C INVALID_CMD = 0x%x\n", cmd);
 
 		mutex_unlock(&ipclock);
-		return -1;
+		return -EIO;
 	}
 	mutex_unlock(&ipclock);
 	return 0;
@@ -641,7 +641,7 @@ update_end:
 
 	if (status == IPC_FW_UPDATE_SUCCESS)
 		return 0;
-	return -1;
+	return -EIO;
 }
 EXPORT_SYMBOL(intel_scu_ipc_fw_update);
 
diff --git a/drivers/platform/x86/intel_scu_ipcutil.c b/drivers/platform/x86/intel_scu_ipcutil.c
new file mode 100644
index 0000000..ba3231d
--- /dev/null
+++ b/drivers/platform/x86/intel_scu_ipcutil.c
@@ -0,0 +1,133 @@
+/*
+ * intel_scu_ipc.c: Driver for the Intel SCU IPC mechanism
+ *
+ * (C) Copyright 2008-2010 Intel Corporation
+ * Author: Sreedhara DS (sreedhara.ds@intel.com)
+ *
+ * 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.
+ *
+ * This driver provides ioctl interfaces to call intel scu ipc driver api
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/fs.h>
+#include <linux/fcntl.h>
+#include <linux/sched.h>
+#include <linux/uaccess.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <asm/intel_scu_ipc.h>
+
+static u32 major;
+
+#define MAX_FW_SIZE 264192
+
+/* ioctl commnds */
+#define	INTE_SCU_IPC_REGISTER_READ	0
+#define INTE_SCU_IPC_REGISTER_WRITE	1
+#define INTE_SCU_IPC_REGISTER_UPDATE	2
+#define INTE_SCU_IPC_FW_UPDATE		0xA2
+
+struct scu_ipc_data {
+	u32     count;  /* No. of registers */
+	u16     addr[5]; /* Register addresses */
+	u8      data[5]; /* Register data */
+	u8      mask; /* Valid for read-modify-write */
+};
+
+/**
+ *	scu_reg_access		-	implement register access ioctls
+ *	@cmd: command we are doing (read/write/update)
+ *	@data: kernel copy of ioctl data
+ *
+ *	Allow the user to perform register accesses on the SCU via the
+ *	kernel interface
+ */
+
+static int scu_reg_access(u32 cmd, struct scu_ipc_data  *data)
+{
+	int count = data->count;
+
+	if (count == 0 || count == 3 || count > 4)
+		return -EINVAL;
+
+	switch (cmd) {
+	case INTE_SCU_IPC_REGISTER_READ:
+		return intel_scu_ipc_readv(data->addr, data->data, count);
+	case INTE_SCU_IPC_REGISTER_WRITE:
+		return intel_scu_ipc_writev(data->addr, data->data, count);
+	case INTE_SCU_IPC_REGISTER_UPDATE:
+		return intel_scu_ipc_update_register(data->addr[0],
+						    data->data[0], data->mask);
+	default:
+		return -ENOTTY;
+	}
+}
+
+/**
+ *	scu_ipc_ioctl		-	control ioctls for the SCU
+ *	@fp: file handle of the SCU device
+ *	@cmd: ioctl coce
+ *	@arg: pointer to user passed structure
+ *
+ *	Support the I/O and firmware flashing interfaces of the SCU
+ */
+static long scu_ipc_ioctl(struct file *fp, unsigned int cmd,
+							unsigned long arg)
+{
+	int ret;
+	struct scu_ipc_data  data;
+	void __user *argp = (void __user *)arg;
+
+	if (!capable(CAP_SYS_RAWIO))
+		return -EPERM;
+
+	if (cmd == INTE_SCU_IPC_FW_UPDATE) {
+			u8 *fwbuf = kmalloc(MAX_FW_SIZE, GFP_KERNEL);
+			if (fwbuf == NULL)
+				return -ENOMEM;
+			if (copy_from_user(fwbuf, (u8 *)arg, MAX_FW_SIZE)) {
+				kfree(fwbuf);
+				return -EFAULT;
+			}
+			ret = intel_scu_ipc_fw_update(fwbuf, MAX_FW_SIZE);
+			kfree(fwbuf);
+			return ret;
+	} else {
+		if (copy_from_user(&data, argp, sizeof(struct scu_ipc_data)))
+			return -EFAULT;
+		ret = scu_reg_access(cmd, &data);
+		if (ret < 0)
+			return ret;
+		if (copy_to_user(argp, &data, sizeof(struct scu_ipc_data)))
+			return -EFAULT;
+		return 0;
+	}
+}
+
+static const struct file_operations scu_ipc_fops = {
+	.unlocked_ioctl = scu_ipc_ioctl,
+};
+
+static int __init ipc_module_init(void)
+{
+	return register_chrdev(0, "intel_mid_scu", &scu_ipc_fops);
+}
+
+static void __exit ipc_module_exit(void)
+{
+	unregister_chrdev(major, "intel_mid_scu");
+}
+
+module_init(ipc_module_init);
+module_exit(ipc_module_exit);
+
+MODULE_LICENSE("GPL V2");
+MODULE_DESCRIPTION("Utility driver for intel scu ipc");
+MODULE_AUTHOR("Sreedhara <sreedhara.ds@intel.com>");

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] intel_scu_ipc: Utility driver for intel scu ipc
  2010-10-22 14:43 [PATCH] intel_scu_ipc: Utility driver for intel scu ipc Alan Cox
@ 2010-11-24 16:48 ` Matthew Garrett
  2011-01-03  9:17 ` Thomas Renninger
  1 sibling, 0 replies; 4+ messages in thread
From: Matthew Garrett @ 2010-11-24 16:48 UTC (permalink / raw)
  To: Alan Cox; +Cc: platform-driver-x86

Applied to -next, thanks.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] intel_scu_ipc: Utility driver for intel scu ipc
  2010-10-22 14:43 [PATCH] intel_scu_ipc: Utility driver for intel scu ipc Alan Cox
  2010-11-24 16:48 ` Matthew Garrett
@ 2011-01-03  9:17 ` Thomas Renninger
  2011-01-03 10:42   ` Alan Cox
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Renninger @ 2011-01-03  9:17 UTC (permalink / raw)
  To: Alan Cox; +Cc: mjg, platform-driver-x86, sreedhara.ds

Hi,

seen this a bit late..., one question:

On Friday 22 October 2010 16:43:55 Alan Cox wrote:
> From: Sreedhara DS <sreedhara.ds@intel.com>
> 
> This driver implements ioctl and interfaces with intel scu ipc driver. It
> is used to access pmic/msic registers from user space and firmware update
> utility.
Why is an ioctl used for updating the firmware?
Why isn't request_firmware(..) via:
/lib/firmware/...
used?
Then the firmware could be maintained here:
http://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git;a=summary
and no further userspace tools for firmware updating are needed.

Thanks,

   Thomas
> 
> Signed-off-by: Sreedhara DS <sreedhara.ds@intel.com>
> [Extensive clean up and debug]
> Signed-off-by: Alan Cox <alan@linux.intel.com>
...
> +/**
> + *	scu_ipc_ioctl		-	control ioctls for the SCU
> + *	@fp: file handle of the SCU device
> + *	@cmd: ioctl coce
> + *	@arg: pointer to user passed structure
> + *
> + *	Support the I/O and firmware flashing interfaces of the SCU
> + */
> +static long scu_ipc_ioctl(struct file *fp, unsigned int cmd,
> +							unsigned long arg)
> +{
> +	int ret;
> +	struct scu_ipc_data  data;
> +	void __user *argp = (void __user *)arg;
> +
> +	if (!capable(CAP_SYS_RAWIO))
> +		return -EPERM;
> +
> +	if (cmd == INTE_SCU_IPC_FW_UPDATE) {
> +			u8 *fwbuf = kmalloc(MAX_FW_SIZE, GFP_KERNEL);
> +			if (fwbuf == NULL)
> +				return -ENOMEM;
> +			if (copy_from_user(fwbuf, (u8 *)arg, MAX_FW_SIZE)) {
> +				kfree(fwbuf);
> +				return -EFAULT;
> +			}
> +			ret = intel_scu_ipc_fw_update(fwbuf, MAX_FW_SIZE);
> +			kfree(fwbuf);
> +			return ret;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] intel_scu_ipc: Utility driver for intel scu ipc
  2011-01-03  9:17 ` Thomas Renninger
@ 2011-01-03 10:42   ` Alan Cox
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Cox @ 2011-01-03 10:42 UTC (permalink / raw)
  To: Thomas Renninger; +Cc: mjg, platform-driver-x86, sreedhara.ds

> > This driver implements ioctl and interfaces with intel scu ipc driver. It
> > is used to access pmic/msic registers from user space and firmware update
> > utility.
> Why is an ioctl used for updating the firmware?
> Why isn't request_firmware(..) via:
> /lib/firmware/...
> used?

Because you would then still need an ioctl to say "go do the upload"

This firmware is flashed into the device, it isn't loaded into memory and
then used by the device. It's not the kind of thing you want to get wrong
or automate behind someone's back.

Alan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-01-03 10:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-22 14:43 [PATCH] intel_scu_ipc: Utility driver for intel scu ipc Alan Cox
2010-11-24 16:48 ` Matthew Garrett
2011-01-03  9:17 ` Thomas Renninger
2011-01-03 10:42   ` Alan Cox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.