Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / drm_gem_ttm_helper.c
blobde28720757af0940268d68cc99498a05b86539f5
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 #include <linux/module.h>
5 #include <drm/drm_gem_ttm_helper.h>
7 /**
8 * DOC: overview
10 * This library provides helper functions for gem objects backed by
11 * ttm.
14 /**
15 * drm_gem_ttm_print_info() - Print &ttm_buffer_object info for debugfs
16 * @p: DRM printer
17 * @indent: Tab indentation level
18 * @gem: GEM object
20 * This function can be used as &drm_gem_object_funcs.print_info
21 * callback.
23 void drm_gem_ttm_print_info(struct drm_printer *p, unsigned int indent,
24 const struct drm_gem_object *gem)
26 static const char * const plname[] = {
27 [ TTM_PL_SYSTEM ] = "system",
28 [ TTM_PL_TT ] = "tt",
29 [ TTM_PL_VRAM ] = "vram",
30 [ TTM_PL_PRIV ] = "priv",
32 [ 16 ] = "cached",
33 [ 17 ] = "uncached",
34 [ 18 ] = "wc",
35 [ 19 ] = "contig",
37 [ 21 ] = "pinned", /* NO_EVICT */
38 [ 22 ] = "topdown",
40 const struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem);
42 drm_printf_indent(p, indent, "placement=");
43 drm_print_bits(p, bo->mem.placement, plname, ARRAY_SIZE(plname));
44 drm_printf(p, "\n");
46 if (bo->mem.bus.is_iomem)
47 drm_printf_indent(p, indent, "bus.offset=%lx\n",
48 (unsigned long)bo->mem.bus.offset);
50 EXPORT_SYMBOL(drm_gem_ttm_print_info);
52 /**
53 * drm_gem_ttm_vmap() - vmap &ttm_buffer_object
54 * @gem: GEM object.
55 * @map: [out] returns the dma-buf mapping.
57 * Maps a GEM object with ttm_bo_vmap(). This function can be used as
58 * &drm_gem_object_funcs.vmap callback.
60 * Returns:
61 * 0 on success, or a negative errno code otherwise.
63 int drm_gem_ttm_vmap(struct drm_gem_object *gem,
64 struct dma_buf_map *map)
66 struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem);
68 return ttm_bo_vmap(bo, map);
70 EXPORT_SYMBOL(drm_gem_ttm_vmap);
72 /**
73 * drm_gem_ttm_vunmap() - vunmap &ttm_buffer_object
74 * @gem: GEM object.
75 * @map: dma-buf mapping.
77 * Unmaps a GEM object with ttm_bo_vunmap(). This function can be used as
78 * &drm_gem_object_funcs.vmap callback.
80 void drm_gem_ttm_vunmap(struct drm_gem_object *gem,
81 struct dma_buf_map *map)
83 struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem);
85 ttm_bo_vunmap(bo, map);
87 EXPORT_SYMBOL(drm_gem_ttm_vunmap);
89 /**
90 * drm_gem_ttm_mmap() - mmap &ttm_buffer_object
91 * @gem: GEM object.
92 * @vma: vm area.
94 * This function can be used as &drm_gem_object_funcs.mmap
95 * callback.
97 int drm_gem_ttm_mmap(struct drm_gem_object *gem,
98 struct vm_area_struct *vma)
100 struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem);
101 int ret;
103 ret = ttm_bo_mmap_obj(vma, bo);
104 if (ret < 0)
105 return ret;
108 * ttm has its own object refcounting, so drop gem reference
109 * to avoid double accounting counting.
111 drm_gem_object_put(gem);
113 return 0;
115 EXPORT_SYMBOL(drm_gem_ttm_mmap);
117 MODULE_DESCRIPTION("DRM gem ttm helpers");
118 MODULE_LICENSE("GPL");