1fada1935SMauro Carvalho Chehab /* 2fada1935SMauro Carvalho Chehab * demux.h 3fada1935SMauro Carvalho Chehab * 4fada1935SMauro Carvalho Chehab * The Kernel Digital TV Demux kABI defines a driver-internal interface for 5fada1935SMauro Carvalho Chehab * registering low-level, hardware specific driver to a hardware independent 6fada1935SMauro Carvalho Chehab * demux layer. 7fada1935SMauro Carvalho Chehab * 8fada1935SMauro Carvalho Chehab * Copyright (c) 2002 Convergence GmbH 9fada1935SMauro Carvalho Chehab * 10fada1935SMauro Carvalho Chehab * based on code: 11fada1935SMauro Carvalho Chehab * Copyright (c) 2000 Nokia Research Center 12fada1935SMauro Carvalho Chehab * Tampere, FINLAND 13fada1935SMauro Carvalho Chehab * 14fada1935SMauro Carvalho Chehab * This program is free software; you can redistribute it and/or 15fada1935SMauro Carvalho Chehab * modify it under the terms of the GNU Lesser General Public License 16fada1935SMauro Carvalho Chehab * as published by the Free Software Foundation; either version 2.1 17fada1935SMauro Carvalho Chehab * of the License, or (at your option) any later version. 18fada1935SMauro Carvalho Chehab * 19fada1935SMauro Carvalho Chehab * This program is distributed in the hope that it will be useful, 20fada1935SMauro Carvalho Chehab * but WITHOUT ANY WARRANTY; without even the implied warranty of 21fada1935SMauro Carvalho Chehab * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22fada1935SMauro Carvalho Chehab * GNU General Public License for more details. 23fada1935SMauro Carvalho Chehab * 24fada1935SMauro Carvalho Chehab */ 25fada1935SMauro Carvalho Chehab 26fada1935SMauro Carvalho Chehab #ifndef __DEMUX_H 27fada1935SMauro Carvalho Chehab #define __DEMUX_H 28fada1935SMauro Carvalho Chehab 29fada1935SMauro Carvalho Chehab #include <linux/types.h> 30fada1935SMauro Carvalho Chehab #include <linux/errno.h> 31fada1935SMauro Carvalho Chehab #include <linux/list.h> 32fada1935SMauro Carvalho Chehab #include <linux/time.h> 33fada1935SMauro Carvalho Chehab #include <linux/dvb/dmx.h> 34fada1935SMauro Carvalho Chehab 35fada1935SMauro Carvalho Chehab /* 36fada1935SMauro Carvalho Chehab * Common definitions 37fada1935SMauro Carvalho Chehab */ 38fada1935SMauro Carvalho Chehab 39fada1935SMauro Carvalho Chehab /* 40fada1935SMauro Carvalho Chehab * DMX_MAX_FILTER_SIZE: Maximum length (in bytes) of a section/PES filter. 41fada1935SMauro Carvalho Chehab */ 42fada1935SMauro Carvalho Chehab 43fada1935SMauro Carvalho Chehab #ifndef DMX_MAX_FILTER_SIZE 44fada1935SMauro Carvalho Chehab #define DMX_MAX_FILTER_SIZE 18 45fada1935SMauro Carvalho Chehab #endif 46fada1935SMauro Carvalho Chehab 47fada1935SMauro Carvalho Chehab /* 48fada1935SMauro Carvalho Chehab * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed 49fada1935SMauro Carvalho Chehab * filter. 50fada1935SMauro Carvalho Chehab */ 51fada1935SMauro Carvalho Chehab 52fada1935SMauro Carvalho Chehab #ifndef DMX_MAX_SECTION_SIZE 53fada1935SMauro Carvalho Chehab #define DMX_MAX_SECTION_SIZE 4096 54fada1935SMauro Carvalho Chehab #endif 55fada1935SMauro Carvalho Chehab #ifndef DMX_MAX_SECFEED_SIZE 56fada1935SMauro Carvalho Chehab #define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188) 57fada1935SMauro Carvalho Chehab #endif 58fada1935SMauro Carvalho Chehab 59fada1935SMauro Carvalho Chehab /* 60fada1935SMauro Carvalho Chehab * TS packet reception 61fada1935SMauro Carvalho Chehab */ 62fada1935SMauro Carvalho Chehab 63fada1935SMauro Carvalho Chehab /** 64fada1935SMauro Carvalho Chehab * enum ts_filter_type - filter type bitmap for dmx_ts_feed.set\(\) 65fada1935SMauro Carvalho Chehab * 66fada1935SMauro Carvalho Chehab * @TS_PACKET: Send TS packets (188 bytes) to callback (default). 67fada1935SMauro Carvalho Chehab * @TS_PAYLOAD_ONLY: In case TS_PACKET is set, only send the TS payload 68fada1935SMauro Carvalho Chehab * (<=184 bytes per packet) to callback 69fada1935SMauro Carvalho Chehab * @TS_DECODER: Send stream to built-in decoder (if present). 70fada1935SMauro Carvalho Chehab * @TS_DEMUX: In case TS_PACKET is set, send the TS to the demux 71fada1935SMauro Carvalho Chehab * device, not to the dvr device 72fada1935SMauro Carvalho Chehab */ 73fada1935SMauro Carvalho Chehab enum ts_filter_type { 74fada1935SMauro Carvalho Chehab TS_PACKET = 1, 75fada1935SMauro Carvalho Chehab TS_PAYLOAD_ONLY = 2, 76fada1935SMauro Carvalho Chehab TS_DECODER = 4, 77fada1935SMauro Carvalho Chehab TS_DEMUX = 8, 78fada1935SMauro Carvalho Chehab }; 79fada1935SMauro Carvalho Chehab 80fada1935SMauro Carvalho Chehab /** 81fada1935SMauro Carvalho Chehab * struct dmx_ts_feed - Structure that contains a TS feed filter 82fada1935SMauro Carvalho Chehab * 83fada1935SMauro Carvalho Chehab * @is_filtering: Set to non-zero when filtering in progress 84fada1935SMauro Carvalho Chehab * @parent: pointer to struct dmx_demux 85fada1935SMauro Carvalho Chehab * @priv: pointer to private data of the API client 86fada1935SMauro Carvalho Chehab * @set: sets the TS filter 87fada1935SMauro Carvalho Chehab * @start_filtering: starts TS filtering 88fada1935SMauro Carvalho Chehab * @stop_filtering: stops TS filtering 89fada1935SMauro Carvalho Chehab * 90fada1935SMauro Carvalho Chehab * A TS feed is typically mapped to a hardware PID filter on the demux chip. 91fada1935SMauro Carvalho Chehab * Using this API, the client can set the filtering properties to start/stop 92fada1935SMauro Carvalho Chehab * filtering TS packets on a particular TS feed. 93fada1935SMauro Carvalho Chehab */ 94fada1935SMauro Carvalho Chehab struct dmx_ts_feed { 95fada1935SMauro Carvalho Chehab int is_filtering; 96fada1935SMauro Carvalho Chehab struct dmx_demux *parent; 97fada1935SMauro Carvalho Chehab void *priv; 98fada1935SMauro Carvalho Chehab int (*set)(struct dmx_ts_feed *feed, 99fada1935SMauro Carvalho Chehab u16 pid, 100fada1935SMauro Carvalho Chehab int type, 101fada1935SMauro Carvalho Chehab enum dmx_ts_pes pes_type, 102fada1935SMauro Carvalho Chehab ktime_t timeout); 103fada1935SMauro Carvalho Chehab int (*start_filtering)(struct dmx_ts_feed *feed); 104fada1935SMauro Carvalho Chehab int (*stop_filtering)(struct dmx_ts_feed *feed); 105fada1935SMauro Carvalho Chehab }; 106fada1935SMauro Carvalho Chehab 107fada1935SMauro Carvalho Chehab /* 108fada1935SMauro Carvalho Chehab * Section reception 109fada1935SMauro Carvalho Chehab */ 110fada1935SMauro Carvalho Chehab 111fada1935SMauro Carvalho Chehab /** 112fada1935SMauro Carvalho Chehab * struct dmx_section_filter - Structure that describes a section filter 113fada1935SMauro Carvalho Chehab * 114fada1935SMauro Carvalho Chehab * @filter_value: Contains up to 16 bytes (128 bits) of the TS section header 115fada1935SMauro Carvalho Chehab * that will be matched by the section filter 116fada1935SMauro Carvalho Chehab * @filter_mask: Contains a 16 bytes (128 bits) filter mask with the bits 117fada1935SMauro Carvalho Chehab * specified by @filter_value that will be used on the filter 118fada1935SMauro Carvalho Chehab * match logic. 119fada1935SMauro Carvalho Chehab * @filter_mode: Contains a 16 bytes (128 bits) filter mode. 120*fdbeb962SMauro Carvalho Chehab * @parent: Back-pointer to struct dmx_section_feed. 121fada1935SMauro Carvalho Chehab * @priv: Pointer to private data of the API client. 122fada1935SMauro Carvalho Chehab * 123fada1935SMauro Carvalho Chehab * 124fada1935SMauro Carvalho Chehab * The @filter_mask controls which bits of @filter_value are compared with 125fada1935SMauro Carvalho Chehab * the section headers/payload. On a binary value of 1 in filter_mask, the 126fada1935SMauro Carvalho Chehab * corresponding bits are compared. The filter only accepts sections that are 127fada1935SMauro Carvalho Chehab * equal to filter_value in all the tested bit positions. 128fada1935SMauro Carvalho Chehab */ 129fada1935SMauro Carvalho Chehab struct dmx_section_filter { 130fada1935SMauro Carvalho Chehab u8 filter_value[DMX_MAX_FILTER_SIZE]; 131fada1935SMauro Carvalho Chehab u8 filter_mask[DMX_MAX_FILTER_SIZE]; 132fada1935SMauro Carvalho Chehab u8 filter_mode[DMX_MAX_FILTER_SIZE]; 133*fdbeb962SMauro Carvalho Chehab struct dmx_section_feed *parent; 134*fdbeb962SMauro Carvalho Chehab 135*fdbeb962SMauro Carvalho Chehab void *priv; 136fada1935SMauro Carvalho Chehab }; 137fada1935SMauro Carvalho Chehab 138fada1935SMauro Carvalho Chehab /** 139fada1935SMauro Carvalho Chehab * struct dmx_section_feed - Structure that contains a section feed filter 140fada1935SMauro Carvalho Chehab * 141fada1935SMauro Carvalho Chehab * @is_filtering: Set to non-zero when filtering in progress 142fada1935SMauro Carvalho Chehab * @parent: pointer to struct dmx_demux 143fada1935SMauro Carvalho Chehab * @priv: pointer to private data of the API client 144fada1935SMauro Carvalho Chehab * @check_crc: If non-zero, check the CRC values of filtered sections. 145fada1935SMauro Carvalho Chehab * @set: sets the section filter 146fada1935SMauro Carvalho Chehab * @allocate_filter: This function is used to allocate a section filter on 147fada1935SMauro Carvalho Chehab * the demux. It should only be called when no filtering 148fada1935SMauro Carvalho Chehab * is in progress on this section feed. If a filter cannot 149fada1935SMauro Carvalho Chehab * be allocated, the function fails with -ENOSPC. 150fada1935SMauro Carvalho Chehab * @release_filter: This function releases all the resources of a 151fada1935SMauro Carvalho Chehab * previously allocated section filter. The function 152fada1935SMauro Carvalho Chehab * should not be called while filtering is in progress 153fada1935SMauro Carvalho Chehab * on this section feed. After calling this function, 154fada1935SMauro Carvalho Chehab * the caller should not try to dereference the filter 155fada1935SMauro Carvalho Chehab * pointer. 156fada1935SMauro Carvalho Chehab * @start_filtering: starts section filtering 157fada1935SMauro Carvalho Chehab * @stop_filtering: stops section filtering 158fada1935SMauro Carvalho Chehab * 159fada1935SMauro Carvalho Chehab * A TS feed is typically mapped to a hardware PID filter on the demux chip. 160fada1935SMauro Carvalho Chehab * Using this API, the client can set the filtering properties to start/stop 161fada1935SMauro Carvalho Chehab * filtering TS packets on a particular TS feed. 162fada1935SMauro Carvalho Chehab */ 163fada1935SMauro Carvalho Chehab struct dmx_section_feed { 164fada1935SMauro Carvalho Chehab int is_filtering; 165fada1935SMauro Carvalho Chehab struct dmx_demux *parent; 166fada1935SMauro Carvalho Chehab void *priv; 167fada1935SMauro Carvalho Chehab 168fada1935SMauro Carvalho Chehab int check_crc; 169fada1935SMauro Carvalho Chehab 170fada1935SMauro Carvalho Chehab /* private: Used internally at dvb_demux.c */ 171fada1935SMauro Carvalho Chehab u32 crc_val; 172fada1935SMauro Carvalho Chehab 173fada1935SMauro Carvalho Chehab u8 *secbuf; 174fada1935SMauro Carvalho Chehab u8 secbuf_base[DMX_MAX_SECFEED_SIZE]; 175fada1935SMauro Carvalho Chehab u16 secbufp, seclen, tsfeedp; 176fada1935SMauro Carvalho Chehab 177fada1935SMauro Carvalho Chehab /* public: */ 178fada1935SMauro Carvalho Chehab int (*set)(struct dmx_section_feed *feed, 179fada1935SMauro Carvalho Chehab u16 pid, 180fada1935SMauro Carvalho Chehab int check_crc); 181fada1935SMauro Carvalho Chehab int (*allocate_filter)(struct dmx_section_feed *feed, 182fada1935SMauro Carvalho Chehab struct dmx_section_filter **filter); 183fada1935SMauro Carvalho Chehab int (*release_filter)(struct dmx_section_feed *feed, 184fada1935SMauro Carvalho Chehab struct dmx_section_filter *filter); 185fada1935SMauro Carvalho Chehab int (*start_filtering)(struct dmx_section_feed *feed); 186fada1935SMauro Carvalho Chehab int (*stop_filtering)(struct dmx_section_feed *feed); 187fada1935SMauro Carvalho Chehab }; 188fada1935SMauro Carvalho Chehab 189fada1935SMauro Carvalho Chehab /** 190fada1935SMauro Carvalho Chehab * typedef dmx_ts_cb - DVB demux TS filter callback function prototype 191fada1935SMauro Carvalho Chehab * 192fada1935SMauro Carvalho Chehab * @buffer1: Pointer to the start of the filtered TS packets. 193fada1935SMauro Carvalho Chehab * @buffer1_length: Length of the TS data in buffer1. 194fada1935SMauro Carvalho Chehab * @buffer2: Pointer to the tail of the filtered TS packets, or NULL. 195fada1935SMauro Carvalho Chehab * @buffer2_length: Length of the TS data in buffer2. 196fada1935SMauro Carvalho Chehab * @source: Indicates which TS feed is the source of the callback. 197*fdbeb962SMauro Carvalho Chehab * @buffer_flags: Address where buffer flags are stored. Those are 198*fdbeb962SMauro Carvalho Chehab * used to report discontinuity users via DVB 199*fdbeb962SMauro Carvalho Chehab * memory mapped API, as defined by 200*fdbeb962SMauro Carvalho Chehab * &enum dmx_buffer_flags. 201fada1935SMauro Carvalho Chehab * 202fada1935SMauro Carvalho Chehab * This function callback prototype, provided by the client of the demux API, 203fada1935SMauro Carvalho Chehab * is called from the demux code. The function is only called when filtering 204fada1935SMauro Carvalho Chehab * on a TS feed has been enabled using the start_filtering\(\) function at 205fada1935SMauro Carvalho Chehab * the &dmx_demux. 206fada1935SMauro Carvalho Chehab * Any TS packets that match the filter settings are copied to a circular 207fada1935SMauro Carvalho Chehab * buffer. The filtered TS packets are delivered to the client using this 208fada1935SMauro Carvalho Chehab * callback function. 209fada1935SMauro Carvalho Chehab * It is expected that the @buffer1 and @buffer2 callback parameters point to 210fada1935SMauro Carvalho Chehab * addresses within the circular buffer, but other implementations are also 211fada1935SMauro Carvalho Chehab * possible. Note that the called party should not try to free the memory 212fada1935SMauro Carvalho Chehab * the @buffer1 and @buffer2 parameters point to. 213fada1935SMauro Carvalho Chehab * 214fada1935SMauro Carvalho Chehab * When this function is called, the @buffer1 parameter typically points to 215fada1935SMauro Carvalho Chehab * the start of the first undelivered TS packet within a circular buffer. 216fada1935SMauro Carvalho Chehab * The @buffer2 buffer parameter is normally NULL, except when the received 217fada1935SMauro Carvalho Chehab * TS packets have crossed the last address of the circular buffer and 218fada1935SMauro Carvalho Chehab * "wrapped" to the beginning of the buffer. In the latter case the @buffer1 219fada1935SMauro Carvalho Chehab * parameter would contain an address within the circular buffer, while the 220fada1935SMauro Carvalho Chehab * @buffer2 parameter would contain the first address of the circular buffer. 221fada1935SMauro Carvalho Chehab * The number of bytes delivered with this function (i.e. @buffer1_length + 222fada1935SMauro Carvalho Chehab * @buffer2_length) is usually equal to the value of callback_length parameter 223fada1935SMauro Carvalho Chehab * given in the set() function, with one exception: if a timeout occurs before 224fada1935SMauro Carvalho Chehab * receiving callback_length bytes of TS data, any undelivered packets are 225fada1935SMauro Carvalho Chehab * immediately delivered to the client by calling this function. The timeout 226fada1935SMauro Carvalho Chehab * duration is controlled by the set() function in the TS Feed API. 227fada1935SMauro Carvalho Chehab * 228fada1935SMauro Carvalho Chehab * If a TS packet is received with errors that could not be fixed by the 229fada1935SMauro Carvalho Chehab * TS-level forward error correction (FEC), the Transport_error_indicator 230fada1935SMauro Carvalho Chehab * flag of the TS packet header should be set. The TS packet should not be 231fada1935SMauro Carvalho Chehab * discarded, as the error can possibly be corrected by a higher layer 232fada1935SMauro Carvalho Chehab * protocol. If the called party is slow in processing the callback, it 233fada1935SMauro Carvalho Chehab * is possible that the circular buffer eventually fills up. If this happens, 234fada1935SMauro Carvalho Chehab * the demux driver should discard any TS packets received while the buffer 235fada1935SMauro Carvalho Chehab * is full and return -EOVERFLOW. 236fada1935SMauro Carvalho Chehab * 237fada1935SMauro Carvalho Chehab * The type of data returned to the callback can be selected by the 238fada1935SMauro Carvalho Chehab * &dmx_ts_feed.@set function. The type parameter decides if the raw 239fada1935SMauro Carvalho Chehab * TS packet (TS_PACKET) or just the payload (TS_PACKET|TS_PAYLOAD_ONLY) 240fada1935SMauro Carvalho Chehab * should be returned. If additionally the TS_DECODER bit is set the stream 241fada1935SMauro Carvalho Chehab * will also be sent to the hardware MPEG decoder. 242fada1935SMauro Carvalho Chehab * 243fada1935SMauro Carvalho Chehab * Return: 244fada1935SMauro Carvalho Chehab * 245fada1935SMauro Carvalho Chehab * - 0, on success; 246fada1935SMauro Carvalho Chehab * 247fada1935SMauro Carvalho Chehab * - -EOVERFLOW, on buffer overflow. 248fada1935SMauro Carvalho Chehab */ 249fada1935SMauro Carvalho Chehab typedef int (*dmx_ts_cb)(const u8 *buffer1, 250fada1935SMauro Carvalho Chehab size_t buffer1_length, 251fada1935SMauro Carvalho Chehab const u8 *buffer2, 252fada1935SMauro Carvalho Chehab size_t buffer2_length, 253*fdbeb962SMauro Carvalho Chehab struct dmx_ts_feed *source, 254*fdbeb962SMauro Carvalho Chehab u32 *buffer_flags); 255fada1935SMauro Carvalho Chehab 256fada1935SMauro Carvalho Chehab /** 257fada1935SMauro Carvalho Chehab * typedef dmx_section_cb - DVB demux TS filter callback function prototype 258fada1935SMauro Carvalho Chehab * 259fada1935SMauro Carvalho Chehab * @buffer1: Pointer to the start of the filtered section, e.g. 260fada1935SMauro Carvalho Chehab * within the circular buffer of the demux driver. 261fada1935SMauro Carvalho Chehab * @buffer1_len: Length of the filtered section data in @buffer1, 262fada1935SMauro Carvalho Chehab * including headers and CRC. 263fada1935SMauro Carvalho Chehab * @buffer2: Pointer to the tail of the filtered section data, 264fada1935SMauro Carvalho Chehab * or NULL. Useful to handle the wrapping of a 265fada1935SMauro Carvalho Chehab * circular buffer. 266fada1935SMauro Carvalho Chehab * @buffer2_len: Length of the filtered section data in @buffer2, 267fada1935SMauro Carvalho Chehab * including headers and CRC. 268fada1935SMauro Carvalho Chehab * @source: Indicates which section feed is the source of the 269fada1935SMauro Carvalho Chehab * callback. 270*fdbeb962SMauro Carvalho Chehab * @buffer_flags: Address where buffer flags are stored. Those are 271*fdbeb962SMauro Carvalho Chehab * used to report discontinuity users via DVB 272*fdbeb962SMauro Carvalho Chehab * memory mapped API, as defined by 273*fdbeb962SMauro Carvalho Chehab * &enum dmx_buffer_flags. 274fada1935SMauro Carvalho Chehab * 275fada1935SMauro Carvalho Chehab * This function callback prototype, provided by the client of the demux API, 276fada1935SMauro Carvalho Chehab * is called from the demux code. The function is only called when 277fada1935SMauro Carvalho Chehab * filtering of sections has been enabled using the function 278fada1935SMauro Carvalho Chehab * &dmx_ts_feed.@start_filtering. When the demux driver has received a 279fada1935SMauro Carvalho Chehab * complete section that matches at least one section filter, the client 280fada1935SMauro Carvalho Chehab * is notified via this callback function. Normally this function is called 281fada1935SMauro Carvalho Chehab * for each received section; however, it is also possible to deliver 282fada1935SMauro Carvalho Chehab * multiple sections with one callback, for example when the system load 283fada1935SMauro Carvalho Chehab * is high. If an error occurs while receiving a section, this 284fada1935SMauro Carvalho Chehab * function should be called with the corresponding error type set in the 285fada1935SMauro Carvalho Chehab * success field, whether or not there is data to deliver. The Section Feed 286fada1935SMauro Carvalho Chehab * implementation should maintain a circular buffer for received sections. 287fada1935SMauro Carvalho Chehab * However, this is not necessary if the Section Feed API is implemented as 288fada1935SMauro Carvalho Chehab * a client of the TS Feed API, because the TS Feed implementation then 289fada1935SMauro Carvalho Chehab * buffers the received data. The size of the circular buffer can be 290fada1935SMauro Carvalho Chehab * configured using the &dmx_ts_feed.@set function in the Section Feed API. 291fada1935SMauro Carvalho Chehab * If there is no room in the circular buffer when a new section is received, 292fada1935SMauro Carvalho Chehab * the section must be discarded. If this happens, the value of the success 293fada1935SMauro Carvalho Chehab * parameter should be DMX_OVERRUN_ERROR on the next callback. 294fada1935SMauro Carvalho Chehab */ 295fada1935SMauro Carvalho Chehab typedef int (*dmx_section_cb)(const u8 *buffer1, 296fada1935SMauro Carvalho Chehab size_t buffer1_len, 297fada1935SMauro Carvalho Chehab const u8 *buffer2, 298fada1935SMauro Carvalho Chehab size_t buffer2_len, 299*fdbeb962SMauro Carvalho Chehab struct dmx_section_filter *source, 300*fdbeb962SMauro Carvalho Chehab u32 *buffer_flags); 301fada1935SMauro Carvalho Chehab 302fada1935SMauro Carvalho Chehab /* 303fada1935SMauro Carvalho Chehab * DVB Front-End 304fada1935SMauro Carvalho Chehab */ 305fada1935SMauro Carvalho Chehab 306fada1935SMauro Carvalho Chehab /** 307fada1935SMauro Carvalho Chehab * enum dmx_frontend_source - Used to identify the type of frontend 308fada1935SMauro Carvalho Chehab * 309fada1935SMauro Carvalho Chehab * @DMX_MEMORY_FE: The source of the demux is memory. It means that 310fada1935SMauro Carvalho Chehab * the MPEG-TS to be filtered comes from userspace, 311fada1935SMauro Carvalho Chehab * via write() syscall. 312fada1935SMauro Carvalho Chehab * 313fada1935SMauro Carvalho Chehab * @DMX_FRONTEND_0: The source of the demux is a frontend connected 314fada1935SMauro Carvalho Chehab * to the demux. 315fada1935SMauro Carvalho Chehab */ 316fada1935SMauro Carvalho Chehab enum dmx_frontend_source { 317fada1935SMauro Carvalho Chehab DMX_MEMORY_FE, 318fada1935SMauro Carvalho Chehab DMX_FRONTEND_0, 319fada1935SMauro Carvalho Chehab }; 320fada1935SMauro Carvalho Chehab 321fada1935SMauro Carvalho Chehab /** 322fada1935SMauro Carvalho Chehab * struct dmx_frontend - Structure that lists the frontends associated with 323fada1935SMauro Carvalho Chehab * a demux 324fada1935SMauro Carvalho Chehab * 325fada1935SMauro Carvalho Chehab * @connectivity_list: List of front-ends that can be connected to a 326fada1935SMauro Carvalho Chehab * particular demux; 327fada1935SMauro Carvalho Chehab * @source: Type of the frontend. 328fada1935SMauro Carvalho Chehab * 329fada1935SMauro Carvalho Chehab * FIXME: this structure should likely be replaced soon by some 330fada1935SMauro Carvalho Chehab * media-controller based logic. 331fada1935SMauro Carvalho Chehab */ 332fada1935SMauro Carvalho Chehab struct dmx_frontend { 333fada1935SMauro Carvalho Chehab struct list_head connectivity_list; 334fada1935SMauro Carvalho Chehab enum dmx_frontend_source source; 335fada1935SMauro Carvalho Chehab }; 336fada1935SMauro Carvalho Chehab 337fada1935SMauro Carvalho Chehab /* 338fada1935SMauro Carvalho Chehab * MPEG-2 TS Demux 339fada1935SMauro Carvalho Chehab */ 340fada1935SMauro Carvalho Chehab 341fada1935SMauro Carvalho Chehab /** 342fada1935SMauro Carvalho Chehab * enum dmx_demux_caps - MPEG-2 TS Demux capabilities bitmap 343fada1935SMauro Carvalho Chehab * 344fada1935SMauro Carvalho Chehab * @DMX_TS_FILTERING: set if TS filtering is supported; 345fada1935SMauro Carvalho Chehab * @DMX_SECTION_FILTERING: set if section filtering is supported; 346fada1935SMauro Carvalho Chehab * @DMX_MEMORY_BASED_FILTERING: set if write() available. 347fada1935SMauro Carvalho Chehab * 348fada1935SMauro Carvalho Chehab * Those flags are OR'ed in the &dmx_demux.capabilities field 349fada1935SMauro Carvalho Chehab */ 350fada1935SMauro Carvalho Chehab enum dmx_demux_caps { 351fada1935SMauro Carvalho Chehab DMX_TS_FILTERING = 1, 352fada1935SMauro Carvalho Chehab DMX_SECTION_FILTERING = 4, 353fada1935SMauro Carvalho Chehab DMX_MEMORY_BASED_FILTERING = 8, 354fada1935SMauro Carvalho Chehab }; 355fada1935SMauro Carvalho Chehab 356fada1935SMauro Carvalho Chehab /* 357fada1935SMauro Carvalho Chehab * Demux resource type identifier. 358fada1935SMauro Carvalho Chehab */ 359fada1935SMauro Carvalho Chehab 360fada1935SMauro Carvalho Chehab /** 361fada1935SMauro Carvalho Chehab * DMX_FE_ENTRY - Casts elements in the list of registered 362fada1935SMauro Carvalho Chehab * front-ends from the generic type struct list_head 363fada1935SMauro Carvalho Chehab * to the type * struct dmx_frontend 364fada1935SMauro Carvalho Chehab * 365fada1935SMauro Carvalho Chehab * @list: list of struct dmx_frontend 366fada1935SMauro Carvalho Chehab */ 367fada1935SMauro Carvalho Chehab #define DMX_FE_ENTRY(list) \ 368fada1935SMauro Carvalho Chehab list_entry(list, struct dmx_frontend, connectivity_list) 369fada1935SMauro Carvalho Chehab 370fada1935SMauro Carvalho Chehab /** 371fada1935SMauro Carvalho Chehab * struct dmx_demux - Structure that contains the demux capabilities and 372fada1935SMauro Carvalho Chehab * callbacks. 373fada1935SMauro Carvalho Chehab * 374fada1935SMauro Carvalho Chehab * @capabilities: Bitfield of capability flags. 375fada1935SMauro Carvalho Chehab * 376fada1935SMauro Carvalho Chehab * @frontend: Front-end connected to the demux 377fada1935SMauro Carvalho Chehab * 378fada1935SMauro Carvalho Chehab * @priv: Pointer to private data of the API client 379fada1935SMauro Carvalho Chehab * 380fada1935SMauro Carvalho Chehab * @open: This function reserves the demux for use by the caller and, if 381fada1935SMauro Carvalho Chehab * necessary, initializes the demux. When the demux is no longer needed, 382fada1935SMauro Carvalho Chehab * the function @close should be called. It should be possible for 383fada1935SMauro Carvalho Chehab * multiple clients to access the demux at the same time. Thus, the 384fada1935SMauro Carvalho Chehab * function implementation should increment the demux usage count when 385fada1935SMauro Carvalho Chehab * @open is called and decrement it when @close is called. 386fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 387fada1935SMauro Carvalho Chehab * instance data. 388fada1935SMauro Carvalho Chehab * It returns: 389fada1935SMauro Carvalho Chehab * 0 on success; 390fada1935SMauro Carvalho Chehab * -EUSERS, if maximum usage count was reached; 391fada1935SMauro Carvalho Chehab * -EINVAL, on bad parameter. 392fada1935SMauro Carvalho Chehab * 393fada1935SMauro Carvalho Chehab * @close: This function reserves the demux for use by the caller and, if 394fada1935SMauro Carvalho Chehab * necessary, initializes the demux. When the demux is no longer needed, 395fada1935SMauro Carvalho Chehab * the function @close should be called. It should be possible for 396fada1935SMauro Carvalho Chehab * multiple clients to access the demux at the same time. Thus, the 397fada1935SMauro Carvalho Chehab * function implementation should increment the demux usage count when 398fada1935SMauro Carvalho Chehab * @open is called and decrement it when @close is called. 399fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 400fada1935SMauro Carvalho Chehab * instance data. 401fada1935SMauro Carvalho Chehab * It returns: 402fada1935SMauro Carvalho Chehab * 0 on success; 403fada1935SMauro Carvalho Chehab * -ENODEV, if demux was not in use (e. g. no users); 404fada1935SMauro Carvalho Chehab * -EINVAL, on bad parameter. 405fada1935SMauro Carvalho Chehab * 406fada1935SMauro Carvalho Chehab * @write: This function provides the demux driver with a memory buffer 407fada1935SMauro Carvalho Chehab * containing TS packets. Instead of receiving TS packets from the DVB 408fada1935SMauro Carvalho Chehab * front-end, the demux driver software will read packets from memory. 409fada1935SMauro Carvalho Chehab * Any clients of this demux with active TS, PES or Section filters will 410fada1935SMauro Carvalho Chehab * receive filtered data via the Demux callback API (see 0). The function 411fada1935SMauro Carvalho Chehab * returns when all the data in the buffer has been consumed by the demux. 412fada1935SMauro Carvalho Chehab * Demux hardware typically cannot read TS from memory. If this is the 413fada1935SMauro Carvalho Chehab * case, memory-based filtering has to be implemented entirely in software. 414fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 415fada1935SMauro Carvalho Chehab * instance data. 416fada1935SMauro Carvalho Chehab * The @buf function parameter contains a pointer to the TS data in 417fada1935SMauro Carvalho Chehab * kernel-space memory. 418fada1935SMauro Carvalho Chehab * The @count function parameter contains the length of the TS data. 419fada1935SMauro Carvalho Chehab * It returns: 420fada1935SMauro Carvalho Chehab * 0 on success; 421fada1935SMauro Carvalho Chehab * -ERESTARTSYS, if mutex lock was interrupted; 422fada1935SMauro Carvalho Chehab * -EINTR, if a signal handling is pending; 423fada1935SMauro Carvalho Chehab * -ENODEV, if demux was removed; 424fada1935SMauro Carvalho Chehab * -EINVAL, on bad parameter. 425fada1935SMauro Carvalho Chehab * 426fada1935SMauro Carvalho Chehab * @allocate_ts_feed: Allocates a new TS feed, which is used to filter the TS 427fada1935SMauro Carvalho Chehab * packets carrying a certain PID. The TS feed normally corresponds to a 428fada1935SMauro Carvalho Chehab * hardware PID filter on the demux chip. 429fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 430fada1935SMauro Carvalho Chehab * instance data. 431fada1935SMauro Carvalho Chehab * The @feed function parameter contains a pointer to the TS feed API and 432fada1935SMauro Carvalho Chehab * instance data. 433fada1935SMauro Carvalho Chehab * The @callback function parameter contains a pointer to the callback 434fada1935SMauro Carvalho Chehab * function for passing received TS packet. 435fada1935SMauro Carvalho Chehab * It returns: 436fada1935SMauro Carvalho Chehab * 0 on success; 437fada1935SMauro Carvalho Chehab * -ERESTARTSYS, if mutex lock was interrupted; 438fada1935SMauro Carvalho Chehab * -EBUSY, if no more TS feeds is available; 439fada1935SMauro Carvalho Chehab * -EINVAL, on bad parameter. 440fada1935SMauro Carvalho Chehab * 441fada1935SMauro Carvalho Chehab * @release_ts_feed: Releases the resources allocated with @allocate_ts_feed. 442fada1935SMauro Carvalho Chehab * Any filtering in progress on the TS feed should be stopped before 443fada1935SMauro Carvalho Chehab * calling this function. 444fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 445fada1935SMauro Carvalho Chehab * instance data. 446fada1935SMauro Carvalho Chehab * The @feed function parameter contains a pointer to the TS feed API and 447fada1935SMauro Carvalho Chehab * instance data. 448fada1935SMauro Carvalho Chehab * It returns: 449fada1935SMauro Carvalho Chehab * 0 on success; 450fada1935SMauro Carvalho Chehab * -EINVAL on bad parameter. 451fada1935SMauro Carvalho Chehab * 452fada1935SMauro Carvalho Chehab * @allocate_section_feed: Allocates a new section feed, i.e. a demux resource 453fada1935SMauro Carvalho Chehab * for filtering and receiving sections. On platforms with hardware 454fada1935SMauro Carvalho Chehab * support for section filtering, a section feed is directly mapped to 455fada1935SMauro Carvalho Chehab * the demux HW. On other platforms, TS packets are first PID filtered in 456fada1935SMauro Carvalho Chehab * hardware and a hardware section filter then emulated in software. The 457fada1935SMauro Carvalho Chehab * caller obtains an API pointer of type dmx_section_feed_t as an out 458fada1935SMauro Carvalho Chehab * parameter. Using this API the caller can set filtering parameters and 459fada1935SMauro Carvalho Chehab * start receiving sections. 460fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 461fada1935SMauro Carvalho Chehab * instance data. 462fada1935SMauro Carvalho Chehab * The @feed function parameter contains a pointer to the TS feed API and 463fada1935SMauro Carvalho Chehab * instance data. 464fada1935SMauro Carvalho Chehab * The @callback function parameter contains a pointer to the callback 465fada1935SMauro Carvalho Chehab * function for passing received TS packet. 466fada1935SMauro Carvalho Chehab * It returns: 467fada1935SMauro Carvalho Chehab * 0 on success; 468fada1935SMauro Carvalho Chehab * -EBUSY, if no more TS feeds is available; 469fada1935SMauro Carvalho Chehab * -EINVAL, on bad parameter. 470fada1935SMauro Carvalho Chehab * 471fada1935SMauro Carvalho Chehab * @release_section_feed: Releases the resources allocated with 472fada1935SMauro Carvalho Chehab * @allocate_section_feed, including allocated filters. Any filtering in 473fada1935SMauro Carvalho Chehab * progress on the section feed should be stopped before calling this 474fada1935SMauro Carvalho Chehab * function. 475fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 476fada1935SMauro Carvalho Chehab * instance data. 477fada1935SMauro Carvalho Chehab * The @feed function parameter contains a pointer to the TS feed API and 478fada1935SMauro Carvalho Chehab * instance data. 479fada1935SMauro Carvalho Chehab * It returns: 480fada1935SMauro Carvalho Chehab * 0 on success; 481fada1935SMauro Carvalho Chehab * -EINVAL, on bad parameter. 482fada1935SMauro Carvalho Chehab * 483fada1935SMauro Carvalho Chehab * @add_frontend: Registers a connectivity between a demux and a front-end, 484fada1935SMauro Carvalho Chehab * i.e., indicates that the demux can be connected via a call to 485fada1935SMauro Carvalho Chehab * @connect_frontend to use the given front-end as a TS source. The 486fada1935SMauro Carvalho Chehab * client of this function has to allocate dynamic or static memory for 487fada1935SMauro Carvalho Chehab * the frontend structure and initialize its fields before calling this 488fada1935SMauro Carvalho Chehab * function. This function is normally called during the driver 489fada1935SMauro Carvalho Chehab * initialization. The caller must not free the memory of the frontend 490fada1935SMauro Carvalho Chehab * struct before successfully calling @remove_frontend. 491fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 492fada1935SMauro Carvalho Chehab * instance data. 493fada1935SMauro Carvalho Chehab * The @frontend function parameter contains a pointer to the front-end 494fada1935SMauro Carvalho Chehab * instance data. 495fada1935SMauro Carvalho Chehab * It returns: 496fada1935SMauro Carvalho Chehab * 0 on success; 497fada1935SMauro Carvalho Chehab * -EINVAL, on bad parameter. 498fada1935SMauro Carvalho Chehab * 499fada1935SMauro Carvalho Chehab * @remove_frontend: Indicates that the given front-end, registered by a call 500fada1935SMauro Carvalho Chehab * to @add_frontend, can no longer be connected as a TS source by this 501fada1935SMauro Carvalho Chehab * demux. The function should be called when a front-end driver or a demux 502fada1935SMauro Carvalho Chehab * driver is removed from the system. If the front-end is in use, the 503fada1935SMauro Carvalho Chehab * function fails with the return value of -EBUSY. After successfully 504fada1935SMauro Carvalho Chehab * calling this function, the caller can free the memory of the frontend 505fada1935SMauro Carvalho Chehab * struct if it was dynamically allocated before the @add_frontend 506fada1935SMauro Carvalho Chehab * operation. 507fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 508fada1935SMauro Carvalho Chehab * instance data. 509fada1935SMauro Carvalho Chehab * The @frontend function parameter contains a pointer to the front-end 510fada1935SMauro Carvalho Chehab * instance data. 511fada1935SMauro Carvalho Chehab * It returns: 512fada1935SMauro Carvalho Chehab * 0 on success; 513fada1935SMauro Carvalho Chehab * -ENODEV, if the front-end was not found, 514fada1935SMauro Carvalho Chehab * -EINVAL, on bad parameter. 515fada1935SMauro Carvalho Chehab * 516fada1935SMauro Carvalho Chehab * @get_frontends: Provides the APIs of the front-ends that have been 517fada1935SMauro Carvalho Chehab * registered for this demux. Any of the front-ends obtained with this 518fada1935SMauro Carvalho Chehab * call can be used as a parameter for @connect_frontend. The include 519fada1935SMauro Carvalho Chehab * file demux.h contains the macro DMX_FE_ENTRY() for converting an 520fada1935SMauro Carvalho Chehab * element of the generic type struct &list_head * to the type 521fada1935SMauro Carvalho Chehab * struct &dmx_frontend *. The caller must not free the memory of any of 522fada1935SMauro Carvalho Chehab * the elements obtained via this function call. 523fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 524fada1935SMauro Carvalho Chehab * instance data. 525fada1935SMauro Carvalho Chehab * It returns a struct list_head pointer to the list of front-end 526fada1935SMauro Carvalho Chehab * interfaces, or NULL in the case of an empty list. 527fada1935SMauro Carvalho Chehab * 528fada1935SMauro Carvalho Chehab * @connect_frontend: Connects the TS output of the front-end to the input of 529fada1935SMauro Carvalho Chehab * the demux. A demux can only be connected to a front-end registered to 530fada1935SMauro Carvalho Chehab * the demux with the function @add_frontend. It may or may not be 531fada1935SMauro Carvalho Chehab * possible to connect multiple demuxes to the same front-end, depending 532fada1935SMauro Carvalho Chehab * on the capabilities of the HW platform. When not used, the front-end 533fada1935SMauro Carvalho Chehab * should be released by calling @disconnect_frontend. 534fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 535fada1935SMauro Carvalho Chehab * instance data. 536fada1935SMauro Carvalho Chehab * The @frontend function parameter contains a pointer to the front-end 537fada1935SMauro Carvalho Chehab * instance data. 538fada1935SMauro Carvalho Chehab * It returns: 539fada1935SMauro Carvalho Chehab * 0 on success; 540fada1935SMauro Carvalho Chehab * -EINVAL, on bad parameter. 541fada1935SMauro Carvalho Chehab * 542fada1935SMauro Carvalho Chehab * @disconnect_frontend: Disconnects the demux and a front-end previously 543fada1935SMauro Carvalho Chehab * connected by a @connect_frontend call. 544fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 545fada1935SMauro Carvalho Chehab * instance data. 546fada1935SMauro Carvalho Chehab * It returns: 547fada1935SMauro Carvalho Chehab * 0 on success; 548fada1935SMauro Carvalho Chehab * -EINVAL on bad parameter. 549fada1935SMauro Carvalho Chehab * 550fada1935SMauro Carvalho Chehab * @get_pes_pids: Get the PIDs for DMX_PES_AUDIO0, DMX_PES_VIDEO0, 551fada1935SMauro Carvalho Chehab * DMX_PES_TELETEXT0, DMX_PES_SUBTITLE0 and DMX_PES_PCR0. 552fada1935SMauro Carvalho Chehab * The @demux function parameter contains a pointer to the demux API and 553fada1935SMauro Carvalho Chehab * instance data. 554fada1935SMauro Carvalho Chehab * The @pids function parameter contains an array with five u16 elements 555fada1935SMauro Carvalho Chehab * where the PIDs will be stored. 556fada1935SMauro Carvalho Chehab * It returns: 557fada1935SMauro Carvalho Chehab * 0 on success; 558fada1935SMauro Carvalho Chehab * -EINVAL on bad parameter. 559fada1935SMauro Carvalho Chehab */ 560fada1935SMauro Carvalho Chehab struct dmx_demux { 561fada1935SMauro Carvalho Chehab enum dmx_demux_caps capabilities; 562fada1935SMauro Carvalho Chehab struct dmx_frontend *frontend; 563fada1935SMauro Carvalho Chehab void *priv; 564fada1935SMauro Carvalho Chehab int (*open)(struct dmx_demux *demux); 565fada1935SMauro Carvalho Chehab int (*close)(struct dmx_demux *demux); 566fada1935SMauro Carvalho Chehab int (*write)(struct dmx_demux *demux, const char __user *buf, 567fada1935SMauro Carvalho Chehab size_t count); 568fada1935SMauro Carvalho Chehab int (*allocate_ts_feed)(struct dmx_demux *demux, 569fada1935SMauro Carvalho Chehab struct dmx_ts_feed **feed, 570fada1935SMauro Carvalho Chehab dmx_ts_cb callback); 571fada1935SMauro Carvalho Chehab int (*release_ts_feed)(struct dmx_demux *demux, 572fada1935SMauro Carvalho Chehab struct dmx_ts_feed *feed); 573fada1935SMauro Carvalho Chehab int (*allocate_section_feed)(struct dmx_demux *demux, 574fada1935SMauro Carvalho Chehab struct dmx_section_feed **feed, 575fada1935SMauro Carvalho Chehab dmx_section_cb callback); 576fada1935SMauro Carvalho Chehab int (*release_section_feed)(struct dmx_demux *demux, 577fada1935SMauro Carvalho Chehab struct dmx_section_feed *feed); 578fada1935SMauro Carvalho Chehab int (*add_frontend)(struct dmx_demux *demux, 579fada1935SMauro Carvalho Chehab struct dmx_frontend *frontend); 580fada1935SMauro Carvalho Chehab int (*remove_frontend)(struct dmx_demux *demux, 581fada1935SMauro Carvalho Chehab struct dmx_frontend *frontend); 582fada1935SMauro Carvalho Chehab struct list_head *(*get_frontends)(struct dmx_demux *demux); 583fada1935SMauro Carvalho Chehab int (*connect_frontend)(struct dmx_demux *demux, 584fada1935SMauro Carvalho Chehab struct dmx_frontend *frontend); 585fada1935SMauro Carvalho Chehab int (*disconnect_frontend)(struct dmx_demux *demux); 586fada1935SMauro Carvalho Chehab 587fada1935SMauro Carvalho Chehab int (*get_pes_pids)(struct dmx_demux *demux, u16 *pids); 588fada1935SMauro Carvalho Chehab 589fada1935SMauro Carvalho Chehab /* private: */ 590fada1935SMauro Carvalho Chehab 591fada1935SMauro Carvalho Chehab /* 592fada1935SMauro Carvalho Chehab * Only used at av7110, to read some data from firmware. 593fada1935SMauro Carvalho Chehab * As this was never documented, we have no clue about what's 594fada1935SMauro Carvalho Chehab * there, and its usage on other drivers aren't encouraged. 595fada1935SMauro Carvalho Chehab */ 596fada1935SMauro Carvalho Chehab int (*get_stc)(struct dmx_demux *demux, unsigned int num, 597fada1935SMauro Carvalho Chehab u64 *stc, unsigned int *base); 598fada1935SMauro Carvalho Chehab }; 599fada1935SMauro Carvalho Chehab 600fada1935SMauro Carvalho Chehab #endif /* #ifndef __DEMUX_H */ 601