xref: /netbsd-src/sys/arch/sun3/sun3x/idprom.c (revision d0fed6c87ddc40a8bffa6f99e7433ddfc864dd83)
1 /*	$NetBSD: idprom.c,v 1.2 1997/01/27 22:16:37 gwr Exp $	*/
2 
3 /*-
4  * Copyright (c) 1996 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/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 #include <sys/kernel.h>
47 
48 #include <machine/autoconf.h>
49 #include <machine/idprom.h>
50 #include <machine/obio.h>
51 #include <machine/machdep.h>
52 #include <machine/mon.h>
53 
54 /*
55  * This structure is what this driver is all about.
56  * It is copied from the device early in startup.
57  */
58 struct idprom identity_prom;
59 static char *idprom_va;
60 
61 /*
62  * This is called very early during startup to
63  * get a copy of the idprom from control space.
64  */
65 void
66 idprom_init()
67 {
68 	struct idprom *idp;
69 	char *src, *dst;
70 	int len, x, xorsum;
71 	union {
72 		long l;
73 		char c[4];
74 	} hid;
75 
76 	idprom_va = obio_find_mapping(OBIO_IDPROM2, sizeof(struct idprom));
77 
78 	idp = &identity_prom;
79 	dst = (char*)idp;
80 	src = (char*)idprom_va;
81 	len = IDPROM_SIZE;
82 	xorsum = 0;	/* calculated as xor of data */
83 
84 	do {
85 		x = *src++;
86 		*dst++ = x;
87 		xorsum ^= x;
88 	} while (--len > 0);
89 
90 	if (xorsum != 0) {
91 		mon_printf("idprom_fetch: bad checksum=%d\n", xorsum);
92 		sunmon_abort();
93 	}
94 	if (idp->idp_format < 1) {
95 		mon_printf("idprom_fetch: bad version=%d\n", idp->idp_format);
96 		sunmon_abort();
97 	}
98 
99 	/*
100 	 * Construct the hostid from the idprom contents.
101 	 * This appears to be the way SunOS does it.
102 	 */
103 	hid.c[0] = idp->idp_machtype;
104 	hid.c[1] = idp->idp_serialnum[0];
105 	hid.c[2] = idp->idp_serialnum[1];
106 	hid.c[3] = idp->idp_serialnum[2];
107 	hostid = hid.l;
108 }
109 
110 void idprom_etheraddr(eaddrp)
111 	u_char *eaddrp;
112 {
113 	u_char *src, *dst;
114 	int len = 6;
115 
116 	src = identity_prom.idp_etheraddr;
117 	dst = eaddrp;
118 
119 	do *dst++ = *src++;
120 	while (--len > 0);
121 }
122