All of lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t v5] tools: Add a simple tool to read/write/decode dpcd registers
@ 2018-10-04 21:50 Tarun Vyas
  2018-10-04 22:44 ` [igt-dev] ✓ Fi.CI.BAT: success for tools: Add a simple tool to read/write/decode dpcd registers (rev6) Patchwork
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Tarun Vyas @ 2018-10-04 21:50 UTC (permalink / raw)
  To: igt-dev; +Cc: dhinakaran.pandiyan, rodrigo.vivi

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.

v2: (Fixes by Rodrigo but no functional changes yet):
    - Indentations, Typo, Missed spaces
    - Removing mentioning to decode and spec that is not implemented yet.
    - Add Makefile.sources back
    - Missed s/printf/igt_warn

v3:
    - Address DK's review comments from v2 above.
    - Squash Rodrigo's file handling unification patch.
    - Make count, offset and device id optional.

v4:
    - Better error handling and refactoring.

Suggested-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
Signed-off-by: Tarun Vyas <tarun.vyas@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
---
 tools/Makefile.sources |   1 +
 tools/dpcd_reg.c       | 280 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/meson.build      |   1 +
 3 files changed, 282 insertions(+)
 create mode 100644 tools/dpcd_reg.c

diff --git a/tools/Makefile.sources b/tools/Makefile.sources
index abd23a0f..50706f41 100644
--- a/tools/Makefile.sources
+++ b/tools/Makefile.sources
@@ -7,6 +7,7 @@ noinst_PROGRAMS =		\
 
 tools_prog_lists =		\
 	igt_stats		\
+	dpcd_reg		\
 	intel_audio_dump	\
 	intel_reg		\
 	intel_backlight		\
diff --git a/tools/dpcd_reg.c b/tools/dpcd_reg.c
new file mode 100644
index 00000000..d577aa55
--- /dev/null
+++ b/tools/dpcd_reg.c
@@ -0,0 +1,280 @@
+/*
+ * 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/write tool
+ * This tool wraps around DRM_DP_AUX_DEV module to provide DPCD register read
+ * and write, so CONFIG_DRM_DP_AUX_DEV needs to be set.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <limits.h>
+#include <stdbool.h>
+
+#define MAX_DP_OFFSET	0xfffff
+#define DRM_AUX_MINORS	256
+
+const char aux_dev[] = "/dev/drm_dp_aux";
+
+struct dpcd_data {
+	int devid;
+	int file_op;
+	uint32_t offset;
+	enum command {
+		INVALID = -1,
+		READ = 2,
+		WRITE,
+	} cmd;
+	size_t count;
+	uint8_t val;
+};
+
+static void print_usage(void)
+{
+	printf("Usage: dpcd_reg [OPTION ...] COMMAND\n\n");
+	printf("COMMAND is one of:\n");
+	printf("  read:		Read [count] bytes dpcd reg at an offset\n");
+	printf("  write:	Write a dpcd reg at an offset\n\n");
+	printf("Options for the above COMMANDS are\n");
+	printf(" --device=DEVID		Aux device id, as listed in /dev/drm_dp_aux_dev[n]. Defaults to 0. Upper limit - 256\n");
+	printf(" --offset=REG_ADDR	DPCD register offset in hex. Defaults to 0x0. Upper limit - 0xfffff\n");
+	printf(" --count=BYTES		For reads, specify number of bytes to be read from the offset. Defaults to 1\n");
+	printf(" --value		For writes, specify a hex value to be written. Upper limit - 0xff\n\n");
+
+	printf(" --help: print the usage\n");
+}
+
+static inline bool strtol_err_util(char *endptr, long *val)
+{
+	if (*endptr != '\0' || *val < 0 ||
+	    (*val == LONG_MAX && errno == ERANGE))
+		return true;
+
+	return false;
+}
+
+static int parse_opts(struct dpcd_data *dpcd, int argc, char **argv)
+{
+	int ret, vflag = 0;
+	long temp;
+	char *endptr;
+
+	struct option longopts[] = {
+		{ "count",	required_argument,	NULL,		'c' },
+		{ "device",	required_argument,	NULL,		'd' },
+		{ "help",	no_argument,		NULL,		'h' },
+		{ "offset",	required_argument,	NULL,		'o' },
+		{ "value",	required_argument,	NULL,		'v' },
+		{ 0 }
+	};
+
+	while ((ret = getopt_long(argc, argv, "-:c:d:ho:v:", longopts, NULL)) != -1) {
+		switch (ret) {
+		case 'c':
+			temp = strtol(optarg, &endptr, 10);
+			if (strtol_err_util(endptr, &temp)) {
+				fprintf(stderr,
+					"--count argument is invalid/negative/out-of-range\n");
+				print_usage();
+				return EXIT_FAILURE;
+			}
+			dpcd->count = temp;
+			break;
+		case 'd':
+			temp = strtol(optarg, &endptr, 10);
+			if (strtol_err_util(endptr, &temp) ||
+					    temp > DRM_AUX_MINORS) {
+				fprintf(stderr,
+					"--device argument is invalid/negative/out-of-range\n");
+				print_usage();
+				return ERANGE;
+			}
+			dpcd->devid = temp;
+			break;
+		case 'h':
+			printf("DPCD register read and write tool\n\n");
+			printf("This tool requires CONFIG_DRM_DP_AUX_CHARDEV\n"
+				"to be set in the kernel config.\n\n");
+			print_usage();
+			exit(EXIT_SUCCESS);
+		case 'o':
+			temp = strtol(optarg, &endptr, 16);
+			if (strtol_err_util(endptr, &temp) ||
+					    temp > MAX_DP_OFFSET) {
+				fprintf(stderr,
+					"--offset argument is invalid/negative/out-of-range\n");
+				print_usage();
+				return ERANGE;
+			}
+			dpcd->offset = temp;
+			break;
+		case 'v':
+			vflag = 'v';
+			temp = strtol(optarg, &endptr, 16);
+			if (strtol_err_util(endptr, &temp) || temp > 0xff) {
+				fprintf(stderr,
+					"--value argument is invalid/negative/out-of-range\n");
+				print_usage();
+				return ERANGE;
+			}
+			dpcd->val = temp;
+			break;
+		/* Command parsing */
+		case 1:
+			if (strcmp(optarg, "read") == 0) {
+				temp = READ;
+			} else if (strcmp(optarg, "write") == 0) {
+				temp = WRITE;
+				dpcd->file_op = O_WRONLY;
+			} else {
+				fprintf(stderr, "Unrecognized command\n");
+				print_usage();
+				return EXIT_FAILURE;
+			}
+			dpcd->cmd = temp;
+			break;
+		case ':':
+			fprintf(stderr, "Option -%c requires an argument\n",
+				 optopt);
+			print_usage();
+			return EXIT_FAILURE;
+		default:
+			fprintf(stderr, "Invalid option\n");
+			print_usage();
+			return EXIT_FAILURE;
+		}
+	}
+
+	if ((dpcd->count + dpcd->offset) > (MAX_DP_OFFSET + 1)) {
+		fprintf(stderr, "Out of bounds. Count + Offset <= 0x100000\n");
+		return ERANGE;
+	}
+
+	if ((dpcd->cmd == WRITE) && (vflag != 'v')) {
+		fprintf(stderr, "Write value is missing\n");
+		print_usage();
+		return EXIT_FAILURE;
+	}
+
+	return EXIT_SUCCESS;
+}
+
+static int dpcd_read(int fd, uint32_t offset, size_t count)
+{
+	int ret = EXIT_SUCCESS, pret, i;
+	uint8_t *buf = calloc(count, sizeof(uint8_t));
+
+	if (!buf) {
+		fprintf(stderr, "Can't allocate read buffer\n");
+		return ENOMEM;
+	}
+
+	pret = pread(fd, buf, count, offset);
+	if (pret < 0) {
+		fprintf(stderr, "Failed to read - %s\n", strerror(errno));
+		ret = errno;
+		goto out;
+	}
+
+	if (pret < count) {
+		fprintf(stderr,
+			"Read %u byte(s), expected %zu bytes, starting at offset %x\n\n", pret, count, offset);
+		ret = EXIT_FAILURE;
+	}
+
+	printf("0x%02x: ", offset);
+	for (i = 0; i < pret; i++)
+		printf(" %02x", *(buf + i));
+	printf("\n");
+
+out:
+	free(buf);
+	return ret;
+}
+
+static int dpcd_write(int fd, uint32_t offset, uint8_t val)
+{
+	int ret = EXIT_SUCCESS, pret;
+
+	pret = pwrite(fd, (const void *)&val, sizeof(uint8_t), offset);
+	if (pret < 0) {
+		fprintf(stderr, "Failed to write - %s\n", strerror(errno));
+		ret = errno;
+	} else if (pret == 0) {
+		fprintf(stderr, "Zero bytes were written\n");
+		ret = EXIT_FAILURE;
+	}
+
+	return ret;
+}
+
+int main(int argc, char **argv)
+{
+	char dev_name[20];
+	int ret, fd;
+
+	struct dpcd_data dpcd = {
+		.devid = 0,
+		.file_op = O_RDONLY,
+		.offset = 0x0,
+		.cmd = INVALID,
+		.count = 1,
+	};
+
+	ret = parse_opts(&dpcd, argc, argv);
+	if (ret != EXIT_SUCCESS)
+		return ret;
+
+	snprintf(dev_name, strlen(aux_dev) + 4, "%s%d", aux_dev, dpcd.devid);
+
+	fd = open(dev_name, dpcd.file_op);
+	if (fd < 0) {
+		fprintf(stderr,
+			"Failed to open %s aux device - error: %s\n", dev_name,
+			strerror(errno));
+		return errno;
+	}
+
+	switch (dpcd.cmd) {
+	case READ:
+		ret = dpcd_read(fd, dpcd.offset, dpcd.count);
+		break;
+	case WRITE:
+		ret = dpcd_write(fd, dpcd.offset, dpcd.val);
+		break;
+	default:
+		fprintf(stderr, "Please specify a command: read/write.\n");
+		print_usage();
+		ret = EXIT_FAILURE;
+		break;
+	}
+
+	close(fd);
+
+	return ret;
+}
diff --git a/tools/meson.build b/tools/meson.build
index e4517d66..79f36aa9 100644
--- a/tools/meson.build
+++ b/tools/meson.build
@@ -36,6 +36,7 @@ tools_progs = [
 	'intel_watermark',
 	'intel_gem_info',
 	'intel_gvtg_test',
+	'dpcd_reg',
 ]
 tool_deps = igt_deps
 
-- 
2.14.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [igt-dev] ✓ Fi.CI.BAT: success for tools: Add a simple tool to read/write/decode dpcd registers (rev6)
  2018-10-04 21:50 [igt-dev] [PATCH i-g-t v5] tools: Add a simple tool to read/write/decode dpcd registers Tarun Vyas
@ 2018-10-04 22:44 ` Patchwork
  2018-10-05  5:12 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
  2018-10-05 17:54 ` [igt-dev] [PATCH i-g-t v5] tools: Add a simple tool to read/write/decode dpcd registers Dhinakaran Pandiyan
  2 siblings, 0 replies; 5+ messages in thread
From: Patchwork @ 2018-10-04 22:44 UTC (permalink / raw)
  To: Tarun Vyas; +Cc: igt-dev

== Series Details ==

Series: tools: Add a simple tool to read/write/decode dpcd registers (rev6)
URL   : https://patchwork.freedesktop.org/series/44736/
State : success

== Summary ==

= CI Bug Log - changes from CI_DRM_4931 -> IGTPW_1913 =

== Summary - SUCCESS ==

  No regressions found.

  External URL: https://patchwork.freedesktop.org/api/1.0/series/44736/revisions/6/mbox/

== Known issues ==

  Here are the changes found in IGTPW_1913 that come from known issues:

  === IGT changes ===

    ==== Issues hit ====

    igt@gem_exec_suspend@basic-s3:
      fi-blb-e6850:       PASS -> INCOMPLETE (fdo#107718)

    
    ==== Possible fixes ====

    igt@gem_ctx_param@basic-default:
      fi-pnv-d510:        INCOMPLETE (fdo#106007) -> SKIP

    igt@kms_pipe_crc_basic@hang-read-crc-pipe-a:
      fi-byt-clapper:     FAIL (fdo#107362, fdo#103191) -> PASS

    igt@kms_pipe_crc_basic@read-crc-pipe-a:
      fi-byt-clapper:     FAIL (fdo#107362) -> PASS

    igt@kms_pipe_crc_basic@suspend-read-crc-pipe-b:
      fi-cfl-8109u:       INCOMPLETE (fdo#108126, fdo#106070) -> PASS

    
  fdo#103191 https://bugs.freedesktop.org/show_bug.cgi?id=103191
  fdo#106007 https://bugs.freedesktop.org/show_bug.cgi?id=106007
  fdo#106070 https://bugs.freedesktop.org/show_bug.cgi?id=106070
  fdo#107362 https://bugs.freedesktop.org/show_bug.cgi?id=107362
  fdo#107718 https://bugs.freedesktop.org/show_bug.cgi?id=107718
  fdo#108126 https://bugs.freedesktop.org/show_bug.cgi?id=108126


== Participating hosts (48 -> 40) ==

  Missing    (8): fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-icl-u2 fi-bwr-2160 fi-bsw-cyan fi-ctg-p8600 fi-kbl-7560u 


== Build changes ==

    * IGT: IGT_4667 -> IGTPW_1913

  CI_DRM_4931: 826702bf60ae2b37841c051ed769b44af194fbb1 @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_1913: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1913/
  IGT_4667: 596f48dcd59fd2f8c16671514f3e69d4a2891374 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1913/issues.html
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [igt-dev] ✓ Fi.CI.IGT: success for tools: Add a simple tool to read/write/decode dpcd registers (rev6)
  2018-10-04 21:50 [igt-dev] [PATCH i-g-t v5] tools: Add a simple tool to read/write/decode dpcd registers Tarun Vyas
  2018-10-04 22:44 ` [igt-dev] ✓ Fi.CI.BAT: success for tools: Add a simple tool to read/write/decode dpcd registers (rev6) Patchwork
@ 2018-10-05  5:12 ` Patchwork
  2018-10-05 17:54 ` [igt-dev] [PATCH i-g-t v5] tools: Add a simple tool to read/write/decode dpcd registers Dhinakaran Pandiyan
  2 siblings, 0 replies; 5+ messages in thread
From: Patchwork @ 2018-10-05  5:12 UTC (permalink / raw)
  To: Tarun Vyas; +Cc: igt-dev

== Series Details ==

Series: tools: Add a simple tool to read/write/decode dpcd registers (rev6)
URL   : https://patchwork.freedesktop.org/series/44736/
State : success

== Summary ==

= CI Bug Log - changes from IGT_4667_full -> IGTPW_1913_full =

== Summary - WARNING ==

  Minor unknown changes coming with IGTPW_1913_full need to be verified
  manually.
  
  If you think the reported changes have nothing to do with the changes
  introduced in IGTPW_1913_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/6/mbox/

== Possible new issues ==

  Here are the unknown changes that may have been introduced in IGTPW_1913_full:

  === IGT changes ===

    ==== Warnings ====

    igt@perf_pmu@rc6:
      shard-kbl:          PASS -> SKIP

    
== Known issues ==

  Here are the changes found in IGTPW_1913_full that come from known issues:

  === IGT changes ===

    ==== Issues hit ====

    igt@gem_userptr_blits@readonly-unsync:
      shard-apl:          PASS -> INCOMPLETE (fdo#103927) +1

    igt@kms_chv_cursor_fail@pipe-a-128x128-left-edge:
      shard-glk:          PASS -> FAIL (fdo#104671)

    igt@kms_color@pipe-a-degamma:
      shard-apl:          PASS -> FAIL (fdo#108145, fdo#104782)
      shard-kbl:          PASS -> FAIL (fdo#108145)

    igt@kms_cursor_crc@cursor-256x256-dpms:
      shard-kbl:          PASS -> FAIL (fdo#103232)

    igt@kms_cursor_crc@cursor-256x256-random:
      shard-glk:          PASS -> FAIL (fdo#103232) +8

    igt@kms_cursor_legacy@cursora-vs-flipa-toggle:
      shard-glk:          PASS -> DMESG-WARN (fdo#105763, fdo#106538)

    igt@kms_draw_crc@fill-fb:
      shard-glk:          PASS -> FAIL (fdo#103184)

    igt@kms_flip@flip-vs-expired-vblank:
      shard-glk:          PASS -> FAIL (fdo#105363)

    igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-mmap-cpu:
      shard-apl:          PASS -> FAIL (fdo#103167)

    igt@kms_frontbuffer_tracking@fbc-2p-primscrn-cur-indfb-draw-mmap-gtt:
      shard-glk:          PASS -> FAIL (fdo#103167) +8

    igt@kms_plane_multiple@atomic-pipe-b-tiling-y:
      shard-apl:          PASS -> FAIL (fdo#103166)

    igt@kms_rotation_crc@sprite-rotation-180:
      shard-snb:          PASS -> FAIL (fdo#103925)

    igt@kms_setmode@basic:
      shard-apl:          PASS -> FAIL (fdo#99912)

    igt@kms_universal_plane@universal-plane-pipe-a-functional:
      shard-glk:          PASS -> FAIL (fdo#103166) +1

    igt@pm_rpm@system-suspend-execbuf:
      shard-kbl:          PASS -> INCOMPLETE (fdo#107807, fdo#103665)

    
    ==== Possible fixes ====

    igt@drv_suspend@fence-restore-untiled:
      shard-kbl:          INCOMPLETE (fdo#103665) -> PASS

    igt@gem_exec_big:
      shard-hsw:          TIMEOUT (fdo#107937) -> PASS

    igt@gem_mmap_gtt@medium-copy:
      shard-snb:          INCOMPLETE (fdo#105411) -> PASS

    igt@kms_ccs@pipe-a-bad-pixel-format:
      shard-apl:          DMESG-WARN (fdo#103558, fdo#105602) -> PASS +5

    igt@kms_cursor_crc@cursor-128x128-dpms:
      shard-kbl:          FAIL (fdo#103232) -> PASS

    igt@kms_cursor_crc@cursor-128x42-onscreen:
      shard-glk:          FAIL (fdo#103232) -> PASS +3

    igt@kms_cursor_crc@cursor-64x21-random:
      shard-apl:          FAIL (fdo#103232) -> PASS +8

    igt@kms_cursor_legacy@2x-long-cursor-vs-flip-legacy:
      shard-hsw:          FAIL (fdo#105767) -> PASS

    igt@kms_flip@flip-vs-expired-vblank-interruptible:
      shard-glk:          FAIL (fdo#102887, fdo#105363) -> PASS

    igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-mmap-gtt:
      shard-apl:          FAIL (fdo#103167) -> PASS +4
      shard-glk:          FAIL (fdo#103167) -> PASS

    igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-fullscreen:
      shard-kbl:          FAIL (fdo#103167) -> PASS +1

    {igt@kms_plane_alpha_blend@pipe-a-alpha-opaque-fb}:
      shard-apl:          FAIL (fdo#108145) -> PASS +1

    {igt@kms_plane_alpha_blend@pipe-b-alpha-opaque-fb}:
      shard-glk:          FAIL (fdo#108145) -> PASS +3
      shard-kbl:          FAIL (fdo#108145) -> PASS +2

    igt@kms_plane_multiple@atomic-pipe-b-tiling-x:
      shard-apl:          FAIL (fdo#103166) -> PASS +2

    igt@kms_plane_multiple@atomic-pipe-b-tiling-yf:
      shard-kbl:          FAIL (fdo#103166) -> PASS
      shard-glk:          FAIL (fdo#103166) -> PASS

    igt@kms_setmode@basic:
      shard-kbl:          FAIL (fdo#99912) -> PASS

    
  {name}: This element is suppressed. This means it is ignored when computing
          the status of the difference (SUCCESS, WARNING, or FAILURE).

  fdo#102887 https://bugs.freedesktop.org/show_bug.cgi?id=102887
  fdo#103166 https://bugs.freedesktop.org/show_bug.cgi?id=103166
  fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167
  fdo#103184 https://bugs.freedesktop.org/show_bug.cgi?id=103184
  fdo#103232 https://bugs.freedesktop.org/show_bug.cgi?id=103232
  fdo#103558 https://bugs.freedesktop.org/show_bug.cgi?id=103558
  fdo#103665 https://bugs.freedesktop.org/show_bug.cgi?id=103665
  fdo#103925 https://bugs.freedesktop.org/show_bug.cgi?id=103925
  fdo#103927 https://bugs.freedesktop.org/show_bug.cgi?id=103927
  fdo#104671 https://bugs.freedesktop.org/show_bug.cgi?id=104671
  fdo#104782 https://bugs.freedesktop.org/show_bug.cgi?id=104782
  fdo#105363 https://bugs.freedesktop.org/show_bug.cgi?id=105363
  fdo#105411 https://bugs.freedesktop.org/show_bug.cgi?id=105411
  fdo#105602 https://bugs.freedesktop.org/show_bug.cgi?id=105602
  fdo#105763 https://bugs.freedesktop.org/show_bug.cgi?id=105763
  fdo#105767 https://bugs.freedesktop.org/show_bug.cgi?id=105767
  fdo#106538 https://bugs.freedesktop.org/show_bug.cgi?id=106538
  fdo#107807 https://bugs.freedesktop.org/show_bug.cgi?id=107807
  fdo#107937 https://bugs.freedesktop.org/show_bug.cgi?id=107937
  fdo#108145 https://bugs.freedesktop.org/show_bug.cgi?id=108145
  fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912


== Participating hosts (6 -> 5) ==

  Missing    (1): shard-skl 


== Build changes ==

    * IGT: IGT_4667 -> IGTPW_1913
    * Linux: CI_DRM_4930 -> CI_DRM_4931

  CI_DRM_4930: bf1bd5e86f267d58ac68c342fcfff70e8ef1fd34 @ git://anongit.freedesktop.org/gfx-ci/linux
  CI_DRM_4931: 826702bf60ae2b37841c051ed769b44af194fbb1 @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_1913: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1913/
  IGT_4667: 596f48dcd59fd2f8c16671514f3e69d4a2891374 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1913/shards.html
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [igt-dev] [PATCH i-g-t v5] tools: Add a simple tool to read/write/decode dpcd registers
  2018-10-04 21:50 [igt-dev] [PATCH i-g-t v5] tools: Add a simple tool to read/write/decode dpcd registers Tarun Vyas
  2018-10-04 22:44 ` [igt-dev] ✓ Fi.CI.BAT: success for tools: Add a simple tool to read/write/decode dpcd registers (rev6) Patchwork
  2018-10-05  5:12 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
@ 2018-10-05 17:54 ` Dhinakaran Pandiyan
  2 siblings, 0 replies; 5+ messages in thread
From: Dhinakaran Pandiyan @ 2018-10-05 17:54 UTC (permalink / raw)
  To: igt-dev; +Cc: rodrigo.vivi

On Thursday, October 4, 2018 2:50:23 PM PDT Tarun Vyas wrote:
> 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.
> 
> v2: (Fixes by Rodrigo but no functional changes yet):
>     - Indentations, Typo, Missed spaces
>     - Removing mentioning to decode and spec that is not implemented yet.
>     - Add Makefile.sources back
>     - Missed s/printf/igt_warn
> 
> v3:
>     - Address DK's review comments from v2 above.
>     - Squash Rodrigo's file handling unification patch.
>     - Make count, offset and device id optional.
> 
> v4:
>     - Better error handling and refactoring.
> 
> Suggested-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
> Signed-off-by: Tarun Vyas <tarun.vyas@intel.com>
> Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Reviewed-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>

Pushed, thanks for the patch.

-DK


_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [igt-dev] [PATCH i-g-t v5] tools: Add a simple tool to read/write/decode dpcd registers
@ 2018-10-04 18:16 Tarun Vyas
  0 siblings, 0 replies; 5+ messages in thread
From: Tarun Vyas @ 2018-10-04 18:16 UTC (permalink / raw)
  To: igt-dev; +Cc: dhinakaran.pandiyan, rodrigo.vivi

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.

v2: (Fixes by Rodrigo but no functional changes yet):
    - Indentations, Typo, Missed spaces
    - Removing mentioning to decode and spec that is not implemented yet.
    - Add Makefile.sources back
    - Missed s/printf/igt_warn

v3:
    - Addres DK's review comments from v2 above.
    - Squash Rodrigo's file handling unification patch.
    - Make count, offset and device id optional.

v4:
    - Better error handling and refactoring.

Suggested-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
Signed-off-by: Tarun Vyas <tarun.vyas@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
---
 tools/Makefile.sources |   1 +
 tools/dpcd_reg.c       | 274 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/meson.build      |   1 +
 3 files changed, 276 insertions(+)
 create mode 100644 tools/dpcd_reg.c

diff --git a/tools/Makefile.sources b/tools/Makefile.sources
index abd23a0f..50706f41 100644
--- a/tools/Makefile.sources
+++ b/tools/Makefile.sources
@@ -7,6 +7,7 @@ noinst_PROGRAMS =		\
 
 tools_prog_lists =		\
 	igt_stats		\
+	dpcd_reg		\
 	intel_audio_dump	\
 	intel_reg		\
 	intel_backlight		\
diff --git a/tools/dpcd_reg.c b/tools/dpcd_reg.c
new file mode 100644
index 00000000..02e51214
--- /dev/null
+++ b/tools/dpcd_reg.c
@@ -0,0 +1,274 @@
+/*
+ * 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/write tool
+ * This tool wraps around DRM_DP_AUX_DEV module to provide DPCD register read
+ * and write, so CONFIG_DRM_DP_AUX_DEV needs to be set.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <limits.h>
+#include <stdbool.h>
+
+#define MAX_DP_OFFSET	0xfffff
+#define DRM_AUX_MINORS	256
+
+const char aux_dev[] = "/dev/drm_dp_aux";
+
+struct dpcd_data {
+	int devid;
+	int file_op;
+	uint32_t offset;
+	enum command {
+		INVALID = -1,
+		READ = 2,
+		WRITE,
+	} cmd;
+	size_t count;
+	uint8_t val;
+};
+
+static void print_usage(void)
+{
+	printf("Usage: dpcd_reg [OPTION ...] COMMAND\n\n");
+	printf("COMMAND is one of:\n");
+	printf("  read:		Read [count] bytes dpcd reg at an offset\n");
+	printf("  write:	Write a dpcd reg at an offset\n\n");
+	printf("Options for the above COMMANDS are\n");
+	printf(" --device=DEVID		Aux device id, as listed in /dev/drm_dp_aux_dev[n]."
+					"Defaults to 0. Upper limit - 256\n");
+	printf(" --offset=REG_ADDR	DPCD register offset in hex. Defaults to 0x0"
+					"Upper limit - 0xfffff\n");
+	printf(" --count=BYTES		For reads, specify number of bytes to be read from"
+					" the offset. Defaults to 1\n");
+	printf(" --value		For writes, specify a hex value to be written"
+					"Upper limit - 0xff\n\n");
+
+	printf(" --help: print the usage\n");
+}
+
+static inline bool strtol_err_util(char *endptr, long *val)
+{
+	if (*endptr != '\0' || *val < 0 || (*val == LONG_MAX && errno == ERANGE))
+		return true;
+
+	return false;
+}
+
+static int parse_opts(struct dpcd_data *dpcd, int argc, char **argv)
+{
+	int ret, vflag = 0;
+	long temp;
+	char *endptr;
+
+	struct option longopts[] = {
+		{ "count",	required_argument,	NULL,		'c' },
+		{ "device",	required_argument,	NULL,		'd' },
+		{ "help",	no_argument,		NULL,		'h' },
+		{ "offset",	required_argument,	NULL,		'o' },
+		{ "value",	required_argument,	NULL,		'v' },
+		{ 0 }
+	};
+
+	while ((ret = getopt_long(argc, argv, "-:c:d:ho:v:", longopts, NULL)) != -1) {
+		switch (ret) {
+		case 'c':
+			temp = strtol(optarg, &endptr, 10);
+			if (strtol_err_util(endptr, &temp)) {
+				fprintf(stderr, "--count argument is invalid/negative/out-of-range\n");
+				print_usage();
+				return EXIT_FAILURE;
+			}
+			dpcd->count = temp;
+			break;
+		case 'd':
+			temp = strtol(optarg, &endptr, 10);
+			if (strtol_err_util(endptr, &temp) || temp > DRM_AUX_MINORS) {
+				fprintf(stderr, "--devid argument is invalid/negative/out-of-range\n");
+				print_usage();
+				return ERANGE;
+			}
+			dpcd->devid = temp;
+			break;
+		case 'h':
+			printf("DPCD register read and write tool\n\n");
+			printf("This tool requires CONFIG_DRM_DP_AUX_CHARDEV\n"
+				"to be set in the kernel config.\n\n");
+			print_usage();
+			exit(EXIT_SUCCESS);
+		case 'o':
+			temp = strtol(optarg, &endptr, 16);
+			if (strtol_err_util(endptr, &temp) || temp > MAX_DP_OFFSET) {
+				fprintf(stderr, "--offset argument is invalid/negative/out-of-range\n");
+				print_usage();
+				return ERANGE;
+			}
+			dpcd->offset = temp;
+			break;
+		case 'v':
+			vflag = 'v';
+			temp = strtol(optarg, &endptr, 16);
+			if (strtol_err_util(endptr, &temp) || temp > 0xff) {
+				fprintf(stderr, "--value argument is invalid/negative/out-of-range\n");
+				print_usage();
+				return ERANGE;
+			}
+			dpcd->val = temp;
+			break;
+		/* Command parsing */
+		case 1:
+			if (strcmp(optarg, "read") == 0) {
+				temp = READ;
+			} else if (strcmp(optarg, "write") == 0) {
+				temp = WRITE;
+				dpcd->file_op = O_WRONLY;
+			} else {
+				fprintf(stderr, "Unrecognized command\n");
+				print_usage();
+				return EXIT_FAILURE;
+			}
+			dpcd->cmd = temp;
+			break;
+		case ':':
+			fprintf(stderr, "Option -%c requires an argument\n",
+				 optopt);
+			print_usage();
+			return EXIT_FAILURE;
+		default:
+			fprintf(stderr, "Invalid option\n");
+			print_usage();
+			return EXIT_FAILURE;
+		}
+	}
+
+	if ((dpcd->count + dpcd->offset) > (MAX_DP_OFFSET + 1)) {
+		fprintf(stderr, "Out of bounds. Count + Offset <= 0x100000\n");
+		return ERANGE;
+	}
+
+	if ((dpcd->cmd == WRITE) && (vflag != 'v')) {
+		fprintf(stderr, "Write value is missing\n");
+		print_usage();
+		return EXIT_FAILURE;
+	}
+
+	return EXIT_SUCCESS;
+}
+
+static int dpcd_read(int fd, uint32_t offset, size_t count)
+{
+	int ret = EXIT_SUCCESS, pret, i;
+	uint8_t *buf = calloc(count, sizeof(uint8_t));
+
+	if (!buf) {
+		fprintf(stderr, "Can't allocate read buffer\n");
+		return ENOMEM;
+	}
+
+	pret = pread(fd, buf, count, offset);
+	if (pret < 0) {
+		fprintf(stderr, "Failed to read - %s\n", strerror(errno));
+		ret = errno;
+		goto out;
+	}
+
+	if (pret < count) {
+		fprintf(stderr, "Read %u byte(s), expected %zu bytes, starting at offset %x\n\n", pret, count, offset);
+		ret = EXIT_FAILURE;
+	}
+
+	printf("0x%02x: ", offset);
+	for (i = 0; i < pret; i++)
+		printf(" %02x", *(buf + i));
+	printf("\n");
+
+out:
+	free(buf);
+	return ret;
+}
+
+static int dpcd_write(int fd, uint32_t offset, uint8_t val)
+{
+	int ret = EXIT_SUCCESS, pret;
+
+	pret = pwrite(fd, (const void *)&val, sizeof(uint8_t), offset);
+	if (pret < 0) {
+		fprintf(stderr, "Failed to write - %s\n", strerror(errno));
+		ret = errno;
+	} else if (pret == 0) {
+		fprintf(stderr, "Zero bytes were written\n");
+		ret = EXIT_FAILURE;
+	}
+
+	return ret;
+}
+
+int main(int argc, char **argv)
+{
+	char dev_name[20];
+	int ret, fd;
+
+	struct dpcd_data dpcd = {
+		.devid = 0,
+		.file_op = O_RDONLY,
+		.offset = 0x0,
+		.cmd = INVALID,
+		.count = 1,
+	};
+
+	if((ret = parse_opts(&dpcd, argc, argv)) != EXIT_SUCCESS)
+		return ret;
+
+	snprintf(dev_name, strlen(aux_dev) + 4, "%s%d", aux_dev, dpcd.devid);
+
+	fd = open(dev_name, dpcd.file_op);
+	if (fd < 0) {
+		fprintf(stderr, "Failed to open %s aux device - error: %s\n", dev_name,
+			strerror(errno));
+		return errno;
+	}
+
+	switch (dpcd.cmd) {
+	case READ:
+		ret = dpcd_read(fd, dpcd.offset, dpcd.count);
+		break;
+	case WRITE:
+		ret = dpcd_write(fd, dpcd.offset, dpcd.val);
+		break;
+	default:
+		fprintf(stderr, "Please specify a command: read/write.\n");
+		print_usage();
+		ret = EXIT_FAILURE;
+		break;
+	}
+
+	close(fd);
+
+	return ret;
+}
diff --git a/tools/meson.build b/tools/meson.build
index e4517d66..79f36aa9 100644
--- a/tools/meson.build
+++ b/tools/meson.build
@@ -36,6 +36,7 @@ tools_progs = [
 	'intel_watermark',
 	'intel_gem_info',
 	'intel_gvtg_test',
+	'dpcd_reg',
 ]
 tool_deps = igt_deps
 
-- 
2.14.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-10-05 17:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-04 21:50 [igt-dev] [PATCH i-g-t v5] tools: Add a simple tool to read/write/decode dpcd registers Tarun Vyas
2018-10-04 22:44 ` [igt-dev] ✓ Fi.CI.BAT: success for tools: Add a simple tool to read/write/decode dpcd registers (rev6) Patchwork
2018-10-05  5:12 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2018-10-05 17:54 ` [igt-dev] [PATCH i-g-t v5] tools: Add a simple tool to read/write/decode dpcd registers Dhinakaran Pandiyan
  -- strict thread matches above, loose matches on Subject: below --
2018-10-04 18:16 Tarun Vyas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.