struct nvkm_client {
struct nvkm_namedb namedb;
struct nvkm_handle *root;
- struct nvkm_object *device;
+ struct nvkm_device *device;
char name[32];
u32 debug;
struct nvkm_vm *vm;
return (void *)client;
}
-#define nvkm_client_create(n,c,oc,od,d) \
- nvkm_client_create_((n), (c), (oc), (od), sizeof(**d), (void **)d)
-
-int nvkm_client_create_(const char *name, u64 device, const char *cfg,
- const char *dbg, int, void **);
-#define nvkm_client_destroy(p) \
- nvkm_namedb_destroy(&(p)->base)
-
+int nvkm_client_new(const char *name, u64 device, const char *cfg,
+ const char *dbg, struct nvkm_client **);
+void nvkm_client_del(struct nvkm_client **);
int nvkm_client_init(struct nvkm_client *);
int nvkm_client_fini(struct nvkm_client *, bool suspend);
const char *nvkm_client_name(void *obj);
return -EINVAL;
}
-static void
-nvkm_client_dtor(struct nvkm_object *object)
-{
- struct nvkm_client *client = (void *)object;
- int i;
- for (i = 0; i < ARRAY_SIZE(client->notify); i++)
- nvkm_client_notify_del(client, i);
- nvkm_object_ref(NULL, &client->device);
- nvkm_handle_destroy(client->root);
- nvkm_namedb_destroy(&client->namedb);
-}
-
static struct nvkm_oclass
nvkm_client_oclass = {
.ofuncs = &(struct nvkm_ofuncs) {
- .dtor = nvkm_client_dtor,
.mthd = nvkm_client_mthd,
},
};
int
-nvkm_client_create_(const char *name, u64 devname, const char *cfg,
- const char *dbg, int length, void **pobject)
+nvkm_client_fini(struct nvkm_client *client, bool suspend)
+{
+ struct nvkm_object *object = &client->namedb.parent.object;
+ const char *name[2] = { "fini", "suspend" };
+ int ret, i;
+ nvif_trace(object, "%s running\n", name[suspend]);
+ nvif_trace(object, "%s notify\n", name[suspend]);
+ for (i = 0; i < ARRAY_SIZE(client->notify); i++)
+ nvkm_client_notify_put(client, i);
+ nvif_trace(object, "%s object\n", name[suspend]);
+ ret = nvkm_handle_fini(client->root, suspend);
+ nvif_trace(object, "%s completed with %d\n", name[suspend], ret);
+ return ret;
+}
+
+int
+nvkm_client_init(struct nvkm_client *client)
+{
+ struct nvkm_object *object = &client->namedb.parent.object;
+ int ret;
+ nvif_trace(object, "init running\n");
+ ret = nvkm_handle_init(client->root);
+ nvif_trace(object, "init completed with %d\n", ret);
+ return ret;
+}
+
+void
+nvkm_client_del(struct nvkm_client **pclient)
+{
+ struct nvkm_client *client = *pclient;
+ int i;
+ if (client) {
+ nvkm_client_fini(client, false);
+ for (i = 0; i < ARRAY_SIZE(client->notify); i++)
+ nvkm_client_notify_del(client, i);
+ nvkm_object_ref(NULL, (struct nvkm_object **)&client->device);
+ nvkm_handle_destroy(client->root);
+ nvkm_namedb_destroy(&client->namedb);
+ *pclient = NULL;
+ }
+}
+
+int
+nvkm_client_new(const char *name, u64 devname, const char *cfg,
+ const char *dbg, struct nvkm_client **pclient)
{
- struct nvkm_object *device;
+ struct nvkm_device *device;
struct nvkm_client *client;
int ret;
- device = (void *)nvkm_device_find(devname);
+ device = nvkm_device_find(devname);
if (!device)
return -ENODEV;
- ret = nvkm_namedb_create_(NULL, NULL, &nvkm_client_oclass,
- NV_CLIENT_CLASS, NULL,
- (1ULL << NVDEV_ENGINE_DEVICE),
- length, pobject);
- client = *pobject;
+ ret = nvkm_namedb_create(NULL, NULL, &nvkm_client_oclass,
+ NV_CLIENT_CLASS, NULL,
+ (1ULL << NVDEV_ENGINE_DEVICE),
+ &client);
+ *pclient = client;
if (ret)
return ret;
/* prevent init/fini being called, os in in charge of this */
atomic_set(&nv_object(client)->usecount, 2);
- nvkm_object_ref(device, &client->device);
+ nvkm_object_ref(&device->engine.subdev.object,
+ (struct nvkm_object **)&client->device);
snprintf(client->name, sizeof(client->name), "%s", name);
client->debug = nvkm_dbgopt(dbg, "CLIENT");
return 0;
}
-int
-nvkm_client_init(struct nvkm_client *client)
-{
- struct nvkm_object *object = &client->namedb.parent.object;
- int ret;
- nvif_trace(object, "init running\n");
- ret = nvkm_handle_init(client->root);
- nvif_trace(object, "init completed with %d\n", ret);
- return ret;
-}
-
-int
-nvkm_client_fini(struct nvkm_client *client, bool suspend)
-{
- struct nvkm_object *object = &client->namedb.parent.object;
- const char *name[2] = { "fini", "suspend" };
- int ret, i;
- nvif_trace(object, "%s running\n", name[suspend]);
- nvif_trace(object, "%s notify\n", name[suspend]);
- for (i = 0; i < ARRAY_SIZE(client->notify); i++)
- nvkm_client_notify_put(client, i);
- nvif_trace(object, "%s object\n", name[suspend]);
- ret = nvkm_handle_fini(client->root, suspend);
- nvif_trace(object, "%s completed with %d\n", name[suspend], ret);
- return ret;
-}
-
const char *
nvkm_client_name(void *obj)
{