1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #ifndef DRM_VRAM_MM_HELPER_H
4 #define DRM_VRAM_MM_HELPER_H
6 #include <drm/ttm/ttm_bo_driver.h>
11 * struct drm_vram_mm_funcs - Callback functions for &struct drm_vram_mm
12 * @evict_flags: Provides an implementation for struct \
13 &ttm_bo_driver.evict_flags
14 * @verify_access: Provides an implementation for \
15 struct &ttm_bo_driver.verify_access
17 * These callback function integrate VRAM MM with TTM buffer objects. New
18 * functions can be added if necessary.
20 struct drm_vram_mm_funcs {
21 void (*evict_flags)(struct ttm_buffer_object *bo,
22 struct ttm_placement *placement);
23 int (*verify_access)(struct ttm_buffer_object *bo, struct file *filp);
27 * struct drm_vram_mm - An instance of VRAM MM
28 * @vram_base: Base address of the managed video memory
29 * @vram_size: Size of the managed video memory in bytes
30 * @bdev: The TTM BO device.
31 * @funcs: TTM BO functions
33 * The fields &struct drm_vram_mm.vram_base and
34 * &struct drm_vram_mm.vrm_size are managed by VRAM MM, but are
35 * available for public read access. Use the field
36 * &struct drm_vram_mm.bdev to access the TTM BO device.
42 struct ttm_bo_device bdev;
44 const struct drm_vram_mm_funcs *funcs;
48 * drm_vram_mm_of_bdev() - \
49 Returns the container of type &struct ttm_bo_device for field bdev.
50 * @bdev: the TTM BO device
53 * The containing instance of &struct drm_vram_mm
55 static inline struct drm_vram_mm *drm_vram_mm_of_bdev(
56 struct ttm_bo_device *bdev)
58 return container_of(bdev, struct drm_vram_mm, bdev);
61 int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
62 uint64_t vram_base, size_t vram_size,
63 const struct drm_vram_mm_funcs *funcs);
64 void drm_vram_mm_cleanup(struct drm_vram_mm *vmm);
66 int drm_vram_mm_mmap(struct file *filp, struct vm_area_struct *vma,
67 struct drm_vram_mm *vmm);
70 * Helpers for integration with struct drm_device
73 struct drm_vram_mm *drm_vram_helper_alloc_mm(
74 struct drm_device *dev, uint64_t vram_base, size_t vram_size,
75 const struct drm_vram_mm_funcs *funcs);
76 void drm_vram_helper_release_mm(struct drm_device *dev);
79 * Helpers for &struct file_operations
82 int drm_vram_mm_file_operations_mmap(
83 struct file *filp, struct vm_area_struct *vma);
86 * define DRM_VRAM_MM_FILE_OPERATIONS - default callback functions for \
87 &struct file_operations
89 * Drivers that use VRAM MM can use this macro to initialize
90 * &struct file_operations with default functions.
92 #define DRM_VRAM_MM_FILE_OPERATIONS \
93 .llseek = no_llseek, \
96 .unlocked_ioctl = drm_ioctl, \
97 .compat_ioctl = drm_compat_ioctl, \
98 .mmap = drm_vram_mm_file_operations_mmap, \
100 .release = drm_release \