1 /* $NetBSD: dtvar.h,v 1.4 2005/12/11 12:18:41 christos 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 #define DT_GET_SHORT(b0, b1) (((b0) << 8) | (b1)) 44 45 struct dt_msg { 46 uint8_t dst; 47 uint8_t src; 48 uint8_t ctl; 49 50 /* varzise, checksum byte at end */ 51 uint8_t body[DT_MAX_MSG_SIZE-3]; 52 53 union { 54 SLIST_ENTRY(dt_msg) slist; 55 SIMPLEQ_ENTRY(dt_msg) simpleq; 56 } chain; 57 }; 58 59 #define DT_CTL(l, s, p) \ 60 ((l & 0x1f) | ((s & 0x03) << 5) | ((p & 0x01) << 7)) 61 #define DT_CTL_P(c) ((c >> 7) & 0x01) 62 #define DT_CTL_SUBADDR(c) ((c >> 5) & 0x03) 63 #define DT_CTL_LEN(c) (c & 0x1f) 64 65 struct dt_device { 66 struct device *dtdv_dv; 67 void (*dtdv_handler)(void *, struct dt_msg *); 68 }; 69 70 struct dt_state { 71 volatile u_int *ds_data; 72 volatile u_int *ds_poll; 73 int ds_bad_pkts; 74 int ds_state; 75 int ds_escaped; 76 int ds_len; 77 int ds_ptr; 78 }; 79 80 struct dt_softc { 81 struct device sc_dv; 82 struct dt_msg sc_msg; 83 void *sc_sih; 84 SLIST_HEAD(, dt_msg) sc_free; 85 SIMPLEQ_HEAD(, dt_msg) sc_queue; 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 void dt_msg_dump(struct dt_msg *); 100 int dt_establish_handler(struct dt_softc *, struct dt_device *, 101 struct device *, void (*)(void *, struct dt_msg *)); 102 103 extern int dt_kbd_addr; 104 extern struct dt_device dt_kbd_dv; 105 extern int dt_ms_addr; 106 extern struct dt_device dt_ms_dv; 107 extern struct dt_state dt_state; 108 109 #endif /* !_DTVAR_H_ */ 110