blob: 894c73aa42cc0758219f3df018ca734ce92be962 [file] [log] [blame]
Eric Anholt4880e132016-01-22 18:04:29 -08001/*
2 * Copyright © 2016 Broadcom
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#include <assert.h>
25#include <string.h>
26#include <signal.h>
27#include <errno.h>
Eric Anholtb8badc22016-01-25 10:01:35 -080028#include <sys/mman.h>
Eric Anholt4880e132016-01-22 18:04:29 -080029#include <sys/types.h>
30#include <sys/stat.h>
31#include <sys/ioctl.h>
32#include <fcntl.h>
33
34#include "drmtest.h"
35#include "igt_aux.h"
36#include "igt_core.h"
37#include "igt_vc4.h"
38#include "ioctl_wrappers.h"
39#include "intel_reg.h"
40#include "intel_chipset.h"
41#include "vc4_drm.h"
42#include "vc4_packet.h"
43
44#if NEW_CONTEXT_PARAM_NO_ERROR_CAPTURE_API
45#define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4
46#endif
47
48/**
49 * SECTION:igt_vc4
50 * @short_description: VC4 support library
51 * @title: VC4
52 * @include: igt.h
53 *
54 * This library provides various auxiliary helper functions for writing VC4
55 * tests.
56 */
57
58/**
59 * igt_vc4_get_cleared_bo:
60 * @size: size of the BO in bytes
61 * @clearval: u32 value that the buffer should be completely cleared with
62 *
63 * This helper returns a new BO with the given size, which has just been
64 * cleared using the render engine.
65 */
66uint32_t igt_vc4_get_cleared_bo(int fd, size_t size, uint32_t clearval)
67{
68 /* A single row will be a page. */
69 uint32_t width = 1024;
70 uint32_t height = size / (width * 4);
Eric Anholt59f98992016-01-25 13:15:36 -080071 uint32_t handle = igt_vc4_create_bo(fd, size);
Eric Anholt4880e132016-01-22 18:04:29 -080072 struct drm_vc4_submit_cl submit = {
73 .color_write = {
74 .hindex = 0,
75 .bits = VC4_SET_FIELD(VC4_RENDER_CONFIG_FORMAT_RGBA8888,
76 VC4_RENDER_CONFIG_FORMAT),
77 },
78
79 .color_read = { .hindex = ~0 },
80 .zs_read = { .hindex = ~0 },
81 .zs_write = { .hindex = ~0 },
82 .msaa_color_write = { .hindex = ~0 },
83 .msaa_zs_write = { .hindex = ~0 },
84
Eric Anholt59f98992016-01-25 13:15:36 -080085 .bo_handles = (uint64_t)(uintptr_t)&handle,
Eric Anholt4880e132016-01-22 18:04:29 -080086 .bo_handle_count = 1,
87 .width = width,
88 .height = height,
89 .max_x_tile = ALIGN(width, 64) / 64 - 1,
90 .max_y_tile = ALIGN(height, 64) / 64 - 1,
91 .clear_color = { clearval, clearval },
92 .flags = VC4_SUBMIT_CL_USE_CLEAR_COLOR,
93 };
94
95 igt_assert_eq_u32(width * height * 4, size);
96
Eric Anholt4880e132016-01-22 18:04:29 -080097 do_ioctl(fd, DRM_IOCTL_VC4_SUBMIT_CL, &submit);
98
Eric Anholt59f98992016-01-25 13:15:36 -080099 return handle;
100}
101
102int
103igt_vc4_create_bo(int fd, size_t size)
104{
105 struct drm_vc4_create_bo create = {
106 .size = size,
107 };
108
109 do_ioctl(fd, DRM_IOCTL_VC4_CREATE_BO, &create);
110
Eric Anholt4880e132016-01-22 18:04:29 -0800111 return create.handle;
112}
Eric Anholtb8badc22016-01-25 10:01:35 -0800113
114void *
115igt_vc4_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot)
116{
117 struct drm_vc4_mmap_bo mmap_bo = {
118 .handle = handle,
119 };
120 void *ptr;
121
122 do_ioctl(fd, DRM_IOCTL_VC4_MMAP_BO, &mmap_bo);
123
124 ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_bo.offset);
125 if (ptr == MAP_FAILED)
126 return NULL;
127 else
128 return ptr;
129}