[Intel-gfx] [PATCH 5/8] drm/i915: Introduce iterators for execlist ports
Mika Kuoppala
mika.kuoppala at linux.intel.com
Tue Sep 12 08:36:15 UTC 2017
Switch to iterators for execlist_port access. This is
a preparation for indexing ports from arbitrary location. Which
in turn allows us to handle ports in ring like fashion.
Signed-off-by: Mika Kuoppala <mika.kuoppala at intel.com>
---
drivers/gpu/drm/i915/i915_debugfs.c | 5 +++--
drivers/gpu/drm/i915/i915_gpu_error.c | 7 ++++---
drivers/gpu/drm/i915/intel_lrc.c | 23 +++++++++++------------
drivers/gpu/drm/i915/intel_ringbuffer.h | 16 +++++++++++-----
4 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 77ac775e312d..6bff702a5fc6 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -3254,6 +3254,7 @@ static int i915_engine_info(struct seq_file *m, void *unused)
for_each_engine(engine, dev_priv, id) {
struct intel_breadcrumbs *b = &engine->breadcrumbs;
+ struct execlist_port *port;
struct drm_i915_gem_request *rq;
struct rb_node *rb;
u64 addr;
@@ -3345,10 +3346,10 @@ static int i915_engine_info(struct seq_file *m, void *unused)
}
rcu_read_lock();
- for (idx = 0; idx < execlist_num_ports(el); idx++) {
+ for_each_execlist_port(el, port, idx) {
unsigned int count;
- rq = port_unpack(&el->port[idx], &count);
+ rq = port_unpack(port, &count);
if (rq) {
seq_printf(m, "\t\tELSP[%d] count=%d, ",
idx, count);
diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c
index e048d713f72c..966f00de53aa 100644
--- a/drivers/gpu/drm/i915/i915_gpu_error.c
+++ b/drivers/gpu/drm/i915/i915_gpu_error.c
@@ -1332,11 +1332,12 @@ static void engine_record_requests(struct intel_engine_cs *engine,
static void error_record_engine_execlists(struct intel_engine_cs *engine,
struct drm_i915_error_engine *ee)
{
- const struct intel_engine_execlist * const el = &engine->execlist;
+ struct intel_engine_execlist * const el = &engine->execlist;
+ const struct execlist_port *port;
unsigned int n;
- for (n = 0; n < execlist_num_ports(el); n++) {
- struct drm_i915_gem_request *rq = port_request(&el->port[n]);
+ for_each_execlist_port(el, port, n) {
+ struct drm_i915_gem_request *rq = port_request(port);
if (!rq)
break;
diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
index 4752d71dd644..cfa21731b9c7 100644
--- a/drivers/gpu/drm/i915/intel_lrc.c
+++ b/drivers/gpu/drm/i915/intel_lrc.c
@@ -338,24 +338,25 @@ static u64 execlists_update_context(struct drm_i915_gem_request *rq)
static void execlists_submit_ports(struct intel_engine_cs *engine)
{
- struct execlist_port *port = engine->execlist.port;
- u32 __iomem *elsp =
+ u32 __iomem * const elsp =
engine->i915->regs + i915_mmio_reg_offset(RING_ELSP(engine));
+ struct intel_engine_execlist * const el = &engine->execlist;
+ struct execlist_port *port;
unsigned int n;
- for (n = execlist_num_ports(&engine->execlist); n--; ) {
+ for_each_execlist_port_reverse(el, port, n) {
struct drm_i915_gem_request *rq;
unsigned int count;
u64 desc;
- rq = port_unpack(&port[n], &count);
+ rq = port_unpack(port, &count);
if (rq) {
GEM_BUG_ON(count > !n);
if (!count++)
execlists_context_status_change(rq, INTEL_CONTEXT_SCHEDULE_IN);
- port_set(&port[n], port_pack(rq, count));
+ port_set(port, port_pack(rq, count));
desc = execlists_update_context(rq);
- GEM_DEBUG_EXEC(port[n].context_id = upper_32_bits(desc));
+ GEM_DEBUG_EXEC(port->context_id = upper_32_bits(desc));
} else {
GEM_BUG_ON(!n);
desc = 0;
@@ -1238,7 +1239,7 @@ static u8 gtiir[] = {
static int gen8_init_common_ring(struct intel_engine_cs *engine)
{
struct drm_i915_private *dev_priv = engine->i915;
- struct intel_engine_execlist * const el = &engine->execlist;
+ struct execlist_port *port;
unsigned int n;
bool submit;
int ret;
@@ -1276,9 +1277,7 @@ static int gen8_init_common_ring(struct intel_engine_cs *engine)
/* After a GPU reset, we may have requests to replay */
submit = false;
- for (n = 0; n < execlist_num_ports(el); n++) {
- struct execlist_port * const port = &el->port[n];
-
+ for_each_execlist_port(&engine->execlist, port, n) {
if (!port_isset(port))
break;
@@ -1764,8 +1763,8 @@ logical_ring_setup(struct intel_engine_cs *engine)
engine->buffer = NULL;
engine->execlist.port_mask = 1;
- BUILD_BUG_ON_NOT_POWER_OF_2(execlist_num_ports(&engine->execlist));
- GEM_BUG_ON(execlist_num_ports(&engine->execlist) > EXECLIST_MAX_PORTS);
+ BUILD_BUG_ON_NOT_POWER_OF_2(engine->execlist.port_mask + 1);
+ GEM_BUG_ON(engine->execlist.port_mask >= EXECLIST_MAX_PORTS);
fw_domains = intel_uncore_forcewake_for_reg(dev_priv,
RING_ELSP(engine),
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h
index 7b64e5e16136..838d2d9b77c1 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -500,11 +500,17 @@ struct intel_engine_cs {
u32 (*get_cmd_length_mask)(u32 cmd_header);
};
-static inline unsigned int
-execlist_num_ports(const struct intel_engine_execlist * const el)
-{
- return el->port_mask + 1;
-}
+/* Iterators over elsp ports */
+#define __port_idx(start, i, m) (((start) + (i)) & (m))
+
+#define for_each_execlist_port(el__, port__, n__) \
+ for ((n__) = 0; \
+ (port__) = &(el__)->port[__port_idx(0, (n__), (el__)->port_mask)], (n__) < (el__)->port_mask + 1; \
+ (n__)++)
+
+#define for_each_execlist_port_reverse(el__, port__, n__) \
+ for ((n__) = (el__)->port_mask + 1; \
+ (port__) = &(el__)->port[__port_idx((el__)->port_mask, (n__), (el__)->port_mask)], (n__)--;)
static inline void
execlist_port_complete(struct intel_engine_execlist * const el,
--
2.11.0
More information about the Intel-gfx
mailing list