blob: 6d8d94d01303a406b829237d69c25816d5de2346 [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>
11#include <xf86drm.h>
12#include <mediatek_drm.h>
13#include <stdio.h>
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070014#include "drv_priv.h"
JB Tsai0c16a0f2015-03-19 14:30:31 +080015#include "helpers.h"
16
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070017static int drv_mediatek_bo_create(struct bo *bo,
Stéphane Marchesined475b42016-02-26 13:36:22 -080018 uint32_t width, uint32_t height,
19 uint32_t format, uint32_t flags)
JB Tsai0c16a0f2015-03-19 14:30:31 +080020{
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050021 size_t size;
JB Tsai0c16a0f2015-03-19 14:30:31 +080022 struct drm_mtk_gem_create gem_create;
23 int ret;
24
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070025 bo->strides[0] = drv_stride_from_format(format, width);
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050026 size = height * bo->strides[0];
27
JB Tsai0c16a0f2015-03-19 14:30:31 +080028 memset(&gem_create, 0, sizeof(gem_create));
29 gem_create.size = size;
30
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070031 ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_CREATE, &gem_create);
Ilja H. Friedelf9d2ab72015-04-09 14:08:36 -070032 if (ret) {
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070033 fprintf(stderr, "drv: DRM_IOCTL_MTK_GEM_CREATE failed "
Ilja H. Friedelf9d2ab72015-04-09 14:08:36 -070034 "(size=%zu)\n", size);
JB Tsai0c16a0f2015-03-19 14:30:31 +080035 return ret;
Ilja H. Friedelf9d2ab72015-04-09 14:08:36 -070036 }
JB Tsai0c16a0f2015-03-19 14:30:31 +080037
Yuly Novikov96c7a3b2015-12-08 22:48:29 -050038 bo->handles[0].u32 = gem_create.handle;
39 bo->sizes[0] = size;
40 bo->offsets[0] = 0;
JB Tsai0c16a0f2015-03-19 14:30:31 +080041
42 return 0;
43}
44
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070045const struct backend backend_mediatek =
JB Tsai0c16a0f2015-03-19 14:30:31 +080046{
47 .name = "mediatek",
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070048 .bo_create = drv_mediatek_bo_create,
49 .bo_destroy = drv_gem_bo_destroy,
JB Tsai0c16a0f2015-03-19 14:30:31 +080050 .format_list = {
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070051 {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING},
52 {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR},
53 {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING},
54 {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR},
JB Tsai0c16a0f2015-03-19 14:30:31 +080055 }
56};
57
58#endif