[igt-dev] [PATCH i-g-t 1/2] lib/intel_mmio: add funtions for read/write register funtions

Chris Wilson chris at chris-wilson.co.uk
Thu Aug 29 14:54:15 UTC 2019


From: Daniel Mrzyglod <daniel.t.mrzyglod at intel.com>

This patch is first move to extend functionality of intel_mmio library.
    There was limitation for 1 device, adding pointer for IO functions to
    mmaped area gives us possibility to use those IO functions for other mmaped
    devices.

    v12: change macros for generating inlines
    v11: fix for previous comments
    v10: add macros
    v9: tried to fix castings
    v8: remove unnecessary castings
    v4: reword commitmsg, spelling errors

    Cc: Antonio Argenziano <antonio.argenziano at intel.com>
    Cc: Daniele Spurio Ceraolo <daniele.ceraolospurio at intel.com>
    Cc: Katarzyna Dec <katarzyna.dec at intel.com>
    Cc: Chris Wilson <chris at chris-wilson.co.uk>
    Cc: Petri Latvala <petri.latvala at intel.com>
    Cc: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
    Cc: Jani Nikula <jani.nikula at intel.com>

    Signed-off-by: Daniel Mrzyglod <daniel.t.mrzyglod at intel.com>
---
 lib/intel_io.h   |  48 +++++++++++++++++++---
 lib/intel_mmio.c | 104 +----------------------------------------------
 2 files changed, 44 insertions(+), 108 deletions(-)

diff --git a/lib/intel_io.h b/lib/intel_io.h
index 6014c4855..49ab08ac9 100644
--- a/lib/intel_io.h
+++ b/lib/intel_io.h
@@ -42,12 +42,48 @@ 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);
 
-uint32_t INREG(uint32_t reg);
-uint16_t INREG16(uint32_t reg);
-uint8_t INREG8(uint32_t reg);
-void OUTREG(uint32_t reg, uint32_t val);
-void OUTREG16(uint32_t reg, uint16_t val);
-void OUTREG8(uint32_t reg, uint8_t val);
+/* mmio register access functions that use igt_global_mmio */
+
+#define __ioread(x__) \
+static inline uint##x__##_t ioread##x__(void *mmio, uint32_t reg) \
+{\
+	return *(volatile uint##x__##_t *)(mmio + reg);\
+}
+__ioread(32)
+__ioread(16)
+__ioread(8)
+#undef __ioread
+
+#define __iowrite(x__) \
+static inline void iowrite##x__(void *mmio, uint32_t reg, uint##x__##_t val) \
+{\
+	*(volatile uint##x__##_t *)(mmio + reg) = val; \
+}
+__iowrite(32)
+__iowrite(16)
+__iowrite(8)
+#undef __iowrite
+
+#define __INREG(x__,s__) \
+static inline uint##x__##_t INREG##s__(uint32_t reg) \
+{\
+	return ioread##x__(igt_global_mmio, reg); \
+}
+
+#define __OUTREG(x__,s__) \
+static inline void OUTREG##s__(uint32_t reg, uint##x__##_t val) \
+{\
+	iowrite##x__(igt_global_mmio, reg, val); \
+}
+__INREG(32,)
+__INREG(16,16)
+__INREG(8,8)
+
+__OUTREG(32,)
+__OUTREG(16,16)
+__OUTREG(8,8)
+#undef __INREG
+#undef __OUTREG
 
 /* sideband access functions from intel_iosf.c */
 uint32_t intel_dpio_reg_read(uint32_t reg, int phy);
diff --git a/lib/intel_mmio.c b/lib/intel_mmio.c
index a5458aeba..464e65284 100644
--- a/lib/intel_mmio.c
+++ b/lib/intel_mmio.c
@@ -266,7 +266,7 @@ intel_register_read(uint32_t reg)
 	}
 
 read_out:
-	ret = *(volatile uint32_t *)((volatile char *)igt_global_mmio + reg);
+	ret = ioread32(igt_global_mmio, reg);
 out:
 	return ret;
 }
@@ -303,105 +303,5 @@ intel_register_write(uint32_t reg, uint32_t val)
 		      "Register write blocked for safety ""(*0x%08x = 0x%x)\n", reg, val);
 
 write_out:
-	*(volatile uint32_t *)((volatile char *)igt_global_mmio + reg) = val;
-}
-
-
-/**
- * INREG:
- * @reg: register offset
- *
- * 32-bit read of the register at offset @reg. This function only works when the
- * new register access helper is initialized with intel_register_access_init().
- *
- * This function directly accesses the #igt_global_mmio without safety checks.
- *
- * Returns:
- * The value read from the register.
- */
-uint32_t INREG(uint32_t reg)
-{
-	return *(volatile uint32_t *)((volatile char *)igt_global_mmio + reg);
-}
-
-/**
- * INREG16:
- * @reg: register offset
- *
- * 16-bit read of the register at offset @reg. This function only works when the
- * new register access helper is initialized with intel_register_access_init().
- *
- * This function directly accesses the #igt_global_mmio without safety checks.
- *
- * Returns:
- * The value read from the register.
- */
-uint16_t INREG16(uint32_t reg)
-{
-	return *(volatile uint16_t *)((volatile char *)igt_global_mmio + reg);
-}
-
-/**
- * INREG8:
- * @reg: register offset
- *
- * 8-bit read of the register at offset @reg. This function only works when the
- * new register access helper is initialized with intel_register_access_init().
- *
- * This function directly accesses the #igt_global_mmio without safety checks.
- *
- * Returns:
- * The value read from the register.
- */
-uint8_t INREG8(uint32_t reg)
-{
-	return *((volatile uint8_t *)igt_global_mmio + reg);
-}
-
-/**
- * OUTREG:
- * @reg: register offset
- * @val: value to write
- *
- * 32-bit write of @val to the register at offset @reg. This function only works
- * when the new register access helper is initialized with
- * intel_register_access_init().
- *
- * This function directly accesses the #igt_global_mmio without safety checks.
- */
-void OUTREG(uint32_t reg, uint32_t val)
-{
-	*(volatile uint32_t *)((volatile char *)igt_global_mmio + reg) = val;
-}
-
-/**
- * OUTREG16:
- * @reg: register offset
- * @val: value to write
- *
- * 16-bit write of @val to the register at offset @reg. This function only works
- * when the new register access helper is initialized with
- * intel_register_access_init().
- *
- * This function directly accesses the #igt_global_mmio without safety checks.
- */
-void OUTREG16(uint32_t reg, uint16_t val)
-{
-	*(volatile uint16_t *)((volatile char *)igt_global_mmio + reg) = val;
-}
-
-/**
- * OUTREG8:
- * @reg: register offset
- * @val: value to write
- *
- * 8-bit write of @val to the register at offset @reg. This function only works
- * when the new register access helper is initialized with
- * intel_register_access_init().
- *
- * This function directly accesses the #igt_global_mmio without safety checks.
- */
-void OUTREG8(uint32_t reg, uint8_t val)
-{
-	*((volatile uint8_t *)igt_global_mmio + reg) = val;
+	iowrite32(igt_global_mmio, reg, val);
 }
-- 
2.23.0



More information about the igt-dev mailing list