qcom-mpq.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. Introduction
  2. ============
  3. MPQ DVB Adapter implements Digital Video Broadcasting devices according
  4. to LinuxTV (linuxtv.org) defined API and infrastructure.
  5. The implemented devices are dvb/demux devices, dvb/dvr devices and
  6. dvb/video devices.
  7. These devices are used in Qualcomm's MPQ chipsets that support
  8. broadcast applications.
  9. dvb/demux is responsible to receive a digital stream broadcasted over
  10. the air from a hardware unit (TSPP - Transport stream packet processor,
  11. or TSIF - Transport Stream Interface) and separates the stream into its
  12. various sub-streams such as video, audio and auxiliary data.
  13. The separation operation is named demuxing.
  14. dvb/dvr is used in conjunction with dvb/demux to re-play a digital
  15. stream from memory or to record stream to memory.
  16. dvb/video is used to handle the video decoding, it receives compressed
  17. video from dvb/demux through a stream-buffer interface and interacts
  18. with the existing HW video driver to perform the decoding.
  19. For more information on the TSIF interface, please refer to TSIF
  20. documentation under "Documentation/arm/msm/tsif.txt".
  21. For more information on the TSPP interface, please refer to TSPP
  22. documentation under "Documentation/arm/msm/tspp.txt".
  23. For more information on DVB-API definition, please refer dvb
  24. documentation under "Documentation/dvb/readme.txt".
  25. Hardware description
  26. ====================
  27. dvb/demux, dvb/dvr and dvb/video do not interact with a hardware directly;
  28. The implementation of these drivers is done using the kernel API of TSPP,
  29. TSIF and video drivers.
  30. Software description
  31. ====================
  32. Terminology
  33. -----------
  34. Stream: A stream is a TS packet source
  35. - For example, MPEG2 Transport Stream from TSIF0
  36. Filter: Enables TS packet filtering and routing according to PID (packet ID)
  37. - The decision regarding which PIDs in the stream will be routed
  38. is done via filters, each demux open request corresponds to a filter.
  39. - Filters can pass TS packets as-is (for recording), assemble them into
  40. "other" PES packets (for PES packets read by client), assemble and send
  41. them to decoder (for decoder PES), or assemble them into sections.
  42. Service: A service is a set of PIDs as defined in the service PMT.
  43. Each service may be carried in a different transport stream or part of the
  44. same transport stream. Processing a service means either preparing the
  45. data for display and/or for recording.
  46. Requirments
  47. -----------
  48. 1. Demuxing from different sources:
  49. - Live transport stream inputs (TSIF)
  50. - Memory inputs
  51. 2. Support different packet formats:
  52. - 188-bytes transport packets
  53. - 192-bytes transport packets
  54. 3. PID filtering
  55. 4. Output of the following data:
  56. - Decoder PES: PES (video and/or audio) that can be directed to HW decoders
  57. in tunneling mode (without interaction of user-space).
  58. - Other PES: a non-decoder PES, such as subtitle, teletext. The consumer
  59. of this data is user-space that reads the data through standard read
  60. calls.
  61. - Sections: Sections are used by user-space to acquire different kinds of
  62. information such as channels list, program user guide, etc.
  63. - Transport Stream Packets: Transport stream packets of specific PIDs as
  64. they were received in the input stream. User-space can use those to
  65. record specific services and/or to perform time-shift buffer.
  66. - PCR/STC: Pairs of PCR/STC can be used by user-space to perform
  67. clock-recovery.
  68. - Frame-indexing: For recorded stream, demux provides indexing of the
  69. I-frames within the stream that can be used for trick-modes operations
  70. while playing a recorded file.
  71. 5. Support decryption of scrambled transport packets.
  72. 6. Support recording of scrambled streams.
  73. 8. Section filtering.
  74. Control path
  75. ------------
  76. 1. Client opens a demux device. Open request is done on the same demux
  77. device for each filter.
  78. 2. Client may configure the demux's internal ring-buffer size used to
  79. hold the data for user-space (or default is used).
  80. 3. Client configures the opened filter either to capture sections,
  81. TS packets (for recording) or PES (decoder or non-decoder PES).
  82. - The demux configures the underlying HW accordingly through
  83. TSPP or TSIF kernel APIs
  84. - demux receives notification of new data from the underlying HW and
  85. performs demuxing operation based on the configuration.
  86. 4. Client can then read data received from the selected filter.
  87. Data path
  88. ---------
  89. For each filter that is opened, demux manages a circular buffer that
  90. holds the captured filter data; Client read commands extract data from
  91. the relevant ring buffer. Data loss can occur if a client cannot keep up
  92. with stream bandwidth.
  93. For PES data tunneled to decoder, demux manages a stream-buffer used to
  94. transfer the PES data to the decoder. The stream-buffer is built from
  95. two ring-buffers: One holding the PES payload (elementary stream) and
  96. the other holding PES parameters extracted from the PES header. The
  97. ring-buffer with PES parameters points to the location of respective PES
  98. payload in the PES payload ring-buffer.
  99. To allow concurrency of multiple stream processing, multiple demux/dvr
  100. devices exist. Each demux devices handles a single stream input. The
  101. number of demux devices is configurable depending on the required number
  102. of concurrent stream processing.
  103. The client configures each demux device with the stream to process,
  104. by default, all devices are configured to process stream from memory.
  105. The default setting can be changed by issuing ioctl that configures
  106. the demux source to either TSIF0 or TSIF1. For specific TSIF input,
  107. only one demux device may process it at a time.
  108. Background Processing
  109. ---------------------
  110. Demux allocates a kernel thread for each live-input to process
  111. the TS packets notified from the HW for specific input. There
  112. are two such inputs (TSIF0 and TSIF1), both can be processed in
  113. parallel by two seperate threads.
  114. The processing is the action of demuxing of the new data; it may sleep
  115. as it locks against the demux data-structure that may be accessed by
  116. user-space in the meanwhile.
  117. Dependencies
  118. ------------
  119. The demux driver depends on the following kernel drivers and subsystems:
  120. 1. TSIF driver: Used to receive TS packets from TSIF interface for
  121. targets supporting TSIF only.
  122. 2. TSPP driver: Used to receive TS packets and/or PES from TSPP
  123. interface for targets supporting TSPP.
  124. 3. TZ-COM: Used to communicate with TrustZone to handle scrambled
  125. streams.
  126. 4. ION: Used to allocate memory for buffers holding decoder-data in
  127. case the data is tunneled between demux and decoders.
  128. Also used to allocate memory for TSPP/TSIF output pipes.
  129. 5. dvb-core: Existing Linux infrastructure used for implementation of
  130. dvb devices.
  131. Design
  132. ======
  133. Goals
  134. -----
  135. The demux driver is designed to:
  136. 1. Fulfil the requirements listed above.
  137. 2. Be able to work on different chipsets having different HW
  138. capabilities. For example, some chipsets are equipped with TSIF only,
  139. others are equipped with TSPP of different versions.
  140. Design Blocks
  141. -------------
  142. Demux implementation hooks to the existing Linux dvb-core
  143. infrastructure as follows:
  144. +----------+ +------------------------------------------+
  145. | | | MPQ Demux Driver |
  146. | | | +----------+ +----------+ +----------+ |
  147. | | | | MPQ DMX | | MPQ DMX | | MPQ DMX | |
  148. | QCOM MPQ | | | TSIF | | TSPPv1 | | TSPPv2 | |
  149. | Adapter | | | Plugin | | Plugin | | Plugin | |
  150. | | | +----------+ +----------+ +----------+ |
  151. | | | +--------------------------------------+ |
  152. | | | | MPQ Demux Common Services | |
  153. | | | +--------------------------------------+ |
  154. +----------+ +------------------------------------------+
  155. +--------------------------------------------------------+
  156. | Linux DVB Core |
  157. | +----------+ +----------+ +----------+ |
  158. | | DVB | | DVB DMX | | DVB | |
  159. | | Demux | | Device | | Device | |
  160. | +----------+ +----------+ +----------+ |
  161. +--------------------------------------------------------+
  162. The new developed code is QCOM MPQ Adapter and the MPQ Demux driver
  163. with the various MPQ-DMX Plugins.
  164. QCOM MPQ Adapter registers a new DVB adapter to Linux dvb-core.
  165. The MPQ DVB adapter is built as a separate kernel module. Using it
  166. demux and video devices can register themselves to the adapter.
  167. MPQ-DMX plugins exist to hook to dvb-core demux implementation
  168. depending on the HW capabilities. Only one of these plugins might be
  169. compiled and run at a time on the target.
  170. As the name of each plugin implies, one plugin implements demux
  171. functionality for targets supporting TSIF only, and the others
  172. implement pluging for targets supporting TSPP in different versions.
  173. The plugin implementation is not hooked to specific chipset as
  174. different chipsets might have the same HW capability.
  175. The MPQ-DMX Plugin Common Services provides common services that are
  176. used by all plugins, such as registrations of demux devices to
  177. the dvb-core.
  178. The demux plugin is built as a separate kernel module. Each plugin
  179. hooks to the DVB-Demux by providing set of pointers to functions
  180. required for DVB-Demux and dvb-core operation. The actual
  181. implementation of these function differs between the plugins depending
  182. on the HW capabilities. The plugins may be viewed as "classes"
  183. inheriting from DVB-Demux "class".
  184. Interface to TSPP/TSIF Drivers
  185. ------------------------------
  186. Each demux plugin interacts with the kernel API of the relevant driver
  187. (either TSIF or TSPP) to receive TS packets or other kinds of data
  188. depending on the HW capabilities.
  189. The demux uses the kernel API of TSIF and TSPP drivers and registers
  190. callback triggered when new data is received. The callback schedules
  191. work to a single-threaded workqueue to process the data. The actual
  192. processing of the data depends on the HW capabilities.
  193. Interface to TZ-COM Driver
  194. --------------------------
  195. For cases HW does not support descrambling, the descrambling is
  196. performed by communicating with TZ using TZ-COM kernel API.
  197. ION driver is used to allocate input and output buffers provided to TZ.
  198. Interface to Decoders
  199. ---------------------
  200. The interface to the decoders is done through a stream-buffer interface.
  201. The design aims not to have direct calls between dvb/demux and
  202. dvb/video for de-coupling and generality. dvb/demux and dvb/video
  203. interact only with stream-buffer API.
  204. Stream buffer is built of two ring-buffers, one holding the PES payload
  205. (the video elementary stream) and the other holding parameters from PES
  206. headers required by decoders.
  207. The separation to two ring-buffers allows locking the payload buffer
  208. as secured buffer that only the decoder's HW may access while allowing
  209. the software to access the PES headers which are not required to be
  210. secured. Locking of the payload buffer is done when the data should be
  211. secured (scrambled video stream for example).
  212. The stream-buffer API make use of dvb-ring buffer implementation that
  213. is part of dvb-core.
  214. SMP/multi-core
  215. ==============
  216. Driver is fully SMP aware.
  217. Interface
  218. =========
  219. User-space API
  220. --------------
  221. dvb/demux and dvb/dvr each expose a char device interface to user-space
  222. as defined by linuxtv.org. Extension to this interface is done to add
  223. new features required by MPQ use-cases. The extensions preserve backward
  224. compatibility of the API defined by linuxtv.org
  225. The devices appear in file-system under:
  226. /dev/dvb/adapter0/demuxN
  227. /dev/dvb/adapter0/dvrN
  228. Where "N" ranges between 0 to total number of demux devices defined.
  229. The default configuration is 4 devices.
  230. Extensions to this API (through new ioctl) exist to provide the
  231. following functionality:
  232. 1. DMX_SET_TS_PACKET_FORMAT: Set the transport stream TS packet format.
  233. Configures whether the stream fed to demux from memory is with TS packet
  234. of 188 bytes long, 192 bytes long, etc.
  235. Default is 188 bytes long to preserve backward compatibility.
  236. Returns the following values:
  237. 0 in case of success.
  238. -EINVAL if the parameter is invalid.
  239. -EBUSY if demux is already running.
  240. 2. DMX_SET_DECODER_BUFFER_SIZE: Set the decoder's buffer size.
  241. For data tunneled to decoder, client can configure the size of the buffer
  242. holding the PES payload.
  243. Default is set to the fixed size value that exists in current dvb-core to
  244. preserve backward compatibility.
  245. Returns the following values:
  246. 0 in case of success.
  247. -EINVAL if the parameter is invalid.
  248. -EBUSY if demux is already running.
  249. 3. DMX_SET_TS_OUT_FORMAT: Set the TS packet recording format.
  250. Indicates whether the TS packet used for recording should be in 188 or 192
  251. bytes long format. In case of 192-packets output, 4 bytes zero timestamp
  252. is attached to the original 188 packet.
  253. Default is set for 188 to preserve backward compatibility.
  254. Returns the following values:
  255. 0 in case of success.
  256. -EINVAL if the parameter is invalid.
  257. -EBUSY if demux is already running.
  258. 4. Added support for mmap for direct access to input/output buffers.
  259. User can either use the original read/write syscalls or use mmap
  260. on the specific file-handle. Several ioctls were exposed so that
  261. user can find-out the status of the buffers (DMX_GET_BUFFER_STATUS),
  262. to notify demux when data is consumed (DMX_RELEASE_DATA) or notify
  263. dvr when data is fed (DMX_FEED_DATA).
  264. 5. DMX_SET_PLAYBACK_MODE: Set playback mode in memory input.
  265. In memory input, contrary to live input, playback can be in pull mode,
  266. where if one of output buffers is full, demux stalls waiting for free space,
  267. this would cause DVR input buffer fullness to accumulate.
  268. Returns the following values:
  269. 0 in case of success.
  270. -EINVAL if the parameter is invalid.
  271. -EBUSY if demux is already running.
  272. debugfs
  273. -------
  274. debugfs is used for debug purposes.
  275. Directory in debugfs is created for each demux device.
  276. Each directory includes several performance counters of the specific demux:
  277. Total demuxing time, total CRC time, HW notification rate, HW notification
  278. buffer size.
  279. Exported Kernel API
  280. -------------------
  281. MPQ adapter exports the following kernel API:
  282. 1. Getter API for the registered MPQ adapter handle.
  283. This is used by demux plugin as well as dvb/video implementation to
  284. register their devices to that adapter.
  285. 2. Stream buffer API: Used to tunnel the data between dvb/demux and
  286. decoders. The API is used by dvb/demux and by decoders to write/read
  287. tunneled data.
  288. 3. Stream buffer interface registration: Used to register stream-buffer
  289. interfaces. When demux driver is asked to tunnel data to a decoder,
  290. the demux allocates a stream-buffer to be shared between demux and
  291. the decoder. For the decoder to retrieve the info of the
  292. stream-buffer it should connect to, stream-buffer registration API
  293. exist.
  294. The demux registers the new allocated stream buffer handle to MPQ
  295. Adapter, and the decoder may query the registered interface through
  296. MPQ Adapter.
  297. Driver parameters
  298. =================
  299. There are three kernel modules required for DVB API operation:
  300. 1. dvb-core.ko: This is an existing Linux module for dvb functionality.
  301. The parameters for this module are the one defined by linuxtv.org.
  302. An additional parameter was added to specify whether to collect
  303. performance debug information exposed through debugfs.
  304. Parameter name: dvb_demux_performancecheck
  305. 2. mpq-adapter.ko: MPQ DVB adapter module. Has a parameter to
  306. specify the adapter number, the number (X) is the same as the one
  307. that appears in /dev/dvb/adapterX. Default is 0.
  308. Parameter name: adapter_nr
  309. 3. mpq-dmx-hw-plugin.ko: Module for demux HW plugin. Receives as a
  310. parameter the number of required demux devices. Default is set to the
  311. number specified in kernel configuration.
  312. Parameter name: mpq_demux_device_num
  313. Config options
  314. ==============
  315. New kernel configurations is available (through make menuconfig) to
  316. enable MPQ based adapter functionality. The following configurations
  317. exist:
  318. 1. Control whether to enable QCOM MPQ DVB adapter (tri-state).
  319. It depends on having dvb-core enabled.
  320. 2. If MPQ adapter is enabled:
  321. 2.1. Control whether to enable MPQ dvb/demux (tri-state)
  322. 2.2. Control whether to enable MPQ dvb/video (tri-state)
  323. 2.3. If dvb/demux is enabled:
  324. 2.3.1. Configure the number of demux devices. Default is 4.
  325. 2.3.2. Select the desired demux plugin. Each plugin would appear
  326. in the list of options depending whether the respective
  327. driver (TSIF/TSPP) is enabled or not.
  328. Dependencies
  329. ============
  330. 1. The implementation depends on having dvb-core enabled.
  331. 2. Each demux plugin depends on whether the relevant driver it uses
  332. is enabled. TSIF plugin depends on TSIF driver and TSPP plugins
  333. depend on TSPP driver.
  334. 3. There's no communication to other processors.
  335. User space utilities
  336. ====================
  337. N/A
  338. Other
  339. =====
  340. N/A
  341. Known issues
  342. ============
  343. N/A