Skip to contentSkip to conversation

Playing with the idea of pulling kernel code into i-g-t

RFC New Damien Lespiau 2 participants 3 messages Jun 5, 2013 Library code

lore
Share & tools
lore
#0 lore raw

I played a bit with this as that's something thas has been floating around for a bit and could be used for:
- unit testing kernel functions (eg. PLL computations)
- reuse off some code (intel_reg.h, sideband, device_info struct, ...)
- Ville wanted to fuzzy test the EDID code (and has a branch somewhere IIRC)
- ...

To make it maintainable we could have a script that, when pointed to a kernel, pulls in the needed pieces. A simple form of this is scripts/sync-from-kernel in the following patch.

$ ./scripts/sync-from-kernel ../linux-2.6/
Using v3.9-rc1-15371-g393f670
Importing intel_sideband.c

You then need a shim layer that replicates what we use from the kernel. A lot can probably be faked without too much trouble.

A good use case for that would be to be able to have one master copy of i915_reg.h (the kernel's) and sync it into i-g-t.

In any case, the following patch pulls in intel_sideband.c and replaces what we currenlty have. It's aboslutely not tested and might just end up being a pointless exercise...

Signature · 1 line
Damien
#1 lore raw

RFC 1/1 lib: Import intel_sideband.c from the kernel

XXX: more detailed commit message

---
 lib/Makefile.am                                    |   9 +-
 lib/intel_dpio.c                                   |  94 ---------
 lib/intel_gpu_tools.h                              |  15 ++
 lib/intel_iosf.c                                   |  85 --------
 lib/intel_reg.h                                    | 221 +++++++++++++++++++--
 lib/intel_sideband.c                               | 191 ++++++++++++++++++
 tools/intel_dpio_read.c => lib/intel_sideband.h    |  64 ++----
 .../kernel-shim/drm-shim.h                         |  62 +++---
 .../kernel-shim/i915_drv.h                         |  53 ++---
 .../kernel-shim/intel_drv.h                        |  69 +++----
 .../intel_dpio_read.c => lib/kernel-shim/kernel.h  |  76 +++----
 scripts/sync-from-kernel                           |  30 +++
 tools/intel_dpio_read.c                            |   4 +-
 tools/intel_dpio_write.c                           |   4 +-
 tools/intel_nc_read.c                              |   6 +-
 tools/intel_nc_write.c                             |  10 +-
 tools/intel_punit_read.c                           |   6 +-
 tools/intel_punit_write.c                          |  10 +-
 18 files changed, 592 insertions(+), 417 deletions(-)
 delete mode 100644 lib/intel_dpio.c
 delete mode 100644 lib/intel_iosf.c
 create mode 100644 lib/intel_sideband.c
 copy tools/intel_dpio_read.c => lib/intel_sideband.h (52%)
 copy tools/intel_dpio_write.c => lib/kernel-shim/drm-shim.h (55%)
 copy tools/intel_dpio_write.c => lib/kernel-shim/i915_drv.h (55%)
 copy tools/intel_dpio_write.c => lib/kernel-shim/intel_drv.h (55%)
 copy tools/intel_dpio_read.c => lib/kernel-shim/kernel.h (52%)
 create mode 100755 scripts/sync-from-kernel
lib/Makefile.am +6 -3
index 387141b..2cafe22 100644
@@ -1,10 +1,14 @@
 
 noinst_LTLIBRARIES = libintel_tools.la
 
-AM_CPPFLAGS = -I$(top_srcdir)
+AM_CPPFLAGS = -I$(top_srcdir) -I$(srcdir)/kernel-shim
 AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS)
 
 libintel_tools_la_SOURCES = 	\
+	kernel-shim/kernel.h	\
+	kernel-shim/i915_drv.h	\
+	kernel-shim/intel_drv.h	\
+	kernel-shim/drm-shim.h	\
 	debug.h			\
 	drmtest.c		\
 	drmtest.h		\
@@ -29,8 +33,7 @@ libintel_tools_la_SOURCES = 	\
 	rendercopy_gen7.c	\
 	rendercopy.h		\
 	intel_reg_map.c		\
-	intel_dpio.c		\
-	intel_iosf.c		\
+	intel_sideband.c	\
 	$(NULL)
 
 LDADD = $(CAIRO_LIBS)
lib/intel_dpio.c deleted +0 -94

94 lines not on this page · raw message

lib/intel_gpu_tools.h +15 -0
index faa948c..bd54171 100644
@@ -112,4 +112,19 @@ void intel_check_pch(void);
 #define HAS_CPT (pch == PCH_CPT)
 #define HAS_LPT (pch == PCH_LPT)
 
+/*
+ * Kernel Shim
+ */
+
+/* Don't really care about locking atm */
+struct mutex
+{
+	int dummy;
+};
+
+struct drm_i915_private
+{
+	struct mutex dpio_lock;
+};
+
 #endif /* INTEL_GPU_TOOLS_H */
lib/intel_iosf.c deleted +0 -85

85 lines not on this page · raw message

lib/intel_reg.h +206 -15

236 lines not on this page · raw message

lib/intel_sideband.c new file +191 -0

191 lines not on this page · raw message

lib/intel_sideband.h renamed from tools/intel_dpio_read.c +21 -43

78 lines not on this page · raw message

lib/kernel-shim/drm-shim.h renamed from tools/intel_dpio_write.c +25 -37

81 lines not on this page · raw message

lib/kernel-shim/i915_drv.h renamed from tools/intel_dpio_write.c +12 -41

68 lines not on this page · raw message

lib/kernel-shim/intel_drv.h renamed from tools/intel_dpio_write.c +25 -44

81 lines not on this page · raw message

lib/kernel-shim/kernel.h renamed from tools/intel_dpio_read.c +39 -37

96 lines not on this page · raw message

scripts/sync-from-kernel new file +30 -0
new file mode 100755
index 0000000..6940815
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+kernel_path=$1
+[ -z "$kernel_path" ] && kernel_path=.
+
+[ -f $kernel_path/Kconfig ] || {
+	echo "$kernel_path is not a path to a kernel"
+	exit 1
+}
+
+kernel_description=$(cd $kernel_path; git describe)
+echo Using $kernel_description
+
+read -r -d '' header <<EOF
+/*
+ * This file is generated from scripts/sync-from-kernel, do not hand-edit.
+ * This file is is from kernel $kernel_description
+ */
+EOF
+
+function import {
+	src=$1
+	dst=$2
+
+	echo "Importing `basename $src`"
+	echo "$header" > $dst
+	cat $kernel_path/$src >> $dst
+}
+
+import "$kernel_path/drivers/gpu/drm/i915/intel_sideband.c" lib/intel_sideband.c
tools/intel_dpio_read.c +3 -1
index c0c904a..52c6080 100644
@@ -31,6 +31,7 @@
 #include <err.h>
 #include <string.h>
 #include "intel_gpu_tools.h"
+#include "intel_sideband.h"
 
 static void usage(char *cmdname)
 {
@@ -45,6 +46,7 @@ int main(int argc, char** argv)
 	uint32_t reg, val;
 	char *cmdname = strdup(argv[0]);
 	struct pci_device *dev = intel_get_pci_device();
+	struct drm_i915_private dev_priv;
 
 	if (argc != 2 || !IS_VALLEYVIEW(dev->device_id)) {
 		usage(cmdname);
@@ -56,7 +58,7 @@ int main(int argc, char** argv)
 
 	intel_register_access_init(dev, 0);
 
-	val = intel_dpio_reg_read(reg);
+	val = vlv_dpio_read(&dev_priv, reg);
 
 	printf("Read DPIO register: 0x%x - Value : 0x%x\n", reg, val);
 
tools/intel_dpio_write.c +3 -1
index f842999..0d519c8 100644
@@ -31,6 +31,7 @@
 #include <err.h>
 #include <string.h>
 #include "intel_gpu_tools.h"
+#include "intel_sideband.h"
 
 static void usage(char *cmdname)
 {
@@ -45,6 +46,7 @@ int main(int argc, char** argv)
 	uint32_t reg, val;
 	char *cmdname = strdup(argv[0]);
 	struct pci_device *dev = intel_get_pci_device();
+	struct drm_i915_private dev_priv;
 
 	if (argc != 3 || !IS_VALLEYVIEW(dev->device_id)) {
 		usage(cmdname);
@@ -57,7 +59,7 @@ int main(int argc, char** argv)
 
 	intel_register_access_init(dev, 0);
 
-	intel_dpio_reg_write(reg, val);
+	vlv_dpio_write(&dev_priv, reg, val);
 
 	intel_register_access_fini();
 
tools/intel_nc_read.c +3 -3
index a2c2e9f..3386305 100644
@@ -31,6 +31,7 @@
 #include <err.h>
 #include <string.h>
 #include "intel_gpu_tools.h"
+#include "intel_sideband.h"
 
 static void usage(char *cmdname)
 {
@@ -45,6 +46,7 @@ int main(int argc, char** argv)
 	uint32_t reg, val;
 	char *cmdname = strdup(argv[0]);
 	struct pci_device *dev = intel_get_pci_device();
+	struct drm_i915_private dev_priv;
 
 	if (argc != 2 || !IS_VALLEYVIEW(dev->device_id)) {
 		usage(cmdname);
@@ -56,9 +58,7 @@ int main(int argc, char** argv)
 
 	intel_register_access_init(dev, 0);
 
-	ret = intel_nc_read(reg, &val);
-	if (ret)
-		fprintf(stderr, "iosf read failed: %d\n", ret);
+	val = vlv_nc_read(&dev_priv, reg);
 
 	printf("Read IOSF register: 0x%x - Value : 0x%x\n", reg, val);
 
tools/intel_nc_write.c +5 -5
index 58be79a..047269a 100644
@@ -31,6 +31,7 @@
 #include <err.h>
 #include <string.h>
 #include "intel_gpu_tools.h"
+#include "intel_sideband.h"
 
 static void usage(char *cmdname)
 {
@@ -45,6 +46,7 @@ int main(int argc, char** argv)
 	uint32_t reg, val, tmp;
 	char *cmdname = strdup(argv[0]);
 	struct pci_device *dev = intel_get_pci_device();
+	struct drm_i915_private dev_priv;
 
 	if (argc != 3 || !IS_VALLEYVIEW(dev->device_id)) {
 		usage(cmdname);
@@ -57,14 +59,12 @@ int main(int argc, char** argv)
 
 	intel_register_access_init(dev, 0);
 
-	intel_nc_read(reg, &tmp);
+	tmp = vlv_nc_read(&dev_priv, reg);
 	printf("Value before: 0x%X\n", tmp);
 
-	ret = intel_nc_write(reg, val);
-	if (ret)
-		fprintf(stderr, "Nc write failed: %d\n", ret);
+	vlv_nc_write(&dev_priv, reg, val);
 
-	intel_nc_read(reg, &tmp);
+	tmp = vlv_nc_read(&dev_priv, reg);
 	printf("Value after: 0x%X\n", tmp);
 
 	intel_register_access_fini();
tools/intel_punit_read.c +3 -3
index 3fa2ca8..4661825 100644
@@ -31,6 +31,7 @@
 #include <err.h>
 #include <string.h>
 #include "intel_gpu_tools.h"
+#include "intel_sideband.h"
 
 static void usage(char *cmdname)
 {
@@ -45,6 +46,7 @@ int main(int argc, char** argv)
 	uint32_t reg, val;
 	char *cmdname = strdup(argv[0]);
 	struct pci_device *dev = intel_get_pci_device();
+	struct drm_i915_private dev_priv;
 
 	if (argc != 2 || !IS_VALLEYVIEW(dev->device_id)) {
 		usage(cmdname);
@@ -56,9 +58,7 @@ int main(int argc, char** argv)
 
 	intel_register_access_init(dev, 0);
 
-	ret = intel_punit_read(reg, &val);
-	if (ret)
-		fprintf(stderr, "iosf read failed: %d\n", ret);
+	val = vlv_punit_read(&dev_priv, reg);
 
 	printf("Read IOSF register: 0x%x - Value : 0x%x\n", reg, val);
 
tools/intel_punit_write.c +5 -5
index eb036ba..30d4522 100644
@@ -31,6 +31,7 @@
 #include <err.h>
 #include <string.h>
 #include "intel_gpu_tools.h"
+#include "intel_sideband.h"
 
 static void usage(char *cmdname)
 {
@@ -45,6 +46,7 @@ int main(int argc, char** argv)
 	uint32_t reg, val, tmp;
 	char *cmdname = strdup(argv[0]);
 	struct pci_device *dev = intel_get_pci_device();
+	struct drm_i915_private dev_priv;
 
 	if (argc != 3 || !IS_VALLEYVIEW(dev->device_id)) {
 		usage(cmdname);
@@ -57,14 +59,12 @@ int main(int argc, char** argv)
 
 	intel_register_access_init(dev, 0);
 
-	intel_punit_read(reg, &tmp);
+	tmp = vlv_punit_read(&dev_priv, reg);
 	printf("Value before: 0x%X\n", tmp);
 
-	ret = intel_punit_write(reg, val);
-	if (ret)
-		fprintf(stderr, "Punit write failed: %d\n", ret);
+	vlv_punit_write(&dev_priv, reg, val);
 
-	intel_punit_read(reg, &tmp);
+	tmp = vlv_punit_read(&dev_priv, reg);
 	printf("Value after: 0x%X\n", tmp);
 
 	intel_register_access_fini();
Signature · 6 lines
1.8.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
In reply to Damien Lespiau
Quoted 6 lines · Damien Lespiau

I played a bit with this as that's something thas has been floating around for a bit and could be used for:
- unit testing kernel functions (eg. PLL computations)
- reuse off some code (intel_reg.h, sideband, device_info struct, ...)
- Ville wanted to fuzzy test the EDID code (and has a branch somewhere IIRC)

So far I always forgot to push it anywhere. Now it's here:
git://gitorious.org/vsyrjala/drm_edid_test.git

It's just a copy drm_edid.c and some other files, a bunch of stubs make it compile, and a small program that reads in an edid and prints a bunch of stuff drm_edid.c managed to parse from it.

Signature · 2 lines
Ville Syrjälä
Intel OTC