idprom.c revision 1.3 1 1.3 chs /* $NetBSD: idprom.c,v 1.3 2005/01/22 15:36:11 chs Exp $ */
2 1.1 fredette
3 1.1 fredette /*-
4 1.1 fredette * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 fredette * All rights reserved.
6 1.1 fredette *
7 1.1 fredette * This code is derived from software contributed to The NetBSD Foundation
8 1.1 fredette * by Adam Glass and Gordon W. Ross.
9 1.1 fredette *
10 1.1 fredette * Redistribution and use in source and binary forms, with or without
11 1.1 fredette * modification, are permitted provided that the following conditions
12 1.1 fredette * are met:
13 1.1 fredette * 1. Redistributions of source code must retain the above copyright
14 1.1 fredette * notice, this list of conditions and the following disclaimer.
15 1.1 fredette * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 fredette * notice, this list of conditions and the following disclaimer in the
17 1.1 fredette * documentation and/or other materials provided with the distribution.
18 1.1 fredette * 3. All advertising materials mentioning features or use of this software
19 1.1 fredette * must display the following acknowledgement:
20 1.1 fredette * This product includes software developed by the NetBSD
21 1.1 fredette * Foundation, Inc. and its contributors.
22 1.1 fredette * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 fredette * contributors may be used to endorse or promote products derived
24 1.1 fredette * from this software without specific prior written permission.
25 1.1 fredette *
26 1.1 fredette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 fredette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 fredette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 fredette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 fredette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 fredette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 fredette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 fredette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 fredette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 fredette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 fredette * POSSIBILITY OF SUCH DAMAGE.
37 1.1 fredette */
38 1.1 fredette
39 1.1 fredette /*
40 1.1 fredette * Machine ID PROM - system type and serial number
41 1.1 fredette */
42 1.1 fredette
43 1.1 fredette #include <sys/types.h>
44 1.1 fredette #include <machine/idprom.h>
45 1.1 fredette #include <machine/mon.h>
46 1.1 fredette
47 1.1 fredette #include "libsa.h"
48 1.1 fredette
49 1.1 fredette /*
50 1.1 fredette * This driver provides a soft copy of the IDPROM.
51 1.1 fredette * It is copied from the device early in startup.
52 1.1 fredette * Allow these to be patched (helps with poor old
53 1.1 fredette * Sun3/80 boxes with dead NVRAM).
54 1.1 fredette */
55 1.1 fredette u_char cpu_machine_id = 0;
56 1.1 fredette struct idprom identity_prom = { 0 };
57 1.1 fredette
58 1.3 chs int idprom_cksum(u_char *);
59 1.3 chs void idprom_init2(void);
60 1.3 chs void idprom_init3(void);
61 1.3 chs void idprom_init3x(void);
62 1.1 fredette
63 1.1 fredette int
64 1.3 chs idprom_cksum(u_char *p)
65 1.1 fredette {
66 1.1 fredette int len, x;
67 1.1 fredette
68 1.1 fredette len = IDPROM_CKSUM_SIZE;
69 1.1 fredette x = 0; /* xor of data */
70 1.1 fredette do x ^= *p++;
71 1.1 fredette while (--len > 0);
72 1.1 fredette return (x);
73 1.1 fredette }
74 1.1 fredette
75 1.1 fredette /* Copy the ethernet address into the passed space. */
76 1.1 fredette void
77 1.3 chs idprom_etheraddr(u_char *eaddrp)
78 1.1 fredette {
79 1.1 fredette
80 1.1 fredette idprom_init();
81 1.3 chs memcpy(eaddrp, identity_prom.idp_etheraddr, 6);
82 1.1 fredette }
83 1.1 fredette
84 1.1 fredette /* Fetch a copy of the idprom. */
85 1.3 chs void
86 1.3 chs idprom_init(void)
87 1.1 fredette {
88 1.1 fredette
89 1.1 fredette if (identity_prom.idp_format == 1)
90 1.1 fredette return;
91 1.1 fredette
92 1.1 fredette /* Copy the IDPROM contents and do the checksum. */
93 1.1 fredette if (_is3x)
94 1.1 fredette idprom_init3x();
95 1.1 fredette else if (_is2)
96 1.1 fredette idprom_init2();
97 1.1 fredette else
98 1.1 fredette idprom_init3();
99 1.1 fredette
100 1.1 fredette if (identity_prom.idp_format != 1)
101 1.2 provos panic("idprom: bad version");
102 1.1 fredette cpu_machine_id = identity_prom.idp_machtype;
103 1.1 fredette }
104 1.1 fredette
105 1.1 fredette /*
106 1.1 fredette * Sun2 version:
107 1.1 fredette * Just copy it from control space.
108 1.1 fredette */
109 1.3 chs void
110 1.3 chs idprom_init2(void)
111 1.1 fredette {
112 1.1 fredette
113 1.1 fredette /* Copy the IDPROM contents and do the checksum. */
114 1.1 fredette sun2_getidprom((u_char *) &identity_prom);
115 1.1 fredette if (idprom_cksum((u_char *) &identity_prom))
116 1.1 fredette printf("idprom: bad checksum\n");
117 1.1 fredette }
118 1.1 fredette
119 1.1 fredette /*
120 1.1 fredette * Sun3 version:
121 1.1 fredette * Just copy it from control space.
122 1.1 fredette */
123 1.3 chs void
124 1.3 chs idprom_init3(void)
125 1.1 fredette {
126 1.1 fredette
127 1.1 fredette /* Copy the IDPROM contents and do the checksum. */
128 1.1 fredette sun3_getidprom((u_char *) &identity_prom);
129 1.1 fredette if (idprom_cksum((u_char *) &identity_prom))
130 1.1 fredette printf("idprom: bad checksum\n");
131 1.1 fredette }
132 1.1 fredette
133 1.1 fredette /*
134 1.1 fredette * Sun3X version:
135 1.1 fredette * Rather than do all the map-in/probe work to find the idprom,
136 1.1 fredette * we can cheat! We _know_ the monitor already made a copy of
137 1.1 fredette * the IDPROM in its data page. All we have to do is find it.
138 1.1 fredette *
139 1.1 fredette * Yeah, this is sorta gross... Only used on old PROMs that
140 1.1 fredette * do not have a sif_macaddr function (rev < 3.0). The area
141 1.1 fredette * to search was determined from some "insider" info. about
142 1.1 fredette * the layout of the PROM data area.
143 1.1 fredette */
144 1.3 chs void
145 1.3 chs idprom_init3x(void)
146 1.1 fredette {
147 1.1 fredette u_char *p;
148 1.1 fredette
149 1.1 fredette printf("idprom: Sun3X search for soft copy...\n");
150 1.1 fredette
151 1.1 fredette for (p = (u_char *)(SUN3X_MONDATA + 0x0400);
152 1.1 fredette p < (u_char *)(SUN3X_MONDATA + 0x1c00); p++)
153 1.1 fredette {
154 1.1 fredette /* first check for some constants */
155 1.1 fredette if (p[0] != 0x01) /* format */
156 1.1 fredette continue;
157 1.1 fredette if (p[2] != 0x08) /* ether[0] */
158 1.1 fredette continue;
159 1.1 fredette if (p[3] != 0x00) /* ether[1] */
160 1.1 fredette continue;
161 1.1 fredette if (p[4] != 0x20) /* ether[2] */
162 1.1 fredette continue;
163 1.1 fredette if ((p[1] & 0xfc) != IDM_ARCH_SUN3X)
164 1.1 fredette continue;
165 1.1 fredette /* Looks plausible. Try the checksum. */
166 1.1 fredette if (idprom_cksum(p) == 0)
167 1.1 fredette goto found;
168 1.1 fredette }
169 1.2 provos panic("idprom: not found in monitor data");
170 1.1 fredette
171 1.1 fredette found:
172 1.1 fredette printf("idprom: copy found at 0x%x\n", (int)p);
173 1.3 chs memcpy(&identity_prom, p, sizeof(struct idprom));
174 1.1 fredette }
175