-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drm/xe: Break of TLB invalidation into its own file
TLB invalidation is used by more than USM (page faults) so break this code out into its own file. Signed-off-by: Matthew Brost <matthew.brost@intel.com> Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com> Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
- Loading branch information
Matthew Brost
authored and
Rodrigo Vivi
committed
Dec 19, 2023
1 parent
5b64366
commit a935184
Showing
9 changed files
with
146 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// SPDX-License-Identifier: MIT | ||
/* | ||
* Copyright © 2023 Intel Corporation | ||
*/ | ||
|
||
#include "xe_gt.h" | ||
#include "xe_gt_tlb_invalidation.h" | ||
#include "xe_guc.h" | ||
#include "xe_guc_ct.h" | ||
|
||
static struct xe_gt * | ||
guc_to_gt(struct xe_guc *guc) | ||
{ | ||
return container_of(guc, struct xe_gt, uc.guc); | ||
} | ||
|
||
int xe_gt_tlb_invalidation_init(struct xe_gt *gt) | ||
{ | ||
gt->usm.tlb_invalidation_seqno = 1; | ||
|
||
return 0; | ||
} | ||
|
||
static int send_tlb_invalidation(struct xe_guc *guc) | ||
{ | ||
struct xe_gt *gt = guc_to_gt(guc); | ||
u32 action[] = { | ||
XE_GUC_ACTION_TLB_INVALIDATION, | ||
0, | ||
XE_GUC_TLB_INVAL_FULL << XE_GUC_TLB_INVAL_TYPE_SHIFT | | ||
XE_GUC_TLB_INVAL_MODE_HEAVY << XE_GUC_TLB_INVAL_MODE_SHIFT | | ||
XE_GUC_TLB_INVAL_FLUSH_CACHE, | ||
}; | ||
int seqno; | ||
int ret; | ||
|
||
/* | ||
* XXX: The seqno algorithm relies on TLB invalidation being processed | ||
* in order which they currently are, if that changes the algorithm will | ||
* need to be updated. | ||
*/ | ||
mutex_lock(&guc->ct.lock); | ||
seqno = gt->usm.tlb_invalidation_seqno; | ||
action[1] = seqno; | ||
gt->usm.tlb_invalidation_seqno = (gt->usm.tlb_invalidation_seqno + 1) % | ||
TLB_INVALIDATION_SEQNO_MAX; | ||
if (!gt->usm.tlb_invalidation_seqno) | ||
gt->usm.tlb_invalidation_seqno = 1; | ||
ret = xe_guc_ct_send_locked(&guc->ct, action, ARRAY_SIZE(action), | ||
G2H_LEN_DW_TLB_INVALIDATE, 1); | ||
if (!ret) | ||
ret = seqno; | ||
mutex_unlock(&guc->ct.lock); | ||
|
||
return ret; | ||
} | ||
|
||
int xe_gt_tlb_invalidation(struct xe_gt *gt) | ||
{ | ||
return send_tlb_invalidation(>->uc.guc); | ||
} | ||
|
||
static bool tlb_invalidation_seqno_past(struct xe_gt *gt, int seqno) | ||
{ | ||
if (gt->usm.tlb_invalidation_seqno_recv >= seqno) | ||
return true; | ||
|
||
if (seqno - gt->usm.tlb_invalidation_seqno_recv > | ||
(TLB_INVALIDATION_SEQNO_MAX / 2)) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno) | ||
{ | ||
struct xe_device *xe = gt_to_xe(gt); | ||
struct xe_guc *guc = >->uc.guc; | ||
int ret; | ||
|
||
/* | ||
* XXX: See above, this algorithm only works if seqno are always in | ||
* order | ||
*/ | ||
ret = wait_event_timeout(guc->ct.wq, | ||
tlb_invalidation_seqno_past(gt, seqno), | ||
HZ / 5); | ||
if (!ret) { | ||
drm_err(&xe->drm, "TLB invalidation time'd out, seqno=%d, recv=%d\n", | ||
seqno, gt->usm.tlb_invalidation_seqno_recv); | ||
return -ETIME; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len) | ||
{ | ||
struct xe_gt *gt = guc_to_gt(guc); | ||
int expected_seqno; | ||
|
||
if (unlikely(len != 1)) | ||
return -EPROTO; | ||
|
||
/* Sanity check on seqno */ | ||
expected_seqno = (gt->usm.tlb_invalidation_seqno_recv + 1) % | ||
TLB_INVALIDATION_SEQNO_MAX; | ||
XE_WARN_ON(expected_seqno != msg[0]); | ||
|
||
gt->usm.tlb_invalidation_seqno_recv = msg[0]; | ||
smp_wmb(); | ||
wake_up_all(&guc->ct.wq); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* SPDX-License-Identifier: MIT */ | ||
/* | ||
* Copyright © 2023 Intel Corporation | ||
*/ | ||
|
||
#ifndef _XE_GT_TLB_INVALIDATION_H_ | ||
#define _XE_GT_TLB_INVALIDATION_H_ | ||
|
||
#include <linux/types.h> | ||
|
||
struct xe_gt; | ||
struct xe_guc; | ||
|
||
int xe_gt_tlb_invalidation_init(struct xe_gt *gt); | ||
int xe_gt_tlb_invalidation(struct xe_gt *gt); | ||
int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno); | ||
int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len); | ||
|
||
#endif /* _XE_GT_TLB_INVALIDATION_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters