Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/nouveau/core/client: allow creation of subclients

We want a supervisor client of NVKM (such as the DRM) to be able to
allow sharing of resources (such as memory objects) between clients.

To allow this, the supervisor creates all its clients as children of
itself, and will use an upcoming ioctl to permit sharing.

Currently it's not possible for indirect clients to use subclients.
Supporting this will require an additional field in the main ioctl.
This isn't important currently, but will need to be fixed for virt.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>

+140 -35
+1 -2
drivers/gpu/drm/nouveau/include/nvif/client.h
··· 11 11 bool super; 12 12 }; 13 13 14 - int nvif_client_init(const char *drv, const char *name, u64 device, 15 - const char *cfg, const char *dbg, 14 + int nvif_client_init(struct nvif_client *parent, const char *name, u64 device, 16 15 struct nvif_client *); 17 16 void nvif_client_fini(struct nvif_client *); 18 17 int nvif_client_ioctl(struct nvif_client *, void *, u32);
+5 -1
drivers/gpu/drm/nouveau/include/nvif/driver.h
··· 1 1 #ifndef __NVIF_DRIVER_H__ 2 2 #define __NVIF_DRIVER_H__ 3 + #include <nvif/os.h> 4 + struct nvif_client; 3 5 4 6 struct nvif_driver { 5 7 const char *name; ··· 16 14 bool keep; 17 15 }; 18 16 17 + int nvif_driver_init(const char *drv, const char *cfg, const char *dbg, 18 + const char *name, u64 device, struct nvif_client *); 19 + 19 20 extern const struct nvif_driver nvif_driver_nvkm; 20 21 extern const struct nvif_driver nvif_driver_drm; 21 22 extern const struct nvif_driver nvif_driver_lib; 22 23 extern const struct nvif_driver nvif_driver_null; 23 - 24 24 #endif
+7
drivers/gpu/drm/nouveau/include/nvif/if0000.h
··· 1 1 #ifndef __NVIF_IF0000_H__ 2 2 #define __NVIF_IF0000_H__ 3 3 4 + struct nvif_client_v0 { 5 + __u8 version; 6 + __u8 pad01[7]; 7 + __u64 device; 8 + char name[32]; 9 + }; 10 + 4 11 #define NVIF_CLIENT_V0_DEVLIST 0x00 5 12 6 13 struct nvif_client_devlist_v0 {
+1
drivers/gpu/drm/nouveau/include/nvkm/core/client.h
··· 23 23 const char *dbg, 24 24 int (*)(const void *, u32, const void *, u32), 25 25 struct nvkm_client **); 26 + struct nvkm_client *nvkm_client_search(struct nvkm_client *, u64 handle); 26 27 27 28 int nvkm_client_notify_new(struct nvkm_object *, struct nvkm_event *, 28 29 void *data, u32 size);
+4 -2
drivers/gpu/drm/nouveau/nouveau_drm.c
··· 37 37 #include <core/pci.h> 38 38 #include <core/tegra.h> 39 39 40 + #include <nvif/driver.h> 41 + 40 42 #include <nvif/class.h> 41 43 #include <nvif/cl0002.h> 42 44 #include <nvif/cla06f.h> ··· 121 119 snprintf(cli->name, sizeof(cli->name), "%s", sname); 122 120 cli->dev = dev; 123 121 124 - ret = nvif_client_init(NULL, cli->name, nouveau_name(dev), 125 - nouveau_config, nouveau_debug, 122 + ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug, 123 + cli->name, nouveau_name(dev), 126 124 &cli->base); 127 125 if (ret == 0) { 128 126 mutex_init(&cli->mutex);
+1
drivers/gpu/drm/nouveau/nvif/Kbuild
··· 1 1 nvif-y := nvif/object.o 2 2 nvif-y += nvif/client.o 3 3 nvif-y += nvif/device.o 4 + nvif-y += nvif/driver.o 4 5 nvif-y += nvif/notify.o
+15 -28
drivers/gpu/drm/nouveau/nvif/client.c
··· 26 26 #include <nvif/driver.h> 27 27 #include <nvif/ioctl.h> 28 28 29 + #include <nvif/class.h> 30 + #include <nvif/if0000.h> 31 + 29 32 int 30 33 nvif_client_ioctl(struct nvif_client *client, void *data, u32 size) 31 34 { ··· 58 55 } 59 56 } 60 57 61 - static const struct nvif_driver * 62 - nvif_drivers[] = { 63 - #ifdef __KERNEL__ 64 - &nvif_driver_nvkm, 65 - #else 66 - &nvif_driver_drm, 67 - &nvif_driver_lib, 68 - &nvif_driver_null, 69 - #endif 70 - NULL 71 - }; 72 - 73 58 int 74 - nvif_client_init(const char *driver, const char *name, u64 device, 75 - const char *cfg, const char *dbg, struct nvif_client *client) 59 + nvif_client_init(struct nvif_client *parent, const char *name, u64 device, 60 + struct nvif_client *client) 76 61 { 62 + struct nvif_client_v0 args = { .device = device }; 77 63 struct { 78 64 struct nvif_ioctl_v0 ioctl; 79 65 struct nvif_ioctl_nop_v0 nop; 80 - } args = {}; 81 - int ret, i; 66 + } nop = {}; 67 + int ret; 82 68 83 - ret = nvif_object_init(NULL, 0, 0, NULL, 0, &client->object); 69 + strncpy(args.name, name, sizeof(args.name)); 70 + ret = nvif_object_init(parent != client ? &parent->object : NULL, 71 + 0, NVIF_CLASS_CLIENT, &args, sizeof(args), 72 + &client->object); 84 73 if (ret) 85 74 return ret; 86 75 ··· 80 85 client->object.handle = ~0; 81 86 client->route = NVIF_IOCTL_V0_ROUTE_NVIF; 82 87 client->super = true; 83 - 84 - for (i = 0, ret = -EINVAL; (client->driver = nvif_drivers[i]); i++) { 85 - if (!driver || !strcmp(client->driver->name, driver)) { 86 - ret = client->driver->init(name, device, cfg, dbg, 87 - &client->object.priv); 88 - if (!ret || driver) 89 - break; 90 - } 91 - } 88 + client->driver = parent->driver; 92 89 93 90 if (ret == 0) { 94 - ret = nvif_client_ioctl(client, &args, sizeof(args)); 95 - client->version = args.nop.version; 91 + ret = nvif_client_ioctl(client, &nop, sizeof(nop)); 92 + client->version = nop.nop.version; 96 93 } 97 94 98 95 if (ret)
+58
drivers/gpu/drm/nouveau/nvif/driver.c
··· 1 + /* 2 + * Copyright 2016 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 23 + */ 24 + #include <nvif/driver.h> 25 + #include <nvif/client.h> 26 + 27 + static const struct nvif_driver * 28 + nvif_driver[] = { 29 + #ifdef __KERNEL__ 30 + &nvif_driver_nvkm, 31 + #else 32 + &nvif_driver_drm, 33 + &nvif_driver_lib, 34 + &nvif_driver_null, 35 + #endif 36 + NULL 37 + }; 38 + 39 + int 40 + nvif_driver_init(const char *drv, const char *cfg, const char *dbg, 41 + const char *name, u64 device, struct nvif_client *client) 42 + { 43 + int ret = -EINVAL, i; 44 + 45 + for (i = 0; (client->driver = nvif_driver[i]); i++) { 46 + if (!drv || !strcmp(client->driver->name, drv)) { 47 + ret = client->driver->init(name, device, cfg, dbg, 48 + &client->object.priv); 49 + if (ret == 0) 50 + break; 51 + client->driver->fini(client->object.priv); 52 + } 53 + } 54 + 55 + if (ret == 0) 56 + ret = nvif_client_init(client, name, device, client); 57 + return ret; 58 + }
+48 -2
drivers/gpu/drm/nouveau/nvkm/core/client.c
··· 31 31 #include <nvif/if0000.h> 32 32 #include <nvif/unpack.h> 33 33 34 - static const struct nvkm_sclass 34 + static int 35 + nvkm_uclient_new(const struct nvkm_oclass *oclass, void *argv, u32 argc, 36 + struct nvkm_object **pobject) 37 + { 38 + union { 39 + struct nvif_client_v0 v0; 40 + } *args = argv; 41 + struct nvkm_client *client; 42 + int ret = -ENOSYS; 43 + 44 + if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))){ 45 + args->v0.name[sizeof(args->v0.name) - 1] = 0; 46 + ret = nvkm_client_new(args->v0.name, args->v0.device, NULL, 47 + NULL, oclass->client->ntfy, &client); 48 + if (ret) 49 + return ret; 50 + } else 51 + return ret; 52 + 53 + client->object.client = oclass->client; 54 + client->object.handle = oclass->handle; 55 + client->object.route = oclass->route; 56 + client->object.token = oclass->token; 57 + client->object.object = oclass->object; 58 + client->debug = oclass->client->debug; 59 + *pobject = &client->object; 60 + return 0; 61 + } 62 + 63 + const struct nvkm_sclass 35 64 nvkm_uclient_sclass = { 36 65 .oclass = NVIF_CLASS_CLIENT, 66 + .minver = 0, 67 + .maxver = 0, 68 + .ctor = nvkm_uclient_new, 37 69 }; 38 70 39 71 struct nvkm_client_notify { ··· 175 143 return ret; 176 144 } 177 145 146 + static const struct nvkm_object_func nvkm_client; 147 + struct nvkm_client * 148 + nvkm_client_search(struct nvkm_client *client, u64 handle) 149 + { 150 + struct nvkm_object *object; 151 + 152 + object = nvkm_object_search(client, handle, &nvkm_client); 153 + if (IS_ERR(object)) 154 + return (void *)object; 155 + 156 + return nvkm_client(object); 157 + } 158 + 178 159 static int 179 160 nvkm_client_mthd_devlist(struct nvkm_client *client, void *data, u32 size) 180 161 { ··· 241 196 const struct nvkm_sclass *sclass; 242 197 243 198 switch (index) { 244 - case 0: sclass = &nvkm_udevice_sclass; break; 199 + case 0: sclass = &nvkm_uclient_sclass; break; 200 + case 1: sclass = &nvkm_udevice_sclass; break; 245 201 default: 246 202 return -EINVAL; 247 203 }