162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * idprom.c: Routines to load the idprom into kernel addresses and
462306a36Sopenharmony_ci *           interpret the data contained within.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
762306a36Sopenharmony_ci * Sun3/3x models added by David Monro (davidm@psrg.cs.usyd.edu.au)
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/module.h>
1162306a36Sopenharmony_ci#include <linux/kernel.h>
1262306a36Sopenharmony_ci#include <linux/types.h>
1362306a36Sopenharmony_ci#include <linux/init.h>
1462306a36Sopenharmony_ci#include <linux/string.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include <asm/oplib.h>
1762306a36Sopenharmony_ci#include <asm/idprom.h>
1862306a36Sopenharmony_ci#include <asm/machines.h>  /* Fun with Sun released architectures. */
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cistruct idprom *idprom;
2162306a36Sopenharmony_ciEXPORT_SYMBOL(idprom);
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_cistatic struct idprom idprom_buffer;
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/* Here is the master table of Sun machines which use some implementation
2662306a36Sopenharmony_ci * of the Sparc CPU and have a meaningful IDPROM machtype value that we
2762306a36Sopenharmony_ci * know about.  See asm-sparc/machines.h for empirical constants.
2862306a36Sopenharmony_ci */
2962306a36Sopenharmony_cistatic struct Sun_Machine_Models Sun_Machines[NUM_SUN_MACHINES] = {
3062306a36Sopenharmony_ci/* First, Sun3's */
3162306a36Sopenharmony_ci    { .name = "Sun 3/160 Series",	.id_machtype = (SM_SUN3 | SM_3_160) },
3262306a36Sopenharmony_ci    { .name = "Sun 3/50",		.id_machtype = (SM_SUN3 | SM_3_50) },
3362306a36Sopenharmony_ci    { .name = "Sun 3/260 Series",	.id_machtype = (SM_SUN3 | SM_3_260) },
3462306a36Sopenharmony_ci    { .name = "Sun 3/110 Series",	.id_machtype = (SM_SUN3 | SM_3_110) },
3562306a36Sopenharmony_ci    { .name = "Sun 3/60",		.id_machtype = (SM_SUN3 | SM_3_60) },
3662306a36Sopenharmony_ci    { .name = "Sun 3/E",		.id_machtype = (SM_SUN3 | SM_3_E) },
3762306a36Sopenharmony_ci/* Now, Sun3x's */
3862306a36Sopenharmony_ci    { .name = "Sun 3/460 Series",	.id_machtype = (SM_SUN3X | SM_3_460) },
3962306a36Sopenharmony_ci    { .name = "Sun 3/80",		.id_machtype = (SM_SUN3X | SM_3_80) },
4062306a36Sopenharmony_ci/* Then, Sun4's */
4162306a36Sopenharmony_ci// { .name = "Sun 4/100 Series",	.id_machtype = (SM_SUN4 | SM_4_110) },
4262306a36Sopenharmony_ci// { .name = "Sun 4/200 Series",	.id_machtype = (SM_SUN4 | SM_4_260) },
4362306a36Sopenharmony_ci// { .name = "Sun 4/300 Series",	.id_machtype = (SM_SUN4 | SM_4_330) },
4462306a36Sopenharmony_ci// { .name = "Sun 4/400 Series",	.id_machtype = (SM_SUN4 | SM_4_470) },
4562306a36Sopenharmony_ci/* And now, Sun4c's */
4662306a36Sopenharmony_ci// { .name = "Sun4c SparcStation 1",	.id_machtype = (SM_SUN4C | SM_4C_SS1) },
4762306a36Sopenharmony_ci// { .name = "Sun4c SparcStation IPC",	.id_machtype = (SM_SUN4C | SM_4C_IPC) },
4862306a36Sopenharmony_ci// { .name = "Sun4c SparcStation 1+",	.id_machtype = (SM_SUN4C | SM_4C_SS1PLUS) },
4962306a36Sopenharmony_ci// { .name = "Sun4c SparcStation SLC",	.id_machtype = (SM_SUN4C | SM_4C_SLC) },
5062306a36Sopenharmony_ci// { .name = "Sun4c SparcStation 2",	.id_machtype = (SM_SUN4C | SM_4C_SS2) },
5162306a36Sopenharmony_ci// { .name = "Sun4c SparcStation ELC",	.id_machtype = (SM_SUN4C | SM_4C_ELC) },
5262306a36Sopenharmony_ci// { .name = "Sun4c SparcStation IPX",	.id_machtype = (SM_SUN4C | SM_4C_IPX) },
5362306a36Sopenharmony_ci/* Finally, early Sun4m's */
5462306a36Sopenharmony_ci// { .name = "Sun4m SparcSystem600",	.id_machtype = (SM_SUN4M | SM_4M_SS60) },
5562306a36Sopenharmony_ci// { .name = "Sun4m SparcStation10/20",	.id_machtype = (SM_SUN4M | SM_4M_SS50) },
5662306a36Sopenharmony_ci// { .name = "Sun4m SparcStation5",	.id_machtype = (SM_SUN4M | SM_4M_SS40) },
5762306a36Sopenharmony_ci/* One entry for the OBP arch's which are sun4d, sun4e, and newer sun4m's */
5862306a36Sopenharmony_ci// { .name = "Sun4M OBP based system",	.id_machtype = (SM_SUN4M_OBP | 0x0) }
5962306a36Sopenharmony_ci};
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistatic void __init display_system_type(unsigned char machtype)
6262306a36Sopenharmony_ci{
6362306a36Sopenharmony_ci	register int i;
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci	for (i = 0; i < NUM_SUN_MACHINES; i++) {
6662306a36Sopenharmony_ci		if(Sun_Machines[i].id_machtype == machtype) {
6762306a36Sopenharmony_ci			if (machtype != (SM_SUN4M_OBP | 0x00))
6862306a36Sopenharmony_ci				pr_info("TYPE: %s\n", Sun_Machines[i].name);
6962306a36Sopenharmony_ci			else {
7062306a36Sopenharmony_ci#if 0
7162306a36Sopenharmony_ci				char sysname[128];
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci				prom_getproperty(prom_root_node, "banner-name",
7462306a36Sopenharmony_ci						 sysname, sizeof(sysname));
7562306a36Sopenharmony_ci				pr_info("TYPE: %s\n", sysname);
7662306a36Sopenharmony_ci#endif
7762306a36Sopenharmony_ci			}
7862306a36Sopenharmony_ci			return;
7962306a36Sopenharmony_ci		}
8062306a36Sopenharmony_ci	}
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci	prom_printf("IDPROM: Bogus id_machtype value, 0x%x\n", machtype);
8362306a36Sopenharmony_ci	prom_halt();
8462306a36Sopenharmony_ci}
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_civoid sun3_get_model(unsigned char* model)
8762306a36Sopenharmony_ci{
8862306a36Sopenharmony_ci	register int i;
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci	for (i = 0; i < NUM_SUN_MACHINES; i++) {
9162306a36Sopenharmony_ci		if(Sun_Machines[i].id_machtype == idprom->id_machtype) {
9262306a36Sopenharmony_ci		        strcpy(model, Sun_Machines[i].name);
9362306a36Sopenharmony_ci			return;
9462306a36Sopenharmony_ci		}
9562306a36Sopenharmony_ci	}
9662306a36Sopenharmony_ci}
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci/* Calculate the IDPROM checksum (xor of the data bytes). */
10162306a36Sopenharmony_cistatic unsigned char __init calc_idprom_cksum(struct idprom *idprom)
10262306a36Sopenharmony_ci{
10362306a36Sopenharmony_ci	unsigned char cksum, i, *ptr = (unsigned char *)idprom;
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci	for (i = cksum = 0; i <= 0x0E; i++)
10662306a36Sopenharmony_ci		cksum ^= *ptr++;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci	return cksum;
10962306a36Sopenharmony_ci}
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci/* Create a local IDPROM copy, verify integrity, and display information. */
11262306a36Sopenharmony_civoid __init idprom_init(void)
11362306a36Sopenharmony_ci{
11462306a36Sopenharmony_ci	prom_get_idprom((char *) &idprom_buffer, sizeof(idprom_buffer));
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci	idprom = &idprom_buffer;
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci	if (idprom->id_format != 0x01)  {
11962306a36Sopenharmony_ci		prom_printf("IDPROM: Unknown format type!\n");
12062306a36Sopenharmony_ci		prom_halt();
12162306a36Sopenharmony_ci	}
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci	if (idprom->id_cksum != calc_idprom_cksum(idprom)) {
12462306a36Sopenharmony_ci		prom_printf("IDPROM: Checksum failure (nvram=%x, calc=%x)!\n",
12562306a36Sopenharmony_ci			    idprom->id_cksum, calc_idprom_cksum(idprom));
12662306a36Sopenharmony_ci		prom_halt();
12762306a36Sopenharmony_ci	}
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	display_system_type(idprom->id_machtype);
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci	pr_info("Ethernet address: %pM\n", idprom->id_ethaddr);
13262306a36Sopenharmony_ci}
133