tspp.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. Introduction
  2. ============
  3. The TSPP (Transport stream packet processor) is a hardware accelerator
  4. designed to process MPEG2 TS (transport stream) data. It is mainly used for
  5. broadcast terrestrial services to off-load the host CPU from real-time
  6. sensitive TS processing for high bandwidth streams (~20Mbps). Data is received
  7. either via TSIF (Transport stream interface) or system memory.
  8. The TSPP driver manages the TSIF 12Seg HW core, which consists of a TSPP, a
  9. BAM (Bus access manager, used for DMA) and two TSIF inputs.
  10. It is applicable to the TSIF 12Seg core found on select Qualcomm MSM chips.
  11. For more information on the TSIF interface, please refer to TSIF documentation
  12. (Documentation/arm/msm/tsif.txt).
  13. For more information on the BAM interface, please refer to SPS documentation
  14. (Documentation/dma/sps/sps_architecture.txt).
  15. Hardware description
  16. ====================
  17. The TSPP unit expands the capabilities of the TSIF interface by adding MPEG2
  18. stream processing such as:
  19. - Elementary Stream PID filtering and de-multiplexing
  20. - Several TSP processing operation modes:
  21. - TSP Raw processing (with or w/o suffix)
  22. - TSP PES assembly
  23. - Error handling
  24. - Multi2 decryption
  25. +-------------+ +------+
  26. +>|ARM subsystem| |Memory|
  27. | +-------------+ +------+
  28. | | |
  29. I| | |
  30. R| ========================== System bus
  31. Q| |
  32. s| | TSIF 12Seg
  33. | +-----------------------+
  34. | | +---+ |
  35. | | |BAM| |
  36. | | +---+ | GPIOs
  37. | | | +------+--|-------- TSIF 0 clk
  38. | | +----+ |TSIF 0|--|-------- TSIF 0 data
  39. +-| | |-----+------+--|-------- TSIF 0 en
  40. | |TSPP| |
  41. | | |-----+------+--|-------- TSIF 1 clk
  42. | +----+ |TSIF 1|--|-------- TSIF 1 data
  43. | +------+--|-------- TSIF 1 en
  44. +-----------------------+
  45. The TSPP unit receives an MPEG2 transport stream either via the two TSIF
  46. interfaces, or via system memory.
  47. It uses the BAM interface to transfer data to and from system memory.
  48. The ARM subsystem receives interrupts on various error conditions from TSPP
  49. and TSIF units, and on data transfer events from the BAM.
  50. Software Description
  51. ====================
  52. The TSPP driver is responsible for:
  53. - TSPP/TSIF hardware configuration (using SPS driver to configure BAM
  54. hardware)
  55. - TSIF GPIO/Clocks configuration
  56. - Memory resource management
  57. - Handling TSIF/TSPP interrupts and BAM events
  58. - TSPP Power management
  59. TSPP Terminology
  60. ----------------
  61. Device - the TSPP hardware instance
  62. - the device contains many streams
  63. Stream: All data that is received from a particular TS packet source
  64. - For example, MPEG2 Transport Stream from TSIF0
  65. - A stream can consist of many channels
  66. Channel: A channel routes part of a stream to a specified memory location
  67. - For example, video and audio can be routed to different memory locations
  68. using different channels
  69. - Channel contents are defined by filters
  70. Filter: Enables TS packet filtering and routing according to PID (packet ID)
  71. - The decision regarding which PIDs in the stream will be routed to a
  72. channel is done via filters
  73. - Several filters can be registered to the same channel
  74. - Filters can pass TS packets as-is (Raw mode) or assemble them into PES
  75. packets (PES mode)
  76. - Groups of contiguous PIDs can be filtered together (i.e. PSI/SI 0x0-0x2F,
  77. 1Seg PMTs 0x1FC8-0x1FCF)
  78. - Filters can be used to discard packets (e.g. eliminate processing of
  79. unwanted channels)
  80. Init flow:
  81. ----------
  82. Driver registers BAM (via SPS driver) and initializes TSIF/TSPP hardware.
  83. Control path:
  84. -------------
  85. 1. Client opens a TSPP stream and channel
  86. 2. Client notifies the driver of the source stream (TSIF0/TSIF1/Memory)
  87. - TSPP driver allocates memory for the channel (circular buffer)
  88. - As the amount of memory varies according to stream bandwidth (which the
  89. driver doesn't know), a client can hint to the driver about the required
  90. memory or stream bandwidth
  91. - TSPP driver configures TSIF/BAM hardware according to selected stream
  92. 3. Client notifies the driver to filter a set of PIDs for the selected channel
  93. - TSPP driver configures TSPP hardware filters accordingly
  94. 4. Client can now read data received from the selected channel
  95. Optional: Scrambling keys can be configured for a filter to decrypt Multi2
  96. encrypted streams. The scrambling keys are received encrypted in-stream every
  97. ~2 seconds. The client uses a smart card and master key to decrypt the
  98. received scrambling keys. The master key remains inside the smart card and is
  99. never revealed to software.
  100. Conceptual flow:
  101. Client TSPP Driver SPS Driver Hardware
  102. | | | |
  103. | | Init TSIF/TSPP | |
  104. | |---------------------------|------------------>|
  105. | | Register BAM | |
  106. | |-------------------------->| |
  107. | | | |
  108. | open(tspp.5) | | |
  109. |-------------------------->| | |
  110. | ioctl(tspp.5,SOURCE,TSIF0)| | |
  111. |-------------------------->| | |
  112. | | buff[0..N] = alloc() | |
  113. | |----------> | |
  114. | | Connect(TSPP,MEM) | |
  115. | |-------------------------->| |
  116. | | Transfer(buff[0..N]) | |
  117. | |-------------------------->| |
  118. | | | |
  119. | | Configure TSIF0 | |
  120. | |---------------------------|------------------>|
  121. | | | |
  122. | ioctl(tspp.5,FILTER,pid) | | |
  123. |-------------------------->| | |
  124. | | Configure TSPP filters | |
  125. | |---------------------------|------------------>|
  126. | | | |
  127. | | | INT |
  128. | | |<------------------|
  129. | | notify(EOT,buff[x]) | |
  130. | |<--------------------------| |
  131. | | Transfer(buff[y]) | |
  132. | |-------------------------->| |
  133. | | | |
  134. | read(tspp.5) | | |
  135. |-------------------------->| | |
  136. | | | |
  137. Data path:
  138. ----------
  139. The TSPP driver is not involved in data transfer, other than managing the
  140. circular buffer pointers when a transfer is complete. Data loss can occur if
  141. a client cannot keep up with stream bandwidth.
  142. The driver does not notify the application if there is data loss. It is
  143. assumed that the application will read data when the data is ready, and when
  144. the application is able.
  145. API
  146. ===
  147. int tspp_open_stream(u32 dev, u32 channel, struct tspp_select_source *source);
  148. int tspp_close_stream(u32 dev, u32 channel);
  149. int tspp_open_channel(u32 dev, u32 channel);
  150. int tspp_close_channelu(32 dev, u32 channel);
  151. int tspp_add_filter(u32 dev, u32 channel, struct tspp_filter *filter);
  152. int tspp_remove_filter(u32 dev, u32 channel, struct tspp_filter *filter);
  153. Refer to chrdev implementation in kernel/drivers/misc/tspp.c for an example of
  154. how to use this api.
  155. Each stream is represented by a chrdev device
  156. 16 available devices: /dev/tspp00 - /dev/tspp15
  157. Each device implements these functions:
  158. open()
  159. close()
  160. read()
  161. ioctl()
  162. ioctl() contains several sub-functions:
  163. 0: select source
  164. 1: add filter
  165. 2: remove filter
  166. 3: set decryption keys
  167. 4: set initial cbc values (IV)
  168. 5: set system keys
  169. 6: set buffer size
  170. You can refer to include/linux/tspp.h for the details on the structures
  171. associated with these IOCTL calls.
  172. Design
  173. ======
  174. Design is based on the existing TSIF driver, with added control functionality
  175. for the extra hardware features.
  176. Power Management
  177. ===============
  178. TSPP driver prevents MSM from sleeping while TSPP hardware is active.
  179. To achieve this, the driver holds the wake lock. When no channels are
  180. configured to receive data, the driver stops the clocks to save power.
  181. It will register for suspend/resume in the future.
  182. SMP/multi-core
  183. ==============
  184. Driver is fully SMP aware.
  185. Performance
  186. ===========
  187. Control flows are rare.
  188. Data path only involves maintaining the circular buffer pointers.
  189. Interface
  190. =========
  191. Driver exposes a char device interface to user-space for each channel.
  192. Control transactions are performed via ioctl on the channel. Data is read as
  193. any regular char device (blocking and non-blocking). Please see sequence
  194. under software description for more info.
  195. Debugfs may be used for debug purposes. Through debugfs, all of the TSIF
  196. registers can be accessed under /sys/kernel/debug/tsif0 and tsif1. The
  197. TSPP registers are found under /sys/kernel/debug/tspp0. If you cannot
  198. see these devices, then either the driver has been built without debugfs
  199. support (check the define TSPP_USE_DEBUGFS in tspp.c) or the debugfs has
  200. not been mounted correctly (or mounted in a different location).
  201. Driver Parameters
  202. =================
  203. TSPP driver has target-specific parameters:
  204. - Memory base addresses for TSIF/TSPP/BAM
  205. - TSIF/TSPP/BAM IRQ numbers
  206. - TSIF GPIO numbers
  207. Config Options
  208. ==============
  209. To enable the driver, set CONFIG_TSPP (=y or =m) in the appropriate
  210. config file for the platform.
  211. Dependencies
  212. ============
  213. The TSPP driver depends on the SPS driver to configure BAM hardware.
  214. User space utilities
  215. ====================
  216. The TSPP test suite can be found in:
  217. vendor/qcom/proprietary/kernel-tests/tspp
  218. Known Issues
  219. ============
  220. Currently PES processing mode cannot be configured for streams in which the PES
  221. length is 0. This is a HW limitation.