xref: /linux/drivers/gpu/drm/xe/xe_pagefault_types.h (revision 546b928da0427b0d6c663cbb992bd7bfa9ac7971)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2025 Intel Corporation
4  */
5 
6 #ifndef _XE_PAGEFAULT_TYPES_H_
7 #define _XE_PAGEFAULT_TYPES_H_
8 
9 #include <linux/workqueue.h>
10 
11 struct xe_device;
12 struct xe_gt;
13 struct xe_pagefault;
14 
15 /** enum xe_pagefault_access_type - Xe page fault access type */
16 enum xe_pagefault_access_type {
17 	/** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */
18 	XE_PAGEFAULT_ACCESS_TYPE_READ	= 0,
19 	/** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */
20 	XE_PAGEFAULT_ACCESS_TYPE_WRITE	= 1,
21 	/** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type */
22 	XE_PAGEFAULT_ACCESS_TYPE_ATOMIC	= 2,
23 };
24 
25 /** enum xe_pagefault_type - Xe page fault type */
26 enum xe_pagefault_type {
27 	/** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */
28 	XE_PAGEFAULT_TYPE_NOT_PRESENT			= 0,
29 	/** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Write access violation */
30 	XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION	= 1,
31 	/** @XE_PAGEFAULT_TYPE_ATOMIC_ACCESS_VIOLATION: Atomic access violation */
32 	XE_PAGEFAULT_TYPE_ATOMIC_ACCESS_VIOLATION	= 2,
33 };
34 
35 /** struct xe_pagefault_ops - Xe pagefault ops (producer) */
36 struct xe_pagefault_ops {
37 	/**
38 	 * @ack_fault: Ack fault
39 	 * @pf: Page fault
40 	 * @err: Error state of fault
41 	 *
42 	 * Page fault producer receives acknowledgment from the consumer and
43 	 * sends the result to the HW/FW interface.
44 	 */
45 	void (*ack_fault)(struct xe_pagefault *pf, int err);
46 };
47 
48 /**
49  * struct xe_pagefault - Xe page fault
50  *
51  * Generic page fault structure for communication between producer and consumer.
52  * Carefully sized to be 64 bytes. Upon a device page fault, the producer
53  * populates this structure, and the consumer copies it into the page-fault
54  * queue for deferred handling.
55  */
56 struct xe_pagefault {
57 	/**
58 	 * @gt: GT of fault
59 	 */
60 	struct xe_gt *gt;
61 	/**
62 	 * @consumer: State for the software handling the fault. Populated by
63 	 * the producer and may be modified by the consumer to communicate
64 	 * information back to the producer upon fault acknowledgment.
65 	 */
66 	struct {
67 		/** @consumer.page_addr: address of page fault */
68 		u64 page_addr;
69 		/** @consumer.asid: address space ID */
70 		u32 asid;
71 		/**
72 		 * @consumer.access_type: access type and prefetch flag packed
73 		 * into a u8.
74 		 */
75 		u8 access_type;
76 #define XE_PAGEFAULT_ACCESS_TYPE_MASK	GENMASK(1, 0)
77 #define XE_PAGEFAULT_ACCESS_PREFETCH	BIT(7)
78 		/**
79 		 * @consumer.fault_type_level: fault type and level, u8 rather
80 		 * than enum to keep size compact
81 		 */
82 		u8 fault_type_level;
83 #define XE_PAGEFAULT_TYPE_LEVEL_NACK		0xff	/* Producer indicates nack fault */
84 #define XE_PAGEFAULT_LEVEL_MASK			GENMASK(3, 0)
85 #define XE_PAGEFAULT_TYPE_MASK			GENMASK(7, 4)
86 		/** @consumer.engine_class: engine class */
87 		u8 engine_class;
88 		/** @consumer.engine_instance: engine instance */
89 		u8 engine_instance;
90 		/** @consumer.reserved: reserved bits for future expansion */
91 		u64 reserved;
92 	} consumer;
93 	/**
94 	 * @producer: State for the producer (i.e., HW/FW interface). Populated
95 	 * by the producer and should not be modified—or even inspected—by the
96 	 * consumer, except for calling operations.
97 	 */
98 	struct {
99 		/** @producer.private: private pointer */
100 		void *private;
101 		/** @producer.ops: operations */
102 		const struct xe_pagefault_ops *ops;
103 #define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW	4
104 		/**
105 		 * @producer.msg: page fault message, used by producer in fault
106 		 * acknowledgment to formulate response to HW/FW interface.
107 		 * Included in the page-fault message because the producer
108 		 * typically receives the fault in a context where memory cannot
109 		 * be allocated (e.g., atomic context or the reclaim path).
110 		 */
111 		u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW];
112 	} producer;
113 };
114 
115 /**
116  * struct xe_pagefault_queue - Xe pagefault queue (consumer)
117  *
118  * Used to capture all device page faults for deferred processing. Size this
119  * queue to absorb the device’s worst-case number of outstanding faults.
120  */
121 struct xe_pagefault_queue {
122 	/** @xe: Back-pointer to the Xe device */
123 	struct xe_device *xe;
124 	/**
125 	 * @data: Data in queue containing struct xe_pagefault, protected by
126 	 * @lock
127 	 */
128 	void *data;
129 	/** @size: Size of queue in bytes */
130 	u32 size;
131 	/** @head: Head pointer in bytes, moved by producer, protected by @lock */
132 	u32 head;
133 	/** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */
134 	u32 tail;
135 	/** @lock: protects page fault queue */
136 	spinlock_t lock;
137 	/** @worker: to process page faults */
138 	struct work_struct worker;
139 };
140 
141 #endif
142