blob: 28f5d397c703257f3902c7009a5439fea1a91c37 [file] [log] [blame]
Hamad Kadmanyd853d132012-05-30 13:13:46 +03001Introduction
2============
3MPQ DVB Adapter implements Digital Video Broadcasting devices according
4to LinuxTV (linuxtv.org) defined API and infrastructure.
5
6The implemented devices are dvb/demux devices, dvb/dvr devices and
7dvb/video devices.
8
9These devices are used in Qualcomm's MPQ chipsets that support
10broadcast applications.
11
12dvb/demux is responsible to receive a digital stream broadcasted over
13the air from a hardware unit (TSPP - Transport stream packet processor,
14or TSIF - Transport Stream Interface) and separates the stream into its
15various sub-streams such as video, audio and auxiliary data.
16The separation operation is named demuxing.
17
18dvb/dvr is used in conjunction with dvb/demux to re-play a digital
19stream from memory or to record stream to memory.
20
21dvb/video is used to handle the video decoding, it receives compressed
22video from dvb/demux through a stream-buffer interface and interacts
23with the existing HW video driver to perform the decoding.
24
25For more information on the TSIF interface, please refer to TSIF
26documentation under "Documentation/arm/msm/tsif.txt".
27For more information on the TSPP interface, please refer to TSPP
28documentation under "Documentation/arm/msm/tspp.txt".
29For more information on DVB-API definition, please refer dvb
30documentation under "Documentation/dvb/readme.txt".
31
32Hardware description
33====================
34dvb/demux, dvb/dvr and dvb/video do not interact with a hardware directly;
35The implementation of these drivers is done using the kernel API of TSPP,
36TSIF and video drivers.
37
38Software description
39====================
40
41Terminology
42-----------
43Stream: A stream is a TS packet source
44 - For example, MPEG2 Transport Stream from TSIF0
45Filter: 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.
51Service: 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
56Requirments
57-----------
581. Demuxing from different sources:
59 - Live transport stream inputs (TSIF)
60 - Memory inputs
612. Support different packet formats:
62 - 188-bytes transport packets
63 - 192-bytes transport packets
643. PID filtering
654. 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.
815. Support decryption of scrambled transport packets.
826. Support recording of scrambled streams.
838. Section filtering.
84
85Control path
86------------
871. Client opens a demux device. Open request is done on the same demux
88 device for each filter.
892. Client may configure the demux's internal ring-buffer size used to
90 hold the data for user-space (or default is used).
913. 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.
974. Client can then read data received from the selected filter.
98
99Data path
100---------
101For each filter that is opened, demux manages a circular buffer that
102holds the captured filter data; Client read commands extract data from
103the relevant ring buffer. Data loss can occur if a client cannot keep up
104with stream bandwidth.
105
106For PES data tunneled to decoder, demux manages a stream-buffer used to
107transfer the PES data to the decoder. The stream-buffer is built from
108two ring-buffers: One holding the PES payload (elementary stream) and
109the other holding PES parameters extracted from the PES header. The
110ring-buffer with PES parameters points to the location of respective PES
111payload in the PES payload ring-buffer.
112
113To allow concurrency of multiple stream processing, multiple demux/dvr
114devices exist. Each demux devices handles a single stream input. The
115number of demux devices is configurable depending on the required number
116of concurrent stream processing.
117
118The client configures each demux device with the stream to process,
119by default, all devices are configured to process stream from memory.
120The default setting can be changed by issuing ioctl that configures
121the demux source to either TSIF0 or TSIF1. For specific TSIF input,
122only one demux device may process it at a time.
123
124Background Processing
125---------------------
126When demux receives notifications from underlying HW drivers about new
127data, it schedules work to a single-threaded workqueue to process the
128notification.
129
130The processing is the action of demuxing of the new data; it may sleep
131as it locks against the demux data-structure that may be accessed by
132user-space in the meanwhile.
133
134A single threaded workqueue exists for each live input (TSIF0 or TSIF1)
135to process the inputs in parallel.
136
137Dependencies
138------------
139The demux driver depends on the following kernel drivers and subsystems:
1401. TSIF driver: Used to receive TS packets from TSIF interface for
141 targets supporting TSIF only.
1422. TSPP driver: Used to receive TS packets and/or PES from TSPP
143 interface for targets supporting TSPP.
1443. TZ-COM: Used to communicate with TrustZone to handle scrambled
145 streams.
1464. 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.
1495. dvb-core: Existing Linux infrastructure used for implementation of
150 dvb devices.
151
152Design
153======
154
155Goals
156-----
157The demux driver is designed to:
1581. Fulfil the requirements listed above.
1592. 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
163Design Blocks
164-------------
165Demux implementation hooks to the existing Linux dvb-core
166infrastructure 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
187The new developed code is QCOM MPQ Adapter and the MPQ Demux driver
188with the various MPQ-DMX Plugins.
189
190QCOM MPQ Adapter registers a new DVB adapter to Linux dvb-core.
191The MPQ DVB adapter is built as a separate kernel module. Using it
192demux and video devices can register themselves to the adapter.
193
194MPQ-DMX plugins exist to hook to dvb-core demux implementation
195depending on the HW capabilities. Only one of these plugins might be
196compiled and run at a time on the target.
197As the name of each plugin implies, one plugin implements demux
198functionality for targets supporting TSIF only, and the others
199implement pluging for targets supporting TSPP in different versions.
200
201The plugin implementation is not hooked to specific chipset as
202different chipsets might have the same HW capability.
203
204The MPQ-DMX Plugin Common Services provides common services that are
205used by all plugins, such as registrations of demux devices to
206the dvb-core.
207
208The demux plugin is built as a separate kernel module. Each plugin
209hooks to the DVB-Demux by providing set of pointers to functions
210required for DVB-Demux and dvb-core operation. The actual
211implementation of these function differs between the plugins depending
212on the HW capabilities. The plugins may be viewed as "classes"
213inheriting from DVB-Demux "class".
214
215Interface to TSPP/TSIF Drivers
216------------------------------
217Each 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
219depending on the HW capabilities.
220
221The demux uses the kernel API of TSIF and TSPP drivers and registers
222callback triggered when new data is received. The callback schedules
223work to a single-threaded workqueue to process the data. The actual
224processing of the data depends on the HW capabilities.
225
226Interface to TZ-COM Driver
227--------------------------
228For cases HW does not support descrambling, the descrambling is
229performed by communicating with TZ using TZ-COM kernel API.
230
231ION driver is used to allocate input and output buffers provided to TZ.
232
233Interface to Decoders
234---------------------
235The interface to the decoders is done through a stream-buffer interface.
236The design aims not to have direct calls between dvb/demux and
237dvb/video for de-coupling and generality. dvb/demux and dvb/video
238interact only with stream-buffer API.
239
240Stream buffer is built of two ring-buffers, one holding the PES payload
241(the video elementary stream) and the other holding parameters from PES
242headers required by decoders.
243
244The separation to two ring-buffers allows locking the payload buffer
245as secured buffer that only the decoder's HW may access while allowing
246the software to access the PES headers which are not required to be
247secured. Locking of the payload buffer is done when the data should be
248secured (scrambled video stream for example).
249
250The stream-buffer API make use of dvb-ring buffer implementation that
251is part of dvb-core.
252
253SMP/multi-core
254==============
255Driver is fully SMP aware.
256
257Interface
258=========
259
260User-space API
261--------------
262dvb/demux and dvb/dvr each expose a char device interface to user-space
263as defined by linuxtv.org. Extension to this interface is done to add
264new features required by MPQ use-cases. The extensions preserve backward
265compatibility of the API defined by linuxtv.org
266
267The devices appear in file-system under:
268/dev/dvb/adapter0/demuxN
269/dev/dvb/adapter0/dvrN
270
271Where "N" ranges between 0 to total number of demux devices defined.
272The default configuration is 4 devices.
273
274Extensions to this API (through new ioctl) exist to provide the
275following functionality:
276
2771. 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
2872. 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
2983. 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
3094. 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
3165. 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
326debugfs
327-------
328debugfs is used for debug purposes.
329
330Directory in debugfs is created for each demux device.
331
332Each directory includes several performance counters of the specific demux:
333Total demuxing time, total CRC time, HW notification rate, HW notification
334buffer size.
335
336
337Exported Kernel API
338-------------------
339MPQ adapter exports the following kernel API:
3401. 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.
3432. 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.
3463. 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
356Driver parameters
357=================
358There are three kernel modules required for DVB API operation:
3591. 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
3652. 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
3703. 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
375Config options
376==============
377New kernel configurations is available (through make menuconfig) to
378enable MPQ based adapter functionality. The following configurations
379exist:
3801. Control whether to enable QCOM MPQ DVB adapter (tri-state).
381 It depends on having dvb-core enabled.
3822. 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
391Dependencies
392============
3931. The implementation depends on having dvb-core enabled.
3942. 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.
3973. There's no communication to other processors.
398
399User space utilities
400====================
401N/A
402
403Other
404=====
405N/A
406
407Known issues
408============
409N/A