Loading...
1/*
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>
30#include "kfd_priv.h"
31#include <uapi/linux/kfd_ioctl.h>
32
33#define KFD_EVENT_ID_NONSIGNAL_MASK 0x80000000U
34#define KFD_FIRST_NONSIGNAL_EVENT_ID KFD_EVENT_ID_NONSIGNAL_MASK
35#define KFD_LAST_NONSIGNAL_EVENT_ID UINT_MAX
36
37/*
38 * Written into kfd_signal_slot_t to indicate that the event is not signaled.
39 * Since the event protocol may need to write the event ID into memory, this
40 * must not be a valid event ID.
41 * For the sake of easy memset-ing, this must be a byte pattern.
42 */
43#define UNSIGNALED_EVENT_SLOT ((uint64_t)-1)
44
45struct kfd_event_waiter;
46struct signal_page;
47
48struct kfd_event {
49 /* All events in process, rooted at kfd_process.events. */
50 struct hlist_node events;
51
52 u32 event_id;
53
54 bool signaled;
55 bool auto_reset;
56
57 int type;
58
59 struct list_head waiters; /* List of kfd_event_waiter by waiters. */
60
61 /* Only for signal events. */
62 struct signal_page *signal_page;
63 unsigned int signal_slot_index;
64 uint64_t __user *user_signal_address;
65
66 /* type specific data */
67 union {
68 struct kfd_hsa_memory_exception_data memory_exception_data;
69 };
70};
71
72#define KFD_EVENT_TIMEOUT_IMMEDIATE 0
73#define KFD_EVENT_TIMEOUT_INFINITE 0xFFFFFFFFu
74
75/* Matching HSA_EVENTTYPE */
76#define KFD_EVENT_TYPE_SIGNAL 0
77#define KFD_EVENT_TYPE_HW_EXCEPTION 3
78#define KFD_EVENT_TYPE_DEBUG 5
79#define KFD_EVENT_TYPE_MEMORY 8
80
81extern void kfd_signal_event_interrupt(unsigned int pasid, uint32_t partial_id,
82 uint32_t valid_id_bits);
83
84#endif
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
24#ifndef KFD_EVENTS_H_INCLUDED
25#define KFD_EVENTS_H_INCLUDED
26
27#include <linux/kernel.h>
28#include <linux/hashtable.h>
29#include <linux/types.h>
30#include <linux/list.h>
31#include <linux/wait.h>
32#include "kfd_priv.h"
33#include <uapi/linux/kfd_ioctl.h>
34
35/*
36 * IDR supports non-negative integer IDs. Small IDs are used for
37 * signal events to match their signal slot. Use the upper half of the
38 * ID space for non-signal events.
39 */
40#define KFD_FIRST_NONSIGNAL_EVENT_ID ((INT_MAX >> 1) + 1)
41#define KFD_LAST_NONSIGNAL_EVENT_ID INT_MAX
42
43/*
44 * Written into kfd_signal_slot_t to indicate that the event is not signaled.
45 * Since the event protocol may need to write the event ID into memory, this
46 * must not be a valid event ID.
47 * For the sake of easy memset-ing, this must be a byte pattern.
48 */
49#define UNSIGNALED_EVENT_SLOT ((uint64_t)-1)
50
51struct kfd_event_waiter;
52struct signal_page;
53
54struct kfd_event {
55 u32 event_id;
56
57 bool signaled;
58 bool auto_reset;
59
60 int type;
61
62 spinlock_t lock;
63 wait_queue_head_t wq; /* List of event waiters. */
64
65 /* Only for signal events. */
66 uint64_t __user *user_signal_address;
67
68 /* type specific data */
69 union {
70 struct kfd_hsa_memory_exception_data memory_exception_data;
71 struct kfd_hsa_hw_exception_data hw_exception_data;
72 };
73
74 struct rcu_head rcu; /* for asynchronous kfree_rcu */
75};
76
77#define KFD_EVENT_TIMEOUT_IMMEDIATE 0
78#define KFD_EVENT_TIMEOUT_INFINITE 0xFFFFFFFFu
79
80/* Matching HSA_EVENTTYPE */
81#define KFD_EVENT_TYPE_SIGNAL 0
82#define KFD_EVENT_TYPE_HW_EXCEPTION 3
83#define KFD_EVENT_TYPE_DEBUG 5
84#define KFD_EVENT_TYPE_MEMORY 8
85
86extern void kfd_signal_event_interrupt(u32 pasid, uint32_t partial_id,
87 uint32_t valid_id_bits);
88
89#endif