blob: b21cc2bc2c6efeafc26e72c9def7f28fac4e154f [file] [log] [blame]
Stéphane Marchesin25a26062014-09-12 16:18:59 -07001/*
Daniele Castagna7a755de2016-12-16 17:32:30 -05002 * Copyright 2014 The Chromium OS Authors. All rights reserved.
Stéphane Marchesin25a26062014-09-12 16:18:59 -07003 * 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_EXYNOS
Stéphane Marchesin25a26062014-09-12 16:18:59 -07008
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -08009// clang-format off
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050010#include <assert.h>
11#include <errno.h>
Ilja H. Friedelf9d2ab72015-04-09 14:08:36 -070012#include <stdio.h>
Stéphane Marchesin25a26062014-09-12 16:18:59 -070013#include <string.h>
14#include <xf86drm.h>
15#include <exynos_drm.h>
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080016// clang-format on
Stéphane Marchesin25a26062014-09-12 16:18:59 -070017
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070018#include "drv_priv.h"
Stéphane Marchesin25a26062014-09-12 16:18:59 -070019#include "helpers.h"
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050020#include "util.h"
Stéphane Marchesin25a26062014-09-12 16:18:59 -070021
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -070022static const uint32_t render_target_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
23
24static const uint32_t texture_source_formats[] = { DRM_FORMAT_NV12 };
Gurchetan Singh179687e2016-10-28 10:07:35 -070025
26static int exynos_init(struct driver *drv)
27{
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -070028 int ret;
29 ret = drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats),
30 &LINEAR_METADATA, BO_USE_RENDER_MASK);
31 if (ret)
32 return ret;
33
34 ret = drv_add_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats),
35 &LINEAR_METADATA, BO_USE_TEXTURE_MASK);
36 if (ret)
37 return ret;
38
39 return drv_modify_linear_combinations(drv);
Gurchetan Singh179687e2016-10-28 10:07:35 -070040}
41
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080042static int exynos_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
43 uint32_t flags)
Stéphane Marchesin25a26062014-09-12 16:18:59 -070044{
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050045 size_t plane;
Stéphane Marchesin25a26062014-09-12 16:18:59 -070046
Gurchetan Singhf3b22da2016-11-21 10:46:38 -080047 if (format == DRM_FORMAT_NV12) {
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050048 uint32_t chroma_height;
49 /* V4L2 s5p-mfc requires width to be 16 byte aligned and height 32. */
50 width = ALIGN(width, 16);
51 height = ALIGN(height, 32);
52 chroma_height = ALIGN(height / 2, 32);
53 bo->strides[0] = bo->strides[1] = width;
54 /* MFC v8+ requires 64 byte padding in the end of luma and chroma buffers. */
55 bo->sizes[0] = bo->strides[0] * height + 64;
56 bo->sizes[1] = bo->strides[1] * chroma_height + 64;
57 bo->offsets[0] = bo->offsets[1] = 0;
Gurchetan Singha40ca9e2016-08-29 19:51:45 -070058 bo->total_size = bo->sizes[0] + bo->sizes[1];
Gurchetan Singhf3b22da2016-11-21 10:46:38 -080059 } else if (format == DRM_FORMAT_XRGB8888 || format == DRM_FORMAT_ARGB8888) {
Gurchetan Singh83dc4fb2016-07-19 15:52:33 -070060 bo->strides[0] = drv_stride_from_format(format, width, 0);
Gurchetan Singha40ca9e2016-08-29 19:51:45 -070061 bo->total_size = bo->sizes[0] = height * bo->strides[0];
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050062 bo->offsets[0] = 0;
63 } else {
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070064 fprintf(stderr, "drv: unsupported format %X\n", format);
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050065 assert(0);
66 return -EINVAL;
Ilja H. Friedelf9d2ab72015-04-09 14:08:36 -070067 }
Stéphane Marchesin25a26062014-09-12 16:18:59 -070068
Zach Reizner74312362016-05-03 15:45:16 -070069 int ret;
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050070 for (plane = 0; plane < bo->num_planes; plane++) {
71 size_t size = bo->sizes[plane];
72 struct drm_exynos_gem_create gem_create;
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050073
74 memset(&gem_create, 0, sizeof(gem_create));
75 gem_create.size = size;
76 gem_create.flags = EXYNOS_BO_NONCONTIG;
77
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070078 ret = drmIoctl(bo->drv->fd, DRM_IOCTL_EXYNOS_GEM_CREATE, &gem_create);
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050079 if (ret) {
Gurchetan Singh085bff12017-03-20 13:05:49 -070080 fprintf(stderr, "drv: DRM_IOCTL_EXYNOS_GEM_CREATE failed (size=%zu)\n",
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080081 size);
Zach Reizner74312362016-05-03 15:45:16 -070082 goto cleanup_planes;
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050083 }
84
85 bo->handles[plane].u32 = gem_create.handle;
86 }
Stéphane Marchesin25a26062014-09-12 16:18:59 -070087
88 return 0;
Zach Reizner74312362016-05-03 15:45:16 -070089
90cleanup_planes:
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080091 for (; plane != 0; plane--) {
Zach Reizner74312362016-05-03 15:45:16 -070092 struct drm_gem_close gem_close;
93 memset(&gem_close, 0, sizeof(gem_close));
94 gem_close.handle = bo->handles[plane - 1].u32;
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080095 int gem_close_ret = drmIoctl(bo->drv->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
Zach Reizner74312362016-05-03 15:45:16 -070096 if (gem_close_ret) {
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080097 fprintf(stderr, "drv: DRM_IOCTL_GEM_CLOSE failed: %d\n", gem_close_ret);
Zach Reizner74312362016-05-03 15:45:16 -070098 }
99 }
100
101 return ret;
Stéphane Marchesin25a26062014-09-12 16:18:59 -0700102}
103
Gurchetan Singhef920532016-08-12 16:38:25 -0700104/*
105 * Use dumb mapping with exynos even though a GEM buffer is created.
106 * libdrm does the same thing in exynos_drm.c
107 */
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -0800108struct backend backend_exynos = {
Stéphane Marchesin25a26062014-09-12 16:18:59 -0700109 .name = "exynos",
Gurchetan Singh179687e2016-10-28 10:07:35 -0700110 .init = exynos_init,
Gurchetan Singhd7c84fd2016-08-16 18:18:24 -0700111 .bo_create = exynos_bo_create,
Gurchetan Singh46faf6b2016-08-05 14:40:07 -0700112 .bo_destroy = drv_gem_bo_destroy,
Gurchetan Singh71611d62017-01-03 16:49:56 -0800113 .bo_import = drv_prime_bo_import,
Gurchetan Singhef920532016-08-12 16:38:25 -0700114 .bo_map = drv_dumb_bo_map,
Gurchetan Singhba6bd502017-09-18 15:29:47 -0700115 .bo_unmap = drv_bo_munmap,
Stéphane Marchesin25a26062014-09-12 16:18:59 -0700116};
117
118#endif