1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <core/object.h>
26#include <core/client.h>
27#include <core/handle.h>
28#include <core/option.h>
29
30#include <engine/device.h>
31
32static void
33nouveau_client_dtor(struct nouveau_object *object)
34{
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);
39}
40
41static struct nouveau_oclass
42nouveau_client_oclass = {
43 .ofuncs = &(struct nouveau_ofuncs) {
44 .dtor = nouveau_client_dtor,
45 },
46};
47
48int
49nouveau_client_create_(const char *name, u64 devname, const char *cfg,
50 const char *dbg, int length, void **pobject)
51{
52 struct nouveau_object *device;
53 struct nouveau_client *client;
54 int ret;
55
56 device = (void *)nouveau_device_find(devname);
57 if (!device)
58 return -ENODEV;
59
60 ret = nouveau_namedb_create_(NULL, NULL, &nouveau_client_oclass,
61 NV_CLIENT_CLASS, NULL,
62 (1ULL << NVDEV_ENGINE_DEVICE),
63 length, pobject);
64 client = *pobject;
65 if (ret)
66 return ret;
67
68 ret = nouveau_handle_create(nv_object(client), ~0, ~0,
69 nv_object(client), &client->root);
70 if (ret)
71 return ret;
72
73
74 atomic_set(&nv_object(client)->usecount, 2);
75
76 nouveau_object_ref(device, &client->device);
77 snprintf(client->name, sizeof(client->name), "%s", name);
78 client->debug = nouveau_dbgopt(dbg, "CLIENT");
79 return 0;
80}
81
82int
83nouveau_client_init(struct nouveau_client *client)
84{
85 int ret;
86 nv_debug(client, "init running\n");
87 ret = nouveau_handle_init(client->root);
88 nv_debug(client, "init completed with %d\n", ret);
89 return ret;
90}
91
92int
93nouveau_client_fini(struct nouveau_client *client, bool suspend)
94{
95 const char *name[2] = { "fini", "suspend" };
96 int ret;
97
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);
101 return ret;
102}
103
104const char *
105nouveau_client_name(void *obj)
106{
107 const char *client_name = "unknown";
108 struct nouveau_client *client = nouveau_client(obj);
109 if (client)
110 client_name = client->name;
111 return client_name;
112}
113