- transition from "ioctl" interface Signed-off-by: Ben Skeggs <bskeggs@xxxxxxxxxx> --- drivers/gpu/drm/nouveau/include/nvif/class.h | 2 - drivers/gpu/drm/nouveau/include/nvif/client.h | 3 +- .../gpu/drm/nouveau/include/nvif/driverif.h | 6 +++ drivers/gpu/drm/nouveau/include/nvif/if0000.h | 11 ----- .../drm/nouveau/include/nvkm/core/object.h | 10 ++++ drivers/gpu/drm/nouveau/nouveau_drm.c | 28 +---------- drivers/gpu/drm/nouveau/nvif/client.c | 26 +++-------- drivers/gpu/drm/nouveau/nvkm/core/client.c | 46 ++++++------------- drivers/gpu/drm/nouveau/nvkm/core/object.c | 33 +++++++++++++ 9 files changed, 72 insertions(+), 93 deletions(-) delete mode 100644 drivers/gpu/drm/nouveau/include/nvif/if0000.h diff --git a/drivers/gpu/drm/nouveau/include/nvif/class.h b/drivers/gpu/drm/nouveau/include/nvif/class.h index 824e052dcc25..b6bba7231750 100644 --- a/drivers/gpu/drm/nouveau/include/nvif/class.h +++ b/drivers/gpu/drm/nouveau/include/nvif/class.h @@ -3,8 +3,6 @@ #define __NVIF_CLASS_H__ /* these class numbers are made up by us, and not nvidia-assigned */ -#define NVIF_CLASS_CLIENT /* if0000.h */ -0x00000000 - #define NVIF_CLASS_CONTROL /* if0001.h */ -0x00000001 #define NVIF_CLASS_SW_NV04 /* if0004.h */ -0x00000004 diff --git a/drivers/gpu/drm/nouveau/include/nvif/client.h b/drivers/gpu/drm/nouveau/include/nvif/client.h index f8e4e25d6e86..1659e989df52 100644 --- a/drivers/gpu/drm/nouveau/include/nvif/client.h +++ b/drivers/gpu/drm/nouveau/include/nvif/client.h @@ -12,8 +12,7 @@ struct nvif_client { const struct nvif_driver *driver; }; -int nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device, - struct nvif_client *); +int nvif_client_ctor(struct nvif_client *parent, const char *name, struct nvif_client *); void nvif_client_dtor(struct nvif_client *); int nvif_client_suspend(struct nvif_client *); int nvif_client_resume(struct nvif_client *); diff --git a/drivers/gpu/drm/nouveau/include/nvif/driverif.h b/drivers/gpu/drm/nouveau/include/nvif/driverif.h index 655bd389044d..a6f95c8475b1 100644 --- a/drivers/gpu/drm/nouveau/include/nvif/driverif.h +++ b/drivers/gpu/drm/nouveau/include/nvif/driverif.h @@ -14,5 +14,11 @@ struct nvif_driver { struct nvif_client_impl { void (*del)(struct nvif_client_priv *); + + struct { + int (*new)(struct nvif_client_priv *parent, + const struct nvif_client_impl **, struct nvif_client_priv **, + u64 handle); + } client; }; #endif diff --git a/drivers/gpu/drm/nouveau/include/nvif/if0000.h b/drivers/gpu/drm/nouveau/include/nvif/if0000.h deleted file mode 100644 index 4b31496b37e1..000000000000 --- a/drivers/gpu/drm/nouveau/include/nvif/if0000.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -#ifndef __NVIF_IF0000_H__ -#define __NVIF_IF0000_H__ - -struct nvif_client_v0 { - __u8 version; - __u8 pad01[7]; - __u64 device; - char name[32]; -}; -#endif diff --git a/drivers/gpu/drm/nouveau/include/nvkm/core/object.h b/drivers/gpu/drm/nouveau/include/nvkm/core/object.h index 10107ef3ca49..9ab163d9a4d0 100644 --- a/drivers/gpu/drm/nouveau/include/nvkm/core/object.h +++ b/drivers/gpu/drm/nouveau/include/nvkm/core/object.h @@ -58,6 +58,16 @@ int nvkm_object_unmap(struct nvkm_object *); int nvkm_object_bind(struct nvkm_object *, struct nvkm_gpuobj *, int align, struct nvkm_gpuobj **); +void nvkm_object_link_(struct nvif_client_priv *, struct nvkm_object *parent, struct nvkm_object *); +int nvkm_object_link_rb(struct nvif_client_priv *, struct nvkm_object *parent, u64 handle, + struct nvkm_object *); + +static inline void +nvkm_object_link(struct nvkm_object *parent, struct nvkm_object *object) +{ + nvkm_object_link_(parent->client, parent, object); +} + bool nvkm_object_insert(struct nvkm_object *); void nvkm_object_remove(struct nvkm_object *); struct nvkm_object *nvkm_object_search(struct nvkm_client *, u64 object, diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c index d793afd929c9..5e4c706bf150 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -113,30 +113,6 @@ static struct drm_driver driver_stub; static struct drm_driver driver_pci; static struct drm_driver driver_platform; -static u64 -nouveau_pci_name(struct pci_dev *pdev) -{ - u64 name = (u64)pci_domain_nr(pdev->bus) << 32; - name |= pdev->bus->number << 16; - name |= PCI_SLOT(pdev->devfn) << 8; - return name | PCI_FUNC(pdev->devfn); -} - -static u64 -nouveau_platform_name(struct platform_device *platformdev) -{ - return platformdev->id; -} - -static u64 -nouveau_name(struct drm_device *dev) -{ - if (dev_is_pci(dev->dev)) - return nouveau_pci_name(to_pci_dev(dev->dev)); - else - return nouveau_platform_name(to_platform_device(dev->dev)); -} - static inline bool nouveau_cli_work_ready(struct dma_fence *fence) { @@ -234,7 +210,6 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname, { NVIF_CLASS_VMM_NV04 , -1 }, {} }; - u64 device = nouveau_name(drm->dev); int ret; snprintf(cli->name, sizeof(cli->name), "%s", sname); @@ -246,8 +221,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname, mutex_init(&cli->lock); mutex_lock(&drm->client_mutex); - ret = nvif_client_ctor(&drm->_client, cli->name, device, - &cli->base); + ret = nvif_client_ctor(&drm->_client, cli->name, &cli->base); mutex_unlock(&drm->client_mutex); if (ret) { NV_PRINTK(err, cli, "Client allocation failed: %d\n", ret); diff --git a/drivers/gpu/drm/nouveau/nvif/client.c b/drivers/gpu/drm/nouveau/nvif/client.c index 4c4a856ab861..0211fa76431f 100644 --- a/drivers/gpu/drm/nouveau/nvif/client.c +++ b/drivers/gpu/drm/nouveau/nvif/client.c @@ -26,9 +26,7 @@ #include <nvif/driver.h> #include <nvif/driverif.h> #include <nvif/ioctl.h> - -#include <nvif/class.h> -#include <nvif/if0000.h> +#include <nvif/printf.h> int nvif_client_suspend(struct nvif_client *client) @@ -45,12 +43,6 @@ nvif_client_resume(struct nvif_client *client) void nvif_client_dtor(struct nvif_client *client) { - if (!client->impl) { - nvif_object_dtor(&client->object); - client->driver = NULL; - return; - } - client->impl->del(client->priv); client->impl = NULL; client->object.client = NULL; @@ -58,22 +50,18 @@ nvif_client_dtor(struct nvif_client *client) } int -nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device, - struct nvif_client *client) +nvif_client_ctor(struct nvif_client *parent, const char *name, struct nvif_client *client) { - struct nvif_client_v0 args = { .device = device }; int ret; - strscpy_pad(args.name, name, sizeof(args.name)); - ret = nvif_object_ctor(parent != client ? &parent->object : NULL, - name ? name : "nvifClient", 0, - NVIF_CLASS_CLIENT, &args, sizeof(args), - &client->object); + ret = parent->impl->client.new(parent->priv, &client->impl, &client->priv, + nvif_handle(&client->object)); + NVIF_ERRON(ret, &parent->object, "[NEW client]"); if (ret) return ret; - client->object.client = client; - client->object.handle = ~0; + nvif_object_ctor(&parent->object, name ?: "nvifClient", 0, 0, &client->object); + client->object.priv = client->priv; client->driver = parent->driver; return 0; } diff --git a/drivers/gpu/drm/nouveau/nvkm/core/client.c b/drivers/gpu/drm/nouveau/nvkm/core/client.c index fa8d0795805e..b57cc0d5a148 100644 --- a/drivers/gpu/drm/nouveau/nvkm/core/client.c +++ b/drivers/gpu/drm/nouveau/nvkm/core/client.c @@ -28,43 +28,25 @@ #include <nvif/class.h> #include <nvif/driverif.h> #include <nvif/event.h> -#include <nvif/if0000.h> #include <nvif/unpack.h> static int -nvkm_uclient_new(const struct nvkm_oclass *oclass, void *argv, u32 argc, - struct nvkm_object **pobject) +nvkm_client_new_client(struct nvif_client_priv *parent, + const struct nvif_client_impl **pimpl, struct nvif_client_priv **ppriv, + u64 handle) { - union { - struct nvif_client_v0 v0; - } *args = argv; struct nvkm_client *client; - int ret = -ENOSYS; - - if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))){ - args->v0.name[sizeof(args->v0.name) - 1] = 0; - ret = nvkm_client_new(args->v0.name, oclass->client->device, - oclass->client->event, &client); - if (ret) - return ret; - } else + int ret; + + ret = nvkm_client_new("client", parent->device, parent->event, &client); + if (ret) return ret; - client->object.client = oclass->client; - client->object.handle = oclass->handle; - client->object.object = oclass->object; - client->debug = oclass->client->debug; - *pobject = &client->object; - return 0; -} + *pimpl = &nvkm_client_impl; + *ppriv = client; -static const struct nvkm_sclass -nvkm_uclient_sclass = { - .oclass = NVIF_CLASS_CLIENT, - .minver = 0, - .maxver = 0, - .ctor = nvkm_uclient_new, -}; + return nvkm_object_link_rb(parent, &parent->object, handle, &client->object); +} static void nvkm_client_del(struct nvif_client_priv *client) @@ -77,6 +59,7 @@ nvkm_client_del(struct nvif_client_priv *client) const struct nvif_client_impl nvkm_client_impl = { .del = nvkm_client_del, + .client.new = nvkm_client_new_client, }; static int @@ -93,8 +76,7 @@ nvkm_client_child_get(struct nvkm_object *object, int index, const struct nvkm_sclass *sclass; switch (index) { - case 0: sclass = &nvkm_uclient_sclass; break; - case 1: sclass = &nvkm_udevice_sclass; break; + case 0: sclass = &nvkm_udevice_sclass; break; default: return -EINVAL; } @@ -120,7 +102,7 @@ int nvkm_client_new(const char *name, struct nvkm_device *device, int (*event)(u64, void *, u32), struct nvif_client_priv **pclient) { - struct nvkm_oclass oclass = { .base = nvkm_uclient_sclass }; + struct nvkm_oclass oclass = {}; struct nvkm_client *client; if (!(client = *pclient = kzalloc(sizeof(*client), GFP_KERNEL))) diff --git a/drivers/gpu/drm/nouveau/nvkm/core/object.c b/drivers/gpu/drm/nouveau/nvkm/core/object.c index 390c265cf8af..d34a8ee1a0ae 100644 --- a/drivers/gpu/drm/nouveau/nvkm/core/object.c +++ b/drivers/gpu/drm/nouveau/nvkm/core/object.c @@ -247,10 +247,15 @@ void nvkm_object_del(struct nvkm_object **pobject) { struct nvkm_object *object = *pobject; + if (object && !WARN_ON(!object->func)) { *pobject = nvkm_object_dtor(object); nvkm_object_remove(object); + + spin_lock_irq(&object->client->obj_lock); list_del(&object->head); + spin_unlock_irq(&object->client->obj_lock); + kfree(*pobject); *pobject = NULL; } @@ -298,3 +303,31 @@ nvkm_object_new(const struct nvkm_oclass *oclass, void *data, u32 size, oclass->base.func ? oclass->base.func : &nvkm_object_func; return nvkm_object_new_(func, oclass, data, size, pobject); } + +void +nvkm_object_link_(struct nvif_client_priv *client, struct nvkm_object *parent, + struct nvkm_object *object) +{ + object->client = client; + + spin_lock_irq(&client->obj_lock); + list_add_tail(&object->head, &parent->tree); + spin_unlock_irq(&client->obj_lock); +} + +int +nvkm_object_link_rb(struct nvif_client_priv *client, struct nvkm_object *parent, u64 handle, + struct nvkm_object *object) +{ + nvkm_object_link_(client, parent, object); + + object->object = handle; + + if (!nvkm_object_insert(object)) { + nvkm_object_fini(object, false); + nvkm_object_del(&object); + return -EEXIST; + } + + return 0; +} -- 2.41.0