2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <core/object.h>
26 #include <core/client.h>
27 #include <core/handle.h>
28 #include <core/option.h>
30 #include <engine/device.h>
33 nouveau_client_dtor(struct nouveau_object *object)
35 struct nouveau_client *client = (void *)object;
36 nouveau_object_ref(NULL, &client->device);
37 nouveau_handle_destroy(client->root);
38 nouveau_namedb_destroy(&client->base);
41 static struct nouveau_oclass
42 nouveau_client_oclass = {
43 .ofuncs = &(struct nouveau_ofuncs) {
44 .dtor = nouveau_client_dtor,
49 nouveau_client_create_(const char *name, u64 devname, const char *cfg,
50 const char *dbg, int length, void **pobject)
52 struct nouveau_object *device;
53 struct nouveau_client *client;
56 device = (void *)nouveau_device_find(devname);
60 ret = nouveau_namedb_create_(NULL, NULL, &nouveau_client_oclass,
61 NV_CLIENT_CLASS, NULL,
62 (1ULL << NVDEV_ENGINE_DEVICE),
68 ret = nouveau_handle_create(nv_object(client), ~0, ~0,
69 nv_object(client), &client->root);
73 /* prevent init/fini being called, os in in charge of this */
74 atomic_set(&nv_object(client)->usecount, 2);
76 nouveau_object_ref(device, &client->device);
77 snprintf(client->name, sizeof(client->name), "%s", name);
78 client->debug = nouveau_dbgopt(dbg, "CLIENT");
83 nouveau_client_init(struct nouveau_client *client)
86 nv_debug(client, "init running\n");
87 ret = nouveau_handle_init(client->root);
88 nv_debug(client, "init completed with %d\n", ret);
93 nouveau_client_fini(struct nouveau_client *client, bool suspend)
95 const char *name[2] = { "fini", "suspend" };
98 nv_debug(client, "%s running\n", name[suspend]);
99 ret = nouveau_handle_fini(client->root, suspend);
100 nv_debug(client, "%s completed with %d\n", name[suspend], ret);
105 nouveau_client_name(void *obj)
107 const char *client_name = "unknown";
108 struct nouveau_client *client = nouveau_client(obj);
110 client_name = client->name;