Misc fixes and cleanup
cover Misc fixes and cleanup
Hi,
This is not really a series but a set of miscellaneous fixes and cleanup.
It should be mostly noncontroversial, with the exception of perhaps the last two patches.
Patch 6 splits all of the igt_crc code out of igt_debugfs into a separate file. The goal here was to make it easier to add new CRC-related code without falling afoul of churn within igt_debugfs (of which there's been a fair amount while I've been carrying these patches). Eventually, the intention is to add support for igt_crc via writeback connectors here, but I understand if this patch should stay out until then.
Patch 7 allows "video=" on the kernel command-line to override a connector's default mode. I don't know if that's widely useful, but we like to use it on our FPGA platforms.
All comments/feedback welcome,
Thanks,
Brian
Brian Starkey (7):
lib/igt_kms: Fix erroneous assert
lib/igt_kms: Fix override_mode handling
lib: Stop igt_get_all_cairo_formats memory leak lib/igt_debugfs: Remove igt_debugfs_t lib/igt_debugfs: Only use valid values in igt_crc_to_str()
igt: lib/igt_crc: Split out CRC functionality lib/igt_kms: Use kernel command line mode if specified
lib/Makefile.sources | 2 + lib/igt_chamelium.h | 1 + lib/igt_crc.c | 563 +++++++++++++++++++++++++++++++++++++ lib/igt_crc.h | 125 ++++++++ lib/igt_debugfs.c | 551 ------------------------------------ lib/igt_debugfs.h | 81 ------ lib/igt_fb.c | 4 +- lib/igt_fb.h | 2 +- lib/igt_kms.c | 157 ++++++++++- tests/chamelium.c | 1 + tests/kms_atomic.c | 3 +- tests/kms_atomic_transition.c | 1 + tests/kms_ccs.c | 1 + tests/kms_chv_cursor_fail.c | 1 + tests/kms_crtc_background_color.c | 1 + tests/kms_cursor_crc.c | 1 + tests/kms_cursor_legacy.c | 1 + tests/kms_draw_crc.c | 1 + tests/kms_fbc_crc.c | 1 + tests/kms_flip_tiling.c | 1 + tests/kms_frontbuffer_tracking.c | 1 + tests/kms_mmap_write_crc.c | 1 + tests/kms_mmio_vs_cs_flip.c | 1 + tests/kms_pipe_color.c | 1 + tests/kms_pipe_crc_basic.c | 1 + tests/kms_plane.c | 1 + tests/kms_plane_lowres.c | 1 + tests/kms_plane_multiple.c | 1 + tests/kms_plane_scaling.c | 1 + tests/kms_pwrite_crc.c | 1 + tests/kms_render.c | 4 +- tests/kms_rotation_crc.c | 1 + tests/kms_universal_plane.c | 1 + tools/intel_display_crc.c | 1 + 34 files changed, 867 insertions(+), 649 deletions(-) create mode 100644 lib/igt_crc.c create mode 100644 lib/igt_crc.h
Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH RESEND 1/7 lib/igt_kms: Fix erroneous assert
In trying to fix igt_display_init() for devices without cursors, I actually made matters worse. Fix the assert.
--- lib/igt_kms.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/igt_kms.c +5 -5
@@ -1789,11 +1789,11 @@ void igt_display_init(igt_display_t *display, int drm_fd)*/ igt_assert_eq (pipe->plane_primary,0 ); -/* -* There should be no gaps. If there is, something happened -* which we can't handle (e.g. all planes are cursors). -*/ -igt_assert_eq (p, last_plane); +/* Check that we filled every slot exactly once */ +if (display->has_cursor_plane) +igt_assert_eq (p, last_plane); +else +igt_assert_eq (p, n_planes); pipe->n_planes = n_planes;
Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/7 lib/igt_kms: Fix override_mode handling
In reply to Brian Starkeyigt_display_commit isn't refreshing all outputs anymore, which means that an override mode may never get picked up.
Instead of forcing a reprobe to handle copying the override_mode into default_mode, just change igt_output_get_mode() to return the override_mode if it's been set, and remove the old code which would directly overwrite default_mode.
This should be more robust, as igt_output_get_mode() will always return the correct mode, without needing the output to be reprobed.
This change means that output->config.default_mode always contains the "non-overridden" default mode.
--- lib/igt_kms.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
lib/igt_kms.c +4 -8
@@ -1575,9 +1575,6 @@ static void igt_output_refresh(igt_output_t *output)igt_atomic_fill_connector_props (display, output,IGT_NUM_CONNECTOR_PROPS , igt_connector_prop_names); -if (output->use_override_mode) - output->config.default_mode = output->override_mode; -if (output->config.pipe ==PIPE_NONE )return ;
@@ -2816,7 +2813,10 @@ const char *igt_output_name(igt_output_t *output)drmModeModeInfo *igt_output_get_mode (igt_output_t *output) { -return &output->config.default_mode; +if (output->use_override_mode) +return &output->override_mode; +else +return &output->config.default_mode; }/**
@@ -2834,10 +2834,6 @@ void igt_output_override_mode(igt_output_t *output, drmModeModeInfo *mode)if (mode) output->override_mode = *mode; -else /* restore default_mode, may have been overwritten in igt_output_refresh */ -kmstest_get_connector_default_mode (output->display->drm_fd, - output->config.connector, - &output->config.default_mode); output->use_override_mode = !!mode;
Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/7 lib: Stop igt_get_all_cairo_formats memory leak
In reply to Brian Starkeyigt_get_all_cairo_formats() allocates the format list on the heap, but returns it in a const pointer. Change this so that callers can free the array without a warning, and free the array in all callers.
--- lib/igt_fb.c | 4 +++- lib/igt_fb.h | 2 +- tests/kms_atomic.c | 3 ++- tests/kms_render.c | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-)
lib/igt_fb.c +3 -1
@@ -1277,8 +1277,10 @@ const char *igt_format_str(uint32_t drm_format)* * This functions returns an array of all the drm fourcc codes supported by * cairo and this library. +* +* The array should be freed by the caller. */ -void igt_get_all_cairo_formats (const uint32_t **formats,int *format_count) +void igt_get_all_cairo_formats (uint32_t **formats,int *format_count) {static uint32_t *drm_formats;static int n_formats;
lib/igt_fb.h +1 -1
@@ -154,7 +154,7 @@ int igt_cairo_printf_line(cairo_t *cr, enum igt_text_align align,uint32_t igt_bpp_depth_to_drm_format (int bpp,int depth);uint32_t igt_drm_format_to_bpp (uint32_t drm_format);const char *igt_format_str (uint32_t drm_format); -void igt_get_all_cairo_formats (const uint32_t **formats,int *format_count); +void igt_get_all_cairo_formats (uint32_t **formats,int *format_count);#endif /* __IGT_FB_H__ */
tests/kms_atomic.c +2 -1
@@ -807,7 +807,7 @@ static void atomic_state_free(struct kms_atomic_state *state)static uint32_t plane_get_igt_format (struct kms_atomic_plane_state *plane) {drmModePlanePtr plane_kms; -const uint32_t *igt_formats; +uint32_t *igt_formats;uint32_t ret =0 ;int num_igt_formats;int i;
@@ -827,6 +827,7 @@ static uint32_t plane_get_igt_format(struct kms_atomic_plane_state *plane) } } +free (igt_formats);drmModeFreePlane (plane_kms);return ret; }
tests/kms_render.c +3 -1
@@ -176,7 +176,7 @@ static void test_connector(const char *test_name,struct kmstest_connector_config *cconf, enum test_flags flags) { - const uint32_t *formats; + uint32_t *formats;int format_count;int i;
@@ -193,6 +193,8 @@ static void test_connector(const char *test_name, cconf, &cconf->connector->modes[0 ], formats[i], flags); } + +free (formats); }static int run_test (const char *test_name,enum test_flags flags)
Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH i-g-t 3/7] lib: Stop igt_get_all_cairo_formats memory leak
Quoted 76 lines · Brian Starkey
igt_get_all_cairo_formats()allocates the format list on the heap, but returns it in a const pointer. Change this so that callers can free the array without a warning, and free the array in all callers.Signed-off-by Brian Starkey <[email protected]>--- lib/igt_fb.c | 4 +++- lib/igt_fb.h | 2 +- tests/kms_atomic.c | 3 ++- tests/kms_render.c | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-)lib/igt_fb.c +3
-1@@ -1277,8 +1277,10 @@ const char *igt_format_str(uint32_t drm_format)* * This functions returns an array of all the drm fourcc codes supported by * cairo and this library. +* +* The array should be freed by the caller. */ -void igt_get_all_cairo_formats (const uint32_t **formats,int *format_count) +void igt_get_all_cairo_formats (uint32_t **formats,int *format_count) {static uint32_t *drm_formats;static int n_formats;lib/igt_fb.h +1
-1@@ -154,7 +154,7 @@ int igt_cairo_printf_line(cairo_t *cr, enum igt_text_align align,uint32_t igt_bpp_depth_to_drm_format (int bpp,int depth);uint32_t igt_drm_format_to_bpp (uint32_t drm_format);const char *igt_format_str (uint32_t drm_format); -void igt_get_all_cairo_formats (const uint32_t **formats,int *format_count); +void igt_get_all_cairo_formats (uint32_t **formats,int *format_count);#endif /* __IGT_FB_H__ */ tests/kms_atomic.c +2
-1@@ -807,7 +807,7 @@ static void atomic_state_free(struct kms_atomic_state *state)static uint32_t plane_get_igt_format (struct kms_atomic_plane_state *plane) {drmModePlanePtr plane_kms; -const uint32_t *igt_formats; +uint32_t *igt_formats;uint32_t ret =0 ;int num_igt_formats;int i;@@ -827,6 +827,7 @@ static uint32_t plane_get_igt_format(struct kms_atomic_plane_state *plane) } } +free (igt_formats);drmModeFreePlane (plane_kms);return ret; }tests/kms_render.c +1
-1@@ -176,7 +176,7 @@ static void test_connector(const char *test_name,struct kmstest_connector_config *cconf, enum test_flags flags) { - const uint32_t *formats; + uint32_t *formats;int format_count;int i;
tests/kms_render.c static void test_connector(const char *test_name, · line 197
Quoted 5 lines
tests/kms_render.c +2
-0@@ -193,6 +193,8 @@ static void test_connector(const char *test_name, cconf, &cconf->connector->modes[0 ], formats[i], flags); } + +free (formats);
Hi,
Assuming I'm not missing anything, I think if you free formats here, the static variable in igt_get_all_cairo_formats() will point to garbage and further calls to that function will return uninitialized memory.
Signature · 5 lines
Gabriel Krisman Bertazi _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH i-g-t 3/7] lib: Stop igt_get_all_cairo_formats memory leak
Quoted 6 lines · Gabriel Krisman Bertazi
Quoted 4 lines · Brian Starkey
igt_get_all_cairo_formats()allocates the format list on the heap, but returns it in a const pointer. Change this so that callers can free the array without a warning, and free the array in all callers.
Quoted 9 lines
Quoted 2 lines
Signed-off-by Brian Starkey <[email protected]>---
Hi,
Assuming I'm not missing anything, I think if you free formats here, the static variable in
igt_get_all_cairo_formats()will point to garbage and further calls to that function will return uninitialized memory.
Hi!
Yes, sorry you're quite right. I'd managed to completely miss the fact the pointer is static.
Please ignore this patch then,
Thanks,
Brian
Quoted 4 lines
Signature · 2 lines
-- Gabriel Krisman Bertazi
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/7 lib/igt_debugfs: Remove igt_debugfs_t
In reply to Brian StarkeyIt's not used anymore, so remove it.
--- lib/igt_debugfs.c | 5 ----- 1 file changed, 5 deletions(-)
lib/igt_debugfs.c +0 -5
@@ -84,11 +84,6 @@* General debugfs helpers */ -typedef struct { -char root[128 ]; -char dri_path[128 ]; -}igt_debugfs_t ; -static bool is_mountpoint (const char *path) {char buf[strlen (path) +4 ];
Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 5/7 lib/igt_debugfs: Only use valid values in igt_crc_to_str()
In reply to Brian StarkeyNot all elements in the crc array may be valid, so only use the valid ones to generate the string.
--- lib/igt_debugfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
lib/igt_debugfs.c +4 -3
@@ -312,10 +312,11 @@ void igt_assert_crc_equal(const igt_crc_t *a, const igt_crc_t *b)*/ char *igt_crc_to_string (igt_crc_t *crc) { -char buf[128 ]; +int i; +char buf[128 ] = {0 }; -sprintf (buf,"%08x %08x %08x %08x %08x" , crc->crc[0 ], - crc->crc[1 ], crc->crc[2 ], crc->crc[3 ], crc->crc[4 ]); +for (i =0 ; i < crc->n_words; i++) +sprintf (buf +strlen (buf),"%08x " , crc->crc[i]);return strdup (buf); }
Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 6/7 igt: lib/igt_crc: Split out CRC functionality
In reply to Brian StarkeySeparate out the CRC code for better compartmentalisation. Should ease the addition of more/different CRC sources in the future.
--- lib/Makefile.sources | 2 + lib/igt_chamelium.h | 1 + lib/igt_crc.c | 563 +++++++++++++++++++++++++++++++++++++ lib/igt_crc.h | 125 ++++++++ lib/igt_debugfs.c | 547 ----------------------------------- lib/igt_debugfs.h | 81 ------ tests/chamelium.c | 1 + tests/kms_atomic_transition.c | 1 + tests/kms_ccs.c | 1 + tests/kms_chv_cursor_fail.c | 1 + tests/kms_crtc_background_color.c | 1 + tests/kms_cursor_crc.c | 1 + tests/kms_cursor_legacy.c | 1 + tests/kms_draw_crc.c | 1 + tests/kms_fbc_crc.c | 1 + tests/kms_flip_tiling.c | 1 + tests/kms_frontbuffer_tracking.c | 1 + tests/kms_mmap_write_crc.c | 1 + tests/kms_mmio_vs_cs_flip.c | 1 + tests/kms_pipe_color.c | 1 + tests/kms_pipe_crc_basic.c | 1 + tests/kms_plane.c | 1 + tests/kms_plane_lowres.c | 1 + tests/kms_plane_multiple.c | 1 + tests/kms_plane_scaling.c | 1 + tests/kms_pwrite_crc.c | 1 + tests/kms_rotation_crc.c | 1 + tests/kms_universal_plane.c | 1 + tools/intel_display_crc.c | 1 + 29 files changed, 714 insertions(+), 628 deletions(-) create mode 100644 lib/igt_crc.c create mode 100644 lib/igt_crc.h
lib/Makefile.sources +2 -0
@@ -11,6 +11,8 @@ lib_source_list = \ igt_debugfs.h \ igt_aux.c \ igt_aux.h \ + igt_crc.c \ + igt_crc.h \ igt_edid_template.h \ igt_gt.c \ igt_gt.h \
lib/igt_chamelium.h +1 -0
@@ -28,6 +28,7 @@#include "config.h" #include "igt.h" +#include "igt_crc.h" #include <stdbool.h> struct chamelium ;
lib/igt_crc.c new file +563 -0
563 lines not on this page · raw message
lib/igt_crc.h new file +125 -0
125 lines not on this page · raw message
lib/igt_debugfs.c +0 -547
565 lines not on this page · raw message
lib/igt_debugfs.h +0 -81
93 lines not on this page · raw message
tests/chamelium.c +1 -0
@@ -26,6 +26,7 @@#include "config.h" #include "igt.h" +#include "igt_crc.h" #include <fcntl.h> #include <string.h>
tests/kms_atomic_transition.c +1 -0
@@ -22,6 +22,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include "drmtest.h" #include "sw_sync.h" #include <errno.h>
tests/kms_ccs.c +1 -0
@@ -23,6 +23,7 @@*/ #include "igt.h" +#include "igt_crc.h" IGT_TEST_DESCRIPTION ("Test render compression (RC), in which the main surface " "is complemented by a color control surface (CCS) that "
tests/kms_chv_cursor_fail.c +1 -0
@@ -23,6 +23,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include <errno.h> #include <limits.h> #include <stdbool.h>
tests/kms_crtc_background_color.c +1 -0
@@ -23,6 +23,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include <math.h>
tests/kms_cursor_crc.c +1 -0
@@ -23,6 +23,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include <errno.h> #include <limits.h> #include <stdbool.h>
tests/kms_cursor_legacy.c +1 -0
@@ -27,6 +27,7 @@#include <sys/poll.h> #include "igt.h" +#include "igt_crc.h" #include "igt_rand.h" #include "igt_stats.h"
tests/kms_draw_crc.c +1 -0
@@ -25,6 +25,7 @@/* This program tests whether the igt_draw library actually works. */ #include "igt.h" +#include "igt_crc.h" #define MAX_CONNECTORS 32
tests/kms_fbc_crc.c +1 -0
@@ -23,6 +23,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include <errno.h> #include <stdbool.h> #include <stdio.h>
tests/kms_flip_tiling.c +1 -0
@@ -25,6 +25,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include <errno.h> #include <stdbool.h> #include <stdio.h>
tests/kms_frontbuffer_tracking.c +1 -0
@@ -25,6 +25,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include "igt_sysfs.h" #include <sys/types.h> #include <sys/stat.h>
tests/kms_mmap_write_crc.c +1 -0
@@ -31,6 +31,7 @@#include <string.h> #include "drmtest.h" +#include "igt_crc.h" #include "igt_debugfs.h" #include "igt_kms.h" #include "intel_chipset.h"
tests/kms_mmio_vs_cs_flip.c +1 -0
@@ -22,6 +22,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include <errno.h> #include <stdbool.h> #include <stdio.h>
tests/kms_pipe_color.c +1 -0
@@ -28,6 +28,7 @@#include "drm.h" #include "drmtest.h" #include "igt.h" +#include "igt_crc.h" IGT_TEST_DESCRIPTION ("Test Color Features at Pipe level" );
tests/kms_pipe_crc_basic.c +1 -0
@@ -23,6 +23,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include "igt_sysfs.h" #include <errno.h> #include <stdbool.h>
tests/kms_plane.c +1 -0
@@ -25,6 +25,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include <errno.h> #include <stdbool.h> #include <stdio.h>
tests/kms_plane_lowres.c +1 -0
@@ -23,6 +23,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include "drmtest.h" #include <errno.h> #include <stdbool.h>
tests/kms_plane_multiple.c +1 -0
@@ -23,6 +23,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include "drmtest.h" #include <errno.h> #include <stdbool.h>
tests/kms_plane_scaling.c +1 -0
@@ -23,6 +23,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include <math.h>
tests/kms_pwrite_crc.c +1 -0
@@ -23,6 +23,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include <errno.h> #include <limits.h> #include <stdbool.h>
tests/kms_rotation_crc.c +1 -0
@@ -23,6 +23,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include <math.h> #define MAX_FENCES 32
tests/kms_universal_plane.c +1 -0
@@ -22,6 +22,7 @@*/ #include "igt.h" +#include "igt_crc.h" #include <errno.h> #include <stdbool.h> #include <stdio.h>
tools/intel_display_crc.c +1 -0
@@ -30,6 +30,7 @@#include <unistd.h> #include "igt_core.h" +#include "igt_crc.h" #include "igt_debugfs.h" #include "igt_kms.h"
Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 7/7 lib/igt_kms: Use kernel command line mode if specified
In reply to Brian StarkeyIf "video=" is specified on the kernel command-line, use it to override the default mode in kmstest_get_connector_default_mode.
If a mode override was provided on the command-line, it was probably for good reason so we should honor it.
--- lib/igt_kms.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+)
lib/igt_kms.c +135 -0
@@ -766,6 +766,131 @@ void kmstest_force_edid(int drm_fd, drmModeConnector *connector,igt_assert (ret !=-1 ); } +/* +* Extract xres, yres, refresh and interlaced from a string of the form: +* <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd] +* xres and yres must be specified, refresh is optional and will be set to +* -1 if not present. interlaced defaults to false. +*/ +static int parse_cmdline_mode (char *video_str,unsigned int *xres, +unsigned int *yres, +int *refresh,bool *interlaced) +{ +int match, len =strlen (video_str); +char *token =strtok (video_str,"@" ); + +if (!token) +return -1 ; + + *interlaced = false; + *refresh =-1 ; + + match =sscanf (token,"%dx%d" , xres, yres); +if (match !=2 ) +return -1 ; + +if (strlen (token) < len -1 ) { + token +=strlen (token) +1 ; + + match =sscanf (token,"%d" , refresh); +if (match !=1 || (*refresh <0 )) +return -1 ; + +if (strchr (token,'i' )) + *interlaced = true; + } + +return 0 ; +} + +static const drmModeModeInfo * +connector_match_cmdline_mode (const drmModeConnector *connector, +unsigned int xres,unsigned int yres,int refresh, +bool interlaced) +{ +const drmModeModeInfo *mode =NULL ; +int i; + +for (i =0 ; i < connector->count_modes; i++) { + mode = &connector->modes[i]; +if (mode->hdisplay == xres && + mode->vdisplay == yres && + (refresh <0 || refresh == mode->vrefresh) && + interlaced == !!(mode->flags &DRM_MODE_FLAG_INTERLACE )) +return mode; + } + +return NULL ; +} + +static const drmModeModeInfo * +kmstest_get_cmdline_mode (int drm_fd,drmModeConnector *connector) +{ +char c, *str =NULL , *cursor, *conn_name =NULL ; +const drmModeModeInfo *mode =NULL ; +unsigned int size =0 ; +FILE *fp =NULL ; + + fp =fopen ("/proc/cmdline" ,"r" ); +if (!fp) +return NULL ; + +/* lseek/fseek+ftell/stat don't work on /proc/cmdline */ +while (fread (&c,1 ,1 , fp)) + size++; +rewind (fp); + + str =calloc (1 , size +1 ); +if (!str) + goto done; + +if (fread (str,1 , size, fp) != size) + goto done; + +if (!asprintf (&conn_name,"%s-%d:" , +kmstest_connector_type_str (connector->connector_type), + connector->connector_type_id)) + goto done; + + cursor = str; +while ((cursor =strstr (cursor,"video=" ))) { +unsigned int xres, yres; +bool interlaced; +int refresh; + + cursor +=strlen ("video=" ); + cursor =strtok (cursor," \n" ); +if (!cursor) +break ; + +/* Strip the name if it matches ours */ +if (!strncmp (cursor, conn_name,strlen (conn_name))) + cursor +=strlen (conn_name); + +/* +* Consider this "video=" specification only if it has no +* name. If the name matched, we would have already stripped it +* above +*/ +if (!strstr (cursor,":" ) && + !parse_cmdline_mode (cursor, &xres, &yres, &refresh, &interlaced)) { + mode =connector_match_cmdline_mode (connector, xres, + yres, refresh, + interlaced); +if (mode) +break ; + } + + cursor +=strlen (cursor) +1 ; + } + +done: +free (conn_name); +free (str); +fclose (fp); +return mode; +} +/** * kmstest_get_connector_default_mode: * @drm_fd: DRM fd
@@ -773,6 +898,8 @@ void kmstest_force_edid(int drm_fd, drmModeConnector *connector,* @mode: libdrm mode * * Retrieves the default mode for @connector and stores it in @mode. +* If video= is specified (optionally for this specific connector) on the +* kernel command line, then it is used as the default. * * Returns: true on success, false on failure */
@@ -780,6 +907,7 @@ bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector, drmModeModeInfo *mode) {int i; +const drmModeModeInfo *cmdline_mode;if (!connector->count_modes) { igt_warn("no modes for connector %d\n",
@@ -787,6 +915,13 @@ bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,return false; } + cmdline_mode =kmstest_get_cmdline_mode (drm_fd, connector); +if (cmdline_mode) { + *mode = *cmdline_mode; +igt_debug ("Using cmdline mode\n" ); +return true; + } +for (i =0 ; i < connector->count_modes; i++) {if (i ==0 || connector->modes[i].type &DRM_MODE_TYPE_PREFERRED ) {
Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH i-g-t 7/7] lib/igt_kms: Use kernel command line mode if specified
Quoted 5 lines · Brian Starkey
If "video=" is specified on the kernel command-line, use it to override the default mode in
kmstest_get_connector_default_mode.If a mode override was provided on the command-line, it was probably for good reason so we should honor it.
Isn't the kernel marking the cmdline mode as preferred already? And if not, maybe it should.
Quoted 180 lines
Signed-off-by Brian Starkey <[email protected]>--- lib/igt_kms.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+)lib/igt_kms.c +135
-0@@ -766,6 +766,131 @@ void kmstest_force_edid(int drm_fd, drmModeConnector *connector,igt_assert (ret !=-1 ); } +/* +* Extract xres, yres, refresh and interlaced from a string of the form: +* <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd] +* xres and yres must be specified, refresh is optional and will be set to +* -1 if not present. interlaced defaults to false. +*/ +static int parse_cmdline_mode (char *video_str,unsigned int *xres, +unsigned int *yres, +int *refresh,bool *interlaced) +{ +int match, len =strlen (video_str); +char *token =strtok (video_str,"@" ); + +if (!token) +return -1 ; + + *interlaced = false; + *refresh =-1 ; + + match =sscanf (token,"%dx%d" , xres, yres); +if (match !=2 ) +return -1 ; + +if (strlen (token) < len -1 ) { + token +=strlen (token) +1 ; + + match =sscanf (token,"%d" , refresh); +if (match !=1 || (*refresh <0 )) +return -1 ; + +if (strchr (token,'i' )) + *interlaced = true; + } + +return 0 ; +} + +static const drmModeModeInfo * +connector_match_cmdline_mode (const drmModeConnector *connector, +unsigned int xres,unsigned int yres,int refresh, +bool interlaced) +{ +const drmModeModeInfo *mode =NULL ; +int i; + +for (i =0 ; i < connector->count_modes; i++) { + mode = &connector->modes[i]; +if (mode->hdisplay == xres && + mode->vdisplay == yres && + (refresh <0 || refresh == mode->vrefresh) && + interlaced == !!(mode->flags &DRM_MODE_FLAG_INTERLACE )) +return mode; + } + +return NULL ; +} + +static const drmModeModeInfo * +kmstest_get_cmdline_mode (int drm_fd,drmModeConnector *connector) +{ +char c, *str =NULL , *cursor, *conn_name =NULL ; +const drmModeModeInfo *mode =NULL ; +unsigned int size =0 ; +FILE *fp =NULL ; + + fp =fopen ("/proc/cmdline" ,"r" ); +if (!fp) +return NULL ; + +/* lseek/fseek+ftell/stat don't work on /proc/cmdline */ +while (fread (&c,1 ,1 , fp)) + size++; +rewind (fp); + + str =calloc (1 , size +1 ); +if (!str) + goto done; + +if (fread (str,1 , size, fp) != size) + goto done; + +if (!asprintf (&conn_name,"%s-%d:" , +kmstest_connector_type_str (connector->connector_type), + connector->connector_type_id)) + goto done; + + cursor = str; +while ((cursor =strstr (cursor,"video=" ))) { +unsigned int xres, yres; +bool interlaced; +int refresh; + + cursor +=strlen ("video=" ); + cursor =strtok (cursor," \n" ); +if (!cursor) +break ; + +/* Strip the name if it matches ours */ +if (!strncmp (cursor, conn_name,strlen (conn_name))) + cursor +=strlen (conn_name); + +/* +* Consider this "video=" specification only if it has no +* name. If the name matched, we would have already stripped it +* above +*/ +if (!strstr (cursor,":" ) && + !parse_cmdline_mode (cursor, &xres, &yres, &refresh, &interlaced)) { + mode =connector_match_cmdline_mode (connector, xres, + yres, refresh, + interlaced); +if (mode) +break ; + } + + cursor +=strlen (cursor) +1 ; + } + +done: +free (conn_name); +free (str); +fclose (fp); +return mode; +} +/** * kmstest_get_connector_default_mode: * @drm_fd: DRM fd @@ -773,6 +898,8 @@ void kmstest_force_edid(int drm_fd, drmModeConnector *connector,* @mode: libdrm mode * * Retrieves the default mode for @connector and stores it in @mode. +* If video= is specified (optionally for this specific connector) on the +* kernel command line, then it is used as the default. * * Returns: true on success, false on failure */ @@ -780,6 +907,7 @@ bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector, drmModeModeInfo *mode) {int i; +const drmModeModeInfo *cmdline_mode;if (!connector->count_modes) { igt_warn("no modes for connector %d\n",@@ -787,6 +915,13 @@ bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,return false; } + cmdline_mode =kmstest_get_cmdline_mode (drm_fd, connector); +if (cmdline_mode) { + *mode = *cmdline_mode; +igt_debug ("Using cmdline mode\n" ); +return true; + } +for (i =0 ; i < connector->count_modes; i++) {if (i ==0 || connector->modes[i].type &DRM_MODE_TYPE_PREFERRED ) {Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH i-g-t 7/7] lib/igt_kms: Use kernel command line mode if specified
Quoted 10 lines · Ville Syrjälä
Quoted 5 lines · Brian Starkey
If "video=" is specified on the kernel command-line, use it to override the default mode in
kmstest_get_connector_default_mode.If a mode override was provided on the command-line, it was probably for good reason so we should honor it.
Isn't the kernel marking the cmdline mode as preferred already? And if not, maybe it should.
It doesn't as far as I've seen. It uses the cmdline mode for setting up the fbdev emulation but I don't think it marks the mode list (or we aren't calling the helper that does it).
I'll have a look at what it would take to do that.
-Brian
Quoted 176 lines
Quoted 176 lines
Signed-off-by Brian Starkey <[email protected]>--- lib/igt_kms.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+)lib/igt_kms.c +135
-1@@ -766,6 +766,131 @@ void kmstest_force_edid(int drm_fd, drmModeConnector *connector,igt_assert (ret !=-1 ); } +/* +* Extract xres, yres, refresh and interlaced from a string of the form: +* <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd] +* xres and yres must be specified, refresh is optional and will be set to +* -1 if not present. interlaced defaults to false. +*/ +static int parse_cmdline_mode (char *video_str,unsigned int *xres, +unsigned int *yres, +int *refresh,bool *interlaced) +{ +int match, len =strlen (video_str); +char *token =strtok (video_str,"@" ); + +if (!token) +return -1 ; + + *interlaced = false; + *refresh =-1 ; + + match =sscanf (token,"%dx%d" , xres, yres); +if (match !=2 ) +return -1 ; + +if (strlen (token) < len -1 ) { + token +=strlen (token) +1 ; + + match =sscanf (token,"%d" , refresh); +if (match !=1 || (*refresh <0 )) +return -1 ; + +if (strchr (token,'i' )) + *interlaced = true; + } + +return 0 ; +} + +static const drmModeModeInfo * +connector_match_cmdline_mode (const drmModeConnector *connector, +unsigned int xres,unsigned int yres,int refresh, +bool interlaced) +{ +const drmModeModeInfo *mode =NULL ; +int i; + +for (i =0 ; i < connector->count_modes; i++) { + mode = &connector->modes[i]; +if (mode->hdisplay == xres && + mode->vdisplay == yres && + (refresh <0 || refresh == mode->vrefresh) && + interlaced == !!(mode->flags &DRM_MODE_FLAG_INTERLACE )) +return mode; + } + +return NULL ; +} + +static const drmModeModeInfo * +kmstest_get_cmdline_mode (int drm_fd,drmModeConnector *connector) +{ +char c, *str =NULL , *cursor, *conn_name =NULL ; +const drmModeModeInfo *mode =NULL ; +unsigned int size =0 ; +FILE *fp =NULL ; + + fp =fopen ("/proc/cmdline" ,"r" ); +if (!fp) +return NULL ; + +/* lseek/fseek+ftell/stat don't work on /proc/cmdline */ +while (fread (&c,1 ,1 , fp)) + size++; +rewind (fp); + + str =calloc (1 , size +1 ); +if (!str) + goto done; + +if (fread (str,1 , size, fp) != size) + goto done; + +if (!asprintf (&conn_name,"%s-%d:" , +kmstest_connector_type_str (connector->connector_type), + connector->connector_type_id)) + goto done; + + cursor = str; +while ((cursor =strstr (cursor,"video=" ))) { +unsigned int xres, yres; +bool interlaced; +int refresh; + + cursor +=strlen ("video=" ); + cursor =strtok (cursor," \n" ); +if (!cursor) +break ; + +/* Strip the name if it matches ours */ +if (!strncmp (cursor, conn_name,strlen (conn_name))) + cursor +=strlen (conn_name); + +/* +* Consider this "video=" specification only if it has no +* name. If the name matched, we would have already stripped it +* above +*/ +if (!strstr (cursor,":" ) && + !parse_cmdline_mode (cursor, &xres, &yres, &refresh, &interlaced)) { + mode =connector_match_cmdline_mode (connector, xres, + yres, refresh, + interlaced); +if (mode) +break ; + } + + cursor +=strlen (cursor) +1 ; + } + +done: +free (conn_name); +free (str); +fclose (fp); +return mode; +} +/** * kmstest_get_connector_default_mode: * @drm_fd: DRM fd @@ -773,6 +898,8 @@ void kmstest_force_edid(int drm_fd, drmModeConnector *connector,* @mode: libdrm mode * * Retrieves the default mode for @connector and stores it in @mode. +* If video= is specified (optionally for this specific connector) on the +* kernel command line, then it is used as the default. * * Returns: true on success, false on failure */ @@ -780,6 +907,7 @@ bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector, drmModeModeInfo *mode) {int i; +const drmModeModeInfo *cmdline_mode;if (!connector->count_modes) { igt_warn("no modes for connector %d\n",@@ -787,6 +915,13 @@ bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,return false; } + cmdline_mode =kmstest_get_cmdline_mode (drm_fd, connector); +if (cmdline_mode) { + *mode = *cmdline_mode; +igt_debug ("Using cmdline mode\n" ); +return true; + } +for (i =0 ; i < connector->count_modes; i++) {if (i ==0 || connector->modes[i].type &DRM_MODE_TYPE_PREFERRED ) { --1.7.9.5
Quoted 8 lines
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfxSignature · 2 lines
Ville Syrjälä Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx