idprom.c revision 1.4 1 /* $NetBSD: idprom.c,v 1.4 1997/04/28 23:43:56 gwr Exp $ */
2
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Glass and Gordon W. Ross.
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 /*
40 * Machine ID PROM - system type and serial number
41 */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 #include <sys/kernel.h>
47
48 #include <machine/autoconf.h>
49 #include <machine/idprom.h>
50 #include <machine/obio.h>
51 #include <machine/machdep.h>
52 #include <machine/mon.h>
53
54 /*
55 * This structure is what this driver is all about.
56 * It is copied from the device early in startup.
57 */
58 struct idprom identity_prom;
59 static u_long idprom_pa;
60
61 static int idprom_match __P((struct device *, struct cfdata *, void *));
62 static void idprom_attach __P((struct device *, struct device *, void *));
63
64 struct cfattach idprom_ca = {
65 sizeof(struct device), idprom_match, idprom_attach
66 };
67
68 struct cfdriver idprom_cd = {
69 NULL, "idprom", DV_DULL
70 };
71
72 /*
73 * Find the IDPROM and copy it to memory.
74 * This is called early during startup,
75 * but late enough so peek_byte() works.
76 * Called by machdep.c:identifycpu()
77 */
78 void
79 idprom_init()
80 {
81 struct idprom *idp;
82 u_char *src, *dst;
83 caddr_t va;
84 u_long pa;
85 int len, x, xorsum;
86 union {
87 long l;
88 char c[4];
89 } hid;
90
91 /* First, probe for a separate IDPROM (3/470). */
92 pa = OBIO_IDPROM1;
93 va = obio_find_mapping(pa, IDPROM_SIZE);
94 if (peek_byte(va) == -1) {
95 /* IDPROM is in the EEPROM */
96 pa = OBIO_IDPROM2;
97 va = obio_find_mapping(pa, IDPROM_SIZE);
98 }
99
100 /* Save the phys. address for idprom_match. */
101 idprom_pa = pa;
102
103 /* Copy the IDPROM contents and do the checksum. */
104 idp = &identity_prom;
105 dst = (u_char *) idp;
106 src = (u_char *) va;
107 len = IDPROM_SIZE;
108 xorsum = 0; /* calculated as xor of data */
109
110 do {
111 x = *src++;
112 *dst++ = x;
113 xorsum ^= x;
114 } while (--len > 0);
115
116 if (xorsum != 0)
117 printf("idprom: bad checksum=%d\n", xorsum);
118 if (idp->idp_format < 1)
119 printf("idprom: bad version=%d\n", idp->idp_format);
120
121 /*
122 * Construct the hostid from the idprom contents.
123 * This appears to be the way SunOS does it.
124 */
125 hid.c[0] = idp->idp_machtype;
126 hid.c[1] = idp->idp_serialnum[0];
127 hid.c[2] = idp->idp_serialnum[1];
128 hid.c[3] = idp->idp_serialnum[2];
129 hostid = hid.l;
130 }
131
132 static int
133 idprom_match(parent, cf, args)
134 struct device *parent;
135 struct cfdata *cf;
136 void *args;
137 {
138 struct confargs *ca = args;
139
140 /* This driver only supports one unit. */
141 if (cf->cf_unit != 0)
142 return (0);
143
144 /* Match the address we determined earlier. */
145 if (ca->ca_paddr != idprom_pa)
146 return (0);
147
148 return (1);
149 }
150
151 static void
152 idprom_attach(parent, self, args)
153 struct device *parent;
154 struct device *self;
155 void *args;
156 {
157
158 printf("\n");
159 }
160
161 void
162 idprom_etheraddr(eaddrp)
163 u_char *eaddrp;
164 {
165 u_char *src, *dst;
166 int len = 6;
167
168 src = identity_prom.idp_etheraddr;
169 dst = eaddrp;
170
171 do *dst++ = *src++;
172 while (--len > 0);
173 }
174