pti_intel_mid.txt 3.6 KB

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