1 /*
2  * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
3  * Copyright (C) 2010-2011 LunarG Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef _GRALLOC_DRM_PRIV_H_
25 #define _GRALLOC_DRM_PRIV_H_
26 
27 #include <pthread.h>
28 #include <xf86drm.h>
29 #include <xf86drmMode.h>
30 
31 #include "gralloc_drm_handle.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 struct gralloc_drm_t {
38 	/* initialized by gralloc_drm_create */
39 	int fd;
40 	struct gralloc_drm_drv_t *drv;
41 };
42 
43 struct drm_module_t {
44 	gralloc_module_t base;
45 
46 	pthread_mutex_t mutex;
47 	struct gralloc_drm_t *drm;
48 };
49 
50 struct gralloc_drm_drv_t {
51 	/* destroy the driver */
52 	void (*destroy)(struct gralloc_drm_drv_t *drv);
53 
54 	/* allocate or import a bo */
55 	struct gralloc_drm_bo_t *(*alloc)(struct gralloc_drm_drv_t *drv,
56 			                  struct gralloc_drm_handle_t *handle);
57 
58 	/* free a bo */
59 	void (*free)(struct gralloc_drm_drv_t *drv,
60 		     struct gralloc_drm_bo_t *bo);
61 
62 	/* map a bo for CPU access */
63 	int (*map)(struct gralloc_drm_drv_t *drv,
64 		   struct gralloc_drm_bo_t *bo,
65 		   int x, int y, int w, int h, int enable_write, void **addr);
66 
67 	/* unmap a bo */
68 	void (*unmap)(struct gralloc_drm_drv_t *drv,
69 		      struct gralloc_drm_bo_t *bo);
70 
71 	/* query component offsets, strides and handles for a format */
72 	void (*resolve_format)(struct gralloc_drm_drv_t *drv,
73 		     struct gralloc_drm_bo_t *bo,
74 		     uint32_t *pitches, uint32_t *offsets, uint32_t *handles);
75 };
76 
77 struct gralloc_drm_bo_t {
78 	struct gralloc_drm_t *drm;
79 	struct gralloc_drm_handle_t *handle;
80 
81 	int imported;  /* the handle is from a remote proces when true */
82 	int fb_handle; /* the GEM handle of the bo */
83 	int fb_id;     /* the fb id */
84 
85 	int lock_count;
86 	int locked_for;
87 
88 	unsigned int refcount;
89 };
90 
91 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_pipe(int fd, const char *name);
92 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_intel(int fd);
93 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_radeon(int fd);
94 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_rockchip(int fd);
95 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_nouveau(int fd);
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 #endif /* _GRALLOC_DRM_PRIV_H_ */
101