idprom.c 2.9 KB

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