1 #ifndef GEM_H
2 #define GEM_H
3 
4 #include "igt.h"
5 
6 struct gem_driver
7 {
8 	/**
9 	 * mmap:
10 	 * @ptr: (out) pointer to the buffer in the user process's memory
11 	 * @drm_fd: open DRM device fd
12 	 * @gem_handle: GEM handle
13 	 * @size: exact size of the GEM buffer
14 	 *
15 	 * Maps the buffer backing the GEM handle for reading and writing.
16 	 *
17 	 * Returns: 0 on success, -1 otherwise
18 	 **/
19 	int (*mmap)(void **ptr, int drm_fd, uint32_t gem_handle, size_t size);
20 
21 	/**
22 	 * munmap:
23 	 * @drm_fd: open DRM device fd
24 	 * @gem_handle: GEM handle
25 	 * @ptr: pointer (see ptr argument to mmap)
26 	 * @size: exact size of the mapped area
27 	 *
28 	 * Unmaps a region previously mapped with mmap.
29 	 *
30 	 * Returns: 0 on success: -1 otherwise
31 	 **/
32 	int (*munmap)(int drm_fd, uint32_t gem_handle, void *ptr, size_t size);
33 };
34 
35 /**
36  * gem_get_driver:
37  * @drm_fd: open DRM device fd
38  *
39  * Gets the driver-specific GEM APIs for a particular device.
40  *
41  * Returns: a struct with function pointers on success; NULL otherwise
42  **/
43 struct gem_driver *gem_get_driver(int drm_fd);
44 
45 /**
46  * gem_size:
47  * @drm_fd: open DRM device fd
48  * @size: (out) size of the buffer
49  * @gem_handle: GEM handle
50  * Returns: size of the buffer backing the GEM handle.
51  **/
52 int gem_size(int drm_fd, size_t *size, uint32_t gem_handle);
53 
54 /**
55  * gem_release_handle
56  * @drm_fd: open DRM device fd
57  * @gem_handle: GEM handle
58  *
59  * Releases a GEM handle.
60  **/
61 void gem_release_handle(int drm_fd, uint32_t gem_handle);
62 
63 struct fb_configuration
64 {
65 	uint32_t width;
66 	uint32_t height;
67 	uint32_t pixel_format;
68 	uint32_t pixel_size;
69 };
70 
71 /**
72  * drm_fb_for_gem_handle
73  * @drm_fd: open DRM device fd
74  * @fb_id: (out) id of the DRM KMS fb
75  * @gem_handle: GEM handle
76  * @fb_config: metadata for the fb
77  *
78  * Converts a GEM buffer into a DRM KMS fb
79  *
80  * Returns: 0 if the buffer could be converted; -1 otherwise
81  **/
82 int drm_fb_for_gem_handle(int drm_fd, uint32_t *fb_id, uint32_t gem_handle,
83 			  const struct fb_configuration *fb_config);
84 
85 #endif
86