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