From: Brian Starkey <brian.starkey@xxxxxxx> Add support in igt_kms for Writeback connectors, with the ability to attach framebuffers and retrieve fences. Signed-off-by: Brian Starkey <brian.starkey@xxxxxxx> Signed-off-by: Liviu Dudau <liviu.dudau@xxxxxxx> --- lib/igt_aux.c | 1 + lib/igt_kms.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- lib/igt_kms.h | 16 +++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index 882dba06..945c1248 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -1087,6 +1087,7 @@ static const struct type_name connector_type_names[] = { { DRM_MODE_CONNECTOR_eDP, "eDP" }, { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, { DRM_MODE_CONNECTOR_DSI, "DSI" }, + { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" }, {} }; diff --git a/lib/igt_kms.c b/lib/igt_kms.c index faf9df2f..c86a2a63 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -186,7 +186,10 @@ const char *igt_crtc_prop_names[IGT_NUM_CRTC_PROPS] = { const char *igt_connector_prop_names[IGT_NUM_CONNECTOR_PROPS] = { "scaling mode", - "CRTC_ID" + "CRTC_ID", + "WRITEBACK_PIXEL_FORMATS", + "WRITEBACK_FB_ID", + "WRITEBACK_OUT_FENCE_PTR" }; /* @@ -1831,6 +1834,7 @@ void igt_display_init(igt_display_t *display, int drm_fd) output->pending_crtc_idx_mask = 0; output->id = resources->connectors[i]; output->display = display; + output->writeback_out_fence_fd = -1; igt_output_refresh(output); @@ -1898,6 +1902,42 @@ igt_output_t *igt_output_from_connector(igt_display_t *display, return found; } +void igt_output_set_writeback_fb(igt_output_t *output, struct igt_fb *fb) +{ + igt_display_t *display = output->display; + struct kmstest_connector_config *config = &output->config; + + if (config->connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) + return; + + LOG(display, "%s: output_set_writeback_fb(%d)\n", output->name, + fb ? fb->fb_id : 0); + + output->writeback_fb = fb; +} + +static void igt_output_reset_writeback_out_fence(igt_output_t *output) +{ + if (output->writeback_out_fence_fd >= 0) { + close(output->writeback_out_fence_fd); + output->writeback_out_fence_fd = -1; + } +} + +void igt_output_request_writeback_out_fence(igt_output_t *output) +{ + igt_output_reset_writeback_out_fence(output); + output->writeback_out_fence_requested = true; +} + +int igt_output_get_last_writeback_out_fence(igt_output_t *output) +{ + int fd = output->writeback_out_fence_fd; + output->writeback_out_fence_fd = -1; + + return fd; +} + static void igt_pipe_fini(igt_pipe_t *pipe) { int i; @@ -1918,6 +1958,8 @@ static void igt_pipe_fini(igt_pipe_t *pipe) static void igt_output_fini(igt_output_t *output) { kmstest_free_connector_config(&output->config); + if (output->writeback_out_fence_fd >= 0) + close(output->writeback_out_fence_fd); free(output->name); output->name = NULL; } @@ -2534,10 +2576,41 @@ static void igt_atomic_prepare_connector_commit(igt_output_t *output, drmModeAto igt_atomic_populate_connector_req(req, output, IGT_CONNECTOR_CRTC_ID, crtc_id); } + + if (output->writeback_fb) { + igt_atomic_populate_connector_req(req, output, IGT_CONNECTOR_WRITEBACK_FB_ID, output->writeback_fb->fb_id); + output->writeback_fb = NULL; + } + + igt_output_reset_writeback_out_fence(output); + if (output->writeback_out_fence_requested) { + igt_atomic_populate_connector_req(req, output, IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR, + (uint64_t)(uintptr_t)&output->writeback_out_fence_fd); + } + /* * TODO: Add all other connector level properties here */ +} + +static void handle_writeback_out_fences(igt_display_t *display, uint32_t flags, int ret) +{ + int i; + for (i = 0; i < display->n_outputs; i++) { + igt_output_t *output = &display->outputs[i]; + + if (!output->config.connector) + continue; + + if (!output->writeback_out_fence_requested) + continue; + + output->writeback_out_fence_requested = false; + + if (ret || (flags & DRM_MODE_ATOMIC_TEST_ONLY)) + igt_assert(output->writeback_out_fence_fd == -1); + } } /* @@ -2586,6 +2659,7 @@ static int igt_atomic_commit(igt_display_t *display, uint32_t flags, void *user_ } ret = drmModeAtomicCommit(display->drm_fd, req, flags, user_data); + handle_writeback_out_fences(display, flags, ret); if (!ret) { for_each_pipe(display, pipe) { diff --git a/lib/igt_kms.h b/lib/igt_kms.h index 35428f3e..ce9a35ef 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -37,6 +37,10 @@ #include "igt_fb.h" #include "ioctl_wrappers.h" +#ifndef DRM_MODE_CONNECTOR_WRITEBACK +#define DRM_MODE_CONNECTOR_WRITEBACK 18 +#endif + /* Low-level helpers with kmstest_ prefix */ /** @@ -113,6 +117,9 @@ extern const char *igt_crtc_prop_names[]; enum igt_atomic_connector_properties { IGT_CONNECTOR_SCALING_MODE = 0, IGT_CONNECTOR_CRTC_ID, + IGT_CONNECTOR_WRITEBACK_PIXEL_FORMATS, + IGT_CONNECTOR_WRITEBACK_FB_ID, + IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR, IGT_NUM_CONNECTOR_PROPS }; @@ -363,6 +370,10 @@ typedef struct { unsigned long pending_crtc_idx_mask; bool use_override_mode; drmModeModeInfo override_mode; + + struct igt_fb *writeback_fb; + int32_t writeback_out_fence_fd; + bool writeback_out_fence_requested; } igt_output_t; struct igt_display { @@ -392,10 +403,15 @@ drmModeModeInfo *igt_output_get_mode(igt_output_t *output); void igt_output_override_mode(igt_output_t *output, drmModeModeInfo *mode); void igt_output_set_pipe(igt_output_t *output, enum pipe pipe); void igt_output_set_scaling_mode(igt_output_t *output, uint64_t scaling_mode); + igt_plane_t *igt_output_get_plane(igt_output_t *output, int plane_idx); igt_plane_t *igt_output_get_plane_type(igt_output_t *output, int plane_type); igt_output_t *igt_output_from_connector(igt_display_t *display, drmModeConnector *connector); +void igt_output_set_writeback_fb(igt_output_t *output, struct igt_fb *fb); +void igt_output_request_writeback_out_fence(igt_output_t *output); +int igt_output_get_last_writeback_out_fence(igt_output_t *output); + igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t *pipe, int plane_type); bool igt_pipe_get_property(igt_pipe_t *pipe, const char *name, uint32_t *prop_id, uint64_t *value, -- 2.13.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx