mca.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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-2006 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 <linux/mutex.h>
  13. #include <asm/mca.h>
  14. #include <asm/sal.h>
  15. #include <asm/sn/sn_sal.h>
  16. /*
  17. * Interval for calling SAL to poll for errors that do NOT cause error
  18. * interrupts. SAL will raise a CPEI if any errors are present that
  19. * need to be logged.
  20. */
  21. #define CPEI_INTERVAL (5*HZ)
  22. struct timer_list sn_cpei_timer;
  23. void sn_init_cpei_timer(void);
  24. /* Printing oemdata from mca uses data that is not passed through SAL, it is
  25. * global. Only one user at a time.
  26. */
  27. static DEFINE_MUTEX(sn_oemdata_mutex);
  28. static u8 **sn_oemdata;
  29. static u64 *sn_oemdata_size, sn_oemdata_bufsize;
  30. /*
  31. * print_hook
  32. *
  33. * This function is the callback routine that SAL calls to log error
  34. * info for platform errors. buf is appended to sn_oemdata, resizing as
  35. * required.
  36. * Note: this is a SAL to OS callback, running under the same rules as the SAL
  37. * code. SAL calls are run with preempt disabled so this routine must not
  38. * sleep. vmalloc can sleep so print_hook cannot resize the output buffer
  39. * itself, instead it must set the required size and return to let the caller
  40. * resize the buffer then redrive the SAL call.
  41. */
  42. static int print_hook(const char *fmt, ...)
  43. {
  44. char buf[400];
  45. int len;
  46. va_list args;
  47. va_start(args, fmt);
  48. vsnprintf(buf, sizeof(buf), fmt, args);
  49. va_end(args);
  50. len = strlen(buf);
  51. if (*sn_oemdata_size + len <= sn_oemdata_bufsize)
  52. memcpy(*sn_oemdata + *sn_oemdata_size, buf, len);
  53. *sn_oemdata_size += len;
  54. return 0;
  55. }
  56. static void sn_cpei_handler(int irq, void *devid, struct pt_regs *regs)
  57. {
  58. /*
  59. * this function's sole purpose is to call SAL when we receive
  60. * a CE interrupt from SHUB or when the timer routine decides
  61. * we need to call SAL to check for CEs.
  62. */
  63. /* CALL SAL_LOG_CE */
  64. ia64_sn_plat_cpei_handler();
  65. }
  66. static void sn_cpei_timer_handler(unsigned long dummy)
  67. {
  68. sn_cpei_handler(-1, NULL, NULL);
  69. mod_timer(&sn_cpei_timer, jiffies + CPEI_INTERVAL);
  70. }
  71. void sn_init_cpei_timer(void)
  72. {
  73. init_timer(&sn_cpei_timer);
  74. sn_cpei_timer.expires = jiffies + CPEI_INTERVAL;
  75. sn_cpei_timer.function = sn_cpei_timer_handler;
  76. add_timer(&sn_cpei_timer);
  77. }
  78. static int
  79. sn_platform_plat_specific_err_print(const u8 * sect_header, u8 ** oemdata,
  80. u64 * oemdata_size)
  81. {
  82. mutex_lock(&sn_oemdata_mutex);
  83. sn_oemdata = oemdata;
  84. sn_oemdata_size = oemdata_size;
  85. sn_oemdata_bufsize = 0;
  86. *sn_oemdata_size = PAGE_SIZE; /* first guess at how much data will be generated */
  87. while (*sn_oemdata_size > sn_oemdata_bufsize) {
  88. u8 *newbuf = vmalloc(*sn_oemdata_size);
  89. if (!newbuf) {
  90. mutex_unlock(&sn_oemdata_mutex);
  91. printk(KERN_ERR "%s: unable to extend sn_oemdata\n",
  92. __func__);
  93. return 1;
  94. }
  95. vfree(*sn_oemdata);
  96. *sn_oemdata = newbuf;
  97. sn_oemdata_bufsize = *sn_oemdata_size;
  98. *sn_oemdata_size = 0;
  99. ia64_sn_plat_specific_err_print(print_hook, (char *)sect_header);
  100. }
  101. mutex_unlock(&sn_oemdata_mutex);
  102. return 0;
  103. }
  104. /* Callback when userspace salinfo wants to decode oem data via the platform
  105. * kernel and/or prom.
  106. */
  107. int sn_salinfo_platform_oemdata(const u8 *sect_header, u8 **oemdata, u64 *oemdata_size)
  108. {
  109. efi_guid_t guid = *(efi_guid_t *)sect_header;
  110. int valid = 0;
  111. *oemdata_size = 0;
  112. vfree(*oemdata);
  113. *oemdata = NULL;
  114. if (efi_guidcmp(guid, SAL_PLAT_SPECIFIC_ERR_SECT_GUID) == 0) {
  115. sal_log_plat_specific_err_info_t *psei = (sal_log_plat_specific_err_info_t *)sect_header;
  116. valid = psei->valid.oem_data;
  117. } else if (efi_guidcmp(guid, SAL_PLAT_MEM_DEV_ERR_SECT_GUID) == 0) {
  118. sal_log_mem_dev_err_info_t *mdei = (sal_log_mem_dev_err_info_t *)sect_header;
  119. valid = mdei->valid.oem_data;
  120. }
  121. if (valid)
  122. return sn_platform_plat_specific_err_print(sect_header, oemdata, oemdata_size);
  123. else
  124. return 0;
  125. }
  126. static int __init sn_salinfo_init(void)
  127. {
  128. if (ia64_platform_is("sn2"))
  129. salinfo_platform_oemdata = &sn_salinfo_platform_oemdata;
  130. return 0;
  131. }
  132. device_initcall(sn_salinfo_init);