blob: c8fe5dbdad55c5c0cf84e8f224fddfea528cd960 [file] [log] [blame]
Andrew Lewyckyf3a39812015-05-10 12:15:46 +03001/*
2 * Copyright 2014 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
23#ifndef KFD_EVENTS_H_INCLUDED
24#define KFD_EVENTS_H_INCLUDED
25
26#include <linux/kernel.h>
27#include <linux/hashtable.h>
28#include <linux/types.h>
29#include <linux/list.h>
Felix Kuehling74e40712017-10-27 19:35:25 -040030#include <linux/wait.h>
Andrew Lewyckyf3a39812015-05-10 12:15:46 +030031#include "kfd_priv.h"
Alexey Skidanov59d3e8b2015-04-14 18:05:49 +030032#include <uapi/linux/kfd_ioctl.h>
Andrew Lewyckyf3a39812015-05-10 12:15:46 +030033
Felix Kuehling482f0772017-10-27 19:35:27 -040034/*
35 * IDR supports non-negative integer IDs. Small IDs are used for
36 * signal events to match their signal slot. Use the upper half of the
37 * ID space for non-signal events.
38 */
39#define KFD_FIRST_NONSIGNAL_EVENT_ID ((INT_MAX >> 1) + 1)
40#define KFD_LAST_NONSIGNAL_EVENT_ID INT_MAX
Andrew Lewyckyf3a39812015-05-10 12:15:46 +030041
42/*
43 * Written into kfd_signal_slot_t to indicate that the event is not signaled.
44 * Since the event protocol may need to write the event ID into memory, this
45 * must not be a valid event ID.
46 * For the sake of easy memset-ing, this must be a byte pattern.
47 */
48#define UNSIGNALED_EVENT_SLOT ((uint64_t)-1)
49
50struct kfd_event_waiter;
51struct signal_page;
52
53struct kfd_event {
Andrew Lewyckyf3a39812015-05-10 12:15:46 +030054 u32 event_id;
55
56 bool signaled;
57 bool auto_reset;
58
59 int type;
60
Felix Kuehling74e40712017-10-27 19:35:25 -040061 wait_queue_head_t wq; /* List of event waiters. */
Andrew Lewyckyf3a39812015-05-10 12:15:46 +030062
63 /* Only for signal events. */
Andrew Lewyckyf3a39812015-05-10 12:15:46 +030064 uint64_t __user *user_signal_address;
Alexey Skidanov59d3e8b2015-04-14 18:05:49 +030065
66 /* type specific data */
67 union {
68 struct kfd_hsa_memory_exception_data memory_exception_data;
Shaoyun Liue42051d22018-07-11 22:32:56 -040069 struct kfd_hsa_hw_exception_data hw_exception_data;
Alexey Skidanov59d3e8b2015-04-14 18:05:49 +030070 };
Andrew Lewyckyf3a39812015-05-10 12:15:46 +030071};
72
73#define KFD_EVENT_TIMEOUT_IMMEDIATE 0
74#define KFD_EVENT_TIMEOUT_INFINITE 0xFFFFFFFFu
75
76/* Matching HSA_EVENTTYPE */
77#define KFD_EVENT_TYPE_SIGNAL 0
Alexey Skidanov930c5ff2014-11-25 10:34:31 +020078#define KFD_EVENT_TYPE_HW_EXCEPTION 3
Andrew Lewyckyf3a39812015-05-10 12:15:46 +030079#define KFD_EVENT_TYPE_DEBUG 5
Alexey Skidanov59d3e8b2015-04-14 18:05:49 +030080#define KFD_EVENT_TYPE_MEMORY 8
Andrew Lewyckyf3a39812015-05-10 12:15:46 +030081
Fenghua Yuc7b6bac2020-09-15 09:30:05 -070082extern void kfd_signal_event_interrupt(u32 pasid, uint32_t partial_id,
83 uint32_t valid_id_bits);
Andrew Lewyckyf3a39812015-05-10 12:15:46 +030084
85#endif