blob: f4fe0ecd8780233620c92c940b57e9af5cb754b6 [file] [log] [blame]
JB Tsai0c16a0f2015-03-19 14:30:31 +08001/*
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 Singh46faf6b2016-08-05 14:40:07 -07007#ifdef DRV_MEDIATEK
JB Tsai0c16a0f2015-03-19 14:30:31 +08008
Ilja H. Friedelf9d2ab72015-04-09 14:08:36 -07009#include <stdio.h>
JB Tsai0c16a0f2015-03-19 14:30:31 +080010#include <string.h>
Gurchetan Singhef920532016-08-12 16:38:25 -070011#include <sys/mman.h>
JB Tsai0c16a0f2015-03-19 14:30:31 +080012#include <xf86drm.h>
13#include <mediatek_drm.h>
Gurchetan Singhef920532016-08-12 16:38:25 -070014
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070015#include "drv_priv.h"
JB Tsai0c16a0f2015-03-19 14:30:31 +080016#include "helpers.h"
17
Gurchetan Singhd7c84fd2016-08-16 18:18:24 -070018static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height,
19 uint32_t format, uint32_t flags)
JB Tsai0c16a0f2015-03-19 14:30:31 +080020{
JB Tsai0c16a0f2015-03-19 14:30:31 +080021 int ret;
Gurchetan Singh42cc6d62016-08-29 18:19:19 -070022 size_t plane;
23 struct drm_mtk_gem_create gem_create;
JB Tsai0c16a0f2015-03-19 14:30:31 +080024
Gurchetan Singh42cc6d62016-08-29 18:19:19 -070025 drv_bo_from_format(bo, width, height, format);
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050026
JB Tsai0c16a0f2015-03-19 14:30:31 +080027 memset(&gem_create, 0, sizeof(gem_create));
Gurchetan Singha40ca9e2016-08-29 19:51:45 -070028 gem_create.size = bo->total_size;
JB Tsai0c16a0f2015-03-19 14:30:31 +080029
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070030 ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_CREATE, &gem_create);
Ilja H. Friedelf9d2ab72015-04-09 14:08:36 -070031 if (ret) {
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070032 fprintf(stderr, "drv: DRM_IOCTL_MTK_GEM_CREATE failed "
Gurchetan Singh42cc6d62016-08-29 18:19:19 -070033 "(size=%llu)\n", gem_create.size);
JB Tsai0c16a0f2015-03-19 14:30:31 +080034 return ret;
Ilja H. Friedelf9d2ab72015-04-09 14:08:36 -070035 }
JB Tsai0c16a0f2015-03-19 14:30:31 +080036
Gurchetan Singh42cc6d62016-08-29 18:19:19 -070037 for (plane = 0; plane < bo->num_planes; plane++)
38 bo->handles[plane].u32 = gem_create.handle;
JB Tsai0c16a0f2015-03-19 14:30:31 +080039
40 return 0;
41}
42
Gurchetan Singhd7c84fd2016-08-16 18:18:24 -070043static void *mediatek_bo_map(struct bo *bo)
Gurchetan Singhef920532016-08-12 16:38:25 -070044{
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 Singha40ca9e2016-08-29 19:51:45 -070057 return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED,
Gurchetan Singhef920532016-08-12 16:38:25 -070058 bo->drv->fd, gem_map.offset);
59}
60
Gurchetan Singh42cc6d62016-08-29 18:19:19 -070061static 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 Singh46faf6b2016-08-05 14:40:07 -070074const struct backend backend_mediatek =
JB Tsai0c16a0f2015-03-19 14:30:31 +080075{
76 .name = "mediatek",
Gurchetan Singhd7c84fd2016-08-16 18:18:24 -070077 .bo_create = mediatek_bo_create,
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070078 .bo_destroy = drv_gem_bo_destroy,
Gurchetan Singhd7c84fd2016-08-16 18:18:24 -070079 .bo_map = mediatek_bo_map,
Gurchetan Singh42cc6d62016-08-29 18:19:19 -070080 .resolve_format = mediatek_resolve_format,
JB Tsai0c16a0f2015-03-19 14:30:31 +080081 .format_list = {
Gurchetan Singhbfba8c22016-08-16 17:57:10 -070082 {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 Singh42cc6d62016-08-29 18:19:19 -070096 {DRV_FORMAT_YVU420, DRV_BO_USE_LINEAR | DRV_BO_USE_SW_READ_OFTEN |
97 DRV_BO_USE_SW_WRITE_OFTEN},
JB Tsai0c16a0f2015-03-19 14:30:31 +080098 }
99};
100
101#endif