drm/nouveau/gsp: add common client alloc code
authorBen Skeggs <bskeggs@nvidia.com>
Tue, 13 May 2025 23:19:56 +0000 (09:19 +1000)
committerDave Airlie <airlied@redhat.com>
Sun, 18 May 2025 20:29:26 +0000 (06:29 +1000)
570.144 has incompatible changes to NV0000_ALLOC_PARAMETERS.

Factor out the common code so it can be shared.

Signed-off-by: Ben Skeggs <bskeggs@nvidia.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/Kbuild
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/client.c [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/handles.h
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/client.c
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h

index 40e1b5300dff85bc4753337be383500a406b9cef..4ad07f3ced69c451a454e4406f0278747d8bfd8b 100644 (file)
@@ -411,21 +411,8 @@ nvkm_gsp_rm_free(struct nvkm_gsp_object *object)
        return 0;
 }
 
-static inline int
-nvkm_gsp_client_ctor(struct nvkm_gsp *gsp, struct nvkm_gsp_client *client)
-{
-       if (WARN_ON(!gsp->rm))
-               return -ENOSYS;
-
-       return gsp->rm->api->client->ctor(gsp, client);
-}
-
-static inline void
-nvkm_gsp_client_dtor(struct nvkm_gsp_client *client)
-{
-       if (client->gsp)
-               client->gsp->rm->api->client->dtor(client);
-}
+int nvkm_gsp_client_ctor(struct nvkm_gsp *, struct nvkm_gsp_client *);
+void nvkm_gsp_client_dtor(struct nvkm_gsp_client *);
 
 static inline int
 nvkm_gsp_device_ctor(struct nvkm_gsp_client *client, struct nvkm_gsp_device *device)
index e5d5f8880d31fd47c44bad70beccd9ab4628080c..0eac850d1f338636b491c46fd2c764dc1b47b7f9 100644 (file)
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: MIT
 #
 # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
+nvkm-y += nvkm/subdev/gsp/rm/client.o
 nvkm-y += nvkm/subdev/gsp/rm/engine.o
 nvkm-y += nvkm/subdev/gsp/rm/gr.o
 nvkm-y += nvkm/subdev/gsp/rm/nvdec.o
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/client.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/client.c
new file mode 100644 (file)
index 0000000..72d3e3c
--- /dev/null
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
+ */
+#include "rm.h"
+
+void
+nvkm_gsp_client_dtor(struct nvkm_gsp_client *client)
+{
+       const unsigned int id = client->object.handle - NVKM_RM_CLIENT(0);
+       struct nvkm_gsp *gsp = client->gsp;
+
+       if (!gsp)
+               return;
+
+       if (client->object.client)
+               nvkm_gsp_rm_free(&client->object);
+
+       mutex_lock(&gsp->client_id.mutex);
+       idr_remove(&gsp->client_id.idr, id);
+       mutex_unlock(&gsp->client_id.mutex);
+
+       client->gsp = NULL;
+}
+
+int
+nvkm_gsp_client_ctor(struct nvkm_gsp *gsp, struct nvkm_gsp_client *client)
+{
+       int id, ret;
+
+       if (WARN_ON(!gsp->rm))
+               return -ENOSYS;
+
+       mutex_lock(&gsp->client_id.mutex);
+       id = idr_alloc(&gsp->client_id.idr, client, 0, NVKM_RM_CLIENT_MASK + 1, GFP_KERNEL);
+       mutex_unlock(&gsp->client_id.mutex);
+       if (id < 0)
+               return id;
+
+       client->gsp = gsp;
+       client->object.client = client;
+       INIT_LIST_HEAD(&client->events);
+
+       ret = gsp->rm->api->client->ctor(client, NVKM_RM_CLIENT(id));
+       if (ret)
+               nvkm_gsp_client_dtor(client);
+
+       return ret;
+}
index 50f2f2a86b5ae9cdb78307df9db44deac8f2df77..3bdb5ad320d787d29971e39aff00cd3bf4344e9a 100644 (file)
@@ -8,6 +8,7 @@
 /* RMAPI handles for various objects allocated from GSP-RM with RM_ALLOC. */
 
 #define NVKM_RM_CLIENT(id)         (0xc1d00000 | (id))
+#define NVKM_RM_CLIENT_MASK         0x0000ffff
 #define NVKM_RM_DEVICE              0xde1d0000
 #define NVKM_RM_SUBDEVICE           0x5d1d0000
 #define NVKM_RM_DISP                0x00730000
index 449338da1795580818d2bd8277d026450d3ed755..ec71f683e6091754d22a0d343f69c213975dc5cb 100644 (file)
 
 #include "nvrm/client.h"
 
-static void
-r535_gsp_client_dtor(struct nvkm_gsp_client *client)
-{
-       struct nvkm_gsp *gsp = client->gsp;
-
-       nvkm_gsp_rm_free(&client->object);
-
-       mutex_lock(&gsp->client_id.mutex);
-       idr_remove(&gsp->client_id.idr, client->object.handle & 0xffff);
-       mutex_unlock(&gsp->client_id.mutex);
-
-       client->gsp = NULL;
-}
-
 static int
-r535_gsp_client_ctor(struct nvkm_gsp *gsp, struct nvkm_gsp_client *client)
+r535_gsp_client_ctor(struct nvkm_gsp_client *client, u32 handle)
 {
        NV0000_ALLOC_PARAMETERS *args;
-       int ret;
-
-       mutex_lock(&gsp->client_id.mutex);
-       ret = idr_alloc(&gsp->client_id.idr, client, 0, 0xffff + 1, GFP_KERNEL);
-       mutex_unlock(&gsp->client_id.mutex);
-       if (ret < 0)
-               return ret;
 
-       client->gsp = gsp;
-       client->object.client = client;
-       INIT_LIST_HEAD(&client->events);
-
-       args = nvkm_gsp_rm_alloc_get(&client->object, NVKM_RM_CLIENT(ret), NV01_ROOT, sizeof(*args),
+       args = nvkm_gsp_rm_alloc_get(&client->object, handle, NV01_ROOT, sizeof(*args),
                                     &client->object);
-       if (IS_ERR(args)) {
-               r535_gsp_client_dtor(client);
-               return ret;
-       }
+       if (IS_ERR(args))
+               return PTR_ERR(args);
 
        args->hClient = client->object.handle;
        args->processID = ~0;
 
-       ret = nvkm_gsp_rm_alloc_wr(&client->object, args);
-       if (ret) {
-               r535_gsp_client_dtor(client);
-               return ret;
-       }
-
-       return 0;
+       return nvkm_gsp_rm_alloc_wr(&client->object, args);
 }
 
 const struct nvkm_rm_api_client
 r535_client = {
        .ctor = r535_gsp_client_ctor,
-       .dtor = r535_gsp_client_dtor,
 };
index eb018b73d26fe88b7e14609971681e8b797921da..5e9d7351ecc41598718151b27c1c916039ab1904 100644 (file)
@@ -59,8 +59,7 @@ struct nvkm_rm_api {
        } *alloc;
 
        const struct nvkm_rm_api_client {
-               int (*ctor)(struct nvkm_gsp *, struct nvkm_gsp_client *);
-               void (*dtor)(struct nvkm_gsp_client *);
+               int (*ctor)(struct nvkm_gsp_client *, u32 handle);
        } *client;
 
        const struct nvkm_rm_api_device {