blob: 5dcd0e84945795a24fb3150c4f98d69059c1bb09 [file] [log] [blame]
Niklas Schulze878fed42017-02-08 15:29:21 +01001/*
2 * Copyright 2017 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
7#ifdef DRV_VC4
8
9#include <stdio.h>
10#include <string.h>
11#include <sys/mman.h>
12#include <vc4_drm.h>
13#include <xf86drm.h>
14
15#include "drv_priv.h"
16#include "helpers.h"
17#include "util.h"
18
Gurchetan Singh6b41fb52017-03-01 20:14:39 -080019static const uint32_t supported_formats[] = {
20 DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888
Niklas Schulze878fed42017-02-08 15:29:21 +010021};
22
23static int vc4_init(struct driver *drv)
24{
Gurchetan Singh6b41fb52017-03-01 20:14:39 -080025 return drv_add_linear_combinations(drv, supported_formats,
26 ARRAY_SIZE(supported_formats));
Niklas Schulze878fed42017-02-08 15:29:21 +010027}
28
29static int vc4_bo_create(struct bo *bo, uint32_t width, uint32_t height,
30 uint32_t format, uint32_t flags)
31{
32 int ret;
33 size_t plane;
34 struct drm_vc4_create_bo bo_create;
35
36 drv_bo_from_format(bo, width, height, format);
37
38 memset(&bo_create, 0, sizeof(bo_create));
39 bo_create.size = bo->total_size;
40
41 ret = drmIoctl(bo->drv->fd, DRM_IOCTL_VC4_CREATE_BO, &bo_create);
42 if (ret) {
43 fprintf(stderr, "drv: DRM_IOCTL_VC4_GEM_CREATE failed "
44 "(size=%zu)\n", bo->total_size);
45 return ret;
46 }
47
48 for (plane = 0; plane < bo->num_planes; plane++)
49 bo->handles[plane].u32 = bo_create.handle;
50
51 return 0;
52}
53
54static void *vc4_bo_map(struct bo *bo, struct map_info *data, size_t plane)
55{
56 int ret;
57 struct drm_vc4_mmap_bo bo_map;
58
59 memset(&bo_map, 0, sizeof(bo_map));
60 bo_map.handle = bo->handles[0].u32;
61
62 ret = drmCommandWriteRead(bo->drv->fd, DRM_VC4_MMAP_BO, &bo_map,
63 sizeof(bo_map));
64 if (ret) {
65 fprintf(stderr, "drv: DRM_VC4_MMAP_BO failed\n");
66 return MAP_FAILED;
67 }
68
69 data->length = bo->total_size;
70
71 return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED,
72 bo->drv->fd, bo_map.offset);
73}
74
75struct backend backend_vc4 =
76{
77 .name = "vc4",
78 .init = vc4_init,
79 .bo_create = vc4_bo_create,
80 .bo_import = drv_prime_bo_import,
81 .bo_destroy = drv_gem_bo_destroy,
82 .bo_map = vc4_bo_map,
83};
84
85#endif