dtvvar.h revision 1.1 1 /* $NetBSD: dtvvar.h,v 1.1 2011/07/09 14:46:56 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_BUFSIZE (64 * 4096)
42
43 #define TS_PKTLEN 188
44 #define TS_HAS_SYNC(_tspkt) ((_tspkt)[0] == 0x47)
45 #define TS_PID(_tspkt) ((((_tspkt)[1] & 0x1f) << 8) | (_tspkt)[2])
46
47 struct dtv_buffer {
48 uint32_t db_offset;
49 uint32_t db_bytesused;
50 size_t db_length;
51 SIMPLEQ_ENTRY(dtv_buffer) db_entries;
52 };
53
54 SIMPLEQ_HEAD(dtv_sample_queue, dtv_buffer);
55
56 struct dtv_stream {
57 unsigned int ds_nbufs;
58 struct dtv_buffer **ds_buf;
59 struct dtv_scatter_buf ds_data;
60 struct dtv_sample_queue ds_ingress, ds_egress;
61 kmutex_t ds_lock;
62 kcondvar_t ds_sample_cv;
63 struct selinfo ds_sel;
64 uint32_t ds_bytesread;
65 };
66
67 struct dtv_ts {
68 uint8_t ts_pidfilter[0x2000];
69 kmutex_t ts_lock;
70 };
71
72 struct dtv_softc {
73 device_t sc_dev;
74 const struct dtv_hw_if *sc_hw;
75 void *sc_priv;
76
77 bool sc_dying;
78
79 unsigned int sc_open;
80
81 size_t sc_bufsize;
82 bool sc_bufsize_chg;
83
84 struct dtv_stream sc_stream;
85 struct dtv_ts sc_ts;
86 };
87
88 #define dtv_device_get_devinfo(sc, info) \
89 ((sc)->sc_hw->get_devinfo((sc)->sc_priv, (info)))
90 #define dtv_device_open(sc, flags) \
91 ((sc)->sc_hw->open((sc)->sc_priv, (flags)))
92 #define dtv_device_close(sc) \
93 ((sc)->sc_hw->close((sc)->sc_priv))
94 #define dtv_device_set_tuner(sc, params) \
95 ((sc)->sc_hw->set_tuner((sc)->sc_priv, (params)))
96 #define dtv_device_get_status(sc) \
97 ((sc)->sc_hw->get_status((sc)->sc_priv))
98 #define dtv_device_get_signal_strength(sc) \
99 ((sc)->sc_hw->get_signal_strength((sc)->sc_priv))
100 #define dtv_device_get_snr(sc) \
101 ((sc)->sc_hw->get_snr((sc)->sc_priv))
102 #define dtv_device_start_transfer(sc) \
103 ((sc)->sc_hw->start_transfer((sc)->sc_priv))
104 #define dtv_device_stop_transfer(sc) \
105 ((sc)->sc_hw->stop_transfer((sc)->sc_priv))
106
107 int dtv_frontend_ioctl(struct dtv_softc *, u_long, void *, int);
108 int dtv_demux_ioctl(struct dtv_softc *, u_long, void *, int);
109
110 int dtv_buffer_setup(struct dtv_softc *, size_t);
111 int dtv_buffer_destroy(struct dtv_softc *);
112 int dtv_buffer_read(struct dtv_softc *, struct uio *, int);
113 int dtv_buffer_poll(struct dtv_softc *, int, lwp_t *);
114
115 #endif /* !_DEV_DTV_DTVVAR_H */
116