Skip to content

Commit 143aa16

Browse files
committed
drm/xe: Implement xe_pagefault_handler
Enqueue (copy) the input struct xe_pagefault into a queue (i.e., into a memory buffer) and schedule a worker to service it. Signed-off-by: Matthew Brost <matthew.brost@intel.com> Reviewed-by: Francois Dugast <francois.dugast@intel.com> Tested-by: Francois Dugast <francois.dugast@intel.com> Link: https://patch.msgid.link/20251031165416.2871503-5-matthew.brost@intel.com
1 parent 79be336 commit 143aa16

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

drivers/gpu/drm/xe/xe_pagefault.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © 2025 Intel Corporation
44
*/
55

6+
#include <linux/circ_buf.h>
7+
68
#include <drm/drm_managed.h>
79

810
#include "xe_device.h"
@@ -167,6 +169,14 @@ void xe_pagefault_reset(struct xe_device *xe, struct xe_gt *gt)
167169
xe_pagefault_queue_reset(xe, gt, xe->usm.pf_queue + i);
168170
}
169171

172+
static bool xe_pagefault_queue_full(struct xe_pagefault_queue *pf_queue)
173+
{
174+
lockdep_assert_held(&pf_queue->lock);
175+
176+
return CIRC_SPACE(pf_queue->head, pf_queue->tail, pf_queue->size) <=
177+
xe_pagefault_entry_size();
178+
}
179+
170180
/**
171181
* xe_pagefault_handler() - Page fault handler
172182
* @xe: xe device instance
@@ -179,6 +189,24 @@ void xe_pagefault_reset(struct xe_device *xe, struct xe_gt *gt)
179189
*/
180190
int xe_pagefault_handler(struct xe_device *xe, struct xe_pagefault *pf)
181191
{
182-
/* TODO - implement */
183-
return 0;
192+
struct xe_pagefault_queue *pf_queue = xe->usm.pf_queue +
193+
(pf->consumer.asid % XE_PAGEFAULT_QUEUE_COUNT);
194+
unsigned long flags;
195+
bool full;
196+
197+
spin_lock_irqsave(&pf_queue->lock, flags);
198+
full = xe_pagefault_queue_full(pf_queue);
199+
if (!full) {
200+
memcpy(pf_queue->data + pf_queue->head, pf, sizeof(*pf));
201+
pf_queue->head = (pf_queue->head + xe_pagefault_entry_size()) %
202+
pf_queue->size;
203+
queue_work(xe->usm.pf_wq, &pf_queue->worker);
204+
} else {
205+
drm_warn(&xe->drm,
206+
"PageFault Queue (%d) full, shouldn't be possible\n",
207+
pf->consumer.asid % XE_PAGEFAULT_QUEUE_COUNT);
208+
}
209+
spin_unlock_irqrestore(&pf_queue->lock, flags);
210+
211+
return full ? -ENOSPC : 0;
184212
}

0 commit comments

Comments
 (0)