1 /* $NetBSD: idprom.c,v 1.29 2008/04/28 20:23:38 martin 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 * 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. 30 */ 31 32 /* 33 * Machine ID PROM - system type and serial number 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: idprom.c,v 1.29 2008/04/28 20:23:38 martin Exp $"); 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/device.h> 42 #include <sys/kernel.h> 43 44 #include <machine/autoconf.h> 45 #include <machine/idprom.h> 46 47 #include <sun3/sun3/machdep.h> 48 #ifdef _SUN3_ 49 #include <sun3/sun3/control.h> 50 #elif _SUN3X_ 51 #include <sun3/sun3x/obio.h> 52 #endif 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(u_char *); 61 static void idprom_get(u_char *); 62 static int idprom_hostid(void); 63 64 /* 65 * Copy the IDPROM contents, 66 * verify the checksum, 67 * set the hostid... 68 */ 69 void 70 idprom_init(void) 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(u_char *p) 85 { 86 int len, x; 87 88 len = IDPROM_CKSUM_SIZE; 89 x = 0; /* xor of data */ 90 do x ^= *p++; 91 while (--len > 0); 92 return (x); 93 } 94 95 static int 96 idprom_hostid(void) 97 { 98 struct idprom *idp; 99 union { 100 long l; 101 char c[4]; 102 } hid; 103 104 /* 105 * Construct the hostid from the idprom contents. 106 * This appears to be the way SunOS does it. 107 */ 108 idp = &identity_prom; 109 hid.c[0] = idp->idp_machtype; 110 hid.c[1] = idp->idp_serialnum[0]; 111 hid.c[2] = idp->idp_serialnum[1]; 112 hid.c[3] = idp->idp_serialnum[2]; 113 return (hid.l); 114 } 115 116 void 117 idprom_etheraddr(u_char *eaddrp) 118 { 119 120 memcpy(eaddrp, identity_prom.idp_etheraddr, 6); 121 } 122 123 /* 124 * Machine specific stuff follows. 125 */ 126 127 #ifdef _SUN3_ 128 /* 129 * Copy the IDPROM to memory. 130 * 131 * On the Sun3, this is called very early, 132 * because we need the cputype. 133 */ 134 static void 135 idprom_get(u_char *dst) 136 { 137 vaddr_t src; /* control space address */ 138 int len, x; 139 140 src = IDPROM_BASE; 141 len = IDPROM_SIZE; 142 do { 143 x = get_control_byte(src++); 144 *dst++ = x; 145 } while (--len > 0); 146 } 147 148 #endif /* SUN3 */ 149 #ifdef _SUN3X_ 150 #error "not yet merged" 151 #endif /* SUN3X */ 152