ari-tegra186.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
  4. */
  5. #include <linux/arm-smccc.h>
  6. #include <linux/kernel.h>
  7. #include <linux/of.h>
  8. #include <linux/panic_notifier.h>
  9. #define SMC_SIP_INVOKE_MCE 0xc2ffff00
  10. #define MCE_SMC_READ_MCA 12
  11. #define MCA_ARI_CMD_RD_SERR 1
  12. #define MCA_ARI_RW_SUBIDX_STAT 1
  13. #define SERR_STATUS_VAL BIT_ULL(63)
  14. #define MCA_ARI_RW_SUBIDX_ADDR 2
  15. #define MCA_ARI_RW_SUBIDX_MSC1 3
  16. #define MCA_ARI_RW_SUBIDX_MSC2 4
  17. static const char * const bank_names[] = {
  18. "SYS:DPMU", "ROC:IOB", "ROC:MCB", "ROC:CCE", "ROC:CQX", "ROC:CTU",
  19. };
  20. static void read_uncore_mca(u8 cmd, u8 idx, u8 subidx, u8 inst, u64 *data)
  21. {
  22. struct arm_smccc_res res;
  23. arm_smccc_smc(SMC_SIP_INVOKE_MCE | MCE_SMC_READ_MCA,
  24. ((u64)inst << 24) | ((u64)idx << 16) |
  25. ((u64)subidx << 8) | ((u64)cmd << 0),
  26. 0, 0, 0, 0, 0, 0, &res);
  27. *data = res.a2;
  28. }
  29. static int tegra186_ari_panic_handler(struct notifier_block *nb,
  30. unsigned long code, void *unused)
  31. {
  32. u64 status;
  33. int i;
  34. for (i = 0; i < ARRAY_SIZE(bank_names); i++) {
  35. read_uncore_mca(MCA_ARI_CMD_RD_SERR, i, MCA_ARI_RW_SUBIDX_STAT,
  36. 0, &status);
  37. if (status & SERR_STATUS_VAL) {
  38. u64 addr, misc1, misc2;
  39. read_uncore_mca(MCA_ARI_CMD_RD_SERR, i,
  40. MCA_ARI_RW_SUBIDX_ADDR, 0, &addr);
  41. read_uncore_mca(MCA_ARI_CMD_RD_SERR, i,
  42. MCA_ARI_RW_SUBIDX_MSC1, 0, &misc1);
  43. read_uncore_mca(MCA_ARI_CMD_RD_SERR, i,
  44. MCA_ARI_RW_SUBIDX_MSC2, 0, &misc2);
  45. pr_crit("Machine Check Error in %s\n"
  46. " status=0x%llx addr=0x%llx\n"
  47. " msc1=0x%llx msc2=0x%llx\n",
  48. bank_names[i], status, addr, misc1, misc2);
  49. }
  50. }
  51. return NOTIFY_DONE;
  52. }
  53. static struct notifier_block tegra186_ari_panic_nb = {
  54. .notifier_call = tegra186_ari_panic_handler,
  55. };
  56. static int __init tegra186_ari_init(void)
  57. {
  58. if (of_machine_is_compatible("nvidia,tegra186"))
  59. atomic_notifier_chain_register(&panic_notifier_list, &tegra186_ari_panic_nb);
  60. return 0;
  61. }
  62. early_initcall(tegra186_ari_init);