From patchwork Thu Feb 7 18:39:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 2112721 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 34CC03FCD5 for ; Thu, 7 Feb 2013 18:42:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 26D69E6882 for ; Thu, 7 Feb 2013 10:42:42 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from shiva.chad-versace.us (209-20-75-48.static.cloud-ips.com [209.20.75.48]) by gabe.freedesktop.org (Postfix) with ESMTP id 22B92E6882 for ; Thu, 7 Feb 2013 10:39:30 -0800 (PST) Received: by shiva.chad-versace.us (Postfix, from userid 1005) id 481D388120; Thu, 7 Feb 2013 18:42:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on shiva.chad-versace.us X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable version=3.3.2 Received: from lundgren.nims.intel.com (jfdmzpr02-ext.jf.intel.com [134.134.137.71]) by shiva.chad-versace.us (Postfix) with ESMTPSA id 863EC8845B; Thu, 7 Feb 2013 18:41:27 +0000 (UTC) From: Ben Widawsky To: intel-gfx@lists.freedesktop.org Date: Thu, 7 Feb 2013 10:39:34 -0800 Message-Id: <1360262377-24179-9-git-send-email-ben@bwidawsk.net> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1360262377-24179-1-git-send-email-ben@bwidawsk.net> References: <1360262377-24179-1-git-send-email-ben@bwidawsk.net> Cc: Ben Widawsky Subject: [Intel-gfx] [PATCH 09/12] quick_dump: Connect libpciaccess and other utils X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Make a register access library with sample to do register reads Signed-off-by: Ben Widawsky --- tools/quick_dump/Makefile.am | 14 +++++++++----- tools/quick_dump/chipset.i | 16 ++++++++++++++-- tools/quick_dump/intel_chipset.c | 7 +++++++ tools/quick_dump/quick_dump.py | 5 ++--- tools/quick_dump/reg_access.py | 25 +++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 10 deletions(-) create mode 100755 tools/quick_dump/reg_access.py diff --git a/tools/quick_dump/Makefile.am b/tools/quick_dump/Makefile.am index 6c04dd5..d898f8e 100644 --- a/tools/quick_dump/Makefile.am +++ b/tools/quick_dump/Makefile.am @@ -1,14 +1,18 @@ BUILT_SOURCES = chipset_wrap_python.c -bin_SCRIPTS = quick_dump.py chipset.py +bin_SCRIPTS = quick_dump.py chipset.py reg_access.py lib_LTLIBRARIES = I915ChipsetPython.la -I915ChipsetPython_la_CFLAGS = -I$(top_srcdir)/lib $(PYTHON_CPPFLAGS) -I915ChipsetPython_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS) -I915ChipsetPython_la_SOURCES = chipset_wrap_python.c intel_chipset.c +I915ChipsetPython_la_CFLAGS = -I$(top_srcdir)/lib $(PYTHON_CPPFLAGS) $(CFLAGS) -I/usr/include/libdrm/ +I915ChipsetPython_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS) -lpciaccess +I915ChipsetPython_la_SOURCES = chipset_wrap_python.c intel_chipset.c \ + $(top_srcdir)/lib/intel_drm.c \ + $(top_srcdir)/lib/intel_pci.c \ + $(top_srcdir)/lib/intel_reg_map.c \ + $(top_srcdir)/lib/intel_mmio.c chipset_wrap_python.c: chipset.i - $(SWIG) $(AX_SWIG_PYTHON_OPT) -I$(top_srcdir)/lib -o $@ $< + $(SWIG) $(AX_SWIG_PYTHON_OPT) -I/usr/include -I$(top_srcdir)/lib -o $@ $< all-local: I915ChipsetPython.la $(LN_S) -f .libs/I915ChipsetPython.so _chipset.so diff --git a/tools/quick_dump/chipset.i b/tools/quick_dump/chipset.i index 16c4932..2f4f5ef 100644 --- a/tools/quick_dump/chipset.i +++ b/tools/quick_dump/chipset.i @@ -1,12 +1,24 @@ -%module chipset +%module chipset +%include "stdint.i" %{ +#include +#include #include "intel_chipset.h" extern int is_sandybridge(unsigned short pciid); extern int is_ivybridge(unsigned short pciid); extern int is_valleyview(unsigned short pciid); +extern struct pci_device *intel_get_pci_device(); +extern int intel_register_access_init(struct pci_device *pci_dev, int safe); +extern uint32_t intel_register_read(uint32_t reg); +extern void intel_register_access_fini(); +extern unsigned short pcidev_to_devid(struct pci_device *pci_dev); %} -%include "intel_chipset.h" extern int is_sandybridge(unsigned short pciid); extern int is_ivybridge(unsigned short pciid); extern int is_valleyview(unsigned short pciid); +extern struct pci_device *intel_get_pci_device(); +extern int intel_register_access_init(struct pci_device *pci_dev, int safe); +extern uint32_t intel_register_read(uint32_t reg); +extern void intel_register_access_fini(); +extern unsigned short pcidev_to_devid(struct pci_device *pci_dev); diff --git a/tools/quick_dump/intel_chipset.c b/tools/quick_dump/intel_chipset.c index b242ffc..d6e7f91 100644 --- a/tools/quick_dump/intel_chipset.c +++ b/tools/quick_dump/intel_chipset.c @@ -1,3 +1,4 @@ +#include #include "intel_chipset.h" int is_sandybridge(unsigned short pciid) @@ -14,3 +15,9 @@ int is_valleyview(unsigned short pciid) { return IS_VALLEYVIEW(pciid); } + +/* Simple helper because I couldn't make this work in the script */ +unsigned short pcidev_to_devid(struct pci_device *pdev) +{ + return pdev->device_id; +} diff --git a/tools/quick_dump/quick_dump.py b/tools/quick_dump/quick_dump.py index 59cae1f..44aa2ba 100755 --- a/tools/quick_dump/quick_dump.py +++ b/tools/quick_dump/quick_dump.py @@ -32,9 +32,8 @@ if args.baseless == False: parse_file(file) if args.autodetect: - sysfs_file = open('/sys/class/drm/card0/device/device', 'r') - devid_str = sysfs_file.read() - devid = int(devid_str, 16) + pci_dev = chipset.intel_get_pci_device() + devid = chipset.pcidev_to_devid(pci_dev) if chipset.is_sandybridge(devid): args.profile = open('sandybridge', 'r') elif chipset.is_ivybridge(devid): diff --git a/tools/quick_dump/reg_access.py b/tools/quick_dump/reg_access.py new file mode 100755 index 0000000..0f63424 --- /dev/null +++ b/tools/quick_dump/reg_access.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +import chipset + +def read(reg): + reg = int(reg, 16) + val = chipset.intel_register_read(reg) + return val + +def init(): + pci_dev = chipset.intel_get_pci_device() + ret = chipset.intel_register_access_init(pci_dev, 0) + if ret != 0: + print("Register access init failed"); + return False + return True + +if __name__ == "__main__": + import sys + + if init() == False: + sys.exit() + + reg = sys.argv[1] + print(hex(read(reg))) + chipset.intel_register_access_fini()