Home | History | Annotate | Line # | Download | only in dtv
dtvvar.h revision 1.3
      1 /* $NetBSD: dtvvar.h,v 1.3 2011/07/12 00:57:19 jmcneill Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2011 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *        This product includes software developed by Jared D. McNeill.
     18  * 4. Neither the name of The NetBSD Foundation nor the names of its
     19  *    contributors may be used to endorse or promote products derived
     20  *    from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32  * POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 #ifndef _DEV_DTV_DTVVAR_H
     36 #define _DEV_DTV_DTVVAR_H
     37 
     38 #include <dev/dtv/dtvif.h>
     39 #include <dev/dtv/dtv_scatter.h>
     40 
     41 #define	DTV_DEFAULT_BLOCKSIZE	(32 * PAGE_SIZE)
     42 #define	DTV_DEFAULT_BUFSIZE	(32 * DTV_DEFAULT_BLOCKSIZE)
     43 
     44 #define	TS_PKTLEN		188
     45 #define	TS_HAS_SYNC(_tspkt)	((_tspkt)[0] == 0x47)
     46 #define	TS_PID(_tspkt)		((((_tspkt)[1] & 0x1f) << 8) | (_tspkt)[2])
     47 
     48 struct dtv_buffer {
     49 	uint32_t	db_offset;
     50 	uint32_t	db_bytesused;
     51 	size_t		db_length;
     52 	SIMPLEQ_ENTRY(dtv_buffer) db_entries;
     53 };
     54 
     55 SIMPLEQ_HEAD(dtv_sample_queue, dtv_buffer);
     56 
     57 struct dtv_stream {
     58 	unsigned int		ds_nbufs;
     59 	struct dtv_buffer	**ds_buf;
     60 	struct dtv_scatter_buf	ds_data;
     61 	struct dtv_sample_queue	ds_ingress, ds_egress;
     62 	kmutex_t		ds_ingress_lock, ds_egress_lock;
     63 	kcondvar_t		ds_sample_cv;
     64 	struct selinfo		ds_sel;
     65 	uint32_t		ds_bytesread;
     66 };
     67 
     68 struct dtv_ts {
     69 	uint8_t			ts_pidfilter[0x2000];
     70 	kmutex_t		ts_lock;
     71 };
     72 
     73 struct dtv_softc {
     74 	device_t	sc_dev;
     75 	const struct dtv_hw_if *sc_hw;
     76 	void		*sc_priv;
     77 
     78 	bool		sc_dying;
     79 
     80 	unsigned int	sc_open;
     81 
     82 	size_t		sc_bufsize;
     83 	bool		sc_bufsize_chg;
     84 
     85 	struct dtv_stream sc_stream;
     86 	struct dtv_ts	sc_ts;
     87 };
     88 
     89 #define	dtv_device_get_devinfo(sc, info)	\
     90 	((sc)->sc_hw->get_devinfo((sc)->sc_priv, (info)))
     91 #define	dtv_device_open(sc, flags)		\
     92 	((sc)->sc_hw->open((sc)->sc_priv, (flags)))
     93 #define	dtv_device_close(sc)			\
     94 	((sc)->sc_hw->close((sc)->sc_priv))
     95 #define	dtv_device_set_tuner(sc, params)	\
     96 	((sc)->sc_hw->set_tuner((sc)->sc_priv, (params)))
     97 #define	dtv_device_get_status(sc)		\
     98 	((sc)->sc_hw->get_status((sc)->sc_priv))
     99 #define	dtv_device_get_signal_strength(sc)	\
    100 	((sc)->sc_hw->get_signal_strength((sc)->sc_priv))
    101 #define	dtv_device_get_snr(sc)			\
    102 	((sc)->sc_hw->get_snr((sc)->sc_priv))
    103 #define	dtv_device_start_transfer(sc)		\
    104 	((sc)->sc_hw->start_transfer((sc)->sc_priv))
    105 #define	dtv_device_stop_transfer(sc)		\
    106 	((sc)->sc_hw->stop_transfer((sc)->sc_priv))
    107 
    108 int	dtv_frontend_ioctl(struct dtv_softc *, u_long, void *, int);
    109 int	dtv_demux_ioctl(struct dtv_softc *, u_long, void *, int);
    110 
    111 int	dtv_buffer_realloc(struct dtv_softc *, size_t);
    112 int	dtv_buffer_setup(struct dtv_softc *);
    113 int	dtv_buffer_destroy(struct dtv_softc *);
    114 int	dtv_buffer_read(struct dtv_softc *, struct uio *, int);
    115 int	dtv_buffer_poll(struct dtv_softc *, int, lwp_t *);
    116 
    117 #endif /* !_DEV_DTV_DTVVAR_H */
    118