[Intel-gfx] [PATCH 12/28] lib: Move non-register things out of intel-gpu-tools.h

Daniel Vetter daniel.vetter at ffwll.ch
Sun Mar 23 15:18:46 CET 2014


Right now almost everything in there concerns itself with register
access. Move everything else out (into drmtest.h for lack of better
place) to prepare for api documentation.

Also rename intel_drm.c to intel_os.c since it contains OS, not
drm abstractions.

Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
---
 lib/Makefile.sources         |   2 +-
 lib/drmtest.h                |  17 +++++
 lib/intel_drm.c              | 158 -------------------------------------------
 lib/intel_gpu_tools.h        |  50 +++++---------
 lib/intel_os.c               | 158 +++++++++++++++++++++++++++++++++++++++++++
 tools/quick_dump/Makefile.am |   2 +-
 6 files changed, 194 insertions(+), 193 deletions(-)
 delete mode 100644 lib/intel_drm.c
 create mode 100644 lib/intel_os.c

diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index e6ada3c900b4..e3942aceab2d 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -15,7 +15,7 @@ libintel_tools_la_SOURCES = 	\
 	intel_batchbuffer.c	\
 	intel_batchbuffer.h	\
 	intel_chipset.h		\
-	intel_drm.c		\
+	intel_os.c		\
 	intel_gpu_tools.h	\
 	intel_mmio.c		\
 	intel_chipset.c		\
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 593f31b97a11..ed6040f7e3b7 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -47,6 +47,19 @@
 #include "ioctl_wrappers.h"
 #include "igt_core.h"
 
+#ifdef ANDROID
+#ifndef HAVE_MMAP64
+extern void*  __mmap2(void *, size_t, int, int, int, off_t);
+static inline void *mmap64(void *addr, size_t length, int prot, int flags,
+        int fd, off64_t offset)
+{
+    return __mmap2(addr, length, prot, flags, fd, offset >> 12);
+}
+#endif
+#endif
+
+#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
+
 int drm_get_card(void);
 int drm_open_any(void);
 int drm_open_any_render(void);
@@ -85,4 +98,8 @@ void igt_drop_root(void);
 
 void igt_wait_for_keypress(void);
 
+/* sysinfo cross-arch wrappers from intel_os.c */
+uint64_t intel_get_total_ram_mb(void);
+uint64_t intel_get_total_swap_mb(void);
+
 #endif /* DRMTEST_H */
diff --git a/lib/intel_drm.c b/lib/intel_drm.c
deleted file mode 100644
index ce4dcbcad5b2..000000000000
--- a/lib/intel_drm.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Copyright © 2008 Intel Corporation
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
- *
- * 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.
- *
- * Authors:
- *    Eric Anholt <eric at anholt.net>
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <err.h>
-#include <assert.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM
-#include <sys/sysinfo.h>
-#elif defined(HAVE_SWAPCTL) /* Solaris */
-#include <sys/swap.h>
-#endif
-
-#include "intel_gpu_tools.h"
-#include "i915_drm.h"
-
-uint64_t
-intel_get_total_ram_mb(void)
-{
-	uint64_t retval;
-
-#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM /* Linux */
-	struct sysinfo sysinf;
-	int ret;
-
-	ret = sysinfo(&sysinf);
-	assert(ret == 0);
-
-	retval = sysinf.totalram;
-	retval *= sysinf.mem_unit;
-#elif defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES) /* Solaris */
-	long pagesize, npages;
-
-	pagesize = sysconf(_SC_PAGESIZE);
-        npages = sysconf(_SC_PHYS_PAGES);
-
-	retval = (uint64_t) pagesize * npages;
-#else
-#error "Unknown how to get RAM size for this OS"
-#endif
-
-	return retval / (1024*1024);
-}
-
-uint64_t
-intel_get_total_swap_mb(void)
-{
-	uint64_t retval;
-
-#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM /* Linux */
-	struct sysinfo sysinf;
-	int ret;
-
-	ret = sysinfo(&sysinf);
-	assert(ret == 0);
-
-	retval = sysinf.freeswap;
-	retval *= sysinf.mem_unit;
-#elif defined(HAVE_SWAPCTL) /* Solaris */
-	long pagesize = sysconf(_SC_PAGESIZE);
-	uint64_t totalpages = 0;
-	swaptbl_t *swt;
-	char *buf;
-	int n, i;
-
-	if ((n = swapctl(SC_GETNSWP, NULL)) == -1) {
-	    perror("swapctl: GETNSWP");
-	    return 0;
-	}
-	if (n == 0) {
-	    /* no error, but no swap devices either */
-	    return 0;
-	}
-
-	swt = malloc(sizeof(struct swaptable) + (n * sizeof(swapent_t)));
-	buf = malloc(n * MAXPATHLEN);
-	if (!swt || !buf) {
-	    perror("malloc");
-	} else {
-	    swt->swt_n = n;
-	    for (i = 0 ; i < n; i++) {
-		swt->swt_ent[i].ste_path = buf + (i * MAXPATHLEN);
-	    }
-
-	    if ((n = swapctl(SC_LIST, swt)) == -1) {
-		perror("swapctl: LIST");
-	    } else {
-		for (i = 0; i < swt->swt_n; i++) {
-		    totalpages += swt->swt_ent[i].ste_pages;
-		}
-	    }
-	}
-	free(swt);
-	free(buf);
-
-	retval = (uint64_t) pagesize * totalpages;
-#else
-#warning "Unknown how to get swap size for this OS"
-	return 0;
-#endif
-
-	return retval / (1024*1024);
-}
-
-
-/*
- * When testing a port to a new platform, create a standalone test binary
- * by running:
- * cc -o porttest intel_drm.c -I.. -DSTANDALONE_TEST `pkg-config --cflags libdrm`
- * and then running the resulting porttest program.
- */
-#ifdef STANDALONE_TEST
-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());
-
-    return 0;
-}
-#endif /* STANDALONE_TEST */
diff --git a/lib/intel_gpu_tools.h b/lib/intel_gpu_tools.h
index 37cbcb19bb4c..aab07290f77b 100644
--- a/lib/intel_gpu_tools.h
+++ b/lib/intel_gpu_tools.h
@@ -34,31 +34,32 @@
 
 #include "intel_chipset.h"
 #include "intel_reg.h"
+#include "drmtest.h"
 
-#ifdef ANDROID
-#ifndef HAVE_MMAP64
-extern void*  __mmap2(void *, size_t, int, int, int, off_t);
-static inline void *mmap64(void *addr, size_t length, int prot, int flags,
-        int fd, off64_t offset)
-{
-    return __mmap2(addr, length, prot, flags, fd, offset >> 12);
-}
-#endif
-#endif
-
-#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
-
+/* register access helpers from intel_mmio.c */
 extern void *mmio;
 void intel_get_mmio(struct pci_device *pci_dev);
+void intel_map_file(char *);
 
-/* New style register access API */
 int intel_register_access_init(struct pci_device *pci_dev, int safe);
 void intel_register_access_fini(void);
 uint32_t intel_register_read(uint32_t reg);
 void intel_register_write(uint32_t reg, uint32_t val);
 int intel_register_access_needs_fakewake(void);
 
-/* Following functions are relevant only for SoCs like Valleyview */
+static inline uint32_t
+INREG(uint32_t reg)
+{
+	return *(volatile uint32_t *)((volatile char *)mmio + reg);
+}
+
+static inline void
+OUTREG(uint32_t reg, uint32_t val)
+{
+	*(volatile uint32_t *)((volatile char *)mmio + reg) = val;
+}
+
+/* sideband access functions from intel_iosf.c */
 uint32_t intel_dpio_reg_read(uint32_t reg, int phy);
 void intel_dpio_reg_write(uint32_t reg, uint32_t val, int phy);
 
@@ -67,6 +68,7 @@ int intel_punit_write(uint8_t addr, uint32_t val);
 int intel_nc_read(uint8_t addr, uint32_t *val);
 int intel_nc_write(uint8_t addr, uint32_t val);
 
+/* register maps from intel_reg_map.c */
 #define INTEL_RANGE_RSVD	(0<<0) /*  Shouldn't be read or written */
 #define INTEL_RANGE_READ	(1<<0)
 #define INTEL_RANGE_WRITE	(1<<1)
@@ -87,22 +89,4 @@ struct intel_register_map {
 struct intel_register_map intel_get_register_map(uint32_t devid);
 struct intel_register_range *intel_get_register_range(struct intel_register_map map, uint32_t offset, uint32_t mode);
 
-
-static inline uint32_t
-INREG(uint32_t reg)
-{
-	return *(volatile uint32_t *)((volatile char *)mmio + reg);
-}
-
-static inline void
-OUTREG(uint32_t reg, uint32_t val)
-{
-	*(volatile uint32_t *)((volatile char *)mmio + reg) = val;
-}
-
-uint64_t intel_get_total_ram_mb(void);
-uint64_t intel_get_total_swap_mb(void);
-
-void intel_map_file(char *);
-
 #endif /* INTEL_GPU_TOOLS_H */
diff --git a/lib/intel_os.c b/lib/intel_os.c
new file mode 100644
index 000000000000..ce4dcbcad5b2
--- /dev/null
+++ b/lib/intel_os.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright © 2008 Intel Corporation
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ *
+ * 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.
+ *
+ * Authors:
+ *    Eric Anholt <eric at anholt.net>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <err.h>
+#include <assert.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM
+#include <sys/sysinfo.h>
+#elif defined(HAVE_SWAPCTL) /* Solaris */
+#include <sys/swap.h>
+#endif
+
+#include "intel_gpu_tools.h"
+#include "i915_drm.h"
+
+uint64_t
+intel_get_total_ram_mb(void)
+{
+	uint64_t retval;
+
+#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM /* Linux */
+	struct sysinfo sysinf;
+	int ret;
+
+	ret = sysinfo(&sysinf);
+	assert(ret == 0);
+
+	retval = sysinf.totalram;
+	retval *= sysinf.mem_unit;
+#elif defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES) /* Solaris */
+	long pagesize, npages;
+
+	pagesize = sysconf(_SC_PAGESIZE);
+        npages = sysconf(_SC_PHYS_PAGES);
+
+	retval = (uint64_t) pagesize * npages;
+#else
+#error "Unknown how to get RAM size for this OS"
+#endif
+
+	return retval / (1024*1024);
+}
+
+uint64_t
+intel_get_total_swap_mb(void)
+{
+	uint64_t retval;
+
+#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM /* Linux */
+	struct sysinfo sysinf;
+	int ret;
+
+	ret = sysinfo(&sysinf);
+	assert(ret == 0);
+
+	retval = sysinf.freeswap;
+	retval *= sysinf.mem_unit;
+#elif defined(HAVE_SWAPCTL) /* Solaris */
+	long pagesize = sysconf(_SC_PAGESIZE);
+	uint64_t totalpages = 0;
+	swaptbl_t *swt;
+	char *buf;
+	int n, i;
+
+	if ((n = swapctl(SC_GETNSWP, NULL)) == -1) {
+	    perror("swapctl: GETNSWP");
+	    return 0;
+	}
+	if (n == 0) {
+	    /* no error, but no swap devices either */
+	    return 0;
+	}
+
+	swt = malloc(sizeof(struct swaptable) + (n * sizeof(swapent_t)));
+	buf = malloc(n * MAXPATHLEN);
+	if (!swt || !buf) {
+	    perror("malloc");
+	} else {
+	    swt->swt_n = n;
+	    for (i = 0 ; i < n; i++) {
+		swt->swt_ent[i].ste_path = buf + (i * MAXPATHLEN);
+	    }
+
+	    if ((n = swapctl(SC_LIST, swt)) == -1) {
+		perror("swapctl: LIST");
+	    } else {
+		for (i = 0; i < swt->swt_n; i++) {
+		    totalpages += swt->swt_ent[i].ste_pages;
+		}
+	    }
+	}
+	free(swt);
+	free(buf);
+
+	retval = (uint64_t) pagesize * totalpages;
+#else
+#warning "Unknown how to get swap size for this OS"
+	return 0;
+#endif
+
+	return retval / (1024*1024);
+}
+
+
+/*
+ * When testing a port to a new platform, create a standalone test binary
+ * by running:
+ * cc -o porttest intel_drm.c -I.. -DSTANDALONE_TEST `pkg-config --cflags libdrm`
+ * and then running the resulting porttest program.
+ */
+#ifdef STANDALONE_TEST
+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());
+
+    return 0;
+}
+#endif /* STANDALONE_TEST */
diff --git a/tools/quick_dump/Makefile.am b/tools/quick_dump/Makefile.am
index e6329c9c2980..7572ee5e5cb5 100644
--- a/tools/quick_dump/Makefile.am
+++ b/tools/quick_dump/Makefile.am
@@ -8,7 +8,7 @@ bin_SCRIPTS = chipset.py
 lib_LTLIBRARIES = I915ChipsetPython.la
 I915ChipsetPython_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS) $(PCIACCESS_LIBS)
 I915ChipsetPython_la_SOURCES = chipset_wrap_python.c chipset_macro_wrap.c \
-			       $(top_srcdir)/lib/intel_drm.c  \
+			       $(top_srcdir)/lib/intel_os.c  \
 			       $(top_srcdir)/lib/intel_chipset.c  \
 			       $(top_srcdir)/lib/intel_reg_map.c  \
 			       $(top_srcdir)/lib/intel_mmio.c  \
-- 
1.8.5.2




More information about the Intel-gfx mailing list