|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +/* |
| 3 | + * Copyright © 2024 Intel Corporation |
| 4 | + */ |
| 5 | + |
| 6 | +#include "xe_svm.h" |
| 7 | +#include "xe_vm.h" |
| 8 | +#include "xe_vm_types.h" |
| 9 | + |
| 10 | +static void xe_svm_invalidate(struct drm_gpusvm *gpusvm, |
| 11 | + struct drm_gpusvm_notifier *notifier, |
| 12 | + const struct mmu_notifier_range *mmu_range) |
| 13 | +{ |
| 14 | + /* TODO: Implement */ |
| 15 | +} |
| 16 | + |
| 17 | +static const struct drm_gpusvm_ops gpusvm_ops = { |
| 18 | + .invalidate = xe_svm_invalidate, |
| 19 | +}; |
| 20 | + |
| 21 | +static const unsigned long fault_chunk_sizes[] = { |
| 22 | + SZ_2M, |
| 23 | + SZ_64K, |
| 24 | + SZ_4K, |
| 25 | +}; |
| 26 | + |
| 27 | +/** |
| 28 | + * xe_svm_init() - SVM initialize |
| 29 | + * @vm: The VM. |
| 30 | + * |
| 31 | + * Initialize SVM state which is embedded within the VM. |
| 32 | + * |
| 33 | + * Return: 0 on success, negative error code on error. |
| 34 | + */ |
| 35 | +int xe_svm_init(struct xe_vm *vm) |
| 36 | +{ |
| 37 | + int err; |
| 38 | + |
| 39 | + err = drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM", &vm->xe->drm, |
| 40 | + current->mm, NULL, 0, vm->size, |
| 41 | + SZ_512M, &gpusvm_ops, fault_chunk_sizes, |
| 42 | + ARRAY_SIZE(fault_chunk_sizes)); |
| 43 | + if (err) |
| 44 | + return err; |
| 45 | + |
| 46 | + drm_gpusvm_driver_set_lock(&vm->svm.gpusvm, &vm->lock); |
| 47 | + |
| 48 | + return 0; |
| 49 | +} |
| 50 | + |
| 51 | +/** |
| 52 | + * xe_svm_close() - SVM close |
| 53 | + * @vm: The VM. |
| 54 | + * |
| 55 | + * Close SVM state (i.e., stop and flush all SVM actions). |
| 56 | + */ |
| 57 | +void xe_svm_close(struct xe_vm *vm) |
| 58 | +{ |
| 59 | + xe_assert(vm->xe, xe_vm_is_closed(vm)); |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * xe_svm_fini() - SVM finalize |
| 64 | + * @vm: The VM. |
| 65 | + * |
| 66 | + * Finalize SVM state which is embedded within the VM. |
| 67 | + */ |
| 68 | +void xe_svm_fini(struct xe_vm *vm) |
| 69 | +{ |
| 70 | + xe_assert(vm->xe, xe_vm_is_closed(vm)); |
| 71 | + |
| 72 | + drm_gpusvm_fini(&vm->svm.gpusvm); |
| 73 | +} |
0 commit comments