On 03/07/19 08:30, Chris Wilson wrote:
Before the i915_pmu kernel interface was available, we had to rely on
doing some decidedly dodgy mmio access to registers. However, now that
we have a stable interface via perf for grabbing all the details we
need, that and its supporting infrastructure can be discarded.

Signed-off-by: Chris Wilson <[email protected]>
Cc: Antonio Argenziano <[email protected]>
Cc: Tvrtko Ursulin <[email protected]>

LGTM.

Acked-by: Antonio Argenziano <[email protected]>

---
  overlay/Makefile.am |   2 -
  overlay/gpu-top.c   | 167 +---------------------------
  overlay/igfx.c      | 264 --------------------------------------------
  overlay/igfx.h      |  44 --------
  overlay/meson.build |   1 -
  5 files changed, 1 insertion(+), 477 deletions(-)
  delete mode 100644 overlay/igfx.c
  delete mode 100644 overlay/igfx.h

diff --git a/overlay/Makefile.am b/overlay/Makefile.am
index 51643e498..eeeddbba4 100644
--- a/overlay/Makefile.am
+++ b/overlay/Makefile.am
@@ -31,8 +31,6 @@ intel_gpu_overlay_SOURCES = \
        gpu-perf.c \
        gpu-freq.h \
        gpu-freq.c \
-       igfx.h \
-       igfx.c \
        overlay.h \
        overlay.c \
        power.h \
diff --git a/overlay/gpu-top.c b/overlay/gpu-top.c
index 61b8f62fd..6cec2e943 100644
--- a/overlay/gpu-top.c
+++ b/overlay/gpu-top.c
@@ -33,7 +33,6 @@
#include "igt_perf.h" -#include "igfx.h"
  #include "gpu-top.h"
#define RING_TAIL 0x00
@@ -99,176 +98,12 @@ static int perf_init(struct gpu_top *gt)
        return 0;
  }
-struct mmio_ring {
-       int id;
-       uint32_t base;
-       void *mmio;
-       int idle, wait, sema;
-};
-
-static uint32_t mmio_ring_read(struct mmio_ring *ring, uint32_t reg)
-{
-       return igfx_read(ring->mmio, ring->base + reg);
-}
-
-static int has_execlists(void)
-{
-       int detected = 0;
-       FILE *file;
-
-       file = fopen("/sys/module/i915/parameters/enable_execlists", "r");
-       if (file) {
-               int value;
-               if (fscanf(file, "%d", &value) == 1)
-                       detected = value != 0;
-               fclose(file);
-       }
-
-       return detected;
-
-}
-
-static void mmio_ring_init(struct mmio_ring *ring, void *mmio)
-{
-       uint32_t ctl;
-
-       ring->mmio = mmio;
-
-       ctl = mmio_ring_read(ring, RING_CTL);
-       if ((ctl & 1) == 0 && !has_execlists())
-               ring->id = -1;
-}
-
-static void mmio_ring_reset(struct mmio_ring *ring)
-{
-       ring->idle = 0;
-       ring->wait = 0;
-       ring->sema = 0;
-}
-
-static void mmio_ring_sample(struct mmio_ring *ring)
-{
-       uint32_t head, tail, ctl;
-
-       if (ring->id == -1)
-               return;
-
-       head = mmio_ring_read(ring, RING_HEAD) & ADDR_MASK;
-       tail = mmio_ring_read(ring, RING_TAIL) & ADDR_MASK;
-       ring->idle += head == tail;
-
-       ctl = mmio_ring_read(ring, RING_CTL);
-       ring->wait += !!(ctl & RING_WAIT);
-       ring->sema += !!(ctl & RING_WAIT_SEMAPHORE);
-}
-
-static void mmio_ring_emit(struct mmio_ring *ring, int samples, union 
gpu_top_payload *payload)
-{
-       if (ring->id == -1)
-               return;
-
-       payload[ring->id].u.busy = 100 - 100 * ring->idle / samples;
-       payload[ring->id].u.wait = 100 * ring->wait / samples;
-       payload[ring->id].u.sema = 100 * ring->sema / samples;
-}
-
-static void mmio_init(struct gpu_top *gt)
-{
-       struct mmio_ring render_ring = {
-               .base = 0x2030,
-               .id = 0,
-       }, bsd_ring = {
-               .base = 0x4030,
-               .id = 1,
-       }, bsd6_ring = {
-               .base = 0x12030,
-               .id = 1,
-       }, blt_ring = {
-               .base = 0x22030,
-               .id = 2,
-       };
-       const struct igfx_info *info;
-       struct pci_device *igfx;
-       void *mmio;
-       int fd[2], i;
-
-       igfx = igfx_get();
-       if (!igfx)
-               return;
-
-       if (pipe(fd) < 0)
-               return;
-
-       info = igfx_get_info(igfx);
-
-       switch (fork()) {
-       case -1: return;
-       default:
-                fcntl(fd[0], F_SETFL, fcntl(fd[0], F_GETFL) | O_NONBLOCK);
-                gt->fd = fd[0];
-                gt->type = MMIO;
-                gt->ring[0].name = "render";
-                gt->num_rings = 1;
-                if (info->gen >= 040) {
-                        gt->ring[1].name = "bitstream";
-                        gt->num_rings++;
-                }
-                if (info->gen >= 060) {
-                        gt->ring[2].name = "blt";
-                        gt->num_rings++;
-                }
-                close(fd[1]);
-                return;
-       case 0:
-                close(fd[0]);
-                break;
-       }
-
-       mmio = igfx_get_mmio(igfx);
-       if (mmio == NULL)
-               exit(127);
-
-       mmio_ring_init(&render_ring, mmio);
-       if (info->gen >= 060) {
-               bsd_ring = bsd6_ring;
-               mmio_ring_init(&blt_ring, mmio);
-       }
-       if (info->gen >= 040) {
-               mmio_ring_init(&bsd_ring, mmio);
-       }
-
-       for (;;) {
-               union gpu_top_payload payload[MAX_RINGS];
-
-               mmio_ring_reset(&render_ring);
-               mmio_ring_reset(&bsd_ring);
-               mmio_ring_reset(&blt_ring);
-
-               for (i = 0; i < 1000; i++) {
-                       mmio_ring_sample(&render_ring);
-                       mmio_ring_sample(&bsd_ring);
-                       mmio_ring_sample(&blt_ring);
-                       usleep(1000);
-               }
-
-               memset(payload, 0, sizeof(payload));
-               mmio_ring_emit(&render_ring, 1000, payload);
-               mmio_ring_emit(&bsd_ring, 1000, payload);
-               mmio_ring_emit(&blt_ring, 1000, payload);
-               assert(write(fd[1], payload, sizeof(payload))
-                      == sizeof(payload));
-       }
-}
-
  void gpu_top_init(struct gpu_top *gt)
  {
        memset(gt, 0, sizeof(*gt));
        gt->fd = -1;
- if (perf_init(gt) == 0)
-               return;
-
-       mmio_init(gt);
+       perf_init(gt);
  }
int gpu_top_update(struct gpu_top *gt)
diff --git a/overlay/igfx.c b/overlay/igfx.c
deleted file mode 100644
index 6d82bc8d3..000000000
--- a/overlay/igfx.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Copyright © 2013 Intel Corporation
- *
- * 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.
- *
- */
-
-#include <pciaccess.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-
-#include "igfx.h"
-#include "../lib/i915_pciids.h"
-
-static const struct igfx_info generic_info = {
-       .gen = -1,
-};
-
-#if 0
-static const struct igfx_info i81x_info = {
-       .gen = 010,
-};
-#endif
-
-static const struct igfx_info i830_info = {
-       .gen = 020,
-};
-static const struct igfx_info i845_info = {
-       .gen = 020,
-};
-static const struct igfx_info i855_info = {
-       .gen = 021,
-};
-static const struct igfx_info i865_info = {
-       .gen = 022,
-};
-
-static const struct igfx_info i915_info = {
-       .gen = 030,
-};
-static const struct igfx_info i945_info = {
-       .gen = 031,
-};
-
-static const struct igfx_info g33_info = {
-       .gen = 033,
-};
-
-static const struct igfx_info i965_info = {
-       .gen = 040,
-};
-
-static const struct igfx_info g4x_info = {
-       .gen = 045,
-};
-
-static const struct igfx_info ironlake_info = {
-       .gen = 050,
-};
-
-static const struct igfx_info sandybridge_info = {
-       .gen = 060,
-};
-
-static const struct igfx_info ivybridge_info = {
-       .gen = 070,
-};
-
-static const struct igfx_info valleyview_info = {
-       .gen = 071,
-};
-
-static const struct igfx_info haswell_info = {
-       .gen = 075,
-};
-
-static const struct igfx_info broadwell_info = {
-       .gen = 0100,
-};
-
-static const struct igfx_info cherryview_info = {
-       .gen = 0101,
-};
-
-static const struct igfx_info skylake_info = {
-       .gen = 0110,
-};
-
-static const struct igfx_info broxton_info = {
-       .gen = 0111,
-};
-
-static const struct pci_id_match match[] = {
-#if 0
-       INTEL_VGA_DEVICE(PCI_CHIP_I810, &i81x_info),
-       INTEL_VGA_DEVICE(PCI_CHIP_I810_DC100, &i81x_info),
-       INTEL_VGA_DEVICE(PCI_CHIP_I810_E, &i81x_info),
-       INTEL_VGA_DEVICE(PCI_CHIP_I815, &i81x_info),
-#endif
-
-       INTEL_I830_IDS(&i830_info),
-       INTEL_I845G_IDS(&i845_info),
-       INTEL_I85X_IDS(&i855_info),
-       INTEL_I865G_IDS(&i865_info),
-
-       INTEL_I915G_IDS(&i915_info),
-       INTEL_I915GM_IDS(&i915_info),
-       INTEL_I945G_IDS(&i945_info),
-       INTEL_I945GM_IDS(&i945_info),
-
-       INTEL_G33_IDS(&g33_info),
-       INTEL_PINEVIEW_IDS(&g33_info),
-
-       INTEL_I965G_IDS(&i965_info),
-       INTEL_I965GM_IDS(&i965_info),
-
-       INTEL_G45_IDS(&g4x_info),
-       INTEL_GM45_IDS(&g4x_info),
-
-       INTEL_IRONLAKE_D_IDS(&ironlake_info),
-       INTEL_IRONLAKE_M_IDS(&ironlake_info),
-
-       INTEL_SNB_D_IDS(&sandybridge_info),
-       INTEL_SNB_M_IDS(&sandybridge_info),
-
-       INTEL_IVB_D_IDS(&ivybridge_info),
-       INTEL_IVB_M_IDS(&ivybridge_info),
-
-       INTEL_HSW_IDS(&haswell_info),
-
-       INTEL_VLV_IDS(&valleyview_info),
-
-       INTEL_BDW_IDS(&broadwell_info),
-
-       INTEL_CHV_IDS(&cherryview_info),
-
-       INTEL_SKL_IDS(&skylake_info),
-       INTEL_BXT_IDS(&broxton_info),
-
-       INTEL_VGA_DEVICE(PCI_MATCH_ANY, &generic_info),
-
-       { 0, 0, 0 },
-};
-
-struct pci_device *igfx_get(void)
-{
-       struct pci_device *dev;
-
-       if (pci_system_init())
-               return 0;
-
-       dev = pci_device_find_by_slot(0, 0, 2, 0);
-       if (dev == NULL || dev->vendor_id != 0x8086) {
-               struct pci_device_iterator *iter;
-
-               iter = pci_id_match_iterator_create(match);
-               if (!iter)
-                       return 0;
-
-               dev = pci_device_next(iter);
-               pci_iterator_destroy(iter);
-       }
-
-       return dev;
-}
-
-const struct igfx_info *igfx_get_info(struct pci_device *dev)
-{
-       int i;
-
-       if (!dev)
-               return 0;
-
-       for (i = 0; match[i].device_id != PCI_MATCH_ANY; i++)
-               if (dev->device_id == match[i].device_id)
-                       return (const struct igfx_info *)match[i].match_data;
-
-       return &generic_info;
-}
-
-static int forcewake = -1;
-
-static void
-igfx_forcewake(void)
-{
-       char buf[1024];
-       const char *path[] = {
-               "/sys/kernel/debug/dri/",
-               "/debug/dri/",
-               0,
-       };
-       int i, j;
-
-       for (j = 0; path[j]; j++) {
-               struct stat st;
-
-               if (stat(path[j], &st))
-                       continue;
-
-               for (i = 0; i < 16; i++) {
-                       snprintf(buf, sizeof(buf),
-                                "%s/%i/i915_forcewake_user",
-                                path[j], i);
-                       forcewake = open(buf, 0);
-                       if (forcewake != -1)
-                               return;
-               }
-       }
-}
-
-void *igfx_get_mmio(struct pci_device *dev)
-{
-       const struct igfx_info *info;
-       int mmio_bar, mmio_size;
-       void *mmio;
-
-       info = igfx_get_info(dev);
-       if (info->gen >> 3 == 2)
-               mmio_bar = 1;
-       else
-               mmio_bar = 0;
-
-       if (info->gen < 030)
-               mmio_size = 512*1024;
-       else if (info->gen < 050)
-               mmio_size = 512*1024;
-       else
-               mmio_size = 2*1024*1024;
-
-       if (pci_device_probe(dev))
-               return 0;
-
-       if (pci_device_map_range(dev,
-                                dev->regions[mmio_bar].base_addr,
-                                mmio_size,
-                                PCI_DEV_MAP_FLAG_WRITABLE,
-                                &mmio))
-               return 0;
-
-       if (info->gen >= 060)
-               igfx_forcewake();
-
-       return mmio;
-}
-
diff --git a/overlay/igfx.h b/overlay/igfx.h
deleted file mode 100644
index c99af186c..000000000
--- a/overlay/igfx.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright © 2013 Intel Corporation
- *
- * 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.
- *
- */
-
-#ifndef IGFX_H
-#define IGFX_H
-
-struct igfx_info {
-       int gen;
-};
-
-struct pci_device;
-
-struct pci_device *igfx_get(void);
-const struct igfx_info *igfx_get_info(struct pci_device *pci_dev);
-void *igfx_get_mmio(struct pci_device *pci_dev);
-
-static inline uint32_t
-igfx_read(void *mmio, uint32_t reg)
-{
-       return *(volatile uint32_t *)((volatile char *)mmio + reg);
-}
-
-#endif /* IGFX_H */
diff --git a/overlay/meson.build b/overlay/meson.build
index d133b6bed..d2d2b16a8 100644
--- a/overlay/meson.build
+++ b/overlay/meson.build
@@ -11,7 +11,6 @@ gpu_overlay_src = [
        'gpu-top.c',
        'gpu-perf.c',
        'gpu-freq.c',
-       'igfx.c',
        'overlay.c',
        'power.c',
        'rc6.c',

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to