]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - include/drm/drm_vram_mm_helper.h
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/drm_file.h>
7 #include <drm/drm_ioctl.h>
8 #include <drm/ttm/ttm_bo_driver.h>
13 * struct drm_vram_mm_funcs - Callback functions for &struct drm_vram_mm
14 * @evict_flags: Provides an implementation for struct \
15 &ttm_bo_driver.evict_flags
16 * @verify_access: Provides an implementation for \
17 struct &ttm_bo_driver.verify_access
19 * These callback function integrate VRAM MM with TTM buffer objects. New
20 * functions can be added if necessary.
22 struct drm_vram_mm_funcs
{
23 void (*evict_flags
)(struct ttm_buffer_object
*bo
,
24 struct ttm_placement
*placement
);
25 int (*verify_access
)(struct ttm_buffer_object
*bo
, struct file
*filp
);
29 * struct drm_vram_mm - An instance of VRAM MM
30 * @vram_base: Base address of the managed video memory
31 * @vram_size: Size of the managed video memory in bytes
32 * @bdev: The TTM BO device.
33 * @funcs: TTM BO functions
35 * The fields &struct drm_vram_mm.vram_base and
36 * &struct drm_vram_mm.vrm_size are managed by VRAM MM, but are
37 * available for public read access. Use the field
38 * &struct drm_vram_mm.bdev to access the TTM BO device.
44 struct ttm_bo_device bdev
;
46 const struct drm_vram_mm_funcs
*funcs
;
50 * drm_vram_mm_of_bdev() - \
51 Returns the container of type &struct ttm_bo_device for field bdev.
52 * @bdev: the TTM BO device
55 * The containing instance of &struct drm_vram_mm
57 static inline struct drm_vram_mm
*drm_vram_mm_of_bdev(
58 struct ttm_bo_device
*bdev
)
60 return container_of(bdev
, struct drm_vram_mm
, bdev
);
63 int drm_vram_mm_init(struct drm_vram_mm
*vmm
, struct drm_device
*dev
,
64 uint64_t vram_base
, size_t vram_size
,
65 const struct drm_vram_mm_funcs
*funcs
);
66 void drm_vram_mm_cleanup(struct drm_vram_mm
*vmm
);
68 int drm_vram_mm_mmap(struct file
*filp
, struct vm_area_struct
*vma
,
69 struct drm_vram_mm
*vmm
);
72 * Helpers for integration with struct drm_device
75 struct drm_vram_mm
*drm_vram_helper_alloc_mm(
76 struct drm_device
*dev
, uint64_t vram_base
, size_t vram_size
,
77 const struct drm_vram_mm_funcs
*funcs
);
78 void drm_vram_helper_release_mm(struct drm_device
*dev
);
81 * Helpers for &struct file_operations
84 int drm_vram_mm_file_operations_mmap(
85 struct file
*filp
, struct vm_area_struct
*vma
);
88 * define DRM_VRAM_MM_FILE_OPERATIONS - default callback functions for \
89 &struct file_operations
91 * Drivers that use VRAM MM can use this macro to initialize
92 * &struct file_operations with default functions.
94 #define DRM_VRAM_MM_FILE_OPERATIONS \
95 .llseek = no_llseek, \
98 .unlocked_ioctl = drm_ioctl, \
99 .compat_ioctl = drm_compat_ioctl, \
100 .mmap = drm_vram_mm_file_operations_mmap, \
102 .release = drm_release \