Re: [PATCH v4 5/8] drm/i915/pxp: Add ARB session creation and cleanup

2023-02-14 Thread Teres Alexis, Alan Previn
On Thu, 2023-02-09 at 16:42 -0800, Teres Alexis, Alan Previn wrote:
> Add MTL's function for ARB session creation using PXP firmware
> version 4.3 ABI structure format.
> 
> Also add MTL's function for ARB session invalidation but this
> reuses PXP firmware version 4.2 ABI structure format.
> 
> Before checking the return status, look at the GSC-CS-Mem-Header's
> pending-bit which means the GSC firmware is busy and we should
> resubmit.
> 
> Signed-off-by: Alan Previn 
> ---
> 

alan:snip..

> +void intel_pxp_gsccs_end_arb_fw_session(struct intel_pxp *pxp, u32 
> session_id)
> +{
> + struct drm_i915_private *i915 = pxp->ctrl_gt->i915;
> + struct pxp42_inv_stream_key_in msg_in = {0};
> + struct pxp42_inv_stream_key_out msg_out = {0};
> + int ret = 0, tries = 0;
> + u64 gsc_session_retry = 0;
> +
> + memset(_in, 0, sizeof(msg_in));
> + memset(_out, 0, sizeof(msg_out));
> + msg_in.header.api_version = PXP_APIVER(4, 2);
> +
Firmware API version is backward compatibility and enforces the correct
API calls for the platform+firmware. Thus, although the structs are v4.2,
the api_version needs to carry PXP_APIVER(4, 3)

alan:snip..



[PATCH v4 5/8] drm/i915/pxp: Add ARB session creation and cleanup

2023-02-09 Thread Alan Previn
Add MTL's function for ARB session creation using PXP firmware
version 4.3 ABI structure format.

Also add MTL's function for ARB session invalidation but this
reuses PXP firmware version 4.2 ABI structure format.

Before checking the return status, look at the GSC-CS-Mem-Header's
pending-bit which means the GSC firmware is busy and we should
resubmit.

Signed-off-by: Alan Previn 
---
 drivers/gpu/drm/i915/pxp/intel_pxp.c  |  9 +-
 .../drm/i915/pxp/intel_pxp_cmd_interface_43.h | 21 +
 drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.c| 92 +++
 drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.h|  3 +
 drivers/gpu/drm/i915/pxp/intel_pxp_session.c  | 11 ++-
 5 files changed, 132 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp.c 
b/drivers/gpu/drm/i915/pxp/intel_pxp.c
index aecc65b5da70..c25e9ff16b57 100644
--- a/drivers/gpu/drm/i915/pxp/intel_pxp.c
+++ b/drivers/gpu/drm/i915/pxp/intel_pxp.c
@@ -353,8 +353,13 @@ int intel_pxp_start(struct intel_pxp *pxp)
if (!intel_pxp_is_enabled(pxp))
return -ENODEV;
 
-   if (wait_for(pxp_component_bound(pxp), 250))
-   return -ENXIO;
+   if (HAS_ENGINE(pxp->ctrl_gt, GSC0)) {
+   if (wait_for(intel_uc_fw_is_running(>ctrl_gt->uc.gsc.fw), 
250))
+   return -ENXIO;
+   } else {
+   if (wait_for(pxp_component_bound(pxp), 250))
+   return -ENXIO;
+   }
 
mutex_lock(>arb_mutex);
 
diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp_cmd_interface_43.h 
b/drivers/gpu/drm/i915/pxp/intel_pxp_cmd_interface_43.h
index b2523d6918c7..9089e02a8c2d 100644
--- a/drivers/gpu/drm/i915/pxp/intel_pxp_cmd_interface_43.h
+++ b/drivers/gpu/drm/i915/pxp/intel_pxp_cmd_interface_43.h
@@ -11,6 +11,7 @@
 
 /* PXP-Cmd-Op definitions */
 #define PXP43_CMDID_START_HUC_AUTH 0x003A
+#define PXP43_CMDID_INIT_SESSION 0x0036
 
 /* PXP-Packet sizes for MTL's GSCCS-HECI instruction */
 #define PXP43_MAX_HECI_IN_SIZE (SZ_32K)
@@ -27,4 +28,24 @@ struct pxp43_start_huc_auth_out {
struct pxp_cmd_header header;
 } __packed;
 
+/* PXP-Input-Packet: Init PXP session */
+struct pxp43_create_arb_in {
+   struct pxp_cmd_header header;
+   /* header.stream_id fields for vesion 4.3 of Init PXP session: 
*/
+   #define PXP43_INIT_SESSION_VALID BIT(0)
+   #define PXP43_INIT_SESSION_APPTYPE BIT(1)
+   #define PXP43_INIT_SESSION_APPID GENMASK(17, 2)
+   u32 protection_mode;
+   #define PXP43_INIT_SESSION_PROTECTION_ARB 0x2
+   u32 sub_session_id;
+   u32 init_flags;
+   u32 rsvd[12];
+} __packed;
+
+/* PXP-Input-Packet: Init PXP session */
+struct pxp43_create_arb_out {
+   struct pxp_cmd_header header;
+   u32 rsvd[8];
+} __packed;
+
 #endif /* __INTEL_PXP_FW_INTERFACE_43_H__ */
diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.c 
b/drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.c
index 51b9959f7813..42fc05582d0a 100644
--- a/drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.c
+++ b/drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.c
@@ -9,6 +9,7 @@
 #include "gt/uc/intel_gsc_uc_heci_cmd_submit.h"
 
 #include "i915_drv.h"
+#include "intel_pxp_cmd_interface_42.h"
 #include "intel_pxp_cmd_interface_43.h"
 #include "intel_pxp_gsccs.h"
 #include "intel_pxp_types.h"
@@ -120,6 +121,97 @@ static int gsccs_send_message(struct intel_pxp *pxp,
return ret;
 }
 
+int intel_pxp_gsccs_create_session(struct intel_pxp *pxp,
+  int arb_session_id)
+{
+   struct drm_i915_private *i915 = pxp->ctrl_gt->i915;
+   struct gsccs_session_resources *exec =  >gsccs_res;
+   struct pxp43_create_arb_in msg_in = {0};
+   struct pxp43_create_arb_out msg_out = {0};
+   u64 gsc_session_retry = 0;
+   int ret, tries = 0;
+
+   /* get a unique host-session-handle (used later in HW cmds) at time of 
session creation */
+   get_random_bytes(>host_session_handle, 
sizeof(exec->host_session_handle));
+
+   msg_in.header.api_version = PXP_APIVER(4, 3);
+   msg_in.header.command_id = PXP43_CMDID_INIT_SESSION;
+   msg_in.header.stream_id = (FIELD_PREP(PXP43_INIT_SESSION_APPID, 
arb_session_id) |
+  FIELD_PREP(PXP43_INIT_SESSION_VALID, 1) |
+  FIELD_PREP(PXP43_INIT_SESSION_APPTYPE, 0));
+   msg_in.header.buffer_len = sizeof(msg_in) - sizeof(msg_in.header);
+   msg_in.protection_mode = PXP43_INIT_SESSION_PROTECTION_ARB;
+
+   /*
+* Keep sending request if GSC firmware was busy.
+* Based on specs, we can expects a worst case pending-bit
+* delay of 2000 milisecs.
+*/
+   do {
+   ret = gsccs_send_message(pxp,
+_in, sizeof(msg_in),
+_out, sizeof(msg_out), NULL,
+_session_retry);
+   /*