drm/nouveau/gsp: split rm alloc handling out on its own

Split base RM_ALLOC handling out into its own module.

Aside from moving the function pointers, no code change is intended.

Signed-off-by: Ben Skeggs <bskeggs@nvidia.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Timur Tabi <ttabi@nvidia.com>
Tested-by: Timur Tabi <ttabi@nvidia.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Ben Skeggs 2024-11-14 13:02:36 +10:00 committed by Dave Airlie
parent 063d193f12
commit be33f49980
6 changed files with 132 additions and 96 deletions

View File

@ -212,12 +212,6 @@ struct nvkm_gsp {
const struct nvkm_gsp_rm {
const struct nvkm_rm_api *api;
void *(*rm_alloc_get)(struct nvkm_gsp_object *, u32 oclass, u32 argc);
void *(*rm_alloc_push)(struct nvkm_gsp_object *, void *argv);
void (*rm_alloc_done)(struct nvkm_gsp_object *, void *repv);
int (*rm_free)(struct nvkm_gsp_object *);
int (*client_ctor)(struct nvkm_gsp *, struct nvkm_gsp_client *);
void (*client_dtor)(struct nvkm_gsp_client *);
@ -364,7 +358,7 @@ nvkm_gsp_rm_alloc_get(struct nvkm_gsp_object *parent, u32 handle, u32 oclass, u3
object->parent = parent;
object->handle = handle;
argv = gsp->rm->rm_alloc_get(object, oclass, argc);
argv = gsp->rm->api->alloc->get(object, oclass, argc);
if (IS_ERR_OR_NULL(argv)) {
object->client = NULL;
return argv;
@ -376,7 +370,7 @@ nvkm_gsp_rm_alloc_get(struct nvkm_gsp_object *parent, u32 handle, u32 oclass, u3
static inline void *
nvkm_gsp_rm_alloc_push(struct nvkm_gsp_object *object, void *argv)
{
void *repv = object->client->gsp->rm->rm_alloc_push(object, argv);
void *repv = object->client->gsp->rm->api->alloc->push(object, argv);
if (IS_ERR(repv))
object->client = NULL;
@ -398,7 +392,7 @@ nvkm_gsp_rm_alloc_wr(struct nvkm_gsp_object *object, void *argv)
static inline void
nvkm_gsp_rm_alloc_done(struct nvkm_gsp_object *object, void *repv)
{
object->client->gsp->rm->rm_alloc_done(object, repv);
object->client->gsp->rm->api->alloc->done(object, repv);
}
static inline int
@ -416,8 +410,11 @@ nvkm_gsp_rm_alloc(struct nvkm_gsp_object *parent, u32 handle, u32 oclass, u32 ar
static inline int
nvkm_gsp_rm_free(struct nvkm_gsp_object *object)
{
if (object->client)
return object->client->gsp->rm->rm_free(object);
if (object->client) {
int ret = object->client->gsp->rm->api->alloc->free(object);
object->client = NULL;
return ret;
}
return 0;
}

View File

@ -226,95 +226,10 @@ r535_gsp_client_ctor(struct nvkm_gsp *gsp, struct nvkm_gsp_client *client)
return 0;
}
static int
r535_gsp_rpc_rm_free(struct nvkm_gsp_object *object)
{
struct nvkm_gsp_client *client = object->client;
struct nvkm_gsp *gsp = client->gsp;
rpc_free_v03_00 *rpc;
nvkm_debug(&gsp->subdev, "cli:0x%08x obj:0x%08x free\n",
client->object.handle, object->handle);
rpc = nvkm_gsp_rpc_get(gsp, NV_VGPU_MSG_FUNCTION_FREE, sizeof(*rpc));
if (WARN_ON(IS_ERR_OR_NULL(rpc)))
return -EIO;
rpc->params.hRoot = client->object.handle;
rpc->params.hObjectParent = 0;
rpc->params.hObjectOld = object->handle;
return nvkm_gsp_rpc_wr(gsp, rpc, NVKM_GSP_RPC_REPLY_RECV);
}
static void
r535_gsp_rpc_rm_alloc_done(struct nvkm_gsp_object *object, void *params)
{
rpc_gsp_rm_alloc_v03_00 *rpc = to_payload_hdr(params, rpc);
nvkm_gsp_rpc_done(object->client->gsp, rpc);
}
static void *
r535_gsp_rpc_rm_alloc_push(struct nvkm_gsp_object *object, void *params)
{
rpc_gsp_rm_alloc_v03_00 *rpc = to_payload_hdr(params, rpc);
struct nvkm_gsp *gsp = object->client->gsp;
void *ret = NULL;
rpc = nvkm_gsp_rpc_push(gsp, rpc, NVKM_GSP_RPC_REPLY_RECV, sizeof(*rpc));
if (IS_ERR_OR_NULL(rpc))
return rpc;
if (rpc->status) {
ret = ERR_PTR(r535_rpc_status_to_errno(rpc->status));
if (PTR_ERR(ret) != -EAGAIN && PTR_ERR(ret) != -EBUSY)
nvkm_error(&gsp->subdev, "RM_ALLOC: 0x%x\n", rpc->status);
}
nvkm_gsp_rpc_done(gsp, rpc);
return ret;
}
static void *
r535_gsp_rpc_rm_alloc_get(struct nvkm_gsp_object *object, u32 oclass,
u32 params_size)
{
struct nvkm_gsp_client *client = object->client;
struct nvkm_gsp *gsp = client->gsp;
rpc_gsp_rm_alloc_v03_00 *rpc;
nvkm_debug(&gsp->subdev, "cli:0x%08x obj:0x%08x new obj:0x%08x\n",
client->object.handle, object->parent->handle,
object->handle);
nvkm_debug(&gsp->subdev, "cls:0x%08x params_size:%d\n", oclass,
params_size);
rpc = nvkm_gsp_rpc_get(gsp, NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC,
sizeof(*rpc) + params_size);
if (IS_ERR(rpc))
return rpc;
rpc->hClient = client->object.handle;
rpc->hParent = object->parent->handle;
rpc->hObject = object->handle;
rpc->hClass = oclass;
rpc->status = 0;
rpc->paramsSize = params_size;
return rpc->params;
}
const struct nvkm_gsp_rm
r535_gsp_rm = {
.api = &r535_rm,
.rm_alloc_get = r535_gsp_rpc_rm_alloc_get,
.rm_alloc_push = r535_gsp_rpc_rm_alloc_push,
.rm_alloc_done = r535_gsp_rpc_rm_alloc_done,
.rm_free = r535_gsp_rpc_rm_free,
.client_ctor = r535_gsp_client_ctor,
.client_dtor = r535_gsp_client_dtor,

View File

@ -5,3 +5,4 @@
nvkm-y += nvkm/subdev/gsp/rm/r535/rm.o
nvkm-y += nvkm/subdev/gsp/rm/r535/rpc.o
nvkm-y += nvkm/subdev/gsp/rm/r535/ctrl.o
nvkm-y += nvkm/subdev/gsp/rm/r535/alloc.o

View File

@ -0,0 +1,113 @@
/*
* Copyright 2023 Red Hat Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <rm/rpc.h>
#include <nvrm/nvtypes.h>
#include <nvrm/535.113.01/nvidia/generated/g_rpc-structures.h>
#include <nvrm/535.113.01/nvidia/kernel/inc/vgpu/rpc_global_enums.h>
static int
r535_gsp_rpc_rm_free(struct nvkm_gsp_object *object)
{
struct nvkm_gsp_client *client = object->client;
struct nvkm_gsp *gsp = client->gsp;
rpc_free_v03_00 *rpc;
nvkm_debug(&gsp->subdev, "cli:0x%08x obj:0x%08x free\n",
client->object.handle, object->handle);
rpc = nvkm_gsp_rpc_get(gsp, NV_VGPU_MSG_FUNCTION_FREE, sizeof(*rpc));
if (WARN_ON(IS_ERR_OR_NULL(rpc)))
return -EIO;
rpc->params.hRoot = client->object.handle;
rpc->params.hObjectParent = 0;
rpc->params.hObjectOld = object->handle;
return nvkm_gsp_rpc_wr(gsp, rpc, NVKM_GSP_RPC_REPLY_RECV);
}
static void
r535_gsp_rpc_rm_alloc_done(struct nvkm_gsp_object *object, void *params)
{
rpc_gsp_rm_alloc_v03_00 *rpc = to_payload_hdr(params, rpc);
nvkm_gsp_rpc_done(object->client->gsp, rpc);
}
static void *
r535_gsp_rpc_rm_alloc_push(struct nvkm_gsp_object *object, void *params)
{
rpc_gsp_rm_alloc_v03_00 *rpc = to_payload_hdr(params, rpc);
struct nvkm_gsp *gsp = object->client->gsp;
void *ret = NULL;
rpc = nvkm_gsp_rpc_push(gsp, rpc, NVKM_GSP_RPC_REPLY_RECV, sizeof(*rpc));
if (IS_ERR_OR_NULL(rpc))
return rpc;
if (rpc->status) {
ret = ERR_PTR(r535_rpc_status_to_errno(rpc->status));
if (PTR_ERR(ret) != -EAGAIN && PTR_ERR(ret) != -EBUSY)
nvkm_error(&gsp->subdev, "RM_ALLOC: 0x%x\n", rpc->status);
}
nvkm_gsp_rpc_done(gsp, rpc);
return ret;
}
static void *
r535_gsp_rpc_rm_alloc_get(struct nvkm_gsp_object *object, u32 oclass,
u32 params_size)
{
struct nvkm_gsp_client *client = object->client;
struct nvkm_gsp *gsp = client->gsp;
rpc_gsp_rm_alloc_v03_00 *rpc;
nvkm_debug(&gsp->subdev, "cli:0x%08x obj:0x%08x new obj:0x%08x\n",
client->object.handle, object->parent->handle,
object->handle);
nvkm_debug(&gsp->subdev, "cls:0x%08x params_size:%d\n", oclass,
params_size);
rpc = nvkm_gsp_rpc_get(gsp, NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC,
sizeof(*rpc) + params_size);
if (IS_ERR(rpc))
return rpc;
rpc->hClient = client->object.handle;
rpc->hParent = object->parent->handle;
rpc->hObject = object->handle;
rpc->hClass = oclass;
rpc->status = 0;
rpc->paramsSize = params_size;
return rpc->params;
}
const struct nvkm_rm_api_alloc
r535_alloc = {
.get = r535_gsp_rpc_rm_alloc_get,
.push = r535_gsp_rpc_rm_alloc_push,
.done = r535_gsp_rpc_rm_alloc_done,
.free = r535_gsp_rpc_rm_free,
};

View File

@ -8,4 +8,5 @@ const struct nvkm_rm_api
r535_rm = {
.rpc = &r535_rpc,
.ctrl = &r535_ctrl,
.alloc = &r535_alloc,
};

View File

@ -19,9 +19,18 @@ struct nvkm_rm_api {
int (*push)(struct nvkm_gsp_object *, void **params, u32 repc);
void (*done)(struct nvkm_gsp_object *, void *params);
} *ctrl;
const struct nvkm_rm_api_alloc {
void *(*get)(struct nvkm_gsp_object *, u32 oclass, u32 params_size);
void *(*push)(struct nvkm_gsp_object *, void *params);
void (*done)(struct nvkm_gsp_object *, void *params);
int (*free)(struct nvkm_gsp_object *);
} *alloc;
};
extern const struct nvkm_rm_api r535_rm;
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;
#endif