JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 7 | #ifdef DRV_MEDIATEK |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 8 | |
Ilja H. Friedel | f9d2ab7 | 2015-04-09 14:08:36 -0700 | [diff] [blame] | 9 | #include <stdio.h> |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 10 | #include <string.h> |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 11 | #include <sys/mman.h> |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 12 | #include <xf86drm.h> |
| 13 | #include <mediatek_drm.h> |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 14 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 15 | #include "drv_priv.h" |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 16 | #include "helpers.h" |
| 17 | |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 18 | static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height, |
| 19 | uint32_t format, uint32_t flags) |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 20 | { |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 21 | int ret; |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 22 | size_t plane; |
| 23 | struct drm_mtk_gem_create gem_create; |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 24 | |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 25 | drv_bo_from_format(bo, width, height, format); |
Yuly Novikov | 96c7a3b | 2015-12-08 22:48:29 -0500 | [diff] [blame] | 26 | |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 27 | memset(&gem_create, 0, sizeof(gem_create)); |
Gurchetan Singh | a40ca9e | 2016-08-29 19:51:45 -0700 | [diff] [blame^] | 28 | gem_create.size = bo->total_size; |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 29 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 30 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_CREATE, &gem_create); |
Ilja H. Friedel | f9d2ab7 | 2015-04-09 14:08:36 -0700 | [diff] [blame] | 31 | if (ret) { |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 32 | fprintf(stderr, "drv: DRM_IOCTL_MTK_GEM_CREATE failed " |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 33 | "(size=%llu)\n", gem_create.size); |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 34 | return ret; |
Ilja H. Friedel | f9d2ab7 | 2015-04-09 14:08:36 -0700 | [diff] [blame] | 35 | } |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 36 | |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 37 | for (plane = 0; plane < bo->num_planes; plane++) |
| 38 | bo->handles[plane].u32 = gem_create.handle; |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 43 | static void *mediatek_bo_map(struct bo *bo) |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 44 | { |
| 45 | int ret; |
| 46 | struct drm_mtk_gem_map_off gem_map; |
| 47 | |
| 48 | memset(&gem_map, 0, sizeof(gem_map)); |
| 49 | gem_map.handle = bo->handles[0].u32; |
| 50 | |
| 51 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_MAP_OFFSET, &gem_map); |
| 52 | if (ret) { |
| 53 | fprintf(stderr,"drv: DRM_IOCTL_MTK_GEM_MAP_OFFSET failed\n"); |
| 54 | return MAP_FAILED; |
| 55 | } |
| 56 | |
Gurchetan Singh | a40ca9e | 2016-08-29 19:51:45 -0700 | [diff] [blame^] | 57 | return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 58 | bo->drv->fd, gem_map.offset); |
| 59 | } |
| 60 | |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 61 | static drv_format_t mediatek_resolve_format(drv_format_t format) |
| 62 | { |
| 63 | switch (format) { |
| 64 | case DRV_FORMAT_FLEX_IMPLEMENTATION_DEFINED: |
| 65 | /*HACK: See b/28671744 */ |
| 66 | return DRV_FORMAT_XBGR8888; |
| 67 | case DRV_FORMAT_FLEX_YCbCr_420_888: |
| 68 | return DRV_FORMAT_YVU420; |
| 69 | default: |
| 70 | return format; |
| 71 | } |
| 72 | } |
| 73 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 74 | const struct backend backend_mediatek = |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 75 | { |
| 76 | .name = "mediatek", |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 77 | .bo_create = mediatek_bo_create, |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 78 | .bo_destroy = drv_gem_bo_destroy, |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 79 | .bo_map = mediatek_bo_map, |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 80 | .resolve_format = mediatek_resolve_format, |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 81 | .format_list = { |
Gurchetan Singh | bfba8c2 | 2016-08-16 17:57:10 -0700 | [diff] [blame] | 82 | {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | |
| 83 | DRV_BO_USE_RENDERING | DRV_BO_USE_HW_TEXTURE | |
| 84 | DRV_BO_USE_HW_RENDER | DRV_BO_USE_HW_2D | |
| 85 | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, |
| 86 | {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | |
| 87 | DRV_BO_USE_LINEAR | DRV_BO_USE_SW_READ_OFTEN | |
| 88 | DRV_BO_USE_SW_WRITE_OFTEN}, |
| 89 | {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | |
| 90 | DRV_BO_USE_RENDERING | DRV_BO_USE_HW_TEXTURE | |
| 91 | DRV_BO_USE_HW_RENDER | DRV_BO_USE_HW_2D | |
| 92 | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, |
| 93 | {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | |
| 94 | DRV_BO_USE_LINEAR | DRV_BO_USE_SW_READ_OFTEN | |
| 95 | DRV_BO_USE_SW_WRITE_OFTEN}, |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 96 | {DRV_FORMAT_YVU420, DRV_BO_USE_LINEAR | DRV_BO_USE_SW_READ_OFTEN | |
| 97 | DRV_BO_USE_SW_WRITE_OFTEN}, |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 98 | } |
| 99 | }; |
| 100 | |
| 101 | #endif |