All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH 09/15] drm/i915/guc: Prepare to handle messages from CT RECV buffer
Date: Fri,  4 Aug 2017 16:27:06 +0000	[thread overview]
Message-ID: <20170804162712.20468-10-michal.wajdeczko@intel.com> (raw)
In-Reply-To: <20170804162712.20468-1-michal.wajdeczko@intel.com>

GuC can respond to our commands not only by updating SEND buffer
descriptor, but can send us message over RECV buffer. Additionally
Guc can also send us unsolicited requests over RECV buffer.
Lets start reading those messages and make placeholders for actual
response/request handlers.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Oscar Mateo <oscar.mateo@intel.com>
Cc: Michel Thierry <michel.thierry@intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
---
 drivers/gpu/drm/i915/intel_guc_ct.c | 120 ++++++++++++++++++++++++++++++++++++
 1 file changed, 120 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_guc_ct.c b/drivers/gpu/drm/i915/intel_guc_ct.c
index c17cb42..dd30c83 100644
--- a/drivers/gpu/drm/i915/intel_guc_ct.c
+++ b/drivers/gpu/drm/i915/intel_guc_ct.c
@@ -414,6 +414,124 @@ static int intel_guc_send_ct(struct intel_guc *guc, const u32 *action, u32 len,
 	return ret;
 }
 
+static inline unsigned int ct_header_get_len(u32 header)
+{
+	return (header >> GUC_CT_MSG_LEN_SHIFT) & GUC_CT_MSG_LEN_MASK;
+}
+
+static inline unsigned int ct_header_get_action(u32 header)
+{
+	return (header >> GUC_CT_MSG_ACTION_SHIFT) & GUC_CT_MSG_ACTION_MASK;
+}
+
+static inline bool ct_header_is_response(u32 header)
+{
+	return !!(header & GUC_CT_MSG_IS_RESPONSE);
+}
+
+static int ctb_read(struct intel_guc_ct_buffer *ctb, u32 *data)
+{
+	struct guc_ct_buffer_desc *desc = ctb->desc;
+	u32 head = desc->head / 4;	/* in dwords */
+	u32 tail = desc->tail / 4;	/* in dwords */
+	u32 size = desc->size / 4;	/* in dwords */
+	u32 *cmds = ctb->cmds;
+	s32 available;			/* in dwords */
+	unsigned int len;
+	unsigned int i;
+
+	GEM_BUG_ON(desc->size % 4);
+	GEM_BUG_ON(desc->head % 4);
+	GEM_BUG_ON(desc->tail % 4);
+	GEM_BUG_ON(tail >= size);
+	GEM_BUG_ON(head >= size);
+
+	/* tail == head condition indicates empty */
+	available = tail - head;
+	if (available == 0)
+		return -ENODATA;
+
+	/* beware of buffer wrap case */
+	if (available < 0)
+		available += size;
+	GEM_BUG_ON(available < 0);
+
+	data[0] = cmds[head];
+	head = (head + 1) % size;
+
+	/* message len with header */
+	len = ct_header_get_len(data[0]) + 1;
+	if (unlikely(len > (u32)available)) {
+		DRM_ERROR("CT: incomplete message %*phn %*phn %*phn\n",
+			  4, data,
+			  4 * (head + available - 1 > size ?
+			       size - head : available - 1), &cmds[head],
+			  4 * (head + available - 1 > size ?
+			       available - 1 - size + head : 0), &cmds[0]);
+		return -EPROTO;
+	}
+
+	for (i = 1; i < len; i++) {
+		data[i] = cmds[head];
+		head = (head + 1) % size;
+	}
+
+	desc->head = head * 4;
+	return 0;
+}
+
+static int guc_handle_response(struct intel_guc *guc, const u32 *data)
+{
+	u32 header = data[0];
+	u32 len = ct_header_get_len(header) + 1; /* total len with header */
+
+	GEM_BUG_ON(!ct_header_is_response(header));
+	/* beyond header, data shall at least include fence and status */
+	if (unlikely(len < 3)) {
+		DRM_ERROR("CT: corrupted response %*phn\n", 4*len, data);
+		return -EPROTO;
+	}
+
+	return 0;
+}
+
+static int guc_handle_request(struct intel_guc *guc, const u32 *data)
+{
+	u32 header = data[0];
+
+	GEM_BUG_ON(ct_header_is_response(header));
+	/* data layout beyond header is request specific */
+
+	return 0;
+}
+
+static void intel_guc_receive_ct(struct intel_guc *guc)
+{
+	struct intel_guc_ct_channel *ctch = &guc->ct.host_channel;
+	struct intel_guc_ct_buffer *ctb = &ctch->ctbs[CTB_RECV];
+	u32 msg[GUC_CT_MSG_LEN_MASK+1];
+	int err = 0;
+
+	if (!ctch_is_open(ctch))
+		return;
+
+	do {
+		err = ctb_read(ctb, msg);
+		if (err)
+			break;
+
+		if (ct_header_is_response(msg[0]))
+			err = guc_handle_response(guc, msg);
+		else
+			err = guc_handle_request(guc, msg);
+	} while (!err);
+
+	if (GEM_WARN_ON(err == -EPROTO)) {
+		DRM_ERROR("CT: corrupted message detected!\n");
+		ctb->desc->is_in_error = 1;
+	}
+}
+
 /**
  * Enable buffer based command transport
  * Shall only be called for platforms with HAS_GUC_CT.
@@ -435,6 +553,7 @@ int intel_guc_enable_ct(struct intel_guc *guc)
 
 	/* Switch into cmd transport buffer based send() */
 	guc->send = intel_guc_send_ct;
+	guc->recv = intel_guc_receive_ct;
 	DRM_INFO("CT: %s\n", enableddisabled(true));
 	return 0;
 }
@@ -458,5 +577,6 @@ void intel_guc_disable_ct(struct intel_guc *guc)
 
 	/* Disable send */
 	guc->send = intel_guc_send_nop;
+	guc->recv = intel_guc_receive_nop;
 	DRM_INFO("CT: %s\n", enableddisabled(false));
 }
-- 
2.7.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2017-08-04 16:27 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-04 16:26 [PATCH 00/15] drm/i915/guc: Support for Guc responses and requests Michal Wajdeczko
2017-08-04 16:26 ` [PATCH 01/15] drm/i915/guc: Add support for data reporting in GuC responses Michal Wajdeczko
2017-08-04 20:40   ` Michel Thierry
2017-08-04 21:29     ` Daniele Ceraolo Spurio
2017-08-04 21:54       ` Michal Wajdeczko
2017-08-04 16:26 ` [PATCH 02/15] drm/i915/guc: Prepare send() function to accept bigger response Michal Wajdeczko
2017-08-04 21:13   ` Michel Thierry
2017-08-04 16:27 ` [PATCH 03/15] drm/i915/guc: Add send_and_receive() helper function Michal Wajdeczko
2017-08-04 21:38   ` Michel Thierry
2017-08-04 16:27 ` [PATCH 04/15] drm/i915/guc: Implement response handling in send_mmio() Michal Wajdeczko
2017-08-04 21:43   ` Michel Thierry
2017-08-04 16:27 ` [PATCH 05/15] drm/i915/guc: Move Guc notification handling to separate function Michal Wajdeczko
2017-08-04 18:00   ` Chris Wilson
2017-08-04 19:35     ` Michal Wajdeczko
2017-08-04 16:27 ` [PATCH 06/15] drm/i915/guc: Move flushing the GuC logs outside notification handler Michal Wajdeczko
2017-08-04 16:27 ` [PATCH 07/15] drm/i915/guc: Create a GuC receive function Michal Wajdeczko
2017-08-04 23:59   ` Michel Thierry
2017-08-04 16:27 ` [PATCH 08/15] drm/i915/guc: Update CT message header definition Michal Wajdeczko
2017-08-04 16:27 ` Michal Wajdeczko [this message]
2017-08-04 16:27 ` [PATCH 10/15] drm/i915/guc: Use better name for helper wait function Michal Wajdeczko
2017-08-04 16:27 ` [PATCH 11/15] drm/i915/guc: Implement response handling in send_ct() Michal Wajdeczko
2017-08-04 16:27 ` [PATCH 12/15] drm/i915/guc: Prepare to process incoming requests from CT Michal Wajdeczko
2017-08-04 17:13   ` Chris Wilson
2017-08-04 19:12     ` Michal Wajdeczko
2017-08-04 16:27 ` [PATCH 13/15] drm/i915/guc: Handle default action received over CT Michal Wajdeczko
2017-08-04 16:27 ` [PATCH 14/15] drm/i915/guc: Enable GuC interrupts when using CT Michal Wajdeczko
2017-08-04 16:27 ` [PATCH 15/15] drm/i915/guc: Trace messages from CT while in debug Michal Wajdeczko
2017-08-04 18:29   ` Chris Wilson
2017-08-04 16:49 ` ✗ Fi.CI.BAT: warning for drm/i915/guc: Support for Guc responses and requests Patchwork
2017-08-07 16:14 ` [PATCH v2 00/16] " Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 01/16] drm/i915/guc: Add support for data reporting in GuC responses Michal Wajdeczko
2017-08-07 17:13     ` Michel Thierry
2017-08-07 16:14   ` [PATCH v2 02/16] drm/i915/guc: Prepare send() function to accept bigger response Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 03/16] drm/i915/guc: Add send_and_receive() helper function Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 04/16] drm/i915/guc: Implement response handling in send_mmio() Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 05/16] drm/i915/guc: Move Guc notification handling to separate function Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 06/16] drm/i915/guc: Move flushing the GuC logs outside notification handler Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 07/16] drm/i915/guc: Create a GuC receive function Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 08/16] drm/i915/guc: Update CT message header definition Michal Wajdeczko
2017-08-07 20:38     ` Daniele Ceraolo Spurio
2017-08-07 16:14   ` [PATCH v2 09/16] drm/i915/guc: Prepare to handle messages from CT RECV buffer Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 10/16] drm/i915/guc: Use better name for helper wait function Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 11/16] drm/i915/guc: Implement response handling in send_ct() Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 12/16] drm/i915/guc: Prepare to process incoming requests from CT Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 13/16] drm/i915/guc: Handle default action received over CT Michal Wajdeczko
2017-08-07 16:14   ` [PATCH v2 14/16] drm/i915/guc: Enable GuC interrupts when using CT Michal Wajdeczko
2017-08-08 15:26     ` Oscar Mateo
2017-08-07 16:14   ` [PATCH v2 15/16] drm/i915/guc: Trace messages from CT while in debug Michal Wajdeczko
2017-08-07 18:42     ` Daniele Ceraolo Spurio
2017-08-07 16:14   ` [PATCH v2 16/16] HAX Enable GuC loading & submission Michal Wajdeczko
2017-08-07 16:41 ` ✗ Fi.CI.BAT: failure for drm/i915/guc: Support for Guc responses and requests Patchwork
2017-08-08 12:30 ` [PATCH v3 15/16] drm/i915/guc: Trace messages from CT while in debug Michal Wajdeczko
2017-08-10 21:17   ` Daniele Ceraolo Spurio
2017-08-09 16:24 ` [PATCH v3 14/16] drm/i915/guc: Enable GuC interrupts when using CT Michal Wajdeczko
2017-08-09 17:06   ` Oscar Mateo

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=20170804162712.20468-10-michal.wajdeczko@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.