xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/nvif/nouveau_nvif_client.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: nouveau_nvif_client.c,v 1.3 2021/12/18 23:45:33 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2013 Red Hat Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors: Ben Skeggs <bskeggs@redhat.com>
25  */
26 
27 #include <sys/cdefs.h>
28 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvif_client.c,v 1.3 2021/12/18 23:45:33 riastradh Exp $");
29 
30 #include <nvif/client.h>
31 #include <nvif/driver.h>
32 #include <nvif/ioctl.h>
33 
34 #include <nvif/class.h>
35 #include <nvif/if0000.h>
36 
37 int
nvif_client_ioctl(struct nvif_client * client,void * data,u32 size)38 nvif_client_ioctl(struct nvif_client *client, void *data, u32 size)
39 {
40 	return client->driver->ioctl(client->object.priv, client->super, data, size, NULL);
41 }
42 
43 int
nvif_client_suspend(struct nvif_client * client)44 nvif_client_suspend(struct nvif_client *client)
45 {
46 	return client->driver->suspend(client->object.priv);
47 }
48 
49 int
nvif_client_resume(struct nvif_client * client)50 nvif_client_resume(struct nvif_client *client)
51 {
52 	return client->driver->resume(client->object.priv);
53 }
54 
55 void
nvif_client_fini(struct nvif_client * client)56 nvif_client_fini(struct nvif_client *client)
57 {
58 	nvif_object_fini(&client->object);
59 	if (client->driver) {
60 		if (client->driver->fini)
61 			client->driver->fini(client->object.priv);
62 		client->driver = NULL;
63 	}
64 }
65 
66 int
nvif_client_init(struct nvif_client * parent,const char * name,u64 device,struct nvif_client * client)67 nvif_client_init(struct nvif_client *parent, const char *name, u64 device,
68 		 struct nvif_client *client)
69 {
70 	struct nvif_client_v0 args = { .device = device };
71 	struct {
72 		struct nvif_ioctl_v0 ioctl;
73 		struct nvif_ioctl_nop_v0 nop;
74 	} nop = {};
75 	int ret;
76 
77 	strncpy(args.name, name, sizeof(args.name));
78 	ret = nvif_object_init(parent != client ? &parent->object : NULL,
79 			       0, NVIF_CLASS_CLIENT, &args, sizeof(args),
80 			       &client->object);
81 	if (ret)
82 		return ret;
83 
84 	client->object.client = client;
85 	client->object.handle = ~0;
86 	client->route = NVIF_IOCTL_V0_ROUTE_NVIF;
87 	client->super = true;
88 	client->driver = parent->driver;
89 
90 	if (ret == 0) {
91 		ret = nvif_client_ioctl(client, &nop, sizeof(nop));
92 		client->version = nop.nop.version;
93 	}
94 
95 	if (ret)
96 		nvif_client_fini(client);
97 	return ret;
98 }
99