Fix memory barrier in a debug function
[netbsd-mini2440.git] / sys / arch / sun68k / stand / libsa / idprom.c
blob939cd459cc5d7efe5f132a1eab829af7b76cba16
1 /* $NetBSD: idprom.c,v 1.5 2008/04/28 20:23:39 martin Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
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
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.
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>
41 #include "libsa.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);
57 int
58 idprom_cksum(u_char *p)
60 int len, x;
62 len = IDPROM_CKSUM_SIZE;
63 x = 0; /* xor of data */
64 do x ^= *p++;
65 while (--len > 0);
66 return (x);
69 /* Copy the ethernet address into the passed space. */
70 void
71 idprom_etheraddr(u_char *eaddrp)
74 idprom_init();
75 memcpy(eaddrp, identity_prom.idp_etheraddr, 6);
78 /* Fetch a copy of the idprom. */
79 void
80 idprom_init(void)
83 if (identity_prom.idp_format == 1)
84 return;
86 /* Copy the IDPROM contents and do the checksum. */
87 if (_is3x)
88 idprom_init3x();
89 else if (_is2)
90 idprom_init2();
91 else
92 idprom_init3();
94 if (identity_prom.idp_format != 1)
95 panic("idprom: bad version");
96 cpu_machine_id = identity_prom.idp_machtype;
100 * Sun2 version:
101 * Just copy it from control space.
103 void
104 idprom_init2(void)
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");
114 * Sun3 version:
115 * Just copy it from control space.
117 void
118 idprom_init3(void)
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");
128 * Sun3X version:
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.
138 void
139 idprom_init3x(void)
141 u_char *p;
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 */
150 continue;
151 if (p[2] != 0x08) /* ether[0] */
152 continue;
153 if (p[3] != 0x00) /* ether[1] */
154 continue;
155 if (p[4] != 0x20) /* ether[2] */
156 continue;
157 if ((p[1] & 0xfc) != IDM_ARCH_SUN3X)
158 continue;
159 /* Looks plausible. Try the checksum. */
160 if (idprom_cksum(p) == 0)
161 goto found;
163 panic("idprom: not found in monitor data");
165 found:
166 printf("idprom: copy found at 0x%x\n", (int)p);
167 memcpy(&identity_prom, p, sizeof(struct idprom));