4 * The Kernel Digital TV Demux kABI defines a driver-internal interface for
5 * registering low-level, hardware specific driver to a hardware independent
8 * Copyright (c) 2002 Convergence GmbH
11 * Copyright (c) 2000 Nokia Research Center
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public License
16 * as published by the Free Software Foundation; either version 2.1
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <linux/types.h>
34 #include <linux/errno.h>
35 #include <linux/list.h>
36 #include <linux/time.h>
37 #include <linux/dvb/dmx.h>
44 * DMX_MAX_FILTER_SIZE: Maximum length (in bytes) of a section/PES filter.
47 #ifndef DMX_MAX_FILTER_SIZE
48 #define DMX_MAX_FILTER_SIZE 18
52 * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed
56 #ifndef DMX_MAX_SECTION_SIZE
57 #define DMX_MAX_SECTION_SIZE 4096
59 #ifndef DMX_MAX_SECFEED_SIZE
60 #define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188)
68 * enum ts_filter_type - filter type bitmap for dmx_ts_feed.set\(\)
70 * @TS_PACKET: Send TS packets (188 bytes) to callback (default).
71 * @TS_PAYLOAD_ONLY: In case TS_PACKET is set, only send the TS payload
72 * (<=184 bytes per packet) to callback
73 * @TS_DECODER: Send stream to built-in decoder (if present).
74 * @TS_DEMUX: In case TS_PACKET is set, send the TS to the demux
75 * device, not to the dvr device
85 * struct dmx_ts_feed - Structure that contains a TS feed filter
87 * @is_filtering: Set to non-zero when filtering in progress
88 * @parent: pointer to struct dmx_demux
89 * @priv: pointer to private data of the API client
90 * @set: sets the TS filter
91 * @start_filtering: starts TS filtering
92 * @stop_filtering: stops TS filtering
94 * A TS feed is typically mapped to a hardware PID filter on the demux chip.
95 * Using this API, the client can set the filtering properties to start/stop
96 * filtering TS packets on a particular TS feed.
100 struct dmx_demux
*parent
;
102 int (*set
)(struct dmx_ts_feed
*feed
,
105 enum dmx_ts_pes pes_type
,
107 int (*start_filtering
)(struct dmx_ts_feed
*feed
);
108 int (*stop_filtering
)(struct dmx_ts_feed
*feed
);
116 * struct dmx_section_filter - Structure that describes a section filter
118 * @filter_value: Contains up to 16 bytes (128 bits) of the TS section header
119 * that will be matched by the section filter
120 * @filter_mask: Contains a 16 bytes (128 bits) filter mask with the bits
121 * specified by @filter_value that will be used on the filter
123 * @filter_mode: Contains a 16 bytes (128 bits) filter mode.
124 * @parent: Pointer to struct dmx_section_feed.
125 * @priv: Pointer to private data of the API client.
128 * The @filter_mask controls which bits of @filter_value are compared with
129 * the section headers/payload. On a binary value of 1 in filter_mask, the
130 * corresponding bits are compared. The filter only accepts sections that are
131 * equal to filter_value in all the tested bit positions.
133 struct dmx_section_filter
{
134 u8 filter_value
[DMX_MAX_FILTER_SIZE
];
135 u8 filter_mask
[DMX_MAX_FILTER_SIZE
];
136 u8 filter_mode
[DMX_MAX_FILTER_SIZE
];
137 struct dmx_section_feed
*parent
; /* Back-pointer */
138 void *priv
; /* Pointer to private data of the API client */
142 * struct dmx_section_feed - Structure that contains a section feed filter
144 * @is_filtering: Set to non-zero when filtering in progress
145 * @parent: pointer to struct dmx_demux
146 * @priv: pointer to private data of the API client
147 * @check_crc: If non-zero, check the CRC values of filtered sections.
148 * @set: sets the section filter
149 * @allocate_filter: This function is used to allocate a section filter on
150 * the demux. It should only be called when no filtering
151 * is in progress on this section feed. If a filter cannot
152 * be allocated, the function fails with -ENOSPC.
153 * @release_filter: This function releases all the resources of a
154 * previously allocated section filter. The function
155 * should not be called while filtering is in progress
156 * on this section feed. After calling this function,
157 * the caller should not try to dereference the filter
159 * @start_filtering: starts section filtering
160 * @stop_filtering: stops section filtering
162 * A TS feed is typically mapped to a hardware PID filter on the demux chip.
163 * Using this API, the client can set the filtering properties to start/stop
164 * filtering TS packets on a particular TS feed.
166 struct dmx_section_feed
{
168 struct dmx_demux
*parent
;
173 /* private: Used internally at dvb_demux.c */
177 u8 secbuf_base
[DMX_MAX_SECFEED_SIZE
];
178 u16 secbufp
, seclen
, tsfeedp
;
181 int (*set
)(struct dmx_section_feed
*feed
,
184 int (*allocate_filter
)(struct dmx_section_feed
*feed
,
185 struct dmx_section_filter
**filter
);
186 int (*release_filter
)(struct dmx_section_feed
*feed
,
187 struct dmx_section_filter
*filter
);
188 int (*start_filtering
)(struct dmx_section_feed
*feed
);
189 int (*stop_filtering
)(struct dmx_section_feed
*feed
);
193 * typedef dmx_ts_cb - DVB demux TS filter callback function prototype
195 * @buffer1: Pointer to the start of the filtered TS packets.
196 * @buffer1_length: Length of the TS data in buffer1.
197 * @buffer2: Pointer to the tail of the filtered TS packets, or NULL.
198 * @buffer2_length: Length of the TS data in buffer2.
199 * @source: Indicates which TS feed is the source of the callback.
201 * This function callback prototype, provided by the client of the demux API,
202 * is called from the demux code. The function is only called when filtering
203 * on a TS feed has been enabled using the start_filtering\(\) function at
205 * Any TS packets that match the filter settings are copied to a circular
206 * buffer. The filtered TS packets are delivered to the client using this
208 * It is expected that the @buffer1 and @buffer2 callback parameters point to
209 * addresses within the circular buffer, but other implementations are also
210 * possible. Note that the called party should not try to free the memory
211 * the @buffer1 and @buffer2 parameters point to.
213 * When this function is called, the @buffer1 parameter typically points to
214 * the start of the first undelivered TS packet within a circular buffer.
215 * The @buffer2 buffer parameter is normally NULL, except when the received
216 * TS packets have crossed the last address of the circular buffer and
217 * ”wrapped” to the beginning of the buffer. In the latter case the @buffer1
218 * parameter would contain an address within the circular buffer, while the
219 * @buffer2 parameter would contain the first address of the circular buffer.
220 * The number of bytes delivered with this function (i.e. @buffer1_length +
221 * @buffer2_length) is usually equal to the value of callback_length parameter
222 * given in the set() function, with one exception: if a timeout occurs before
223 * receiving callback_length bytes of TS data, any undelivered packets are
224 * immediately delivered to the client by calling this function. The timeout
225 * duration is controlled by the set() function in the TS Feed API.
227 * If a TS packet is received with errors that could not be fixed by the
228 * TS-level forward error correction (FEC), the Transport_error_indicator
229 * flag of the TS packet header should be set. The TS packet should not be
230 * discarded, as the error can possibly be corrected by a higher layer
231 * protocol. If the called party is slow in processing the callback, it
232 * is possible that the circular buffer eventually fills up. If this happens,
233 * the demux driver should discard any TS packets received while the buffer
234 * is full and return -EOVERFLOW.
236 * The type of data returned to the callback can be selected by the
237 * &dmx_ts_feed.@set function. The type parameter decides if the raw
238 * TS packet (TS_PACKET) or just the payload (TS_PACKET|TS_PAYLOAD_ONLY)
239 * should be returned. If additionally the TS_DECODER bit is set the stream
240 * will also be sent to the hardware MPEG decoder.
246 * - -EOVERFLOW, on buffer overflow.
248 typedef int (*dmx_ts_cb
)(const u8
*buffer1
,
249 size_t buffer1_length
,
251 size_t buffer2_length
,
252 struct dmx_ts_feed
*source
);
255 * typedef dmx_section_cb - DVB demux TS filter callback function prototype
257 * @buffer1: Pointer to the start of the filtered section, e.g.
258 * within the circular buffer of the demux driver.
259 * @buffer1_len: Length of the filtered section data in @buffer1,
260 * including headers and CRC.
261 * @buffer2: Pointer to the tail of the filtered section data,
262 * or NULL. Useful to handle the wrapping of a
264 * @buffer2_len: Length of the filtered section data in @buffer2,
265 * including headers and CRC.
266 * @source: Indicates which section feed is the source of the
269 * This function callback prototype, provided by the client of the demux API,
270 * is called from the demux code. The function is only called when
271 * filtering of sections has been enabled using the function
272 * &dmx_ts_feed.@start_filtering. When the demux driver has received a
273 * complete section that matches at least one section filter, the client
274 * is notified via this callback function. Normally this function is called
275 * for each received section; however, it is also possible to deliver
276 * multiple sections with one callback, for example when the system load
277 * is high. If an error occurs while receiving a section, this
278 * function should be called with the corresponding error type set in the
279 * success field, whether or not there is data to deliver. The Section Feed
280 * implementation should maintain a circular buffer for received sections.
281 * However, this is not necessary if the Section Feed API is implemented as
282 * a client of the TS Feed API, because the TS Feed implementation then
283 * buffers the received data. The size of the circular buffer can be
284 * configured using the &dmx_ts_feed.@set function in the Section Feed API.
285 * If there is no room in the circular buffer when a new section is received,
286 * the section must be discarded. If this happens, the value of the success
287 * parameter should be DMX_OVERRUN_ERROR on the next callback.
289 typedef int (*dmx_section_cb
)(const u8
*buffer1
,
293 struct dmx_section_filter
*source
);
300 * enum dmx_frontend_source - Used to identify the type of frontend
302 * @DMX_MEMORY_FE: The source of the demux is memory. It means that
303 * the MPEG-TS to be filtered comes from userspace,
304 * via write() syscall.
306 * @DMX_FRONTEND_0: The source of the demux is a frontend connected
309 enum dmx_frontend_source
{
315 * struct dmx_frontend - Structure that lists the frontends associated with
318 * @connectivity_list: List of front-ends that can be connected to a
320 * @source: Type of the frontend.
322 * FIXME: this structure should likely be replaced soon by some
323 * media-controller based logic.
325 struct dmx_frontend
{
326 struct list_head connectivity_list
;
327 enum dmx_frontend_source source
;
335 * enum dmx_demux_caps - MPEG-2 TS Demux capabilities bitmap
337 * @DMX_TS_FILTERING: set if TS filtering is supported;
338 * @DMX_SECTION_FILTERING: set if section filtering is supported;
339 * @DMX_MEMORY_BASED_FILTERING: set if write() available.
341 * Those flags are OR'ed in the &dmx_demux.capabilities field
343 enum dmx_demux_caps
{
344 DMX_TS_FILTERING
= 1,
345 DMX_SECTION_FILTERING
= 4,
346 DMX_MEMORY_BASED_FILTERING
= 8,
350 * Demux resource type identifier.
354 * DMX_FE_ENTRY - Casts elements in the list of registered
355 * front-ends from the generic type struct list_head
356 * to the type * struct dmx_frontend
358 * @list: list of struct dmx_frontend
360 #define DMX_FE_ENTRY(list) \
361 list_entry(list, struct dmx_frontend, connectivity_list)
364 * struct dmx_demux - Structure that contains the demux capabilities and
367 * @capabilities: Bitfield of capability flags.
369 * @frontend: Front-end connected to the demux
371 * @priv: Pointer to private data of the API client
373 * @open: This function reserves the demux for use by the caller and, if
374 * necessary, initializes the demux. When the demux is no longer needed,
375 * the function @close should be called. It should be possible for
376 * multiple clients to access the demux at the same time. Thus, the
377 * function implementation should increment the demux usage count when
378 * @open is called and decrement it when @close is called.
379 * The @demux function parameter contains a pointer to the demux API and
383 * -EUSERS, if maximum usage count was reached;
384 * -EINVAL, on bad parameter.
386 * @close: This function reserves the demux for use by the caller and, if
387 * necessary, initializes the demux. When the demux is no longer needed,
388 * the function @close should be called. It should be possible for
389 * multiple clients to access the demux at the same time. Thus, the
390 * function implementation should increment the demux usage count when
391 * @open is called and decrement it when @close is called.
392 * The @demux function parameter contains a pointer to the demux API and
396 * -ENODEV, if demux was not in use (e. g. no users);
397 * -EINVAL, on bad parameter.
399 * @write: This function provides the demux driver with a memory buffer
400 * containing TS packets. Instead of receiving TS packets from the DVB
401 * front-end, the demux driver software will read packets from memory.
402 * Any clients of this demux with active TS, PES or Section filters will
403 * receive filtered data via the Demux callback API (see 0). The function
404 * returns when all the data in the buffer has been consumed by the demux.
405 * Demux hardware typically cannot read TS from memory. If this is the
406 * case, memory-based filtering has to be implemented entirely in software.
407 * The @demux function parameter contains a pointer to the demux API and
409 * The @buf function parameter contains a pointer to the TS data in
410 * kernel-space memory.
411 * The @count function parameter contains the length of the TS data.
414 * -ERESTARTSYS, if mutex lock was interrupted;
415 * -EINTR, if a signal handling is pending;
416 * -ENODEV, if demux was removed;
417 * -EINVAL, on bad parameter.
419 * @allocate_ts_feed: Allocates a new TS feed, which is used to filter the TS
420 * packets carrying a certain PID. The TS feed normally corresponds to a
421 * hardware PID filter on the demux chip.
422 * The @demux function parameter contains a pointer to the demux API and
424 * The @feed function parameter contains a pointer to the TS feed API and
426 * The @callback function parameter contains a pointer to the callback
427 * function for passing received TS packet.
430 * -ERESTARTSYS, if mutex lock was interrupted;
431 * -EBUSY, if no more TS feeds is available;
432 * -EINVAL, on bad parameter.
434 * @release_ts_feed: Releases the resources allocated with @allocate_ts_feed.
435 * Any filtering in progress on the TS feed should be stopped before
436 * calling this function.
437 * The @demux function parameter contains a pointer to the demux API and
439 * The @feed function parameter contains a pointer to the TS feed API and
443 * -EINVAL on bad parameter.
445 * @allocate_section_feed: Allocates a new section feed, i.e. a demux resource
446 * for filtering and receiving sections. On platforms with hardware
447 * support for section filtering, a section feed is directly mapped to
448 * the demux HW. On other platforms, TS packets are first PID filtered in
449 * hardware and a hardware section filter then emulated in software. The
450 * caller obtains an API pointer of type dmx_section_feed_t as an out
451 * parameter. Using this API the caller can set filtering parameters and
452 * start receiving sections.
453 * The @demux function parameter contains a pointer to the demux API and
455 * The @feed function parameter contains a pointer to the TS feed API and
457 * The @callback function parameter contains a pointer to the callback
458 * function for passing received TS packet.
461 * -EBUSY, if no more TS feeds is available;
462 * -EINVAL, on bad parameter.
464 * @release_section_feed: Releases the resources allocated with
465 * @allocate_section_feed, including allocated filters. Any filtering in
466 * progress on the section feed should be stopped before calling this
468 * The @demux function parameter contains a pointer to the demux API and
470 * The @feed function parameter contains a pointer to the TS feed API and
474 * -EINVAL, on bad parameter.
476 * @add_frontend: Registers a connectivity between a demux and a front-end,
477 * i.e., indicates that the demux can be connected via a call to
478 * @connect_frontend to use the given front-end as a TS source. The
479 * client of this function has to allocate dynamic or static memory for
480 * the frontend structure and initialize its fields before calling this
481 * function. This function is normally called during the driver
482 * initialization. The caller must not free the memory of the frontend
483 * struct before successfully calling @remove_frontend.
484 * The @demux function parameter contains a pointer to the demux API and
486 * The @frontend function parameter contains a pointer to the front-end
490 * -EINVAL, on bad parameter.
492 * @remove_frontend: Indicates that the given front-end, registered by a call
493 * to @add_frontend, can no longer be connected as a TS source by this
494 * demux. The function should be called when a front-end driver or a demux
495 * driver is removed from the system. If the front-end is in use, the
496 * function fails with the return value of -EBUSY. After successfully
497 * calling this function, the caller can free the memory of the frontend
498 * struct if it was dynamically allocated before the @add_frontend
500 * The @demux function parameter contains a pointer to the demux API and
502 * The @frontend function parameter contains a pointer to the front-end
506 * -ENODEV, if the front-end was not found,
507 * -EINVAL, on bad parameter.
509 * @get_frontends: Provides the APIs of the front-ends that have been
510 * registered for this demux. Any of the front-ends obtained with this
511 * call can be used as a parameter for @connect_frontend. The include
512 * file demux.h contains the macro DMX_FE_ENTRY() for converting an
513 * element of the generic type struct &list_head * to the type
514 * struct &dmx_frontend *. The caller must not free the memory of any of
515 * the elements obtained via this function call.
516 * The @demux function parameter contains a pointer to the demux API and
518 * It returns a struct list_head pointer to the list of front-end
519 * interfaces, or NULL in the case of an empty list.
521 * @connect_frontend: Connects the TS output of the front-end to the input of
522 * the demux. A demux can only be connected to a front-end registered to
523 * the demux with the function @add_frontend. It may or may not be
524 * possible to connect multiple demuxes to the same front-end, depending
525 * on the capabilities of the HW platform. When not used, the front-end
526 * should be released by calling @disconnect_frontend.
527 * The @demux function parameter contains a pointer to the demux API and
529 * The @frontend function parameter contains a pointer to the front-end
533 * -EINVAL, on bad parameter.
535 * @disconnect_frontend: Disconnects the demux and a front-end previously
536 * connected by a @connect_frontend call.
537 * The @demux function parameter contains a pointer to the demux API and
541 * -EINVAL on bad parameter.
543 * @get_pes_pids: Get the PIDs for DMX_PES_AUDIO0, DMX_PES_VIDEO0,
544 * DMX_PES_TELETEXT0, DMX_PES_SUBTITLE0 and DMX_PES_PCR0.
545 * The @demux function parameter contains a pointer to the demux API and
547 * The @pids function parameter contains an array with five u16 elements
548 * where the PIDs will be stored.
551 * -EINVAL on bad parameter.
554 enum dmx_demux_caps capabilities
;
555 struct dmx_frontend
*frontend
;
557 int (*open
)(struct dmx_demux
*demux
);
558 int (*close
)(struct dmx_demux
*demux
);
559 int (*write
)(struct dmx_demux
*demux
, const char __user
*buf
,
561 int (*allocate_ts_feed
)(struct dmx_demux
*demux
,
562 struct dmx_ts_feed
**feed
,
564 int (*release_ts_feed
)(struct dmx_demux
*demux
,
565 struct dmx_ts_feed
*feed
);
566 int (*allocate_section_feed
)(struct dmx_demux
*demux
,
567 struct dmx_section_feed
**feed
,
568 dmx_section_cb callback
);
569 int (*release_section_feed
)(struct dmx_demux
*demux
,
570 struct dmx_section_feed
*feed
);
571 int (*add_frontend
)(struct dmx_demux
*demux
,
572 struct dmx_frontend
*frontend
);
573 int (*remove_frontend
)(struct dmx_demux
*demux
,
574 struct dmx_frontend
*frontend
);
575 struct list_head
*(*get_frontends
)(struct dmx_demux
*demux
);
576 int (*connect_frontend
)(struct dmx_demux
*demux
,
577 struct dmx_frontend
*frontend
);
578 int (*disconnect_frontend
)(struct dmx_demux
*demux
);
580 int (*get_pes_pids
)(struct dmx_demux
*demux
, u16
*pids
);
585 * Only used at av7110, to read some data from firmware.
586 * As this was never documented, we have no clue about what's
587 * there, and its usage on other drivers aren't encouraged.
589 int (*get_stc
)(struct dmx_demux
*demux
, unsigned int num
,
590 u64
*stc
, unsigned int *base
);
593 #endif /* #ifndef __DEMUX_H */