1 /* $NetBSD: dtvar.h,v 1.6 2011/06/04 01:37:36 tsutsui 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _DTVAR_H_ 33 #define _DTVAR_H_ 34 35 #define DT_DEVICE_NO(a) (((a) - DT_ADDR_FIRST) >> 1) 36 #define DT_GET_SHORT(b0, b1) (((b0) << 8) | (b1)) 37 38 struct dt_msg { 39 uint8_t dst; 40 uint8_t src; 41 uint8_t ctl; 42 43 /* varzise, checksum byte at end */ 44 uint8_t body[DT_MAX_MSG_SIZE-3]; 45 46 union { 47 SLIST_ENTRY(dt_msg) slist; 48 SIMPLEQ_ENTRY(dt_msg) simpleq; 49 } chain; 50 }; 51 52 #define DT_CTL(l, s, p) \ 53 ((l & 0x1f) | ((s & 0x03) << 5) | ((p & 0x01) << 7)) 54 #define DT_CTL_P(c) ((c >> 7) & 0x01) 55 #define DT_CTL_SUBADDR(c) ((c >> 5) & 0x03) 56 #define DT_CTL_LEN(c) (c & 0x1f) 57 58 struct dt_device { 59 void *dtdv_arg; 60 void (*dtdv_handler)(void *, struct dt_msg *); 61 }; 62 63 struct dt_state { 64 volatile u_int *ds_data; 65 volatile u_int *ds_poll; 66 int ds_bad_pkts; 67 int ds_state; 68 int ds_escaped; 69 int ds_len; 70 int ds_ptr; 71 }; 72 73 struct dt_softc { 74 device_t sc_dev; 75 struct dt_msg sc_msg; 76 void *sc_sih; 77 SLIST_HEAD(, dt_msg) sc_free; 78 SIMPLEQ_HEAD(, dt_msg) sc_queue; 79 }; 80 81 struct dt_attach_args { 82 int dta_addr; 83 }; 84 85 #define DT_GET_ERROR -1 86 #define DT_GET_DONE 0 87 #define DT_GET_NOTYET 1 88 89 void dt_cninit(void); 90 int dt_identify(int, struct dt_ident *); 91 int dt_msg_get(struct dt_msg *, int); 92 void dt_msg_dump(struct dt_msg *); 93 int dt_establish_handler(struct dt_softc *, struct dt_device *, 94 void *, void (*)(void *, struct dt_msg *)); 95 96 extern int dt_kbd_addr; 97 extern struct dt_device dt_kbd_dv; 98 extern int dt_ms_addr; 99 extern struct dt_device dt_ms_dv; 100 extern struct dt_state dt_state; 101 102 #endif /* !_DTVAR_H_ */ 103