From patchwork Sun Mar 23 14:18:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 3879061 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 350019F2B6 for ; Sun, 23 Mar 2014 14:19:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E0254201BF for ; Sun, 23 Mar 2014 14:19:32 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8AB4A2018E for ; Sun, 23 Mar 2014 14:19:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 19A076E69A; Sun, 23 Mar 2014 07:19:31 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-ee0-f52.google.com (mail-ee0-f52.google.com [74.125.83.52]) by gabe.freedesktop.org (Postfix) with ESMTP id 840616E694 for ; Sun, 23 Mar 2014 07:19:27 -0700 (PDT) Received: by mail-ee0-f52.google.com with SMTP id e49so3503957eek.11 for ; Sun, 23 Mar 2014 07:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=sivSRZ7eW6zTNHxsG+ds3jofXpOWCOB4BQO0W5gJViA=; b=Ws8r3/fEdrwPgfDsH5E4OWFP8DOdFOdKE5KcOcA0TLWO0Lq0pVsHgUsnnvjYU2XjYL rC0d1dHvaA27oL1z+7bFQcYOC7Smi9LrJncCaCrjmfsfMJyfTFR8GA77HlcrCsRnsKxW suQTsMk1V0k0XCsz8BpDFL4U2QedcL16TosPM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=sivSRZ7eW6zTNHxsG+ds3jofXpOWCOB4BQO0W5gJViA=; b=KsAnwnZqdFcAY7xM4MQAm0NqdLGKYKp3BLXTxBuBWy+A4At9tenVt1/utlWKzPlAGp +VooahYV1l7vyAyVggmpegUvNRX4cfUbqsgCDVef4Ol1LYMroktTU8n7Zydb8xbTsj5K dxv3fVO51DJAf7q6kiXFk6EgzfQXCYRNftaMM86TrYwrp7rM2XdN0xIrjLQgIsFrDUY6 dMJbwHTe6Llz72cnLiwJ4V765aoqmsyyzZ4dMFAw927GmwdsfzSp03c3garxdI2V4leo l1i1erVQpAXid7W1wOJrEx7XaiucKeB7KBlnfxe3JvP+dU23jVhjj1TFAaqLkNU8hSvE xp7Q== X-Gm-Message-State: ALoCoQk9HMlFC6i+D2iAjdEfS9wkhu6NSxNpQy6PNBe4N30trr1PN91L+FN68GFIy1HY60XzqgOp X-Received: by 10.15.31.137 with SMTP id y9mr58486987eeu.12.1395584366818; Sun, 23 Mar 2014 07:19:26 -0700 (PDT) Received: from phenom.ffwll.local (84-73-67-144.dclient.hispeed.ch. [84.73.67.144]) by mx.google.com with ESMTPSA id cb5sm26392589eeb.18.2014.03.23.07.19.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Mar 2014 07:19:26 -0700 (PDT) From: Daniel Vetter To: Intel Graphics Development Date: Sun, 23 Mar 2014 15:18:46 +0100 Message-Id: <1395584342-11812-13-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1395584342-11812-1-git-send-email-daniel.vetter@ffwll.ch> References: <1395584342-11812-1-git-send-email-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Cc: Daniel Vetter Subject: [Intel-gfx] [PATCH 12/28] lib: Move non-register things out of intel-gpu-tools.h X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM -#include -#elif defined(HAVE_SWAPCTL) /* Solaris */ -#include -#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 + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM +#include +#elif defined(HAVE_SWAPCTL) /* Solaris */ +#include +#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 \