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