Commit 7beba5bd authored by Maarten Lankhorst's avatar Maarten Lankhorst

lib/igt_kms: Add try_prop_enum and set_prop_enum for mode objects, v2.

This adds the possibility to test arbitrary enumerations in IGT without
having to define mappings for each and every one.

Changes since v1:
- Add commit description.
- Add try_prop_enum, to allow handling unknown enumerations.
Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
Reviewed-by: default avatarMika Kahola <mika.kahola@intel.com>
parent b966dd93
......@@ -2891,6 +2891,48 @@ uint64_t igt_plane_get_prop(igt_plane_t *plane, enum igt_atomic_plane_properties
plane->drm_plane->plane_id, plane->props[prop]);
}
static bool igt_mode_object_get_prop_enum_value(int drm_fd, uint32_t id, const char *str, uint64_t *val)
{
drmModePropertyPtr prop = drmModeGetProperty(drm_fd, id);
int i;
igt_assert(id);
igt_assert(prop);
for (i = 0; i < prop->count_enums; i++)
if (!strcmp(str, prop->enums[i].name)) {
*val = prop->enums[i].value;
drmModeFreeProperty(prop);
return true;
}
return false;
}
bool igt_plane_try_prop_enum(igt_plane_t *plane,
enum igt_atomic_plane_properties prop,
const char *val)
{
igt_display_t *display = plane->pipe->display;
uint64_t uval;
igt_assert(plane->props[prop]);
if (!igt_mode_object_get_prop_enum_value(display->drm_fd,
plane->props[prop], val, &uval))
return false;
igt_plane_set_prop_value(plane, prop, uval);
return true;
}
void igt_plane_set_prop_enum(igt_plane_t *plane,
enum igt_atomic_plane_properties prop,
const char *val)
{
igt_assert(igt_plane_try_prop_enum(plane, prop, val));
}
/**
* igt_plane_replace_prop_blob:
* @plane: plane to set property on.
......@@ -2942,6 +2984,30 @@ uint64_t igt_output_get_prop(igt_output_t *output, enum igt_atomic_connector_pro
output->id, output->props[prop]);
}
bool igt_output_try_prop_enum(igt_output_t *output,
enum igt_atomic_connector_properties prop,
const char *val)
{
igt_display_t *display = output->display;
uint64_t uval;
igt_assert(output->props[prop]);
if (!igt_mode_object_get_prop_enum_value(display->drm_fd,
output->props[prop], val, &uval))
return false;
igt_output_set_prop_value(output, prop, uval);
return true;
}
void igt_output_set_prop_enum(igt_output_t *output,
enum igt_atomic_connector_properties prop,
const char *val)
{
igt_assert(igt_output_try_prop_enum(output, prop, val));
}
/**
* igt_output_replace_prop_blob:
* @output: output to set property on.
......@@ -2993,6 +3059,30 @@ uint64_t igt_pipe_obj_get_prop(igt_pipe_t *pipe, enum igt_atomic_crtc_properties
pipe->crtc_id, pipe->props[prop]);
}
bool igt_pipe_obj_try_prop_enum(igt_pipe_t *pipe_obj,
enum igt_atomic_crtc_properties prop,
const char *val)
{
igt_display_t *display = pipe_obj->display;
uint64_t uval;
igt_assert(pipe_obj->props[prop]);
if (!igt_mode_object_get_prop_enum_value(display->drm_fd,
pipe_obj->props[prop], val, &uval))
return false;
igt_pipe_obj_set_prop_value(pipe_obj, prop, uval);
return true;
}
void igt_pipe_obj_set_prop_enum(igt_pipe_t *pipe_obj,
enum igt_atomic_crtc_properties prop,
const char *val)
{
igt_assert(igt_pipe_obj_try_prop_enum(pipe_obj, prop, val));
}
/**
* igt_pipe_obj_replace_prop_blob:
* @pipe: pipe to set property on.
......
......@@ -574,6 +574,14 @@ uint64_t igt_plane_get_prop(igt_plane_t *plane, enum igt_atomic_plane_properties
igt_plane_set_prop_changed(plane, prop); \
} while (0)
extern bool igt_plane_try_prop_enum(igt_plane_t *plane,
enum igt_atomic_plane_properties prop,
const char *val);
extern void igt_plane_set_prop_enum(igt_plane_t *plane,
enum igt_atomic_plane_properties prop,
const char *val);
extern void igt_plane_replace_prop_blob(igt_plane_t *plane,
enum igt_atomic_plane_properties prop,
const void *ptr, size_t length);
......@@ -609,10 +617,17 @@ uint64_t igt_output_get_prop(igt_output_t *output, enum igt_atomic_connector_pro
igt_output_set_prop_changed(output, prop); \
} while (0)
extern bool igt_output_try_prop_enum(igt_output_t *output,
enum igt_atomic_connector_properties prop,
const char *val);
extern void igt_output_set_prop_enum(igt_output_t *output,
enum igt_atomic_connector_properties prop,
const char *val);
extern void igt_output_replace_prop_blob(igt_output_t *output,
enum igt_atomic_connector_properties prop,
const void *ptr, size_t length);
/**
* igt_pipe_obj_has_prop:
* @pipe: Pipe to check.
......@@ -693,6 +708,20 @@ igt_pipe_has_prop(igt_display_t *display, enum pipe pipe,
#define igt_pipe_set_prop_value(display, pipe, prop, value) \
igt_pipe_obj_set_prop_value(&(display)->pipes[(pipe)], prop, value)
extern bool igt_pipe_obj_try_prop_enum(igt_pipe_t *pipe,
enum igt_atomic_crtc_properties prop,
const char *val);
extern void igt_pipe_obj_set_prop_enum(igt_pipe_t *pipe,
enum igt_atomic_crtc_properties prop,
const char *val);
#define igt_pipe_try_prop_enum(display, pipe, prop, val) \
igt_pipe_obj_try_prop_enum(&(display)->pipes[(pipe)], prop, val)
#define igt_pipe_set_prop_enum(display, pipe, prop, val) \
igt_pipe_obj_set_prop_enum(&(display)->pipes[(pipe)], prop, val)
extern void igt_pipe_obj_replace_prop_blob(igt_pipe_t *pipe,
enum igt_atomic_crtc_properties prop,
const void *ptr, size_t length);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment