aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/pti/pti_intel_mid.txt
blob: 651fcf51d2d7c0b4c7a1328e4c87f121969b8c52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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);