Eric Anholt | 4880e13 | 2016-01-22 18:04:29 -0800 | [diff] [blame] | 1 | /* |
| 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 Anholt | b8badc2 | 2016-01-25 10:01:35 -0800 | [diff] [blame] | 28 | #include <sys/mman.h> |
Eric Anholt | 4880e13 | 2016-01-22 18:04:29 -0800 | [diff] [blame] | 29 | #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 | */ |
| 66 | uint32_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 Anholt | 59f9899 | 2016-01-25 13:15:36 -0800 | [diff] [blame] | 71 | uint32_t handle = igt_vc4_create_bo(fd, size); |
Eric Anholt | 4880e13 | 2016-01-22 18:04:29 -0800 | [diff] [blame] | 72 | 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 Anholt | 59f9899 | 2016-01-25 13:15:36 -0800 | [diff] [blame] | 85 | .bo_handles = (uint64_t)(uintptr_t)&handle, |
Eric Anholt | 4880e13 | 2016-01-22 18:04:29 -0800 | [diff] [blame] | 86 | .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 Anholt | 4880e13 | 2016-01-22 18:04:29 -0800 | [diff] [blame] | 97 | do_ioctl(fd, DRM_IOCTL_VC4_SUBMIT_CL, &submit); |
| 98 | |
Eric Anholt | 59f9899 | 2016-01-25 13:15:36 -0800 | [diff] [blame] | 99 | return handle; |
| 100 | } |
| 101 | |
| 102 | int |
| 103 | igt_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 Anholt | 4880e13 | 2016-01-22 18:04:29 -0800 | [diff] [blame] | 111 | return create.handle; |
| 112 | } |
Eric Anholt | b8badc2 | 2016-01-25 10:01:35 -0800 | [diff] [blame] | 113 | |
| 114 | void * |
| 115 | igt_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 | } |