1 1.16 thorpej /* $NetBSD: dt.c,v 1.16 2021/08/07 16:19:02 thorpej Exp $ */ 2 1.2 ad 3 1.2 ad /*- 4 1.2 ad * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc. 5 1.2 ad * All rights reserved. 6 1.2 ad * 7 1.2 ad * This code is derived from software contributed to The NetBSD Foundation 8 1.2 ad * by Andrew Doran. 9 1.2 ad * 10 1.2 ad * Redistribution and use in source and binary forms, with or without 11 1.2 ad * modification, are permitted provided that the following conditions 12 1.2 ad * are met: 13 1.2 ad * 1. Redistributions of source code must retain the above copyright 14 1.2 ad * notice, this list of conditions and the following disclaimer. 15 1.2 ad * 2. Redistributions in binary form must reproduce the above copyright 16 1.2 ad * notice, this list of conditions and the following disclaimer in the 17 1.2 ad * documentation and/or other materials provided with the distribution. 18 1.2 ad * 19 1.2 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.2 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.2 ad * POSSIBILITY OF SUCH DAMAGE. 30 1.2 ad */ 31 1.2 ad 32 1.2 ad /*- 33 1.2 ad * Copyright (c) 1992, 1993 34 1.2 ad * The Regents of the University of California. All rights reserved. 35 1.2 ad * 36 1.2 ad * This code is derived from software contributed to Berkeley by 37 1.2 ad * Ralph Campbell and Rick Macklem. 38 1.2 ad * 39 1.2 ad * Redistribution and use in source and binary forms, with or without 40 1.2 ad * modification, are permitted provided that the following conditions 41 1.2 ad * are met: 42 1.2 ad * 1. Redistributions of source code must retain the above copyright 43 1.2 ad * notice, this list of conditions and the following disclaimer. 44 1.2 ad * 2. Redistributions in binary form must reproduce the above copyright 45 1.2 ad * notice, this list of conditions and the following disclaimer in the 46 1.2 ad * documentation and/or other materials provided with the distribution. 47 1.2 ad * 3. Neither the name of the University nor the names of its contributors 48 1.2 ad * may be used to endorse or promote products derived from this software 49 1.2 ad * without specific prior written permission. 50 1.2 ad * 51 1.2 ad * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 52 1.2 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 53 1.2 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 54 1.2 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 55 1.2 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 56 1.2 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 57 1.2 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 58 1.2 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 59 1.2 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 60 1.2 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 61 1.2 ad * SUCH DAMAGE. 62 1.2 ad * 63 1.2 ad * @(#)dtop.c 8.2 (Berkeley) 11/30/93 64 1.2 ad */ 65 1.2 ad 66 1.2 ad /* 67 1.2 ad * Mach Operating System 68 1.2 ad * Copyright (c) 1991,1990,1989 Carnegie Mellon University 69 1.2 ad * All Rights Reserved. 70 1.2 ad * 71 1.2 ad * Permission to use, copy, modify and distribute this software and its 72 1.2 ad * documentation is hereby granted, provided that both the copyright 73 1.2 ad * notice and this permission notice appear in all copies of the 74 1.2 ad * software, derivative works or modified versions, and any portions 75 1.2 ad * thereof, and that both notices appear in supporting documentation. 76 1.2 ad * 77 1.2 ad * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 78 1.2 ad * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 79 1.2 ad * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 80 1.2 ad * 81 1.2 ad * Carnegie Mellon requests users of this software to return to 82 1.2 ad * 83 1.2 ad * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU 84 1.2 ad * School of Computer Science 85 1.2 ad * Carnegie Mellon University 86 1.2 ad * Pittsburgh PA 15213-3890 87 1.2 ad * 88 1.2 ad * any improvements or extensions that they make and grant Carnegie the 89 1.2 ad * rights to redistribute these changes. 90 1.2 ad */ 91 1.2 ad /* 92 1.2 ad * Author: Alessandro Forin, Carnegie Mellon University 93 1.2 ad * 94 1.2 ad * Hardware-level operations for the Desktop serial line 95 1.2 ad * bus (i2c aka ACCESS). 96 1.2 ad */ 97 1.2 ad /************************************************************ 98 1.2 ad Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, 99 1.2 ad and the Massachusetts Institute of Technology, Cambridge, Massachusetts. 100 1.2 ad 101 1.2 ad All Rights Reserved 102 1.2 ad 103 1.2 ad Permission to use, copy, modify, and distribute this software and its 104 1.2 ad documentation for any purpose and without fee is hereby granted, 105 1.2 ad provided that the above copyright notice appear in all copies and that 106 1.2 ad both that copyright notice and this permission notice appear in 107 1.2 ad supporting documentation, and that the names of Digital or MIT not be 108 1.2 ad used in advertising or publicity pertaining to distribution of the 109 1.2 ad software without specific, written prior permission. 110 1.2 ad 111 1.2 ad DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 112 1.2 ad ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 113 1.2 ad DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 114 1.2 ad ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 115 1.2 ad WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 116 1.2 ad ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 117 1.2 ad SOFTWARE. 118 1.2 ad 119 1.2 ad ********************************************************/ 120 1.2 ad 121 1.3 ad /* 122 1.3 ad * ACCESS.bus device support for the Personal DECstation. This code handles 123 1.3 ad * only the keyboard and mouse, and will likely not work if other ACCESS.bus 124 1.3 ad * devices are physically attached to the system. 125 1.3 ad * 126 1.3 ad * Since we do not know how to drive the hardware (the only reference being 127 1.3 ad * Mach), we can't identify which devices are connected to the system by 128 1.3 ad * sending idenfication requests. With only a mouse and keyboard attached 129 1.3 ad * to the system, we do know which two slave addresses will be in use. 130 1.3 ad * However, we don't know which is the mouse, and which is the keyboard. 131 1.3 ad * So, we resort to inspecting device reports and making an educated guess 132 1.3 ad * as to which is which. 133 1.3 ad */ 134 1.3 ad 135 1.2 ad #include <sys/cdefs.h> 136 1.16 thorpej __KERNEL_RCSID(0, "$NetBSD: dt.c,v 1.16 2021/08/07 16:19:02 thorpej Exp $"); 137 1.2 ad 138 1.2 ad #include <sys/param.h> 139 1.2 ad #include <sys/systm.h> 140 1.2 ad #include <sys/tty.h> 141 1.2 ad #include <sys/proc.h> 142 1.2 ad #include <sys/conf.h> 143 1.2 ad #include <sys/file.h> 144 1.2 ad #include <sys/kernel.h> 145 1.2 ad #include <sys/device.h> 146 1.14 thorpej #include <sys/kmem.h> 147 1.8 ad #include <sys/intr.h> 148 1.2 ad 149 1.2 ad #include <dev/dec/lk201.h> 150 1.2 ad 151 1.2 ad #include <dev/tc/tcvar.h> 152 1.2 ad #include <dev/tc/ioasicreg.h> 153 1.2 ad #include <dev/tc/ioasicvar.h> 154 1.2 ad 155 1.2 ad #include <pmax/pmax/maxine.h> 156 1.2 ad 157 1.2 ad #include <pmax/tc/dtreg.h> 158 1.2 ad #include <pmax/tc/dtvar.h> 159 1.2 ad 160 1.2 ad #define DT_BUF_CNT 16 161 1.2 ad #define DT_ESC_CHAR 0xf8 162 1.3 ad #define DT_XMT_OK 0xfb 163 1.2 ad #define DT_MAX_POLL 0x70000 /* about half a sec */ 164 1.2 ad 165 1.2 ad #define DT_GET_BYTE(data) (((*(data)) >> 8) & 0xff) 166 1.2 ad #define DT_PUT_BYTE(data,c) { *(data) = (c) << 8; wbflush(); } 167 1.2 ad 168 1.2 ad #define DT_RX_AVAIL(poll) ((*(poll) & 1) != 0) 169 1.2 ad #define DT_TX_AVAIL(poll) ((*(poll) & 2) != 0) 170 1.2 ad 171 1.11 tsutsui int dt_match(device_t, cfdata_t, void *); 172 1.11 tsutsui void dt_attach(device_t, device_t, void *); 173 1.2 ad int dt_intr(void *); 174 1.2 ad int dt_print(void *, const char *); 175 1.2 ad void dt_strvis(uint8_t *, char *, int); 176 1.3 ad void dt_dispatch(void *); 177 1.2 ad 178 1.2 ad int dt_kbd_addr = DT_ADDR_KBD; 179 1.3 ad struct dt_device dt_kbd_dv; 180 1.3 ad int dt_ms_addr = DT_ADDR_MOUSE; 181 1.3 ad struct dt_device dt_ms_dv; 182 1.2 ad struct dt_state dt_state; 183 1.2 ad 184 1.11 tsutsui CFATTACH_DECL_NEW(dt, sizeof(struct dt_softc), 185 1.2 ad dt_match, dt_attach, NULL, NULL); 186 1.2 ad 187 1.2 ad int 188 1.11 tsutsui dt_match(device_t parent, cfdata_t cf, void *aux) 189 1.2 ad { 190 1.2 ad struct ioasicdev_attach_args *d; 191 1.2 ad 192 1.2 ad d = aux; 193 1.2 ad 194 1.2 ad if (strcmp(d->iada_modname, "dtop") != 0) 195 1.2 ad return (0); 196 1.2 ad 197 1.7 christos if (badaddr((void *)(d->iada_addr), 2)) 198 1.2 ad return (0); 199 1.2 ad 200 1.2 ad return (1); 201 1.2 ad } 202 1.2 ad 203 1.2 ad void 204 1.11 tsutsui dt_attach(device_t parent, device_t self, void *aux) 205 1.2 ad { 206 1.2 ad struct ioasicdev_attach_args *d; 207 1.2 ad struct dt_attach_args dta; 208 1.2 ad struct dt_softc *sc; 209 1.2 ad struct dt_msg *msg; 210 1.2 ad int i; 211 1.2 ad 212 1.2 ad d = aux; 213 1.11 tsutsui sc = device_private(self); 214 1.11 tsutsui sc->sc_dev = self; 215 1.2 ad 216 1.2 ad dt_cninit(); 217 1.2 ad 218 1.14 thorpej msg = kmem_alloc(sizeof(*msg) * DT_BUF_CNT, KM_SLEEP); 219 1.8 ad sc->sc_sih = softint_establish(SOFTINT_SERIAL, dt_dispatch, sc); 220 1.3 ad if (sc->sc_sih == NULL) { 221 1.11 tsutsui printf("%s: memory exhausted\n", device_xname(self)); 222 1.14 thorpej kmem_free(msg, sizeof(*msg) * DT_BUF_CNT); 223 1.12 maxv return; 224 1.3 ad } 225 1.3 ad 226 1.3 ad SIMPLEQ_INIT(&sc->sc_queue); 227 1.2 ad SLIST_INIT(&sc->sc_free); 228 1.2 ad for (i = 0; i < DT_BUF_CNT; i++, msg++) 229 1.2 ad SLIST_INSERT_HEAD(&sc->sc_free, msg, chain.slist); 230 1.2 ad 231 1.2 ad ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_TTY, dt_intr, sc); 232 1.2 ad printf("\n"); 233 1.2 ad 234 1.3 ad dta.dta_addr = DT_ADDR_KBD; 235 1.16 thorpej config_found(self, &dta, dt_print, CFARGS_NONE); 236 1.3 ad dta.dta_addr = DT_ADDR_MOUSE; 237 1.16 thorpej config_found(self, &dta, dt_print, CFARGS_NONE); 238 1.2 ad } 239 1.2 ad 240 1.2 ad void 241 1.2 ad dt_cninit(void) 242 1.2 ad { 243 1.2 ad 244 1.2 ad dt_state.ds_poll = (volatile u_int *) 245 1.2 ad MIPS_PHYS_TO_KSEG1(XINE_REG_INTR); 246 1.2 ad dt_state.ds_data = (volatile u_int *) 247 1.2 ad MIPS_PHYS_TO_KSEG1(XINE_PHYS_TC_3_START + 0x280000); 248 1.2 ad } 249 1.2 ad 250 1.2 ad int 251 1.2 ad dt_print(void *aux, const char *pnp) 252 1.2 ad { 253 1.2 ad 254 1.2 ad return (QUIET); 255 1.2 ad } 256 1.2 ad 257 1.2 ad int 258 1.3 ad dt_establish_handler(struct dt_softc *sc, struct dt_device *dtdv, 259 1.11 tsutsui void *arg, void (*hdlr)(void *, struct dt_msg *)) 260 1.2 ad { 261 1.2 ad 262 1.11 tsutsui dtdv->dtdv_arg = arg; 263 1.3 ad dtdv->dtdv_handler = hdlr; 264 1.2 ad return (0); 265 1.2 ad } 266 1.2 ad 267 1.2 ad int 268 1.2 ad dt_intr(void *cookie) 269 1.2 ad { 270 1.2 ad struct dt_softc *sc; 271 1.2 ad struct dt_msg *msg, *pend; 272 1.2 ad 273 1.2 ad sc = cookie; 274 1.2 ad 275 1.2 ad switch (dt_msg_get(&sc->sc_msg, 1)) { 276 1.2 ad case DT_GET_ERROR: 277 1.2 ad /* 278 1.2 ad * Ugh! The most common occurrence of a data overrun is upon 279 1.2 ad * a key press and the result is a software generated "stuck 280 1.2 ad * key". All I can think to do is fake an "all keys up" 281 1.2 ad * whenever a data overrun occurs. 282 1.2 ad */ 283 1.2 ad sc->sc_msg.src = dt_kbd_addr; 284 1.3 ad sc->sc_msg.ctl = DT_CTL(1, 0, 0); 285 1.2 ad sc->sc_msg.body[0] = DT_KBD_EMPTY; 286 1.2 ad #ifdef DIAGNOSTIC 287 1.2 ad printf("%s: data overrun or stray interrupt\n", 288 1.11 tsutsui device_xname(sc->sc_dev)); 289 1.2 ad #endif 290 1.2 ad break; 291 1.2 ad 292 1.2 ad case DT_GET_DONE: 293 1.2 ad break; 294 1.2 ad 295 1.2 ad case DT_GET_NOTYET: 296 1.2 ad return (1); 297 1.2 ad } 298 1.2 ad 299 1.2 ad if ((msg = SLIST_FIRST(&sc->sc_free)) == NULL) { 300 1.11 tsutsui printf("%s: input overflow\n", device_xname(sc->sc_dev)); 301 1.2 ad return (1); 302 1.2 ad } 303 1.2 ad SLIST_REMOVE_HEAD(&sc->sc_free, chain.slist); 304 1.2 ad memcpy(msg, &sc->sc_msg, sizeof(*msg)); 305 1.2 ad 306 1.3 ad pend = SIMPLEQ_FIRST(&sc->sc_queue); 307 1.3 ad SIMPLEQ_INSERT_TAIL(&sc->sc_queue, msg, chain.simpleq); 308 1.2 ad if (pend == NULL) 309 1.8 ad softint_schedule(sc->sc_sih); 310 1.2 ad 311 1.2 ad return (1); 312 1.2 ad } 313 1.2 ad 314 1.3 ad void 315 1.3 ad dt_dispatch(void *cookie) 316 1.3 ad { 317 1.3 ad struct dt_softc *sc; 318 1.3 ad struct dt_msg *msg; 319 1.4 mhitch int s; 320 1.3 ad struct dt_device *dtdv; 321 1.3 ad 322 1.3 ad sc = cookie; 323 1.3 ad msg = NULL; 324 1.3 ad 325 1.3 ad for (;;) { 326 1.3 ad s = spltty(); 327 1.4 mhitch if (msg != NULL) 328 1.3 ad SLIST_INSERT_HEAD(&sc->sc_free, msg, chain.slist); 329 1.3 ad msg = SIMPLEQ_FIRST(&sc->sc_queue); 330 1.3 ad if (msg != NULL) 331 1.3 ad SIMPLEQ_REMOVE_HEAD(&sc->sc_queue, chain.simpleq); 332 1.3 ad splx(s); 333 1.3 ad if (msg == NULL) 334 1.3 ad break; 335 1.3 ad 336 1.4 mhitch if (msg->src != DT_ADDR_MOUSE && msg->src != DT_ADDR_KBD) { 337 1.3 ad printf("%s: message from unknown dev 0x%x\n", 338 1.11 tsutsui device_xname(sc->sc_dev), sc->sc_msg.src); 339 1.3 ad dt_msg_dump(msg); 340 1.3 ad continue; 341 1.3 ad } 342 1.3 ad if (DT_CTL_P(msg->ctl) != 0) { 343 1.3 ad printf("%s: received control message\n", 344 1.11 tsutsui device_xname(sc->sc_dev)); 345 1.3 ad dt_msg_dump(msg); 346 1.3 ad continue; 347 1.3 ad } 348 1.3 ad 349 1.3 ad /* 350 1.4 mhitch * 1. Mouse should have no more than eight buttons, so first 351 1.4 mhitch * 8 bits of body will be zero. 352 1.3 ad * 2. Mouse should always send full locator report. 353 1.4 mhitch * Note: my mouse does not send 'z' data, so the size 354 1.4 mhitch * did not match the size of struct dt_locator_msg - mhitch 355 1.3 ad * 3. Keyboard should never report all-up (0x00) in 356 1.3 ad * a packet with size > 1. 357 1.3 ad */ 358 1.4 mhitch if (DT_CTL_LEN(msg->ctl) >= 6 && 359 1.4 mhitch msg->body[0] == 0 && msg->src != dt_ms_addr) { 360 1.4 mhitch dt_kbd_addr = dt_ms_addr; 361 1.4 mhitch dt_ms_addr = msg->src; 362 1.4 mhitch } else if (DT_CTL_LEN(msg->ctl) < 6 && msg->body[0] != 0 && 363 1.4 mhitch msg->src != dt_kbd_addr) { 364 1.4 mhitch dt_ms_addr = dt_kbd_addr; 365 1.4 mhitch dt_kbd_addr = msg->src; 366 1.4 mhitch } 367 1.4 mhitch 368 1.4 mhitch if (msg->src == dt_kbd_addr) 369 1.4 mhitch dtdv = &dt_kbd_dv; 370 1.4 mhitch else 371 1.3 ad dtdv = &dt_ms_dv; 372 1.3 ad 373 1.3 ad if (dtdv->dtdv_handler != NULL) 374 1.11 tsutsui (*dtdv->dtdv_handler)(dtdv->dtdv_arg, msg); 375 1.3 ad } 376 1.3 ad } 377 1.3 ad 378 1.2 ad int 379 1.2 ad dt_msg_get(struct dt_msg *msg, int intr) 380 1.2 ad { 381 1.2 ad volatile u_int *poll, *data; 382 1.2 ad uint8_t c; 383 1.5 jmc int max_polls; 384 1.2 ad 385 1.2 ad poll = dt_state.ds_poll; 386 1.2 ad data = dt_state.ds_data; 387 1.2 ad 388 1.2 ad /* 389 1.2 ad * The interface does not hand us the first byte, which is our 390 1.2 ad * address and cannot ever be anything else but 0x50. 391 1.2 ad */ 392 1.2 ad if (dt_state.ds_state == 0) { 393 1.2 ad dt_state.ds_escaped = 0; 394 1.2 ad dt_state.ds_ptr = 0; 395 1.2 ad } 396 1.2 ad 397 1.2 ad for (;;) { 398 1.5 jmc max_polls = DT_MAX_POLL; 399 1.2 ad 400 1.2 ad while (!DT_RX_AVAIL(poll)) { 401 1.2 ad if (intr) 402 1.2 ad return (DT_GET_NOTYET); 403 1.5 jmc if (max_polls-- <= 0) 404 1.2 ad break; 405 1.2 ad DELAY(1); 406 1.2 ad } 407 1.2 ad 408 1.5 jmc if (max_polls <= 0) { 409 1.2 ad if (dt_state.ds_state != 0) { 410 1.2 ad dt_state.ds_bad_pkts++; 411 1.2 ad dt_state.ds_state = 0; 412 1.2 ad } 413 1.2 ad return (DT_GET_ERROR); 414 1.2 ad } 415 1.2 ad 416 1.2 ad c = DT_GET_BYTE(data); 417 1.2 ad 418 1.2 ad if (dt_state.ds_escaped) { 419 1.2 ad switch (c) { 420 1.2 ad case 0xe8: 421 1.2 ad case 0xe9: 422 1.2 ad case 0xea: 423 1.2 ad case 0xeb: 424 1.2 ad c += 0x10; 425 1.2 ad break; 426 1.2 ad } 427 1.2 ad if (c == 'O') { 428 1.2 ad dt_state.ds_bad_pkts++; 429 1.2 ad dt_state.ds_state = 0; 430 1.2 ad return (DT_GET_ERROR); 431 1.2 ad } 432 1.2 ad dt_state.ds_escaped = 0; 433 1.2 ad } else if (c == DT_ESC_CHAR) { 434 1.2 ad dt_state.ds_escaped = 1; 435 1.2 ad continue; 436 1.2 ad } 437 1.2 ad 438 1.2 ad if (dt_state.ds_state == 0) { 439 1.2 ad msg->src = c; 440 1.2 ad dt_state.ds_state = 1; 441 1.2 ad } else if (dt_state.ds_state == 1) { 442 1.3 ad msg->ctl = c; 443 1.2 ad dt_state.ds_state = 2; 444 1.3 ad dt_state.ds_len = DT_CTL_LEN(msg->ctl) + 1; 445 1.2 ad if (dt_state.ds_len > sizeof(msg->body)) 446 1.2 ad printf("dt_msg_get: msg truncated: %d\n", 447 1.2 ad dt_state.ds_len); 448 1.2 ad } else /* if (dt_state.ds_state == 2) */ { 449 1.2 ad if (dt_state.ds_ptr < sizeof(msg->body)) 450 1.2 ad msg->body[dt_state.ds_ptr++] = c; 451 1.2 ad if (dt_state.ds_ptr >= dt_state.ds_len) 452 1.2 ad break; 453 1.2 ad } 454 1.2 ad } 455 1.2 ad 456 1.2 ad msg->dst = DT_ADDR_HOST; 457 1.2 ad dt_state.ds_state = 0; 458 1.2 ad return (DT_GET_DONE); 459 1.2 ad } 460 1.2 ad 461 1.2 ad void 462 1.3 ad dt_msg_dump(struct dt_msg *msg) 463 1.2 ad { 464 1.3 ad int i, l; 465 1.2 ad 466 1.3 ad l = DT_CTL_LEN(msg->ctl); 467 1.2 ad 468 1.3 ad printf("hdr: dst=%02x src=%02x p=%02x sub=%02x len=%02x\n", 469 1.3 ad msg->dst, msg->src, DT_CTL_P(msg->ctl), DT_CTL_SUBADDR(msg->ctl), 470 1.3 ad l); 471 1.3 ad 472 1.3 ad printf("body: "); 473 1.3 ad for (i = 0; i < l && i < 20; i++) 474 1.3 ad printf("%02x ", msg->body[i]); 475 1.3 ad if (i < l) { 476 1.3 ad printf("\n"); 477 1.3 ad for (; i < l; i++) 478 1.3 ad printf("%02x ", msg->body[i]); 479 1.2 ad } 480 1.3 ad printf("\n"); 481 1.2 ad } 482