/*1* demux.h2*3* The Kernel Digital TV Demux kABI defines a driver-internal interface for4* registering low-level, hardware specific driver to a hardware independent5* demux layer.6*7* Copyright (c) 2002 Convergence GmbH8*9* based on code:10* Copyright (c) 2000 Nokia Research Center11* Tampere, FINLAND12*13* This program is free software; you can redistribute it and/or14* modify it under the terms of the GNU Lesser General Public License15* as published by the Free Software Foundation; either version 2.116* of the License, or (at your option) any later version.17*18* This program is distributed in the hope that it will be useful,19* but WITHOUT ANY WARRANTY; without even the implied warranty of20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the21* GNU General Public License for more details.22*23*/2425#ifndef __DEMUX_H26#define __DEMUX_H2728#include <linux/types.h>29#include <linux/errno.h>30#include <linux/list.h>31#include <linux/time.h>32#include <linux/dvb/dmx.h>3334/*35* Common definitions36*/3738/*39* DMX_MAX_FILTER_SIZE: Maximum length (in bytes) of a section/PES filter.40*/4142#ifndef DMX_MAX_FILTER_SIZE43#define DMX_MAX_FILTER_SIZE 1844#endif4546/*47* DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed48* filter.49*/5051#ifndef DMX_MAX_SECTION_SIZE52#define DMX_MAX_SECTION_SIZE 409653#endif54#ifndef DMX_MAX_SECFEED_SIZE55#define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188)56#endif5758/*59* TS packet reception60*/6162/**63* enum ts_filter_type - filter type bitmap for dmx_ts_feed.set\(\)64*65* @TS_PACKET: Send TS packets (188 bytes) to callback (default).66* @TS_PAYLOAD_ONLY: In case TS_PACKET is set, only send the TS payload67* (<=184 bytes per packet) to callback68* @TS_DECODER: Send stream to built-in decoder (if present).69* @TS_DEMUX: In case TS_PACKET is set, send the TS to the demux70* device, not to the dvr device71*/72enum ts_filter_type {73TS_PACKET = 1,74TS_PAYLOAD_ONLY = 2,75TS_DECODER = 4,76TS_DEMUX = 8,77};7879/**80* struct dmx_ts_feed - Structure that contains a TS feed filter81*82* @is_filtering: Set to non-zero when filtering in progress83* @parent: pointer to struct dmx_demux84* @priv: pointer to private data of the API client85* @set: sets the TS filter86* @start_filtering: starts TS filtering87* @stop_filtering: stops TS filtering88*89* A TS feed is typically mapped to a hardware PID filter on the demux chip.90* Using this API, the client can set the filtering properties to start/stop91* filtering TS packets on a particular TS feed.92*/93struct dmx_ts_feed {94int is_filtering;95struct dmx_demux *parent;96void *priv;97int (*set)(struct dmx_ts_feed *feed,98u16 pid,99int type,100enum dmx_ts_pes pes_type,101ktime_t timeout);102int (*start_filtering)(struct dmx_ts_feed *feed);103int (*stop_filtering)(struct dmx_ts_feed *feed);104};105106/*107* Section reception108*/109110/**111* struct dmx_section_filter - Structure that describes a section filter112*113* @filter_value: Contains up to 16 bytes (128 bits) of the TS section header114* that will be matched by the section filter115* @filter_mask: Contains a 16 bytes (128 bits) filter mask with the bits116* specified by @filter_value that will be used on the filter117* match logic.118* @filter_mode: Contains a 16 bytes (128 bits) filter mode.119* @parent: Back-pointer to struct dmx_section_feed.120* @priv: Pointer to private data of the API client.121*122*123* The @filter_mask controls which bits of @filter_value are compared with124* the section headers/payload. On a binary value of 1 in filter_mask, the125* corresponding bits are compared. The filter only accepts sections that are126* equal to filter_value in all the tested bit positions.127*/128struct dmx_section_filter {129u8 filter_value[DMX_MAX_FILTER_SIZE];130u8 filter_mask[DMX_MAX_FILTER_SIZE];131u8 filter_mode[DMX_MAX_FILTER_SIZE];132struct dmx_section_feed *parent;133134void *priv;135};136137/**138* struct dmx_section_feed - Structure that contains a section feed filter139*140* @is_filtering: Set to non-zero when filtering in progress141* @parent: pointer to struct dmx_demux142* @priv: pointer to private data of the API client143* @check_crc: If non-zero, check the CRC values of filtered sections.144* @set: sets the section filter145* @allocate_filter: This function is used to allocate a section filter on146* the demux. It should only be called when no filtering147* is in progress on this section feed. If a filter cannot148* be allocated, the function fails with -ENOSPC.149* @release_filter: This function releases all the resources of a150* previously allocated section filter. The function151* should not be called while filtering is in progress152* on this section feed. After calling this function,153* the caller should not try to dereference the filter154* pointer.155* @start_filtering: starts section filtering156* @stop_filtering: stops section filtering157*158* A TS feed is typically mapped to a hardware PID filter on the demux chip.159* Using this API, the client can set the filtering properties to start/stop160* filtering TS packets on a particular TS feed.161*/162struct dmx_section_feed {163int is_filtering;164struct dmx_demux *parent;165void *priv;166167int check_crc;168169/* private: Used internally at dvb_demux.c */170u32 crc_val;171172u8 *secbuf;173u8 secbuf_base[DMX_MAX_SECFEED_SIZE];174u16 secbufp, seclen, tsfeedp;175176/* public: */177int (*set)(struct dmx_section_feed *feed,178u16 pid,179int check_crc);180int (*allocate_filter)(struct dmx_section_feed *feed,181struct dmx_section_filter **filter);182int (*release_filter)(struct dmx_section_feed *feed,183struct dmx_section_filter *filter);184int (*start_filtering)(struct dmx_section_feed *feed);185int (*stop_filtering)(struct dmx_section_feed *feed);186};187188/**189* typedef dmx_ts_cb - DVB demux TS filter callback function prototype190*191* @buffer1: Pointer to the start of the filtered TS packets.192* @buffer1_length: Length of the TS data in buffer1.193* @buffer2: Pointer to the tail of the filtered TS packets, or NULL.194* @buffer2_length: Length of the TS data in buffer2.195* @source: Indicates which TS feed is the source of the callback.196* @buffer_flags: Address where buffer flags are stored. Those are197* used to report discontinuity users via DVB198* memory mapped API, as defined by199* &enum dmx_buffer_flags.200*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 filtering203* on a TS feed has been enabled using the start_filtering\(\) function at204* the &dmx_demux.205* Any TS packets that match the filter settings are copied to a circular206* buffer. The filtered TS packets are delivered to the client using this207* callback function.208* It is expected that the @buffer1 and @buffer2 callback parameters point to209* addresses within the circular buffer, but other implementations are also210* possible. Note that the called party should not try to free the memory211* the @buffer1 and @buffer2 parameters point to.212*213* When this function is called, the @buffer1 parameter typically points to214* the start of the first undelivered TS packet within a circular buffer.215* The @buffer2 buffer parameter is normally NULL, except when the received216* TS packets have crossed the last address of the circular buffer and217* "wrapped" to the beginning of the buffer. In the latter case the @buffer1218* parameter would contain an address within the circular buffer, while the219* @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 parameter222* given in the set() function, with one exception: if a timeout occurs before223* receiving callback_length bytes of TS data, any undelivered packets are224* immediately delivered to the client by calling this function. The timeout225* duration is controlled by the set() function in the TS Feed API.226*227* If a TS packet is received with errors that could not be fixed by the228* TS-level forward error correction (FEC), the Transport_error_indicator229* flag of the TS packet header should be set. The TS packet should not be230* discarded, as the error can possibly be corrected by a higher layer231* protocol. If the called party is slow in processing the callback, it232* is possible that the circular buffer eventually fills up. If this happens,233* the demux driver should discard any TS packets received while the buffer234* is full and return -EOVERFLOW.235*236* The type of data returned to the callback can be selected by the237* &dmx_ts_feed.@set function. The type parameter decides if the raw238* 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 stream240* will also be sent to the hardware MPEG decoder.241*242* Return:243*244* - 0, on success;245*246* - -EOVERFLOW, on buffer overflow.247*/248typedef int (*dmx_ts_cb)(const u8 *buffer1,249size_t buffer1_length,250const u8 *buffer2,251size_t buffer2_length,252struct dmx_ts_feed *source,253u32 *buffer_flags);254255/**256* typedef dmx_section_cb - DVB demux TS filter callback function prototype257*258* @buffer1: Pointer to the start of the filtered section, e.g.259* within the circular buffer of the demux driver.260* @buffer1_len: Length of the filtered section data in @buffer1,261* including headers and CRC.262* @buffer2: Pointer to the tail of the filtered section data,263* or NULL. Useful to handle the wrapping of a264* circular buffer.265* @buffer2_len: Length of the filtered section data in @buffer2,266* including headers and CRC.267* @source: Indicates which section feed is the source of the268* callback.269* @buffer_flags: Address where buffer flags are stored. Those are270* used to report discontinuity users via DVB271* memory mapped API, as defined by272* &enum dmx_buffer_flags.273*274* This function callback prototype, provided by the client of the demux API,275* is called from the demux code. The function is only called when276* filtering of sections has been enabled using the function277* &dmx_ts_feed.@start_filtering. When the demux driver has received a278* complete section that matches at least one section filter, the client279* is notified via this callback function. Normally this function is called280* for each received section; however, it is also possible to deliver281* multiple sections with one callback, for example when the system load282* is high. If an error occurs while receiving a section, this283* function should be called with the corresponding error type set in the284* success field, whether or not there is data to deliver. The Section Feed285* implementation should maintain a circular buffer for received sections.286* However, this is not necessary if the Section Feed API is implemented as287* a client of the TS Feed API, because the TS Feed implementation then288* buffers the received data. The size of the circular buffer can be289* configured using the &dmx_ts_feed.@set function in the Section Feed API.290* If there is no room in the circular buffer when a new section is received,291* the section must be discarded. If this happens, the value of the success292* parameter should be DMX_OVERRUN_ERROR on the next callback.293*/294typedef int (*dmx_section_cb)(const u8 *buffer1,295size_t buffer1_len,296const u8 *buffer2,297size_t buffer2_len,298struct dmx_section_filter *source,299u32 *buffer_flags);300301/*302* DVB Front-End303*/304305/**306* enum dmx_frontend_source - Used to identify the type of frontend307*308* @DMX_MEMORY_FE: The source of the demux is memory. It means that309* the MPEG-TS to be filtered comes from userspace,310* via write() syscall.311*312* @DMX_FRONTEND_0: The source of the demux is a frontend connected313* to the demux.314*/315enum dmx_frontend_source {316DMX_MEMORY_FE,317DMX_FRONTEND_0,318};319320/**321* struct dmx_frontend - Structure that lists the frontends associated with322* a demux323*324* @connectivity_list: List of front-ends that can be connected to a325* particular demux;326* @source: Type of the frontend.327*328* FIXME: this structure should likely be replaced soon by some329* media-controller based logic.330*/331struct dmx_frontend {332struct list_head connectivity_list;333enum dmx_frontend_source source;334};335336/*337* MPEG-2 TS Demux338*/339340/**341* enum dmx_demux_caps - MPEG-2 TS Demux capabilities bitmap342*343* @DMX_TS_FILTERING: set if TS filtering is supported;344* @DMX_SECTION_FILTERING: set if section filtering is supported;345* @DMX_MEMORY_BASED_FILTERING: set if write() available.346*347* Those flags are OR'ed in the &dmx_demux.capabilities field348*/349enum dmx_demux_caps {350DMX_TS_FILTERING = 1,351DMX_SECTION_FILTERING = 4,352DMX_MEMORY_BASED_FILTERING = 8,353};354355/*356* Demux resource type identifier.357*/358359/**360* DMX_FE_ENTRY - Casts elements in the list of registered361* front-ends from the generic type struct list_head362* to the type * struct dmx_frontend363*364* @list: list of struct dmx_frontend365*/366#define DMX_FE_ENTRY(list) \367list_entry(list, struct dmx_frontend, connectivity_list)368369/**370* struct dmx_demux - Structure that contains the demux capabilities and371* callbacks.372*373* @capabilities: Bitfield of capability flags.374*375* @frontend: Front-end connected to the demux376*377* @priv: Pointer to private data of the API client378*379* @open: This function reserves the demux for use by the caller and, if380* necessary, initializes the demux. When the demux is no longer needed,381* the function @close should be called. It should be possible for382* multiple clients to access the demux at the same time. Thus, the383* function implementation should increment the demux usage count when384* @open is called and decrement it when @close is called.385* The @demux function parameter contains a pointer to the demux API and386* instance data.387* It returns:388* 0 on success;389* -EUSERS, if maximum usage count was reached;390* -EINVAL, on bad parameter.391*392* @close: This function reserves the demux for use by the caller and, if393* necessary, initializes the demux. When the demux is no longer needed,394* the function @close should be called. It should be possible for395* multiple clients to access the demux at the same time. Thus, the396* function implementation should increment the demux usage count when397* @open is called and decrement it when @close is called.398* The @demux function parameter contains a pointer to the demux API and399* instance data.400* It returns:401* 0 on success;402* -ENODEV, if demux was not in use (e. g. no users);403* -EINVAL, on bad parameter.404*405* @write: This function provides the demux driver with a memory buffer406* containing TS packets. Instead of receiving TS packets from the DVB407* front-end, the demux driver software will read packets from memory.408* Any clients of this demux with active TS, PES or Section filters will409* receive filtered data via the Demux callback API (see 0). The function410* returns when all the data in the buffer has been consumed by the demux.411* Demux hardware typically cannot read TS from memory. If this is the412* case, memory-based filtering has to be implemented entirely in software.413* The @demux function parameter contains a pointer to the demux API and414* instance data.415* The @buf function parameter contains a pointer to the TS data in416* kernel-space memory.417* The @count function parameter contains the length of the TS data.418* It returns:419* 0 on success;420* -ERESTARTSYS, if mutex lock was interrupted;421* -EINTR, if a signal handling is pending;422* -ENODEV, if demux was removed;423* -EINVAL, on bad parameter.424*425* @allocate_ts_feed: Allocates a new TS feed, which is used to filter the TS426* packets carrying a certain PID. The TS feed normally corresponds to a427* hardware PID filter on the demux chip.428* The @demux function parameter contains a pointer to the demux API and429* instance data.430* The @feed function parameter contains a pointer to the TS feed API and431* instance data.432* The @callback function parameter contains a pointer to the callback433* function for passing received TS packet.434* It returns:435* 0 on success;436* -ERESTARTSYS, if mutex lock was interrupted;437* -EBUSY, if no more TS feeds is available;438* -EINVAL, on bad parameter.439*440* @release_ts_feed: Releases the resources allocated with @allocate_ts_feed.441* Any filtering in progress on the TS feed should be stopped before442* calling this function.443* The @demux function parameter contains a pointer to the demux API and444* instance data.445* The @feed function parameter contains a pointer to the TS feed API and446* instance data.447* It returns:448* 0 on success;449* -EINVAL on bad parameter.450*451* @allocate_section_feed: Allocates a new section feed, i.e. a demux resource452* for filtering and receiving sections. On platforms with hardware453* support for section filtering, a section feed is directly mapped to454* the demux HW. On other platforms, TS packets are first PID filtered in455* hardware and a hardware section filter then emulated in software. The456* caller obtains an API pointer of type dmx_section_feed_t as an out457* parameter. Using this API the caller can set filtering parameters and458* start receiving sections.459* The @demux function parameter contains a pointer to the demux API and460* instance data.461* The @feed function parameter contains a pointer to the TS feed API and462* instance data.463* The @callback function parameter contains a pointer to the callback464* function for passing received TS packet.465* It returns:466* 0 on success;467* -EBUSY, if no more TS feeds is available;468* -EINVAL, on bad parameter.469*470* @release_section_feed: Releases the resources allocated with471* @allocate_section_feed, including allocated filters. Any filtering in472* progress on the section feed should be stopped before calling this473* function.474* The @demux function parameter contains a pointer to the demux API and475* instance data.476* The @feed function parameter contains a pointer to the TS feed API and477* instance data.478* It returns:479* 0 on success;480* -EINVAL, on bad parameter.481*482* @add_frontend: Registers a connectivity between a demux and a front-end,483* i.e., indicates that the demux can be connected via a call to484* @connect_frontend to use the given front-end as a TS source. The485* client of this function has to allocate dynamic or static memory for486* the frontend structure and initialize its fields before calling this487* function. This function is normally called during the driver488* initialization. The caller must not free the memory of the frontend489* struct before successfully calling @remove_frontend.490* The @demux function parameter contains a pointer to the demux API and491* instance data.492* The @frontend function parameter contains a pointer to the front-end493* instance data.494* It returns:495* 0 on success;496* -EINVAL, on bad parameter.497*498* @remove_frontend: Indicates that the given front-end, registered by a call499* to @add_frontend, can no longer be connected as a TS source by this500* demux. The function should be called when a front-end driver or a demux501* driver is removed from the system. If the front-end is in use, the502* function fails with the return value of -EBUSY. After successfully503* calling this function, the caller can free the memory of the frontend504* struct if it was dynamically allocated before the @add_frontend505* operation.506* The @demux function parameter contains a pointer to the demux API and507* instance data.508* The @frontend function parameter contains a pointer to the front-end509* instance data.510* It returns:511* 0 on success;512* -ENODEV, if the front-end was not found,513* -EINVAL, on bad parameter.514*515* @get_frontends: Provides the APIs of the front-ends that have been516* registered for this demux. Any of the front-ends obtained with this517* call can be used as a parameter for @connect_frontend. The include518* file demux.h contains the macro DMX_FE_ENTRY() for converting an519* element of the generic type struct &list_head * to the type520* struct &dmx_frontend *. The caller must not free the memory of any of521* the elements obtained via this function call.522* The @demux function parameter contains a pointer to the demux API and523* instance data.524* It returns a struct list_head pointer to the list of front-end525* interfaces, or NULL in the case of an empty list.526*527* @connect_frontend: Connects the TS output of the front-end to the input of528* the demux. A demux can only be connected to a front-end registered to529* the demux with the function @add_frontend. It may or may not be530* possible to connect multiple demuxes to the same front-end, depending531* on the capabilities of the HW platform. When not used, the front-end532* should be released by calling @disconnect_frontend.533* The @demux function parameter contains a pointer to the demux API and534* instance data.535* The @frontend function parameter contains a pointer to the front-end536* instance data.537* It returns:538* 0 on success;539* -EINVAL, on bad parameter.540*541* @disconnect_frontend: Disconnects the demux and a front-end previously542* connected by a @connect_frontend call.543* The @demux function parameter contains a pointer to the demux API and544* instance data.545* It returns:546* 0 on success;547* -EINVAL on bad parameter.548*549* @get_pes_pids: Get the PIDs for DMX_PES_AUDIO0, DMX_PES_VIDEO0,550* DMX_PES_TELETEXT0, DMX_PES_SUBTITLE0 and DMX_PES_PCR0.551* The @demux function parameter contains a pointer to the demux API and552* instance data.553* The @pids function parameter contains an array with five u16 elements554* where the PIDs will be stored.555* It returns:556* 0 on success;557* -EINVAL on bad parameter.558*/559struct dmx_demux {560enum dmx_demux_caps capabilities;561struct dmx_frontend *frontend;562void *priv;563int (*open)(struct dmx_demux *demux);564int (*close)(struct dmx_demux *demux);565int (*write)(struct dmx_demux *demux, const char __user *buf,566size_t count);567int (*allocate_ts_feed)(struct dmx_demux *demux,568struct dmx_ts_feed **feed,569dmx_ts_cb callback);570int (*release_ts_feed)(struct dmx_demux *demux,571struct dmx_ts_feed *feed);572int (*allocate_section_feed)(struct dmx_demux *demux,573struct dmx_section_feed **feed,574dmx_section_cb callback);575int (*release_section_feed)(struct dmx_demux *demux,576struct dmx_section_feed *feed);577int (*add_frontend)(struct dmx_demux *demux,578struct dmx_frontend *frontend);579int (*remove_frontend)(struct dmx_demux *demux,580struct dmx_frontend *frontend);581struct list_head *(*get_frontends)(struct dmx_demux *demux);582int (*connect_frontend)(struct dmx_demux *demux,583struct dmx_frontend *frontend);584int (*disconnect_frontend)(struct dmx_demux *demux);585586int (*get_pes_pids)(struct dmx_demux *demux, u16 *pids);587588/* private: */589590/*591* Only used at av7110, to read some data from firmware.592* As this was never documented, we have no clue about what's593* there, and its usage on other drivers aren't encouraged.594*/595int (*get_stc)(struct dmx_demux *demux, unsigned int num,596u64 *stc, unsigned int *base);597};598599#endif /* #ifndef __DEMUX_H */600601602