nouveau_nvif.c revision 1.1 1 /* $NetBSD: nouveau_nvif.c,v 1.1 2018/08/27 01:34:55 riastradh Exp $ */
2
3 /*
4 * Copyright 2014 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 (at) redhat.com>
25 */
26
27 /*******************************************************************************
28 * NVIF client driver - NVKM directly linked
29 ******************************************************************************/
30
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvif.c,v 1.1 2018/08/27 01:34:55 riastradh Exp $");
33
34 #include <core/client.h>
35 #include <core/notify.h>
36 #include <core/ioctl.h>
37
38 #include <nvif/client.h>
39 #include <nvif/driver.h>
40 #include <nvif/notify.h>
41 #include <nvif/event.h>
42 #include <nvif/ioctl.h>
43
44 #include "nouveau_drm.h"
45 #include "nouveau_usif.h"
46
47 static void
48 nvkm_client_unmap(void *priv, void __iomem *ptr, u32 size)
49 {
50 iounmap(ptr);
51 }
52
53 static void __iomem *
54 nvkm_client_map(void *priv, u64 handle, u32 size)
55 {
56 return ioremap(handle, size);
57 }
58
59 static int
60 nvkm_client_ioctl(void *priv, bool super, void *data, u32 size, void **hack)
61 {
62 return nvkm_ioctl(priv, super, data, size, hack);
63 }
64
65 static int
66 nvkm_client_resume(void *priv)
67 {
68 return nvkm_client_init(priv);
69 }
70
71 static int
72 nvkm_client_suspend(void *priv)
73 {
74 return nvkm_client_fini(priv, true);
75 }
76
77 static void
78 nvkm_client_driver_fini(void *priv)
79 {
80 struct nvkm_client *client = priv;
81 nvkm_client_del(&client);
82 }
83
84 static int
85 nvkm_client_ntfy(const void *header, u32 length, const void *data, u32 size)
86 {
87 const union {
88 struct nvif_notify_req_v0 v0;
89 } *args = header;
90 u8 route;
91
92 if (length == sizeof(args->v0) && args->v0.version == 0) {
93 route = args->v0.route;
94 } else {
95 WARN_ON(1);
96 return NVKM_NOTIFY_DROP;
97 }
98
99 switch (route) {
100 case NVDRM_NOTIFY_NVIF:
101 return nvif_notify(header, length, data, size);
102 case NVDRM_NOTIFY_USIF:
103 return usif_notify(header, length, data, size);
104 default:
105 WARN_ON(1);
106 break;
107 }
108
109 return NVKM_NOTIFY_DROP;
110 }
111
112 static int
113 nvkm_client_driver_init(const char *name, u64 device, const char *cfg,
114 const char *dbg, void **ppriv)
115 {
116 struct nvkm_client *client;
117 int ret;
118
119 ret = nvkm_client_new(name, device, cfg, dbg, &client);
120 *ppriv = client;
121 if (ret)
122 return ret;
123
124 client->ntfy = nvkm_client_ntfy;
125 return 0;
126 }
127
128 const struct nvif_driver
129 nvif_driver_nvkm = {
130 .name = "nvkm",
131 .init = nvkm_client_driver_init,
132 .fini = nvkm_client_driver_fini,
133 .suspend = nvkm_client_suspend,
134 .resume = nvkm_client_resume,
135 .ioctl = nvkm_client_ioctl,
136 .map = nvkm_client_map,
137 .unmap = nvkm_client_unmap,
138 .keep = false,
139 };
140