From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: "Michal Wajdeczko" <michal.wajdeczko@intel.com>,
"Piotr Piórkowski" <piotr.piorkowski@intel.com>
Subject: [PATCH v2 2/5] drm/xe: Add helper to calculate adjusted register offset
Date: Tue, 23 Apr 2024 20:04:33 +0200 [thread overview]
Message-ID: <20240423180436.2089-3-michal.wajdeczko@intel.com> (raw)
In-Reply-To: <20240423180436.2089-1-michal.wajdeczko@intel.com>
Our MMIO accessing functions automatically adjust addresses for the
media registers based on mmio.adj_limit and mmio.adj_offset logic.
Move it to the separate helper to avoid code duplication and to
allow using it by the upcoming changes to PF driver code.
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Piotr Piórkowski <piotr.piorkowski@intel.com>
---
v2: start using helper (Piotr)
make gt param const to allow use in xe_mmio_in_range()
assert that we adjust both or none addr in xe_mmio_read64_2x32()
---
drivers/gpu/drm/xe/xe_mmio.c | 38 ++++++++++++++----------------------
drivers/gpu/drm/xe/xe_mmio.h | 7 +++++++
2 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_mmio.c b/drivers/gpu/drm/xe/xe_mmio.c
index 334637511e75..2b18e8149ec3 100644
--- a/drivers/gpu/drm/xe/xe_mmio.c
+++ b/drivers/gpu/drm/xe/xe_mmio.c
@@ -423,41 +423,33 @@ int xe_mmio_init(struct xe_device *xe)
u8 xe_mmio_read8(struct xe_gt *gt, struct xe_reg reg)
{
struct xe_tile *tile = gt_to_tile(gt);
+ u32 addr = xe_mmio_adjusted_addr(gt, reg.addr);
- if (reg.addr < gt->mmio.adj_limit)
- reg.addr += gt->mmio.adj_offset;
-
- return readb((reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + reg.addr);
+ return readb((reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + addr);
}
u16 xe_mmio_read16(struct xe_gt *gt, struct xe_reg reg)
{
struct xe_tile *tile = gt_to_tile(gt);
+ u32 addr = xe_mmio_adjusted_addr(gt, reg.addr);
- if (reg.addr < gt->mmio.adj_limit)
- reg.addr += gt->mmio.adj_offset;
-
- return readw((reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + reg.addr);
+ return readw((reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + addr);
}
void xe_mmio_write32(struct xe_gt *gt, struct xe_reg reg, u32 val)
{
struct xe_tile *tile = gt_to_tile(gt);
+ u32 addr = xe_mmio_adjusted_addr(gt, reg.addr);
- if (reg.addr < gt->mmio.adj_limit)
- reg.addr += gt->mmio.adj_offset;
-
- writel(val, (reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + reg.addr);
+ writel(val, (reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + addr);
}
u32 xe_mmio_read32(struct xe_gt *gt, struct xe_reg reg)
{
struct xe_tile *tile = gt_to_tile(gt);
+ u32 addr = xe_mmio_adjusted_addr(gt, reg.addr);
- if (reg.addr < gt->mmio.adj_limit)
- reg.addr += gt->mmio.adj_offset;
-
- return readl((reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + reg.addr);
+ return readl((reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + addr);
}
u32 xe_mmio_rmw32(struct xe_gt *gt, struct xe_reg reg, u32 clr, u32 set)
@@ -486,10 +478,9 @@ bool xe_mmio_in_range(const struct xe_gt *gt,
const struct xe_mmio_range *range,
struct xe_reg reg)
{
- if (reg.addr < gt->mmio.adj_limit)
- reg.addr += gt->mmio.adj_offset;
+ u32 addr = xe_mmio_adjusted_addr(gt, reg.addr);
- return range && reg.addr >= range->start && reg.addr <= range->end;
+ return range && addr >= range->start && addr <= range->end;
}
/**
@@ -519,10 +510,11 @@ u64 xe_mmio_read64_2x32(struct xe_gt *gt, struct xe_reg reg)
struct xe_reg reg_udw = { .addr = reg.addr + 0x4 };
u32 ldw, udw, oldudw, retries;
- if (reg.addr < gt->mmio.adj_limit) {
- reg.addr += gt->mmio.adj_offset;
- reg_udw.addr += gt->mmio.adj_offset;
- }
+ reg.addr = xe_mmio_adjusted_addr(gt, reg.addr);
+ reg_udw.addr = xe_mmio_adjusted_addr(gt, reg_udw.addr);
+
+ /* we shouldn't adjust just one register address */
+ xe_gt_assert(gt, reg_udw.addr == reg.addr + 0x4);
oldudw = xe_mmio_read32(gt, reg_udw);
for (retries = 5; retries; --retries) {
diff --git a/drivers/gpu/drm/xe/xe_mmio.h b/drivers/gpu/drm/xe/xe_mmio.h
index a3cd7b3036c7..445ec6a0753e 100644
--- a/drivers/gpu/drm/xe/xe_mmio.h
+++ b/drivers/gpu/drm/xe/xe_mmio.h
@@ -36,4 +36,11 @@ u64 xe_mmio_read64_2x32(struct xe_gt *gt, struct xe_reg reg);
int xe_mmio_wait32(struct xe_gt *gt, struct xe_reg reg, u32 mask, u32 val, u32 timeout_us,
u32 *out_val, bool atomic);
+static inline u32 xe_mmio_adjusted_addr(const struct xe_gt *gt, u32 addr)
+{
+ if (addr < gt->mmio.adj_limit)
+ addr += gt->mmio.adj_offset;
+ return addr;
+}
+
#endif
--
2.43.0
next prev parent reply other threads:[~2024-04-23 18:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-23 18:04 [PATCH v2 0/5] Add SR-IOV GuC Relay PF services Michal Wajdeczko
2024-04-23 18:04 ` [PATCH v2 1/5] drm/xe/guc: Add GuC Relay ABI version 1.0 definitions Michal Wajdeczko
2024-04-23 18:04 ` Michal Wajdeczko [this message]
2024-04-23 19:19 ` [PATCH v2 2/5] drm/xe: Add helper to calculate adjusted register offset Piotr Piórkowski
2024-04-23 18:04 ` [PATCH v2 3/5] drm/xe: Add few more GT register definitions Michal Wajdeczko
2024-04-23 18:04 ` [PATCH v2 4/5] drm/xe/pf: Add SR-IOV GuC Relay PF services Michal Wajdeczko
2024-04-23 18:04 ` [PATCH v2 5/5] drm/xe/kunit: Add PF service tests Michal Wajdeczko
2024-04-23 21:06 ` ✓ CI.Patch_applied: success for Add SR-IOV GuC Relay PF services (rev3) Patchwork
2024-04-23 21:06 ` ✗ CI.checkpatch: warning " Patchwork
2024-04-23 21:07 ` ✓ CI.KUnit: success " Patchwork
2024-04-23 21:19 ` ✓ CI.Build: " Patchwork
2024-04-23 21:22 ` ✓ CI.Hooks: " Patchwork
2024-04-23 21:23 ` ✓ CI.checksparse: " Patchwork
2024-04-23 22:02 ` ✓ CI.BAT: " Patchwork
2024-04-24 10:57 ` ✗ CI.FULL: failure " Patchwork
2024-04-24 11:24 ` Michal Wajdeczko
2024-04-26 7:21 ` Balne, VinayX Kumar Goud
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240423180436.2089-3-michal.wajdeczko@intel.com \
--to=michal.wajdeczko@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=piotr.piorkowski@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox