tools: Add a simple tool to read/write/decode dpcd registers
PATCH v2 1/1 tools: Add a simple tool to read/write/decode dpcd registers
This tool serves as a wrapper around the constructs provided by the drm_dpcd_aux_dev kernel module by working on the /dev/drm_dp_aux[n] devices created by the kernel module.
It supports reading and writing dpcd registers on the connected aux channels.
In the follow-up patch, support for decoding these registers will be added to facilate debugging panel related issues.
--- tools/dpcd_reg.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/meson.build | 1 + 2 files changed, 214 insertions(+) create mode 100644 tools/dpcd_reg.c
tools/dpcd_reg.c new file +213 -0
@@ -0,0 +1,213 @@ +/* +* Copyright © 2018 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* DPCD register read/decode tool +* This tool wraps around DRM_DP_AUX_DEV module to provide DPCD register read, +* write and decode, so CONFIG_DRM_DP_AUX_DEV needs to be set. +*/ + +#include "igt_core.h" +#include <errno.h> +#include <fcntl.h> + +#define INVALID 0xff + +const char aux_dev[] ="/dev/drm_dp_aux" ; + +static void print_usage (char *tool,int help) +{ +igt_info ("DPCD register rw and decode tool\n\n" ); +igt_info ("This tool requires CONFIG_DRM_DP_AUX_CHARDEV\n" +"to be set in the kernel config.\n\n" ); +igt_info ("Usage: %s [OPTION ...] COMMAND\n\n" , tool); +igt_info ("COMMAND is one of:\n" ); +igt_info (" read: Read [count] bytes dpcd reg at an offset\n" ); +igt_info (" write: Write a dpcd reg at an offset\n\n" ); +igt_info ("Options for the above COMMANDS are\n" ); +igt_info (" --device=DEVID Aux device id, as listed in /dev/drm_dp_aux_dev[n]\n" ); +igt_info (" --offset=REG_ADDR DPCD register offset in hex\n" ); +igt_info (" --count=BYTES For reads, specify # of bytes to be read from the offset\n" ); +igt_info (" --val=BYTE For writes, specify a BYTE sized value to be writteni\n\n" ); + +igt_info (" --help: print the usage\n" ); + +exit ((help ==1 )?EXIT_SUCCESS :EXIT_FAILURE ); +} + +static int dpcd_read (char *device,const uint32_t offset,size_t count) +{ +int fd, ret, i; +void *buf =malloc (sizeof (uint8_t ) * count); + +if (NULL != buf) +memset (buf,0 ,sizeof (uint8_t ) * count); +else { +igt_warn ("Can't allocate read buffer\n" ); + ret =EXIT_FAILURE ; + goto out; + } + + fd =open (device,O_RDONLY ); +if (fd >0 ) { + ret =pread (fd, buf, count, offset); +close (fd); +if (ret != count) { +igt_warn ("Failed to read from %s aux device - error %s\n" , device,strerror (errno)); + ret =EXIT_FAILURE ; + goto free_up; + } + +igt_info ("Read %zu byte(s) starting at offset %x\n\n" , count, offset); +for (i =0 ; i < count; i++) +igt_info ("%x\n" , *(((uint8_t *)(buf)) + i)); + } +else { +igt_warn ("Failed to open %s aux device - error: %s\n" , device,strerror (errno)); + ret =EXIT_FAILURE ; + } +free_up: +free (buf); +out: +return ret; +} + +static int dpcd_write (char *device,const uint32_t offset,const uint8_t *val) +{ +int fd, ret; + + fd =open (device,O_RDWR ); +if (fd >0 ) { + ret =pwrite (fd, (const void *)val,sizeof (uint8_t ), offset); +close (fd); +if (ret <0 ) { +igt_warn ("Failed to write to %s aux device - error %s\n" , device,strerror (errno)); + ret =EXIT_FAILURE ; + goto out; + } + ret =dpcd_read (device, offset,sizeof (uint8_t )); + } +else { +igt_warn ("Failed to open %s aux device - error: %s\n" , device,strerror (errno)); + ret =EXIT_FAILURE ; + } +out: +return ret; +} + +int main (int argc,char **argv) +{ +char dev_name[20 ]; +int ret, devid, help_flg; +uint32_t offset; +uint8_t val; +size_t count; + +enum command { +INV =-1 , +READ =2 , +WRITE , + } cmd =INV ; + +struct option longopts [] = { + {"count" , required_argument,NULL ,'c' }, + {"device" , required_argument,NULL ,'d' }, + {"help" , no_argument, &help_flg,2 }, + {"offset" , required_argument,NULL ,'o' }, + {"spec" , optional_argument,NULL ,'s' }, + {"val" , required_argument,NULL ,'v' }, + {0 } + }; + + offset = val = count =INVALID ; + devid =-1 ; + +while ((ret =getopt_long (argc, argv,"-:c:d:o:s::v:" , longopts,NULL )) !=-1 ) { +switch (ret) { +case 'c' : + count =strtoul (optarg,NULL ,10 ); +break ; +case 'd' : + devid =strtoul (optarg,NULL ,10 ); +break ; +case 'o' : + offset =strtoul (optarg,NULL ,16 ); +break ; +case 's' : +/* TO-DO: Parse --spec version */ +break ; +case 'v' : + val =strtoul (optarg,NULL ,16 ); +break ; +/* Fall through for --help */ +case 0 : +break ; +/* Command parsing */ +case 1 : +if (strcmp (optarg,"read" ) ==0 ) + cmd =READ ; +else if (strcmp (optarg,"write" ) ==0 ) + cmd =WRITE ; +break ; +case ':' : +fprintf (stderr,"The -%c option of %s requires an argument\n" , optopt, argv[0 ]); +print_usage (argv[0 ],0 ); +case '?' : +default : +printf ("%s - option %c is invalid\n" , argv[0 ], optopt); +print_usage (argv[0 ],0 ); + } + } + +if (help_flg ==2 ) +print_usage (argv[0 ],1 ); + +if (devid ==-1 || offset ==INVALID ) { +printf ("Aux device id and/or offset missing\n" ); +print_usage (argv[0 ],0 ); + } + +memset (dev_name,'\0' ,20 ); +snprintf (dev_name,sizeof (aux_dev) +2 ,"%s%d" , aux_dev, devid); + +switch (cmd) { +case READ : +if (count ==INVALID ) { +igt_warn ("Please specify the count in bytes\n" ); +print_usage (argv[0 ],0 ); + } + ret =dpcd_read (dev_name, offset, count); +break ; +case WRITE : +if (val ==INVALID ) { +igt_warn ("Write value is missing\n" ); +print_usage (argv[0 ],0 ); + } + ret =dpcd_write (dev_name, offset, &val); +break ; +case INV : +default : +igt_warn ("Please specify a comand: read/write/decode. See usage\n" ); +print_usage (argv[0 ],0 ); + } + +return ret; +}
tools/meson.build +1 -0
@@ -37,6 +37,7 @@ tools_progs = [ 'intel_watermark', 'intel_gem_info', 'intel_gvtg_test', + 'dpcd_reg', ] tool_deps = igt_deps
Signature · 6 lines
2.13.5 _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev
Patchwork
CI[igt-dev] ✓ Fi.CI.BAT: success for tools: Add a simple tool to read/write/decode dpcd registers (rev2)
== Series Details ==
== Series Details ==
Series: tools: Add a simple tool to read/write/decode dpcd registers (rev2)
URL : https://patchwork.freedesktop.org/series/44736/
State : success
== Summary ==
= CI Bug Log - changes from CI_DRM_4314 -> IGTPW_1462 =
== Summary - SUCCESS ==
No regressions found.
External URL: https://patchwork.freedesktop.org/api/1.0/series/44736/revisions/2/mbox/
== Known issues ==
Here are the changes found in IGTPW_1462 that come from known issues:
=== IGT changes ===
==== Issues hit ====
igt@drv_module_reload@basic-reload-inject:
fi-glk-j4005: PASS -> DMESG-WARN (fdo#106248, fdo#106725) +1
igt@kms_addfb_basic@addfb25-modifier-no-flag:
fi-glk-j4005: PASS -> DMESG-WARN (fdo#106000)
igt@kms_flip@basic-flip-vs-wf_vblank:
fi-glk-j4005: PASS -> FAIL (fdo#103928)
igt@kms_frontbuffer_tracking@basic:
fi-hsw-peppy: PASS -> DMESG-FAIL (fdo#102614, fdo#106103)
==== Possible fixes ====
igt@debugfs_test@read_all_entries:
fi-snb-2520m: INCOMPLETE (fdo#103713) -> PASS
igt@gem_exec_suspend@basic-s4-devices:
fi-kbl-7500u: DMESG-WARN (fdo#105128) -> PASS
igt@kms_flip@basic-flip-vs-wf_vblank:
fi-cnl-psr: FAIL (fdo#100368) -> PASS fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
fdo#102614 https://bugs.freedesktop.org/show_bug.cgi?id=102614
fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713
fdo#103928 https://bugs.freedesktop.org/show_bug.cgi?id=103928
fdo#105128 https://bugs.freedesktop.org/show_bug.cgi?id=105128
fdo#106000 https://bugs.freedesktop.org/show_bug.cgi?id=106000
fdo#106103 https://bugs.freedesktop.org/show_bug.cgi?id=106103
fdo#106248 https://bugs.freedesktop.org/show_bug.cgi?id=106248
fdo#106725 https://bugs.freedesktop.org/show_bug.cgi?id=106725
== Participating hosts (44 -> 38) ==
Missing (6): fi-ilk-m540 fi-hsw-4200u fi-cnl-y3 fi-byt-squawks fi-bsw-cyan fi-ctg-p8600
== Build changes ==
* IGT: IGT_4518 -> IGTPW_1462
CI_DRM_4314: 2f4a101babe898ba750fa274dc90db1ede57d59c @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_1462: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1462/
IGT_4518: e4908004547b63131352fbc0ddcdb1d3d55480e0 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1462/issues.html
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Patchwork
CI[igt-dev] ✓ Fi.CI.IGT: success for tools: Add a simple tool to read/write/decode dpcd registers (rev2)
In reply to Tarun Vyas== Series Details ==
== Series Details ==
Series: tools: Add a simple tool to read/write/decode dpcd registers (rev2)
URL : https://patchwork.freedesktop.org/series/44736/
State : success
== Summary ==
= CI Bug Log - changes from IGT_4518_full -> IGTPW_1462_full =
== Summary - WARNING ==
Minor unknown changes coming with IGTPW_1462_full need to be verified manually.
If you think the reported changes have nothing to do with the changes introduced in IGTPW_1462_full, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://patchwork.freedesktop.org/api/1.0/series/44736/revisions/2/mbox/
== Possible new issues ==
Here are the unknown changes that may have been introduced in IGTPW_1462_full:
=== IGT changes ===
==== Warnings ====
igt@gem_mocs_settings@mocs-rc6-bsd2:
shard-kbl: PASS -> SKIP
igt@gem_mocs_settings@mocs-rc6-vebox:
shard-kbl: SKIP -> PASS +2
igt@pm_rc6_residency@rc6-accuracy:
shard-snb: PASS -> SKIP== Known issues ==
Here are the changes found in IGTPW_1462_full that come from known issues:
=== IGT changes ===
==== Issues hit ====
igt@drv_hangman@error-state-sysfs-entry:
shard-snb: PASS -> INCOMPLETE (fdo#105411)
igt@drv_suspend@shrink:
shard-hsw: PASS -> INCOMPLETE (fdo#103540)
igt@kms_flip@2x-plain-flip-fb-recreate-interruptible:
shard-hsw: PASS -> FAIL (fdo#100368)
igt@kms_frontbuffer_tracking@fbc-2p-scndscrn-shrfb-plflip-blt:
shard-glk: PASS -> FAIL (fdo#103167, fdo#104724)
igt@kms_rotation_crc@sprite-rotation-90:
shard-kbl: PASS -> FAIL (fdo#103925, fdo#104724)
igt@kms_setmode@basic:
shard-hsw: PASS -> FAIL (fdo#99912)
==== Possible fixes ====
igt@gem_wait@await-bsd2:
shard-snb: INCOMPLETE (fdo#105411) -> SKIP
igt@kms_atomic_transition@1x-modeset-transitions-nonblocking:
shard-glk: FAIL (fdo#105703) -> PASS
igt@kms_flip@2x-flip-vs-expired-vblank-interruptible:
shard-glk: FAIL (fdo#105363) -> PASS
igt@kms_flip@2x-plain-flip-fb-recreate-interruptible:
shard-glk: FAIL (fdo#100368) -> PASS +1
igt@kms_flip@2x-plain-flip-ts-check:
shard-hsw: FAIL (fdo#100368) -> PASS
igt@kms_rotation_crc@sprite-rotation-180:
shard-snb: FAIL (fdo#103925, fdo#104724) -> PASS
shard-hsw: FAIL (fdo#103925, fdo#104724) -> PASS fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167
fdo#103540 https://bugs.freedesktop.org/show_bug.cgi?id=103540
fdo#103925 https://bugs.freedesktop.org/show_bug.cgi?id=103925
fdo#104724 https://bugs.freedesktop.org/show_bug.cgi?id=104724
fdo#105363 https://bugs.freedesktop.org/show_bug.cgi?id=105363
fdo#105411 https://bugs.freedesktop.org/show_bug.cgi?id=105411
fdo#105703 https://bugs.freedesktop.org/show_bug.cgi?id=105703
fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912
== Participating hosts (5 -> 5) ==
No changes in participating hosts
== Build changes ==
* IGT: IGT_4518 -> IGTPW_1462
* Linux: CI_DRM_4309 -> CI_DRM_4314
CI_DRM_4309: 2740c5b0d0f40092355b329a62ede8cced7f64b9 @ git://anongit.freedesktop.org/gfx-ci/linux
CI_DRM_4314: 2f4a101babe898ba750fa274dc90db1ede57d59c @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_1462: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1462/
IGT_4518: e4908004547b63131352fbc0ddcdb1d3d55480e0 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1462/shards.html
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev