All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Airlie <airlied@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: nouveau@lists.freedesktop.org, dakr@kernel.org
Subject: [PATCH 2/6] nouveau/gsp: make libos init per-gsp version.
Date: Wed, 29 Jul 2026 14:15:26 +1000	[thread overview]
Message-ID: <20260729041653.3985549-3-airlied@gmail.com> (raw)
In-Reply-To: <20260729041653.3985549-1-airlied@gmail.com>

From: Dave Airlie <airlied@redhat.com>

This makes it a per-gsp thing, but just adds r570 as a copy of r535
for now.

r570 will be enhanced next.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 .../drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c | 23 ++-----
 .../drm/nouveau/nvkm/subdev/gsp/rm/r570/gsp.c | 68 +++++++++++++++++++
 .../nvkm/subdev/gsp/rm/r570/nvrm/gsp.h        | 23 +++++++
 .../gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h   | 16 +++++
 4 files changed, 114 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c
index f4f4142ec8d0..8e1ad2e79d3e 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c
@@ -1205,7 +1205,7 @@ r535_gsp_set_rmargs(struct nvkm_gsp *gsp, bool resume)
 	}
 }
 
-static int
+int
 r535_gsp_rmargs_init(struct nvkm_gsp *gsp, bool resume)
 {
 	int ret;
@@ -1362,7 +1362,7 @@ static struct dentry *create_debugfs(struct nvkm_gsp *gsp, const char *name,
  * r535_gsp_booter_load() is called, so that if GSP-RM fails to initialize,
  * there could still be a log to capture.
  */
-static void
+void
 r535_gsp_libos_debugfs_init(struct nvkm_gsp *gsp)
 {
 	struct device *dev = gsp->subdev.device->dev;
@@ -1433,17 +1433,6 @@ r535_gsp_libos_debugfs_init(struct nvkm_gsp *gsp)
 
 #endif
 
-static inline u64
-r535_gsp_libos_id8(const char *name)
-{
-	u64 id = 0;
-
-	for (int i = 0; i < sizeof(id) && *name; i++, name++)
-		id = (id << 8) | *name;
-
-	return id;
-}
-
 /**
  * create_pte_array() - creates a PTE array of a physically contiguous buffer
  * @ptes: pointer to the array
@@ -1461,7 +1450,8 @@ r535_gsp_libos_id8(const char *name)
  *
  * See memdescGetPhysAddrsForGpu()
  */
-static void create_pte_array(u64 *ptes, dma_addr_t addr, size_t size)
+void
+r535_gsp_create_pte_array(u64 *ptes, dma_addr_t addr, size_t size)
 {
 	unsigned int num_pages = DIV_ROUND_UP_ULL(size, GSP_PAGE_SIZE);
 	unsigned int i;
@@ -1488,7 +1478,7 @@ gsp_fill_libos_entry(struct nvkm_gsp *gsp,
 	arg->size = mem->size;
 	arg->kind = LIBOS_MEMORY_REGION_CONTIGUOUS;
 	arg->loc  = LIBOS_MEMORY_REGION_LOC_SYSMEM;
-	create_pte_array(mem->data + sizeof(u64), mem->addr, mem->size);
+	r535_gsp_create_pte_array(mem->data + sizeof(u64), mem->addr, mem->size);
 	return 0;
 }
 
@@ -2187,7 +2177,7 @@ r535_gsp_oneinit(struct nvkm_gsp *gsp)
 	/* Release FW images - we've copied them to DMA buffers now. */
 	nvkm_gsp_dtor_fws(gsp);
 
-	ret = r535_gsp_libos_init(gsp);
+	ret = rmapi->gsp->libos_init(gsp);
 	if (WARN_ON(ret))
 		return ret;
 
@@ -2206,6 +2196,7 @@ r535_gsp_oneinit(struct nvkm_gsp *gsp)
 
 const struct nvkm_rm_api_gsp
 r535_gsp = {
+	.libos_init = r535_gsp_libos_init,
 	.set_rmargs = r535_gsp_set_rmargs,
 	.set_system_info = r535_gsp_set_system_info,
 	.get_static_info = r535_gsp_get_static_info,
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/gsp.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/gsp.c
index 996941c668ba..64011430f4c0 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/gsp.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/gsp.c
@@ -205,8 +205,76 @@ r570_gsp_set_rmargs(struct nvkm_gsp *gsp, bool resume)
 	args->bDmemStack = 1;
 }
 
+static int
+gsp_fill_libos_entry(struct nvkm_gsp *gsp,
+		     LibosMemoryRegionInitArgument *arg,
+		     size_t size,
+		     struct nvkm_gsp_mem *mem,
+		     const char *name)
+{
+	int ret;
+
+	ret = nvkm_gsp_mem_ctor(gsp, size, mem);
+	if (ret)
+		return ret;
+
+	arg->id8  = r535_gsp_libos_id8(name);
+	arg->pa   = mem->addr;
+	arg->size = mem->size;
+	arg->kind = LIBOS_MEMORY_REGION_CONTIGUOUS;
+	arg->loc  = LIBOS_MEMORY_REGION_LOC_SYSMEM;
+	r535_gsp_create_pte_array(mem->data + sizeof(u64), mem->addr, mem->size);
+	return 0;
+}
+
+/**
+ * r570_gsp_libos_init() -- create the libos arguments structure
+ * @gsp: gsp pointer
+ */
+static int
+r570_gsp_libos_init(struct nvkm_gsp *gsp)
+{
+	LibosMemoryRegionInitArgument *args;
+	int ret;
+
+	ret = nvkm_gsp_mem_ctor(gsp, 0x1000, &gsp->libos);
+	if (ret)
+		return ret;
+
+	args = gsp->libos.data;
+
+	ret = gsp_fill_libos_entry(gsp, &args[0], 0x10000, &gsp->loginit, "LOGINIT");
+	if (ret)
+		return ret;
+
+	ret = gsp_fill_libos_entry(gsp, &args[1], 0x10000, &gsp->logintr, "LOGINTR");
+	if (ret)
+		return ret;
+
+	ret = gsp_fill_libos_entry(gsp, &args[2], 0x10000, &gsp->logrm, "LOGRM");
+	if (ret)
+		return ret;
+
+	ret = r535_gsp_rmargs_init(gsp, false);
+	if (ret)
+		return ret;
+
+	args[3].id8  = r535_gsp_libos_id8("RMARGS");
+	args[3].pa   = gsp->rmargs.addr;
+	args[3].size = gsp->rmargs.size;
+	args[3].kind = LIBOS_MEMORY_REGION_CONTIGUOUS;
+	args[3].loc  = LIBOS_MEMORY_REGION_LOC_SYSMEM;
+
+#ifdef CONFIG_DEBUG_FS
+	r535_gsp_libos_debugfs_init(gsp);
+#endif
+
+	return 0;
+}
+
 const struct nvkm_rm_api_gsp
 r570_gsp = {
+	.libos_init = r570_gsp_libos_init,
 	.set_rmargs = r570_gsp_set_rmargs,
 	.set_system_info = r570_gsp_set_system_info,
 	.get_static_info = r570_gsp_get_static_info,
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/gsp.h b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/gsp.h
index b6075021e74f..23c30cbdefff 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/gsp.h
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/gsp.h
@@ -523,6 +523,29 @@ typedef struct
 
 #define NV2080_CTRL_GPU_SET_POWER_STATE_GPU_LEVEL_3            (0x00000003U)
 
+typedef NvU64 LibosAddress;
+
+typedef struct
+{
+    LibosAddress          id8;  // Id tag.
+    LibosAddress          pa;   // Physical address.
+    LibosAddress          size; // Size of memory area.
+    NvU8                  kind; // See LibosMemoryRegionKind above.
+    NvU8                  loc;  // See LibosMemoryRegionLoc above.
+} LibosMemoryRegionInitArgument;
+
+typedef enum {
+    LIBOS_MEMORY_REGION_NONE,
+    LIBOS_MEMORY_REGION_CONTIGUOUS,
+    LIBOS_MEMORY_REGION_RADIX3
+} LibosMemoryRegionKind;
+
+typedef enum {
+    LIBOS_MEMORY_REGION_LOC_NONE,
+    LIBOS_MEMORY_REGION_LOC_SYSMEM,
+    LIBOS_MEMORY_REGION_LOC_FB
+} LibosMemoryRegionLoc;
+
 typedef struct
 {
     // Magic for verification by secure ucode
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h
index a9af94adf9ef..cc9f33202673 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h
@@ -32,6 +32,7 @@ struct nvkm_rm_wpr {
 
 struct nvkm_rm_api {
 	const struct nvkm_rm_api_gsp {
+		int (*libos_init)(struct nvkm_gsp *);
 		void (*set_rmargs)(struct nvkm_gsp *, bool resume);
 		int (*set_system_info)(struct nvkm_gsp *);
 		int (*get_static_info)(struct nvkm_gsp *);
@@ -144,6 +145,9 @@ void r535_gsp_acpi_caps(acpi_handle, CAPS_METHOD_DATA *);
 struct NV2080_CTRL_CMD_FB_GET_FB_REGION_INFO_PARAMS;
 void r535_gsp_get_static_info_fb(struct nvkm_gsp *,
 				 const struct NV2080_CTRL_CMD_FB_GET_FB_REGION_INFO_PARAMS *);
+void r535_gsp_create_pte_array(u64 *ptes, dma_addr_t addr, size_t size);
+int r535_gsp_rmargs_init(struct nvkm_gsp *gsp, bool resume);
+void r535_gsp_libos_debugfs_init(struct nvkm_gsp *gsp);
 extern const struct nvkm_rm_api_rpc r535_rpc;
 extern const struct nvkm_rm_api_ctrl r535_ctrl;
 extern const struct nvkm_rm_api_alloc r535_alloc;
@@ -188,4 +192,16 @@ extern const struct nvkm_rm_api_gr r570_gr;
 int r570_gr_gpc_mask(struct nvkm_gsp *, u32 *mask);
 int r570_gr_tpc_mask(struct nvkm_gsp *, int gpc, u32 *mask);
 extern const struct nvkm_rm_api_engine r570_ofa;
+
+static inline u64
+r535_gsp_libos_id8(const char *name)
+{
+	u64 id = 0;
+
+	for (int i = 0; i < sizeof(id) && *name; i++, name++)
+		id = (id << 8) | *name;
+
+	return id;
+}
+
 #endif
-- 
2.55.0


  parent reply	other threads:[~2026-07-29  4:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29  4:15 nouveau/gsp: some r570 additions and refactoring Dave Airlie
2026-07-29  4:15 ` [PATCH 1/6] nouveau/gsp: refactor libos entry handling for r535 Dave Airlie
2026-07-29  4:15 ` Dave Airlie [this message]
2026-07-29  4:32   ` [PATCH 2/6] nouveau/gsp: make libos init per-gsp version sashiko-bot
2026-07-29  4:15 ` [PATCH 3/6] nouveau/gsp: add logging entries for r570 Dave Airlie
2026-07-29  4:33   ` sashiko-bot
2026-07-29  4:15 ` [PATCH 4/6] nouveau/gsp: refactor the chan allocation arguments into a struct Dave Airlie
2026-07-29  4:15 ` [PATCH 5/6] nouveau/gsp: add some more fields to r570 system info Dave Airlie
2026-07-29  4:29   ` sashiko-bot
2026-07-29  4:15 ` [PATCH 6/6] nouveau: set wpr boost flags like open driver does Dave Airlie

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=20260729041653.3985549-3-airlied@gmail.com \
    --to=airlied@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=nouveau@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.