[Intel-gfx] [PATCH 2/4] lib/intel_* Use igt checks and macros

Daniel Vetter daniel.vetter at ffwll.ch
Tue Aug 26 19:36:12 CEST 2014


Various stuff all over. Most done with the igt.cocci spatch, but
with a few fixups by hand. And add igt_core.h includes where needed.

Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
---
 lib/igt_fb.c        |  2 +-
 lib/intel_chipset.c | 17 ++++++-----------
 lib/intel_iosf.c    |  8 ++++----
 lib/intel_mmio.c    | 42 ++++++++++++++++--------------------------
 lib/intel_os.c      | 16 ++++++++--------
 lib/intel_reg_map.c |  6 +++---
 6 files changed, 38 insertions(+), 53 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index b8448c86d5b5..71d9a26a24c5 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -455,7 +455,7 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
  * The kms id of the created framebuffer.
  */
 unsigned int igt_create_fb(int fd, int width, int height, uint32_t format,
-			   unsigned int tiling, struct igt_fb *fb)
+			   unsigned tiling, struct igt_fb *fb)
 {
 	return igt_create_fb_with_bo_size(fd, width, height, format, tiling, fb, 0);
 }
diff --git a/lib/intel_chipset.c b/lib/intel_chipset.c
index 54d55ac00811..0828e444b7b0 100644
--- a/lib/intel_chipset.c
+++ b/lib/intel_chipset.c
@@ -39,6 +39,7 @@
 #include "i915_drm.h"
 
 #include "intel_chipset.h"
+#include "igt_core.h"
 
 /**
  * SECTION:intel_chipset
@@ -74,11 +75,8 @@ intel_get_pci_device(void)
 	int error;
 
 	error = pci_system_init();
-	if (error != 0) {
-		fprintf(stderr, "Couldn't initialize PCI system: %s\n",
-			strerror(error));
-		exit(1);
-	}
+	igt_fail_on_f(error != 0,
+		      "Couldn't initialize PCI system\n");
 
 	/* Grab the graphics card. Try the canonical slot first, then
 	 * walk the entire PCI bus for a matching device. */
@@ -105,11 +103,8 @@ intel_get_pci_device(void)
 		errx(1, "Couldn't find graphics card");
 
 	error = pci_device_probe(pci_dev);
-	if (error != 0) {
-		fprintf(stderr, "Couldn't probe graphics card: %s\n",
-			strerror(error));
-		exit(1);
-	}
+	igt_fail_on_f(error != 0,
+		      "Couldn't probe graphics card\n");
 
 	if (pci_dev->vendor_id != 0x8086)
 		errx(1, "Graphics card is non-intel");
@@ -145,7 +140,7 @@ intel_get_drm_devid(int fd)
 		gp.value = (int *)&devid;
 
 		ret = ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
-		assert(ret == 0);
+		igt_assert(ret == 0);
 		errno = 0;
 	}
 
diff --git a/lib/intel_iosf.c b/lib/intel_iosf.c
index 2f1ef90cdd3d..27134a07319e 100644
--- a/lib/intel_iosf.c
+++ b/lib/intel_iosf.c
@@ -3,8 +3,10 @@
 #include <stdio.h>
 #include <err.h>
 #include <errno.h>
+
 #include "intel_io.h"
 #include "intel_reg.h"
+#include "igt_core.h"
 
 #define TIMEOUT_US 500000
 
@@ -33,8 +35,7 @@ static int vlv_sideband_rw(uint32_t port, uint8_t opcode, uint32_t addr,
 		(bar << IOSF_BAR_SHIFT);
 
 	if (intel_register_read(VLV_IOSF_DOORBELL_REQ) & IOSF_SB_BUSY) {
-		fprintf(stderr, "warning: pcode (%s) mailbox access failed\n",
-			is_read ? "read" : "write");
+		igt_warn("warning: pcode (%s) mailbox access failed\n", is_read ? "read" : "write");
 		return -EAGAIN;
 	}
 
@@ -51,8 +52,7 @@ static int vlv_sideband_rw(uint32_t port, uint8_t opcode, uint32_t addr,
 		 timeout < TIMEOUT_US);
 
 	if (timeout >= TIMEOUT_US) {
-		fprintf(stderr, "timeout waiting for pcode %s (%d) to finish\n",
-			is_read ? "read" : "write", addr);
+		igt_warn("timeout waiting for pcode %s (%d) to finish\n", is_read ? "read" : "write", addr);
 		return -ETIMEDOUT;
 	}
 
diff --git a/lib/intel_mmio.c b/lib/intel_mmio.c
index 45f39a46aff9..c95ae583619f 100644
--- a/lib/intel_mmio.c
+++ b/lib/intel_mmio.c
@@ -42,6 +42,7 @@
 #include <sys/mman.h>
 
 #include "intel_io.h"
+#include "igt_core.h"
 #include "igt_debugfs.h"
 #include "intel_chipset.h"
 
@@ -93,18 +94,13 @@ intel_mmio_use_dump_file(char *file)
 	struct stat st;
 
 	fd = open(file, O_RDWR);
-	if (fd == -1) {
-		    fprintf(stderr, "Couldn't open %s: %s\n", file,
-			    strerror(errno));
-		    exit(1);
-	}
+	igt_fail_on_f(fd == -1,
+		      "Couldn't open %s\n", file);
+
 	fstat(fd, &st);
 	mmio = mmap(NULL, st.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
-	if (mmio == MAP_FAILED) {
-		    fprintf(stderr, "Couldn't mmap %s: %s\n", file,
-			    strerror(errno));
-		    exit(1);
-	}
+	igt_fail_on_f(mmio == MAP_FAILED,
+		      "Couldn't mmap %s\n", file);
 	close(fd);
 }
 
@@ -145,11 +141,8 @@ intel_mmio_use_pci_bar(struct pci_device *pci_dev)
 				      PCI_DEV_MAP_FLAG_WRITABLE,
 				      &mmio);
 
-	if (error != 0) {
-		fprintf(stderr, "Couldn't map MMIO region: %s\n",
-			strerror(error));
-		exit(1);
-	}
+	igt_fail_on_f(error != 0,
+		      "Couldn't map MMIO region\n");
 }
 
 static void
@@ -180,7 +173,7 @@ intel_register_access_init(struct pci_device *pci_dev, int safe)
 	if (mmio == NULL)
 		intel_mmio_use_pci_bar(pci_dev);
 
-	assert(mmio != NULL);
+	igt_assert(mmio != NULL);
 
 	if (mmio_data.inited)
 		return -1;
@@ -254,10 +247,10 @@ intel_register_read(uint32_t reg)
 	struct intel_register_range *range;
 	uint32_t ret;
 
-	assert(mmio_data.inited);
+	igt_assert(mmio_data.inited);
 
 	if (intel_gen(mmio_data.i915_devid) >= 6)
-		assert(mmio_data.key != -1);
+		igt_assert(mmio_data.key != -1);
 
 	if (!mmio_data.safe)
 		goto read_out;
@@ -267,8 +260,7 @@ intel_register_read(uint32_t reg)
 					 INTEL_RANGE_READ);
 
 	if(!range) {
-		fprintf(stderr, "Register read blocked for safety "
-			"(*0x%08x)\n", reg);
+		igt_warn("Register read blocked for safety ""(*0x%08x)\n", reg);
 		ret = 0xffffffff;
 		goto out;
 	}
@@ -295,10 +287,10 @@ intel_register_write(uint32_t reg, uint32_t val)
 {
 	struct intel_register_range *range;
 
-	assert(mmio_data.inited);
+	igt_assert(mmio_data.inited);
 
 	if (intel_gen(mmio_data.i915_devid) >= 6)
-		assert(mmio_data.key != -1);
+		igt_assert(mmio_data.key != -1);
 
 	if (!mmio_data.safe)
 		goto write_out;
@@ -307,10 +299,8 @@ intel_register_write(uint32_t reg, uint32_t val)
 					 reg,
 					 INTEL_RANGE_WRITE);
 
-	if (!range) {
-		fprintf(stderr, "Register write blocked for safety "
-			"(*0x%08x = 0x%x)\n", reg, val);
-	}
+	igt_warn_on_f(!range,
+		      "Register write blocked for safety ""(*0x%08x = 0x%x)\n", reg, val);
 
 write_out:
 	*(volatile uint32_t *)((volatile char *)mmio + reg) = val;
diff --git a/lib/intel_os.c b/lib/intel_os.c
index 4194744a076f..538327a82105 100644
--- a/lib/intel_os.c
+++ b/lib/intel_os.c
@@ -67,7 +67,7 @@ intel_get_total_ram_mb(void)
 	int ret;
 
 	ret = sysinfo(&sysinf);
-	assert(ret == 0);
+	igt_assert(ret == 0);
 
 	retval = sysinf.totalram;
 	retval *= sysinf.mem_unit;
@@ -108,7 +108,7 @@ intel_get_avail_ram_mb(void)
 	}
 
 	ret = sysinfo(&sysinf);
-	assert(ret == 0);
+	igt_assert(ret == 0);
 
 	retval = sysinf.freeram;
 	retval *= sysinf.mem_unit;
@@ -142,7 +142,7 @@ intel_get_total_swap_mb(void)
 	int ret;
 
 	ret = sysinfo(&sysinf);
-	assert(ret == 0);
+	igt_assert(ret == 0);
 
 	retval = sysinf.freeswap;
 	retval *= sysinf.mem_unit;
@@ -154,7 +154,7 @@ intel_get_total_swap_mb(void)
 	int n, i;
 
 	if ((n = swapctl(SC_GETNSWP, NULL)) == -1) {
-	    perror("swapctl: GETNSWP");
+	    igt_warn("swapctl: GETNSWP");
 	    return 0;
 	}
 	if (n == 0) {
@@ -165,7 +165,7 @@ intel_get_total_swap_mb(void)
 	swt = malloc(sizeof(struct swaptable) + (n * sizeof(swapent_t)));
 	buf = malloc(n * MAXPATHLEN);
 	if (!swt || !buf) {
-	    perror("malloc");
+	    igt_warn("malloc");
 	} else {
 	    swt->swt_n = n;
 	    for (i = 0 ; i < n; i++) {
@@ -173,7 +173,7 @@ intel_get_total_swap_mb(void)
 	    }
 
 	    if ((n = swapctl(SC_LIST, swt)) == -1) {
-		perror("swapctl: LIST");
+		igt_warn("swapctl: LIST");
 	    } else {
 		for (i = 0; i < swt->swt_n; i++) {
 		    totalpages += swt->swt_ent[i].ste_pages;
@@ -273,8 +273,8 @@ void *mmio;
 
 int main(int argc, char **argv)
 {
-    printf("Total RAM:  %" PRIu64 " Mb\n", intel_get_total_ram_mb());
-    printf("Total Swap: %" PRIu64 " Mb\n", intel_get_total_swap_mb());
+    igt_info("Total RAM:  %"PRIu64" Mb\n", intel_get_total_ram_mb());
+    igt_info("Total Swap: %"PRIu64" Mb\n", intel_get_total_swap_mb());
 
     return 0;
 }
diff --git a/lib/intel_reg_map.c b/lib/intel_reg_map.c
index 402274baabb9..0e2ee06c8a50 100644
--- a/lib/intel_reg_map.c
+++ b/lib/intel_reg_map.c
@@ -29,8 +29,10 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <sys/types.h>
+
 #include "intel_io.h"
 #include "intel_chipset.h"
+#include "igt_core.h"
 
 static struct intel_register_range gen_bwcl_register_map[] = {
 	{0x00000000, 0x00000fff, INTEL_RANGE_RW},
@@ -141,9 +143,7 @@ intel_get_register_map(uint32_t devid)
 		map.map = gen4_register_map;
 		map.top = 0x80000;
 	} else {
-		fprintf(stderr, "Gen2/3 Ranges are not supported. Please use "
-			"unsafe access.");
-		abort();
+		igt_fail_on("Gen2/3 Ranges are not supported. Please use ""unsafe access.");
 	}
 
 	map.alignment_mask = 0x3;
-- 
2.0.1




More information about the Intel-gfx mailing list