1 /* $NetBSD: hilid.c,v 1.2 2011/02/15 11:05:51 tsutsui Exp $ */ 2 /* $OpenBSD: hilid.c,v 1.4 2005/01/09 23:49:36 miod Exp $ */ 3 /* 4 * Copyright (c) 2003, Miodrag Vallat. 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 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #include <sys/param.h> 31 #include <sys/systm.h> 32 #include <sys/device.h> 33 #include <sys/ioctl.h> 34 #include <sys/bus.h> 35 #include <sys/cpu.h> 36 37 #include <machine/autoconf.h> 38 39 #include <dev/hil/hilreg.h> 40 #include <dev/hil/hilvar.h> 41 #include <dev/hil/hildevs.h> 42 43 struct hilid_softc { 44 struct hildev_softc sc_hildev; 45 46 uint8_t sc_id[16]; 47 }; 48 49 static int hilidprobe(device_t, cfdata_t, void *); 50 static void hilidattach(device_t, device_t, void *); 51 static int hiliddetach(device_t, int); 52 53 CFATTACH_DECL_NEW(hilid, sizeof(struct hilid_softc), 54 hilidprobe, hilidattach, hiliddetach, NULL); 55 56 int 57 hilidprobe(device_t parent, cfdata_t cf, void *aux) 58 { 59 struct hil_attach_args *ha = aux; 60 61 if (ha->ha_type != HIL_DEVICE_IDMODULE) 62 return 0; 63 64 return 1; 65 } 66 67 void 68 hilidattach(device_t parent, device_t self, void *aux) 69 { 70 struct hilid_softc *sc = device_private(self); 71 struct hildev_softc *hdsc = &sc->sc_hildev; 72 struct hil_attach_args *ha = aux; 73 u_int i, len; 74 75 sc->sc_hildev.sc_dev = self; 76 sc->hd_code = ha->ha_code; 77 sc->hd_type = ha->ha_type; 78 sc->hd_infolen = ha->ha_infolen; 79 memcpy(sc->hd_info, ha->ha_info, ha->ha_infolen); 80 sc->hd_fn = NULL; 81 82 aprint_normal("\n"); 83 84 memset(sc->sc_id, 0, sizeof(sc->sc_id)); 85 len = sizeof(sc->sc_id); 86 aprint_normal("%s: security code", device_xname(self)); 87 88 if (send_hildev_cmd(hdsc, 89 HIL_SECURITY, sc->sc_id, &len) == 0) { 90 for (i = 0; i < sizeof(sc->sc_id); i++) 91 printf(" %02x", sc->sc_id[i]); 92 aprint_normal("\n"); 93 } else 94 aprint_normal(" unavailable\n"); 95 } 96 97 int 98 hiliddetach(device_t self, int flags) 99 { 100 101 return 0; 102 } 103