CK Hu | 119f517 | 2016-01-04 18:36:34 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2015 MediaTek Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #ifndef _MTK_DRM_GEM_H_ |
| 15 | #define _MTK_DRM_GEM_H_ |
| 16 | |
| 17 | #include <drm/drm_gem.h> |
| 18 | |
| 19 | /* |
| 20 | * mtk drm buffer structure. |
| 21 | * |
| 22 | * @base: a gem object. |
| 23 | * - a new handle to this gem object would be created |
| 24 | * by drm_gem_handle_create(). |
| 25 | * @cookie: the return value of dma_alloc_attrs(), keep it for dma_free_attrs() |
| 26 | * @kvaddr: kernel virtual address of gem buffer. |
| 27 | * @dma_addr: dma address of gem buffer. |
| 28 | * @dma_attrs: dma attributes of gem buffer. |
| 29 | * |
| 30 | * P.S. this object would be transferred to user as kms_bo.handle so |
| 31 | * user can access the buffer through kms_bo.handle. |
| 32 | */ |
| 33 | struct mtk_drm_gem_obj { |
| 34 | struct drm_gem_object base; |
| 35 | void *cookie; |
| 36 | void *kvaddr; |
| 37 | dma_addr_t dma_addr; |
| 38 | struct dma_attrs dma_attrs; |
| 39 | struct sg_table *sg; |
| 40 | }; |
| 41 | |
| 42 | #define to_mtk_gem_obj(x) container_of(x, struct mtk_drm_gem_obj, base) |
| 43 | |
| 44 | void mtk_drm_gem_free_object(struct drm_gem_object *gem); |
| 45 | struct mtk_drm_gem_obj *mtk_drm_gem_create(struct drm_device *dev, size_t size, |
| 46 | bool alloc_kmap); |
| 47 | int mtk_drm_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev, |
| 48 | struct drm_mode_create_dumb *args); |
| 49 | int mtk_drm_gem_dumb_map_offset(struct drm_file *file_priv, |
| 50 | struct drm_device *dev, uint32_t handle, |
| 51 | uint64_t *offset); |
| 52 | int mtk_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); |
| 53 | int mtk_drm_gem_mmap_buf(struct drm_gem_object *obj, |
| 54 | struct vm_area_struct *vma); |
| 55 | struct sg_table *mtk_gem_prime_get_sg_table(struct drm_gem_object *obj); |
| 56 | struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev, |
| 57 | struct dma_buf_attachment *attach, struct sg_table *sg); |
| 58 | |
| 59 | #endif |