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>
29 #include <nvif/unpack.h>
30 #include <nvif/class.h>
32 #include <nvif/unpack.h>
33 #include <nvif/event.h>
35 #include <engine/device.h>
37 struct nvkm_client_notify {
38 struct nouveau_client *client;
43 struct nvif_notify_rep_v0 v0;
48 nvkm_client_notify(struct nvkm_notify *n)
50 struct nvkm_client_notify *notify = container_of(n, typeof(*notify), n);
51 struct nouveau_client *client = notify->client;
52 return client->ntfy(¬ify->rep, notify->size, n->data, n->size);
56 nvkm_client_notify_put(struct nouveau_client *client, int index)
58 if (index < ARRAY_SIZE(client->notify)) {
59 if (client->notify[index]) {
60 nvkm_notify_put(&client->notify[index]->n);
68 nvkm_client_notify_get(struct nouveau_client *client, int index)
70 if (index < ARRAY_SIZE(client->notify)) {
71 if (client->notify[index]) {
72 nvkm_notify_get(&client->notify[index]->n);
80 nvkm_client_notify_del(struct nouveau_client *client, int index)
82 if (index < ARRAY_SIZE(client->notify)) {
83 if (client->notify[index]) {
84 nvkm_notify_fini(&client->notify[index]->n);
85 kfree(client->notify[index]);
86 client->notify[index] = NULL;
94 nvkm_client_notify_new(struct nouveau_object *object,
95 struct nvkm_event *event, void *data, u32 size)
97 struct nouveau_client *client = nouveau_client(object);
98 struct nvkm_client_notify *notify;
100 struct nvif_notify_req_v0 v0;
105 for (index = 0; index < ARRAY_SIZE(client->notify); index++) {
106 if (!client->notify[index])
110 if (index == ARRAY_SIZE(client->notify))
113 notify = kzalloc(sizeof(*notify), GFP_KERNEL);
117 nv_ioctl(client, "notify new size %d\n", size);
118 if (nvif_unpack(req->v0, 0, 0, true)) {
119 nv_ioctl(client, "notify new vers %d reply %d route %02x "
120 "token %llx\n", req->v0.version,
121 req->v0.reply, req->v0.route, req->v0.token);
122 notify->version = req->v0.version;
123 notify->size = sizeof(notify->rep.v0);
124 notify->rep.v0.version = req->v0.version;
125 notify->rep.v0.route = req->v0.route;
126 notify->rep.v0.token = req->v0.token;
127 reply = req->v0.reply;
131 ret = nvkm_notify_init(object, event, nvkm_client_notify,
132 false, data, size, reply, ¬ify->n);
134 client->notify[index] = notify;
135 notify->client = client;
145 nouveau_client_devlist(struct nouveau_object *object, void *data, u32 size)
148 struct nv_client_devlist_v0 v0;
152 nv_ioctl(object, "client devlist size %d\n", size);
153 if (nvif_unpack(args->v0, 0, 0, true)) {
154 nv_ioctl(object, "client devlist vers %d count %d\n",
155 args->v0.version, args->v0.count);
156 if (size == sizeof(args->v0.device[0]) * args->v0.count) {
157 ret = nouveau_device_list(args->v0.device,
160 args->v0.count = ret;
172 nouveau_client_mthd(struct nouveau_object *object, u32 mthd,
173 void *data, u32 size)
176 case NV_CLIENT_DEVLIST:
177 return nouveau_client_devlist(object, data, size);
185 nouveau_client_dtor(struct nouveau_object *object)
187 struct nouveau_client *client = (void *)object;
189 for (i = 0; i < ARRAY_SIZE(client->notify); i++)
190 nvkm_client_notify_del(client, i);
191 nouveau_object_ref(NULL, &client->device);
192 nouveau_handle_destroy(client->root);
193 nouveau_namedb_destroy(&client->base);
196 static struct nouveau_oclass
197 nouveau_client_oclass = {
198 .ofuncs = &(struct nouveau_ofuncs) {
199 .dtor = nouveau_client_dtor,
200 .mthd = nouveau_client_mthd,
205 nouveau_client_create_(const char *name, u64 devname, const char *cfg,
206 const char *dbg, int length, void **pobject)
208 struct nouveau_object *device;
209 struct nouveau_client *client;
212 device = (void *)nouveau_device_find(devname);
216 ret = nouveau_namedb_create_(NULL, NULL, &nouveau_client_oclass,
217 NV_CLIENT_CLASS, NULL,
218 (1ULL << NVDEV_ENGINE_DEVICE),
224 ret = nouveau_handle_create(nv_object(client), ~0, ~0,
225 nv_object(client), &client->root);
229 /* prevent init/fini being called, os in in charge of this */
230 atomic_set(&nv_object(client)->usecount, 2);
232 nouveau_object_ref(device, &client->device);
233 snprintf(client->name, sizeof(client->name), "%s", name);
234 client->debug = nouveau_dbgopt(dbg, "CLIENT");
239 nouveau_client_init(struct nouveau_client *client)
242 nv_debug(client, "init running\n");
243 ret = nouveau_handle_init(client->root);
244 nv_debug(client, "init completed with %d\n", ret);
249 nouveau_client_fini(struct nouveau_client *client, bool suspend)
251 const char *name[2] = { "fini", "suspend" };
253 nv_debug(client, "%s running\n", name[suspend]);
254 nv_debug(client, "%s notify\n", name[suspend]);
255 for (i = 0; i < ARRAY_SIZE(client->notify); i++)
256 nvkm_client_notify_put(client, i);
257 nv_debug(client, "%s object\n", name[suspend]);
258 ret = nouveau_handle_fini(client->root, suspend);
259 nv_debug(client, "%s completed with %d\n", name[suspend], ret);
264 nouveau_client_name(void *obj)
266 const char *client_name = "unknown";
267 struct nouveau_client *client = nouveau_client(obj);
269 client_name = client->name;