Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 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 | |
Tapani Pälli | b89d7ca | 2012-10-04 16:01:27 +0300 | [diff] [blame] | 27 | #include <pthread.h> |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 28 | #include <xf86drm.h> |
| 29 | #include <xf86drmMode.h> |
| 30 | |
| 31 | #include "gralloc_drm_handle.h" |
| 32 | |
Chih-Wei Huang | 4b3db54 | 2013-04-11 10:41:50 +0300 | [diff] [blame] | 33 | #ifdef __cplusplus |
| 34 | extern "C" { |
| 35 | #endif |
| 36 | |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 37 | struct gralloc_drm_t { |
| 38 | /* initialized by gralloc_drm_create */ |
| 39 | int fd; |
| 40 | struct gralloc_drm_drv_t *drv; |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 41 | }; |
| 42 | |
Tapani Pälli | 25d2251 | 2013-02-18 12:35:42 +0200 | [diff] [blame] | 43 | struct drm_module_t { |
| 44 | gralloc_module_t base; |
| 45 | |
| 46 | pthread_mutex_t mutex; |
| 47 | struct gralloc_drm_t *drm; |
| 48 | }; |
| 49 | |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 50 | struct gralloc_drm_drv_t { |
| 51 | /* destroy the driver */ |
| 52 | void (*destroy)(struct gralloc_drm_drv_t *drv); |
| 53 | |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 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 | |
Tapani Pälli | a8f0334 | 2013-01-18 15:01:43 +0200 | [diff] [blame] | 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); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 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 */ |
Chia-I Wu | 25e0413 | 2011-07-29 20:43:12 +0900 | [diff] [blame] | 84 | |
| 85 | int lock_count; |
| 86 | int locked_for; |
Tapani Pälli | a86ecd9 | 2012-08-01 16:06:00 +0300 | [diff] [blame] | 87 | |
| 88 | unsigned int refcount; |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 89 | }; |
| 90 | |
Chia-I Wu | a020bfa | 2011-06-13 08:48:44 +0800 | [diff] [blame] | 91 | struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_pipe(int fd, const char *name); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 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); |
Tomasz Figa | 47e7aba | 2015-05-07 02:17:46 +0900 | [diff] [blame] | 94 | struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_rockchip(int fd); |
Chia-I Wu | 64345b4 | 2011-06-12 18:43:33 +0800 | [diff] [blame] | 95 | struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_nouveau(int fd); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 96 | |
Chih-Wei Huang | 4b3db54 | 2013-04-11 10:41:50 +0300 | [diff] [blame] | 97 | #ifdef __cplusplus |
| 98 | } |
| 99 | #endif |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 100 | #endif /* _GRALLOC_DRM_PRIV_H_ */ |