2
* Copyright © 2014 Broadcom
3
* Copyright © 208 Alyssa Rosenzweig
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
* copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation
8
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
* and/or sell copies of the Software, and to permit persons to whom the
10
* Software is furnished to do so, subject to the following conditions:
12
* The above copyright notice and this permission notice (including the next
13
* paragraph) shall be included in all copies or substantial portions of the
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29
#include "util/format/u_format.h"
30
#include "util/os_file.h"
31
#include "util/u_math.h"
32
#include "util/u_memory.h"
34
#include "drm-uapi/drm.h"
35
#include "renderonly/renderonly.h"
36
#include "panfrost_drm_public.h"
37
#include "panfrost/pan_public.h"
40
static struct renderonly_scanout *
41
panfrost_create_kms_dumb_buffer_for_resource(struct pipe_resource *rsc,
42
struct renderonly *ro,
43
struct winsys_handle *out_handle)
45
/* Find the smallest width alignment that gives us a 64byte aligned stride */
46
unsigned blk_sz = util_format_get_blocksize(rsc->format);
51
for (unsigned i = 1; i <= blk_sz; i++) {
52
if (!((64 * i) % blk_sz)) {
53
align_w = (64 * i) / blk_sz;
58
struct drm_mode_create_dumb create_dumb = {
59
.width = ALIGN_NPOT(rsc->width0, align_w),
60
.height = rsc->height0,
61
.bpp = util_format_get_blocksizebits(rsc->format),
63
struct drm_mode_destroy_dumb destroy_dumb = {0};
65
/* Align width to end up with a buffer that's aligned on 64 bytes. */
67
struct renderonly_scanout *scanout = CALLOC_STRUCT(renderonly_scanout);
71
/* create dumb buffer at scanout GPU */
72
int err = drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
74
fprintf(stderr, "DRM_IOCTL_MODE_CREATE_DUMB failed: %s\n",
79
if (create_dumb.pitch % 64)
82
scanout->handle = create_dumb.handle;
83
scanout->stride = create_dumb.pitch;
88
/* fill in winsys handle */
89
memset(out_handle, 0, sizeof(*out_handle));
90
out_handle->type = WINSYS_HANDLE_TYPE_FD;
91
out_handle->stride = create_dumb.pitch;
93
err = drmPrimeHandleToFD(ro->kms_fd, create_dumb.handle, O_CLOEXEC,
94
(int *)&out_handle->handle);
96
fprintf(stderr, "failed to export dumb buffer: %s\n", strerror(errno));
103
destroy_dumb.handle = scanout->handle;
104
drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
114
panfrost_drm_screen_create(int fd)
116
return panfrost_create_screen(os_dupfd_cloexec(fd), NULL);
120
panfrost_drm_screen_create_renderonly(struct renderonly *ro)
122
ro->create_for_resource = panfrost_create_kms_dumb_buffer_for_resource;
123
return panfrost_create_screen(os_dupfd_cloexec(ro->gpu_fd), ro);