/*1* dvbdev.h2*3* Copyright (C) 2000 Ralph Metzler & Marcus Metzler4* for convergence integrated media GmbH5*6* This program is free software; you can redistribute it and/or7* modify it under the terms of the GNU General Lesser Public License8* as published by the Free Software Foundation; either version 2.19* of the License, or (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16*/1718#ifndef _DVBDEV_H_19#define _DVBDEV_H_2021#include <linux/types.h>22#include <linux/poll.h>23#include <linux/fs.h>24#include <linux/list.h>25#include <media/media-device.h>2627#define DVB_MAJOR 2122829#if defined(CONFIG_DVB_MAX_ADAPTERS) && CONFIG_DVB_MAX_ADAPTERS > 030#define DVB_MAX_ADAPTERS CONFIG_DVB_MAX_ADAPTERS31#else32#define DVB_MAX_ADAPTERS 1633#endif3435#define DVB_UNSET (-1)3637/* List of DVB device types */3839/**40* enum dvb_device_type - type of the Digital TV device41*42* @DVB_DEVICE_SEC: Digital TV standalone Common Interface (CI)43* @DVB_DEVICE_FRONTEND: Digital TV frontend.44* @DVB_DEVICE_DEMUX: Digital TV demux.45* @DVB_DEVICE_DVR: Digital TV digital video record (DVR).46* @DVB_DEVICE_CA: Digital TV Conditional Access (CA).47* @DVB_DEVICE_NET: Digital TV network.48*49* @DVB_DEVICE_VIDEO: Digital TV video decoder.50* Deprecated. Used only on av7110-av.51* @DVB_DEVICE_AUDIO: Digital TV audio decoder.52* Deprecated. Used only on av7110-av.53* @DVB_DEVICE_OSD: Digital TV On Screen Display (OSD).54* Deprecated. Used only on av7110.55*/56enum dvb_device_type {57DVB_DEVICE_SEC,58DVB_DEVICE_FRONTEND,59DVB_DEVICE_DEMUX,60DVB_DEVICE_DVR,61DVB_DEVICE_CA,62DVB_DEVICE_NET,6364DVB_DEVICE_VIDEO,65DVB_DEVICE_AUDIO,66DVB_DEVICE_OSD,67};6869#define DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr) \70static short adapter_nr[] = \71{[0 ... (DVB_MAX_ADAPTERS - 1)] = DVB_UNSET }; \72module_param_array(adapter_nr, short, NULL, 0444); \73MODULE_PARM_DESC(adapter_nr, "DVB adapter numbers")7475struct dvb_frontend;7677/**78* struct dvb_adapter - represents a Digital TV adapter using Linux DVB API79*80* @num: Number of the adapter81* @list_head: List with the DVB adapters82* @device_list: List with the DVB devices83* @name: Name of the adapter84* @proposed_mac: proposed MAC address for the adapter85* @priv: private data86* @device: pointer to struct device87* @module: pointer to struct module88* @mfe_shared: indicates mutually exclusive frontends.89* 1 = legacy exclusion behavior: blocking any open() call90* 2 = enhanced exclusion behavior, emulating the standard91* behavior of busy frontends: allowing read-only sharing92* and otherwise returning immediately with -EBUSY when any93* of the frontends is already opened with write access.94* @mfe_dvbdev: Frontend device in use, in the case of MFE95* @mfe_lock: Lock to prevent using the other frontends when MFE is96* used.97* @mdev_lock: Protect access to the mdev pointer.98* @mdev: pointer to struct media_device, used when the media99* controller is used.100* @conn: RF connector. Used only if the device has no separate101* tuner.102* @conn_pads: pointer to struct media_pad associated with @conn;103*/104struct dvb_adapter {105int num;106struct list_head list_head;107struct list_head device_list;108const char *name;109u8 proposed_mac [6];110void* priv;111112struct device *device;113114struct module *module;115116int mfe_shared; /* indicates mutually exclusive frontends */117struct dvb_device *mfe_dvbdev; /* frontend device in use */118struct mutex mfe_lock; /* access lock for thread creation */119120#if defined(CONFIG_MEDIA_CONTROLLER_DVB)121struct mutex mdev_lock;122struct media_device *mdev;123struct media_entity *conn;124struct media_pad *conn_pads;125#endif126};127128/**129* struct dvb_device - represents a DVB device node130*131* @list_head: List head with all DVB devices132* @ref: reference count for this device133* @fops: pointer to struct file_operations134* @adapter: pointer to the adapter that holds this device node135* @type: type of the device, as defined by &enum dvb_device_type.136* @minor: devnode minor number. Major number is always DVB_MAJOR.137* @id: device ID number, inside the adapter138* @readers: Initialized by the caller. Each call to open() in Read Only mode139* decreases this counter by one.140* @writers: Initialized by the caller. Each call to open() in Read/Write141* mode decreases this counter by one.142* @users: Initialized by the caller. Each call to open() in any mode143* decreases this counter by one.144* @wait_queue: wait queue, used to wait for certain events inside one of145* the DVB API callers146* @kernel_ioctl: callback function used to handle ioctl calls from userspace.147* @name: Name to be used for the device at the Media Controller148* @entity: pointer to struct media_entity associated with the device node149* @pads: pointer to struct media_pad associated with @entity;150* @priv: private data151* @intf_devnode: Pointer to media_intf_devnode. Used by the dvbdev core to152* store the MC device node interface153* @tsout_num_entities: Number of Transport Stream output entities154* @tsout_entity: array with MC entities associated to each TS output node155* @tsout_pads: array with the source pads for each @tsout_entity156*157* This structure is used by the DVB core (frontend, CA, net, demux) in158* order to create the device nodes. Usually, driver should not initialize159* this struct diretly.160*/161struct dvb_device {162struct list_head list_head;163struct kref ref;164const struct file_operations *fops;165struct dvb_adapter *adapter;166enum dvb_device_type type;167int minor;168u32 id;169170/* in theory, 'users' can vanish now,171but I don't want to change too much now... */172int readers;173int writers;174int users;175176wait_queue_head_t wait_queue;177/* don't really need those !? -- FIXME: use video_usercopy */178int (*kernel_ioctl)(struct file *file, unsigned int cmd, void *arg);179180/* Needed for media controller register/unregister */181#if defined(CONFIG_MEDIA_CONTROLLER_DVB)182const char *name;183184/* Allocated and filled inside dvbdev.c */185struct media_intf_devnode *intf_devnode;186187unsigned tsout_num_entities;188struct media_entity *entity, *tsout_entity;189struct media_pad *pads, *tsout_pads;190#endif191192void *priv;193};194195/**196* struct dvbdevfops_node - fops nodes registered in dvbdevfops_list197*198* @fops: Dynamically allocated fops for ->owner registration199* @type: type of dvb_device200* @template: dvb_device used for registration201* @list_head: list_head for dvbdevfops_list202*/203struct dvbdevfops_node {204struct file_operations *fops;205enum dvb_device_type type;206const struct dvb_device *template;207struct list_head list_head;208};209210/**211* dvb_device_get - Increase dvb_device reference212*213* @dvbdev: pointer to struct dvb_device214*/215struct dvb_device *dvb_device_get(struct dvb_device *dvbdev);216217/**218* dvb_device_put - Decrease dvb_device reference219*220* @dvbdev: pointer to struct dvb_device221*/222void dvb_device_put(struct dvb_device *dvbdev);223224/**225* dvb_register_adapter - Registers a new DVB adapter226*227* @adap: pointer to struct dvb_adapter228* @name: Adapter's name229* @module: initialized with THIS_MODULE at the caller230* @device: pointer to struct device that corresponds to the device driver231* @adapter_nums: Array with a list of the numbers for @dvb_register_adapter;232* to select among them. Typically, initialized with:233* DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums)234*/235int dvb_register_adapter(struct dvb_adapter *adap, const char *name,236struct module *module, struct device *device,237short *adapter_nums);238239/**240* dvb_unregister_adapter - Unregisters a DVB adapter241*242* @adap: pointer to struct dvb_adapter243*/244int dvb_unregister_adapter(struct dvb_adapter *adap);245246/**247* dvb_register_device - Registers a new DVB device248*249* @adap: pointer to struct dvb_adapter250* @pdvbdev: pointer to the place where the new struct dvb_device will be251* stored252* @template: Template used to create &pdvbdev;253* @priv: private data254* @type: type of the device, as defined by &enum dvb_device_type.255* @demux_sink_pads: Number of demux outputs, to be used to create the TS256* outputs via the Media Controller.257*/258int dvb_register_device(struct dvb_adapter *adap,259struct dvb_device **pdvbdev,260const struct dvb_device *template,261void *priv,262enum dvb_device_type type,263int demux_sink_pads);264265/**266* dvb_remove_device - Remove a registered DVB device267*268* @dvbdev: pointer to struct dvb_device269*270* This does not free memory. dvb_free_device() will do that when271* reference counter is empty272*/273void dvb_remove_device(struct dvb_device *dvbdev);274275276/**277* dvb_unregister_device - Unregisters a DVB device278*279* @dvbdev: pointer to struct dvb_device280*/281void dvb_unregister_device(struct dvb_device *dvbdev);282283#ifdef CONFIG_MEDIA_CONTROLLER_DVB284/**285* dvb_create_media_graph - Creates media graph for the Digital TV part of the286* device.287*288* @adap: pointer to &struct dvb_adapter289* @create_rf_connector: if true, it creates the RF connector too290*291* This function checks all DVB-related functions at the media controller292* entities and creates the needed links for the media graph. It is293* capable of working with multiple tuners or multiple frontends, but it294* won't create links if the device has multiple tuners and multiple frontends295* or if the device has multiple muxes. In such case, the caller driver should296* manually create the remaining links.297*/298__must_check int dvb_create_media_graph(struct dvb_adapter *adap,299bool create_rf_connector);300301/**302* dvb_register_media_controller - registers a media controller at DVB adapter303*304* @adap: pointer to &struct dvb_adapter305* @mdev: pointer to &struct media_device306*/307static inline void dvb_register_media_controller(struct dvb_adapter *adap,308struct media_device *mdev)309{310adap->mdev = mdev;311}312313/**314* dvb_get_media_controller - gets the associated media controller315*316* @adap: pointer to &struct dvb_adapter317*/318static inline struct media_device *319dvb_get_media_controller(struct dvb_adapter *adap)320{321return adap->mdev;322}323#else324static inline325int dvb_create_media_graph(struct dvb_adapter *adap,326bool create_rf_connector)327{328return 0;329};330#define dvb_register_media_controller(a, b) {}331#define dvb_get_media_controller(a) NULL332#endif333334/**335* dvb_generic_open - Digital TV open function, used by DVB devices336*337* @inode: pointer to &struct inode.338* @file: pointer to &struct file.339*340* Checks if a DVB devnode is still valid, and if the permissions are341* OK and increment negative use count.342*/343int dvb_generic_open(struct inode *inode, struct file *file);344345/**346* dvb_generic_release - Digital TV close function, used by DVB devices347*348* @inode: pointer to &struct inode.349* @file: pointer to &struct file.350*351* Checks if a DVB devnode is still valid, and if the permissions are352* OK and decrement negative use count.353*/354int dvb_generic_release(struct inode *inode, struct file *file);355356/**357* dvb_generic_ioctl - Digital TV close function, used by DVB devices358*359* @file: pointer to &struct file.360* @cmd: Ioctl name.361* @arg: Ioctl argument.362*363* Checks if a DVB devnode and struct dvbdev.kernel_ioctl is still valid.364* If so, calls dvb_usercopy().365*/366long dvb_generic_ioctl(struct file *file,367unsigned int cmd, unsigned long arg);368369/**370* dvb_usercopy - copies data from/to userspace memory when an ioctl is371* issued.372*373* @file: Pointer to struct &file.374* @cmd: Ioctl name.375* @arg: Ioctl argument.376* @func: function that will actually handle the ioctl377*378* Ancillary function that uses ioctl direction and size to copy from379* userspace. Then, it calls @func, and, if needed, data is copied back380* to userspace.381*/382int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg,383int (*func)(struct file *file, unsigned int cmd, void *arg));384385#if IS_ENABLED(CONFIG_I2C)386387struct i2c_adapter;388struct i2c_client;389/**390* dvb_module_probe - helper routine to probe an I2C module391*392* @module_name:393* Name of the I2C module to be probed394* @name:395* Optional name for the I2C module. Used for debug purposes.396* If %NULL, defaults to @module_name.397* @adap:398* pointer to &struct i2c_adapter that describes the I2C adapter where399* the module will be bound.400* @addr:401* I2C address of the adapter, in 7-bit notation.402* @platform_data:403* Platform data to be passed to the I2C module probed.404*405* This function binds an I2C device into the DVB core. Should be used by406* all drivers that use I2C bus to control the hardware. A module bound407* with dvb_module_probe() should use dvb_module_release() to unbind.408*409* Return:410* On success, return an &struct i2c_client, pointing to the bound411* I2C device. %NULL otherwise.412*413* .. note::414*415* In the past, DVB modules (mainly, frontends) were bound via dvb_attach()416* macro, with does an ugly hack, using I2C low level functions. Such417* usage is deprecated and will be removed soon. Instead, use this routine.418*/419struct i2c_client *dvb_module_probe(const char *module_name,420const char *name,421struct i2c_adapter *adap,422unsigned char addr,423void *platform_data);424425/**426* dvb_module_release - releases an I2C device allocated with427* dvb_module_probe().428*429* @client: pointer to &struct i2c_client with the I2C client to be released.430* can be %NULL.431*432* This function should be used to free all resources reserved by433* dvb_module_probe() and unbinding the I2C hardware.434*/435void dvb_module_release(struct i2c_client *client);436437#endif /* CONFIG_I2C */438439/* Legacy generic DVB attach function. */440#ifdef CONFIG_MEDIA_ATTACH441442/**443* dvb_attach - attaches a DVB frontend into the DVB core.444*445* @FUNCTION: function on a frontend module to be called.446* @ARGS: @FUNCTION arguments.447*448* This ancillary function loads a frontend module in runtime and runs449* the @FUNCTION function there, with @ARGS.450* As it increments symbol usage cont, at unregister, dvb_detach()451* should be called.452*453* .. note::454*455* In the past, DVB modules (mainly, frontends) were bound via dvb_attach()456* macro, with does an ugly hack, using I2C low level functions. Such457* usage is deprecated and will be removed soon. Instead, you should use458* dvb_module_probe().459*/460#define dvb_attach(FUNCTION, ARGS...) ({ \461void *__r = NULL; \462typeof(&FUNCTION) __a = symbol_request(FUNCTION); \463if (__a) { \464__r = (void *) __a(ARGS); \465if (__r == NULL) \466symbol_put(FUNCTION); \467} else { \468printk(KERN_ERR "DVB: Unable to find symbol "#FUNCTION"()\n"); \469} \470__r; \471})472473/**474* dvb_detach - detaches a DVB frontend loaded via dvb_attach()475*476* @FUNC: attach function477*478* Decrements usage count for a function previously called via dvb_attach().479*/480481#define dvb_detach(FUNC) symbol_put_addr(FUNC)482483#else484#define dvb_attach(FUNCTION, ARGS...) ({ \485FUNCTION(ARGS); \486})487488#define dvb_detach(FUNC) {}489490#endif /* CONFIG_MEDIA_ATTACH */491492#endif /* #ifndef _DVBDEV_H_ */493494495