xref: /netbsd/sys/arch/sun2/sun2/idprom.c (revision bf9ec67e)
1 /*	$NetBSD: idprom.c,v 1.2 2001/11/30 18:06:55 fredette 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, Gordon W. Ross, and Matthew Fredette.
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 
51 #include <sun2/sun2/machdep.h>
52 #include <sun2/sun2/control.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 
60 static int idprom_cksum __P((u_char *));
61 static void idprom_get __P((u_char *));
62 static int idprom_hostid __P((void));
63 
64 /*
65  * Copy the IDPROM contents,
66  * verify the checksum,
67  * set the hostid...
68  */
69 void
70 idprom_init()
71 {
72 
73 	idprom_get((u_char *)&identity_prom);
74 	if (idprom_cksum((u_char *) &identity_prom))
75 		printf("idprom: bad checksum\n");
76 	if (identity_prom.idp_format < 1)
77 		printf("idprom: bad version\n");
78 
79 	cpu_machine_id = identity_prom.idp_machtype;
80 	hostid = idprom_hostid();
81 }
82 
83 static int
84 idprom_cksum(p)
85 	u_char *p;
86 {
87 	int len, x;
88 
89 	len = IDPROM_CKSUM_SIZE;
90 	x = 0;	/* xor of data */
91 	do x ^= *p++;
92 	while (--len > 0);
93 	return (x);
94 }
95 
96 static int
97 idprom_hostid()
98 {
99 	struct idprom *idp;
100 	union {
101 		long l;
102 		char c[4];
103 	} hid;
104 
105 	/*
106 	 * Construct the hostid from the idprom contents.
107 	 * This appears to be the way SunOS does it.
108 	 */
109 	idp = &identity_prom;
110 	hid.c[0] = idp->idp_machtype;
111 	hid.c[1] = idp->idp_serialnum[0];
112 	hid.c[2] = idp->idp_serialnum[1];
113 	hid.c[3] = idp->idp_serialnum[2];
114 	return (hid.l);
115 }
116 
117 void
118 idprom_etheraddr(eaddrp)
119 	u_char *eaddrp;
120 {
121 
122 	memcpy(eaddrp, identity_prom.idp_etheraddr, 6);
123 }
124 
125 /*
126  * Machine specific stuff follows.
127  */
128 
129 /*
130  * Copy the IDPROM to memory.
131  *
132  * On the Sun2, this is called very early,
133  * because we need the cputype.
134  */
135 static void
136 idprom_get(dst)
137 	u_char *dst;
138 {
139 	vaddr_t src;	/* control space address */
140 	int len, x;
141 
142 	src = IDPROM_BASE;
143 	len = IDPROM_SIZE;
144 	do {
145 		x = get_control_byte(src);
146 		src += NBPG;
147 		*dst++ = x;
148 	} while (--len > 0);
149 }
150 
151