Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame^] | 7 | #ifdef DRV_ROCKCHIP |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 8 | |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 9 | #include <assert.h> |
| 10 | #include <errno.h> |
Ilja H. Friedel | f9d2ab7 | 2015-04-09 14:08:36 -0700 | [diff] [blame] | 11 | #include <stdio.h> |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 12 | #include <string.h> |
| 13 | #include <xf86drm.h> |
| 14 | #include <rockchip_drm.h> |
| 15 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame^] | 16 | #include "drv_priv.h" |
Dominik Behr | e13ac28 | 2015-01-13 00:59:21 -0800 | [diff] [blame] | 17 | #include "helpers.h" |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 18 | #include "util.h" |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 19 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame^] | 20 | static int drv_rockchip_bo_create(struct bo *bo, |
Stéphane Marchesin | ed475b4 | 2016-02-26 13:36:22 -0800 | [diff] [blame] | 21 | uint32_t width, uint32_t height, |
| 22 | uint32_t format, uint32_t flags) |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 23 | { |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 24 | size_t plane; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 25 | |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 26 | switch (format) { |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame^] | 27 | case DRV_FORMAT_NV12: |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 28 | width = ALIGN(width, 4); |
| 29 | height = ALIGN(height, 4); |
| 30 | bo->strides[0] = bo->strides[1] = width; |
| 31 | bo->sizes[0] = height * bo->strides[0]; |
| 32 | bo->sizes[1] = height * bo->strides[1] / 2; |
| 33 | bo->offsets[0] = 0; |
| 34 | bo->offsets[1] = height * bo->strides[0]; |
| 35 | break; |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame^] | 36 | case DRV_FORMAT_XRGB8888: |
| 37 | case DRV_FORMAT_ARGB8888: |
| 38 | case DRV_FORMAT_ABGR8888: |
| 39 | bo->strides[0] = drv_stride_from_format(format, width); |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 40 | bo->sizes[0] = height * bo->strides[0]; |
| 41 | bo->offsets[0] = 0; |
| 42 | break; |
| 43 | default: |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame^] | 44 | fprintf(stderr, "drv: rockchip: unsupported format %4.4s\n", |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 45 | (char*)&format); |
| 46 | assert(0); |
| 47 | return -EINVAL; |
Ilja H. Friedel | f9d2ab7 | 2015-04-09 14:08:36 -0700 | [diff] [blame] | 48 | } |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 49 | |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 50 | int ret; |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 51 | size_t size = 0; |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 52 | |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 53 | for (plane = 0; plane < bo->num_planes; plane++) |
| 54 | size += bo->sizes[plane]; |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 55 | |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 56 | struct drm_rockchip_gem_create gem_create; |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 57 | |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 58 | memset(&gem_create, 0, sizeof(gem_create)); |
| 59 | gem_create.size = size; |
| 60 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame^] | 61 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_CREATE, |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 62 | &gem_create); |
| 63 | |
| 64 | if (ret) { |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame^] | 65 | fprintf(stderr, "drv: DRM_IOCTL_ROCKCHIP_GEM_CREATE failed " |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 66 | "(size=%zu)\n", size); |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 67 | } |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 68 | else { |
| 69 | for (plane = 0; plane < bo->num_planes; plane++) |
| 70 | bo->handles[plane].u32 = gem_create.handle; |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | return ret; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame^] | 76 | const struct backend backend_rockchip = |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 77 | { |
| 78 | .name = "rockchip", |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame^] | 79 | .bo_create = drv_rockchip_bo_create, |
| 80 | .bo_destroy = drv_gem_bo_destroy, |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 81 | .format_list = { |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame^] | 82 | {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, |
| 83 | {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, |
| 84 | {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, |
| 85 | {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, |
| 86 | {DRV_FORMAT_ABGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, |
| 87 | {DRV_FORMAT_NV12, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING}, |
| 88 | {DRV_FORMAT_NV12, DRV_BO_USE_SCANOUT | DRV_BO_USE_LINEAR}, |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 89 | } |
| 90 | }; |
| 91 | |
| 92 | #endif |