idprom.c revision 1.2 1 /* $NetBSD: idprom.c,v 1.2 2002/09/27 15:36:57 provos Exp $ */
2
3 /*-
4 * Copyright (c) 1998 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/types.h>
44 #include <machine/idprom.h>
45 #include <machine/mon.h>
46
47 #include "libsa.h"
48
49 /*
50 * This driver provides a soft copy of the IDPROM.
51 * It is copied from the device early in startup.
52 * Allow these to be patched (helps with poor old
53 * Sun3/80 boxes with dead NVRAM).
54 */
55 u_char cpu_machine_id = 0;
56 struct idprom identity_prom = { 0 };
57
58 int idprom_cksum __P((u_char *));
59 void idprom_init2 __P((void));
60 void idprom_init3 __P((void));
61 void idprom_init3x __P((void));
62
63 int
64 idprom_cksum(p)
65 u_char *p;
66 {
67 int len, x;
68
69 len = IDPROM_CKSUM_SIZE;
70 x = 0; /* xor of data */
71 do x ^= *p++;
72 while (--len > 0);
73 return (x);
74 }
75
76 /* Copy the ethernet address into the passed space. */
77 void
78 idprom_etheraddr(eaddrp)
79 u_char *eaddrp;
80 {
81
82 idprom_init();
83 bcopy(identity_prom.idp_etheraddr, eaddrp, 6);
84 }
85
86 /* Fetch a copy of the idprom. */
87 void
88 idprom_init()
89 {
90
91 if (identity_prom.idp_format == 1)
92 return;
93
94 /* Copy the IDPROM contents and do the checksum. */
95 if (_is3x)
96 idprom_init3x();
97 else if (_is2)
98 idprom_init2();
99 else
100 idprom_init3();
101
102 if (identity_prom.idp_format != 1)
103 panic("idprom: bad version");
104 cpu_machine_id = identity_prom.idp_machtype;
105 }
106
107 /*
108 * Sun2 version:
109 * Just copy it from control space.
110 */
111 void
112 idprom_init2()
113 {
114
115 /* Copy the IDPROM contents and do the checksum. */
116 sun2_getidprom((u_char *) &identity_prom);
117 if (idprom_cksum((u_char *) &identity_prom))
118 printf("idprom: bad checksum\n");
119 }
120
121 /*
122 * Sun3 version:
123 * Just copy it from control space.
124 */
125 void
126 idprom_init3()
127 {
128
129 /* Copy the IDPROM contents and do the checksum. */
130 sun3_getidprom((u_char *) &identity_prom);
131 if (idprom_cksum((u_char *) &identity_prom))
132 printf("idprom: bad checksum\n");
133 }
134
135 /*
136 * Sun3X version:
137 * Rather than do all the map-in/probe work to find the idprom,
138 * we can cheat! We _know_ the monitor already made a copy of
139 * the IDPROM in its data page. All we have to do is find it.
140 *
141 * Yeah, this is sorta gross... Only used on old PROMs that
142 * do not have a sif_macaddr function (rev < 3.0). The area
143 * to search was determined from some "insider" info. about
144 * the layout of the PROM data area.
145 */
146 void
147 idprom_init3x()
148 {
149 u_char *p;
150
151 printf("idprom: Sun3X search for soft copy...\n");
152
153 for (p = (u_char *)(SUN3X_MONDATA + 0x0400);
154 p < (u_char *)(SUN3X_MONDATA + 0x1c00); p++)
155 {
156 /* first check for some constants */
157 if (p[0] != 0x01) /* format */
158 continue;
159 if (p[2] != 0x08) /* ether[0] */
160 continue;
161 if (p[3] != 0x00) /* ether[1] */
162 continue;
163 if (p[4] != 0x20) /* ether[2] */
164 continue;
165 if ((p[1] & 0xfc) != IDM_ARCH_SUN3X)
166 continue;
167 /* Looks plausible. Try the checksum. */
168 if (idprom_cksum(p) == 0)
169 goto found;
170 }
171 panic("idprom: not found in monitor data");
172
173 found:
174 printf("idprom: copy found at 0x%x\n", (int)p);
175 bcopy(p, &identity_prom, sizeof(struct idprom));
176 }
177