1 /* $NetBSD: idprom.c,v 1.5 2008/04/28 20:23:39 martin Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Glass and Gordon W. Ross.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Machine ID PROM - system type and serial number
36 #include <sys/types.h>
37 #include <machine/idprom.h>
38 #include <machine/mon.h>
39 #include <lib/libsa/stand.h>
44 * This driver provides a soft copy of the IDPROM.
45 * It is copied from the device early in startup.
46 * Allow these to be patched (helps with poor old
47 * Sun3/80 boxes with dead NVRAM).
49 u_char cpu_machine_id
= 0;
50 struct idprom identity_prom
= { 0 };
52 int idprom_cksum(u_char
*);
53 void idprom_init2(void);
54 void idprom_init3(void);
55 void idprom_init3x(void);
58 idprom_cksum(u_char
*p
)
62 len
= IDPROM_CKSUM_SIZE
;
63 x
= 0; /* xor of data */
69 /* Copy the ethernet address into the passed space. */
71 idprom_etheraddr(u_char
*eaddrp
)
75 memcpy(eaddrp
, identity_prom
.idp_etheraddr
, 6);
78 /* Fetch a copy of the idprom. */
83 if (identity_prom
.idp_format
== 1)
86 /* Copy the IDPROM contents and do the checksum. */
94 if (identity_prom
.idp_format
!= 1)
95 panic("idprom: bad version");
96 cpu_machine_id
= identity_prom
.idp_machtype
;
101 * Just copy it from control space.
107 /* Copy the IDPROM contents and do the checksum. */
108 sun2_getidprom((u_char
*) &identity_prom
);
109 if (idprom_cksum((u_char
*) &identity_prom
))
110 printf("idprom: bad checksum\n");
115 * Just copy it from control space.
121 /* Copy the IDPROM contents and do the checksum. */
122 sun3_getidprom((u_char
*) &identity_prom
);
123 if (idprom_cksum((u_char
*) &identity_prom
))
124 printf("idprom: bad checksum\n");
129 * Rather than do all the map-in/probe work to find the idprom,
130 * we can cheat! We _know_ the monitor already made a copy of
131 * the IDPROM in its data page. All we have to do is find it.
133 * Yeah, this is sorta gross... Only used on old PROMs that
134 * do not have a sif_macaddr function (rev < 3.0). The area
135 * to search was determined from some "insider" info. about
136 * the layout of the PROM data area.
143 printf("idprom: Sun3X search for soft copy...\n");
145 for (p
= (u_char
*)(SUN3X_MONDATA
+ 0x0400);
146 p
< (u_char
*)(SUN3X_MONDATA
+ 0x1c00); p
++)
148 /* first check for some constants */
149 if (p
[0] != 0x01) /* format */
151 if (p
[2] != 0x08) /* ether[0] */
153 if (p
[3] != 0x00) /* ether[1] */
155 if (p
[4] != 0x20) /* ether[2] */
157 if ((p
[1] & 0xfc) != IDM_ARCH_SUN3X
)
159 /* Looks plausible. Try the checksum. */
160 if (idprom_cksum(p
) == 0)
163 panic("idprom: not found in monitor data");
166 printf("idprom: copy found at 0x%x\n", (int)p
);
167 memcpy(&identity_prom
, p
, sizeof(struct idprom
));