Skip to content

Commit eb79d71

Browse files
illevilucasdemarchi
authored andcommitted
drm/xe: Add xe_mmio_init() initialization function
Add a convenience function for minimal initialization of struct xe_mmio. This function also validates that the entirety of the provided mmio region is usable with struct xe_reg. v2: Modify commit message, add kernel doc, refactor assert (Michal) v3: Fix off-by-one bug, add clarifying macro (Michal) v4: Derive bitfield width from size (Michal) Signed-off-by: Ilia Levi <ilia.levi@intel.com> Reviewed-by: Michal Wajdeczko <michal.wajdeczko@intel.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250213093559.204652-1-ilia.levi@intel.com Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
1 parent 5bee1e2 commit eb79d71

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

drivers/gpu/drm/xe/regs/xe_reg_defs.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@
77
#define _XE_REG_DEFS_H_
88

99
#include <linux/build_bug.h>
10+
#include <linux/log2.h>
11+
#include <linux/sizes.h>
1012

1113
#include "compat-i915-headers/i915_reg_defs.h"
1214

15+
/**
16+
* XE_REG_ADDR_MAX - The upper limit on MMIO register address
17+
*
18+
* This macro specifies the upper limit (not inclusive) on MMIO register offset
19+
* supported by struct xe_reg and functions based on struct xe_mmio.
20+
*
21+
* Currently this is defined as 4 MiB.
22+
*/
23+
#define XE_REG_ADDR_MAX SZ_4M
24+
1325
/**
1426
* struct xe_reg - Register definition
1527
*
@@ -21,7 +33,7 @@ struct xe_reg {
2133
union {
2234
struct {
2335
/** @addr: address */
24-
u32 addr:22;
36+
u32 addr:const_ilog2(XE_REG_ADDR_MAX);
2537
/**
2638
* @masked: register is "masked", with upper 16bits used
2739
* to identify the bits that are updated on the lower

drivers/gpu/drm/xe/xe_gt.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,9 @@ int xe_gt_init(struct xe_gt *gt)
626626
void xe_gt_mmio_init(struct xe_gt *gt)
627627
{
628628
struct xe_tile *tile = gt_to_tile(gt);
629+
struct xe_device *xe = tile_to_xe(tile);
629630

630-
gt->mmio.regs = tile->mmio.regs;
631-
gt->mmio.regs_size = tile->mmio.regs_size;
632-
gt->mmio.tile = tile;
631+
xe_mmio_init(&gt->mmio, tile, tile->mmio.regs, tile->mmio.regs_size);
633632

634633
if (gt->info.type == XE_GT_TYPE_MEDIA) {
635634
gt->mmio.adj_offset = MEDIA_GT_GSI_OFFSET;
@@ -639,7 +638,7 @@ void xe_gt_mmio_init(struct xe_gt *gt)
639638
gt->mmio.adj_limit = 0;
640639
}
641640

642-
if (IS_SRIOV_VF(gt_to_xe(gt)))
641+
if (IS_SRIOV_VF(xe))
643642
gt->mmio.sriov_vf_gt = gt;
644643
}
645644

drivers/gpu/drm/xe/xe_mmio.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ static void tiles_fini(void *arg)
5555
static void mmio_multi_tile_setup(struct xe_device *xe, size_t tile_mmio_size)
5656
{
5757
struct xe_tile *tile;
58-
void __iomem *regs;
5958
u8 id;
6059

6160
/*
@@ -94,13 +93,8 @@ static void mmio_multi_tile_setup(struct xe_device *xe, size_t tile_mmio_size)
9493
}
9594
}
9695

97-
regs = xe->mmio.regs;
98-
for_each_tile(tile, xe, id) {
99-
tile->mmio.regs_size = SZ_4M;
100-
tile->mmio.regs = regs;
101-
tile->mmio.tile = tile;
102-
regs += tile_mmio_size;
103-
}
96+
for_each_remote_tile(tile, xe, id)
97+
xe_mmio_init(&tile->mmio, tile, xe->mmio.regs + id * tile_mmio_size, SZ_4M);
10498
}
10599

106100
int xe_mmio_probe_tiles(struct xe_device *xe)
@@ -140,13 +134,29 @@ int xe_mmio_probe_early(struct xe_device *xe)
140134
}
141135

142136
/* Setup first tile; other tiles (if present) will be setup later. */
143-
root_tile->mmio.regs_size = SZ_4M;
144-
root_tile->mmio.regs = xe->mmio.regs;
145-
root_tile->mmio.tile = root_tile;
137+
xe_mmio_init(&root_tile->mmio, root_tile, xe->mmio.regs, SZ_4M);
146138

147139
return devm_add_action_or_reset(xe->drm.dev, mmio_fini, xe);
148140
}
149141

142+
/**
143+
* xe_mmio_init() - Initialize an MMIO instance
144+
* @mmio: Pointer to the MMIO instance to initialize
145+
* @tile: The tile to which the MMIO region belongs
146+
* @ptr: Pointer to the start of the MMIO region
147+
* @size: The size of the MMIO region in bytes
148+
*
149+
* This is a convenience function for minimal initialization of struct xe_mmio.
150+
*/
151+
void xe_mmio_init(struct xe_mmio *mmio, struct xe_tile *tile, void __iomem *ptr, u32 size)
152+
{
153+
xe_tile_assert(tile, size <= XE_REG_ADDR_MAX);
154+
155+
mmio->regs = ptr;
156+
mmio->regs_size = size;
157+
mmio->tile = tile;
158+
}
159+
150160
static void mmio_flush_pending_writes(struct xe_mmio *mmio)
151161
{
152162
#define DUMMY_REG_OFFSET 0x130030

drivers/gpu/drm/xe/xe_mmio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ struct xe_reg;
1414
int xe_mmio_probe_early(struct xe_device *xe);
1515
int xe_mmio_probe_tiles(struct xe_device *xe);
1616

17+
void xe_mmio_init(struct xe_mmio *mmio, struct xe_tile *tile, void __iomem *ptr, u32 size);
18+
1719
u8 xe_mmio_read8(struct xe_mmio *mmio, struct xe_reg reg);
1820
u16 xe_mmio_read16(struct xe_mmio *mmio, struct xe_reg reg);
1921
void xe_mmio_write32(struct xe_mmio *mmio, struct xe_reg reg, u32 val);

0 commit comments

Comments
 (0)