xref: /kernel/linux/linux-5.10/include/media/demux.h (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * demux.h
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * The Kernel Digital TV Demux kABI defines a driver-internal interface for
58c2ecf20Sopenharmony_ci * registering low-level, hardware specific driver to a hardware independent
68c2ecf20Sopenharmony_ci * demux layer.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copyright (c) 2002 Convergence GmbH
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * based on code:
118c2ecf20Sopenharmony_ci * Copyright (c) 2000 Nokia Research Center
128c2ecf20Sopenharmony_ci *                    Tampere, FINLAND
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or
158c2ecf20Sopenharmony_ci * modify it under the terms of the GNU Lesser General Public License
168c2ecf20Sopenharmony_ci * as published by the Free Software Foundation; either version 2.1
178c2ecf20Sopenharmony_ci * of the License, or (at your option) any later version.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful,
208c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
218c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
228c2ecf20Sopenharmony_ci * GNU General Public License for more details.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci */
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#ifndef __DEMUX_H
278c2ecf20Sopenharmony_ci#define __DEMUX_H
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#include <linux/types.h>
308c2ecf20Sopenharmony_ci#include <linux/errno.h>
318c2ecf20Sopenharmony_ci#include <linux/list.h>
328c2ecf20Sopenharmony_ci#include <linux/time.h>
338c2ecf20Sopenharmony_ci#include <linux/dvb/dmx.h>
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/*
368c2ecf20Sopenharmony_ci * Common definitions
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/*
408c2ecf20Sopenharmony_ci * DMX_MAX_FILTER_SIZE: Maximum length (in bytes) of a section/PES filter.
418c2ecf20Sopenharmony_ci */
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#ifndef DMX_MAX_FILTER_SIZE
448c2ecf20Sopenharmony_ci#define DMX_MAX_FILTER_SIZE 18
458c2ecf20Sopenharmony_ci#endif
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/*
488c2ecf20Sopenharmony_ci * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed
498c2ecf20Sopenharmony_ci * filter.
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#ifndef DMX_MAX_SECTION_SIZE
538c2ecf20Sopenharmony_ci#define DMX_MAX_SECTION_SIZE 4096
548c2ecf20Sopenharmony_ci#endif
558c2ecf20Sopenharmony_ci#ifndef DMX_MAX_SECFEED_SIZE
568c2ecf20Sopenharmony_ci#define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188)
578c2ecf20Sopenharmony_ci#endif
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/*
608c2ecf20Sopenharmony_ci * TS packet reception
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/**
648c2ecf20Sopenharmony_ci * enum ts_filter_type - filter type bitmap for dmx_ts_feed.set\(\)
658c2ecf20Sopenharmony_ci *
668c2ecf20Sopenharmony_ci * @TS_PACKET:		Send TS packets (188 bytes) to callback (default).
678c2ecf20Sopenharmony_ci * @TS_PAYLOAD_ONLY:	In case TS_PACKET is set, only send the TS payload
688c2ecf20Sopenharmony_ci *			(<=184 bytes per packet) to callback
698c2ecf20Sopenharmony_ci * @TS_DECODER:		Send stream to built-in decoder (if present).
708c2ecf20Sopenharmony_ci * @TS_DEMUX:		In case TS_PACKET is set, send the TS to the demux
718c2ecf20Sopenharmony_ci *			device, not to the dvr device
728c2ecf20Sopenharmony_ci */
738c2ecf20Sopenharmony_cienum ts_filter_type {
748c2ecf20Sopenharmony_ci	TS_PACKET = 1,
758c2ecf20Sopenharmony_ci	TS_PAYLOAD_ONLY = 2,
768c2ecf20Sopenharmony_ci	TS_DECODER = 4,
778c2ecf20Sopenharmony_ci	TS_DEMUX = 8,
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/**
818c2ecf20Sopenharmony_ci * struct dmx_ts_feed - Structure that contains a TS feed filter
828c2ecf20Sopenharmony_ci *
838c2ecf20Sopenharmony_ci * @is_filtering:	Set to non-zero when filtering in progress
848c2ecf20Sopenharmony_ci * @parent:		pointer to struct dmx_demux
858c2ecf20Sopenharmony_ci * @priv:		pointer to private data of the API client
868c2ecf20Sopenharmony_ci * @set:		sets the TS filter
878c2ecf20Sopenharmony_ci * @start_filtering:	starts TS filtering
888c2ecf20Sopenharmony_ci * @stop_filtering:	stops TS filtering
898c2ecf20Sopenharmony_ci *
908c2ecf20Sopenharmony_ci * A TS feed is typically mapped to a hardware PID filter on the demux chip.
918c2ecf20Sopenharmony_ci * Using this API, the client can set the filtering properties to start/stop
928c2ecf20Sopenharmony_ci * filtering TS packets on a particular TS feed.
938c2ecf20Sopenharmony_ci */
948c2ecf20Sopenharmony_cistruct dmx_ts_feed {
958c2ecf20Sopenharmony_ci	int is_filtering;
968c2ecf20Sopenharmony_ci	struct dmx_demux *parent;
978c2ecf20Sopenharmony_ci	void *priv;
988c2ecf20Sopenharmony_ci	int (*set)(struct dmx_ts_feed *feed,
998c2ecf20Sopenharmony_ci		   u16 pid,
1008c2ecf20Sopenharmony_ci		   int type,
1018c2ecf20Sopenharmony_ci		   enum dmx_ts_pes pes_type,
1028c2ecf20Sopenharmony_ci		   ktime_t timeout);
1038c2ecf20Sopenharmony_ci	int (*start_filtering)(struct dmx_ts_feed *feed);
1048c2ecf20Sopenharmony_ci	int (*stop_filtering)(struct dmx_ts_feed *feed);
1058c2ecf20Sopenharmony_ci};
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/*
1088c2ecf20Sopenharmony_ci * Section reception
1098c2ecf20Sopenharmony_ci */
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci/**
1128c2ecf20Sopenharmony_ci * struct dmx_section_filter - Structure that describes a section filter
1138c2ecf20Sopenharmony_ci *
1148c2ecf20Sopenharmony_ci * @filter_value: Contains up to 16 bytes (128 bits) of the TS section header
1158c2ecf20Sopenharmony_ci *		  that will be matched by the section filter
1168c2ecf20Sopenharmony_ci * @filter_mask:  Contains a 16 bytes (128 bits) filter mask with the bits
1178c2ecf20Sopenharmony_ci *		  specified by @filter_value that will be used on the filter
1188c2ecf20Sopenharmony_ci *		  match logic.
1198c2ecf20Sopenharmony_ci * @filter_mode:  Contains a 16 bytes (128 bits) filter mode.
1208c2ecf20Sopenharmony_ci * @parent:	  Back-pointer to struct dmx_section_feed.
1218c2ecf20Sopenharmony_ci * @priv:	  Pointer to private data of the API client.
1228c2ecf20Sopenharmony_ci *
1238c2ecf20Sopenharmony_ci *
1248c2ecf20Sopenharmony_ci * The @filter_mask controls which bits of @filter_value are compared with
1258c2ecf20Sopenharmony_ci * the section headers/payload. On a binary value of 1 in filter_mask, the
1268c2ecf20Sopenharmony_ci * corresponding bits are compared. The filter only accepts sections that are
1278c2ecf20Sopenharmony_ci * equal to filter_value in all the tested bit positions.
1288c2ecf20Sopenharmony_ci */
1298c2ecf20Sopenharmony_cistruct dmx_section_filter {
1308c2ecf20Sopenharmony_ci	u8 filter_value[DMX_MAX_FILTER_SIZE];
1318c2ecf20Sopenharmony_ci	u8 filter_mask[DMX_MAX_FILTER_SIZE];
1328c2ecf20Sopenharmony_ci	u8 filter_mode[DMX_MAX_FILTER_SIZE];
1338c2ecf20Sopenharmony_ci	struct dmx_section_feed *parent;
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	void *priv;
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci/**
1398c2ecf20Sopenharmony_ci * struct dmx_section_feed - Structure that contains a section feed filter
1408c2ecf20Sopenharmony_ci *
1418c2ecf20Sopenharmony_ci * @is_filtering:	Set to non-zero when filtering in progress
1428c2ecf20Sopenharmony_ci * @parent:		pointer to struct dmx_demux
1438c2ecf20Sopenharmony_ci * @priv:		pointer to private data of the API client
1448c2ecf20Sopenharmony_ci * @check_crc:		If non-zero, check the CRC values of filtered sections.
1458c2ecf20Sopenharmony_ci * @set:		sets the section filter
1468c2ecf20Sopenharmony_ci * @allocate_filter:	This function is used to allocate a section filter on
1478c2ecf20Sopenharmony_ci *			the demux. It should only be called when no filtering
1488c2ecf20Sopenharmony_ci *			is in progress on this section feed. If a filter cannot
1498c2ecf20Sopenharmony_ci *			be allocated, the function fails with -ENOSPC.
1508c2ecf20Sopenharmony_ci * @release_filter:	This function releases all the resources of a
1518c2ecf20Sopenharmony_ci *			previously allocated section filter. The function
1528c2ecf20Sopenharmony_ci *			should not be called while filtering is in progress
1538c2ecf20Sopenharmony_ci *			on this section feed. After calling this function,
1548c2ecf20Sopenharmony_ci *			the caller should not try to dereference the filter
1558c2ecf20Sopenharmony_ci *			pointer.
1568c2ecf20Sopenharmony_ci * @start_filtering:	starts section filtering
1578c2ecf20Sopenharmony_ci * @stop_filtering:	stops section filtering
1588c2ecf20Sopenharmony_ci *
1598c2ecf20Sopenharmony_ci * A TS feed is typically mapped to a hardware PID filter on the demux chip.
1608c2ecf20Sopenharmony_ci * Using this API, the client can set the filtering properties to start/stop
1618c2ecf20Sopenharmony_ci * filtering TS packets on a particular TS feed.
1628c2ecf20Sopenharmony_ci */
1638c2ecf20Sopenharmony_cistruct dmx_section_feed {
1648c2ecf20Sopenharmony_ci	int is_filtering;
1658c2ecf20Sopenharmony_ci	struct dmx_demux *parent;
1668c2ecf20Sopenharmony_ci	void *priv;
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	int check_crc;
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	/* private: Used internally at dvb_demux.c */
1718c2ecf20Sopenharmony_ci	u32 crc_val;
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	u8 *secbuf;
1748c2ecf20Sopenharmony_ci	u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
1758c2ecf20Sopenharmony_ci	u16 secbufp, seclen, tsfeedp;
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	/* public: */
1788c2ecf20Sopenharmony_ci	int (*set)(struct dmx_section_feed *feed,
1798c2ecf20Sopenharmony_ci		   u16 pid,
1808c2ecf20Sopenharmony_ci		   int check_crc);
1818c2ecf20Sopenharmony_ci	int (*allocate_filter)(struct dmx_section_feed *feed,
1828c2ecf20Sopenharmony_ci			       struct dmx_section_filter **filter);
1838c2ecf20Sopenharmony_ci	int (*release_filter)(struct dmx_section_feed *feed,
1848c2ecf20Sopenharmony_ci			      struct dmx_section_filter *filter);
1858c2ecf20Sopenharmony_ci	int (*start_filtering)(struct dmx_section_feed *feed);
1868c2ecf20Sopenharmony_ci	int (*stop_filtering)(struct dmx_section_feed *feed);
1878c2ecf20Sopenharmony_ci};
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci/**
1908c2ecf20Sopenharmony_ci * typedef dmx_ts_cb - DVB demux TS filter callback function prototype
1918c2ecf20Sopenharmony_ci *
1928c2ecf20Sopenharmony_ci * @buffer1:		Pointer to the start of the filtered TS packets.
1938c2ecf20Sopenharmony_ci * @buffer1_length:	Length of the TS data in buffer1.
1948c2ecf20Sopenharmony_ci * @buffer2:		Pointer to the tail of the filtered TS packets, or NULL.
1958c2ecf20Sopenharmony_ci * @buffer2_length:	Length of the TS data in buffer2.
1968c2ecf20Sopenharmony_ci * @source:		Indicates which TS feed is the source of the callback.
1978c2ecf20Sopenharmony_ci * @buffer_flags:	Address where buffer flags are stored. Those are
1988c2ecf20Sopenharmony_ci *			used to report discontinuity users via DVB
1998c2ecf20Sopenharmony_ci *			memory mapped API, as defined by
2008c2ecf20Sopenharmony_ci *			&enum dmx_buffer_flags.
2018c2ecf20Sopenharmony_ci *
2028c2ecf20Sopenharmony_ci * This function callback prototype, provided by the client of the demux API,
2038c2ecf20Sopenharmony_ci * is called from the demux code. The function is only called when filtering
2048c2ecf20Sopenharmony_ci * on a TS feed has been enabled using the start_filtering\(\) function at
2058c2ecf20Sopenharmony_ci * the &dmx_demux.
2068c2ecf20Sopenharmony_ci * Any TS packets that match the filter settings are copied to a circular
2078c2ecf20Sopenharmony_ci * buffer. The filtered TS packets are delivered to the client using this
2088c2ecf20Sopenharmony_ci * callback function.
2098c2ecf20Sopenharmony_ci * It is expected that the @buffer1 and @buffer2 callback parameters point to
2108c2ecf20Sopenharmony_ci * addresses within the circular buffer, but other implementations are also
2118c2ecf20Sopenharmony_ci * possible. Note that the called party should not try to free the memory
2128c2ecf20Sopenharmony_ci * the @buffer1 and @buffer2 parameters point to.
2138c2ecf20Sopenharmony_ci *
2148c2ecf20Sopenharmony_ci * When this function is called, the @buffer1 parameter typically points to
2158c2ecf20Sopenharmony_ci * the start of the first undelivered TS packet within a circular buffer.
2168c2ecf20Sopenharmony_ci * The @buffer2 buffer parameter is normally NULL, except when the received
2178c2ecf20Sopenharmony_ci * TS packets have crossed the last address of the circular buffer and
2188c2ecf20Sopenharmony_ci * "wrapped" to the beginning of the buffer. In the latter case the @buffer1
2198c2ecf20Sopenharmony_ci * parameter would contain an address within the circular buffer, while the
2208c2ecf20Sopenharmony_ci * @buffer2 parameter would contain the first address of the circular buffer.
2218c2ecf20Sopenharmony_ci * The number of bytes delivered with this function (i.e. @buffer1_length +
2228c2ecf20Sopenharmony_ci * @buffer2_length) is usually equal to the value of callback_length parameter
2238c2ecf20Sopenharmony_ci * given in the set() function, with one exception: if a timeout occurs before
2248c2ecf20Sopenharmony_ci * receiving callback_length bytes of TS data, any undelivered packets are
2258c2ecf20Sopenharmony_ci * immediately delivered to the client by calling this function. The timeout
2268c2ecf20Sopenharmony_ci * duration is controlled by the set() function in the TS Feed API.
2278c2ecf20Sopenharmony_ci *
2288c2ecf20Sopenharmony_ci * If a TS packet is received with errors that could not be fixed by the
2298c2ecf20Sopenharmony_ci * TS-level forward error correction (FEC), the Transport_error_indicator
2308c2ecf20Sopenharmony_ci * flag of the TS packet header should be set. The TS packet should not be
2318c2ecf20Sopenharmony_ci * discarded, as the error can possibly be corrected by a higher layer
2328c2ecf20Sopenharmony_ci * protocol. If the called party is slow in processing the callback, it
2338c2ecf20Sopenharmony_ci * is possible that the circular buffer eventually fills up. If this happens,
2348c2ecf20Sopenharmony_ci * the demux driver should discard any TS packets received while the buffer
2358c2ecf20Sopenharmony_ci * is full and return -EOVERFLOW.
2368c2ecf20Sopenharmony_ci *
2378c2ecf20Sopenharmony_ci * The type of data returned to the callback can be selected by the
2388c2ecf20Sopenharmony_ci * &dmx_ts_feed.@set function. The type parameter decides if the raw
2398c2ecf20Sopenharmony_ci * TS packet (TS_PACKET) or just the payload (TS_PACKET|TS_PAYLOAD_ONLY)
2408c2ecf20Sopenharmony_ci * should be returned. If additionally the TS_DECODER bit is set the stream
2418c2ecf20Sopenharmony_ci * will also be sent to the hardware MPEG decoder.
2428c2ecf20Sopenharmony_ci *
2438c2ecf20Sopenharmony_ci * Return:
2448c2ecf20Sopenharmony_ci *
2458c2ecf20Sopenharmony_ci * - 0, on success;
2468c2ecf20Sopenharmony_ci *
2478c2ecf20Sopenharmony_ci * - -EOVERFLOW, on buffer overflow.
2488c2ecf20Sopenharmony_ci */
2498c2ecf20Sopenharmony_citypedef int (*dmx_ts_cb)(const u8 *buffer1,
2508c2ecf20Sopenharmony_ci			 size_t buffer1_length,
2518c2ecf20Sopenharmony_ci			 const u8 *buffer2,
2528c2ecf20Sopenharmony_ci			 size_t buffer2_length,
2538c2ecf20Sopenharmony_ci			 struct dmx_ts_feed *source,
2548c2ecf20Sopenharmony_ci			 u32 *buffer_flags);
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci/**
2578c2ecf20Sopenharmony_ci * typedef dmx_section_cb - DVB demux TS filter callback function prototype
2588c2ecf20Sopenharmony_ci *
2598c2ecf20Sopenharmony_ci * @buffer1:		Pointer to the start of the filtered section, e.g.
2608c2ecf20Sopenharmony_ci *			within the circular buffer of the demux driver.
2618c2ecf20Sopenharmony_ci * @buffer1_len:	Length of the filtered section data in @buffer1,
2628c2ecf20Sopenharmony_ci *			including headers and CRC.
2638c2ecf20Sopenharmony_ci * @buffer2:		Pointer to the tail of the filtered section data,
2648c2ecf20Sopenharmony_ci *			or NULL. Useful to handle the wrapping of a
2658c2ecf20Sopenharmony_ci *			circular buffer.
2668c2ecf20Sopenharmony_ci * @buffer2_len:	Length of the filtered section data in @buffer2,
2678c2ecf20Sopenharmony_ci *			including headers and CRC.
2688c2ecf20Sopenharmony_ci * @source:		Indicates which section feed is the source of the
2698c2ecf20Sopenharmony_ci *			callback.
2708c2ecf20Sopenharmony_ci * @buffer_flags:	Address where buffer flags are stored. Those are
2718c2ecf20Sopenharmony_ci *			used to report discontinuity users via DVB
2728c2ecf20Sopenharmony_ci *			memory mapped API, as defined by
2738c2ecf20Sopenharmony_ci *			&enum dmx_buffer_flags.
2748c2ecf20Sopenharmony_ci *
2758c2ecf20Sopenharmony_ci * This function callback prototype, provided by the client of the demux API,
2768c2ecf20Sopenharmony_ci * is called from the demux code. The function is only called when
2778c2ecf20Sopenharmony_ci * filtering of sections has been enabled using the function
2788c2ecf20Sopenharmony_ci * &dmx_ts_feed.@start_filtering. When the demux driver has received a
2798c2ecf20Sopenharmony_ci * complete section that matches at least one section filter, the client
2808c2ecf20Sopenharmony_ci * is notified via this callback function. Normally this function is called
2818c2ecf20Sopenharmony_ci * for each received section; however, it is also possible to deliver
2828c2ecf20Sopenharmony_ci * multiple sections with one callback, for example when the system load
2838c2ecf20Sopenharmony_ci * is high. If an error occurs while receiving a section, this
2848c2ecf20Sopenharmony_ci * function should be called with the corresponding error type set in the
2858c2ecf20Sopenharmony_ci * success field, whether or not there is data to deliver. The Section Feed
2868c2ecf20Sopenharmony_ci * implementation should maintain a circular buffer for received sections.
2878c2ecf20Sopenharmony_ci * However, this is not necessary if the Section Feed API is implemented as
2888c2ecf20Sopenharmony_ci * a client of the TS Feed API, because the TS Feed implementation then
2898c2ecf20Sopenharmony_ci * buffers the received data. The size of the circular buffer can be
2908c2ecf20Sopenharmony_ci * configured using the &dmx_ts_feed.@set function in the Section Feed API.
2918c2ecf20Sopenharmony_ci * If there is no room in the circular buffer when a new section is received,
2928c2ecf20Sopenharmony_ci * the section must be discarded. If this happens, the value of the success
2938c2ecf20Sopenharmony_ci * parameter should be DMX_OVERRUN_ERROR on the next callback.
2948c2ecf20Sopenharmony_ci */
2958c2ecf20Sopenharmony_citypedef int (*dmx_section_cb)(const u8 *buffer1,
2968c2ecf20Sopenharmony_ci			      size_t buffer1_len,
2978c2ecf20Sopenharmony_ci			      const u8 *buffer2,
2988c2ecf20Sopenharmony_ci			      size_t buffer2_len,
2998c2ecf20Sopenharmony_ci			      struct dmx_section_filter *source,
3008c2ecf20Sopenharmony_ci			      u32 *buffer_flags);
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci/*
3038c2ecf20Sopenharmony_ci * DVB Front-End
3048c2ecf20Sopenharmony_ci */
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci/**
3078c2ecf20Sopenharmony_ci * enum dmx_frontend_source - Used to identify the type of frontend
3088c2ecf20Sopenharmony_ci *
3098c2ecf20Sopenharmony_ci * @DMX_MEMORY_FE:	The source of the demux is memory. It means that
3108c2ecf20Sopenharmony_ci *			the MPEG-TS to be filtered comes from userspace,
3118c2ecf20Sopenharmony_ci *			via write() syscall.
3128c2ecf20Sopenharmony_ci *
3138c2ecf20Sopenharmony_ci * @DMX_FRONTEND_0:	The source of the demux is a frontend connected
3148c2ecf20Sopenharmony_ci *			to the demux.
3158c2ecf20Sopenharmony_ci */
3168c2ecf20Sopenharmony_cienum dmx_frontend_source {
3178c2ecf20Sopenharmony_ci	DMX_MEMORY_FE,
3188c2ecf20Sopenharmony_ci	DMX_FRONTEND_0,
3198c2ecf20Sopenharmony_ci};
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci/**
3228c2ecf20Sopenharmony_ci * struct dmx_frontend - Structure that lists the frontends associated with
3238c2ecf20Sopenharmony_ci *			 a demux
3248c2ecf20Sopenharmony_ci *
3258c2ecf20Sopenharmony_ci * @connectivity_list:	List of front-ends that can be connected to a
3268c2ecf20Sopenharmony_ci *			particular demux;
3278c2ecf20Sopenharmony_ci * @source:		Type of the frontend.
3288c2ecf20Sopenharmony_ci *
3298c2ecf20Sopenharmony_ci * FIXME: this structure should likely be replaced soon by some
3308c2ecf20Sopenharmony_ci *	media-controller based logic.
3318c2ecf20Sopenharmony_ci */
3328c2ecf20Sopenharmony_cistruct dmx_frontend {
3338c2ecf20Sopenharmony_ci	struct list_head connectivity_list;
3348c2ecf20Sopenharmony_ci	enum dmx_frontend_source source;
3358c2ecf20Sopenharmony_ci};
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci/*
3388c2ecf20Sopenharmony_ci * MPEG-2 TS Demux
3398c2ecf20Sopenharmony_ci */
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci/**
3428c2ecf20Sopenharmony_ci * enum dmx_demux_caps - MPEG-2 TS Demux capabilities bitmap
3438c2ecf20Sopenharmony_ci *
3448c2ecf20Sopenharmony_ci * @DMX_TS_FILTERING:		set if TS filtering is supported;
3458c2ecf20Sopenharmony_ci * @DMX_SECTION_FILTERING:	set if section filtering is supported;
3468c2ecf20Sopenharmony_ci * @DMX_MEMORY_BASED_FILTERING:	set if write() available.
3478c2ecf20Sopenharmony_ci *
3488c2ecf20Sopenharmony_ci * Those flags are OR'ed in the &dmx_demux.capabilities field
3498c2ecf20Sopenharmony_ci */
3508c2ecf20Sopenharmony_cienum dmx_demux_caps {
3518c2ecf20Sopenharmony_ci	DMX_TS_FILTERING = 1,
3528c2ecf20Sopenharmony_ci	DMX_SECTION_FILTERING = 4,
3538c2ecf20Sopenharmony_ci	DMX_MEMORY_BASED_FILTERING = 8,
3548c2ecf20Sopenharmony_ci};
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci/*
3578c2ecf20Sopenharmony_ci * Demux resource type identifier.
3588c2ecf20Sopenharmony_ci */
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci/**
3618c2ecf20Sopenharmony_ci * DMX_FE_ENTRY - Casts elements in the list of registered
3628c2ecf20Sopenharmony_ci *		  front-ends from the generic type struct list_head
3638c2ecf20Sopenharmony_ci *		  to the type * struct dmx_frontend
3648c2ecf20Sopenharmony_ci *
3658c2ecf20Sopenharmony_ci * @list: list of struct dmx_frontend
3668c2ecf20Sopenharmony_ci */
3678c2ecf20Sopenharmony_ci#define DMX_FE_ENTRY(list) \
3688c2ecf20Sopenharmony_ci	list_entry(list, struct dmx_frontend, connectivity_list)
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci/**
3718c2ecf20Sopenharmony_ci * struct dmx_demux - Structure that contains the demux capabilities and
3728c2ecf20Sopenharmony_ci *		      callbacks.
3738c2ecf20Sopenharmony_ci *
3748c2ecf20Sopenharmony_ci * @capabilities: Bitfield of capability flags.
3758c2ecf20Sopenharmony_ci *
3768c2ecf20Sopenharmony_ci * @frontend: Front-end connected to the demux
3778c2ecf20Sopenharmony_ci *
3788c2ecf20Sopenharmony_ci * @priv: Pointer to private data of the API client
3798c2ecf20Sopenharmony_ci *
3808c2ecf20Sopenharmony_ci * @open: This function reserves the demux for use by the caller and, if
3818c2ecf20Sopenharmony_ci *	necessary, initializes the demux. When the demux is no longer needed,
3828c2ecf20Sopenharmony_ci *	the function @close should be called. It should be possible for
3838c2ecf20Sopenharmony_ci *	multiple clients to access the demux at the same time. Thus, the
3848c2ecf20Sopenharmony_ci *	function implementation should increment the demux usage count when
3858c2ecf20Sopenharmony_ci *	@open is called and decrement it when @close is called.
3868c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
3878c2ecf20Sopenharmony_ci *	instance data.
3888c2ecf20Sopenharmony_ci *	It returns:
3898c2ecf20Sopenharmony_ci *	0 on success;
3908c2ecf20Sopenharmony_ci *	-EUSERS, if maximum usage count was reached;
3918c2ecf20Sopenharmony_ci *	-EINVAL, on bad parameter.
3928c2ecf20Sopenharmony_ci *
3938c2ecf20Sopenharmony_ci * @close: This function reserves the demux for use by the caller and, if
3948c2ecf20Sopenharmony_ci *	necessary, initializes the demux. When the demux is no longer needed,
3958c2ecf20Sopenharmony_ci *	the function @close should be called. It should be possible for
3968c2ecf20Sopenharmony_ci *	multiple clients to access the demux at the same time. Thus, the
3978c2ecf20Sopenharmony_ci *	function implementation should increment the demux usage count when
3988c2ecf20Sopenharmony_ci *	@open is called and decrement it when @close is called.
3998c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
4008c2ecf20Sopenharmony_ci *	instance data.
4018c2ecf20Sopenharmony_ci *	It returns:
4028c2ecf20Sopenharmony_ci *	0 on success;
4038c2ecf20Sopenharmony_ci *	-ENODEV, if demux was not in use (e. g. no users);
4048c2ecf20Sopenharmony_ci *	-EINVAL, on bad parameter.
4058c2ecf20Sopenharmony_ci *
4068c2ecf20Sopenharmony_ci * @write: This function provides the demux driver with a memory buffer
4078c2ecf20Sopenharmony_ci *	containing TS packets. Instead of receiving TS packets from the DVB
4088c2ecf20Sopenharmony_ci *	front-end, the demux driver software will read packets from memory.
4098c2ecf20Sopenharmony_ci *	Any clients of this demux with active TS, PES or Section filters will
4108c2ecf20Sopenharmony_ci *	receive filtered data via the Demux callback API (see 0). The function
4118c2ecf20Sopenharmony_ci *	returns when all the data in the buffer has been consumed by the demux.
4128c2ecf20Sopenharmony_ci *	Demux hardware typically cannot read TS from memory. If this is the
4138c2ecf20Sopenharmony_ci *	case, memory-based filtering has to be implemented entirely in software.
4148c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
4158c2ecf20Sopenharmony_ci *	instance data.
4168c2ecf20Sopenharmony_ci *	The @buf function parameter contains a pointer to the TS data in
4178c2ecf20Sopenharmony_ci *	kernel-space memory.
4188c2ecf20Sopenharmony_ci *	The @count function parameter contains the length of the TS data.
4198c2ecf20Sopenharmony_ci *	It returns:
4208c2ecf20Sopenharmony_ci *	0 on success;
4218c2ecf20Sopenharmony_ci *	-ERESTARTSYS, if mutex lock was interrupted;
4228c2ecf20Sopenharmony_ci *	-EINTR, if a signal handling is pending;
4238c2ecf20Sopenharmony_ci *	-ENODEV, if demux was removed;
4248c2ecf20Sopenharmony_ci *	-EINVAL, on bad parameter.
4258c2ecf20Sopenharmony_ci *
4268c2ecf20Sopenharmony_ci * @allocate_ts_feed: Allocates a new TS feed, which is used to filter the TS
4278c2ecf20Sopenharmony_ci *	packets carrying a certain PID. The TS feed normally corresponds to a
4288c2ecf20Sopenharmony_ci *	hardware PID filter on the demux chip.
4298c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
4308c2ecf20Sopenharmony_ci *	instance data.
4318c2ecf20Sopenharmony_ci *	The @feed function parameter contains a pointer to the TS feed API and
4328c2ecf20Sopenharmony_ci *	instance data.
4338c2ecf20Sopenharmony_ci *	The @callback function parameter contains a pointer to the callback
4348c2ecf20Sopenharmony_ci *	function for passing received TS packet.
4358c2ecf20Sopenharmony_ci *	It returns:
4368c2ecf20Sopenharmony_ci *	0 on success;
4378c2ecf20Sopenharmony_ci *	-ERESTARTSYS, if mutex lock was interrupted;
4388c2ecf20Sopenharmony_ci *	-EBUSY, if no more TS feeds is available;
4398c2ecf20Sopenharmony_ci *	-EINVAL, on bad parameter.
4408c2ecf20Sopenharmony_ci *
4418c2ecf20Sopenharmony_ci * @release_ts_feed: Releases the resources allocated with @allocate_ts_feed.
4428c2ecf20Sopenharmony_ci *	Any filtering in progress on the TS feed should be stopped before
4438c2ecf20Sopenharmony_ci *	calling this function.
4448c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
4458c2ecf20Sopenharmony_ci *	instance data.
4468c2ecf20Sopenharmony_ci *	The @feed function parameter contains a pointer to the TS feed API and
4478c2ecf20Sopenharmony_ci *	instance data.
4488c2ecf20Sopenharmony_ci *	It returns:
4498c2ecf20Sopenharmony_ci *	0 on success;
4508c2ecf20Sopenharmony_ci *	-EINVAL on bad parameter.
4518c2ecf20Sopenharmony_ci *
4528c2ecf20Sopenharmony_ci * @allocate_section_feed: Allocates a new section feed, i.e. a demux resource
4538c2ecf20Sopenharmony_ci *	for filtering and receiving sections. On platforms with hardware
4548c2ecf20Sopenharmony_ci *	support for section filtering, a section feed is directly mapped to
4558c2ecf20Sopenharmony_ci *	the demux HW. On other platforms, TS packets are first PID filtered in
4568c2ecf20Sopenharmony_ci *	hardware and a hardware section filter then emulated in software. The
4578c2ecf20Sopenharmony_ci *	caller obtains an API pointer of type dmx_section_feed_t as an out
4588c2ecf20Sopenharmony_ci *	parameter. Using this API the caller can set filtering parameters and
4598c2ecf20Sopenharmony_ci *	start receiving sections.
4608c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
4618c2ecf20Sopenharmony_ci *	instance data.
4628c2ecf20Sopenharmony_ci *	The @feed function parameter contains a pointer to the TS feed API and
4638c2ecf20Sopenharmony_ci *	instance data.
4648c2ecf20Sopenharmony_ci *	The @callback function parameter contains a pointer to the callback
4658c2ecf20Sopenharmony_ci *	function for passing received TS packet.
4668c2ecf20Sopenharmony_ci *	It returns:
4678c2ecf20Sopenharmony_ci *	0 on success;
4688c2ecf20Sopenharmony_ci *	-EBUSY, if no more TS feeds is available;
4698c2ecf20Sopenharmony_ci *	-EINVAL, on bad parameter.
4708c2ecf20Sopenharmony_ci *
4718c2ecf20Sopenharmony_ci * @release_section_feed: Releases the resources allocated with
4728c2ecf20Sopenharmony_ci *	@allocate_section_feed, including allocated filters. Any filtering in
4738c2ecf20Sopenharmony_ci *	progress on the section feed should be stopped before calling this
4748c2ecf20Sopenharmony_ci *	function.
4758c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
4768c2ecf20Sopenharmony_ci *	instance data.
4778c2ecf20Sopenharmony_ci *	The @feed function parameter contains a pointer to the TS feed API and
4788c2ecf20Sopenharmony_ci *	instance data.
4798c2ecf20Sopenharmony_ci *	It returns:
4808c2ecf20Sopenharmony_ci *	0 on success;
4818c2ecf20Sopenharmony_ci *	-EINVAL, on bad parameter.
4828c2ecf20Sopenharmony_ci *
4838c2ecf20Sopenharmony_ci * @add_frontend: Registers a connectivity between a demux and a front-end,
4848c2ecf20Sopenharmony_ci *	i.e., indicates that the demux can be connected via a call to
4858c2ecf20Sopenharmony_ci *	@connect_frontend to use the given front-end as a TS source. The
4868c2ecf20Sopenharmony_ci *	client of this function has to allocate dynamic or static memory for
4878c2ecf20Sopenharmony_ci *	the frontend structure and initialize its fields before calling this
4888c2ecf20Sopenharmony_ci *	function. This function is normally called during the driver
4898c2ecf20Sopenharmony_ci *	initialization. The caller must not free the memory of the frontend
4908c2ecf20Sopenharmony_ci *	struct before successfully calling @remove_frontend.
4918c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
4928c2ecf20Sopenharmony_ci *	instance data.
4938c2ecf20Sopenharmony_ci *	The @frontend function parameter contains a pointer to the front-end
4948c2ecf20Sopenharmony_ci *	instance data.
4958c2ecf20Sopenharmony_ci *	It returns:
4968c2ecf20Sopenharmony_ci *	0 on success;
4978c2ecf20Sopenharmony_ci *	-EINVAL, on bad parameter.
4988c2ecf20Sopenharmony_ci *
4998c2ecf20Sopenharmony_ci * @remove_frontend: Indicates that the given front-end, registered by a call
5008c2ecf20Sopenharmony_ci *	to @add_frontend, can no longer be connected as a TS source by this
5018c2ecf20Sopenharmony_ci *	demux. The function should be called when a front-end driver or a demux
5028c2ecf20Sopenharmony_ci *	driver is removed from the system. If the front-end is in use, the
5038c2ecf20Sopenharmony_ci *	function fails with the return value of -EBUSY. After successfully
5048c2ecf20Sopenharmony_ci *	calling this function, the caller can free the memory of the frontend
5058c2ecf20Sopenharmony_ci *	struct if it was dynamically allocated before the @add_frontend
5068c2ecf20Sopenharmony_ci *	operation.
5078c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
5088c2ecf20Sopenharmony_ci *	instance data.
5098c2ecf20Sopenharmony_ci *	The @frontend function parameter contains a pointer to the front-end
5108c2ecf20Sopenharmony_ci *	instance data.
5118c2ecf20Sopenharmony_ci *	It returns:
5128c2ecf20Sopenharmony_ci *	0 on success;
5138c2ecf20Sopenharmony_ci *	-ENODEV, if the front-end was not found,
5148c2ecf20Sopenharmony_ci *	-EINVAL, on bad parameter.
5158c2ecf20Sopenharmony_ci *
5168c2ecf20Sopenharmony_ci * @get_frontends: Provides the APIs of the front-ends that have been
5178c2ecf20Sopenharmony_ci *	registered for this demux. Any of the front-ends obtained with this
5188c2ecf20Sopenharmony_ci *	call can be used as a parameter for @connect_frontend. The include
5198c2ecf20Sopenharmony_ci *	file demux.h contains the macro DMX_FE_ENTRY() for converting an
5208c2ecf20Sopenharmony_ci *	element of the generic type struct &list_head * to the type
5218c2ecf20Sopenharmony_ci *	struct &dmx_frontend *. The caller must not free the memory of any of
5228c2ecf20Sopenharmony_ci *	the elements obtained via this function call.
5238c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
5248c2ecf20Sopenharmony_ci *	instance data.
5258c2ecf20Sopenharmony_ci *	It returns a struct list_head pointer to the list of front-end
5268c2ecf20Sopenharmony_ci *	interfaces, or NULL in the case of an empty list.
5278c2ecf20Sopenharmony_ci *
5288c2ecf20Sopenharmony_ci * @connect_frontend: Connects the TS output of the front-end to the input of
5298c2ecf20Sopenharmony_ci *	the demux. A demux can only be connected to a front-end registered to
5308c2ecf20Sopenharmony_ci *	the demux with the function @add_frontend. It may or may not be
5318c2ecf20Sopenharmony_ci *	possible to connect multiple demuxes to the same front-end, depending
5328c2ecf20Sopenharmony_ci *	on the capabilities of the HW platform. When not used, the front-end
5338c2ecf20Sopenharmony_ci *	should be released by calling @disconnect_frontend.
5348c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
5358c2ecf20Sopenharmony_ci *	instance data.
5368c2ecf20Sopenharmony_ci *	The @frontend function parameter contains a pointer to the front-end
5378c2ecf20Sopenharmony_ci *	instance data.
5388c2ecf20Sopenharmony_ci *	It returns:
5398c2ecf20Sopenharmony_ci *	0 on success;
5408c2ecf20Sopenharmony_ci *	-EINVAL, on bad parameter.
5418c2ecf20Sopenharmony_ci *
5428c2ecf20Sopenharmony_ci * @disconnect_frontend: Disconnects the demux and a front-end previously
5438c2ecf20Sopenharmony_ci *	connected by a @connect_frontend call.
5448c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
5458c2ecf20Sopenharmony_ci *	instance data.
5468c2ecf20Sopenharmony_ci *	It returns:
5478c2ecf20Sopenharmony_ci *	0 on success;
5488c2ecf20Sopenharmony_ci *	-EINVAL on bad parameter.
5498c2ecf20Sopenharmony_ci *
5508c2ecf20Sopenharmony_ci * @get_pes_pids: Get the PIDs for DMX_PES_AUDIO0, DMX_PES_VIDEO0,
5518c2ecf20Sopenharmony_ci *	DMX_PES_TELETEXT0, DMX_PES_SUBTITLE0 and DMX_PES_PCR0.
5528c2ecf20Sopenharmony_ci *	The @demux function parameter contains a pointer to the demux API and
5538c2ecf20Sopenharmony_ci *	instance data.
5548c2ecf20Sopenharmony_ci *	The @pids function parameter contains an array with five u16 elements
5558c2ecf20Sopenharmony_ci *	where the PIDs will be stored.
5568c2ecf20Sopenharmony_ci *	It returns:
5578c2ecf20Sopenharmony_ci *	0 on success;
5588c2ecf20Sopenharmony_ci *	-EINVAL on bad parameter.
5598c2ecf20Sopenharmony_ci */
5608c2ecf20Sopenharmony_cistruct dmx_demux {
5618c2ecf20Sopenharmony_ci	enum dmx_demux_caps capabilities;
5628c2ecf20Sopenharmony_ci	struct dmx_frontend *frontend;
5638c2ecf20Sopenharmony_ci	void *priv;
5648c2ecf20Sopenharmony_ci	int (*open)(struct dmx_demux *demux);
5658c2ecf20Sopenharmony_ci	int (*close)(struct dmx_demux *demux);
5668c2ecf20Sopenharmony_ci	int (*write)(struct dmx_demux *demux, const char __user *buf,
5678c2ecf20Sopenharmony_ci		     size_t count);
5688c2ecf20Sopenharmony_ci	int (*allocate_ts_feed)(struct dmx_demux *demux,
5698c2ecf20Sopenharmony_ci				struct dmx_ts_feed **feed,
5708c2ecf20Sopenharmony_ci				dmx_ts_cb callback);
5718c2ecf20Sopenharmony_ci	int (*release_ts_feed)(struct dmx_demux *demux,
5728c2ecf20Sopenharmony_ci			       struct dmx_ts_feed *feed);
5738c2ecf20Sopenharmony_ci	int (*allocate_section_feed)(struct dmx_demux *demux,
5748c2ecf20Sopenharmony_ci				     struct dmx_section_feed **feed,
5758c2ecf20Sopenharmony_ci				     dmx_section_cb callback);
5768c2ecf20Sopenharmony_ci	int (*release_section_feed)(struct dmx_demux *demux,
5778c2ecf20Sopenharmony_ci				    struct dmx_section_feed *feed);
5788c2ecf20Sopenharmony_ci	int (*add_frontend)(struct dmx_demux *demux,
5798c2ecf20Sopenharmony_ci			    struct dmx_frontend *frontend);
5808c2ecf20Sopenharmony_ci	int (*remove_frontend)(struct dmx_demux *demux,
5818c2ecf20Sopenharmony_ci			       struct dmx_frontend *frontend);
5828c2ecf20Sopenharmony_ci	struct list_head *(*get_frontends)(struct dmx_demux *demux);
5838c2ecf20Sopenharmony_ci	int (*connect_frontend)(struct dmx_demux *demux,
5848c2ecf20Sopenharmony_ci				struct dmx_frontend *frontend);
5858c2ecf20Sopenharmony_ci	int (*disconnect_frontend)(struct dmx_demux *demux);
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci	int (*get_pes_pids)(struct dmx_demux *demux, u16 *pids);
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci	/* private: */
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci	/*
5928c2ecf20Sopenharmony_ci	 * Only used at av7110, to read some data from firmware.
5938c2ecf20Sopenharmony_ci	 * As this was never documented, we have no clue about what's
5948c2ecf20Sopenharmony_ci	 * there, and its usage on other drivers aren't encouraged.
5958c2ecf20Sopenharmony_ci	 */
5968c2ecf20Sopenharmony_ci	int (*get_stc)(struct dmx_demux *demux, unsigned int num,
5978c2ecf20Sopenharmony_ci		       u64 *stc, unsigned int *base);
5988c2ecf20Sopenharmony_ci};
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci#endif /* #ifndef __DEMUX_H */
601