kfd_events.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /*
  3. * Copyright 2014-2022 Advanced Micro Devices, Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef KFD_EVENTS_H_INCLUDED
  24. #define KFD_EVENTS_H_INCLUDED
  25. #include <linux/kernel.h>
  26. #include <linux/hashtable.h>
  27. #include <linux/types.h>
  28. #include <linux/list.h>
  29. #include <linux/wait.h>
  30. #include "kfd_priv.h"
  31. #include <uapi/linux/kfd_ioctl.h>
  32. /*
  33. * IDR supports non-negative integer IDs. Small IDs are used for
  34. * signal events to match their signal slot. Use the upper half of the
  35. * ID space for non-signal events.
  36. */
  37. #define KFD_FIRST_NONSIGNAL_EVENT_ID ((INT_MAX >> 1) + 1)
  38. #define KFD_LAST_NONSIGNAL_EVENT_ID INT_MAX
  39. /*
  40. * Written into kfd_signal_slot_t to indicate that the event is not signaled.
  41. * Since the event protocol may need to write the event ID into memory, this
  42. * must not be a valid event ID.
  43. * For the sake of easy memset-ing, this must be a byte pattern.
  44. */
  45. #define UNSIGNALED_EVENT_SLOT ((uint64_t)-1)
  46. struct kfd_event_waiter;
  47. struct signal_page;
  48. struct kfd_event {
  49. u32 event_id;
  50. u64 event_age;
  51. bool signaled;
  52. bool auto_reset;
  53. int type;
  54. spinlock_t lock;
  55. wait_queue_head_t wq; /* List of event waiters. */
  56. /* Only for signal events. */
  57. uint64_t __user *user_signal_address;
  58. /* type specific data */
  59. union {
  60. struct kfd_hsa_memory_exception_data memory_exception_data;
  61. struct kfd_hsa_hw_exception_data hw_exception_data;
  62. };
  63. struct rcu_head rcu; /* for asynchronous kfree_rcu */
  64. };
  65. #define KFD_EVENT_TIMEOUT_IMMEDIATE 0
  66. #define KFD_EVENT_TIMEOUT_INFINITE 0xFFFFFFFFu
  67. /* Matching HSA_EVENTTYPE */
  68. #define KFD_EVENT_TYPE_SIGNAL 0
  69. #define KFD_EVENT_TYPE_HW_EXCEPTION 3
  70. #define KFD_EVENT_TYPE_DEBUG 5
  71. #define KFD_EVENT_TYPE_MEMORY 8
  72. extern void kfd_signal_event_interrupt(u32 pasid, uint32_t partial_id,
  73. uint32_t valid_id_bits);
  74. #endif