[igt-dev] [PATCH i-g-t v3 3/5] lib/intel_mmio: different functions are used for mapping if fd is known.
Daniel Mrzyglod
daniel.t.mrzyglod at intel.com
Mon Apr 15 08:59:35 UTC 2019
intel_mmio_use_pci_bar function if fd is known now use igt_device_map_pci_bar_region.
old method from pciaccess library is left for legacy
apps that work when driver is not loaded.
Signed-off-by: Daniel Mrzyglod <daniel.t.mrzyglod at intel.com>
---
lib/intel_io.h | 2 +-
lib/intel_mmio.c | 32 +++++++++++++++++++++++---------
tools/intel_audio_dump.c | 2 +-
tools/intel_backlight.c | 2 +-
tools/intel_gpu_time.c | 2 +-
tools/intel_lid.c | 2 +-
tools/intel_reg.c | 2 +-
tools/intel_reg_checker.c | 2 +-
8 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/lib/intel_io.h b/lib/intel_io.h
index 6014c485..09fea386 100644
--- a/lib/intel_io.h
+++ b/lib/intel_io.h
@@ -33,7 +33,7 @@
/* register access helpers from intel_mmio.c */
extern void *igt_global_mmio;
-void intel_mmio_use_pci_bar(struct pci_device *pci_dev);
+void intel_mmio_use_pci_bar(struct pci_device *pci_dev, int fd);
void intel_mmio_use_dump_file(char *file);
int intel_register_access_init(struct pci_device *pci_dev, int safe, int fd);
diff --git a/lib/intel_mmio.c b/lib/intel_mmio.c
index a5458aeb..daca1ad2 100644
--- a/lib/intel_mmio.c
+++ b/lib/intel_mmio.c
@@ -45,6 +45,7 @@
#include "igt_core.h"
#include "igt_gt.h"
#include "intel_chipset.h"
+#include "igt_device.h"
/**
* SECTION:intel_io
@@ -115,7 +116,7 @@ intel_mmio_use_dump_file(char *file)
* @pci_dev can be obtained from intel_get_pci_device().
*/
void
-intel_mmio_use_pci_bar(struct pci_device *pci_dev)
+intel_mmio_use_pci_bar(struct pci_device *pci_dev, int fd)
{
uint32_t devid, gen;
int mmio_bar, mmio_size;
@@ -135,14 +136,27 @@ intel_mmio_use_pci_bar(struct pci_device *pci_dev)
else
mmio_size = 2*1024*1024;
- error = pci_device_map_range (pci_dev,
- pci_dev->regions[mmio_bar].base_addr,
- mmio_size,
- PCI_DEV_MAP_FLAG_WRITABLE,
- &igt_global_mmio);
+ /* It's for some legacy tools existing in tree that require
+ * working without driver
+ */
+
+ if (fd == -1) {
+ error = pci_device_map_range(pci_dev,
+ pci_dev->regions[mmio_bar].base_addr,
+ mmio_size,
+ PCI_DEV_MAP_FLAG_WRITABLE,
+ &igt_global_mmio);
+
+ igt_fail_on_f(error != 0, "Couldn't map MMIO region\n");
+ } else {
+ /* This method is much more convenient when we have many
+ * concurrent PCI devices
+ */
+ igt_global_mmio = igt_device_map_pci_bar_region(fd, mmio_bar,
+ mmio_size);
+ }
- igt_fail_on_f(error != 0,
- "Couldn't map MMIO region\n");
+ igt_fail_on_f(error != 0, "Couldn't map MMIO region\n");
}
static void
@@ -171,7 +185,7 @@ intel_register_access_init(struct pci_device *pci_dev, int safe, int fd)
/* after old API is deprecated, remove this */
if (igt_global_mmio == NULL)
- intel_mmio_use_pci_bar(pci_dev);
+ intel_mmio_use_pci_bar(pci_dev, fd);
igt_assert(igt_global_mmio != NULL);
diff --git a/tools/intel_audio_dump.c b/tools/intel_audio_dump.c
index 90260a2f..d952e54b 100644
--- a/tools/intel_audio_dump.c
+++ b/tools/intel_audio_dump.c
@@ -2473,7 +2473,7 @@ int main(int argc, char **argv)
if (argc == 2)
intel_mmio_use_dump_file(argv[1]);
else
- intel_mmio_use_pci_bar(pci_dev);
+ intel_mmio_use_pci_bar(pci_dev, -1);
printf("%s audio registers:\n\n", intel_get_device_info(devid)->codename);
if (IS_VALLEYVIEW(devid)) {
diff --git a/tools/intel_backlight.c b/tools/intel_backlight.c
index 067fd418..e4850e88 100644
--- a/tools/intel_backlight.c
+++ b/tools/intel_backlight.c
@@ -40,7 +40,7 @@ int main(int argc, char** argv)
{
uint32_t current, max;
- intel_mmio_use_pci_bar(intel_get_pci_device());
+ intel_mmio_use_pci_bar(intel_get_pci_device(), -1);
current = INREG(BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK;
max = INREG(BLC_PWM_PCH_CTL2) >> 16;
diff --git a/tools/intel_gpu_time.c b/tools/intel_gpu_time.c
index 56d65fe0..4ed6430e 100644
--- a/tools/intel_gpu_time.c
+++ b/tools/intel_gpu_time.c
@@ -67,7 +67,7 @@ int main(int argc, char **argv)
static struct rusage rusage;
int status;
- intel_mmio_use_pci_bar(intel_get_pci_device());
+ intel_mmio_use_pci_bar(intel_get_pci_device(), -1);
if (argc == 1) {
fprintf(stderr, "usage: %s cmd [args...]\n", argv[0]);
diff --git a/tools/intel_lid.c b/tools/intel_lid.c
index 37c6ba5e..f45756e2 100644
--- a/tools/intel_lid.c
+++ b/tools/intel_lid.c
@@ -119,7 +119,7 @@ int main(int argc, char **argv)
{
int swf14, acpi_lid;
- intel_mmio_use_pci_bar(intel_get_pci_device());
+ intel_mmio_use_pci_bar(intel_get_pci_device(), -1);
while (1) {
swf14 = INREG(SWF14);
diff --git a/tools/intel_reg.c b/tools/intel_reg.c
index 1247b70b..947ec378 100644
--- a/tools/intel_reg.c
+++ b/tools/intel_reg.c
@@ -650,7 +650,7 @@ static int intel_reg_snapshot(struct config *config, int argc, char *argv[])
return EXIT_FAILURE;
}
- intel_mmio_use_pci_bar(config->pci_dev);
+ intel_mmio_use_pci_bar(config->pci_dev, -1);
/* XXX: error handling */
if (write(1, igt_global_mmio, config->pci_dev->regions[mmio_bar].size) == -1)
diff --git a/tools/intel_reg_checker.c b/tools/intel_reg_checker.c
index 6bde63ec..92a89ae0 100644
--- a/tools/intel_reg_checker.c
+++ b/tools/intel_reg_checker.c
@@ -345,7 +345,7 @@ int main(int argc, char** argv)
dev = intel_get_pci_device();
devid = dev->device_id;
- intel_mmio_use_pci_bar(dev);
+ intel_mmio_use_pci_bar(dev, -1);
if (IS_GEN7(devid))
gen = 7;
--
2.20.1
More information about the igt-dev
mailing list