[PATCH 04/10] staging: unisys: move installer to sysfs and split fields

Benjamin Romer benjamin.romer at unisys.com
Tue Jul 15 17:30:44 UTC 2014


The installer entry in /proc/visorchipset/installer was composed of three
separate fields as one entry. This patch removes the proc entry and associated
functions, and creates new fields with distinct entries under sysfs in the
visorchipset/install directory. The fields are:

	textid: used to send the ID of a string that should be displayed on
		s-Par's automatic installation progress screen. Setting this
		field when not in installation mode (boottotool was set on
		the previous guest boot) has no effect.

	remaining_steps: used to set the value of the progress bar on the
		s-Par automatic installation progress screen. This field has
		no effect if not in installation mode.

	error: used to send the ID of a string that should be displayed on
		s-Par's automatic installation progress screen when an error
		is encountered during installation. This field has no effect
		if not in installation mode.

s-Par's automatic Linux installation software uses these fields to communicate
progress with the system management partition.

Signed-off-by: Benjamin Romer <benjamin.romer at unisys.com>
---
 .../unisys/visorchipset/visorchipset_main.c        | 267 +++++++++++----------
 1 file changed, 134 insertions(+), 133 deletions(-)

diff --git a/drivers/staging/unisys/visorchipset/visorchipset_main.c b/drivers/staging/unisys/visorchipset/visorchipset_main.c
index 04d6349..d4987b1 100644
--- a/drivers/staging/unisys/visorchipset/visorchipset_main.c
+++ b/drivers/staging/unisys/visorchipset/visorchipset_main.c
@@ -145,16 +145,6 @@ static VISORCHANNEL *ControlVm_channel;
 static ssize_t visorchipset_proc_read_writeonly(struct file *file,
 						char __user *buf,
 						size_t len, loff_t *offset);
-static ssize_t proc_read_installer(struct file *file, char __user *buf,
-				   size_t len, loff_t *offset);
-static ssize_t proc_write_installer(struct file *file,
-				    const char __user *buffer,
-				    size_t count, loff_t *ppos);
-
-static const struct file_operations proc_installer_fops = {
-	.read = proc_read_installer,
-	.write = proc_write_installer,
-};
 
 typedef struct {
 	U8 __iomem *ptr;	/* pointer to base address of payload pool */
@@ -316,15 +306,43 @@ static ssize_t show_boottotool(struct device *dev,
 static ssize_t store_boottotool(struct device *dev,
 	struct device_attribute *attr, const char *buf, size_t count);
 
+static ssize_t show_error(struct device *dev, struct device_attribute *attr,
+	char *buf);
+
+static ssize_t store_error(struct device *dev, struct device_attribute *attr,
+	const char *buf, size_t count);
+
+static ssize_t show_textid(struct device *dev, struct device_attribute *attr,
+	char *buf);
+
+static ssize_t store_textid(struct device *dev,	struct device_attribute *attr,
+	const char *buf, size_t count);
+
+static ssize_t show_remaining_steps(struct device *dev,
+	struct device_attribute *attr, char *buf);
+
+static ssize_t store_remaining_steps(struct device *dev,
+	struct device_attribute *attr, const char *buf, size_t count);
+
 static DEVICE_ATTR(toolaction, S_IRUSR | S_IWUSR, show_toolaction,
 	store_toolaction);
 
 static DEVICE_ATTR(boottotool, S_IRUSR | S_IWUSR, show_boottotool,
 	store_boottotool);
 
+static DEVICE_ATTR(error, S_IRUSR | S_IWUSR, show_error, store_error);
+
+static DEVICE_ATTR(textid, S_IRUSR | S_IWUSR, show_textid, store_textid);
+
+static DEVICE_ATTR(remaining_steps, S_IRUSR | S_IWUSR, show_remaining_steps,
+	store_remaining_steps);
+
 static struct attribute *visorchipset_install_attrs[] = {
 	&dev_attr_toolaction.attr,
 	&dev_attr_boottotool.attr,
+	&dev_attr_error.attr,
+	&dev_attr_textid.attr,
+	&dev_attr_remaining_steps.attr,
 	NULL
 };
 
@@ -428,6 +446,112 @@ ssize_t store_boottotool(struct device *dev, struct device_attribute *attr,
 		return -ENODEV;
 	}
 }
+
+ssize_t show_error(struct device *dev, struct device_attribute *attr,
+		char *buf)
+{
+	U32 error;
+
+	if (ControlVm_channel) {
+		visorchannel_read(ControlVm_channel, offsetof(
+			ULTRA_CONTROLVM_CHANNEL_PROTOCOL, InstallationError),
+			&error, sizeof(U32));
+		return scnprintf(buf, PAGE_SIZE, "%i\n", error);
+	} else {
+		return -ENODEV;
+	}
+}
+
+ssize_t store_error(struct device *dev, struct device_attribute *attr,
+		const char *buf, size_t count)
+{
+	U32 error;
+
+	if (ControlVm_channel) {
+		if (sscanf(buf, "%i\n", &error) == 1) {
+			if (visorchannel_write(ControlVm_channel,
+				offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL,
+					InstallationError),
+				&error, sizeof(U32)) == 1) {
+					return count;
+			}
+		}
+		return -EIO;
+	} else
+		return -ENODEV;
+}
+
+ssize_t show_textid(struct device *dev, struct device_attribute *attr,
+		char *buf)
+{
+	U32 textId;
+
+	if (ControlVm_channel) {
+		visorchannel_read(ControlVm_channel, offsetof(
+			ULTRA_CONTROLVM_CHANNEL_PROTOCOL, InstallationTextId),
+			&textId, sizeof(U32));
+		return scnprintf(buf, PAGE_SIZE, "%i\n", textId);
+	} else {
+		return -ENODEV;
+	}
+}
+
+ssize_t store_textid(struct device *dev, struct device_attribute *attr,
+		const char *buf, size_t count)
+{
+	U32 textId;
+
+	if (ControlVm_channel) {
+		if (sscanf(buf, "%i\n", &textId) == 1) {
+			if (visorchannel_write(ControlVm_channel,
+				offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL,
+					InstallationTextId),
+				&textId, sizeof(U32)) == 1) {
+					return count;
+			}
+		}
+		return -EIO;
+	} else
+		return -ENODEV;
+}
+
+
+ssize_t show_remaining_steps(struct device *dev, struct device_attribute *attr,
+		char *buf)
+{
+	U16 remainingSteps;
+
+	if (ControlVm_channel) {
+		visorchannel_read(ControlVm_channel,
+			offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL,
+				InstallationRemainingSteps),
+			&remainingSteps,
+			sizeof(U16));
+		return scnprintf(buf, PAGE_SIZE, "%hu\n", remainingSteps);
+	} else {
+		return -ENODEV;
+	}
+}
+
+ssize_t store_remaining_steps(struct device *dev, struct device_attribute *attr,
+		const char *buf, size_t count)
+{
+	U16 remainingSteps;
+
+	if (ControlVm_channel) {
+		if (sscanf(buf, "%hu\n", &remainingSteps) == 1) {
+			if (visorchannel_write(ControlVm_channel,
+				offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL,
+					InstallationRemainingSteps),
+				&remainingSteps, sizeof(U16)) == 1) {
+					return count;
+			}
+		}
+		return -EIO;
+	} else
+		return -ENODEV;
+}
+
 static void
 show_partition_property(struct seq_file *f, void *ctx, int property)
 {
@@ -2395,124 +2519,6 @@ visorchipset_proc_read_writeonly(struct file *file, char __user *buf,
 	return 0;
 }
 
-/**
- * Reads the InstallationError, InstallationTextId,
- * InstallationRemainingSteps fields of ControlVMChannel.
- */
-static ssize_t
-proc_read_installer(struct file *file, char __user *buf,
-		    size_t len, loff_t *offset)
-{
-	int length = 0;
-	U16 remainingSteps;
-	U32 error, textId;
-	char *vbuf;
-	loff_t pos = *offset;
-
-	if (!ControlVm_channel)
-		return -ENODEV;
-
-	if (pos < 0)
-		return -EINVAL;
-
-	if (pos > 0 || !len)
-		return 0;
-
-	vbuf = kzalloc(len, GFP_KERNEL);
-	if (!vbuf)
-		return -ENOMEM;
-
-	visorchannel_read(ControlVm_channel,
-			  offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL,
-				   InstallationRemainingSteps), &remainingSteps,
-			  sizeof(U16));
-	visorchannel_read(ControlVm_channel,
-			  offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL,
-				   InstallationError), &error, sizeof(U32));
-	visorchannel_read(ControlVm_channel,
-			  offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL,
-				   InstallationTextId), &textId, sizeof(U32));
-
-	length = sprintf(vbuf, "%u %u %u\n", remainingSteps, error, textId);
-	if (copy_to_user(buf, vbuf, length)) {
-		kfree(vbuf);
-		return -EFAULT;
-	}
-
-	kfree(vbuf);
-	*offset += length;
-	return length;
-}
-
-/**
- * Writes to the InstallationError, InstallationTextId,
- * InstallationRemainingSteps fields of
- * ControlVMChannel.
- * Input: RemainingSteps Error TextId
- * Limit 32 characters input
- */
-#define UINT16_MAX		(65535U)
-#define UINT32_MAX		(4294967295U)
-static ssize_t
-proc_write_installer(struct file *file,
-		     const char __user *buffer, size_t count, loff_t *ppos)
-{
-	char buf[32];
-	U16 remainingSteps;
-	U32 error, textId;
-
-	if (!ControlVm_channel)
-		return -ENODEV;
-
-	/* Check to make sure there is no buffer overflow */
-	if (count > (sizeof(buf) - 1))
-		return -EINVAL;
-
-	if (copy_from_user(buf, buffer, count)) {
-		WARN(1, "Error copying from user space\n");
-		return -EFAULT;
-	}
-
-	if (sscanf(buf, "%hu %i %i", &remainingSteps, &error, &textId) != 3) {
-		remainingSteps = UINT16_MAX;
-		error = UINT32_MAX;
-		textId = UINT32_MAX;
-	}
-
-	if (remainingSteps != UINT16_MAX) {
-		if (visorchannel_write
-		    (ControlVm_channel,
-		     offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL,
-			      InstallationRemainingSteps), &remainingSteps,
-		     sizeof(U16)) < 0)
-			WARN(1, "Installation Status Write Failed - Write function error - RemainingSteps = %d\n",
-			     remainingSteps);
-	}
-
-	if (error != UINT32_MAX) {
-		if (visorchannel_write
-		    (ControlVm_channel,
-		     offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL,
-			      InstallationError), &error, sizeof(U32)) < 0)
-			WARN(1, "Installation Status Write Failed - Write function error - Error = %d\n",
-			     error);
-	}
-
-	if (textId != UINT32_MAX) {
-		if (visorchannel_write
-		    (ControlVm_channel,
-		     offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL,
-			      InstallationTextId), &textId, sizeof(U32)) < 0)
-			WARN(1, "Installation Status Write Failed - Write function error - TextId = %d\n",
-			     textId);
-	}
-
-	/* So this function isn't called multiple times, must return
-	 * size of buffer
-	 */
-	return count;
-}
-
 static const struct file_operations chipset_proc_fops = {
 	.owner = THIS_MODULE,
 	.read = visorchipset_proc_read_writeonly,
@@ -2523,7 +2529,6 @@ static int __init
 visorchipset_init(void)
 {
 	int rc = 0, x = 0;
-	struct proc_dir_entry *installer_file;
 
 	if (!unisys_spar_platform)
 		return -ENODEV;
@@ -2573,10 +2578,6 @@ visorchipset_init(void)
 					      PartitionPropertyNames,
 					      &show_partition_property);
 
-	/* Setup Installation fields */
-	installer_file = proc_create("installer", 0644, ProcDir,
-				     &proc_installer_fops);
-
 	memset(&g_DiagMsgHdr, 0, sizeof(CONTROLVM_MESSAGE_HEADER));
 
 	chipset_proc_dir = proc_create(VISORCHIPSET_CHIPSET_PROC_ENTRY_FN,
-- 
1.9.1



More information about the devel mailing list