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