Home | History | Annotate | Line # | Download | only in nouveau
nouveau_nvif.c revision 1.1.1.2
      1 /*	$NetBSD: nouveau_nvif.c,v 1.1.1.2 2021/12/18 20:15:36 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.1.2 2021/12/18 20:15:36 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_drv.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 	struct nvkm_client *client = priv;
     69 	return nvkm_object_init(&client->object);
     70 }
     71 
     72 static int
     73 nvkm_client_suspend(void *priv)
     74 {
     75 	struct nvkm_client *client = priv;
     76 	return nvkm_object_fini(&client->object, true);
     77 }
     78 
     79 static int
     80 nvkm_client_ntfy(const void *header, u32 length, const void *data, u32 size)
     81 {
     82 	const union {
     83 		struct nvif_notify_req_v0 v0;
     84 	} *args = header;
     85 	u8 route;
     86 
     87 	if (length == sizeof(args->v0) && args->v0.version == 0) {
     88 		route = args->v0.route;
     89 	} else {
     90 		WARN_ON(1);
     91 		return NVKM_NOTIFY_DROP;
     92 	}
     93 
     94 	switch (route) {
     95 	case NVDRM_NOTIFY_NVIF:
     96 		return nvif_notify(header, length, data, size);
     97 	case NVDRM_NOTIFY_USIF:
     98 		return usif_notify(header, length, data, size);
     99 	default:
    100 		WARN_ON(1);
    101 		break;
    102 	}
    103 
    104 	return NVKM_NOTIFY_DROP;
    105 }
    106 
    107 static int
    108 nvkm_client_driver_init(const char *name, u64 device, const char *cfg,
    109 			const char *dbg, void **ppriv)
    110 {
    111 	return nvkm_client_new(name, device, cfg, dbg, nvkm_client_ntfy,
    112 			       (struct nvkm_client **)ppriv);
    113 }
    114 
    115 const struct nvif_driver
    116 nvif_driver_nvkm = {
    117 	.name = "nvkm",
    118 	.init = nvkm_client_driver_init,
    119 	.suspend = nvkm_client_suspend,
    120 	.resume = nvkm_client_resume,
    121 	.ioctl = nvkm_client_ioctl,
    122 	.map = nvkm_client_map,
    123 	.unmap = nvkm_client_unmap,
    124 	.keep = false,
    125 };
    126