[PATCH linux v1 2/3] drivers: misc: Character driver to update BMC post code

Jaghathiswari Rankappagounder Natarajan jaghu at google.com
Thu Oct 13 11:41:44 AEDT 2016


Character driver - On state change, the BMC will write its POST code to the
character device. The POST code is then sent to update-postcard platform
driver for display on the POST card. The BMC POST code consists of 3 digits

Signed-off-by: Jaghathiswari Rankappagounder Natarajan <jaghu at google.com>
---
 drivers/misc/Kconfig               |   8 +++
 drivers/misc/Makefile              |   1 +
 drivers/misc/update-bmc-postcode.c | 123 +++++++++++++++++++++++++++++++++++++
 3 files changed, 132 insertions(+)
 create mode 100644 drivers/misc/update-bmc-postcode.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index d65b83f..69dc3b6 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -815,6 +815,14 @@ config ASPEED_BT_IPMI_HOST
 	help
 	  Support for the Aspeed BT ipmi host.

+config ASPEED_UPDATE_BMC_POSTCODE
+	tristate "Character driver for BMC POST code update"
+	depends on ASPEED_UPDATE_POSTCARD
+	help
+	 On state change, the BMC will write its POST code to the
+	 character device. The POST code is then sent to update-postcard platform
+	 driver for display on the POST card
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 730c6c2..dce20cb 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -59,3 +59,4 @@ obj-$(CONFIG_CXL_BASE)		+= cxl/
 obj-$(CONFIG_PANEL)             += panel.o
 obj-$(CONFIG_ASPEED_UPDATE_POSTCARD)    += update-postcard.o
 obj-$(CONFIG_ASPEED_BT_IPMI_HOST)	+= bt-host.o
+obj-$(CONFIG_ASPEED_UPDATE_BMC_POSTCODE)	+= update-bmc-postcode.o
diff --git a/drivers/misc/update-bmc-postcode.c b/drivers/misc/update-bmc-postcode.c
new file mode 100644
index 0000000..8e368a4
--- /dev/null
+++ b/drivers/misc/update-bmc-postcode.c
@@ -0,0 +1,123 @@
+/*
+ * Character driver - On state change, the BMC will write its POST code to the
+ * character device. The POST code is then sent to update-postcard platform
+ * driver for display on the POST card. The BMC POST code consists of 3 digits.
+ */
+
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/kdev_t.h>
+#include <linux/fs.h>
+#include <linux/device.h>
+#include <linux/cdev.h>
+#include <linux/uaccess.h>
+#include <linux/ctype.h>
+
+#include "update-postcard.h"
+
+#define MAX_POSTCODE_SIZE 3
+
+static dev_t bmc_state_dev;
+static struct cdev c_dev;
+static struct class *bmc_state_class;
+
+static int bmc_state_open(struct inode *i, struct file *f)
+{
+	return 0;
+}
+
+static int bmc_state_close(struct inode *i, struct file *f)
+{
+	return 0;
+}
+
+static ssize_t bmc_state_read(struct file *f, char __user *buf, size_t
+				len, loff_t *off)
+{
+	return 0;
+}
+
+/* Write post code from bmc to the correct variable */
+static ssize_t bmc_state_write(struct file *f, const char __user *buf,
+				size_t len, loff_t *off)
+{
+	char tmp[MAX_POSTCODE_SIZE];
+	int length = len - 1;
+	int i;
+
+	if (length != MAX_POSTCODE_SIZE) {
+		return -EINVAL;
+	}
+
+	if (copy_from_user(tmp, buf, length) != 0) {
+		return -EFAULT;
+	}
+
+	for (i = 0; i < MAX_POSTCODE_SIZE; i++) {
+		if (!isxdigit(tmp[i]))
+			return -EINVAL;
+	}
+
+	update_postcode(tmp);
+	return len;
+}
+
+static const struct file_operations bmc_state_fops = {
+
+	.owner = THIS_MODULE,
+	.open = bmc_state_open,
+	.release = bmc_state_close,
+	.read = bmc_state_read,
+	.write = bmc_state_write
+};
+
+static int __init update_bmc_pc_init(void)
+{
+	if (alloc_chrdev_region(&bmc_state_dev, 0, 1, "bmc_state") < 0) {
+		return -1;
+	}
+
+	bmc_state_class = class_create(THIS_MODULE, "bmc_state");
+	if (bmc_state_class == NULL) {
+		goto unregister;
+		return -1;
+	}
+
+	if (device_create(bmc_state_class, NULL, bmc_state_dev,
+		NULL, "current_state") == NULL) {
+		goto class_destroy;
+		return -1;
+	}
+
+	cdev_init(&c_dev, &bmc_state_fops);
+	if (cdev_add(&c_dev, bmc_state_dev, 1) == -1) {
+		goto device_destroy;
+		return -1;
+	}
+
+	return 0;
+
+device_destroy:
+		device_destroy(bmc_state_class, bmc_state_dev);
+class_destroy:
+		class_destroy(bmc_state_class);
+unregister:
+		unregister_chrdev_region(bmc_state_dev, 1);
+	return -1;
+}
+
+static void __exit update_bmc_pc_exit(void)
+{
+	cdev_del(&c_dev);
+	device_destroy(bmc_state_class, bmc_state_dev);
+	class_destroy(bmc_state_class);
+	unregister_chrdev_region(bmc_state_dev, 1);
+}
+
+module_init(update_bmc_pc_init);
+module_exit(update_bmc_pc_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <jaghu at google.com>");
+MODULE_DESCRIPTION("Character driver - update bmc postcode");
--
2.8.0.rc3.226.g39d4020



More information about the openbmc mailing list