>From 17bf0a5815a076b4778f2211cdb34cac0e4a66e0 Mon Sep 17 00:00:00 2001
From: Ken Mills <[email protected]>
Date: Mon, 18 Oct 2010 18:21:34 -0700
Subject: [PATCH 1/4] Add console device to capture kernel printk() messages.

Signed-off-by: Ken Mills <[email protected]>
---
 drivers/misc/pti.c |   92 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 87 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index f1b5e4b..174a87d 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -28,6 +28,7 @@
  */
 
 #include <linux/init.h>
+#include <linux/console.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/tty.h>
@@ -43,6 +44,7 @@
 #define CHARNAME                       "pti"
 #define MAX_APP_IDS                    256
 #define MAX_OS_IDS                     128
+#define CONSOLE_ID                     73   /* console master ID address */
 #define OS_BASE_ID                     72   /* base OS master ID address */
 #define APP_BASE_ID                    80   /* base App master ID address */
 
@@ -72,6 +74,7 @@ static struct tty_driver *pti_tty_driver;
 
 static struct pti_dev *drv_data;
 
+static unsigned int pti_console_channel;
 
 #define DTS 0x30               /* offset for last dword of a PTI message */
 
@@ -301,9 +304,6 @@ void mipi_pti_writedata(struct masterchannel *mc, u8 *buf, 
int count)
 }
 EXPORT_SYMBOL(mipi_pti_writedata);
 
-static const struct tty_port_operations tty_port_ops = {
-};
-
 static void __devexit pti_pci_remove(struct pci_dev *pdev)
 {
        struct pti_dev *drv_data;
@@ -542,7 +542,7 @@ ssize_t pti_char_write(struct file *filp, const char *data, 
size_t len,
        return len;
 }
 
-const struct tty_operations pti_tty_driver_ops = {
+static const struct tty_operations pti_tty_driver_ops = {
        .open           = pti_tty_driver_open,
        .close          = pti_tty_driver_close,
        .write          = pti_tty_driver_write,
@@ -551,7 +551,7 @@ const struct tty_operations pti_tty_driver_ops = {
        .cleanup        = pti_tty_cleanup
 };
 
-const struct file_operations pti_char_driver_ops = {
+static const struct file_operations pti_char_driver_ops = {
        .owner          = THIS_MODULE,
        .open           = pti_char_open,
        .release        = pti_char_release,
@@ -564,6 +564,86 @@ static struct miscdevice pti_char_driver = {
        .fops           = &pti_char_driver_ops
 };
 
+static void pti_console_write(struct console *c, const char *buf, unsigned len)
+{
+       static struct masterchannel mc = {.master = CONSOLE_ID, .channel = 0};
+
+       mc.channel = pti_console_channel;
+       pti_console_channel = (pti_console_channel + 1) & 0x7f;
+
+       pti_write_to_aperture(&mc, (u8 *)buf, len);
+}
+
+static struct tty_driver *pti_console_device(struct console *c, int *index)
+{
+       *index = c->index;
+       return pti_tty_driver;
+}
+
+static int pti_console_setup(struct console *c, char *opts)
+{
+       pti_console_channel = 0;
+       return 0;
+}
+
+/* pti_console struct, used to capture OS printk()'s and shift
+ * out to the PTI device for debugging.  This cannot be
+ * enabled upon boot because of the possibility of eating
+ * any serial console printk's (race condition discovered).
+ * The console should be enabled upon when the tty port is
+ * used for the first time.  Since the primary purpose for
+ * the tty port is to hook up syslog to it, the tty port
+ * will be open for a really long time.
+ */
+static struct console pti_console = {
+       .name           = TTYNAME,
+       .write          = pti_console_write,
+       .device         = pti_console_device,
+       .setup          = pti_console_setup,
+       .flags          = CON_PRINTBUFFER | CON_BOOT,
+       .index          = 0,
+};
+
+/**
+ * pti_port_activate(): Used to start/initialize any items upon
+ * first opening of tty_port().
+ *
+ * @param port
+ * @param tty
+ *
+ * @return int - Always returns 0.
+ *
+ * Notes: The primary purpose of the PTI tty port is to hook the
+ * syslog daemon to it; thus this port will be open for a very
+ * long time.
+ */
+int pti_port_activate(struct tty_port *port, struct tty_struct *tty)
+{
+       pr_debug("%s(%d): Called.\n", __func__, __LINE__);
+       console_start(&pti_console);
+       return 0;
+}
+
+/**
+ * pti_port_shutdown(): Used to stop/shutdown any items upon the
+ * last tty port close.
+ *
+ * @param port
+ *
+ * Notes: The primary purpose of the PTI tty port is to hook the
+ * syslog daemon to it; thus this port will be open for a very
+ * long time.
+ */
+void pti_port_shutdown(struct tty_port *port)
+{
+       pr_debug("%s(%d): Called.\n", __func__, __LINE__);
+       console_stop(&pti_console);
+}
+
+static const struct tty_port_operations tty_port_ops = {
+       .activate = pti_port_activate,
+       .shutdown = pti_port_shutdown,
+};
 /*
    Note the _probe() call sets everything up and ties the char and tty
    to successfully detecting the PTI device on the pci bus.
@@ -624,6 +704,8 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev,
 
        tty_register_device(pti_tty_driver, 0, NULL);
 
+       register_console(&pti_console);
+
        retval = misc_register(&pti_char_driver);
        if (retval) {
                pr_err("%s(%d): CHAR registration failed of pti driver\n",
-- 
1.7.0.4
From 17bf0a5815a076b4778f2211cdb34cac0e4a66e0 Mon Sep 17 00:00:00 2001
From: Ken Mills <[email protected]>
Date: Mon, 18 Oct 2010 18:21:34 -0700
Subject: [PATCH 1/4] Add console device to capture kernel printk() messages.

Signed-off-by: Ken Mills <[email protected]>
---
 drivers/misc/pti.c |   92 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 87 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index f1b5e4b..174a87d 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -28,6 +28,7 @@
  */
 
 #include <linux/init.h>
+#include <linux/console.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/tty.h>
@@ -43,6 +44,7 @@
 #define CHARNAME			"pti"
 #define MAX_APP_IDS			256
 #define MAX_OS_IDS			128
+#define CONSOLE_ID			73   /* console master ID address */
 #define OS_BASE_ID			72   /* base OS master ID address */
 #define APP_BASE_ID			80   /* base App master ID address */
 
@@ -72,6 +74,7 @@ static struct tty_driver *pti_tty_driver;
 
 static struct pti_dev *drv_data;
 
+static unsigned int pti_console_channel;
 
 #define DTS 0x30		/* offset for last dword of a PTI message */
 
@@ -301,9 +304,6 @@ void mipi_pti_writedata(struct masterchannel *mc, u8 *buf, int count)
 }
 EXPORT_SYMBOL(mipi_pti_writedata);
 
-static const struct tty_port_operations tty_port_ops = {
-};
-
 static void __devexit pti_pci_remove(struct pci_dev *pdev)
 {
 	struct pti_dev *drv_data;
@@ -542,7 +542,7 @@ ssize_t pti_char_write(struct file *filp, const char *data, size_t len,
 	return len;
 }
 
-const struct tty_operations pti_tty_driver_ops = {
+static const struct tty_operations pti_tty_driver_ops = {
 	.open		= pti_tty_driver_open,
 	.close		= pti_tty_driver_close,
 	.write		= pti_tty_driver_write,
@@ -551,7 +551,7 @@ const struct tty_operations pti_tty_driver_ops = {
 	.cleanup	= pti_tty_cleanup
 };
 
-const struct file_operations pti_char_driver_ops = {
+static const struct file_operations pti_char_driver_ops = {
 	.owner		= THIS_MODULE,
 	.open		= pti_char_open,
 	.release	= pti_char_release,
@@ -564,6 +564,86 @@ static struct miscdevice pti_char_driver = {
 	.fops		= &pti_char_driver_ops
 };
 
+static void pti_console_write(struct console *c, const char *buf, unsigned len)
+{
+	static struct masterchannel mc = {.master = CONSOLE_ID, .channel = 0};
+
+	mc.channel = pti_console_channel;
+	pti_console_channel = (pti_console_channel + 1) & 0x7f;
+
+	pti_write_to_aperture(&mc, (u8 *)buf, len);
+}
+
+static struct tty_driver *pti_console_device(struct console *c, int *index)
+{
+	*index = c->index;
+	return pti_tty_driver;
+}
+
+static int pti_console_setup(struct console *c, char *opts)
+{
+	pti_console_channel = 0;
+	return 0;
+}
+
+/* pti_console struct, used to capture OS printk()'s and shift
+ * out to the PTI device for debugging.  This cannot be
+ * enabled upon boot because of the possibility of eating
+ * any serial console printk's (race condition discovered).
+ * The console should be enabled upon when the tty port is
+ * used for the first time.  Since the primary purpose for
+ * the tty port is to hook up syslog to it, the tty port
+ * will be open for a really long time.
+ */
+static struct console pti_console = {
+	.name		= TTYNAME,
+	.write		= pti_console_write,
+	.device		= pti_console_device,
+	.setup		= pti_console_setup,
+	.flags		= CON_PRINTBUFFER | CON_BOOT,
+	.index		= 0,
+};
+
+/**
+ * pti_port_activate(): Used to start/initialize any items upon
+ * first opening of tty_port().
+ *
+ * @param port
+ * @param tty
+ *
+ * @return int - Always returns 0.
+ *
+ * Notes: The primary purpose of the PTI tty port is to hook the
+ * syslog daemon to it; thus this port will be open for a very
+ * long time.
+ */
+int pti_port_activate(struct tty_port *port, struct tty_struct *tty)
+{
+	pr_debug("%s(%d): Called.\n", __func__, __LINE__);
+	console_start(&pti_console);
+	return 0;
+}
+
+/**
+ * pti_port_shutdown(): Used to stop/shutdown any items upon the
+ * last tty port close.
+ *
+ * @param port
+ *
+ * Notes: The primary purpose of the PTI tty port is to hook the
+ * syslog daemon to it; thus this port will be open for a very
+ * long time.
+ */
+void pti_port_shutdown(struct tty_port *port)
+{
+	pr_debug("%s(%d): Called.\n", __func__, __LINE__);
+	console_stop(&pti_console);
+}
+
+static const struct tty_port_operations tty_port_ops = {
+	.activate = pti_port_activate,
+	.shutdown = pti_port_shutdown,
+};
 /*
    Note the _probe() call sets everything up and ties the char and tty
    to successfully detecting the PTI device on the pci bus.
@@ -624,6 +704,8 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev,
 
 	tty_register_device(pti_tty_driver, 0, NULL);
 
+	register_console(&pti_console);
+
 	retval = misc_register(&pti_char_driver);
 	if (retval) {
 		pr_err("%s(%d): CHAR registration failed of pti driver\n",
-- 
1.7.0.4

_______________________________________________
Meego-kernel mailing list
[email protected]
http://lists.meego.com/listinfo/meego-kernel

Reply via email to