hilid.c revision 1.1
1/*	$NetBSD: hilid.c,v 1.1 2011/02/06 18:26:54 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
43struct hilid_softc {
44	struct hildev_softc sc_hildev;
45
46	u_int8_t	sc_id[16];
47};
48
49int	hilidprobe(device_t, cfdata_t, void *);
50void	hilidattach(device_t, struct device *, void *);
51int	hiliddetach(device_t, int);
52
53CFATTACH_DECL_NEW(hilid, sizeof(struct hilid_softc),
54    hilidprobe, hilidattach, hiliddetach, NULL);
55
56int
57hilidprobe(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
67void
68hilidattach(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	printf("\n");
83
84	memset(sc->sc_id, 0, sizeof(sc->sc_id));
85	len = sizeof(sc->sc_id);
86	printf("%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		printf("\n");
93	} else
94		printf(" unavailable\n");
95}
96
97int
98hiliddetach(struct device *self, int flags)
99{
100	return (0);
101}
102