idprom.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * idprom.c: Routines to load the idprom into kernel addresses and
  4. * interpret the data contained within.
  5. *
  6. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/types.h>
  10. #include <linux/init.h>
  11. #include <linux/export.h>
  12. #include <linux/etherdevice.h>
  13. #include <asm/oplib.h>
  14. #include <asm/idprom.h>
  15. struct idprom *idprom;
  16. EXPORT_SYMBOL(idprom);
  17. static struct idprom idprom_buffer;
  18. #ifdef CONFIG_SPARC32
  19. #include <asm/machines.h> /* Fun with Sun released architectures. */
  20. /* Here is the master table of Sun machines which use some implementation
  21. * of the Sparc CPU and have a meaningful IDPROM machtype value that we
  22. * know about. See asm-sparc/machines.h for empirical constants.
  23. */
  24. static struct Sun_Machine_Models Sun_Machines[] = {
  25. /* First, Leon */
  26. { .name = "Leon3 System-on-a-Chip", .id_machtype = (M_LEON | M_LEON3_SOC) },
  27. /* Finally, early Sun4m's */
  28. { .name = "Sun4m SparcSystem600", .id_machtype = (SM_SUN4M | SM_4M_SS60) },
  29. { .name = "Sun4m SparcStation10/20", .id_machtype = (SM_SUN4M | SM_4M_SS50) },
  30. { .name = "Sun4m SparcStation5", .id_machtype = (SM_SUN4M | SM_4M_SS40) },
  31. /* One entry for the OBP arch's which are sun4d, sun4e, and newer sun4m's */
  32. { .name = "Sun4M OBP based system", .id_machtype = (SM_SUN4M_OBP | 0x0) } };
  33. static void __init display_system_type(unsigned char machtype)
  34. {
  35. char sysname[128];
  36. register int i;
  37. for (i = 0; i < ARRAY_SIZE(Sun_Machines); i++) {
  38. if (Sun_Machines[i].id_machtype == machtype) {
  39. if (machtype != (SM_SUN4M_OBP | 0x00) ||
  40. prom_getproperty(prom_root_node, "banner-name",
  41. sysname, sizeof(sysname)) <= 0)
  42. printk(KERN_WARNING "TYPE: %s\n",
  43. Sun_Machines[i].name);
  44. else
  45. printk(KERN_WARNING "TYPE: %s\n", sysname);
  46. return;
  47. }
  48. }
  49. prom_printf("IDPROM: Warning, bogus id_machtype value, 0x%x\n", machtype);
  50. }
  51. #else
  52. static void __init display_system_type(unsigned char machtype)
  53. {
  54. }
  55. #endif
  56. unsigned char *arch_get_platform_mac_address(void)
  57. {
  58. return idprom->id_ethaddr;
  59. }
  60. /* Calculate the IDPROM checksum (xor of the data bytes). */
  61. static unsigned char __init calc_idprom_cksum(struct idprom *idprom)
  62. {
  63. unsigned char cksum, i, *ptr = (unsigned char *)idprom;
  64. for (i = cksum = 0; i <= 0x0E; i++)
  65. cksum ^= *ptr++;
  66. return cksum;
  67. }
  68. /* Create a local IDPROM copy, verify integrity, and display information. */
  69. void __init idprom_init(void)
  70. {
  71. prom_get_idprom((char *) &idprom_buffer, sizeof(idprom_buffer));
  72. idprom = &idprom_buffer;
  73. if (idprom->id_format != 0x01)
  74. prom_printf("IDPROM: Warning, unknown format type!\n");
  75. if (idprom->id_cksum != calc_idprom_cksum(idprom))
  76. prom_printf("IDPROM: Warning, checksum failure (nvram=%x, calc=%x)!\n",
  77. idprom->id_cksum, calc_idprom_cksum(idprom));
  78. display_system_type(idprom->id_machtype);
  79. printk(KERN_WARNING "Ethernet address: %pM\n", idprom->id_ethaddr);
  80. }