-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockchip.c
130 lines (110 loc) · 4.16 KB
/
rockchip.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifdef DRV_ROCKCHIP
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <xf86drm.h>
#include <rockchip_drm.h>
#include "drv_priv.h"
#include "helpers.h"
#include "util.h"
static int rockchip_bo_create(struct bo *bo, uint32_t width, uint32_t height,
uint32_t format, uint32_t flags)
{
int ret;
size_t plane;
struct drm_rockchip_gem_create gem_create;
if (format == DRV_FORMAT_NV12) {
uint32_t w_mbs = DIV_ROUND_UP(ALIGN(width, 16), 16);
uint32_t h_mbs = DIV_ROUND_UP(ALIGN(width, 16), 16);
uint32_t aligned_width = w_mbs * 16;
uint32_t aligned_height = DIV_ROUND_UP(h_mbs * 16 * 3, 2);
drv_bo_from_format(bo, aligned_width, height, format);
bo->total_size = bo->strides[0] * aligned_height
+ w_mbs * h_mbs * 128;
} else {
drv_bo_from_format(bo, width, height, format);
}
memset(&gem_create, 0, sizeof(gem_create));
gem_create.size = bo->total_size;
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_CREATE,
&gem_create);
if (ret) {
fprintf(stderr, "drv: DRM_IOCTL_ROCKCHIP_GEM_CREATE failed "
"(size=%llu)\n", gem_create.size);
return ret;
}
for (plane = 0; plane < bo->num_planes; plane++)
bo->handles[plane].u32 = gem_create.handle;
return 0;
}
static void *rockchip_bo_map(struct bo *bo, struct map_info *data, size_t plane)
{
int ret;
struct drm_rockchip_gem_map_off gem_map;
memset(&gem_map, 0, sizeof(gem_map));
gem_map.handle = bo->handles[0].u32;
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET,
&gem_map);
if (ret) {
fprintf(stderr,
"drv: DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET failed\n");
return MAP_FAILED;
}
data->length = bo->total_size;
return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED,
bo->drv->fd, gem_map.offset);
}
static drv_format_t rockchip_resolve_format(drv_format_t format)
{
switch (format) {
case DRV_FORMAT_FLEX_IMPLEMENTATION_DEFINED:
/*HACK: See b/28671744 */
return DRV_FORMAT_XBGR8888;
case DRV_FORMAT_FLEX_YCbCr_420_888:
return DRV_FORMAT_NV12;
default:
return format;
}
}
const struct backend backend_rockchip =
{
.name = "rockchip",
.bo_create = rockchip_bo_create,
.bo_destroy = drv_gem_bo_destroy,
.bo_map = rockchip_bo_map,
.resolve_format = rockchip_resolve_format,
.format_list = {
{DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING
| DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY},
{DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR |
DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN},
{DRV_FORMAT_XBGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING
| DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN
| DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY},
{DRV_FORMAT_XBGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR |
DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN},
{DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING
| DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY},
{DRV_FORMAT_RGB565, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING
| DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY},
{DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR |
DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN},
{DRV_FORMAT_ABGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING
| DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN
| DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY},
{DRV_FORMAT_NV12, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING |
DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY},
{DRV_FORMAT_NV12, DRV_BO_USE_SCANOUT | DRV_BO_USE_LINEAR |
DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN},
{DRV_FORMAT_YVU420, DRV_BO_USE_RENDERING | DRV_BO_USE_SW_READ_RARELY |
DRV_BO_USE_SW_WRITE_RARELY},
}
};
#endif