Skip to content

Commit 1b9d7b9

Browse files
Ben Skeggsairlied
authored andcommitted
drm/nouveau/gsp: add common client alloc code
570.144 has incompatible changes to NV0000_ALLOC_PARAMETERS. Factor out the common code so it can be shared. Signed-off-by: Ben Skeggs <[email protected]> Signed-off-by: Dave Airlie <[email protected]>
1 parent 9c86a60 commit 1b9d7b9

File tree

6 files changed

+59
-56
lines changed

6 files changed

+59
-56
lines changed

drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -411,21 +411,8 @@ nvkm_gsp_rm_free(struct nvkm_gsp_object *object)
411411
return 0;
412412
}
413413

414-
static inline int
415-
nvkm_gsp_client_ctor(struct nvkm_gsp *gsp, struct nvkm_gsp_client *client)
416-
{
417-
if (WARN_ON(!gsp->rm))
418-
return -ENOSYS;
419-
420-
return gsp->rm->api->client->ctor(gsp, client);
421-
}
422-
423-
static inline void
424-
nvkm_gsp_client_dtor(struct nvkm_gsp_client *client)
425-
{
426-
if (client->gsp)
427-
client->gsp->rm->api->client->dtor(client);
428-
}
414+
int nvkm_gsp_client_ctor(struct nvkm_gsp *, struct nvkm_gsp_client *);
415+
void nvkm_gsp_client_dtor(struct nvkm_gsp_client *);
429416

430417
static inline int
431418
nvkm_gsp_device_ctor(struct nvkm_gsp_client *client, struct nvkm_gsp_device *device)

drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: MIT
22
#
33
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
4+
nvkm-y += nvkm/subdev/gsp/rm/client.o
45
nvkm-y += nvkm/subdev/gsp/rm/engine.o
56
nvkm-y += nvkm/subdev/gsp/rm/gr.o
67
nvkm-y += nvkm/subdev/gsp/rm/nvdec.o
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* SPDX-License-Identifier: MIT
2+
*
3+
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
4+
*/
5+
#include "rm.h"
6+
7+
void
8+
nvkm_gsp_client_dtor(struct nvkm_gsp_client *client)
9+
{
10+
const unsigned int id = client->object.handle - NVKM_RM_CLIENT(0);
11+
struct nvkm_gsp *gsp = client->gsp;
12+
13+
if (!gsp)
14+
return;
15+
16+
if (client->object.client)
17+
nvkm_gsp_rm_free(&client->object);
18+
19+
mutex_lock(&gsp->client_id.mutex);
20+
idr_remove(&gsp->client_id.idr, id);
21+
mutex_unlock(&gsp->client_id.mutex);
22+
23+
client->gsp = NULL;
24+
}
25+
26+
int
27+
nvkm_gsp_client_ctor(struct nvkm_gsp *gsp, struct nvkm_gsp_client *client)
28+
{
29+
int id, ret;
30+
31+
if (WARN_ON(!gsp->rm))
32+
return -ENOSYS;
33+
34+
mutex_lock(&gsp->client_id.mutex);
35+
id = idr_alloc(&gsp->client_id.idr, client, 0, NVKM_RM_CLIENT_MASK + 1, GFP_KERNEL);
36+
mutex_unlock(&gsp->client_id.mutex);
37+
if (id < 0)
38+
return id;
39+
40+
client->gsp = gsp;
41+
client->object.client = client;
42+
INIT_LIST_HEAD(&client->events);
43+
44+
ret = gsp->rm->api->client->ctor(client, NVKM_RM_CLIENT(id));
45+
if (ret)
46+
nvkm_gsp_client_dtor(client);
47+
48+
return ret;
49+
}

drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/handles.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/* RMAPI handles for various objects allocated from GSP-RM with RM_ALLOC. */
99

1010
#define NVKM_RM_CLIENT(id) (0xc1d00000 | (id))
11+
#define NVKM_RM_CLIENT_MASK 0x0000ffff
1112
#define NVKM_RM_DEVICE 0xde1d0000
1213
#define NVKM_RM_SUBDEVICE 0x5d1d0000
1314
#define NVKM_RM_DISP 0x00730000

drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/client.c

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,57 +23,23 @@
2323

2424
#include "nvrm/client.h"
2525

26-
static void
27-
r535_gsp_client_dtor(struct nvkm_gsp_client *client)
28-
{
29-
struct nvkm_gsp *gsp = client->gsp;
30-
31-
nvkm_gsp_rm_free(&client->object);
32-
33-
mutex_lock(&gsp->client_id.mutex);
34-
idr_remove(&gsp->client_id.idr, client->object.handle & 0xffff);
35-
mutex_unlock(&gsp->client_id.mutex);
36-
37-
client->gsp = NULL;
38-
}
39-
4026
static int
41-
r535_gsp_client_ctor(struct nvkm_gsp *gsp, struct nvkm_gsp_client *client)
27+
r535_gsp_client_ctor(struct nvkm_gsp_client *client, u32 handle)
4228
{
4329
NV0000_ALLOC_PARAMETERS *args;
44-
int ret;
45-
46-
mutex_lock(&gsp->client_id.mutex);
47-
ret = idr_alloc(&gsp->client_id.idr, client, 0, 0xffff + 1, GFP_KERNEL);
48-
mutex_unlock(&gsp->client_id.mutex);
49-
if (ret < 0)
50-
return ret;
5130

52-
client->gsp = gsp;
53-
client->object.client = client;
54-
INIT_LIST_HEAD(&client->events);
55-
56-
args = nvkm_gsp_rm_alloc_get(&client->object, NVKM_RM_CLIENT(ret), NV01_ROOT, sizeof(*args),
31+
args = nvkm_gsp_rm_alloc_get(&client->object, handle, NV01_ROOT, sizeof(*args),
5732
&client->object);
58-
if (IS_ERR(args)) {
59-
r535_gsp_client_dtor(client);
60-
return ret;
61-
}
33+
if (IS_ERR(args))
34+
return PTR_ERR(args);
6235

6336
args->hClient = client->object.handle;
6437
args->processID = ~0;
6538

66-
ret = nvkm_gsp_rm_alloc_wr(&client->object, args);
67-
if (ret) {
68-
r535_gsp_client_dtor(client);
69-
return ret;
70-
}
71-
72-
return 0;
39+
return nvkm_gsp_rm_alloc_wr(&client->object, args);
7340
}
7441

7542
const struct nvkm_rm_api_client
7643
r535_client = {
7744
.ctor = r535_gsp_client_ctor,
78-
.dtor = r535_gsp_client_dtor,
7945
};

drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ struct nvkm_rm_api {
5959
} *alloc;
6060

6161
const struct nvkm_rm_api_client {
62-
int (*ctor)(struct nvkm_gsp *, struct nvkm_gsp_client *);
63-
void (*dtor)(struct nvkm_gsp_client *);
62+
int (*ctor)(struct nvkm_gsp_client *, u32 handle);
6463
} *client;
6564

6665
const struct nvkm_rm_api_device {

0 commit comments

Comments
 (0)