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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
// SPDX-License-Identifier: MIT
/*
* Copyright © 2023 Intel Corporation
*/
/**
* TEST: kms_fb_coherency
* Category: Display
* Description: Exercise coherency of future scanout buffer objects
* Mega feature: General Display Features
* Driver requirement: i915, xe
*/
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "igt.h"
#include "xe/xe_ioctl.h"
/**
* SUBTEST: memset-crc
* Description: Use display controller CRC hardware to validate (non)coherency
* of memset operations on future scanout buffer objects
* mmapped with different mmap methods and different caching modes.
*/
typedef struct {
int drm_fd;
igt_display_t display;
struct igt_fb fb[2];
igt_output_t *output;
igt_plane_t *primary;
enum pipe pipe;
igt_crc_t ref_crc;
igt_pipe_crc_t *pipe_crc;
uint32_t devid;
} data_t;
static void prepare_crtc(data_t *data)
{
igt_display_t *display = &data->display;
igt_output_t *output = data->output;
drmModeModeInfo *mode;
igt_display_reset(display);
/* select the pipe we want to use */
igt_output_set_pipe(output, data->pipe);
mode = igt_output_get_mode(output);
/* create a white reference fb and flip to it */
igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_LINEAR,
1.0, 1.0, 1.0, &data->fb[0]);
data->primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
igt_plane_set_fb(data->primary, &data->fb[0]);
igt_display_commit(display);
if (data->pipe_crc)
igt_pipe_crc_free(data->pipe_crc);
data->pipe_crc = igt_pipe_crc_new(data->drm_fd, data->pipe,
IGT_PIPE_CRC_SOURCE_AUTO);
/* get reference crc for the white fb */
igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc);
}
static struct igt_fb *prepare_fb(data_t *data)
{
igt_output_t *output = data->output;
struct igt_fb *fb = &data->fb[1];
drmModeModeInfo *mode;
prepare_crtc(data);
mode = igt_output_get_mode(output);
/* create a non-white fb we can overwrite later */
igt_create_pattern_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_LINEAR, fb);
/* flip to it to make it UC/WC and fully flushed */
drmModeSetPlane(data->drm_fd,
data->primary->drm_plane->plane_id,
output->config.crtc->crtc_id,
fb->fb_id, 0,
0, 0, fb->width, fb->height,
0, 0, fb->width << 16, fb->height << 16);
/* flip back the original white buffer */
drmModeSetPlane(data->drm_fd,
data->primary->drm_plane->plane_id,
output->config.crtc->crtc_id,
data->fb[0].fb_id, 0,
0, 0, fb->width, fb->height,
0, 0, fb->width << 16, fb->height << 16);
if (is_i915_device(data->drm_fd) && !gem_has_lmem(data->drm_fd)) {
uint32_t caching;
/* make sure caching mode has become UC/WT */
caching = gem_get_caching(data->drm_fd, fb->gem_handle);
igt_assert(caching == I915_CACHING_NONE ||
caching == I915_CACHING_DISPLAY);
}
return fb;
}
static void check_buf_crc(data_t *data, void *buf, igt_fb_t *fb)
{
igt_crc_t crc;
/* use memset to make the mmapped fb all white */
memset(buf, 0xff, fb->size);
munmap(buf, fb->size);
/* and flip to it */
drmModeSetPlane(data->drm_fd,
data->primary->drm_plane->plane_id,
data->output->config.crtc->crtc_id,
fb->fb_id, 0,
0, 0, fb->width, fb->height,
0, 0, fb->width << 16, fb->height << 16);
/* check that the crc is as expected, which requires that caches got flushed */
igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
igt_assert_crc_equal(&crc, &data->ref_crc);
}
static void cleanup_crtc(data_t *data)
{
igt_display_t *display = &data->display;
igt_output_t *output = data->output;
igt_pipe_crc_free(data->pipe_crc);
data->pipe_crc = NULL;
igt_plane_set_fb(data->primary, NULL);
igt_output_set_pipe(output, PIPE_ANY);
igt_display_commit(display);
igt_remove_fb(data->drm_fd, &data->fb[0]);
igt_remove_fb(data->drm_fd, &data->fb[1]);
}
static void test_mmap_gtt(data_t *data)
{
igt_fb_t *fb;
void *buf;
fb = prepare_fb(data);
buf = gem_mmap__gtt(data->drm_fd, fb->gem_handle, fb->size, PROT_WRITE);
check_buf_crc(data, buf, fb);
}
static void test_mmap_offset_wc(data_t *data)
{
igt_fb_t *fb;
void *buf;
fb = prepare_fb(data);
if (is_i915_device(data->drm_fd))
buf = gem_mmap_offset__wc(data->drm_fd, fb->gem_handle, 0, fb->size, PROT_WRITE);
else
buf = xe_bo_mmap_ext(data->drm_fd, fb->gem_handle, fb->size, PROT_WRITE);
check_buf_crc(data, buf, fb);
}
static void test_mmap_offset_uc(data_t *data)
{
igt_fb_t *fb;
void *buf;
fb = prepare_fb(data);
/* mmap the fb */
buf = __gem_mmap_offset(data->drm_fd, fb->gem_handle, 0, fb->size, PROT_WRITE,
I915_MMAP_OFFSET_UC);
igt_assert(buf);
check_buf_crc(data, buf, fb);
}
static void test_mmap_offset_fixed(data_t *data)
{
igt_fb_t *fb;
void *buf;
fb = prepare_fb(data);
/* mmap the fb */
buf = gem_mmap_offset__fixed(data->drm_fd, fb->gem_handle, 0, fb->size, PROT_WRITE);
check_buf_crc(data, buf, fb);
}
static void test_legacy_mmap_wc(data_t *data)
{
igt_fb_t *fb;
void *buf;
fb = prepare_fb(data);
/* mmap the fb */
buf = gem_mmap__wc(data->drm_fd, fb->gem_handle, 0, fb->size, PROT_WRITE);
check_buf_crc(data, buf, fb);
}
static void select_valid_pipe_output_combo(data_t *data)
{
igt_display_t *display = &data->display;
for_each_pipe_with_valid_output(display, data->pipe, data->output) {
igt_display_reset(display);
igt_output_set_pipe(data->output, data->pipe);
if (intel_pipe_output_combo_valid(display))
return;
}
igt_skip("no valid crtc/connector combinations found\n");
}
igt_main
{
data_t data;
igt_fixture {
data.drm_fd = drm_open_driver_master(DRIVER_INTEL | DRIVER_XE);
data.devid = intel_get_drm_devid(data.drm_fd);
kmstest_set_vt_graphics_mode();
igt_require_pipe_crc(data.drm_fd);
igt_display_require(&data.display, data.drm_fd);
select_valid_pipe_output_combo(&data);
}
igt_subtest_with_dynamic("memset-crc") {
if (igt_draw_supports_method(data.drm_fd, IGT_DRAW_MMAP_GTT)) {
igt_dynamic("mmap-gtt")
test_mmap_gtt(&data);
cleanup_crtc(&data);
}
if (igt_draw_supports_method(data.drm_fd, IGT_DRAW_MMAP_WC)) {
igt_dynamic("mmap-offset-wc")
test_mmap_offset_wc(&data);
cleanup_crtc(&data);
}
if (is_i915_device(data.drm_fd)) {
if (gem_has_lmem(data.drm_fd)) {
igt_dynamic("mmap-offset-fixed")
test_mmap_offset_fixed(&data);
} else if (gem_has_mmap_offset(data.drm_fd)) {
igt_dynamic("mmap-offset-uc")
test_mmap_offset_uc(&data);
}
cleanup_crtc(&data);
if (gem_has_legacy_mmap(data.drm_fd) &&
gem_mmap__has_wc(data.drm_fd)) {
igt_dynamic("mmap-legacy-wc")
test_legacy_mmap_wc(&data);
cleanup_crtc(&data);
}
}
}
igt_fixture {
igt_display_fini(&data.display);
drm_close_driver(data.drm_fd);
}
}
|