idprom.c revision 1.3
1/* $NetBSD: idprom.c,v 1.3 2005/01/22 15:36:11 chs Exp $ */ 2 3/*- 4 * Copyright (c) 1998 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/types.h> 44#include <machine/idprom.h> 45#include <machine/mon.h> 46 47#include "libsa.h" 48 49/* 50 * This driver provides a soft copy of the IDPROM. 51 * It is copied from the device early in startup. 52 * Allow these to be patched (helps with poor old 53 * Sun3/80 boxes with dead NVRAM). 54 */ 55u_char cpu_machine_id = 0; 56struct idprom identity_prom = { 0 }; 57 58int idprom_cksum(u_char *); 59void idprom_init2(void); 60void idprom_init3(void); 61void idprom_init3x(void); 62 63int 64idprom_cksum(u_char *p) 65{ 66 int len, x; 67 68 len = IDPROM_CKSUM_SIZE; 69 x = 0; /* xor of data */ 70 do x ^= *p++; 71 while (--len > 0); 72 return (x); 73} 74 75/* Copy the ethernet address into the passed space. */ 76void 77idprom_etheraddr(u_char *eaddrp) 78{ 79 80 idprom_init(); 81 memcpy(eaddrp, identity_prom.idp_etheraddr, 6); 82} 83 84/* Fetch a copy of the idprom. */ 85void 86idprom_init(void) 87{ 88 89 if (identity_prom.idp_format == 1) 90 return; 91 92 /* Copy the IDPROM contents and do the checksum. */ 93 if (_is3x) 94 idprom_init3x(); 95 else if (_is2) 96 idprom_init2(); 97 else 98 idprom_init3(); 99 100 if (identity_prom.idp_format != 1) 101 panic("idprom: bad version"); 102 cpu_machine_id = identity_prom.idp_machtype; 103} 104 105/* 106 * Sun2 version: 107 * Just copy it from control space. 108 */ 109void 110idprom_init2(void) 111{ 112 113 /* Copy the IDPROM contents and do the checksum. */ 114 sun2_getidprom((u_char *) &identity_prom); 115 if (idprom_cksum((u_char *) &identity_prom)) 116 printf("idprom: bad checksum\n"); 117} 118 119/* 120 * Sun3 version: 121 * Just copy it from control space. 122 */ 123void 124idprom_init3(void) 125{ 126 127 /* Copy the IDPROM contents and do the checksum. */ 128 sun3_getidprom((u_char *) &identity_prom); 129 if (idprom_cksum((u_char *) &identity_prom)) 130 printf("idprom: bad checksum\n"); 131} 132 133/* 134 * Sun3X version: 135 * Rather than do all the map-in/probe work to find the idprom, 136 * we can cheat! We _know_ the monitor already made a copy of 137 * the IDPROM in its data page. All we have to do is find it. 138 * 139 * Yeah, this is sorta gross... Only used on old PROMs that 140 * do not have a sif_macaddr function (rev < 3.0). The area 141 * to search was determined from some "insider" info. about 142 * the layout of the PROM data area. 143 */ 144void 145idprom_init3x(void) 146{ 147 u_char *p; 148 149 printf("idprom: Sun3X search for soft copy...\n"); 150 151 for (p = (u_char *)(SUN3X_MONDATA + 0x0400); 152 p < (u_char *)(SUN3X_MONDATA + 0x1c00); p++) 153 { 154 /* first check for some constants */ 155 if (p[0] != 0x01) /* format */ 156 continue; 157 if (p[2] != 0x08) /* ether[0] */ 158 continue; 159 if (p[3] != 0x00) /* ether[1] */ 160 continue; 161 if (p[4] != 0x20) /* ether[2] */ 162 continue; 163 if ((p[1] & 0xfc) != IDM_ARCH_SUN3X) 164 continue; 165 /* Looks plausible. Try the checksum. */ 166 if (idprom_cksum(p) == 0) 167 goto found; 168 } 169 panic("idprom: not found in monitor data"); 170 171found: 172 printf("idprom: copy found at 0x%x\n", (int)p); 173 memcpy(&identity_prom, p, sizeof(struct idprom)); 174} 175