Commit 07fbd1f8 authored by Lucas De Marchi's avatar Lucas De Marchi Committed by Rodrigo Vivi

drm/xe: Plumb xe_reg into WAs, rtp, etc

Now that struct xe_reg and struct xe_reg_mcr are types that can be used
by xe, convert more of the driver to use them. Some notes about the
conversions:

	- The RTP tables don't need the MASKED flags anymore in the
	  actions as that information now comes from the register
	  definition

	- There is no need for the _XE_RTP_REG/_XE_RTP_REG_MCR macros
	  and the register types on RTP infra: that comes from the
	  register definitions.

	- When declaring the RTP entries, there is no need anymore to
	  undef XE_REG and friends: the RTP macros deal with removing
	  the cast where needed due to not being able to use a compound
	  statement for initialization in the tables

	- The index in the reg-sr xarray is the register offset only.
	  Otherwise we wouldn't catch mistakes about adding both a
	  MCR-style and normal-style registers. For that, the register
	  is now also part of the entry, so the options can be compared
	  to check for compatible entries.

In order to be able to accomplish this, some improvements are needed on
the RTP macros. Change its implementation to concentrate on "pasting a prefix
to each argument" rather than the more general "call any macro for each
argument". Hopefully this will avoid trying to extend this infra and
making it more complex. With the use of tuples for building the
arguments, it's not possible to pass additional register fields and
using xe_reg in the RTP tables.

xe_mmio_* still need to be converted, from u32 to xe_reg, but that is
left for another change.
Reviewed-by: default avatarMatt Roper <matthew.d.roper@intel.com>
Link: https://lore.kernel.org/r/20230427223256.1432787-10-lucas.demarchi@intel.com
Link: https://lore.kernel.org/r/20230427223256.1432787-6-lucas.demarchi@intel.comSigned-off-by: default avatarLucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: default avatarLucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
parent ca2acce7
......@@ -18,25 +18,21 @@
#include "xe_reg_sr.h"
#include "xe_rtp.h"
#undef XE_REG
#undef XE_REG_MCR
#define XE_REG(x, ...) _XE_RTP_REG(x)
#define XE_REG_MCR(x, ...) _XE_RTP_MCR_REG(x)
#define REGULAR_REG1 XE_REG(1)
#define REGULAR_REG2 XE_REG(2)
#define REGULAR_REG3 XE_REG(3)
#define MCR_REG1 XE_REG_MCR(1)
#define MCR_REG2 XE_REG_MCR(2)
#define MCR_REG3 XE_REG_MCR(3)
#define MASKED_REG1 XE_REG(1, XE_REG_OPTION_MASKED)
#undef XE_REG_MCR
#define XE_REG_MCR(...) XE_REG(__VA_ARGS__, .mcr = 1)
struct rtp_test_case {
const char *name;
struct {
u32 offset;
u32 type;
} expected_reg;
u32 expected_set_bits;
struct xe_reg expected_reg;
u32 expected_set_bits;
u32 expected_clr_bits;
unsigned long expected_count;
unsigned int expected_sr_errors;
......@@ -56,7 +52,7 @@ static bool match_no(const struct xe_gt *gt, const struct xe_hw_engine *hwe)
static const struct rtp_test_case cases[] = {
{
.name = "coalesce-same-reg",
.expected_reg = { REGULAR_REG1 },
.expected_reg = REGULAR_REG1,
.expected_set_bits = REG_BIT(0) | REG_BIT(1),
.expected_clr_bits = REG_BIT(0) | REG_BIT(1),
.expected_count = 1,
......@@ -75,7 +71,7 @@ static const struct rtp_test_case cases[] = {
},
{
.name = "no-match-no-add",
.expected_reg = { REGULAR_REG1 },
.expected_reg = REGULAR_REG1,
.expected_set_bits = REG_BIT(0),
.expected_clr_bits = REG_BIT(0),
.expected_count = 1,
......@@ -94,7 +90,7 @@ static const struct rtp_test_case cases[] = {
},
{
.name = "no-match-no-add-multiple-rules",
.expected_reg = { REGULAR_REG1 },
.expected_reg = REGULAR_REG1,
.expected_set_bits = REG_BIT(0),
.expected_clr_bits = REG_BIT(0),
.expected_count = 1,
......@@ -113,7 +109,7 @@ static const struct rtp_test_case cases[] = {
},
{
.name = "two-regs-two-entries",
.expected_reg = { REGULAR_REG1 },
.expected_reg = REGULAR_REG1,
.expected_set_bits = REG_BIT(0),
.expected_clr_bits = REG_BIT(0),
.expected_count = 2,
......@@ -132,7 +128,7 @@ static const struct rtp_test_case cases[] = {
},
{
.name = "clr-one-set-other",
.expected_reg = { REGULAR_REG1 },
.expected_reg = REGULAR_REG1,
.expected_set_bits = REG_BIT(0),
.expected_clr_bits = REG_BIT(1) | REG_BIT(0),
.expected_count = 1,
......@@ -153,7 +149,7 @@ static const struct rtp_test_case cases[] = {
#define TEMP_MASK REG_GENMASK(10, 8)
#define TEMP_FIELD REG_FIELD_PREP(TEMP_MASK, 2)
.name = "set-field",
.expected_reg = { REGULAR_REG1 },
.expected_reg = REGULAR_REG1,
.expected_set_bits = TEMP_FIELD,
.expected_clr_bits = TEMP_MASK,
.expected_count = 1,
......@@ -171,7 +167,7 @@ static const struct rtp_test_case cases[] = {
},
{
.name = "conflict-duplicate",
.expected_reg = { REGULAR_REG1 },
.expected_reg = REGULAR_REG1,
.expected_set_bits = REG_BIT(0),
.expected_clr_bits = REG_BIT(0),
.expected_count = 1,
......@@ -191,7 +187,7 @@ static const struct rtp_test_case cases[] = {
},
{
.name = "conflict-not-disjoint",
.expected_reg = { REGULAR_REG1 },
.expected_reg = REGULAR_REG1,
.expected_set_bits = REG_BIT(0),
.expected_clr_bits = REG_BIT(0),
.expected_count = 1,
......@@ -211,7 +207,7 @@ static const struct rtp_test_case cases[] = {
},
{
.name = "conflict-reg-type",
.expected_reg = { REGULAR_REG1 },
.expected_reg = REGULAR_REG1,
.expected_set_bits = REG_BIT(0),
.expected_clr_bits = REG_BIT(0),
.expected_count = 1,
......@@ -229,8 +225,7 @@ static const struct rtp_test_case cases[] = {
/* drop: regular vs masked */
{ XE_RTP_NAME("basic-3"),
XE_RTP_RULES(FUNC(match_yes)),
XE_RTP_ACTIONS(SET(REGULAR_REG1, REG_BIT(0),
XE_RTP_ACTION_FLAG(MASKED_REG)))
XE_RTP_ACTIONS(SET(MASKED_REG1, REG_BIT(0)))
},
{}
},
......@@ -249,7 +244,7 @@ static void xe_rtp_process_tests(struct kunit *test)
xe_rtp_process(param->entries, reg_sr, &xe->gt[0], NULL);
xa_for_each(&reg_sr->xa, idx, sre) {
if (idx == param->expected_reg.offset)
if (idx == param->expected_reg.reg)
sr_entry = sre;
count++;
......@@ -258,7 +253,7 @@ static void xe_rtp_process_tests(struct kunit *test)
KUNIT_EXPECT_EQ(test, count, param->expected_count);
KUNIT_EXPECT_EQ(test, sr_entry->clr_bits, param->expected_clr_bits);
KUNIT_EXPECT_EQ(test, sr_entry->set_bits, param->expected_set_bits);
KUNIT_EXPECT_EQ(test, sr_entry->reg_type, param->expected_reg.type);
KUNIT_EXPECT_EQ(test, sr_entry->reg.raw, param->expected_reg.raw);
KUNIT_EXPECT_EQ(test, reg_sr->errors, param->expected_sr_errors);
}
......
......@@ -461,7 +461,7 @@ static unsigned int guc_mmio_regset_write(struct xe_guc_ads *ads,
BUILD_BUG_ON(ARRAY_SIZE(extra_regs) > ADS_REGSET_EXTRA_MAX);
xa_for_each(&hwe->reg_sr.xa, idx, entry) {
u32 flags = entry->masked_reg ? GUC_REGSET_MASKED : 0;
u32 flags = entry->reg.masked ? GUC_REGSET_MASKED : 0;
guc_mmio_regset_write_one(ads, regset_map, idx, flags, count++);
}
......
......@@ -75,10 +75,7 @@ static bool compatible_entries(const struct xe_reg_sr_entry *e1,
e1->clr_bits & e2->set_bits || e1->set_bits & e2->clr_bits)
return false;
if (e1->masked_reg != e2->masked_reg)
return false;
if (e1->reg_type != e2->reg_type)
if (e1->reg.raw != e2->reg.raw)
return false;
return true;
......@@ -91,10 +88,10 @@ static void reg_sr_inc_error(struct xe_reg_sr *sr)
#endif
}
int xe_reg_sr_add(struct xe_reg_sr *sr, u32 reg,
int xe_reg_sr_add(struct xe_reg_sr *sr,
const struct xe_reg_sr_entry *e)
{
unsigned long idx = reg;
unsigned long idx = e->reg.reg;
struct xe_reg_sr_entry *pentry = xa_load(&sr->xa, idx);
int ret;
......@@ -125,18 +122,30 @@ int xe_reg_sr_add(struct xe_reg_sr *sr, u32 reg,
return 0;
fail:
DRM_ERROR("Discarding save-restore reg %04lx (clear: %08x, set: %08x, masked: %s): ret=%d\n",
DRM_ERROR("Discarding save-restore reg %04lx (clear: %08x, set: %08x, masked: %s, mcr: %s): ret=%d\n",
idx, e->clr_bits, e->set_bits,
str_yes_no(e->masked_reg), ret);
str_yes_no(e->reg.masked),
str_yes_no(e->reg.mcr),
ret);
reg_sr_inc_error(sr);
return ret;
}
static void apply_one_mmio(struct xe_gt *gt, u32 reg,
struct xe_reg_sr_entry *entry)
/*
* Convert back from encoded value to type-safe, only to be used when reg.mcr
* is true
*/
static struct xe_reg_mcr to_xe_reg_mcr(const struct xe_reg reg)
{
return (const struct xe_reg_mcr){.__reg.raw = reg.raw };
}
static void apply_one_mmio(struct xe_gt *gt, struct xe_reg_sr_entry *entry)
{
struct xe_device *xe = gt_to_xe(gt);
struct xe_reg reg = entry->reg;
struct xe_reg_mcr reg_mcr = to_xe_reg_mcr(reg);
u32 val;
/*
......@@ -147,12 +156,12 @@ static void apply_one_mmio(struct xe_gt *gt, u32 reg,
* When it's not masked, we have to read it from hardware, unless we are
* supposed to set all bits.
*/
if (entry->masked_reg)
if (reg.masked)
val = (entry->clr_bits ?: entry->set_bits) << 16;
else if (entry->clr_bits + 1)
val = (entry->reg_type == XE_RTP_REG_MCR ?
xe_gt_mcr_unicast_read_any(gt, XE_REG_MCR(reg)) :
xe_mmio_read32(gt, reg)) & (~entry->clr_bits);
val = (reg.mcr ?
xe_gt_mcr_unicast_read_any(gt, reg_mcr) :
xe_mmio_read32(gt, reg.reg)) & (~entry->clr_bits);
else
val = 0;
......@@ -163,12 +172,12 @@ static void apply_one_mmio(struct xe_gt *gt, u32 reg,
*/
val |= entry->set_bits;
drm_dbg(&xe->drm, "REG[0x%x] = 0x%08x", reg, val);
drm_dbg(&xe->drm, "REG[0x%x] = 0x%08x", reg.reg, val);
if (entry->reg_type == XE_RTP_REG_MCR)
xe_gt_mcr_multicast_write(gt, XE_REG_MCR(reg), val);
if (entry->reg.mcr)
xe_gt_mcr_multicast_write(gt, reg_mcr, val);
else
xe_mmio_write32(gt, reg, val);
xe_mmio_write32(gt, reg.reg, val);
}
void xe_reg_sr_apply_mmio(struct xe_reg_sr *sr, struct xe_gt *gt)
......@@ -188,7 +197,7 @@ void xe_reg_sr_apply_mmio(struct xe_reg_sr *sr, struct xe_gt *gt)
goto err_force_wake;
xa_for_each(&sr->xa, reg, entry)
apply_one_mmio(gt, reg, entry);
apply_one_mmio(gt, entry);
err = xe_force_wake_put(&gt->mmio.fw, XE_FORCEWAKE_ALL);
XE_WARN_ON(err);
......@@ -257,6 +266,6 @@ void xe_reg_sr_dump(struct xe_reg_sr *sr, struct drm_printer *p)
xa_for_each(&sr->xa, reg, entry)
drm_printf(p, "\tREG[0x%lx] clr=0x%08x set=0x%08x masked=%s mcr=%s\n",
reg, entry->clr_bits, entry->set_bits,
str_yes_no(entry->masked_reg),
str_yes_no(entry->reg_type == XE_RTP_REG_MCR));
str_yes_no(entry->reg.masked),
str_yes_no(entry->reg.mcr));
}
......@@ -19,8 +19,7 @@ struct drm_printer;
int xe_reg_sr_init(struct xe_reg_sr *sr, const char *name, struct xe_device *xe);
void xe_reg_sr_dump(struct xe_reg_sr *sr, struct drm_printer *p);
int xe_reg_sr_add(struct xe_reg_sr *sr, u32 reg,
const struct xe_reg_sr_entry *e);
int xe_reg_sr_add(struct xe_reg_sr *sr, const struct xe_reg_sr_entry *e);
void xe_reg_sr_apply_mmio(struct xe_reg_sr *sr, struct xe_gt *gt);
void xe_reg_sr_apply_whitelist(struct xe_reg_sr *sr, u32 mmio_base,
struct xe_gt *gt);
......
......@@ -9,18 +9,14 @@
#include <linux/types.h>
#include <linux/xarray.h>
#include "regs/xe_reg_defs.h"
struct xe_reg_sr_entry {
struct xe_reg reg;
u32 clr_bits;
u32 set_bits;
/* Mask for bits to consider when reading value back */
u32 read_mask;
/*
* "Masked registers" are marked in spec as register with the upper 16
* bits as a mask for the bits that is being updated on the lower 16
* bits when writing to it.
*/
u8 masked_reg;
u8 reg_type;
};
struct xe_reg_sr {
......
......@@ -11,10 +11,8 @@
#include "xe_platform_types.h"
#include "xe_rtp.h"
#undef XE_REG
#undef XE_REG_MCR
#define XE_REG(x, ...) _XE_RTP_REG(x)
#define XE_REG_MCR(x, ...) _XE_RTP_MCR_REG(x)
#define XE_REG_MCR(...) XE_REG(__VA_ARGS__, .mcr = 1)
static bool match_not_render(const struct xe_gt *gt,
const struct xe_hw_engine *hwe)
......
......@@ -94,16 +94,15 @@ static void rtp_add_sr_entry(const struct xe_rtp_action *action,
u32 mmio_base,
struct xe_reg_sr *sr)
{
u32 reg = action->reg + mmio_base;
struct xe_reg_sr_entry sr_entry = {
.reg = action->reg,
.clr_bits = action->clr_bits,
.set_bits = action->set_bits,
.read_mask = action->read_mask,
.masked_reg = action->flags & XE_RTP_ACTION_FLAG_MASKED_REG,
.reg_type = action->reg_type,
};
xe_reg_sr_add(sr, reg, &sr_entry);
sr_entry.reg.reg += mmio_base;
xe_reg_sr_add(sr, &sr_entry);
}
static void rtp_process_one(const struct xe_rtp_entry *entry, struct xe_gt *gt,
......
This diff is collapsed.
......@@ -8,14 +8,11 @@
#include <linux/types.h>
#include "regs/xe_reg_defs.h"
struct xe_hw_engine;
struct xe_gt;
enum {
XE_RTP_REG_REGULAR,
XE_RTP_REG_MCR,
};
/**
* struct xe_rtp_action - action to take for any matching rule
*
......@@ -24,20 +21,17 @@ enum {
*/
struct xe_rtp_action {
/** @reg: Register */
u32 reg;
struct xe_reg reg;
/** @clr_bits: bits to clear when updating register */
u32 clr_bits;
u32 clr_bits;
/** @set_bits: bits to set when updating register */
u32 set_bits;
u32 set_bits;
#define XE_RTP_NOCHECK .read_mask = 0
/** @read_mask: mask for bits to consider when reading value back */
u32 read_mask;
#define XE_RTP_ACTION_FLAG_MASKED_REG BIT(0)
#define XE_RTP_ACTION_FLAG_ENGINE_BASE BIT(1)
u32 read_mask;
#define XE_RTP_ACTION_FLAG_ENGINE_BASE BIT(0)
/** @flags: flags to apply on rule evaluation or action */
u8 flags;
/** @reg_type: register type, see ``XE_RTP_REG_*`` */
u8 reg_type;
u8 flags;
};
enum {
......
......@@ -12,10 +12,8 @@
#include "xe_platform_types.h"
#include "xe_rtp.h"
#undef XE_REG
#undef XE_REG_MCR
#define XE_REG(x, ...) _XE_RTP_REG(x)
#define XE_REG_MCR(x, ...) _XE_RTP_MCR_REG(x)
#define XE_REG_MCR(...) XE_REG(__VA_ARGS__, .mcr = 1)
static const struct xe_rtp_entry gt_tunings[] = {
{ XE_RTP_NAME("Tuning: Blend Fill Caching Optimization Disable"),
......@@ -54,8 +52,7 @@ static const struct xe_rtp_entry lrc_tunings[] = {
},
{ XE_RTP_NAME("Tuning: TBIMR fast clip"),
XE_RTP_RULES(PLATFORM(DG2)),
XE_RTP_ACTIONS(SET(CHICKEN_RASTER_2, TBIMR_FAST_CLIP,
XE_RTP_ACTION_FLAG(MASKED_REG)))
XE_RTP_ACTIONS(SET(CHICKEN_RASTER_2, TBIMR_FAST_CLIP))
},
{}
};
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment