Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * idprom.c: Routines to load the idprom into kernel addresses and
0004  *           interpret the data contained within.
0005  *
0006  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
0007  */
0008 
0009 #include <linux/kernel.h>
0010 #include <linux/types.h>
0011 #include <linux/init.h>
0012 #include <linux/export.h>
0013 #include <linux/etherdevice.h>
0014 
0015 #include <asm/oplib.h>
0016 #include <asm/idprom.h>
0017 
0018 struct idprom *idprom;
0019 EXPORT_SYMBOL(idprom);
0020 
0021 static struct idprom idprom_buffer;
0022 
0023 #ifdef CONFIG_SPARC32
0024 #include <asm/machines.h>  /* Fun with Sun released architectures. */
0025 
0026 /* Here is the master table of Sun machines which use some implementation
0027  * of the Sparc CPU and have a meaningful IDPROM machtype value that we
0028  * know about.  See asm-sparc/machines.h for empirical constants.
0029  */
0030 static struct Sun_Machine_Models Sun_Machines[] = {
0031 /* First, Leon */
0032 { .name = "Leon3 System-on-a-Chip",  .id_machtype = (M_LEON | M_LEON3_SOC) },
0033 /* Finally, early Sun4m's */
0034 { .name = "Sun4m SparcSystem600",    .id_machtype = (SM_SUN4M | SM_4M_SS60) },
0035 { .name = "Sun4m SparcStation10/20", .id_machtype = (SM_SUN4M | SM_4M_SS50) },
0036 { .name = "Sun4m SparcStation5",     .id_machtype = (SM_SUN4M | SM_4M_SS40) },
0037 /* One entry for the OBP arch's which are sun4d, sun4e, and newer sun4m's */
0038 { .name = "Sun4M OBP based system",  .id_machtype = (SM_SUN4M_OBP | 0x0) } };
0039 
0040 static void __init display_system_type(unsigned char machtype)
0041 {
0042     char sysname[128];
0043     register int i;
0044 
0045     for (i = 0; i < ARRAY_SIZE(Sun_Machines); i++) {
0046         if (Sun_Machines[i].id_machtype == machtype) {
0047             if (machtype != (SM_SUN4M_OBP | 0x00) ||
0048                 prom_getproperty(prom_root_node, "banner-name",
0049                          sysname, sizeof(sysname)) <= 0)
0050                 printk(KERN_WARNING "TYPE: %s\n",
0051                        Sun_Machines[i].name);
0052             else
0053                 printk(KERN_WARNING "TYPE: %s\n", sysname);
0054             return;
0055         }
0056     }
0057 
0058     prom_printf("IDPROM: Warning, bogus id_machtype value, 0x%x\n", machtype);
0059 }
0060 #else
0061 static void __init display_system_type(unsigned char machtype)
0062 {
0063 }
0064 #endif
0065 
0066 unsigned char *arch_get_platform_mac_address(void)
0067 {
0068     return idprom->id_ethaddr;
0069 }
0070 
0071 /* Calculate the IDPROM checksum (xor of the data bytes). */
0072 static unsigned char __init calc_idprom_cksum(struct idprom *idprom)
0073 {
0074     unsigned char cksum, i, *ptr = (unsigned char *)idprom;
0075 
0076     for (i = cksum = 0; i <= 0x0E; i++)
0077         cksum ^= *ptr++;
0078 
0079     return cksum;
0080 }
0081 
0082 /* Create a local IDPROM copy, verify integrity, and display information. */
0083 void __init idprom_init(void)
0084 {
0085     prom_get_idprom((char *) &idprom_buffer, sizeof(idprom_buffer));
0086 
0087     idprom = &idprom_buffer;
0088 
0089     if (idprom->id_format != 0x01)
0090         prom_printf("IDPROM: Warning, unknown format type!\n");
0091 
0092     if (idprom->id_cksum != calc_idprom_cksum(idprom))
0093         prom_printf("IDPROM: Warning, checksum failure (nvram=%x, calc=%x)!\n",
0094                 idprom->id_cksum, calc_idprom_cksum(idprom));
0095 
0096     display_system_type(idprom->id_machtype);
0097 
0098     printk(KERN_WARNING "Ethernet address: %pM\n", idprom->id_ethaddr);
0099 }