LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Resend: Request for review and addition of PTI implementation into kernel
       [not found] <james_p_freyensee@linux.intel.com>
@ 2011-02-08 19:34 ` james_p_freyensee
  2011-02-08 19:34   ` [PATCH 01/12] export kernel call get_task_comm() james_p_freyensee
  2011-02-09  0:17 ` [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
                   ` (40 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

I apologize if this winds up being a duplicate; I believe yesterday's email 
attempt never made it out completely.

This is a request for review and acceptance into the mainline kernel
for the Intel-Atom implementation of the MIPI P1149.7 compact JTAG
standard for mobile devices.  Complete documentation and background
has been provided in PATCH 02/12, "Kernel documentation for the PTI
feature".  PATCH 01/12 is a kernel fix to allow the PTI driver
to compile modularly; this is a fix Greg KH, Alan Cox, and Arjan
van de Ven and I talked about a while ago.  It's not techincally
related to PTI, but it is it's own separate patch so it can be
applied independent of any possible problems with the PTI submission.

Thanks for your help and time.  Regards,
J Freyensee


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

* [PATCH 01/12] export kernel call get_task_comm()
  2011-02-08 19:34 ` Resend: Request for review and addition of PTI implementation into kernel james_p_freyensee
@ 2011-02-08 19:34   ` james_p_freyensee
  2011-02-08 19:34     ` [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
                       ` (2 more replies)
  0 siblings, 3 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows drivers who call this function to be compiled modularly.
Otherwise, a driver who is interested in this type of functionality
has to implement their own.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 fs/exec.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index c62efcb..7b209f9 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -998,6 +998,7 @@ char *get_task_comm(char *buf, struct task_struct *tsk)
 	task_unlock(tsk);
 	return buf;
 }
+EXPORT_SYMBOL_GPL(get_task_comm);
 
 void set_task_comm(struct task_struct *tsk, char *buf)
 {
-- 
1.6.6.1


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

* [PATCH 02/12] Kernel documentation for the PTI feature.
  2011-02-08 19:34   ` [PATCH 01/12] export kernel call get_task_comm() james_p_freyensee
@ 2011-02-08 19:34     ` james_p_freyensee
  2011-02-08 19:34       ` [PATCH 03/12] Intel PTI implementaiton of 1149 james_p_freyensee
  2011-02-08 20:55       ` [PATCH 02/12] Kernel documentation for the PTI feature Randy Dunlap
  2011-02-08 19:38     ` [PATCH 01/12] export kernel call get_task_comm() Christoph Hellwig
  2011-02-22 18:38     ` J Freyensee
  2 siblings, 2 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This provides Kernel documentation for the PTI
feature for Linux mobile solutions.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 Documentation/pti/pti_intel_mid.txt |   89 +++++++++++++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/pti/pti_intel_mid.txt

diff --git a/Documentation/pti/pti_intel_mid.txt b/Documentation/pti/pti_intel_mid.txt
new file mode 100644
index 0000000..b9c3f3a
--- /dev/null
+++ b/Documentation/pti/pti_intel_mid.txt
@@ -0,0 +1,89 @@
+The Intel MID PTI project is HW implemented in Intel Atom
+system-on-a-chip designs based on the Parallel Trace
+Interface for MIPI P1149.7 cJTAG standard.  The kernel solution
+for this platform involves the following files:
+
+./include/linux/pti.h
+./include/linux/n_tracesink.h
+./drivers/.../n_tracerouter.c
+./drivers/.../n_tracesink.c
+./drivers/.../pti.c
+
+pti.c is the driver that enables various debugging features
+popular on certain mobile manufacturers.  n_tracerouter.c
+and n_tracesink.c allow extra system information to be
+collected and routed to the pti driver, such as trace
+debugging data from a modem.  Altough n_tracerouter
+and n_tracesink are a part of the complete PTI solution,
+these two line disciplines can work separate from
+pti.c and route any data stream from one /dev/tty node
+to another /dev/tty node via kernel-space.  This provides
+a stable, reliable connection that will not break unless
+the user-space application shuts down (plus avoids
+kernel->user->kernel context switch overheads of routing
+data).
+
+An example debugging usage for this driver system:
+   *Hook /dev/ttyPTI0 to syslogd.  Opening this port will also start
+    a console device to further capture debugging messages to PTI.
+   *Hook /dev/ttyPTI1 to modem debugging data to write to PTI HW.
+    This is where n_tracerouter and n_tracesink are used.
+   *Hook /dev/pti to a user-level debugging application for writing
+    to PTI HW.
+   *Use mipi_* Kernel Driver API in other device drivers for
+    debugging to PTI by first requesting a PTI write address via
+    mipi_request_masterchannel(1).
+
+Example 'privileged' (normal user privileges are not enough)
+user-space code on how to setup the n_tracerouter and n_tracesink
+ldisc drivers (note: n_tracerouter depends on n_tracesink):
+
+/////////// To hook up n_tracerouter and n_tracesink /////////
+
+#include <errno.h>
+#define ONE_TTY "/dev/ttyOne"
+#define TWO_TTY "/dev/ttyTwo"
+
+// needed global to hand onto ldisc connection
+static int g_fd_source = -1;
+static int g_fd_sink  = -1;
+
+// grab LDISC values from loaded ldisc drivers from /proc/tty/ldiscs
+int source_ldisc_num, sink_ldisc_num = -1;
+int retval;
+
+g_fd_source = open(ONE_TTY, O_RDWR); // must be R/W
+g_fd_sink   = open(TWO_TTY, O_RDWR); // must be R/W
+
+if (g_fd_source <= 0) || (g_fd_sink <= 0) {
+   // doubt you'll want to use these exact error lines of code
+   printf("Error on open(). errno: %d\n",errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_sink, TIOCSETD, &sink_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_source, TIOCSETD, &source_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+/////////// To disconnect n_tracerouter and n_tracesink ////////
+
+// First make sure data through the ldiscs has stopped.
+
+// Second, disconnect ldiscs.  This provides a
+// little cleaner shutdown on tty stack.
+sink_ldisc_num = 0;
+source_ldisc_num = 0;
+ioctl(g_fd_uart, TIOCSETD, &sink_ldisc_num);
+ioctl(g_fd_gadget, TIOCSETD, &source_ldisc_num);
+
+// Three, program closes connection:
+close(g_fd_uart);
+close(g_fd_gadget);
-- 
1.6.6.1


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

* [PATCH 03/12] Intel PTI implementaiton of 1149.
  2011-02-08 19:34     ` [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
@ 2011-02-08 19:34       ` james_p_freyensee
  2011-02-08 19:34         ` [PATCH 04/12] PTI Kconfig change in misc james_p_freyensee
  2011-02-08 20:55       ` [PATCH 02/12] Kernel documentation for the PTI feature Randy Dunlap
  1 sibling, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This driver is the implementation of MIPI P1149.7, compact JTAG
standard for Intel Atom mobile devices.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/pti.c |  891 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 891 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pti.c

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
new file mode 100644
index 0000000..c88b1e5
--- /dev/null
+++ b/drivers/misc/pti.c
@@ -0,0 +1,891 @@
+/*
+ *  pti.c - PTI driver for cJTAG data extration
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA
+ */
+
+
+/*
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ */
+
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/console.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/pci.h>
+#include <linux/mutex.h>
+#include <linux/miscdevice.h>
+#include <linux/pti.h>
+
+#define DRIVERNAME		"pti"
+#define PCINAME			"pciPTI"
+#define TTYNAME			"ttyPTI"
+#define CHARNAME		"pti"
+#define PTITTY_MINOR_START	0
+#define PTITTY_MINOR_NUM	2
+#define MAX_APP_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_OS_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_MODEM_IDS		16   /* 128 channel ids / u8 bit size */
+#define MODEM_BASE_ID		71   /* modem master ID address    */
+#define CONTROL_ID		72   /* control master ID address  */
+#define CONSOLE_ID		73   /* console master ID address  */
+#define OS_BASE_ID		74   /* base OS master ID address  */
+#define APP_BASE_ID		80   /* base App master ID address */
+#define CONTROL_FRAME_LEN	32   /* PTI control frame maximum size */
+#define USER_COPY_SIZE		8192 /* 8Kb buffer for user space copy */
+
+struct pti_tty {
+	struct masterchannel *mc;
+};
+
+struct pti_dev {
+	struct tty_port port;
+	unsigned long pti_addr;
+	unsigned long aperture_base;
+	void __iomem *pti_ioaddr;
+	unsigned long pti_iolen;
+	u8 IA_App[MAX_APP_IDS];
+	u8 IA_OS[MAX_OS_IDS];
+	u8 IA_Modem[MAX_MODEM_IDS];
+};
+
+
+static DEFINE_MUTEX(alloclock);
+
+static struct pci_device_id pci_ids[] __devinitconst = {
+		{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B) },
+		{0}
+};
+
+static struct tty_driver *pti_tty_driver;
+
+static struct pti_dev *drv_data;
+
+static unsigned int pti_console_channel;
+static unsigned int pti_control_channel;
+
+#define DTS 0x30		/* offset for last dword of a PTI message */
+
+/**
+ *  pti_write_to_aperture() - THE private write function to PTI HW.
+ *  @mc: The 'aperture'. It's part of a write address that holds
+ *       a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  Since each aperture is specified by a unique
+ *  master/channel ID, no two processes will be writing
+ *  to the same aperture at the same time so no lock is required. The
+ *  PTI-Output agent will send these out in the order that they arrived, and
+ *  thus, it will intermix these messages. The debug tool can then later
+ *  regroup the appropriate message segments together reconstituting each
+ *  message.
+ */
+static void pti_write_to_aperture(struct masterchannel *mc, u8 *buf, int len)
+{
+	int dwordcnt, final, i;
+	u32 ptiword;
+	u8 *p;
+	u32 __iomem *aperture;
+
+	p = buf;
+
+	/*
+	   calculate the aperture offset from the base using the master and
+	   channel id's.
+	*/
+	aperture = drv_data->pti_ioaddr + (mc->master << 15)
+		+ (mc->channel << 8);
+
+	dwordcnt = len >> 2;
+	final = len - (dwordcnt << 2);		/* final = trailing bytes */
+	if (final == 0 && dwordcnt != 0) {	/* always have a final dword */
+		final += 4;
+		dwordcnt--;
+	}
+
+	for (i = 0; i < dwordcnt; i++) {
+		ptiword = be32_to_cpu(*(u32 *)p);
+		p += 4;
+		iowrite32(ptiword, aperture);
+	}
+
+	aperture += DTS;		/* adding DTS signals that is EOM */
+
+	ptiword = 0;
+	for (i = 0; i < final; i++)
+		ptiword |= *p++ << (24-(8*i));
+
+	iowrite32(ptiword, aperture);
+	return;
+}
+
+/**
+ *  pti_control_frame_built_and_sent() - control frame build and send function.
+ *  @mc: The master / channel structure on which the function built a control
+ *  frame.
+ *
+ *  To be able to post process the PTI contents on host side, a control frame
+ *  is added before sending any PTI content. So the host side knows on
+ *  each PTI frame the name of the thread using a dedicated master / channel.
+ *  This function builds this frame and sends it to a master ID CONTROL_ID.
+ *  The overhead is only 32 bytes since the driver only writes to HW
+ *  in 32 byte chunks.
+ */
+
+static void pti_control_frame_built_and_sent(struct masterchannel *mc)
+{
+	struct masterchannel mccontrol = {.master = CONTROL_ID, .channel = 0};
+	const char *control_format = "%3d %3d %s";
+
+	char comm[sizeof(current->comm) + 1];
+	u8 control_frame[CONTROL_FRAME_LEN];
+
+	if (!in_interrupt())
+		get_task_comm(comm, current);
+	else
+		strcpy(comm, "Interrupt");
+
+	/* Ensure our buffer is zero terminated */
+	comm[sizeof(current->comm)] = 0;
+
+	mccontrol.channel = pti_control_channel;
+	pti_control_channel = (pti_control_channel + 1) & 0x7f;
+
+	snprintf(control_frame, CONTROL_FRAME_LEN, control_format, mc->master,
+		mc->channel, comm);
+	pti_write_to_aperture(&mccontrol, control_frame, strlen(control_frame));
+}
+
+/**
+ *  pti_write_full_frame_to_aperture() - high level function to write to PTI
+ *  @mc: The 'aperture'. It's part of a write address that holds
+ *       a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  All threads sending data (either console, user space application, ...)
+ *  are calling the high level function to write to PTI meaning that it is
+ *  possible to add a control frame before sending the content.
+ */
+static void pti_write_full_frame_to_aperture(struct masterchannel *mc,
+						const unsigned char *buf,
+						int len)
+{
+	pti_control_frame_built_and_sent(mc);
+	pti_write_to_aperture(mc, (u8 *)buf, len);
+}
+
+
+/**
+ * getID(): Allocate a master and channel ID.
+ *
+ * @IDarray:
+ * @max_IDS: The max amount of available write IDs to use.
+ * @baseID:  The starting SW channel ID, based on the Intel
+ *           PTI arch.
+ *
+ * @return: masterchannel struct containing master, channel ID address,
+ * or 0 for error.
+ *
+ * Each bit in the arrays IA_App and IA_OS correspond to a master and
+ * channel id. The bit is one if the id is taken and 0 if free. For
+ * every master there are 128 channel id's.
+ */
+static struct masterchannel *getID(u8 *IDarray, int max_IDS, int baseID)
+{
+	struct masterchannel *mc;
+	int i, j, mask;
+
+	mc = kmalloc(sizeof(struct masterchannel), GFP_KERNEL);
+	if (mc == NULL)
+		return NULL;
+
+	/* look for a byte with a free bit */
+	for (i = 0; i < max_IDS; i++)
+		if (IDarray[i] != 0xff)
+			break;
+	if (i == max_IDS) {
+		kfree(mc);
+		return NULL;
+	}
+	/* find the bit in the 128 possible channel opportunities */
+	mask = 0x80;
+	for (j = 0; j < 8; j++) {
+		if ((IDarray[i] & mask) == 0)
+			break;
+		mask >>= 1;
+	}
+
+	/* grab it */
+	IDarray[i] |= mask;
+	mc->master  = baseID;
+	mc->channel = ((i & 0xf)<<3) + j;
+	/* write new master Id / channel Id allocation to channel control */
+	pti_control_frame_built_and_sent(mc);
+	return mc;
+}
+
+/*
+	The following three functions:
+	mipi_request_mastercahannel(), mipi_release masterchannel()
+	and mipi_write_data() are an API for other kernel drivers to
+	access PTI.
+*/
+
+/**
+ * mipi_request_masterchannel() - Kernel API function used to allocate
+ *                                a master, channel ID address to write to
+ *                                PTI HW.
+ * @type: 0- request Application  master, channel aperture ID write address.
+ *        1- request OS master, channel aperture ID write address.
+ *        2- request Modem master, channel aperture ID write
+ *           address.
+ *        Other values, error.
+ * @return: masterchannel struct or 0 for error.
+ *
+ */
+struct masterchannel *mipi_request_masterchannel(u8 type)
+{
+	struct masterchannel *mc;
+
+	mutex_lock(&alloclock);
+
+	switch (type) {
+
+	case 0:
+		mc = getID(drv_data->IA_App, MAX_APP_IDS, APP_BASE_ID);
+		break;
+
+	case 1:
+		mc = getID(drv_data->IA_OS, MAX_OS_IDS, OS_BASE_ID);
+		break;
+
+	case 2:
+		mc = getID(drv_data->IA_Modem, MAX_MODEM_IDS, MODEM_BASE_ID);
+		break;
+	default:
+		mc = NULL;
+	}
+
+	mutex_unlock(&alloclock);
+	return mc;
+}
+EXPORT_SYMBOL_GPL(mipi_request_masterchannel);
+
+/**
+ * mipi_release_masterchannel() - Kernel API function used to release
+ *                                a master, channel ID address
+ *                                used to write to PTI HW.
+ * @mc: master, channel apeture ID address to be released.
+ *
+ */
+void mipi_release_masterchannel(struct masterchannel *mc)
+{
+	u8 master, channel, i;
+
+	mutex_lock(&alloclock);
+
+	if (mc) {
+		master = mc->master;
+		channel = mc->channel;
+
+		if (master == APP_BASE_ID) {
+			i = channel >> 3;
+			drv_data->IA_App[i] &=  ~(0x80>>(channel & 0x7));
+		} else if (master == OS_BASE_ID) {
+			i = channel >> 3;
+			drv_data->IA_OS[i] &= ~(0x80>>(channel & 0x7));
+		} else {
+			i = channel >> 3;
+			drv_data->IA_Modem[i] &= ~(0x80>>(channel & 0x7));
+		}
+
+		kfree(mc);
+	}
+
+	mutex_unlock(&alloclock);
+}
+EXPORT_SYMBOL_GPL(mipi_release_masterchannel);
+
+/**
+ * mipi_pti_writedata() - Kernel API function used to write trace
+ *                        debugging data to PTI HW.
+ *
+ * @mc:    Master, channel aperture ID address to write to.
+ *         Null value will return with no write occurring.
+ * @buf:   Trace debuging data to write to the PTI HW.
+ *         Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         retrn with no write occuring.
+ */
+void mipi_pti_writedata(struct masterchannel *mc, u8 *buf, int count)
+{
+	/*
+	   since this function is exported, this is treated like an
+	   API function, thus, all parameters should
+	   be checked for validity.
+	*/
+	if ((mc != NULL) && (buf != NULL) && (count > 0))
+		pti_write_to_aperture(mc, buf, count);
+	return;
+}
+EXPORT_SYMBOL_GPL(mipi_pti_writedata);
+
+static void __devexit pti_pci_remove(struct pci_dev *pdev)
+{
+	struct pti_dev *drv_data;
+
+	drv_data = pci_get_drvdata(pdev);
+	if (drv_data != NULL) {
+		pci_iounmap(pdev, drv_data->pti_ioaddr);
+		pci_set_drvdata(pdev, NULL);
+		kfree(drv_data);
+		pci_release_region(pdev, 1);
+		pci_disable_device(pdev);
+	}
+}
+
+/*
+   for the tty_driver_*() basic function descriptions, see tty_driver.h.
+   Specific header comments made for PTI-related specifics.
+*/
+
+/**
+ * pti_tty_driver_open()- Open an Application master, channel aperture
+ * ID to the PTI device via tty device.
+ *
+ * @param tty: tty interface.
+ * @param filp: filp interface pased to tty_port_open() call.
+ *
+ * @return int : Success = 0, otherwise fail.
+ *
+ * The main purpose of using the tty device interface is for
+ * each tty port to have a unique PTI write aperture.  In an
+ * example use case, ttyPTI0 gets syslogd and an APP aperture
+ * ID and ttyPTI1 is where the n_tracesink ldisc hooks to route
+ * modem messages into PTI.  Modem trace data does not have to
+ * go to ttyPTI1, but ttyPTI0 and ttyPTI1 do need to be distinct
+ * master IDs.  These messages go through the PTI HW and out of
+ * the handheld platform and to the Fido/Lauterbach device.
+ */
+static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
+{
+	int ret = 0;
+
+	/*
+	   we actually want to allocate a new channel per open, per
+	   system arch.  HW gives more than plenty channels for a single
+	   system task to have its own channel to write trace data. This
+	   also removes a locking requirement for the actual write
+	   procedure.
+	*/
+	ret = tty_port_open(&drv_data->port, tty, filp);
+
+	return ret;
+}
+
+/**
+ * pti_tty_driver_close()- close tty device and release Application
+ * master, channel aperture ID to the PTI device via tty device.
+ *
+ * @param tty: tty interface.
+ * @param filp: filp interface pased to tty_port_close() call.
+ *
+ * The main purpose of using the tty device interface is to route
+ * syslog daemon messages to the PTI HW and out of the handheld platform
+ * and to the Fido/Lauterbach device.
+ */
+static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
+{
+	tty_port_close(&drv_data->port, tty, filp);
+
+	return;
+}
+
+static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
+{
+	int idx = tty->index;
+	struct pti_tty *pti_tty_data;
+	struct masterchannel *mc;
+	int ret = tty_init_termios(tty);
+
+	if (ret == 0) {
+		tty_driver_kref_get(driver);
+		tty->count++;
+		driver->ttys[idx] = tty;
+
+		pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL);
+		if (pti_tty_data == NULL)
+			return -ENOMEM;
+
+		tty->driver_data = pti_tty_data;
+
+		if (idx == PTITTY_MINOR_START)
+			mc = mipi_request_masterchannel(0);
+		else
+			mc = mipi_request_masterchannel(2);
+
+		if (mc == NULL)
+			return -ENXIO;
+
+		pti_tty_data->mc = mc;
+	}
+
+	return ret;
+}
+
+static void pti_tty_cleanup(struct tty_struct *tty)
+{
+	struct pti_tty *pti_tty_data;
+	struct masterchannel *mc;
+
+	pti_tty_data = tty->driver_data;
+
+	if (pti_tty_data != NULL) {
+		mc = pti_tty_data->mc;
+		mipi_release_masterchannel(mc);
+		pti_tty_data->mc = NULL;
+	}
+
+	if (pti_tty_data != NULL)
+		kfree(pti_tty_data);
+
+	tty->driver_data = NULL;
+}
+
+/**
+ * pti_tty_driver_write():  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @param filp: Contains private data which is used to obtain
+ *              master, channel write ID.
+ * @param data: trace data to be written.
+ * @param len:  # of byte to write.
+ * @return int : # of bytes written, or error.
+ */
+static int pti_tty_driver_write(struct tty_struct *tty,
+	const unsigned char *buf, int len)
+{
+	struct masterchannel *mc;
+	struct pti_tty *pti_tty_data;
+
+	pti_tty_data = tty->driver_data;
+	mc = pti_tty_data->mc;
+	pti_write_to_aperture(mc, (u8 *)buf, len);
+
+	return len;
+}
+
+static int pti_tty_write_room(struct tty_struct *tty)
+{
+	return 2048;
+}
+
+/**
+ * pti_char_open()- Open an Application master, channel aperture
+ * ID to the PTI device. Part of the misc device implementation.
+ *
+ * @param inode: not used.
+ * @param filp: Output- will have a masterchannel struct set containing
+ * the allocated application PTI aperture write address.
+ *
+ * @return int : Success = 0, otherwise fail.  As of right now,
+ *         it is not sure what needs to really be initialized
+ *         for open(), so it always returns 0.
+ */
+static int pti_char_open(struct inode *inode, struct file *filp)
+{
+	struct masterchannel *mc;
+
+	mc = mipi_request_masterchannel(0);
+	if (mc == NULL)
+		return -ENOMEM;
+	filp->private_data = mc;
+	return 0;
+}
+
+/**
+ * pti_char_release()-  Close a char channel to the PTI device. Part
+ * of the misc device implementation.
+ *
+ * @param inode: Not used in this implementaiton.
+ * @param filp: Contains private_data that contains the master, channel
+ * ID to be released by the PTI device.
+ *
+ * @return int : Success = 0
+ */
+static int pti_char_release(struct inode *inode, struct file *filp)
+{
+	mipi_release_masterchannel(filp->private_data);
+
+	return 0;
+}
+
+/**
+ * pti_char_write():  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @param filp: Contains private data which is used to obtain
+ *              master, channel write ID.
+ * @param data: trace data to be written.
+ * @param len:  # of byte to write.
+ * @param ppose: Not used in this function implementation.
+ * @return int : # of bytes written, or error.
+ */
+static ssize_t pti_char_write(struct file *filp, const char __user *data,
+			      size_t len, loff_t *ppose)
+{
+	struct masterchannel *mc;
+	void *kbuf;
+	const char __user *tmp;
+	size_t size = USER_COPY_SIZE, n = 0;
+
+	tmp = data;
+	mc = filp->private_data;
+
+	kbuf = kmalloc(size, GFP_KERNEL);
+	if (kbuf == NULL)  {
+		pr_err("%s(%d): buf allocation failed\n",
+			__func__, __LINE__);
+		return 0;
+	}
+
+	do {
+		if (len - n > USER_COPY_SIZE)
+			size = USER_COPY_SIZE;
+		else
+			size = len - n;
+
+		if (copy_from_user(kbuf, tmp, size)) {
+			kfree(kbuf);
+			return n ? n : -EFAULT;
+		}
+
+		pti_write_to_aperture(mc, kbuf, size);
+		n  += size;
+		tmp += size;
+
+	} while (len > n);
+
+	kfree(kbuf);
+	kbuf = NULL;
+
+	return len;
+}
+
+static const struct tty_operations pti_tty_driver_ops = {
+	.open		= pti_tty_driver_open,
+	.close		= pti_tty_driver_close,
+	.write		= pti_tty_driver_write,
+	.write_room	= pti_tty_write_room,
+	.install	= pti_tty_install,
+	.cleanup	= pti_tty_cleanup
+};
+
+static const struct file_operations pti_char_driver_ops = {
+	.owner		= THIS_MODULE,
+	.write		= pti_char_write,
+	.open		= pti_char_open,
+	.release	= pti_char_release,
+};
+
+static struct miscdevice pti_char_driver = {
+	.minor		= MISC_DYNAMIC_MINOR,
+	.name		= CHARNAME,
+	.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_full_frame_to_aperture(&mc, 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;
+	pti_control_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,
+	.index		= 0,
+};
+
+/**
+ * pti_port_activate(): Used to start/initialize any items upon
+ * first opening of tty_port().
+ *
+ * @param port- The tty port number of the PTI device.
+ * @param tty-  The tty struct associated with this device.
+ *
+ * @return int - Always returns 0.
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static int pti_port_activate(struct tty_port *port, struct tty_struct *tty)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		console_start(&pti_console);
+	return 0;
+}
+
+/**
+ * pti_port_shutdown(): Used to stop/shutdown any items upon the
+ * last tty port close.
+ *
+ * @param port- The tty port number of the PTI device.
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static void pti_port_shutdown(struct tty_port *port)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		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.
+*/
+
+static int __devinit pti_pci_probe(struct pci_dev *pdev,
+		const struct pci_device_id *ent)
+{
+	int retval = -EINVAL;
+	int pci_bar = 1;
+
+	dev_dbg(&pdev->dev, "%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__,
+			__func__, __LINE__, pdev->vendor, pdev->device);
+
+	retval = misc_register(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+		return retval;
+	}
+
+	retval = pci_enable_device(pdev);
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s: pci_enable_device() returned error %d\n",
+			__func__, retval);
+		return retval;
+	}
+
+	drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
+
+	if (drv_data == NULL) {
+		retval = -ENOMEM;
+		dev_err(&pdev->dev,
+			"%s(%d): kmalloc() returned NULL memory.\n",
+			__func__, __LINE__);
+		return retval;
+	}
+	drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
+
+	retval = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev));
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s(%d): pci_request_region() returned error %d\n",
+			__func__, __LINE__, retval);
+		kfree(drv_data);
+		return retval;
+	}
+	drv_data->pti_iolen = pci_resource_len(pdev, pci_bar);
+	drv_data->aperture_base = drv_data->pti_addr+APERTURE_14;
+	drv_data->pti_ioaddr =
+		ioremap_nocache((u32)drv_data->aperture_base,
+		APERTURE_LEN);
+	if (!drv_data->pti_ioaddr) {
+		pci_release_region(pdev, pci_bar);
+		retval = -ENOMEM;
+		kfree(drv_data);
+		return retval;
+	}
+
+	pci_set_drvdata(pdev, drv_data);
+
+	tty_port_init(&drv_data->port);
+	drv_data->port.ops = &tty_port_ops;
+
+	tty_register_device(pti_tty_driver, 0, &pdev->dev);
+	tty_register_device(pti_tty_driver, 1, &pdev->dev);
+
+	register_console(&pti_console);
+
+	return retval;
+}
+
+static struct pci_driver pti_pci_driver = {
+	.name		= PCINAME,
+	.id_table	= pci_ids,
+	.probe		= pti_pci_probe,
+	.remove		= pti_pci_remove,
+};
+
+/**
+ *
+ * pti_init():
+ *
+ * @return int __init: 0 for success, any other value error.
+ *
+ */
+static int __init pti_init(void)
+{
+	int retval = -EINVAL;
+
+	/* First register module as tty device */
+
+	pti_tty_driver = alloc_tty_driver(1);
+	if (pti_tty_driver == NULL) {
+		pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n",
+			__func__, __LINE__);
+		return -ENOMEM;
+	}
+
+	pti_tty_driver->owner			= THIS_MODULE;
+	pti_tty_driver->magic			= TTY_DRIVER_MAGIC;
+	pti_tty_driver->driver_name		= DRIVERNAME;
+	pti_tty_driver->name			= TTYNAME;
+	pti_tty_driver->major			= 0;
+	pti_tty_driver->minor_start		= PTITTY_MINOR_START;
+	pti_tty_driver->minor_num		= PTITTY_MINOR_NUM;
+	pti_tty_driver->num			= PTITTY_MINOR_NUM;
+	pti_tty_driver->type			= TTY_DRIVER_TYPE_SYSTEM;
+	pti_tty_driver->subtype			= SYSTEM_TYPE_SYSCONS;
+	pti_tty_driver->flags			= TTY_DRIVER_REAL_RAW |
+						  TTY_DRIVER_DYNAMIC_DEV;
+	pti_tty_driver->init_termios		= tty_std_termios;
+
+	tty_set_operations(pti_tty_driver, &pti_tty_driver_ops);
+
+	retval = tty_register_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	retval = pci_register_driver(&pti_pci_driver);
+
+	if (retval) {
+		pr_err("%s(%d): PCI registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		tty_unregister_driver(pti_tty_driver);
+		pr_err("%s(%d): Unregistering TTY part of pti driver\n",
+			__func__, __LINE__);
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	return retval;
+}
+
+/**
+ * pti_exit(): Unregisters this module as a tty and pci driver.
+ */
+static void __exit pti_exit(void)
+{
+	int retval;
+
+	tty_unregister_device(pti_tty_driver, 0);
+	tty_unregister_device(pti_tty_driver, 1);
+
+	retval = tty_unregister_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	pci_unregister_driver(&pti_pci_driver);
+
+	retval = misc_deregister(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	unregister_console(&pti_console);
+	return;
+}
+
+module_init(pti_init);
+module_exit(pti_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ken Mills, Jay Freyensee");
+MODULE_DESCRIPTION("PTI Driver");
+
-- 
1.6.6.1


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

* [PATCH 04/12] PTI Kconfig change in misc.
  2011-02-08 19:34       ` [PATCH 03/12] Intel PTI implementaiton of 1149 james_p_freyensee
@ 2011-02-08 19:34         ` james_p_freyensee
  2011-02-08 19:34           ` [PATCH 05/12] PTI misc Makefile addition james_p_freyensee
  2011-02-17 19:20           ` [PATCH 04/12] PTI Kconfig change in misc Greg KH
  0 siblings, 2 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This adds the Intel PTI Kconfig option.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/Kconfig |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4d073f1..f8076f1 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -136,6 +136,18 @@ config PHANTOM
 	  If you choose to build module, its name will be phantom. If unsure,
 	  say N here.
 
+config INTEL_MID_PTI
+        tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
+        help
+          The PTI (Parallel Trace Interface) driver directs
+          trace data routed from various parts in the system out
+          through an Intel Penwell PTI port and out of the mobile
+          device for analysis with a debugging tool (Lauterbach or Fido).
+
+          You should select this driver if the target kernel is meant for
+          an Intel Atom (non-netbook) mobile device containing a MIPI
+          P1149.7 standard implementation.
+
 config SGI_IOC4
 	tristate "SGI IOC4 Base IO support"
 	depends on PCI
-- 
1.6.6.1


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

* [PATCH 05/12] PTI misc Makefile addition.
  2011-02-08 19:34         ` [PATCH 04/12] PTI Kconfig change in misc james_p_freyensee
@ 2011-02-08 19:34           ` james_p_freyensee
  2011-02-08 19:34             ` [PATCH 06/12] PTI header file james_p_freyensee
  2011-02-17 19:20           ` [PATCH 04/12] PTI Kconfig change in misc Greg KH
  1 sibling, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows the Intel implementation of the PTI standard to be compiled.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/Makefile |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 98009cc..cae0463 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_IBM_ASM)		+= ibmasm/
 obj-$(CONFIG_AD525X_DPOT)	+= ad525x_dpot.o
 obj-$(CONFIG_AD525X_DPOT_I2C)	+= ad525x_dpot-i2c.o
 obj-$(CONFIG_AD525X_DPOT_SPI)	+= ad525x_dpot-spi.o
+obj-$(CONFIG_INTEL_MID_PTI)     += pti.o
 obj-$(CONFIG_ATMEL_PWM)		+= atmel_pwm.o
 obj-$(CONFIG_ATMEL_SSC)		+= atmel-ssc.o
 obj-$(CONFIG_ATMEL_TCLIB)	+= atmel_tclib.o
-- 
1.6.6.1


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

* [PATCH 06/12] PTI header file.
  2011-02-08 19:34           ` [PATCH 05/12] PTI misc Makefile addition james_p_freyensee
@ 2011-02-08 19:34             ` james_p_freyensee
  2011-02-08 19:34               ` [PATCH 07/12] n_tracerouter and n_tracesink additions james_p_freyensee
  2011-02-17 19:20               ` [PATCH 06/12] PTI header file Greg KH
  0 siblings, 2 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This adds PTI header information for the PTI project.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 include/linux/pti.h |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/pti.h

diff --git a/include/linux/pti.h b/include/linux/pti.h
new file mode 100644
index 0000000..4b1c9f6
--- /dev/null
+++ b/include/linux/pti.h
@@ -0,0 +1,38 @@
+/*
+ *  Copyright (C) Intel 2010
+ *  Ken Mills <ken.k.mills@intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA
+ *
+ */
+
+#ifndef PTI_H_
+#define PTI_H_
+
+/* basic structure used as a write address to the PTI HW */
+struct masterchannel {
+	u8 master;
+	u8 channel;
+};
+
+/* the following functions are defined in misc/pti.c */
+void mipi_pti_writedata(struct masterchannel *mc, u8 *cp, int count);
+struct masterchannel *mipi_request_masterchannel(u8 kerneluser);
+void mipi_release_masterchannel(struct masterchannel *mc);
+
+#define APERTURE_14 0x3800000
+#define APERTURE_LEN 0x400000
+
+#endif /*PTI_H_*/
-- 
1.6.6.1


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

* [PATCH 07/12] n_tracerouter and n_tracesink additions.
  2011-02-08 19:34             ` [PATCH 06/12] PTI header file james_p_freyensee
@ 2011-02-08 19:34               ` james_p_freyensee
  2011-02-08 19:34                 ` [PATCH 08/12] n_tracesink ldisc addition james_p_freyensee
  2011-02-17 19:21                 ` [PATCH 07/12] n_tracerouter and n_tracesink additions Greg KH
  2011-02-17 19:20               ` [PATCH 06/12] PTI header file Greg KH
  1 sibling, 2 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch adds line discipline numbers to n_tracerouter and
n_tracesink line disciplines for the Intel-Atom PTI implementation
for mobile devices.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 include/linux/tty.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/linux/tty.h b/include/linux/tty.h
index 54e4eaa..c507f53 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -50,6 +50,8 @@
 #define N_CAIF		20      /* CAIF protocol for talking to modems */
 #define N_GSM0710	21	/* GSM 0710 Mux */
 #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
+#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
+#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
-- 
1.6.6.1


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

* [PATCH 08/12] n_tracesink ldisc addition.
  2011-02-08 19:34               ` [PATCH 07/12] n_tracerouter and n_tracesink additions james_p_freyensee
@ 2011-02-08 19:34                 ` james_p_freyensee
  2011-02-08 19:34                   ` [PATCH 09/12] n_tracesink header file james_p_freyensee
  2011-02-17 19:21                 ` [PATCH 07/12] n_tracerouter and n_tracesink additions Greg KH
  1 sibling, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch adds n_tracesink line discipline driver, which is
part of the Intel-Atom PTI implementation solution.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/n_tracesink.c |  253 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 253 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/n_tracesink.c

diff --git a/drivers/tty/n_tracesink.c b/drivers/tty/n_tracesink.c
new file mode 100644
index 0000000..0d072e3
--- /dev/null
+++ b/drivers/tty/n_tracesink.c
@@ -0,0 +1,253 @@
+/*
+ *  n_tracesink.c - Trace data router and sink path through tty space.
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The trace sink uses the Linux line discipline framework to receive
+ * trace data coming from the PTI source line discipline driver
+ * to a user-desired tty port, like USB.
+ * This is to provide a way to extract modem trace data on
+ * devices that do not have a PTI HW module, or just need modem
+ * trace data to come out of a different HW output port.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <asm-generic/bug.h>
+#include <linux/n_tracesink.h>
+
+/* Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracesink"
+
+/* there is a quirk with this ldisc is he can write data
+ * to a tty from anyone calling his kernel API, which
+ * meets customer requirements in the drivers/misc/pti.c
+ * project.  So he needs to know when he can and cannot write when
+ * the API is called. In theory, the API can be called
+ * after an init() but before a successful open() which
+ * would crash the system if tty is not checked.
+ */
+static struct tty_struct *this_tty;
+static DEFINE_MUTEX(writelock);
+
+/**
+ * n_tracesink_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success,
+ *      -EFAULT = couldn't get a tty kref n_tracesink will sit
+ *       on top of
+ *      -EEXIST = open() called successfully once and it cannot
+ *      be called again.
+ *
+ * Caveats: open() should only be successful the first time a
+ * SW entity calls it.
+ */
+static int n_tracesink_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&writelock);
+	if (this_tty == NULL) {
+
+		this_tty = tty_kref_get(tty);
+
+		if (this_tty == NULL)
+			retval = -EFAULT;
+		else {
+			tty->disc_data = this_tty;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&writelock);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracesink_close(struct tty_struct *tty)
+{
+
+	tty_driver_flush_buffer(tty);
+
+	mutex_lock(&writelock);
+	tty_kref_put(this_tty);
+	this_tty = NULL;
+	mutex_unlock(&writelock);
+
+	tty->disc_data = NULL;
+}
+
+/**
+ * n_tracesink_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracesink_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracesink_read(struct tty_struct *tty, struct file *file,
+				unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracesink_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracesink_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracesink_write(struct tty_struct *tty, struct file *file,
+				 const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ *  mipi_pti_sinkdata() - Kernel API function used to route
+ *			trace debugging data to user-defined
+ *			port like USB.
+ *
+ * @buf:   Trace debuging data buffer to write to tty target
+ *         port. Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         return with no write occuring.
+ *
+ * Caveat: If this line discipline does not set the tty it sits
+ * on top of via an open() call, this API function will not
+ * call the tty's write() call because it will have no pointer
+ * to call the write().
+ */
+
+void n_tracesink_datadrain(u8 *cp, int count)
+{
+	mutex_lock(&writelock);
+
+	if ((cp != NULL) && (count > 0) && (this_tty != NULL))
+		this_tty->ops->write(this_tty, cp, count);
+
+	mutex_unlock(&writelock);
+}
+EXPORT_SYMBOL_GPL(n_tracesink_datadrain);
+
+/* Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+/*
+ * tty_ldisc function operations for this driver.
+ */
+static struct tty_ldisc_ops tty_n_tracesink = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracesink_open,
+	.close		= n_tracesink_close,
+	.read		= n_tracesink_read,
+	.write		= n_tracesink_write
+};
+
+/**
+ * n_tracesink_init-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracesink_init(void)
+{
+	int retval;
+
+	/* Note N_TRACESINK is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
+
+	if (retval < 0)
+		pr_err("%s: Registration failed: %d\n",
+					__func__, retval);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_exit -	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracesink_exit(void)
+{
+	int retval;
+
+	retval = tty_unregister_ldisc(N_TRACESINK);
+
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n",
+					__func__,  retval);
+}
+
+module_init(n_tracesink_init);
+module_exit(n_tracesink_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACESINK);
+MODULE_DESCRIPTION("Trace sink ldisc driver");
-- 
1.6.6.1


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

* [PATCH 09/12] n_tracesink header file.
  2011-02-08 19:34                 ` [PATCH 08/12] n_tracesink ldisc addition james_p_freyensee
@ 2011-02-08 19:34                   ` james_p_freyensee
  2011-02-08 19:34                     ` [PATCH 10/12] n_tracerouter ldisc driver james_p_freyensee
  2011-02-17 19:23                     ` [PATCH 09/12] n_tracesink header file Greg KH
  0 siblings, 2 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This header file allows the n_tracerouter to send it's information
to the n_tracesink ldisc driver.  It's part of the Intel-Atom
PTI implementation solution.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 include/linux/n_tracesink.h |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/n_tracesink.h

diff --git a/include/linux/n_tracesink.h b/include/linux/n_tracesink.h
new file mode 100644
index 0000000..b1a3ad8
--- /dev/null
+++ b/include/linux/n_tracesink.h
@@ -0,0 +1,32 @@
+/*
+ *  n_tracesink.h - Kernel driver API to route trace data in kernel space.
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * The implementation of the function seen in this file can be found in
+ * char/n_tracesink.c
+ */
+
+#ifndef N_TRACESINK_H_
+#define N_TRACESINK_H_
+
+void n_tracesink_datadrain(u8 *cp, int count);
+
+#endif
-- 
1.6.6.1


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

* [PATCH 10/12] n_tracerouter ldisc driver.
  2011-02-08 19:34                   ` [PATCH 09/12] n_tracesink header file james_p_freyensee
@ 2011-02-08 19:34                     ` james_p_freyensee
  2011-02-08 19:34                       ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig james_p_freyensee
  2011-02-17 19:23                     ` [PATCH 09/12] n_tracesink header file Greg KH
  1 sibling, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch adds the n_tracerouter ldisc driver.  It is part
of the Intel-Atom PTI implementation solution.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/n_tracerouter.c |  264 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 264 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/n_tracerouter.c

diff --git a/drivers/tty/n_tracerouter.c b/drivers/tty/n_tracerouter.c
new file mode 100644
index 0000000..1bb8c9e
--- /dev/null
+++ b/drivers/tty/n_tracerouter.c
@@ -0,0 +1,264 @@
+/*
+ *  n_tracerouter.c - Trace data router through tty space
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This trace router uses the Linux line discipline framework to route
+ * trace data coming from a HW Modem to a PTI (Parallel Trace Module) port.
+ * The solution is not specific to a HW modem and this line disciple can
+ * be used to route any stream of data in kernel space.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <asm-generic/bug.h>
+#include <linux/n_tracesink.h>
+
+/* Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracerouter"
+
+/* struct to hold private configuration data for this ldisc.
+ * opencalled is used to hold if this ldisc has been opened.
+ * kref_tty holds the tty reference the ldisc sits on top of.
+ */
+struct tracerouter_data {
+	u8 opencalled;
+	struct tty_struct *kref_tty;
+};
+static struct tracerouter_data *tr_data;
+
+/* lock for ioctl() setting of tracerouter_data values */
+static DEFINE_MUTEX(routelock);
+
+/**
+ * tracerouter_alloc
+ *
+ * Allocates the structure needed for this ldisc.
+ */
+static struct tracerouter_data *tracerouter_alloc(void)
+{
+	struct tracerouter_data *tptr = kzalloc(
+					sizeof(struct tracerouter_data),
+					GFP_KERNEL);
+	if (tptr == NULL)
+		return NULL;
+	tptr->opencalled = 0;
+	return tptr;
+}
+
+/**
+ * n_tracerouter_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success.
+ *
+ * Caveats: This should only be opened one time per SW entity.
+ */
+static int n_tracerouter_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&routelock);
+	if (tr_data->opencalled == 0) {
+
+		tr_data->kref_tty = tty_kref_get(tty);
+		if (tr_data->kref_tty == NULL)
+			retval = -EFAULT;
+		else {
+			tr_data->opencalled = 1;
+			tty->disc_data      = tr_data;
+			tty->receive_room   = RECEIVE_ROOM;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&routelock);
+	return retval;
+}
+
+/**
+ * n_tracerouter_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracerouter_close(struct tty_struct *tty)
+{
+	struct tracerouter_data *tptr = tty->disc_data;
+
+	WARN_ON(tptr->kref_tty != tr_data->kref_tty);
+	tty_driver_flush_buffer(tty);
+	mutex_lock(&routelock);
+	tty_kref_put(tr_data->kref_tty);
+	tr_data->kref_tty = NULL;
+	tr_data->opencalled = 0;
+	tty->disc_data = NULL;
+	mutex_unlock(&routelock);
+}
+
+/**
+ * n_tracerouter_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracerouter_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracerouter_read(struct tty_struct *tty, struct file *file,
+				  unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracerouter_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracerouter_write(struct tty_struct *tty, struct file *file,
+				   const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_receivebuf() - Routing function for driver.
+ * @tty: terminal device passed into the ldisc.  It's assumed
+ *       tty will never be NULL.
+ * @cp:  buffer, block of characters to be eventually read by
+ *       someone, somewhere (user read() call or some kernel function).
+ * @fp:  flag buffer.
+ * @count: number of characters (aka, bytes) in cp.
+ *
+ * This function takes the input buffer, cp, and passes it to
+ * an external API function for processing.
+ */
+static void n_tracerouter_receivebuf(struct tty_struct *tty,
+					const unsigned char *cp,
+					char *fp, int count)
+{
+	mutex_lock(&routelock);
+	n_tracesink_datadrain((u8 *) cp, count);
+	mutex_unlock(&routelock);
+}
+
+/* Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+static struct tty_ldisc_ops tty_ptirouter_ldisc = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracerouter_open,
+	.close		= n_tracerouter_close,
+	.read		= n_tracerouter_read,
+	.write		= n_tracerouter_write,
+	.receive_buf	= n_tracerouter_receivebuf
+};
+
+/**
+ * n_tracerouter_init		-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracerouter_init(void)
+{
+	int retval;
+
+	tr_data = tracerouter_alloc();
+	if (tr_data == NULL)
+		return -ENOMEM;
+
+	/* Note N_TRACEROUTER is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACEROUTER, &tty_ptirouter_ldisc);
+	if (retval < 0) {
+		pr_err("%s: Registration failed: %d\n",
+					__func__, retval);
+		kfree(tr_data);
+	}
+	return retval;
+}
+
+/**
+ * n_tracerouter_exit -	-	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracerouter_exit(void)
+{
+	int retval;
+
+	kfree(tr_data);
+	retval = tty_unregister_ldisc(N_TRACEROUTER);
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n",
+					__func__,  retval);
+}
+
+module_init(n_tracerouter_init);
+module_exit(n_tracerouter_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACEROUTER);
+MODULE_DESCRIPTION("Trace router ldisc driver");
-- 
1.6.6.1


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

* [PATCH 11/12] n_tracerouter and n_tracesink Kconfig.
  2011-02-08 19:34                     ` [PATCH 10/12] n_tracerouter ldisc driver james_p_freyensee
@ 2011-02-08 19:34                       ` james_p_freyensee
  2011-02-08 19:34                         ` [PATCH 12/12] n_tracerouter and n_tracesink Makefile addition james_p_freyensee
  2011-02-08 21:03                         ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig Randy Dunlap
  0 siblings, 2 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch allows n_tracerouter and n_tracesink ldisc drivers
to be configured in menuconfig.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/char/Kconfig |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 43d3395..02b9be2 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -289,6 +289,38 @@ config N_GSM
 	  This line discipline provides support for the GSM MUX protocol and
 	  presents the mux as a set of 61 individual tty devices.
 
+config TRACE_ROUTER
+        tristate "Trace data router for MIPI P1149.7 cJTAG standard"
+                depends on TRACE_SINK
+                default Y
+        ---help---
+          The trace router uses the Linux tty line discipline framework to
+          route trace data coming from a tty port (say UART for example) to
+           the trace sink line discipline driver and to another tty port(say USB).
+           This is part of a solution for the MIPI P1149.7, compact JTAG,
+           standard, which is for debugging mobile devices. The PTI driver in
+           drivers/misc/pti.c defines the majority of this MIPI solution.
+
+          You should select this driver if the target kernel is meant for
+          a mobile device containing a modem.  Then you will need to select
+          "Trace data sink for MIPI P1149.7 cJTAG standard" line discipline
+          driver.
+
+config TRACE_SINK
+        tristate "Trace data sink for MIPI P1149.7 cJTAG standard"
+                default Y
+        ---help---
+          The trace sink uses the Linux line discipline framework to receive
+          trace data coming from the trace router line discipline driver
+          to a user-defined tty port target, like USB.
+          This is to provide a way to extract modem trace data on
+          devices that do not have a PTI HW module, or just need modem
+          trace data to come out of a different HW output port.
+          This is part of a solution for the P1149.7, compact JTAG, standard.
+
+          If you select this option, you need to select
+          "Trace data router for MIPI P1149.7 cJTAG standard".
+
 config RISCOM8
 	tristate "SDL RISCom/8 card support"
 	depends on SERIAL_NONSTANDARD
-- 
1.6.6.1


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

* [PATCH 12/12] n_tracerouter and n_tracesink Makefile addition.
  2011-02-08 19:34                       ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig james_p_freyensee
@ 2011-02-08 19:34                         ` james_p_freyensee
  2011-02-08 21:03                         ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig Randy Dunlap
  1 sibling, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:34 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows n_tracerouter and n_tracesink to be compiled in the
Linux kernel.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/Makefile |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index c43ef48..8c56ffd 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -7,5 +7,7 @@ obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
 obj-$(CONFIG_N_HDLC)		+= n_hdlc.o
 obj-$(CONFIG_N_GSM)		+= n_gsm.o
 obj-$(CONFIG_R3964)		+= n_r3964.o
+obj-$(CONFIG_TRACE_ROUTER)      += n_tracerouter.o
+obj-$(CONFIG_TRACE_SINK)        += n_tracesink.o
 
 obj-y				+= vt/
-- 
1.6.6.1


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

* Re: [PATCH 01/12] export kernel call get_task_comm()
  2011-02-08 19:34   ` [PATCH 01/12] export kernel call get_task_comm() james_p_freyensee
  2011-02-08 19:34     ` [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
@ 2011-02-08 19:38     ` Christoph Hellwig
  2011-02-08 19:44       ` james_p_freyensee
  2011-02-22 18:38     ` J Freyensee
  2 siblings, 1 reply; 171+ messages in thread
From: Christoph Hellwig @ 2011-02-08 19:38 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed

On Tue, Feb 08, 2011 at 11:34:46AM -0800, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This allows drivers who call this function to be compiled modularly.
> Otherwise, a driver who is interested in this type of functionality
> has to implement their own.

NAK.

>From current you can just dereference current->comm, and access from
other threads from drivers is a bad idea.


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

* Re: [PATCH 01/12] export kernel call get_task_comm()
  2011-02-08 19:38     ` [PATCH 01/12] export kernel call get_task_comm() Christoph Hellwig
@ 2011-02-08 19:44       ` james_p_freyensee
  2011-02-08 20:04         ` Christoph Hellwig
  2011-02-08 20:28         ` Alan Cox
  0 siblings, 2 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 19:44 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: james_p_freyensee, gregkh, linux-kernel, suhail.ahmed

> On Tue, Feb 08, 2011 at 11:34:46AM -0800,
> james_p_freyensee@linux.intel.com wrote:
>> From: J Freyensee <james_p_freyensee@linux.intel.com>
>>
>> This allows drivers who call this function to be compiled modularly.
>> Otherwise, a driver who is interested in this type of functionality
>> has to implement their own.
>
> NAK.
>
> From current you can just dereference current->comm, and access from
> other threads from drivers is a bad idea.
>
>

That is originally what I did, but after talking with Greg KH, Arjan vdv,
and Alan Cox I made this patch instead.


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

* Re: [PATCH 01/12] export kernel call get_task_comm()
  2011-02-08 19:44       ` james_p_freyensee
@ 2011-02-08 20:04         ` Christoph Hellwig
  2011-02-08 20:35           ` james_p_freyensee
  2011-02-08 20:28         ` Alan Cox
  1 sibling, 1 reply; 171+ messages in thread
From: Christoph Hellwig @ 2011-02-08 20:04 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: Christoph Hellwig, gregkh, linux-kernel, suhail.ahmed

On Tue, Feb 08, 2011 at 11:44:16AM -0800, james_p_freyensee@linux.intel.com wrote:
> That is originally what I did, but after talking with Greg KH, Arjan vdv,
> and Alan Cox I made this patch instead.

Care to explain why exactly?


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

* Re: [PATCH 01/12] export kernel call get_task_comm()
  2011-02-08 19:44       ` james_p_freyensee
  2011-02-08 20:04         ` Christoph Hellwig
@ 2011-02-08 20:28         ` Alan Cox
  2011-02-08 20:28           ` Christoph Hellwig
  1 sibling, 1 reply; 171+ messages in thread
From: Alan Cox @ 2011-02-08 20:28 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: Christoph Hellwig, gregkh, linux-kernel, suhail.ahmed

On Tue, 8 Feb 2011 11:44:16 -0800 (PST)
> > From current you can just dereference current->comm, and access from
> > other threads from drivers is a bad idea.

You need to take the locks for it - which get_task_comm encapsulates.

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

* Re: [PATCH 01/12] export kernel call get_task_comm()
  2011-02-08 20:28         ` Alan Cox
@ 2011-02-08 20:28           ` Christoph Hellwig
  2011-02-08 20:36             ` Alan Cox
  0 siblings, 1 reply; 171+ messages in thread
From: Christoph Hellwig @ 2011-02-08 20:28 UTC (permalink / raw)
  To: Alan Cox
  Cc: james_p_freyensee, Christoph Hellwig, gregkh, linux-kernel, suhail.ahmed

On Tue, Feb 08, 2011 at 08:28:52PM +0000, Alan Cox wrote:
> On Tue, 8 Feb 2011 11:44:16 -0800 (PST)
> > > From current you can just dereference current->comm, and access from
> > > other threads from drivers is a bad idea.
> 
> You need to take the locks for it - which get_task_comm encapsulates.

Not for current->comm, which is the only thing it cares about.

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

* Re: [PATCH 01/12] export kernel call get_task_comm()
  2011-02-08 20:04         ` Christoph Hellwig
@ 2011-02-08 20:35           ` james_p_freyensee
  0 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-08 20:35 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: james_p_freyensee, Christoph Hellwig, gregkh, linux-kernel, suhail.ahmed

> On Tue, Feb 08, 2011 at 11:44:16AM -0800,
> james_p_freyensee@linux.intel.com wrote:
>> That is originally what I did, but after talking with Greg KH, Arjan
>> vdv,
>> and Alan Cox I made this patch instead.
>
> Care to explain why exactly?
>
>

If I can jog my own memory as this was a while ago...

Well for starters, Arjan van de Ven first suggested it, and I trust his
judgement because of his Linux kernel experience.

But looking at the code, the kernel function get_task_comm() provides a
level of safety with a lock, so the global resource 'current' can be used
without someone else trying to use it at the same time.  And using this
function facilitates code reuse which is something Greg KH was trying to
point out to me at the time:

http://lists.meego.com/pipermail/meego-kernel/2010-October/000823.html

In fact, I remember finding existing, accepted drivers in the kernel that
wrote their own locks before accessing current (I quickly just now found
block/dfdb/drbd_main.c as an example), so Greg is making a valid point
about code reuse.  So not exporting get_task_comm() encourages code
locking re-write of every driver that wants to access 'current'.

In that email, Greg clearly reminded me my goal is to get my work into the
kernel.  Thus, I listened to their advice and made this patch.

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

* Re: [PATCH 01/12] export kernel call get_task_comm()
  2011-02-08 20:28           ` Christoph Hellwig
@ 2011-02-08 20:36             ` Alan Cox
  2011-02-15 10:57               ` Christoph Hellwig
  0 siblings, 1 reply; 171+ messages in thread
From: Alan Cox @ 2011-02-08 20:36 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: james_p_freyensee, gregkh, linux-kernel, suhail.ahmed

On Tue, 8 Feb 2011 15:28:56 -0500
Christoph Hellwig <hch@infradead.org> wrote:

> On Tue, Feb 08, 2011 at 08:28:52PM +0000, Alan Cox wrote:
> > On Tue, 8 Feb 2011 11:44:16 -0800 (PST)
> > > > From current you can just dereference current->comm, and access from
> > > > other threads from drivers is a bad idea.
> > 
> > You need to take the locks for it - which get_task_comm encapsulates.
> 
> Not for current->comm, which is the only thing it cares about.

Which is a detail you really don't want to leak out of the proper
abstraction use. I really don't see why you are advocating bad
programming practice - everything else uses the abstraction properly,
this just happens to be the first modular case that wants to behave
properly.

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

* Re: [PATCH 02/12] Kernel documentation for the PTI feature.
  2011-02-08 19:34     ` [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
  2011-02-08 19:34       ` [PATCH 03/12] Intel PTI implementaiton of 1149 james_p_freyensee
@ 2011-02-08 20:55       ` Randy Dunlap
  1 sibling, 0 replies; 171+ messages in thread
From: Randy Dunlap @ 2011-02-08 20:55 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed

On 2/8/2011 11:34 AM, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee<james_p_freyensee@linux.intel.com>
>
> This provides Kernel documentation for the PTI
> feature for Linux mobile solutions.
>
> Signed-off-by: J Freyensee<james_p_freyensee@linux.intel.com>
> ---
>   Documentation/pti/pti_intel_mid.txt |   89 +++++++++++++++++++++++++++++++++++
>   1 files changed, 89 insertions(+), 0 deletions(-)
>   create mode 100644 Documentation/pti/pti_intel_mid.txt
>
> diff --git a/Documentation/pti/pti_intel_mid.txt b/Documentation/pti/pti_intel_mid.txt
> new file mode 100644
> index 0000000..b9c3f3a
> --- /dev/null
> +++ b/Documentation/pti/pti_intel_mid.txt
> @@ -0,0 +1,89 @@
> +The Intel MID PTI project is HW implemented in Intel Atom
> +system-on-a-chip designs based on the Parallel Trace
> +Interface for MIPI P1149.7 cJTAG standard.  The kernel solution
> +for this platform involves the following files:
> +
> +./include/linux/pti.h
> +./include/linux/n_tracesink.h
> +./drivers/.../n_tracerouter.c
> +./drivers/.../n_tracesink.c
> +./drivers/.../pti.c
> +
> +pti.c is the driver that enables various debugging features
> +popular on certain mobile manufacturers.  n_tracerouter.c
> +and n_tracesink.c allow extra system information to be
> +collected and routed to the pti driver, such as trace
> +debugging data from a modem.  Altough n_tracerouter

                                  Although

> +and n_tracesink are a part of the complete PTI solution,
> +these two line disciplines can work separate from

                                        separately

> +pti.c and route any data stream from one /dev/tty node
> +to another /dev/tty node via kernel-space.  This provides
> +a stable, reliable connection that will not break unless
> +the user-space application shuts down (plus avoids
> +kernel->user->kernel context switch overheads of routing
> +data).

~Randy

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

* Re: [PATCH 11/12] n_tracerouter and n_tracesink Kconfig.
  2011-02-08 19:34                       ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig james_p_freyensee
  2011-02-08 19:34                         ` [PATCH 12/12] n_tracerouter and n_tracesink Makefile addition james_p_freyensee
@ 2011-02-08 21:03                         ` Randy Dunlap
  1 sibling, 0 replies; 171+ messages in thread
From: Randy Dunlap @ 2011-02-08 21:03 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed

On 2/8/2011 11:34 AM, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee<james_p_freyensee@linux.intel.com>
>
> This patch allows n_tracerouter and n_tracesink ldisc drivers
> to be configured in menuconfig.

s/menuconfig/kconfig tools/


> Signed-off-by: J Freyensee<james_p_freyensee@linux.intel.com>
> ---
>   drivers/char/Kconfig |   32 ++++++++++++++++++++++++++++++++
>   1 files changed, 32 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
> index 43d3395..02b9be2 100644
> --- a/drivers/char/Kconfig
> +++ b/drivers/char/Kconfig
> @@ -289,6 +289,38 @@ config N_GSM
>   	  This line discipline provides support for the GSM MUX protocol and
>   	  presents the mux as a set of 61 individual tty devices.
>
> +config TRACE_ROUTER
> +        tristate "Trace data router for MIPI P1149.7 cJTAG standard"
> +                depends on TRACE_SINK
> +                default Y

Indentation above and on the "default" below looks flaky.
Should line up with "tristate".

> +        ---help---
> +          The trace router uses the Linux tty line discipline framework to
> +          route trace data coming from a tty port (say UART for example) to
> +           the trace sink line discipline driver and to another tty port(say USB).
> +           This is part of a solution for the MIPI P1149.7, compact JTAG,
> +           standard, which is for debugging mobile devices. The PTI driver in
> +           drivers/misc/pti.c defines the majority of this MIPI solution.
> +
> +          You should select this driver if the target kernel is meant for
> +          a mobile device containing a modem.  Then you will need to select
> +          "Trace data sink for MIPI P1149.7 cJTAG standard" line discipline
> +          driver.
> +
> +config TRACE_SINK
> +        tristate "Trace data sink for MIPI P1149.7 cJTAG standard"
> +                default Y
> +        ---help---
> +          The trace sink uses the Linux line discipline framework to receive
> +          trace data coming from the trace router line discipline driver
> +          to a user-defined tty port target, like USB.
> +          This is to provide a way to extract modem trace data on
> +          devices that do not have a PTI HW module, or just need modem
> +          trace data to come out of a different HW output port.
> +          This is part of a solution for the P1149.7, compact JTAG, standard.
> +
> +          If you select this option, you need to select
> +          "Trace data router for MIPI P1149.7 cJTAG standard".
> +
>   config RISCOM8
>   	tristate "SDL RISCom/8 card support"
>   	depends on SERIAL_NONSTANDARD


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

* [PATCH 02/12] Kernel documentation for the PTI feature.
       [not found] <james_p_freyensee@linux.intel.com>
  2011-02-08 19:34 ` Resend: Request for review and addition of PTI implementation into kernel james_p_freyensee
@ 2011-02-09  0:17 ` james_p_freyensee
  2011-02-09  0:17   ` [PATCH 03/12] Intel PTI implementaiton of 1149 james_p_freyensee
  2011-02-24 18:06 ` 2nd request for review and addition of PTI implementation into kernel james_p_freyensee
                   ` (39 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This provides Kernel documentation for the PTI
feature for Linux mobile solutions.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 Documentation/pti/pti_intel_mid.txt |   89 +++++++++++++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/pti/pti_intel_mid.txt

diff --git a/Documentation/pti/pti_intel_mid.txt b/Documentation/pti/pti_intel_mid.txt
new file mode 100644
index 0000000..b9c3f3a
--- /dev/null
+++ b/Documentation/pti/pti_intel_mid.txt
@@ -0,0 +1,89 @@
+The Intel MID PTI project is HW implemented in Intel Atom
+system-on-a-chip designs based on the Parallel Trace
+Interface for MIPI P1149.7 cJTAG standard.  The kernel solution
+for this platform involves the following files:
+
+./include/linux/pti.h
+./include/linux/n_tracesink.h
+./drivers/.../n_tracerouter.c
+./drivers/.../n_tracesink.c
+./drivers/.../pti.c
+
+pti.c is the driver that enables various debugging features
+popular on certain mobile manufacturers.  n_tracerouter.c
+and n_tracesink.c allow extra system information to be
+collected and routed to the pti driver, such as trace
+debugging data from a modem.  Altough n_tracerouter
+and n_tracesink are a part of the complete PTI solution,
+these two line disciplines can work separate from
+pti.c and route any data stream from one /dev/tty node
+to another /dev/tty node via kernel-space.  This provides
+a stable, reliable connection that will not break unless
+the user-space application shuts down (plus avoids
+kernel->user->kernel context switch overheads of routing
+data).
+
+An example debugging usage for this driver system:
+   *Hook /dev/ttyPTI0 to syslogd.  Opening this port will also start
+    a console device to further capture debugging messages to PTI.
+   *Hook /dev/ttyPTI1 to modem debugging data to write to PTI HW.
+    This is where n_tracerouter and n_tracesink are used.
+   *Hook /dev/pti to a user-level debugging application for writing
+    to PTI HW.
+   *Use mipi_* Kernel Driver API in other device drivers for
+    debugging to PTI by first requesting a PTI write address via
+    mipi_request_masterchannel(1).
+
+Example 'privileged' (normal user privileges are not enough)
+user-space code on how to setup the n_tracerouter and n_tracesink
+ldisc drivers (note: n_tracerouter depends on n_tracesink):
+
+/////////// To hook up n_tracerouter and n_tracesink /////////
+
+#include <errno.h>
+#define ONE_TTY "/dev/ttyOne"
+#define TWO_TTY "/dev/ttyTwo"
+
+// needed global to hand onto ldisc connection
+static int g_fd_source = -1;
+static int g_fd_sink  = -1;
+
+// grab LDISC values from loaded ldisc drivers from /proc/tty/ldiscs
+int source_ldisc_num, sink_ldisc_num = -1;
+int retval;
+
+g_fd_source = open(ONE_TTY, O_RDWR); // must be R/W
+g_fd_sink   = open(TWO_TTY, O_RDWR); // must be R/W
+
+if (g_fd_source <= 0) || (g_fd_sink <= 0) {
+   // doubt you'll want to use these exact error lines of code
+   printf("Error on open(). errno: %d\n",errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_sink, TIOCSETD, &sink_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_source, TIOCSETD, &source_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+/////////// To disconnect n_tracerouter and n_tracesink ////////
+
+// First make sure data through the ldiscs has stopped.
+
+// Second, disconnect ldiscs.  This provides a
+// little cleaner shutdown on tty stack.
+sink_ldisc_num = 0;
+source_ldisc_num = 0;
+ioctl(g_fd_uart, TIOCSETD, &sink_ldisc_num);
+ioctl(g_fd_gadget, TIOCSETD, &source_ldisc_num);
+
+// Three, program closes connection:
+close(g_fd_uart);
+close(g_fd_gadget);
-- 
1.6.6.1


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

* [PATCH 03/12] Intel PTI implementaiton of 1149.
  2011-02-09  0:17 ` [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
@ 2011-02-09  0:17   ` james_p_freyensee
  2011-02-09  0:17     ` [PATCH 04/12] PTI Kconfig change in misc james_p_freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This driver is the implementation of MIPI P1149.7, compact JTAG
standard for Intel Atom mobile devices.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/pti.c |  891 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 891 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pti.c

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
new file mode 100644
index 0000000..c88b1e5
--- /dev/null
+++ b/drivers/misc/pti.c
@@ -0,0 +1,891 @@
+/*
+ *  pti.c - PTI driver for cJTAG data extration
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA
+ */
+
+
+/*
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ */
+
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/console.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/pci.h>
+#include <linux/mutex.h>
+#include <linux/miscdevice.h>
+#include <linux/pti.h>
+
+#define DRIVERNAME		"pti"
+#define PCINAME			"pciPTI"
+#define TTYNAME			"ttyPTI"
+#define CHARNAME		"pti"
+#define PTITTY_MINOR_START	0
+#define PTITTY_MINOR_NUM	2
+#define MAX_APP_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_OS_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_MODEM_IDS		16   /* 128 channel ids / u8 bit size */
+#define MODEM_BASE_ID		71   /* modem master ID address    */
+#define CONTROL_ID		72   /* control master ID address  */
+#define CONSOLE_ID		73   /* console master ID address  */
+#define OS_BASE_ID		74   /* base OS master ID address  */
+#define APP_BASE_ID		80   /* base App master ID address */
+#define CONTROL_FRAME_LEN	32   /* PTI control frame maximum size */
+#define USER_COPY_SIZE		8192 /* 8Kb buffer for user space copy */
+
+struct pti_tty {
+	struct masterchannel *mc;
+};
+
+struct pti_dev {
+	struct tty_port port;
+	unsigned long pti_addr;
+	unsigned long aperture_base;
+	void __iomem *pti_ioaddr;
+	unsigned long pti_iolen;
+	u8 IA_App[MAX_APP_IDS];
+	u8 IA_OS[MAX_OS_IDS];
+	u8 IA_Modem[MAX_MODEM_IDS];
+};
+
+
+static DEFINE_MUTEX(alloclock);
+
+static struct pci_device_id pci_ids[] __devinitconst = {
+		{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B) },
+		{0}
+};
+
+static struct tty_driver *pti_tty_driver;
+
+static struct pti_dev *drv_data;
+
+static unsigned int pti_console_channel;
+static unsigned int pti_control_channel;
+
+#define DTS 0x30		/* offset for last dword of a PTI message */
+
+/**
+ *  pti_write_to_aperture() - THE private write function to PTI HW.
+ *  @mc: The 'aperture'. It's part of a write address that holds
+ *       a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  Since each aperture is specified by a unique
+ *  master/channel ID, no two processes will be writing
+ *  to the same aperture at the same time so no lock is required. The
+ *  PTI-Output agent will send these out in the order that they arrived, and
+ *  thus, it will intermix these messages. The debug tool can then later
+ *  regroup the appropriate message segments together reconstituting each
+ *  message.
+ */
+static void pti_write_to_aperture(struct masterchannel *mc, u8 *buf, int len)
+{
+	int dwordcnt, final, i;
+	u32 ptiword;
+	u8 *p;
+	u32 __iomem *aperture;
+
+	p = buf;
+
+	/*
+	   calculate the aperture offset from the base using the master and
+	   channel id's.
+	*/
+	aperture = drv_data->pti_ioaddr + (mc->master << 15)
+		+ (mc->channel << 8);
+
+	dwordcnt = len >> 2;
+	final = len - (dwordcnt << 2);		/* final = trailing bytes */
+	if (final == 0 && dwordcnt != 0) {	/* always have a final dword */
+		final += 4;
+		dwordcnt--;
+	}
+
+	for (i = 0; i < dwordcnt; i++) {
+		ptiword = be32_to_cpu(*(u32 *)p);
+		p += 4;
+		iowrite32(ptiword, aperture);
+	}
+
+	aperture += DTS;		/* adding DTS signals that is EOM */
+
+	ptiword = 0;
+	for (i = 0; i < final; i++)
+		ptiword |= *p++ << (24-(8*i));
+
+	iowrite32(ptiword, aperture);
+	return;
+}
+
+/**
+ *  pti_control_frame_built_and_sent() - control frame build and send function.
+ *  @mc: The master / channel structure on which the function built a control
+ *  frame.
+ *
+ *  To be able to post process the PTI contents on host side, a control frame
+ *  is added before sending any PTI content. So the host side knows on
+ *  each PTI frame the name of the thread using a dedicated master / channel.
+ *  This function builds this frame and sends it to a master ID CONTROL_ID.
+ *  The overhead is only 32 bytes since the driver only writes to HW
+ *  in 32 byte chunks.
+ */
+
+static void pti_control_frame_built_and_sent(struct masterchannel *mc)
+{
+	struct masterchannel mccontrol = {.master = CONTROL_ID, .channel = 0};
+	const char *control_format = "%3d %3d %s";
+
+	char comm[sizeof(current->comm) + 1];
+	u8 control_frame[CONTROL_FRAME_LEN];
+
+	if (!in_interrupt())
+		get_task_comm(comm, current);
+	else
+		strcpy(comm, "Interrupt");
+
+	/* Ensure our buffer is zero terminated */
+	comm[sizeof(current->comm)] = 0;
+
+	mccontrol.channel = pti_control_channel;
+	pti_control_channel = (pti_control_channel + 1) & 0x7f;
+
+	snprintf(control_frame, CONTROL_FRAME_LEN, control_format, mc->master,
+		mc->channel, comm);
+	pti_write_to_aperture(&mccontrol, control_frame, strlen(control_frame));
+}
+
+/**
+ *  pti_write_full_frame_to_aperture() - high level function to write to PTI
+ *  @mc: The 'aperture'. It's part of a write address that holds
+ *       a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  All threads sending data (either console, user space application, ...)
+ *  are calling the high level function to write to PTI meaning that it is
+ *  possible to add a control frame before sending the content.
+ */
+static void pti_write_full_frame_to_aperture(struct masterchannel *mc,
+						const unsigned char *buf,
+						int len)
+{
+	pti_control_frame_built_and_sent(mc);
+	pti_write_to_aperture(mc, (u8 *)buf, len);
+}
+
+
+/**
+ * getID(): Allocate a master and channel ID.
+ *
+ * @IDarray:
+ * @max_IDS: The max amount of available write IDs to use.
+ * @baseID:  The starting SW channel ID, based on the Intel
+ *           PTI arch.
+ *
+ * @return: masterchannel struct containing master, channel ID address,
+ * or 0 for error.
+ *
+ * Each bit in the arrays IA_App and IA_OS correspond to a master and
+ * channel id. The bit is one if the id is taken and 0 if free. For
+ * every master there are 128 channel id's.
+ */
+static struct masterchannel *getID(u8 *IDarray, int max_IDS, int baseID)
+{
+	struct masterchannel *mc;
+	int i, j, mask;
+
+	mc = kmalloc(sizeof(struct masterchannel), GFP_KERNEL);
+	if (mc == NULL)
+		return NULL;
+
+	/* look for a byte with a free bit */
+	for (i = 0; i < max_IDS; i++)
+		if (IDarray[i] != 0xff)
+			break;
+	if (i == max_IDS) {
+		kfree(mc);
+		return NULL;
+	}
+	/* find the bit in the 128 possible channel opportunities */
+	mask = 0x80;
+	for (j = 0; j < 8; j++) {
+		if ((IDarray[i] & mask) == 0)
+			break;
+		mask >>= 1;
+	}
+
+	/* grab it */
+	IDarray[i] |= mask;
+	mc->master  = baseID;
+	mc->channel = ((i & 0xf)<<3) + j;
+	/* write new master Id / channel Id allocation to channel control */
+	pti_control_frame_built_and_sent(mc);
+	return mc;
+}
+
+/*
+	The following three functions:
+	mipi_request_mastercahannel(), mipi_release masterchannel()
+	and mipi_write_data() are an API for other kernel drivers to
+	access PTI.
+*/
+
+/**
+ * mipi_request_masterchannel() - Kernel API function used to allocate
+ *                                a master, channel ID address to write to
+ *                                PTI HW.
+ * @type: 0- request Application  master, channel aperture ID write address.
+ *        1- request OS master, channel aperture ID write address.
+ *        2- request Modem master, channel aperture ID write
+ *           address.
+ *        Other values, error.
+ * @return: masterchannel struct or 0 for error.
+ *
+ */
+struct masterchannel *mipi_request_masterchannel(u8 type)
+{
+	struct masterchannel *mc;
+
+	mutex_lock(&alloclock);
+
+	switch (type) {
+
+	case 0:
+		mc = getID(drv_data->IA_App, MAX_APP_IDS, APP_BASE_ID);
+		break;
+
+	case 1:
+		mc = getID(drv_data->IA_OS, MAX_OS_IDS, OS_BASE_ID);
+		break;
+
+	case 2:
+		mc = getID(drv_data->IA_Modem, MAX_MODEM_IDS, MODEM_BASE_ID);
+		break;
+	default:
+		mc = NULL;
+	}
+
+	mutex_unlock(&alloclock);
+	return mc;
+}
+EXPORT_SYMBOL_GPL(mipi_request_masterchannel);
+
+/**
+ * mipi_release_masterchannel() - Kernel API function used to release
+ *                                a master, channel ID address
+ *                                used to write to PTI HW.
+ * @mc: master, channel apeture ID address to be released.
+ *
+ */
+void mipi_release_masterchannel(struct masterchannel *mc)
+{
+	u8 master, channel, i;
+
+	mutex_lock(&alloclock);
+
+	if (mc) {
+		master = mc->master;
+		channel = mc->channel;
+
+		if (master == APP_BASE_ID) {
+			i = channel >> 3;
+			drv_data->IA_App[i] &=  ~(0x80>>(channel & 0x7));
+		} else if (master == OS_BASE_ID) {
+			i = channel >> 3;
+			drv_data->IA_OS[i] &= ~(0x80>>(channel & 0x7));
+		} else {
+			i = channel >> 3;
+			drv_data->IA_Modem[i] &= ~(0x80>>(channel & 0x7));
+		}
+
+		kfree(mc);
+	}
+
+	mutex_unlock(&alloclock);
+}
+EXPORT_SYMBOL_GPL(mipi_release_masterchannel);
+
+/**
+ * mipi_pti_writedata() - Kernel API function used to write trace
+ *                        debugging data to PTI HW.
+ *
+ * @mc:    Master, channel aperture ID address to write to.
+ *         Null value will return with no write occurring.
+ * @buf:   Trace debuging data to write to the PTI HW.
+ *         Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         retrn with no write occuring.
+ */
+void mipi_pti_writedata(struct masterchannel *mc, u8 *buf, int count)
+{
+	/*
+	   since this function is exported, this is treated like an
+	   API function, thus, all parameters should
+	   be checked for validity.
+	*/
+	if ((mc != NULL) && (buf != NULL) && (count > 0))
+		pti_write_to_aperture(mc, buf, count);
+	return;
+}
+EXPORT_SYMBOL_GPL(mipi_pti_writedata);
+
+static void __devexit pti_pci_remove(struct pci_dev *pdev)
+{
+	struct pti_dev *drv_data;
+
+	drv_data = pci_get_drvdata(pdev);
+	if (drv_data != NULL) {
+		pci_iounmap(pdev, drv_data->pti_ioaddr);
+		pci_set_drvdata(pdev, NULL);
+		kfree(drv_data);
+		pci_release_region(pdev, 1);
+		pci_disable_device(pdev);
+	}
+}
+
+/*
+   for the tty_driver_*() basic function descriptions, see tty_driver.h.
+   Specific header comments made for PTI-related specifics.
+*/
+
+/**
+ * pti_tty_driver_open()- Open an Application master, channel aperture
+ * ID to the PTI device via tty device.
+ *
+ * @param tty: tty interface.
+ * @param filp: filp interface pased to tty_port_open() call.
+ *
+ * @return int : Success = 0, otherwise fail.
+ *
+ * The main purpose of using the tty device interface is for
+ * each tty port to have a unique PTI write aperture.  In an
+ * example use case, ttyPTI0 gets syslogd and an APP aperture
+ * ID and ttyPTI1 is where the n_tracesink ldisc hooks to route
+ * modem messages into PTI.  Modem trace data does not have to
+ * go to ttyPTI1, but ttyPTI0 and ttyPTI1 do need to be distinct
+ * master IDs.  These messages go through the PTI HW and out of
+ * the handheld platform and to the Fido/Lauterbach device.
+ */
+static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
+{
+	int ret = 0;
+
+	/*
+	   we actually want to allocate a new channel per open, per
+	   system arch.  HW gives more than plenty channels for a single
+	   system task to have its own channel to write trace data. This
+	   also removes a locking requirement for the actual write
+	   procedure.
+	*/
+	ret = tty_port_open(&drv_data->port, tty, filp);
+
+	return ret;
+}
+
+/**
+ * pti_tty_driver_close()- close tty device and release Application
+ * master, channel aperture ID to the PTI device via tty device.
+ *
+ * @param tty: tty interface.
+ * @param filp: filp interface pased to tty_port_close() call.
+ *
+ * The main purpose of using the tty device interface is to route
+ * syslog daemon messages to the PTI HW and out of the handheld platform
+ * and to the Fido/Lauterbach device.
+ */
+static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
+{
+	tty_port_close(&drv_data->port, tty, filp);
+
+	return;
+}
+
+static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
+{
+	int idx = tty->index;
+	struct pti_tty *pti_tty_data;
+	struct masterchannel *mc;
+	int ret = tty_init_termios(tty);
+
+	if (ret == 0) {
+		tty_driver_kref_get(driver);
+		tty->count++;
+		driver->ttys[idx] = tty;
+
+		pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL);
+		if (pti_tty_data == NULL)
+			return -ENOMEM;
+
+		tty->driver_data = pti_tty_data;
+
+		if (idx == PTITTY_MINOR_START)
+			mc = mipi_request_masterchannel(0);
+		else
+			mc = mipi_request_masterchannel(2);
+
+		if (mc == NULL)
+			return -ENXIO;
+
+		pti_tty_data->mc = mc;
+	}
+
+	return ret;
+}
+
+static void pti_tty_cleanup(struct tty_struct *tty)
+{
+	struct pti_tty *pti_tty_data;
+	struct masterchannel *mc;
+
+	pti_tty_data = tty->driver_data;
+
+	if (pti_tty_data != NULL) {
+		mc = pti_tty_data->mc;
+		mipi_release_masterchannel(mc);
+		pti_tty_data->mc = NULL;
+	}
+
+	if (pti_tty_data != NULL)
+		kfree(pti_tty_data);
+
+	tty->driver_data = NULL;
+}
+
+/**
+ * pti_tty_driver_write():  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @param filp: Contains private data which is used to obtain
+ *              master, channel write ID.
+ * @param data: trace data to be written.
+ * @param len:  # of byte to write.
+ * @return int : # of bytes written, or error.
+ */
+static int pti_tty_driver_write(struct tty_struct *tty,
+	const unsigned char *buf, int len)
+{
+	struct masterchannel *mc;
+	struct pti_tty *pti_tty_data;
+
+	pti_tty_data = tty->driver_data;
+	mc = pti_tty_data->mc;
+	pti_write_to_aperture(mc, (u8 *)buf, len);
+
+	return len;
+}
+
+static int pti_tty_write_room(struct tty_struct *tty)
+{
+	return 2048;
+}
+
+/**
+ * pti_char_open()- Open an Application master, channel aperture
+ * ID to the PTI device. Part of the misc device implementation.
+ *
+ * @param inode: not used.
+ * @param filp: Output- will have a masterchannel struct set containing
+ * the allocated application PTI aperture write address.
+ *
+ * @return int : Success = 0, otherwise fail.  As of right now,
+ *         it is not sure what needs to really be initialized
+ *         for open(), so it always returns 0.
+ */
+static int pti_char_open(struct inode *inode, struct file *filp)
+{
+	struct masterchannel *mc;
+
+	mc = mipi_request_masterchannel(0);
+	if (mc == NULL)
+		return -ENOMEM;
+	filp->private_data = mc;
+	return 0;
+}
+
+/**
+ * pti_char_release()-  Close a char channel to the PTI device. Part
+ * of the misc device implementation.
+ *
+ * @param inode: Not used in this implementaiton.
+ * @param filp: Contains private_data that contains the master, channel
+ * ID to be released by the PTI device.
+ *
+ * @return int : Success = 0
+ */
+static int pti_char_release(struct inode *inode, struct file *filp)
+{
+	mipi_release_masterchannel(filp->private_data);
+
+	return 0;
+}
+
+/**
+ * pti_char_write():  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @param filp: Contains private data which is used to obtain
+ *              master, channel write ID.
+ * @param data: trace data to be written.
+ * @param len:  # of byte to write.
+ * @param ppose: Not used in this function implementation.
+ * @return int : # of bytes written, or error.
+ */
+static ssize_t pti_char_write(struct file *filp, const char __user *data,
+			      size_t len, loff_t *ppose)
+{
+	struct masterchannel *mc;
+	void *kbuf;
+	const char __user *tmp;
+	size_t size = USER_COPY_SIZE, n = 0;
+
+	tmp = data;
+	mc = filp->private_data;
+
+	kbuf = kmalloc(size, GFP_KERNEL);
+	if (kbuf == NULL)  {
+		pr_err("%s(%d): buf allocation failed\n",
+			__func__, __LINE__);
+		return 0;
+	}
+
+	do {
+		if (len - n > USER_COPY_SIZE)
+			size = USER_COPY_SIZE;
+		else
+			size = len - n;
+
+		if (copy_from_user(kbuf, tmp, size)) {
+			kfree(kbuf);
+			return n ? n : -EFAULT;
+		}
+
+		pti_write_to_aperture(mc, kbuf, size);
+		n  += size;
+		tmp += size;
+
+	} while (len > n);
+
+	kfree(kbuf);
+	kbuf = NULL;
+
+	return len;
+}
+
+static const struct tty_operations pti_tty_driver_ops = {
+	.open		= pti_tty_driver_open,
+	.close		= pti_tty_driver_close,
+	.write		= pti_tty_driver_write,
+	.write_room	= pti_tty_write_room,
+	.install	= pti_tty_install,
+	.cleanup	= pti_tty_cleanup
+};
+
+static const struct file_operations pti_char_driver_ops = {
+	.owner		= THIS_MODULE,
+	.write		= pti_char_write,
+	.open		= pti_char_open,
+	.release	= pti_char_release,
+};
+
+static struct miscdevice pti_char_driver = {
+	.minor		= MISC_DYNAMIC_MINOR,
+	.name		= CHARNAME,
+	.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_full_frame_to_aperture(&mc, 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;
+	pti_control_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,
+	.index		= 0,
+};
+
+/**
+ * pti_port_activate(): Used to start/initialize any items upon
+ * first opening of tty_port().
+ *
+ * @param port- The tty port number of the PTI device.
+ * @param tty-  The tty struct associated with this device.
+ *
+ * @return int - Always returns 0.
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static int pti_port_activate(struct tty_port *port, struct tty_struct *tty)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		console_start(&pti_console);
+	return 0;
+}
+
+/**
+ * pti_port_shutdown(): Used to stop/shutdown any items upon the
+ * last tty port close.
+ *
+ * @param port- The tty port number of the PTI device.
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static void pti_port_shutdown(struct tty_port *port)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		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.
+*/
+
+static int __devinit pti_pci_probe(struct pci_dev *pdev,
+		const struct pci_device_id *ent)
+{
+	int retval = -EINVAL;
+	int pci_bar = 1;
+
+	dev_dbg(&pdev->dev, "%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__,
+			__func__, __LINE__, pdev->vendor, pdev->device);
+
+	retval = misc_register(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+		return retval;
+	}
+
+	retval = pci_enable_device(pdev);
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s: pci_enable_device() returned error %d\n",
+			__func__, retval);
+		return retval;
+	}
+
+	drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
+
+	if (drv_data == NULL) {
+		retval = -ENOMEM;
+		dev_err(&pdev->dev,
+			"%s(%d): kmalloc() returned NULL memory.\n",
+			__func__, __LINE__);
+		return retval;
+	}
+	drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
+
+	retval = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev));
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s(%d): pci_request_region() returned error %d\n",
+			__func__, __LINE__, retval);
+		kfree(drv_data);
+		return retval;
+	}
+	drv_data->pti_iolen = pci_resource_len(pdev, pci_bar);
+	drv_data->aperture_base = drv_data->pti_addr+APERTURE_14;
+	drv_data->pti_ioaddr =
+		ioremap_nocache((u32)drv_data->aperture_base,
+		APERTURE_LEN);
+	if (!drv_data->pti_ioaddr) {
+		pci_release_region(pdev, pci_bar);
+		retval = -ENOMEM;
+		kfree(drv_data);
+		return retval;
+	}
+
+	pci_set_drvdata(pdev, drv_data);
+
+	tty_port_init(&drv_data->port);
+	drv_data->port.ops = &tty_port_ops;
+
+	tty_register_device(pti_tty_driver, 0, &pdev->dev);
+	tty_register_device(pti_tty_driver, 1, &pdev->dev);
+
+	register_console(&pti_console);
+
+	return retval;
+}
+
+static struct pci_driver pti_pci_driver = {
+	.name		= PCINAME,
+	.id_table	= pci_ids,
+	.probe		= pti_pci_probe,
+	.remove		= pti_pci_remove,
+};
+
+/**
+ *
+ * pti_init():
+ *
+ * @return int __init: 0 for success, any other value error.
+ *
+ */
+static int __init pti_init(void)
+{
+	int retval = -EINVAL;
+
+	/* First register module as tty device */
+
+	pti_tty_driver = alloc_tty_driver(1);
+	if (pti_tty_driver == NULL) {
+		pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n",
+			__func__, __LINE__);
+		return -ENOMEM;
+	}
+
+	pti_tty_driver->owner			= THIS_MODULE;
+	pti_tty_driver->magic			= TTY_DRIVER_MAGIC;
+	pti_tty_driver->driver_name		= DRIVERNAME;
+	pti_tty_driver->name			= TTYNAME;
+	pti_tty_driver->major			= 0;
+	pti_tty_driver->minor_start		= PTITTY_MINOR_START;
+	pti_tty_driver->minor_num		= PTITTY_MINOR_NUM;
+	pti_tty_driver->num			= PTITTY_MINOR_NUM;
+	pti_tty_driver->type			= TTY_DRIVER_TYPE_SYSTEM;
+	pti_tty_driver->subtype			= SYSTEM_TYPE_SYSCONS;
+	pti_tty_driver->flags			= TTY_DRIVER_REAL_RAW |
+						  TTY_DRIVER_DYNAMIC_DEV;
+	pti_tty_driver->init_termios		= tty_std_termios;
+
+	tty_set_operations(pti_tty_driver, &pti_tty_driver_ops);
+
+	retval = tty_register_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	retval = pci_register_driver(&pti_pci_driver);
+
+	if (retval) {
+		pr_err("%s(%d): PCI registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		tty_unregister_driver(pti_tty_driver);
+		pr_err("%s(%d): Unregistering TTY part of pti driver\n",
+			__func__, __LINE__);
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	return retval;
+}
+
+/**
+ * pti_exit(): Unregisters this module as a tty and pci driver.
+ */
+static void __exit pti_exit(void)
+{
+	int retval;
+
+	tty_unregister_device(pti_tty_driver, 0);
+	tty_unregister_device(pti_tty_driver, 1);
+
+	retval = tty_unregister_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	pci_unregister_driver(&pti_pci_driver);
+
+	retval = misc_deregister(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	unregister_console(&pti_console);
+	return;
+}
+
+module_init(pti_init);
+module_exit(pti_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ken Mills, Jay Freyensee");
+MODULE_DESCRIPTION("PTI Driver");
+
-- 
1.6.6.1


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

* [PATCH 04/12] PTI Kconfig change in misc.
  2011-02-09  0:17   ` [PATCH 03/12] Intel PTI implementaiton of 1149 james_p_freyensee
@ 2011-02-09  0:17     ` james_p_freyensee
  2011-02-09  0:17       ` [PATCH 05/12] PTI misc Makefile addition james_p_freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This adds the Intel PTI Kconfig option.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/Kconfig |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4d073f1..f8076f1 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -136,6 +136,18 @@ config PHANTOM
 	  If you choose to build module, its name will be phantom. If unsure,
 	  say N here.
 
+config INTEL_MID_PTI
+        tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
+        help
+          The PTI (Parallel Trace Interface) driver directs
+          trace data routed from various parts in the system out
+          through an Intel Penwell PTI port and out of the mobile
+          device for analysis with a debugging tool (Lauterbach or Fido).
+
+          You should select this driver if the target kernel is meant for
+          an Intel Atom (non-netbook) mobile device containing a MIPI
+          P1149.7 standard implementation.
+
 config SGI_IOC4
 	tristate "SGI IOC4 Base IO support"
 	depends on PCI
-- 
1.6.6.1


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

* [PATCH 05/12] PTI misc Makefile addition.
  2011-02-09  0:17     ` [PATCH 04/12] PTI Kconfig change in misc james_p_freyensee
@ 2011-02-09  0:17       ` james_p_freyensee
  2011-02-09  0:17         ` [PATCH 06/12] PTI header file james_p_freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows the Intel implementation of the PTI standard to be compiled.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/Makefile |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 98009cc..cae0463 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_IBM_ASM)		+= ibmasm/
 obj-$(CONFIG_AD525X_DPOT)	+= ad525x_dpot.o
 obj-$(CONFIG_AD525X_DPOT_I2C)	+= ad525x_dpot-i2c.o
 obj-$(CONFIG_AD525X_DPOT_SPI)	+= ad525x_dpot-spi.o
+obj-$(CONFIG_INTEL_MID_PTI)     += pti.o
 obj-$(CONFIG_ATMEL_PWM)		+= atmel_pwm.o
 obj-$(CONFIG_ATMEL_SSC)		+= atmel-ssc.o
 obj-$(CONFIG_ATMEL_TCLIB)	+= atmel_tclib.o
-- 
1.6.6.1


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

* [PATCH 06/12] PTI header file.
  2011-02-09  0:17       ` [PATCH 05/12] PTI misc Makefile addition james_p_freyensee
@ 2011-02-09  0:17         ` james_p_freyensee
  2011-02-09  0:17           ` [PATCH 07/12] n_tracerouter and n_tracesink additions james_p_freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This adds PTI header information for the PTI project.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 include/linux/pti.h |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/pti.h

diff --git a/include/linux/pti.h b/include/linux/pti.h
new file mode 100644
index 0000000..4b1c9f6
--- /dev/null
+++ b/include/linux/pti.h
@@ -0,0 +1,38 @@
+/*
+ *  Copyright (C) Intel 2010
+ *  Ken Mills <ken.k.mills@intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA
+ *
+ */
+
+#ifndef PTI_H_
+#define PTI_H_
+
+/* basic structure used as a write address to the PTI HW */
+struct masterchannel {
+	u8 master;
+	u8 channel;
+};
+
+/* the following functions are defined in misc/pti.c */
+void mipi_pti_writedata(struct masterchannel *mc, u8 *cp, int count);
+struct masterchannel *mipi_request_masterchannel(u8 kerneluser);
+void mipi_release_masterchannel(struct masterchannel *mc);
+
+#define APERTURE_14 0x3800000
+#define APERTURE_LEN 0x400000
+
+#endif /*PTI_H_*/
-- 
1.6.6.1


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

* [PATCH 07/12] n_tracerouter and n_tracesink additions.
  2011-02-09  0:17         ` [PATCH 06/12] PTI header file james_p_freyensee
@ 2011-02-09  0:17           ` james_p_freyensee
  2011-02-09  0:17             ` [PATCH 08/12] n_tracesink ldisc addition james_p_freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch adds line discipline numbers to n_tracerouter and
n_tracesink line disciplines for the Intel-Atom PTI implementation
for mobile devices.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 include/linux/tty.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/linux/tty.h b/include/linux/tty.h
index 54e4eaa..c507f53 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -50,6 +50,8 @@
 #define N_CAIF		20      /* CAIF protocol for talking to modems */
 #define N_GSM0710	21	/* GSM 0710 Mux */
 #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
+#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
+#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
-- 
1.6.6.1


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

* [PATCH 08/12] n_tracesink ldisc addition.
  2011-02-09  0:17           ` [PATCH 07/12] n_tracerouter and n_tracesink additions james_p_freyensee
@ 2011-02-09  0:17             ` james_p_freyensee
  2011-02-09  0:17               ` [PATCH 09/12] n_tracesink header file james_p_freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch adds n_tracesink line discipline driver, which is
part of the Intel-Atom PTI implementation solution.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/n_tracesink.c |  253 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 253 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/n_tracesink.c

diff --git a/drivers/tty/n_tracesink.c b/drivers/tty/n_tracesink.c
new file mode 100644
index 0000000..0d072e3
--- /dev/null
+++ b/drivers/tty/n_tracesink.c
@@ -0,0 +1,253 @@
+/*
+ *  n_tracesink.c - Trace data router and sink path through tty space.
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The trace sink uses the Linux line discipline framework to receive
+ * trace data coming from the PTI source line discipline driver
+ * to a user-desired tty port, like USB.
+ * This is to provide a way to extract modem trace data on
+ * devices that do not have a PTI HW module, or just need modem
+ * trace data to come out of a different HW output port.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <asm-generic/bug.h>
+#include <linux/n_tracesink.h>
+
+/* Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracesink"
+
+/* there is a quirk with this ldisc is he can write data
+ * to a tty from anyone calling his kernel API, which
+ * meets customer requirements in the drivers/misc/pti.c
+ * project.  So he needs to know when he can and cannot write when
+ * the API is called. In theory, the API can be called
+ * after an init() but before a successful open() which
+ * would crash the system if tty is not checked.
+ */
+static struct tty_struct *this_tty;
+static DEFINE_MUTEX(writelock);
+
+/**
+ * n_tracesink_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success,
+ *      -EFAULT = couldn't get a tty kref n_tracesink will sit
+ *       on top of
+ *      -EEXIST = open() called successfully once and it cannot
+ *      be called again.
+ *
+ * Caveats: open() should only be successful the first time a
+ * SW entity calls it.
+ */
+static int n_tracesink_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&writelock);
+	if (this_tty == NULL) {
+
+		this_tty = tty_kref_get(tty);
+
+		if (this_tty == NULL)
+			retval = -EFAULT;
+		else {
+			tty->disc_data = this_tty;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&writelock);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracesink_close(struct tty_struct *tty)
+{
+
+	tty_driver_flush_buffer(tty);
+
+	mutex_lock(&writelock);
+	tty_kref_put(this_tty);
+	this_tty = NULL;
+	mutex_unlock(&writelock);
+
+	tty->disc_data = NULL;
+}
+
+/**
+ * n_tracesink_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracesink_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracesink_read(struct tty_struct *tty, struct file *file,
+				unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracesink_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracesink_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracesink_write(struct tty_struct *tty, struct file *file,
+				 const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ *  mipi_pti_sinkdata() - Kernel API function used to route
+ *			trace debugging data to user-defined
+ *			port like USB.
+ *
+ * @buf:   Trace debuging data buffer to write to tty target
+ *         port. Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         return with no write occuring.
+ *
+ * Caveat: If this line discipline does not set the tty it sits
+ * on top of via an open() call, this API function will not
+ * call the tty's write() call because it will have no pointer
+ * to call the write().
+ */
+
+void n_tracesink_datadrain(u8 *cp, int count)
+{
+	mutex_lock(&writelock);
+
+	if ((cp != NULL) && (count > 0) && (this_tty != NULL))
+		this_tty->ops->write(this_tty, cp, count);
+
+	mutex_unlock(&writelock);
+}
+EXPORT_SYMBOL_GPL(n_tracesink_datadrain);
+
+/* Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+/*
+ * tty_ldisc function operations for this driver.
+ */
+static struct tty_ldisc_ops tty_n_tracesink = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracesink_open,
+	.close		= n_tracesink_close,
+	.read		= n_tracesink_read,
+	.write		= n_tracesink_write
+};
+
+/**
+ * n_tracesink_init-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracesink_init(void)
+{
+	int retval;
+
+	/* Note N_TRACESINK is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
+
+	if (retval < 0)
+		pr_err("%s: Registration failed: %d\n",
+					__func__, retval);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_exit -	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracesink_exit(void)
+{
+	int retval;
+
+	retval = tty_unregister_ldisc(N_TRACESINK);
+
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n",
+					__func__,  retval);
+}
+
+module_init(n_tracesink_init);
+module_exit(n_tracesink_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACESINK);
+MODULE_DESCRIPTION("Trace sink ldisc driver");
-- 
1.6.6.1


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

* [PATCH 09/12] n_tracesink header file.
  2011-02-09  0:17             ` [PATCH 08/12] n_tracesink ldisc addition james_p_freyensee
@ 2011-02-09  0:17               ` james_p_freyensee
  2011-02-09  0:17                 ` [PATCH 10/12] n_tracerouter ldisc driver james_p_freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This header file allows the n_tracerouter to send it's information
to the n_tracesink ldisc driver.  It's part of the Intel-Atom
PTI implementation solution.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 include/linux/n_tracesink.h |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/n_tracesink.h

diff --git a/include/linux/n_tracesink.h b/include/linux/n_tracesink.h
new file mode 100644
index 0000000..b1a3ad8
--- /dev/null
+++ b/include/linux/n_tracesink.h
@@ -0,0 +1,32 @@
+/*
+ *  n_tracesink.h - Kernel driver API to route trace data in kernel space.
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * The implementation of the function seen in this file can be found in
+ * char/n_tracesink.c
+ */
+
+#ifndef N_TRACESINK_H_
+#define N_TRACESINK_H_
+
+void n_tracesink_datadrain(u8 *cp, int count);
+
+#endif
-- 
1.6.6.1


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

* [PATCH 10/12] n_tracerouter ldisc driver.
  2011-02-09  0:17               ` [PATCH 09/12] n_tracesink header file james_p_freyensee
@ 2011-02-09  0:17                 ` james_p_freyensee
  2011-02-09  0:17                   ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig james_p_freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch adds the n_tracerouter ldisc driver.  It is part
of the Intel-Atom PTI implementation solution.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/n_tracerouter.c |  264 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 264 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/n_tracerouter.c

diff --git a/drivers/tty/n_tracerouter.c b/drivers/tty/n_tracerouter.c
new file mode 100644
index 0000000..1bb8c9e
--- /dev/null
+++ b/drivers/tty/n_tracerouter.c
@@ -0,0 +1,264 @@
+/*
+ *  n_tracerouter.c - Trace data router through tty space
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This trace router uses the Linux line discipline framework to route
+ * trace data coming from a HW Modem to a PTI (Parallel Trace Module) port.
+ * The solution is not specific to a HW modem and this line disciple can
+ * be used to route any stream of data in kernel space.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <asm-generic/bug.h>
+#include <linux/n_tracesink.h>
+
+/* Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracerouter"
+
+/* struct to hold private configuration data for this ldisc.
+ * opencalled is used to hold if this ldisc has been opened.
+ * kref_tty holds the tty reference the ldisc sits on top of.
+ */
+struct tracerouter_data {
+	u8 opencalled;
+	struct tty_struct *kref_tty;
+};
+static struct tracerouter_data *tr_data;
+
+/* lock for ioctl() setting of tracerouter_data values */
+static DEFINE_MUTEX(routelock);
+
+/**
+ * tracerouter_alloc
+ *
+ * Allocates the structure needed for this ldisc.
+ */
+static struct tracerouter_data *tracerouter_alloc(void)
+{
+	struct tracerouter_data *tptr = kzalloc(
+					sizeof(struct tracerouter_data),
+					GFP_KERNEL);
+	if (tptr == NULL)
+		return NULL;
+	tptr->opencalled = 0;
+	return tptr;
+}
+
+/**
+ * n_tracerouter_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success.
+ *
+ * Caveats: This should only be opened one time per SW entity.
+ */
+static int n_tracerouter_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&routelock);
+	if (tr_data->opencalled == 0) {
+
+		tr_data->kref_tty = tty_kref_get(tty);
+		if (tr_data->kref_tty == NULL)
+			retval = -EFAULT;
+		else {
+			tr_data->opencalled = 1;
+			tty->disc_data      = tr_data;
+			tty->receive_room   = RECEIVE_ROOM;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&routelock);
+	return retval;
+}
+
+/**
+ * n_tracerouter_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracerouter_close(struct tty_struct *tty)
+{
+	struct tracerouter_data *tptr = tty->disc_data;
+
+	WARN_ON(tptr->kref_tty != tr_data->kref_tty);
+	tty_driver_flush_buffer(tty);
+	mutex_lock(&routelock);
+	tty_kref_put(tr_data->kref_tty);
+	tr_data->kref_tty = NULL;
+	tr_data->opencalled = 0;
+	tty->disc_data = NULL;
+	mutex_unlock(&routelock);
+}
+
+/**
+ * n_tracerouter_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracerouter_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracerouter_read(struct tty_struct *tty, struct file *file,
+				  unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracerouter_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracerouter_write(struct tty_struct *tty, struct file *file,
+				   const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_receivebuf() - Routing function for driver.
+ * @tty: terminal device passed into the ldisc.  It's assumed
+ *       tty will never be NULL.
+ * @cp:  buffer, block of characters to be eventually read by
+ *       someone, somewhere (user read() call or some kernel function).
+ * @fp:  flag buffer.
+ * @count: number of characters (aka, bytes) in cp.
+ *
+ * This function takes the input buffer, cp, and passes it to
+ * an external API function for processing.
+ */
+static void n_tracerouter_receivebuf(struct tty_struct *tty,
+					const unsigned char *cp,
+					char *fp, int count)
+{
+	mutex_lock(&routelock);
+	n_tracesink_datadrain((u8 *) cp, count);
+	mutex_unlock(&routelock);
+}
+
+/* Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+static struct tty_ldisc_ops tty_ptirouter_ldisc = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracerouter_open,
+	.close		= n_tracerouter_close,
+	.read		= n_tracerouter_read,
+	.write		= n_tracerouter_write,
+	.receive_buf	= n_tracerouter_receivebuf
+};
+
+/**
+ * n_tracerouter_init		-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracerouter_init(void)
+{
+	int retval;
+
+	tr_data = tracerouter_alloc();
+	if (tr_data == NULL)
+		return -ENOMEM;
+
+	/* Note N_TRACEROUTER is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACEROUTER, &tty_ptirouter_ldisc);
+	if (retval < 0) {
+		pr_err("%s: Registration failed: %d\n",
+					__func__, retval);
+		kfree(tr_data);
+	}
+	return retval;
+}
+
+/**
+ * n_tracerouter_exit -	-	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracerouter_exit(void)
+{
+	int retval;
+
+	kfree(tr_data);
+	retval = tty_unregister_ldisc(N_TRACEROUTER);
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n",
+					__func__,  retval);
+}
+
+module_init(n_tracerouter_init);
+module_exit(n_tracerouter_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACEROUTER);
+MODULE_DESCRIPTION("Trace router ldisc driver");
-- 
1.6.6.1


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

* [PATCH 11/12] n_tracerouter and n_tracesink Kconfig.
  2011-02-09  0:17                 ` [PATCH 10/12] n_tracerouter ldisc driver james_p_freyensee
@ 2011-02-09  0:17                   ` james_p_freyensee
  2011-02-09  0:17                     ` [PATCH 12/12] n_tracerouter and n_tracesink Makefile addition james_p_freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch allows n_tracerouter and n_tracesink ldisc drivers
to be configured in menuconfig.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/char/Kconfig |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 43d3395..02b9be2 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -289,6 +289,38 @@ config N_GSM
 	  This line discipline provides support for the GSM MUX protocol and
 	  presents the mux as a set of 61 individual tty devices.
 
+config TRACE_ROUTER
+        tristate "Trace data router for MIPI P1149.7 cJTAG standard"
+                depends on TRACE_SINK
+                default Y
+        ---help---
+          The trace router uses the Linux tty line discipline framework to
+          route trace data coming from a tty port (say UART for example) to
+           the trace sink line discipline driver and to another tty port(say USB).
+           This is part of a solution for the MIPI P1149.7, compact JTAG,
+           standard, which is for debugging mobile devices. The PTI driver in
+           drivers/misc/pti.c defines the majority of this MIPI solution.
+
+          You should select this driver if the target kernel is meant for
+          a mobile device containing a modem.  Then you will need to select
+          "Trace data sink for MIPI P1149.7 cJTAG standard" line discipline
+          driver.
+
+config TRACE_SINK
+        tristate "Trace data sink for MIPI P1149.7 cJTAG standard"
+                default Y
+        ---help---
+          The trace sink uses the Linux line discipline framework to receive
+          trace data coming from the trace router line discipline driver
+          to a user-defined tty port target, like USB.
+          This is to provide a way to extract modem trace data on
+          devices that do not have a PTI HW module, or just need modem
+          trace data to come out of a different HW output port.
+          This is part of a solution for the P1149.7, compact JTAG, standard.
+
+          If you select this option, you need to select
+          "Trace data router for MIPI P1149.7 cJTAG standard".
+
 config RISCOM8
 	tristate "SDL RISCom/8 card support"
 	depends on SERIAL_NONSTANDARD
-- 
1.6.6.1


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

* [PATCH 12/12] n_tracerouter and n_tracesink Makefile addition.
  2011-02-09  0:17                   ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig james_p_freyensee
@ 2011-02-09  0:17                     ` james_p_freyensee
  2011-02-09  0:19                       ` james_p_freyensee
       [not found]                       ` <57934.10.23.16.85.1297210742.squirrel@linux.intel.com>
  0 siblings, 2 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows n_tracerouter and n_tracesink to be compiled in the
Linux kernel.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/Makefile |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index c43ef48..8c56ffd 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -7,5 +7,7 @@ obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
 obj-$(CONFIG_N_HDLC)		+= n_hdlc.o
 obj-$(CONFIG_N_GSM)		+= n_gsm.o
 obj-$(CONFIG_R3964)		+= n_r3964.o
+obj-$(CONFIG_TRACE_ROUTER)      += n_tracerouter.o
+obj-$(CONFIG_TRACE_SINK)        += n_tracesink.o
 
 obj-y				+= vt/
-- 
1.6.6.1


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

* Re: [PATCH 12/12] n_tracerouter and n_tracesink Makefile addition.
  2011-02-09  0:17                     ` [PATCH 12/12] n_tracerouter and n_tracesink Makefile addition james_p_freyensee
@ 2011-02-09  0:19                       ` james_p_freyensee
       [not found]                       ` <57934.10.23.16.85.1297210742.squirrel@linux.intel.com>
  1 sibling, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:19 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, james_p_freyensee

Apologies for this duplicate email; I think that was the email that I sent
yesterday of it finally going out :-/.

> From: J Freyensee <james_p_freyensee@linux.intel.com>
>
> This allows n_tracerouter and n_tracesink to be compiled in the
> Linux kernel.
>
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> ---
>  drivers/tty/Makefile |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
> index c43ef48..8c56ffd 100644
> --- a/drivers/tty/Makefile
> +++ b/drivers/tty/Makefile
> @@ -7,5 +7,7 @@ obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
>  obj-$(CONFIG_N_HDLC)		+= n_hdlc.o
>  obj-$(CONFIG_N_GSM)		+= n_gsm.o
>  obj-$(CONFIG_R3964)		+= n_r3964.o
> +obj-$(CONFIG_TRACE_ROUTER)      += n_tracerouter.o
> +obj-$(CONFIG_TRACE_SINK)        += n_tracesink.o
>
>  obj-y				+= vt/
> --
> 1.6.6.1
>
>


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

* PTI- PLEASE IGNORE SECOND DUPLICATE 12 PATCH SET
       [not found]                       ` <57934.10.23.16.85.1297210742.squirrel@linux.intel.com>
@ 2011-02-09  0:34                         ` james_p_freyensee
  0 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-09  0:34 UTC (permalink / raw)
  To: gregkh; +Cc: james_p_freyensee, linux-kernel, suhail.ahmed

Sincere apologies for these duplicate patches; I think that was the email
that I sent yesterday of it finally going out :-/.

J Freyensee


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

* Re: [PATCH 01/12] export kernel call get_task_comm()
  2011-02-08 20:36             ` Alan Cox
@ 2011-02-15 10:57               ` Christoph Hellwig
  0 siblings, 0 replies; 171+ messages in thread
From: Christoph Hellwig @ 2011-02-15 10:57 UTC (permalink / raw)
  To: Alan Cox
  Cc: Christoph Hellwig, james_p_freyensee, gregkh, linux-kernel, suhail.ahmed

On Tue, Feb 08, 2011 at 08:36:02PM +0000, Alan Cox wrote:
> Which is a detail you really don't want to leak out of the proper
> abstraction use. I really don't see why you are advocating bad
> programming practice - everything else uses the abstraction properly,
> this just happens to be the first modular case that wants to behave
> properly.

Just grep for current->comm uses and get_task_comm uses and see that
this is not true.


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

* Re: [PATCH 06/12] PTI header file.
  2011-02-08 19:34             ` [PATCH 06/12] PTI header file james_p_freyensee
  2011-02-08 19:34               ` [PATCH 07/12] n_tracerouter and n_tracesink additions james_p_freyensee
@ 2011-02-17 19:20               ` Greg KH
  2011-02-17 19:41                 ` J Freyensee
  1 sibling, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-02-17 19:20 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed

On Tue, Feb 08, 2011 at 11:34:51AM -0800, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This adds PTI header information for the PTI project.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> ---
>  include/linux/pti.h |   38 ++++++++++++++++++++++++++++++++++++++

Why does this have to be in include/linux/?  What other files use it?

>  1 files changed, 38 insertions(+), 0 deletions(-)
>  create mode 100644 include/linux/pti.h
> 
> diff --git a/include/linux/pti.h b/include/linux/pti.h
> new file mode 100644
> index 0000000..4b1c9f6
> --- /dev/null
> +++ b/include/linux/pti.h
> @@ -0,0 +1,38 @@
> +/*
> + *  Copyright (C) Intel 2010
> + *  Ken Mills <ken.k.mills@intel.com>

That's nice, where is Ken's signed-off-by?  We need that please.

> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
> + * USA

This paragraph is not needed, please remove it unless you are willing to
keep up with the FSF's office moves for the next 40+ years.

Same goes for this paragraph on other files in this patchset, please
remove it.

> + *
> + */
> +
> +#ifndef PTI_H_
> +#define PTI_H_
> +
> +/* basic structure used as a write address to the PTI HW */
> +struct masterchannel {

Pretty generic structure name, please prefix it with "pti_"

> +	u8 master;
> +	u8 channel;
> +};
> +
> +/* the following functions are defined in misc/pti.c */
> +void mipi_pti_writedata(struct masterchannel *mc, u8 *cp, int count);

"cp"?

> +struct masterchannel *mipi_request_masterchannel(u8 kerneluser);

kerneluser?

> +void mipi_release_masterchannel(struct masterchannel *mc);

"Mipi"?  What's that?

> +
> +#define APERTURE_14 0x3800000
> +#define APERTURE_LEN 0x400000

What are these for?

> +
> +#endif /*PTI_H_*/
> -- 
> 1.6.6.1

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

* Re: [PATCH 04/12] PTI Kconfig change in misc.
  2011-02-08 19:34         ` [PATCH 04/12] PTI Kconfig change in misc james_p_freyensee
  2011-02-08 19:34           ` [PATCH 05/12] PTI misc Makefile addition james_p_freyensee
@ 2011-02-17 19:20           ` Greg KH
  2011-02-17 19:35             ` J Freyensee
  1 sibling, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-02-17 19:20 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed

On Tue, Feb 08, 2011 at 11:34:49AM -0800, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This adds the Intel PTI Kconfig option.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> ---
>  drivers/misc/Kconfig |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 4d073f1..f8076f1 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -136,6 +136,18 @@ config PHANTOM
>  	  If you choose to build module, its name will be phantom. If unsure,
>  	  say N here.
>  
> +config INTEL_MID_PTI

Don't add new Kconfig options when there is no code for it yet to use
it.  Merge this with the Makefile patch.

thanks,

greg k-h

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

* Re: [PATCH 07/12] n_tracerouter and n_tracesink additions.
  2011-02-08 19:34               ` [PATCH 07/12] n_tracerouter and n_tracesink additions james_p_freyensee
  2011-02-08 19:34                 ` [PATCH 08/12] n_tracesink ldisc addition james_p_freyensee
@ 2011-02-17 19:21                 ` Greg KH
  2011-02-17 19:43                   ` J Freyensee
  1 sibling, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-02-17 19:21 UTC (permalink / raw)
  To: james_p_freyensee, Alan Cox; +Cc: gregkh, linux-kernel, suhail.ahmed

On Tue, Feb 08, 2011 at 11:34:52AM -0800, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This patch adds line discipline numbers to n_tracerouter and
> n_tracesink line disciplines for the Intel-Atom PTI implementation
> for mobile devices.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> ---
>  include/linux/tty.h |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/tty.h b/include/linux/tty.h
> index 54e4eaa..c507f53 100644
> --- a/include/linux/tty.h
> +++ b/include/linux/tty.h
> @@ -50,6 +50,8 @@
>  #define N_CAIF		20      /* CAIF protocol for talking to modems */
>  #define N_GSM0710	21	/* GSM 0710 Mux */
>  #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
> +#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
> +#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */

Two new ones?  Really?  Alan, no objection from you on this?

thanks,

greg k-h

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

* Re: [PATCH 09/12] n_tracesink header file.
  2011-02-08 19:34                   ` [PATCH 09/12] n_tracesink header file james_p_freyensee
  2011-02-08 19:34                     ` [PATCH 10/12] n_tracerouter ldisc driver james_p_freyensee
@ 2011-02-17 19:23                     ` Greg KH
  2011-02-17 19:45                       ` J Freyensee
  1 sibling, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-02-17 19:23 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed

On Tue, Feb 08, 2011 at 11:34:54AM -0800, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This header file allows the n_tracerouter to send it's information
> to the n_tracesink ldisc driver.  It's part of the Intel-Atom
> PTI implementation solution.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> ---
>  include/linux/n_tracesink.h |   32 ++++++++++++++++++++++++++++++++

Why is this in include/linux/ ?

thanks,

greg k-h

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

* Re: [PATCH 04/12] PTI Kconfig change in misc.
  2011-02-17 19:20           ` [PATCH 04/12] PTI Kconfig change in misc Greg KH
@ 2011-02-17 19:35             ` J Freyensee
  2011-02-17 19:45               ` Greg KH
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-02-17 19:35 UTC (permalink / raw)
  To: Greg KH; +Cc: gregkh, linux-kernel, suhail.ahmed

On Thu, 2011-02-17 at 11:20 -0800, Greg KH wrote:
> On Tue, Feb 08, 2011 at 11:34:49AM -0800, james_p_freyensee@linux.intel.com wrote:
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > This adds the Intel PTI Kconfig option.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > ---
> >  drivers/misc/Kconfig |   12 ++++++++++++
> >  1 files changed, 12 insertions(+), 0 deletions(-)
> > 
> > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > index 4d073f1..f8076f1 100644
> > --- a/drivers/misc/Kconfig
> > +++ b/drivers/misc/Kconfig
> > @@ -136,6 +136,18 @@ config PHANTOM
> >  	  If you choose to build module, its name will be phantom. If unsure,
> >  	  say N here.
> >  
> > +config INTEL_MID_PTI
> 
> Don't add new Kconfig options when there is no code for it yet to use
> it.  Merge this with the Makefile patch.
> 

I do not quite understand the problem.  The code for this Kconfig is
~/drivers/misc/pti.c and it was patch 3/12.  I tested that in 'make
menuconfig' the kernel turns the compile option on and off fine.

What needs to be fixed here?

> thanks,
> 
> greg k-h



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

* Re: [PATCH 06/12] PTI header file.
  2011-02-17 19:20               ` [PATCH 06/12] PTI header file Greg KH
@ 2011-02-17 19:41                 ` J Freyensee
  2011-02-17 19:55                   ` Greg KH
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-02-17 19:41 UTC (permalink / raw)
  To: Greg KH; +Cc: gregkh, linux-kernel, suhail.ahmed

On Thu, 2011-02-17 at 11:20 -0800, Greg KH wrote:
> On Tue, Feb 08, 2011 at 11:34:51AM -0800, james_p_freyensee@linux.intel.com wrote:
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > This adds PTI header information for the PTI project.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > ---
> >  include/linux/pti.h |   38 ++++++++++++++++++++++++++++++++++++++
> 
> Why does this have to be in include/linux/?  What other files use it?
> 
> >  1 files changed, 38 insertions(+), 0 deletions(-)
> >  create mode 100644 include/linux/pti.h
> > 
> > diff --git a/include/linux/pti.h b/include/linux/pti.h
> > new file mode 100644
> > index 0000000..4b1c9f6
> > --- /dev/null
> > +++ b/include/linux/pti.h
> > @@ -0,0 +1,38 @@
> > +/*
> > + *  Copyright (C) Intel 2010
> > + *  Ken Mills <ken.k.mills@intel.com>
> 
> That's nice, where is Ken's signed-off-by?  We need that please.
> 
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program; if not, write to the Free Software
> > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
> > + * USA
> 
> This paragraph is not needed, please remove it unless you are willing to
> keep up with the FSF's office moves for the next 40+ years.
> 
> Same goes for this paragraph on other files in this patchset, please
> remove it.
> 
> > + *
> > + */
> > +
> > +#ifndef PTI_H_
> > +#define PTI_H_
> > +
> > +/* basic structure used as a write address to the PTI HW */
> > +struct masterchannel {
> 
> Pretty generic structure name, please prefix it with "pti_"
> 

no problem, I'll fix all these.

> > +	u8 master;
> > +	u8 channel;
> > +};
> > +
> > +/* the following functions are defined in misc/pti.c */
> > +void mipi_pti_writedata(struct masterchannel *mc, u8 *cp, int count);
> 
> "cp"?
> 

All of the questions concerning these variables are described in pti.c.
Should have the function header comments been copied/moved here??

> > +struct masterchannel *mipi_request_masterchannel(u8 kerneluser);
> 
> kerneluser?
> 
> > +void mipi_release_masterchannel(struct masterchannel *mc);
> 
> "Mipi"?  What's that?

'mipi' is the standard body for the PTI standard.  It's an acronymn that
does not stand for anything other than the Organization controlling the
standard: http://www.mipi.org/about-mipi/frequently-asked-questions#q2

> 
> > +
> > +#define APERTURE_14 0x3800000
> > +#define APERTURE_LEN 0x400000

> What are these for?
> 

Write address and write length for the PTI but I can add that.

Thanks,
jay

> > +
> > +#endif /*PTI_H_*/
> > -- 
> > 1.6.6.1



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

* Re: [PATCH 07/12] n_tracerouter and n_tracesink additions.
  2011-02-17 19:21                 ` [PATCH 07/12] n_tracerouter and n_tracesink additions Greg KH
@ 2011-02-17 19:43                   ` J Freyensee
  2011-02-17 19:54                     ` Greg KH
  2011-02-24 11:52                     ` Alan Cox
  0 siblings, 2 replies; 171+ messages in thread
From: J Freyensee @ 2011-02-17 19:43 UTC (permalink / raw)
  To: Greg KH; +Cc: Alan Cox, gregkh, linux-kernel, suhail.ahmed

On Thu, 2011-02-17 at 11:21 -0800, Greg KH wrote:
> On Tue, Feb 08, 2011 at 11:34:52AM -0800, james_p_freyensee@linux.intel.com wrote:
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > This patch adds line discipline numbers to n_tracerouter and
> > n_tracesink line disciplines for the Intel-Atom PTI implementation
> > for mobile devices.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > ---
> >  include/linux/tty.h |    2 ++
> >  1 files changed, 2 insertions(+), 0 deletions(-)
> > 
> > diff --git a/include/linux/tty.h b/include/linux/tty.h
> > index 54e4eaa..c507f53 100644
> > --- a/include/linux/tty.h
> > +++ b/include/linux/tty.h
> > @@ -50,6 +50,8 @@
> >  #define N_CAIF		20      /* CAIF protocol for talking to modems */
> >  #define N_GSM0710	21	/* GSM 0710 Mux */
> >  #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
> > +#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
> > +#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
> 
> Two new ones?  Really?  Alan, no objection from you on this?

I'll let Alan chime in, but I did have Alan review this code before I
submitted here.

Jay

> thanks,
> 
> greg k-h



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

* Re: [PATCH 04/12] PTI Kconfig change in misc.
  2011-02-17 19:35             ` J Freyensee
@ 2011-02-17 19:45               ` Greg KH
  0 siblings, 0 replies; 171+ messages in thread
From: Greg KH @ 2011-02-17 19:45 UTC (permalink / raw)
  To: J Freyensee; +Cc: Greg KH, linux-kernel, suhail.ahmed

On Thu, Feb 17, 2011 at 11:35:51AM -0800, J Freyensee wrote:
> On Thu, 2011-02-17 at 11:20 -0800, Greg KH wrote:
> > On Tue, Feb 08, 2011 at 11:34:49AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > 
> > > This adds the Intel PTI Kconfig option.
> > > 
> > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > ---
> > >  drivers/misc/Kconfig |   12 ++++++++++++
> > >  1 files changed, 12 insertions(+), 0 deletions(-)
> > > 
> > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > > index 4d073f1..f8076f1 100644
> > > --- a/drivers/misc/Kconfig
> > > +++ b/drivers/misc/Kconfig
> > > @@ -136,6 +136,18 @@ config PHANTOM
> > >  	  If you choose to build module, its name will be phantom. If unsure,
> > >  	  say N here.
> > >  
> > > +config INTEL_MID_PTI
> > 
> > Don't add new Kconfig options when there is no code for it yet to use
> > it.  Merge this with the Makefile patch.
> > 
> 
> I do not quite understand the problem.  The code for this Kconfig is
> ~/drivers/misc/pti.c and it was patch 3/12.  I tested that in 'make
> menuconfig' the kernel turns the compile option on and off fine.
> 
> What needs to be fixed here?

Merge it with your Makefile patch, it doesn't need to be separate.

thanks,

greg k-h

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

* Re: [PATCH 09/12] n_tracesink header file.
  2011-02-17 19:23                     ` [PATCH 09/12] n_tracesink header file Greg KH
@ 2011-02-17 19:45                       ` J Freyensee
  2011-02-17 19:54                         ` Greg KH
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-02-17 19:45 UTC (permalink / raw)
  To: Greg KH; +Cc: gregkh, linux-kernel, suhail.ahmed

On Thu, 2011-02-17 at 11:23 -0800, Greg KH wrote:
> On Tue, Feb 08, 2011 at 11:34:54AM -0800, james_p_freyensee@linux.intel.com wrote:
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > This header file allows the n_tracerouter to send it's information
> > to the n_tracesink ldisc driver.  It's part of the Intel-Atom
> > PTI implementation solution.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > ---
> >  include/linux/n_tracesink.h |   32 ++++++++++++++++++++++++++++++++
> 
> Why is this in include/linux/ ?
> 

I thought this was the best place to stick this .h file.  I'd be happy
to change locations based off of your suggestion.

Thanks,
jay

> thanks,
> 
> greg k-h



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

* Re: [PATCH 09/12] n_tracesink header file.
  2011-02-17 19:45                       ` J Freyensee
@ 2011-02-17 19:54                         ` Greg KH
  2011-02-17 20:10                           ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-02-17 19:54 UTC (permalink / raw)
  To: J Freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed

On Thu, Feb 17, 2011 at 11:45:15AM -0800, J Freyensee wrote:
> On Thu, 2011-02-17 at 11:23 -0800, Greg KH wrote:
> > On Tue, Feb 08, 2011 at 11:34:54AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > 
> > > This header file allows the n_tracerouter to send it's information
> > > to the n_tracesink ldisc driver.  It's part of the Intel-Atom
> > > PTI implementation solution.
> > > 
> > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > ---
> > >  include/linux/n_tracesink.h |   32 ++++++++++++++++++++++++++++++++
> > 
> > Why is this in include/linux/ ?
> > 
> 
> I thought this was the best place to stick this .h file.  I'd be happy
> to change locations based off of your suggestion.

Why do you need a .h file at all?  Who is using it?

thanks,

greg k-h

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

* Re: [PATCH 07/12] n_tracerouter and n_tracesink additions.
  2011-02-17 19:43                   ` J Freyensee
@ 2011-02-17 19:54                     ` Greg KH
  2011-02-17 20:11                       ` J Freyensee
  2011-02-24 11:52                     ` Alan Cox
  1 sibling, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-02-17 19:54 UTC (permalink / raw)
  To: J Freyensee; +Cc: Alan Cox, gregkh, linux-kernel, suhail.ahmed

On Thu, Feb 17, 2011 at 11:43:26AM -0800, J Freyensee wrote:
> On Thu, 2011-02-17 at 11:21 -0800, Greg KH wrote:
> > On Tue, Feb 08, 2011 at 11:34:52AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > 
> > > This patch adds line discipline numbers to n_tracerouter and
> > > n_tracesink line disciplines for the Intel-Atom PTI implementation
> > > for mobile devices.
> > > 
> > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > ---
> > >  include/linux/tty.h |    2 ++
> > >  1 files changed, 2 insertions(+), 0 deletions(-)
> > > 
> > > diff --git a/include/linux/tty.h b/include/linux/tty.h
> > > index 54e4eaa..c507f53 100644
> > > --- a/include/linux/tty.h
> > > +++ b/include/linux/tty.h
> > > @@ -50,6 +50,8 @@
> > >  #define N_CAIF		20      /* CAIF protocol for talking to modems */
> > >  #define N_GSM0710	21	/* GSM 0710 Mux */
> > >  #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
> > > +#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
> > > +#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
> > 
> > Two new ones?  Really?  Alan, no objection from you on this?
> 
> I'll let Alan chime in, but I did have Alan review this code before I
> submitted here.

Hm, I don't see a "Reviewed-by:" line on the patch...

thanks,

greg k-h

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

* Re: [PATCH 06/12] PTI header file.
  2011-02-17 19:41                 ` J Freyensee
@ 2011-02-17 19:55                   ` Greg KH
  2011-02-17 20:13                     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-02-17 19:55 UTC (permalink / raw)
  To: J Freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed

On Thu, Feb 17, 2011 at 11:41:55AM -0800, J Freyensee wrote:
> On Thu, 2011-02-17 at 11:20 -0800, Greg KH wrote:
> > On Tue, Feb 08, 2011 at 11:34:51AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > 
> > > This adds PTI header information for the PTI project.
> > > 
> > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > ---
> > >  include/linux/pti.h |   38 ++++++++++++++++++++++++++++++++++++++
> > 
> > Why does this have to be in include/linux/?  What other files use it?
> > 
> > >  1 files changed, 38 insertions(+), 0 deletions(-)
> > >  create mode 100644 include/linux/pti.h
> > > 
> > > diff --git a/include/linux/pti.h b/include/linux/pti.h
> > > new file mode 100644
> > > index 0000000..4b1c9f6
> > > --- /dev/null
> > > +++ b/include/linux/pti.h
> > > @@ -0,0 +1,38 @@
> > > +/*
> > > + *  Copyright (C) Intel 2010
> > > + *  Ken Mills <ken.k.mills@intel.com>
> > 
> > That's nice, where is Ken's signed-off-by?  We need that please.
> > 
> > > + *
> > > + * This program is free software; you can redistribute it and/or modify
> > > + * it under the terms of the GNU General Public License version 2 as
> > > + * published by the Free Software Foundation.
> > > + *
> > > + * This program is distributed in the hope that it will be useful,
> > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > + * GNU General Public License for more details.
> > > + *
> > > + * You should have received a copy of the GNU General Public License
> > > + * along with this program; if not, write to the Free Software
> > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
> > > + * USA
> > 
> > This paragraph is not needed, please remove it unless you are willing to
> > keep up with the FSF's office moves for the next 40+ years.
> > 
> > Same goes for this paragraph on other files in this patchset, please
> > remove it.
> > 
> > > + *
> > > + */
> > > +
> > > +#ifndef PTI_H_
> > > +#define PTI_H_
> > > +
> > > +/* basic structure used as a write address to the PTI HW */
> > > +struct masterchannel {
> > 
> > Pretty generic structure name, please prefix it with "pti_"
> > 
> 
> no problem, I'll fix all these.
> 
> > > +	u8 master;
> > > +	u8 channel;
> > > +};
> > > +
> > > +/* the following functions are defined in misc/pti.c */
> > > +void mipi_pti_writedata(struct masterchannel *mc, u8 *cp, int count);
> > 
> > "cp"?
> > 
> 
> All of the questions concerning these variables are described in pti.c.
> Should have the function header comments been copied/moved here??

No, you are right, as long as you are using the proper kerneldoc
structure for the functions there, all is fine.

> > > +struct masterchannel *mipi_request_masterchannel(u8 kerneluser);
> > 
> > kerneluser?
> > 
> > > +void mipi_release_masterchannel(struct masterchannel *mc);
> > 
> > "Mipi"?  What's that?
> 
> 'mipi' is the standard body for the PTI standard.  It's an acronymn that
> does not stand for anything other than the Organization controlling the
> standard: http://www.mipi.org/about-mipi/frequently-asked-questions#q2

Why not just use "pti" as that's what you are dealing with here.
Otherwise people are going to be confused.

thanks,

greg k-h

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

* Re: [PATCH 09/12] n_tracesink header file.
  2011-02-17 19:54                         ` Greg KH
@ 2011-02-17 20:10                           ` J Freyensee
  2011-02-17 21:43                             ` Greg KH
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-02-17 20:10 UTC (permalink / raw)
  To: Greg KH; +Cc: gregkh, linux-kernel, suhail.ahmed

On Thu, 2011-02-17 at 11:54 -0800, Greg KH wrote:
> On Thu, Feb 17, 2011 at 11:45:15AM -0800, J Freyensee wrote:
> > On Thu, 2011-02-17 at 11:23 -0800, Greg KH wrote:
> > > On Tue, Feb 08, 2011 at 11:34:54AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > 
> > > > This header file allows the n_tracerouter to send it's information
> > > > to the n_tracesink ldisc driver.  It's part of the Intel-Atom
> > > > PTI implementation solution.
> > > > 
> > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > ---
> > > >  include/linux/n_tracesink.h |   32 ++++++++++++++++++++++++++++++++
> > > 
> > > Why is this in include/linux/ ?
> > > 
> > 
> > I thought this was the best place to stick this .h file.  I'd be happy
> > to change locations based off of your suggestion.
> 
> Why do you need a .h file at all?  Who is using it?

The only current module that really uses it is n_tracerouter; however, I
thought sticking this in a .h file made things slightly more modular and
more re-usable, especially for future device driver writers that could
want something like this.

If you would like me to remove this though, I can, just let me know.
Thanks.

> 
> thanks,
> 
> greg k-h



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

* Re: [PATCH 07/12] n_tracerouter and n_tracesink additions.
  2011-02-17 19:54                     ` Greg KH
@ 2011-02-17 20:11                       ` J Freyensee
  0 siblings, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-02-17 20:11 UTC (permalink / raw)
  To: Greg KH; +Cc: Alan Cox, gregkh, linux-kernel, suhail.ahmed

On Thu, 2011-02-17 at 11:54 -0800, Greg KH wrote:
> On Thu, Feb 17, 2011 at 11:43:26AM -0800, J Freyensee wrote:
> > On Thu, 2011-02-17 at 11:21 -0800, Greg KH wrote:
> > > On Tue, Feb 08, 2011 at 11:34:52AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > 
> > > > This patch adds line discipline numbers to n_tracerouter and
> > > > n_tracesink line disciplines for the Intel-Atom PTI implementation
> > > > for mobile devices.
> > > > 
> > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > ---
> > > >  include/linux/tty.h |    2 ++
> > > >  1 files changed, 2 insertions(+), 0 deletions(-)
> > > > 
> > > > diff --git a/include/linux/tty.h b/include/linux/tty.h
> > > > index 54e4eaa..c507f53 100644
> > > > --- a/include/linux/tty.h
> > > > +++ b/include/linux/tty.h
> > > > @@ -50,6 +50,8 @@
> > > >  #define N_CAIF		20      /* CAIF protocol for talking to modems */
> > > >  #define N_GSM0710	21	/* GSM 0710 Mux */
> > > >  #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
> > > > +#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
> > > > +#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
> > > 
> > > Two new ones?  Really?  Alan, no objection from you on this?
> > 
> > I'll let Alan chime in, but I did have Alan review this code before I
> > submitted here.
> 
> Hm, I don't see a "Reviewed-by:" line on the patch...

Good point...I can add this to all patches as Alan reviewed all this
code before-hand.

> 
> thanks,
> 
> greg k-h



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

* Re: [PATCH 06/12] PTI header file.
  2011-02-17 19:55                   ` Greg KH
@ 2011-02-17 20:13                     ` J Freyensee
  0 siblings, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-02-17 20:13 UTC (permalink / raw)
  To: Greg KH; +Cc: gregkh, linux-kernel, suhail.ahmed

On Thu, 2011-02-17 at 11:55 -0800, Greg KH wrote:
> On Thu, Feb 17, 2011 at 11:41:55AM -0800, J Freyensee wrote:
> > On Thu, 2011-02-17 at 11:20 -0800, Greg KH wrote:
> > > On Tue, Feb 08, 2011 at 11:34:51AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > 
> > > > This adds PTI header information for the PTI project.
> > > > 
> > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > ---
> > > >  include/linux/pti.h |   38 ++++++++++++++++++++++++++++++++++++++
> > > 
> > > Why does this have to be in include/linux/?  What other files use it?
> > > 
> > > >  1 files changed, 38 insertions(+), 0 deletions(-)
> > > >  create mode 100644 include/linux/pti.h
> > > > 
> > > > diff --git a/include/linux/pti.h b/include/linux/pti.h
> > > > new file mode 100644
> > > > index 0000000..4b1c9f6
> > > > --- /dev/null
> > > > +++ b/include/linux/pti.h
> > > > @@ -0,0 +1,38 @@
> > > > +/*
> > > > + *  Copyright (C) Intel 2010
> > > > + *  Ken Mills <ken.k.mills@intel.com>
> > > 
> > > That's nice, where is Ken's signed-off-by?  We need that please.
> > > 
> > > > + *
> > > > + * This program is free software; you can redistribute it and/or modify
> > > > + * it under the terms of the GNU General Public License version 2 as
> > > > + * published by the Free Software Foundation.
> > > > + *
> > > > + * This program is distributed in the hope that it will be useful,
> > > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > > + * GNU General Public License for more details.
> > > > + *
> > > > + * You should have received a copy of the GNU General Public License
> > > > + * along with this program; if not, write to the Free Software
> > > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
> > > > + * USA
> > > 
> > > This paragraph is not needed, please remove it unless you are willing to
> > > keep up with the FSF's office moves for the next 40+ years.
> > > 
> > > Same goes for this paragraph on other files in this patchset, please
> > > remove it.
> > > 
> > > > + *
> > > > + */
> > > > +
> > > > +#ifndef PTI_H_
> > > > +#define PTI_H_
> > > > +
> > > > +/* basic structure used as a write address to the PTI HW */
> > > > +struct masterchannel {
> > > 
> > > Pretty generic structure name, please prefix it with "pti_"
> > > 
> > 
> > no problem, I'll fix all these.
> > 
> > > > +	u8 master;
> > > > +	u8 channel;
> > > > +};
> > > > +
> > > > +/* the following functions are defined in misc/pti.c */
> > > > +void mipi_pti_writedata(struct masterchannel *mc, u8 *cp, int count);
> > > 
> > > "cp"?
> > > 
> > 
> > All of the questions concerning these variables are described in pti.c.
> > Should have the function header comments been copied/moved here??
> 
> No, you are right, as long as you are using the proper kerneldoc
> structure for the functions there, all is fine.
> 
> > > > +struct masterchannel *mipi_request_masterchannel(u8 kerneluser);
> > > 
> > > kerneluser?
> > > 
> > > > +void mipi_release_masterchannel(struct masterchannel *mc);
> > > 
> > > "Mipi"?  What's that?
> > 
> > 'mipi' is the standard body for the PTI standard.  It's an acronymn that
> > does not stand for anything other than the Organization controlling the
> > standard: http://www.mipi.org/about-mipi/frequently-asked-questions#q2
> 
> Why not just use "pti" as that's what you are dealing with here.
> Otherwise people are going to be confused.

Good idea, I can change this and re-submit.

Thanks for the review,
Jay

> 
> thanks,
> 
> greg k-h



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

* Re: [PATCH 09/12] n_tracesink header file.
  2011-02-17 20:10                           ` J Freyensee
@ 2011-02-17 21:43                             ` Greg KH
  2011-02-22 20:22                               ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-02-17 21:43 UTC (permalink / raw)
  To: J Freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed

On Thu, Feb 17, 2011 at 12:10:47PM -0800, J Freyensee wrote:
> On Thu, 2011-02-17 at 11:54 -0800, Greg KH wrote:
> > On Thu, Feb 17, 2011 at 11:45:15AM -0800, J Freyensee wrote:
> > > On Thu, 2011-02-17 at 11:23 -0800, Greg KH wrote:
> > > > On Tue, Feb 08, 2011 at 11:34:54AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > 
> > > > > This header file allows the n_tracerouter to send it's information
> > > > > to the n_tracesink ldisc driver.  It's part of the Intel-Atom
> > > > > PTI implementation solution.
> > > > > 
> > > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > ---
> > > > >  include/linux/n_tracesink.h |   32 ++++++++++++++++++++++++++++++++
> > > > 
> > > > Why is this in include/linux/ ?
> > > > 
> > > 
> > > I thought this was the best place to stick this .h file.  I'd be happy
> > > to change locations based off of your suggestion.
> > 
> > Why do you need a .h file at all?  Who is using it?
> 
> The only current module that really uses it is n_tracerouter; however, I
> thought sticking this in a .h file made things slightly more modular and
> more re-usable, especially for future device driver writers that could
> want something like this.
> 
> If you would like me to remove this though, I can, just let me know.

Yes, please remove it.

thanks,

greg k-h

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

* Re: [PATCH 01/12] export kernel call get_task_comm()
  2011-02-08 19:34   ` [PATCH 01/12] export kernel call get_task_comm() james_p_freyensee
  2011-02-08 19:34     ` [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
  2011-02-08 19:38     ` [PATCH 01/12] export kernel call get_task_comm() Christoph Hellwig
@ 2011-02-22 18:38     ` J Freyensee
  2011-02-22 18:41       ` Greg KH
  2 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-02-22 18:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed

Greg:

Is this a patch you will or have already take/taken?  Or do you want me
to re-submit this with the rest of the patches like last time?  

My default is I will re-send you all of these patches with the changes
we talked about last week.

thanks,
jay

On Tue, 2011-02-08 at 11:34 -0800, james_p_freyensee@linux.intel.com
wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This allows drivers who call this function to be compiled modularly.
> Otherwise, a driver who is interested in this type of functionality
> has to implement their own.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> ---
>  fs/exec.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/exec.c b/fs/exec.c
> index c62efcb..7b209f9 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -998,6 +998,7 @@ char *get_task_comm(char *buf, struct task_struct *tsk)
>  	task_unlock(tsk);
>  	return buf;
>  }
> +EXPORT_SYMBOL_GPL(get_task_comm);
>  
>  void set_task_comm(struct task_struct *tsk, char *buf)
>  {



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

* Re: [PATCH 01/12] export kernel call get_task_comm()
  2011-02-22 18:38     ` J Freyensee
@ 2011-02-22 18:41       ` Greg KH
  0 siblings, 0 replies; 171+ messages in thread
From: Greg KH @ 2011-02-22 18:41 UTC (permalink / raw)
  To: J Freyensee; +Cc: linux-kernel, suhail.ahmed

On Tue, Feb 22, 2011 at 10:38:06AM -0800, J Freyensee wrote:
> Greg:
> 
> Is this a patch you will or have already take/taken?  Or do you want me
> to re-submit this with the rest of the patches like last time?  
> 
> My default is I will re-send you all of these patches with the changes
> we talked about last week.

I have not taken any of this patch series, so yes, if you want it
applied, you need to resend it.

thanks,

greg k-h

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

* Re: [PATCH 09/12] n_tracesink header file.
  2011-02-17 21:43                             ` Greg KH
@ 2011-02-22 20:22                               ` J Freyensee
  2011-02-22 20:26                                 ` Greg KH
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-02-22 20:22 UTC (permalink / raw)
  To: Greg KH; +Cc: gregkh, linux-kernel, suhail.ahmed

On Thu, 2011-02-17 at 13:43 -0800, Greg KH wrote:
> On Thu, Feb 17, 2011 at 12:10:47PM -0800, J Freyensee wrote:
> > On Thu, 2011-02-17 at 11:54 -0800, Greg KH wrote:
> > > On Thu, Feb 17, 2011 at 11:45:15AM -0800, J Freyensee wrote:
> > > > On Thu, 2011-02-17 at 11:23 -0800, Greg KH wrote:
> > > > > On Tue, Feb 08, 2011 at 11:34:54AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > > 
> > > > > > This header file allows the n_tracerouter to send it's information
> > > > > > to the n_tracesink ldisc driver.  It's part of the Intel-Atom
> > > > > > PTI implementation solution.
> > > > > > 
> > > > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > > ---
> > > > > >  include/linux/n_tracesink.h |   32 ++++++++++++++++++++++++++++++++
> > > > > 
> > > > > Why is this in include/linux/ ?
> > > > > 
> > > > 
> > > > I thought this was the best place to stick this .h file.  I'd be happy
> > > > to change locations based off of your suggestion.
> > > 
> > > Why do you need a .h file at all?  Who is using it?
> > 
> > The only current module that really uses it is n_tracerouter; however, I
> > thought sticking this in a .h file made things slightly more modular and
> > more re-usable, especially for future device driver writers that could
> > want something like this.
> > 
> > If you would like me to remove this though, I can, just let me know.
> 
> Yes, please remove it.
> 
Greg,

If I remove this file I need to add the function header
n_tracesink_datadrain() that is in this file to n_tracerouter.c.

If I add that function header to n_tracerouter.c then checkpatch.pl
complains that extern should be avoided in .c files.

If I don't have this function header in n_tracerouter.c then it won't
compile at all.

Do you have an alternative suggestion on what I should do here?  It
appears the best solution is for me to keep this .h file considering the
constraints.

Thanks,
Jay

> thanks,
> 
> greg k-h



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

* Re: [PATCH 09/12] n_tracesink header file.
  2011-02-22 20:22                               ` J Freyensee
@ 2011-02-22 20:26                                 ` Greg KH
  2011-02-22 22:55                                   ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-02-22 20:26 UTC (permalink / raw)
  To: J Freyensee; +Cc: Greg KH, linux-kernel, suhail.ahmed

On Tue, Feb 22, 2011 at 12:22:58PM -0800, J Freyensee wrote:
> On Thu, 2011-02-17 at 13:43 -0800, Greg KH wrote:
> > On Thu, Feb 17, 2011 at 12:10:47PM -0800, J Freyensee wrote:
> > > On Thu, 2011-02-17 at 11:54 -0800, Greg KH wrote:
> > > > On Thu, Feb 17, 2011 at 11:45:15AM -0800, J Freyensee wrote:
> > > > > On Thu, 2011-02-17 at 11:23 -0800, Greg KH wrote:
> > > > > > On Tue, Feb 08, 2011 at 11:34:54AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > > > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > > > 
> > > > > > > This header file allows the n_tracerouter to send it's information
> > > > > > > to the n_tracesink ldisc driver.  It's part of the Intel-Atom
> > > > > > > PTI implementation solution.
> > > > > > > 
> > > > > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > > > ---
> > > > > > >  include/linux/n_tracesink.h |   32 ++++++++++++++++++++++++++++++++
> > > > > > 
> > > > > > Why is this in include/linux/ ?
> > > > > > 
> > > > > 
> > > > > I thought this was the best place to stick this .h file.  I'd be happy
> > > > > to change locations based off of your suggestion.
> > > > 
> > > > Why do you need a .h file at all?  Who is using it?
> > > 
> > > The only current module that really uses it is n_tracerouter; however, I
> > > thought sticking this in a .h file made things slightly more modular and
> > > more re-usable, especially for future device driver writers that could
> > > want something like this.
> > > 
> > > If you would like me to remove this though, I can, just let me know.
> > 
> > Yes, please remove it.
> > 
> Greg,
> 
> If I remove this file I need to add the function header
> n_tracesink_datadrain() that is in this file to n_tracerouter.c.
> 
> If I add that function header to n_tracerouter.c then checkpatch.pl
> complains that extern should be avoided in .c files.
> 
> If I don't have this function header in n_tracerouter.c then it won't
> compile at all.
> 
> Do you have an alternative suggestion on what I should do here?  It
> appears the best solution is for me to keep this .h file considering the
> constraints.

Make it a "local" .h file, in the same directory as these two .c files,
no need to make it global for the whole of the kernel tree, right?

thanks,

greg k-h

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

* Re: [PATCH 09/12] n_tracesink header file.
  2011-02-22 20:26                                 ` Greg KH
@ 2011-02-22 22:55                                   ` J Freyensee
  0 siblings, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-02-22 22:55 UTC (permalink / raw)
  To: Greg KH; +Cc: Greg KH, linux-kernel, suhail.ahmed

On Tue, 2011-02-22 at 12:26 -0800, Greg KH wrote:
> On Tue, Feb 22, 2011 at 12:22:58PM -0800, J Freyensee wrote:
> > On Thu, 2011-02-17 at 13:43 -0800, Greg KH wrote:
> > > On Thu, Feb 17, 2011 at 12:10:47PM -0800, J Freyensee wrote:
> > > > On Thu, 2011-02-17 at 11:54 -0800, Greg KH wrote:
> > > > > On Thu, Feb 17, 2011 at 11:45:15AM -0800, J Freyensee wrote:
> > > > > > On Thu, 2011-02-17 at 11:23 -0800, Greg KH wrote:
> > > > > > > On Tue, Feb 08, 2011 at 11:34:54AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > > > > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > > > > 
> > > > > > > > This header file allows the n_tracerouter to send it's information
> > > > > > > > to the n_tracesink ldisc driver.  It's part of the Intel-Atom
> > > > > > > > PTI implementation solution.
> > > > > > > > 
> > > > > > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > > > > ---
> > > > > > > >  include/linux/n_tracesink.h |   32 ++++++++++++++++++++++++++++++++
> > > > > > > 
> > > > > > > Why is this in include/linux/ ?
> > > > > > > 
> > > > > > 
> > > > > > I thought this was the best place to stick this .h file.  I'd be happy
> > > > > > to change locations based off of your suggestion.
> > > > > 
> > > > > Why do you need a .h file at all?  Who is using it?
> > > > 
> > > > The only current module that really uses it is n_tracerouter; however, I
> > > > thought sticking this in a .h file made things slightly more modular and
> > > > more re-usable, especially for future device driver writers that could
> > > > want something like this.
> > > > 
> > > > If you would like me to remove this though, I can, just let me know.
> > > 
> > > Yes, please remove it.
> > > 
> > Greg,
> > 
> > If I remove this file I need to add the function header
> > n_tracesink_datadrain() that is in this file to n_tracerouter.c.
> > 
> > If I add that function header to n_tracerouter.c then checkpatch.pl
> > complains that extern should be avoided in .c files.
> > 
> > If I don't have this function header in n_tracerouter.c then it won't
> > compile at all.
> > 
> > Do you have an alternative suggestion on what I should do here?  It
> > appears the best solution is for me to keep this .h file considering the
> > constraints.
> 
> Make it a "local" .h file, in the same directory as these two .c files,
> no need to make it global for the whole of the kernel tree, right?
> 

yes, you are right, I don't think it needs to be global for the whole
tree since the two .c files are in the same place and they are the only
ones that care about it.

Jay

> thanks,
> 
> greg k-h



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

* Re: [PATCH 07/12] n_tracerouter and n_tracesink additions.
  2011-02-17 19:43                   ` J Freyensee
  2011-02-17 19:54                     ` Greg KH
@ 2011-02-24 11:52                     ` Alan Cox
  1 sibling, 0 replies; 171+ messages in thread
From: Alan Cox @ 2011-02-24 11:52 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: Greg KH, Alan Cox, gregkh, linux-kernel, suhail.ahmed

> > > +#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
> > > +#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
> > 
> > Two new ones?  Really?  Alan, no objection from you on this?
> 
> I'll let Alan chime in, but I did have Alan review this code before I
> submitted here.

There isn't really an elegant way of avoiding that. What probably does
want doing for a final merge is to make them more generic. So that
anything can be a source or a sink that meets a basic interface.

Then you'd be able to do

	set ldisc to tracesink
	ioctl (something or other) 		"attach to sink of
						 name 'modem/mipi/p1149.7'

or similar.

That would need a struct of some sort and a register_sink/unregister_sink
method. Ditto for tracerouter. Obviously for now only the current drivers
would support it but the interface is then there for anything else

Alan

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

* 2nd request for review and addition of PTI implementation into kernel
       [not found] <james_p_freyensee@linux.intel.com>
  2011-02-08 19:34 ` Resend: Request for review and addition of PTI implementation into kernel james_p_freyensee
  2011-02-09  0:17 ` [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
@ 2011-02-24 18:06 ` james_p_freyensee
  2011-02-24 18:06 ` [PATCH 01/10] export kernel call get_task_comm() james_p_freyensee
                   ` (38 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-24 18:06 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

This is a second request for review and acceptance into the mainline kernel
for the Intel-Atom implementation of the MIPI P1149.7 compact JTAG
standard for mobile devices.  Complete documentation and background
has been provided in PATCH 02/12, "Kernel documentation for the PTI
feature".  PATCH 01/12 is a kernel fix to allow the PTI driver
to compile modularly; this is a fix Greg KH, Alan Cox, and Arjan
van de Ven and I talked about a while ago.  It's not techincally
related to PTI, but it is it's own separate patch so it can be
applied independent of any possible problems with the PTI submission.

Changes from last review included n_tracesink.h move, pti function
and struct renaming, and patch re-organization.

Thanks for your help and time.  Regards,
Jay


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

* [PATCH 01/10] export kernel call get_task_comm().
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (2 preceding siblings ...)
  2011-02-24 18:06 ` 2nd request for review and addition of PTI implementation into kernel james_p_freyensee
@ 2011-02-24 18:06 ` james_p_freyensee
  2011-02-24 18:06 ` [PATCH 02/10] Kernel documentation for the PTI feature james_p_freyensee
                   ` (37 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-24 18:06 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows drivers who call this function to be compiled modularly.
Otherwise, a driver who is interested in this type of functionality
has to implement their own.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 fs/exec.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index c62efcb..7b209f9 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -998,6 +998,7 @@ char *get_task_comm(char *buf, struct task_struct *tsk)
 	task_unlock(tsk);
 	return buf;
 }
+EXPORT_SYMBOL_GPL(get_task_comm);
 
 void set_task_comm(struct task_struct *tsk, char *buf)
 {
-- 
1.7.2.3


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

* [PATCH 02/10] Kernel documentation for the PTI feature.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (3 preceding siblings ...)
  2011-02-24 18:06 ` [PATCH 01/10] export kernel call get_task_comm() james_p_freyensee
@ 2011-02-24 18:06 ` james_p_freyensee
  2011-02-24 18:06 ` [PATCH 03/10] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
                   ` (36 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-24 18:06 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This provides Kernel documentation for the PTI
feature for Linux mobile solutions.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 Documentation/pti/pti_intel_mid.txt |   96 +++++++++++++++++++++++++++++++++++
 1 files changed, 96 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/pti/pti_intel_mid.txt

diff --git a/Documentation/pti/pti_intel_mid.txt b/Documentation/pti/pti_intel_mid.txt
new file mode 100644
index 0000000..8e9837d
--- /dev/null
+++ b/Documentation/pti/pti_intel_mid.txt
@@ -0,0 +1,96 @@
+The Intel MID PTI project is HW implemented in Intel Atom
+system-on-a-chip designs based on the Parallel Trace
+Interface for MIPI P1149.7 cJTAG standard.  The kernel solution
+for this platform involves the following files:
+
+./include/linux/pti.h
+./drivers/.../n_tracesink.h
+./drivers/.../n_tracerouter.c
+./drivers/.../n_tracesink.c
+./drivers/.../pti.c
+
+pti.c is the driver that enables various debugging features
+popular on certain mobile manufacturers.  n_tracerouter.c
+and n_tracesink.c allow extra system information to be
+collected and routed to the pti driver, such as trace
+debugging data from a modem.  Although n_tracerouter
+and n_tracesink are a part of the complete PTI solution,
+these two line disciplines can work separately from
+pti.c and route any data stream from one /dev/tty node
+to another /dev/tty node via kernel-space.  This provides
+a stable, reliable connection that will not break unless
+the user-space application shuts down (plus avoids
+kernel->user->kernel context switch overheads of routing
+data).
+
+An example debugging usage for this driver system:
+   *Hook /dev/ttyPTI0 to syslogd.  Opening this port will also start
+    a console device to further capture debugging messages to PTI.
+   *Hook /dev/ttyPTI1 to modem debugging data to write to PTI HW.
+    This is where n_tracerouter and n_tracesink are used.
+   *Hook /dev/pti to a user-level debugging application for writing
+    to PTI HW.
+   *Use mipi_* Kernel Driver API in other device drivers for
+    debugging to PTI by first requesting a PTI write address via
+    mipi_request_masterchannel(1).
+
+Below is example pseudo-code on how a 'privileged' application
+can hook up n_tracerouter and n_tracesink to any tty on
+a system.  'Privileged' means the application has enough
+privileges to successfully manipulate the ldisc drivers
+but is not just blindly executing as 'root'.
+
+Note that n_tracerouter depends on n_tracesink.
+
+/////////// To hook up n_tracerouter and n_tracesink /////////
+
+#include <errno.h>
+#define ONE_TTY "/dev/ttyOne"
+#define TWO_TTY "/dev/ttyTwo"
+
+// needed global to hand onto ldisc connection
+static int g_fd_source = -1;
+static int g_fd_sink  = -1;
+
+// these two vars used to grab LDISC values from loaded ldisc drivers
+// in OS.  Look at /proc/tty/ldiscs to get the right numbers from
+// the ldiscs loaded in the system.
+int source_ldisc_num, sink_ldisc_num = -1;
+int retval;
+
+g_fd_source = open(ONE_TTY, O_RDWR); // must be R/W
+g_fd_sink   = open(TWO_TTY, O_RDWR); // must be R/W
+
+if (g_fd_source <= 0) || (g_fd_sink <= 0) {
+   // doubt you'll want to use these exact error lines of code
+   printf("Error on open(). errno: %d\n",errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_sink, TIOCSETD, &sink_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_source, TIOCSETD, &source_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+/////////// To disconnect n_tracerouter and n_tracesink ////////
+
+// First make sure data through the ldiscs has stopped.
+
+// Second, disconnect ldiscs.  This provides a
+// little cleaner shutdown on tty stack.
+sink_ldisc_num = 0;
+source_ldisc_num = 0;
+ioctl(g_fd_uart, TIOCSETD, &sink_ldisc_num);
+ioctl(g_fd_gadget, TIOCSETD, &source_ldisc_num);
+
+// Three, program closes connection, and cleanup:
+close(g_fd_uart);
+close(g_fd_gadget);
+g_fd_uart = g_fd_gadget = NULL;
-- 
1.7.2.3


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

* [PATCH 03/10] Intel PTI implementaiton of MIPI 1149.7.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (4 preceding siblings ...)
  2011-02-24 18:06 ` [PATCH 02/10] Kernel documentation for the PTI feature james_p_freyensee
@ 2011-02-24 18:06 ` james_p_freyensee
  2011-02-28  9:28   ` Arnd Bergmann
  2011-02-24 18:06 ` [PATCH 04/10] PTI Makefile and Kconfig additions james_p_freyensee
                   ` (35 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-24 18:06 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This driver is the Intel Atom implementation of MIPI P1149.7,
compact JTAG standard for mobile devices.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/pti.c |  890 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 890 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pti.c

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
new file mode 100644
index 0000000..213c900
--- /dev/null
+++ b/drivers/misc/pti.c
@@ -0,0 +1,890 @@
+/*
+ *  pti.c - PTI driver for cJTAG data extration
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ */
+
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/console.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/pci.h>
+#include <linux/mutex.h>
+#include <linux/miscdevice.h>
+#include <linux/pti.h>
+
+#define DRIVERNAME		"pti"
+#define PCINAME			"pciPTI"
+#define TTYNAME			"ttyPTI"
+#define CHARNAME		"pti"
+#define PTITTY_MINOR_START	0
+#define PTITTY_MINOR_NUM	2
+#define MAX_APP_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_OS_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_MODEM_IDS		16   /* 128 channel ids / u8 bit size */
+#define MODEM_BASE_ID		71   /* modem master ID address    */
+#define CONTROL_ID		72   /* control master ID address  */
+#define CONSOLE_ID		73   /* console master ID address  */
+#define OS_BASE_ID		74   /* base OS master ID address  */
+#define APP_BASE_ID		80   /* base App master ID address */
+#define CONTROL_FRAME_LEN	32   /* PTI control frame maximum size */
+#define USER_COPY_SIZE		8192 /* 8Kb buffer for user space copy */
+#define APERTURE_14 		0x3800000 /* offset to first OS write addr */
+#define APERTURE_LEN		0x400000  /* address length */
+
+struct pti_tty {
+	struct pti_masterchannel *mc;
+};
+
+struct pti_dev {
+	struct tty_port port;
+	unsigned long pti_addr;
+	unsigned long aperture_base;
+	void __iomem *pti_ioaddr;
+	unsigned long pti_iolen;
+	u8 IA_App[MAX_APP_IDS];
+	u8 IA_OS[MAX_OS_IDS];
+	u8 IA_Modem[MAX_MODEM_IDS];
+};
+
+
+static DEFINE_MUTEX(alloclock);
+
+static struct pci_device_id pci_ids[] __devinitconst = {
+		{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B) },
+		{0}
+};
+
+static struct tty_driver *pti_tty_driver;
+
+static struct pti_dev *drv_data;
+
+static unsigned int pti_console_channel;
+static unsigned int pti_control_channel;
+
+#define DTS 0x30		/* offset for last dword of a PTI message */
+
+/**
+ *  pti_write_to_aperture() - THE private write function to PTI HW.
+ *  @mc: The 'aperture'. It's part of a write address that holds
+ *       a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  Since each aperture is specified by a unique
+ *  master/channel ID, no two processes will be writing
+ *  to the same aperture at the same time so no lock is required. The
+ *  PTI-Output agent will send these out in the order that they arrived, and
+ *  thus, it will intermix these messages. The debug tool can then later
+ *  regroup the appropriate message segments together reconstituting each
+ *  message.
+ */
+static void pti_write_to_aperture(struct pti_masterchannel *mc,
+				  u8 *buf,
+				  int len)
+{
+	int dwordcnt, final, i;
+	u32 ptiword;
+	u8 *p;
+	u32 __iomem *aperture;
+
+	p = buf;
+
+	/*
+	   calculate the aperture offset from the base using the master and
+	   channel id's.
+	*/
+	aperture = drv_data->pti_ioaddr + (mc->master << 15)
+		+ (mc->channel << 8);
+
+	dwordcnt = len >> 2;
+	final = len - (dwordcnt << 2);		/* final = trailing bytes */
+	if (final == 0 && dwordcnt != 0) {	/* always have a final dword */
+		final += 4;
+		dwordcnt--;
+	}
+
+	for (i = 0; i < dwordcnt; i++) {
+		ptiword = be32_to_cpu(*(u32 *)p);
+		p += 4;
+		iowrite32(ptiword, aperture);
+	}
+
+	aperture += DTS;		/* adding DTS signals that is EOM */
+
+	ptiword = 0;
+	for (i = 0; i < final; i++)
+		ptiword |= *p++ << (24-(8*i));
+
+	iowrite32(ptiword, aperture);
+	return;
+}
+
+/**
+ *  pti_control_frame_built_and_sent() - control frame build and send function.
+ *  @mc: The master / channel structure on which the function built a control
+ *  frame.
+ *
+ *  To be able to post process the PTI contents on host side, a control frame
+ *  is added before sending any PTI content. So the host side knows on
+ *  each PTI frame the name of the thread using a dedicated master / channel.
+ *  This function builds this frame and sends it to a master ID CONTROL_ID.
+ *  The overhead is only 32 bytes since the driver only writes to HW
+ *  in 32 byte chunks.
+ */
+
+static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc)
+{
+	struct pti_masterchannel mccontrol = {.master = CONTROL_ID,
+					      .channel = 0};
+	const char *control_format = "%3d %3d %s";
+
+	char comm[sizeof(current->comm) + 1];
+	u8 control_frame[CONTROL_FRAME_LEN];
+
+	if (!in_interrupt())
+		get_task_comm(comm, current);
+	else
+		strcpy(comm, "Interrupt");
+
+	/* Ensure our buffer is zero terminated */
+	comm[sizeof(current->comm)] = 0;
+
+	mccontrol.channel = pti_control_channel;
+	pti_control_channel = (pti_control_channel + 1) & 0x7f;
+
+	snprintf(control_frame, CONTROL_FRAME_LEN, control_format, mc->master,
+		mc->channel, comm);
+	pti_write_to_aperture(&mccontrol, control_frame, strlen(control_frame));
+}
+
+/**
+ *  pti_write_full_frame_to_aperture() - high level function to write to PTI
+ *  @mc: The 'aperture'. It's part of a write address that holds
+ *       a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  All threads sending data (either console, user space application, ...)
+ *  are calling the high level function to write to PTI meaning that it is
+ *  possible to add a control frame before sending the content.
+ */
+static void pti_write_full_frame_to_aperture(struct pti_masterchannel *mc,
+						const unsigned char *buf,
+						int len)
+{
+	pti_control_frame_built_and_sent(mc);
+	pti_write_to_aperture(mc, (u8 *)buf, len);
+}
+
+
+/**
+ * getID(): Allocate a master and channel ID.
+ *
+ * @IDarray:
+ * @max_IDS: The max amount of available write IDs to use.
+ * @baseID:  The starting SW channel ID, based on the Intel
+ *           PTI arch.
+ *
+ * @return: pti_masterchannel struct containing master, channel ID address,
+ * or 0 for error.
+ *
+ * Each bit in the arrays IA_App and IA_OS correspond to a master and
+ * channel id. The bit is one if the id is taken and 0 if free. For
+ * every master there are 128 channel id's.
+ */
+static struct pti_masterchannel *getID(u8 *IDarray, int max_IDS, int baseID)
+{
+	struct pti_masterchannel *mc;
+	int i, j, mask;
+
+	mc = kmalloc(sizeof(struct pti_masterchannel), GFP_KERNEL);
+	if (mc == NULL)
+		return NULL;
+
+	/* look for a byte with a free bit */
+	for (i = 0; i < max_IDS; i++)
+		if (IDarray[i] != 0xff)
+			break;
+	if (i == max_IDS) {
+		kfree(mc);
+		return NULL;
+	}
+	/* find the bit in the 128 possible channel opportunities */
+	mask = 0x80;
+	for (j = 0; j < 8; j++) {
+		if ((IDarray[i] & mask) == 0)
+			break;
+		mask >>= 1;
+	}
+
+	/* grab it */
+	IDarray[i] |= mask;
+	mc->master  = baseID;
+	mc->channel = ((i & 0xf)<<3) + j;
+	/* write new master Id / channel Id allocation to channel control */
+	pti_control_frame_built_and_sent(mc);
+	return mc;
+}
+
+/*
+	The following three functions:
+	pti_request_mastercahannel(), mipi_release_masterchannel()
+	and pti_writedata() are an API for other kernel drivers to
+	access PTI.
+*/
+
+/**
+ * pti_request_masterchannel() - Kernel API function used to allocate
+ *                                a master, channel ID address to write to
+ *                                PTI HW.
+ * @type: 0- request Application  master, channel aperture ID write address.
+ *        1- request OS master, channel aperture ID write address.
+ *        2- request Modem master, channel aperture ID write
+ *           address.
+ *        Other values, error.
+ * @return: pti_masterchannel struct or 0 for error.
+ *
+ */
+struct pti_masterchannel *pti_request_masterchannel(u8 type)
+{
+	struct pti_masterchannel *mc;
+
+	mutex_lock(&alloclock);
+
+	switch (type) {
+
+	case 0:
+		mc = getID(drv_data->IA_App, MAX_APP_IDS, APP_BASE_ID);
+		break;
+
+	case 1:
+		mc = getID(drv_data->IA_OS, MAX_OS_IDS, OS_BASE_ID);
+		break;
+
+	case 2:
+		mc = getID(drv_data->IA_Modem, MAX_MODEM_IDS, MODEM_BASE_ID);
+		break;
+	default:
+		mc = NULL;
+	}
+
+	mutex_unlock(&alloclock);
+	return mc;
+}
+EXPORT_SYMBOL_GPL(pti_request_masterchannel);
+
+/**
+ * pti_release_masterchannel() - Kernel API function used to release
+ *                                a master, channel ID address
+ *                                used to write to PTI HW.
+ * @mc: master, channel apeture ID address to be released.
+ *
+ */
+void pti_release_masterchannel(struct pti_masterchannel *mc)
+{
+	u8 master, channel, i;
+
+	mutex_lock(&alloclock);
+
+	if (mc) {
+		master = mc->master;
+		channel = mc->channel;
+
+		if (master == APP_BASE_ID) {
+			i = channel >> 3;
+			drv_data->IA_App[i] &=  ~(0x80>>(channel & 0x7));
+		} else if (master == OS_BASE_ID) {
+			i = channel >> 3;
+			drv_data->IA_OS[i] &= ~(0x80>>(channel & 0x7));
+		} else {
+			i = channel >> 3;
+			drv_data->IA_Modem[i] &= ~(0x80>>(channel & 0x7));
+		}
+
+		kfree(mc);
+	}
+
+	mutex_unlock(&alloclock);
+}
+EXPORT_SYMBOL_GPL(pti_release_masterchannel);
+
+/**
+ * pti_writedata() - Kernel API function used to write trace
+ *                   debugging data to PTI HW.
+ *
+ * @mc:    Master, channel aperture ID address to write to.
+ *         Null value will return with no write occurring.
+ * @buf:   Trace debuging data to write to the PTI HW.
+ *         Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         retrn with no write occuring.
+ */
+void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
+{
+	/*
+	   since this function is exported, this is treated like an
+	   API function, thus, all parameters should
+	   be checked for validity.
+	*/
+	if ((mc != NULL) && (buf != NULL) && (count > 0))
+		pti_write_to_aperture(mc, buf, count);
+	return;
+}
+EXPORT_SYMBOL_GPL(pti_writedata);
+
+static void __devexit pti_pci_remove(struct pci_dev *pdev)
+{
+	struct pti_dev *drv_data;
+
+	drv_data = pci_get_drvdata(pdev);
+	if (drv_data != NULL) {
+		pci_iounmap(pdev, drv_data->pti_ioaddr);
+		pci_set_drvdata(pdev, NULL);
+		kfree(drv_data);
+		pci_release_region(pdev, 1);
+		pci_disable_device(pdev);
+	}
+}
+
+/*
+   for the tty_driver_*() basic function descriptions, see tty_driver.h.
+   Specific header comments made for PTI-related specifics.
+*/
+
+/**
+ * pti_tty_driver_open()- Open an Application master, channel aperture
+ * ID to the PTI device via tty device.
+ *
+ * @param tty: tty interface.
+ * @param filp: filp interface pased to tty_port_open() call.
+ *
+ * @return int : Success = 0, otherwise fail.
+ *
+ * The main purpose of using the tty device interface is for
+ * each tty port to have a unique PTI write aperture.  In an
+ * example use case, ttyPTI0 gets syslogd and an APP aperture
+ * ID and ttyPTI1 is where the n_tracesink ldisc hooks to route
+ * modem messages into PTI.  Modem trace data does not have to
+ * go to ttyPTI1, but ttyPTI0 and ttyPTI1 do need to be distinct
+ * master IDs.  These messages go through the PTI HW and out of
+ * the handheld platform and to the Fido/Lauterbach device.
+ */
+static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
+{
+	int ret = 0;
+
+	/*
+	   we actually want to allocate a new channel per open, per
+	   system arch.  HW gives more than plenty channels for a single
+	   system task to have its own channel to write trace data. This
+	   also removes a locking requirement for the actual write
+	   procedure.
+	*/
+	ret = tty_port_open(&drv_data->port, tty, filp);
+
+	return ret;
+}
+
+/**
+ * pti_tty_driver_close()- close tty device and release Application
+ * master, channel aperture ID to the PTI device via tty device.
+ *
+ * @param tty: tty interface.
+ * @param filp: filp interface pased to tty_port_close() call.
+ *
+ * The main purpose of using the tty device interface is to route
+ * syslog daemon messages to the PTI HW and out of the handheld platform
+ * and to the Fido/Lauterbach device.
+ */
+static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
+{
+	tty_port_close(&drv_data->port, tty, filp);
+
+	return;
+}
+
+static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
+{
+	int idx = tty->index;
+	struct pti_tty *pti_tty_data;
+	struct pti_masterchannel *mc;
+	int ret = tty_init_termios(tty);
+
+	if (ret == 0) {
+		tty_driver_kref_get(driver);
+		tty->count++;
+		driver->ttys[idx] = tty;
+
+		pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL);
+		if (pti_tty_data == NULL)
+			return -ENOMEM;
+
+		tty->driver_data = pti_tty_data;
+
+		if (idx == PTITTY_MINOR_START)
+			mc = pti_request_masterchannel(0);
+		else
+			mc = pti_request_masterchannel(2);
+
+		if (mc == NULL)
+			return -ENXIO;
+
+		pti_tty_data->mc = mc;
+	}
+
+	return ret;
+}
+
+static void pti_tty_cleanup(struct tty_struct *tty)
+{
+	struct pti_tty *pti_tty_data;
+	struct pti_masterchannel *mc;
+
+	pti_tty_data = tty->driver_data;
+
+	if (pti_tty_data != NULL) {
+		mc = pti_tty_data->mc;
+		pti_release_masterchannel(mc);
+		pti_tty_data->mc = NULL;
+	}
+
+	if (pti_tty_data != NULL)
+		kfree(pti_tty_data);
+
+	tty->driver_data = NULL;
+}
+
+/**
+ * pti_tty_driver_write():  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @param filp: Contains private data which is used to obtain
+ *              master, channel write ID.
+ * @param data: trace data to be written.
+ * @param len:  # of byte to write.
+ * @return int : # of bytes written, or error.
+ */
+static int pti_tty_driver_write(struct tty_struct *tty,
+	const unsigned char *buf, int len)
+{
+	struct pti_masterchannel *mc;
+	struct pti_tty *pti_tty_data;
+
+	pti_tty_data = tty->driver_data;
+	mc = pti_tty_data->mc;
+	pti_write_to_aperture(mc, (u8 *)buf, len);
+
+	return len;
+}
+
+static int pti_tty_write_room(struct tty_struct *tty)
+{
+	return 2048;
+}
+
+/**
+ * pti_char_open()- Open an Application master, channel aperture
+ * ID to the PTI device. Part of the misc device implementation.
+ *
+ * @param inode: not used.
+ * @param filp: Output- will have a masterchannel struct set containing
+ * the allocated application PTI aperture write address.
+ *
+ * @return int : Success = 0, otherwise fail.  As of right now,
+ *         it is not sure what needs to really be initialized
+ *         for open(), so it always returns 0.
+ */
+static int pti_char_open(struct inode *inode, struct file *filp)
+{
+	struct pti_masterchannel *mc;
+
+	mc = pti_request_masterchannel(0);
+	if (mc == NULL)
+		return -ENOMEM;
+	filp->private_data = mc;
+	return 0;
+}
+
+/**
+ * pti_char_release()-  Close a char channel to the PTI device. Part
+ * of the misc device implementation.
+ *
+ * @param inode: Not used in this implementaiton.
+ * @param filp: Contains private_data that contains the master, channel
+ * ID to be released by the PTI device.
+ *
+ * @return int : Success = 0
+ */
+static int pti_char_release(struct inode *inode, struct file *filp)
+{
+	pti_release_masterchannel(filp->private_data);
+	return 0;
+}
+
+/**
+ * pti_char_write():  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @param filp: Contains private data which is used to obtain
+ *              master, channel write ID.
+ * @param data: trace data to be written.
+ * @param len:  # of byte to write.
+ * @param ppose: Not used in this function implementation.
+ * @return int : # of bytes written, or error.
+ */
+static ssize_t pti_char_write(struct file *filp, const char __user *data,
+			      size_t len, loff_t *ppose)
+{
+	struct pti_masterchannel *mc;
+	void *kbuf;
+	const char __user *tmp;
+	size_t size = USER_COPY_SIZE, n = 0;
+
+	tmp = data;
+	mc = filp->private_data;
+
+	kbuf = kmalloc(size, GFP_KERNEL);
+	if (kbuf == NULL)  {
+		pr_err("%s(%d): buf allocation failed\n",
+			__func__, __LINE__);
+		return 0;
+	}
+
+	do {
+		if (len - n > USER_COPY_SIZE)
+			size = USER_COPY_SIZE;
+		else
+			size = len - n;
+
+		if (copy_from_user(kbuf, tmp, size)) {
+			kfree(kbuf);
+			return n ? n : -EFAULT;
+		}
+
+		pti_write_to_aperture(mc, kbuf, size);
+		n  += size;
+		tmp += size;
+
+	} while (len > n);
+
+	kfree(kbuf);
+	kbuf = NULL;
+
+	return len;
+}
+
+static const struct tty_operations pti_tty_driver_ops = {
+	.open		= pti_tty_driver_open,
+	.close		= pti_tty_driver_close,
+	.write		= pti_tty_driver_write,
+	.write_room	= pti_tty_write_room,
+	.install	= pti_tty_install,
+	.cleanup	= pti_tty_cleanup
+};
+
+static const struct file_operations pti_char_driver_ops = {
+	.owner		= THIS_MODULE,
+	.write		= pti_char_write,
+	.open		= pti_char_open,
+	.release	= pti_char_release,
+};
+
+static struct miscdevice pti_char_driver = {
+	.minor		= MISC_DYNAMIC_MINOR,
+	.name		= CHARNAME,
+	.fops		= &pti_char_driver_ops
+};
+
+static void pti_console_write(struct console *c, const char *buf, unsigned len)
+{
+	static struct pti_masterchannel mc = {.master  = CONSOLE_ID,
+					      .channel = 0};
+
+	mc.channel = pti_console_channel;
+	pti_console_channel = (pti_console_channel + 1) & 0x7f;
+
+	pti_write_full_frame_to_aperture(&mc, 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;
+	pti_control_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,
+	.index		= 0,
+};
+
+/**
+ * pti_port_activate(): Used to start/initialize any items upon
+ * first opening of tty_port().
+ *
+ * @param port- The tty port number of the PTI device.
+ * @param tty-  The tty struct associated with this device.
+ *
+ * @return int - Always returns 0.
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static int pti_port_activate(struct tty_port *port, struct tty_struct *tty)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		console_start(&pti_console);
+	return 0;
+}
+
+/**
+ * pti_port_shutdown(): Used to stop/shutdown any items upon the
+ * last tty port close.
+ *
+ * @param port- The tty port number of the PTI device.
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static void pti_port_shutdown(struct tty_port *port)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		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.
+*/
+
+static int __devinit pti_pci_probe(struct pci_dev *pdev,
+		const struct pci_device_id *ent)
+{
+	int retval = -EINVAL;
+	int pci_bar = 1;
+
+	dev_dbg(&pdev->dev, "%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__,
+			__func__, __LINE__, pdev->vendor, pdev->device);
+
+	retval = misc_register(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+		return retval;
+	}
+
+	retval = pci_enable_device(pdev);
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s: pci_enable_device() returned error %d\n",
+			__func__, retval);
+		return retval;
+	}
+
+	drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
+
+	if (drv_data == NULL) {
+		retval = -ENOMEM;
+		dev_err(&pdev->dev,
+			"%s(%d): kmalloc() returned NULL memory.\n",
+			__func__, __LINE__);
+		return retval;
+	}
+	drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
+
+	retval = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev));
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s(%d): pci_request_region() returned error %d\n",
+			__func__, __LINE__, retval);
+		kfree(drv_data);
+		return retval;
+	}
+	drv_data->pti_iolen = pci_resource_len(pdev, pci_bar);
+	drv_data->aperture_base = drv_data->pti_addr+APERTURE_14;
+	drv_data->pti_ioaddr =
+		ioremap_nocache((u32)drv_data->aperture_base,
+		APERTURE_LEN);
+	if (!drv_data->pti_ioaddr) {
+		pci_release_region(pdev, pci_bar);
+		retval = -ENOMEM;
+		kfree(drv_data);
+		return retval;
+	}
+
+	pci_set_drvdata(pdev, drv_data);
+
+	tty_port_init(&drv_data->port);
+	drv_data->port.ops = &tty_port_ops;
+
+	tty_register_device(pti_tty_driver, 0, &pdev->dev);
+	tty_register_device(pti_tty_driver, 1, &pdev->dev);
+
+	register_console(&pti_console);
+
+	return retval;
+}
+
+static struct pci_driver pti_pci_driver = {
+	.name		= PCINAME,
+	.id_table	= pci_ids,
+	.probe		= pti_pci_probe,
+	.remove		= pti_pci_remove,
+};
+
+/**
+ *
+ * pti_init():
+ *
+ * @return int __init: 0 for success, any other value error.
+ *
+ */
+static int __init pti_init(void)
+{
+	int retval = -EINVAL;
+
+	/* First register module as tty device */
+
+	pti_tty_driver = alloc_tty_driver(1);
+	if (pti_tty_driver == NULL) {
+		pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n",
+			__func__, __LINE__);
+		return -ENOMEM;
+	}
+
+	pti_tty_driver->owner			= THIS_MODULE;
+	pti_tty_driver->magic			= TTY_DRIVER_MAGIC;
+	pti_tty_driver->driver_name		= DRIVERNAME;
+	pti_tty_driver->name			= TTYNAME;
+	pti_tty_driver->major			= 0;
+	pti_tty_driver->minor_start		= PTITTY_MINOR_START;
+	pti_tty_driver->minor_num		= PTITTY_MINOR_NUM;
+	pti_tty_driver->num			= PTITTY_MINOR_NUM;
+	pti_tty_driver->type			= TTY_DRIVER_TYPE_SYSTEM;
+	pti_tty_driver->subtype			= SYSTEM_TYPE_SYSCONS;
+	pti_tty_driver->flags			= TTY_DRIVER_REAL_RAW |
+						  TTY_DRIVER_DYNAMIC_DEV;
+	pti_tty_driver->init_termios		= tty_std_termios;
+
+	tty_set_operations(pti_tty_driver, &pti_tty_driver_ops);
+
+	retval = tty_register_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	retval = pci_register_driver(&pti_pci_driver);
+
+	if (retval) {
+		pr_err("%s(%d): PCI registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		tty_unregister_driver(pti_tty_driver);
+		pr_err("%s(%d): Unregistering TTY part of pti driver\n",
+			__func__, __LINE__);
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	return retval;
+}
+
+/**
+ * pti_exit(): Unregisters this module as a tty and pci driver.
+ */
+static void __exit pti_exit(void)
+{
+	int retval;
+
+	tty_unregister_device(pti_tty_driver, 0);
+	tty_unregister_device(pti_tty_driver, 1);
+
+	retval = tty_unregister_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	pci_unregister_driver(&pti_pci_driver);
+
+	retval = misc_deregister(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	unregister_console(&pti_console);
+	return;
+}
+
+module_init(pti_init);
+module_exit(pti_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ken Mills, Jay Freyensee");
+MODULE_DESCRIPTION("PTI Driver");
+
-- 
1.7.2.3


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

* [PATCH 04/10] PTI Makefile and Kconfig additions.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (5 preceding siblings ...)
  2011-02-24 18:06 ` [PATCH 03/10] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
@ 2011-02-24 18:06 ` james_p_freyensee
  2011-02-28  9:31   ` Arnd Bergmann
  2011-02-24 18:06 ` [PATCH 05/10] PTI header file james_p_freyensee
                   ` (34 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-24 18:06 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows the Intel implementation of the PTI standard to be
compiled and configured in Kconfig.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/Kconfig  |   12 ++++++++++++
 drivers/misc/Makefile |    1 +
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4d073f1..f8076f1 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -136,6 +136,18 @@ config PHANTOM
 	  If you choose to build module, its name will be phantom. If unsure,
 	  say N here.
 
+config INTEL_MID_PTI
+        tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
+        help
+          The PTI (Parallel Trace Interface) driver directs
+          trace data routed from various parts in the system out
+          through an Intel Penwell PTI port and out of the mobile
+          device for analysis with a debugging tool (Lauterbach or Fido).
+
+          You should select this driver if the target kernel is meant for
+          an Intel Atom (non-netbook) mobile device containing a MIPI
+          P1149.7 standard implementation.
+
 config SGI_IOC4
 	tristate "SGI IOC4 Base IO support"
 	depends on PCI
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 98009cc..cae0463 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_IBM_ASM)		+= ibmasm/
 obj-$(CONFIG_AD525X_DPOT)	+= ad525x_dpot.o
 obj-$(CONFIG_AD525X_DPOT_I2C)	+= ad525x_dpot-i2c.o
 obj-$(CONFIG_AD525X_DPOT_SPI)	+= ad525x_dpot-spi.o
+obj-$(CONFIG_INTEL_MID_PTI)     += pti.o
 obj-$(CONFIG_ATMEL_PWM)		+= atmel_pwm.o
 obj-$(CONFIG_ATMEL_SSC)		+= atmel-ssc.o
 obj-$(CONFIG_ATMEL_TCLIB)	+= atmel_tclib.o
-- 
1.7.2.3


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

* [PATCH 05/10] PTI header file.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (6 preceding siblings ...)
  2011-02-24 18:06 ` [PATCH 04/10] PTI Makefile and Kconfig additions james_p_freyensee
@ 2011-02-24 18:06 ` james_p_freyensee
  2011-02-28  9:30   ` Arnd Bergmann
  2011-02-24 18:07 ` [PATCH 06/10] n_tracerouter and n_tracesink additions james_p_freyensee
                   ` (33 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-24 18:06 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This adds PTI header information for the PTI project.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 include/linux/pti.h |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/pti.h

diff --git a/include/linux/pti.h b/include/linux/pti.h
new file mode 100644
index 0000000..94d05bc
--- /dev/null
+++ b/include/linux/pti.h
@@ -0,0 +1,39 @@
+/*
+ *  Copyright (C) Intel 2011
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ *
+ * This header file will allow other parts of the OS to use the
+ * interface to write out it's contents for debugging a mobile system.
+ */
+
+#ifndef PTI_H_
+#define PTI_H_
+
+/* basic structure used as a write address to the PTI HW */
+struct pti_masterchannel {
+	u8 master;
+	u8 channel;
+};
+
+/* the following functions are defined in misc/pti.c */
+void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count);
+struct pti_masterchannel *pti_request_masterchannel(u8 type);
+void pti_release_masterchannel(struct pti_masterchannel *mc);
+
+#endif /*PTI_H_*/
-- 
1.7.2.3


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

* [PATCH 06/10] n_tracerouter and n_tracesink additions.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (7 preceding siblings ...)
  2011-02-24 18:06 ` [PATCH 05/10] PTI header file james_p_freyensee
@ 2011-02-24 18:07 ` james_p_freyensee
  2011-02-24 18:07 ` [PATCH 07/10] n_tracesink ldisc addition james_p_freyensee
                   ` (32 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-24 18:07 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch adds line discipline numbers to n_tracerouter and
n_tracesink line disciplines for the Intel-Atom PTI implementation
for mobile devices.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 include/linux/tty.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/linux/tty.h b/include/linux/tty.h
index 54e4eaa..c507f53 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -50,6 +50,8 @@
 #define N_CAIF		20      /* CAIF protocol for talking to modems */
 #define N_GSM0710	21	/* GSM 0710 Mux */
 #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
+#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
+#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
-- 
1.7.2.3


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

* [PATCH 07/10] n_tracesink ldisc addition.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (8 preceding siblings ...)
  2011-02-24 18:07 ` [PATCH 06/10] n_tracerouter and n_tracesink additions james_p_freyensee
@ 2011-02-24 18:07 ` james_p_freyensee
  2011-02-24 18:07 ` [PATCH 08/10] n_tracesink header file james_p_freyensee
                   ` (31 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-24 18:07 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch adds n_tracesink line discipline driver, which is
part of the Intel-Atom PTI implementation solution.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/n_tracesink.c |  247 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 247 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/n_tracesink.c

diff --git a/drivers/tty/n_tracesink.c b/drivers/tty/n_tracesink.c
new file mode 100644
index 0000000..1ca7028
--- /dev/null
+++ b/drivers/tty/n_tracesink.c
@@ -0,0 +1,247 @@
+/*
+ *  n_tracesink.c - Trace data router and sink path through tty space.
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The trace sink uses the Linux line discipline framework to receive
+ * trace data coming from the PTI source line discipline driver
+ * to a user-desired tty port, like USB.
+ * This is to provide a way to extract modem trace data on
+ * devices that do not have a PTI HW module, or just need modem
+ * trace data to come out of a different HW output port.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <asm-generic/bug.h>
+#include "n_tracesink.h"
+
+/* Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracesink"
+
+/* there is a quirk with this ldisc is he can write data
+ * to a tty from anyone calling his kernel API, which
+ * meets customer requirements in the drivers/misc/pti.c
+ * project.  So he needs to know when he can and cannot write when
+ * the API is called. In theory, the API can be called
+ * after an init() but before a successful open() which
+ * would crash the system if tty is not checked.
+ */
+static struct tty_struct *this_tty;
+static DEFINE_MUTEX(writelock);
+
+/**
+ * n_tracesink_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success,
+ *      -EFAULT = couldn't get a tty kref n_tracesink will sit
+ *       on top of
+ *      -EEXIST = open() called successfully once and it cannot
+ *      be called again.
+ *
+ * Caveats: open() should only be successful the first time a
+ * SW entity calls it.
+ */
+static int n_tracesink_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&writelock);
+	if (this_tty == NULL) {
+
+		this_tty = tty_kref_get(tty);
+
+		if (this_tty == NULL)
+			retval = -EFAULT;
+		else {
+			tty->disc_data = this_tty;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&writelock);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracesink_close(struct tty_struct *tty)
+{
+
+	tty_driver_flush_buffer(tty);
+
+	mutex_lock(&writelock);
+	tty_kref_put(this_tty);
+	this_tty = NULL;
+	mutex_unlock(&writelock);
+
+	tty->disc_data = NULL;
+}
+
+/**
+ * n_tracesink_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracesink_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracesink_read(struct tty_struct *tty, struct file *file,
+				unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracesink_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracesink_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracesink_write(struct tty_struct *tty, struct file *file,
+				 const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracesink_datadrain() - Kernel API function used to route
+ *			     trace debugging data to user-defined
+ *			     port like USB.
+ *
+ * @buf:   Trace debuging data buffer to write to tty target
+ *         port. Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         return with no write occuring.
+ *
+ * Caveat: If this line discipline does not set the tty it sits
+ * on top of via an open() call, this API function will not
+ * call the tty's write() call because it will have no pointer
+ * to call the write().
+ */
+void n_tracesink_datadrain(u8 *buf, int count)
+{
+	mutex_lock(&writelock);
+
+	if ((buf != NULL) && (count > 0) && (this_tty != NULL))
+		this_tty->ops->write(this_tty, buf, count);
+
+	mutex_unlock(&writelock);
+}
+EXPORT_SYMBOL_GPL(n_tracesink_datadrain);
+
+/* Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+/*
+ * tty_ldisc function operations for this driver.
+ */
+static struct tty_ldisc_ops tty_n_tracesink = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracesink_open,
+	.close		= n_tracesink_close,
+	.read		= n_tracesink_read,
+	.write		= n_tracesink_write
+};
+
+/**
+ * n_tracesink_init-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracesink_init(void)
+{
+	int retval;
+
+	/* Note N_TRACESINK is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
+
+	if (retval < 0)
+		pr_err("%s: Registration failed: %d\n",
+					__func__, retval);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_exit -	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracesink_exit(void)
+{
+	int retval;
+
+	retval = tty_unregister_ldisc(N_TRACESINK);
+
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n",
+					__func__,  retval);
+}
+
+module_init(n_tracesink_init);
+module_exit(n_tracesink_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACESINK);
+MODULE_DESCRIPTION("Trace sink ldisc driver");
-- 
1.7.2.3


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

* [PATCH 08/10] n_tracesink header file.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (9 preceding siblings ...)
  2011-02-24 18:07 ` [PATCH 07/10] n_tracesink ldisc addition james_p_freyensee
@ 2011-02-24 18:07 ` james_p_freyensee
  2011-02-24 18:07 ` [PATCH 09/10] n_tracerouter ldisc driver james_p_freyensee
                   ` (30 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-24 18:07 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This header file allows the n_tracerouter to send it's information
to the n_tracesink ldisc driver.  It's part of the Intel-Atom
PTI implementation solution.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/n_tracesink.h |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/n_tracesink.h

diff --git a/drivers/tty/n_tracesink.h b/drivers/tty/n_tracesink.h
new file mode 100644
index 0000000..10ab772
--- /dev/null
+++ b/drivers/tty/n_tracesink.h
@@ -0,0 +1,36 @@
+/*
+ *  n_tracesink.h - Kernel driver API to route trace data in kernel space.
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ * 
+ * This header file is used by n_tracerouter to be able to send the 
+ * data of it's tty port to the tty port this module sits.  This
+ * mechanism can also be used independent of the PTI module.
+ *
+ */
+
+#ifndef N_TRACESINK_H_
+#define N_TRACESINK_H_
+
+void n_tracesink_datadrain(u8 *buf, int count);
+
+#endif
-- 
1.7.2.3


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

* [PATCH 09/10] n_tracerouter ldisc driver.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (10 preceding siblings ...)
  2011-02-24 18:07 ` [PATCH 08/10] n_tracesink header file james_p_freyensee
@ 2011-02-24 18:07 ` james_p_freyensee
  2011-02-24 19:20   ` Thomas Gleixner
  2011-02-24 18:07 ` [PATCH 10/10] n_tracerouter and n_tracesink compile configurations james_p_freyensee
                   ` (29 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-02-24 18:07 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch adds the n_tracerouter ldisc driver.  It is part
of the Intel-Atom PTI implementation solution.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/n_tracerouter.c |  258 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 258 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/n_tracerouter.c

diff --git a/drivers/tty/n_tracerouter.c b/drivers/tty/n_tracerouter.c
new file mode 100644
index 0000000..d28dcb9
--- /dev/null
+++ b/drivers/tty/n_tracerouter.c
@@ -0,0 +1,258 @@
+/*
+ *  n_tracerouter.c - Trace data router through tty space
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This trace router uses the Linux line discipline framework to route
+ * trace data coming from a HW Modem to a PTI (Parallel Trace Module) port.
+ * The solution is not specific to a HW modem and this line disciple can
+ * be used to route any stream of data in kernel space.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <asm-generic/bug.h>
+#include "n_tracesink.h"
+
+/* Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracerouter"
+
+/* struct to hold private configuration data for this ldisc.
+ * opencalled is used to hold if this ldisc has been opened.
+ * kref_tty holds the tty reference the ldisc sits on top of.
+ */
+struct tracerouter_data {
+	u8 opencalled;
+	struct tty_struct *kref_tty;
+};
+static struct tracerouter_data *tr_data;
+
+/* lock for when tty reference is being used */
+static DEFINE_MUTEX(routelock);
+
+/**
+ * tracerouter_alloc
+ *
+ * Allocates the structure needed for this ldisc.
+ */
+static struct tracerouter_data *tracerouter_alloc(void)
+{
+	struct tracerouter_data *tptr = kzalloc(
+					sizeof(struct tracerouter_data),
+					GFP_KERNEL);
+	if (tptr == NULL)
+		return NULL;
+	tptr->opencalled = 0;
+	return tptr;
+}
+
+/**
+ * n_tracerouter_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success.
+ *
+ * Caveats: This should only be opened one time per SW entity.
+ */
+static int n_tracerouter_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&routelock);
+	if (tr_data->opencalled == 0) {
+
+		tr_data->kref_tty = tty_kref_get(tty);
+		if (tr_data->kref_tty == NULL)
+			retval = -EFAULT;
+		else {
+			tr_data->opencalled = 1;
+			tty->disc_data      = tr_data;
+			tty->receive_room   = RECEIVE_ROOM;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&routelock);
+	return retval;
+}
+
+/**
+ * n_tracerouter_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracerouter_close(struct tty_struct *tty)
+{
+	struct tracerouter_data *tptr = tty->disc_data;
+
+	WARN_ON(tptr->kref_tty != tr_data->kref_tty);
+	tty_driver_flush_buffer(tty);
+	mutex_lock(&routelock);
+	tty_kref_put(tr_data->kref_tty);
+	tr_data->kref_tty = NULL;
+	tr_data->opencalled = 0;
+	tty->disc_data = NULL;
+	mutex_unlock(&routelock);
+}
+
+/**
+ * n_tracerouter_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracerouter_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracerouter_read(struct tty_struct *tty, struct file *file,
+				  unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracerouter_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracerouter_write(struct tty_struct *tty, struct file *file,
+				   const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_receivebuf() - Routing function for driver.
+ * @tty: terminal device passed into the ldisc.  It's assumed
+ *       tty will never be NULL.
+ * @cp:  buffer, block of characters to be eventually read by
+ *       someone, somewhere (user read() call or some kernel function).
+ * @fp:  flag buffer.
+ * @count: number of characters (aka, bytes) in cp.
+ *
+ * This function takes the input buffer, cp, and passes it to
+ * an external API function for processing.
+ */
+static void n_tracerouter_receivebuf(struct tty_struct *tty,
+					const unsigned char *cp,
+					char *fp, int count)
+{
+	mutex_lock(&routelock);
+	n_tracesink_datadrain((u8 *) cp, count);
+	mutex_unlock(&routelock);
+}
+
+/* Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+static struct tty_ldisc_ops tty_ptirouter_ldisc = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracerouter_open,
+	.close		= n_tracerouter_close,
+	.read		= n_tracerouter_read,
+	.write		= n_tracerouter_write,
+	.receive_buf	= n_tracerouter_receivebuf
+};
+
+/**
+ * n_tracerouter_init		-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracerouter_init(void)
+{
+	int retval;
+
+	tr_data = tracerouter_alloc();
+	if (tr_data == NULL)
+		return -ENOMEM;
+
+	/* Note N_TRACEROUTER is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACEROUTER, &tty_ptirouter_ldisc);
+	if (retval < 0) {
+		pr_err("%s: Registration failed: %d\n",
+					__func__, retval);
+		kfree(tr_data);
+	}
+	return retval;
+}
+
+/**
+ * n_tracerouter_exit -	-	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracerouter_exit(void)
+{
+	int retval;
+
+	kfree(tr_data);
+	retval = tty_unregister_ldisc(N_TRACEROUTER);
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n",
+					__func__,  retval);
+}
+
+module_init(n_tracerouter_init);
+module_exit(n_tracerouter_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACEROUTER);
+MODULE_DESCRIPTION("Trace router ldisc driver");
-- 
1.7.2.3


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

* [PATCH 10/10] n_tracerouter and n_tracesink compile configurations.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (11 preceding siblings ...)
  2011-02-24 18:07 ` [PATCH 09/10] n_tracerouter ldisc driver james_p_freyensee
@ 2011-02-24 18:07 ` james_p_freyensee
  2011-02-25 18:00   ` Greg KH
  2011-02-25 18:01   ` Greg KH
  2011-04-19 22:58 ` 3rd request for review & addition of PTI/n_trace implementation into kernel james_p_freyensee
                   ` (28 subsequent siblings)
  41 siblings, 2 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-02-24 18:07 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch allows n_tracerouter and n_tracesink to be compiled and
configured in the Linux kernel.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/char/Kconfig |   32 ++++++++++++++++++++++++++++++++
 drivers/tty/Makefile |    2 ++
 2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 43d3395..02b9be2 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -289,6 +289,38 @@ config N_GSM
 	  This line discipline provides support for the GSM MUX protocol and
 	  presents the mux as a set of 61 individual tty devices.
 
+config TRACE_ROUTER
+        tristate "Trace data router for MIPI P1149.7 cJTAG standard"
+                depends on TRACE_SINK
+                default Y
+        ---help---
+          The trace router uses the Linux tty line discipline framework to
+          route trace data coming from a tty port (say UART for example) to
+           the trace sink line discipline driver and to another tty port(say USB).
+           This is part of a solution for the MIPI P1149.7, compact JTAG,
+           standard, which is for debugging mobile devices. The PTI driver in
+           drivers/misc/pti.c defines the majority of this MIPI solution.
+
+          You should select this driver if the target kernel is meant for
+          a mobile device containing a modem.  Then you will need to select
+          "Trace data sink for MIPI P1149.7 cJTAG standard" line discipline
+          driver.
+
+config TRACE_SINK
+        tristate "Trace data sink for MIPI P1149.7 cJTAG standard"
+                default Y
+        ---help---
+          The trace sink uses the Linux line discipline framework to receive
+          trace data coming from the trace router line discipline driver
+          to a user-defined tty port target, like USB.
+          This is to provide a way to extract modem trace data on
+          devices that do not have a PTI HW module, or just need modem
+          trace data to come out of a different HW output port.
+          This is part of a solution for the P1149.7, compact JTAG, standard.
+
+          If you select this option, you need to select
+          "Trace data router for MIPI P1149.7 cJTAG standard".
+
 config RISCOM8
 	tristate "SDL RISCom/8 card support"
 	depends on SERIAL_NONSTANDARD
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index c43ef48..8c56ffd 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -7,5 +7,7 @@ obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
 obj-$(CONFIG_N_HDLC)		+= n_hdlc.o
 obj-$(CONFIG_N_GSM)		+= n_gsm.o
 obj-$(CONFIG_R3964)		+= n_r3964.o
+obj-$(CONFIG_TRACE_ROUTER)      += n_tracerouter.o
+obj-$(CONFIG_TRACE_SINK)        += n_tracesink.o
 
 obj-y				+= vt/
-- 
1.7.2.3


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

* Re: [PATCH 09/10] n_tracerouter ldisc driver.
  2011-02-24 18:07 ` [PATCH 09/10] n_tracerouter ldisc driver james_p_freyensee
@ 2011-02-24 19:20   ` Thomas Gleixner
  2011-02-24 20:20     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Thomas Gleixner @ 2011-02-24 19:20 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Thu, 24 Feb 2011, james_p_freyensee@linux.intel.com wrote:
> +
> +/**
> + * tracerouter_alloc
> + *
> + * Allocates the structure needed for this ldisc.
> + */
> +static struct tracerouter_data *tracerouter_alloc(void)
> +{
> +	struct tracerouter_data *tptr = kzalloc(
> +					sizeof(struct tracerouter_data),
> +					GFP_KERNEL);
> +	if (tptr == NULL)
> +		return NULL;
> +	tptr->opencalled = 0;

Wheeee!

You first alloc it with kzalloc and then clear the already zero member
again ?

That whole crap condenses down to:

     return kzalloc(sizeof(*tptr), GFP_KERNEL);

Which hardly justfies a separate function

> +	return tptr;
> +}
> +
> +/**
> + * n_tracerouter_open() - Called when a tty is opened by a SW entity.
> + * @tty: terminal device to the ldisc.
> + *
> + * Return:
> + *      0 for success.
> + *
> + * Caveats: This should only be opened one time per SW entity.
> + */
> +static int n_tracerouter_open(struct tty_struct *tty)
> +{
> +	int retval = -EEXIST;
> +
> +	mutex_lock(&routelock);
> +	if (tr_data->opencalled == 0) {
> +
> +		tr_data->kref_tty = tty_kref_get(tty);
> +		if (tr_data->kref_tty == NULL)
> +			retval = -EFAULT;
> +		else {

Please use braces for the if as well. It's just irritating not to have
them before the else.

> +			tr_data->opencalled = 1;
> +			tty->disc_data      = tr_data;
> +			tty->receive_room   = RECEIVE_ROOM;
> +			tty_driver_flush_buffer(tty);
> +			retval = 0;
> +		}
> +	}
> +	mutex_unlock(&routelock);
> +	return retval;
> +}
> +
> +/**
> + * n_tracerouter_close() - close connection
> + * @tty: terminal device to the ldisc.
> + *
> + * Called when a software entity wants to close a connection.
> + */
> +static void n_tracerouter_close(struct tty_struct *tty)
> +{
> +	struct tracerouter_data *tptr = tty->disc_data;
> +
> +	WARN_ON(tptr->kref_tty != tr_data->kref_tty);
> +	tty_driver_flush_buffer(tty);

That code probably never run with lockdep as you would get a potential
deadlock warning. See n_tracerouter_open().

Though the deadlock cannot happen as you are protected by
tr_data->opencalled it does not make it more correct.

> +	mutex_lock(&routelock);
> +	tty_kref_put(tr_data->kref_tty);
> +	tr_data->kref_tty = NULL;
> +	tr_data->opencalled = 0;
> +	tty->disc_data = NULL;
> +	mutex_unlock(&routelock);
> +}
> +

Thanks,

	tglx

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

* Re: [PATCH 09/10] n_tracerouter ldisc driver.
  2011-02-24 19:20   ` Thomas Gleixner
@ 2011-02-24 20:20     ` J Freyensee
  2011-02-24 20:27       ` Thomas Gleixner
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-02-24 20:20 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Thu, 2011-02-24 at 20:20 +0100, Thomas Gleixner wrote:
> On Thu, 24 Feb 2011, james_p_freyensee@linux.intel.com wrote:
> > +
> > +/**
> > + * tracerouter_alloc
> > + *
> > + * Allocates the structure needed for this ldisc.
> > + */
> > +static struct tracerouter_data *tracerouter_alloc(void)
> > +{
> > +	struct tracerouter_data *tptr = kzalloc(
> > +					sizeof(struct tracerouter_data),
> > +					GFP_KERNEL);
> > +	if (tptr == NULL)
> > +		return NULL;
> > +	tptr->opencalled = 0;
> 
> Wheeee!
> 
> You first alloc it with kzalloc and then clear the already zero member
> again ?
> 
> That whole crap condenses down to:
> 
>      return kzalloc(sizeof(*tptr), GFP_KERNEL);
> 
> Which hardly justfies a separate function
> 
> > +	return tptr;
> > +}
> > +
> > +/**
> > + * n_tracerouter_open() - Called when a tty is opened by a SW entity.
> > + * @tty: terminal device to the ldisc.
> > + *
> > + * Return:
> > + *      0 for success.
> > + *
> > + * Caveats: This should only be opened one time per SW entity.
> > + */
> > +static int n_tracerouter_open(struct tty_struct *tty)
> > +{
> > +	int retval = -EEXIST;
> > +
> > +	mutex_lock(&routelock);
> > +	if (tr_data->opencalled == 0) {
> > +
> > +		tr_data->kref_tty = tty_kref_get(tty);
> > +		if (tr_data->kref_tty == NULL)
> > +			retval = -EFAULT;
> > +		else {
> 
> Please use braces for the if as well. It's just irritating not to have
> them before the else.

checkpatch.pl did not care about the lack of braces so that is why this
got missed; I can add it.

> 
> > +			tr_data->opencalled = 1;
> > +			tty->disc_data      = tr_data;
> > +			tty->receive_room   = RECEIVE_ROOM;
> > +			tty_driver_flush_buffer(tty);
> > +			retval = 0;
> > +		}
> > +	}
> > +	mutex_unlock(&routelock);
> > +	return retval;
> > +}
> > +
> > +/**
> > + * n_tracerouter_close() - close connection
> > + * @tty: terminal device to the ldisc.
> > + *
> > + * Called when a software entity wants to close a connection.
> > + */
> > +static void n_tracerouter_close(struct tty_struct *tty)
> > +{
> > +	struct tracerouter_data *tptr = tty->disc_data;
> > +
> > +	WARN_ON(tptr->kref_tty != tr_data->kref_tty);
> > +	tty_driver_flush_buffer(tty);
> 
> That code probably never run with lockdep as you would get a potential
> deadlock warning. See n_tracerouter_open().
> 
> Though the deadlock cannot happen as you are protected by
> tr_data->opencalled it does not make it more correct.
> 

What do you suggest to make it correct for upstream?

Thanks,
jay

> > +	mutex_lock(&routelock);
> > +	tty_kref_put(tr_data->kref_tty);
> > +	tr_data->kref_tty = NULL;
> > +	tr_data->opencalled = 0;
> > +	tty->disc_data = NULL;
> > +	mutex_unlock(&routelock);
> > +}
> > +
> 
> Thanks,
> 
> 	tglx



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

* Re: [PATCH 09/10] n_tracerouter ldisc driver.
  2011-02-24 20:20     ` J Freyensee
@ 2011-02-24 20:27       ` Thomas Gleixner
  0 siblings, 0 replies; 171+ messages in thread
From: Thomas Gleixner @ 2011-02-24 20:27 UTC (permalink / raw)
  To: J Freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Thu, 24 Feb 2011, J Freyensee wrote:
> > > +
> > > +	mutex_lock(&routelock);
> > > +	if (tr_data->opencalled == 0) {
> > > +
> > > +		tr_data->kref_tty = tty_kref_get(tty);
> > > +		if (tr_data->kref_tty == NULL)
> > > +			retval = -EFAULT;
> > > +		else {
> > 
> > Please use braces for the if as well. It's just irritating not to have
> > them before the else.
> 
> checkpatch.pl did not care about the lack of braces so that is why this
> got missed; I can add it.

It's not a strict requirement, but add it and look at the result. Then
judge yourself.

> > +static void n_tracerouter_close(struct tty_struct *tty)
> > > +{
> > > +	struct tracerouter_data *tptr = tty->disc_data;
> > > +
> > > +	WARN_ON(tptr->kref_tty != tr_data->kref_tty);
> > > +	tty_driver_flush_buffer(tty);
> > 
> > That code probably never run with lockdep as you would get a potential
> > deadlock warning. See n_tracerouter_open().
> > 
> > Though the deadlock cannot happen as you are protected by
> > tr_data->opencalled it does not make it more correct.
> > 
> 
> What do you suggest to make it correct for upstream?

Keep the lock ordering consistent. Either call that under the lock
always or do not.

Thanks,

	tglx

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

* Re: [PATCH 10/10] n_tracerouter and n_tracesink compile configurations.
  2011-02-24 18:07 ` [PATCH 10/10] n_tracerouter and n_tracesink compile configurations james_p_freyensee
@ 2011-02-25 18:00   ` Greg KH
  2011-02-25 18:39     ` J Freyensee
  2011-02-25 18:01   ` Greg KH
  1 sibling, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-02-25 18:00 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Thu, Feb 24, 2011 at 10:07:04AM -0800, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This patch allows n_tracerouter and n_tracesink to be compiled and
> configured in the Linux kernel.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> ---
>  drivers/char/Kconfig |   32 ++++++++++++++++++++++++++++++++

Why drivers/char/Kconfig?  This should be in drivers/tty/Kconfig, right?

Yes, this is a recent change, see the linux-next tree for the addition
of this file :)

thanks,

greg k-h

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

* Re: [PATCH 10/10] n_tracerouter and n_tracesink compile configurations.
  2011-02-24 18:07 ` [PATCH 10/10] n_tracerouter and n_tracesink compile configurations james_p_freyensee
  2011-02-25 18:00   ` Greg KH
@ 2011-02-25 18:01   ` Greg KH
  1 sibling, 0 replies; 171+ messages in thread
From: Greg KH @ 2011-02-25 18:01 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Thu, Feb 24, 2011 at 10:07:04AM -0800, james_p_freyensee@linux.intel.com wrote:
> --- a/drivers/tty/Makefile
> +++ b/drivers/tty/Makefile
> @@ -7,5 +7,7 @@ obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
>  obj-$(CONFIG_N_HDLC)		+= n_hdlc.o
>  obj-$(CONFIG_N_GSM)		+= n_gsm.o
>  obj-$(CONFIG_R3964)		+= n_r3964.o
> +obj-$(CONFIG_TRACE_ROUTER)      += n_tracerouter.o
> +obj-$(CONFIG_TRACE_SINK)        += n_tracesink.o

Please follow the standards of this file and use tabs :(


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

* Re: [PATCH 10/10] n_tracerouter and n_tracesink compile configurations.
  2011-02-25 18:00   ` Greg KH
@ 2011-02-25 18:39     ` J Freyensee
  2011-02-25 18:45       ` Greg KH
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-02-25 18:39 UTC (permalink / raw)
  To: Greg KH; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, 2011-02-25 at 10:00 -0800, Greg KH wrote:
> On Thu, Feb 24, 2011 at 10:07:04AM -0800, james_p_freyensee@linux.intel.com wrote:
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > This patch allows n_tracerouter and n_tracesink to be compiled and
> > configured in the Linux kernel.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > ---
> >  drivers/char/Kconfig |   32 ++++++++++++++++++++++++++++++++
> 
> Why drivers/char/Kconfig?  This should be in drivers/tty/Kconfig, right?
> 
> Yes, this is a recent change, see the linux-next tree for the addition
> of this file :)
> 

That is what I was going to ask because I did base this patch off of the
2.6.37 stable tree and did not see a drivers/tty/Kconfig :-O.  I figured
the stable branch was the better choice since you own it and I need to
go through you for my work.

So I should pull from linux-next I guess to fix the changes mentioned
this round?:

-Thomas's comments on Patch 9.
-These issues in this patch

?

Thanks,
jay

> thanks,
> 
> greg k-h



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

* Re: [PATCH 10/10] n_tracerouter and n_tracesink compile configurations.
  2011-02-25 18:39     ` J Freyensee
@ 2011-02-25 18:45       ` Greg KH
  0 siblings, 0 replies; 171+ messages in thread
From: Greg KH @ 2011-02-25 18:45 UTC (permalink / raw)
  To: J Freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, Feb 25, 2011 at 10:39:12AM -0800, J Freyensee wrote:
> On Fri, 2011-02-25 at 10:00 -0800, Greg KH wrote:
> > On Thu, Feb 24, 2011 at 10:07:04AM -0800, james_p_freyensee@linux.intel.com wrote:
> > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > 
> > > This patch allows n_tracerouter and n_tracesink to be compiled and
> > > configured in the Linux kernel.
> > > 
> > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > ---
> > >  drivers/char/Kconfig |   32 ++++++++++++++++++++++++++++++++
> > 
> > Why drivers/char/Kconfig?  This should be in drivers/tty/Kconfig, right?
> > 
> > Yes, this is a recent change, see the linux-next tree for the addition
> > of this file :)
> > 
> 
> That is what I was going to ask because I did base this patch off of the
> 2.6.37 stable tree and did not see a drivers/tty/Kconfig :-O.  I figured
> the stable branch was the better choice since you own it and I need to
> go through you for my work.

You should always submit against linux-next as that's pretty close to
the tree that we would be able to apply your patches to.  We can't go
back in time and add them to 2.6.37 :)

> So I should pull from linux-next I guess to fix the changes mentioned
> this round?:
> 
> -Thomas's comments on Patch 9.
> -These issues in this patch

Yes.

thanks,

greg k-h

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

* Re: [PATCH 03/10] Intel PTI implementaiton of MIPI 1149.7.
  2011-02-24 18:06 ` [PATCH 03/10] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
@ 2011-02-28  9:28   ` Arnd Bergmann
  2011-02-28 17:46     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Arnd Bergmann @ 2011-02-28  9:28 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

Hi James,

On Thursday 24 February 2011, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This driver is the Intel Atom implementation of MIPI P1149.7,
> compact JTAG standard for mobile devices.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> ---
>  drivers/misc/pti.c |  890 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 890 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/misc/pti.c

I have no idea what a "misc" driver really is, but this one clearly isn't
one. When you register a tty here, drivers/tty would be the right place.
> +
> +struct pti_tty {
> +	struct pti_masterchannel *mc;
> +};
> +
> +struct pti_dev {
> +	struct tty_port port;
> +	unsigned long pti_addr;
> +	unsigned long aperture_base;
> +	void __iomem *pti_ioaddr;
> +	unsigned long pti_iolen;

pti_adr, aperture_base and pti_iolen seem to be unused in the driver, you
only use them to get pti_ioaddr, so no need to store them.

> +	u8 IA_App[MAX_APP_IDS];
> +	u8 IA_OS[MAX_OS_IDS];
> +	u8 IA_Modem[MAX_MODEM_IDS];

Please use lowercase identifiers.

> +static DEFINE_MUTEX(alloclock);

It's not really clear what this protects. Please add some comment here.

> +static struct tty_driver *pti_tty_driver;
> +
> +static struct pti_dev *drv_data;

You use drv_data both for the global structure and for local variables,
which is rather confusing to the reader.

> +static unsigned int pti_console_channel;
> +static unsigned int pti_control_channel;

These don't need to be global, because they are only used in one function
each (besides a pointless initialization).

Are you sure that you need no locking for them?


> +static ssize_t pti_char_write(struct file *filp, const char __user *data,
> +			      size_t len, loff_t *ppose)
> +{
> +	struct pti_masterchannel *mc;
> +	void *kbuf;
> +	const char __user *tmp;
> +	size_t size = USER_COPY_SIZE, n = 0;
> +
> +	tmp = data;
> +	mc = filp->private_data;
> +
> +	kbuf = kmalloc(size, GFP_KERNEL);
> +	if (kbuf == NULL)  {
> +		pr_err("%s(%d): buf allocation failed\n",
> +			__func__, __LINE__);
> +		return 0;
> +	}
> +
> +	do {
> +		if (len - n > USER_COPY_SIZE)
> +			size = USER_COPY_SIZE;
> +		else
> +			size = len - n;
> +
> +		if (copy_from_user(kbuf, tmp, size)) {
> +			kfree(kbuf);
> +			return n ? n : -EFAULT;
> +		}
> +
> +		pti_write_to_aperture(mc, kbuf, size);
> +		n  += size;
> +		tmp += size;
> +
> +	} while (len > n);
> +
> +	kfree(kbuf);
> +	kbuf = NULL;
> +
> +	return len;
> +}

You write chunks of 8KB here, which sounds rather large for a serial port.
Is that intentional? What is the typical line rate? If you need more than
a milisecond for a single write, you should probably return a short write
to user space or at least call cond_resched() to be more friendly to
other tasks.

> +static const struct tty_operations pti_tty_driver_ops = {
> +	.open		= pti_tty_driver_open,
> +	.close		= pti_tty_driver_close,
> +	.write		= pti_tty_driver_write,
> +	.write_room	= pti_tty_write_room,
> +	.install	= pti_tty_install,
> +	.cleanup	= pti_tty_cleanup
> +};
> +
> +static const struct file_operations pti_char_driver_ops = {
> +	.owner		= THIS_MODULE,
> +	.write		= pti_char_write,
> +	.open		= pti_char_open,
> +	.release	= pti_char_release,
> +};
> +
> +static struct miscdevice pti_char_driver = {
> +	.minor		= MISC_DYNAMIC_MINOR,
> +	.name		= CHARNAME,
> +	.fops		= &pti_char_driver_ops
> +};
> +

It's really strange to have both a tty and a character device that have similar
operations. Why can't you have the pti_char_driver functionality in the tty driver?

	Arnd

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

* Re: [PATCH 05/10] PTI header file.
  2011-02-24 18:06 ` [PATCH 05/10] PTI header file james_p_freyensee
@ 2011-02-28  9:30   ` Arnd Bergmann
  0 siblings, 0 replies; 171+ messages in thread
From: Arnd Bergmann @ 2011-02-28  9:30 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Thursday 24 February 2011, james_p_freyensee@linux.intel.com wrote:
> 
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This adds PTI header information for the PTI project.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>

Don't split the changes by file, but by functionality.

The header file belongs with the code whose interfaces it exports, so
merge it into that patch.

Just make sure that the patch order is right, so you introduce the file before
you use it.

	Arnd

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

* Re: [PATCH 04/10] PTI Makefile and Kconfig additions.
  2011-02-24 18:06 ` [PATCH 04/10] PTI Makefile and Kconfig additions james_p_freyensee
@ 2011-02-28  9:31   ` Arnd Bergmann
  2011-02-28 17:49     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Arnd Bergmann @ 2011-02-28  9:31 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Thursday 24 February 2011, james_p_freyensee@linux.intel.com wrote:
> 
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This allows the Intel implementation of the PTI standard to be
> compiled and configured in Kconfig.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>

This belongs together with the pti.c file, just merge the patches
into one.

The Kconfig description is a nice text, how about copying it to the
changeset so that reviewers know what the driver is about?

	Arnd

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

* Re: [PATCH 03/10] Intel PTI implementaiton of MIPI 1149.7.
  2011-02-28  9:28   ` Arnd Bergmann
@ 2011-02-28 17:46     ` J Freyensee
  2011-02-28 18:36       ` Thomas Gleixner
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-02-28 17:46 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Mon, 2011-02-28 at 10:28 +0100, Arnd Bergmann wrote:
> Hi James,
> 
> On Thursday 24 February 2011, james_p_freyensee@linux.intel.com wrote:
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > This driver is the Intel Atom implementation of MIPI P1149.7,
> > compact JTAG standard for mobile devices.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > ---
> >  drivers/misc/pti.c |  890 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 files changed, 890 insertions(+), 0 deletions(-)
> >  create mode 100644 drivers/misc/pti.c
> 
> I have no idea what a "misc" driver really is, but this one clearly isn't
> one. When you register a tty here, drivers/tty would be the right place.

It went in misc because this driver has a tty interface, char interface,
and uses other things like console.  It is not just a tty-only device.

> > +
> > +struct pti_tty {
> > +	struct pti_masterchannel *mc;
> > +};
> > +
> > +struct pti_dev {
> > +	struct tty_port port;
> > +	unsigned long pti_addr;
> > +	unsigned long aperture_base;
> > +	void __iomem *pti_ioaddr;
> > +	unsigned long pti_iolen;
> 
> pti_adr, aperture_base and pti_iolen seem to be unused in the driver, you
> only use them to get pti_ioaddr, so no need to store them.
> 
> > +	u8 IA_App[MAX_APP_IDS];
> > +	u8 IA_OS[MAX_OS_IDS];
> > +	u8 IA_Modem[MAX_MODEM_IDS];
> 
> Please use lowercase identifiers.
> 
> > +static DEFINE_MUTEX(alloclock);
> 
> It's not really clear what this protects. Please add some comment here.
> 
> > +static struct tty_driver *pti_tty_driver;
> > +
> > +static struct pti_dev *drv_data;
> 
> You use drv_data both for the global structure and for local variables,
> which is rather confusing to the reader.
> 
> > +static unsigned int pti_console_channel;
> > +static unsigned int pti_control_channel;
> 
> These don't need to be global, because they are only used in one function
> each (besides a pointless initialization).
> 
> Are you sure that you need no locking for them?
> 
> 
> > +static ssize_t pti_char_write(struct file *filp, const char __user *data,
> > +			      size_t len, loff_t *ppose)
> > +{
> > +	struct pti_masterchannel *mc;
> > +	void *kbuf;
> > +	const char __user *tmp;
> > +	size_t size = USER_COPY_SIZE, n = 0;
> > +
> > +	tmp = data;
> > +	mc = filp->private_data;
> > +
> > +	kbuf = kmalloc(size, GFP_KERNEL);
> > +	if (kbuf == NULL)  {
> > +		pr_err("%s(%d): buf allocation failed\n",
> > +			__func__, __LINE__);
> > +		return 0;
> > +	}
> > +
> > +	do {
> > +		if (len - n > USER_COPY_SIZE)
> > +			size = USER_COPY_SIZE;
> > +		else
> > +			size = len - n;
> > +
> > +		if (copy_from_user(kbuf, tmp, size)) {
> > +			kfree(kbuf);
> > +			return n ? n : -EFAULT;
> > +		}
> > +
> > +		pti_write_to_aperture(mc, kbuf, size);
> > +		n  += size;
> > +		tmp += size;
> > +
> > +	} while (len > n);
> > +
> > +	kfree(kbuf);
> > +	kbuf = NULL;
> > +
> > +	return len;
> > +}
> 
> You write chunks of 8KB here, which sounds rather large for a serial port.
> Is that intentional? What is the typical line rate? If you need more than
> a milisecond for a single write, you should probably return a short write
> to user space or at least call cond_resched() to be more friendly to
> other tasks.

Yes, 8KB of chunks is intentional.  In a side review with Alan cox, we
concluded 8KB was an appropriate size for this driver.

> 
> > +static const struct tty_operations pti_tty_driver_ops = {
> > +	.open		= pti_tty_driver_open,
> > +	.close		= pti_tty_driver_close,
> > +	.write		= pti_tty_driver_write,
> > +	.write_room	= pti_tty_write_room,
> > +	.install	= pti_tty_install,
> > +	.cleanup	= pti_tty_cleanup
> > +};
> > +
> > +static const struct file_operations pti_char_driver_ops = {
> > +	.owner		= THIS_MODULE,
> > +	.write		= pti_char_write,
> > +	.open		= pti_char_open,
> > +	.release	= pti_char_release,
> > +};
> > +
> > +static struct miscdevice pti_char_driver = {
> > +	.minor		= MISC_DYNAMIC_MINOR,
> > +	.name		= CHARNAME,
> > +	.fops		= &pti_char_driver_ops
> > +};
> > +
> 
> It's really strange to have both a tty and a character device that have similar
> operations. Why can't you have the pti_char_driver functionality in the tty driver?
> 

Because that is not what the customer wanted and this is why the driver
is located in misc/ ;-).  


> 	Arnd



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

* Re: [PATCH 04/10] PTI Makefile and Kconfig additions.
  2011-02-28  9:31   ` Arnd Bergmann
@ 2011-02-28 17:49     ` J Freyensee
  2011-03-01 11:37       ` Arnd Bergmann
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-02-28 17:49 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Mon, 2011-02-28 at 10:31 +0100, Arnd Bergmann wrote:
> On Thursday 24 February 2011, james_p_freyensee@linux.intel.com wrote:
> > 
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > This allows the Intel implementation of the PTI standard to be
> > compiled and configured in Kconfig.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This belongs together with the pti.c file, just merge the patches
> into one.
> 
> The Kconfig description is a nice text, how about copying it to the
> changeset so that reviewers know what the driver is about?
> 
> 	Arnd

I thought patch 02/10, 'Kernel documentation', would had been first and
met this need?  


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

* Re: [PATCH 03/10] Intel PTI implementaiton of MIPI 1149.7.
  2011-02-28 17:46     ` J Freyensee
@ 2011-02-28 18:36       ` Thomas Gleixner
  0 siblings, 0 replies; 171+ messages in thread
From: Thomas Gleixner @ 2011-02-28 18:36 UTC (permalink / raw)
  To: J Freyensee
  Cc: Arnd Bergmann, gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Mon, 28 Feb 2011, J Freyensee wrote:
> On Mon, 2011-02-28 at 10:28 +0100, Arnd Bergmann wrote:
> > > +static struct miscdevice pti_char_driver = {
> > > +	.minor		= MISC_DYNAMIC_MINOR,
> > > +	.name		= CHARNAME,
> > > +	.fops		= &pti_char_driver_ops
> > > +};
> > > +
> > 
> > It's really strange to have both a tty and a character device that have similar
> > operations. Why can't you have the pti_char_driver functionality in the tty driver?
> > 
> 
> Because that is not what the customer wanted and this is why the driver
> is located in misc/ ;-).  

Brilliant argument. Next time you tell us that the customer wanted a
root hole in his driver and that's why you put it there.

What's the fcking technical reason for having a char and a tty device ?

Thanks,

	tglx

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

* Re: [PATCH 04/10] PTI Makefile and Kconfig additions.
  2011-02-28 17:49     ` J Freyensee
@ 2011-03-01 11:37       ` Arnd Bergmann
  2011-03-01 17:37         ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Arnd Bergmann @ 2011-03-01 11:37 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Monday 28 February 2011, J Freyensee wrote:
> On Mon, 2011-02-28 at 10:31 +0100, Arnd Bergmann wrote:
>
> > The Kconfig description is a nice text, how about copying it to the
> > changeset so that reviewers know what the driver is about?
> > 
> 
> I thought patch 02/10, 'Kernel documentation', would had been first and
> met this need?  

Documentation in source files is not the same as documentation in the
changelog, you need both. The changeset comments are usually just one
sentence in your series, and a little more would certainly be helpful.

Also, if you have one changeset with the documentation, that does
not help anyone who looks at another changeset.

	Arnd

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

* Re: [PATCH 04/10] PTI Makefile and Kconfig additions.
  2011-03-01 11:37       ` Arnd Bergmann
@ 2011-03-01 17:37         ` J Freyensee
  0 siblings, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-03-01 17:37 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 2011-03-01 at 12:37 +0100, Arnd Bergmann wrote:
> On Monday 28 February 2011, J Freyensee wrote:
> > On Mon, 2011-02-28 at 10:31 +0100, Arnd Bergmann wrote:
> >
> > > The Kconfig description is a nice text, how about copying it to the
> > > changeset so that reviewers know what the driver is about?
> > > 
> > 
> > I thought patch 02/10, 'Kernel documentation', would had been first and
> > met this need?  
> 
> Documentation in source files is not the same as documentation in the
> changelog, you need both. The changeset comments are usually just one
> sentence in your series, and a little more would certainly be helpful.
> 

Okay, I can do that.

Thanks,
Jay

> Also, if you have one changeset with the documentation, that does
> not help anyone who looks at another changeset.
> 
> 	Arnd



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

* 3rd request for review & addition of PTI/n_trace implementation into kernel
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (12 preceding siblings ...)
  2011-02-24 18:07 ` [PATCH 10/10] n_tracerouter and n_tracesink compile configurations james_p_freyensee
@ 2011-04-19 22:58 ` james_p_freyensee
  2011-04-19 22:58 ` [PATCH 1/4] export kernel call get_task_comm() james_p_freyensee
                   ` (27 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-04-19 22:58 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

Apologies for a long delay between submission attempts- this is the 3rd request
for review and acceptance into the mainline kernel for the Intel-Atom
implementation of the MIPI P1149.7 compact JTAG
standard for mobile devices.  Complete documentation and background
has been provided in PATCH 02/12, "Kernel documentation for the PTI
feature".  PATCH 01/12 is a kernel fix to allow the PTI driver
to compile modularly; this is a fix Greg KH, Alan Cox, and Arjan
van de Ven and I talked about a while ago.  It's not techincally
related to PTI, but it is it's own separate patch so it can be
applied independent of any possible problems with the PTI submission.

Changes/fixes from last review include:
-lock acquire and release same ordering in n_tracesink and n_tracerouter
-variable renaming in pti.c
-elimination of one variable not used in pti.c
-patch groups submissions in logical, independent chunks instead one
 file per patch.
-use of linux-next instead of linux-stable for patch base
-Kconfig descriptions appearing in patch descriptions for
 pti and n_tracesink/n_tracerouter, as requested.

Thanks for your help and time. Regards,
J Freyensee

From: james_p_freyensee@linux.intel.com
Subject: 3rd request for review & addition of PTI/n_trace implementation into kernel
In-Reply-To: james_p_freyensee@linux.intel.com


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

* [PATCH 1/4] export kernel call get_task_comm().
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (13 preceding siblings ...)
  2011-04-19 22:58 ` 3rd request for review & addition of PTI/n_trace implementation into kernel james_p_freyensee
@ 2011-04-19 22:58 ` james_p_freyensee
  2011-04-19 23:22   ` David Rientjes
  2011-04-19 22:58 ` [PATCH 2/4] Kernel documentation for the PTI feature james_p_freyensee
                   ` (26 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-04-19 22:58 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows drivers who call this function to be compiled modularly.
Otherwise, a driver who is interested in this type of functionality
has to implement their own get_task_comm() call, causing code
duplication in the Linux source tree.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 fs/exec.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 8328beb..e1ac338 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1004,6 +1004,7 @@ char *get_task_comm(char *buf, struct task_struct *tsk)
 	task_unlock(tsk);
 	return buf;
 }
+EXPORT_SYMBOL_GPL(get_task_comm);
 
 void set_task_comm(struct task_struct *tsk, char *buf)
 {
-- 
1.7.2.3


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

* [PATCH 2/4] Kernel documentation for the PTI feature.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (14 preceding siblings ...)
  2011-04-19 22:58 ` [PATCH 1/4] export kernel call get_task_comm() james_p_freyensee
@ 2011-04-19 22:58 ` james_p_freyensee
  2011-04-19 23:26   ` Randy Dunlap
  2011-04-19 22:58 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
                   ` (25 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-04-19 22:58 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This provides Kernel documentation for the PTI
feature and setting line discipline drivers
on top of tty's for Linux mobile solutions.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 Documentation/pti/pti_intel_mid.txt |   99 +++++++++++++++++++++++++++++++++++
 1 files changed, 99 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/pti/pti_intel_mid.txt

diff --git a/Documentation/pti/pti_intel_mid.txt b/Documentation/pti/pti_intel_mid.txt
new file mode 100644
index 0000000..900f6db
--- /dev/null
+++ b/Documentation/pti/pti_intel_mid.txt
@@ -0,0 +1,99 @@
+The Intel MID PTI project is HW implemented in Intel Atom
+system-on-a-chip designs based on the Parallel Trace
+Interface for MIPI P1149.7 cJTAG standard.  The kernel solution
+for this platform involves the following files:
+
+./include/linux/pti.h
+./drivers/.../n_tracesink.h
+./drivers/.../n_tracerouter.c
+./drivers/.../n_tracesink.c
+./drivers/.../pti.c
+
+pti.c is the driver that enables various debugging features
+popular on certain mobile manufacturers.  n_tracerouter.c
+and n_tracesink.c allow extra system information to be
+collected and routed to the pti driver, such as trace
+debugging data from a modem.  Although n_tracerouter
+and n_tracesink are a part of the complete PTI solution,
+these two line disciplines can work separately from
+pti.c and route any data stream from one /dev/tty node
+to another /dev/tty node via kernel-space.  This provides
+a stable, reliable connection that will not break unless
+the user-space application shuts down (plus avoids
+kernel->user->kernel context switch overheads of routing
+data).
+
+An example debugging usage for this driver system:
+   *Hook /dev/ttyPTI0 to syslogd.  Opening this port will also start
+    a console device to further capture debugging messages to PTI.
+   *Hook /dev/ttyPTI1 to modem debugging data to write to PTI HW.
+    This is where n_tracerouter and n_tracesink are used.
+   *Hook /dev/pti to a user-level debugging application for writing
+    to PTI HW.
+   *Use mipi_* Kernel Driver API in other device drivers for
+    debugging to PTI by first requesting a PTI write address via
+    mipi_request_masterchannel(1).
+
+Below is example pseudo-code on how a 'privileged' application
+can hook up n_tracerouter and n_tracesink to any tty on
+a system.  'Privileged' means the application has enough
+privileges to successfully manipulate the ldisc drivers
+but is not just blindly executing as 'root'. Keep in mind
+the use of ioctl(,TIOCSETD,) is not specific to the n_tracerouter
+and n_tracesink line discpline drivers but is a generic
+operation for a program to use a line discpline driver
+on a tty port other than the default n_tty.
+
+/////////// To hook up n_tracerouter and n_tracesink /////////
+
+// Note that n_tracerouter depends on n_tracesink.
+#include <errno.h>
+#define ONE_TTY "/dev/ttyOne"
+#define TWO_TTY "/dev/ttyTwo"
+
+// needed global to hand onto ldisc connection
+static int g_fd_source = -1;
+static int g_fd_sink  = -1;
+
+// these two vars used to grab LDISC values from loaded ldisc drivers
+// in OS.  Look at /proc/tty/ldiscs to get the right numbers from
+// the ldiscs loaded in the system.
+int source_ldisc_num, sink_ldisc_num = -1;
+int retval;
+
+g_fd_source = open(ONE_TTY, O_RDWR); // must be R/W
+g_fd_sink   = open(TWO_TTY, O_RDWR); // must be R/W
+
+if (g_fd_source <= 0) || (g_fd_sink <= 0) {
+   // doubt you'll want to use these exact error lines of code
+   printf("Error on open(). errno: %d\n",errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_sink, TIOCSETD, &sink_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_source, TIOCSETD, &source_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+/////////// To disconnect n_tracerouter and n_tracesink ////////
+
+// First make sure data through the ldiscs has stopped.
+
+// Second, disconnect ldiscs.  This provides a
+// little cleaner shutdown on tty stack.
+sink_ldisc_num = 0;
+source_ldisc_num = 0;
+ioctl(g_fd_uart, TIOCSETD, &sink_ldisc_num);
+ioctl(g_fd_gadget, TIOCSETD, &source_ldisc_num);
+
+// Three, program closes connection, and cleanup:
+close(g_fd_uart);
+close(g_fd_gadget);
+g_fd_uart = g_fd_gadget = NULL;
-- 
1.7.2.3


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

* [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (15 preceding siblings ...)
  2011-04-19 22:58 ` [PATCH 2/4] Kernel documentation for the PTI feature james_p_freyensee
@ 2011-04-19 22:58 ` james_p_freyensee
  2011-04-19 23:15   ` Randy Dunlap
  2011-04-20  1:25   ` David Rientjes
  2011-04-19 22:58 ` [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions james_p_freyensee
                   ` (24 subsequent siblings)
  41 siblings, 2 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-04-19 22:58 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

The PTI (Parallel Trace Interface) driver directs
trace data routed from various parts in the system out
through an Intel Penwell PTI port and out of the mobile
device for analysis with a debugging tool (Lauterbach or Fido).
Though n_tracesink and n_tracerouter line discipline drivers
are used to extract modem tracing data to the PTI driver
and other parts of an Intel mobile solution, the PTI driver
can be used independent of n_tracesink and n_tracerouter.

You should select this driver if the target kernel is meant for
an Intel Atom (non-netbook) mobile device containing a MIPI
P1149.7 standard implementation.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/Kconfig  |   12 +
 drivers/misc/Makefile |    1 +
 drivers/misc/pti.c    |  898 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pti.h   |   39 +++
 4 files changed, 950 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pti.c
 create mode 100644 include/linux/pti.h

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4e007c6..95baff1 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -144,6 +144,18 @@ config PHANTOM
 	  If you choose to build module, its name will be phantom. If unsure,
 	  say N here.
 
+config INTEL_MID_PTI
+        tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
+        help
+          The PTI (Parallel Trace Interface) driver directs
+          trace data routed from various parts in the system out
+          through an Intel Penwell PTI port and out of the mobile
+          device for analysis with a debugging tool (Lauterbach or Fido).
+
+          You should select this driver if the target kernel is meant for
+          an Intel Atom (non-netbook) mobile device containing a MIPI
+          P1149.7 standard implementation.
+
 config SGI_IOC4
 	tristate "SGI IOC4 Base IO support"
 	depends on PCI
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index f546860..662aa3c 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_IBM_ASM)		+= ibmasm/
 obj-$(CONFIG_AD525X_DPOT)	+= ad525x_dpot.o
 obj-$(CONFIG_AD525X_DPOT_I2C)	+= ad525x_dpot-i2c.o
 obj-$(CONFIG_AD525X_DPOT_SPI)	+= ad525x_dpot-spi.o
+0bj-$(CONFIG_INTEL_MID_PTI)	+= pti.o
 obj-$(CONFIG_ATMEL_PWM)		+= atmel_pwm.o
 obj-$(CONFIG_ATMEL_SSC)		+= atmel-ssc.o
 obj-$(CONFIG_ATMEL_TCLIB)	+= atmel_tclib.o
diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
new file mode 100644
index 0000000..f3a2980
--- /dev/null
+++ b/drivers/misc/pti.c
@@ -0,0 +1,898 @@
+/*
+ *  pti.c - PTI driver for cJTAG data extration
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ */
+
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/console.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/pci.h>
+#include <linux/mutex.h>
+#include <linux/miscdevice.h>
+#include <linux/pti.h>
+
+#define DRIVERNAME		"pti"
+#define PCINAME			"pciPTI"
+#define TTYNAME			"ttyPTI"
+#define CHARNAME		"pti"
+#define PTITTY_MINOR_START	0
+#define PTITTY_MINOR_NUM	2
+#define MAX_APP_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_OS_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_MODEM_IDS		16   /* 128 channel ids / u8 bit size */
+#define MODEM_BASE_ID		71   /* modem master ID address    */
+#define CONTROL_ID		72   /* control master ID address  */
+#define CONSOLE_ID		73   /* console master ID address  */
+#define OS_BASE_ID		74   /* base OS master ID address  */
+#define APP_BASE_ID		80   /* base App master ID address */
+#define CONTROL_FRAME_LEN	32   /* PTI control frame maximum size */
+#define USER_COPY_SIZE		8192 /* 8Kb buffer for user space copy */
+#define APERTURE_14		0x3800000 /* offset to first OS write addr */
+#define APERTURE_LEN		0x400000  /* address length */
+
+struct pti_tty {
+	struct pti_masterchannel *mc;
+};
+
+struct pti_dev {
+	struct tty_port port;
+	unsigned long pti_addr;
+	unsigned long aperture_base;
+	void __iomem *pti_ioaddr;
+	u8 ia_app[MAX_APP_IDS];
+	u8 ia_os[MAX_OS_IDS];
+	u8 ia_modem[MAX_MODEM_IDS];
+};
+
+/*
+   This protects access to ia_app, ia_os, and ia_modem,
+   which keeps track of channels allocated in
+   an aperture write id.
+*/
+static DEFINE_MUTEX(alloclock);
+
+static struct pci_device_id pci_ids[] __devinitconst = {
+		{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B) },
+		{0}
+};
+
+static struct tty_driver *pti_tty_driver;
+
+static struct pti_dev *drv_data;
+
+static unsigned int pti_console_channel;
+static unsigned int pti_control_channel;
+
+#define DTS 0x30		/* offset for last dword of a PTI message */
+
+/**
+ *  pti_write_to_aperture() - THE private write function to PTI HW.
+ *  @mc: The 'aperture'. It's part of a write address that holds
+ *       a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  Since each aperture is specified by a unique
+ *  master/channel ID, no two processes will be writing
+ *  to the same aperture at the same time so no lock is required. The
+ *  PTI-Output agent will send these out in the order that they arrived, and
+ *  thus, it will intermix these messages. The debug tool can then later
+ *  regroup the appropriate message segments together reconstituting each
+ *  message.
+ */
+static void pti_write_to_aperture(struct pti_masterchannel *mc,
+				  u8 *buf,
+				  int len)
+{
+	int dwordcnt, final, i;
+	u32 ptiword;
+	u8 *p;
+	u32 __iomem *aperture;
+
+	p = buf;
+
+	/*
+	   calculate the aperture offset from the base using the master and
+	   channel id's.
+	*/
+	aperture = drv_data->pti_ioaddr + (mc->master << 15)
+		+ (mc->channel << 8);
+
+	dwordcnt = len >> 2;
+	final = len - (dwordcnt << 2);		/* final = trailing bytes */
+	if (final == 0 && dwordcnt != 0) {	/* always have a final dword */
+		final += 4;
+		dwordcnt--;
+	}
+
+	for (i = 0; i < dwordcnt; i++) {
+		ptiword = be32_to_cpu(*(u32 *)p);
+		p += 4;
+		iowrite32(ptiword, aperture);
+	}
+
+	aperture += DTS;		/* adding DTS signals that is EOM */
+
+	ptiword = 0;
+	for (i = 0; i < final; i++)
+		ptiword |= *p++ << (24-(8*i));
+
+	iowrite32(ptiword, aperture);
+	return;
+}
+
+/**
+ *  pti_control_frame_built_and_sent() - control frame build and send function.
+ *  @mc: The master / channel structure on which the function built a control
+ *  frame.
+ *
+ *  To be able to post process the PTI contents on host side, a control frame
+ *  is added before sending any PTI content. So the host side knows on
+ *  each PTI frame the name of the thread using a dedicated master / channel.
+ *  This function builds this frame and sends it to a master ID CONTROL_ID.
+ *  The overhead is only 32 bytes since the driver only writes to HW
+ *  in 32 byte chunks.
+ */
+
+static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc)
+{
+	struct pti_masterchannel mccontrol = {.master = CONTROL_ID,
+					      .channel = 0};
+	const char *control_format = "%3d %3d %s";
+
+	char comm[sizeof(current->comm) + 1];
+	u8 control_frame[CONTROL_FRAME_LEN];
+
+	if (!in_interrupt())
+		get_task_comm(comm, current);
+	else
+		strcpy(comm, "Interrupt");
+
+	/* Ensure our buffer is zero terminated */
+	comm[sizeof(current->comm)] = 0;
+
+	mccontrol.channel = pti_control_channel;
+	pti_control_channel = (pti_control_channel + 1) & 0x7f;
+
+	snprintf(control_frame, CONTROL_FRAME_LEN, control_format, mc->master,
+		mc->channel, comm);
+	pti_write_to_aperture(&mccontrol, control_frame, strlen(control_frame));
+}
+
+/**
+ *  pti_write_full_frame_to_aperture() - high level function to write to PTI
+ *  @mc: The 'aperture'. It's part of a write address that holds
+ *       a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  All threads sending data (either console, user space application, ...)
+ *  are calling the high level function to write to PTI meaning that it is
+ *  possible to add a control frame before sending the content.
+ */
+static void pti_write_full_frame_to_aperture(struct pti_masterchannel *mc,
+						const unsigned char *buf,
+						int len)
+{
+	pti_control_frame_built_and_sent(mc);
+	pti_write_to_aperture(mc, (u8 *)buf, len);
+}
+
+
+/**
+ * getID(): Allocate a master and channel ID.
+ *
+ * @IDarray:
+ * @max_IDS: The max amount of available write IDs to use.
+ * @baseID:  The starting SW channel ID, based on the Intel
+ *           PTI arch.
+ *
+ * @return: pti_masterchannel struct containing master, channel ID address,
+ * or 0 for error.
+ *
+ * Each bit in the arrays ia_app and ia_os correspond to a master and
+ * channel id. The bit is one if the id is taken and 0 if free. For
+ * every master there are 128 channel id's.
+ */
+static struct pti_masterchannel *getID(u8 *IDarray, int max_IDS, int baseID)
+{
+	struct pti_masterchannel *mc;
+	int i, j, mask;
+
+	mc = kmalloc(sizeof(struct pti_masterchannel), GFP_KERNEL);
+	if (mc == NULL)
+		return NULL;
+
+	/* look for a byte with a free bit */
+	for (i = 0; i < max_IDS; i++)
+		if (IDarray[i] != 0xff)
+			break;
+	if (i == max_IDS) {
+		kfree(mc);
+		return NULL;
+	}
+	/* find the bit in the 128 possible channel opportunities */
+	mask = 0x80;
+	for (j = 0; j < 8; j++) {
+		if ((IDarray[i] & mask) == 0)
+			break;
+		mask >>= 1;
+	}
+
+	/* grab it */
+	IDarray[i] |= mask;
+	mc->master  = baseID;
+	mc->channel = ((i & 0xf)<<3) + j;
+	/* write new master Id / channel Id allocation to channel control */
+	pti_control_frame_built_and_sent(mc);
+	return mc;
+}
+
+/*
+	The following three functions:
+	pti_request_mastercahannel(), mipi_release_masterchannel()
+	and pti_writedata() are an API for other kernel drivers to
+	access PTI.
+*/
+
+/**
+ * pti_request_masterchannel() - Kernel API function used to allocate
+ *                                a master, channel ID address to write to
+ *                                PTI HW.
+ * @type: 0- request Application  master, channel aperture ID write address.
+ *        1- request OS master, channel aperture ID write address.
+ *        2- request Modem master, channel aperture ID write
+ *           address.
+ *        Other values, error.
+ * @return: pti_masterchannel struct or 0 for error.
+ *
+ */
+struct pti_masterchannel *pti_request_masterchannel(u8 type)
+{
+	struct pti_masterchannel *mc;
+
+	mutex_lock(&alloclock);
+
+	switch (type) {
+
+	case 0:
+		mc = getID(drv_data->ia_app, MAX_APP_IDS, APP_BASE_ID);
+		break;
+
+	case 1:
+		mc = getID(drv_data->ia_os, MAX_OS_IDS, OS_BASE_ID);
+		break;
+
+	case 2:
+		mc = getID(drv_data->ia_modem, MAX_MODEM_IDS, MODEM_BASE_ID);
+		break;
+	default:
+		mc = NULL;
+	}
+
+	mutex_unlock(&alloclock);
+	return mc;
+}
+EXPORT_SYMBOL_GPL(pti_request_masterchannel);
+
+/**
+ * pti_release_masterchannel() - Kernel API function used to release
+ *                                a master, channel ID address
+ *                                used to write to PTI HW.
+ * @mc: master, channel apeture ID address to be released.
+ *
+ */
+void pti_release_masterchannel(struct pti_masterchannel *mc)
+{
+	u8 master, channel, i;
+
+	mutex_lock(&alloclock);
+
+	if (mc) {
+		master = mc->master;
+		channel = mc->channel;
+
+		if (master == APP_BASE_ID) {
+			i = channel >> 3;
+			drv_data->ia_app[i] &=  ~(0x80>>(channel & 0x7));
+		} else if (master == OS_BASE_ID) {
+			i = channel >> 3;
+			drv_data->ia_os[i] &= ~(0x80>>(channel & 0x7));
+		} else {
+			i = channel >> 3;
+			drv_data->ia_modem[i] &= ~(0x80>>(channel & 0x7));
+		}
+
+		kfree(mc);
+	}
+
+	mutex_unlock(&alloclock);
+}
+EXPORT_SYMBOL_GPL(pti_release_masterchannel);
+
+/**
+ * pti_writedata() - Kernel API function used to write trace
+ *                   debugging data to PTI HW.
+ *
+ * @mc:    Master, channel aperture ID address to write to.
+ *         Null value will return with no write occurring.
+ * @buf:   Trace debuging data to write to the PTI HW.
+ *         Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         retrn with no write occuring.
+ */
+void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
+{
+	/*
+	   since this function is exported, this is treated like an
+	   API function, thus, all parameters should
+	   be checked for validity.
+	*/
+	if ((mc != NULL) && (buf != NULL) && (count > 0))
+		pti_write_to_aperture(mc, buf, count);
+	return;
+}
+EXPORT_SYMBOL_GPL(pti_writedata);
+
+static void __devexit pti_pci_remove(struct pci_dev *pdev)
+{
+	struct pti_dev *drv_data;
+
+	drv_data = pci_get_drvdata(pdev);
+	if (drv_data != NULL) {
+		pci_iounmap(pdev, drv_data->pti_ioaddr);
+		pci_set_drvdata(pdev, NULL);
+		kfree(drv_data);
+		pci_release_region(pdev, 1);
+		pci_disable_device(pdev);
+	}
+}
+
+/*
+   for the tty_driver_*() basic function descriptions, see tty_driver.h.
+   Specific header comments made for PTI-related specifics.
+*/
+
+/**
+ * pti_tty_driver_open()- Open an Application master, channel aperture
+ * ID to the PTI device via tty device.
+ *
+ * @param tty: tty interface.
+ * @param filp: filp interface pased to tty_port_open() call.
+ *
+ * @return int : Success = 0, otherwise fail.
+ *
+ * The main purpose of using the tty device interface is for
+ * each tty port to have a unique PTI write aperture.  In an
+ * example use case, ttyPTI0 gets syslogd and an APP aperture
+ * ID and ttyPTI1 is where the n_tracesink ldisc hooks to route
+ * modem messages into PTI.  Modem trace data does not have to
+ * go to ttyPTI1, but ttyPTI0 and ttyPTI1 do need to be distinct
+ * master IDs.  These messages go through the PTI HW and out of
+ * the handheld platform and to the Fido/Lauterbach device.
+ */
+static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
+{
+	int ret = 0;
+
+	/*
+	   we actually want to allocate a new channel per open, per
+	   system arch.  HW gives more than plenty channels for a single
+	   system task to have its own channel to write trace data. This
+	   also removes a locking requirement for the actual write
+	   procedure.
+	*/
+	ret = tty_port_open(&drv_data->port, tty, filp);
+
+	return ret;
+}
+
+/**
+ * pti_tty_driver_close()- close tty device and release Application
+ * master, channel aperture ID to the PTI device via tty device.
+ *
+ * @param tty: tty interface.
+ * @param filp: filp interface pased to tty_port_close() call.
+ *
+ * The main purpose of using the tty device interface is to route
+ * syslog daemon messages to the PTI HW and out of the handheld platform
+ * and to the Fido/Lauterbach device.
+ */
+static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
+{
+	tty_port_close(&drv_data->port, tty, filp);
+
+	return;
+}
+
+static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
+{
+	int idx = tty->index;
+	struct pti_tty *pti_tty_data;
+	struct pti_masterchannel *mc;
+	int ret = tty_init_termios(tty);
+
+	if (ret == 0) {
+		tty_driver_kref_get(driver);
+		tty->count++;
+		driver->ttys[idx] = tty;
+
+		pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL);
+		if (pti_tty_data == NULL)
+			return -ENOMEM;
+
+		tty->driver_data = pti_tty_data;
+
+		if (idx == PTITTY_MINOR_START)
+			mc = pti_request_masterchannel(0);
+		else
+			mc = pti_request_masterchannel(2);
+
+		if (mc == NULL)
+			return -ENXIO;
+
+		pti_tty_data->mc = mc;
+	}
+
+	return ret;
+}
+
+static void pti_tty_cleanup(struct tty_struct *tty)
+{
+	struct pti_tty *pti_tty_data;
+	struct pti_masterchannel *mc;
+
+	pti_tty_data = tty->driver_data;
+
+	if (pti_tty_data != NULL) {
+		mc = pti_tty_data->mc;
+		pti_release_masterchannel(mc);
+		pti_tty_data->mc = NULL;
+	}
+
+	if (pti_tty_data != NULL)
+		kfree(pti_tty_data);
+
+	tty->driver_data = NULL;
+}
+
+/**
+ * pti_tty_driver_write():  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @param filp: Contains private data which is used to obtain
+ *              master, channel write ID.
+ * @param data: trace data to be written.
+ * @param len:  # of byte to write.
+ * @return int : # of bytes written, or error.
+ */
+static int pti_tty_driver_write(struct tty_struct *tty,
+	const unsigned char *buf, int len)
+{
+	struct pti_masterchannel *mc;
+	struct pti_tty *pti_tty_data;
+
+	pti_tty_data = tty->driver_data;
+	mc = pti_tty_data->mc;
+	pti_write_to_aperture(mc, (u8 *)buf, len);
+
+	return len;
+}
+
+static int pti_tty_write_room(struct tty_struct *tty)
+{
+	return 2048;
+}
+
+/**
+ * pti_char_open()- Open an Application master, channel aperture
+ * ID to the PTI device. Part of the misc device implementation.
+ *
+ * @param inode: not used.
+ * @param filp: Output- will have a masterchannel struct set containing
+ * the allocated application PTI aperture write address.
+ *
+ * @return int : Success = 0, otherwise fail.  As of right now,
+ *         it is not sure what needs to really be initialized
+ *         for open(), so it always returns 0.
+ */
+static int pti_char_open(struct inode *inode, struct file *filp)
+{
+	struct pti_masterchannel *mc;
+
+	mc = pti_request_masterchannel(0);
+	if (mc == NULL)
+		return -ENOMEM;
+	filp->private_data = mc;
+	return 0;
+}
+
+/**
+ * pti_char_release()-  Close a char channel to the PTI device. Part
+ * of the misc device implementation.
+ *
+ * @param inode: Not used in this implementaiton.
+ * @param filp: Contains private_data that contains the master, channel
+ * ID to be released by the PTI device.
+ *
+ * @return int : Success = 0
+ */
+static int pti_char_release(struct inode *inode, struct file *filp)
+{
+	pti_release_masterchannel(filp->private_data);
+	return 0;
+}
+
+/**
+ * pti_char_write():  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @param filp: Contains private data which is used to obtain
+ *              master, channel write ID.
+ * @param data: trace data to be written.
+ * @param len:  # of byte to write.
+ * @param ppose: Not used in this function implementation.
+ * @return int : # of bytes written, or error.
+ *
+ * Notes: From side discussions with Alan Cox and experimenting
+ * with PTI debug HW like Nokia's Fido box and Lauterbach
+ * devices, 8192 byte write buffer used by USER_COPY_SIZE was
+ * deemed an appropriate size for this type of usage with
+ * debugging HW.
+ */
+static ssize_t pti_char_write(struct file *filp, const char __user *data,
+			      size_t len, loff_t *ppose)
+{
+	struct pti_masterchannel *mc;
+	void *kbuf;
+	const char __user *tmp;
+	size_t size = USER_COPY_SIZE, n = 0;
+
+	tmp = data;
+	mc = filp->private_data;
+
+	kbuf = kmalloc(size, GFP_KERNEL);
+	if (kbuf == NULL)  {
+		pr_err("%s(%d): buf allocation failed\n",
+			__func__, __LINE__);
+		return 0;
+	}
+
+	do {
+		if (len - n > USER_COPY_SIZE)
+			size = USER_COPY_SIZE;
+		else
+			size = len - n;
+
+		if (copy_from_user(kbuf, tmp, size)) {
+			kfree(kbuf);
+			return n ? n : -EFAULT;
+		}
+
+		pti_write_to_aperture(mc, kbuf, size);
+		n  += size;
+		tmp += size;
+
+	} while (len > n);
+
+	kfree(kbuf);
+	kbuf = NULL;
+
+	return len;
+}
+
+static const struct tty_operations pti_tty_driver_ops = {
+	.open		= pti_tty_driver_open,
+	.close		= pti_tty_driver_close,
+	.write		= pti_tty_driver_write,
+	.write_room	= pti_tty_write_room,
+	.install	= pti_tty_install,
+	.cleanup	= pti_tty_cleanup
+};
+
+static const struct file_operations pti_char_driver_ops = {
+	.owner		= THIS_MODULE,
+	.write		= pti_char_write,
+	.open		= pti_char_open,
+	.release	= pti_char_release,
+};
+
+static struct miscdevice pti_char_driver = {
+	.minor		= MISC_DYNAMIC_MINOR,
+	.name		= CHARNAME,
+	.fops		= &pti_char_driver_ops
+};
+
+static void pti_console_write(struct console *c, const char *buf, unsigned len)
+{
+	static struct pti_masterchannel mc = {.master  = CONSOLE_ID,
+					      .channel = 0};
+
+	mc.channel = pti_console_channel;
+	pti_console_channel = (pti_console_channel + 1) & 0x7f;
+
+	pti_write_full_frame_to_aperture(&mc, 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;
+	pti_control_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,
+	.index		= 0,
+};
+
+/**
+ * pti_port_activate(): Used to start/initialize any items upon
+ * first opening of tty_port().
+ *
+ * @param port- The tty port number of the PTI device.
+ * @param tty-  The tty struct associated with this device.
+ *
+ * @return int - Always returns 0.
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static int pti_port_activate(struct tty_port *port, struct tty_struct *tty)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		console_start(&pti_console);
+	return 0;
+}
+
+/**
+ * pti_port_shutdown(): Used to stop/shutdown any items upon the
+ * last tty port close.
+ *
+ * @param port- The tty port number of the PTI device.
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static void pti_port_shutdown(struct tty_port *port)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		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.
+*/
+
+static int __devinit pti_pci_probe(struct pci_dev *pdev,
+		const struct pci_device_id *ent)
+{
+	int retval = -EINVAL;
+	int pci_bar = 1;
+
+	dev_dbg(&pdev->dev, "%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__,
+			__func__, __LINE__, pdev->vendor, pdev->device);
+
+	retval = misc_register(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+		return retval;
+	}
+
+	retval = pci_enable_device(pdev);
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s: pci_enable_device() returned error %d\n",
+			__func__, retval);
+		return retval;
+	}
+
+	drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
+
+	if (drv_data == NULL) {
+		retval = -ENOMEM;
+		dev_err(&pdev->dev,
+			"%s(%d): kmalloc() returned NULL memory.\n",
+			__func__, __LINE__);
+		return retval;
+	}
+	drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
+
+	retval = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev));
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s(%d): pci_request_region() returned error %d\n",
+			__func__, __LINE__, retval);
+		kfree(drv_data);
+		return retval;
+	}
+	drv_data->aperture_base = drv_data->pti_addr+APERTURE_14;
+	drv_data->pti_ioaddr =
+		ioremap_nocache((u32)drv_data->aperture_base,
+		APERTURE_LEN);
+	if (!drv_data->pti_ioaddr) {
+		pci_release_region(pdev, pci_bar);
+		retval = -ENOMEM;
+		kfree(drv_data);
+		return retval;
+	}
+
+	pci_set_drvdata(pdev, drv_data);
+
+	tty_port_init(&drv_data->port);
+	drv_data->port.ops = &tty_port_ops;
+
+	tty_register_device(pti_tty_driver, 0, &pdev->dev);
+	tty_register_device(pti_tty_driver, 1, &pdev->dev);
+
+	register_console(&pti_console);
+
+	return retval;
+}
+
+static struct pci_driver pti_pci_driver = {
+	.name		= PCINAME,
+	.id_table	= pci_ids,
+	.probe		= pti_pci_probe,
+	.remove		= pti_pci_remove,
+};
+
+/**
+ *
+ * pti_init():
+ *
+ * @return int __init: 0 for success, any other value error.
+ *
+ */
+static int __init pti_init(void)
+{
+	int retval = -EINVAL;
+
+	/* First register module as tty device */
+
+	pti_tty_driver = alloc_tty_driver(1);
+	if (pti_tty_driver == NULL) {
+		pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n",
+			__func__, __LINE__);
+		return -ENOMEM;
+	}
+
+	pti_tty_driver->owner			= THIS_MODULE;
+	pti_tty_driver->magic			= TTY_DRIVER_MAGIC;
+	pti_tty_driver->driver_name		= DRIVERNAME;
+	pti_tty_driver->name			= TTYNAME;
+	pti_tty_driver->major			= 0;
+	pti_tty_driver->minor_start		= PTITTY_MINOR_START;
+	pti_tty_driver->minor_num		= PTITTY_MINOR_NUM;
+	pti_tty_driver->num			= PTITTY_MINOR_NUM;
+	pti_tty_driver->type			= TTY_DRIVER_TYPE_SYSTEM;
+	pti_tty_driver->subtype			= SYSTEM_TYPE_SYSCONS;
+	pti_tty_driver->flags			= TTY_DRIVER_REAL_RAW |
+						  TTY_DRIVER_DYNAMIC_DEV;
+	pti_tty_driver->init_termios		= tty_std_termios;
+
+	tty_set_operations(pti_tty_driver, &pti_tty_driver_ops);
+
+	retval = tty_register_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	retval = pci_register_driver(&pti_pci_driver);
+
+	if (retval) {
+		pr_err("%s(%d): PCI registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		tty_unregister_driver(pti_tty_driver);
+		pr_err("%s(%d): Unregistering TTY part of pti driver\n",
+			__func__, __LINE__);
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	return retval;
+}
+
+/**
+ * pti_exit(): Unregisters this module as a tty and pci driver.
+ */
+static void __exit pti_exit(void)
+{
+	int retval;
+
+	tty_unregister_device(pti_tty_driver, 0);
+	tty_unregister_device(pti_tty_driver, 1);
+
+	retval = tty_unregister_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	pci_unregister_driver(&pti_pci_driver);
+
+	retval = misc_deregister(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	unregister_console(&pti_console);
+	return;
+}
+
+module_init(pti_init);
+module_exit(pti_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ken Mills, Jay Freyensee");
+MODULE_DESCRIPTION("PTI Driver");
+
diff --git a/include/linux/pti.h b/include/linux/pti.h
new file mode 100644
index 0000000..94d05bc
--- /dev/null
+++ b/include/linux/pti.h
@@ -0,0 +1,39 @@
+/*
+ *  Copyright (C) Intel 2011
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ *
+ * This header file will allow other parts of the OS to use the
+ * interface to write out it's contents for debugging a mobile system.
+ */
+
+#ifndef PTI_H_
+#define PTI_H_
+
+/* basic structure used as a write address to the PTI HW */
+struct pti_masterchannel {
+	u8 master;
+	u8 channel;
+};
+
+/* the following functions are defined in misc/pti.c */
+void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count);
+struct pti_masterchannel *pti_request_masterchannel(u8 type);
+void pti_release_masterchannel(struct pti_masterchannel *mc);
+
+#endif /*PTI_H_*/
-- 
1.7.2.3


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

* [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (16 preceding siblings ...)
  2011-04-19 22:58 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
@ 2011-04-19 22:58 ` james_p_freyensee
  2011-04-19 23:20   ` Randy Dunlap
  2011-04-22 22:26 ` export kernel call get_task_comm for driver use james_p_freyensee
                   ` (23 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-04-19 22:58 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

The n_tracerouter and n_tracesink line discpline drivers use the
Linux tty line discpline framework to route trace data coming
from a tty port (say UART for example) to the trace sink line
discipline driver and to another tty port(say USB).  Those
these two line discipline drivers can be used together,
independently from pti.c, they are part of the original
implementation solution of the MIPI P1149.7, compact JTAG, PTI
solution for Intel mobile platforms starting with the
Medfield platform.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/Kconfig         |   31 ++++++
 drivers/tty/Makefile        |    2 +
 drivers/tty/n_tracerouter.c |  241 ++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/n_tracesink.c   |  244 +++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/n_tracesink.h   |   36 +++++++
 include/linux/tty.h         |    2 +
 6 files changed, 556 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/n_tracerouter.c
 create mode 100644 drivers/tty/n_tracesink.c
 create mode 100644 drivers/tty/n_tracesink.h

diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 3fd7199..d1ab9c0 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -319,3 +319,34 @@ config N_GSM
 	  This line discipline provides support for the GSM MUX protocol and
 	  presents the mux as a set of 61 individual tty devices.
 
+config TRACE_ROUTER
+	tristate "Trace data router for MIPI P1149.7 cJTAG standard"
+	depends on TRACE_SINK
+	default Y
+	help
+	  The trace router uses the Linux tty line discipline framework to
+	  route trace data coming from a tty port (say UART for example) to
+	  the trace sink line discipline driver and to another tty port(say 
+	  USB). This is part of a solution for the MIPI P1149.7, compact JTAG,
+	  standard, which is for debugging mobile devices. The PTI driver in
+	  drivers/misc/pti.c defines the majority of this MIPI solution.
+
+	  You should select this driver if the target kernel is meant for
+	  a mobile device containing a modem.  Then you will need to select
+	  "Trace data sink for MIPI P1149.7 cJTAG standard" line discipline
+	  driver.
+
+config TRACE_SINK
+	tristate "Trace data sink for MIPI P1149.7 cJTAG standard"
+	default Y
+	help
+	  The trace sink uses the Linux line discipline framework to receive
+	  trace data coming from the trace router line discipline driver
+	  to a user-defined tty port target, like USB.
+	  This is to provide a way to extract modem trace data on
+	  devices that do not have a PTI HW module, or just need modem
+	  trace data to come out of a different HW output port.
+	  This is part of a solution for the P1149.7, compact JTAG, standard.
+
+	  If you select this option, you need to select
+	  "Trace data router for MIPI P1149.7 cJTAG standard".
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index 690522f..ea89b0b 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -6,6 +6,8 @@ obj-$(CONFIG_AUDIT)		+= tty_audit.o
 obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
 obj-$(CONFIG_N_HDLC)		+= n_hdlc.o
 obj-$(CONFIG_N_GSM)		+= n_gsm.o
+obj-$(CONFIG_TRACE_ROUTER)	+= n_tracerouter.o
+obj-$(CONFIG_TRACE_SINK)	+= n_tracesink.o
 obj-$(CONFIG_R3964)		+= n_r3964.o
 
 obj-y				+= vt/
diff --git a/drivers/tty/n_tracerouter.c b/drivers/tty/n_tracerouter.c
new file mode 100644
index 0000000..7295799
--- /dev/null
+++ b/drivers/tty/n_tracerouter.c
@@ -0,0 +1,241 @@
+/*
+ *  n_tracerouter.c - Trace data router through tty space
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This trace router uses the Linux line discipline framework to route
+ * trace data coming from a HW Modem to a PTI (Parallel Trace Module) port.
+ * The solution is not specific to a HW modem and this line disciple can
+ * be used to route any stream of data in kernel space.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <asm-generic/bug.h>
+#include "n_tracesink.h"
+
+/* Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracerouter"
+
+/* struct to hold private configuration data for this ldisc.
+ * opencalled is used to hold if this ldisc has been opened.
+ * kref_tty holds the tty reference the ldisc sits on top of.
+ */
+struct tracerouter_data {
+	u8 opencalled;
+	struct tty_struct *kref_tty;
+};
+static struct tracerouter_data *tr_data;
+
+/* lock for when tty reference is being used */
+static DEFINE_MUTEX(routelock);
+
+/**
+ * n_tracerouter_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success.
+ *
+ * Caveats: This should only be opened one time per SW entity.
+ */
+static int n_tracerouter_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&routelock);
+	if (tr_data->opencalled == 0) {
+
+		tr_data->kref_tty = tty_kref_get(tty);
+		if (tr_data->kref_tty == NULL) {
+			retval = -EFAULT;
+		} else {
+			tr_data->opencalled = 1;
+			tty->disc_data      = tr_data;
+			tty->receive_room   = RECEIVE_ROOM;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&routelock);
+	return retval;
+}
+
+/**
+ * n_tracerouter_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracerouter_close(struct tty_struct *tty)
+{
+	struct tracerouter_data *tptr = tty->disc_data;
+
+	mutex_lock(&routelock);
+	WARN_ON(tptr->kref_tty != tr_data->kref_tty);
+	tty_driver_flush_buffer(tty);
+	tty_kref_put(tr_data->kref_tty);
+	tr_data->kref_tty = NULL;
+	tr_data->opencalled = 0;
+	tty->disc_data = NULL;
+	mutex_unlock(&routelock);
+}
+
+/**
+ * n_tracerouter_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracerouter_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracerouter_read(struct tty_struct *tty, struct file *file,
+				  unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracerouter_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracerouter_write(struct tty_struct *tty, struct file *file,
+				   const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_receivebuf() - Routing function for driver.
+ * @tty: terminal device passed into the ldisc.  It's assumed
+ *       tty will never be NULL.
+ * @cp:  buffer, block of characters to be eventually read by
+ *       someone, somewhere (user read() call or some kernel function).
+ * @fp:  flag buffer.
+ * @count: number of characters (aka, bytes) in cp.
+ *
+ * This function takes the input buffer, cp, and passes it to
+ * an external API function for processing.
+ */
+static void n_tracerouter_receivebuf(struct tty_struct *tty,
+					const unsigned char *cp,
+					char *fp, int count)
+{
+	mutex_lock(&routelock);
+	n_tracesink_datadrain((u8 *) cp, count);
+	mutex_unlock(&routelock);
+}
+
+/* Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+static struct tty_ldisc_ops tty_ptirouter_ldisc = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracerouter_open,
+	.close		= n_tracerouter_close,
+	.read		= n_tracerouter_read,
+	.write		= n_tracerouter_write,
+	.receive_buf	= n_tracerouter_receivebuf
+};
+
+/**
+ * n_tracerouter_init		-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracerouter_init(void)
+{
+	int retval;
+
+	tr_data = kzalloc(sizeof(struct tracerouter_data), GFP_KERNEL);
+	if (tr_data == NULL)
+		return -ENOMEM;
+
+
+	/* Note N_TRACEROUTER is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACEROUTER, &tty_ptirouter_ldisc);
+	if (retval < 0) {
+		pr_err("%s: Registration failed: %d\n", __func__, retval);
+		kfree(tr_data);
+	}
+	return retval;
+}
+
+/**
+ * n_tracerouter_exit -	-	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracerouter_exit(void)
+{
+	int retval;
+
+	kfree(tr_data);
+	retval = tty_unregister_ldisc(N_TRACEROUTER);
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
+}
+
+module_init(n_tracerouter_init);
+module_exit(n_tracerouter_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACEROUTER);
+MODULE_DESCRIPTION("Trace router ldisc driver");
diff --git a/drivers/tty/n_tracesink.c b/drivers/tty/n_tracesink.c
new file mode 100644
index 0000000..4c40127
--- /dev/null
+++ b/drivers/tty/n_tracesink.c
@@ -0,0 +1,244 @@
+/*
+ *  n_tracesink.c - Trace data router and sink path through tty space.
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The trace sink uses the Linux line discipline framework to receive
+ * trace data coming from the PTI source line discipline driver
+ * to a user-desired tty port, like USB.
+ * This is to provide a way to extract modem trace data on
+ * devices that do not have a PTI HW module, or just need modem
+ * trace data to come out of a different HW output port.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <asm-generic/bug.h>
+#include "n_tracesink.h"
+
+/* Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracesink"
+
+/* there is a quirk with this ldisc is he can write data
+ * to a tty from anyone calling his kernel API, which
+ * meets customer requirements in the drivers/misc/pti.c
+ * project.  So he needs to know when he can and cannot write when
+ * the API is called. In theory, the API can be called
+ * after an init() but before a successful open() which
+ * would crash the system if tty is not checked.
+ */
+static struct tty_struct *this_tty;
+static DEFINE_MUTEX(writelock);
+
+/**
+ * n_tracesink_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success,
+ *      -EFAULT = couldn't get a tty kref n_tracesink will sit
+ *       on top of
+ *      -EEXIST = open() called successfully once and it cannot
+ *      be called again.
+ *
+ * Caveats: open() should only be successful the first time a
+ * SW entity calls it.
+ */
+static int n_tracesink_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&writelock);
+	if (this_tty == NULL) {
+
+		this_tty = tty_kref_get(tty);
+
+		if (this_tty == NULL)
+			retval = -EFAULT;
+		else {
+			tty->disc_data = this_tty;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&writelock);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracesink_close(struct tty_struct *tty)
+{
+
+	mutex_lock(&writelock);
+	tty_driver_flush_buffer(tty);
+	tty_kref_put(this_tty);
+	this_tty = NULL;
+	tty->disc_data = NULL;
+	mutex_unlock(&writelock);
+
+}
+
+/**
+ * n_tracesink_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracesink_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracesink_read(struct tty_struct *tty, struct file *file,
+				unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracesink_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracesink_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracesink_write(struct tty_struct *tty, struct file *file,
+				 const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracesink_datadrain() - Kernel API function used to route
+ *			     trace debugging data to user-defined
+ *			     port like USB.
+ *
+ * @buf:   Trace debuging data buffer to write to tty target
+ *         port. Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         return with no write occuring.
+ *
+ * Caveat: If this line discipline does not set the tty it sits
+ * on top of via an open() call, this API function will not
+ * call the tty's write() call because it will have no pointer
+ * to call the write().
+ */
+void n_tracesink_datadrain(u8 *buf, int count)
+{
+	mutex_lock(&writelock);
+
+	if ((buf != NULL) && (count > 0) && (this_tty != NULL))
+		this_tty->ops->write(this_tty, buf, count);
+
+	mutex_unlock(&writelock);
+}
+EXPORT_SYMBOL_GPL(n_tracesink_datadrain);
+
+/* Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+/*
+ * tty_ldisc function operations for this driver.
+ */
+static struct tty_ldisc_ops tty_n_tracesink = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracesink_open,
+	.close		= n_tracesink_close,
+	.read		= n_tracesink_read,
+	.write		= n_tracesink_write
+};
+
+/**
+ * n_tracesink_init-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracesink_init(void)
+{
+	int retval;
+
+	/* Note N_TRACESINK is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
+
+	if (retval < 0)
+		pr_err("%s: Registration failed: %d\n", __func__, retval);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_exit -	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracesink_exit(void)
+{
+	int retval;
+
+	retval = tty_unregister_ldisc(N_TRACESINK);
+
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
+}
+
+module_init(n_tracesink_init);
+module_exit(n_tracesink_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACESINK);
+MODULE_DESCRIPTION("Trace sink ldisc driver");
diff --git a/drivers/tty/n_tracesink.h b/drivers/tty/n_tracesink.h
new file mode 100644
index 0000000..a68bb44
--- /dev/null
+++ b/drivers/tty/n_tracesink.h
@@ -0,0 +1,36 @@
+/*
+ *  n_tracesink.h - Kernel driver API to route trace data in kernel space.
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ *
+ * This header file is used by n_tracerouter to be able to send the
+ * data of it's tty port to the tty port this module sits.  This
+ * mechanism can also be used independent of the PTI module.
+ *
+ */
+
+#ifndef N_TRACESINK_H_
+#define N_TRACESINK_H_
+
+void n_tracesink_datadrain(u8 *buf, int count);
+
+#endif
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 9f469c7..fbf17de 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -50,6 +50,8 @@
 #define N_CAIF		20      /* CAIF protocol for talking to modems */
 #define N_GSM0710	21	/* GSM 0710 Mux */
 #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
+#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
+#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
-- 
1.7.2.3


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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-19 22:58 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
@ 2011-04-19 23:15   ` Randy Dunlap
  2011-04-20 23:05     ` J Freyensee
  2011-04-20  1:25   ` David Rientjes
  1 sibling, 1 reply; 171+ messages in thread
From: Randy Dunlap @ 2011-04-19 23:15 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 19 Apr 2011 15:58:08 -0700 james_p_freyensee@linux.intel.com wrote:


> diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
> new file mode 100644
> index 0000000..f3a2980
> --- /dev/null
> +++ b/drivers/misc/pti.c
> @@ -0,0 +1,898 @@
> +/*
> + *  pti.c - PTI driver for cJTAG data extration
> + *
> + *  Copyright (C) Intel 2010
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + *
> + * The PTI (Parallel Trace Interface) driver directs trace data routed from
> + * various parts in the system out through the Intel Penwell PTI port and
> + * out of the mobile device for analysis with a debugging tool
> + * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
> + * compact JTAG, standard.
> + */
> +
> +#include <linux/init.h>
> +#include <linux/sched.h>
> +#include <linux/interrupt.h>
> +#include <linux/console.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/tty.h>
> +#include <linux/tty_driver.h>
> +#include <linux/pci.h>
> +#include <linux/mutex.h>
> +#include <linux/miscdevice.h>
> +#include <linux/pti.h>
> +
> +#define DRIVERNAME		"pti"
> +#define PCINAME			"pciPTI"
> +#define TTYNAME			"ttyPTI"
> +#define CHARNAME		"pti"
> +#define PTITTY_MINOR_START	0
> +#define PTITTY_MINOR_NUM	2
> +#define MAX_APP_IDS		16   /* 128 channel ids / u8 bit size */
> +#define MAX_OS_IDS		16   /* 128 channel ids / u8 bit size */
> +#define MAX_MODEM_IDS		16   /* 128 channel ids / u8 bit size */
> +#define MODEM_BASE_ID		71   /* modem master ID address    */
> +#define CONTROL_ID		72   /* control master ID address  */
> +#define CONSOLE_ID		73   /* console master ID address  */
> +#define OS_BASE_ID		74   /* base OS master ID address  */
> +#define APP_BASE_ID		80   /* base App master ID address */
> +#define CONTROL_FRAME_LEN	32   /* PTI control frame maximum size */
> +#define USER_COPY_SIZE		8192 /* 8Kb buffer for user space copy */
> +#define APERTURE_14		0x3800000 /* offset to first OS write addr */
> +#define APERTURE_LEN		0x400000  /* address length */
> +
> +struct pti_tty {
> +	struct pti_masterchannel *mc;
> +};
> +
> +struct pti_dev {
> +	struct tty_port port;
> +	unsigned long pti_addr;
> +	unsigned long aperture_base;
> +	void __iomem *pti_ioaddr;
> +	u8 ia_app[MAX_APP_IDS];
> +	u8 ia_os[MAX_OS_IDS];
> +	u8 ia_modem[MAX_MODEM_IDS];
> +};
> +
> +/*
> +   This protects access to ia_app, ia_os, and ia_modem,
> +   which keeps track of channels allocated in
> +   an aperture write id.
> +*/

Use normal multi-line comment format:

/*
 * line1
 * line2
 */

> +static DEFINE_MUTEX(alloclock);
> +
> +static struct pci_device_id pci_ids[] __devinitconst = {
> +		{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B) },
> +		{0}
> +};
> +
> +static struct tty_driver *pti_tty_driver;
> +
> +static struct pti_dev *drv_data;
> +
> +static unsigned int pti_console_channel;
> +static unsigned int pti_control_channel;
> +
> +#define DTS 0x30		/* offset for last dword of a PTI message */
> +
> +/**
> + *  pti_write_to_aperture() - THE private write function to PTI HW.

THE ?

> + *  @mc: The 'aperture'. It's part of a write address that holds
> + *       a master and channel ID.
> + *  @buf: Data being written to the HW that will ultimately be seen
> + *        in a debugging tool (Fido, Lauterbach).
> + *  @len: Size of buffer.
> + *
> + *  Since each aperture is specified by a unique
> + *  master/channel ID, no two processes will be writing
> + *  to the same aperture at the same time so no lock is required. The
> + *  PTI-Output agent will send these out in the order that they arrived, and
> + *  thus, it will intermix these messages. The debug tool can then later
> + *  regroup the appropriate message segments together reconstituting each
> + *  message.
> + */
> +static void pti_write_to_aperture(struct pti_masterchannel *mc,
> +				  u8 *buf,
> +				  int len)
> +{
> +	int dwordcnt, final, i;
> +	u32 ptiword;
> +	u8 *p;
> +	u32 __iomem *aperture;
> +
> +	p = buf;
> +
> +	/*
> +	   calculate the aperture offset from the base using the master and
> +	   channel id's.
> +	*/

comment style (see Documentation/CodingStyle, section 8)


> +	aperture = drv_data->pti_ioaddr + (mc->master << 15)
> +		+ (mc->channel << 8);
> +
> +	dwordcnt = len >> 2;
> +	final = len - (dwordcnt << 2);		/* final = trailing bytes */
> +	if (final == 0 && dwordcnt != 0) {	/* always have a final dword */
> +		final += 4;
> +		dwordcnt--;
> +	}
> +
> +	for (i = 0; i < dwordcnt; i++) {
> +		ptiword = be32_to_cpu(*(u32 *)p);
> +		p += 4;
> +		iowrite32(ptiword, aperture);
> +	}
> +
> +	aperture += DTS;		/* adding DTS signals that is EOM */
> +
> +	ptiword = 0;
> +	for (i = 0; i < final; i++)
> +		ptiword |= *p++ << (24-(8*i));
> +
> +	iowrite32(ptiword, aperture);
> +	return;
> +}
> +
> +/**
> + *  pti_control_frame_built_and_sent() - control frame build and send function.
> + *  @mc: The master / channel structure on which the function built a control
> + *  frame.
> + *
> + *  To be able to post process the PTI contents on host side, a control frame
> + *  is added before sending any PTI content. So the host side knows on
> + *  each PTI frame the name of the thread using a dedicated master / channel.
> + *  This function builds this frame and sends it to a master ID CONTROL_ID.
> + *  The overhead is only 32 bytes since the driver only writes to HW
> + *  in 32 byte chunks.
> + */
> +
> +static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc)
> +{
> +	struct pti_masterchannel mccontrol = {.master = CONTROL_ID,
> +					      .channel = 0};
> +	const char *control_format = "%3d %3d %s";
> +
> +	char comm[sizeof(current->comm) + 1];
> +	u8 control_frame[CONTROL_FRAME_LEN];
> +
> +	if (!in_interrupt())
> +		get_task_comm(comm, current);
> +	else
> +		strcpy(comm, "Interrupt");
> +
> +	/* Ensure our buffer is zero terminated */
> +	comm[sizeof(current->comm)] = 0;
> +
> +	mccontrol.channel = pti_control_channel;
> +	pti_control_channel = (pti_control_channel + 1) & 0x7f;
> +
> +	snprintf(control_frame, CONTROL_FRAME_LEN, control_format, mc->master,
> +		mc->channel, comm);
> +	pti_write_to_aperture(&mccontrol, control_frame, strlen(control_frame));
> +}
> +
> +/**
> + *  pti_write_full_frame_to_aperture() - high level function to write to PTI
> + *  @mc: The 'aperture'. It's part of a write address that holds
> + *       a master and channel ID.
> + *  @buf: Data being written to the HW that will ultimately be seen
> + *        in a debugging tool (Fido, Lauterbach).
> + *  @len: Size of buffer.
> + *
> + *  All threads sending data (either console, user space application, ...)
> + *  are calling the high level function to write to PTI meaning that it is
> + *  possible to add a control frame before sending the content.
> + */
> +static void pti_write_full_frame_to_aperture(struct pti_masterchannel *mc,
> +						const unsigned char *buf,
> +						int len)
> +{
> +	pti_control_frame_built_and_sent(mc);
> +	pti_write_to_aperture(mc, (u8 *)buf, len);
> +}
> +
> +
> +/**
> + * getID(): Allocate a master and channel ID.

 * getID() - Allocate a master and channel ID

> + *
> + * @IDarray:

needs explanatory text

> + * @max_IDS: The max amount of available write IDs to use.
> + * @baseID:  The starting SW channel ID, based on the Intel
> + *           PTI arch.
> + *
> + * @return: pti_masterchannel struct containing master, channel ID address,

No '@' on "return".


> + * or 0 for error.
> + *
> + * Each bit in the arrays ia_app and ia_os correspond to a master and
> + * channel id. The bit is one if the id is taken and 0 if free. For
> + * every master there are 128 channel id's.
> + */
> +static struct pti_masterchannel *getID(u8 *IDarray, int max_IDS, int baseID)
> +{
> +	struct pti_masterchannel *mc;
> +	int i, j, mask;
> +
> +	mc = kmalloc(sizeof(struct pti_masterchannel), GFP_KERNEL);
> +	if (mc == NULL)
> +		return NULL;
> +
> +	/* look for a byte with a free bit */
> +	for (i = 0; i < max_IDS; i++)
> +		if (IDarray[i] != 0xff)
> +			break;
> +	if (i == max_IDS) {
> +		kfree(mc);
> +		return NULL;
> +	}
> +	/* find the bit in the 128 possible channel opportunities */
> +	mask = 0x80;
> +	for (j = 0; j < 8; j++) {
> +		if ((IDarray[i] & mask) == 0)
> +			break;
> +		mask >>= 1;
> +	}
> +
> +	/* grab it */
> +	IDarray[i] |= mask;
> +	mc->master  = baseID;
> +	mc->channel = ((i & 0xf)<<3) + j;
> +	/* write new master Id / channel Id allocation to channel control */
> +	pti_control_frame_built_and_sent(mc);
> +	return mc;
> +}
> +
> +/*
> +	The following three functions:
> +	pti_request_mastercahannel(), mipi_release_masterchannel()
> +	and pti_writedata() are an API for other kernel drivers to
> +	access PTI.
> +*/

multi-line comment style.

> +
> +/**
> + * pti_request_masterchannel() - Kernel API function used to allocate
> + *                                a master, channel ID address to write to
> + *                                PTI HW.
> + * @type: 0- request Application  master, channel aperture ID write address.
> + *        1- request OS master, channel aperture ID write address.
> + *        2- request Modem master, channel aperture ID write
> + *           address.
> + *        Other values, error.
> + * @return: pti_masterchannel struct or 0 for error.

No '@' on "return".

> + *
> + */
> +struct pti_masterchannel *pti_request_masterchannel(u8 type)
> +{
> +	struct pti_masterchannel *mc;
> +
> +	mutex_lock(&alloclock);
> +
> +	switch (type) {
> +
> +	case 0:
> +		mc = getID(drv_data->ia_app, MAX_APP_IDS, APP_BASE_ID);
> +		break;
> +
> +	case 1:
> +		mc = getID(drv_data->ia_os, MAX_OS_IDS, OS_BASE_ID);
> +		break;
> +
> +	case 2:
> +		mc = getID(drv_data->ia_modem, MAX_MODEM_IDS, MODEM_BASE_ID);
> +		break;
> +	default:
> +		mc = NULL;
> +	}
> +
> +	mutex_unlock(&alloclock);
> +	return mc;
> +}
> +EXPORT_SYMBOL_GPL(pti_request_masterchannel);
> +
> +/**
> + * pti_release_masterchannel() - Kernel API function used to release
> + *                                a master, channel ID address
> + *                                used to write to PTI HW.
> + * @mc: master, channel apeture ID address to be released.
> + *
> + */
> +void pti_release_masterchannel(struct pti_masterchannel *mc)
> +{
> +	u8 master, channel, i;
> +
> +	mutex_lock(&alloclock);
> +
> +	if (mc) {
> +		master = mc->master;
> +		channel = mc->channel;
> +
> +		if (master == APP_BASE_ID) {
> +			i = channel >> 3;
> +			drv_data->ia_app[i] &=  ~(0x80>>(channel & 0x7));
> +		} else if (master == OS_BASE_ID) {
> +			i = channel >> 3;
> +			drv_data->ia_os[i] &= ~(0x80>>(channel & 0x7));
> +		} else {
> +			i = channel >> 3;
> +			drv_data->ia_modem[i] &= ~(0x80>>(channel & 0x7));
> +		}
> +
> +		kfree(mc);
> +	}
> +
> +	mutex_unlock(&alloclock);
> +}
> +EXPORT_SYMBOL_GPL(pti_release_masterchannel);
> +
> +/**
> + * pti_writedata() - Kernel API function used to write trace
> + *                   debugging data to PTI HW.
> + *
> + * @mc:    Master, channel aperture ID address to write to.
> + *         Null value will return with no write occurring.
> + * @buf:   Trace debuging data to write to the PTI HW.
> + *         Null value will return with no write occurring.
> + * @count: Size of buf. Value of 0 or a negative number will
> + *         retrn with no write occuring.

	      return with no write occurring.

or maybe the @count/@len parameters should be size_t so that they cannot
be negative.

> + */
> +void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
> +{
> +	/*
> +	   since this function is exported, this is treated like an
> +	   API function, thus, all parameters should
> +	   be checked for validity.
> +	*/

comment style.

> +	if ((mc != NULL) && (buf != NULL) && (count > 0))
> +		pti_write_to_aperture(mc, buf, count);
> +	return;
> +}
> +EXPORT_SYMBOL_GPL(pti_writedata);
> +
> +static void __devexit pti_pci_remove(struct pci_dev *pdev)
> +{
> +	struct pti_dev *drv_data;
> +
> +	drv_data = pci_get_drvdata(pdev);
> +	if (drv_data != NULL) {
> +		pci_iounmap(pdev, drv_data->pti_ioaddr);
> +		pci_set_drvdata(pdev, NULL);
> +		kfree(drv_data);
> +		pci_release_region(pdev, 1);
> +		pci_disable_device(pdev);
> +	}
> +}
> +
> +/*
> +   for the tty_driver_*() basic function descriptions, see tty_driver.h.
> +   Specific header comments made for PTI-related specifics.
> +*/

comment style.

> +
> +/**
> + * pti_tty_driver_open()- Open an Application master, channel aperture
> + * ID to the PTI device via tty device.
> + *
> + * @param tty: tty interface.
> + * @param filp: filp interface pased to tty_port_open() call.

drop "param".  Just use:

 * @tty: <text>
 * @filp: <text>

> + *
> + * @return int : Success = 0, otherwise fail.

No '@' on "return".


> + *
> + * The main purpose of using the tty device interface is for
> + * each tty port to have a unique PTI write aperture.  In an
> + * example use case, ttyPTI0 gets syslogd and an APP aperture
> + * ID and ttyPTI1 is where the n_tracesink ldisc hooks to route
> + * modem messages into PTI.  Modem trace data does not have to
> + * go to ttyPTI1, but ttyPTI0 and ttyPTI1 do need to be distinct
> + * master IDs.  These messages go through the PTI HW and out of
> + * the handheld platform and to the Fido/Lauterbach device.
> + */
> +static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
> +{
> +	int ret = 0;
> +
> +	/*
> +	   we actually want to allocate a new channel per open, per
> +	   system arch.  HW gives more than plenty channels for a single
> +	   system task to have its own channel to write trace data. This
> +	   also removes a locking requirement for the actual write
> +	   procedure.
> +	*/

comment style.

> +	ret = tty_port_open(&drv_data->port, tty, filp);
> +
> +	return ret;
> +}
> +
> +/**
> + * pti_tty_driver_close()- close tty device and release Application
> + * master, channel aperture ID to the PTI device via tty device.
> + *
> + * @param tty: tty interface.
> + * @param filp: filp interface pased to tty_port_close() call.

Incorrect kernel-doc notation.  See Documentation/kernel-doc-nano-HOWTO.txt.

> + *
> + * The main purpose of using the tty device interface is to route
> + * syslog daemon messages to the PTI HW and out of the handheld platform
> + * and to the Fido/Lauterbach device.
> + */
> +static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
> +{
> +	tty_port_close(&drv_data->port, tty, filp);
> +
> +	return;
> +}
> +
> +static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
> +{
> +	int idx = tty->index;
> +	struct pti_tty *pti_tty_data;
> +	struct pti_masterchannel *mc;
> +	int ret = tty_init_termios(tty);
> +
> +	if (ret == 0) {
> +		tty_driver_kref_get(driver);
> +		tty->count++;
> +		driver->ttys[idx] = tty;
> +
> +		pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL);
> +		if (pti_tty_data == NULL)
> +			return -ENOMEM;
> +
> +		tty->driver_data = pti_tty_data;
> +
> +		if (idx == PTITTY_MINOR_START)
> +			mc = pti_request_masterchannel(0);
> +		else
> +			mc = pti_request_masterchannel(2);
> +
> +		if (mc == NULL)
> +			return -ENXIO;
> +
> +		pti_tty_data->mc = mc;
> +	}
> +
> +	return ret;
> +}
> +
> +static void pti_tty_cleanup(struct tty_struct *tty)
> +{
> +	struct pti_tty *pti_tty_data;
> +	struct pti_masterchannel *mc;
> +
> +	pti_tty_data = tty->driver_data;
> +
> +	if (pti_tty_data != NULL) {
> +		mc = pti_tty_data->mc;
> +		pti_release_masterchannel(mc);
> +		pti_tty_data->mc = NULL;
> +	}
> +
> +	if (pti_tty_data != NULL)
> +		kfree(pti_tty_data);
> +
> +	tty->driver_data = NULL;
> +}
> +
> +/**
> + * pti_tty_driver_write():  Write trace debugging data through the char

 * pti_tty_driver_write() - <text>

> + * interface to the PTI HW.  Part of the misc device implementation.
> + *
> + * @param filp: Contains private data which is used to obtain
> + *              master, channel write ID.
> + * @param data: trace data to be written.
> + * @param len:  # of byte to write.
> + * @return int : # of bytes written, or error.

Fix kernel-doc notation.  again.  :(

> + */
> +static int pti_tty_driver_write(struct tty_struct *tty,
> +	const unsigned char *buf, int len)
> +{
> +	struct pti_masterchannel *mc;
> +	struct pti_tty *pti_tty_data;
> +
> +	pti_tty_data = tty->driver_data;
> +	mc = pti_tty_data->mc;
> +	pti_write_to_aperture(mc, (u8 *)buf, len);
> +
> +	return len;
> +}
> +
> +static int pti_tty_write_room(struct tty_struct *tty)
> +{
> +	return 2048;
> +}
> +
> +/**
> + * pti_char_open()- Open an Application master, channel aperture
> + * ID to the PTI device. Part of the misc device implementation.
> + *
> + * @param inode: not used.
> + * @param filp: Output- will have a masterchannel struct set containing
> + * the allocated application PTI aperture write address.
> + *
> + * @return int : Success = 0, otherwise fail.  As of right now,
> + *         it is not sure what needs to really be initialized
> + *         for open(), so it always returns 0.

Fix kernel-doc notation.

> + */
> +static int pti_char_open(struct inode *inode, struct file *filp)
> +{
> +	struct pti_masterchannel *mc;
> +
> +	mc = pti_request_masterchannel(0);
> +	if (mc == NULL)
> +		return -ENOMEM;
> +	filp->private_data = mc;
> +	return 0;
> +}
> +
> +/**
> + * pti_char_release()-  Close a char channel to the PTI device. Part
> + * of the misc device implementation.
> + *
> + * @param inode: Not used in this implementaiton.
> + * @param filp: Contains private_data that contains the master, channel
> + * ID to be released by the PTI device.
> + *
> + * @return int : Success = 0

fix kernel-doc notation.

> + */
> +static int pti_char_release(struct inode *inode, struct file *filp)
> +{
> +	pti_release_masterchannel(filp->private_data);
> +	return 0;
> +}
> +
> +/**
> + * pti_char_write():  Write trace debugging data through the char

use '-' instead of ':'

> + * interface to the PTI HW.  Part of the misc device implementation.
> + *
> + * @param filp: Contains private data which is used to obtain
> + *              master, channel write ID.
> + * @param data: trace data to be written.
> + * @param len:  # of byte to write.
> + * @param ppose: Not used in this function implementation.
> + * @return int : # of bytes written, or error.

Fix kernel-doc notation.

> + *
> + * Notes: From side discussions with Alan Cox and experimenting
> + * with PTI debug HW like Nokia's Fido box and Lauterbach
> + * devices, 8192 byte write buffer used by USER_COPY_SIZE was
> + * deemed an appropriate size for this type of usage with
> + * debugging HW.
> + */
> +static ssize_t pti_char_write(struct file *filp, const char __user *data,
> +			      size_t len, loff_t *ppose)
> +{
> +	struct pti_masterchannel *mc;
> +	void *kbuf;
> +	const char __user *tmp;
> +	size_t size = USER_COPY_SIZE, n = 0;
> +
> +	tmp = data;
> +	mc = filp->private_data;
> +
> +	kbuf = kmalloc(size, GFP_KERNEL);
> +	if (kbuf == NULL)  {
> +		pr_err("%s(%d): buf allocation failed\n",
> +			__func__, __LINE__);
> +		return 0;
> +	}
> +
> +	do {
> +		if (len - n > USER_COPY_SIZE)
> +			size = USER_COPY_SIZE;
> +		else
> +			size = len - n;
> +
> +		if (copy_from_user(kbuf, tmp, size)) {
> +			kfree(kbuf);
> +			return n ? n : -EFAULT;
> +		}
> +
> +		pti_write_to_aperture(mc, kbuf, size);
> +		n  += size;
> +		tmp += size;
> +
> +	} while (len > n);
> +
> +	kfree(kbuf);
> +	kbuf = NULL;
> +
> +	return len;
> +}
> +
> +static const struct tty_operations pti_tty_driver_ops = {
> +	.open		= pti_tty_driver_open,
> +	.close		= pti_tty_driver_close,
> +	.write		= pti_tty_driver_write,
> +	.write_room	= pti_tty_write_room,
> +	.install	= pti_tty_install,
> +	.cleanup	= pti_tty_cleanup
> +};
> +
> +static const struct file_operations pti_char_driver_ops = {
> +	.owner		= THIS_MODULE,
> +	.write		= pti_char_write,
> +	.open		= pti_char_open,
> +	.release	= pti_char_release,
> +};
> +
> +static struct miscdevice pti_char_driver = {
> +	.minor		= MISC_DYNAMIC_MINOR,
> +	.name		= CHARNAME,
> +	.fops		= &pti_char_driver_ops
> +};
> +
> +static void pti_console_write(struct console *c, const char *buf, unsigned len)
> +{
> +	static struct pti_masterchannel mc = {.master  = CONSOLE_ID,
> +					      .channel = 0};
> +
> +	mc.channel = pti_console_channel;
> +	pti_console_channel = (pti_console_channel + 1) & 0x7f;
> +
> +	pti_write_full_frame_to_aperture(&mc, 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;
> +	pti_control_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.
> + */

fix long comment style.

> +static struct console pti_console = {
> +	.name		= TTYNAME,
> +	.write		= pti_console_write,
> +	.device		= pti_console_device,
> +	.setup		= pti_console_setup,
> +	.flags		= CON_PRINTBUFFER,
> +	.index		= 0,
> +};
> +
> +/**
> + * pti_port_activate(): Used to start/initialize any items upon

use '-' instead of ':'

> + * first opening of tty_port().
> + *
> + * @param port- The tty port number of the PTI device.
> + * @param tty-  The tty struct associated with this device.
> + *
> + * @return int - Always returns 0.

fix kernel-doc notation.

> + *
> + * Notes: The primary purpose of the PTI tty port 0 is to hook
> + * the syslog daemon to it; thus this port will be open for a
> + * very long time.
> + */
> +static int pti_port_activate(struct tty_port *port, struct tty_struct *tty)
> +{
> +	if (port->tty->index == PTITTY_MINOR_START)
> +		console_start(&pti_console);
> +	return 0;
> +}
> +
> +/**
> + * pti_port_shutdown(): Used to stop/shutdown any items upon the

use - instead of :

> + * last tty port close.
> + *
> + * @param port- The tty port number of the PTI device.

fix kernel-doc notation.

> + *
> + * Notes: The primary purpose of the PTI tty port 0 is to hook
> + * the syslog daemon to it; thus this port will be open for a
> + * very long time.
> + */
> +static void pti_port_shutdown(struct tty_port *port)
> +{
> +	if (port->tty->index == PTITTY_MINOR_START)
> +		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.
> +*/

fix long comment style.

> +
> +static int __devinit pti_pci_probe(struct pci_dev *pdev,
> +		const struct pci_device_id *ent)
> +{
> +	int retval = -EINVAL;
> +	int pci_bar = 1;
> +
> +	dev_dbg(&pdev->dev, "%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__,
> +			__func__, __LINE__, pdev->vendor, pdev->device);
> +
> +	retval = misc_register(&pti_char_driver);
> +	if (retval) {
> +		pr_err("%s(%d): CHAR registration failed of pti driver\n",
> +			__func__, __LINE__);
> +		pr_err("%s(%d): Error value returned: %d\n",
> +			__func__, __LINE__, retval);
> +		return retval;
> +	}
> +
> +	retval = pci_enable_device(pdev);
> +	if (retval != 0) {
> +		dev_err(&pdev->dev,
> +			"%s: pci_enable_device() returned error %d\n",
> +			__func__, retval);
> +		return retval;
> +	}
> +
> +	drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
> +
> +	if (drv_data == NULL) {
> +		retval = -ENOMEM;
> +		dev_err(&pdev->dev,
> +			"%s(%d): kmalloc() returned NULL memory.\n",
> +			__func__, __LINE__);
> +		return retval;
> +	}
> +	drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
> +
> +	retval = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev));
> +	if (retval != 0) {
> +		dev_err(&pdev->dev,
> +			"%s(%d): pci_request_region() returned error %d\n",
> +			__func__, __LINE__, retval);
> +		kfree(drv_data);
> +		return retval;
> +	}
> +	drv_data->aperture_base = drv_data->pti_addr+APERTURE_14;
> +	drv_data->pti_ioaddr =
> +		ioremap_nocache((u32)drv_data->aperture_base,
> +		APERTURE_LEN);
> +	if (!drv_data->pti_ioaddr) {
> +		pci_release_region(pdev, pci_bar);
> +		retval = -ENOMEM;
> +		kfree(drv_data);
> +		return retval;
> +	}
> +
> +	pci_set_drvdata(pdev, drv_data);
> +
> +	tty_port_init(&drv_data->port);
> +	drv_data->port.ops = &tty_port_ops;
> +
> +	tty_register_device(pti_tty_driver, 0, &pdev->dev);
> +	tty_register_device(pti_tty_driver, 1, &pdev->dev);
> +
> +	register_console(&pti_console);
> +
> +	return retval;
> +}
> +
> +static struct pci_driver pti_pci_driver = {
> +	.name		= PCINAME,
> +	.id_table	= pci_ids,
> +	.probe		= pti_pci_probe,
> +	.remove		= pti_pci_remove,
> +};
> +
> +/**
> + *
> + * pti_init():

Needs short function summary on line above.

> + *
> + * @return int __init: 0 for success, any other value error.

fix kernel-doc notation.

> + *
> + */
> +static int __init pti_init(void)
> +{
> +	int retval = -EINVAL;
> +
> +	/* First register module as tty device */
> +
> +	pti_tty_driver = alloc_tty_driver(1);
> +	if (pti_tty_driver == NULL) {
> +		pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n",
> +			__func__, __LINE__);
> +		return -ENOMEM;
> +	}
> +
> +	pti_tty_driver->owner			= THIS_MODULE;
> +	pti_tty_driver->magic			= TTY_DRIVER_MAGIC;
> +	pti_tty_driver->driver_name		= DRIVERNAME;
> +	pti_tty_driver->name			= TTYNAME;
> +	pti_tty_driver->major			= 0;
> +	pti_tty_driver->minor_start		= PTITTY_MINOR_START;
> +	pti_tty_driver->minor_num		= PTITTY_MINOR_NUM;
> +	pti_tty_driver->num			= PTITTY_MINOR_NUM;
> +	pti_tty_driver->type			= TTY_DRIVER_TYPE_SYSTEM;
> +	pti_tty_driver->subtype			= SYSTEM_TYPE_SYSCONS;
> +	pti_tty_driver->flags			= TTY_DRIVER_REAL_RAW |
> +						  TTY_DRIVER_DYNAMIC_DEV;
> +	pti_tty_driver->init_termios		= tty_std_termios;
> +
> +	tty_set_operations(pti_tty_driver, &pti_tty_driver_ops);
> +
> +	retval = tty_register_driver(pti_tty_driver);
> +	if (retval) {
> +		pr_err("%s(%d): TTY registration failed of pti driver\n",
> +			__func__, __LINE__);
> +		pr_err("%s(%d): Error value returned: %d\n",
> +			__func__, __LINE__, retval);
> +
> +		pti_tty_driver = NULL;
> +		return retval;
> +	}
> +
> +	retval = pci_register_driver(&pti_pci_driver);
> +
> +	if (retval) {
> +		pr_err("%s(%d): PCI registration failed of pti driver\n",
> +			__func__, __LINE__);
> +		pr_err("%s(%d): Error value returned: %d\n",
> +			__func__, __LINE__, retval);
> +
> +		tty_unregister_driver(pti_tty_driver);
> +		pr_err("%s(%d): Unregistering TTY part of pti driver\n",
> +			__func__, __LINE__);
> +		pti_tty_driver = NULL;
> +		return retval;
> +	}
> +
> +	return retval;
> +}
> +
> +/**
> + * pti_exit(): Unregisters this module as a tty and pci driver.

use - instead of :

> + */
> +static void __exit pti_exit(void)
> +{
> +	int retval;
> +
> +	tty_unregister_device(pti_tty_driver, 0);
> +	tty_unregister_device(pti_tty_driver, 1);
> +
> +	retval = tty_unregister_driver(pti_tty_driver);
> +	if (retval) {
> +		pr_err("%s(%d): TTY unregistration failed of pti driver\n",
> +			__func__, __LINE__);
> +		pr_err("%s(%d): Error value returned: %d\n",
> +			__func__, __LINE__, retval);
> +	}
> +
> +	pci_unregister_driver(&pti_pci_driver);
> +
> +	retval = misc_deregister(&pti_char_driver);
> +	if (retval) {
> +		pr_err("%s(%d): CHAR unregistration failed of pti driver\n",
> +			__func__, __LINE__);
> +		pr_err("%s(%d): Error value returned: %d\n",
> +			__func__, __LINE__, retval);
> +	}
> +
> +	unregister_console(&pti_console);
> +	return;
> +}
> +
> +module_init(pti_init);
> +module_exit(pti_exit);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Ken Mills, Jay Freyensee");
> +MODULE_DESCRIPTION("PTI Driver");


---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* Re: [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions.
  2011-04-19 22:58 ` [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions james_p_freyensee
@ 2011-04-19 23:20   ` Randy Dunlap
  2011-04-20  0:05     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Randy Dunlap @ 2011-04-19 23:20 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 19 Apr 2011 15:58:09 -0700 james_p_freyensee@linux.intel.com wrote:

>  drivers/tty/Kconfig         |   31 ++++++
>  drivers/tty/Makefile        |    2 +
>  drivers/tty/n_tracerouter.c |  241 ++++++++++++++++++++++++++++++++++++++++++
>  drivers/tty/n_tracesink.c   |  244 +++++++++++++++++++++++++++++++++++++++++++
>  drivers/tty/n_tracesink.h   |   36 +++++++
>  include/linux/tty.h         |    2 +
>  6 files changed, 556 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/tty/n_tracerouter.c
>  create mode 100644 drivers/tty/n_tracesink.c
>  create mode 100644 drivers/tty/n_tracesink.h
> 
> diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
> index 3fd7199..d1ab9c0 100644
> --- a/drivers/tty/Kconfig
> +++ b/drivers/tty/Kconfig
> @@ -319,3 +319,34 @@ config N_GSM
>  	  This line discipline provides support for the GSM MUX protocol and
>  	  presents the mux as a set of 61 individual tty devices.
>  
> +config TRACE_ROUTER
> +	tristate "Trace data router for MIPI P1149.7 cJTAG standard"
> +	depends on TRACE_SINK
> +	default Y

Don't add default Y misc drivers.

> +	help
> +	  The trace router uses the Linux tty line discipline framework to
> +	  route trace data coming from a tty port (say UART for example) to
> +	  the trace sink line discipline driver and to another tty port(say 
> +	  USB). This is part of a solution for the MIPI P1149.7, compact JTAG,
> +	  standard, which is for debugging mobile devices. The PTI driver in
> +	  drivers/misc/pti.c defines the majority of this MIPI solution.
> +
> +	  You should select this driver if the target kernel is meant for
> +	  a mobile device containing a modem.  Then you will need to select
> +	  "Trace data sink for MIPI P1149.7 cJTAG standard" line discipline
> +	  driver.
> +
> +config TRACE_SINK
> +	tristate "Trace data sink for MIPI P1149.7 cJTAG standard"
> +	default Y

ditto.

> +	help
> +	  The trace sink uses the Linux line discipline framework to receive
> +	  trace data coming from the trace router line discipline driver
> +	  to a user-defined tty port target, like USB.
> +	  This is to provide a way to extract modem trace data on
> +	  devices that do not have a PTI HW module, or just need modem
> +	  trace data to come out of a different HW output port.
> +	  This is part of a solution for the P1149.7, compact JTAG, standard.
> +
> +	  If you select this option, you need to select
> +	  "Trace data router for MIPI P1149.7 cJTAG standard".

> diff --git a/drivers/tty/n_tracerouter.c b/drivers/tty/n_tracerouter.c
> new file mode 100644
> index 0000000..7295799
> --- /dev/null
> +++ b/drivers/tty/n_tracerouter.c
> @@ -0,0 +1,241 @@
> +/*
> + *  n_tracerouter.c - Trace data router through tty space
> + *
> + *  Copyright (C) Intel 2011
> + *
> + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License version 2
> + *  as published by the Free Software Foundation.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + *
> + * This trace router uses the Linux line discipline framework to route
> + * trace data coming from a HW Modem to a PTI (Parallel Trace Module) port.
> + * The solution is not specific to a HW modem and this line disciple can
> + * be used to route any stream of data in kernel space.
> + * This is part of a solution for the P1149.7, compact JTAG, standard.
> + *
> + */
> +
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/types.h>
> +#include <linux/ioctl.h>
> +#include <linux/tty.h>
> +#include <linux/tty_ldisc.h>
> +#include <linux/errno.h>
> +#include <linux/string.h>
> +#include <linux/mutex.h>
> +#include <linux/slab.h>
> +#include <asm-generic/bug.h>
> +#include "n_tracesink.h"
> +
> +/* Other ldisc drivers use 65536 which basically means,
> + * 'I can always accept 64k' and flow control is off.
> + * This number is deemed appropriate for this driver.
> + */

Fix multi-line comment style throughout.

> +#define RECEIVE_ROOM	65536
> +#define DRIVERNAME	"n_tracerouter"
> +
> +/* struct to hold private configuration data for this ldisc.
> + * opencalled is used to hold if this ldisc has been opened.
> + * kref_tty holds the tty reference the ldisc sits on top of.
> + */
> +struct tracerouter_data {
> +	u8 opencalled;
> +	struct tty_struct *kref_tty;
> +};
> +static struct tracerouter_data *tr_data;
> +
> +/* lock for when tty reference is being used */
> +static DEFINE_MUTEX(routelock);


> +/* Flush buffer is not impelemented as the ldisc has no internal buffering
> + * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
> + */
> +
> +static struct tty_ldisc_ops tty_ptirouter_ldisc = {
> +	.owner		= THIS_MODULE,
> +	.magic		= TTY_LDISC_MAGIC,
> +	.name		= DRIVERNAME,
> +	.open		= n_tracerouter_open,
> +	.close		= n_tracerouter_close,
> +	.read		= n_tracerouter_read,
> +	.write		= n_tracerouter_write,
> +	.receive_buf	= n_tracerouter_receivebuf
> +};

> diff --git a/drivers/tty/n_tracesink.c b/drivers/tty/n_tracesink.c
> new file mode 100644
> index 0000000..4c40127
> --- /dev/null
> +++ b/drivers/tty/n_tracesink.c
> @@ -0,0 +1,244 @@
> +/*
> + *  n_tracesink.c - Trace data router and sink path through tty space.
> + *
> + *  Copyright (C) Intel 2011
> + *
> + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License version 2
> + *  as published by the Free Software Foundation.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + *
> + * The trace sink uses the Linux line discipline framework to receive
> + * trace data coming from the PTI source line discipline driver
> + * to a user-desired tty port, like USB.
> + * This is to provide a way to extract modem trace data on
> + * devices that do not have a PTI HW module, or just need modem
> + * trace data to come out of a different HW output port.
> + * This is part of a solution for the P1149.7, compact JTAG, standard.
> + *
> + */
> +
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/types.h>
> +#include <linux/ioctl.h>
> +#include <linux/tty.h>
> +#include <linux/tty_ldisc.h>
> +#include <linux/errno.h>
> +#include <linux/string.h>
> +#include <asm-generic/bug.h>
> +#include "n_tracesink.h"
> +
> +/* Other ldisc drivers use 65536 which basically means,
> + * 'I can always accept 64k' and flow control is off.
> + * This number is deemed appropriate for this driver.
> + */

Fix multi-line comment style throughout.

> +#define RECEIVE_ROOM	65536
> +#define DRIVERNAME	"n_tracesink"
> +
> +/* there is a quirk with this ldisc is he can write data
> + * to a tty from anyone calling his kernel API, which
> + * meets customer requirements in the drivers/misc/pti.c
> + * project.  So he needs to know when he can and cannot write when
> + * the API is called. In theory, the API can be called
> + * after an init() but before a successful open() which
> + * would crash the system if tty is not checked.
> + */
> +static struct tty_struct *this_tty;
> +static DEFINE_MUTEX(writelock);

> +/* Flush buffer is not impelemented as the ldisc has no internal buffering
> + * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
> + */
> +
> +/*
> + * tty_ldisc function operations for this driver.
> + */
> +static struct tty_ldisc_ops tty_n_tracesink = {
> +	.owner		= THIS_MODULE,
> +	.magic		= TTY_LDISC_MAGIC,
> +	.name		= DRIVERNAME,
> +	.open		= n_tracesink_open,
> +	.close		= n_tracesink_close,
> +	.read		= n_tracesink_read,
> +	.write		= n_tracesink_write
> +};


---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-19 22:58 ` [PATCH 1/4] export kernel call get_task_comm() james_p_freyensee
@ 2011-04-19 23:22   ` David Rientjes
  2011-04-20  0:10     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: David Rientjes @ 2011-04-19 23:22 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 19 Apr 2011, james_p_freyensee@linux.intel.com wrote:

> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This allows drivers who call this function to be compiled modularly.
> Otherwise, a driver who is interested in this type of functionality
> has to implement their own get_task_comm() call, causing code
> duplication in the Linux source tree.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>

Acked-by: David Rientjes <rientjes@google.com>

There've been some other patchsets proposed recently that need to print a 
thread's comm and since /proc/pid/comm can change the comm's of other 
threads out from under them, it's necessary to serialize access to it with 
task_lock().  This patch certainly makes it easier for modules to do so 
correctly, thanks!

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

* Re: [PATCH 2/4] Kernel documentation for the PTI feature.
  2011-04-19 22:58 ` [PATCH 2/4] Kernel documentation for the PTI feature james_p_freyensee
@ 2011-04-19 23:26   ` Randy Dunlap
  0 siblings, 0 replies; 171+ messages in thread
From: Randy Dunlap @ 2011-04-19 23:26 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 19 Apr 2011 15:58:07 -0700 james_p_freyensee@linux.intel.com wrote:

> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This provides Kernel documentation for the PTI
> feature and setting line discipline drivers
> on top of tty's for Linux mobile solutions.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> ---
>  Documentation/pti/pti_intel_mid.txt |   99 +++++++++++++++++++++++++++++++++++
>  1 files changed, 99 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/pti/pti_intel_mid.txt
> 
> diff --git a/Documentation/pti/pti_intel_mid.txt b/Documentation/pti/pti_intel_mid.txt
> new file mode 100644
> index 0000000..900f6db
> --- /dev/null
> +++ b/Documentation/pti/pti_intel_mid.txt
> @@ -0,0 +1,99 @@
> +The Intel MID PTI project is HW implemented in Intel Atom
> +system-on-a-chip designs based on the Parallel Trace
> +Interface for MIPI P1149.7 cJTAG standard.  The kernel solution
> +for this platform involves the following files:
> +
> +./include/linux/pti.h
> +./drivers/.../n_tracesink.h
> +./drivers/.../n_tracerouter.c
> +./drivers/.../n_tracesink.c
> +./drivers/.../pti.c
> +
> +pti.c is the driver that enables various debugging features
> +popular on certain mobile manufacturers.

   popular on devices | platforms | chips | whatever from certain mobile
   manufacturers.


---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* Re: [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions.
  2011-04-19 23:20   ` Randy Dunlap
@ 2011-04-20  0:05     ` J Freyensee
  2011-04-20  0:14       ` Randy Dunlap
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-04-20  0:05 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 2011-04-19 at 16:20 -0700, Randy Dunlap wrote:
> On Tue, 19 Apr 2011 15:58:09 -0700 james_p_freyensee@linux.intel.com wrote:
> 
> >  drivers/tty/Kconfig         |   31 ++++++
> >  drivers/tty/Makefile        |    2 +
> >  drivers/tty/n_tracerouter.c |  241 ++++++++++++++++++++++++++++++++++++++++++
> >  drivers/tty/n_tracesink.c   |  244 +++++++++++++++++++++++++++++++++++++++++++
> >  drivers/tty/n_tracesink.h   |   36 +++++++
> >  include/linux/tty.h         |    2 +
> >  6 files changed, 556 insertions(+), 0 deletions(-)
> >  create mode 100644 drivers/tty/n_tracerouter.c
> >  create mode 100644 drivers/tty/n_tracesink.c
> >  create mode 100644 drivers/tty/n_tracesink.h
> > 
> > diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
> > index 3fd7199..d1ab9c0 100644
> > --- a/drivers/tty/Kconfig
> > +++ b/drivers/tty/Kconfig
> > @@ -319,3 +319,34 @@ config N_GSM
> >  	  This line discipline provides support for the GSM MUX protocol and
> >  	  presents the mux as a set of 61 individual tty devices.
> >  
> > +config TRACE_ROUTER
> > +	tristate "Trace data router for MIPI P1149.7 cJTAG standard"
> > +	depends on TRACE_SINK
> > +	default Y
> 
> Don't add default Y misc drivers.

This actually isn't a misc driver.  From the help, it's "Linux tty line
discipline"

But I can turn it off.

> 
> > +	help
> > +	  The trace router uses the Linux tty line discipline framework to
> > +	  route trace data coming from a tty port (say UART for example) to
> > +	  the trace sink line discipline driver and to another tty port(say 
> > +	  USB). This is part of a solution for the MIPI P1149.7, compact JTAG,
> > +	  standard, which is for debugging mobile devices. The PTI driver in
> > +	  drivers/misc/pti.c defines the majority of this MIPI solution.
> > +
> > +	  You should select this driver if the target kernel is meant for
> > +	  a mobile device containing a modem.  Then you will need to select
> > +	  "Trace data sink for MIPI P1149.7 cJTAG standard" line discipline
> > +	  driver.
> > +
> > +config TRACE_SINK
> > +	tristate "Trace data sink for MIPI P1149.7 cJTAG standard"
> > +	default Y
> 
> ditto.
> 
> > +	help
> > +	  The trace sink uses the Linux line discipline framework to receive
> > +	  trace data coming from the trace router line discipline driver
> > +	  to a user-defined tty port target, like USB.
> > +	  This is to provide a way to extract modem trace data on
> > +	  devices that do not have a PTI HW module, or just need modem
> > +	  trace data to come out of a different HW output port.
> > +	  This is part of a solution for the P1149.7, compact JTAG, standard.
> > +
> > +	  If you select this option, you need to select
> > +	  "Trace data router for MIPI P1149.7 cJTAG standard".
> 
> > diff --git a/drivers/tty/n_tracerouter.c b/drivers/tty/n_tracerouter.c
> > new file mode 100644
> > index 0000000..7295799
> > --- /dev/null
> > +++ b/drivers/tty/n_tracerouter.c
> > @@ -0,0 +1,241 @@
> > +/*
> > + *  n_tracerouter.c - Trace data router through tty space
> > + *
> > + *  Copyright (C) Intel 2011
> > + *
> > + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > + *
> > + *  This program is free software; you can redistribute it and/or modify
> > + *  it under the terms of the GNU General Public License version 2
> > + *  as published by the Free Software Foundation.
> > + *
> > + *  This program is distributed in the hope that it will be useful,
> > + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + *  GNU General Public License for more details.
> > + *
> > + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > + *
> > + * This trace router uses the Linux line discipline framework to route
> > + * trace data coming from a HW Modem to a PTI (Parallel Trace Module) port.
> > + * The solution is not specific to a HW modem and this line disciple can
> > + * be used to route any stream of data in kernel space.
> > + * This is part of a solution for the P1149.7, compact JTAG, standard.
> > + *
> > + */
> > +
> > +#include <linux/init.h>
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
> > +#include <linux/types.h>
> > +#include <linux/ioctl.h>
> > +#include <linux/tty.h>
> > +#include <linux/tty_ldisc.h>
> > +#include <linux/errno.h>
> > +#include <linux/string.h>
> > +#include <linux/mutex.h>
> > +#include <linux/slab.h>
> > +#include <asm-generic/bug.h>
> > +#include "n_tracesink.h"
> > +
> > +/* Other ldisc drivers use 65536 which basically means,
> > + * 'I can always accept 64k' and flow control is off.
> > + * This number is deemed appropriate for this driver.
> > + */
> 
> Fix multi-line comment style throughout.

Could you please show me how and what you are looking for?  You pointed
out a similar issue using a different comment style, despite that at
least I made it a point to maintain a consistent comment style
throughout the code in the file.  So I'm not quite sure what is desired.
Thanks, I appreciate this.


> 
> > +#define RECEIVE_ROOM	65536
> > +#define DRIVERNAME	"n_tracerouter"
> > +
> > +/* struct to hold private configuration data for this ldisc.
> > + * opencalled is used to hold if this ldisc has been opened.
> > + * kref_tty holds the tty reference the ldisc sits on top of.
> > + */
> > +struct tracerouter_data {
> > +	u8 opencalled;
> > +	struct tty_struct *kref_tty;
> > +};
> > +static struct tracerouter_data *tr_data;
> > +
> > +/* lock for when tty reference is being used */
> > +static DEFINE_MUTEX(routelock);
> 
> 
> > +/* Flush buffer is not impelemented as the ldisc has no internal buffering
> > + * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
> > + */
> > +
> > +static struct tty_ldisc_ops tty_ptirouter_ldisc = {
> > +	.owner		= THIS_MODULE,
> > +	.magic		= TTY_LDISC_MAGIC,
> > +	.name		= DRIVERNAME,
> > +	.open		= n_tracerouter_open,
> > +	.close		= n_tracerouter_close,
> > +	.read		= n_tracerouter_read,
> > +	.write		= n_tracerouter_write,
> > +	.receive_buf	= n_tracerouter_receivebuf
> > +};
> 
> > diff --git a/drivers/tty/n_tracesink.c b/drivers/tty/n_tracesink.c
> > new file mode 100644
> > index 0000000..4c40127
> > --- /dev/null
> > +++ b/drivers/tty/n_tracesink.c
> > @@ -0,0 +1,244 @@
> > +/*
> > + *  n_tracesink.c - Trace data router and sink path through tty space.
> > + *
> > + *  Copyright (C) Intel 2011
> > + *
> > + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > + *
> > + *  This program is free software; you can redistribute it and/or modify
> > + *  it under the terms of the GNU General Public License version 2
> > + *  as published by the Free Software Foundation.
> > + *
> > + *  This program is distributed in the hope that it will be useful,
> > + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + *  GNU General Public License for more details.
> > + *
> > + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > + *
> > + * The trace sink uses the Linux line discipline framework to receive
> > + * trace data coming from the PTI source line discipline driver
> > + * to a user-desired tty port, like USB.
> > + * This is to provide a way to extract modem trace data on
> > + * devices that do not have a PTI HW module, or just need modem
> > + * trace data to come out of a different HW output port.
> > + * This is part of a solution for the P1149.7, compact JTAG, standard.
> > + *
> > + */
> > +
> > +#include <linux/init.h>
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
> > +#include <linux/types.h>
> > +#include <linux/ioctl.h>
> > +#include <linux/tty.h>
> > +#include <linux/tty_ldisc.h>
> > +#include <linux/errno.h>
> > +#include <linux/string.h>
> > +#include <asm-generic/bug.h>
> > +#include "n_tracesink.h"
> > +
> > +/* Other ldisc drivers use 65536 which basically means,
> > + * 'I can always accept 64k' and flow control is off.
> > + * This number is deemed appropriate for this driver.
> > + */
> 
> Fix multi-line comment style throughout.
> 
> > +#define RECEIVE_ROOM	65536
> > +#define DRIVERNAME	"n_tracesink"
> > +
> > +/* there is a quirk with this ldisc is he can write data
> > + * to a tty from anyone calling his kernel API, which
> > + * meets customer requirements in the drivers/misc/pti.c
> > + * project.  So he needs to know when he can and cannot write when
> > + * the API is called. In theory, the API can be called
> > + * after an init() but before a successful open() which
> > + * would crash the system if tty is not checked.
> > + */
> > +static struct tty_struct *this_tty;
> > +static DEFINE_MUTEX(writelock);
> 
> > +/* Flush buffer is not impelemented as the ldisc has no internal buffering
> > + * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
> > + */
> > +
> > +/*
> > + * tty_ldisc function operations for this driver.
> > + */
> > +static struct tty_ldisc_ops tty_n_tracesink = {
> > +	.owner		= THIS_MODULE,
> > +	.magic		= TTY_LDISC_MAGIC,
> > +	.name		= DRIVERNAME,
> > +	.open		= n_tracesink_open,
> > +	.close		= n_tracesink_close,
> > +	.read		= n_tracesink_read,
> > +	.write		= n_tracesink_write
> > +};
> 
> 
> ---
> ~Randy
> *** Remember to use Documentation/SubmitChecklist when testing your code ***



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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-19 23:22   ` David Rientjes
@ 2011-04-20  0:10     ` J Freyensee
  2011-04-20  1:22       ` David Rientjes
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-04-20  0:10 UTC (permalink / raw)
  To: David Rientjes; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 2011-04-19 at 16:22 -0700, David Rientjes wrote:
> On Tue, 19 Apr 2011, james_p_freyensee@linux.intel.com wrote:
> 
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > This allows drivers who call this function to be compiled modularly.
> > Otherwise, a driver who is interested in this type of functionality
> > has to implement their own get_task_comm() call, causing code
> > duplication in the Linux source tree.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> Acked-by: David Rientjes <rientjes@google.com>
> 
> There've been some other patchsets proposed recently that need to print a 
> thread's comm and since /proc/pid/comm can change the comm's of other 
> threads out from under them, it's necessary to serialize access to it with 
> task_lock().  This patch certainly makes it easier for modules to do so 
> correctly, thanks!

Thanks for the compliment; it's appreciated.  I've made my patch sets
independent from one another.  And I believe a common consensus (at
least with Greg KH, Alan C., Arjan VdV and myself) was achieved that
this is a good patch to apply? So maybe this can be applied to the
kernel, independent of my other patches, so this will fit your needs?



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

* Re: [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions.
  2011-04-20  0:05     ` J Freyensee
@ 2011-04-20  0:14       ` Randy Dunlap
  0 siblings, 0 replies; 171+ messages in thread
From: Randy Dunlap @ 2011-04-20  0:14 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 19 Apr 2011 17:05:55 -0700 J Freyensee wrote:

> On Tue, 2011-04-19 at 16:20 -0700, Randy Dunlap wrote:
> > On Tue, 19 Apr 2011 15:58:09 -0700 james_p_freyensee@linux.intel.com wrote:
> > 
> > >  drivers/tty/Kconfig         |   31 ++++++
> > >  drivers/tty/Makefile        |    2 +
> > >  drivers/tty/n_tracerouter.c |  241 ++++++++++++++++++++++++++++++++++++++++++
> > >  drivers/tty/n_tracesink.c   |  244 +++++++++++++++++++++++++++++++++++++++++++
> > >  drivers/tty/n_tracesink.h   |   36 +++++++
> > >  include/linux/tty.h         |    2 +
> > >  6 files changed, 556 insertions(+), 0 deletions(-)
> > >  create mode 100644 drivers/tty/n_tracerouter.c
> > >  create mode 100644 drivers/tty/n_tracesink.c
> > >  create mode 100644 drivers/tty/n_tracesink.h
> > > 
> > > diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
> > > index 3fd7199..d1ab9c0 100644
> > > --- a/drivers/tty/Kconfig
> > > +++ b/drivers/tty/Kconfig
> > > @@ -319,3 +319,34 @@ config N_GSM
> > >  	  This line discipline provides support for the GSM MUX protocol and
> > >  	  presents the mux as a set of 61 individual tty devices.
> > >  
> > > +config TRACE_ROUTER
> > > +	tristate "Trace data router for MIPI P1149.7 cJTAG standard"
> > > +	depends on TRACE_SINK
> > > +	default Y
> > 
> > Don't add default Y misc drivers.
> 
> This actually isn't a misc driver.  From the help, it's "Linux tty line
> discipline"
> 
> But I can turn it off.

OK, random drivers.  Thanks.


> > > +/* Other ldisc drivers use 65536 which basically means,
> > > + * 'I can always accept 64k' and flow control is off.
> > > + * This number is deemed appropriate for this driver.
> > > + */
> > 
> > Fix multi-line comment style throughout.
> 
> Could you please show me how and what you are looking for?  You pointed
> out a similar issue using a different comment style, despite that at
> least I made it a point to maintain a consistent comment style
> throughout the code in the file.  So I'm not quite sure what is desired.
> Thanks, I appreciate this.

See Documentation/CodingStyle, section 8:

The preferred style for long (multi-line) comments is:

	/*
	 * This is the preferred style for multi-line
	 * comments in the Linux kernel source code.
	 * Please use it consistently.
	 *
	 * Description:  A column of asterisks on the left side,
	 * with beginning and ending almost-blank lines.
	 */

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-20  0:10     ` J Freyensee
@ 2011-04-20  1:22       ` David Rientjes
  2011-04-20  1:43         ` Greg KH
  0 siblings, 1 reply; 171+ messages in thread
From: David Rientjes @ 2011-04-20  1:22 UTC (permalink / raw)
  To: Andrew Morton, J Freyensee
  Cc: Greg Kroah-Hartman, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 19 Apr 2011, J Freyensee wrote:

> > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > 
> > > This allows drivers who call this function to be compiled modularly.
> > > Otherwise, a driver who is interested in this type of functionality
> > > has to implement their own get_task_comm() call, causing code
> > > duplication in the Linux source tree.
> > > 
> > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > Acked-by: David Rientjes <rientjes@google.com>
> > 
> > There've been some other patchsets proposed recently that need to print a 
> > thread's comm and since /proc/pid/comm can change the comm's of other 
> > threads out from under them, it's necessary to serialize access to it with 
> > task_lock().  This patch certainly makes it easier for modules to do so 
> > correctly, thanks!
> 
> Thanks for the compliment; it's appreciated.  I've made my patch sets
> independent from one another.  And I believe a common consensus (at
> least with Greg KH, Alan C., Arjan VdV and myself) was achieved that
> this is a good patch to apply? So maybe this can be applied to the
> kernel, independent of my other patches, so this will fit your needs?
> 

This patch in particular can probably go through the -mm tree; the last 
activity for get_task_comm() was three years ago (59714d65dfbc 
"get_task_comm(): return the result") which also went through the -mm tree 
and its export is a general service to module authors.  Let's cc Andrew 
and see if he'll merge it.

The only other dependency on this is in your third patch in the series 
which actually has potential stack overflow that I'll comment on there, so 
there's nothing else that has a dependency on this patch being merged 
immediately.

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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-19 22:58 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
  2011-04-19 23:15   ` Randy Dunlap
@ 2011-04-20  1:25   ` David Rientjes
  2011-04-20  9:46     ` Alan Cox
  2011-04-22 17:57     ` J Freyensee
  1 sibling, 2 replies; 171+ messages in thread
From: David Rientjes @ 2011-04-20  1:25 UTC (permalink / raw)
  To: james_p_freyensee
  Cc: Greg Kroah-Hartman, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 19 Apr 2011, james_p_freyensee@linux.intel.com wrote:

> +static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc)
> +{
> +	struct pti_masterchannel mccontrol = {.master = CONTROL_ID,
> +					      .channel = 0};
> +	const char *control_format = "%3d %3d %s";
> +
> +	char comm[sizeof(current->comm) + 1];
> +	u8 control_frame[CONTROL_FRAME_LEN];
> +
> +	if (!in_interrupt())
> +		get_task_comm(comm, current);
> +	else
> +		strcpy(comm, "Interrupt");
> +
> +	/* Ensure our buffer is zero terminated */
> +	comm[sizeof(current->comm)] = 0;
> +

You definitely need to use get_task_comm() here, but that means you can't 
allocate char comm[] on the stack with anything but TASK_COMM_LEN, which 
is small enough that it shouldn't be an issue.  Otherwise there's nothing 
protecting sizeof(current->comm) from changing without holding 
task_lock(current).

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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-20  1:22       ` David Rientjes
@ 2011-04-20  1:43         ` Greg KH
  2011-04-20 18:11           ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-04-20  1:43 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, J Freyensee, linux-kernel, suhail.ahmed,
	christophe.guerard

On Tue, Apr 19, 2011 at 06:22:14PM -0700, David Rientjes wrote:
> On Tue, 19 Apr 2011, J Freyensee wrote:
> 
> > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > 
> > > > This allows drivers who call this function to be compiled modularly.
> > > > Otherwise, a driver who is interested in this type of functionality
> > > > has to implement their own get_task_comm() call, causing code
> > > > duplication in the Linux source tree.
> > > > 
> > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > 
> > > Acked-by: David Rientjes <rientjes@google.com>
> > > 
> > > There've been some other patchsets proposed recently that need to print a 
> > > thread's comm and since /proc/pid/comm can change the comm's of other 
> > > threads out from under them, it's necessary to serialize access to it with 
> > > task_lock().  This patch certainly makes it easier for modules to do so 
> > > correctly, thanks!
> > 
> > Thanks for the compliment; it's appreciated.  I've made my patch sets
> > independent from one another.  And I believe a common consensus (at
> > least with Greg KH, Alan C., Arjan VdV and myself) was achieved that
> > this is a good patch to apply? So maybe this can be applied to the
> > kernel, independent of my other patches, so this will fit your needs?
> > 
> 
> This patch in particular can probably go through the -mm tree; the last 
> activity for get_task_comm() was three years ago (59714d65dfbc 
> "get_task_comm(): return the result") which also went through the -mm tree 
> and its export is a general service to module authors.  Let's cc Andrew 
> and see if he'll merge it.

No, let's wait for the other patches to get acceptable before we merge
it.  We don't need to add exports when there are no users of it in the
tree. It's not for .39 at this point anyway, so no rush at the moment.

thanks,

greg k-h

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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-20  1:25   ` David Rientjes
@ 2011-04-20  9:46     ` Alan Cox
  2011-04-20 18:07       ` J Freyensee
  2011-04-22 17:57     ` J Freyensee
  1 sibling, 1 reply; 171+ messages in thread
From: Alan Cox @ 2011-04-20  9:46 UTC (permalink / raw)
  To: David Rientjes
  Cc: james_p_freyensee, Greg Kroah-Hartman, linux-kernel,
	suhail.ahmed, christophe.guerard

> is small enough that it shouldn't be an issue.  Otherwise there's nothing 
> protecting sizeof(current->comm) from changing without holding 
> task_lock(current).

The C language definition for one - sizeof() is a constant at compile time

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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-20  9:46     ` Alan Cox
@ 2011-04-20 18:07       ` J Freyensee
  0 siblings, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-04-20 18:07 UTC (permalink / raw)
  To: Alan Cox
  Cc: David Rientjes, Greg Kroah-Hartman, linux-kernel, suhail.ahmed,
	christophe.guerard

On Wed, 2011-04-20 at 10:46 +0100, Alan Cox wrote:
> > is small enough that it shouldn't be an issue.  Otherwise there's nothing 
> > protecting sizeof(current->comm) from changing without holding 
> > task_lock(current).
> 
> The C language definition for one - sizeof() is a constant at compile time

K, thanks, I'll look at re-working these couple lines of code.



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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-20  1:43         ` Greg KH
@ 2011-04-20 18:11           ` J Freyensee
  2011-04-20 19:14             ` Greg KH
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-04-20 18:11 UTC (permalink / raw)
  To: Greg KH
  Cc: David Rientjes, Andrew Morton, linux-kernel, suhail.ahmed,
	christophe.guerard

On Tue, 2011-04-19 at 18:43 -0700, Greg KH wrote:
> On Tue, Apr 19, 2011 at 06:22:14PM -0700, David Rientjes wrote:
> > On Tue, 19 Apr 2011, J Freyensee wrote:
> > 
> > > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > 
> > > > > This allows drivers who call this function to be compiled modularly.
> > > > > Otherwise, a driver who is interested in this type of functionality
> > > > > has to implement their own get_task_comm() call, causing code
> > > > > duplication in the Linux source tree.
> > > > > 
> > > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > 
> > > > Acked-by: David Rientjes <rientjes@google.com>
> > > > 
> > > > There've been some other patchsets proposed recently that need to print a 
> > > > thread's comm and since /proc/pid/comm can change the comm's of other 
> > > > threads out from under them, it's necessary to serialize access to it with 
> > > > task_lock().  This patch certainly makes it easier for modules to do so 
> > > > correctly, thanks!
> > > 
> > > Thanks for the compliment; it's appreciated.  I've made my patch sets
> > > independent from one another.  And I believe a common consensus (at
> > > least with Greg KH, Alan C., Arjan VdV and myself) was achieved that
> > > this is a good patch to apply? So maybe this can be applied to the
> > > kernel, independent of my other patches, so this will fit your needs?
> > > 
> > 
> > This patch in particular can probably go through the -mm tree; the last 
> > activity for get_task_comm() was three years ago (59714d65dfbc 
> > "get_task_comm(): return the result") which also went through the -mm tree 
> > and its export is a general service to module authors.  Let's cc Andrew 
> > and see if he'll merge it.
> 
> No, let's wait for the other patches to get acceptable before we merge
> it.  We don't need to add exports when there are no users of it in the
> tree. It's not for .39 at this point anyway, so no rush at the moment.
> 

But as David pointed out, if there is work other than mine coming that
has already been proposed, wouldn't it be good to get this patch in
place now to start the encouragement of future eyes to just call this
function than re-invent the wheel?

> thanks,
> 
> greg k-h



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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-20 18:11           ` J Freyensee
@ 2011-04-20 19:14             ` Greg KH
  2011-04-20 23:11               ` Andrew Morton
  0 siblings, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-04-20 19:14 UTC (permalink / raw)
  To: J Freyensee
  Cc: David Rientjes, Andrew Morton, linux-kernel, suhail.ahmed,
	christophe.guerard

On Wed, Apr 20, 2011 at 11:11:23AM -0700, J Freyensee wrote:
> On Tue, 2011-04-19 at 18:43 -0700, Greg KH wrote:
> > On Tue, Apr 19, 2011 at 06:22:14PM -0700, David Rientjes wrote:
> > > On Tue, 19 Apr 2011, J Freyensee wrote:
> > > 
> > > > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > > 
> > > > > > This allows drivers who call this function to be compiled modularly.
> > > > > > Otherwise, a driver who is interested in this type of functionality
> > > > > > has to implement their own get_task_comm() call, causing code
> > > > > > duplication in the Linux source tree.
> > > > > > 
> > > > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > 
> > > > > Acked-by: David Rientjes <rientjes@google.com>
> > > > > 
> > > > > There've been some other patchsets proposed recently that need to print a 
> > > > > thread's comm and since /proc/pid/comm can change the comm's of other 
> > > > > threads out from under them, it's necessary to serialize access to it with 
> > > > > task_lock().  This patch certainly makes it easier for modules to do so 
> > > > > correctly, thanks!
> > > > 
> > > > Thanks for the compliment; it's appreciated.  I've made my patch sets
> > > > independent from one another.  And I believe a common consensus (at
> > > > least with Greg KH, Alan C., Arjan VdV and myself) was achieved that
> > > > this is a good patch to apply? So maybe this can be applied to the
> > > > kernel, independent of my other patches, so this will fit your needs?
> > > > 
> > > 
> > > This patch in particular can probably go through the -mm tree; the last 
> > > activity for get_task_comm() was three years ago (59714d65dfbc 
> > > "get_task_comm(): return the result") which also went through the -mm tree 
> > > and its export is a general service to module authors.  Let's cc Andrew 
> > > and see if he'll merge it.
> > 
> > No, let's wait for the other patches to get acceptable before we merge
> > it.  We don't need to add exports when there are no users of it in the
> > tree. It's not for .39 at this point anyway, so no rush at the moment.
> > 
> 
> But as David pointed out, if there is work other than mine coming that
> has already been proposed, wouldn't it be good to get this patch in
> place now to start the encouragement of future eyes to just call this
> function than re-invent the wheel?

No, then those projects submit the patch to export this, if they happen
to get to mainline before this one does.

Again, don't export something unless you are using it at the time, no
"this is to be used hopefully by something in the future" type stuff
please.  Who knows if those future plans ever pan out.

thanks,

greg k-h

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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-19 23:15   ` Randy Dunlap
@ 2011-04-20 23:05     ` J Freyensee
  2011-04-20 23:10       ` Randy Dunlap
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-04-20 23:05 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 2011-04-19 at 16:15 -0700, Randy Dunlap wrote:

A couple more comments below.

> On Tue, 19 Apr 2011 15:58:08 -0700 james_p_freyensee@linux.intel.com wrote:
> 
> 
> > diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
> > new file mode 100644
> > index 0000000..f3a2980
> > --- /dev/null
> > +++ b/drivers/misc/pti.c
> > @@ -0,0 +1,898 @@
> > +/*
> > + *  pti.c - PTI driver for cJTAG data extration
> > + *
> > + *  Copyright (C) Intel 2010
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > + *
> > + * The PTI (Parallel Trace Interface) driver directs trace data routed from
> > + * various parts in the system out through the Intel Penwell PTI port and
> > + * out of the mobile device for analysis with a debugging tool
> > + * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
> > + * compact JTAG, standard.
> > + */
> > +
> > +#include <linux/init.h>
> > +#include <linux/sched.h>
> > +#include <linux/interrupt.h>
> > +#include <linux/console.h>
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
> > +#include <linux/tty.h>
> > +#include <linux/tty_driver.h>
> > +#include <linux/pci.h>
> > +#include <linux/mutex.h>
> > +#include <linux/miscdevice.h>
> > +#include <linux/pti.h>
> > +
> > +#define DRIVERNAME		"pti"
> > +#define PCINAME			"pciPTI"
> > +#define TTYNAME			"ttyPTI"
> > +#define CHARNAME		"pti"
> > +#define PTITTY_MINOR_START	0
> > +#define PTITTY_MINOR_NUM	2
> > +#define MAX_APP_IDS		16   /* 128 channel ids / u8 bit size */
> > +#define MAX_OS_IDS		16   /* 128 channel ids / u8 bit size */
> > +#define MAX_MODEM_IDS		16   /* 128 channel ids / u8 bit size */
> > +#define MODEM_BASE_ID		71   /* modem master ID address    */
> > +#define CONTROL_ID		72   /* control master ID address  */
> > +#define CONSOLE_ID		73   /* console master ID address  */
> > +#define OS_BASE_ID		74   /* base OS master ID address  */
> > +#define APP_BASE_ID		80   /* base App master ID address */
> > +#define CONTROL_FRAME_LEN	32   /* PTI control frame maximum size */
> > +#define USER_COPY_SIZE		8192 /* 8Kb buffer for user space copy */
> > +#define APERTURE_14		0x3800000 /* offset to first OS write addr */
> > +#define APERTURE_LEN		0x400000  /* address length */
> > +
> > +struct pti_tty {
> > +	struct pti_masterchannel *mc;
> > +};
> > +
> > +struct pti_dev {
> > +	struct tty_port port;
> > +	unsigned long pti_addr;
> > +	unsigned long aperture_base;
> > +	void __iomem *pti_ioaddr;
> > +	u8 ia_app[MAX_APP_IDS];
> > +	u8 ia_os[MAX_OS_IDS];
> > +	u8 ia_modem[MAX_MODEM_IDS];
> > +};
> > +
> > +/*
> > +   This protects access to ia_app, ia_os, and ia_modem,
> > +   which keeps track of channels allocated in
> > +   an aperture write id.
> > +*/
> 
> Use normal multi-line comment format:
> 
> /*
>  * line1
>  * line2
>  */
> 
> > +static DEFINE_MUTEX(alloclock);
> > +
> > +static struct pci_device_id pci_ids[] __devinitconst = {
> > +		{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B) },
> > +		{0}
> > +};
> > +
> > +static struct tty_driver *pti_tty_driver;
> > +
> > +static struct pti_dev *drv_data;
> > +
> > +static unsigned int pti_console_channel;
> > +static unsigned int pti_control_channel;
> > +
> > +#define DTS 0x30		/* offset for last dword of a PTI message */
> > +
> > +/**
> > + *  pti_write_to_aperture() - THE private write function to PTI HW.
> 
> THE ?
> 
> > + *  @mc: The 'aperture'. It's part of a write address that holds
> > + *       a master and channel ID.
> > + *  @buf: Data being written to the HW that will ultimately be seen
> > + *        in a debugging tool (Fido, Lauterbach).
> > + *  @len: Size of buffer.
> > + *
> > + *  Since each aperture is specified by a unique
> > + *  master/channel ID, no two processes will be writing
> > + *  to the same aperture at the same time so no lock is required. The
> > + *  PTI-Output agent will send these out in the order that they arrived, and
> > + *  thus, it will intermix these messages. The debug tool can then later
> > + *  regroup the appropriate message segments together reconstituting each
> > + *  message.
> > + */
> > +static void pti_write_to_aperture(struct pti_masterchannel *mc,
> > +				  u8 *buf,
> > +				  int len)
> > +{
> > +	int dwordcnt, final, i;
> > +	u32 ptiword;
> > +	u8 *p;
> > +	u32 __iomem *aperture;
> > +
> > +	p = buf;
> > +
> > +	/*
> > +	   calculate the aperture offset from the base using the master and
> > +	   channel id's.
> > +	*/
> 
> comment style (see Documentation/CodingStyle, section 8)
> 
> 
> > +	aperture = drv_data->pti_ioaddr + (mc->master << 15)
> > +		+ (mc->channel << 8);
> > +
> > +	dwordcnt = len >> 2;
> > +	final = len - (dwordcnt << 2);		/* final = trailing bytes */
> > +	if (final == 0 && dwordcnt != 0) {	/* always have a final dword */
> > +		final += 4;
> > +		dwordcnt--;
> > +	}
> > +
> > +	for (i = 0; i < dwordcnt; i++) {
> > +		ptiword = be32_to_cpu(*(u32 *)p);
> > +		p += 4;
> > +		iowrite32(ptiword, aperture);
> > +	}
> > +
> > +	aperture += DTS;		/* adding DTS signals that is EOM */
> > +
> > +	ptiword = 0;
> > +	for (i = 0; i < final; i++)
> > +		ptiword |= *p++ << (24-(8*i));
> > +
> > +	iowrite32(ptiword, aperture);
> > +	return;
> > +}
> > +
> > +/**
> > + *  pti_control_frame_built_and_sent() - control frame build and send function.
> > + *  @mc: The master / channel structure on which the function built a control
> > + *  frame.
> > + *
> > + *  To be able to post process the PTI contents on host side, a control frame
> > + *  is added before sending any PTI content. So the host side knows on
> > + *  each PTI frame the name of the thread using a dedicated master / channel.
> > + *  This function builds this frame and sends it to a master ID CONTROL_ID.
> > + *  The overhead is only 32 bytes since the driver only writes to HW
> > + *  in 32 byte chunks.
> > + */
> > +
> > +static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc)
> > +{
> > +	struct pti_masterchannel mccontrol = {.master = CONTROL_ID,
> > +					      .channel = 0};
> > +	const char *control_format = "%3d %3d %s";
> > +
> > +	char comm[sizeof(current->comm) + 1];
> > +	u8 control_frame[CONTROL_FRAME_LEN];
> > +
> > +	if (!in_interrupt())
> > +		get_task_comm(comm, current);
> > +	else
> > +		strcpy(comm, "Interrupt");
> > +
> > +	/* Ensure our buffer is zero terminated */
> > +	comm[sizeof(current->comm)] = 0;
> > +
> > +	mccontrol.channel = pti_control_channel;
> > +	pti_control_channel = (pti_control_channel + 1) & 0x7f;
> > +
> > +	snprintf(control_frame, CONTROL_FRAME_LEN, control_format, mc->master,
> > +		mc->channel, comm);
> > +	pti_write_to_aperture(&mccontrol, control_frame, strlen(control_frame));
> > +}
> > +
> > +/**
> > + *  pti_write_full_frame_to_aperture() - high level function to write to PTI
> > + *  @mc: The 'aperture'. It's part of a write address that holds
> > + *       a master and channel ID.
> > + *  @buf: Data being written to the HW that will ultimately be seen
> > + *        in a debugging tool (Fido, Lauterbach).
> > + *  @len: Size of buffer.
> > + *
> > + *  All threads sending data (either console, user space application, ...)
> > + *  are calling the high level function to write to PTI meaning that it is
> > + *  possible to add a control frame before sending the content.
> > + */
> > +static void pti_write_full_frame_to_aperture(struct pti_masterchannel *mc,
> > +						const unsigned char *buf,
> > +						int len)
> > +{
> > +	pti_control_frame_built_and_sent(mc);
> > +	pti_write_to_aperture(mc, (u8 *)buf, len);
> > +}
> > +
> > +
> > +/**
> > + * getID(): Allocate a master and channel ID.
> 
>  * getID() - Allocate a master and channel ID
> 
> > + *
> > + * @IDarray:
> 
> needs explanatory text
> 
> > + * @max_IDS: The max amount of available write IDs to use.
> > + * @baseID:  The starting SW channel ID, based on the Intel
> > + *           PTI arch.
> > + *
> > + * @return: pti_masterchannel struct containing master, channel ID address,
> 
> No '@' on "return".

Why no '@' on 'return' when just by doing a 'grep -Ri "@return" drivers/
| wc -l' I count 369 examples of '@return' being used already in the
kernel?  It looks like an acceptable format to me.

> 
> 
> > + * or 0 for error.
> > + *
> > + * Each bit in the arrays ia_app and ia_os correspond to a master and
> > + * channel id. The bit is one if the id is taken and 0 if free. For
> > + * every master there are 128 channel id's.
> > + */
> > +static struct pti_masterchannel *getID(u8 *IDarray, int max_IDS, int baseID)
> > +{
> > +	struct pti_masterchannel *mc;
> > +	int i, j, mask;
> > +
> > +	mc = kmalloc(sizeof(struct pti_masterchannel), GFP_KERNEL);
> > +	if (mc == NULL)
> > +		return NULL;
> > +
> > +	/* look for a byte with a free bit */
> > +	for (i = 0; i < max_IDS; i++)
> > +		if (IDarray[i] != 0xff)
> > +			break;
> > +	if (i == max_IDS) {
> > +		kfree(mc);
> > +		return NULL;
> > +	}
> > +	/* find the bit in the 128 possible channel opportunities */
> > +	mask = 0x80;
> > +	for (j = 0; j < 8; j++) {
> > +		if ((IDarray[i] & mask) == 0)
> > +			break;
> > +		mask >>= 1;
> > +	}
> > +
> > +	/* grab it */
> > +	IDarray[i] |= mask;
> > +	mc->master  = baseID;
> > +	mc->channel = ((i & 0xf)<<3) + j;
> > +	/* write new master Id / channel Id allocation to channel control */
> > +	pti_control_frame_built_and_sent(mc);
> > +	return mc;
> > +}
> > +
> > +/*
> > +	The following three functions:
> > +	pti_request_mastercahannel(), mipi_release_masterchannel()
> > +	and pti_writedata() are an API for other kernel drivers to
> > +	access PTI.
> > +*/
> 
> multi-line comment style.
> 
> > +
> > +/**
> > + * pti_request_masterchannel() - Kernel API function used to allocate
> > + *                                a master, channel ID address to write to
> > + *                                PTI HW.
> > + * @type: 0- request Application  master, channel aperture ID write address.
> > + *        1- request OS master, channel aperture ID write address.
> > + *        2- request Modem master, channel aperture ID write
> > + *           address.
> > + *        Other values, error.
> > + * @return: pti_masterchannel struct or 0 for error.
> 
> No '@' on "return".

Same reason here.

> 
> > + *
> > + */
> > +struct pti_masterchannel *pti_request_masterchannel(u8 type)
> > +{
> > +	struct pti_masterchannel *mc;
> > +
> > +	mutex_lock(&alloclock);
> > +
> > +	switch (type) {
> > +
> > +	case 0:
> > +		mc = getID(drv_data->ia_app, MAX_APP_IDS, APP_BASE_ID);
> > +		break;
> > +
> > +	case 1:
> > +		mc = getID(drv_data->ia_os, MAX_OS_IDS, OS_BASE_ID);
> > +		break;
> > +
> > +	case 2:
> > +		mc = getID(drv_data->ia_modem, MAX_MODEM_IDS, MODEM_BASE_ID);
> > +		break;
> > +	default:
> > +		mc = NULL;
> > +	}
> > +
> > +	mutex_unlock(&alloclock);
> > +	return mc;
> > +}
> > +EXPORT_SYMBOL_GPL(pti_request_masterchannel);
> > +
> > +/**
> > + * pti_release_masterchannel() - Kernel API function used to release
> > + *                                a master, channel ID address
> > + *                                used to write to PTI HW.
> > + * @mc: master, channel apeture ID address to be released.
> > + *
> > + */
> > +void pti_release_masterchannel(struct pti_masterchannel *mc)
> > +{
> > +	u8 master, channel, i;
> > +
> > +	mutex_lock(&alloclock);
> > +
> > +	if (mc) {
> > +		master = mc->master;
> > +		channel = mc->channel;
> > +
> > +		if (master == APP_BASE_ID) {
> > +			i = channel >> 3;
> > +			drv_data->ia_app[i] &=  ~(0x80>>(channel & 0x7));
> > +		} else if (master == OS_BASE_ID) {
> > +			i = channel >> 3;
> > +			drv_data->ia_os[i] &= ~(0x80>>(channel & 0x7));
> > +		} else {
> > +			i = channel >> 3;
> > +			drv_data->ia_modem[i] &= ~(0x80>>(channel & 0x7));
> > +		}
> > +
> > +		kfree(mc);
> > +	}
> > +
> > +	mutex_unlock(&alloclock);
> > +}
> > +EXPORT_SYMBOL_GPL(pti_release_masterchannel);
> > +
> > +/**
> > + * pti_writedata() - Kernel API function used to write trace
> > + *                   debugging data to PTI HW.
> > + *
> > + * @mc:    Master, channel aperture ID address to write to.
> > + *         Null value will return with no write occurring.
> > + * @buf:   Trace debuging data to write to the PTI HW.
> > + *         Null value will return with no write occurring.
> > + * @count: Size of buf. Value of 0 or a negative number will
> > + *         retrn with no write occuring.
> 
> 	      return with no write occurring.
> 
> or maybe the @count/@len parameters should be size_t so that they cannot
> be negative.

I'll think about this one, because I thought the check was appropriate
and I'd rather force the user to understand how to use this call
correctly rather than automatically correct for something they may or
may not have intended.

> 
> > + */
> > +void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
> > +{
> > +	/*
> > +	   since this function is exported, this is treated like an
> > +	   API function, thus, all parameters should
> > +	   be checked for validity.
> > +	*/
> 
> comment style.
> 
> > +	if ((mc != NULL) && (buf != NULL) && (count > 0))
> > +		pti_write_to_aperture(mc, buf, count);
> > +	return;
> > +}
> > +EXPORT_SYMBOL_GPL(pti_writedata);
> > +
> > +static void __devexit pti_pci_remove(struct pci_dev *pdev)
> > +{
> > +	struct pti_dev *drv_data;
> > +
> > +	drv_data = pci_get_drvdata(pdev);
> > +	if (drv_data != NULL) {
> > +		pci_iounmap(pdev, drv_data->pti_ioaddr);
> > +		pci_set_drvdata(pdev, NULL);
> > +		kfree(drv_data);
> > +		pci_release_region(pdev, 1);
> > +		pci_disable_device(pdev);
> > +	}
> > +}
> > +
> > +/*
> > +   for the tty_driver_*() basic function descriptions, see tty_driver.h.
> > +   Specific header comments made for PTI-related specifics.
> > +*/
> 
> comment style.
> 
> > +
> > +/**
> > + * pti_tty_driver_open()- Open an Application master, channel aperture
> > + * ID to the PTI device via tty device.
> > + *
> > + * @param tty: tty interface.
> > + * @param filp: filp interface pased to tty_port_open() call.
> 
> drop "param".  Just use:
> 
>  * @tty: <text>
>  * @filp: <text>

Okay.

> 
> > + *
> > + * @return int : Success = 0, otherwise fail.
> 
> No '@' on "return".

Same explanation as above.

> 
> 
> > + *
> > + * The main purpose of using the tty device interface is for
> > + * each tty port to have a unique PTI write aperture.  In an
> > + * example use case, ttyPTI0 gets syslogd and an APP aperture
> > + * ID and ttyPTI1 is where the n_tracesink ldisc hooks to route
> > + * modem messages into PTI.  Modem trace data does not have to
> > + * go to ttyPTI1, but ttyPTI0 and ttyPTI1 do need to be distinct
> > + * master IDs.  These messages go through the PTI HW and out of
> > + * the handheld platform and to the Fido/Lauterbach device.
> > + */
> > +static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
> > +{
> > +	int ret = 0;
> > +
> > +	/*
> > +	   we actually want to allocate a new channel per open, per
> > +	   system arch.  HW gives more than plenty channels for a single
> > +	   system task to have its own channel to write trace data. This
> > +	   also removes a locking requirement for the actual write
> > +	   procedure.
> > +	*/
> 
> comment style.
> 
> > +	ret = tty_port_open(&drv_data->port, tty, filp);
> > +
> > +	return ret;
> > +}
> > +
> > +/**
> > + * pti_tty_driver_close()- close tty device and release Application
> > + * master, channel aperture ID to the PTI device via tty device.
> > + *
> > + * @param tty: tty interface.
> > + * @param filp: filp interface pased to tty_port_close() call.
> 
> Incorrect kernel-doc notation.  See Documentation/kernel-doc-nano-HOWTO.txt.
> 
> > + *
> > + * The main purpose of using the tty device interface is to route
> > + * syslog daemon messages to the PTI HW and out of the handheld platform
> > + * and to the Fido/Lauterbach device.
> > + */
> > +static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
> > +{
> > +	tty_port_close(&drv_data->port, tty, filp);
> > +
> > +	return;
> > +}
> > +
> > +static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
> > +{
> > +	int idx = tty->index;
> > +	struct pti_tty *pti_tty_data;
> > +	struct pti_masterchannel *mc;
> > +	int ret = tty_init_termios(tty);
> > +
> > +	if (ret == 0) {
> > +		tty_driver_kref_get(driver);
> > +		tty->count++;
> > +		driver->ttys[idx] = tty;
> > +
> > +		pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL);
> > +		if (pti_tty_data == NULL)
> > +			return -ENOMEM;
> > +
> > +		tty->driver_data = pti_tty_data;
> > +
> > +		if (idx == PTITTY_MINOR_START)
> > +			mc = pti_request_masterchannel(0);
> > +		else
> > +			mc = pti_request_masterchannel(2);
> > +
> > +		if (mc == NULL)
> > +			return -ENXIO;
> > +
> > +		pti_tty_data->mc = mc;
> > +	}
> > +
> > +	return ret;
> > +}
> > +
> > +static void pti_tty_cleanup(struct tty_struct *tty)
> > +{
> > +	struct pti_tty *pti_tty_data;
> > +	struct pti_masterchannel *mc;
> > +
> > +	pti_tty_data = tty->driver_data;
> > +
> > +	if (pti_tty_data != NULL) {
> > +		mc = pti_tty_data->mc;
> > +		pti_release_masterchannel(mc);
> > +		pti_tty_data->mc = NULL;
> > +	}
> > +
> > +	if (pti_tty_data != NULL)
> > +		kfree(pti_tty_data);
> > +
> > +	tty->driver_data = NULL;
> > +}
> > +
> > +/**
> > + * pti_tty_driver_write():  Write trace debugging data through the char
> 
>  * pti_tty_driver_write() - <text>
> 
> > + * interface to the PTI HW.  Part of the misc device implementation.
> > + *
> > + * @param filp: Contains private data which is used to obtain
> > + *              master, channel write ID.
> > + * @param data: trace data to be written.
> > + * @param len:  # of byte to write.
> > + * @return int : # of bytes written, or error.
> 
> Fix kernel-doc notation.  again.  :(
> 
> > + */
> > +static int pti_tty_driver_write(struct tty_struct *tty,
> > +	const unsigned char *buf, int len)
> > +{
> > +	struct pti_masterchannel *mc;
> > +	struct pti_tty *pti_tty_data;
> > +
> > +	pti_tty_data = tty->driver_data;
> > +	mc = pti_tty_data->mc;
> > +	pti_write_to_aperture(mc, (u8 *)buf, len);
> > +
> > +	return len;
> > +}
> > +
> > +static int pti_tty_write_room(struct tty_struct *tty)
> > +{
> > +	return 2048;
> > +}
> > +
> > +/**
> > + * pti_char_open()- Open an Application master, channel aperture
> > + * ID to the PTI device. Part of the misc device implementation.
> > + *
> > + * @param inode: not used.
> > + * @param filp: Output- will have a masterchannel struct set containing
> > + * the allocated application PTI aperture write address.
> > + *
> > + * @return int : Success = 0, otherwise fail.  As of right now,
> > + *         it is not sure what needs to really be initialized
> > + *         for open(), so it always returns 0.
> 
> Fix kernel-doc notation.
> 
> > + */
> > +static int pti_char_open(struct inode *inode, struct file *filp)
> > +{
> > +	struct pti_masterchannel *mc;
> > +
> > +	mc = pti_request_masterchannel(0);
> > +	if (mc == NULL)
> > +		return -ENOMEM;
> > +	filp->private_data = mc;
> > +	return 0;
> > +}
> > +
> > +/**
> > + * pti_char_release()-  Close a char channel to the PTI device. Part
> > + * of the misc device implementation.
> > + *
> > + * @param inode: Not used in this implementaiton.
> > + * @param filp: Contains private_data that contains the master, channel
> > + * ID to be released by the PTI device.
> > + *
> > + * @return int : Success = 0
> 
> fix kernel-doc notation.
> 
> > + */
> > +static int pti_char_release(struct inode *inode, struct file *filp)
> > +{
> > +	pti_release_masterchannel(filp->private_data);
> > +	return 0;
> > +}
> > +
> > +/**
> > + * pti_char_write():  Write trace debugging data through the char
> 
> use '-' instead of ':'
> 
> > + * interface to the PTI HW.  Part of the misc device implementation.
> > + *
> > + * @param filp: Contains private data which is used to obtain
> > + *              master, channel write ID.
> > + * @param data: trace data to be written.
> > + * @param len:  # of byte to write.
> > + * @param ppose: Not used in this function implementation.
> > + * @return int : # of bytes written, or error.
> 
> Fix kernel-doc notation.
> 
> > + *
> > + * Notes: From side discussions with Alan Cox and experimenting
> > + * with PTI debug HW like Nokia's Fido box and Lauterbach
> > + * devices, 8192 byte write buffer used by USER_COPY_SIZE was
> > + * deemed an appropriate size for this type of usage with
> > + * debugging HW.
> > + */
> > +static ssize_t pti_char_write(struct file *filp, const char __user *data,
> > +			      size_t len, loff_t *ppose)
> > +{
> > +	struct pti_masterchannel *mc;
> > +	void *kbuf;
> > +	const char __user *tmp;
> > +	size_t size = USER_COPY_SIZE, n = 0;
> > +
> > +	tmp = data;
> > +	mc = filp->private_data;
> > +
> > +	kbuf = kmalloc(size, GFP_KERNEL);
> > +	if (kbuf == NULL)  {
> > +		pr_err("%s(%d): buf allocation failed\n",
> > +			__func__, __LINE__);
> > +		return 0;
> > +	}
> > +
> > +	do {
> > +		if (len - n > USER_COPY_SIZE)
> > +			size = USER_COPY_SIZE;
> > +		else
> > +			size = len - n;
> > +
> > +		if (copy_from_user(kbuf, tmp, size)) {
> > +			kfree(kbuf);
> > +			return n ? n : -EFAULT;
> > +		}
> > +
> > +		pti_write_to_aperture(mc, kbuf, size);
> > +		n  += size;
> > +		tmp += size;
> > +
> > +	} while (len > n);
> > +
> > +	kfree(kbuf);
> > +	kbuf = NULL;
> > +
> > +	return len;
> > +}
> > +
> > +static const struct tty_operations pti_tty_driver_ops = {
> > +	.open		= pti_tty_driver_open,
> > +	.close		= pti_tty_driver_close,
> > +	.write		= pti_tty_driver_write,
> > +	.write_room	= pti_tty_write_room,
> > +	.install	= pti_tty_install,
> > +	.cleanup	= pti_tty_cleanup
> > +};
> > +
> > +static const struct file_operations pti_char_driver_ops = {
> > +	.owner		= THIS_MODULE,
> > +	.write		= pti_char_write,
> > +	.open		= pti_char_open,
> > +	.release	= pti_char_release,
> > +};
> > +
> > +static struct miscdevice pti_char_driver = {
> > +	.minor		= MISC_DYNAMIC_MINOR,
> > +	.name		= CHARNAME,
> > +	.fops		= &pti_char_driver_ops
> > +};
> > +
> > +static void pti_console_write(struct console *c, const char *buf, unsigned len)
> > +{
> > +	static struct pti_masterchannel mc = {.master  = CONSOLE_ID,
> > +					      .channel = 0};
> > +
> > +	mc.channel = pti_console_channel;
> > +	pti_console_channel = (pti_console_channel + 1) & 0x7f;
> > +
> > +	pti_write_full_frame_to_aperture(&mc, 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;
> > +	pti_control_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.
> > + */
> 
> fix long comment style.
> 
> > +static struct console pti_console = {
> > +	.name		= TTYNAME,
> > +	.write		= pti_console_write,
> > +	.device		= pti_console_device,
> > +	.setup		= pti_console_setup,
> > +	.flags		= CON_PRINTBUFFER,
> > +	.index		= 0,
> > +};
> > +
> > +/**
> > + * pti_port_activate(): Used to start/initialize any items upon
> 
> use '-' instead of ':'
> 
> > + * first opening of tty_port().
> > + *
> > + * @param port- The tty port number of the PTI device.
> > + * @param tty-  The tty struct associated with this device.
> > + *
> > + * @return int - Always returns 0.
> 
> fix kernel-doc notation.
> 
> > + *
> > + * Notes: The primary purpose of the PTI tty port 0 is to hook
> > + * the syslog daemon to it; thus this port will be open for a
> > + * very long time.
> > + */
> > +static int pti_port_activate(struct tty_port *port, struct tty_struct *tty)
> > +{
> > +	if (port->tty->index == PTITTY_MINOR_START)
> > +		console_start(&pti_console);
> > +	return 0;
> > +}
> > +
> > +/**
> > + * pti_port_shutdown(): Used to stop/shutdown any items upon the
> 
> use - instead of :
> 
> > + * last tty port close.
> > + *
> > + * @param port- The tty port number of the PTI device.
> 
> fix kernel-doc notation.
> 
> > + *
> > + * Notes: The primary purpose of the PTI tty port 0 is to hook
> > + * the syslog daemon to it; thus this port will be open for a
> > + * very long time.
> > + */
> > +static void pti_port_shutdown(struct tty_port *port)
> > +{
> > +	if (port->tty->index == PTITTY_MINOR_START)
> > +		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.
> > +*/
> 
> fix long comment style.
> 
> > +
> > +static int __devinit pti_pci_probe(struct pci_dev *pdev,
> > +		const struct pci_device_id *ent)
> > +{
> > +	int retval = -EINVAL;
> > +	int pci_bar = 1;
> > +
> > +	dev_dbg(&pdev->dev, "%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__,
> > +			__func__, __LINE__, pdev->vendor, pdev->device);
> > +
> > +	retval = misc_register(&pti_char_driver);
> > +	if (retval) {
> > +		pr_err("%s(%d): CHAR registration failed of pti driver\n",
> > +			__func__, __LINE__);
> > +		pr_err("%s(%d): Error value returned: %d\n",
> > +			__func__, __LINE__, retval);
> > +		return retval;
> > +	}
> > +
> > +	retval = pci_enable_device(pdev);
> > +	if (retval != 0) {
> > +		dev_err(&pdev->dev,
> > +			"%s: pci_enable_device() returned error %d\n",
> > +			__func__, retval);
> > +		return retval;
> > +	}
> > +
> > +	drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
> > +
> > +	if (drv_data == NULL) {
> > +		retval = -ENOMEM;
> > +		dev_err(&pdev->dev,
> > +			"%s(%d): kmalloc() returned NULL memory.\n",
> > +			__func__, __LINE__);
> > +		return retval;
> > +	}
> > +	drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
> > +
> > +	retval = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev));
> > +	if (retval != 0) {
> > +		dev_err(&pdev->dev,
> > +			"%s(%d): pci_request_region() returned error %d\n",
> > +			__func__, __LINE__, retval);
> > +		kfree(drv_data);
> > +		return retval;
> > +	}
> > +	drv_data->aperture_base = drv_data->pti_addr+APERTURE_14;
> > +	drv_data->pti_ioaddr =
> > +		ioremap_nocache((u32)drv_data->aperture_base,
> > +		APERTURE_LEN);
> > +	if (!drv_data->pti_ioaddr) {
> > +		pci_release_region(pdev, pci_bar);
> > +		retval = -ENOMEM;
> > +		kfree(drv_data);
> > +		return retval;
> > +	}
> > +
> > +	pci_set_drvdata(pdev, drv_data);
> > +
> > +	tty_port_init(&drv_data->port);
> > +	drv_data->port.ops = &tty_port_ops;
> > +
> > +	tty_register_device(pti_tty_driver, 0, &pdev->dev);
> > +	tty_register_device(pti_tty_driver, 1, &pdev->dev);
> > +
> > +	register_console(&pti_console);
> > +
> > +	return retval;
> > +}
> > +
> > +static struct pci_driver pti_pci_driver = {
> > +	.name		= PCINAME,
> > +	.id_table	= pci_ids,
> > +	.probe		= pti_pci_probe,
> > +	.remove		= pti_pci_remove,
> > +};
> > +
> > +/**
> > + *
> > + * pti_init():
> 
> Needs short function summary on line above.
> 
> > + *
> > + * @return int __init: 0 for success, any other value error.
> 
> fix kernel-doc notation.
> 
> > + *
> > + */
> > +static int __init pti_init(void)
> > +{
> > +	int retval = -EINVAL;
> > +
> > +	/* First register module as tty device */
> > +
> > +	pti_tty_driver = alloc_tty_driver(1);
> > +	if (pti_tty_driver == NULL) {
> > +		pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n",
> > +			__func__, __LINE__);
> > +		return -ENOMEM;
> > +	}
> > +
> > +	pti_tty_driver->owner			= THIS_MODULE;
> > +	pti_tty_driver->magic			= TTY_DRIVER_MAGIC;
> > +	pti_tty_driver->driver_name		= DRIVERNAME;
> > +	pti_tty_driver->name			= TTYNAME;
> > +	pti_tty_driver->major			= 0;
> > +	pti_tty_driver->minor_start		= PTITTY_MINOR_START;
> > +	pti_tty_driver->minor_num		= PTITTY_MINOR_NUM;
> > +	pti_tty_driver->num			= PTITTY_MINOR_NUM;
> > +	pti_tty_driver->type			= TTY_DRIVER_TYPE_SYSTEM;
> > +	pti_tty_driver->subtype			= SYSTEM_TYPE_SYSCONS;
> > +	pti_tty_driver->flags			= TTY_DRIVER_REAL_RAW |
> > +						  TTY_DRIVER_DYNAMIC_DEV;
> > +	pti_tty_driver->init_termios		= tty_std_termios;
> > +
> > +	tty_set_operations(pti_tty_driver, &pti_tty_driver_ops);
> > +
> > +	retval = tty_register_driver(pti_tty_driver);
> > +	if (retval) {
> > +		pr_err("%s(%d): TTY registration failed of pti driver\n",
> > +			__func__, __LINE__);
> > +		pr_err("%s(%d): Error value returned: %d\n",
> > +			__func__, __LINE__, retval);
> > +
> > +		pti_tty_driver = NULL;
> > +		return retval;
> > +	}
> > +
> > +	retval = pci_register_driver(&pti_pci_driver);
> > +
> > +	if (retval) {
> > +		pr_err("%s(%d): PCI registration failed of pti driver\n",
> > +			__func__, __LINE__);
> > +		pr_err("%s(%d): Error value returned: %d\n",
> > +			__func__, __LINE__, retval);
> > +
> > +		tty_unregister_driver(pti_tty_driver);
> > +		pr_err("%s(%d): Unregistering TTY part of pti driver\n",
> > +			__func__, __LINE__);
> > +		pti_tty_driver = NULL;
> > +		return retval;
> > +	}
> > +
> > +	return retval;
> > +}
> > +
> > +/**
> > + * pti_exit(): Unregisters this module as a tty and pci driver.
> 
> use - instead of :
> 
> > + */
> > +static void __exit pti_exit(void)
> > +{
> > +	int retval;
> > +
> > +	tty_unregister_device(pti_tty_driver, 0);
> > +	tty_unregister_device(pti_tty_driver, 1);
> > +
> > +	retval = tty_unregister_driver(pti_tty_driver);
> > +	if (retval) {
> > +		pr_err("%s(%d): TTY unregistration failed of pti driver\n",
> > +			__func__, __LINE__);
> > +		pr_err("%s(%d): Error value returned: %d\n",
> > +			__func__, __LINE__, retval);
> > +	}
> > +
> > +	pci_unregister_driver(&pti_pci_driver);
> > +
> > +	retval = misc_deregister(&pti_char_driver);
> > +	if (retval) {
> > +		pr_err("%s(%d): CHAR unregistration failed of pti driver\n",
> > +			__func__, __LINE__);
> > +		pr_err("%s(%d): Error value returned: %d\n",
> > +			__func__, __LINE__, retval);
> > +	}
> > +
> > +	unregister_console(&pti_console);
> > +	return;
> > +}
> > +
> > +module_init(pti_init);
> > +module_exit(pti_exit);
> > +
> > +MODULE_LICENSE("GPL");
> > +MODULE_AUTHOR("Ken Mills, Jay Freyensee");
> > +MODULE_DESCRIPTION("PTI Driver");
> 
> 
> ---
> ~Randy
> *** Remember to use Documentation/SubmitChecklist when testing your code ***



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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-20 23:05     ` J Freyensee
@ 2011-04-20 23:10       ` Randy Dunlap
  2011-04-21 21:06         ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Randy Dunlap @ 2011-04-20 23:10 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Wed, 20 Apr 2011 16:05:00 -0700 J Freyensee wrote:

> On Tue, 2011-04-19 at 16:15 -0700, Randy Dunlap wrote:
> 
> A couple more comments below.
> 
> > On Tue, 19 Apr 2011 15:58:08 -0700 james_p_freyensee@linux.intel.com wrote:


> > > + * @max_IDS: The max amount of available write IDs to use.
> > > + * @baseID:  The starting SW channel ID, based on the Intel
> > > + *           PTI arch.
> > > + *
> > > + * @return: pti_masterchannel struct containing master, channel ID address,
> > 
> > No '@' on "return".
> 
> Why no '@' on 'return' when just by doing a 'grep -Ri "@return" drivers/
> | wc -l' I count 369 examples of '@return' being used already in the
> kernel?  It looks like an acceptable format to me.

It's not.  See Documentation/kernel-doc-nano-HOWTO.txt.
'@' goes on function parameters (or struct members).
Not on return values.  Those other places should be fixed, but
it's just not a high priority thing to do.


> > > + * or 0 for error.
> > > + *
> > > + * Each bit in the arrays ia_app and ia_os correspond to a master and
> > > + * channel id. The bit is one if the id is taken and 0 if free. For
> > > + * every master there are 128 channel id's.
> > > + */
> > > +static struct pti_masterchannel *getID(u8 *IDarray, int max_IDS, int baseID)
> > > +{


> > > +/**
> > > + * pti_request_masterchannel() - Kernel API function used to allocate
> > > + *                                a master, channel ID address to write to
> > > + *                                PTI HW.
> > > + * @type: 0- request Application  master, channel aperture ID write address.
> > > + *        1- request OS master, channel aperture ID write address.
> > > + *        2- request Modem master, channel aperture ID write
> > > + *           address.
> > > + *        Other values, error.
> > > + * @return: pti_masterchannel struct or 0 for error.
> > 
> > No '@' on "return".
> 
> Same reason here.

Same answer here.



> > > + *
> > > + * @return int : Success = 0, otherwise fail.
> > 
> > No '@' on "return".
> 
> Same explanation as above.

Same reply also.



---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-20 19:14             ` Greg KH
@ 2011-04-20 23:11               ` Andrew Morton
  2011-04-20 23:16                 ` J Freyensee
  2011-04-20 23:19                 ` David Rientjes
  0 siblings, 2 replies; 171+ messages in thread
From: Andrew Morton @ 2011-04-20 23:11 UTC (permalink / raw)
  To: Greg KH
  Cc: J Freyensee, David Rientjes, linux-kernel, suhail.ahmed,
	christophe.guerard

On Wed, 20 Apr 2011 12:14:21 -0700
Greg KH <gregkh@suse.de> wrote:

> > But as David pointed out, if there is work other than mine coming that
> > has already been proposed, wouldn't it be good to get this patch in
> > place now to start the encouragement of future eyes to just call this
> > function than re-invent the wheel?
> 
> No, then those projects submit the patch to export this, if they happen
> to get to mainline before this one does.
> 
> Again, don't export something unless you are using it at the time, no
> "this is to be used hopefully by something in the future" type stuff
> please.  Who knows if those future plans ever pan out.

Well there's an easy solution here.  Send the patch to export
get_task_comm(), then send along some patches which fix

z:/usr/src/linux-2.6.39-rc4> grep -r 'current->comm' drivers | wc -l
89


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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-20 23:11               ` Andrew Morton
@ 2011-04-20 23:16                 ` J Freyensee
  2011-04-20 23:46                   ` Andrew Morton
  2011-04-20 23:19                 ` David Rientjes
  1 sibling, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-04-20 23:16 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Greg KH, David Rientjes, linux-kernel, suhail.ahmed, christophe.guerard

On Wed, 2011-04-20 at 16:11 -0700, Andrew Morton wrote:
> On Wed, 20 Apr 2011 12:14:21 -0700
> Greg KH <gregkh@suse.de> wrote:
> 
> > > But as David pointed out, if there is work other than mine coming that
> > > has already been proposed, wouldn't it be good to get this patch in
> > > place now to start the encouragement of future eyes to just call this
> > > function than re-invent the wheel?
> > 
> > No, then those projects submit the patch to export this, if they happen
> > to get to mainline before this one does.
> > 
> > Again, don't export something unless you are using it at the time, no
> > "this is to be used hopefully by something in the future" type stuff
> > please.  Who knows if those future plans ever pan out.
> 
> Well there's an easy solution here.  Send the patch to export
> get_task_comm(), then send along some patches which fix
> 
> z:/usr/src/linux-2.6.39-rc4> grep -r 'current->comm' drivers | wc -l
> 89
> 

Andrew, so does this mean you want me to send this patch to export
get_task_comm() to you then?

Thanks,
Jay



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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-20 23:11               ` Andrew Morton
  2011-04-20 23:16                 ` J Freyensee
@ 2011-04-20 23:19                 ` David Rientjes
  1 sibling, 0 replies; 171+ messages in thread
From: David Rientjes @ 2011-04-20 23:19 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Greg KH, J Freyensee, linux-kernel, suhail.ahmed, christophe.guerard

On Wed, 20 Apr 2011, Andrew Morton wrote:

> > > But as David pointed out, if there is work other than mine coming that
> > > has already been proposed, wouldn't it be good to get this patch in
> > > place now to start the encouragement of future eyes to just call this
> > > function than re-invent the wheel?
> > 
> > No, then those projects submit the patch to export this, if they happen
> > to get to mainline before this one does.
> > 
> > Again, don't export something unless you are using it at the time, no
> > "this is to be used hopefully by something in the future" type stuff
> > please.  Who knows if those future plans ever pan out.
> 
> Well there's an easy solution here.  Send the patch to export
> get_task_comm(), then send along some patches which fix
> 
> z:/usr/src/linux-2.6.39-rc4> grep -r 'current->comm' drivers | wc -l
> 89
> 

If we go this route and continue to support /proc/pid/comm, then we're 
going to need to ensure nothing that dereferences p->comm for any thread p 
is in a blockable context and that it's acceptable for get_task_comm(p) to 
take task_lock(p), and that requires not nesting it with 
write_lock(&tasklist_lock).

I'm thinking that we're going to want to choose something else other than 
p->alloc_lock to protect p->comm since that lock is protecting so many 
different members of struct task_struct that we may not know whether it's 
held when we want to print p->comm.

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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-20 23:16                 ` J Freyensee
@ 2011-04-20 23:46                   ` Andrew Morton
  2011-04-21 16:12                     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Andrew Morton @ 2011-04-20 23:46 UTC (permalink / raw)
  To: james_p_freyensee
  Cc: Greg KH, David Rientjes, linux-kernel, suhail.ahmed, christophe.guerard

On Wed, 20 Apr 2011 16:16:08 -0700
J Freyensee <james_p_freyensee@linux.intel.com> wrote:

> On Wed, 2011-04-20 at 16:11 -0700, Andrew Morton wrote:
> > On Wed, 20 Apr 2011 12:14:21 -0700
> > Greg KH <gregkh@suse.de> wrote:
> > 
> > > > But as David pointed out, if there is work other than mine coming that
> > > > has already been proposed, wouldn't it be good to get this patch in
> > > > place now to start the encouragement of future eyes to just call this
> > > > function than re-invent the wheel?
> > > 
> > > No, then those projects submit the patch to export this, if they happen
> > > to get to mainline before this one does.
> > > 
> > > Again, don't export something unless you are using it at the time, no
> > > "this is to be used hopefully by something in the future" type stuff
> > > please.  Who knows if those future plans ever pan out.
> > 
> > Well there's an easy solution here.  Send the patch to export
> > get_task_comm(), then send along some patches which fix
> > 
> > z:/usr/src/linux-2.6.39-rc4> grep -r 'current->comm' drivers | wc -l
> > 89
> > 
> 
> Andrew, so does this mean you want me to send this patch to export
> get_task_comm() to you then?
> 

That works.  But Greg might see us doing it, so some additional
mergeable patches which *need* that export will keep him happy.

(iow, you're being extorted into doing some kernel cleanup work)

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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-20 23:46                   ` Andrew Morton
@ 2011-04-21 16:12                     ` J Freyensee
  0 siblings, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-04-21 16:12 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Greg KH, David Rientjes, linux-kernel, suhail.ahmed, christophe.guerard

On Wed, 2011-04-20 at 16:46 -0700, Andrew Morton wrote:
> On Wed, 20 Apr 2011 16:16:08 -0700
> J Freyensee <james_p_freyensee@linux.intel.com> wrote:
> 
> > On Wed, 2011-04-20 at 16:11 -0700, Andrew Morton wrote:
> > > On Wed, 20 Apr 2011 12:14:21 -0700
> > > Greg KH <gregkh@suse.de> wrote:
> > > 
> > > > > But as David pointed out, if there is work other than mine coming that
> > > > > has already been proposed, wouldn't it be good to get this patch in
> > > > > place now to start the encouragement of future eyes to just call this
> > > > > function than re-invent the wheel?
> > > > 
> > > > No, then those projects submit the patch to export this, if they happen
> > > > to get to mainline before this one does.
> > > > 
> > > > Again, don't export something unless you are using it at the time, no
> > > > "this is to be used hopefully by something in the future" type stuff
> > > > please.  Who knows if those future plans ever pan out.
> > > 
> > > Well there's an easy solution here.  Send the patch to export
> > > get_task_comm(), then send along some patches which fix
> > > 
> > > z:/usr/src/linux-2.6.39-rc4> grep -r 'current->comm' drivers | wc -l
> > > 89
> > > 
> > 
> > Andrew, so does this mean you want me to send this patch to export
> > get_task_comm() to you then?
> > 
> 
> That works.  But Greg might see us doing it, so some additional
> mergeable patches which *need* that export will keep him happy.
> 

Okay, so the pti driver I own needs that export to be able to build as a
module, so that is a start :-)

> (iow, you're being extorted into doing some kernel cleanup work)



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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-20 23:10       ` Randy Dunlap
@ 2011-04-21 21:06         ` J Freyensee
  2011-04-21 21:17           ` Randy Dunlap
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-04-21 21:06 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Wed, 2011-04-20 at 16:10 -0700, Randy Dunlap wrote:
> On Wed, 20 Apr 2011 16:05:00 -0700 J Freyensee wrote:
> 
> > On Tue, 2011-04-19 at 16:15 -0700, Randy Dunlap wrote:
> > 
> > A couple more comments below.
> > 
> > > On Tue, 19 Apr 2011 15:58:08 -0700 james_p_freyensee@linux.intel.com wrote:
> 
> 
> > > > + * @max_IDS: The max amount of available write IDs to use.
> > > > + * @baseID:  The starting SW channel ID, based on the Intel
> > > > + *           PTI arch.
> > > > + *
> > > > + * @return: pti_masterchannel struct containing master, channel ID address,
> > > 
> > > No '@' on "return".
> > 
> > Why no '@' on 'return' when just by doing a 'grep -Ri "@return" drivers/
> > | wc -l' I count 369 examples of '@return' being used already in the
> > kernel?  It looks like an acceptable format to me.
> 
> It's not.  See Documentation/kernel-doc-nano-HOWTO.txt.
> '@' goes on function parameters (or struct members).
> Not on return values.  Those other places should be fixed, but
> it's just not a high priority thing to do.
> 

How should I document return values of functions?  I would like them
documented somehow.

kernel-doc-nano-HOWTO.txt does not say other than give examples of what
I don't want to do and to 'Take a look around the source tree for
examples'.  

So one example I found that documents return values does not seem to
follow kernel-doc-nano-HOWTO.txt:

(acpi/acpica/dsutils.c)
 /*******************************************************************************
 *
 * FUNCTION:    acpi_ds_clear_implicit_return
 *
 * PARAMETERS:  walk_state          - Current State
 *
 * RETURN:      None.
 *

then another driver, net/wireless/libertas/tx.c, does exactly what I do
that I'm being advised against (minus the 's' at the end of 'return'):

/**
 *  @brief This function sends to the host the last transmitted packet,
 *  filling the radiotap headers with transmission information.
 *
 *  @param priv     A pointer to struct lbs_private structure
 *  @param status   A 32 bit value containing transmission status.
 *
 *  @returns void
 */



> 
> > > > + * or 0 for error.
> > > > + *
> > > > + * Each bit in the arrays ia_app and ia_os correspond to a master and
> > > > + * channel id. The bit is one if the id is taken and 0 if free. For
> > > > + * every master there are 128 channel id's.
> > > > + */
> > > > +static struct pti_masterchannel *getID(u8 *IDarray, int max_IDS, int baseID)
> > > > +{
> 
> 
> > > > +/**
> > > > + * pti_request_masterchannel() - Kernel API function used to allocate
> > > > + *                                a master, channel ID address to write to
> > > > + *                                PTI HW.
> > > > + * @type: 0- request Application  master, channel aperture ID write address.
> > > > + *        1- request OS master, channel aperture ID write address.
> > > > + *        2- request Modem master, channel aperture ID write
> > > > + *           address.
> > > > + *        Other values, error.
> > > > + * @return: pti_masterchannel struct or 0 for error.
> > > 
> > > No '@' on "return".
> > 
> > Same reason here.
> 
> Same answer here.
> 
> 
> 
> > > > + *
> > > > + * @return int : Success = 0, otherwise fail.
> > > 
> > > No '@' on "return".
> > 
> > Same explanation as above.
> 
> Same reply also.
> 
> 
> 
> ---
> ~Randy
> *** Remember to use Documentation/SubmitChecklist when testing your code ***



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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-21 21:06         ` J Freyensee
@ 2011-04-21 21:17           ` Randy Dunlap
  0 siblings, 0 replies; 171+ messages in thread
From: Randy Dunlap @ 2011-04-21 21:17 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Thu, 21 Apr 2011 14:06:39 -0700 J Freyensee wrote:

> On Wed, 2011-04-20 at 16:10 -0700, Randy Dunlap wrote:
> > On Wed, 20 Apr 2011 16:05:00 -0700 J Freyensee wrote:
> > 
> > > On Tue, 2011-04-19 at 16:15 -0700, Randy Dunlap wrote:
> > > 
> > > A couple more comments below.
> > > 
> > > > On Tue, 19 Apr 2011 15:58:08 -0700 james_p_freyensee@linux.intel.com wrote:
> > 
> > 
> > > > > + * @max_IDS: The max amount of available write IDs to use.
> > > > > + * @baseID:  The starting SW channel ID, based on the Intel
> > > > > + *           PTI arch.
> > > > > + *
> > > > > + * @return: pti_masterchannel struct containing master, channel ID address,
> > > > 
> > > > No '@' on "return".
> > > 
> > > Why no '@' on 'return' when just by doing a 'grep -Ri "@return" drivers/
> > > | wc -l' I count 369 examples of '@return' being used already in the
> > > kernel?  It looks like an acceptable format to me.
> > 
> > It's not.  See Documentation/kernel-doc-nano-HOWTO.txt.
> > '@' goes on function parameters (or struct members).
> > Not on return values.  Those other places should be fixed, but
> > it's just not a high priority thing to do.
> > 
> 
> How should I document return values of functions?  I would like them
> documented somehow.

Agreed.

Just use something like:

 * Returns:
 *	0 for success
 *	error code < 0 for errors


> kernel-doc-nano-HOWTO.txt does not say other than give examples of what
> I don't want to do and to 'Take a look around the source tree for
> examples'.  
> 
> So one example I found that documents return values does not seem to
> follow kernel-doc-nano-HOWTO.txt:
> 
> (acpi/acpica/dsutils.c)
>  /*******************************************************************************
>  *
>  * FUNCTION:    acpi_ds_clear_implicit_return
>  *
>  * PARAMETERS:  walk_state          - Current State
>  *
>  * RETURN:      None.
>  *

Yes, I know that there are several that don't do so.
And at least in this case, they have a reason:  acpica is portable code,
not specific to Linux.


> then another driver, net/wireless/libertas/tx.c, does exactly what I do
> that I'm being advised against (minus the 's' at the end of 'return'):
> 
> /**
>  *  @brief This function sends to the host the last transmitted packet,
>  *  filling the radiotap headers with transmission information.
>  *
>  *  @param priv     A pointer to struct lbs_private structure
>  *  @param status   A 32 bit value containing transmission status.
>  *
>  *  @returns void
>  */

I'll be glad to send them email about this.  Thanks for noticing.


> > > > > + * or 0 for error.
> > > > > + *
> > > > > + * Each bit in the arrays ia_app and ia_os correspond to a master and
> > > > > + * channel id. The bit is one if the id is taken and 0 if free. For
> > > > > + * every master there are 128 channel id's.
> > > > > + */
> > > > > +static struct pti_masterchannel *getID(u8 *IDarray, int max_IDS, int baseID)
> > > > > +{
> > 
> > 
> > > > > +/**
> > > > > + * pti_request_masterchannel() - Kernel API function used to allocate
> > > > > + *                                a master, channel ID address to write to
> > > > > + *                                PTI HW.
> > > > > + * @type: 0- request Application  master, channel aperture ID write address.
> > > > > + *        1- request OS master, channel aperture ID write address.
> > > > > + *        2- request Modem master, channel aperture ID write
> > > > > + *           address.
> > > > > + *        Other values, error.
> > > > > + * @return: pti_masterchannel struct or 0 for error.
> > > > 
> > > > No '@' on "return".
> > > 
> > > Same reason here.
> > 
> > Same answer here.
> > 
> > 
> > 
> > > > > + *
> > > > > + * @return int : Success = 0, otherwise fail.
> > > > 
> > > > No '@' on "return".
> > > 
> > > Same explanation as above.
> > 
> > Same reply also.


---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-20  1:25   ` David Rientjes
  2011-04-20  9:46     ` Alan Cox
@ 2011-04-22 17:57     ` J Freyensee
  1 sibling, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-04-22 17:57 UTC (permalink / raw)
  To: David Rientjes
  Cc: Greg Kroah-Hartman, linux-kernel, suhail.ahmed, christophe.guerard

On Tue, 2011-04-19 at 18:25 -0700, David Rientjes wrote:
> On Tue, 19 Apr 2011, james_p_freyensee@linux.intel.com wrote:
> 
> > +static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc)
> > +{
> > +	struct pti_masterchannel mccontrol = {.master = CONTROL_ID,
> > +					      .channel = 0};
> > +	const char *control_format = "%3d %3d %s";
> > +
> > +	char comm[sizeof(current->comm) + 1];
> > +	u8 control_frame[CONTROL_FRAME_LEN];
> > +
> > +	if (!in_interrupt())
> > +		get_task_comm(comm, current);
> > +	else
> > +		strcpy(comm, "Interrupt");
> > +
> > +	/* Ensure our buffer is zero terminated */
> > +	comm[sizeof(current->comm)] = 0;
> > +
> 
> You definitely need to use get_task_comm() here, but that means you can't 
> allocate char comm[] on the stack with anything but TASK_COMM_LEN, which 
> is small enough that it shouldn't be an issue.  Otherwise there's nothing 
> protecting sizeof(current->comm) from changing without holding 
> task_lock(current).

I'm going to look at utilizing get_task_comm() more in this function,
but I think I am okay even if I miss one, as I am just doing a read from
it.  What is written in set_task_comm() states that threads may read
from current->comm without holding the task_lock().  The name could be
incomplete, which would be non-ideal (but acceptable), but it's supposed
to be safe from non-terminating string reads.

And it seems like the fix for

> + comm[sizeof(current->comm)] = 0;

can just be comm[TASK_COMM_LEN].


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

* export kernel call get_task_comm for driver use
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (17 preceding siblings ...)
  2011-04-19 22:58 ` [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions james_p_freyensee
@ 2011-04-22 22:26 ` james_p_freyensee
  2011-04-22 22:35   ` Greg KH
  2011-04-22 22:26 ` [PATCH] export kernel call get_task_comm() james_p_freyensee
                   ` (22 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-04-22 22:26 UTC (permalink / raw)
  To: akpm
  Cc: rientjes, gregkh, linux-kernel, suhail.ahmed, christophe.guerard,
	james_p_freyensee

>From an earlier submission by me it was suggested that this patch
should go to Andrew for merging to be used by the pti driver
I will be re-submitting shortly.

Once my device drivers are accepted into the kernel, I will try
and help out to clean up the kernel a little from this
patch that exports get_task_comm() that Andrew suggested. 
I cannot promise a timeline or what I can fix, but I will
look into fixing a few (Andrew found 89 potential cleanups).

From: james_p_freyensee@linux.intel.com
Subject: export kernel call get_task_comm for driver use
In-Reply-To: james_p_freyensee@linux.intel.com


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

* [PATCH] export kernel call get_task_comm().
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (18 preceding siblings ...)
  2011-04-22 22:26 ` export kernel call get_task_comm for driver use james_p_freyensee
@ 2011-04-22 22:26 ` james_p_freyensee
  2011-04-22 22:35   ` David Rientjes
  2011-04-22 22:35 ` Resend: export kernel call get_task_comm for driver use james_p_freyensee
                   ` (21 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-04-22 22:26 UTC (permalink / raw)
  To: akpm
  Cc: rientjes, gregkh, linux-kernel, suhail.ahmed, christophe.guerard,
	james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows drivers who call this function to be compiled modularly.
Otherwise, a driver who is interested in this type of functionality
has to implement their own get_task_comm() call, causing code
duplication in the Linux source tree.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 fs/exec.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 8328beb..e1ac338 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1004,6 +1004,7 @@ char *get_task_comm(char *buf, struct task_struct *tsk)
 	task_unlock(tsk);
 	return buf;
 }
+EXPORT_SYMBOL_GPL(get_task_comm);
 
 void set_task_comm(struct task_struct *tsk, char *buf)
 {
-- 
1.7.2.3


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

* Re: export kernel call get_task_comm for driver use
  2011-04-22 22:26 ` export kernel call get_task_comm for driver use james_p_freyensee
@ 2011-04-22 22:35   ` Greg KH
  0 siblings, 0 replies; 171+ messages in thread
From: Greg KH @ 2011-04-22 22:35 UTC (permalink / raw)
  To: james_p_freyensee
  Cc: akpm, rientjes, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, Apr 22, 2011 at 03:26:27PM -0700, james_p_freyensee@linux.intel.com wrote:
> >From an earlier submission by me it was suggested that this patch
> should go to Andrew for merging to be used by the pti driver
> I will be re-submitting shortly.
> 
> Once my device drivers are accepted into the kernel, I will try
> and help out to clean up the kernel a little from this
> patch that exports get_task_comm() that Andrew suggested. 
> I cannot promise a timeline or what I can fix, but I will
> look into fixing a few (Andrew found 89 potential cleanups).

I think the goal is for that cleanup to happen now, to justify the
addition of the exported symbol.  Without that, there is no need to
export the symbol now at all, as who knows when your driver will be
accepted.

Or, just wait and make it part of your driver patch series, like you did
before, no need to get it accepted now, right?

thanks,

greg k-h

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

* Resend: export kernel call get_task_comm for driver use
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (19 preceding siblings ...)
  2011-04-22 22:26 ` [PATCH] export kernel call get_task_comm() james_p_freyensee
@ 2011-04-22 22:35 ` james_p_freyensee
  2011-04-22 22:35 ` [PATCH] export kernel call get_task_comm() james_p_freyensee
                   ` (20 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-04-22 22:35 UTC (permalink / raw)
  To: akpm
  Cc: rientjes, gregkh, linux-kernel, suhail.ahmed, christophe.guerard,
	james_p_freyensee

Resend: Sorry, I misspelled the email address of the main
person I want this patch directed to.

>From an earlier submission by me it was suggested that this patch
should go to Andrew for merging to be used by the pti driver
I will be re-submitting shortly.

Once my device drivers are accepted into the kernel, I will try
and help out to clean up the kernel a little from this
patch that exports get_task_comm() that Andrew suggested. 
I cannot promise a timeline or what I can fix, but I will
look into fixing a few (Andrew found 89 potential cleanups).

From: james_p_freyensee@linux.intel.com
Subject: Resend: export kernel call get_task_comm for driver use
In-Reply-To: james_p_freyensee@linux.intel.com


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

* [PATCH] export kernel call get_task_comm().
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (20 preceding siblings ...)
  2011-04-22 22:35 ` Resend: export kernel call get_task_comm for driver use james_p_freyensee
@ 2011-04-22 22:35 ` james_p_freyensee
  2011-04-22 22:43   ` Greg KH
  2011-04-22 23:32 ` Request for review and addition of PTI implementation into kernel james_p_freyensee
                   ` (19 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-04-22 22:35 UTC (permalink / raw)
  To: akpm
  Cc: rientjes, gregkh, linux-kernel, suhail.ahmed, christophe.guerard,
	james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows drivers who call this function to be compiled modularly.
Otherwise, a driver who is interested in this type of functionality
has to implement their own get_task_comm() call, causing code
duplication in the Linux source tree.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 fs/exec.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 8328beb..e1ac338 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1004,6 +1004,7 @@ char *get_task_comm(char *buf, struct task_struct *tsk)
 	task_unlock(tsk);
 	return buf;
 }
+EXPORT_SYMBOL_GPL(get_task_comm);
 
 void set_task_comm(struct task_struct *tsk, char *buf)
 {
-- 
1.7.2.3


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

* Re: [PATCH] export kernel call get_task_comm().
  2011-04-22 22:26 ` [PATCH] export kernel call get_task_comm() james_p_freyensee
@ 2011-04-22 22:35   ` David Rientjes
  2011-04-22 22:43     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: David Rientjes @ 2011-04-22 22:35 UTC (permalink / raw)
  To: james_p_freyensee
  Cc: akpm, gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, 22 Apr 2011, james_p_freyensee@linux.intel.com wrote:

> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This allows drivers who call this function to be compiled modularly.
> Otherwise, a driver who is interested in this type of functionality
> has to implement their own get_task_comm() call, causing code
> duplication in the Linux source tree.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>

Acked-by: David Rientjes <rientjes@google.com>

I still suggest that we implement finer-grained protection for tsk->comm 
through get_task_comm(), though, because it's going to be difficult to 
know whether task_lock(tsk) is held in all contexts we'll want to call it; 
task_lock(tsk) is used to protect many members of task_struct.

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

* Re: [PATCH] export kernel call get_task_comm().
  2011-04-22 22:35 ` [PATCH] export kernel call get_task_comm() james_p_freyensee
@ 2011-04-22 22:43   ` Greg KH
  2011-04-22 22:59     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-04-22 22:43 UTC (permalink / raw)
  To: james_p_freyensee
  Cc: akpm, rientjes, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, Apr 22, 2011 at 03:35:44PM -0700, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This allows drivers who call this function to be compiled modularly.
> Otherwise, a driver who is interested in this type of functionality
> has to implement their own get_task_comm() call, causing code
> duplication in the Linux source tree.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>

I think the goal is for the cleanup to happen now, to justify the
addition of the exported symbol.  Without that, there is no need to
export the symbol now at all, as who knows when your driver will be
accepted.

Or, just wait and make it part of your driver patch series, like you did
before, no need to get it accepted now, right?

thanks,

greg k-h

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

* Re: [PATCH] export kernel call get_task_comm().
  2011-04-22 22:35   ` David Rientjes
@ 2011-04-22 22:43     ` J Freyensee
  0 siblings, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-04-22 22:43 UTC (permalink / raw)
  To: David Rientjes
  Cc: akpm, gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, 2011-04-22 at 15:35 -0700, David Rientjes wrote:
> On Fri, 22 Apr 2011, james_p_freyensee@linux.intel.com wrote:
> 
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > This allows drivers who call this function to be compiled modularly.
> > Otherwise, a driver who is interested in this type of functionality
> > has to implement their own get_task_comm() call, causing code
> > duplication in the Linux source tree.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> Acked-by: David Rientjes <rientjes@google.com>
> 
> I still suggest that we implement finer-grained protection for tsk->comm 
> through get_task_comm(), though, because it's going to be difficult to 
> know whether task_lock(tsk) is held in all contexts we'll want to call it; 
> task_lock(tsk) is used to protect many members of task_struct.

Okay, but how about accepting this as step 1, then investigate a finer
grained lock structure as step 2?


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

* Re: [PATCH] export kernel call get_task_comm().
  2011-04-22 22:43   ` Greg KH
@ 2011-04-22 22:59     ` J Freyensee
  2011-04-22 23:04       ` Greg KH
  2011-04-22 23:19       ` David Rientjes
  0 siblings, 2 replies; 171+ messages in thread
From: J Freyensee @ 2011-04-22 22:59 UTC (permalink / raw)
  To: Greg KH; +Cc: akpm, rientjes, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, 2011-04-22 at 15:43 -0700, Greg KH wrote:
> On Fri, Apr 22, 2011 at 03:35:44PM -0700, james_p_freyensee@linux.intel.com wrote:
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > This allows drivers who call this function to be compiled modularly.
> > Otherwise, a driver who is interested in this type of functionality
> > has to implement their own get_task_comm() call, causing code
> > duplication in the Linux source tree.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> I think the goal is for the cleanup to happen now, to justify the
> addition of the exported symbol.  Without that, there is no need to
> export the symbol now at all, as who knows when your driver will be
> accepted.
> 
> Or, just wait and make it part of your driver patch series, like you did
> before, no need to get it accepted now, right?
>

Well, at some point a few people like Alan Cox and Arjan VdV would like
to see this work on it's way to Linus's tree.

I'll do whatever is best and easiest for you and will bring a close to
my submission attempts.  I can also just go into the Kconfig where the
pti driver is configured and just make the selection bool, yes or no,
and not make it an option to compile this modularly.  Then I'll drop
this patch all together.  This is the whole reason why I'm making this
change.  I don't have to have the pti driver as a module, just more
convenient.  And within the fs/exec.c it states reads to 'current->comm'
without a lock is safe.

> thanks,
> 
> greg k-h



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

* Re: [PATCH] export kernel call get_task_comm().
  2011-04-22 22:59     ` J Freyensee
@ 2011-04-22 23:04       ` Greg KH
  2011-04-22 23:08         ` J Freyensee
  2011-04-22 23:19       ` David Rientjes
  1 sibling, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-04-22 23:04 UTC (permalink / raw)
  To: J Freyensee
  Cc: akpm, rientjes, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, Apr 22, 2011 at 03:59:42PM -0700, J Freyensee wrote:
> On Fri, 2011-04-22 at 15:43 -0700, Greg KH wrote:
> > On Fri, Apr 22, 2011 at 03:35:44PM -0700, james_p_freyensee@linux.intel.com wrote:
> > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > 
> > > This allows drivers who call this function to be compiled modularly.
> > > Otherwise, a driver who is interested in this type of functionality
> > > has to implement their own get_task_comm() call, causing code
> > > duplication in the Linux source tree.
> > > 
> > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > I think the goal is for the cleanup to happen now, to justify the
> > addition of the exported symbol.  Without that, there is no need to
> > export the symbol now at all, as who knows when your driver will be
> > accepted.
> > 
> > Or, just wait and make it part of your driver patch series, like you did
> > before, no need to get it accepted now, right?
> >
> 
> Well, at some point a few people like Alan Cox and Arjan VdV would like
> to see this work on it's way to Linus's tree.

That's because that is the policy of your distro you are working with,
which has nothing to do with the kernel developers.

Again, if you get your driver accepted, I have no objection to this
export at all.  Just take the time and get your driver merged, it's that
simple.

thanks,

greg k-h

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

* Re: [PATCH] export kernel call get_task_comm().
  2011-04-22 23:04       ` Greg KH
@ 2011-04-22 23:08         ` J Freyensee
  2011-04-22 23:17           ` Greg KH
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-04-22 23:08 UTC (permalink / raw)
  To: Greg KH; +Cc: akpm, rientjes, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, 2011-04-22 at 16:04 -0700, Greg KH wrote:
> On Fri, Apr 22, 2011 at 03:59:42PM -0700, J Freyensee wrote:
> > On Fri, 2011-04-22 at 15:43 -0700, Greg KH wrote:
> > > On Fri, Apr 22, 2011 at 03:35:44PM -0700, james_p_freyensee@linux.intel.com wrote:
> > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > 
> > > > This allows drivers who call this function to be compiled modularly.
> > > > Otherwise, a driver who is interested in this type of functionality
> > > > has to implement their own get_task_comm() call, causing code
> > > > duplication in the Linux source tree.
> > > > 
> > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > 
> > > I think the goal is for the cleanup to happen now, to justify the
> > > addition of the exported symbol.  Without that, there is no need to
> > > export the symbol now at all, as who knows when your driver will be
> > > accepted.
> > > 
> > > Or, just wait and make it part of your driver patch series, like you did
> > > before, no need to get it accepted now, right?
> > >
> > 
> > Well, at some point a few people like Alan Cox and Arjan VdV would like
> > to see this work on it's way to Linus's tree.
> 
> That's because that is the policy of your distro you are working with,
> which has nothing to do with the kernel developers.
> 
> Again, if you get your driver accepted, I have no objection to this
> export at all.  Just take the time and get your driver merged, it's that
> simple.

So I guess the best route is for me to make this patch with my driver
then?  I'm ready to re-submit those drivers again; I cleaned up all the
style issues pointed out by Randy.

> 
> thanks,
> 
> greg k-h



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

* Re: [PATCH] export kernel call get_task_comm().
  2011-04-22 23:08         ` J Freyensee
@ 2011-04-22 23:17           ` Greg KH
  0 siblings, 0 replies; 171+ messages in thread
From: Greg KH @ 2011-04-22 23:17 UTC (permalink / raw)
  To: J Freyensee
  Cc: akpm, rientjes, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, Apr 22, 2011 at 04:08:16PM -0700, J Freyensee wrote:
> On Fri, 2011-04-22 at 16:04 -0700, Greg KH wrote:
> > On Fri, Apr 22, 2011 at 03:59:42PM -0700, J Freyensee wrote:
> > > On Fri, 2011-04-22 at 15:43 -0700, Greg KH wrote:
> > > > On Fri, Apr 22, 2011 at 03:35:44PM -0700, james_p_freyensee@linux.intel.com wrote:
> > > > > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > > 
> > > > > This allows drivers who call this function to be compiled modularly.
> > > > > Otherwise, a driver who is interested in this type of functionality
> > > > > has to implement their own get_task_comm() call, causing code
> > > > > duplication in the Linux source tree.
> > > > > 
> > > > > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> > > > 
> > > > I think the goal is for the cleanup to happen now, to justify the
> > > > addition of the exported symbol.  Without that, there is no need to
> > > > export the symbol now at all, as who knows when your driver will be
> > > > accepted.
> > > > 
> > > > Or, just wait and make it part of your driver patch series, like you did
> > > > before, no need to get it accepted now, right?
> > > >
> > > 
> > > Well, at some point a few people like Alan Cox and Arjan VdV would like
> > > to see this work on it's way to Linus's tree.
> > 
> > That's because that is the policy of your distro you are working with,
> > which has nothing to do with the kernel developers.
> > 
> > Again, if you get your driver accepted, I have no objection to this
> > export at all.  Just take the time and get your driver merged, it's that
> > simple.
> 
> So I guess the best route is for me to make this patch with my driver
> then?  I'm ready to re-submit those drivers again; I cleaned up all the
> style issues pointed out by Randy.

Yes, make it part of that patch series.

thanks,

greg k-h

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

* Re: [PATCH] export kernel call get_task_comm().
  2011-04-22 22:59     ` J Freyensee
  2011-04-22 23:04       ` Greg KH
@ 2011-04-22 23:19       ` David Rientjes
  1 sibling, 0 replies; 171+ messages in thread
From: David Rientjes @ 2011-04-22 23:19 UTC (permalink / raw)
  To: J Freyensee
  Cc: Greg KH, Andrew Morton, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, 22 Apr 2011, J Freyensee wrote:

> I'll do whatever is best and easiest for you and will bring a close to
> my submission attempts.  I can also just go into the Kconfig where the
> pti driver is configured and just make the selection bool, yes or no,
> and not make it an option to compile this modularly.  Then I'll drop
> this patch all together.  This is the whole reason why I'm making this
> change.  I don't have to have the pti driver as a module, just more
> convenient.  And within the fs/exec.c it states reads to 'current->comm'
> without a lock is safe.
> 

It's safe to read current->comm without holding task_lock(current), but it 
may be corrupted by a concurrent write via /proc/pid-of-current/comm, 
which could result in garbage where you'd expect the name of the thread.  
That doesn't sound very clean to me and adds more incentive to implement 
some finer-grained protection like a seqlock specifically for tsk->comm.

If /proc/pid/comm is really that important and we can't get away with the 
long-standing prctl(PR_SET_NAME), then you need to protect the string 
somehow and I'm quite surprised this wasn't required before writing other 
threads' comm was allowed.

If you can get away with task_lock(current) in your driver, then great, 
export the symbol and use it, but we have hundreds of racy reads to a 
thread's comm all over the kernel.

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

* Request for review and addition of PTI implementation into kernel
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (21 preceding siblings ...)
  2011-04-22 22:35 ` [PATCH] export kernel call get_task_comm() james_p_freyensee
@ 2011-04-22 23:32 ` james_p_freyensee
  2011-04-22 23:32 ` [PATCH 1/4] export kernel call get_task_comm() james_p_freyensee
                   ` (18 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-04-22 23:32 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

This is a fourth submission and inclusion request into the mainline
kernel.  Fixes include mainly style issues pointed out in the last
review.

From: james_p_freyensee@linux.intel.com
Subject: Request for review and addition of PTI implementation into kernel
In-Reply-To: james_p_freyensee@linux.intel.com


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

* [PATCH 1/4] export kernel call get_task_comm().
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (22 preceding siblings ...)
  2011-04-22 23:32 ` Request for review and addition of PTI implementation into kernel james_p_freyensee
@ 2011-04-22 23:32 ` james_p_freyensee
  2011-04-25 20:57   ` David Rientjes
  2011-04-22 23:32 ` [PATCH 2/4] Kernel documentation for the PTI feature james_p_freyensee
                   ` (17 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-04-22 23:32 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows drivers who call this function to be compiled modularly.
Otherwise, a driver who is interested in this type of functionality
has to implement their own get_task_comm() call, causing code
duplication in the Linux source tree.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 fs/exec.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 8328beb..e1ac338 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1004,6 +1004,7 @@ char *get_task_comm(char *buf, struct task_struct *tsk)
 	task_unlock(tsk);
 	return buf;
 }
+EXPORT_SYMBOL_GPL(get_task_comm);
 
 void set_task_comm(struct task_struct *tsk, char *buf)
 {
-- 
1.7.2.3


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

* [PATCH 2/4] Kernel documentation for the PTI feature.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (23 preceding siblings ...)
  2011-04-22 23:32 ` [PATCH 1/4] export kernel call get_task_comm() james_p_freyensee
@ 2011-04-22 23:32 ` james_p_freyensee
  2011-04-22 23:32 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
                   ` (16 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-04-22 23:32 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

This provides Kernel documentation for the PTI
feature and setting line discipline drivers
on top of tty's for Linux mobile solutions.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 Documentation/pti/pti_intel_mid.txt |   99 +++++++++++++++++++++++++++++++++++
 1 files changed, 99 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/pti/pti_intel_mid.txt

diff --git a/Documentation/pti/pti_intel_mid.txt b/Documentation/pti/pti_intel_mid.txt
new file mode 100644
index 0000000..ab8408b
--- /dev/null
+++ b/Documentation/pti/pti_intel_mid.txt
@@ -0,0 +1,99 @@
+The Intel MID PTI project is HW implemented in Intel Atom
+system-on-a-chip designs based on the Parallel Trace
+Interface for MIPI P1149.7 cJTAG standard.  The kernel solution
+for this platform involves the following files:
+
+./include/linux/pti.h
+./drivers/.../n_tracesink.h
+./drivers/.../n_tracerouter.c
+./drivers/.../n_tracesink.c
+./drivers/.../pti.c
+
+pti.c is the driver that enables various debugging features
+popular on platforms from certain mobile manufacturers.  
+n_tracerouter.c and n_tracesink.c allow extra system information to 
+be collected and routed to the pti driver, such as trace
+debugging data from a modem.  Although n_tracerouter
+and n_tracesink are a part of the complete PTI solution,
+these two line disciplines can work separately from
+pti.c and route any data stream from one /dev/tty node
+to another /dev/tty node via kernel-space.  This provides
+a stable, reliable connection that will not break unless
+the user-space application shuts down (plus avoids
+kernel->user->kernel context switch overheads of routing
+data).
+
+An example debugging usage for this driver system:
+   *Hook /dev/ttyPTI0 to syslogd.  Opening this port will also start
+    a console device to further capture debugging messages to PTI.
+   *Hook /dev/ttyPTI1 to modem debugging data to write to PTI HW.
+    This is where n_tracerouter and n_tracesink are used.
+   *Hook /dev/pti to a user-level debugging application for writing
+    to PTI HW.
+   *Use mipi_* Kernel Driver API in other device drivers for
+    debugging to PTI by first requesting a PTI write address via
+    mipi_request_masterchannel(1).
+
+Below is example pseudo-code on how a 'privileged' application
+can hook up n_tracerouter and n_tracesink to any tty on
+a system.  'Privileged' means the application has enough
+privileges to successfully manipulate the ldisc drivers
+but is not just blindly executing as 'root'. Keep in mind
+the use of ioctl(,TIOCSETD,) is not specific to the n_tracerouter
+and n_tracesink line discpline drivers but is a generic
+operation for a program to use a line discpline driver
+on a tty port other than the default n_tty.
+
+/////////// To hook up n_tracerouter and n_tracesink /////////
+
+// Note that n_tracerouter depends on n_tracesink.
+#include <errno.h>
+#define ONE_TTY "/dev/ttyOne"
+#define TWO_TTY "/dev/ttyTwo"
+
+// needed global to hand onto ldisc connection
+static int g_fd_source = -1;
+static int g_fd_sink  = -1;
+
+// these two vars used to grab LDISC values from loaded ldisc drivers
+// in OS.  Look at /proc/tty/ldiscs to get the right numbers from
+// the ldiscs loaded in the system.
+int source_ldisc_num, sink_ldisc_num = -1;
+int retval;
+
+g_fd_source = open(ONE_TTY, O_RDWR); // must be R/W
+g_fd_sink   = open(TWO_TTY, O_RDWR); // must be R/W
+
+if (g_fd_source <= 0) || (g_fd_sink <= 0) {
+   // doubt you'll want to use these exact error lines of code
+   printf("Error on open(). errno: %d\n",errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_sink, TIOCSETD, &sink_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_source, TIOCSETD, &source_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+/////////// To disconnect n_tracerouter and n_tracesink ////////
+
+// First make sure data through the ldiscs has stopped.
+
+// Second, disconnect ldiscs.  This provides a
+// little cleaner shutdown on tty stack.
+sink_ldisc_num = 0;
+source_ldisc_num = 0;
+ioctl(g_fd_uart, TIOCSETD, &sink_ldisc_num);
+ioctl(g_fd_gadget, TIOCSETD, &source_ldisc_num);
+
+// Three, program closes connection, and cleanup:
+close(g_fd_uart);
+close(g_fd_gadget);
+g_fd_uart = g_fd_gadget = NULL;
-- 
1.7.2.3


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

* [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (24 preceding siblings ...)
  2011-04-22 23:32 ` [PATCH 2/4] Kernel documentation for the PTI feature james_p_freyensee
@ 2011-04-22 23:32 ` james_p_freyensee
  2011-04-24  0:55   ` Jesper Juhl
  2011-04-22 23:32 ` [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions james_p_freyensee
                   ` (15 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-04-22 23:32 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

The PTI (Parallel Trace Interface) driver directs
trace data routed from various parts in the system out
through an Intel Penwell PTI port and out of the mobile
device for analysis with a debugging tool (Lauterbach or Fido).
Though n_tracesink and n_tracerouter line discipline drivers
are used to extract modem tracing data to the PTI driver
and other parts of an Intel mobile solution, the PTI driver
can be used independent of n_tracesink and n_tracerouter.

You should select this driver if the target kernel is meant for
an Intel Atom (non-netbook) mobile device containing a MIPI
P1149.7 standard implementation.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/Kconfig  |   13 +
 drivers/misc/Makefile |    1 +
 drivers/misc/pti.c    |  994 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pti.h   |   42 ++
 4 files changed, 1050 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pti.c
 create mode 100644 include/linux/pti.h

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4e007c6..e87babd 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -144,6 +144,19 @@ config PHANTOM
 	  If you choose to build module, its name will be phantom. If unsure,
 	  say N here.
 
+config INTEL_MID_PTI
+	tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
+	default n
+	help
+	  The PTI (Parallel Trace Interface) driver directs
+	  trace data routed from various parts in the system out
+	  through an Intel Penwell PTI port and out of the mobile
+	  device for analysis with a debugging tool (Lauterbach or Fido).
+
+	  You should select this driver if the target kernel is meant for
+	  an Intel Atom (non-netbook) mobile device containing a MIPI
+	  P1149.7 standard implementation.
+
 config SGI_IOC4
 	tristate "SGI IOC4 Base IO support"
 	depends on PCI
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index f546860..662aa3c 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_IBM_ASM)		+= ibmasm/
 obj-$(CONFIG_AD525X_DPOT)	+= ad525x_dpot.o
 obj-$(CONFIG_AD525X_DPOT_I2C)	+= ad525x_dpot-i2c.o
 obj-$(CONFIG_AD525X_DPOT_SPI)	+= ad525x_dpot-spi.o
+0bj-$(CONFIG_INTEL_MID_PTI)	+= pti.o
 obj-$(CONFIG_ATMEL_PWM)		+= atmel_pwm.o
 obj-$(CONFIG_ATMEL_SSC)		+= atmel-ssc.o
 obj-$(CONFIG_ATMEL_TCLIB)	+= atmel_tclib.o
diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
new file mode 100644
index 0000000..061c3a2
--- /dev/null
+++ b/drivers/misc/pti.c
@@ -0,0 +1,994 @@
+/*
+ *  pti.c - PTI driver for cJTAG data extration
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ */
+
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/console.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/pci.h>
+#include <linux/mutex.h>
+#include <linux/miscdevice.h>
+#include <linux/pti.h>
+
+#define DRIVERNAME		"pti"
+#define PCINAME			"pciPTI"
+#define TTYNAME			"ttyPTI"
+#define CHARNAME		"pti"
+#define PTITTY_MINOR_START	0
+#define PTITTY_MINOR_NUM	2
+#define MAX_APP_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_OS_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_MODEM_IDS		16   /* 128 channel ids / u8 bit size */
+#define MODEM_BASE_ID		71   /* modem master ID address    */
+#define CONTROL_ID		72   /* control master ID address  */
+#define CONSOLE_ID		73   /* console master ID address  */
+#define OS_BASE_ID		74   /* base OS master ID address  */
+#define APP_BASE_ID		80   /* base App master ID address */
+#define CONTROL_FRAME_LEN	32   /* PTI control frame maximum size */
+#define USER_COPY_SIZE		8192 /* 8Kb buffer for user space copy */
+#define APERTURE_14		0x3800000 /* offset to first OS write addr */
+#define APERTURE_LEN		0x400000  /* address length */
+
+struct pti_tty {
+	struct pti_masterchannel *mc;
+};
+
+struct pti_dev {
+	struct tty_port port;
+	unsigned long pti_addr;
+	unsigned long aperture_base;
+	void __iomem *pti_ioaddr;
+	u8 ia_app[MAX_APP_IDS];
+	u8 ia_os[MAX_OS_IDS];
+	u8 ia_modem[MAX_MODEM_IDS];
+};
+
+/*
+ * This protects access to ia_app, ia_os, and ia_modem,
+ * which keeps track of channels allocated in
+ * an aperture write id.
+ */
+static DEFINE_MUTEX(alloclock);
+
+static struct pci_device_id pci_ids[] __devinitconst = {
+		{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B) },
+		{0}
+};
+
+static struct tty_driver *pti_tty_driver;
+static struct pti_dev *drv_data;
+
+static unsigned int pti_console_channel;
+static unsigned int pti_control_channel;
+
+/**
+ *  pti_write_to_aperture()- The private write function to PTI HW.
+ *
+ *  @mc: The 'aperture'. It's part of a write address that holds
+ *       a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  Since each aperture is specified by a unique
+ *  master/channel ID, no two processes will be writing
+ *  to the same aperture at the same time so no lock is required. The
+ *  PTI-Output agent will send these out in the order that they arrived, and
+ *  thus, it will intermix these messages. The debug tool can then later
+ *  regroup the appropriate message segments together reconstituting each
+ *  message.
+ */
+static void pti_write_to_aperture(struct pti_masterchannel *mc,
+				  u8 *buf,
+				  int len)
+{
+	int dwordcnt, final, i;
+	u32 ptiword;
+	u8 *p;
+	u32 __iomem *aperture;
+
+	p = buf;
+
+	/*
+	 * calculate the aperture offset from the base using the master and
+	 * channel id's.
+	 */
+	aperture = drv_data->pti_ioaddr + (mc->master << 15)
+		+ (mc->channel << 8);
+
+	dwordcnt = len >> 2;
+	final = len - (dwordcnt << 2);	    /* final = trailing bytes    */
+	if (final == 0 && dwordcnt != 0) {  /* always need a final dword */
+		final += 4;
+		dwordcnt--;
+	}
+
+	for (i = 0; i < dwordcnt; i++) {
+		ptiword = be32_to_cpu(*(u32 *)p);
+		p += 4;
+		iowrite32(ptiword, aperture);
+	}
+
+	aperture += PTI_LASTDWORD_DTS;	/* adding DTS signals that is EOM */
+
+	ptiword = 0;
+	for (i = 0; i < final; i++)
+		ptiword |= *p++ << (24-(8*i));
+
+	iowrite32(ptiword, aperture);
+	return;
+}
+
+/**
+ *  pti_control_frame_built_and_sent()- control frame build and send function.
+ *
+ *  @mc: The master / channel structure on which the function
+ *       built a control frame.
+ *
+ *  To be able to post process the PTI contents on host side, a control frame
+ *  is added before sending any PTI content. So the host side knows on
+ *  each PTI frame the name of the thread using a dedicated master / channel.
+ *  The thread name is retrieved from the 'current' global variable.
+ *  This function builds this frame and sends it to a master ID CONTROL_ID.
+ *  The overhead is only 32 bytes since the driver only writes to HW
+ *  in 32 byte chunks.
+ */
+
+static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc)
+{
+	struct pti_masterchannel mccontrol = {.master = CONTROL_ID,
+					      .channel = 0};
+	const char *control_format = "%3d %3d %s";
+	u8 control_frame[CONTROL_FRAME_LEN];
+
+	/*
+	 * Since we access the comm member in current's task_struct,
+	 * we only need to be as large as what 'comm' in that
+	 * structure is.
+	 */
+	char comm[TASK_COMM_LEN];
+
+	if (!in_interrupt())
+		get_task_comm(comm, current);
+	else
+		strncpy(comm, "Interrupt", TASK_COMM_LEN);
+
+	/* Absolutely ensure our buffer is zero terminated. */
+	comm[TASK_COMM_LEN-1] = 0;
+
+	mccontrol.channel = pti_control_channel;
+	pti_control_channel = (pti_control_channel + 1) & 0x7f;
+
+	snprintf(control_frame, CONTROL_FRAME_LEN, control_format, mc->master,
+		mc->channel, comm);
+	pti_write_to_aperture(&mccontrol, control_frame, strlen(control_frame));
+}
+
+/**
+ *  pti_write_full_frame_to_aperture()- high level function to
+ *					write to PTI.
+ *
+ *  @mc:  The 'aperture'. It's part of a write address that holds
+ *        a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  All threads sending data (either console, user space application, ...)
+ *  are calling the high level function to write to PTI meaning that it is
+ *  possible to add a control frame before sending the content.
+ */
+static void pti_write_full_frame_to_aperture(struct pti_masterchannel *mc,
+						const unsigned char *buf,
+						int len)
+{
+	pti_control_frame_built_and_sent(mc);
+	pti_write_to_aperture(mc, (u8 *)buf, len);
+}
+
+/**
+ * get_id()- Allocate a master and channel ID.
+ *
+ * @id_array: an array of bits representing what channel
+ *            id's are allocated for writing.
+ * @max_ids:  The max amount of available write IDs to use.
+ * @base_id:  The starting SW channel ID, based on the Intel
+ *            PTI arch.
+ *
+ * Returns:
+ *	pti_masterchannel struct with master, channel ID address
+ *	0 for error
+ *
+ * Each bit in the arrays ia_app and ia_os correspond to a master and
+ * channel id. The bit is one if the id is taken and 0 if free. For
+ * every master there are 128 channel id's.
+ */
+static struct pti_masterchannel *get_id(u8 *id_array, int max_ids, int base_id)
+{
+	struct pti_masterchannel *mc;
+	int i, j, mask;
+
+	mc = kmalloc(sizeof(struct pti_masterchannel), GFP_KERNEL);
+	if (mc == NULL)
+		return NULL;
+
+	/* look for a byte with a free bit */
+	for (i = 0; i < max_ids; i++)
+		if (id_array[i] != 0xff)
+			break;
+	if (i == max_ids) {
+		kfree(mc);
+		return NULL;
+	}
+	/* find the bit in the 128 possible channel opportunities */
+	mask = 0x80;
+	for (j = 0; j < 8; j++) {
+		if ((id_array[i] & mask) == 0)
+			break;
+		mask >>= 1;
+	}
+
+	/* grab it */
+	id_array[i] |= mask;
+	mc->master  = base_id;
+	mc->channel = ((i & 0xf)<<3) + j;
+	/* write new master Id / channel Id allocation to channel control */
+	pti_control_frame_built_and_sent(mc);
+	return mc;
+}
+
+/*
+ * The following three functions:
+ * pti_request_mastercahannel(), mipi_release_masterchannel()
+ * and pti_writedata() are an API for other kernel drivers to
+ * access PTI.
+ */
+
+/**
+ * pti_request_masterchannel()- Kernel API function used to allocate
+ *				a master, channel ID address
+ *				to write to PTI HW.
+ *
+ * @type: 0- request Application  master, channel aperture ID write address.
+ *        1- request OS master, channel aperture ID write
+ *           address.
+ *        2- request Modem master, channel aperture ID
+ *           write address.
+ *        Other values, error.
+ *
+ * Returns:
+ *	pti_masterchannel struct
+ *	0 for error
+ */
+struct pti_masterchannel *pti_request_masterchannel(u8 type)
+{
+	struct pti_masterchannel *mc;
+
+	mutex_lock(&alloclock);
+
+	switch (type) {
+
+	case 0:
+		mc = get_id(drv_data->ia_app, MAX_APP_IDS, APP_BASE_ID);
+		break;
+
+	case 1:
+		mc = get_id(drv_data->ia_os, MAX_OS_IDS, OS_BASE_ID);
+		break;
+
+	case 2:
+		mc = get_id(drv_data->ia_modem, MAX_MODEM_IDS, MODEM_BASE_ID);
+		break;
+	default:
+		mc = NULL;
+	}
+
+	mutex_unlock(&alloclock);
+	return mc;
+}
+EXPORT_SYMBOL_GPL(pti_request_masterchannel);
+
+/**
+ * pti_release_masterchannel()- Kernel API function used to release
+ *				a master, channel ID address
+ *				used to write to PTI HW.
+ *
+ * @mc: master, channel apeture ID address to be released.
+ */
+void pti_release_masterchannel(struct pti_masterchannel *mc)
+{
+	u8 master, channel, i;
+
+	mutex_lock(&alloclock);
+
+	if (mc) {
+		master = mc->master;
+		channel = mc->channel;
+
+		if (master == APP_BASE_ID) {
+			i = channel >> 3;
+			drv_data->ia_app[i] &=  ~(0x80>>(channel & 0x7));
+		} else if (master == OS_BASE_ID) {
+			i = channel >> 3;
+			drv_data->ia_os[i] &= ~(0x80>>(channel & 0x7));
+		} else {
+			i = channel >> 3;
+			drv_data->ia_modem[i] &= ~(0x80>>(channel & 0x7));
+		}
+
+		kfree(mc);
+	}
+
+	mutex_unlock(&alloclock);
+}
+EXPORT_SYMBOL_GPL(pti_release_masterchannel);
+
+/**
+ * pti_writedata()- Kernel API function used to write trace
+ *                  debugging data to PTI HW.
+ *
+ * @mc:    Master, channel aperture ID address to write to.
+ *         Null value will return with no write occurring.
+ * @buf:   Trace debuging data to write to the PTI HW.
+ *         Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         return with no write occuring.
+ */
+void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
+{
+	/*
+	 * since this function is exported, this is treated like an
+	 * API function, thus, all parameters should
+	 * be checked for validity.
+	 */
+	if ((mc != NULL) && (buf != NULL) && (count > 0))
+		pti_write_to_aperture(mc, buf, count);
+	return;
+}
+EXPORT_SYMBOL_GPL(pti_writedata);
+
+/**
+ * pti_pci_remove()- Driver exit method to remove PTI from
+ *		   PCI bus.
+ * @pdev: variable containing pci info of PTI.
+ */
+static void __devexit pti_pci_remove(struct pci_dev *pdev)
+{
+	struct pti_dev *drv_data;
+
+	drv_data = pci_get_drvdata(pdev);
+	if (drv_data != NULL) {
+		pci_iounmap(pdev, drv_data->pti_ioaddr);
+		pci_set_drvdata(pdev, NULL);
+		kfree(drv_data);
+		pci_release_region(pdev, 1);
+		pci_disable_device(pdev);
+	}
+}
+
+/*
+ * for the tty_driver_*() basic function descriptions, see tty_driver.h.
+ * Specific header comments made for PTI-related specifics.
+ */
+
+/**
+ * pti_tty_driver_open()- Open an Application master, channel aperture
+ * ID to the PTI device via tty device.
+ *
+ * @tty: tty interface.
+ * @filp: filp interface pased to tty_port_open() call.
+ *
+ * Returns:
+ *	int, 0 for success
+ *	otherwise, fail value
+ *
+ * The main purpose of using the tty device interface is for
+ * each tty port to have a unique PTI write aperture.  In an
+ * example use case, ttyPTI0 gets syslogd and an APP aperture
+ * ID and ttyPTI1 is where the n_tracesink ldisc hooks to route
+ * modem messages into PTI.  Modem trace data does not have to
+ * go to ttyPTI1, but ttyPTI0 and ttyPTI1 do need to be distinct
+ * master IDs.  These messages go through the PTI HW and out of
+ * the handheld platform and to the Fido/Lauterbach device.
+ */
+static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
+{
+	int ret = 0;
+
+	/*
+	 * we actually want to allocate a new channel per open, per
+	 * system arch.  HW gives more than plenty channels for a single
+	 * system task to have its own channel to write trace data. This
+	 * also removes a locking requirement for the actual write
+	 * procedure.
+	 */
+	ret = tty_port_open(&drv_data->port, tty, filp);
+
+	return ret;
+}
+
+/**
+ * pti_tty_driver_close()- close tty device and release Application
+ * master, channel aperture ID to the PTI device via tty device.
+ *
+ * @tty: tty interface.
+ * @filp: filp interface pased to tty_port_close() call.
+ *
+ * The main purpose of using the tty device interface is to route
+ * syslog daemon messages to the PTI HW and out of the handheld platform
+ * and to the Fido/Lauterbach device.
+ */
+static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
+{
+	tty_port_close(&drv_data->port, tty, filp);
+
+	return;
+}
+
+/**
+ * pti_tty_intstall()- Used to set up specific master-channels
+ *		       to tty ports for organizational purposes when
+ *		       tracing viewed from debuging tools.
+ *
+ * @driver: tty driver information.
+ * @tty: tty struct containing pti information.
+ *
+ * Returns:
+ *	0 for success
+ *	otherwise, error
+ */
+static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
+{
+	int idx = tty->index;
+	struct pti_tty *pti_tty_data;
+	struct pti_masterchannel *mc;
+	int ret = tty_init_termios(tty);
+
+	if (ret == 0) {
+		tty_driver_kref_get(driver);
+		tty->count++;
+		driver->ttys[idx] = tty;
+
+		pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL);
+		if (pti_tty_data == NULL)
+			return -ENOMEM;
+
+		tty->driver_data = pti_tty_data;
+
+		if (idx == PTITTY_MINOR_START)
+			mc = pti_request_masterchannel(0);
+		else
+			mc = pti_request_masterchannel(2);
+
+		if (mc == NULL)
+			return -ENXIO;
+
+		pti_tty_data->mc = mc;
+	}
+
+	return ret;
+}
+
+/**
+ * pti_tty_cleanup()- Used to de-allocate master-channel resources
+ *		      tied to tty's of this driver.
+ *
+ * @tty: tty struct containing pti information.
+ */
+static void pti_tty_cleanup(struct tty_struct *tty)
+{
+	struct pti_tty *pti_tty_data;
+	struct pti_masterchannel *mc;
+
+	pti_tty_data = tty->driver_data;
+
+	if (pti_tty_data != NULL) {
+		mc = pti_tty_data->mc;
+		pti_release_masterchannel(mc);
+		pti_tty_data->mc = NULL;
+	}
+
+	if (pti_tty_data != NULL)
+		kfree(pti_tty_data);
+
+	tty->driver_data = NULL;
+}
+
+/**
+ * pti_tty_driver_write()-  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @filp: Contains private data which is used to obtain
+ *        master, channel write ID.
+ * @data: trace data to be written.
+ * @len:  # of byte to write.
+ *
+ * Returns:
+ *	int, # of bytes written
+ *	otherwise, error
+ */
+static int pti_tty_driver_write(struct tty_struct *tty,
+	const unsigned char *buf, int len)
+{
+	struct pti_masterchannel *mc;
+	struct pti_tty *pti_tty_data;
+
+	pti_tty_data = tty->driver_data;
+	mc = pti_tty_data->mc;
+	pti_write_to_aperture(mc, (u8 *)buf, len);
+
+	return len;
+}
+
+/**
+ * pti_tty_write_room()- Always returns 2048.
+ *
+ * @tty: contains tty info of the pti driver.
+ */
+static int pti_tty_write_room(struct tty_struct *tty)
+{
+	return 2048;
+}
+
+/**
+ * pti_char_open()- Open an Application master, channel aperture
+ * ID to the PTI device. Part of the misc device implementation.
+ *
+ * @inode: not used.
+ * @filp:  Output- will have a masterchannel struct set containing
+ *                 the allocated application PTI aperture write address.
+ *
+ * Returns:
+ *	int, 0 for success
+ *	otherwise, a fail value
+ */
+static int pti_char_open(struct inode *inode, struct file *filp)
+{
+	struct pti_masterchannel *mc;
+
+	mc = pti_request_masterchannel(0);
+	if (mc == NULL)
+		return -ENOMEM;
+	filp->private_data = mc;
+	return 0;
+}
+
+/**
+ * pti_char_release()-  Close a char channel to the PTI device. Part
+ * of the misc device implementation.
+ *
+ * @inode: Not used in this implementaiton.
+ * @filp:  Contains private_data that contains the master, channel
+ *         ID to be released by the PTI device.
+ *
+ * Returns:
+ *	always 0
+ */
+static int pti_char_release(struct inode *inode, struct file *filp)
+{
+	pti_release_masterchannel(filp->private_data);
+	return 0;
+}
+
+/**
+ * pti_char_write()-  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @filp:  Contains private data which is used to obtain
+ *         master, channel write ID.
+ * @data:  trace data to be written.
+ * @len:   # of byte to write.
+ * @ppose: Not used in this function implementation.
+ *
+ * Returns:
+ *	int, # of bytes written
+ *	otherwise, error value
+ *
+ * Notes: From side discussions with Alan Cox and experimenting
+ * with PTI debug HW like Nokia's Fido box and Lauterbach
+ * devices, 8192 byte write buffer used by USER_COPY_SIZE was
+ * deemed an appropriate size for this type of usage with
+ * debugging HW.
+ */
+static ssize_t pti_char_write(struct file *filp, const char __user *data,
+			      size_t len, loff_t *ppose)
+{
+	struct pti_masterchannel *mc;
+	void *kbuf;
+	const char __user *tmp;
+	size_t size = USER_COPY_SIZE, n = 0;
+
+	tmp = data;
+	mc = filp->private_data;
+
+	kbuf = kmalloc(size, GFP_KERNEL);
+	if (kbuf == NULL)  {
+		pr_err("%s(%d): buf allocation failed\n",
+			__func__, __LINE__);
+		return 0;
+	}
+
+	do {
+		if (len - n > USER_COPY_SIZE)
+			size = USER_COPY_SIZE;
+		else
+			size = len - n;
+
+		if (copy_from_user(kbuf, tmp, size)) {
+			kfree(kbuf);
+			return n ? n : -EFAULT;
+		}
+
+		pti_write_to_aperture(mc, kbuf, size);
+		n  += size;
+		tmp += size;
+
+	} while (len > n);
+
+	kfree(kbuf);
+	kbuf = NULL;
+
+	return len;
+}
+
+static const struct tty_operations pti_tty_driver_ops = {
+	.open		= pti_tty_driver_open,
+	.close		= pti_tty_driver_close,
+	.write		= pti_tty_driver_write,
+	.write_room	= pti_tty_write_room,
+	.install	= pti_tty_install,
+	.cleanup	= pti_tty_cleanup
+};
+
+static const struct file_operations pti_char_driver_ops = {
+	.owner		= THIS_MODULE,
+	.write		= pti_char_write,
+	.open		= pti_char_open,
+	.release	= pti_char_release,
+};
+
+static struct miscdevice pti_char_driver = {
+	.minor		= MISC_DYNAMIC_MINOR,
+	.name		= CHARNAME,
+	.fops		= &pti_char_driver_ops
+};
+
+/**
+ * pti_char_release()-  Close a char channel to the PTI device. Part
+ * of the misc device implementation.
+ *
+ * @inode: Not used in this implementaiton.
+ * @filp:  Contains private_data that contains the master, channel
+ *         ID to be released by the PTI device.
+ *
+ * Returns:
+ *	always 0
+ */
+static void pti_console_write(struct console *c, const char *buf, unsigned len)
+{
+	static struct pti_masterchannel mc = {.master  = CONSOLE_ID,
+					      .channel = 0};
+
+	mc.channel = pti_console_channel;
+	pti_console_channel = (pti_console_channel + 1) & 0x7f;
+
+	pti_write_full_frame_to_aperture(&mc, buf, len);
+}
+
+/**
+ * pti_console_device()-  Return the driver tty structure and set the
+ *			  associated index implementation.
+ *
+ * @c:     Console device of the driver.
+ * @index: index associated with c.
+ *
+ * Returns:
+ *	always value of pti_tty_driver structure when this function
+ *	is called.
+ */
+static struct tty_driver *pti_console_device(struct console *c, int *index)
+{
+	*index = c->index;
+	return pti_tty_driver;
+}
+
+/**
+ * pti_console_setup()-  Initialize console variables used by the driver.
+ *
+ * @c:     Not used.
+ * @opts:  Not used.
+ *
+ * Returns:
+ *	always 0.
+ */
+static int pti_console_setup(struct console *c, char *opts)
+{
+	pti_console_channel = 0;
+	pti_control_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,
+	.index		= 0,
+};
+
+/**
+ * pti_port_activate()- Used to start/initialize any items upon
+ * first opening of tty_port().
+ *
+ * @port- The tty port number of the PTI device.
+ * @tty-  The tty struct associated with this device.
+ *
+ * Returns:
+ *	always returns 0
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static int pti_port_activate(struct tty_port *port, struct tty_struct *tty)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		console_start(&pti_console);
+	return 0;
+}
+
+/**
+ * pti_port_shutdown()- Used to stop/shutdown any items upon the
+ * last tty port close.
+ *
+ * @port- The tty port number of the PTI device.
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static void pti_port_shutdown(struct tty_port *port)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		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.
+ */
+
+/**
+ * pti_pci_probe()- Used to detect pti on the pci bus and set
+ *		    things up in the driver.
+ *
+ * @pdev- pci_dev struct values for pti.
+ * @ent-  pci_device_id struct for pti driver.
+ *
+ * Returns:
+ *	0 for success
+ *	otherwise, error
+ */
+static int __devinit pti_pci_probe(struct pci_dev *pdev,
+		const struct pci_device_id *ent)
+{
+	int retval = -EINVAL;
+	int pci_bar = 1;
+
+	dev_dbg(&pdev->dev, "%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__,
+			__func__, __LINE__, pdev->vendor, pdev->device);
+
+	retval = misc_register(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+		return retval;
+	}
+
+	retval = pci_enable_device(pdev);
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s: pci_enable_device() returned error %d\n",
+			__func__, retval);
+		return retval;
+	}
+
+	drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
+
+	if (drv_data == NULL) {
+		retval = -ENOMEM;
+		dev_err(&pdev->dev,
+			"%s(%d): kmalloc() returned NULL memory.\n",
+			__func__, __LINE__);
+		return retval;
+	}
+	drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
+
+	retval = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev));
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s(%d): pci_request_region() returned error %d\n",
+			__func__, __LINE__, retval);
+		kfree(drv_data);
+		return retval;
+	}
+	drv_data->aperture_base = drv_data->pti_addr+APERTURE_14;
+	drv_data->pti_ioaddr =
+		ioremap_nocache((u32)drv_data->aperture_base,
+		APERTURE_LEN);
+	if (!drv_data->pti_ioaddr) {
+		pci_release_region(pdev, pci_bar);
+		retval = -ENOMEM;
+		kfree(drv_data);
+		return retval;
+	}
+
+	pci_set_drvdata(pdev, drv_data);
+
+	tty_port_init(&drv_data->port);
+	drv_data->port.ops = &tty_port_ops;
+
+	tty_register_device(pti_tty_driver, 0, &pdev->dev);
+	tty_register_device(pti_tty_driver, 1, &pdev->dev);
+
+	register_console(&pti_console);
+
+	return retval;
+}
+
+static struct pci_driver pti_pci_driver = {
+	.name		= PCINAME,
+	.id_table	= pci_ids,
+	.probe		= pti_pci_probe,
+	.remove		= pti_pci_remove,
+};
+
+/**
+ *
+ * pti_init()- Overall entry/init call to the pti driver.
+ *             It starts the registration process with the kernel.
+ *
+ * Returns:
+ *	int __init, 0 for success
+ *	otherwise value is an error
+ *
+ */
+static int __init pti_init(void)
+{
+	int retval = -EINVAL;
+
+	/* First register module as tty device */
+
+	pti_tty_driver = alloc_tty_driver(1);
+	if (pti_tty_driver == NULL) {
+		pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n",
+			__func__, __LINE__);
+		return -ENOMEM;
+	}
+
+	pti_tty_driver->owner			= THIS_MODULE;
+	pti_tty_driver->magic			= TTY_DRIVER_MAGIC;
+	pti_tty_driver->driver_name		= DRIVERNAME;
+	pti_tty_driver->name			= TTYNAME;
+	pti_tty_driver->major			= 0;
+	pti_tty_driver->minor_start		= PTITTY_MINOR_START;
+	pti_tty_driver->minor_num		= PTITTY_MINOR_NUM;
+	pti_tty_driver->num			= PTITTY_MINOR_NUM;
+	pti_tty_driver->type			= TTY_DRIVER_TYPE_SYSTEM;
+	pti_tty_driver->subtype			= SYSTEM_TYPE_SYSCONS;
+	pti_tty_driver->flags			= TTY_DRIVER_REAL_RAW |
+						  TTY_DRIVER_DYNAMIC_DEV;
+	pti_tty_driver->init_termios		= tty_std_termios;
+
+	tty_set_operations(pti_tty_driver, &pti_tty_driver_ops);
+
+	retval = tty_register_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	retval = pci_register_driver(&pti_pci_driver);
+
+	if (retval) {
+		pr_err("%s(%d): PCI registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		tty_unregister_driver(pti_tty_driver);
+		pr_err("%s(%d): Unregistering TTY part of pti driver\n",
+			__func__, __LINE__);
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	return retval;
+}
+
+/**
+ * pti_exit()- Unregisters this module as a tty and pci driver.
+ */
+static void __exit pti_exit(void)
+{
+	int retval;
+
+	tty_unregister_device(pti_tty_driver, 0);
+	tty_unregister_device(pti_tty_driver, 1);
+
+	retval = tty_unregister_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	pci_unregister_driver(&pti_pci_driver);
+
+	retval = misc_deregister(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	unregister_console(&pti_console);
+	return;
+}
+
+module_init(pti_init);
+module_exit(pti_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ken Mills, Jay Freyensee");
+MODULE_DESCRIPTION("PTI Driver");
+
diff --git a/include/linux/pti.h b/include/linux/pti.h
new file mode 100644
index 0000000..81af667
--- /dev/null
+++ b/include/linux/pti.h
@@ -0,0 +1,42 @@
+/*
+ *  Copyright (C) Intel 2011
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ *
+ * This header file will allow other parts of the OS to use the
+ * interface to write out it's contents for debugging a mobile system.
+ */
+
+#ifndef PTI_H_
+#define PTI_H_
+
+/* offset for last dword of any PTI message. Part of MIPI P1149.7 */
+#define PTI_LASTDWORD_DTS	0x30
+
+/* basic structure used as a write address to the PTI HW */
+struct pti_masterchannel {
+	u8 master;
+	u8 channel;
+};
+
+/* the following functions are defined in misc/pti.c */
+void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count);
+struct pti_masterchannel *pti_request_masterchannel(u8 type);
+void pti_release_masterchannel(struct pti_masterchannel *mc);
+
+#endif /*PTI_H_*/
-- 
1.7.2.3


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

* [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (25 preceding siblings ...)
  2011-04-22 23:32 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
@ 2011-04-22 23:32 ` james_p_freyensee
  2011-04-24  1:04   ` Jesper Juhl
  2011-05-06 23:56 ` Request for review and addition of PTI implementation into kernel james_p_freyensee
                   ` (14 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-04-22 23:32 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, james_p_freyensee, christophe.guerard

From: J Freyensee <james_p_freyensee@linux.intel.com>

The n_tracerouter and n_tracesink line discpline drivers use the
Linux tty line discpline framework to route trace data coming
from a tty port (say UART for example) to the trace sink line
discipline driver and to another tty port(say USB).  Those
these two line discipline drivers can be used together,
independently from pti.c, they are part of the original
implementation solution of the MIPI P1149.7, compact JTAG, PTI
solution for Intel mobile platforms starting with the
Medfield platform.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/Kconfig         |   31 ++++++
 drivers/tty/Makefile        |    2 +
 drivers/tty/n_tracerouter.c |  243 ++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/n_tracesink.c   |  246 +++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/n_tracesink.h   |   36 +++++++
 include/linux/tty.h         |    2 +
 6 files changed, 560 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/n_tracerouter.c
 create mode 100644 drivers/tty/n_tracesink.c
 create mode 100644 drivers/tty/n_tracesink.h

diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 3fd7199..2e5f2f2 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -319,3 +319,34 @@ config N_GSM
 	  This line discipline provides support for the GSM MUX protocol and
 	  presents the mux as a set of 61 individual tty devices.
 
+config TRACE_ROUTER
+	tristate "Trace data router for MIPI P1149.7 cJTAG standard"
+	depends on TRACE_SINK
+	default n
+	help
+	  The trace router uses the Linux tty line discipline framework to
+	  route trace data coming from a tty port (say UART for example) to
+	  the trace sink line discipline driver and to another tty port(say 
+	  USB). This is part of a solution for the MIPI P1149.7, compact JTAG,
+	  standard, which is for debugging mobile devices. The PTI driver in
+	  drivers/misc/pti.c defines the majority of this MIPI solution.
+
+	  You should select this driver if the target kernel is meant for
+	  a mobile device containing a modem.  Then you will need to select
+	  "Trace data sink for MIPI P1149.7 cJTAG standard" line discipline
+	  driver.
+
+config TRACE_SINK
+	tristate "Trace data sink for MIPI P1149.7 cJTAG standard"
+	default n
+	help
+	  The trace sink uses the Linux line discipline framework to receive
+	  trace data coming from the trace router line discipline driver
+	  to a user-defined tty port target, like USB.
+	  This is to provide a way to extract modem trace data on
+	  devices that do not have a PTI HW module, or just need modem
+	  trace data to come out of a different HW output port.
+	  This is part of a solution for the P1149.7, compact JTAG, standard.
+
+	  If you select this option, you need to select
+	  "Trace data router for MIPI P1149.7 cJTAG standard".
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index 690522f..ea89b0b 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -6,6 +6,8 @@ obj-$(CONFIG_AUDIT)		+= tty_audit.o
 obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
 obj-$(CONFIG_N_HDLC)		+= n_hdlc.o
 obj-$(CONFIG_N_GSM)		+= n_gsm.o
+obj-$(CONFIG_TRACE_ROUTER)	+= n_tracerouter.o
+obj-$(CONFIG_TRACE_SINK)	+= n_tracesink.o
 obj-$(CONFIG_R3964)		+= n_r3964.o
 
 obj-y				+= vt/
diff --git a/drivers/tty/n_tracerouter.c b/drivers/tty/n_tracerouter.c
new file mode 100644
index 0000000..94f330a
--- /dev/null
+++ b/drivers/tty/n_tracerouter.c
@@ -0,0 +1,243 @@
+/*
+ *  n_tracerouter.c - Trace data router through tty space
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This trace router uses the Linux line discipline framework to route
+ * trace data coming from a HW Modem to a PTI (Parallel Trace Module) port.
+ * The solution is not specific to a HW modem and this line disciple can
+ * be used to route any stream of data in kernel space.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <asm-generic/bug.h>
+#include "n_tracesink.h"
+
+/*
+ * Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracerouter"
+
+/*
+ * struct to hold private configuration data for this ldisc.
+ * opencalled is used to hold if this ldisc has been opened.
+ * kref_tty holds the tty reference the ldisc sits on top of.
+ */
+struct tracerouter_data {
+	u8 opencalled;
+	struct tty_struct *kref_tty;
+};
+static struct tracerouter_data *tr_data;
+
+/* lock for when tty reference is being used */
+static DEFINE_MUTEX(routelock);
+
+/**
+ * n_tracerouter_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success.
+ *
+ * Caveats: This should only be opened one time per SW entity.
+ */
+static int n_tracerouter_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&routelock);
+	if (tr_data->opencalled == 0) {
+
+		tr_data->kref_tty = tty_kref_get(tty);
+		if (tr_data->kref_tty == NULL) {
+			retval = -EFAULT;
+		} else {
+			tr_data->opencalled = 1;
+			tty->disc_data      = tr_data;
+			tty->receive_room   = RECEIVE_ROOM;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&routelock);
+	return retval;
+}
+
+/**
+ * n_tracerouter_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracerouter_close(struct tty_struct *tty)
+{
+	struct tracerouter_data *tptr = tty->disc_data;
+
+	mutex_lock(&routelock);
+	WARN_ON(tptr->kref_tty != tr_data->kref_tty);
+	tty_driver_flush_buffer(tty);
+	tty_kref_put(tr_data->kref_tty);
+	tr_data->kref_tty = NULL;
+	tr_data->opencalled = 0;
+	tty->disc_data = NULL;
+	mutex_unlock(&routelock);
+}
+
+/**
+ * n_tracerouter_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracerouter_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracerouter_read(struct tty_struct *tty, struct file *file,
+				  unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracerouter_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracerouter_write(struct tty_struct *tty, struct file *file,
+				   const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_receivebuf() - Routing function for driver.
+ * @tty: terminal device passed into the ldisc.  It's assumed
+ *       tty will never be NULL.
+ * @cp:  buffer, block of characters to be eventually read by
+ *       someone, somewhere (user read() call or some kernel function).
+ * @fp:  flag buffer.
+ * @count: number of characters (aka, bytes) in cp.
+ *
+ * This function takes the input buffer, cp, and passes it to
+ * an external API function for processing.
+ */
+static void n_tracerouter_receivebuf(struct tty_struct *tty,
+					const unsigned char *cp,
+					char *fp, int count)
+{
+	mutex_lock(&routelock);
+	n_tracesink_datadrain((u8 *) cp, count);
+	mutex_unlock(&routelock);
+}
+
+/*
+ * Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+static struct tty_ldisc_ops tty_ptirouter_ldisc = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracerouter_open,
+	.close		= n_tracerouter_close,
+	.read		= n_tracerouter_read,
+	.write		= n_tracerouter_write,
+	.receive_buf	= n_tracerouter_receivebuf
+};
+
+/**
+ * n_tracerouter_init		-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracerouter_init(void)
+{
+	int retval;
+
+	tr_data = kzalloc(sizeof(struct tracerouter_data), GFP_KERNEL);
+	if (tr_data == NULL)
+		return -ENOMEM;
+
+
+	/* Note N_TRACEROUTER is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACEROUTER, &tty_ptirouter_ldisc);
+	if (retval < 0) {
+		pr_err("%s: Registration failed: %d\n", __func__, retval);
+		kfree(tr_data);
+	}
+	return retval;
+}
+
+/**
+ * n_tracerouter_exit -	-	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracerouter_exit(void)
+{
+	int retval;
+
+	kfree(tr_data);
+	retval = tty_unregister_ldisc(N_TRACEROUTER);
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
+}
+
+module_init(n_tracerouter_init);
+module_exit(n_tracerouter_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACEROUTER);
+MODULE_DESCRIPTION("Trace router ldisc driver");
diff --git a/drivers/tty/n_tracesink.c b/drivers/tty/n_tracesink.c
new file mode 100644
index 0000000..c4e6c0f
--- /dev/null
+++ b/drivers/tty/n_tracesink.c
@@ -0,0 +1,246 @@
+/*
+ *  n_tracesink.c - Trace data router and sink path through tty space.
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The trace sink uses the Linux line discipline framework to receive
+ * trace data coming from the PTI source line discipline driver
+ * to a user-desired tty port, like USB.
+ * This is to provide a way to extract modem trace data on
+ * devices that do not have a PTI HW module, or just need modem
+ * trace data to come out of a different HW output port.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <asm-generic/bug.h>
+#include "n_tracesink.h"
+
+/*
+ * Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracesink"
+
+/*
+ * there is a quirk with this ldisc is he can write data
+ * to a tty from anyone calling his kernel API, which
+ * meets customer requirements in the drivers/misc/pti.c
+ * project.  So he needs to know when he can and cannot write when
+ * the API is called. In theory, the API can be called
+ * after an init() but before a successful open() which
+ * would crash the system if tty is not checked.
+ */
+static struct tty_struct *this_tty;
+static DEFINE_MUTEX(writelock);
+
+/**
+ * n_tracesink_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success,
+ *      -EFAULT = couldn't get a tty kref n_tracesink will sit
+ *       on top of
+ *      -EEXIST = open() called successfully once and it cannot
+ *      be called again.
+ *
+ * Caveats: open() should only be successful the first time a
+ * SW entity calls it.
+ */
+static int n_tracesink_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&writelock);
+	if (this_tty == NULL) {
+
+		this_tty = tty_kref_get(tty);
+
+		if (this_tty == NULL)
+			retval = -EFAULT;
+		else {
+			tty->disc_data = this_tty;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&writelock);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracesink_close(struct tty_struct *tty)
+{
+
+	mutex_lock(&writelock);
+	tty_driver_flush_buffer(tty);
+	tty_kref_put(this_tty);
+	this_tty = NULL;
+	tty->disc_data = NULL;
+	mutex_unlock(&writelock);
+
+}
+
+/**
+ * n_tracesink_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracesink_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracesink_read(struct tty_struct *tty, struct file *file,
+				unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracesink_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracesink_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracesink_write(struct tty_struct *tty, struct file *file,
+				 const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracesink_datadrain() - Kernel API function used to route
+ *			     trace debugging data to user-defined
+ *			     port like USB.
+ *
+ * @buf:   Trace debuging data buffer to write to tty target
+ *         port. Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         return with no write occuring.
+ *
+ * Caveat: If this line discipline does not set the tty it sits
+ * on top of via an open() call, this API function will not
+ * call the tty's write() call because it will have no pointer
+ * to call the write().
+ */
+void n_tracesink_datadrain(u8 *buf, int count)
+{
+	mutex_lock(&writelock);
+
+	if ((buf != NULL) && (count > 0) && (this_tty != NULL))
+		this_tty->ops->write(this_tty, buf, count);
+
+	mutex_unlock(&writelock);
+}
+EXPORT_SYMBOL_GPL(n_tracesink_datadrain);
+
+/*
+ * Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+/*
+ * tty_ldisc function operations for this driver.
+ */
+static struct tty_ldisc_ops tty_n_tracesink = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracesink_open,
+	.close		= n_tracesink_close,
+	.read		= n_tracesink_read,
+	.write		= n_tracesink_write
+};
+
+/**
+ * n_tracesink_init-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracesink_init(void)
+{
+	int retval;
+
+	/* Note N_TRACESINK is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
+
+	if (retval < 0)
+		pr_err("%s: Registration failed: %d\n", __func__, retval);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_exit -	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracesink_exit(void)
+{
+	int retval;
+
+	retval = tty_unregister_ldisc(N_TRACESINK);
+
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
+}
+
+module_init(n_tracesink_init);
+module_exit(n_tracesink_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACESINK);
+MODULE_DESCRIPTION("Trace sink ldisc driver");
diff --git a/drivers/tty/n_tracesink.h b/drivers/tty/n_tracesink.h
new file mode 100644
index 0000000..a68bb44
--- /dev/null
+++ b/drivers/tty/n_tracesink.h
@@ -0,0 +1,36 @@
+/*
+ *  n_tracesink.h - Kernel driver API to route trace data in kernel space.
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ *
+ * This header file is used by n_tracerouter to be able to send the
+ * data of it's tty port to the tty port this module sits.  This
+ * mechanism can also be used independent of the PTI module.
+ *
+ */
+
+#ifndef N_TRACESINK_H_
+#define N_TRACESINK_H_
+
+void n_tracesink_datadrain(u8 *buf, int count);
+
+#endif
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 9f469c7..fbf17de 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -50,6 +50,8 @@
 #define N_CAIF		20      /* CAIF protocol for talking to modems */
 #define N_GSM0710	21	/* GSM 0710 Mux */
 #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
+#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
+#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
-- 
1.7.2.3


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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-22 23:32 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
@ 2011-04-24  0:55   ` Jesper Juhl
  2011-04-24  1:08     ` Jesper Juhl
  2011-05-05 17:27     ` J Freyensee
  0 siblings, 2 replies; 171+ messages in thread
From: Jesper Juhl @ 2011-04-24  0:55 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, 22 Apr 2011, james_p_freyensee@linux.intel.com wrote:

> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> The PTI (Parallel Trace Interface) driver directs
> trace data routed from various parts in the system out
> through an Intel Penwell PTI port and out of the mobile
> device for analysis with a debugging tool (Lauterbach or Fido).
> Though n_tracesink and n_tracerouter line discipline drivers
> are used to extract modem tracing data to the PTI driver
> and other parts of an Intel mobile solution, the PTI driver
> can be used independent of n_tracesink and n_tracerouter.
> 
> You should select this driver if the target kernel is meant for
> an Intel Atom (non-netbook) mobile device containing a MIPI
> P1149.7 standard implementation.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>

A few comments below.

...
> +#define DRIVERNAME		"pti"
> +#define PCINAME			"pciPTI"
> +#define TTYNAME			"ttyPTI"
> +#define CHARNAME		"pti"
> +#define PTITTY_MINOR_START	0
> +#define PTITTY_MINOR_NUM	2
> +#define MAX_APP_IDS		16   /* 128 channel ids / u8 bit size */
> +#define MAX_OS_IDS		16   /* 128 channel ids / u8 bit size */
> +#define MAX_MODEM_IDS		16   /* 128 channel ids / u8 bit size */
> +#define MODEM_BASE_ID		71   /* modem master ID address    */
...

Would be nice if the values of these defines would line up nicely.


...
> +static struct pci_device_id pci_ids[] __devinitconst = {
> +		{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B) },
> +		{0}
...

Why are there spaces after the opening { and before the closing } for the 
first entry, but not the second. Looks like you need to pick a 
consistent style.


> + *  regroup the appropriate message segments together reconstituting each
> + *  message.
> + */
> +static void pti_write_to_aperture(struct pti_masterchannel *mc,
> +				  u8 *buf,
> +				  int len)
> +{
> +	int dwordcnt, final, i;
> +	u32 ptiword;
> +	u8 *p;
> +	u32 __iomem *aperture;
> +
> +	p = buf;
...

Perhaps save a few lines by doing

static void pti_write_to_aperture(struct pti_masterchannel *mc,
                               u8 *buf,
                               int len)
{
     int dwordcnt, final, i;
     u32 ptiword;
     u32 __iomem *aperture;
     u8 *p = buf;


...
> +void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
> +{
> +	/*
> +	 * since this function is exported, this is treated like an
> +	 * API function, thus, all parameters should
> +	 * be checked for validity.
> +	 */
> +	if ((mc != NULL) && (buf != NULL) && (count > 0))
> +		pti_write_to_aperture(mc, buf, count);
> +	return;
...

Pointless return; statement.


...
> +static void __devexit pti_pci_remove(struct pci_dev *pdev)
> +{
> +	struct pti_dev *drv_data;
> +
> +	drv_data = pci_get_drvdata(pdev);
> +	if (drv_data != NULL) {

Perhaps

static void __devexit pti_pci_remove(struct pci_dev *pdev)
{
     struct pti_dev *drv_data = pci_get_drvdata(pdev);
     
     if (drv_data) {


...
> +static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
> +{
> +	int ret = 0;
> +
> +	/*
> +	 * we actually want to allocate a new channel per open, per
> +	 * system arch.  HW gives more than plenty channels for a single
> +	 * system task to have its own channel to write trace data. This
> +	 * also removes a locking requirement for the actual write
> +	 * procedure.
> +	 */
> +	ret = tty_port_open(&drv_data->port, tty, filp);
> +
> +	return ret;
> +}
...

Why not get rid of the pointless 'ret' variable and simplify this down to

static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
{     
     /*
      * we actually want to allocate a new channel per open, per
      * system arch.  HW gives more than plenty channels for a single
      * system task to have its own channel to write trace data. This
      * also removes a locking requirement for the actual write
      * procedure.
      */
     return tty_port_open(&drv_data->port, tty, filp);
}

??


...
> +static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
> +{
> +	tty_port_close(&drv_data->port, tty, filp);
> +
> +	return;
> +}

Just kill that superfluous return statement.


...
> +static void pti_tty_cleanup(struct tty_struct *tty)
> +{
> +	struct pti_tty *pti_tty_data;
> +	struct pti_masterchannel *mc;
> +
> +	pti_tty_data = tty->driver_data;
> +
> +	if (pti_tty_data != NULL) {
> +		mc = pti_tty_data->mc;
> +		pti_release_masterchannel(mc);
> +		pti_tty_data->mc = NULL;
> +	}
> +
> +	if (pti_tty_data != NULL)
> +		kfree(pti_tty_data);
> +
> +	tty->driver_data = NULL;
> +}

How about this instead?

static void pti_tty_cleanup(struct tty_struct *tty)
{
     if (!tty->driver_data)
             return;
     pti_release_masterchannel(tty->driver_data->mc);
     kfree(tty->driver_data);
}

...
> +static int pti_tty_driver_write(struct tty_struct *tty,
> +	const unsigned char *buf, int len)
> +{
> +	struct pti_masterchannel *mc;
> +	struct pti_tty *pti_tty_data;
> +
> +	pti_tty_data = tty->driver_data;
> +	mc = pti_tty_data->mc;
> +	pti_write_to_aperture(mc, (u8 *)buf, len);
> +
> +	return len;
> +}

I'd like to suggest this as an alternative:

static int pti_tty_driver_write(struct tty_struct *tty,
     const unsigned char *buf, int len)
{
     pti_write_to_aperture(tty->driver_data->mc, (u8 *)buf, len);
     return len;
}


..
> +static int pti_char_open(struct inode *inode, struct file *filp)
> +{
> +	struct pti_masterchannel *mc;
> +
> +	mc = pti_request_masterchannel(0);
> +	if (mc == NULL)
> +		return -ENOMEM;
> +	filp->private_data = mc;
> +	return 0;
> +}

Ok, so I admit that I haven't looked to check if it's actually important 
that filp->private_data does not get overwritten if 
pti_request_masterchannel() returns NULL, but if we assume that it is not 
important, then this would be an improvement IMHO:

static int pti_char_open(struct inode *inode, struct file *filp)
{
     filp->private_data = pti_request_masterchannel(0);
     if (!filp->private_data)
             return -ENOMEM; 
     return 0;
}


...
> +
> +/**
> + * pti_char_release()-  Close a char channel to the PTI device. Part
> + * of the misc device implementation.
> + *
> + * @inode: Not used in this implementaiton.
> + * @filp:  Contains private_data that contains the master, channel
> + *         ID to be released by the PTI device.
> + *
> + * Returns:
> + *	always 0

Why not void then?


> +	pti_release_masterchannel(filp->private_data);
> +	return 0;
> +}
> +
> +/**
> + * pti_char_write()-  Write trace debugging data through the char
> + * interface to the PTI HW.  Part of the misc device implementation.
> + *
> + * @filp:  Contains private data which is used to obtain
> + *         master, channel write ID.
> + * @data:  trace data to be written.
> + * @len:   # of byte to write.
> + * @ppose: Not used in this function implementation.
> + *
> + * Returns:
> + *	int, # of bytes written
> + *	otherwise, error value
> + *
> + * Notes: From side discussions with Alan Cox and experimenting
> + * with PTI debug HW like Nokia's Fido box and Lauterbach
> + * devices, 8192 byte write buffer used by USER_COPY_SIZE was
> + * deemed an appropriate size for this type of usage with
> + * debugging HW.
> + */
> +static ssize_t pti_char_write(struct file *filp, const char __user *data,
> +			      size_t len, loff_t *ppose)
> +{
> +	struct pti_masterchannel *mc;
> +	void *kbuf;
> +	const char __user *tmp;
> +	size_t size = USER_COPY_SIZE, n = 0;

It would be nice to declare these two variables on two sepperate lines 
IMO.

> +
> +	tmp = data;
> +	mc = filp->private_data;
> +
> +	kbuf = kmalloc(size, GFP_KERNEL);
> +	if (kbuf == NULL)  {
> +		pr_err("%s(%d): buf allocation failed\n",
> +			__func__, __LINE__);
> +		return 0;

Shouldn't you be returning -ENOMEM here?

> +	}
> +
> +	do {
> +		if (len - n > USER_COPY_SIZE)
> +			size = USER_COPY_SIZE;
> +		else
> +			size = len - n;
> +
> +		if (copy_from_user(kbuf, tmp, size)) {
> +			kfree(kbuf);
> +			return n ? n : -EFAULT;
> +		}
> +
> +		pti_write_to_aperture(mc, kbuf, size);
> +		n  += size;
> +		tmp += size;
> +
> +	} while (len > n);
> +
> +	kfree(kbuf);
> +	kbuf = NULL;
> +

 kbuff is a local variable. What's the point in assigning NULL to it just 
before you return? Just get rid of that silly assignment.


...
> + * pti_char_release()-  Close a char channel to the PTI device. Part
> + * of the misc device implementation.
> + *
> + * @inode: Not used in this implementaiton.
> + * @filp:  Contains private_data that contains the master, channel
> + *         ID to be released by the PTI device.
> + *
> + * Returns:
> + *	always 0

So why not void?

...
> + * pti_console_setup()-  Initialize console variables used by the driver.
> + *
> + * @c:     Not used.
> + * @opts:  Not used.
> + *
> + * Returns:
> + *	always 0.

Why not void?


...
> + * pti_port_activate()- Used to start/initialize any items upon
> + * first opening of tty_port().
> + *
> + * @port- The tty port number of the PTI device.
> + * @tty-  The tty struct associated with this device.
> + *
> + * Returns:
> + *	always returns 0

Shouldn't it just return void then?


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


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

* Re: [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions.
  2011-04-22 23:32 ` [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions james_p_freyensee
@ 2011-04-24  1:04   ` Jesper Juhl
  2011-04-24  1:51     ` Greg KH
                       ` (2 more replies)
  0 siblings, 3 replies; 171+ messages in thread
From: Jesper Juhl @ 2011-04-24  1:04 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, 22 Apr 2011, james_p_freyensee@linux.intel.com wrote:

> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> The n_tracerouter and n_tracesink line discpline drivers use the
> Linux tty line discpline framework to route trace data coming
> from a tty port (say UART for example) to the trace sink line
> discipline driver and to another tty port(say USB).  Those
> these two line discipline drivers can be used together,
> independently from pti.c, they are part of the original
> implementation solution of the MIPI P1149.7, compact JTAG, PTI
> solution for Intel mobile platforms starting with the
> Medfield platform.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>

A few minor comments can be found below.


...
> +static int n_tracesink_open(struct tty_struct *tty)
> +{
> +	int retval = -EEXIST;
> +
> +	mutex_lock(&writelock);
> +	if (this_tty == NULL) {
> +
> +		this_tty = tty_kref_get(tty);
> +

pointless blank line. I'd suggest removing it.


...
> +		if (this_tty == NULL)
> +			retval = -EFAULT;
> +		else {

If one branch requires braces, both should have them

        } else {


...
> +static void n_tracesink_close(struct tty_struct *tty)
> +{
> +
> +	mutex_lock(&writelock);
> +	tty_driver_flush_buffer(tty);
> +	tty_kref_put(this_tty);
> +	this_tty = NULL;
> +	tty->disc_data = NULL;
> +	mutex_unlock(&writelock);
> +
> +}

pointless blank line at end of function. Remove it.


> +static int __init n_tracesink_init(void)
> +{
> +	int retval;
> +
> +	/* Note N_TRACESINK is defined in linux/tty.h */
> +	retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
> +
> +	if (retval < 0)
> +		pr_err("%s: Registration failed: %d\n", __func__, retval);
> +
> +	return retval;
> +}

How about shortening is a bit - like this?

static int __init n_tracesink_init(void)
{
     /* Note N_TRACESINK is defined in linux/tty.h */
     int retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
     
     if (retval < 0)
             pr_err("%s: Registration failed: %d\n", __func__, retval);
             
     return retval;
}


...
> +static void __exit n_tracesink_exit(void)
> +{
> +	int retval;
> +
> +	retval = tty_unregister_ldisc(N_TRACESINK);
> +
> +	if (retval < 0)
> +		pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
> +}

How about:

static void __exit n_tracesink_exit(void)
{
     int retval = tty_unregister_ldisc(N_TRACESINK);
     
     if (retval < 0)
             pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
}


...
> --- a/include/linux/tty.h
> +++ b/include/linux/tty.h
> @@ -50,6 +50,8 @@
>  #define N_CAIF		20      /* CAIF protocol for talking to modems */
>  #define N_GSM0710	21	/* GSM 0710 Mux */
>  #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
> +#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
> +#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
>  

Lining up those defines would be nice :)


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-24  0:55   ` Jesper Juhl
@ 2011-04-24  1:08     ` Jesper Juhl
  2011-05-05 17:06       ` J Freyensee
  2011-05-05 17:27     ` J Freyensee
  1 sibling, 1 reply; 171+ messages in thread
From: Jesper Juhl @ 2011-04-24  1:08 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Sun, 24 Apr 2011, Jesper Juhl wrote:

> On Fri, 22 Apr 2011, james_p_freyensee@linux.intel.com wrote:
> 
...
> > +static void pti_tty_cleanup(struct tty_struct *tty)
> > +{
> > +	struct pti_tty *pti_tty_data;
> > +	struct pti_masterchannel *mc;
> > +
> > +	pti_tty_data = tty->driver_data;
> > +
> > +	if (pti_tty_data != NULL) {
> > +		mc = pti_tty_data->mc;
> > +		pti_release_masterchannel(mc);
> > +		pti_tty_data->mc = NULL;
> > +	}
> > +
> > +	if (pti_tty_data != NULL)
> > +		kfree(pti_tty_data);
> > +
> > +	tty->driver_data = NULL;
> > +}
> 
> How about this instead?
> 
> static void pti_tty_cleanup(struct tty_struct *tty)
> {
>      if (!tty->driver_data)
>              return;
>      pti_release_masterchannel(tty->driver_data->mc);
>      kfree(tty->driver_data);
> }
> 
I meant to say :

static void pti_tty_cleanup(struct tty_struct *tty)
{
     if (!tty->driver_data)
             return;
     pti_release_masterchannel(tty->driver_data->mc);
     kfree(tty->driver_data);
     tty->driver_data = NULL
}   


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


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

* Re: [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions.
  2011-04-24  1:04   ` Jesper Juhl
@ 2011-04-24  1:51     ` Greg KH
  2011-04-24 23:03       ` Jesper Juhl
  2011-04-29 17:02     ` J Freyensee
  2011-05-05 17:08     ` J Freyensee
  2 siblings, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-04-24  1:51 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: james_p_freyensee, linux-kernel, suhail.ahmed, christophe.guerard

On Sun, Apr 24, 2011 at 03:04:31AM +0200, Jesper Juhl wrote:
> > --- a/include/linux/tty.h
> > +++ b/include/linux/tty.h
> > @@ -50,6 +50,8 @@
> >  #define N_CAIF		20      /* CAIF protocol for talking to modems */
> >  #define N_GSM0710	21	/* GSM 0710 Mux */
> >  #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
> > +#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
> > +#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
> >  
> 
> Lining up those defines would be nice :)

They are lined up in the original file just fine.

thanks,

greg k-h

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

* Re: [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions.
  2011-04-24  1:51     ` Greg KH
@ 2011-04-24 23:03       ` Jesper Juhl
  0 siblings, 0 replies; 171+ messages in thread
From: Jesper Juhl @ 2011-04-24 23:03 UTC (permalink / raw)
  To: Greg KH; +Cc: james_p_freyensee, linux-kernel, suhail.ahmed, christophe.guerard

On Sat, 23 Apr 2011, Greg KH wrote:

> On Sun, Apr 24, 2011 at 03:04:31AM +0200, Jesper Juhl wrote:
> > > --- a/include/linux/tty.h
> > > +++ b/include/linux/tty.h
> > > @@ -50,6 +50,8 @@
> > >  #define N_CAIF		20      /* CAIF protocol for talking to modems */
> > >  #define N_GSM0710	21	/* GSM 0710 Mux */
> > >  #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
> > > +#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
> > > +#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
> > >  
> > 
> > Lining up those defines would be nice :)
> 
> They are lined up in the original file just fine.
> 
Ok, then my email client is messing things up for me.

-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-22 23:32 ` [PATCH 1/4] export kernel call get_task_comm() james_p_freyensee
@ 2011-04-25 20:57   ` David Rientjes
  2011-05-05 16:59     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: David Rientjes @ 2011-04-25 20:57 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Fri, 22 Apr 2011, james_p_freyensee@linux.intel.com wrote:

> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> This allows drivers who call this function to be compiled modularly.
> Otherwise, a driver who is interested in this type of functionality
> has to implement their own get_task_comm() call, causing code
> duplication in the Linux source tree.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>

Third time:

Acked-by: David Rientjes <rientjes@google.com>

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

* Re: [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions.
  2011-04-24  1:04   ` Jesper Juhl
  2011-04-24  1:51     ` Greg KH
@ 2011-04-29 17:02     ` J Freyensee
  2011-05-05 17:08     ` J Freyensee
  2 siblings, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-04-29 17:02 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

Thanks for the feedback.  I've been out on business and will go through
the comments when I can.

Jay

On Sun, 2011-04-24 at 03:04 +0200, Jesper Juhl wrote:
> On Fri, 22 Apr 2011, james_p_freyensee@linux.intel.com wrote:
> 
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > The n_tracerouter and n_tracesink line discpline drivers use the
> > Linux tty line discpline framework to route trace data coming
> > from a tty port (say UART for example) to the trace sink line
> > discipline driver and to another tty port(say USB).  Those
> > these two line discipline drivers can be used together,
> > independently from pti.c, they are part of the original
> > implementation solution of the MIPI P1149.7, compact JTAG, PTI
> > solution for Intel mobile platforms starting with the
> > Medfield platform.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> A few minor comments can be found below.
> 
> 
> ...
> > +static int n_tracesink_open(struct tty_struct *tty)
> > +{
> > +	int retval = -EEXIST;
> > +
> > +	mutex_lock(&writelock);
> > +	if (this_tty == NULL) {
> > +
> > +		this_tty = tty_kref_get(tty);
> > +
> 
> pointless blank line. I'd suggest removing it.
> 
> 
> ...
> > +		if (this_tty == NULL)
> > +			retval = -EFAULT;
> > +		else {
> 
> If one branch requires braces, both should have them
> 
>         } else {
> 
> 
> ...
> > +static void n_tracesink_close(struct tty_struct *tty)
> > +{
> > +
> > +	mutex_lock(&writelock);
> > +	tty_driver_flush_buffer(tty);
> > +	tty_kref_put(this_tty);
> > +	this_tty = NULL;
> > +	tty->disc_data = NULL;
> > +	mutex_unlock(&writelock);
> > +
> > +}
> 
> pointless blank line at end of function. Remove it.
> 
> 
> > +static int __init n_tracesink_init(void)
> > +{
> > +	int retval;
> > +
> > +	/* Note N_TRACESINK is defined in linux/tty.h */
> > +	retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
> > +
> > +	if (retval < 0)
> > +		pr_err("%s: Registration failed: %d\n", __func__, retval);
> > +
> > +	return retval;
> > +}
> 
> How about shortening is a bit - like this?
> 
> static int __init n_tracesink_init(void)
> {
>      /* Note N_TRACESINK is defined in linux/tty.h */
>      int retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
>      
>      if (retval < 0)
>              pr_err("%s: Registration failed: %d\n", __func__, retval);
>              
>      return retval;
> }
> 
> 
> ...
> > +static void __exit n_tracesink_exit(void)
> > +{
> > +	int retval;
> > +
> > +	retval = tty_unregister_ldisc(N_TRACESINK);
> > +
> > +	if (retval < 0)
> > +		pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
> > +}
> 
> How about:
> 
> static void __exit n_tracesink_exit(void)
> {
>      int retval = tty_unregister_ldisc(N_TRACESINK);
>      
>      if (retval < 0)
>              pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
> }
> 
> 
> ...
> > --- a/include/linux/tty.h
> > +++ b/include/linux/tty.h
> > @@ -50,6 +50,8 @@
> >  #define N_CAIF		20      /* CAIF protocol for talking to modems */
> >  #define N_GSM0710	21	/* GSM 0710 Mux */
> >  #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
> > +#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
> > +#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
> >  
> 
> Lining up those defines would be nice :)
> 
> 



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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-04-25 20:57   ` David Rientjes
@ 2011-05-05 16:59     ` J Freyensee
  2011-05-05 18:55       ` David Rientjes
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-05-05 16:59 UTC (permalink / raw)
  To: David Rientjes; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Mon, 2011-04-25 at 13:57 -0700, David Rientjes wrote:
> On Fri, 22 Apr 2011, james_p_freyensee@linux.intel.com wrote:
> 
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > This allows drivers who call this function to be compiled modularly.
> > Otherwise, a driver who is interested in this type of functionality
> > has to implement their own get_task_comm() call, causing code
> > duplication in the Linux source tree.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> Third time:
> 
> Acked-by: David Rientjes <rientjes@google.com>

Okay, so you want me to add an 'acked-by' next time on this patch in my
patch-set series?


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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-24  1:08     ` Jesper Juhl
@ 2011-05-05 17:06       ` J Freyensee
  2011-05-05 20:37         ` Jesper Juhl
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-05-05 17:06 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Sun, 2011-04-24 at 03:08 +0200, Jesper Juhl wrote:
> On Sun, 24 Apr 2011, Jesper Juhl wrote:
> 
> > On Fri, 22 Apr 2011, james_p_freyensee@linux.intel.com wrote:
> > 
> ...
> > > +static void pti_tty_cleanup(struct tty_struct *tty)
> > > +{
> > > +	struct pti_tty *pti_tty_data;
> > > +	struct pti_masterchannel *mc;
> > > +
> > > +	pti_tty_data = tty->driver_data;
> > > +
> > > +	if (pti_tty_data != NULL) {
> > > +		mc = pti_tty_data->mc;
> > > +		pti_release_masterchannel(mc);
> > > +		pti_tty_data->mc = NULL;
> > > +	}
> > > +
> > > +	if (pti_tty_data != NULL)
> > > +		kfree(pti_tty_data);
> > > +
> > > +	tty->driver_data = NULL;
> > > +}
> > 
> > How about this instead?
> > 
> > static void pti_tty_cleanup(struct tty_struct *tty)
> > {
> >      if (!tty->driver_data)
> >              return;
> >      pti_release_masterchannel(tty->driver_data->mc);

I like this suggestion.  I'll incorporate this.  

> >      kfree(tty->driver_data);

I'm no means an expert in the kernel, but I assume kfree() is like C
free(), that it's a nop if it receives a NULL value?

> > }
> > 
> I meant to say :
> 
> static void pti_tty_cleanup(struct tty_struct *tty)
> {
>      if (!tty->driver_data)
>              return;
>      pti_release_masterchannel(tty->driver_data->mc);
>      kfree(tty->driver_data);
>      tty->driver_data = NULL
> }   
> 
> 



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

* Re: [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions.
  2011-04-24  1:04   ` Jesper Juhl
  2011-04-24  1:51     ` Greg KH
  2011-04-29 17:02     ` J Freyensee
@ 2011-05-05 17:08     ` J Freyensee
  2 siblings, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-05-05 17:08 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Sun, 2011-04-24 at 03:04 +0200, Jesper Juhl wrote:
> On Fri, 22 Apr 2011, james_p_freyensee@linux.intel.com wrote:
> 
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > The n_tracerouter and n_tracesink line discpline drivers use the
> > Linux tty line discpline framework to route trace data coming
> > from a tty port (say UART for example) to the trace sink line
> > discipline driver and to another tty port(say USB).  Those
> > these two line discipline drivers can be used together,
> > independently from pti.c, they are part of the original
> > implementation solution of the MIPI P1149.7, compact JTAG, PTI
> > solution for Intel mobile platforms starting with the
> > Medfield platform.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> A few minor comments can be found below.
> 
> 
> ...
> > +static int n_tracesink_open(struct tty_struct *tty)
> > +{
> > +	int retval = -EEXIST;
> > +
> > +	mutex_lock(&writelock);
> > +	if (this_tty == NULL) {
> > +
> > +		this_tty = tty_kref_get(tty);
> > +
> 
> pointless blank line. I'd suggest removing it.
> 
> 
> ...
> > +		if (this_tty == NULL)
> > +			retval = -EFAULT;
> > +		else {
> 
> If one branch requires braces, both should have them
> 
>         } else {
> 

It's not this way because it passed checkpatch.pl.  In fact, I believe
checkpatch.pl will complain if I add {} to a single if() line.

> 
> ...
> > +static void n_tracesink_close(struct tty_struct *tty)
> > +{
> > +
> > +	mutex_lock(&writelock);
> > +	tty_driver_flush_buffer(tty);
> > +	tty_kref_put(this_tty);
> > +	this_tty = NULL;
> > +	tty->disc_data = NULL;
> > +	mutex_unlock(&writelock);
> > +
> > +}
> 
> pointless blank line at end of function. Remove it.
> 
> 
> > +static int __init n_tracesink_init(void)
> > +{
> > +	int retval;
> > +
> > +	/* Note N_TRACESINK is defined in linux/tty.h */
> > +	retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
> > +
> > +	if (retval < 0)
> > +		pr_err("%s: Registration failed: %d\n", __func__, retval);
> > +
> > +	return retval;
> > +}
> 
> How about shortening is a bit - like this?
> 
> static int __init n_tracesink_init(void)
> {
>      /* Note N_TRACESINK is defined in linux/tty.h */
>      int retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
>      
>      if (retval < 0)
>              pr_err("%s: Registration failed: %d\n", __func__, retval);
>              
>      return retval;
> }

I can make the minor modification.

> 
> ...
> > +static void __exit n_tracesink_exit(void)
> > +{
> > +	int retval;
> > +
> > +	retval = tty_unregister_ldisc(N_TRACESINK);
> > +
> > +	if (retval < 0)
> > +		pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
> > +}
> 
> How about:
> 
> static void __exit n_tracesink_exit(void)
> {
>      int retval = tty_unregister_ldisc(N_TRACESINK);
>      
>      if (retval < 0)
>              pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
> }
> 
> 
Dido here.

> ...
> > --- a/include/linux/tty.h
> > +++ b/include/linux/tty.h
> > @@ -50,6 +50,8 @@
> >  #define N_CAIF		20      /* CAIF protocol for talking to modems */
> >  #define N_GSM0710	21	/* GSM 0710 Mux */
> >  #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
> > +#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
> > +#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
> >  
> 
> Lining up those defines would be nice :)
> 
> 



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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-04-24  0:55   ` Jesper Juhl
  2011-04-24  1:08     ` Jesper Juhl
@ 2011-05-05 17:27     ` J Freyensee
  2011-05-05 20:42       ` Jesper Juhl
  2011-05-05 22:30       ` J Freyensee
  1 sibling, 2 replies; 171+ messages in thread
From: J Freyensee @ 2011-05-05 17:27 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Sun, 2011-04-24 at 02:55 +0200, Jesper Juhl wrote:
> On Fri, 22 Apr 2011, james_p_freyensee@linux.intel.com wrote:
> 
> > From: J Freyensee <james_p_freyensee@linux.intel.com>
> > 
> > The PTI (Parallel Trace Interface) driver directs
> > trace data routed from various parts in the system out
> > through an Intel Penwell PTI port and out of the mobile
> > device for analysis with a debugging tool (Lauterbach or Fido).
> > Though n_tracesink and n_tracerouter line discipline drivers
> > are used to extract modem tracing data to the PTI driver
> > and other parts of an Intel mobile solution, the PTI driver
> > can be used independent of n_tracesink and n_tracerouter.
> > 
> > You should select this driver if the target kernel is meant for
> > an Intel Atom (non-netbook) mobile device containing a MIPI
> > P1149.7 standard implementation.
> > 
> > Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> A few comments below.
> 
> ...
> > +#define DRIVERNAME		"pti"
> > +#define PCINAME			"pciPTI"
> > +#define TTYNAME			"ttyPTI"
> > +#define CHARNAME		"pti"
> > +#define PTITTY_MINOR_START	0
> > +#define PTITTY_MINOR_NUM	2
> > +#define MAX_APP_IDS		16   /* 128 channel ids / u8 bit size */
> > +#define MAX_OS_IDS		16   /* 128 channel ids / u8 bit size */
> > +#define MAX_MODEM_IDS		16   /* 128 channel ids / u8 bit size */
> > +#define MODEM_BASE_ID		71   /* modem master ID address    */
> ...
> 
> Would be nice if the values of these defines would line up nicely.
> 
> 
> ...
> > +static struct pci_device_id pci_ids[] __devinitconst = {
> > +		{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B) },
> > +		{0}
> ...
> 
> Why are there spaces after the opening { and before the closing } for the 
> first entry, but not the second. Looks like you need to pick a 
> consistent style.
> 
> 
> > + *  regroup the appropriate message segments together reconstituting each
> > + *  message.
> > + */
> > +static void pti_write_to_aperture(struct pti_masterchannel *mc,
> > +				  u8 *buf,
> > +				  int len)
> > +{
> > +	int dwordcnt, final, i;
> > +	u32 ptiword;
> > +	u8 *p;
> > +	u32 __iomem *aperture;
> > +
> > +	p = buf;
> ...
> 
> Perhaps save a few lines by doing
> 
> static void pti_write_to_aperture(struct pti_masterchannel *mc,
>                                u8 *buf,
>                                int len)
> {
>      int dwordcnt, final, i;
>      u32 ptiword;
>      u32 __iomem *aperture;
>      u8 *p = buf;
> 
> 

I can make the tweak.

> ...
> > +void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
> > +{
> > +	/*
> > +	 * since this function is exported, this is treated like an
> > +	 * API function, thus, all parameters should
> > +	 * be checked for validity.
> > +	 */
> > +	if ((mc != NULL) && (buf != NULL) && (count > 0))
> > +		pti_write_to_aperture(mc, buf, count);
> > +	return;
> ...
> 
> Pointless return; statement.
> 
> 
> ...
> > +static void __devexit pti_pci_remove(struct pci_dev *pdev)
> > +{
> > +	struct pti_dev *drv_data;
> > +
> > +	drv_data = pci_get_drvdata(pdev);
> > +	if (drv_data != NULL) {
> 
> Perhaps
> 
> static void __devexit pti_pci_remove(struct pci_dev *pdev)
> {
>      struct pti_dev *drv_data = pci_get_drvdata(pdev);
>      
>      if (drv_data) {
> 
> 

I'd rather keep my way.  Just easier to read and more self-explanatory.
I realize everyone on this list are expert programmers, but I tend to
default to code that is dead-simple to read and understand.

> ...
> > +static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
> > +{
> > +	int ret = 0;
> > +
> > +	/*
> > +	 * we actually want to allocate a new channel per open, per
> > +	 * system arch.  HW gives more than plenty channels for a single
> > +	 * system task to have its own channel to write trace data. This
> > +	 * also removes a locking requirement for the actual write
> > +	 * procedure.
> > +	 */
> > +	ret = tty_port_open(&drv_data->port, tty, filp);
> > +
> > +	return ret;
> > +}
> ...
> 
> Why not get rid of the pointless 'ret' variable and simplify this down to
> 
> static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
> {     
>      /*
>       * we actually want to allocate a new channel per open, per
>       * system arch.  HW gives more than plenty channels for a single
>       * system task to have its own channel to write trace data. This
>       * also removes a locking requirement for the actual write
>       * procedure.
>       */
>      return tty_port_open(&drv_data->port, tty, filp);
> }
> 
> ??
> 

Sure, I can change it.

> 
> ...
> > +static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
> > +{
> > +	tty_port_close(&drv_data->port, tty, filp);
> > +
> > +	return;
> > +}
> 
> Just kill that superfluous return statement.
> 
> 
Dido here too.

> ...
> > +static void pti_tty_cleanup(struct tty_struct *tty)
> > +{
> > +	struct pti_tty *pti_tty_data;
> > +	struct pti_masterchannel *mc;
> > +
> > +	pti_tty_data = tty->driver_data;
> > +
> > +	if (pti_tty_data != NULL) {
> > +		mc = pti_tty_data->mc;
> > +		pti_release_masterchannel(mc);
> > +		pti_tty_data->mc = NULL;
> > +	}
> > +
> > +	if (pti_tty_data != NULL)
> > +		kfree(pti_tty_data);
> > +
> > +	tty->driver_data = NULL;
> > +}
> 
> How about this instead?
> 
> static void pti_tty_cleanup(struct tty_struct *tty)
> {
>      if (!tty->driver_data)
>              return;
>      pti_release_masterchannel(tty->driver_data->mc);
>      kfree(tty->driver_data);
> }
> 

I think I answered this already; I like the suggestion and will tweak.

> ...
> > +static int pti_tty_driver_write(struct tty_struct *tty,
> > +	const unsigned char *buf, int len)
> > +{
> > +	struct pti_masterchannel *mc;
> > +	struct pti_tty *pti_tty_data;
> > +
> > +	pti_tty_data = tty->driver_data;
> > +	mc = pti_tty_data->mc;
> > +	pti_write_to_aperture(mc, (u8 *)buf, len);
> > +
> > +	return len;
> > +}
> 
> I'd like to suggest this as an alternative:
> 
> static int pti_tty_driver_write(struct tty_struct *tty,
>      const unsigned char *buf, int len)
> {
>      pti_write_to_aperture(tty->driver_data->mc, (u8 *)buf, len);
>      return len;
> }
> 
> 

If there is no objections I will do it.  What I've coded is the observed
coding style I've seen, if for no other reason that to shorten up the
number of '->' used in accessing a member of driver_data.  But this
doesn't look so bad/ugly.

> ..
> > +static int pti_char_open(struct inode *inode, struct file *filp)
> > +{
> > +	struct pti_masterchannel *mc;
> > +
> > +	mc = pti_request_masterchannel(0);
> > +	if (mc == NULL)
> > +		return -ENOMEM;
> > +	filp->private_data = mc;
> > +	return 0;
> > +}
> 
> Ok, so I admit that I haven't looked to check if it's actually important 
> that filp->private_data does not get overwritten if 
> pti_request_masterchannel() returns NULL, but if we assume that it is not 
> important, then this would be an improvement IMHO:
> 
> static int pti_char_open(struct inode *inode, struct file *filp)
> {
>      filp->private_data = pti_request_masterchannel(0);
>      if (!filp->private_data)
>              return -ENOMEM; 
>      return 0;
> }
> 
> 

I'll play with this with a debugging tool, but I may want to leave the
code the way I have it.

> ...
> > +
> > +/**
> > + * pti_char_release()-  Close a char channel to the PTI device. Part
> > + * of the misc device implementation.
> > + *
> > + * @inode: Not used in this implementaiton.
> > + * @filp:  Contains private_data that contains the master, channel
> > + *         ID to be released by the PTI device.
> > + *
> > + * Returns:
> > + *	always 0
> 
> Why not void then?

Because the prototype for struct file_definitions calls for returning an
int value.

> 
> 
> > +	pti_release_masterchannel(filp->private_data);
> > +	return 0;
> > +}
> > +
> > +/**
> > + * pti_char_write()-  Write trace debugging data through the char
> > + * interface to the PTI HW.  Part of the misc device implementation.
> > + *
> > + * @filp:  Contains private data which is used to obtain
> > + *         master, channel write ID.
> > + * @data:  trace data to be written.
> > + * @len:   # of byte to write.
> > + * @ppose: Not used in this function implementation.
> > + *
> > + * Returns:
> > + *	int, # of bytes written
> > + *	otherwise, error value
> > + *
> > + * Notes: From side discussions with Alan Cox and experimenting
> > + * with PTI debug HW like Nokia's Fido box and Lauterbach
> > + * devices, 8192 byte write buffer used by USER_COPY_SIZE was
> > + * deemed an appropriate size for this type of usage with
> > + * debugging HW.
> > + */
> > +static ssize_t pti_char_write(struct file *filp, const char __user *data,
> > +			      size_t len, loff_t *ppose)
> > +{
> > +	struct pti_masterchannel *mc;
> > +	void *kbuf;
> > +	const char __user *tmp;
> > +	size_t size = USER_COPY_SIZE, n = 0;
> 
> It would be nice to declare these two variables on two sepperate lines 
> IMO.

K, I can fix.

> 
> > +
> > +	tmp = data;
> > +	mc = filp->private_data;
> > +
> > +	kbuf = kmalloc(size, GFP_KERNEL);
> > +	if (kbuf == NULL)  {
> > +		pr_err("%s(%d): buf allocation failed\n",
> > +			__func__, __LINE__);
> > +		return 0;
> 
> Shouldn't you be returning -ENOMEM here?
> 
> > +	}
> > +
> > +	do {
> > +		if (len - n > USER_COPY_SIZE)
> > +			size = USER_COPY_SIZE;
> > +		else
> > +			size = len - n;
> > +
> > +		if (copy_from_user(kbuf, tmp, size)) {
> > +			kfree(kbuf);
> > +			return n ? n : -EFAULT;
> > +		}
> > +
> > +		pti_write_to_aperture(mc, kbuf, size);
> > +		n  += size;
> > +		tmp += size;
> > +
> > +	} while (len > n);
> > +
> > +	kfree(kbuf);
> > +	kbuf = NULL;
> > +
> 
>  kbuff is a local variable. What's the point in assigning NULL to it just 
> before you return? Just get rid of that silly assignment.

I err on the side of paranoia and default to attempting to use good
programming practices and rather receiving comments like this, than the
alternative where I should have assigned something to NULL/0 and I
introduce a security flaw in the driver/kernel.

> 
> 
> ...
> > + * pti_char_release()-  Close a char channel to the PTI device. Part
> > + * of the misc device implementation.
> > + *
> > + * @inode: Not used in this implementaiton.
> > + * @filp:  Contains private_data that contains the master, channel
> > + *         ID to be released by the PTI device.
> > + *
> > + * Returns:
> > + *	always 0
> 
> So why not void?

Same reason; struct file_operations calls for the function prototype
returning an int.

> 
> ...
> > + * pti_console_setup()-  Initialize console variables used by the driver.
> > + *
> > + * @c:     Not used.
> > + * @opts:  Not used.
> > + *
> > + * Returns:
> > + *	always 0.
> 
> Why not void?

Same reason; the kernel driver prototype function calls for an int
return value.

> 
> 
> ...
> > + * pti_port_activate()- Used to start/initialize any items upon
> > + * first opening of tty_port().
> > + *
> > + * @port- The tty port number of the PTI device.
> > + * @tty-  The tty struct associated with this device.
> > + *
> > + * Returns:
> > + *	always returns 0
> 
> Shouldn't it just return void then?

Same reason as above.

> 
> 



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

* Re: [PATCH 1/4] export kernel call get_task_comm().
  2011-05-05 16:59     ` J Freyensee
@ 2011-05-05 18:55       ` David Rientjes
  0 siblings, 0 replies; 171+ messages in thread
From: David Rientjes @ 2011-05-05 18:55 UTC (permalink / raw)
  To: J Freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Thu, 5 May 2011, J Freyensee wrote:

> > Third time:
> > 
> > Acked-by: David Rientjes <rientjes@google.com>
> 
> Okay, so you want me to add an 'acked-by' next time on this patch in my
> patch-set series?
> 

That's the usual convention, yes.

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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-05-05 17:06       ` J Freyensee
@ 2011-05-05 20:37         ` Jesper Juhl
  0 siblings, 0 replies; 171+ messages in thread
From: Jesper Juhl @ 2011-05-05 20:37 UTC (permalink / raw)
  To: J Freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Thu, 5 May 2011, J Freyensee wrote:

[...]
> 
> I'm no means an expert in the kernel, but I assume kfree() is like C
> free(), that it's a nop if it receives a NULL value?
> 

Yes. kfree(NULL) is a nop, so you can avoid the conditional branch.

-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-05-05 17:27     ` J Freyensee
@ 2011-05-05 20:42       ` Jesper Juhl
  2011-05-05 22:30       ` J Freyensee
  1 sibling, 0 replies; 171+ messages in thread
From: Jesper Juhl @ 2011-05-05 20:42 UTC (permalink / raw)
  To: J Freyensee; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard

On Thu, 5 May 2011, J Freyensee wrote:

> On Sun, 2011-04-24 at 02:55 +0200, Jesper Juhl wrote:
...
> > 
> >  kbuff is a local variable. What's the point in assigning NULL to it just 
> > before you return? Just get rid of that silly assignment.
> 
> I err on the side of paranoia and default to attempting to use good
> programming practices and rather receiving comments like this, than the
> alternative where I should have assigned something to NULL/0 and I
> introduce a security flaw in the driver/kernel.
> 

That is all well and good, but assigning to a local variable just before 
it goes out of scope is utterly pointless. Nothing can access the variable 
afterwards, so it's value is completely irrelevant at that point.

-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


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

* Re: [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
  2011-05-05 17:27     ` J Freyensee
  2011-05-05 20:42       ` Jesper Juhl
@ 2011-05-05 22:30       ` J Freyensee
  1 sibling, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-05-05 22:30 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: gregkh, linux-kernel, suhail.ahmed, christophe.guerard


> > 
> > static void pti_tty_cleanup(struct tty_struct *tty)
> > {
> >      if (!tty->driver_data)
> >              return;
> >      pti_release_masterchannel(tty->driver_data->mc);
> >      kfree(tty->driver_data);
> > }
> > 
> 
> I think I answered this already; I like the suggestion and will tweak.
> 
> > ...
> > > +static int pti_tty_driver_write(struct tty_struct *tty,
> > > +	const unsigned char *buf, int len)
> > > +{
> > > +	struct pti_masterchannel *mc;
> > > +	struct pti_tty *pti_tty_data;
> > > +
> > > +	pti_tty_data = tty->driver_data;
> > > +	mc = pti_tty_data->mc;
> > > +	pti_write_to_aperture(mc, (u8 *)buf, len);
> > > +
> > > +	return len;
> > > +}
> > 
> > I'd like to suggest this as an alternative:
> > 
> > static int pti_tty_driver_write(struct tty_struct *tty,
> >      const unsigned char *buf, int len)
> > {
> >      pti_write_to_aperture(tty->driver_data->mc, (u8 *)buf, len);
> >      return len;
> > }
> > 
> > 
> 
> If there is no objections I will do it.  What I've coded is the observed
> coding style I've seen, if for no other reason that to shorten up the
> number of '->' used in accessing a member of driver_data.  But this
> doesn't look so bad/ugly.
> 

Ok, so now I remember why this suggestion isn't good and I am going to
have to go back to what I had before.  Some picky compilers do not like
for you to do operations on (void *) variables, other than a beginning
assign statement to a variable with an actual type.    



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

* Request for review and addition of PTI implementation into kernel
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (26 preceding siblings ...)
  2011-04-22 23:32 ` [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions james_p_freyensee
@ 2011-05-06 23:56 ` james_p_freyensee
  2011-05-07  0:33   ` Greg KH
  2011-05-06 23:56 ` [PATCH 1/4] export kernel call get_task_comm() james_p_freyensee
                   ` (13 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-05-06 23:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, christophe.guerard, james_p_freyensee

>From james_p_freyensee@linux.intel.com # This line is ignored.
From: james_p_freyensee@linux.intel.com
Subject: Request for review and addition of PTI implementation into kernel
In-Reply-To: james_p_freyensee@linux.intel.com


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

* [PATCH 1/4] export kernel call get_task_comm().
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (27 preceding siblings ...)
  2011-05-06 23:56 ` Request for review and addition of PTI implementation into kernel james_p_freyensee
@ 2011-05-06 23:56 ` james_p_freyensee
  2011-05-06 23:56 ` [PATCH 2/4] Kernel documentation for the PTI feature james_p_freyensee
                   ` (12 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-05-06 23:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, christophe.guerard, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This allows drivers who call this function to be compiled modularly.
Otherwise, a driver who is interested in this type of functionality
has to implement their own get_task_comm() call, causing code
duplication in the Linux source tree.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
Acked-by: David Rientjes <rientjes@google.com>
---
 fs/exec.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 8328beb..e1ac338 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1004,6 +1004,7 @@ char *get_task_comm(char *buf, struct task_struct *tsk)
 	task_unlock(tsk);
 	return buf;
 }
+EXPORT_SYMBOL_GPL(get_task_comm);
 
 void set_task_comm(struct task_struct *tsk, char *buf)
 {
-- 
1.7.2.3


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

* [PATCH 2/4] Kernel documentation for the PTI feature.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (28 preceding siblings ...)
  2011-05-06 23:56 ` [PATCH 1/4] export kernel call get_task_comm() james_p_freyensee
@ 2011-05-06 23:56 ` james_p_freyensee
  2011-05-06 23:56 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
                   ` (11 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-05-06 23:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, christophe.guerard, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

This provides Kernel documentation for the PTI
feature and setting line discipline drivers
on top of tty's for Linux mobile solutions.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 Documentation/pti/pti_intel_mid.txt |   99 +++++++++++++++++++++++++++++++++++
 1 files changed, 99 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/pti/pti_intel_mid.txt

diff --git a/Documentation/pti/pti_intel_mid.txt b/Documentation/pti/pti_intel_mid.txt
new file mode 100644
index 0000000..ab8408b
--- /dev/null
+++ b/Documentation/pti/pti_intel_mid.txt
@@ -0,0 +1,99 @@
+The Intel MID PTI project is HW implemented in Intel Atom
+system-on-a-chip designs based on the Parallel Trace
+Interface for MIPI P1149.7 cJTAG standard.  The kernel solution
+for this platform involves the following files:
+
+./include/linux/pti.h
+./drivers/.../n_tracesink.h
+./drivers/.../n_tracerouter.c
+./drivers/.../n_tracesink.c
+./drivers/.../pti.c
+
+pti.c is the driver that enables various debugging features
+popular on platforms from certain mobile manufacturers.  
+n_tracerouter.c and n_tracesink.c allow extra system information to 
+be collected and routed to the pti driver, such as trace
+debugging data from a modem.  Although n_tracerouter
+and n_tracesink are a part of the complete PTI solution,
+these two line disciplines can work separately from
+pti.c and route any data stream from one /dev/tty node
+to another /dev/tty node via kernel-space.  This provides
+a stable, reliable connection that will not break unless
+the user-space application shuts down (plus avoids
+kernel->user->kernel context switch overheads of routing
+data).
+
+An example debugging usage for this driver system:
+   *Hook /dev/ttyPTI0 to syslogd.  Opening this port will also start
+    a console device to further capture debugging messages to PTI.
+   *Hook /dev/ttyPTI1 to modem debugging data to write to PTI HW.
+    This is where n_tracerouter and n_tracesink are used.
+   *Hook /dev/pti to a user-level debugging application for writing
+    to PTI HW.
+   *Use mipi_* Kernel Driver API in other device drivers for
+    debugging to PTI by first requesting a PTI write address via
+    mipi_request_masterchannel(1).
+
+Below is example pseudo-code on how a 'privileged' application
+can hook up n_tracerouter and n_tracesink to any tty on
+a system.  'Privileged' means the application has enough
+privileges to successfully manipulate the ldisc drivers
+but is not just blindly executing as 'root'. Keep in mind
+the use of ioctl(,TIOCSETD,) is not specific to the n_tracerouter
+and n_tracesink line discpline drivers but is a generic
+operation for a program to use a line discpline driver
+on a tty port other than the default n_tty.
+
+/////////// To hook up n_tracerouter and n_tracesink /////////
+
+// Note that n_tracerouter depends on n_tracesink.
+#include <errno.h>
+#define ONE_TTY "/dev/ttyOne"
+#define TWO_TTY "/dev/ttyTwo"
+
+// needed global to hand onto ldisc connection
+static int g_fd_source = -1;
+static int g_fd_sink  = -1;
+
+// these two vars used to grab LDISC values from loaded ldisc drivers
+// in OS.  Look at /proc/tty/ldiscs to get the right numbers from
+// the ldiscs loaded in the system.
+int source_ldisc_num, sink_ldisc_num = -1;
+int retval;
+
+g_fd_source = open(ONE_TTY, O_RDWR); // must be R/W
+g_fd_sink   = open(TWO_TTY, O_RDWR); // must be R/W
+
+if (g_fd_source <= 0) || (g_fd_sink <= 0) {
+   // doubt you'll want to use these exact error lines of code
+   printf("Error on open(). errno: %d\n",errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_sink, TIOCSETD, &sink_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+retval = ioctl(g_fd_source, TIOCSETD, &source_ldisc_num);
+if (retval < 0) {
+   printf("Error on ioctl().  errno: %d\n", errno);
+   return errno;
+}
+
+/////////// To disconnect n_tracerouter and n_tracesink ////////
+
+// First make sure data through the ldiscs has stopped.
+
+// Second, disconnect ldiscs.  This provides a
+// little cleaner shutdown on tty stack.
+sink_ldisc_num = 0;
+source_ldisc_num = 0;
+ioctl(g_fd_uart, TIOCSETD, &sink_ldisc_num);
+ioctl(g_fd_gadget, TIOCSETD, &source_ldisc_num);
+
+// Three, program closes connection, and cleanup:
+close(g_fd_uart);
+close(g_fd_gadget);
+g_fd_uart = g_fd_gadget = NULL;
-- 
1.7.2.3


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

* [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (29 preceding siblings ...)
  2011-05-06 23:56 ` [PATCH 2/4] Kernel documentation for the PTI feature james_p_freyensee
@ 2011-05-06 23:56 ` james_p_freyensee
  2011-05-06 23:56 ` [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions james_p_freyensee
                   ` (10 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-05-06 23:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, christophe.guerard, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

The PTI (Parallel Trace Interface) driver directs
trace data routed from various parts in the system out
through an Intel Penwell PTI port and out of the mobile
device for analysis with a debugging tool (Lauterbach or Fido).
Though n_tracesink and n_tracerouter line discipline drivers
are used to extract modem tracing data to the PTI driver
and other parts of an Intel mobile solution, the PTI driver
can be used independent of n_tracesink and n_tracerouter.

You should select this driver if the target kernel is meant for
an Intel Atom (non-netbook) mobile device containing a MIPI
P1149.7 standard implementation.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/Kconfig  |   13 +
 drivers/misc/Makefile |    1 +
 drivers/misc/pti.c    |  980 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pti.h   |   42 +++
 4 files changed, 1036 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pti.c
 create mode 100644 include/linux/pti.h

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4e007c6..e87babd 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -144,6 +144,19 @@ config PHANTOM
 	  If you choose to build module, its name will be phantom. If unsure,
 	  say N here.
 
+config INTEL_MID_PTI
+	tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
+	default n
+	help
+	  The PTI (Parallel Trace Interface) driver directs
+	  trace data routed from various parts in the system out
+	  through an Intel Penwell PTI port and out of the mobile
+	  device for analysis with a debugging tool (Lauterbach or Fido).
+
+	  You should select this driver if the target kernel is meant for
+	  an Intel Atom (non-netbook) mobile device containing a MIPI
+	  P1149.7 standard implementation.
+
 config SGI_IOC4
 	tristate "SGI IOC4 Base IO support"
 	depends on PCI
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index f546860..662aa3c 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_IBM_ASM)		+= ibmasm/
 obj-$(CONFIG_AD525X_DPOT)	+= ad525x_dpot.o
 obj-$(CONFIG_AD525X_DPOT_I2C)	+= ad525x_dpot-i2c.o
 obj-$(CONFIG_AD525X_DPOT_SPI)	+= ad525x_dpot-spi.o
+0bj-$(CONFIG_INTEL_MID_PTI)	+= pti.o
 obj-$(CONFIG_ATMEL_PWM)		+= atmel_pwm.o
 obj-$(CONFIG_ATMEL_SSC)		+= atmel-ssc.o
 obj-$(CONFIG_ATMEL_TCLIB)	+= atmel_tclib.o
diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
new file mode 100644
index 0000000..bb6f925
--- /dev/null
+++ b/drivers/misc/pti.c
@@ -0,0 +1,980 @@
+/*
+ *  pti.c - PTI driver for cJTAG data extration
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ */
+
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/console.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/pci.h>
+#include <linux/mutex.h>
+#include <linux/miscdevice.h>
+#include <linux/pti.h>
+
+#define DRIVERNAME		"pti"
+#define PCINAME			"pciPTI"
+#define TTYNAME			"ttyPTI"
+#define CHARNAME		"pti"
+#define PTITTY_MINOR_START	0
+#define PTITTY_MINOR_NUM	2
+#define MAX_APP_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_OS_IDS		16   /* 128 channel ids / u8 bit size */
+#define MAX_MODEM_IDS		16   /* 128 channel ids / u8 bit size */
+#define MODEM_BASE_ID		71   /* modem master ID address    */
+#define CONTROL_ID		72   /* control master ID address  */
+#define CONSOLE_ID		73   /* console master ID address  */
+#define OS_BASE_ID		74   /* base OS master ID address  */
+#define APP_BASE_ID		80   /* base App master ID address */
+#define CONTROL_FRAME_LEN	32   /* PTI control frame maximum size */
+#define USER_COPY_SIZE		8192 /* 8Kb buffer for user space copy */
+#define APERTURE_14		0x3800000 /* offset to first OS write addr */
+#define APERTURE_LEN		0x400000  /* address length */
+
+struct pti_tty {
+	struct pti_masterchannel *mc;
+};
+
+struct pti_dev {
+	struct tty_port port;
+	unsigned long pti_addr;
+	unsigned long aperture_base;
+	void __iomem *pti_ioaddr;
+	u8 ia_app[MAX_APP_IDS];
+	u8 ia_os[MAX_OS_IDS];
+	u8 ia_modem[MAX_MODEM_IDS];
+};
+
+/*
+ * This protects access to ia_app, ia_os, and ia_modem,
+ * which keeps track of channels allocated in
+ * an aperture write id.
+ */
+static DEFINE_MUTEX(alloclock);
+
+static struct pci_device_id pci_ids[] __devinitconst = {
+		{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B)},
+		{0}
+};
+
+static struct tty_driver *pti_tty_driver;
+static struct pti_dev *drv_data;
+
+static unsigned int pti_console_channel;
+static unsigned int pti_control_channel;
+
+/**
+ *  pti_write_to_aperture()- The private write function to PTI HW.
+ *
+ *  @mc: The 'aperture'. It's part of a write address that holds
+ *       a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  Since each aperture is specified by a unique
+ *  master/channel ID, no two processes will be writing
+ *  to the same aperture at the same time so no lock is required. The
+ *  PTI-Output agent will send these out in the order that they arrived, and
+ *  thus, it will intermix these messages. The debug tool can then later
+ *  regroup the appropriate message segments together reconstituting each
+ *  message.
+ */
+static void pti_write_to_aperture(struct pti_masterchannel *mc,
+				  u8 *buf,
+				  int len)
+{
+	int dwordcnt;
+	int final;
+	int i;
+	u32 ptiword;
+	u32 __iomem *aperture;
+	u8 *p = buf;
+
+	/*
+	 * calculate the aperture offset from the base using the master and
+	 * channel id's.
+	 */
+	aperture = drv_data->pti_ioaddr + (mc->master << 15)
+		+ (mc->channel << 8);
+
+	dwordcnt = len >> 2;
+	final = len - (dwordcnt << 2);	    /* final = trailing bytes    */
+	if (final == 0 && dwordcnt != 0) {  /* always need a final dword */
+		final += 4;
+		dwordcnt--;
+	}
+
+	for (i = 0; i < dwordcnt; i++) {
+		ptiword = be32_to_cpu(*(u32 *)p);
+		p += 4;
+		iowrite32(ptiword, aperture);
+	}
+
+	aperture += PTI_LASTDWORD_DTS;	/* adding DTS signals that is EOM */
+
+	ptiword = 0;
+	for (i = 0; i < final; i++)
+		ptiword |= *p++ << (24-(8*i));
+
+	iowrite32(ptiword, aperture);
+	return;
+}
+
+/**
+ *  pti_control_frame_built_and_sent()- control frame build and send function.
+ *
+ *  @mc: The master / channel structure on which the function
+ *       built a control frame.
+ *
+ *  To be able to post process the PTI contents on host side, a control frame
+ *  is added before sending any PTI content. So the host side knows on
+ *  each PTI frame the name of the thread using a dedicated master / channel.
+ *  The thread name is retrieved from the 'current' global variable.
+ *  This function builds this frame and sends it to a master ID CONTROL_ID.
+ *  The overhead is only 32 bytes since the driver only writes to HW
+ *  in 32 byte chunks.
+ */
+
+static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc)
+{
+	struct pti_masterchannel mccontrol = {.master = CONTROL_ID,
+					      .channel = 0};
+	const char *control_format = "%3d %3d %s";
+	u8 control_frame[CONTROL_FRAME_LEN];
+
+	/*
+	 * Since we access the comm member in current's task_struct,
+	 * we only need to be as large as what 'comm' in that
+	 * structure is.
+	 */
+	char comm[TASK_COMM_LEN];
+
+	if (!in_interrupt())
+		get_task_comm(comm, current);
+	else
+		strncpy(comm, "Interrupt", TASK_COMM_LEN);
+
+	/* Absolutely ensure our buffer is zero terminated. */
+	comm[TASK_COMM_LEN-1] = 0;
+
+	mccontrol.channel = pti_control_channel;
+	pti_control_channel = (pti_control_channel + 1) & 0x7f;
+
+	snprintf(control_frame, CONTROL_FRAME_LEN, control_format, mc->master,
+		mc->channel, comm);
+	pti_write_to_aperture(&mccontrol, control_frame, strlen(control_frame));
+}
+
+/**
+ *  pti_write_full_frame_to_aperture()- high level function to
+ *					write to PTI.
+ *
+ *  @mc:  The 'aperture'. It's part of a write address that holds
+ *        a master and channel ID.
+ *  @buf: Data being written to the HW that will ultimately be seen
+ *        in a debugging tool (Fido, Lauterbach).
+ *  @len: Size of buffer.
+ *
+ *  All threads sending data (either console, user space application, ...)
+ *  are calling the high level function to write to PTI meaning that it is
+ *  possible to add a control frame before sending the content.
+ */
+static void pti_write_full_frame_to_aperture(struct pti_masterchannel *mc,
+						const unsigned char *buf,
+						int len)
+{
+	pti_control_frame_built_and_sent(mc);
+	pti_write_to_aperture(mc, (u8 *)buf, len);
+}
+
+/**
+ * get_id()- Allocate a master and channel ID.
+ *
+ * @id_array: an array of bits representing what channel
+ *            id's are allocated for writing.
+ * @max_ids:  The max amount of available write IDs to use.
+ * @base_id:  The starting SW channel ID, based on the Intel
+ *            PTI arch.
+ *
+ * Returns:
+ *	pti_masterchannel struct with master, channel ID address
+ *	0 for error
+ *
+ * Each bit in the arrays ia_app and ia_os correspond to a master and
+ * channel id. The bit is one if the id is taken and 0 if free. For
+ * every master there are 128 channel id's.
+ */
+static struct pti_masterchannel *get_id(u8 *id_array, int max_ids, int base_id)
+{
+	struct pti_masterchannel *mc;
+	int i, j, mask;
+
+	mc = kmalloc(sizeof(struct pti_masterchannel), GFP_KERNEL);
+	if (mc == NULL)
+		return NULL;
+
+	/* look for a byte with a free bit */
+	for (i = 0; i < max_ids; i++)
+		if (id_array[i] != 0xff)
+			break;
+	if (i == max_ids) {
+		kfree(mc);
+		return NULL;
+	}
+	/* find the bit in the 128 possible channel opportunities */
+	mask = 0x80;
+	for (j = 0; j < 8; j++) {
+		if ((id_array[i] & mask) == 0)
+			break;
+		mask >>= 1;
+	}
+
+	/* grab it */
+	id_array[i] |= mask;
+	mc->master  = base_id;
+	mc->channel = ((i & 0xf)<<3) + j;
+	/* write new master Id / channel Id allocation to channel control */
+	pti_control_frame_built_and_sent(mc);
+	return mc;
+}
+
+/*
+ * The following three functions:
+ * pti_request_mastercahannel(), mipi_release_masterchannel()
+ * and pti_writedata() are an API for other kernel drivers to
+ * access PTI.
+ */
+
+/**
+ * pti_request_masterchannel()- Kernel API function used to allocate
+ *				a master, channel ID address
+ *				to write to PTI HW.
+ *
+ * @type: 0- request Application  master, channel aperture ID write address.
+ *        1- request OS master, channel aperture ID write
+ *           address.
+ *        2- request Modem master, channel aperture ID
+ *           write address.
+ *        Other values, error.
+ *
+ * Returns:
+ *	pti_masterchannel struct
+ *	0 for error
+ */
+struct pti_masterchannel *pti_request_masterchannel(u8 type)
+{
+	struct pti_masterchannel *mc;
+
+	mutex_lock(&alloclock);
+
+	switch (type) {
+
+	case 0:
+		mc = get_id(drv_data->ia_app, MAX_APP_IDS, APP_BASE_ID);
+		break;
+
+	case 1:
+		mc = get_id(drv_data->ia_os, MAX_OS_IDS, OS_BASE_ID);
+		break;
+
+	case 2:
+		mc = get_id(drv_data->ia_modem, MAX_MODEM_IDS, MODEM_BASE_ID);
+		break;
+	default:
+		mc = NULL;
+	}
+
+	mutex_unlock(&alloclock);
+	return mc;
+}
+EXPORT_SYMBOL_GPL(pti_request_masterchannel);
+
+/**
+ * pti_release_masterchannel()- Kernel API function used to release
+ *				a master, channel ID address
+ *				used to write to PTI HW.
+ *
+ * @mc: master, channel apeture ID address to be released.
+ */
+void pti_release_masterchannel(struct pti_masterchannel *mc)
+{
+	u8 master, channel, i;
+
+	mutex_lock(&alloclock);
+
+	if (mc) {
+		master = mc->master;
+		channel = mc->channel;
+
+		if (master == APP_BASE_ID) {
+			i = channel >> 3;
+			drv_data->ia_app[i] &=  ~(0x80>>(channel & 0x7));
+		} else if (master == OS_BASE_ID) {
+			i = channel >> 3;
+			drv_data->ia_os[i] &= ~(0x80>>(channel & 0x7));
+		} else {
+			i = channel >> 3;
+			drv_data->ia_modem[i] &= ~(0x80>>(channel & 0x7));
+		}
+
+		kfree(mc);
+	}
+
+	mutex_unlock(&alloclock);
+}
+EXPORT_SYMBOL_GPL(pti_release_masterchannel);
+
+/**
+ * pti_writedata()- Kernel API function used to write trace
+ *                  debugging data to PTI HW.
+ *
+ * @mc:    Master, channel aperture ID address to write to.
+ *         Null value will return with no write occurring.
+ * @buf:   Trace debuging data to write to the PTI HW.
+ *         Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         return with no write occuring.
+ */
+void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
+{
+	/*
+	 * since this function is exported, this is treated like an
+	 * API function, thus, all parameters should
+	 * be checked for validity.
+	 */
+	if ((mc != NULL) && (buf != NULL) && (count > 0))
+		pti_write_to_aperture(mc, buf, count);
+	return;
+}
+EXPORT_SYMBOL_GPL(pti_writedata);
+
+/**
+ * pti_pci_remove()- Driver exit method to remove PTI from
+ *		   PCI bus.
+ * @pdev: variable containing pci info of PTI.
+ */
+static void __devexit pti_pci_remove(struct pci_dev *pdev)
+{
+	struct pti_dev *drv_data;
+
+	drv_data = pci_get_drvdata(pdev);
+	if (drv_data != NULL) {
+		pci_iounmap(pdev, drv_data->pti_ioaddr);
+		pci_set_drvdata(pdev, NULL);
+		kfree(drv_data);
+		pci_release_region(pdev, 1);
+		pci_disable_device(pdev);
+	}
+}
+
+/*
+ * for the tty_driver_*() basic function descriptions, see tty_driver.h.
+ * Specific header comments made for PTI-related specifics.
+ */
+
+/**
+ * pti_tty_driver_open()- Open an Application master, channel aperture
+ * ID to the PTI device via tty device.
+ *
+ * @tty: tty interface.
+ * @filp: filp interface pased to tty_port_open() call.
+ *
+ * Returns:
+ *	int, 0 for success
+ *	otherwise, fail value
+ *
+ * The main purpose of using the tty device interface is for
+ * each tty port to have a unique PTI write aperture.  In an
+ * example use case, ttyPTI0 gets syslogd and an APP aperture
+ * ID and ttyPTI1 is where the n_tracesink ldisc hooks to route
+ * modem messages into PTI.  Modem trace data does not have to
+ * go to ttyPTI1, but ttyPTI0 and ttyPTI1 do need to be distinct
+ * master IDs.  These messages go through the PTI HW and out of
+ * the handheld platform and to the Fido/Lauterbach device.
+ */
+static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
+{
+	/*
+	 * we actually want to allocate a new channel per open, per
+	 * system arch.  HW gives more than plenty channels for a single
+	 * system task to have its own channel to write trace data. This
+	 * also removes a locking requirement for the actual write
+	 * procedure.
+	 */
+	return tty_port_open(&drv_data->port, tty, filp);
+}
+
+/**
+ * pti_tty_driver_close()- close tty device and release Application
+ * master, channel aperture ID to the PTI device via tty device.
+ *
+ * @tty: tty interface.
+ * @filp: filp interface pased to tty_port_close() call.
+ *
+ * The main purpose of using the tty device interface is to route
+ * syslog daemon messages to the PTI HW and out of the handheld platform
+ * and to the Fido/Lauterbach device.
+ */
+static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
+{
+	tty_port_close(&drv_data->port, tty, filp);
+}
+
+/**
+ * pti_tty_intstall()- Used to set up specific master-channels
+ *		       to tty ports for organizational purposes when
+ *		       tracing viewed from debuging tools.
+ *
+ * @driver: tty driver information.
+ * @tty: tty struct containing pti information.
+ *
+ * Returns:
+ *	0 for success
+ *	otherwise, error
+ */
+static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
+{
+	int idx = tty->index;
+	struct pti_tty *pti_tty_data;
+	int ret = tty_init_termios(tty);
+
+	if (ret == 0) {
+		tty_driver_kref_get(driver);
+		tty->count++;
+		driver->ttys[idx] = tty;
+
+		pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL);
+		if (pti_tty_data == NULL)
+			return -ENOMEM;
+
+		if (idx == PTITTY_MINOR_START)
+			pti_tty_data->mc = pti_request_masterchannel(0);
+		else
+			pti_tty_data->mc = pti_request_masterchannel(2);
+
+		if (pti_tty_data->mc == NULL)
+			return -ENXIO;
+		tty->driver_data = pti_tty_data;
+	}
+
+	return ret;
+}
+
+/**
+ * pti_tty_cleanup()- Used to de-allocate master-channel resources
+ *		      tied to tty's of this driver.
+ *
+ * @tty: tty struct containing pti information.
+ */
+static void pti_tty_cleanup(struct tty_struct *tty)
+{
+	struct pti_tty *pti_tty_data = tty->driver_data;
+	if (pti_tty_data == NULL)
+		return;
+	pti_release_masterchannel(pti_tty_data->mc);
+	kfree(tty->driver_data);
+	tty->driver_data = NULL;
+}
+
+/**
+ * pti_tty_driver_write()-  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @filp: Contains private data which is used to obtain
+ *        master, channel write ID.
+ * @data: trace data to be written.
+ * @len:  # of byte to write.
+ *
+ * Returns:
+ *	int, # of bytes written
+ *	otherwise, error
+ */
+static int pti_tty_driver_write(struct tty_struct *tty,
+	const unsigned char *buf, int len)
+{
+	struct pti_tty *pti_tty_data = tty->driver_data;
+	if ((pti_tty_data != NULL) && (pti_tty_data->mc != NULL)) {
+		pti_write_to_aperture(pti_tty_data->mc, (u8 *)buf, len);
+		return len;
+	}
+	/*
+	 * we can't write to the pti hardware if the private driver_data
+	 * and the mc address is not there.
+	 */
+	else
+		return -EFAULT;
+}
+
+/**
+ * pti_tty_write_room()- Always returns 2048.
+ *
+ * @tty: contains tty info of the pti driver.
+ */
+static int pti_tty_write_room(struct tty_struct *tty)
+{
+	return 2048;
+}
+
+/**
+ * pti_char_open()- Open an Application master, channel aperture
+ * ID to the PTI device. Part of the misc device implementation.
+ *
+ * @inode: not used.
+ * @filp:  Output- will have a masterchannel struct set containing
+ *                 the allocated application PTI aperture write address.
+ *
+ * Returns:
+ *	int, 0 for success
+ *	otherwise, a fail value
+ */
+static int pti_char_open(struct inode *inode, struct file *filp)
+{
+	struct pti_masterchannel *mc;
+
+	/*
+	 * We really do want to fail immediately if
+	 * pti_request_masterchannel() fails,
+	 * before assigning the value to filp->private_data.
+	 * Slightly easier to debug if this driver needs debugging.
+	 */
+	mc = pti_request_masterchannel(0);
+	if (mc == NULL)
+		return -ENOMEM;
+	filp->private_data = mc;
+	return 0;
+}
+
+/**
+ * pti_char_release()-  Close a char channel to the PTI device. Part
+ * of the misc device implementation.
+ *
+ * @inode: Not used in this implementaiton.
+ * @filp:  Contains private_data that contains the master, channel
+ *         ID to be released by the PTI device.
+ *
+ * Returns:
+ *	always 0
+ */
+static int pti_char_release(struct inode *inode, struct file *filp)
+{
+	pti_release_masterchannel(filp->private_data);
+	kfree(filp->private_data);
+	return 0;
+}
+
+/**
+ * pti_char_write()-  Write trace debugging data through the char
+ * interface to the PTI HW.  Part of the misc device implementation.
+ *
+ * @filp:  Contains private data which is used to obtain
+ *         master, channel write ID.
+ * @data:  trace data to be written.
+ * @len:   # of byte to write.
+ * @ppose: Not used in this function implementation.
+ *
+ * Returns:
+ *	int, # of bytes written
+ *	otherwise, error value
+ *
+ * Notes: From side discussions with Alan Cox and experimenting
+ * with PTI debug HW like Nokia's Fido box and Lauterbach
+ * devices, 8192 byte write buffer used by USER_COPY_SIZE was
+ * deemed an appropriate size for this type of usage with
+ * debugging HW.
+ */
+static ssize_t pti_char_write(struct file *filp, const char __user *data,
+			      size_t len, loff_t *ppose)
+{
+	struct pti_masterchannel *mc;
+	void *kbuf;
+	const char __user *tmp;
+	size_t size = USER_COPY_SIZE;
+	size_t n = 0;
+
+	tmp = data;
+	mc = filp->private_data;
+
+	kbuf = kmalloc(size, GFP_KERNEL);
+	if (kbuf == NULL)  {
+		pr_err("%s(%d): buf allocation failed\n",
+			__func__, __LINE__);
+		return -ENOMEM;
+	}
+
+	do {
+		if (len - n > USER_COPY_SIZE)
+			size = USER_COPY_SIZE;
+		else
+			size = len - n;
+
+		if (copy_from_user(kbuf, tmp, size)) {
+			kfree(kbuf);
+			return n ? n : -EFAULT;
+		}
+
+		pti_write_to_aperture(mc, kbuf, size);
+		n  += size;
+		tmp += size;
+
+	} while (len > n);
+
+	kfree(kbuf);
+	return len;
+}
+
+static const struct tty_operations pti_tty_driver_ops = {
+	.open		= pti_tty_driver_open,
+	.close		= pti_tty_driver_close,
+	.write		= pti_tty_driver_write,
+	.write_room	= pti_tty_write_room,
+	.install	= pti_tty_install,
+	.cleanup	= pti_tty_cleanup
+};
+
+static const struct file_operations pti_char_driver_ops = {
+	.owner		= THIS_MODULE,
+	.write		= pti_char_write,
+	.open		= pti_char_open,
+	.release	= pti_char_release,
+};
+
+static struct miscdevice pti_char_driver = {
+	.minor		= MISC_DYNAMIC_MINOR,
+	.name		= CHARNAME,
+	.fops		= &pti_char_driver_ops
+};
+
+/**
+ * pti_console_write()-  Write to the console that has been acquired.
+ *
+ * @c:   Not used in this implementaiton.
+ * @buf: Data to be written.
+ * @len: Length of buf.
+ */
+static void pti_console_write(struct console *c, const char *buf, unsigned len)
+{
+	static struct pti_masterchannel mc = {.master  = CONSOLE_ID,
+					      .channel = 0};
+
+	mc.channel = pti_console_channel;
+	pti_console_channel = (pti_console_channel + 1) & 0x7f;
+
+	pti_write_full_frame_to_aperture(&mc, buf, len);
+}
+
+/**
+ * pti_console_device()-  Return the driver tty structure and set the
+ *			  associated index implementation.
+ *
+ * @c:     Console device of the driver.
+ * @index: index associated with c.
+ *
+ * Returns:
+ *	always value of pti_tty_driver structure when this function
+ *	is called.
+ */
+static struct tty_driver *pti_console_device(struct console *c, int *index)
+{
+	*index = c->index;
+	return pti_tty_driver;
+}
+
+/**
+ * pti_console_setup()-  Initialize console variables used by the driver.
+ *
+ * @c:     Not used.
+ * @opts:  Not used.
+ *
+ * Returns:
+ *	always 0.
+ */
+static int pti_console_setup(struct console *c, char *opts)
+{
+	pti_console_channel = 0;
+	pti_control_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,
+	.index		= 0,
+};
+
+/**
+ * pti_port_activate()- Used to start/initialize any items upon
+ * first opening of tty_port().
+ *
+ * @port- The tty port number of the PTI device.
+ * @tty-  The tty struct associated with this device.
+ *
+ * Returns:
+ *	always returns 0
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static int pti_port_activate(struct tty_port *port, struct tty_struct *tty)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		console_start(&pti_console);
+	return 0;
+}
+
+/**
+ * pti_port_shutdown()- Used to stop/shutdown any items upon the
+ * last tty port close.
+ *
+ * @port- The tty port number of the PTI device.
+ *
+ * Notes: The primary purpose of the PTI tty port 0 is to hook
+ * the syslog daemon to it; thus this port will be open for a
+ * very long time.
+ */
+static void pti_port_shutdown(struct tty_port *port)
+{
+	if (port->tty->index == PTITTY_MINOR_START)
+		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.
+ */
+
+/**
+ * pti_pci_probe()- Used to detect pti on the pci bus and set
+ *		    things up in the driver.
+ *
+ * @pdev- pci_dev struct values for pti.
+ * @ent-  pci_device_id struct for pti driver.
+ *
+ * Returns:
+ *	0 for success
+ *	otherwise, error
+ */
+static int __devinit pti_pci_probe(struct pci_dev *pdev,
+		const struct pci_device_id *ent)
+{
+	int retval = -EINVAL;
+	int pci_bar = 1;
+
+	dev_dbg(&pdev->dev, "%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__,
+			__func__, __LINE__, pdev->vendor, pdev->device);
+
+	retval = misc_register(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+		return retval;
+	}
+
+	retval = pci_enable_device(pdev);
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s: pci_enable_device() returned error %d\n",
+			__func__, retval);
+		return retval;
+	}
+
+	drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
+
+	if (drv_data == NULL) {
+		retval = -ENOMEM;
+		dev_err(&pdev->dev,
+			"%s(%d): kmalloc() returned NULL memory.\n",
+			__func__, __LINE__);
+		return retval;
+	}
+	drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
+
+	retval = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev));
+	if (retval != 0) {
+		dev_err(&pdev->dev,
+			"%s(%d): pci_request_region() returned error %d\n",
+			__func__, __LINE__, retval);
+		kfree(drv_data);
+		return retval;
+	}
+	drv_data->aperture_base = drv_data->pti_addr+APERTURE_14;
+	drv_data->pti_ioaddr =
+		ioremap_nocache((u32)drv_data->aperture_base,
+		APERTURE_LEN);
+	if (!drv_data->pti_ioaddr) {
+		pci_release_region(pdev, pci_bar);
+		retval = -ENOMEM;
+		kfree(drv_data);
+		return retval;
+	}
+
+	pci_set_drvdata(pdev, drv_data);
+
+	tty_port_init(&drv_data->port);
+	drv_data->port.ops = &tty_port_ops;
+
+	tty_register_device(pti_tty_driver, 0, &pdev->dev);
+	tty_register_device(pti_tty_driver, 1, &pdev->dev);
+
+	register_console(&pti_console);
+
+	return retval;
+}
+
+static struct pci_driver pti_pci_driver = {
+	.name		= PCINAME,
+	.id_table	= pci_ids,
+	.probe		= pti_pci_probe,
+	.remove		= pti_pci_remove,
+};
+
+/**
+ *
+ * pti_init()- Overall entry/init call to the pti driver.
+ *             It starts the registration process with the kernel.
+ *
+ * Returns:
+ *	int __init, 0 for success
+ *	otherwise value is an error
+ *
+ */
+static int __init pti_init(void)
+{
+	int retval = -EINVAL;
+
+	/* First register module as tty device */
+
+	pti_tty_driver = alloc_tty_driver(1);
+	if (pti_tty_driver == NULL) {
+		pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n",
+			__func__, __LINE__);
+		return -ENOMEM;
+	}
+
+	pti_tty_driver->owner			= THIS_MODULE;
+	pti_tty_driver->magic			= TTY_DRIVER_MAGIC;
+	pti_tty_driver->driver_name		= DRIVERNAME;
+	pti_tty_driver->name			= TTYNAME;
+	pti_tty_driver->major			= 0;
+	pti_tty_driver->minor_start		= PTITTY_MINOR_START;
+	pti_tty_driver->minor_num		= PTITTY_MINOR_NUM;
+	pti_tty_driver->num			= PTITTY_MINOR_NUM;
+	pti_tty_driver->type			= TTY_DRIVER_TYPE_SYSTEM;
+	pti_tty_driver->subtype			= SYSTEM_TYPE_SYSCONS;
+	pti_tty_driver->flags			= TTY_DRIVER_REAL_RAW |
+						  TTY_DRIVER_DYNAMIC_DEV;
+	pti_tty_driver->init_termios		= tty_std_termios;
+
+	tty_set_operations(pti_tty_driver, &pti_tty_driver_ops);
+
+	retval = tty_register_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	retval = pci_register_driver(&pti_pci_driver);
+
+	if (retval) {
+		pr_err("%s(%d): PCI registration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+
+		tty_unregister_driver(pti_tty_driver);
+		pr_err("%s(%d): Unregistering TTY part of pti driver\n",
+			__func__, __LINE__);
+		pti_tty_driver = NULL;
+		return retval;
+	}
+
+	return retval;
+}
+
+/**
+ * pti_exit()- Unregisters this module as a tty and pci driver.
+ */
+static void __exit pti_exit(void)
+{
+	int retval;
+
+	tty_unregister_device(pti_tty_driver, 0);
+	tty_unregister_device(pti_tty_driver, 1);
+
+	retval = tty_unregister_driver(pti_tty_driver);
+	if (retval) {
+		pr_err("%s(%d): TTY unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	pci_unregister_driver(&pti_pci_driver);
+
+	retval = misc_deregister(&pti_char_driver);
+	if (retval) {
+		pr_err("%s(%d): CHAR unregistration failed of pti driver\n",
+			__func__, __LINE__);
+		pr_err("%s(%d): Error value returned: %d\n",
+			__func__, __LINE__, retval);
+	}
+
+	unregister_console(&pti_console);
+	return;
+}
+
+module_init(pti_init);
+module_exit(pti_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ken Mills, Jay Freyensee");
+MODULE_DESCRIPTION("PTI Driver");
+
diff --git a/include/linux/pti.h b/include/linux/pti.h
new file mode 100644
index 0000000..81af667
--- /dev/null
+++ b/include/linux/pti.h
@@ -0,0 +1,42 @@
+/*
+ *  Copyright (C) Intel 2011
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ *
+ * This header file will allow other parts of the OS to use the
+ * interface to write out it's contents for debugging a mobile system.
+ */
+
+#ifndef PTI_H_
+#define PTI_H_
+
+/* offset for last dword of any PTI message. Part of MIPI P1149.7 */
+#define PTI_LASTDWORD_DTS	0x30
+
+/* basic structure used as a write address to the PTI HW */
+struct pti_masterchannel {
+	u8 master;
+	u8 channel;
+};
+
+/* the following functions are defined in misc/pti.c */
+void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count);
+struct pti_masterchannel *pti_request_masterchannel(u8 type);
+void pti_release_masterchannel(struct pti_masterchannel *mc);
+
+#endif /*PTI_H_*/
-- 
1.7.2.3


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

* [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (30 preceding siblings ...)
  2011-05-06 23:56 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
@ 2011-05-06 23:56 ` james_p_freyensee
  2011-05-25 21:38 ` [PATCH] double-free security PTI fix james_p_freyensee
                   ` (9 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-05-06 23:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, suhail.ahmed, christophe.guerard, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

The n_tracerouter and n_tracesink line discpline drivers use the
Linux tty line discpline framework to route trace data coming
from a tty port (say UART for example) to the trace sink line
discipline driver and to another tty port(say USB).  Those
these two line discipline drivers can be used together,
independently from pti.c, they are part of the original
implementation solution of the MIPI P1149.7, compact JTAG, PTI
solution for Intel mobile platforms starting with the
Medfield platform.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/Kconfig         |   31 ++++++
 drivers/tty/Makefile        |    2 +
 drivers/tty/n_tracerouter.c |  243 +++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/n_tracesink.c   |  238 ++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/n_tracesink.h   |   36 +++++++
 include/linux/tty.h         |    2 +
 6 files changed, 552 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/n_tracerouter.c
 create mode 100644 drivers/tty/n_tracesink.c
 create mode 100644 drivers/tty/n_tracesink.h

diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 3fd7199..2e5f2f2 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -319,3 +319,34 @@ config N_GSM
 	  This line discipline provides support for the GSM MUX protocol and
 	  presents the mux as a set of 61 individual tty devices.
 
+config TRACE_ROUTER
+	tristate "Trace data router for MIPI P1149.7 cJTAG standard"
+	depends on TRACE_SINK
+	default n
+	help
+	  The trace router uses the Linux tty line discipline framework to
+	  route trace data coming from a tty port (say UART for example) to
+	  the trace sink line discipline driver and to another tty port(say 
+	  USB). This is part of a solution for the MIPI P1149.7, compact JTAG,
+	  standard, which is for debugging mobile devices. The PTI driver in
+	  drivers/misc/pti.c defines the majority of this MIPI solution.
+
+	  You should select this driver if the target kernel is meant for
+	  a mobile device containing a modem.  Then you will need to select
+	  "Trace data sink for MIPI P1149.7 cJTAG standard" line discipline
+	  driver.
+
+config TRACE_SINK
+	tristate "Trace data sink for MIPI P1149.7 cJTAG standard"
+	default n
+	help
+	  The trace sink uses the Linux line discipline framework to receive
+	  trace data coming from the trace router line discipline driver
+	  to a user-defined tty port target, like USB.
+	  This is to provide a way to extract modem trace data on
+	  devices that do not have a PTI HW module, or just need modem
+	  trace data to come out of a different HW output port.
+	  This is part of a solution for the P1149.7, compact JTAG, standard.
+
+	  If you select this option, you need to select
+	  "Trace data router for MIPI P1149.7 cJTAG standard".
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index 690522f..ea89b0b 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -6,6 +6,8 @@ obj-$(CONFIG_AUDIT)		+= tty_audit.o
 obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
 obj-$(CONFIG_N_HDLC)		+= n_hdlc.o
 obj-$(CONFIG_N_GSM)		+= n_gsm.o
+obj-$(CONFIG_TRACE_ROUTER)	+= n_tracerouter.o
+obj-$(CONFIG_TRACE_SINK)	+= n_tracesink.o
 obj-$(CONFIG_R3964)		+= n_r3964.o
 
 obj-y				+= vt/
diff --git a/drivers/tty/n_tracerouter.c b/drivers/tty/n_tracerouter.c
new file mode 100644
index 0000000..1f063d3
--- /dev/null
+++ b/drivers/tty/n_tracerouter.c
@@ -0,0 +1,243 @@
+/*
+ *  n_tracerouter.c - Trace data router through tty space
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This trace router uses the Linux line discipline framework to route
+ * trace data coming from a HW Modem to a PTI (Parallel Trace Module) port.
+ * The solution is not specific to a HW modem and this line disciple can
+ * be used to route any stream of data in kernel space.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <asm-generic/bug.h>
+#include "n_tracesink.h"
+
+/*
+ * Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracerouter"
+
+/*
+ * struct to hold private configuration data for this ldisc.
+ * opencalled is used to hold if this ldisc has been opened.
+ * kref_tty holds the tty reference the ldisc sits on top of.
+ */
+struct tracerouter_data {
+	u8 opencalled;
+	struct tty_struct *kref_tty;
+};
+static struct tracerouter_data *tr_data;
+
+/* lock for when tty reference is being used */
+static DEFINE_MUTEX(routelock);
+
+/**
+ * n_tracerouter_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success.
+ *
+ * Caveats: This should only be opened one time per SW entity.
+ */
+static int n_tracerouter_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&routelock);
+	if (tr_data->opencalled == 0) {
+
+		tr_data->kref_tty = tty_kref_get(tty);
+		if (tr_data->kref_tty == NULL) {
+			retval = -EFAULT;
+		} else {
+			tr_data->opencalled = 1;
+			tty->disc_data      = tr_data;
+			tty->receive_room   = RECEIVE_ROOM;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&routelock);
+	return retval;
+}
+
+/**
+ * n_tracerouter_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracerouter_close(struct tty_struct *tty)
+{
+	struct tracerouter_data *tptr = tty->disc_data;
+
+	mutex_lock(&routelock);
+	WARN_ON(tptr->kref_tty != tr_data->kref_tty);
+	tty_driver_flush_buffer(tty);
+	tty_kref_put(tr_data->kref_tty);
+	tr_data->kref_tty = NULL;
+	tr_data->opencalled = 0;
+	tty->disc_data = NULL;
+	mutex_unlock(&routelock);
+}
+
+/**
+ * n_tracerouter_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracerouter_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracerouter_read(struct tty_struct *tty, struct file *file,
+				  unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracerouter_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracerouter_write(struct tty_struct *tty, struct file *file,
+				   const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracerouter_receivebuf() - Routing function for driver.
+ * @tty: terminal device passed into the ldisc.  It's assumed
+ *       tty will never be NULL.
+ * @cp:  buffer, block of characters to be eventually read by
+ *       someone, somewhere (user read() call or some kernel function).
+ * @fp:  flag buffer.
+ * @count: number of characters (aka, bytes) in cp.
+ *
+ * This function takes the input buffer, cp, and passes it to
+ * an external API function for processing.
+ */
+static void n_tracerouter_receivebuf(struct tty_struct *tty,
+					const unsigned char *cp,
+					char *fp, int count)
+{
+	mutex_lock(&routelock);
+	n_tracesink_datadrain((u8 *) cp, count);
+	mutex_unlock(&routelock);
+}
+
+/*
+ * Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+static struct tty_ldisc_ops tty_ptirouter_ldisc = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracerouter_open,
+	.close		= n_tracerouter_close,
+	.read		= n_tracerouter_read,
+	.write		= n_tracerouter_write,
+	.receive_buf	= n_tracerouter_receivebuf
+};
+
+/**
+ * n_tracerouter_init -	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracerouter_init(void)
+{
+	int retval;
+
+	tr_data = kzalloc(sizeof(struct tracerouter_data), GFP_KERNEL);
+	if (tr_data == NULL)
+		return -ENOMEM;
+
+
+	/* Note N_TRACEROUTER is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACEROUTER, &tty_ptirouter_ldisc);
+	if (retval < 0) {
+		pr_err("%s: Registration failed: %d\n", __func__, retval);
+		kfree(tr_data);
+	}
+	return retval;
+}
+
+/**
+ * n_tracerouter_exit -	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracerouter_exit(void)
+{
+	int retval = tty_unregister_ldisc(N_TRACEROUTER);
+
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
+	else
+		kfree(tr_data);
+}
+
+module_init(n_tracerouter_init);
+module_exit(n_tracerouter_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACEROUTER);
+MODULE_DESCRIPTION("Trace router ldisc driver");
diff --git a/drivers/tty/n_tracesink.c b/drivers/tty/n_tracesink.c
new file mode 100644
index 0000000..ddce58b
--- /dev/null
+++ b/drivers/tty/n_tracesink.c
@@ -0,0 +1,238 @@
+/*
+ *  n_tracesink.c - Trace data router and sink path through tty space.
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The trace sink uses the Linux line discipline framework to receive
+ * trace data coming from the PTI source line discipline driver
+ * to a user-desired tty port, like USB.
+ * This is to provide a way to extract modem trace data on
+ * devices that do not have a PTI HW module, or just need modem
+ * trace data to come out of a different HW output port.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <asm-generic/bug.h>
+#include "n_tracesink.h"
+
+/*
+ * Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracesink"
+
+/*
+ * there is a quirk with this ldisc is he can write data
+ * to a tty from anyone calling his kernel API, which
+ * meets customer requirements in the drivers/misc/pti.c
+ * project.  So he needs to know when he can and cannot write when
+ * the API is called. In theory, the API can be called
+ * after an init() but before a successful open() which
+ * would crash the system if tty is not checked.
+ */
+static struct tty_struct *this_tty;
+static DEFINE_MUTEX(writelock);
+
+/**
+ * n_tracesink_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success,
+ *      -EFAULT = couldn't get a tty kref n_tracesink will sit
+ *       on top of
+ *      -EEXIST = open() called successfully once and it cannot
+ *      be called again.
+ *
+ * Caveats: open() should only be successful the first time a
+ * SW entity calls it.
+ */
+static int n_tracesink_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&writelock);
+	if (this_tty == NULL) {
+		this_tty = tty_kref_get(tty);
+		if (this_tty == NULL) {
+			retval = -EFAULT;
+		} else {
+			tty->disc_data = this_tty;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&writelock);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracesink_close(struct tty_struct *tty)
+{
+	mutex_lock(&writelock);
+	tty_driver_flush_buffer(tty);
+	tty_kref_put(this_tty);
+	this_tty = NULL;
+	tty->disc_data = NULL;
+	mutex_unlock(&writelock);
+}
+
+/**
+ * n_tracesink_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracesink_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracesink_read(struct tty_struct *tty, struct file *file,
+				unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracesink_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracesink_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracesink_write(struct tty_struct *tty, struct file *file,
+				 const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracesink_datadrain() - Kernel API function used to route
+ *			     trace debugging data to user-defined
+ *			     port like USB.
+ *
+ * @buf:   Trace debuging data buffer to write to tty target
+ *         port. Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         return with no write occuring.
+ *
+ * Caveat: If this line discipline does not set the tty it sits
+ * on top of via an open() call, this API function will not
+ * call the tty's write() call because it will have no pointer
+ * to call the write().
+ */
+void n_tracesink_datadrain(u8 *buf, int count)
+{
+	mutex_lock(&writelock);
+
+	if ((buf != NULL) && (count > 0) && (this_tty != NULL))
+		this_tty->ops->write(this_tty, buf, count);
+
+	mutex_unlock(&writelock);
+}
+EXPORT_SYMBOL_GPL(n_tracesink_datadrain);
+
+/*
+ * Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+/*
+ * tty_ldisc function operations for this driver.
+ */
+static struct tty_ldisc_ops tty_n_tracesink = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracesink_open,
+	.close		= n_tracesink_close,
+	.read		= n_tracesink_read,
+	.write		= n_tracesink_write
+};
+
+/**
+ * n_tracesink_init-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracesink_init(void)
+{
+	/* Note N_TRACESINK is defined in linux/tty.h */
+	int retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
+
+	if (retval < 0)
+		pr_err("%s: Registration failed: %d\n", __func__, retval);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_exit -	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracesink_exit(void)
+{
+	int retval = tty_unregister_ldisc(N_TRACESINK);
+
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n", __func__,  retval);
+}
+
+module_init(n_tracesink_init);
+module_exit(n_tracesink_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACESINK);
+MODULE_DESCRIPTION("Trace sink ldisc driver");
diff --git a/drivers/tty/n_tracesink.h b/drivers/tty/n_tracesink.h
new file mode 100644
index 0000000..a68bb44
--- /dev/null
+++ b/drivers/tty/n_tracesink.h
@@ -0,0 +1,36 @@
+/*
+ *  n_tracesink.h - Kernel driver API to route trace data in kernel space.
+ *
+ *  Copyright (C) Intel 2011
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ *
+ * This header file is used by n_tracerouter to be able to send the
+ * data of it's tty port to the tty port this module sits.  This
+ * mechanism can also be used independent of the PTI module.
+ *
+ */
+
+#ifndef N_TRACESINK_H_
+#define N_TRACESINK_H_
+
+void n_tracesink_datadrain(u8 *buf, int count);
+
+#endif
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 9f469c7..fbf17de 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -50,6 +50,8 @@
 #define N_CAIF		20      /* CAIF protocol for talking to modems */
 #define N_GSM0710	21	/* GSM 0710 Mux */
 #define N_TI_WL		22	/* for TI's WL BT, FM, GPS combo chips */
+#define N_TRACESINK	23	/* Trace data routing for MIPI P1149.7 */
+#define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
-- 
1.7.2.3


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

* Re: Request for review and addition of PTI implementation into kernel
  2011-05-06 23:56 ` Request for review and addition of PTI implementation into kernel james_p_freyensee
@ 2011-05-07  0:33   ` Greg KH
  2011-05-09 19:07     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Greg KH @ 2011-05-07  0:33 UTC (permalink / raw)
  To: james_p_freyensee; +Cc: linux-kernel, suhail.ahmed, christophe.guerard

On Fri, May 06, 2011 at 04:56:46PM -0700, james_p_freyensee@linux.intel.com wrote:
> >From james_p_freyensee@linux.intel.com # This line is ignored.
> From: james_p_freyensee@linux.intel.com
> Subject: Request for review and addition of PTI implementation into kernel
> In-Reply-To: james_p_freyensee@linux.intel.com

What was this?

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

* Re: Request for review and addition of PTI implementation into kernel
  2011-05-07  0:33   ` Greg KH
@ 2011-05-09 19:07     ` J Freyensee
  0 siblings, 0 replies; 171+ messages in thread
From: J Freyensee @ 2011-05-09 19:07 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, suhail.ahmed, christophe.guerard

On Fri, 2011-05-06 at 17:33 -0700, Greg KH wrote:
> On Fri, May 06, 2011 at 04:56:46PM -0700, james_p_freyensee@linux.intel.com wrote:
> > >From james_p_freyensee@linux.intel.com # This line is ignored.
> > From: james_p_freyensee@linux.intel.com
> > Subject: Request for review and addition of PTI implementation into kernel
> > In-Reply-To: james_p_freyensee@linux.intel.com
> 
> What was this?

That's a good question...I guess that didn't come out well :-/.

It was just a summary of the latest patches I submitted on Friday,
highlighting that the summary of changes this time were mainly cosmetic.
Nothing to patch against the kernel.



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

* [PATCH] double-free security PTI fix
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (31 preceding siblings ...)
  2011-05-06 23:56 ` [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions james_p_freyensee
@ 2011-05-25 21:38 ` james_p_freyensee
  2011-05-25 21:45 ` [PATCH] ENXIO error case memory leak " james_p_freyensee
                   ` (8 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-05-25 21:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, christophe.guerard, james_p_freyensee, rocher.jeremy

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch fixes a double-free error that will not always be
seen unless /dev/pti char interface is stressed.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/pti.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index bb6f925..be48573 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -317,7 +317,8 @@ EXPORT_SYMBOL_GPL(pti_request_masterchannel);
  *				a master, channel ID address
  *				used to write to PTI HW.
  *
- * @mc: master, channel apeture ID address to be released.
+ * @mc: master, channel apeture ID address to be released.  This
+ *      will de-allocate the structure via kfree().
  */
 void pti_release_masterchannel(struct pti_masterchannel *mc)
 {
@@ -581,7 +582,7 @@ static int pti_char_open(struct inode *inode, struct file *filp)
 static int pti_char_release(struct inode *inode, struct file *filp)
 {
 	pti_release_masterchannel(filp->private_data);
-	kfree(filp->private_data);
+	filp->private_data = NULL;
 	return 0;
 }
 
-- 
1.7.2.3


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

* [PATCH] ENXIO error case memory leak PTI fix.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (32 preceding siblings ...)
  2011-05-25 21:38 ` [PATCH] double-free security PTI fix james_p_freyensee
@ 2011-05-25 21:45 ` james_p_freyensee
  2011-05-25 21:50 ` [PATCH] pti_tty_install documentation mispelling james_p_freyensee
                   ` (7 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-05-25 21:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, christophe.guerard, james_p_freyensee, rocher.jeremy

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch fixes a memory leak that can occur in the error case
ENXIO is returned in the pti_tty_install() routine.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/pti.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index be48573..e74e7d2 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -476,8 +476,10 @@ static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
 		else
 			pti_tty_data->mc = pti_request_masterchannel(2);
 
-		if (pti_tty_data->mc == NULL)
+		if (pti_tty_data->mc == NULL) {
+			kfree(pti_tty_data);
 			return -ENXIO;
+		}
 		tty->driver_data = pti_tty_data;
 	}
 
-- 
1.7.2.3


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

* [PATCH] pti_tty_install documentation mispelling.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (33 preceding siblings ...)
  2011-05-25 21:45 ` [PATCH] ENXIO error case memory leak " james_p_freyensee
@ 2011-05-25 21:50 ` james_p_freyensee
  2011-05-25 21:56 ` [PATCH] PTI semantics fix in pti_tty_cleanup james_p_freyensee
                   ` (6 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-05-25 21:50 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, christophe.guerard, james_p_freyensee, rocher.jeremy

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch tidies up the documentation for pti_tty_install()
function.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/pti.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index e74e7d2..62b7ba4 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -445,9 +445,9 @@ static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
 }
 
 /**
- * pti_tty_intstall()- Used to set up specific master-channels
- *		       to tty ports for organizational purposes when
- *		       tracing viewed from debuging tools.
+ * pti_tty_install()- Used to set up specific master-channels
+ *		      to tty ports for organizational purposes when
+ *		      tracing viewed from debuging tools.
  *
  * @driver: tty driver information.
  * @tty: tty struct containing pti information.
-- 
1.7.2.3


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

* [PATCH] PTI semantics fix in pti_tty_cleanup.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (34 preceding siblings ...)
  2011-05-25 21:50 ` [PATCH] pti_tty_install documentation mispelling james_p_freyensee
@ 2011-05-25 21:56 ` james_p_freyensee
  2011-06-17 22:09 ` [PATCH] PTI feature to allow user to name and mark masterchannel request james_p_freyensee
                   ` (5 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-05-25 21:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, christophe.guerard, james_p_freyensee, rocher.jeremy

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch fixes a semantics issue in the pti_tty_cleanup()
routine.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/pti.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index 62b7ba4..e5f295a 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -498,7 +498,7 @@ static void pti_tty_cleanup(struct tty_struct *tty)
 	if (pti_tty_data == NULL)
 		return;
 	pti_release_masterchannel(pti_tty_data->mc);
-	kfree(tty->driver_data);
+	kfree(pti_tty_data);
 	tty->driver_data = NULL;
 }
 
-- 
1.7.2.3


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

* [PATCH] PTI feature to allow user to name and mark masterchannel request.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (35 preceding siblings ...)
  2011-05-25 21:56 ` [PATCH] PTI semantics fix in pti_tty_cleanup james_p_freyensee
@ 2011-06-17 22:09 ` james_p_freyensee
  2011-06-17 22:13 ` [PATCH] 0 for o PTI Makefile bug james_p_freyensee
                   ` (4 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-06-17 22:09 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, christophe.guerard, james_p_freyensee, rocher.jeremy

From: J Freyensee <james_p_freyensee@linux.intel.com>

This feature addition provides a new parameter in
pti_request_masterchannel() to allow the user
to provide their own name to mark the request when
the trace is viewed in a PTI SW trace viewer
(like MPTA).  If a name is not provided and
NULL is provided, the 'current' process name is used.
API function header documentation documents this.

Signed-off-by: Jeremy Rocher <rocher.jeremy@gmail.com>
Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/pti.c  |   99 +++++++++++++++++++++++++++++++--------------------
 include/linux/pti.h |    3 +-
 2 files changed, 62 insertions(+), 40 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index e5f295a..8653bd0 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -146,45 +146,54 @@ static void pti_write_to_aperture(struct pti_masterchannel *mc,
 /**
  *  pti_control_frame_built_and_sent()- control frame build and send function.
  *
- *  @mc: The master / channel structure on which the function
- *       built a control frame.
+ *  @mc:          The master / channel structure on which the function
+ *                built a control frame.
+ *  @thread_name: The thread name associated with the master / channel or
+ *                'NULL' if using the 'current' global variable.
  *
  *  To be able to post process the PTI contents on host side, a control frame
  *  is added before sending any PTI content. So the host side knows on
  *  each PTI frame the name of the thread using a dedicated master / channel.
- *  The thread name is retrieved from the 'current' global variable.
+ *  The thread name is retrieved from 'current' global variable if 'thread_name'
+ *  is 'NULL', else it is retrieved from 'thread_name' parameter.
  *  This function builds this frame and sends it to a master ID CONTROL_ID.
  *  The overhead is only 32 bytes since the driver only writes to HW
  *  in 32 byte chunks.
  */
-
-static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc)
+static void pti_control_frame_built_and_sent(struct pti_masterchannel *mc,
+					     const char *thread_name)
 {
 	struct pti_masterchannel mccontrol = {.master = CONTROL_ID,
 					      .channel = 0};
+	const char *thread_name_p;
 	const char *control_format = "%3d %3d %s";
 	u8 control_frame[CONTROL_FRAME_LEN];
 
-	/*
-	 * Since we access the comm member in current's task_struct,
-	 * we only need to be as large as what 'comm' in that
-	 * structure is.
-	 */
-	char comm[TASK_COMM_LEN];
+	if (!thread_name) {
+		/*
+		 * Since we access the comm member in current's task_struct,
+		 * we only need to be as large as what 'comm' in that
+		 * structure is.
+		 */
+		char comm[TASK_COMM_LEN];
 
-	if (!in_interrupt())
-		get_task_comm(comm, current);
-	else
-		strncpy(comm, "Interrupt", TASK_COMM_LEN);
+		if (!in_interrupt())
+			get_task_comm(comm, current);
+		else
+			strncpy(comm, "Interrupt", TASK_COMM_LEN);
 
-	/* Absolutely ensure our buffer is zero terminated. */
-	comm[TASK_COMM_LEN-1] = 0;
+		/* Absolutely ensure our buffer is zero terminated. */
+		comm[TASK_COMM_LEN-1] = 0;
+		thread_name_p = comm;
+	} else {
+		thread_name_p = thread_name;
+	}
 
 	mccontrol.channel = pti_control_channel;
 	pti_control_channel = (pti_control_channel + 1) & 0x7f;
 
 	snprintf(control_frame, CONTROL_FRAME_LEN, control_format, mc->master,
-		mc->channel, comm);
+		mc->channel, thread_name_p);
 	pti_write_to_aperture(&mccontrol, control_frame, strlen(control_frame));
 }
 
@@ -206,18 +215,20 @@ static void pti_write_full_frame_to_aperture(struct pti_masterchannel *mc,
 						const unsigned char *buf,
 						int len)
 {
-	pti_control_frame_built_and_sent(mc);
+	pti_control_frame_built_and_sent(mc, NULL);
 	pti_write_to_aperture(mc, (u8 *)buf, len);
 }
 
 /**
  * get_id()- Allocate a master and channel ID.
  *
- * @id_array: an array of bits representing what channel
- *            id's are allocated for writing.
- * @max_ids:  The max amount of available write IDs to use.
- * @base_id:  The starting SW channel ID, based on the Intel
- *            PTI arch.
+ * @id_array:    an array of bits representing what channel
+ *               id's are allocated for writing.
+ * @max_ids:     The max amount of available write IDs to use.
+ * @base_id:     The starting SW channel ID, based on the Intel
+ *               PTI arch.
+ * @thread_name: The thread name associated with the master / channel or
+ *               'NULL' if using the 'current' global variable.
  *
  * Returns:
  *	pti_masterchannel struct with master, channel ID address
@@ -227,7 +238,10 @@ static void pti_write_full_frame_to_aperture(struct pti_masterchannel *mc,
  * channel id. The bit is one if the id is taken and 0 if free. For
  * every master there are 128 channel id's.
  */
-static struct pti_masterchannel *get_id(u8 *id_array, int max_ids, int base_id)
+static struct pti_masterchannel *get_id(u8 *id_array,
+					int max_ids,
+					int base_id,
+					const char *thread_name)
 {
 	struct pti_masterchannel *mc;
 	int i, j, mask;
@@ -257,7 +271,7 @@ static struct pti_masterchannel *get_id(u8 *id_array, int max_ids, int base_id)
 	mc->master  = base_id;
 	mc->channel = ((i & 0xf)<<3) + j;
 	/* write new master Id / channel Id allocation to channel control */
-	pti_control_frame_built_and_sent(mc);
+	pti_control_frame_built_and_sent(mc, thread_name);
 	return mc;
 }
 
@@ -273,18 +287,22 @@ static struct pti_masterchannel *get_id(u8 *id_array, int max_ids, int base_id)
  *				a master, channel ID address
  *				to write to PTI HW.
  *
- * @type: 0- request Application  master, channel aperture ID write address.
- *        1- request OS master, channel aperture ID write
- *           address.
- *        2- request Modem master, channel aperture ID
- *           write address.
- *        Other values, error.
+ * @type:        0- request Application  master, channel aperture ID
+ *                  write address.
+ *               1- request OS master, channel aperture ID write
+ *                  address.
+ *               2- request Modem master, channel aperture ID
+ *                  write address.
+ *               Other values, error.
+ * @thread_name: The thread name associated with the master / channel or
+ *               'NULL' if using the 'current' global variable.
  *
  * Returns:
  *	pti_masterchannel struct
  *	0 for error
  */
-struct pti_masterchannel *pti_request_masterchannel(u8 type)
+struct pti_masterchannel *pti_request_masterchannel(u8 type,
+						    const char *thread_name)
 {
 	struct pti_masterchannel *mc;
 
@@ -293,15 +311,18 @@ struct pti_masterchannel *pti_request_masterchannel(u8 type)
 	switch (type) {
 
 	case 0:
-		mc = get_id(drv_data->ia_app, MAX_APP_IDS, APP_BASE_ID);
+		mc = get_id(drv_data->ia_app, MAX_APP_IDS,
+			    APP_BASE_ID, thread_name);
 		break;
 
 	case 1:
-		mc = get_id(drv_data->ia_os, MAX_OS_IDS, OS_BASE_ID);
+		mc = get_id(drv_data->ia_os, MAX_OS_IDS,
+			    OS_BASE_ID, thread_name);
 		break;
 
 	case 2:
-		mc = get_id(drv_data->ia_modem, MAX_MODEM_IDS, MODEM_BASE_ID);
+		mc = get_id(drv_data->ia_modem, MAX_MODEM_IDS,
+			    MODEM_BASE_ID, thread_name);
 		break;
 	default:
 		mc = NULL;
@@ -472,9 +493,9 @@ static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
 			return -ENOMEM;
 
 		if (idx == PTITTY_MINOR_START)
-			pti_tty_data->mc = pti_request_masterchannel(0);
+			pti_tty_data->mc = pti_request_masterchannel(0, NULL);
 		else
-			pti_tty_data->mc = pti_request_masterchannel(2);
+			pti_tty_data->mc = pti_request_masterchannel(2, NULL);
 
 		if (pti_tty_data->mc == NULL) {
 			kfree(pti_tty_data);
@@ -563,7 +584,7 @@ static int pti_char_open(struct inode *inode, struct file *filp)
 	 * before assigning the value to filp->private_data.
 	 * Slightly easier to debug if this driver needs debugging.
 	 */
-	mc = pti_request_masterchannel(0);
+	mc = pti_request_masterchannel(0, NULL);
 	if (mc == NULL)
 		return -ENOMEM;
 	filp->private_data = mc;
diff --git a/include/linux/pti.h b/include/linux/pti.h
index 81af667..b3ea01a 100644
--- a/include/linux/pti.h
+++ b/include/linux/pti.h
@@ -36,7 +36,8 @@ struct pti_masterchannel {
 
 /* the following functions are defined in misc/pti.c */
 void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count);
-struct pti_masterchannel *pti_request_masterchannel(u8 type);
+struct pti_masterchannel *pti_request_masterchannel(u8 type,
+						    const char *thread_name);
 void pti_release_masterchannel(struct pti_masterchannel *mc);
 
 #endif /*PTI_H_*/
-- 
1.7.2.3


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

* [PATCH] 0 for o PTI Makefile bug.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (36 preceding siblings ...)
  2011-06-17 22:09 ` [PATCH] PTI feature to allow user to name and mark masterchannel request james_p_freyensee
@ 2011-06-17 22:13 ` james_p_freyensee
  2011-07-07 19:24 ` [PATCH] Add PCI config dependency for PTI james_p_freyensee
                   ` (3 subsequent siblings)
  41 siblings, 0 replies; 171+ messages in thread
From: james_p_freyensee @ 2011-06-17 22:13 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, christophe.guerard, james_p_freyensee, rocher.jeremy

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch fixes an issue where 'obj' was actually
spelled '0bj' and would skip compiling the pti driver.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 5f03172..fa429f5 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -6,7 +6,7 @@ obj-$(CONFIG_IBM_ASM)		+= ibmasm/
 obj-$(CONFIG_AD525X_DPOT)	+= ad525x_dpot.o
 obj-$(CONFIG_AD525X_DPOT_I2C)	+= ad525x_dpot-i2c.o
 obj-$(CONFIG_AD525X_DPOT_SPI)	+= ad525x_dpot-spi.o
-0bj-$(CONFIG_INTEL_MID_PTI)	+= pti.o
+obj-$(CONFIG_INTEL_MID_PTI)	+= pti.o
 obj-$(CONFIG_ATMEL_PWM)		+= atmel_pwm.o
 obj-$(CONFIG_ATMEL_SSC)		+= atmel-ssc.o
 obj-$(CONFIG_ATMEL_TCLIB)	+= atmel_tclib.o
-- 
1.7.2.3


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

* [PATCH] Add PCI config dependency for PTI.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (37 preceding siblings ...)
  2011-06-17 22:13 ` [PATCH] 0 for o PTI Makefile bug james_p_freyensee
@ 2011-07-07 19:24 ` james_p_freyensee
  2011-07-07 19:31   ` Randy Dunlap
  2011-07-07 21:12 ` james_p_freyensee
                   ` (2 subsequent siblings)
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-07-07 19:24 UTC (permalink / raw)
  To: linux-next
  Cc: linux-kernel, randy.dunlap, sfr, christophe.guerard, pranav.k.sanghadia

From: J Freyensee <james_p_freyensee@linux.intel.com>

Intel-Atom implementation of PTI will not work with PCI
configured off, so the pti driver should not be compiled
in the event someone does not enable PCI in the linux kernel.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
Acked-by: Randy Dunlap <randy.dunlap@oracle.com>
Acked-by: Stephen Rothwell <sfr@canb.auug.org.au>
---
 drivers/misc/Kconfig |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4e349cd..7fd32a6 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -146,6 +146,7 @@ config PHANTOM
 
 config INTEL_MID_PTI
 	tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
+	depends on PCI
 	default n
 	help
 	  The PTI (Parallel Trace Interface) driver directs
-- 
1.7.0.4


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

* Re: [PATCH] Add PCI config dependency for PTI.
  2011-07-07 19:24 ` [PATCH] Add PCI config dependency for PTI james_p_freyensee
@ 2011-07-07 19:31   ` Randy Dunlap
  2011-07-07 19:59     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Randy Dunlap @ 2011-07-07 19:31 UTC (permalink / raw)
  To: james_p_freyensee
  Cc: linux-next, linux-kernel, randy.dunlap, sfr, christophe.guerard,
	pranav.k.sanghadia

On Thu,  7 Jul 2011 12:24:13 -0700 james_p_freyensee@linux.intel.com wrote:

> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> Intel-Atom implementation of PTI will not work with PCI
> configured off, so the pti driver should not be compiled
> in the event someone does not enable PCI in the linux kernel.
> 
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> Acked-by: Randy Dunlap <randy.dunlap@oracle.com>

now you can say that above. ^^^

Also
Reported-by: Randy Dunlap <randy.dunlap@oracle.com>

Thanks.

> Acked-by: Stephen Rothwell <sfr@canb.auug.org.au>
> ---
>  drivers/misc/Kconfig |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 4e349cd..7fd32a6 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -146,6 +146,7 @@ config PHANTOM
>  
>  config INTEL_MID_PTI
>  	tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
> +	depends on PCI
>  	default n
>  	help
>  	  The PTI (Parallel Trace Interface) driver directs
> -- 


---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* Re: [PATCH] Add PCI config dependency for PTI.
  2011-07-07 19:31   ` Randy Dunlap
@ 2011-07-07 19:59     ` J Freyensee
  2011-07-07 20:59       ` Randy Dunlap
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-07-07 19:59 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: linux-next, linux-kernel, sfr, christophe.guerard, pranav.k.sanghadia

On 07/07/2011 12:31 PM, Randy Dunlap wrote:
> On Thu,  7 Jul 2011 12:24:13 -0700 james_p_freyensee@linux.intel.com wrote:
>
>> From: J Freyensee<james_p_freyensee@linux.intel.com>
>>
>> Intel-Atom implementation of PTI will not work with PCI
>> configured off, so the pti driver should not be compiled
>> in the event someone does not enable PCI in the linux kernel.
>>
>> Signed-off-by: J Freyensee<james_p_freyensee@linux.intel.com>
>> Acked-by: Randy Dunlap<randy.dunlap@oracle.com>
> now you can say that above. ^^^
So you want me to stick the 'Acked-by' and 'Reported-by' above the 
Signed-off-by line?

> Also
> Reported-by: Randy Dunlap<randy.dunlap@oracle.com>
>
> Thanks.
>
>> Acked-by: Stephen Rothwell<sfr@canb.auug.org.au>
>> ---
>>   drivers/misc/Kconfig |    1 +
>>   1 files changed, 1 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
>> index 4e349cd..7fd32a6 100644
>> --- a/drivers/misc/Kconfig
>> +++ b/drivers/misc/Kconfig
>> @@ -146,6 +146,7 @@ config PHANTOM
>>
>>   config INTEL_MID_PTI
>>   	tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
>> +	depends on PCI
>>   	default n
>>   	help
>>   	  The PTI (Parallel Trace Interface) driver directs
>> -- 
>
> ---
> ~Randy
> *** Remember to use Documentation/SubmitChecklist when testing your code ***


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

* Re: [PATCH] Add PCI config dependency for PTI.
  2011-07-07 19:59     ` J Freyensee
@ 2011-07-07 20:59       ` Randy Dunlap
  0 siblings, 0 replies; 171+ messages in thread
From: Randy Dunlap @ 2011-07-07 20:59 UTC (permalink / raw)
  To: J Freyensee
  Cc: linux-next, linux-kernel, sfr, christophe.guerard, pranav.k.sanghadia

On 07/07/11 12:59, J Freyensee wrote:
> On 07/07/2011 12:31 PM, Randy Dunlap wrote:
>> On Thu,  7 Jul 2011 12:24:13 -0700 james_p_freyensee@linux.intel.com
>> wrote:
>>
>>> From: J Freyensee<james_p_freyensee@linux.intel.com>
>>>
>>> Intel-Atom implementation of PTI will not work with PCI
>>> configured off, so the pti driver should not be compiled
>>> in the event someone does not enable PCI in the linux kernel.
>>>
>>> Signed-off-by: J Freyensee<james_p_freyensee@linux.intel.com>
>>> Acked-by: Randy Dunlap<randy.dunlap@oracle.com>
>> now you can say that above. ^^^
> So you want me to stick the 'Acked-by' and 'Reported-by' above the
> Signed-off-by line?

You had Acked-by: prematurely.

Yes, now you can put both Acked-by: and Reported-by:
above the S-O-B: line.

>> Also
>> Reported-by: Randy Dunlap<randy.dunlap@oracle.com>
>>
>> Thanks.
>>
>>> Acked-by: Stephen Rothwell<sfr@canb.auug.org.au>
>>> ---
>>>   drivers/misc/Kconfig |    1 +
>>>   1 files changed, 1 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
>>> index 4e349cd..7fd32a6 100644
>>> --- a/drivers/misc/Kconfig
>>> +++ b/drivers/misc/Kconfig
>>> @@ -146,6 +146,7 @@ config PHANTOM
>>>
>>>   config INTEL_MID_PTI
>>>       tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG
>>> standard"
>>> +    depends on PCI
>>>       default n
>>>       help
>>>         The PTI (Parallel Trace Interface) driver directs
>>> -- 
>>
>> ---
>> ~Randy
>> *** Remember to use Documentation/SubmitChecklist when testing your
>> code ***
> 


-- 
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* [PATCH] Add PCI config dependency for PTI.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (38 preceding siblings ...)
  2011-07-07 19:24 ` [PATCH] Add PCI config dependency for PTI james_p_freyensee
@ 2011-07-07 21:12 ` james_p_freyensee
  2011-07-07 21:17   ` Randy Dunlap
  2011-07-07 22:02 ` james_p_freyensee
  2011-07-08 21:34 ` [PATCH] PTI implicit declaration fix james_p_freyensee
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-07-07 21:12 UTC (permalink / raw)
  To: linux-next
  Cc: linux-kernel, randy.dunlap, sfr, christophe.guerard,
	pranav.k.sanghadia, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

Intel-Atom implementation of PTI will not work with PCI
configured off, so the pti driver should not be compiled
in the event someone does not enable PCI in the linux kernel.

Reported-by: Randy Dunlap <randy.dunlap@oracle.com>
Acked-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/Kconfig |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4e349cd..7fd32a6 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -146,6 +146,7 @@ config PHANTOM
 
 config INTEL_MID_PTI
 	tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
+	depends on PCI
 	default n
 	help
 	  The PTI (Parallel Trace Interface) driver directs
-- 
1.7.0.4


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

* Re: [PATCH] Add PCI config dependency for PTI.
  2011-07-07 21:12 ` james_p_freyensee
@ 2011-07-07 21:17   ` Randy Dunlap
  0 siblings, 0 replies; 171+ messages in thread
From: Randy Dunlap @ 2011-07-07 21:17 UTC (permalink / raw)
  To: james_p_freyensee
  Cc: linux-next, linux-kernel, sfr, christophe.guerard, pranav.k.sanghadia

On 07/07/11 14:12, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> Intel-Atom implementation of PTI will not work with PCI
> configured off, so the pti driver should not be compiled
> in the event someone does not enable PCI in the linux kernel.
> 
> Reported-by: Randy Dunlap <randy.dunlap@oracle.com>
> Acked-by: Stephen Rothwell <sfr@canb.auug.org.au>

Acked-by: Randy Dunlap <randy.dunlap@oracle.com>

Yes, that also.

Thanks.

> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> ---
>  drivers/misc/Kconfig |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 4e349cd..7fd32a6 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -146,6 +146,7 @@ config PHANTOM
>  
>  config INTEL_MID_PTI
>  	tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
> +	depends on PCI
>  	default n
>  	help
>  	  The PTI (Parallel Trace Interface) driver directs


-- 
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* [PATCH] Add PCI config dependency for PTI.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (39 preceding siblings ...)
  2011-07-07 21:12 ` james_p_freyensee
@ 2011-07-07 22:02 ` james_p_freyensee
  2011-07-07 22:09   ` Randy Dunlap
  2011-07-08 21:34 ` [PATCH] PTI implicit declaration fix james_p_freyensee
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-07-07 22:02 UTC (permalink / raw)
  To: linux-next
  Cc: linux-kernel, randy.dunlap, sfr, christophe.guerard,
	pranav.k.sanghadia, james_p_freyensee

From: J Freyensee <james_p_freyensee@linux.intel.com>

Intel-Atom implementation of PTI will not work with PCI
configured off, so the pti driver should not be compiled
in the event someone does not enable PCI in the linux kernel.

Reported-by: Randy Dunlap <randy.dunlap@oracle.com>
Acked-by: Randy Dunlap <randy.dunlap@oracle.com>
Acked-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/Kconfig |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4e349cd..7fd32a6 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -146,6 +146,7 @@ config PHANTOM
 
 config INTEL_MID_PTI
 	tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
+	depends on PCI
 	default n
 	help
 	  The PTI (Parallel Trace Interface) driver directs
-- 
1.7.0.4


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

* Re: [PATCH] Add PCI config dependency for PTI.
  2011-07-07 22:02 ` james_p_freyensee
@ 2011-07-07 22:09   ` Randy Dunlap
  0 siblings, 0 replies; 171+ messages in thread
From: Randy Dunlap @ 2011-07-07 22:09 UTC (permalink / raw)
  To: james_p_freyensee
  Cc: linux-next, linux-kernel, sfr, christophe.guerard, pranav.k.sanghadia

On 07/07/11 15:02, james_p_freyensee@linux.intel.com wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
> 
> Intel-Atom implementation of PTI will not work with PCI
> configured off, so the pti driver should not be compiled
> in the event someone does not enable PCI in the linux kernel.
> 
> Reported-by: Randy Dunlap <randy.dunlap@oracle.com>
> Acked-by: Randy Dunlap <randy.dunlap@oracle.com>
> Acked-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>

That's good.  Thanks.
Sorry this was so much trouble.

> ---
>  drivers/misc/Kconfig |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 4e349cd..7fd32a6 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -146,6 +146,7 @@ config PHANTOM
>  
>  config INTEL_MID_PTI
>  	tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
> +	depends on PCI
>  	default n
>  	help
>  	  The PTI (Parallel Trace Interface) driver directs


-- 
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* [PATCH] PTI implicit declaration fix.
       [not found] <james_p_freyensee@linux.intel.com>
                   ` (40 preceding siblings ...)
  2011-07-07 22:02 ` james_p_freyensee
@ 2011-07-08 21:34 ` james_p_freyensee
  2011-07-09  8:08   ` Geert Uytterhoeven
  41 siblings, 1 reply; 171+ messages in thread
From: james_p_freyensee @ 2011-07-08 21:34 UTC (permalink / raw)
  To: linux-next
  Cc: linux-kernel, randy.dunlap, sfr, christophe.guerard,
	pranav.k.sanghadia, geert

From: J Freyensee <james_p_freyensee@linux.intel.com>

In a certain compile configuration, functions like
'kmalloc' and 'copy_from_user' were coming up as
implicit errors.  This patch adds slab.h and
uaccess.h to the driver.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/misc/pti.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index 8653bd0..4ba4e5f 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -22,6 +22,8 @@
  */
 
 #include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
 #include <linux/sched.h>
 #include <linux/interrupt.h>
 #include <linux/console.h>
-- 
1.7.0.4


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

* Re: [PATCH] PTI implicit declaration fix.
  2011-07-08 21:34 ` [PATCH] PTI implicit declaration fix james_p_freyensee
@ 2011-07-09  8:08   ` Geert Uytterhoeven
  2011-07-11 16:10     ` J Freyensee
  0 siblings, 1 reply; 171+ messages in thread
From: Geert Uytterhoeven @ 2011-07-09  8:08 UTC (permalink / raw)
  To: james_p_freyensee
  Cc: linux-next, linux-kernel, randy.dunlap, sfr, christophe.guerard,
	pranav.k.sanghadia

On Fri, Jul 8, 2011 at 23:34,  <james_p_freyensee@linux.intel.com> wrote:
> From: J Freyensee <james_p_freyensee@linux.intel.com>
>
> In a certain compile configuration, functions like
> 'kmalloc' and 'copy_from_user' were coming up as
> implicit errors.  This patch adds slab.h and
> uaccess.h to the driver.
>
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>

Please don't add "Acked-by" lines before people have ack'ed your patches.

> Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
> ---
>  drivers/misc/pti.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
> index 8653bd0..4ba4e5f 100644
> --- a/drivers/misc/pti.c
> +++ b/drivers/misc/pti.c
> @@ -22,6 +22,8 @@
>  */
>
>  #include <linux/init.h>
> +#include <linux/slab.h>
> +#include <linux/uaccess.h>
>  #include <linux/sched.h>
>  #include <linux/interrupt.h>
>  #include <linux/console.h>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] PTI implicit declaration fix.
  2011-07-09  8:08   ` Geert Uytterhoeven
@ 2011-07-11 16:10     ` J Freyensee
  2011-07-11 16:57       ` Geert Uytterhoeven
  0 siblings, 1 reply; 171+ messages in thread
From: J Freyensee @ 2011-07-11 16:10 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-next, linux-kernel, randy.dunlap, sfr, christophe.guerard,
	pranav.k.sanghadia

On 07/09/2011 01:08 AM, Geert Uytterhoeven wrote:
> On Fri, Jul 8, 2011 at 23:34,<james_p_freyensee@linux.intel.com>  wrote:
>> From: J Freyensee<james_p_freyensee@linux.intel.com>
>>
>> In a certain compile configuration, functions like
>> 'kmalloc' and 'copy_from_user' were coming up as
>> implicit errors.  This patch adds slab.h and
>> uaccess.h to the driver.
>>
>> Reported-by: Geert Uytterhoeven<geert@linux-m68k.org>
>> Acked-by: Geert Uytterhoeven<geert@linux-m68k.org>
>
> Please don't add "Acked-by" lines before people have ack'ed your patches.
>

Okay...so should I re-send this patch out without the Acked-by in it? 
Or is it okay this time and next time please do this?

>> Signed-off-by: J Freyensee<james_p_freyensee@linux.intel.com>
>> ---
>>   drivers/misc/pti.c |    2 ++
>>   1 files changed, 2 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
>> index 8653bd0..4ba4e5f 100644
>> --- a/drivers/misc/pti.c
>> +++ b/drivers/misc/pti.c
>> @@ -22,6 +22,8 @@
>>   */
>>
>>   #include<linux/init.h>
>> +#include<linux/slab.h>
>> +#include<linux/uaccess.h>
>>   #include<linux/sched.h>
>>   #include<linux/interrupt.h>
>>   #include<linux/console.h>
>
> Gr{oetje,eeting}s,
>
>                          Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                  -- Linus Torvalds


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

* Re: [PATCH] PTI implicit declaration fix.
  2011-07-11 16:10     ` J Freyensee
@ 2011-07-11 16:57       ` Geert Uytterhoeven
  0 siblings, 0 replies; 171+ messages in thread
From: Geert Uytterhoeven @ 2011-07-11 16:57 UTC (permalink / raw)
  To: J Freyensee
  Cc: linux-next, linux-kernel, randy.dunlap, sfr, christophe.guerard,
	pranav.k.sanghadia

On Mon, Jul 11, 2011 at 18:10, J Freyensee
<james_p_freyensee@linux.intel.com> wrote:
> On 07/09/2011 01:08 AM, Geert Uytterhoeven wrote:
>> On Fri, Jul 8, 2011 at 23:34,<james_p_freyensee@linux.intel.com>  wrote:
>>>
>>> From: J Freyensee<james_p_freyensee@linux.intel.com>
>>>
>>> In a certain compile configuration, functions like
>>> 'kmalloc' and 'copy_from_user' were coming up as
>>> implicit errors.  This patch adds slab.h and
>>> uaccess.h to the driver.
>>>
>>> Reported-by: Geert Uytterhoeven<geert@linux-m68k.org>
>>> Acked-by: Geert Uytterhoeven<geert@linux-m68k.org>
>>
>> Please don't add "Acked-by" lines before people have ack'ed your patches.
>>
>
> Okay...so should I re-send this patch out without the Acked-by in it? Or is
> it okay this time and next time please do this?

It's OK for now. It's a trivial patch anyway.

>>> Signed-off-by: J Freyensee<james_p_freyensee@linux.intel.com>
>>> ---
>>>  drivers/misc/pti.c |    2 ++
>>>  1 files changed, 2 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
>>> index 8653bd0..4ba4e5f 100644
>>> --- a/drivers/misc/pti.c
>>> +++ b/drivers/misc/pti.c
>>> @@ -22,6 +22,8 @@
>>>  */
>>>
>>>  #include<linux/init.h>
>>> +#include<linux/slab.h>
>>> +#include<linux/uaccess.h>
>>>  #include<linux/sched.h>
>>>  #include<linux/interrupt.h>
>>>  #include<linux/console.h>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2011-07-11 16:57 UTC | newest]

Thread overview: 171+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <james_p_freyensee@linux.intel.com>
2011-02-08 19:34 ` Resend: Request for review and addition of PTI implementation into kernel james_p_freyensee
2011-02-08 19:34   ` [PATCH 01/12] export kernel call get_task_comm() james_p_freyensee
2011-02-08 19:34     ` [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
2011-02-08 19:34       ` [PATCH 03/12] Intel PTI implementaiton of 1149 james_p_freyensee
2011-02-08 19:34         ` [PATCH 04/12] PTI Kconfig change in misc james_p_freyensee
2011-02-08 19:34           ` [PATCH 05/12] PTI misc Makefile addition james_p_freyensee
2011-02-08 19:34             ` [PATCH 06/12] PTI header file james_p_freyensee
2011-02-08 19:34               ` [PATCH 07/12] n_tracerouter and n_tracesink additions james_p_freyensee
2011-02-08 19:34                 ` [PATCH 08/12] n_tracesink ldisc addition james_p_freyensee
2011-02-08 19:34                   ` [PATCH 09/12] n_tracesink header file james_p_freyensee
2011-02-08 19:34                     ` [PATCH 10/12] n_tracerouter ldisc driver james_p_freyensee
2011-02-08 19:34                       ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig james_p_freyensee
2011-02-08 19:34                         ` [PATCH 12/12] n_tracerouter and n_tracesink Makefile addition james_p_freyensee
2011-02-08 21:03                         ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig Randy Dunlap
2011-02-17 19:23                     ` [PATCH 09/12] n_tracesink header file Greg KH
2011-02-17 19:45                       ` J Freyensee
2011-02-17 19:54                         ` Greg KH
2011-02-17 20:10                           ` J Freyensee
2011-02-17 21:43                             ` Greg KH
2011-02-22 20:22                               ` J Freyensee
2011-02-22 20:26                                 ` Greg KH
2011-02-22 22:55                                   ` J Freyensee
2011-02-17 19:21                 ` [PATCH 07/12] n_tracerouter and n_tracesink additions Greg KH
2011-02-17 19:43                   ` J Freyensee
2011-02-17 19:54                     ` Greg KH
2011-02-17 20:11                       ` J Freyensee
2011-02-24 11:52                     ` Alan Cox
2011-02-17 19:20               ` [PATCH 06/12] PTI header file Greg KH
2011-02-17 19:41                 ` J Freyensee
2011-02-17 19:55                   ` Greg KH
2011-02-17 20:13                     ` J Freyensee
2011-02-17 19:20           ` [PATCH 04/12] PTI Kconfig change in misc Greg KH
2011-02-17 19:35             ` J Freyensee
2011-02-17 19:45               ` Greg KH
2011-02-08 20:55       ` [PATCH 02/12] Kernel documentation for the PTI feature Randy Dunlap
2011-02-08 19:38     ` [PATCH 01/12] export kernel call get_task_comm() Christoph Hellwig
2011-02-08 19:44       ` james_p_freyensee
2011-02-08 20:04         ` Christoph Hellwig
2011-02-08 20:35           ` james_p_freyensee
2011-02-08 20:28         ` Alan Cox
2011-02-08 20:28           ` Christoph Hellwig
2011-02-08 20:36             ` Alan Cox
2011-02-15 10:57               ` Christoph Hellwig
2011-02-22 18:38     ` J Freyensee
2011-02-22 18:41       ` Greg KH
2011-02-09  0:17 ` [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
2011-02-09  0:17   ` [PATCH 03/12] Intel PTI implementaiton of 1149 james_p_freyensee
2011-02-09  0:17     ` [PATCH 04/12] PTI Kconfig change in misc james_p_freyensee
2011-02-09  0:17       ` [PATCH 05/12] PTI misc Makefile addition james_p_freyensee
2011-02-09  0:17         ` [PATCH 06/12] PTI header file james_p_freyensee
2011-02-09  0:17           ` [PATCH 07/12] n_tracerouter and n_tracesink additions james_p_freyensee
2011-02-09  0:17             ` [PATCH 08/12] n_tracesink ldisc addition james_p_freyensee
2011-02-09  0:17               ` [PATCH 09/12] n_tracesink header file james_p_freyensee
2011-02-09  0:17                 ` [PATCH 10/12] n_tracerouter ldisc driver james_p_freyensee
2011-02-09  0:17                   ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig james_p_freyensee
2011-02-09  0:17                     ` [PATCH 12/12] n_tracerouter and n_tracesink Makefile addition james_p_freyensee
2011-02-09  0:19                       ` james_p_freyensee
     [not found]                       ` <57934.10.23.16.85.1297210742.squirrel@linux.intel.com>
2011-02-09  0:34                         ` PTI- PLEASE IGNORE SECOND DUPLICATE 12 PATCH SET james_p_freyensee
2011-02-24 18:06 ` 2nd request for review and addition of PTI implementation into kernel james_p_freyensee
2011-02-24 18:06 ` [PATCH 01/10] export kernel call get_task_comm() james_p_freyensee
2011-02-24 18:06 ` [PATCH 02/10] Kernel documentation for the PTI feature james_p_freyensee
2011-02-24 18:06 ` [PATCH 03/10] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
2011-02-28  9:28   ` Arnd Bergmann
2011-02-28 17:46     ` J Freyensee
2011-02-28 18:36       ` Thomas Gleixner
2011-02-24 18:06 ` [PATCH 04/10] PTI Makefile and Kconfig additions james_p_freyensee
2011-02-28  9:31   ` Arnd Bergmann
2011-02-28 17:49     ` J Freyensee
2011-03-01 11:37       ` Arnd Bergmann
2011-03-01 17:37         ` J Freyensee
2011-02-24 18:06 ` [PATCH 05/10] PTI header file james_p_freyensee
2011-02-28  9:30   ` Arnd Bergmann
2011-02-24 18:07 ` [PATCH 06/10] n_tracerouter and n_tracesink additions james_p_freyensee
2011-02-24 18:07 ` [PATCH 07/10] n_tracesink ldisc addition james_p_freyensee
2011-02-24 18:07 ` [PATCH 08/10] n_tracesink header file james_p_freyensee
2011-02-24 18:07 ` [PATCH 09/10] n_tracerouter ldisc driver james_p_freyensee
2011-02-24 19:20   ` Thomas Gleixner
2011-02-24 20:20     ` J Freyensee
2011-02-24 20:27       ` Thomas Gleixner
2011-02-24 18:07 ` [PATCH 10/10] n_tracerouter and n_tracesink compile configurations james_p_freyensee
2011-02-25 18:00   ` Greg KH
2011-02-25 18:39     ` J Freyensee
2011-02-25 18:45       ` Greg KH
2011-02-25 18:01   ` Greg KH
2011-04-19 22:58 ` 3rd request for review & addition of PTI/n_trace implementation into kernel james_p_freyensee
2011-04-19 22:58 ` [PATCH 1/4] export kernel call get_task_comm() james_p_freyensee
2011-04-19 23:22   ` David Rientjes
2011-04-20  0:10     ` J Freyensee
2011-04-20  1:22       ` David Rientjes
2011-04-20  1:43         ` Greg KH
2011-04-20 18:11           ` J Freyensee
2011-04-20 19:14             ` Greg KH
2011-04-20 23:11               ` Andrew Morton
2011-04-20 23:16                 ` J Freyensee
2011-04-20 23:46                   ` Andrew Morton
2011-04-21 16:12                     ` J Freyensee
2011-04-20 23:19                 ` David Rientjes
2011-04-19 22:58 ` [PATCH 2/4] Kernel documentation for the PTI feature james_p_freyensee
2011-04-19 23:26   ` Randy Dunlap
2011-04-19 22:58 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
2011-04-19 23:15   ` Randy Dunlap
2011-04-20 23:05     ` J Freyensee
2011-04-20 23:10       ` Randy Dunlap
2011-04-21 21:06         ` J Freyensee
2011-04-21 21:17           ` Randy Dunlap
2011-04-20  1:25   ` David Rientjes
2011-04-20  9:46     ` Alan Cox
2011-04-20 18:07       ` J Freyensee
2011-04-22 17:57     ` J Freyensee
2011-04-19 22:58 ` [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions james_p_freyensee
2011-04-19 23:20   ` Randy Dunlap
2011-04-20  0:05     ` J Freyensee
2011-04-20  0:14       ` Randy Dunlap
2011-04-22 22:26 ` export kernel call get_task_comm for driver use james_p_freyensee
2011-04-22 22:35   ` Greg KH
2011-04-22 22:26 ` [PATCH] export kernel call get_task_comm() james_p_freyensee
2011-04-22 22:35   ` David Rientjes
2011-04-22 22:43     ` J Freyensee
2011-04-22 22:35 ` Resend: export kernel call get_task_comm for driver use james_p_freyensee
2011-04-22 22:35 ` [PATCH] export kernel call get_task_comm() james_p_freyensee
2011-04-22 22:43   ` Greg KH
2011-04-22 22:59     ` J Freyensee
2011-04-22 23:04       ` Greg KH
2011-04-22 23:08         ` J Freyensee
2011-04-22 23:17           ` Greg KH
2011-04-22 23:19       ` David Rientjes
2011-04-22 23:32 ` Request for review and addition of PTI implementation into kernel james_p_freyensee
2011-04-22 23:32 ` [PATCH 1/4] export kernel call get_task_comm() james_p_freyensee
2011-04-25 20:57   ` David Rientjes
2011-05-05 16:59     ` J Freyensee
2011-05-05 18:55       ` David Rientjes
2011-04-22 23:32 ` [PATCH 2/4] Kernel documentation for the PTI feature james_p_freyensee
2011-04-22 23:32 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
2011-04-24  0:55   ` Jesper Juhl
2011-04-24  1:08     ` Jesper Juhl
2011-05-05 17:06       ` J Freyensee
2011-05-05 20:37         ` Jesper Juhl
2011-05-05 17:27     ` J Freyensee
2011-05-05 20:42       ` Jesper Juhl
2011-05-05 22:30       ` J Freyensee
2011-04-22 23:32 ` [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions james_p_freyensee
2011-04-24  1:04   ` Jesper Juhl
2011-04-24  1:51     ` Greg KH
2011-04-24 23:03       ` Jesper Juhl
2011-04-29 17:02     ` J Freyensee
2011-05-05 17:08     ` J Freyensee
2011-05-06 23:56 ` Request for review and addition of PTI implementation into kernel james_p_freyensee
2011-05-07  0:33   ` Greg KH
2011-05-09 19:07     ` J Freyensee
2011-05-06 23:56 ` [PATCH 1/4] export kernel call get_task_comm() james_p_freyensee
2011-05-06 23:56 ` [PATCH 2/4] Kernel documentation for the PTI feature james_p_freyensee
2011-05-06 23:56 ` [PATCH 3/4] Intel PTI implementaiton of MIPI 1149.7 james_p_freyensee
2011-05-06 23:56 ` [PATCH 4/4] n_tracerouter and n_tracesink ldisc additions james_p_freyensee
2011-05-25 21:38 ` [PATCH] double-free security PTI fix james_p_freyensee
2011-05-25 21:45 ` [PATCH] ENXIO error case memory leak " james_p_freyensee
2011-05-25 21:50 ` [PATCH] pti_tty_install documentation mispelling james_p_freyensee
2011-05-25 21:56 ` [PATCH] PTI semantics fix in pti_tty_cleanup james_p_freyensee
2011-06-17 22:09 ` [PATCH] PTI feature to allow user to name and mark masterchannel request james_p_freyensee
2011-06-17 22:13 ` [PATCH] 0 for o PTI Makefile bug james_p_freyensee
2011-07-07 19:24 ` [PATCH] Add PCI config dependency for PTI james_p_freyensee
2011-07-07 19:31   ` Randy Dunlap
2011-07-07 19:59     ` J Freyensee
2011-07-07 20:59       ` Randy Dunlap
2011-07-07 21:12 ` james_p_freyensee
2011-07-07 21:17   ` Randy Dunlap
2011-07-07 22:02 ` james_p_freyensee
2011-07-07 22:09   ` Randy Dunlap
2011-07-08 21:34 ` [PATCH] PTI implicit declaration fix james_p_freyensee
2011-07-09  8:08   ` Geert Uytterhoeven
2011-07-11 16:10     ` J Freyensee
2011-07-11 16:57       ` Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).