blob: ca0ad9d1563df627bd4228212ae294b47f894d74 [file] [log] [blame]
Ben Skeggs0ad72862014-08-10 04:10:22 +10001/*
2 * Copyright 2014 Red Hat Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
23 */
24
25/*******************************************************************************
26 * NVIF client driver - NVKM directly linked
27 ******************************************************************************/
28
29#include <core/client.h>
30#include <core/notify.h>
31#include <core/ioctl.h>
32
33#include <nvif/client.h>
34#include <nvif/driver.h>
35#include <nvif/notify.h>
36#include <nvif/event.h>
37#include <nvif/ioctl.h>
38
39#include "nouveau_drm.h"
Ben Skeggs27111a22014-08-10 04:10:31 +100040#include "nouveau_usif.h"
Ben Skeggs0ad72862014-08-10 04:10:22 +100041
42static void
Al Viro3cfb2fa2014-08-31 15:06:09 -040043nvkm_client_unmap(void *priv, void __iomem *ptr, u32 size)
Ben Skeggs0ad72862014-08-10 04:10:22 +100044{
45 iounmap(ptr);
46}
47
Al Viro3cfb2fa2014-08-31 15:06:09 -040048static void __iomem *
Ben Skeggs0ad72862014-08-10 04:10:22 +100049nvkm_client_map(void *priv, u64 handle, u32 size)
50{
51 return ioremap(handle, size);
52}
53
54static int
55nvkm_client_ioctl(void *priv, bool super, void *data, u32 size, void **hack)
56{
57 return nvkm_ioctl(priv, super, data, size, hack);
58}
59
60static int
61nvkm_client_resume(void *priv)
62{
Ben Skeggsbe83cd42015-01-14 15:36:34 +100063 return nvkm_client_init(priv);
Ben Skeggs0ad72862014-08-10 04:10:22 +100064}
65
66static int
67nvkm_client_suspend(void *priv)
68{
Ben Skeggsbe83cd42015-01-14 15:36:34 +100069 return nvkm_client_fini(priv, true);
Ben Skeggs0ad72862014-08-10 04:10:22 +100070}
71
72static void
Ben Skeggs50254072015-01-14 14:11:21 +100073nvkm_client_driver_fini(void *priv)
Ben Skeggs0ad72862014-08-10 04:10:22 +100074{
Ben Skeggsbe83cd42015-01-14 15:36:34 +100075 struct nvkm_object *client = priv;
76 nvkm_client_fini(nv_client(client), false);
Ben Skeggs0ad72862014-08-10 04:10:22 +100077 atomic_set(&client->refcount, 1);
Ben Skeggsbe83cd42015-01-14 15:36:34 +100078 nvkm_object_ref(NULL, &client);
Ben Skeggs0ad72862014-08-10 04:10:22 +100079}
80
81static int
82nvkm_client_ntfy(const void *header, u32 length, const void *data, u32 size)
83{
84 const union {
85 struct nvif_notify_req_v0 v0;
86 } *args = header;
87 u8 route;
88
89 if (length == sizeof(args->v0) && args->v0.version == 0) {
90 route = args->v0.route;
91 } else {
92 WARN_ON(1);
93 return NVKM_NOTIFY_DROP;
94 }
95
96 switch (route) {
97 case NVDRM_NOTIFY_NVIF:
98 return nvif_notify(header, length, data, size);
Ben Skeggs27111a22014-08-10 04:10:31 +100099 case NVDRM_NOTIFY_USIF:
100 return usif_notify(header, length, data, size);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000101 default:
102 WARN_ON(1);
103 break;
104 }
105
106 return NVKM_NOTIFY_DROP;
107}
108
109static int
Ben Skeggs50254072015-01-14 14:11:21 +1000110nvkm_client_driver_init(const char *name, u64 device, const char *cfg,
111 const char *dbg, void **ppriv)
Ben Skeggs0ad72862014-08-10 04:10:22 +1000112{
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000113 struct nvkm_client *client;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000114 int ret;
115
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000116 ret = nvkm_client_create(name, device, cfg, dbg, &client);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000117 *ppriv = client;
118 if (ret)
119 return ret;
120
121 client->ntfy = nvkm_client_ntfy;
122 return 0;
123}
124
125const struct nvif_driver
126nvif_driver_nvkm = {
127 .name = "nvkm",
Ben Skeggs50254072015-01-14 14:11:21 +1000128 .init = nvkm_client_driver_init,
129 .fini = nvkm_client_driver_fini,
Ben Skeggs0ad72862014-08-10 04:10:22 +1000130 .suspend = nvkm_client_suspend,
131 .resume = nvkm_client_resume,
132 .ioctl = nvkm_client_ioctl,
133 .map = nvkm_client_map,
134 .unmap = nvkm_client_unmap,
135 .keep = false,
136};