Commit | Line | Data |
---|---|---|
baa293e9 | 1 | .. SPDX-License-Identifier: GPL-2.0 |
93d2c159 MCC |
2 | |
3 | ============= | |
4 | Intel MID PTI | |
5 | ============= | |
6 | ||
7 | The Intel MID PTI project is HW implemented in Intel Atom | |
8 | system-on-a-chip designs based on the Parallel Trace | |
9 | Interface for MIPI P1149.7 cJTAG standard. The kernel solution | |
10 | for this platform involves the following files:: | |
11 | ||
12 | ./include/linux/pti.h | |
13 | ./drivers/.../n_tracesink.h | |
14 | ./drivers/.../n_tracerouter.c | |
15 | ./drivers/.../n_tracesink.c | |
16 | ./drivers/.../pti.c | |
17 | ||
18 | pti.c is the driver that enables various debugging features | |
19 | popular on platforms from certain mobile manufacturers. | |
20 | n_tracerouter.c and n_tracesink.c allow extra system information to | |
21 | be collected and routed to the pti driver, such as trace | |
22 | debugging data from a modem. Although n_tracerouter | |
23 | and n_tracesink are a part of the complete PTI solution, | |
24 | these two line disciplines can work separately from | |
25 | pti.c and route any data stream from one /dev/tty node | |
26 | to another /dev/tty node via kernel-space. This provides | |
27 | a stable, reliable connection that will not break unless | |
28 | the user-space application shuts down (plus avoids | |
29 | kernel->user->kernel context switch overheads of routing | |
30 | data). | |
31 | ||
32 | An example debugging usage for this driver system: | |
33 | ||
34 | * Hook /dev/ttyPTI0 to syslogd. Opening this port will also start | |
35 | a console device to further capture debugging messages to PTI. | |
36 | * Hook /dev/ttyPTI1 to modem debugging data to write to PTI HW. | |
37 | This is where n_tracerouter and n_tracesink are used. | |
38 | * Hook /dev/pti to a user-level debugging application for writing | |
39 | to PTI HW. | |
40 | * `Use mipi_` Kernel Driver API in other device drivers for | |
41 | debugging to PTI by first requesting a PTI write address via | |
42 | mipi_request_masterchannel(1). | |
43 | ||
44 | Below is example pseudo-code on how a 'privileged' application | |
45 | can hook up n_tracerouter and n_tracesink to any tty on | |
46 | a system. 'Privileged' means the application has enough | |
47 | privileges to successfully manipulate the ldisc drivers | |
48 | but is not just blindly executing as 'root'. Keep in mind | |
49 | the use of ioctl(,TIOCSETD,) is not specific to the n_tracerouter | |
50 | and n_tracesink line discpline drivers but is a generic | |
51 | operation for a program to use a line discpline driver | |
52 | on a tty port other than the default n_tty:: | |
53 | ||
54 | /////////// To hook up n_tracerouter and n_tracesink ///////// | |
55 | ||
56 | // Note that n_tracerouter depends on n_tracesink. | |
57 | #include <errno.h> | |
58 | #define ONE_TTY "/dev/ttyOne" | |
59 | #define TWO_TTY "/dev/ttyTwo" | |
60 | ||
61 | // needed global to hand onto ldisc connection | |
62 | static int g_fd_source = -1; | |
63 | static int g_fd_sink = -1; | |
64 | ||
65 | // these two vars used to grab LDISC values from loaded ldisc drivers | |
66 | // in OS. Look at /proc/tty/ldiscs to get the right numbers from | |
67 | // the ldiscs loaded in the system. | |
68 | int source_ldisc_num, sink_ldisc_num = -1; | |
69 | int retval; | |
70 | ||
71 | g_fd_source = open(ONE_TTY, O_RDWR); // must be R/W | |
72 | g_fd_sink = open(TWO_TTY, O_RDWR); // must be R/W | |
73 | ||
74 | if (g_fd_source <= 0) || (g_fd_sink <= 0) { | |
75 | // doubt you'll want to use these exact error lines of code | |
76 | printf("Error on open(). errno: %d\n",errno); | |
77 | return errno; | |
78 | } | |
79 | ||
80 | retval = ioctl(g_fd_sink, TIOCSETD, &sink_ldisc_num); | |
81 | if (retval < 0) { | |
82 | printf("Error on ioctl(). errno: %d\n", errno); | |
83 | return errno; | |
84 | } | |
85 | ||
86 | retval = ioctl(g_fd_source, TIOCSETD, &source_ldisc_num); | |
87 | if (retval < 0) { | |
88 | printf("Error on ioctl(). errno: %d\n", errno); | |
89 | return errno; | |
90 | } | |
91 | ||
92 | /////////// To disconnect n_tracerouter and n_tracesink //////// | |
93 | ||
94 | // First make sure data through the ldiscs has stopped. | |
95 | ||
96 | // Second, disconnect ldiscs. This provides a | |
97 | // little cleaner shutdown on tty stack. | |
98 | sink_ldisc_num = 0; | |
99 | source_ldisc_num = 0; | |
100 | ioctl(g_fd_uart, TIOCSETD, &sink_ldisc_num); | |
101 | ioctl(g_fd_gadget, TIOCSETD, &source_ldisc_num); | |
102 | ||
103 | // Three, program closes connection, and cleanup: | |
104 | close(g_fd_uart); | |
105 | close(g_fd_gadget); | |
106 | g_fd_uart = g_fd_gadget = NULL; |