Home | History | Annotate | Line # | Download | only in nouveau
nouveau_nvif.c revision 1.3
      1 /*	$NetBSD: nouveau_nvif.c,v 1.3 2018/08/27 07:35:56 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.3 2018/08/27 07:35:56 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 #ifdef __NetBSD__
     48 #define	__iomem	__nvif_iomem
     49 static int
     50 nvkm_client_map(void *priv, bus_space_tag_t tag, u64 busaddr, u32 size,
     51     bus_space_handle_t *handlep, void __iomem **ptrp)
     52 {
     53 	int ret;
     54 
     55 	ret = -bus_space_map(tag, busaddr, size, BUS_SPACE_MAP_LINEAR,
     56 	    handlep);
     57 	if (ret)
     58 		return ret;
     59 	*ptrp = bus_space_vaddr(tag, *handlep);
     60 	return 0;
     61 }
     62 
     63 static void
     64 nvkm_client_unmap(void *priv, bus_space_tag_t tag, bus_space_handle_t handle,
     65     u32 size)
     66 {
     67 
     68 	bus_space_unmap(tag, handle, size);
     69 }
     70 #else
     71 static void
     72 nvkm_client_unmap(void *priv, void __iomem *ptr, u32 size)
     73 {
     74 	iounmap(ptr);
     75 }
     76 
     77 static void __iomem *
     78 nvkm_client_map(void *priv, u64 handle, u32 size)
     79 {
     80 	return ioremap(handle, size);
     81 }
     82 #endif
     83 
     84 static int
     85 nvkm_client_ioctl(void *priv, bool super, void *data, u32 size, void **hack)
     86 {
     87 	return nvkm_ioctl(priv, super, data, size, hack);
     88 }
     89 
     90 static int
     91 nvkm_client_resume(void *priv)
     92 {
     93 	return nvkm_client_init(priv);
     94 }
     95 
     96 static int
     97 nvkm_client_suspend(void *priv)
     98 {
     99 	return nvkm_client_fini(priv, true);
    100 }
    101 
    102 static void
    103 nvkm_client_driver_fini(void *priv)
    104 {
    105 	struct nvkm_client *client = priv;
    106 	nvkm_client_del(&client);
    107 }
    108 
    109 static int
    110 nvkm_client_ntfy(const void *header, u32 length, const void *data, u32 size)
    111 {
    112 	const union {
    113 		struct nvif_notify_req_v0 v0;
    114 	} *args = header;
    115 	u8 route;
    116 
    117 	if (length == sizeof(args->v0) && args->v0.version == 0) {
    118 		route = args->v0.route;
    119 	} else {
    120 		WARN_ON(1);
    121 		return NVKM_NOTIFY_DROP;
    122 	}
    123 
    124 	switch (route) {
    125 	case NVDRM_NOTIFY_NVIF:
    126 		return nvif_notify(header, length, data, size);
    127 	case NVDRM_NOTIFY_USIF:
    128 		return usif_notify(header, length, data, size);
    129 	default:
    130 		WARN_ON(1);
    131 		break;
    132 	}
    133 
    134 	return NVKM_NOTIFY_DROP;
    135 }
    136 
    137 static int
    138 nvkm_client_driver_init(const char *name, u64 device, const char *cfg,
    139 			const char *dbg, void **ppriv)
    140 {
    141 	struct nvkm_client *client;
    142 	int ret;
    143 
    144 	ret = nvkm_client_new(name, device, cfg, dbg, &client);
    145 	*ppriv = client;
    146 	if (ret)
    147 		return ret;
    148 
    149 	client->ntfy = nvkm_client_ntfy;
    150 	return 0;
    151 }
    152 
    153 const struct nvif_driver
    154 nvif_driver_nvkm = {
    155 	.name = "nvkm",
    156 	.init = nvkm_client_driver_init,
    157 	.fini = nvkm_client_driver_fini,
    158 	.suspend = nvkm_client_suspend,
    159 	.resume = nvkm_client_resume,
    160 	.ioctl = nvkm_client_ioctl,
    161 	.map = nvkm_client_map,
    162 	.unmap = nvkm_client_unmap,
    163 	.keep = false,
    164 };
    165