Home | History | Annotate | Line # | Download | only in sun3x
idprom.c revision 1.14.44.1
      1  1.14.44.1      yamt /*	$NetBSD: idprom.c,v 1.14.44.1 2008/05/16 02:23:21 yamt Exp $	*/
      2        1.1       gwr 
      3        1.1       gwr /*-
      4        1.1       gwr  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5        1.1       gwr  * All rights reserved.
      6        1.1       gwr  *
      7        1.1       gwr  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1       gwr  * by Adam Glass and Gordon W. Ross.
      9        1.1       gwr  *
     10        1.1       gwr  * Redistribution and use in source and binary forms, with or without
     11        1.1       gwr  * modification, are permitted provided that the following conditions
     12        1.1       gwr  * are met:
     13        1.1       gwr  * 1. Redistributions of source code must retain the above copyright
     14        1.1       gwr  *    notice, this list of conditions and the following disclaimer.
     15        1.1       gwr  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1       gwr  *    notice, this list of conditions and the following disclaimer in the
     17        1.1       gwr  *    documentation and/or other materials provided with the distribution.
     18        1.1       gwr  *
     19        1.1       gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1       gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1       gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1       gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1       gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1       gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1       gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1       gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1       gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1       gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1       gwr  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1       gwr  */
     31        1.1       gwr 
     32        1.1       gwr /*
     33        1.1       gwr  * Machine ID PROM - system type and serial number
     34        1.1       gwr  */
     35       1.10     lukem 
     36       1.10     lukem #include <sys/cdefs.h>
     37  1.14.44.1      yamt __KERNEL_RCSID(0, "$NetBSD: idprom.c,v 1.14.44.1 2008/05/16 02:23:21 yamt Exp $");
     38        1.1       gwr 
     39        1.1       gwr #include <sys/param.h>
     40        1.1       gwr #include <sys/systm.h>
     41        1.1       gwr #include <sys/device.h>
     42        1.1       gwr #include <sys/kernel.h>
     43        1.1       gwr 
     44       1.13   tsutsui #include <uvm/uvm_extern.h>
     45       1.13   tsutsui 
     46        1.1       gwr #include <machine/autoconf.h>
     47        1.1       gwr #include <machine/idprom.h>
     48        1.6       gwr 
     49        1.6       gwr #include <sun3/sun3/machdep.h>
     50        1.7       gwr #ifdef _SUN3_
     51        1.7       gwr #include <sun3/sun3/control.h>
     52        1.7       gwr #elif _SUN3X_
     53        1.6       gwr #include <sun3/sun3x/obio.h>
     54        1.7       gwr #endif
     55        1.1       gwr 
     56        1.1       gwr /*
     57        1.1       gwr  * This structure is what this driver is all about.
     58        1.1       gwr  * It is copied from the device early in startup.
     59        1.1       gwr  */
     60        1.1       gwr struct idprom identity_prom;
     61        1.3       gwr 
     62       1.11       chs static int idprom_cksum(u_char *);
     63       1.11       chs static void idprom_get(u_char *);
     64       1.11       chs static int idprom_hostid(void);
     65        1.1       gwr 
     66        1.1       gwr /*
     67        1.7       gwr  * Copy the IDPROM contents,
     68        1.7       gwr  * verify the checksum,
     69        1.7       gwr  * set the hostid...
     70        1.1       gwr  */
     71       1.11       chs void
     72       1.11       chs idprom_init(void)
     73        1.1       gwr {
     74        1.1       gwr 
     75        1.7       gwr 	idprom_get((u_char *)&identity_prom);
     76        1.7       gwr 	if (idprom_cksum((u_char *) &identity_prom))
     77        1.5       gwr 		printf("idprom: bad checksum\n");
     78        1.5       gwr 	if (identity_prom.idp_format < 1)
     79        1.5       gwr 		printf("idprom: bad version\n");
     80        1.5       gwr 
     81        1.6       gwr 	cpu_machine_id = identity_prom.idp_machtype;
     82        1.5       gwr 	hostid = idprom_hostid();
     83        1.5       gwr }
     84        1.5       gwr 
     85        1.5       gwr static int
     86       1.11       chs idprom_cksum(u_char *p)
     87        1.7       gwr {
     88        1.7       gwr 	int len, x;
     89        1.7       gwr 
     90        1.7       gwr 	len = IDPROM_CKSUM_SIZE;
     91        1.7       gwr 	x = 0;	/* xor of data */
     92        1.7       gwr 	do x ^= *p++;
     93        1.7       gwr 	while (--len > 0);
     94        1.7       gwr 	return (x);
     95        1.7       gwr }
     96        1.7       gwr 
     97       1.11       chs static int
     98       1.11       chs idprom_hostid(void)
     99        1.5       gwr {
    100        1.5       gwr 	struct idprom *idp;
    101        1.5       gwr 	union {
    102        1.5       gwr 		long l;
    103        1.5       gwr 		char c[4];
    104        1.5       gwr 	} hid;
    105        1.1       gwr 
    106        1.1       gwr 	/*
    107        1.1       gwr 	 * Construct the hostid from the idprom contents.
    108        1.1       gwr 	 * This appears to be the way SunOS does it.
    109        1.1       gwr 	 */
    110        1.5       gwr 	idp = &identity_prom;
    111        1.1       gwr 	hid.c[0] = idp->idp_machtype;
    112        1.1       gwr 	hid.c[1] = idp->idp_serialnum[0];
    113        1.1       gwr 	hid.c[2] = idp->idp_serialnum[1];
    114        1.1       gwr 	hid.c[3] = idp->idp_serialnum[2];
    115        1.5       gwr 	return (hid.l);
    116        1.3       gwr }
    117        1.3       gwr 
    118        1.3       gwr void
    119       1.11       chs idprom_etheraddr(u_char *eaddrp)
    120        1.1       gwr {
    121        1.1       gwr 
    122        1.9   tsutsui 	memcpy(eaddrp, identity_prom.idp_etheraddr, 6);
    123        1.1       gwr }
    124        1.7       gwr 
    125        1.7       gwr /*
    126        1.7       gwr  * Machine specific stuff follows.
    127        1.7       gwr  */
    128        1.7       gwr 
    129        1.7       gwr #ifdef _SUN3_
    130        1.7       gwr #error "not yet merged"
    131        1.7       gwr #endif /* SUN3 */
    132        1.7       gwr #ifdef _SUN3X_
    133        1.7       gwr /*
    134        1.7       gwr  * On the Sun3X, this is called early during startup,
    135        1.7       gwr  * but after trap table setup so peek_byte() works.
    136        1.7       gwr  * Called by machdep.c:identifycpu()
    137        1.7       gwr  */
    138        1.7       gwr static void
    139       1.11       chs idprom_get(u_char *dst)
    140        1.7       gwr {
    141        1.7       gwr 	u_char *src;
    142       1.13   tsutsui 	vaddr_t va;
    143        1.8       gwr 	int len;
    144        1.7       gwr 
    145        1.7       gwr 	/* First, probe for a separate IDPROM (3/470). */
    146       1.13   tsutsui 	find_prom_map(OBIO_IDPROM1, PMAP_OBIO, IDPROM_SIZE, &va);
    147       1.14  christos 	if (peek_byte((void *)va) == -1) {
    148        1.7       gwr 		/* IDPROM is in the EEPROM */
    149       1.13   tsutsui 		find_prom_map(OBIO_IDPROM2, PMAP_OBIO, IDPROM_SIZE, &va);
    150        1.7       gwr 	}
    151        1.7       gwr 
    152        1.7       gwr 	/* Copy the IDPROM contents and do the checksum. */
    153       1.13   tsutsui 	src = (void *)va;
    154        1.7       gwr 	len = IDPROM_SIZE;
    155        1.7       gwr 	do {
    156        1.7       gwr 		*dst++ = *src++;
    157        1.7       gwr 	} while (--len > 0);
    158        1.7       gwr }
    159        1.7       gwr 
    160        1.7       gwr #endif /* SUN3X */
    161