kfd_int_process_v9.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2016-2018 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #include "kfd_priv.h"
  23. #include "kfd_events.h"
  24. #include "soc15_int.h"
  25. static bool event_interrupt_isr_v9(struct kfd_dev *dev,
  26. const uint32_t *ih_ring_entry,
  27. uint32_t *patched_ihre,
  28. bool *patched_flag)
  29. {
  30. uint16_t source_id, client_id, pasid, vmid;
  31. const uint32_t *data = ih_ring_entry;
  32. /* Only handle interrupts from KFD VMIDs */
  33. vmid = SOC15_VMID_FROM_IH_ENTRY(ih_ring_entry);
  34. if (vmid < dev->vm_info.first_vmid_kfd ||
  35. vmid > dev->vm_info.last_vmid_kfd)
  36. return 0;
  37. /* If there is no valid PASID, it's likely a firmware bug */
  38. pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
  39. if (WARN_ONCE(pasid == 0, "FW bug: No PASID in KFD interrupt"))
  40. return 0;
  41. source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
  42. client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
  43. pr_debug("client id 0x%x, source id %d, pasid 0x%x. raw data:\n",
  44. client_id, source_id, pasid);
  45. pr_debug("%8X, %8X, %8X, %8X, %8X, %8X, %8X, %8X.\n",
  46. data[0], data[1], data[2], data[3],
  47. data[4], data[5], data[6], data[7]);
  48. /* Interrupt types we care about: various signals and faults.
  49. * They will be forwarded to a work queue (see below).
  50. */
  51. return source_id == SOC15_INTSRC_CP_END_OF_PIPE ||
  52. source_id == SOC15_INTSRC_SDMA_TRAP ||
  53. source_id == SOC15_INTSRC_SQ_INTERRUPT_MSG ||
  54. source_id == SOC15_INTSRC_CP_BAD_OPCODE ||
  55. client_id == SOC15_IH_CLIENTID_VMC ||
  56. client_id == SOC15_IH_CLIENTID_UTCL2;
  57. }
  58. static void event_interrupt_wq_v9(struct kfd_dev *dev,
  59. const uint32_t *ih_ring_entry)
  60. {
  61. uint16_t source_id, client_id, pasid, vmid;
  62. uint32_t context_id;
  63. source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
  64. client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
  65. pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
  66. vmid = SOC15_VMID_FROM_IH_ENTRY(ih_ring_entry);
  67. context_id = SOC15_CONTEXT_ID0_FROM_IH_ENTRY(ih_ring_entry);
  68. if (source_id == SOC15_INTSRC_CP_END_OF_PIPE)
  69. kfd_signal_event_interrupt(pasid, context_id, 32);
  70. else if (source_id == SOC15_INTSRC_SDMA_TRAP)
  71. kfd_signal_event_interrupt(pasid, context_id & 0xfffffff, 28);
  72. else if (source_id == SOC15_INTSRC_SQ_INTERRUPT_MSG)
  73. kfd_signal_event_interrupt(pasid, context_id & 0xffffff, 24);
  74. else if (source_id == SOC15_INTSRC_CP_BAD_OPCODE)
  75. kfd_signal_hw_exception_event(pasid);
  76. else if (client_id == SOC15_IH_CLIENTID_VMC ||
  77. client_id == SOC15_IH_CLIENTID_UTCL2) {
  78. struct kfd_vm_fault_info info = {0};
  79. uint16_t ring_id = SOC15_RING_ID_FROM_IH_ENTRY(ih_ring_entry);
  80. info.vmid = vmid;
  81. info.mc_id = client_id;
  82. info.page_addr = ih_ring_entry[4] |
  83. (uint64_t)(ih_ring_entry[5] & 0xf) << 32;
  84. info.prot_valid = ring_id & 0x08;
  85. info.prot_read = ring_id & 0x10;
  86. info.prot_write = ring_id & 0x20;
  87. kfd_process_vm_fault(dev->dqm, pasid);
  88. kfd_signal_vm_fault_event(dev, pasid, &info);
  89. }
  90. }
  91. const struct kfd_event_interrupt_class event_interrupt_class_v9 = {
  92. .interrupt_isr = event_interrupt_isr_v9,
  93. .interrupt_wq = event_interrupt_wq_v9,
  94. };