]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/ast: Move 32-bit register-access helpers to ast_drv.{c, h}
authorThomas Zimmermann <tzimmermann@suse.de>
Fri, 27 Mar 2026 13:32:54 +0000 (14:32 +0100)
committerThomas Zimmermann <tzimmermann@suse.de>
Wed, 8 Apr 2026 09:04:48 +0000 (11:04 +0200)
The helpers ast_mindwm() and ast_moutdwm() access the I/O memory of
the various IP modules on the Aspeed device. This is based on the
"P-Bus to AHB Bridge" interface.

Reimplement the access function with properly defined constants and
helper macros.

- Define P2A constants for the related registers and addresses. The P2A
interface is located in the memory range at [0x00000000, 0x00010000].

- Memory access is segmented. An address' upper 16-bit select the
memory segment, the lower 16-bit select the offset within the segment.
Implement segment selection in a shared helper __ast_segsel(). Validate
that the segment hs been changes. This logic has previously been part
of __ast_moudwm() and __ast_mindwm(). Relax the CPU while busy-waiting.

- Put intra-segment reads and writes in the helpers __ast_rdseg32()
and __ast_wrseg32(). The helpers set the segment offset automatically.

- Reimplement the existing interfaces on top of these helpers.

Put the new implementation next to the other I/O helpers.

v2:
- fix typo in commit description (Jocelyn)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://patch.msgid.link/20260327133532.79696-3-tzimmermann@suse.de
drivers/gpu/drm/ast/ast_drv.c
drivers/gpu/drm/ast/ast_drv.h
drivers/gpu/drm/ast/ast_post.c
drivers/gpu/drm/ast/ast_post.h
drivers/gpu/drm/ast/ast_reg.h

index b9a9b050b5461ddb79e20ddd131d4fbc35ac73c9..05ec3542ab62f43e4455ef5b3b387c6f1284965b 100644 (file)
@@ -47,6 +47,65 @@ static int ast_modeset = -1;
 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
 module_param_named(modeset, ast_modeset, int, 0400);
 
+/*
+ * Register access
+ */
+
+/* Select R/W segment */
+static void __ast_selseg(void __iomem *regs, u32 r)
+{
+       u32 p2a04, p2a04_base;
+
+       p2a04 = r & AST_REG_P2A04_BASE_MASK;
+       __ast_write32(regs, AST_REG_P2A04, p2a04);
+       __ast_write32(regs, AST_REG_P2A00, AST_REG_P2A00_PROTECTION_KEY);
+
+       do {
+               cpu_relax();
+               p2a04_base = __ast_read32(regs, AST_REG_P2A04);
+               p2a04_base &= AST_REG_P2A04_BASE_MASK;
+       } while (p2a04_base != p2a04);
+}
+
+/* Read within segment */
+static u32 __ast_rdseg32(void __iomem *regs, u32 r)
+{
+       return __ast_read32(regs, AST_REG_P2A_ADDR(r));
+}
+
+/* Write within segment */
+static void __ast_wrseg32(void __iomem *regs, u32 r, u32 v)
+{
+       __ast_write32(regs, AST_REG_P2A_ADDR(r), v);
+}
+
+u32 __ast_mindwm(void __iomem *regs, u32 r)
+{
+       __ast_selseg(regs, r);
+
+       return __ast_rdseg32(regs, r);
+}
+
+void __ast_moutdwm(void __iomem *regs, u32 r, u32 v)
+{
+       __ast_selseg(regs, r);
+       __ast_wrseg32(regs, r, v);
+}
+
+u32 ast_mindwm(struct ast_device *ast, u32 r)
+{
+       return __ast_mindwm(ast->regs, r);
+}
+
+void ast_moutdwm(struct ast_device *ast, u32 r, u32 v)
+{
+       __ast_moutdwm(ast->regs, r, v);
+}
+
+/*
+ * AST device
+ */
+
 void ast_device_init(struct ast_device *ast,
                     enum ast_chip chip,
                     enum ast_config_mode config_mode,
index 787e38c6c17dd5f9fe83e2fbee30fa89dc04cc99..3eedf8239333b9d5e4f4bb67645b82f8e8e9733f 100644 (file)
@@ -259,26 +259,20 @@ static inline bool __ast_gen_is_eq(struct ast_device *ast, unsigned long gen)
 #define IS_AST_GEN6(__ast)     __ast_gen_is_eq(__ast, 6)
 #define IS_AST_GEN7(__ast)     __ast_gen_is_eq(__ast, 7)
 
+/*
+ * MMIO access
+ */
+
 static inline u8 __ast_read8(const void __iomem *addr, u32 reg)
 {
        return ioread8(addr + reg);
 }
 
-static inline u32 __ast_read32(const void __iomem *addr, u32 reg)
-{
-       return ioread32(addr + reg);
-}
-
 static inline void __ast_write8(void __iomem *addr, u32 reg, u8 val)
 {
        iowrite8(val, addr + reg);
 }
 
-static inline void __ast_write32(void __iomem *addr, u32 reg, u32 val)
-{
-       iowrite32(val, addr + reg);
-}
-
 static inline u8 __ast_read8_i(void __iomem *addr, u32 reg, u8 index)
 {
        __ast_write8(addr, reg, index);
@@ -307,16 +301,6 @@ static inline void __ast_write8_i_masked(void __iomem *addr, u32 reg, u8 index,
        __ast_write8_i(addr, reg, index, tmp | val);
 }
 
-static inline u32 ast_read32(struct ast_device *ast, u32 reg)
-{
-       return __ast_read32(ast->regs, reg);
-}
-
-static inline void ast_write32(struct ast_device *ast, u32 reg, u32 val)
-{
-       __ast_write32(ast->regs, reg, val);
-}
-
 static inline u8 ast_io_read8(struct ast_device *ast, u32 reg)
 {
        return __ast_read8(ast->ioregs, reg);
@@ -349,6 +333,39 @@ static inline void ast_set_index_reg_mask(struct ast_device *ast, u32 base, u8 i
        __ast_write8_i_masked(ast->ioregs, base, index, preserve_mask, val);
 }
 
+/*
+ * Register access
+ */
+
+static inline u32 __ast_read32(const void __iomem *addr, u32 reg)
+{
+       return ioread32(addr + reg);
+}
+
+static inline void __ast_write32(void __iomem *addr, u32 reg, u32 val)
+{
+       iowrite32(val, addr + reg);
+}
+
+static inline u32 ast_read32(struct ast_device *ast, u32 reg)
+{
+       return __ast_read32(ast->regs, reg);
+}
+
+static inline void ast_write32(struct ast_device *ast, u32 reg, u32 val)
+{
+       __ast_write32(ast->regs, reg, val);
+}
+
+u32 __ast_mindwm(void __iomem *regs, u32 r);
+void __ast_moutdwm(void __iomem *regs, u32 r, u32 v);
+u32 ast_mindwm(struct ast_device *ast, u32 r);
+void ast_moutdwm(struct ast_device *ast, u32 r, u32 v);
+
+/*
+ * VBIOS
+ */
+
 struct ast_vbios_stdtable {
        u8 misc;
        u8 seq[4];
@@ -517,8 +534,6 @@ struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
 
 /* ast post */
 int ast_post_gpu(struct ast_device *ast);
-u32 ast_mindwm(struct ast_device *ast, u32 r);
-void ast_moutdwm(struct ast_device *ast, u32 r, u32 v);
 
 int ast_vga_output_init(struct ast_device *ast);
 int ast_sil164_output_init(struct ast_device *ast);
index b72914dbed38d3edbfc48ae511552255cda65db6..5cec5d735b6ace9b450639acfeb847c6d7bf4468 100644 (file)
 #include "ast_drv.h"
 #include "ast_post.h"
 
-u32 __ast_mindwm(void __iomem *regs, u32 r)
-{
-       u32 data;
-
-       __ast_write32(regs, 0xf004, r & 0xffff0000);
-       __ast_write32(regs, 0xf000, 0x1);
-
-       do {
-               data = __ast_read32(regs, 0xf004) & 0xffff0000;
-       } while (data != (r & 0xffff0000));
-
-       return __ast_read32(regs, 0x10000 + (r & 0x0000ffff));
-}
-
-void __ast_moutdwm(void __iomem *regs, u32 r, u32 v)
-{
-       u32 data;
-
-       __ast_write32(regs, 0xf004, r & 0xffff0000);
-       __ast_write32(regs, 0xf000, 0x1);
-
-       do {
-               data = __ast_read32(regs, 0xf004) & 0xffff0000;
-       } while (data != (r & 0xffff0000));
-
-       __ast_write32(regs, 0x10000 + (r & 0x0000ffff), v);
-}
-
-u32 ast_mindwm(struct ast_device *ast, u32 r)
-{
-       return __ast_mindwm(ast->regs, r);
-}
-
-void ast_moutdwm(struct ast_device *ast, u32 r, u32 v)
-{
-       __ast_moutdwm(ast->regs, r, v);
-}
-
 int ast_post_gpu(struct ast_device *ast)
 {
        int ret;
index aa5d247bebe8d3091c627018da7f95e1fcb66bb6..41cd753b7f679e60a2150194a60132c797c1a4de 100644 (file)
@@ -35,9 +35,6 @@ struct ast_dramstruct {
 #define AST_DRAMSTRUCT_IS(_entry, _name) \
        ((_entry)->index == __AST_DRAMSTRUCT_INDEX(_name))
 
-u32 __ast_mindwm(void __iomem *regs, u32 r);
-void __ast_moutdwm(void __iomem *regs, u32 r, u32 v);
-
 bool mmc_test(struct ast_device *ast, u32 datagen, u8 test_ctl);
 bool mmc_test_burst(struct ast_device *ast, u32 datagen);
 
index 30578e3b07e43ae05a09341648056c5fc1750135..ca9403efc7f9125fe0ecacaecc1ecb082c95e7ab 100644 (file)
 #define AST_IO_VGAIR1_R                        (0x5A)
 #define AST_IO_VGAIR1_VREFRESH         BIT(3)
 
+/*
+ * P-Bus to AHB Bridge (0x00000000 - 0x0001ffff)
+ */
+
+#define AST_REG_P2A_BASE                       (0x00000000)
+#define AST_REG_P2A(__offset)                  (AST_REG_P2A_BASE + (__offset))
+#define AST_REG_P2A_ADDR(__addr)               AST_REG_P2A(0x10000 + ((__addr) & GENMASK(15, 0)))
+#define AST_REG_P2A00                          AST_REG_P2A(0xf000)
+#define AST_REG_P2A00_PROTECTION_KEY           (0x01)
+#define AST_REG_P2A04                          AST_REG_P2A(0xf004)
+#define AST_REG_P2A04_BASE_MASK                        GENMASK(31, 16)
+
 #endif