mca.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/timer.h>
  11. #include <linux/vmalloc.h>
  12. #include <asm/mca.h>
  13. #include <asm/sal.h>
  14. #include <asm/sn/sn_sal.h>
  15. /*
  16. * Interval for calling SAL to poll for errors that do NOT cause error
  17. * interrupts. SAL will raise a CPEI if any errors are present that
  18. * need to be logged.
  19. */
  20. #define CPEI_INTERVAL (5*HZ)
  21. struct timer_list sn_cpei_timer;
  22. void sn_init_cpei_timer(void);
  23. /* Printing oemdata from mca uses data that is not passed through SAL, it is
  24. * global. Only one user at a time.
  25. */
  26. static DECLARE_MUTEX(sn_oemdata_mutex);
  27. static u8 **sn_oemdata;
  28. static u64 *sn_oemdata_size, sn_oemdata_bufsize;
  29. /*
  30. * print_hook
  31. *
  32. * This function is the callback routine that SAL calls to log error
  33. * info for platform errors. buf is appended to sn_oemdata, resizing as
  34. * required.
  35. */
  36. static int print_hook(const char *fmt, ...)
  37. {
  38. char buf[400];
  39. int len;
  40. va_list args;
  41. va_start(args, fmt);
  42. vsnprintf(buf, sizeof(buf), fmt, args);
  43. va_end(args);
  44. len = strlen(buf);
  45. while (*sn_oemdata_size + len + 1 > sn_oemdata_bufsize) {
  46. u8 *newbuf = vmalloc(sn_oemdata_bufsize += 1000);
  47. if (!newbuf) {
  48. printk(KERN_ERR "%s: unable to extend sn_oemdata\n",
  49. __FUNCTION__);
  50. return 0;
  51. }
  52. memcpy(newbuf, *sn_oemdata, *sn_oemdata_size);
  53. vfree(*sn_oemdata);
  54. *sn_oemdata = newbuf;
  55. }
  56. memcpy(*sn_oemdata + *sn_oemdata_size, buf, len + 1);
  57. *sn_oemdata_size += len;
  58. return 0;
  59. }
  60. static void sn_cpei_handler(int irq, void *devid, struct pt_regs *regs)
  61. {
  62. /*
  63. * this function's sole purpose is to call SAL when we receive
  64. * a CE interrupt from SHUB or when the timer routine decides
  65. * we need to call SAL to check for CEs.
  66. */
  67. /* CALL SAL_LOG_CE */
  68. ia64_sn_plat_cpei_handler();
  69. }
  70. static void sn_cpei_timer_handler(unsigned long dummy)
  71. {
  72. sn_cpei_handler(-1, NULL, NULL);
  73. mod_timer(&sn_cpei_timer, jiffies + CPEI_INTERVAL);
  74. }
  75. void sn_init_cpei_timer(void)
  76. {
  77. init_timer(&sn_cpei_timer);
  78. sn_cpei_timer.expires = jiffies + CPEI_INTERVAL;
  79. sn_cpei_timer.function = sn_cpei_timer_handler;
  80. add_timer(&sn_cpei_timer);
  81. }
  82. static int
  83. sn_platform_plat_specific_err_print(const u8 * sect_header, u8 ** oemdata,
  84. u64 * oemdata_size)
  85. {
  86. down(&sn_oemdata_mutex);
  87. sn_oemdata = oemdata;
  88. sn_oemdata_size = oemdata_size;
  89. sn_oemdata_bufsize = 0;
  90. ia64_sn_plat_specific_err_print(print_hook, (char *)sect_header);
  91. up(&sn_oemdata_mutex);
  92. return 0;
  93. }
  94. /* Callback when userspace salinfo wants to decode oem data via the platform
  95. * kernel and/or prom.
  96. */
  97. int sn_salinfo_platform_oemdata(const u8 *sect_header, u8 **oemdata, u64 *oemdata_size)
  98. {
  99. efi_guid_t guid = *(efi_guid_t *)sect_header;
  100. int valid = 0;
  101. *oemdata_size = 0;
  102. vfree(*oemdata);
  103. *oemdata = NULL;
  104. if (efi_guidcmp(guid, SAL_PLAT_SPECIFIC_ERR_SECT_GUID) == 0) {
  105. sal_log_plat_specific_err_info_t *psei = (sal_log_plat_specific_err_info_t *)sect_header;
  106. valid = psei->valid.oem_data;
  107. } else if (efi_guidcmp(guid, SAL_PLAT_MEM_DEV_ERR_SECT_GUID) == 0) {
  108. sal_log_mem_dev_err_info_t *mdei = (sal_log_mem_dev_err_info_t *)sect_header;
  109. valid = mdei->valid.oem_data;
  110. }
  111. if (valid)
  112. return sn_platform_plat_specific_err_print(sect_header, oemdata, oemdata_size);
  113. else
  114. return 0;
  115. }
  116. static int __init sn_salinfo_init(void)
  117. {
  118. salinfo_platform_oemdata = &sn_salinfo_platform_oemdata;
  119. return 0;
  120. }
  121. module_init(sn_salinfo_init)