^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * idprom.c: Routines to load the idprom into kernel addresses and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * interpret the data contained within.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Sun3/3x models added by David Monro (davidm@psrg.cs.usyd.edu.au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/idprom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/machines.h> /* Fun with Sun released architectures. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct idprom *idprom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) EXPORT_SYMBOL(idprom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static struct idprom idprom_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /* Here is the master table of Sun machines which use some implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * of the Sparc CPU and have a meaningful IDPROM machtype value that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * know about. See asm-sparc/machines.h for empirical constants.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static struct Sun_Machine_Models Sun_Machines[NUM_SUN_MACHINES] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* First, Sun3's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) { .name = "Sun 3/160 Series", .id_machtype = (SM_SUN3 | SM_3_160) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) { .name = "Sun 3/50", .id_machtype = (SM_SUN3 | SM_3_50) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) { .name = "Sun 3/260 Series", .id_machtype = (SM_SUN3 | SM_3_260) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) { .name = "Sun 3/110 Series", .id_machtype = (SM_SUN3 | SM_3_110) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) { .name = "Sun 3/60", .id_machtype = (SM_SUN3 | SM_3_60) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) { .name = "Sun 3/E", .id_machtype = (SM_SUN3 | SM_3_E) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* Now, Sun3x's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) { .name = "Sun 3/460 Series", .id_machtype = (SM_SUN3X | SM_3_460) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) { .name = "Sun 3/80", .id_machtype = (SM_SUN3X | SM_3_80) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* Then, Sun4's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) // { .name = "Sun 4/100 Series", .id_machtype = (SM_SUN4 | SM_4_110) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) // { .name = "Sun 4/200 Series", .id_machtype = (SM_SUN4 | SM_4_260) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) // { .name = "Sun 4/300 Series", .id_machtype = (SM_SUN4 | SM_4_330) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) // { .name = "Sun 4/400 Series", .id_machtype = (SM_SUN4 | SM_4_470) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* And now, Sun4c's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) // { .name = "Sun4c SparcStation 1", .id_machtype = (SM_SUN4C | SM_4C_SS1) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) // { .name = "Sun4c SparcStation IPC", .id_machtype = (SM_SUN4C | SM_4C_IPC) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) // { .name = "Sun4c SparcStation 1+", .id_machtype = (SM_SUN4C | SM_4C_SS1PLUS) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) // { .name = "Sun4c SparcStation SLC", .id_machtype = (SM_SUN4C | SM_4C_SLC) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) // { .name = "Sun4c SparcStation 2", .id_machtype = (SM_SUN4C | SM_4C_SS2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) // { .name = "Sun4c SparcStation ELC", .id_machtype = (SM_SUN4C | SM_4C_ELC) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) // { .name = "Sun4c SparcStation IPX", .id_machtype = (SM_SUN4C | SM_4C_IPX) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /* Finally, early Sun4m's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) // { .name = "Sun4m SparcSystem600", .id_machtype = (SM_SUN4M | SM_4M_SS60) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) // { .name = "Sun4m SparcStation10/20", .id_machtype = (SM_SUN4M | SM_4M_SS50) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) // { .name = "Sun4m SparcStation5", .id_machtype = (SM_SUN4M | SM_4M_SS40) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* One entry for the OBP arch's which are sun4d, sun4e, and newer sun4m's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) // { .name = "Sun4M OBP based system", .id_machtype = (SM_SUN4M_OBP | 0x0) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static void __init display_system_type(unsigned char machtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) register int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) for (i = 0; i < NUM_SUN_MACHINES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if(Sun_Machines[i].id_machtype == machtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (machtype != (SM_SUN4M_OBP | 0x00))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) pr_info("TYPE: %s\n", Sun_Machines[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) char sysname[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) prom_getproperty(prom_root_node, "banner-name",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) sysname, sizeof(sysname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) pr_info("TYPE: %s\n", sysname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) prom_printf("IDPROM: Bogus id_machtype value, 0x%x\n", machtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) void sun3_get_model(unsigned char* model)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) register int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) for (i = 0; i < NUM_SUN_MACHINES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if(Sun_Machines[i].id_machtype == idprom->id_machtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) strcpy(model, Sun_Machines[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* Calculate the IDPROM checksum (xor of the data bytes). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static unsigned char __init calc_idprom_cksum(struct idprom *idprom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned char cksum, i, *ptr = (unsigned char *)idprom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) for (i = cksum = 0; i <= 0x0E; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) cksum ^= *ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return cksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* Create a local IDPROM copy, verify integrity, and display information. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) void __init idprom_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) prom_get_idprom((char *) &idprom_buffer, sizeof(idprom_buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) idprom = &idprom_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (idprom->id_format != 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) prom_printf("IDPROM: Unknown format type!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (idprom->id_cksum != calc_idprom_cksum(idprom)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) prom_printf("IDPROM: Checksum failure (nvram=%x, calc=%x)!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) idprom->id_cksum, calc_idprom_cksum(idprom));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) display_system_type(idprom->id_machtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) pr_info("Ethernet address: %pM\n", idprom->id_ethaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }