dtvar.h revision 1.2 1 /* $NetBSD: dtvar.h,v 1.2 2003/12/13 23:04:38 ad Exp $ */
2
3 /*-
4 * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef _DTVAR_H_
40 #define _DTVAR_H_
41
42 #define DT_DEVICE_NO(a) (((a) - DT_ADDR_FIRST) >> 1)
43
44 struct dt_msg {
45 uint8_t dst;
46 uint8_t src;
47 union {
48 struct {
49 uint8_t len : 5, /* message byte len */
50 sub : 2, /* sub-address */
51 P : 1; /* Ctl(1)/Data(0) marker */
52 } val;
53 uint8_t bits; /* quick check */
54 } code;
55
56 /* varzise, checksum byte at end */
57 uint8_t body[DT_MAX_MSG_SIZE-3];
58
59 union {
60 SLIST_ENTRY(dt_msg) slist;
61 SIMPLEQ_ENTRY(dt_msg) simpleq;
62 } chain;
63 };
64
65 struct dt_device {
66 struct device *dtdv_dv;
67 void *dtdv_sih;
68 SIMPLEQ_HEAD(, dt_msg) dtdv_queue;
69 };
70
71 struct dt_state {
72 volatile u_int *ds_data;
73 volatile u_int *ds_poll;
74 int ds_bad_pkts;
75 int ds_state;
76 int ds_escaped;
77 int ds_len;
78 int ds_ptr;
79 };
80
81 struct dt_softc {
82 struct device sc_dv;
83 struct dt_msg sc_msg;
84 SLIST_HEAD(, dt_msg) sc_free;
85 struct dt_device sc_dtdv[(DT_ADDR_DEFAULT - DT_ADDR_FIRST) >> 1];
86 };
87
88 struct dt_attach_args {
89 int dta_addr;
90 };
91
92 #define DT_GET_ERROR -1
93 #define DT_GET_DONE 0
94 #define DT_GET_NOTYET 1
95
96 void dt_cninit(void);
97 int dt_identify(int, struct dt_ident *);
98 int dt_msg_get(struct dt_msg *, int);
99 int dt_establish_handler(struct dt_softc *, int, struct device *,
100 void (*)(void *));
101
102 static __inline__ struct dt_msg *dt_msg_dequeue(struct dt_device *);
103 static __inline__ void dt_msg_release(struct dt_softc *, struct dt_msg *);
104
105 extern int dt_kbd_addr;
106 extern struct dt_state dt_state;
107
108 static __inline__ struct dt_msg *
109 dt_msg_dequeue(struct dt_device *dtdv)
110 {
111 struct dt_msg *msg;
112 int s;
113
114 s = spltty();
115 msg = SIMPLEQ_FIRST(&dtdv->dtdv_queue);
116 if (msg != NULL)
117 SIMPLEQ_REMOVE_HEAD(&dtdv->dtdv_queue, chain.simpleq);
118 splx(s);
119 return (msg);
120 }
121
122 static __inline__ void
123 dt_msg_release(struct dt_softc *sc, struct dt_msg *msg)
124 {
125 int s;
126
127 s = spltty();
128 SLIST_INSERT_HEAD(&sc->sc_free, msg, chain.slist);
129 splx(s);
130 }
131
132 #endif /* !_DTVAR_H_ */
133