Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Maslak <jan.maslak@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: zbigniew.kempczynski@intel.com, Jan Maslak <jan.maslak@intel.com>
Subject: [PATCH 05/10] lib/mocs: Add intel_get_wb_mocs() and intel_buf_mocs() for genxml MOCS fields
Date: Thu, 16 Apr 2026 00:07:15 +0200	[thread overview]
Message-ID: <20260415220720.1594414-6-jan.maslak@intel.com> (raw)
In-Reply-To: <20260415220720.1594414-1-jan.maslak@intel.com>

genxml-generated pack headers represent MOCS as a single 7-bit field
encoding both the 6-bit MOCS table index (bits 6:1) and the PXP
protected-content bit (bit 0).  The existing intel_get_wb_mocs_index()
returns only the 6-bit index; assigning it directly to a genxml .MOCS
field places the index in the wrong bit position.

Add two helpers that return the full 7-bit value ready for direct
assignment to a genxml .MOCS field:

 - intel_get_wb_mocs(fd): write-back policy, PXP clear.  Equivalent to
   intel_get_wb_mocs_index(fd) << 1.

 - intel_buf_mocs(buf): encodes the buffer's mocs_index together with its
   PXP flag: (buf->mocs_index << 1) | intel_buf_pxp(buf).  Use this
   wherever a surface-state or sampler-state MOCS field is set for a
   specific intel_buf.

The old intel_get_wb_mocs_index() and related _index() functions remain
for callers that use hand-crafted bitfield structs with the index occupying
a separate bitfield.

Signed-off-by: Jan Maslak <jan.maslak@intel.com>
---
 lib/intel_bufops.h | 13 +++++++++++++
 lib/intel_mocs.c   | 14 ++++++++++++++
 lib/intel_mocs.h   |  1 +
 3 files changed, 28 insertions(+)

diff --git a/lib/intel_bufops.h b/lib/intel_bufops.h
index d111346aa..ead2c53e3 100644
--- a/lib/intel_bufops.h
+++ b/lib/intel_bufops.h
@@ -210,6 +210,19 @@ static inline bool intel_buf_pxp(const struct intel_buf *buf)
 	return buf->is_protected;
 }
 
+/**
+ * intel_buf_mocs:
+ * @buf: the intel_buf
+ *
+ * Returns the full 7-bit MOCS field value for @buf, encoding the 6-bit
+ * table index at bits 6:1 and the PXP protected-content bit at bit 0.
+ * Use this when assigning to a genxml-generated MOCS field.
+ */
+static inline uint8_t intel_buf_mocs(const struct intel_buf *buf)
+{
+	return (buf->mocs_index << 1) | (intel_buf_pxp(buf) ? 1 : 0);
+}
+
 void *intel_buf_cpu_map(struct intel_buf *buf, bool write);
 void *intel_buf_device_map(struct intel_buf *buf, bool write);
 void intel_buf_unmap(struct intel_buf *buf);
diff --git a/lib/intel_mocs.c b/lib/intel_mocs.c
index 778fd848e..08b5985c8 100644
--- a/lib/intel_mocs.c
+++ b/lib/intel_mocs.c
@@ -81,6 +81,20 @@ uint8_t intel_get_wb_mocs_index(int fd)
 	return mocs.wb_index;
 }
 
+/**
+ * intel_get_wb_mocs:
+ * @fd: the DRM file descriptor
+ *
+ * Returns: The full 7-bit MOCS field value for write-back caching, with the
+ * 6-bit table index shifted to bits 6:1 and the PXP bit (bit 0) cleared.
+ * Use this when assigning to a genxml-generated MOCS field, which encodes
+ * both the index and PXP bit in a single 7-bit value.
+ */
+uint8_t intel_get_wb_mocs(int fd)
+{
+	return intel_get_wb_mocs_index(fd) << 1;
+}
+
 /**
  * intel_get_uc_mocs_index:
  * @fd: the DRM file descriptor
diff --git a/lib/intel_mocs.h b/lib/intel_mocs.h
index 394bb41be..7d9c7d8b0 100644
--- a/lib/intel_mocs.h
+++ b/lib/intel_mocs.h
@@ -12,6 +12,7 @@
 #define DISPLAYABLE_MOCS_INDEX ((uint8_t)-2)
 
 uint8_t intel_get_wb_mocs_index(int fd);
+uint8_t intel_get_wb_mocs(int fd);
 uint8_t intel_get_uc_mocs_index(int fd);
 uint8_t intel_get_displayable_mocs_index(int fd);
 uint8_t intel_get_defer_to_pat_mocs_index(int fd);
-- 
2.34.1


  parent reply	other threads:[~2026-04-15 22:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15 22:07 [PATCH 00/10] lib/genxml: Introduce Mesa genxml infrastructure to IGT Jan Maslak
2026-04-15 22:07 ` [PATCH 01/10] lib/intel/genxml: Add genxml generators, headers, and build integration Jan Maslak
2026-04-23  9:32   ` Zbigniew Kempczyński
2026-04-23 11:04   ` Kamil Konieczny
2026-04-24  6:54   ` Zbigniew Kempczyński
2026-04-15 22:07 ` [PATCH 02/10] lib/intel/genxml: Import gen4-gen8 XML hardware definitions from Mesa Jan Maslak
2026-04-23  9:33   ` Zbigniew Kempczyński
2026-04-15 22:07 ` [PATCH 03/10] lib/intel/genxml: Import gen9-gen12.5 " Jan Maslak
2026-04-23  9:34   ` Zbigniew Kempczyński
2026-04-15 22:07 ` [PATCH 04/10] lib/intel/genxml: Import Xe2/Xe3/Xe3p " Jan Maslak
2026-04-23  9:35   ` Zbigniew Kempczyński
2026-04-15 22:07 ` Jan Maslak [this message]
2026-04-23 15:24   ` [PATCH 05/10] lib/mocs: Add intel_get_wb_mocs() and intel_buf_mocs() for genxml MOCS fields Zbigniew Kempczyński
2026-04-15 22:07 ` [PATCH 06/10] lib/rendercopy: Convert surface state and sampler setup to genxml Jan Maslak
2026-04-27  8:54   ` Zbigniew Kempczyński
2026-04-15 22:07 ` [PATCH 07/10] lib/rendercopy: Convert vertex data and CC state " Jan Maslak
2026-04-27 11:15   ` Zbigniew Kempczyński
2026-04-15 22:07 ` [PATCH 08/10] lib/rendercopy: Convert pipeline emit commands " Jan Maslak
2026-04-15 22:07 ` [PATCH 09/10] lib/rendercopy: Convert render op and entry points " Jan Maslak
2026-04-15 22:07 ` [PATCH 10/10] lib: Add genxml annotated batch buffer decode Jan Maslak
2026-04-23 10:56   ` Kamil Konieczny

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=20260415220720.1594414-6-jan.maslak@intel.com \
    --to=jan.maslak@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=zbigniew.kempczynski@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