blob: 24c398f76712a2d48810d4d5210aa9d92d4e07d9 [file] [log] [blame]
Chia-I Wu2ec32d42011-06-12 16:21:30 +08001/*
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
Tapani Pällib89d7ca2012-10-04 16:01:27 +030027#include <pthread.h>
Chia-I Wu2ec32d42011-06-12 16:21:30 +080028#include <xf86drm.h>
29#include <xf86drmMode.h>
30
31#include "gralloc_drm_handle.h"
32
Chih-Wei Huang4b3db542013-04-11 10:41:50 +030033#ifdef __cplusplus
34extern "C" {
35#endif
36
Chia-I Wu2ec32d42011-06-12 16:21:30 +080037struct gralloc_drm_t {
38 /* initialized by gralloc_drm_create */
39 int fd;
40 struct gralloc_drm_drv_t *drv;
Chia-I Wu2ec32d42011-06-12 16:21:30 +080041};
42
Tapani Pälli25d22512013-02-18 12:35:42 +020043struct drm_module_t {
44 gralloc_module_t base;
45
46 pthread_mutex_t mutex;
47 struct gralloc_drm_t *drm;
48};
49
Chia-I Wu2ec32d42011-06-12 16:21:30 +080050struct gralloc_drm_drv_t {
51 /* destroy the driver */
52 void (*destroy)(struct gralloc_drm_drv_t *drv);
53
Chia-I Wu2ec32d42011-06-12 16:21:30 +080054 /* 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
Tapani Pällia8f03342013-01-18 15:01:43 +020071 /* 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);
Chia-I Wu2ec32d42011-06-12 16:21:30 +080075};
76
77struct 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 */
Chia-I Wu25e04132011-07-29 20:43:12 +090084
85 int lock_count;
86 int locked_for;
Tapani Pällia86ecd92012-08-01 16:06:00 +030087
88 unsigned int refcount;
Chia-I Wu2ec32d42011-06-12 16:21:30 +080089};
90
Chia-I Wua020bfa2011-06-13 08:48:44 +080091struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_pipe(int fd, const char *name);
Chia-I Wu2ec32d42011-06-12 16:21:30 +080092struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_intel(int fd);
93struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_radeon(int fd);
Tomasz Figa47e7aba2015-05-07 02:17:46 +090094struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_rockchip(int fd);
Chia-I Wu64345b42011-06-12 18:43:33 +080095struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_nouveau(int fd);
Chia-I Wu2ec32d42011-06-12 16:21:30 +080096
Chih-Wei Huang4b3db542013-04-11 10:41:50 +030097#ifdef __cplusplus
98}
99#endif
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800100#endif /* _GRALLOC_DRM_PRIV_H_ */