1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2020-2023 Intel Corporation
6 #ifndef __IVPU_MMU_CONTEXT_H__
7 #define __IVPU_MMU_CONTEXT_H__
9 #include <drm/drm_mm.h>
12 struct ivpu_file_priv
;
13 struct ivpu_addr_range
;
15 #define IVPU_MMU_PGTABLE_ENTRIES 512ull
17 struct ivpu_mmu_pgtable
{
18 u64
***pte_ptrs
[IVPU_MMU_PGTABLE_ENTRIES
];
19 u64
**pmd_ptrs
[IVPU_MMU_PGTABLE_ENTRIES
];
20 u64
*pud_ptrs
[IVPU_MMU_PGTABLE_ENTRIES
];
25 struct ivpu_mmu_context
{
26 struct mutex lock
; /* Protects: mm, pgtable, is_cd_valid */
28 struct ivpu_mmu_pgtable pgtable
;
33 void ivpu_mmu_context_init(struct ivpu_device
*vdev
, struct ivpu_mmu_context
*ctx
, u32 context_id
);
34 void ivpu_mmu_context_fini(struct ivpu_device
*vdev
, struct ivpu_mmu_context
*ctx
);
35 void ivpu_mmu_global_context_init(struct ivpu_device
*vdev
);
36 void ivpu_mmu_global_context_fini(struct ivpu_device
*vdev
);
37 int ivpu_mmu_reserved_context_init(struct ivpu_device
*vdev
);
38 void ivpu_mmu_reserved_context_fini(struct ivpu_device
*vdev
);
40 void ivpu_mmu_user_context_mark_invalid(struct ivpu_device
*vdev
, u32 ssid
);
42 int ivpu_mmu_context_insert_node(struct ivpu_mmu_context
*ctx
, const struct ivpu_addr_range
*range
,
43 u64 size
, struct drm_mm_node
*node
);
44 void ivpu_mmu_context_remove_node(struct ivpu_mmu_context
*ctx
, struct drm_mm_node
*node
);
46 int ivpu_mmu_context_map_sgt(struct ivpu_device
*vdev
, struct ivpu_mmu_context
*ctx
,
47 u64 vpu_addr
, struct sg_table
*sgt
, bool llc_coherent
);
48 void ivpu_mmu_context_unmap_sgt(struct ivpu_device
*vdev
, struct ivpu_mmu_context
*ctx
,
49 u64 vpu_addr
, struct sg_table
*sgt
);
50 int ivpu_mmu_context_set_pages_ro(struct ivpu_device
*vdev
, struct ivpu_mmu_context
*ctx
,
51 u64 vpu_addr
, size_t size
);
53 #endif /* __IVPU_MMU_CONTEXT_H__ */