Skip to contentSkip to conversation

drm/nouveau: misc. cleanups and removal of unused apis

PATCH Superseded Ben Skeggs 4 participants 77 messages Jul 9, 2024 – Dec 13, 2025 Page 1 of 2

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ben Skeggs

author
#0 lore raw

v2 cover drm/nouveau: misc. cleanups and removal of unused apis

This series is a smaller subset of the prior series I posted, that aimed to remove the ioctl layer between NVKM and the nouveau DRM driver.

Whilst this series doesn't go the full way, it aims to remove a bunch of internal APIs that aren't useful anymore so they don't have to be ported, and to cleanup a few paths in the DRM driver that have suffered from bit- rot over the years to ensure it's safe to remove the ioctl layer next.

There's more details of the specific changes in the relevant commits.

A git tree is available at [1], and the remaining commits that were in the prior series, but not this one, are available at [2].

v2:
- prepended a couple of patches that begin to cleanup pci vs tegra paths, addressing some comments about variable naming, more in a future series
- rebased on current drm-misc-next
- other changes mentioned in their relevant commits

[1] https://gitlab.freedesktop.org/bskeggs/nouveau/-/tree/00.00-cleanup
[2] https://gitlab.freedesktop.org/bskeggs/nouveau/-/tree/00.01-remove-ioctl

Ben Skeggs (37):
drm/nouveau: move nouveau_drm_device_fini() above init() drm/nouveau: handle pci/tegra drm_dev_{alloc,register} from common
code
drm/nouveau: replace drm_device* with nouveau_drm* as dev drvdata drm/nouveau: create pci device once
drm/nouveau: store nvkm_device pointer in nouveau_drm drm/nouveau: move allocation of root client out of nouveau_cli_init() drm/nouveau: add nouveau_cli to nouveau_abi16
drm/nouveau: handle limited nvif ioctl in abi16 drm/nouveau: remove abi16->device
drm/nouveau: remove abi16->handles
drm/nouveau/nvkm: remove detect/mmio/subdev_mask from device args drm/nouveau/nvkm: remove perfmon
drm/nouveau/nvkm: remove nvkm_client_search() drm/nouveau/nvif: remove support for userspace backends drm/nouveau/nvif: remove route/token
drm/nouveau/nvif: remove nvxx_object()
drm/nouveau/nvif: remove nvxx_client()
drm/nouveau/nvif: remove driver keep/fini drm/nouveau/nvif: remove client device arg drm/nouveau/nvif: remove client version
drm/nouveau/nvif: remove client devlist
drm/nouveau/nvif: remove client fini
drm/nouveau/nvif: remove device args
drm/nouveau: always map device
drm/nouveau/nvif: remove device rd/wr
drm/nouveau/nvif: remove disp chan rd/wr
drm/nouveau: move nvxx_* definitions to nouveau_drv.h drm/nouveau: add nvif_mmu to nouveau_drm
drm/nouveau: pass drm to nouveau_mem_new(), instead of cli drm/nouveau: pass drm to nv50_dmac_create(), rather than device+disp drm/nouveau: pass cli to nouveau_channel_new() instead of drm+device drm/nouveau: remove nouveau_chan.device
drm/nouveau: remove chan->drm
drm/nouveau: remove master
drm/nouveau: remove push pointer from nouveau_channel drm/nouveau/kms: remove a few unused struct members and fn decls drm/nouveau/kms: remove push pointer from nv50_dmac

 drivers/gpu/drm/nouveau/Kbuild                |   1 -
 drivers/gpu/drm/nouveau/dispnv04/crtc.c       |  14 +-
 drivers/gpu/drm/nouveau/dispnv04/dac.c        |   2 +-
 drivers/gpu/drm/nouveau/dispnv04/dfp.c        |   2 +-
 drivers/gpu/drm/nouveau/dispnv04/disp.c       |   7 +-
 drivers/gpu/drm/nouveau/dispnv04/disp.h       |   2 +-
 drivers/gpu/drm/nouveau/dispnv04/hw.c         |   9 +-
 drivers/gpu/drm/nouveau/dispnv04/tvnv04.c     |   4 +-
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c     |   6 +-
 drivers/gpu/drm/nouveau/dispnv50/base507c.c   |  21 +-
 drivers/gpu/drm/nouveau/dispnv50/base827c.c   |   2 +-
 drivers/gpu/drm/nouveau/dispnv50/base907c.c   |  10 +-
 drivers/gpu/drm/nouveau/dispnv50/core507d.c   |   8 +-
 drivers/gpu/drm/nouveau/dispnv50/corec37d.c   |   6 +-
 drivers/gpu/drm/nouveau/dispnv50/corec57d.c   |   2 +-
 drivers/gpu/drm/nouveau/dispnv50/crc907d.c    |   4 +-
 drivers/gpu/drm/nouveau/dispnv50/crcc37d.c    |   4 +-
 drivers/gpu/drm/nouveau/dispnv50/crcc57d.c    |   2 +-
 drivers/gpu/drm/nouveau/dispnv50/dac507d.c    |   2 +-
 drivers/gpu/drm/nouveau/dispnv50/dac907d.c    |   2 +-
 drivers/gpu/drm/nouveau/dispnv50/disp.c       |  74 +-
 drivers/gpu/drm/nouveau/dispnv50/disp.h       |  14 +-
 drivers/gpu/drm/nouveau/dispnv50/head507d.c   |  24 +-
 drivers/gpu/drm/nouveau/dispnv50/head827d.c   |  10 +-
 drivers/gpu/drm/nouveau/dispnv50/head907d.c   |  26 +-
 drivers/gpu/drm/nouveau/dispnv50/head917d.c   |   6 +-
 drivers/gpu/drm/nouveau/dispnv50/headc37d.c   |  18 +-
 drivers/gpu/drm/nouveau/dispnv50/headc57d.c   |  12 +-
 drivers/gpu/drm/nouveau/dispnv50/ovly507e.c   |   6 +-
 drivers/gpu/drm/nouveau/dispnv50/ovly827e.c   |   2 +-
 drivers/gpu/drm/nouveau/dispnv50/ovly907e.c   |   2 +-
 drivers/gpu/drm/nouveau/dispnv50/pior507d.c   |   2 +-
 drivers/gpu/drm/nouveau/dispnv50/sor507d.c    |   2 +-
 drivers/gpu/drm/nouveau/dispnv50/sor907d.c    |   2 +-
 drivers/gpu/drm/nouveau/dispnv50/sorc37d.c    |   2 +-
 drivers/gpu/drm/nouveau/dispnv50/wimmc37b.c   |   7 +-
 drivers/gpu/drm/nouveau/dispnv50/wndwc37e.c   |  24 +-
 drivers/gpu/drm/nouveau/dispnv50/wndwc57e.c   |  10 +-
 drivers/gpu/drm/nouveau/dispnv50/wndwc67e.c   |   2 +-
 drivers/gpu/drm/nouveau/include/nvif/cl0080.h |   7 -
 drivers/gpu/drm/nouveau/include/nvif/class.h  |   3 -
 drivers/gpu/drm/nouveau/include/nvif/client.h |  11 +-
 drivers/gpu/drm/nouveau/include/nvif/device.h |  37 +-
 drivers/gpu/drm/nouveau/include/nvif/driver.h |   5 -
 drivers/gpu/drm/nouveau/include/nvif/if0000.h |  10 -
 drivers/gpu/drm/nouveau/include/nvif/if0002.h |  39 -
 drivers/gpu/drm/nouveau/include/nvif/if0003.h |  34 -
 drivers/gpu/drm/nouveau/include/nvif/ioctl.h  |  27 -
 drivers/gpu/drm/nouveau/include/nvif/object.h |  26 +-
 drivers/gpu/drm/nouveau/include/nvif/os.h     |  19 +
 .../drm/nouveau/include/nvkm/core/client.h    |   1 -
 .../drm/nouveau/include/nvkm/core/device.h    |   1 -
 .../drm/nouveau/include/nvkm/core/layout.h    |   1 -
 .../drm/nouveau/include/nvkm/core/object.h    |  14 -
 .../drm/nouveau/include/nvkm/core/oclass.h    |   2 -
 .../gpu/drm/nouveau/include/nvkm/core/os.h    |  19 -
 .../gpu/drm/nouveau/include/nvkm/core/pci.h   |   1 -
 .../gpu/drm/nouveau/include/nvkm/core/tegra.h |   1 -
 .../gpu/drm/nouveau/include/nvkm/engine/pm.h  |  29 -
 drivers/gpu/drm/nouveau/nouveau_abi16.c       | 321 +++++--
 drivers/gpu/drm/nouveau/nouveau_abi16.h       |   6 +-
 drivers/gpu/drm/nouveau/nouveau_bios.c        |   4 +-
 drivers/gpu/drm/nouveau/nouveau_bios.h        |   1 +
 drivers/gpu/drm/nouveau/nouveau_bo.c          |  10 +-
 drivers/gpu/drm/nouveau/nouveau_bo0039.c      |   6 +-
 drivers/gpu/drm/nouveau/nouveau_bo5039.c      |   6 +-
 drivers/gpu/drm/nouveau/nouveau_bo74c1.c      |   2 +-
 drivers/gpu/drm/nouveau/nouveau_bo85b5.c      |   2 +-
 drivers/gpu/drm/nouveau/nouveau_bo9039.c      |   4 +-
 drivers/gpu/drm/nouveau/nouveau_bo90b5.c      |   2 +-
 drivers/gpu/drm/nouveau/nouveau_boa0b5.c      |   4 +-
 drivers/gpu/drm/nouveau/nouveau_chan.c        |  96 +-
 drivers/gpu/drm/nouveau/nouveau_chan.h        |   8 +-
 drivers/gpu/drm/nouveau/nouveau_display.c     |   4 +-
 drivers/gpu/drm/nouveau/nouveau_display.h     |   2 +-
 drivers/gpu/drm/nouveau/nouveau_dma.c         |   2 +-
 drivers/gpu/drm/nouveau/nouveau_dmem.c        |   4 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c         | 395 ++++----
 drivers/gpu/drm/nouveau/nouveau_drv.h         |  51 +-
 drivers/gpu/drm/nouveau/nouveau_fence.c       |  17 +-
 drivers/gpu/drm/nouveau/nouveau_gem.c         |  21 +-
 drivers/gpu/drm/nouveau/nouveau_hwmon.c       |  46 +-
 drivers/gpu/drm/nouveau/nouveau_led.c         |   2 +-
 drivers/gpu/drm/nouveau/nouveau_mem.c         |  38 +-
 drivers/gpu/drm/nouveau/nouveau_mem.h         |   4 +-
 drivers/gpu/drm/nouveau/nouveau_nvif.c        |   2 -
 drivers/gpu/drm/nouveau/nouveau_platform.c    |  11 +-
 drivers/gpu/drm/nouveau/nouveau_sgdma.c       |   2 +-
 drivers/gpu/drm/nouveau/nouveau_ttm.c         |  12 +-
 drivers/gpu/drm/nouveau/nouveau_usif.c        | 194 ----
 drivers/gpu/drm/nouveau/nouveau_usif.h        |  10 -
 drivers/gpu/drm/nouveau/nouveau_vga.c         |  14 +-
 drivers/gpu/drm/nouveau/nv04_fence.c          |   2 +-
 drivers/gpu/drm/nouveau/nv10_fence.c          |   2 +-
 drivers/gpu/drm/nouveau/nv17_fence.c          |  10 +-
 drivers/gpu/drm/nouveau/nv50_fence.c          |   2 +-
 drivers/gpu/drm/nouveau/nv84_fence.c          |  12 +-
 drivers/gpu/drm/nouveau/nvc0_fence.c          |   4 +-
 drivers/gpu/drm/nouveau/nvif/client.c         |  32 +-
 drivers/gpu/drm/nouveau/nvif/device.c         |  15 +-
 drivers/gpu/drm/nouveau/nvif/driver.c         |  32 +-
 drivers/gpu/drm/nouveau/nvif/object.c         |  40 -
 drivers/gpu/drm/nouveau/nvkm/core/client.c    |  64 +-
 drivers/gpu/drm/nouveau/nvkm/core/ioctl.c     |  91 +-
 drivers/gpu/drm/nouveau/nvkm/core/object.c    |  50 -
 drivers/gpu/drm/nouveau/nvkm/core/oproxy.c    |  42 -
 drivers/gpu/drm/nouveau/nvkm/core/uevent.c    |   4 +-
 drivers/gpu/drm/nouveau/nvkm/engine/Kbuild    |   1 -
 .../gpu/drm/nouveau/nvkm/engine/device/base.c | 479 +++++-----
 .../gpu/drm/nouveau/nvkm/engine/device/pci.c  |   4 +-
 .../gpu/drm/nouveau/nvkm/engine/device/priv.h |   2 -
 .../drm/nouveau/nvkm/engine/device/tegra.c    |   5 +-
 .../gpu/drm/nouveau/nvkm/engine/device/user.c |  93 +-
 .../gpu/drm/nouveau/nvkm/engine/disp/chan.c   |  24 -
 drivers/gpu/drm/nouveau/nvkm/engine/pm/Kbuild |  11 -
 drivers/gpu/drm/nouveau/nvkm/engine/pm/base.c | 867 ------------------
 drivers/gpu/drm/nouveau/nvkm/engine/pm/g84.c  | 165 ----
 .../gpu/drm/nouveau/nvkm/engine/pm/gf100.c    | 243 -----
 .../gpu/drm/nouveau/nvkm/engine/pm/gf100.h    |  20 -
 .../gpu/drm/nouveau/nvkm/engine/pm/gf108.c    |  66 --
 .../gpu/drm/nouveau/nvkm/engine/pm/gf117.c    |  80 --
 .../gpu/drm/nouveau/nvkm/engine/pm/gk104.c    | 184 ----
 .../gpu/drm/nouveau/nvkm/engine/pm/gt200.c    | 157 ----
 .../gpu/drm/nouveau/nvkm/engine/pm/gt215.c    | 138 ---
 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv40.c | 123 ---
 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv40.h |  15 -
 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv50.c | 175 ----
 drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h | 105 ---
 128 files changed, 1105 insertions(+), 4199 deletions(-)
 delete mode 100644 drivers/gpu/drm/nouveau/include/nvif/if0002.h
 delete mode 100644 drivers/gpu/drm/nouveau/include/nvif/if0003.h
 delete mode 100644 drivers/gpu/drm/nouveau/include/nvkm/engine/pm.h
 delete mode 100644 drivers/gpu/drm/nouveau/nouveau_usif.c
 delete mode 100644 drivers/gpu/drm/nouveau/nouveau_usif.h
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/Kbuild
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/base.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/g84.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gf100.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gf100.h
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gf108.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gf117.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gk104.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gt200.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gt215.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv40.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv40.h
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv50.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h
Signature · 1 line
2.45.1
author
#1 lore raw

PATCH v2 1/37 drm/nouveau: move nouveau_drm_device_fini() above init()

The next commit wants to be able to call fini() from an init() failure path to remove the need to duplicate a bunch of cleanup.

Moving fini() above init() avoids the need for a forward-declaration.

---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 106 +++++++++++++-------------
 1 file changed, 53 insertions(+), 53 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +53 -53
index a58c31089613..eae48c87e3d5 100644
@@ -578,6 +578,59 @@ nouveau_parent = {
 	.errorf = nouveau_drm_errorf,
 };
 
+static void
+nouveau_drm_device_fini(struct drm_device *dev)
+{
+	struct nouveau_cli *cli, *temp_cli;
+	struct nouveau_drm *drm = nouveau_drm(dev);
+
+	if (nouveau_pmops_runtime()) {
+		pm_runtime_get_sync(dev->dev);
+		pm_runtime_forbid(dev->dev);
+	}
+
+	nouveau_led_fini(dev);
+	nouveau_dmem_fini(drm);
+	nouveau_svm_fini(drm);
+	nouveau_hwmon_fini(dev);
+	nouveau_debugfs_fini(drm);
+
+	if (dev->mode_config.num_crtc)
+		nouveau_display_fini(dev, false, false);
+	nouveau_display_destroy(dev);
+
+	nouveau_accel_fini(drm);
+	nouveau_bios_takedown(dev);
+
+	nouveau_ttm_fini(drm);
+	nouveau_vga_fini(drm);
+
+	/*
+	 * There may be existing clients from as-yet unclosed files. For now,
+	 * clean them up here rather than deferring until the file is closed,
+	 * but this likely not correct if we want to support hot-unplugging
+	 * properly.
+	 */
+	mutex_lock(&drm->clients_lock);
+	list_for_each_entry_safe(cli, temp_cli, &drm->clients, head) {
+		list_del(&cli->head);
+		mutex_lock(&cli->mutex);
+		if (cli->abi16)
+			nouveau_abi16_fini(cli->abi16);
+		mutex_unlock(&cli->mutex);
+		nouveau_cli_fini(cli);
+		kfree(cli);
+	}
+	mutex_unlock(&drm->clients_lock);
+
+	nouveau_cli_fini(&drm->client);
+	nouveau_cli_fini(&drm->master);
+	destroy_workqueue(drm->sched_wq);
+	nvif_parent_dtor(&drm->parent);
+	mutex_destroy(&drm->clients_lock);
+	kfree(drm);
+}
+
 static int
 nouveau_drm_device_init(struct drm_device *dev)
 {
@@ -679,59 +732,6 @@ nouveau_drm_device_init(struct drm_device *dev)
 	return ret;
 }
 
-static void
-nouveau_drm_device_fini(struct drm_device *dev)
-{
-	struct nouveau_cli *cli, *temp_cli;
-	struct nouveau_drm *drm = nouveau_drm(dev);
-
-	if (nouveau_pmops_runtime()) {
-		pm_runtime_get_sync(dev->dev);
-		pm_runtime_forbid(dev->dev);
-	}
-
-	nouveau_led_fini(dev);
-	nouveau_dmem_fini(drm);
-	nouveau_svm_fini(drm);
-	nouveau_hwmon_fini(dev);
-	nouveau_debugfs_fini(drm);
-
-	if (dev->mode_config.num_crtc)
-		nouveau_display_fini(dev, false, false);
-	nouveau_display_destroy(dev);
-
-	nouveau_accel_fini(drm);
-	nouveau_bios_takedown(dev);
-
-	nouveau_ttm_fini(drm);
-	nouveau_vga_fini(drm);
-
-	/*
-	 * There may be existing clients from as-yet unclosed files. For now,
-	 * clean them up here rather than deferring until the file is closed,
-	 * but this likely not correct if we want to support hot-unplugging
-	 * properly.
-	 */
-	mutex_lock(&drm->clients_lock);
-	list_for_each_entry_safe(cli, temp_cli, &drm->clients, head) {
-		list_del(&cli->head);
-		mutex_lock(&cli->mutex);
-		if (cli->abi16)
-			nouveau_abi16_fini(cli->abi16);
-		mutex_unlock(&cli->mutex);
-		nouveau_cli_fini(cli);
-		kfree(cli);
-	}
-	mutex_unlock(&drm->clients_lock);
-
-	nouveau_cli_fini(&drm->client);
-	nouveau_cli_fini(&drm->master);
-	destroy_workqueue(drm->sched_wq);
-	nvif_parent_dtor(&drm->parent);
-	mutex_destroy(&drm->clients_lock);
-	kfree(drm);
-}
-
 /*
  * On some Intel PCIe bridge controllers doing a
  * D0 -> D3hot -> D3cold -> D0 sequence causes Nvidia GPUs to not reappear.
Signature · 1 line
2.45.1
#2 lore raw

Re: [PATCH v2 01/37] drm/nouveau: move nouveau_drm_device_fini() above init()

Quoted 4 lines · Ben Skeggs

The next commit wants to be able to call fini() from an init() failure path to remove the need to duplicate a bunch of cleanup.

Moving fini() above init() avoids the need for a forward-declaration.

Hm, I don't really like that this makes git-blame less useful for this function, moving it up is clearly cleaner though - your call.

Quoted 133 lines
---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 106 +++++++++++++-------------
 1 file changed, 53 insertions(+), 53 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +53 -53
index a58c31089613..eae48c87e3d5 100644
@@ -578,6 +578,59 @@ nouveau_parent = {
 	.errorf = nouveau_drm_errorf,
 };
 
+static void
+nouveau_drm_device_fini(struct drm_device *dev)
+{
+	struct nouveau_cli *cli, *temp_cli;
+	struct nouveau_drm *drm = nouveau_drm(dev);
+
+	if (nouveau_pmops_runtime()) {
+		pm_runtime_get_sync(dev->dev);
+		pm_runtime_forbid(dev->dev);
+	}
+
+	nouveau_led_fini(dev);
+	nouveau_dmem_fini(drm);
+	nouveau_svm_fini(drm);
+	nouveau_hwmon_fini(dev);
+	nouveau_debugfs_fini(drm);
+
+	if (dev->mode_config.num_crtc)
+		nouveau_display_fini(dev, false, false);
+	nouveau_display_destroy(dev);
+
+	nouveau_accel_fini(drm);
+	nouveau_bios_takedown(dev);
+
+	nouveau_ttm_fini(drm);
+	nouveau_vga_fini(drm);
+
+	/*
+	 * There may be existing clients from as-yet unclosed files. For now,
+	 * clean them up here rather than deferring until the file is closed,
+	 * but this likely not correct if we want to support hot-unplugging
+	 * properly.
+	 */
+	mutex_lock(&drm->clients_lock);
+	list_for_each_entry_safe(cli, temp_cli, &drm->clients, head) {
+		list_del(&cli->head);
+		mutex_lock(&cli->mutex);
+		if (cli->abi16)
+			nouveau_abi16_fini(cli->abi16);
+		mutex_unlock(&cli->mutex);
+		nouveau_cli_fini(cli);
+		kfree(cli);
+	}
+	mutex_unlock(&drm->clients_lock);
+
+	nouveau_cli_fini(&drm->client);
+	nouveau_cli_fini(&drm->master);
+	destroy_workqueue(drm->sched_wq);
+	nvif_parent_dtor(&drm->parent);
+	mutex_destroy(&drm->clients_lock);
+	kfree(drm);
+}
+
 static int
 nouveau_drm_device_init(struct drm_device *dev)
 {
@@ -679,59 +732,6 @@ nouveau_drm_device_init(struct drm_device *dev)
 	return ret;
 }
 
-static void
-nouveau_drm_device_fini(struct drm_device *dev)
-{
-	struct nouveau_cli *cli, *temp_cli;
-	struct nouveau_drm *drm = nouveau_drm(dev);
-
-	if (nouveau_pmops_runtime()) {
-		pm_runtime_get_sync(dev->dev);
-		pm_runtime_forbid(dev->dev);
-	}
-
-	nouveau_led_fini(dev);
-	nouveau_dmem_fini(drm);
-	nouveau_svm_fini(drm);
-	nouveau_hwmon_fini(dev);
-	nouveau_debugfs_fini(drm);
-
-	if (dev->mode_config.num_crtc)
-		nouveau_display_fini(dev, false, false);
-	nouveau_display_destroy(dev);
-
-	nouveau_accel_fini(drm);
-	nouveau_bios_takedown(dev);
-
-	nouveau_ttm_fini(drm);
-	nouveau_vga_fini(drm);
-
-	/*
-	 * There may be existing clients from as-yet unclosed files. For now,
-	 * clean them up here rather than deferring until the file is closed,
-	 * but this likely not correct if we want to support hot-unplugging
-	 * properly.
-	 */
-	mutex_lock(&drm->clients_lock);
-	list_for_each_entry_safe(cli, temp_cli, &drm->clients, head) {
-		list_del(&cli->head);
-		mutex_lock(&cli->mutex);
-		if (cli->abi16)
-			nouveau_abi16_fini(cli->abi16);
-		mutex_unlock(&cli->mutex);
-		nouveau_cli_fini(cli);
-		kfree(cli);
-	}
-	mutex_unlock(&drm->clients_lock);
-
-	nouveau_cli_fini(&drm->client);
-	nouveau_cli_fini(&drm->master);
-	destroy_workqueue(drm->sched_wq);
-	nvif_parent_dtor(&drm->parent);
-	mutex_destroy(&drm->clients_lock);
-	kfree(drm);
-}
-
 /*
  * On some Intel PCIe bridge controllers doing a
  * D0 -> D3hot -> D3cold -> D0 sequence causes Nvidia GPUs to not reappear.
Signature · 1 line
2.45.1
author
#3 lore raw

PATCH v2 2/37 drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

In reply to Ben Skeggs

The next commit will change the pointer we store via dev_set_drvdata() to allow simplifying the code using it.

Here we want to unify some more of the PCI/Tegra DRM driver init, both as a general cleanup, and to enable the dev_set_drvdata() change to be made in a single place.

---
 drivers/gpu/drm/nouveau/nouveau_drm.c      | 93 ++++++++++++++--------
 drivers/gpu/drm/nouveau/nouveau_platform.c |  6 --
 2 files changed, 60 insertions(+), 39 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +60 -33
index eae48c87e3d5..9beff8737617 100644
@@ -628,20 +628,14 @@ nouveau_drm_device_fini(struct drm_device *dev)
 	destroy_workqueue(drm->sched_wq);
 	nvif_parent_dtor(&drm->parent);
 	mutex_destroy(&drm->clients_lock);
-	kfree(drm);
 }
 
 static int
-nouveau_drm_device_init(struct drm_device *dev)
+nouveau_drm_device_init(struct nouveau_drm *drm)
 {
-	struct nouveau_drm *drm;
+	struct drm_device *dev = drm->dev;
 	int ret;
 
-	if (!(drm = kzalloc(sizeof(*drm), GFP_KERNEL)))
-		return -ENOMEM;
-	dev->dev_private = drm;
-	drm->dev = dev;
-
 	nvif_parent_ctor(&nouveau_parent, &drm->parent);
 	drm->master.base.object.parent = &drm->parent;
 
@@ -711,6 +705,12 @@ nouveau_drm_device_init(struct drm_device *dev)
 		pm_runtime_put(dev->dev);
 	}
 
+	ret = drm_dev_register(drm->dev, 0);
+	if (ret) {
+		nouveau_drm_device_fini(drm->dev);
+		return ret;
+	}
+
 	return 0;
 fail_dispinit:
 	nouveau_display_destroy(dev);
@@ -728,10 +728,47 @@ nouveau_drm_device_init(struct drm_device *dev)
 	destroy_workqueue(drm->sched_wq);
 fail_alloc:
 	nvif_parent_dtor(&drm->parent);
-	kfree(drm);
 	return ret;
 }
 
+static void
+nouveau_drm_device_del(struct nouveau_drm *drm)
+{
+	if (drm->dev)
+		drm_dev_put(drm->dev);
+
+	kfree(drm);
+}
+
+static struct nouveau_drm *
+nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,
+		       struct nvkm_device *device)
+{
+	struct nouveau_drm *drm;
+	int ret;
+
+	drm = kzalloc(sizeof(*drm), GFP_KERNEL);
+	if (!drm)
+		return ERR_PTR(-ENOMEM);
+
+	drm->dev = drm_dev_alloc(drm_driver, parent);
+	if (IS_ERR(drm->dev)) {
+		ret = PTR_ERR(drm->dev);
+		goto done;
+	}
+
+	drm->dev->dev_private = drm;
+	dev_set_drvdata(parent, drm->dev);
+
+done:
+	if (ret) {
+		nouveau_drm_device_del(drm);
+		drm = NULL;
+	}
+
+	return ret ? ERR_PTR(ret) : drm;
+}
+
 /*
  * On some Intel PCIe bridge controllers doing a
  * D0 -> D3hot -> D3cold -> D0 sequence causes Nvidia GPUs to not reappear.
@@ -794,7 +831,7 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 			     const struct pci_device_id *pent)
 {
 	struct nvkm_device *device;
-	struct drm_device *drm_dev;
+	struct nouveau_drm *drm;
 	int ret;
 
 	if (vga_switcheroo_client_probe_defer(pdev))
@@ -825,9 +862,9 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 	if (nouveau_atomic)
 		driver_pci.driver_features |= DRIVER_ATOMIC;
 
-	drm_dev = drm_dev_alloc(&driver_pci, &pdev->dev);
-	if (IS_ERR(drm_dev)) {
-		ret = PTR_ERR(drm_dev);
+	drm = nouveau_drm_device_new(&driver_pci, &pdev->dev, device);
+	if (IS_ERR(drm)) {
+		ret = PTR_ERR(drm);
 		goto fail_nvkm;
 	}
 
@@ -835,30 +872,22 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 	if (ret)
 		goto fail_drm;
 
-	pci_set_drvdata(pdev, drm_dev);
-
-	ret = nouveau_drm_device_init(drm_dev);
+	ret = nouveau_drm_device_init(drm);
 	if (ret)
 		goto fail_pci;
 
-	ret = drm_dev_register(drm_dev, pent->driver_data);
-	if (ret)
-		goto fail_drm_dev_init;
-
-	if (nouveau_drm(drm_dev)->client.device.info.ram_size <= 32 * 1024 * 1024)
-		drm_fbdev_ttm_setup(drm_dev, 8);
+	if (drm->client.device.info.ram_size <= 32 * 1024 * 1024)
+		drm_fbdev_ttm_setup(drm->dev, 8);
 	else
-		drm_fbdev_ttm_setup(drm_dev, 32);
+		drm_fbdev_ttm_setup(drm->dev, 32);
 
 	quirk_broken_nv_runpm(pdev);
 	return 0;
 
-fail_drm_dev_init:
-	nouveau_drm_device_fini(drm_dev);
 fail_pci:
 	pci_disable_device(pdev);
 fail_drm:
-	drm_dev_put(drm_dev);
+	nouveau_drm_device_del(drm);
 fail_nvkm:
 	nvkm_device_del(&device);
 	return ret;
@@ -877,7 +906,7 @@ nouveau_drm_device_remove(struct drm_device *dev)
 	device = nvkm_device_find(client->device);
 
 	nouveau_drm_device_fini(dev);
-	drm_dev_put(dev);
+	nouveau_drm_device_del(drm);
 	nvkm_device_del(&device);
 }
 
@@ -1369,7 +1398,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
 			       struct platform_device *pdev,
 			       struct nvkm_device **pdevice)
 {
-	struct drm_device *drm;
+	struct nouveau_drm *drm;
 	int err;
 
 	err = nvkm_device_tegra_new(func, pdev, nouveau_config, nouveau_debug,
@@ -1377,7 +1406,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
 	if (err)
 		goto err_free;
 
-	drm = drm_dev_alloc(&driver_platform, &pdev->dev);
+	drm = nouveau_drm_device_new(&driver_platform, &pdev->dev, *pdevice);
 	if (IS_ERR(drm)) {
 		err = PTR_ERR(drm);
 		goto err_free;
@@ -1387,12 +1416,10 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
 	if (err)
 		goto err_put;
 
-	platform_set_drvdata(pdev, drm);
-
-	return drm;
+	return drm->dev;
 
 err_put:
-	drm_dev_put(drm);
+	nouveau_drm_device_del(drm);
 err_free:
 	nvkm_device_del(pdevice);
 
drivers/gpu/drm/nouveau/nouveau_platform.c +0 -6
index bf2dc7567ea4..d0a63f0f54a2 100644
@@ -34,12 +34,6 @@ static int nouveau_platform_probe(struct platform_device *pdev)
 	if (IS_ERR(drm))
 		return PTR_ERR(drm);
 
-	ret = drm_dev_register(drm, 0);
-	if (ret < 0) {
-		drm_dev_put(drm);
-		return ret;
-	}
-
 	return 0;
 }
 
Signature · 1 line
2.45.1
#4 lore raw

Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

Quoted 2 lines · Ben Skeggs

The next commit will change the pointer we store via dev_set_drvdata() to allow simplifying the code using it.

Please don't use future tense, e.g "In subsequent commits, the pointer we store [...]". Also, when you mention that something is changes (such as the pointer type here), it probably makes sense to mention what it is changed to instead.

Quoted 4 lines

Here we want to unify some more of the PCI/Tegra DRM driver init, both as a general cleanup, and to enable the dev_set_drvdata() change to be made in a single place.

In this case I think it makes sense to switch things up. First mention what the commit does and why, i.e. "Unify some more of the PCI/Tegra DRM driver init [...]" and then mention that the actual change to the pointer stored in a device' drvdata in done in a subsequent commit.

Quoted 66 lines
---
 drivers/gpu/drm/nouveau/nouveau_drm.c      | 93 ++++++++++++++--------
 drivers/gpu/drm/nouveau/nouveau_platform.c |  6 --
 2 files changed, 60 insertions(+), 39 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +19 -9
index eae48c87e3d5..9beff8737617 100644
@@ -628,20 +628,14 @@ nouveau_drm_device_fini(struct drm_device *dev)
 	destroy_workqueue(drm->sched_wq);
 	nvif_parent_dtor(&drm->parent);
 	mutex_destroy(&drm->clients_lock);
-	kfree(drm);
 }
 
 static int
-nouveau_drm_device_init(struct drm_device *dev)
+nouveau_drm_device_init(struct nouveau_drm *drm)
 {
-	struct nouveau_drm *drm;
+	struct drm_device *dev = drm->dev;
 	int ret;
 
-	if (!(drm = kzalloc(sizeof(*drm), GFP_KERNEL)))
-		return -ENOMEM;
-	dev->dev_private = drm;
-	drm->dev = dev;
-
 	nvif_parent_ctor(&nouveau_parent, &drm->parent);
 	drm->master.base.object.parent = &drm->parent;
 
@@ -711,6 +705,12 @@ nouveau_drm_device_init(struct drm_device *dev)
 		pm_runtime_put(dev->dev);
 	}
 
+	ret = drm_dev_register(drm->dev, 0);
+	if (ret) {
+		nouveau_drm_device_fini(drm->dev);
+		return ret;
+	}
+
 	return 0;
 fail_dispinit:
 	nouveau_display_destroy(dev);
@@ -728,10 +728,47 @@ nouveau_drm_device_init(struct drm_device *dev)
 	destroy_workqueue(drm->sched_wq);
 fail_alloc:
 	nvif_parent_dtor(&drm->parent);
-	kfree(drm);
 	return ret;
 }
 
+static void
+nouveau_drm_device_del(struct nouveau_drm *drm)
+{
+	if (drm->dev)
+		drm_dev_put(drm->dev);
+
+	kfree(drm);
+}
+
+static struct nouveau_drm *
+nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_drm_device_init(struct drm_device *dev) · line 754

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +10 -0
+		       struct nvkm_device *device)
+{
+	struct nouveau_drm *drm;
+	int ret;
+
+	drm = kzalloc(sizeof(*drm), GFP_KERNEL);
+	if (!drm)
+		return ERR_PTR(-ENOMEM);
+
+	drm->dev = drm_dev_alloc(drm_driver, parent);

Since you're reworking this anyways, can we switch to devm_drm_dev_alloc()?

This also gets us rid of nouveau_drm_device_del().

Quoted 140 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +31 -24
+	if (IS_ERR(drm->dev)) {
+		ret = PTR_ERR(drm->dev);
+		goto done;
+	}
+
+	drm->dev->dev_private = drm;
+	dev_set_drvdata(parent, drm->dev);
+
+done:
+	if (ret) {
+		nouveau_drm_device_del(drm);
+		drm = NULL;
+	}
+
+	return ret ? ERR_PTR(ret) : drm;
+}
+
 /*
  * On some Intel PCIe bridge controllers doing a
  * D0 -> D3hot -> D3cold -> D0 sequence causes Nvidia GPUs to not reappear.
@@ -794,7 +831,7 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 			     const struct pci_device_id *pent)
 {
 	struct nvkm_device *device;
-	struct drm_device *drm_dev;
+	struct nouveau_drm *drm;
 	int ret;
 
 	if (vga_switcheroo_client_probe_defer(pdev))
@@ -825,9 +862,9 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 	if (nouveau_atomic)
 		driver_pci.driver_features |= DRIVER_ATOMIC;
 
-	drm_dev = drm_dev_alloc(&driver_pci, &pdev->dev);
-	if (IS_ERR(drm_dev)) {
-		ret = PTR_ERR(drm_dev);
+	drm = nouveau_drm_device_new(&driver_pci, &pdev->dev, device);
+	if (IS_ERR(drm)) {
+		ret = PTR_ERR(drm);
 		goto fail_nvkm;
 	}
 
@@ -835,30 +872,22 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 	if (ret)
 		goto fail_drm;
 
-	pci_set_drvdata(pdev, drm_dev);
-
-	ret = nouveau_drm_device_init(drm_dev);
+	ret = nouveau_drm_device_init(drm);
 	if (ret)
 		goto fail_pci;
 
-	ret = drm_dev_register(drm_dev, pent->driver_data);
-	if (ret)
-		goto fail_drm_dev_init;
-
-	if (nouveau_drm(drm_dev)->client.device.info.ram_size <= 32 * 1024 * 1024)
-		drm_fbdev_ttm_setup(drm_dev, 8);
+	if (drm->client.device.info.ram_size <= 32 * 1024 * 1024)
+		drm_fbdev_ttm_setup(drm->dev, 8);
 	else
-		drm_fbdev_ttm_setup(drm_dev, 32);
+		drm_fbdev_ttm_setup(drm->dev, 32);
 
 	quirk_broken_nv_runpm(pdev);
 	return 0;
 
-fail_drm_dev_init:
-	nouveau_drm_device_fini(drm_dev);
 fail_pci:
 	pci_disable_device(pdev);
 fail_drm:
-	drm_dev_put(drm_dev);
+	nouveau_drm_device_del(drm);
 fail_nvkm:
 	nvkm_device_del(&device);
 	return ret;
@@ -877,7 +906,7 @@ nouveau_drm_device_remove(struct drm_device *dev)
 	device = nvkm_device_find(client->device);
 
 	nouveau_drm_device_fini(dev);
-	drm_dev_put(dev);
+	nouveau_drm_device_del(drm);
 	nvkm_device_del(&device);
 }
 
@@ -1369,7 +1398,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
 			       struct platform_device *pdev,
 			       struct nvkm_device **pdevice)
 {
-	struct drm_device *drm;
+	struct nouveau_drm *drm;
 	int err;
 
 	err = nvkm_device_tegra_new(func, pdev, nouveau_config, nouveau_debug,
@@ -1377,7 +1406,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
 	if (err)
 		goto err_free;
 
-	drm = drm_dev_alloc(&driver_platform, &pdev->dev);
+	drm = nouveau_drm_device_new(&driver_platform, &pdev->dev, *pdevice);
 	if (IS_ERR(drm)) {
 		err = PTR_ERR(drm);
 		goto err_free;
@@ -1387,12 +1416,10 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
 	if (err)
 		goto err_put;
 
-	platform_set_drvdata(pdev, drm);
-
-	return drm;
+	return drm->dev;
 
 err_put:
-	drm_dev_put(drm);
+	nouveau_drm_device_del(drm);
 err_free:
 	nvkm_device_del(pdevice);
 
drivers/gpu/drm/nouveau/nouveau_platform.c +0 -6
index bf2dc7567ea4..d0a63f0f54a2 100644
@@ -34,12 +34,6 @@ static int nouveau_platform_probe(struct platform_device *pdev)
 	if (IS_ERR(drm))
 		return PTR_ERR(drm);
 
-	ret = drm_dev_register(drm, 0);
-	if (ret < 0) {
-		drm_dev_put(drm);
-		return ret;
-	}
-
 	return 0;
 }
 
Signature · 1 line
2.45.1
author
#5 lore raw

Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

Quoted 7 lines · Danilo Krummrich
Quoted 2 lines · Ben Skeggs

The next commit will change the pointer we store via dev_set_drvdata() to allow simplifying the code using it.

Please don't use future tense, e.g "In subsequent commits, the pointer we store [...]". Also, when you mention that something is changes (such as the pointer type here), it probably makes sense to mention what it is changed to instead.

Quoted 7 lines
Quoted 3 lines

Here we want to unify some more of the PCI/Tegra DRM driver init, both as a general cleanup, and to enable the dev_set_drvdata() change to be made in a single place.

In this case I think it makes sense to switch things up. First mention what the commit does and why, i.e. "Unify some more of the PCI/Tegra DRM driver init [...]" and then mention that the actual change to the pointer stored in a device' drvdata in done in a subsequent commit.

I've reworded the commit message.

Quoted 78 lines
Quoted 66 lines
---
  drivers/gpu/drm/nouveau/nouveau_drm.c      | 93 ++++++++++++++--------
  drivers/gpu/drm/nouveau/nouveau_platform.c |  6 --
  2 files changed, 60 insertions(+), 39 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +19 -9
index eae48c87e3d5..9beff8737617 100644
@@ -628,20 +628,14 @@ nouveau_drm_device_fini(struct drm_device *dev)
  	destroy_workqueue(drm->sched_wq);
  	nvif_parent_dtor(&drm->parent);
  	mutex_destroy(&drm->clients_lock);
-	kfree(drm);
  }
 
  static int
-nouveau_drm_device_init(struct drm_device *dev)
+nouveau_drm_device_init(struct nouveau_drm *drm)
  {
-	struct nouveau_drm *drm;
+	struct drm_device *dev = drm->dev;
  	int ret;
 
-	if (!(drm = kzalloc(sizeof(*drm), GFP_KERNEL)))
-		return -ENOMEM;
-	dev->dev_private = drm;
-	drm->dev = dev;
-
  	nvif_parent_ctor(&nouveau_parent, &drm->parent);
  	drm->master.base.object.parent = &drm->parent;
 
@@ -711,6 +705,12 @@ nouveau_drm_device_init(struct drm_device *dev)
  		pm_runtime_put(dev->dev);
  	}
 
+	ret = drm_dev_register(drm->dev, 0);
+	if (ret) {
+		nouveau_drm_device_fini(drm->dev);
+		return ret;
+	}
+
  	return 0;
  fail_dispinit:
  	nouveau_display_destroy(dev);
@@ -728,10 +728,47 @@ nouveau_drm_device_init(struct drm_device *dev)
  	destroy_workqueue(drm->sched_wq);
  fail_alloc:
  	nvif_parent_dtor(&drm->parent);
-	kfree(drm);
  	return ret;
  }
 
+static void
+nouveau_drm_device_del(struct nouveau_drm *drm)
+{
+	if (drm->dev)
+		drm_dev_put(drm->dev);
+
+	kfree(drm);
+}
+
+static struct nouveau_drm *
+nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_drm_device_init(struct drm_device *dev) · line 754

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +10 -0
+		       struct nvkm_device *device)
+{
+	struct nouveau_drm *drm;
+	int ret;
+
+	drm = kzalloc(sizeof(*drm), GFP_KERNEL);
+	if (!drm)
+		return ERR_PTR(-ENOMEM);
+
+	drm->dev = drm_dev_alloc(drm_driver, parent);

Since you're reworking this anyways, can we switch to devm_drm_dev_alloc()?

Quoted 1 line

This also gets us rid of nouveau_drm_device_del().

No, we can't.  I originally had this change as a cleanup patch in the series I posted implementing aux bus support.  However it turns out that in order to avoid breaking udev etc, we can't use the aux device as parent of the drm device and instead have to continue passing the pci/platform device as we do now.

Using devm_drm_dev_alloc() with the pci device as parent would tie the lifetime of the drm device to the pci device, which is owned by nvkm (after the auxdev series).  We could look at changing devm_drm_dev_alloc() of course, but I think that's best left until later.

Quoted 141 lines
Quoted 141 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +31 -24
+	if (IS_ERR(drm->dev)) {
+		ret = PTR_ERR(drm->dev);
+		goto done;
+	}
+
+	drm->dev->dev_private = drm;
+	dev_set_drvdata(parent, drm->dev);
+
+done:
+	if (ret) {
+		nouveau_drm_device_del(drm);
+		drm = NULL;
+	}
+
+	return ret ? ERR_PTR(ret) : drm;
+}
+
  /*
   * On some Intel PCIe bridge controllers doing a
   * D0 -> D3hot -> D3cold -> D0 sequence causes Nvidia GPUs to not reappear.
@@ -794,7 +831,7 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
  			     const struct pci_device_id *pent)
  {
  	struct nvkm_device *device;
-	struct drm_device *drm_dev;
+	struct nouveau_drm *drm;
  	int ret;
 
  	if (vga_switcheroo_client_probe_defer(pdev))
@@ -825,9 +862,9 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
  	if (nouveau_atomic)
  		driver_pci.driver_features |= DRIVER_ATOMIC;
 
-	drm_dev = drm_dev_alloc(&driver_pci, &pdev->dev);
-	if (IS_ERR(drm_dev)) {
-		ret = PTR_ERR(drm_dev);
+	drm = nouveau_drm_device_new(&driver_pci, &pdev->dev, device);
+	if (IS_ERR(drm)) {
+		ret = PTR_ERR(drm);
  		goto fail_nvkm;
  	}
 
@@ -835,30 +872,22 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
  	if (ret)
  		goto fail_drm;
 
-	pci_set_drvdata(pdev, drm_dev);
-
-	ret = nouveau_drm_device_init(drm_dev);
+	ret = nouveau_drm_device_init(drm);
  	if (ret)
  		goto fail_pci;
 
-	ret = drm_dev_register(drm_dev, pent->driver_data);
-	if (ret)
-		goto fail_drm_dev_init;
-
-	if (nouveau_drm(drm_dev)->client.device.info.ram_size <= 32 * 1024 * 1024)
-		drm_fbdev_ttm_setup(drm_dev, 8);
+	if (drm->client.device.info.ram_size <= 32 * 1024 * 1024)
+		drm_fbdev_ttm_setup(drm->dev, 8);
  	else
-		drm_fbdev_ttm_setup(drm_dev, 32);
+		drm_fbdev_ttm_setup(drm->dev, 32);
 
  	quirk_broken_nv_runpm(pdev);
  	return 0;
 
-fail_drm_dev_init:
-	nouveau_drm_device_fini(drm_dev);
  fail_pci:
  	pci_disable_device(pdev);
  fail_drm:
-	drm_dev_put(drm_dev);
+	nouveau_drm_device_del(drm);
  fail_nvkm:
  	nvkm_device_del(&device);
  	return ret;
@@ -877,7 +906,7 @@ nouveau_drm_device_remove(struct drm_device *dev)
  	device = nvkm_device_find(client->device);
 
  	nouveau_drm_device_fini(dev);
-	drm_dev_put(dev);
+	nouveau_drm_device_del(drm);
  	nvkm_device_del(&device);
  }
 
@@ -1369,7 +1398,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
  			       struct platform_device *pdev,
  			       struct nvkm_device **pdevice)
  {
-	struct drm_device *drm;
+	struct nouveau_drm *drm;
  	int err;
 
  	err = nvkm_device_tegra_new(func, pdev, nouveau_config, nouveau_debug,
@@ -1377,7 +1406,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
  	if (err)
  		goto err_free;
 
-	drm = drm_dev_alloc(&driver_platform, &pdev->dev);
+	drm = nouveau_drm_device_new(&driver_platform, &pdev->dev, *pdevice);
  	if (IS_ERR(drm)) {
  		err = PTR_ERR(drm);
  		goto err_free;
@@ -1387,12 +1416,10 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
  	if (err)
  		goto err_put;
 
-	platform_set_drvdata(pdev, drm);
-
-	return drm;
+	return drm->dev;
 
  err_put:
-	drm_dev_put(drm);
+	nouveau_drm_device_del(drm);
  err_free:
  	nvkm_device_del(pdevice);
 
drivers/gpu/drm/nouveau/nouveau_platform.c +0 -6
index bf2dc7567ea4..d0a63f0f54a2 100644
@@ -34,12 +34,6 @@ static int nouveau_platform_probe(struct platform_device *pdev)
  	if (IS_ERR(drm))
  		return PTR_ERR(drm);
 
-	ret = drm_dev_register(drm, 0);
-	if (ret < 0) {
-		drm_dev_put(drm);
-		return ret;
-	}
-
  	return 0;
  }
 
Signature · 1 line
2.45.1
#6 lore raw

Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

Quoted 93 lines · Ben Skeggs
Quoted 7 lines · Danilo Krummrich
Quoted 2 lines · Ben Skeggs

The next commit will change the pointer we store via dev_set_drvdata() to allow simplifying the code using it.

Please don't use future tense, e.g "In subsequent commits, the pointer we store [...]". Also, when you mention that something is changes (such as the pointer type here), it probably makes sense to mention what it is changed to instead.

Quoted 7 lines
Quoted 3 lines

Here we want to unify some more of the PCI/Tegra DRM driver init, both as a general cleanup, and to enable the dev_set_drvdata() change to be made in a single place.

In this case I think it makes sense to switch things up. First mention what the commit does and why, i.e. "Unify some more of the PCI/Tegra DRM driver init [...]" and then mention that the actual change to the pointer stored in a device' drvdata in done in a subsequent commit.

I've reworded the commit message.

Quoted 73 lines
Quoted 61 lines
---
  drivers/gpu/drm/nouveau/nouveau_drm.c      | 93 ++++++++++++++--------
  drivers/gpu/drm/nouveau/nouveau_platform.c |  6 --
  2 files changed, 60 insertions(+), 39 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +19 -9
index eae48c87e3d5..9beff8737617 100644
@@ -628,20 +628,14 @@ nouveau_drm_device_fini(struct drm_device *dev)
  	destroy_workqueue(drm->sched_wq);
  	nvif_parent_dtor(&drm->parent);
  	mutex_destroy(&drm->clients_lock);
-	kfree(drm);
  }
  static int
-nouveau_drm_device_init(struct drm_device *dev)
+nouveau_drm_device_init(struct nouveau_drm *drm)
  {
-	struct nouveau_drm *drm;
+	struct drm_device *dev = drm->dev;
  	int ret;
-	if (!(drm = kzalloc(sizeof(*drm), GFP_KERNEL)))
-		return -ENOMEM;
-	dev->dev_private = drm;
-	drm->dev = dev;
-
  	nvif_parent_ctor(&nouveau_parent, &drm->parent);
  	drm->master.base.object.parent = &drm->parent;
@@ -711,6 +705,12 @@ nouveau_drm_device_init(struct drm_device *dev)
  		pm_runtime_put(dev->dev);
  	}
+	ret = drm_dev_register(drm->dev, 0);
+	if (ret) {
+		nouveau_drm_device_fini(drm->dev);
+		return ret;
+	}
+
  	return 0;
  fail_dispinit:
  	nouveau_display_destroy(dev);
@@ -728,10 +728,47 @@ nouveau_drm_device_init(struct drm_device *dev)
  	destroy_workqueue(drm->sched_wq);
  fail_alloc:
  	nvif_parent_dtor(&drm->parent);
-	kfree(drm);
  	return ret;
  }
+static void
+nouveau_drm_device_del(struct nouveau_drm *drm)
+{
+	if (drm->dev)
+		drm_dev_put(drm->dev);
+
+	kfree(drm);
+}
+
+static struct nouveau_drm *
+nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_drm_device_init(struct drm_device *dev) · line 753

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +10 -0
+		       struct nvkm_device *device)
+{
+	struct nouveau_drm *drm;
+	int ret;
+
+	drm = kzalloc(sizeof(*drm), GFP_KERNEL);
+	if (!drm)
+		return ERR_PTR(-ENOMEM);
+
+	drm->dev = drm_dev_alloc(drm_driver, parent);

Since you're reworking this anyways, can we switch to devm_drm_dev_alloc()?

Quoted 5 lines
Quoted 1 line

This also gets us rid of nouveau_drm_device_del().

No, we can't.  I originally had this change as a cleanup patch in the series I posted implementing aux bus support.  However it turns out that in order to avoid breaking udev etc, we can't use the aux device as parent of the drm

Can you please expand a bit on what was breaking?

Quoted 5 lines

device and instead have to continue passing the pci/platform device as we do now.

Using devm_drm_dev_alloc() with the pci device as parent would tie the lifetime of the drm device to the pci device, which is owned by nvkm (after

How does this tie the lifetime of the drm device to the pci device? It's the other way around, the drm device takes a reference of its parent (i.e. the pci device).

I don't think there's anything wrong with that.

Quoted 2 lines

the auxdev series).  We could look at changing devm_drm_dev_alloc() of course, but I think that's best left until later.

I don't think that this is necessary.

Quoted 127 lines
Quoted 126 lines
Quoted 126 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +31 -24
+	if (IS_ERR(drm->dev)) {
+		ret = PTR_ERR(drm->dev);
+		goto done;
+	}
+
+	drm->dev->dev_private = drm;
+	dev_set_drvdata(parent, drm->dev);
+
+done:
+	if (ret) {
+		nouveau_drm_device_del(drm);
+		drm = NULL;
+	}
+
+	return ret ? ERR_PTR(ret) : drm;
+}
+
  /*
   * On some Intel PCIe bridge controllers doing a
   * D0 -> D3hot -> D3cold -> D0 sequence causes Nvidia GPUs to not reappear.
@@ -794,7 +831,7 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
  			     const struct pci_device_id *pent)
  {
  	struct nvkm_device *device;
-	struct drm_device *drm_dev;
+	struct nouveau_drm *drm;
  	int ret;
  	if (vga_switcheroo_client_probe_defer(pdev))
@@ -825,9 +862,9 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
  	if (nouveau_atomic)
  		driver_pci.driver_features |= DRIVER_ATOMIC;
-	drm_dev = drm_dev_alloc(&driver_pci, &pdev->dev);
-	if (IS_ERR(drm_dev)) {
-		ret = PTR_ERR(drm_dev);
+	drm = nouveau_drm_device_new(&driver_pci, &pdev->dev, device);
+	if (IS_ERR(drm)) {
+		ret = PTR_ERR(drm);
  		goto fail_nvkm;
  	}
@@ -835,30 +872,22 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
  	if (ret)
  		goto fail_drm;
-	pci_set_drvdata(pdev, drm_dev);
-
-	ret = nouveau_drm_device_init(drm_dev);
+	ret = nouveau_drm_device_init(drm);
  	if (ret)
  		goto fail_pci;
-	ret = drm_dev_register(drm_dev, pent->driver_data);
-	if (ret)
-		goto fail_drm_dev_init;
-
-	if (nouveau_drm(drm_dev)->client.device.info.ram_size <= 32 * 1024 * 1024)
-		drm_fbdev_ttm_setup(drm_dev, 8);
+	if (drm->client.device.info.ram_size <= 32 * 1024 * 1024)
+		drm_fbdev_ttm_setup(drm->dev, 8);
  	else
-		drm_fbdev_ttm_setup(drm_dev, 32);
+		drm_fbdev_ttm_setup(drm->dev, 32);
  	quirk_broken_nv_runpm(pdev);
  	return 0;
-fail_drm_dev_init:
-	nouveau_drm_device_fini(drm_dev);
  fail_pci:
  	pci_disable_device(pdev);
  fail_drm:
-	drm_dev_put(drm_dev);
+	nouveau_drm_device_del(drm);
  fail_nvkm:
  	nvkm_device_del(&device);
  	return ret;
@@ -877,7 +906,7 @@ nouveau_drm_device_remove(struct drm_device *dev)
  	device = nvkm_device_find(client->device);
  	nouveau_drm_device_fini(dev);
-	drm_dev_put(dev);
+	nouveau_drm_device_del(drm);
  	nvkm_device_del(&device);
  }
@@ -1369,7 +1398,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
  			       struct platform_device *pdev,
  			       struct nvkm_device **pdevice)
  {
-	struct drm_device *drm;
+	struct nouveau_drm *drm;
  	int err;
  	err = nvkm_device_tegra_new(func, pdev, nouveau_config, nouveau_debug,
@@ -1377,7 +1406,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
  	if (err)
  		goto err_free;
-	drm = drm_dev_alloc(&driver_platform, &pdev->dev);
+	drm = nouveau_drm_device_new(&driver_platform, &pdev->dev, *pdevice);
  	if (IS_ERR(drm)) {
  		err = PTR_ERR(drm);
  		goto err_free;
@@ -1387,12 +1416,10 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
  	if (err)
  		goto err_put;
-	platform_set_drvdata(pdev, drm);
-
-	return drm;
+	return drm->dev;
  err_put:
-	drm_dev_put(drm);
+	nouveau_drm_device_del(drm);
  err_free:
  	nvkm_device_del(pdevice);
drivers/gpu/drm/nouveau/nouveau_platform.c +0 -6
index bf2dc7567ea4..d0a63f0f54a2 100644
@@ -34,12 +34,6 @@ static int nouveau_platform_probe(struct platform_device *pdev)
  	if (IS_ERR(drm))
  		return PTR_ERR(drm);
-	ret = drm_dev_register(drm, 0);
-	if (ret < 0) {
-		drm_dev_put(drm);
-		return ret;
-	}
-
  	return 0;
  }
Signature · 1 line
2.45.1
author
#7 lore raw

Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

Quoted 92 lines · Danilo Krummrich
Quoted 91 lines · Ben Skeggs
Quoted 7 lines · Danilo Krummrich
Quoted 2 lines · Ben Skeggs

The next commit will change the pointer we store via dev_set_drvdata() to allow simplifying the code using it.

Please don't use future tense, e.g "In subsequent commits, the pointer we store [...]". Also, when you mention that something is changes (such as the pointer type here), it probably makes sense to mention what it is changed to instead.

Quoted 7 lines
Quoted 3 lines

Here we want to unify some more of the PCI/Tegra DRM driver init, both as a general cleanup, and to enable the dev_set_drvdata() change to be made in a single place.

In this case I think it makes sense to switch things up. First mention what the commit does and why, i.e. "Unify some more of the PCI/Tegra DRM driver init [...]" and then mention that the actual change to the pointer stored in a device' drvdata in done in a subsequent commit.

I've reworded the commit message.

Quoted 72 lines
Quoted 60 lines
---
   drivers/gpu/drm/nouveau/nouveau_drm.c      | 93 ++++++++++++++--------
   drivers/gpu/drm/nouveau/nouveau_platform.c |  6 --
   2 files changed, 60 insertions(+), 39 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +19 -9
index eae48c87e3d5..9beff8737617 100644
@@ -628,20 +628,14 @@ nouveau_drm_device_fini(struct drm_device *dev)
   	destroy_workqueue(drm->sched_wq);
   	nvif_parent_dtor(&drm->parent);
   	mutex_destroy(&drm->clients_lock);
-	kfree(drm);
   }
   static int
-nouveau_drm_device_init(struct drm_device *dev)
+nouveau_drm_device_init(struct nouveau_drm *drm)
   {
-	struct nouveau_drm *drm;
+	struct drm_device *dev = drm->dev;
   	int ret;
-	if (!(drm = kzalloc(sizeof(*drm), GFP_KERNEL)))
-		return -ENOMEM;
-	dev->dev_private = drm;
-	drm->dev = dev;
-
   	nvif_parent_ctor(&nouveau_parent, &drm->parent);
   	drm->master.base.object.parent = &drm->parent;
@@ -711,6 +705,12 @@ nouveau_drm_device_init(struct drm_device *dev)
   		pm_runtime_put(dev->dev);
   	}
+	ret = drm_dev_register(drm->dev, 0);
+	if (ret) {
+		nouveau_drm_device_fini(drm->dev);
+		return ret;
+	}
+
   	return 0;
   fail_dispinit:
   	nouveau_display_destroy(dev);
@@ -728,10 +728,47 @@ nouveau_drm_device_init(struct drm_device *dev)
   	destroy_workqueue(drm->sched_wq);
   fail_alloc:
   	nvif_parent_dtor(&drm->parent);
-	kfree(drm);
   	return ret;
   }
+static void
+nouveau_drm_device_del(struct nouveau_drm *drm)
+{
+	if (drm->dev)
+		drm_dev_put(drm->dev);
+
+	kfree(drm);
+}
+
+static struct nouveau_drm *
+nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_drm_device_init(struct drm_device *dev) · line 753

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +10 -0
+		       struct nvkm_device *device)
+{
+	struct nouveau_drm *drm;
+	int ret;
+
+	drm = kzalloc(sizeof(*drm), GFP_KERNEL);
+	if (!drm)
+		return ERR_PTR(-ENOMEM);
+
+	drm->dev = drm_dev_alloc(drm_driver, parent);

Since you're reworking this anyways, can we switch to devm_drm_dev_alloc()?

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

This also gets us rid of nouveau_drm_device_del().

No, we can't.  I originally had this change as a cleanup patch in the series I posted implementing aux bus support.  However it turns out that in order to avoid breaking udev etc, we can't use the aux device as parent of the drm

Can you please expand a bit on what was breaking?

Sorry, I meant to say PRIME, not udev.  The device selection logic ties the DRM device back to its sysfs node, and doesn't understand the auxiliary bus.  So, if nouveau were to use its auxiliary device as parent of the DRM device, PRIME breaks. Fortunately it didn't turn out to be necessary, and we can happily probe() against the auxiliary device and still use the PCI device as the DRM device's parent.

Quoted 11 lines
Quoted 6 lines

device and instead have to continue passing the pci/platform device as we do now.

Using devm_drm_dev_alloc() with the pci device as parent would tie the lifetime of the drm device to the pci device, which is owned by nvkm (after

How does this tie the lifetime of the drm device to the pci device? It's the other way around, the drm device takes a reference of its parent (i.e. the pci device).

I don't think there's anything wrong with that.

My understanding is that devres will cleanup allocations when the driver detaches from the device.  With the auxdev changes, it's *NVKM* that's attached to the PCI device, not the DRM driver (which is attached to an auxiliary device instead).

This means that the devm_drm_dev_init_release() won't be called when the DRM driver detaches from its auxiliary device as it should, but when NVKM detaches from the PCI device, which isn't the most obvious and could lead to confusion.

It also entirely blows up in the split module case as nouveau.ko is unloaded already by the time NVKM detaches and drm_dev_put() gets called.

Quoted 129 lines
Quoted 3 lines

the auxdev series).  We could look at changing devm_drm_dev_alloc() of course, but I think that's best left until later.

I don't think that this is necessary.

Quoted 124 lines
Quoted 124 lines
Quoted 124 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +31 -24
+	if (IS_ERR(drm->dev)) {
+		ret = PTR_ERR(drm->dev);
+		goto done;
+	}
+
+	drm->dev->dev_private = drm;
+	dev_set_drvdata(parent, drm->dev);
+
+done:
+	if (ret) {
+		nouveau_drm_device_del(drm);
+		drm = NULL;
+	}
+
+	return ret ? ERR_PTR(ret) : drm;
+}
+
   /*
    * On some Intel PCIe bridge controllers doing a
    * D0 -> D3hot -> D3cold -> D0 sequence causes Nvidia GPUs to not reappear.
@@ -794,7 +831,7 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
   			     const struct pci_device_id *pent)
   {
   	struct nvkm_device *device;
-	struct drm_device *drm_dev;
+	struct nouveau_drm *drm;
   	int ret;
   	if (vga_switcheroo_client_probe_defer(pdev))
@@ -825,9 +862,9 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
   	if (nouveau_atomic)
   		driver_pci.driver_features |= DRIVER_ATOMIC;
-	drm_dev = drm_dev_alloc(&driver_pci, &pdev->dev);
-	if (IS_ERR(drm_dev)) {
-		ret = PTR_ERR(drm_dev);
+	drm = nouveau_drm_device_new(&driver_pci, &pdev->dev, device);
+	if (IS_ERR(drm)) {
+		ret = PTR_ERR(drm);
   		goto fail_nvkm;
   	}
@@ -835,30 +872,22 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
   	if (ret)
   		goto fail_drm;
-	pci_set_drvdata(pdev, drm_dev);
-
-	ret = nouveau_drm_device_init(drm_dev);
+	ret = nouveau_drm_device_init(drm);
   	if (ret)
   		goto fail_pci;
-	ret = drm_dev_register(drm_dev, pent->driver_data);
-	if (ret)
-		goto fail_drm_dev_init;
-
-	if (nouveau_drm(drm_dev)->client.device.info.ram_size <= 32 * 1024 * 1024)
-		drm_fbdev_ttm_setup(drm_dev, 8);
+	if (drm->client.device.info.ram_size <= 32 * 1024 * 1024)
+		drm_fbdev_ttm_setup(drm->dev, 8);
   	else
-		drm_fbdev_ttm_setup(drm_dev, 32);
+		drm_fbdev_ttm_setup(drm->dev, 32);
   	quirk_broken_nv_runpm(pdev);
   	return 0;
-fail_drm_dev_init:
-	nouveau_drm_device_fini(drm_dev);
   fail_pci:
   	pci_disable_device(pdev);
   fail_drm:
-	drm_dev_put(drm_dev);
+	nouveau_drm_device_del(drm);
   fail_nvkm:
   	nvkm_device_del(&device);
   	return ret;
@@ -877,7 +906,7 @@ nouveau_drm_device_remove(struct drm_device *dev)
   	device = nvkm_device_find(client->device);
   	nouveau_drm_device_fini(dev);
-	drm_dev_put(dev);
+	nouveau_drm_device_del(drm);
   	nvkm_device_del(&device);
   }
@@ -1369,7 +1398,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
   			       struct platform_device *pdev,
   			       struct nvkm_device **pdevice)
   {
-	struct drm_device *drm;
+	struct nouveau_drm *drm;
   	int err;
   	err = nvkm_device_tegra_new(func, pdev, nouveau_config, nouveau_debug,
@@ -1377,7 +1406,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
   	if (err)
   		goto err_free;
-	drm = drm_dev_alloc(&driver_platform, &pdev->dev);
+	drm = nouveau_drm_device_new(&driver_platform, &pdev->dev, *pdevice);
   	if (IS_ERR(drm)) {
   		err = PTR_ERR(drm);
   		goto err_free;
@@ -1387,12 +1416,10 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
   	if (err)
   		goto err_put;
-	platform_set_drvdata(pdev, drm);
-
-	return drm;
+	return drm->dev;
   err_put:
-	drm_dev_put(drm);
+	nouveau_drm_device_del(drm);
   err_free:
   	nvkm_device_del(pdevice);
drivers/gpu/drm/nouveau/nouveau_platform.c +0 -6
index bf2dc7567ea4..d0a63f0f54a2 100644
@@ -34,12 +34,6 @@ static int nouveau_platform_probe(struct platform_device *pdev)
   	if (IS_ERR(drm))
   		return PTR_ERR(drm);
-	ret = drm_dev_register(drm, 0);
-	if (ret < 0) {
-		drm_dev_put(drm);
-		return ret;
-	}
-
   	return 0;
   }
Signature · 1 line
2.45.1
maintainer
#8 lore raw

Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

Quoted 19 lines · Ben Skeggs
Quoted 19 lines
Quoted 19 lines
Quoted 15 lines

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_drm_device_init(struct drm_device *dev) · line 754

Quoted 13 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +13 -0
+
+static struct nouveau_drm *
+nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,
+		       struct nvkm_device *device)
+{
+	struct nouveau_drm *drm;
+	int ret;
+
+	drm = kzalloc(sizeof(*drm), GFP_KERNEL);
+	if (!drm)
+		return ERR_PTR(-ENOMEM);
+
+	drm->dev = drm_dev_alloc(drm_driver, parent);

Since you're reworking this anyways, can we switch to devm_drm_dev_alloc()?

Quoted 1 line

This also gets us rid of nouveau_drm_device_del().

No, we can't.  I originally had this change as a cleanup patch in the series I posted implementing aux bus support.  However it turns out that in order to avoid breaking udev etc, we can't use the aux device as parent of the drm

Quoted 6 lines
Quoted 1 line

Can you please expand a bit on what was breaking?

Sorry, I meant to say PRIME, not udev.  The device selection logic ties the DRM device back to its sysfs node, and doesn't understand the auxiliary bus.  So, if nouveau were to use its auxiliary device as parent of the DRM device, PRIME breaks.

The Vulkan device selector stuff looks like it should mostly work.

However, I guess you refer to the loader stuff in Mesa that uses drmGetDevices2() from libdrm? This stuff indeed whitelists busses it accepts to report DRM device from:

	{ "/pci", DRM_BUS_PCI },
	{ "/usb", DRM_BUS_USB },
	{ "/platform", DRM_BUS_PLATFORM },
	{ "/spi", DRM_BUS_PLATFORM },
	{ "/host1x", DRM_BUS_HOST1X },
	{ "/virtio", DRM_BUS_VIRTIO },

Not a big deal to just add it for a new driver, but obviously we can't just do this for an existing one.

Quoted 3 lines

Fortunately it didn't turn out to be necessary, and we
can happily probe() against the auxiliary device and still use the PCI device as the DRM device's parent.

At a first glance, I guess this should work. But, before we introduce workarounds like this one and add even more complexity, I wonder what's the benefit of doing this for Nouveau in the first place? I think we agreed to this split for Nova, for the reasons discussed in [1].

[1] https://lore.kernel.org/dri-devel/[email protected]/

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

device and instead have to continue passing the pci/platform device as we do now.

Using devm_drm_dev_alloc() with the pci device as parent would tie the lifetime of the drm device to the pci device, which is owned by nvkm (after

Quoted 8 lines
Quoted 5 lines

How does this tie the lifetime of the drm device to the pci device? It's the other way around, the drm device takes a reference of its parent (i.e. the pci device).

I don't think there's anything wrong with that.

My understanding is that devres will cleanup allocations when the driver detaches from the device.

Right, I think I took that too literally.

The lifetime of the DRM device (or more precisely one of its references) is bound to the binding between the parent device and its corresponding driver.

But the lifetime of the parent device itself is bound to the DRM device.

So, yes this doesn't work, and proves the point that initializing the DRM device with the parent's parent is just a workaround.

Quoted 16 lines

With the auxdev changes, it's *NVKM* that's
attached to the PCI device, not the DRM driver (which is attached to an auxiliary device instead).

This means that the devm_drm_dev_init_release() won't be called when the DRM driver detaches from its auxiliary device as it should, but when NVKM detaches from the PCI device, which isn't the most obvious and could lead to confusion.

It also entirely blows up in the split module case as nouveau.ko is unloaded already by the time NVKM detaches and drm_dev_put() gets called.

Quoted 4 lines
Quoted 3 lines

the auxdev series).  We could look at changing devm_drm_dev_alloc() of course, but I think that's best left until later.

I don't think that this is necessary.

author
#9 lore raw

Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

Quoted 41 lines · Danilo Krummrich
Quoted 16 lines · Ben Skeggs
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_drm_device_init(struct drm_device *dev) · line 754

Quoted 13 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +13 -0
+
+static struct nouveau_drm *
+nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,
+		       struct nvkm_device *device)
+{
+	struct nouveau_drm *drm;
+	int ret;
+
+	drm = kzalloc(sizeof(*drm), GFP_KERNEL);
+	if (!drm)
+		return ERR_PTR(-ENOMEM);
+
+	drm->dev = drm_dev_alloc(drm_driver, parent);

Since you're reworking this anyways, can we switch to devm_drm_dev_alloc()?

This also gets us rid of nouveau_drm_device_del().

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

No, we can't.  I originally had this change as a cleanup patch in the series I posted implementing aux bus support.  However it turns out that in order to avoid breaking udev etc, we can't use the aux device as parent of the drm

Can you please expand a bit on what was breaking?

Sorry, I meant to say PRIME, not udev.  The device selection logic ties the DRM device back to its sysfs node, and doesn't understand the auxiliary bus.  So, if nouveau were to use its auxiliary device as parent of the DRM device, PRIME breaks.

The Vulkan device selector stuff looks like it should mostly work.

However, I guess you refer to the loader stuff in Mesa that uses drmGetDevices2() from libdrm? This stuff indeed whitelists busses it accepts to report DRM device from:

	{ "/pci", DRM_BUS_PCI },
	{ "/usb", DRM_BUS_USB },
	{ "/platform", DRM_BUS_PLATFORM },
	{ "/spi", DRM_BUS_PLATFORM },
	{ "/host1x", DRM_BUS_HOST1X },
	{ "/virtio", DRM_BUS_VIRTIO },

Not a big deal to just add it for a new driver, but obviously we can't just do this for an existing one.

Quoted 7 lines
Quoted 3 lines

Fortunately it didn't turn out to be necessary, and we
can happily probe() against the auxiliary device and still use the PCI device as the DRM device's parent.

At a first glance, I guess this should work. But, before we introduce workarounds like this one and add even more complexity, I wonder what's the benefit of doing this for Nouveau in the first place? I think we agreed to this split for Nova, for the reasons discussed in [1].

Because, as I already mentioned in the cover letter for series I posted implementing the auxiliary bus support, this brings immediate benefits to users, such as eliminating the long pauses on systems using prime whilst the entire GPU is woken up for some PCI query by userspace.

It also (finally) integrates Tegra in a reasonably clean fashion, and would allow the DRM-level suspend/resume code to be shared there too if someone were to implement the platform-level code for it.  That was not possible before.

Quoted 17 lines

[1] https://lore.kernel.org/dri-devel/[email protected]/

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

device and instead have to continue passing the pci/platform device as we do now.

Using devm_drm_dev_alloc() with the pci device as parent would tie the lifetime of the drm device to the pci device, which is owned by nvkm (after

Quoted 7 lines
Quoted 5 lines

How does this tie the lifetime of the drm device to the pci device? It's the other way around, the drm device takes a reference of its parent (i.e. the pci device).

I don't think there's anything wrong with that.

My understanding is that devres will cleanup allocations when the driver detaches from the device.

Right, I think I took that too literally.

Quoted 7 lines

The lifetime of the DRM device (or more precisely one of its references) is bound to the binding between the parent device and its corresponding driver.

But the lifetime of the parent device itself is bound to the DRM device.

So, yes this doesn't work, and proves the point that initializing the DRM device with the parent's parent is just a workaround.

You're greatly overstating the "complexity" that's added here. It's a minor inconvenience that doesn't require much code at all to implement, and is essentially irrelevant outside of module load/unload.

I agree it's not ideal, and userspace should gain auxiliary bus support before a new driver implements a similar architecture, but it's really not that big a deal.

Quoted 16 lines
Quoted 16 lines

With the auxdev changes, it's *NVKM* that's
attached to the PCI device, not the DRM driver (which is attached to an auxiliary device instead).

This means that the devm_drm_dev_init_release() won't be called when the DRM driver detaches from its auxiliary device as it should, but when NVKM detaches from the PCI device, which isn't the most obvious and could lead to confusion.

It also entirely blows up in the split module case as nouveau.ko is unloaded already by the time NVKM detaches and drm_dev_put() gets called.

Quoted 3 lines
Quoted 2 lines

the auxdev series).  We could look at changing devm_drm_dev_alloc() of course, but I think that's best left until later.

I don't think that this is necessary.

#10 lore raw

Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

Quoted 46 lines · Ben Skeggs
Quoted 44 lines · Danilo Krummrich
Quoted 16 lines · Ben Skeggs
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

Review

Quoted 13 lines
(quoted diff) +13 -0
+
+static struct nouveau_drm *
+nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,
+		       struct nvkm_device *device)
+{
+	struct nouveau_drm *drm;
+	int ret;
+
+	drm = kzalloc(sizeof(*drm), GFP_KERNEL);
+	if (!drm)
+		return ERR_PTR(-ENOMEM);
+
+	drm->dev = drm_dev_alloc(drm_driver, parent);

Since you're reworking this anyways, can we switch to devm_drm_dev_alloc()?

This also gets us rid of nouveau_drm_device_del().

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

No, we can't.  I originally had this change as a cleanup patch in the series I posted implementing aux bus support.  However it turns out that in order to avoid breaking udev etc, we can't use the aux device as parent of the drm

Can you please expand a bit on what was breaking?

Sorry, I meant to say PRIME, not udev.  The device selection logic ties the DRM device back to its sysfs node, and doesn't understand the auxiliary bus.  So, if nouveau were to use its auxiliary device as parent of the DRM device, PRIME breaks.

The Vulkan device selector stuff looks like it should mostly work.

However, I guess you refer to the loader stuff in Mesa that uses drmGetDevices2() from libdrm? This stuff indeed whitelists busses it accepts to report DRM device from:

	{ "/pci", DRM_BUS_PCI },
	{ "/usb", DRM_BUS_USB },
	{ "/platform", DRM_BUS_PLATFORM },
	{ "/spi", DRM_BUS_PLATFORM },
	{ "/host1x", DRM_BUS_HOST1X },
	{ "/virtio", DRM_BUS_VIRTIO },

Not a big deal to just add it for a new driver, but obviously we can't just do this for an existing one.

Quoted 3 lines

Fortunately it didn't turn out to be necessary, and we
can happily probe() against the auxiliary device and still use the PCI device as the DRM device's parent.

Quoted 6 lines
Quoted 4 lines

At a first glance, I guess this should work. But, before we introduce workarounds like this one and add even more complexity, I wonder what's the benefit of doing this for Nouveau in the first place? I think we agreed to this split for Nova, for the reasons discussed in [1].

Because, as I already mentioned in the cover letter for series I posted

For some reason your auxbus series never hit my inbox - fetched it from lore now.

Quoted 3 lines

implementing the auxiliary bus support, this brings immediate benefits to users, such as eliminating the long pauses on systems using prime whilst the entire GPU is woken up for some PCI query by userspace.

Sounds good, what is the difference we're talking about?

Quoted 5 lines

It also (finally) integrates Tegra in a reasonably clean fashion, and would allow the DRM-level suspend/resume code to be shared there too if someone were to implement the platform-level code for it.  That was not possible before.

I agree it's an advantage, but it's probably not too bad as it currently is either.

Quoted 21 lines
Quoted 21 lines

[1] https://lore.kernel.org/dri-devel/[email protected]/

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

device and instead have to continue passing the pci/platform device as we do now.

Using devm_drm_dev_alloc() with the pci device as parent would tie the lifetime of the drm device to the pci device, which is owned by nvkm (after

Quoted 7 lines
Quoted 5 lines

How does this tie the lifetime of the drm device to the pci device? It's the other way around, the drm device takes a reference of its parent (i.e. the pci device).

I don't think there's anything wrong with that.

My understanding is that devres will cleanup allocations when the driver detaches from the device.

Right, I think I took that too literally.

The lifetime of the DRM device (or more precisely one of its references) is bound to the binding between the parent device and its corresponding driver.

Quoted 8 lines
Quoted 4 lines

But the lifetime of the parent device itself is bound to the DRM device.

So, yes this doesn't work, and proves the point that initializing the DRM device with the parent's parent is just a workaround.

You're greatly overstating the "complexity" that's added here. It's a minor inconvenience that doesn't require much code at all to implement, and is essentially irrelevant outside of module load/unload.

When I was talking about complexity I was referring to the changes required to integrate the auxbus stuff.

Having to call drm_dev_put() from .remove() by hand obviously isn't something I'm overly concerned about in terms of complexity...

Quoted 22 lines

I agree it's not ideal, and userspace should gain auxiliary bus support before a new driver implements a similar architecture, but it's really not that big a deal.

Quoted 16 lines
Quoted 16 lines

With the auxdev changes, it's *NVKM* that's
attached to the PCI device, not the DRM driver (which is attached to an auxiliary device instead).

This means that the devm_drm_dev_init_release() won't be called when the DRM driver detaches from its auxiliary device as it should, but when NVKM detaches from the PCI device, which isn't the most obvious and could lead to confusion.

It also entirely blows up in the split module case as nouveau.ko is unloaded already by the time NVKM detaches and drm_dev_put() gets called.

Quoted 3 lines
Quoted 2 lines

the auxdev series).  We could look at changing devm_drm_dev_alloc() of course, but I think that's best left until later.

I don't think that this is necessary.

#11 lore raw

Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

In reply to Ben Skeggs
Quoted 10 lines · Ben Skeggs
Quoted 9 lines

Right, I think I took that too literally.

The lifetime of the DRM device (or more precisely one of its references) is bound to the binding between the parent device and its corresponding driver.

But the lifetime of the parent device itself is bound to the DRM device.

So, yes this doesn't work, and proves the point that initializing the DRM device with the parent's parent is just a workaround.

Quoted 7 lines

You're greatly overstating the "complexity" that's added here. It's a minor inconvenience that doesn't require much code at all to implement, and is essentially irrelevant outside of module load/unload.

I agree it's not ideal, and userspace should gain auxiliary bus support before a new driver implements a similar architecture, but it's really not that big a deal.

Ben asked me to share what other places are doing this stuff.

To recap, when converting a legacy driver into an aux split we've found in several places that there is existing userspace that has hardwired certain sysfs paths. ie an assumption that an infiniband device appears under the sys/../pci/ directory.

Argubaly this userspace is not in good shape, but we have to preserve it.

So the approach is to make the sysfs visible elements tied to the original sysfs location (ie the pci device) and continue to use aux otherwise for discovery, probing and tying subsystems together.

Obviously you have to be careful about the difference between the sysfs parent (for owning a subordinate struct device, sysfs files, etc) and the probe time parent (for owning devres, and other tasks)

We've been fortunate enough that subsystems so far have had a clean enough setup that this is easy enough to do. It sounds like DRM is the same if it just requires calling a put in .remove() - that is pretty normal (though most subsystems would call that unregister, not put)

Jason

#12 lore raw

Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

Quoted 30 lines · Jason Gunthorpe
Quoted 10 lines · Ben Skeggs
Quoted 9 lines

Right, I think I took that too literally.

The lifetime of the DRM device (or more precisely one of its references) is bound to the binding between the parent device and its corresponding driver.

But the lifetime of the parent device itself is bound to the DRM device.

So, yes this doesn't work, and proves the point that initializing the DRM device with the parent's parent is just a workaround.

Quoted 7 lines

You're greatly overstating the "complexity" that's added here. It's a minor inconvenience that doesn't require much code at all to implement, and is essentially irrelevant outside of module load/unload.

I agree it's not ideal, and userspace should gain auxiliary bus support before a new driver implements a similar architecture, but it's really not that big a deal.

Ben asked me to share what other places are doing this stuff.

To recap, when converting a legacy driver into an aux split we've found in several places that there is existing userspace that has hardwired certain sysfs paths. ie an assumption that an infiniband device appears under the sys/../pci/ directory.

Argubaly this userspace is not in good shape, but we have to preserve it.

Quoted 7 lines

So the approach is to make the sysfs visible elements tied to the original sysfs location (ie the pci device) and continue to use aux otherwise for discovery, probing and tying subsystems together.

Obviously you have to be careful about the difference between the sysfs parent (for owning a subordinate struct device, sysfs files, etc) and the probe time parent (for owning devres, and other tasks)

I think we're on the same page with all that. As clarified in [1], that's not a big concern, I was referring to the changes required to integrate the auxbus stuff.

[1] https://lore.kernel.org/nouveau/[email protected]/

Quoted 4 lines

We've been fortunate enough that subsystems so far have had a clean enough setup that this is easy enough to do. It sounds like DRM is the same if it just requires calling a put in .remove() - that is pretty

Yes, I already mentioned that that DRM devices should still work with this workaround.

Quoted 1 line

normal (though most subsystems would call that unregister, not put)

A DRM device is reference counted and can out-live the driver, hence the drm_dev_put() call in .remove(). There is also a special drm_dev_unplug() function, which does not only unregister the DRM device, but also sets a guard to be able prevent HW accesses after the HW is accessible anymore.

Quoted 3 lines

Jason

#13 lore raw

Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

Quoted 5 lines · Danilo Krummrich

On Sun, Jul 28, 2024 at 03:13:08PM -0300, Jason Gunthorpe wrote:

I think we're on the same page with all that. As clarified in [1], that's not a big concern, I was referring to the changes required to integrate the auxbus stuff.

Well, I see this thread having the realization that things are not setup proeprly to use devres. To be fair devres creates almost as many bugs as it solves :\ cleanup.h is possibly a better option for most simple things and harder to misuse...

Quoted 6 lines
Quoted 1 line

normal (though most subsystems would call that unregister, not put)

A DRM device is reference counted and can out-live the driver, hence the drm_dev_put() call in .remove(). There is also a special drm_dev_unplug() function, which does not only unregister the DRM device, but also sets a guard to be able prevent HW accesses after the HW is accessible anymore.

Every subsystem has a refcounted object, struct device is inherently refcounted. You call the thing driver calls during .remove() 'unregister' because it is special. Once it returns the subsystem has to promise no more code is running in driver callbacks and the driver is permitted to start destroying anything it might need to use when processing any callbacks.

This is really tricky and people routinely misunderstand the requirements and get this wrong. The consequence is UAF problems in obscure cases with unbind races (that few actually care about), but getting it right starts with labeling things properly :)

We went through this long ago in RDMA because someone actually had a usecase of live driver unbind, making that work reliably under a full active work load took some thoughtfulness.

Jason

#14 lore raw

Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code

Quoted 9 lines · Jason Gunthorpe
Quoted 5 lines · Danilo Krummrich

On Sun, Jul 28, 2024 at 03:13:08PM -0300, Jason Gunthorpe wrote:

I think we're on the same page with all that. As clarified in [1], that's not a big concern, I was referring to the changes required to integrate the auxbus stuff.

Well, I see this thread having the realization that things are not setup proeprly to use devres.

We could use it in Nouveau without issue, it starts to become an issue when moving to the auxbus design because userspace isn't aware. But again, if we figure out that switching to auxbus is worth it, that is totally fine.

Quoted 3 lines

To be fair devres creates almost as many
bugs as it solves :\ cleanup.h is possibly a better option for most simple things and harder to misuse...

I agree cleanup.h is useful, it has a whole different purpose though.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

normal (though most subsystems would call that unregister, not put)

A DRM device is reference counted and can out-live the driver, hence the drm_dev_put() call in .remove(). There is also a special drm_dev_unplug() function, which does not only unregister the DRM device, but also sets a guard to be able prevent HW accesses after the HW is accessible anymore.

Quoted 6 lines

Every subsystem has a refcounted object, struct device is inherently refcounted. You call the thing driver calls during .remove() 'unregister' because it is special. Once it returns the subsystem has to promise no more code is running in driver callbacks and the driver is permitted to start destroying anything it might need to use when processing any callbacks.

I'm well aware, that is not the case for DRM though. Again, a DRM device can (and is allowed to) out-live the driver. There can even still be calls into the driver after it has been unregistered. This is where drm_dev_unplug(), drm_dev_enter() and drm_dev_exit() [1] are used to guard the places where device resources, such as MMIO mappings, are accessed.

[1] https://elixir.bootlin.com/linux/v6.10/source/drivers/gpu/drm/drm_drv.c#L436

Quoted 4 lines

This is really tricky and people routinely misunderstand the requirements and get this wrong. The consequence is UAF problems in obscure cases with unbind races (that few actually care about), but

As for memory safety in this context, DRM has it's own managed memory allocators, which tie memory allocations to the lifetime of a DRM device. This stuff is called the DRM managed API [2]. Some structures have to be allocated with, e.g. drmm_kzalloc(), for this purpose.

[2] https://elixir.bootlin.com/linux/v6.10/source/drivers/gpu/drm/drm_managed.c#L21

Quoted 1 line

getting it right starts with labeling things properly :)

As for DRM, I think everything is labeled properly.

Quoted 4 lines

We went through this long ago in RDMA because someone actually had a usecase of live driver unbind, making that work reliably under a full active work load took some thoughtfulness.

And so did DRM. :)

Quoted 3 lines

Jason

author
#15 lore raw

PATCH v2 3/37 drm/nouveau: replace drm_device* with nouveau_drm* as dev drvdata

In reply to Ben Skeggs

We almost always want to cast the pointer from dev_get_drvdata() to 'struct nouveau_drm *', so just directly store that pointer instead, simplifying callers, and fixing some clumsy naming of dev/drm_dev variables at the same time.

---
 drivers/gpu/drm/nouveau/dispnv50/disp.c    | 17 ++---
 drivers/gpu/drm/nouveau/nouveau_display.c  |  4 +-
 drivers/gpu/drm/nouveau/nouveau_display.h  |  2 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c      | 78 ++++++++++------------
 drivers/gpu/drm/nouveau/nouveau_drv.h      |  2 +-
 drivers/gpu/drm/nouveau/nouveau_platform.c |  5 +-
 drivers/gpu/drm/nouveau/nouveau_vga.c      | 14 ++--
 7 files changed, 58 insertions(+), 64 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/disp.c +7 -10
index ac9657d7e92d..6750f66bb1ff 100644
@@ -593,8 +593,7 @@ static int
 nv50_audio_component_get_eld(struct device *kdev, int port, int dev_id,
 			     bool *enabled, unsigned char *buf, int max_bytes)
 {
-	struct drm_device *drm_dev = dev_get_drvdata(kdev);
-	struct nouveau_drm *drm = nouveau_drm(drm_dev);
+	struct nouveau_drm *drm = dev_get_drvdata(kdev);
 	struct drm_encoder *encoder;
 	struct nouveau_encoder *nv_encoder;
 	struct nouveau_crtc *nv_crtc;
@@ -639,18 +638,17 @@ static int
 nv50_audio_component_bind(struct device *kdev, struct device *hda_kdev,
 			  void *data)
 {
-	struct drm_device *drm_dev = dev_get_drvdata(kdev);
-	struct nouveau_drm *drm = nouveau_drm(drm_dev);
+	struct nouveau_drm *drm = dev_get_drvdata(kdev);
 	struct drm_audio_component *acomp = data;
 
 	if (WARN_ON(!device_link_add(hda_kdev, kdev, DL_FLAG_STATELESS)))
 		return -ENOMEM;
 
-	drm_modeset_lock_all(drm_dev);
+	drm_modeset_lock_all(drm->dev);
 	acomp->ops = &nv50_audio_component_ops;
 	acomp->dev = kdev;
 	drm->audio.component = acomp;
-	drm_modeset_unlock_all(drm_dev);
+	drm_modeset_unlock_all(drm->dev);
 	return 0;
 }
 
@@ -658,15 +656,14 @@ static void
 nv50_audio_component_unbind(struct device *kdev, struct device *hda_kdev,
 			    void *data)
 {
-	struct drm_device *drm_dev = dev_get_drvdata(kdev);
-	struct nouveau_drm *drm = nouveau_drm(drm_dev);
+	struct nouveau_drm *drm = dev_get_drvdata(kdev);
 	struct drm_audio_component *acomp = data;
 
-	drm_modeset_lock_all(drm_dev);
+	drm_modeset_lock_all(drm->dev);
 	drm->audio.component = NULL;
 	acomp->ops = NULL;
 	acomp->dev = NULL;
-	drm_modeset_unlock_all(drm_dev);
+	drm_modeset_unlock_all(drm->dev);
 }
 
 static const struct component_ops nv50_audio_component_bind_ops = {
drivers/gpu/drm/nouveau/nouveau_display.c +1 -3
index aed5d5b51b43..fa30c97bcf90 100644
@@ -446,10 +446,8 @@ static struct nouveau_drm_prop_enum_list dither_depth[] = {
 } while(0)
 
 void
-nouveau_display_hpd_resume(struct drm_device *dev)
+nouveau_display_hpd_resume(struct nouveau_drm *drm)
 {
-	struct nouveau_drm *drm = nouveau_drm(dev);
-
 	spin_lock_irq(&drm->hpd_lock);
 	drm->hpd_pending = ~0;
 	spin_unlock_irq(&drm->hpd_lock);
drivers/gpu/drm/nouveau/nouveau_display.h +1 -1
index 2ab2ddb1eadf..1f506f8b289c 100644
@@ -45,7 +45,7 @@ nouveau_display(struct drm_device *dev)
 int  nouveau_display_create(struct drm_device *dev);
 void nouveau_display_destroy(struct drm_device *dev);
 int  nouveau_display_init(struct drm_device *dev, bool resume, bool runtime);
-void nouveau_display_hpd_resume(struct drm_device *dev);
+void nouveau_display_hpd_resume(struct nouveau_drm *);
 void nouveau_display_fini(struct drm_device *dev, bool suspend, bool runtime);
 int  nouveau_display_suspend(struct drm_device *dev, bool runtime);
 void nouveau_display_resume(struct drm_device *dev, bool runtime);
drivers/gpu/drm/nouveau/nouveau_drm.c +37 -41

214 lines not on this page · raw message

drivers/gpu/drm/nouveau/nouveau_drv.h +1 -1
index e239c6bf4afa..7e624c587fc0 100644
@@ -325,7 +325,7 @@ bool nouveau_pmops_runtime(void);
 struct drm_device *
 nouveau_platform_device_create(const struct nvkm_device_tegra_func *,
 			       struct platform_device *, struct nvkm_device **);
-void nouveau_drm_device_remove(struct drm_device *dev);
+void nouveau_drm_device_remove(struct nouveau_drm *);
 
 #define NV_PRINTK(l,c,f,a...) do {                                             \
 	struct nouveau_cli *_cli = (c);                                        \
drivers/gpu/drm/nouveau/nouveau_platform.c +3 -2
index d0a63f0f54a2..3194b110eff8 100644
@@ -39,8 +39,9 @@ static int nouveau_platform_probe(struct platform_device *pdev)
 
 static void nouveau_platform_remove(struct platform_device *pdev)
 {
-	struct drm_device *dev = platform_get_drvdata(pdev);
-	nouveau_drm_device_remove(dev);
+	struct nouveau_drm *drm = platform_get_drvdata(pdev);
+
+	nouveau_drm_device_remove(drm);
 }
 
 #if IS_ENABLED(CONFIG_OF)
drivers/gpu/drm/nouveau/nouveau_vga.c +8 -6
index f8bf0ec26844..2525e08938b3 100644
@@ -11,7 +11,7 @@
 static unsigned int
 nouveau_vga_set_decode(struct pci_dev *pdev, bool state)
 {
-	struct nouveau_drm *drm = nouveau_drm(pci_get_drvdata(pdev));
+	struct nouveau_drm *drm = pci_get_drvdata(pdev);
 	struct nvif_object *device = &drm->client.device.object;
 
 	if (drm->client.device.info.family == NV_DEVICE_INFO_V0_CURIE &&
@@ -34,7 +34,8 @@ static void
 nouveau_switcheroo_set_state(struct pci_dev *pdev,
 			     enum vga_switcheroo_state state)
 {
-	struct drm_device *dev = pci_get_drvdata(pdev);
+	struct nouveau_drm *drm = pci_get_drvdata(pdev);
+	struct drm_device *dev = drm->dev;
 
 	if ((nouveau_is_optimus() || nouveau_is_v1_dsm()) && state == VGA_SWITCHEROO_OFF)
 		return;
@@ -56,21 +57,22 @@ nouveau_switcheroo_set_state(struct pci_dev *pdev,
 static void
 nouveau_switcheroo_reprobe(struct pci_dev *pdev)
 {
-	struct drm_device *dev = pci_get_drvdata(pdev);
-	drm_fb_helper_output_poll_changed(dev);
+	struct nouveau_drm *drm = pci_get_drvdata(pdev);
+
+	drm_fb_helper_output_poll_changed(drm->dev);
 }
 
 static bool
 nouveau_switcheroo_can_switch(struct pci_dev *pdev)
 {
-	struct drm_device *dev = pci_get_drvdata(pdev);
+	struct nouveau_drm *drm = pci_get_drvdata(pdev);
 
 	/*
 	 * FIXME: open_count is protected by drm_global_mutex but that would lead to
 	 * locking inversion with the driver load path. And the access here is
 	 * completely racy anyway. So don't bother with locking for now.
 	 */
-	return atomic_read(&dev->open_count) == 0;
+	return atomic_read(&drm->dev->open_count) == 0;
 }
 
 static const struct vga_switcheroo_client_ops
Signature · 1 line
2.45.1
author
#16 lore raw

PATCH v2 4/37 drm/nouveau: create pci device once

In reply to Ben Skeggs

HW isn't touched anymore (aside from detection) until the first nvif_device has been allocated, so we no longer need a separate probe-only step before kicking efifb (etc) off the HW.

---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +2 -9
index 0687bc59d486..f372bf2954aa 100644
@@ -839,23 +839,16 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 	/* We need to check that the chipset is supported before booting
 	 * fbdev off the hardware, as there's no way to put it back.
 	 */
-	ret = nvkm_device_pci_new(pdev, nouveau_config, "error",
-				  true, false, 0, &device);
+	ret = nvkm_device_pci_new(pdev, nouveau_config, nouveau_debug,
+				  true, true, ~0ULL, &device);
 	if (ret)
 		return ret;
 
-	nvkm_device_del(&device);
-
 	/* Remove conflicting drivers (vesafb, efifb etc). */
 	ret = drm_aperture_remove_conflicting_pci_framebuffers(pdev, &driver_pci);
 	if (ret)
 		return ret;
 
-	ret = nvkm_device_pci_new(pdev, nouveau_config, nouveau_debug,
-				  true, true, ~0ULL, &device);
-	if (ret)
-		return ret;
-
 	pci_set_master(pdev);
 
 	if (nouveau_atomic)
Signature · 1 line
2.45.1
author
#17 lore raw

PATCH v2 5/37 drm/nouveau: store nvkm_device pointer in nouveau_drm

In reply to Ben Skeggs

There's various different places in the drm code that get at the nvkm_device via various creative (and not very type-safe) means.

One of those being via nvif_device.object.priv.

Another patch series is going to entirely remove the ioctl-like interfaces beween the drm code and nvkm, and that field will no longer exist.

This provides a safer replacement for accessing the nvkm_device, and will used more in upcoming patches to cleanup other cases.

v2:
- fixup printk macros to not oops if used before client ctor

---
 drivers/gpu/drm/nouveau/nouveau_drm.c |  8 +++-----
 drivers/gpu/drm/nouveau/nouveau_drv.h | 16 ++++++++++------
 2 files changed, 13 insertions(+), 11 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +3 -5
index f372bf2954aa..140e27af0d64 100644
@@ -751,6 +751,8 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
 	if (!drm)
 		return ERR_PTR(-ENOMEM);
 
+	drm->nvkm = device;
+
 	drm->dev = drm_dev_alloc(drm_driver, parent);
 	if (IS_ERR(drm->dev)) {
 		ret = PTR_ERR(drm->dev);
@@ -888,14 +890,10 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 void
 nouveau_drm_device_remove(struct nouveau_drm *drm)
 {
-	struct nvkm_client *client;
-	struct nvkm_device *device;
+	struct nvkm_device *device = drm->nvkm;
 
 	drm_dev_unplug(drm->dev);
 
-	client = nvxx_client(&drm->client.base);
-	device = nvkm_device_find(client->device);
-
 	nouveau_drm_device_fini(drm);
 	nouveau_drm_device_del(drm);
 	nvkm_device_del(&device);
drivers/gpu/drm/nouveau/nouveau_drv.h +10 -6
index 7e624c587fc0..e7d072a9a477 100644
@@ -201,6 +201,7 @@ u_memcpya(uint64_t user, unsigned int nmemb, unsigned int size)
 #include <nvif/parent.h>
 
 struct nouveau_drm {
+	struct nvkm_device *nvkm;
 	struct nvif_parent parent;
 	struct nouveau_cli master;
 	struct nouveau_cli client;
@@ -332,18 +333,21 @@ void nouveau_drm_device_remove(struct nouveau_drm *);
 	dev_##l(_cli->drm->dev->dev, "%s: "f, _cli->name, ##a);                \
 } while(0)
 
-#define NV_FATAL(drm,f,a...) NV_PRINTK(crit, &(drm)->client, f, ##a)
-#define NV_ERROR(drm,f,a...) NV_PRINTK(err, &(drm)->client, f, ##a)
-#define NV_WARN(drm,f,a...) NV_PRINTK(warn, &(drm)->client, f, ##a)
-#define NV_INFO(drm,f,a...) NV_PRINTK(info, &(drm)->client, f, ##a)
+#define NV_PRINTK_(l,drm,f,a...) do {             \
+	dev_##l((drm)->nvkm->dev, "drm: "f, ##a); \
+} while(0)
+#define NV_FATAL(drm,f,a...) NV_PRINTK_(crit, (drm), f, ##a)
+#define NV_ERROR(drm,f,a...) NV_PRINTK_(err, (drm), f, ##a)
+#define NV_WARN(drm,f,a...) NV_PRINTK_(warn, (drm), f, ##a)
+#define NV_INFO(drm,f,a...) NV_PRINTK_(info, (drm), f, ##a)
 
 #define NV_DEBUG(drm,f,a...) do {                                              \
 	if (drm_debug_enabled(DRM_UT_DRIVER))                                  \
-		NV_PRINTK(info, &(drm)->client, f, ##a);                       \
+		NV_PRINTK_(info, (drm), f, ##a);                               \
 } while(0)
 #define NV_ATOMIC(drm,f,a...) do {                                             \
 	if (drm_debug_enabled(DRM_UT_ATOMIC))                                  \
-		NV_PRINTK(info, &(drm)->client, f, ##a);                       \
+		NV_PRINTK_(info, (drm), f, ##a);                               \
 } while(0)
 
 #define NV_PRINTK_ONCE(l,c,f,a...) NV_PRINTK(l##_once,c,f, ##a)
Signature · 1 line
2.45.1
author
#18 lore raw

PATCH v2 6/37 drm/nouveau: move allocation of root client out of nouveau_cli_init()

In reply to Ben Skeggs

drm->master isn't really a nouveau_cli, and is mostly just used to get at an nvif_mmu object to implement a hack around issues with the ioctl interface to nvkm.

Later patches in this series will allocate nvif_device/mmu objects in nouveau_drm directly, removing the need for master.

Another patch series will remove the need for the above-mentioned hack entirely.

The only other member of drm->master that's needed is the nvif_client, and is a dependency of device/mmu. So the first step is to move its allocation out of code handling nouveau_cli init.

v2:
- modified slightly due to the addition of tegra/pci cleanup patches

---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 46 ++++++++++++++-------------
 1 file changed, 24 insertions(+), 22 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +24 -22
index 140e27af0d64..a942d2c03d44 100644
@@ -129,12 +129,12 @@ nouveau_platform_name(struct platform_device *platformdev)
 }
 
 static u64
-nouveau_name(struct drm_device *dev)
+nouveau_name(struct device *dev)
 {
-	if (dev_is_pci(dev->dev))
-		return nouveau_pci_name(to_pci_dev(dev->dev));
+	if (dev_is_pci(dev))
+		return nouveau_pci_name(to_pci_dev(dev));
 	else
-		return nouveau_platform_name(to_platform_device(dev->dev));
+		return nouveau_platform_name(to_platform_device(dev));
 }
 
 static inline bool
@@ -209,9 +209,11 @@ nouveau_cli_fini(struct nouveau_cli *cli)
 	nouveau_vmm_fini(&cli->vmm);
 	nvif_mmu_dtor(&cli->mmu);
 	nvif_device_dtor(&cli->device);
-	mutex_lock(&cli->drm->master.lock);
-	nvif_client_dtor(&cli->base);
-	mutex_unlock(&cli->drm->master.lock);
+	if (cli != &cli->drm->master) {
+		mutex_lock(&cli->drm->master.lock);
+		nvif_client_dtor(&cli->base);
+		mutex_unlock(&cli->drm->master.lock);
+	}
 }
 
 static int
@@ -241,7 +243,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 		{ NVIF_CLASS_VMM_NV04 , -1 },
 		{}
 	};
-	u64 device = nouveau_name(drm->dev);
+	u64 device = nouveau_name(drm->dev->dev);
 	int ret;
 
 	snprintf(cli->name, sizeof(cli->name), "%s", sname);
@@ -253,10 +255,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 	INIT_LIST_HEAD(&cli->worker);
 	mutex_init(&cli->lock);
 
-	if (cli == &drm->master) {
-		ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug,
-				       cli->name, device, &cli->base);
-	} else {
+	if (cli != &drm->master) {
 		mutex_lock(&drm->master.lock);
 		ret = nvif_client_ctor(&drm->master.base, cli->name, device,
 				       &cli->base);
@@ -626,7 +625,6 @@ nouveau_drm_device_fini(struct nouveau_drm *drm)
 	nouveau_cli_fini(&drm->client);
 	nouveau_cli_fini(&drm->master);
 	destroy_workqueue(drm->sched_wq);
-	nvif_parent_dtor(&drm->parent);
 	mutex_destroy(&drm->clients_lock);
 }
 
@@ -636,15 +634,10 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
 	struct drm_device *dev = drm->dev;
 	int ret;
 
-	nvif_parent_ctor(&nouveau_parent, &drm->parent);
-	drm->master.base.object.parent = &drm->parent;
-
 	drm->sched_wq = alloc_workqueue("nouveau_sched_wq_shared", 0,
 					WQ_MAX_ACTIVE);
-	if (!drm->sched_wq) {
-		ret = -ENOMEM;
-		goto fail_alloc;
-	}
+	if (!drm->sched_wq)
+		return -ENOMEM;
 
 	ret = nouveau_cli_init(drm, "DRM-master", &drm->master);
 	if (ret)
@@ -726,8 +719,6 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
 	nouveau_cli_fini(&drm->master);
 fail_wq:
 	destroy_workqueue(drm->sched_wq);
-fail_alloc:
-	nvif_parent_dtor(&drm->parent);
 	return ret;
 }
 
@@ -737,6 +728,9 @@ nouveau_drm_device_del(struct nouveau_drm *drm)
 	if (drm->dev)
 		drm_dev_put(drm->dev);
 
+	nvif_client_dtor(&drm->master.base);
+	nvif_parent_dtor(&drm->parent);
+
 	kfree(drm);
 }
 
@@ -753,6 +747,14 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
 
 	drm->nvkm = device;
 
+	nvif_parent_ctor(&nouveau_parent, &drm->parent);
+	drm->master.base.object.parent = &drm->parent;
+
+	ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug, "drm",
+			       nouveau_name(parent), &drm->master.base);
+	if (ret)
+		goto done;
+
 	drm->dev = drm_dev_alloc(drm_driver, parent);
 	if (IS_ERR(drm->dev)) {
 		ret = PTR_ERR(drm->dev);
Signature · 1 line
2.45.1
#19 lore raw

Re: [PATCH v2 06/37] drm/nouveau: move allocation of root client out of nouveau_cli_init()

Quoted 6 lines · Ben Skeggs

drm->master isn't really a nouveau_cli, and is mostly just used to get at an nvif_mmu object to implement a hack around issues with the ioctl interface to nvkm.

Later patches in this series will allocate nvif_device/mmu objects in nouveau_drm directly, removing the need for master.

Please don't use future tense.

Quoted 3 lines

Another patch series will remove the need for the above-mentioned hack entirely.

Do you have those patches already?

Quoted 21 lines

The only other member of drm->master that's needed is the nvif_client, and is a dependency of device/mmu. So the first step is to move its allocation out of code handling nouveau_cli init.

v2:
- modified slightly due to the addition of tegra/pci cleanup patches

---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 46 ++++++++++++++-------------
 1 file changed, 24 insertions(+), 22 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -0
index 140e27af0d64..a942d2c03d44 100644
@@ -129,12 +129,12 @@ nouveau_platform_name(struct platform_device *platformdev)
 }
 
 static u64

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_platform_name(struct platform_device *platformdev) · line 137

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +4 -4
-nouveau_name(struct drm_device *dev)
+nouveau_name(struct device *dev)
 {
-	if (dev_is_pci(dev->dev))
-		return nouveau_pci_name(to_pci_dev(dev->dev));
+	if (dev_is_pci(dev))
+		return nouveau_pci_name(to_pci_dev(dev));
 	else
-		return nouveau_platform_name(to_platform_device(dev->dev));
+		return nouveau_platform_name(to_platform_device(dev));

This looks like it should be a separate patch.

Quoted 48 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +7 -9
 }
 
 static inline bool
@@ -209,9 +209,11 @@ nouveau_cli_fini(struct nouveau_cli *cli)
 	nouveau_vmm_fini(&cli->vmm);
 	nvif_mmu_dtor(&cli->mmu);
 	nvif_device_dtor(&cli->device);
-	mutex_lock(&cli->drm->master.lock);
-	nvif_client_dtor(&cli->base);
-	mutex_unlock(&cli->drm->master.lock);
+	if (cli != &cli->drm->master) {
+		mutex_lock(&cli->drm->master.lock);
+		nvif_client_dtor(&cli->base);
+		mutex_unlock(&cli->drm->master.lock);
+	}
 }
 
 static int
@@ -241,7 +243,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 		{ NVIF_CLASS_VMM_NV04 , -1 },
 		{}
 	};
-	u64 device = nouveau_name(drm->dev);
+	u64 device = nouveau_name(drm->dev->dev);
 	int ret;
 
 	snprintf(cli->name, sizeof(cli->name), "%s", sname);
@@ -253,10 +255,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 	INIT_LIST_HEAD(&cli->worker);
 	mutex_init(&cli->lock);
 
-	if (cli == &drm->master) {
-		ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug,
-				       cli->name, device, &cli->base);
-	} else {
+	if (cli != &drm->master) {
 		mutex_lock(&drm->master.lock);
 		ret = nvif_client_ctor(&drm->master.base, cli->name, device,
 				       &cli->base);
@@ -626,7 +625,6 @@ nouveau_drm_device_fini(struct nouveau_drm *drm)
 	nouveau_cli_fini(&drm->client);
 	nouveau_cli_fini(&drm->master);
 	destroy_workqueue(drm->sched_wq);
-	nvif_parent_dtor(&drm->parent);
 	mutex_destroy(&drm->clients_lock);
 }
 

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_drm_device_init(struct nouveau_drm *drm) · line 640

Quoted 5 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -2
@@ -636,15 +634,10 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
 	struct drm_device *dev = drm->dev;
 	int ret;
 
-	nvif_parent_ctor(&nouveau_parent, &drm->parent);
-	drm->master.base.object.parent = &drm->parent;

Moving this to nouveau_drm_device_new(), plus the resulting changes in error handling, don't seem to be related to this commit either.

Quoted 49 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +13 -7
-
 	drm->sched_wq = alloc_workqueue("nouveau_sched_wq_shared", 0,
 					WQ_MAX_ACTIVE);
-	if (!drm->sched_wq) {
-		ret = -ENOMEM;
-		goto fail_alloc;
-	}
+	if (!drm->sched_wq)
+		return -ENOMEM;
 
 	ret = nouveau_cli_init(drm, "DRM-master", &drm->master);
 	if (ret)
@@ -726,8 +719,6 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
 	nouveau_cli_fini(&drm->master);
 fail_wq:
 	destroy_workqueue(drm->sched_wq);
-fail_alloc:
-	nvif_parent_dtor(&drm->parent);
 	return ret;
 }
 
@@ -737,6 +728,9 @@ nouveau_drm_device_del(struct nouveau_drm *drm)
 	if (drm->dev)
 		drm_dev_put(drm->dev);
 
+	nvif_client_dtor(&drm->master.base);
+	nvif_parent_dtor(&drm->parent);
+
 	kfree(drm);
 }
 
@@ -753,6 +747,14 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
 
 	drm->nvkm = device;
 
+	nvif_parent_ctor(&nouveau_parent, &drm->parent);
+	drm->master.base.object.parent = &drm->parent;
+
+	ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug, "drm",
+			       nouveau_name(parent), &drm->master.base);
+	if (ret)
+		goto done;
+
 	drm->dev = drm_dev_alloc(drm_driver, parent);
 	if (IS_ERR(drm->dev)) {
 		ret = PTR_ERR(drm->dev);
Signature · 1 line
2.45.1
author
#20 lore raw

Re: [PATCH v2 06/37] drm/nouveau: move allocation of root client out of nouveau_cli_init()

Quoted 5 lines · Danilo Krummrich
Quoted 4 lines · Ben Skeggs

drm->master isn't really a nouveau_cli, and is mostly just used to get at an nvif_mmu object to implement a hack around issues with the ioctl interface to nvkm.

Quoted 7 lines
Quoted 2 lines

Later patches in this series will allocate nvif_device/mmu objects in nouveau_drm directly, removing the need for master.

Please don't use future tense.

Quoted 2 lines

Another patch series will remove the need for the above-mentioned hack entirely.

Do you have those patches already?

Yes.  It's the "remove-ioctl" series, of which this one used to be a part of.  I've mentioned it in the updated commit message regardless.

Quoted 20 lines
Quoted 20 lines

The only other member of drm->master that's needed is the nvif_client, and is a dependency of device/mmu. So the first step is to move its allocation out of code handling nouveau_cli init.

v2:
- modified slightly due to the addition of tegra/pci cleanup patches

---
  drivers/gpu/drm/nouveau/nouveau_drm.c | 46 ++++++++++++++-------------
  1 file changed, 24 insertions(+), 22 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -0
index 140e27af0d64..a942d2c03d44 100644
@@ -129,12 +129,12 @@ nouveau_platform_name(struct platform_device *platformdev)
  }
 
Quoted 12 lines

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_platform_name(struct platform_device *platformdev) · line 137

Quoted 11 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +4 -4
  static u64
-nouveau_name(struct drm_device *dev)
+nouveau_name(struct device *dev)
  {
-	if (dev_is_pci(dev->dev))
-		return nouveau_pci_name(to_pci_dev(dev->dev));
+	if (dev_is_pci(dev))
+		return nouveau_pci_name(to_pci_dev(dev));
  	else
-		return nouveau_platform_name(to_platform_device(dev->dev));
+		return nouveau_platform_name(to_platform_device(dev));

This looks like it should be a separate patch.

No.  One of its callers is now before drm_device.dev is valid. Also, the remove-ioctl series removes these functions entirely.

Quoted 48 lines
Quoted 48 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +7 -9
  }
 
  static inline bool
@@ -209,9 +209,11 @@ nouveau_cli_fini(struct nouveau_cli *cli)
  	nouveau_vmm_fini(&cli->vmm);
  	nvif_mmu_dtor(&cli->mmu);
  	nvif_device_dtor(&cli->device);
-	mutex_lock(&cli->drm->master.lock);
-	nvif_client_dtor(&cli->base);
-	mutex_unlock(&cli->drm->master.lock);
+	if (cli != &cli->drm->master) {
+		mutex_lock(&cli->drm->master.lock);
+		nvif_client_dtor(&cli->base);
+		mutex_unlock(&cli->drm->master.lock);
+	}
  }
 
  static int
@@ -241,7 +243,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
  		{ NVIF_CLASS_VMM_NV04 , -1 },
  		{}
  	};
-	u64 device = nouveau_name(drm->dev);
+	u64 device = nouveau_name(drm->dev->dev);
  	int ret;
 
  	snprintf(cli->name, sizeof(cli->name), "%s", sname);
@@ -253,10 +255,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
  	INIT_LIST_HEAD(&cli->worker);
  	mutex_init(&cli->lock);
 
-	if (cli == &drm->master) {
-		ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug,
-				       cli->name, device, &cli->base);
-	} else {
+	if (cli != &drm->master) {
  		mutex_lock(&drm->master.lock);
  		ret = nvif_client_ctor(&drm->master.base, cli->name, device,
  				       &cli->base);
@@ -626,7 +625,6 @@ nouveau_drm_device_fini(struct nouveau_drm *drm)
  	nouveau_cli_fini(&drm->client);
  	nouveau_cli_fini(&drm->master);
  	destroy_workqueue(drm->sched_wq);
-	nvif_parent_dtor(&drm->parent);
  	mutex_destroy(&drm->clients_lock);
  }
 
Quoted 8 lines

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_drm_device_init(struct nouveau_drm *drm) · line 640

Quoted 6 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -2
@@ -636,15 +634,10 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
  	struct drm_device *dev = drm->dev;
  	int ret;
 
-	nvif_parent_ctor(&nouveau_parent, &drm->parent);
-	drm->master.base.object.parent = &drm->parent;

Moving this to nouveau_drm_device_new(), plus the resulting changes in error handling, don't seem to be related to this commit either.

They are, because they're needed by nvif printk macros, and as other nvif-related setup moves to this function, they'll oops without it.

Yes, the linkage between "parent" and master.base (nvif_client) is clumsy, but, once again, this is fixed in the remove-ioctl series.

Quoted 50 lines
Quoted 50 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +13 -7
-
  	drm->sched_wq = alloc_workqueue("nouveau_sched_wq_shared", 0,
  					WQ_MAX_ACTIVE);
-	if (!drm->sched_wq) {
-		ret = -ENOMEM;
-		goto fail_alloc;
-	}
+	if (!drm->sched_wq)
+		return -ENOMEM;
 
  	ret = nouveau_cli_init(drm, "DRM-master", &drm->master);
  	if (ret)
@@ -726,8 +719,6 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
  	nouveau_cli_fini(&drm->master);
  fail_wq:
  	destroy_workqueue(drm->sched_wq);
-fail_alloc:
-	nvif_parent_dtor(&drm->parent);
  	return ret;
  }
 
@@ -737,6 +728,9 @@ nouveau_drm_device_del(struct nouveau_drm *drm)
  	if (drm->dev)
  		drm_dev_put(drm->dev);
 
+	nvif_client_dtor(&drm->master.base);
+	nvif_parent_dtor(&drm->parent);
+
  	kfree(drm);
  }
 
@@ -753,6 +747,14 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
 
  	drm->nvkm = device;
 
+	nvif_parent_ctor(&nouveau_parent, &drm->parent);
+	drm->master.base.object.parent = &drm->parent;
+
+	ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug, "drm",
+			       nouveau_name(parent), &drm->master.base);
+	if (ret)
+		goto done;
+
  	drm->dev = drm_dev_alloc(drm_driver, parent);
  	if (IS_ERR(drm->dev)) {
  		ret = PTR_ERR(drm->dev);
Signature · 1 line
2.45.1
#21 lore raw

Re: [PATCH v2 06/37] drm/nouveau: move allocation of root client out of nouveau_cli_init()

Quoted 51 lines · Ben Skeggs
Quoted 5 lines · Danilo Krummrich
Quoted 4 lines · Ben Skeggs

drm->master isn't really a nouveau_cli, and is mostly just used to get at an nvif_mmu object to implement a hack around issues with the ioctl interface to nvkm.

Quoted 7 lines
Quoted 2 lines

Later patches in this series will allocate nvif_device/mmu objects in nouveau_drm directly, removing the need for master.

Please don't use future tense.

Quoted 2 lines

Another patch series will remove the need for the above-mentioned hack entirely.

Do you have those patches already?

Yes.  It's the "remove-ioctl" series, of which this one used to be a part of.  I've mentioned it in the updated commit message regardless.

Quoted 23 lines
Quoted 23 lines

The only other member of drm->master that's needed is the nvif_client, and is a dependency of device/mmu. So the first step is to move its allocation out of code handling nouveau_cli init.

v2:
- modified slightly due to the addition of tegra/pci cleanup patches

---
  drivers/gpu/drm/nouveau/nouveau_drm.c | 46 ++++++++++++++-------------
  1 file changed, 24 insertions(+), 22 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -1
index 140e27af0d64..a942d2c03d44 100644
@@ -129,12 +129,12 @@ nouveau_platform_name(struct platform_device *platformdev)
  }
  static u64
-nouveau_name(struct drm_device *dev)
+nouveau_name(struct device *dev)
  {
Quoted 8 lines

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_platform_name(struct platform_device *platformdev) · line 137

Quoted 7 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +3 -3
-	if (dev_is_pci(dev->dev))
-		return nouveau_pci_name(to_pci_dev(dev->dev));
+	if (dev_is_pci(dev))
+		return nouveau_pci_name(to_pci_dev(dev));
  	else
-		return nouveau_platform_name(to_platform_device(dev->dev));
+		return nouveau_platform_name(to_platform_device(dev));

This looks like it should be a separate patch.

Quoted 1 line

No.  One of its callers is now before drm_device.dev is valid. Also, the

Which doesn't seem necessary. You could call drm_dev_alloc() before nvif_driver_init() in nouveau_drm_device_new(), can't you?

Quoted 1 line

remove-ioctl series removes these functions entirely.

Then why bother changing?

Quoted 53 lines
Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +7 -9
  }
  static inline bool
@@ -209,9 +209,11 @@ nouveau_cli_fini(struct nouveau_cli *cli)
  	nouveau_vmm_fini(&cli->vmm);
  	nvif_mmu_dtor(&cli->mmu);
  	nvif_device_dtor(&cli->device);
-	mutex_lock(&cli->drm->master.lock);
-	nvif_client_dtor(&cli->base);
-	mutex_unlock(&cli->drm->master.lock);
+	if (cli != &cli->drm->master) {
+		mutex_lock(&cli->drm->master.lock);
+		nvif_client_dtor(&cli->base);
+		mutex_unlock(&cli->drm->master.lock);
+	}
  }
  static int
@@ -241,7 +243,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
  		{ NVIF_CLASS_VMM_NV04 , -1 },
  		{}
  	};
-	u64 device = nouveau_name(drm->dev);
+	u64 device = nouveau_name(drm->dev->dev);
  	int ret;
  	snprintf(cli->name, sizeof(cli->name), "%s", sname);
@@ -253,10 +255,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
  	INIT_LIST_HEAD(&cli->worker);
  	mutex_init(&cli->lock);
-	if (cli == &drm->master) {
-		ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug,
-				       cli->name, device, &cli->base);
-	} else {
+	if (cli != &drm->master) {
  		mutex_lock(&drm->master.lock);
  		ret = nvif_client_ctor(&drm->master.base, cli->name, device,
  				       &cli->base);
@@ -626,7 +625,6 @@ nouveau_drm_device_fini(struct nouveau_drm *drm)
  	nouveau_cli_fini(&drm->client);
  	nouveau_cli_fini(&drm->master);
  	destroy_workqueue(drm->sched_wq);
-	nvif_parent_dtor(&drm->parent);
  	mutex_destroy(&drm->clients_lock);
Quoted 8 lines

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_drm_device_init(struct nouveau_drm *drm) · line 639

Quoted 6 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -2
  }
@@ -636,15 +634,10 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
  	struct drm_device *dev = drm->dev;
  	int ret;
-	nvif_parent_ctor(&nouveau_parent, &drm->parent);
-	drm->master.base.object.parent = &drm->parent;

Moving this to nouveau_drm_device_new(), plus the resulting changes in error handling, don't seem to be related to this commit either.

Quoted 2 lines

They are, because they're needed by nvif printk macros, and as other nvif-related setup moves to this function, they'll oops without it.

Such things definitely deserve a comment, this is not obvious.

Quoted 3 lines

Yes, the linkage between "parent" and master.base (nvif_client) is clumsy, but, once again, this is fixed in the remove-ioctl series.

Less important if removed later on, but you still want to make it obvious to the reviewers that what you are doing is required and the "right" thing to do.

Quoted 46 lines
Quoted 45 lines
Quoted 45 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +13 -7
-
  	drm->sched_wq = alloc_workqueue("nouveau_sched_wq_shared", 0,
  					WQ_MAX_ACTIVE);
-	if (!drm->sched_wq) {
-		ret = -ENOMEM;
-		goto fail_alloc;
-	}
+	if (!drm->sched_wq)
+		return -ENOMEM;
  	ret = nouveau_cli_init(drm, "DRM-master", &drm->master);
  	if (ret)
@@ -726,8 +719,6 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
  	nouveau_cli_fini(&drm->master);
  fail_wq:
  	destroy_workqueue(drm->sched_wq);
-fail_alloc:
-	nvif_parent_dtor(&drm->parent);
  	return ret;
  }
@@ -737,6 +728,9 @@ nouveau_drm_device_del(struct nouveau_drm *drm)
  	if (drm->dev)
  		drm_dev_put(drm->dev);
+	nvif_client_dtor(&drm->master.base);
+	nvif_parent_dtor(&drm->parent);
+
  	kfree(drm);
  }
@@ -753,6 +747,14 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
  	drm->nvkm = device;
+	nvif_parent_ctor(&nouveau_parent, &drm->parent);
+	drm->master.base.object.parent = &drm->parent;
+
+	ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug, "drm",
+			       nouveau_name(parent), &drm->master.base);
+	if (ret)
+		goto done;
+
  	drm->dev = drm_dev_alloc(drm_driver, parent);
  	if (IS_ERR(drm->dev)) {
  		ret = PTR_ERR(drm->dev);
Signature · 1 line
2.45.1
author
#22 lore raw

Re: [PATCH v2 06/37] drm/nouveau: move allocation of root client out of nouveau_cli_init()

Quoted 49 lines · Danilo Krummrich
Quoted 48 lines · Ben Skeggs
Quoted 5 lines · Danilo Krummrich
Quoted 4 lines · Ben Skeggs

drm->master isn't really a nouveau_cli, and is mostly just used to get at an nvif_mmu object to implement a hack around issues with the ioctl interface to nvkm.

Quoted 7 lines
Quoted 2 lines

Later patches in this series will allocate nvif_device/mmu objects in nouveau_drm directly, removing the need for master.

Please don't use future tense.

Quoted 2 lines

Another patch series will remove the need for the above-mentioned hack entirely.

Do you have those patches already?

Yes.  It's the "remove-ioctl" series, of which this one used to be a part of.  I've mentioned it in the updated commit message regardless.

Quoted 30 lines
Quoted 19 lines

The only other member of drm->master that's needed is the nvif_client, and is a dependency of device/mmu. So the first step is to move its allocation out of code handling nouveau_cli init.

v2:
- modified slightly due to the addition of tegra/pci cleanup patches

---
   drivers/gpu/drm/nouveau/nouveau_drm.c | 46 ++++++++++++++-------------
   1 file changed, 24 insertions(+), 22 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -0
index 140e27af0d64..a942d2c03d44 100644
@@ -129,12 +129,12 @@ nouveau_platform_name(struct platform_device *platformdev)
   }
   static u64

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_platform_name(struct platform_device *platformdev) · line 136

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +4 -4
-nouveau_name(struct drm_device *dev)
+nouveau_name(struct device *dev)
   {
-	if (dev_is_pci(dev->dev))
-		return nouveau_pci_name(to_pci_dev(dev->dev));
+	if (dev_is_pci(dev))
+		return nouveau_pci_name(to_pci_dev(dev));
   	else
-		return nouveau_platform_name(to_platform_device(dev->dev));
+		return nouveau_platform_name(to_platform_device(dev));

This looks like it should be a separate patch.

Quoted 3 lines
Quoted 1 line

No.  One of its callers is now before drm_device.dev is valid. Also, the

Which doesn't seem necessary. You could call drm_dev_alloc() before nvif_driver_init() in nouveau_drm_device_new(), can't you?

True.  I've made this change.

Quoted 106 lines
Quoted 2 lines

remove-ioctl series removes these functions entirely.

Then why bother changing?

Quoted 50 lines
Quoted 42 lines
Quoted 42 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +7 -9
   }
   static inline bool
@@ -209,9 +209,11 @@ nouveau_cli_fini(struct nouveau_cli *cli)
   	nouveau_vmm_fini(&cli->vmm);
   	nvif_mmu_dtor(&cli->mmu);
   	nvif_device_dtor(&cli->device);
-	mutex_lock(&cli->drm->master.lock);
-	nvif_client_dtor(&cli->base);
-	mutex_unlock(&cli->drm->master.lock);
+	if (cli != &cli->drm->master) {
+		mutex_lock(&cli->drm->master.lock);
+		nvif_client_dtor(&cli->base);
+		mutex_unlock(&cli->drm->master.lock);
+	}
   }
   static int
@@ -241,7 +243,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
   		{ NVIF_CLASS_VMM_NV04 , -1 },
   		{}
   	};
-	u64 device = nouveau_name(drm->dev);
+	u64 device = nouveau_name(drm->dev->dev);
   	int ret;
   	snprintf(cli->name, sizeof(cli->name), "%s", sname);
@@ -253,10 +255,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
   	INIT_LIST_HEAD(&cli->worker);
   	mutex_init(&cli->lock);
-	if (cli == &drm->master) {
-		ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug,
-				       cli->name, device, &cli->base);
-	} else {
+	if (cli != &drm->master) {
   		mutex_lock(&drm->master.lock);
   		ret = nvif_client_ctor(&drm->master.base, cli->name, device,
   				       &cli->base);
@@ -626,7 +625,6 @@ nouveau_drm_device_fini(struct nouveau_drm *drm)
   	nouveau_cli_fini(&drm->client);
   	nouveau_cli_fini(&drm->master);
   	destroy_workqueue(drm->sched_wq);
-	nvif_parent_dtor(&drm->parent);
   	mutex_destroy(&drm->clients_lock);
Quoted 8 lines

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_drm_device_init(struct nouveau_drm *drm) · line 639

Quoted 6 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -2
   }
@@ -636,15 +634,10 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
   	struct drm_device *dev = drm->dev;
   	int ret;
-	nvif_parent_ctor(&nouveau_parent, &drm->parent);
-	drm->master.base.object.parent = &drm->parent;

Moving this to nouveau_drm_device_new(), plus the resulting changes in error handling, don't seem to be related to this commit either.

Quoted 2 lines

They are, because they're needed by nvif printk macros, and as other nvif-related setup moves to this function, they'll oops without it.

Such things definitely deserve a comment, this is not obvious.

Quoted 2 lines

Yes, the linkage between "parent" and master.base (nvif_client) is clumsy, but, once again, this is fixed in the remove-ioctl series.

Less important if removed later on, but you still want to make it obvious to the reviewers that what you are doing is required and the "right" thing to do.

Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +13 -7
-
   	drm->sched_wq = alloc_workqueue("nouveau_sched_wq_shared", 0,
   					WQ_MAX_ACTIVE);
-	if (!drm->sched_wq) {
-		ret = -ENOMEM;
-		goto fail_alloc;
-	}
+	if (!drm->sched_wq)
+		return -ENOMEM;
   	ret = nouveau_cli_init(drm, "DRM-master", &drm->master);
   	if (ret)
@@ -726,8 +719,6 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
   	nouveau_cli_fini(&drm->master);
   fail_wq:
   	destroy_workqueue(drm->sched_wq);
-fail_alloc:
-	nvif_parent_dtor(&drm->parent);
   	return ret;
   }
@@ -737,6 +728,9 @@ nouveau_drm_device_del(struct nouveau_drm *drm)
   	if (drm->dev)
   		drm_dev_put(drm->dev);
+	nvif_client_dtor(&drm->master.base);
+	nvif_parent_dtor(&drm->parent);
+
   	kfree(drm);
   }
@@ -753,6 +747,14 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
   	drm->nvkm = device;
+	nvif_parent_ctor(&nouveau_parent, &drm->parent);
+	drm->master.base.object.parent = &drm->parent;
+
+	ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug, "drm",
+			       nouveau_name(parent), &drm->master.base);
+	if (ret)
+		goto done;
+
   	drm->dev = drm_dev_alloc(drm_driver, parent);
   	if (IS_ERR(drm->dev)) {
   		ret = PTR_ERR(drm->dev);
Signature · 1 line
2.45.1
author
#23 lore raw

PATCH v2 7/37 drm/nouveau: add nouveau_cli to nouveau_abi16

In reply to Ben Skeggs

Removes some dubious void casts.

---
 drivers/gpu/drm/nouveau/nouveau_abi16.c | 9 +++++----
 drivers/gpu/drm/nouveau/nouveau_abi16.h | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/nouveau/nouveau_abi16.c +5 -4
index d56909071de6..ac50c300d2eb 100644
@@ -50,6 +50,7 @@ nouveau_abi16(struct drm_file *file_priv)
 				.device = ~0ULL,
 			};
 
+			abi16->cli = cli;
 			INIT_LIST_HEAD(&abi16->channels);
 
 			/* allocate device object targeting client's default
@@ -82,7 +83,7 @@ nouveau_abi16_get(struct drm_file *file_priv)
 int
 nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret)
 {
-	struct nouveau_cli *cli = (void *)abi16->device.object.client;
+	struct nouveau_cli *cli = abi16->cli;
 	mutex_unlock(&cli->mutex);
 	return ret;
 }
@@ -164,7 +165,7 @@ nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16,
 void
 nouveau_abi16_fini(struct nouveau_abi16 *abi16)
 {
-	struct nouveau_cli *cli = (void *)abi16->device.object.client;
+	struct nouveau_cli *cli = abi16->cli;
 	struct nouveau_abi16_chan *chan, *temp;
 
 	/* cleanup channels */
@@ -529,7 +530,7 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
 
 	if (init->handle == ~0)
 		return nouveau_abi16_put(abi16, -EINVAL);
-	client = abi16->device.object.client;
+	client = &abi16->cli->base;
 
 	chan = nouveau_abi16_chan(abi16, init->channel);
 	if (!chan)
@@ -623,7 +624,7 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
 	/* completely unnecessary for these chipsets... */
 	if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
 		return nouveau_abi16_put(abi16, -EINVAL);
-	client = abi16->device.object.client;
+	client = &abi16->cli->base;
 
 	chan = nouveau_abi16_chan(abi16, info->channel);
 	if (!chan)
drivers/gpu/drm/nouveau/nouveau_abi16.h +1 -0
index 661b901d8ecc..0a9121e63143 100644
@@ -30,6 +30,7 @@ struct nouveau_abi16_chan {
 };
 
 struct nouveau_abi16 {
+	struct nouveau_cli *cli;
 	struct nvif_device device;
 	struct list_head channels;
 	u64 handles;
Signature · 1 line
2.45.1
#24 lore raw

Re: [PATCH v2 07/37] drm/nouveau: add nouveau_cli to nouveau_abi16

Quoted 1 line · Ben Skeggs

Removes some dubious void casts.

Please use the imperative form:

"Store a pointer to struct nouveau_cli in struct nouveau_abi16 to avoid some dubious void casts."

Quoted 70 lines
---
 drivers/gpu/drm/nouveau/nouveau_abi16.c | 9 +++++----
 drivers/gpu/drm/nouveau/nouveau_abi16.h | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/nouveau/nouveau_abi16.c +5 -4
index d56909071de6..ac50c300d2eb 100644
@@ -50,6 +50,7 @@ nouveau_abi16(struct drm_file *file_priv)
 				.device = ~0ULL,
 			};
 
+			abi16->cli = cli;
 			INIT_LIST_HEAD(&abi16->channels);
 
 			/* allocate device object targeting client's default
@@ -82,7 +83,7 @@ nouveau_abi16_get(struct drm_file *file_priv)
 int
 nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret)
 {
-	struct nouveau_cli *cli = (void *)abi16->device.object.client;
+	struct nouveau_cli *cli = abi16->cli;
 	mutex_unlock(&cli->mutex);
 	return ret;
 }
@@ -164,7 +165,7 @@ nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16,
 void
 nouveau_abi16_fini(struct nouveau_abi16 *abi16)
 {
-	struct nouveau_cli *cli = (void *)abi16->device.object.client;
+	struct nouveau_cli *cli = abi16->cli;
 	struct nouveau_abi16_chan *chan, *temp;
 
 	/* cleanup channels */
@@ -529,7 +530,7 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
 
 	if (init->handle == ~0)
 		return nouveau_abi16_put(abi16, -EINVAL);
-	client = abi16->device.object.client;
+	client = &abi16->cli->base;
 
 	chan = nouveau_abi16_chan(abi16, init->channel);
 	if (!chan)
@@ -623,7 +624,7 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
 	/* completely unnecessary for these chipsets... */
 	if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
 		return nouveau_abi16_put(abi16, -EINVAL);
-	client = abi16->device.object.client;
+	client = &abi16->cli->base;
 
 	chan = nouveau_abi16_chan(abi16, info->channel);
 	if (!chan)
drivers/gpu/drm/nouveau/nouveau_abi16.h +1 -0
index 661b901d8ecc..0a9121e63143 100644
@@ -30,6 +30,7 @@ struct nouveau_abi16_chan {
 };
 
 struct nouveau_abi16 {
+	struct nouveau_cli *cli;
 	struct nvif_device device;
 	struct list_head channels;
 	u64 handles;
Signature · 1 line
2.45.1
author
#25 lore raw

PATCH v2 8/37 drm/nouveau: handle limited nvif ioctl in abi16

In reply to Ben Skeggs

nouveau_usif.c was already stripped right back a couple of years ago, limiting what userspace could do with it, and now I'd like to remove the nvkm side of these interfaces entirely, in order to make it less of a nightmare to add/change internal APIs in the future.

Unfortunately. Userspace uses some of this.

Fortunately, userspace only ever ended up using a fraction of the APIs, so I've reimplemented those in a more direct manner, and return -EINVAL to userspace for everything else.

v2:
- simplified struct nouveau_abi16_obj
- added a couple of comments

---
 drivers/gpu/drm/nouveau/Kbuild          |   1 -
 drivers/gpu/drm/nouveau/nouveau_abi16.c | 277 ++++++++++++++++++++----
 drivers/gpu/drm/nouveau/nouveau_abi16.h |   3 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c   |   5 +-
 drivers/gpu/drm/nouveau/nouveau_nvif.c  |   1 -
 drivers/gpu/drm/nouveau/nouveau_usif.c  | 194 -----------------
 drivers/gpu/drm/nouveau/nouveau_usif.h  |  10 -
 7 files changed, 242 insertions(+), 249 deletions(-)
 delete mode 100644 drivers/gpu/drm/nouveau/nouveau_usif.c
 delete mode 100644 drivers/gpu/drm/nouveau/nouveau_usif.h
drivers/gpu/drm/nouveau/Kbuild +0 -1
index c32c01827c1d..7b863355c5c6 100644
@@ -25,7 +25,6 @@ nouveau-$(CONFIG_COMPAT) += nouveau_ioc32.o
 nouveau-$(CONFIG_LEDS_CLASS) += nouveau_led.o
 nouveau-y += nouveau_nvif.o
 nouveau-$(CONFIG_NOUVEAU_PLATFORM_DRIVER) += nouveau_platform.o
-nouveau-y += nouveau_usif.o # userspace <-> nvif
 nouveau-y += nouveau_vga.o
 
 # DRM - memory management
drivers/gpu/drm/nouveau/nouveau_abi16.c +239 -38

304 lines not on this page · raw message

drivers/gpu/drm/nouveau/nouveau_abi16.h +2 -1
index 0a9121e63143..75a883a44e04 100644
@@ -34,13 +34,14 @@ struct nouveau_abi16 {
 	struct nvif_device device;
 	struct list_head channels;
 	u64 handles;
+	struct list_head objects;
 };
 
 struct nouveau_abi16 *nouveau_abi16_get(struct drm_file *);
 int  nouveau_abi16_put(struct nouveau_abi16 *, int);
 void nouveau_abi16_fini(struct nouveau_abi16 *);
 s32  nouveau_abi16_swclass(struct nouveau_drm *);
-int  nouveau_abi16_usif(struct drm_file *, void *data, u32 size);
+int nouveau_abi16_ioctl(struct drm_file *, void __user *user, u32 size);
 
 #define NOUVEAU_GEM_DOMAIN_VRAM      (1 << 1)
 #define NOUVEAU_GEM_DOMAIN_GART      (1 << 2)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -4
index a942d2c03d44..6726f463d2d3 100644
@@ -63,7 +63,6 @@
 #include "nouveau_abi16.h"
 #include "nouveau_fence.h"
 #include "nouveau_debugfs.h"
-#include "nouveau_usif.h"
 #include "nouveau_connector.h"
 #include "nouveau_platform.h"
 #include "nouveau_svm.h"
@@ -200,7 +199,6 @@ nouveau_cli_fini(struct nouveau_cli *cli)
 	flush_work(&cli->work);
 	WARN_ON(!list_empty(&cli->worker));
 
-	usif_client_fini(cli);
 	if (cli->sched)
 		nouveau_sched_destroy(&cli->sched);
 	if (uvmm)
@@ -249,7 +247,6 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 	snprintf(cli->name, sizeof(cli->name), "%s", sname);
 	cli->drm = drm;
 	mutex_init(&cli->mutex);
-	usif_client_init(cli);
 
 	INIT_WORK(&cli->work, nouveau_cli_work);
 	INIT_LIST_HEAD(&cli->worker);
@@ -1267,7 +1264,7 @@ nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
 	switch (_IOC_NR(cmd) - DRM_COMMAND_BASE) {
 	case DRM_NOUVEAU_NVIF:
-		ret = usif_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
+		ret = nouveau_abi16_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
 		break;
 	default:
 		ret = drm_ioctl(file, cmd, arg);
drivers/gpu/drm/nouveau/nouveau_nvif.c +0 -1
index 1d49ebdfd5dc..9a7e3f64b79f 100644
@@ -35,7 +35,6 @@
 #include <nvif/ioctl.h>
 
 #include "nouveau_drv.h"
-#include "nouveau_usif.h"
 
 static void
 nvkm_client_unmap(void *priv, void __iomem *ptr, u32 size)
drivers/gpu/drm/nouveau/nouveau_usif.c deleted +0 -194

194 lines not on this page · raw message

drivers/gpu/drm/nouveau/nouveau_usif.h deleted +0 -10
deleted file mode 100644
index dc90d4a9d0d9..000000000000
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-#ifndef __NOUVEAU_USIF_H__
-#define __NOUVEAU_USIF_H__
-
-void usif_client_init(struct nouveau_cli *);
-void usif_client_fini(struct nouveau_cli *);
-int  usif_ioctl(struct drm_file *, void __user *, u32);
-int  usif_notify(const void *, u32, const void *, u32);
-
-#endif
Signature · 1 line
2.45.1
#26 lore raw

Re: [PATCH v2 08/37] drm/nouveau: handle limited nvif ioctl in abi16

Quoted 10 lines · Ben Skeggs

nouveau_usif.c was already stripped right back a couple of years ago, limiting what userspace could do with it, and now I'd like to remove the nvkm side of these interfaces entirely, in order to make it less of a nightmare to add/change internal APIs in the future.

Unfortunately. Userspace uses some of this.

Fortunately, userspace only ever ended up using a fraction of the APIs, so I've reimplemented those in a more direct manner, and return -EINVAL to userspace for everything else.

Please use imperative form.

Quoted 43 lines

v2:
- simplified struct nouveau_abi16_obj
- added a couple of comments

---
 drivers/gpu/drm/nouveau/Kbuild          |   1 -
 drivers/gpu/drm/nouveau/nouveau_abi16.c | 277 ++++++++++++++++++++----
 drivers/gpu/drm/nouveau/nouveau_abi16.h |   3 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c   |   5 +-
 drivers/gpu/drm/nouveau/nouveau_nvif.c  |   1 -
 drivers/gpu/drm/nouveau/nouveau_usif.c  | 194 -----------------
 drivers/gpu/drm/nouveau/nouveau_usif.h  |  10 -
 7 files changed, 242 insertions(+), 249 deletions(-)
 delete mode 100644 drivers/gpu/drm/nouveau/nouveau_usif.c
 delete mode 100644 drivers/gpu/drm/nouveau/nouveau_usif.h
drivers/gpu/drm/nouveau/Kbuild +0 -1
index c32c01827c1d..7b863355c5c6 100644
@@ -25,7 +25,6 @@ nouveau-$(CONFIG_COMPAT) += nouveau_ioc32.o
 nouveau-$(CONFIG_LEDS_CLASS) += nouveau_led.o
 nouveau-y += nouveau_nvif.o
 nouveau-$(CONFIG_NOUVEAU_PLATFORM_DRIVER) += nouveau_platform.o
-nouveau-y += nouveau_usif.o # userspace <-> nvif
 nouveau-y += nouveau_vga.o
 
 # DRM - memory management
drivers/gpu/drm/nouveau/nouveau_abi16.c +1 -0
index ac50c300d2eb..f80d777cee5d 100644
@@ -52,6 +52,7 @@ nouveau_abi16(struct drm_file *file_priv)
 
 			abi16->cli = cli;
 			INIT_LIST_HEAD(&abi16->channels);
+			INIT_LIST_HEAD(&abi16->objects);
 
 			/* allocate device object targeting client's default
 			 * device (ie. the one that belongs to the fd it

drivers/gpu/drm/nouveau/nouveau_abi16.c nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret) · line 92

Quoted 4 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +1 -0
@@ -88,6 +89,58 @@ nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret)
 	return ret;
 }
 
+/* Tracks objects created via nvif_ioctl_v0 APIs. */

Here I asked about some documentation on the semantical meaning of this object, as in "What does it represent?".

The fact this it is created via some generic nvif_ioctl_v0 interface may be part of an explanation, but with only that information I doubt that anyone who does not know already) is capabale to make any sense of this structure.

Try to answer the following questions:

1. What kind of object does it track? What do they represent?
2. For generic objects, what would be examples for specific ones?
3. Where do the objects originate from?
4. What is a "DEVICE" object and what is an "ENGOBJ"? Do we have documentation we can point to already for that?

If we'd want to go even more crazy, we could ask:
1. Who owns those objects, once created?
2. What are their lifetime rules?
3. How do we ensure we don't violate lifetime rules?

Quoted 235 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +176 -38
+struct nouveau_abi16_obj {
+	enum nouveau_abi16_obj_type {
+		DEVICE,
+		ENGOBJ,
+	} type;
+	u64 object;
+
+	struct nvif_object engobj;
+
+	struct list_head head; /* protected by nouveau_abi16.cli.mutex */
+};
+
+static struct nouveau_abi16_obj *
+nouveau_abi16_obj_find(struct nouveau_abi16 *abi16, u64 object)
+{
+	struct nouveau_abi16_obj *obj;
+
+	list_for_each_entry(obj, &abi16->objects, head) {
+		if (obj->object == object)
+			return obj;
+	}
+
+	return NULL;
+}
+
+static void
+nouveau_abi16_obj_del(struct nouveau_abi16_obj *obj)
+{
+	list_del(&obj->head);
+	kfree(obj);
+}
+
+static struct nouveau_abi16_obj *
+nouveau_abi16_obj_new(struct nouveau_abi16 *abi16, enum nouveau_abi16_obj_type type, u64 object)
+{
+	struct nouveau_abi16_obj *obj;
+
+	obj = nouveau_abi16_obj_find(abi16, object);
+	if (obj)
+		return ERR_PTR(-EEXIST);
+
+	obj = kzalloc(sizeof(*obj), GFP_KERNEL);
+	if (!obj)
+		return ERR_PTR(-ENOMEM);
+
+	obj->type = type;
+	obj->object = object;
+	list_add_tail(&obj->head, &abi16->objects);
+	return obj;
+}
+
 s32
 nouveau_abi16_swclass(struct nouveau_drm *drm)
 {
@@ -167,6 +220,12 @@ nouveau_abi16_fini(struct nouveau_abi16 *abi16)
 {
 	struct nouveau_cli *cli = abi16->cli;
 	struct nouveau_abi16_chan *chan, *temp;
+	struct nouveau_abi16_obj *obj, *tmp;
+
+	/* cleanup objects */
+	list_for_each_entry_safe(obj, tmp, &abi16->objects, head) {
+		nouveau_abi16_obj_del(obj);
+	}
 
 	/* cleanup channels */
 	list_for_each_entry_safe(chan, temp, &abi16->channels, head) {
@@ -458,44 +517,6 @@ nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel)
 	return NULL;
 }
 
-int
-nouveau_abi16_usif(struct drm_file *file_priv, void *data, u32 size)
-{
-	union {
-		struct nvif_ioctl_v0 v0;
-	} *args = data;
-	struct nouveau_abi16_chan *chan;
-	struct nouveau_abi16 *abi16;
-	int ret = -ENOSYS;
-
-	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
-		switch (args->v0.type) {
-		case NVIF_IOCTL_V0_NEW:
-		case NVIF_IOCTL_V0_MTHD:
-		case NVIF_IOCTL_V0_SCLASS:
-			break;
-		default:
-			return -EACCES;
-		}
-	} else
-		return ret;
-
-	if (!(abi16 = nouveau_abi16(file_priv)))
-		return -ENOMEM;
-
-	if (args->v0.token != ~0ULL) {
-		if (!(chan = nouveau_abi16_chan(abi16, args->v0.token)))
-			return -EINVAL;
-		args->v0.object = nvif_handle(&chan->chan->user);
-		args->v0.owner  = NVIF_IOCTL_V0_OWNER_ANY;
-		return 0;
-	}
-
-	args->v0.object = nvif_handle(&abi16->device.object);
-	args->v0.owner  = NVIF_IOCTL_V0_OWNER_ANY;
-	return 0;
-}
-
 int
 nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS)
 {
@@ -705,3 +726,183 @@ nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS)
 
 	return nouveau_abi16_put(abi16, ret);
 }
+
+static int
+nouveau_abi16_ioctl_mthd(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nouveau_cli *cli = abi16->cli;
+	struct nvif_ioctl_mthd_v0 *args;
+	struct nouveau_abi16_obj *obj;
+	struct nv_device_info_v0 *info;
+
+	if (ioctl->route || argc < sizeof(*args))
+		return -EINVAL;
+	args = (void *)ioctl->data;
+	argc -= sizeof(*args);
+
+	obj = nouveau_abi16_obj_find(abi16, ioctl->object);
+	if (!obj || obj->type != DEVICE)
+		return -EINVAL;
+
+	if (args->method != NV_DEVICE_V0_INFO ||
+	    argc != sizeof(*info))
+		return -EINVAL;
+
+	info = (void *)args->data;
+	if (info->version != 0x00)
+		return -EINVAL;
+
+	info = &cli->device.info;
+	memcpy(args->data, info, sizeof(*info));
+	return 0;
+}
+
+static int
+nouveau_abi16_ioctl_del(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nouveau_abi16_obj *obj;
+
+	if (ioctl->route || argc)
+		return -EINVAL;
+
+	obj = nouveau_abi16_obj_find(abi16, ioctl->object);
+	if (obj) {
+		if (obj->type == ENGOBJ)
+			nvif_object_dtor(&obj->engobj);
+		nouveau_abi16_obj_del(obj);
+	}
+
+	return 0;
+}
+
+static int
+nouveau_abi16_ioctl_new(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nvif_ioctl_new_v0 *args;
+	struct nouveau_abi16_chan *chan;
+	struct nouveau_abi16_obj *obj;
+	int ret;
+
+	if (argc < sizeof(*args))
+		return -EINVAL;
+	args = (void *)ioctl->data;
+	argc -= sizeof(*args);
+
+	if (args->version != 0)
+		return -EINVAL;
+
+	if (!ioctl->route) {
+		if (ioctl->object || args->oclass != NV_DEVICE)
+			return -EINVAL;
+
+		obj = nouveau_abi16_obj_new(abi16, DEVICE, args->object);
+		if (IS_ERR(obj))
+			return PTR_ERR(obj);
+
+		return 0;
+	}
+
+	chan = nouveau_abi16_chan(abi16, ioctl->token);
+	if (!chan)
+		return -EINVAL;
+
+	obj = nouveau_abi16_obj_new(abi16, ENGOBJ, args->object);
+	if (IS_ERR(obj))
+		return PTR_ERR(obj);
+
+	ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", args->handle, args->oclass,
+			       NULL, 0, &obj->engobj);
+	if (ret)
+		nouveau_abi16_obj_del(obj);
+
+	return ret;
+}
+
+static int
+nouveau_abi16_ioctl_sclass(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nvif_ioctl_sclass_v0 *args;
+	struct nouveau_abi16_chan *chan;
+	struct nvif_sclass *sclass;
+	int ret;
+
+	if (!ioctl->route || argc < sizeof(*args))
+		return -EINVAL;
+	args = (void *)ioctl->data;
+	argc -= sizeof(*args);
+
+	if (argc != args->count * sizeof(args->oclass[0]))
+		return -EINVAL;
+
+	chan = nouveau_abi16_chan(abi16, ioctl->token);
+	if (!chan)
+		return -EINVAL;
+
+	ret = nvif_object_sclass_get(&chan->chan->user, &sclass);
+	if (ret < 0)
+		return ret;
+
+	for (int i = 0; i < min_t(u8, args->count, ret); i++) {
+		args->oclass[i].oclass = sclass[i].oclass;
+		args->oclass[i].minver = sclass[i].minver;

drivers/gpu/drm/nouveau/nouveau_abi16.c nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS) · line 857

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +10 -0
+		args->oclass[i].maxver = sclass[i].maxver;
+	}
+	args->count = ret;
+
+	nvif_object_sclass_put(&sclass);
+	return 0;
+}
+
+int
+nouveau_abi16_ioctl(struct drm_file *filp, void __user *user, u32 size)

Actually, it would also be good to add documentation on what this uAPI provides and how it works. But since this patch just moves things over, I don't think it's required for this patch.

Quoted 339 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +51 -0
+{
+	struct nvif_ioctl_v0 *ioctl;
+	struct nouveau_abi16 *abi16;
+	u32 argc = size;
+	int ret;
+
+	if (argc < sizeof(*ioctl))
+		return -EINVAL;
+	argc -= sizeof(*ioctl);
+
+	ioctl = kmalloc(size, GFP_KERNEL);
+	if (!ioctl)
+		return -ENOMEM;
+
+	ret = -EFAULT;
+	if (copy_from_user(ioctl, user, size))
+		goto done_free;
+
+	if (ioctl->version != 0x00 ||
+	    (ioctl->route && ioctl->route != 0xff)) {
+		ret = -EINVAL;
+		goto done_free;
+	}
+
+	abi16 = nouveau_abi16_get(filp);
+	if (unlikely(!abi16)) {
+		ret = -ENOMEM;
+		goto done_free;
+	}
+
+	switch (ioctl->type) {
+	case NVIF_IOCTL_V0_SCLASS: ret = nouveau_abi16_ioctl_sclass(abi16, ioctl, argc); break;
+	case NVIF_IOCTL_V0_NEW   : ret = nouveau_abi16_ioctl_new   (abi16, ioctl, argc); break;
+	case NVIF_IOCTL_V0_DEL   : ret = nouveau_abi16_ioctl_del   (abi16, ioctl, argc); break;
+	case NVIF_IOCTL_V0_MTHD  : ret = nouveau_abi16_ioctl_mthd  (abi16, ioctl, argc); break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	nouveau_abi16_put(abi16, 0);
+
+	if (ret == 0) {
+		if (copy_to_user(user, ioctl, size))
+			ret = -EFAULT;
+	}
+
+done_free:
+	kfree(ioctl);
+	return ret;
+}
drivers/gpu/drm/nouveau/nouveau_abi16.h +2 -1
index 0a9121e63143..75a883a44e04 100644
@@ -34,13 +34,14 @@ struct nouveau_abi16 {
 	struct nvif_device device;
 	struct list_head channels;
 	u64 handles;
+	struct list_head objects;
 };
 
 struct nouveau_abi16 *nouveau_abi16_get(struct drm_file *);
 int  nouveau_abi16_put(struct nouveau_abi16 *, int);
 void nouveau_abi16_fini(struct nouveau_abi16 *);
 s32  nouveau_abi16_swclass(struct nouveau_drm *);
-int  nouveau_abi16_usif(struct drm_file *, void *data, u32 size);
+int nouveau_abi16_ioctl(struct drm_file *, void __user *user, u32 size);
 
 #define NOUVEAU_GEM_DOMAIN_VRAM      (1 << 1)
 #define NOUVEAU_GEM_DOMAIN_GART      (1 << 2)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -4
index a942d2c03d44..6726f463d2d3 100644
@@ -63,7 +63,6 @@
 #include "nouveau_abi16.h"
 #include "nouveau_fence.h"
 #include "nouveau_debugfs.h"
-#include "nouveau_usif.h"
 #include "nouveau_connector.h"
 #include "nouveau_platform.h"
 #include "nouveau_svm.h"
@@ -200,7 +199,6 @@ nouveau_cli_fini(struct nouveau_cli *cli)
 	flush_work(&cli->work);
 	WARN_ON(!list_empty(&cli->worker));
 
-	usif_client_fini(cli);
 	if (cli->sched)
 		nouveau_sched_destroy(&cli->sched);
 	if (uvmm)
@@ -249,7 +247,6 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 	snprintf(cli->name, sizeof(cli->name), "%s", sname);
 	cli->drm = drm;
 	mutex_init(&cli->mutex);
-	usif_client_init(cli);
 
 	INIT_WORK(&cli->work, nouveau_cli_work);
 	INIT_LIST_HEAD(&cli->worker);
@@ -1267,7 +1264,7 @@ nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
 	switch (_IOC_NR(cmd) - DRM_COMMAND_BASE) {
 	case DRM_NOUVEAU_NVIF:
-		ret = usif_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
+		ret = nouveau_abi16_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
 		break;
 	default:
 		ret = drm_ioctl(file, cmd, arg);
drivers/gpu/drm/nouveau/nouveau_nvif.c +0 -1
index 1d49ebdfd5dc..9a7e3f64b79f 100644
@@ -35,7 +35,6 @@
 #include <nvif/ioctl.h>
 
 #include "nouveau_drv.h"
-#include "nouveau_usif.h"
 
 static void
 nvkm_client_unmap(void *priv, void __iomem *ptr, u32 size)
drivers/gpu/drm/nouveau/nouveau_usif.c deleted +0 -194
deleted file mode 100644
index 002d1479ba89..000000000000
@@ -1,194 +0,0 @@
-/*
- * Copyright 2014 Red Hat Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: Ben Skeggs <[email protected]>
- */
-
-#include "nouveau_drv.h"
-#include "nouveau_usif.h"
-#include "nouveau_abi16.h"
-
-#include <nvif/unpack.h>
-#include <nvif/client.h>
-#include <nvif/ioctl.h>
-
-#include <nvif/class.h>
-#include <nvif/cl0080.h>
-
-struct usif_object {
-	struct list_head head;
-	u8  route;
-	u64 token;
-};
-
-static void
-usif_object_dtor(struct usif_object *object)
-{
-	list_del(&object->head);
-	kfree(object);
-}
-
-static int
-usif_object_new(struct drm_file *f, void *data, u32 size, void *argv, u32 argc, bool parent_abi16)
-{
-	struct nouveau_cli *cli = nouveau_cli(f);
-	struct nvif_client *client = &cli->base;
-	union {
-		struct nvif_ioctl_new_v0 v0;
-	} *args = data;
-	struct usif_object *object;
-	int ret = -ENOSYS;
-
-	if ((ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true)))
-		return ret;
-
-	switch (args->v0.oclass) {
-	case NV_DMA_FROM_MEMORY:
-	case NV_DMA_TO_MEMORY:
-	case NV_DMA_IN_MEMORY:
-		return -EINVAL;
-	case NV_DEVICE: {
-		union {
-			struct nv_device_v0 v0;
-		} *args = data;
-
-		if ((ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false)))
-			return ret;
-
-		args->v0.priv = false;
-		break;
-	}
-	default:
-		if (!parent_abi16)
-			return -EINVAL;
-		break;
-	}
-
-	if (!(object = kmalloc(sizeof(*object), GFP_KERNEL)))
-		return -ENOMEM;
-	list_add(&object->head, &cli->objects);
-
-	object->route = args->v0.route;
-	object->token = args->v0.token;
-	args->v0.route = NVDRM_OBJECT_USIF;
-	args->v0.token = (unsigned long)(void *)object;
-	ret = nvif_client_ioctl(client, argv, argc);
-	if (ret) {
-		usif_object_dtor(object);
-		return ret;
-	}
-
-	args->v0.token = object->token;
-	args->v0.route = object->route;
-	return 0;
-}
-
-int
-usif_ioctl(struct drm_file *filp, void __user *user, u32 argc)
-{
-	struct nouveau_cli *cli = nouveau_cli(filp);
-	struct nvif_client *client = &cli->base;
-	void *data = kmalloc(argc, GFP_KERNEL);
-	u32   size = argc;
-	union {
-		struct nvif_ioctl_v0 v0;
-	} *argv = data;
-	struct usif_object *object;
-	bool abi16 = false;
-	u8 owner;
-	int ret;
-
-	if (ret = -ENOMEM, !argv)
-		goto done;
-	if (ret = -EFAULT, copy_from_user(argv, user, size))
-		goto done;
-
-	if (!(ret = nvif_unpack(-ENOSYS, &data, &size, argv->v0, 0, 0, true))) {
-		/* block access to objects not created via this interface */
-		owner = argv->v0.owner;
-		if (argv->v0.object == 0ULL &&
-		    argv->v0.type != NVIF_IOCTL_V0_DEL)
-			argv->v0.owner = NVDRM_OBJECT_ANY; /* except client */
-		else
-			argv->v0.owner = NVDRM_OBJECT_USIF;
-	} else
-		goto done;
-
-	/* USIF slightly abuses some return-only ioctl members in order
-	 * to provide interoperability with the older ABI16 objects
-	 */
-	mutex_lock(&cli->mutex);
-	if (argv->v0.route) {
-		if (ret = -EINVAL, argv->v0.route == 0xff)
-			ret = nouveau_abi16_usif(filp, argv, argc);
-		if (ret) {
-			mutex_unlock(&cli->mutex);
-			goto done;
-		}
-
-		abi16 = true;
-	}
-
-	switch (argv->v0.type) {
-	case NVIF_IOCTL_V0_NEW:
-		ret = usif_object_new(filp, data, size, argv, argc, abi16);
-		break;
-	default:
-		ret = nvif_client_ioctl(client, argv, argc);
-		break;
-	}
-	if (argv->v0.route == NVDRM_OBJECT_USIF) {
-		object = (void *)(unsigned long)argv->v0.token;
-		argv->v0.route = object->route;
-		argv->v0.token = object->token;
-		if (ret == 0 && argv->v0.type == NVIF_IOCTL_V0_DEL) {
-			list_del(&object->head);
-			kfree(object);
-		}
-	} else {
-		argv->v0.route = NVIF_IOCTL_V0_ROUTE_HIDDEN;
-		argv->v0.token = 0;
-	}
-	argv->v0.owner = owner;
-	mutex_unlock(&cli->mutex);
-
-	if (copy_to_user(user, argv, argc))
-		ret = -EFAULT;
-done:
-	kfree(argv);
-	return ret;
-}
-
-void
-usif_client_fini(struct nouveau_cli *cli)
-{
-	struct usif_object *object, *otemp;
-
-	list_for_each_entry_safe(object, otemp, &cli->objects, head) {
-		usif_object_dtor(object);
-	}
-}
-
-void
-usif_client_init(struct nouveau_cli *cli)
-{
-	INIT_LIST_HEAD(&cli->objects);
-}
drivers/gpu/drm/nouveau/nouveau_usif.h deleted +0 -10
deleted file mode 100644
index dc90d4a9d0d9..000000000000
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-#ifndef __NOUVEAU_USIF_H__
-#define __NOUVEAU_USIF_H__
-
-void usif_client_init(struct nouveau_cli *);
-void usif_client_fini(struct nouveau_cli *);
-int  usif_ioctl(struct drm_file *, void __user *, u32);
-int  usif_notify(const void *, u32, const void *, u32);
-
-#endif
Signature · 1 line
2.45.1
author
#27 lore raw

Re: [PATCH v2 08/37] drm/nouveau: handle limited nvif ioctl in abi16

Quoted 74 lines · Danilo Krummrich
Quoted 10 lines · Ben Skeggs

nouveau_usif.c was already stripped right back a couple of years ago, limiting what userspace could do with it, and now I'd like to remove the nvkm side of these interfaces entirely, in order to make it less of a nightmare to add/change internal APIs in the future.

Unfortunately. Userspace uses some of this.

Fortunately, userspace only ever ended up using a fraction of the APIs, so I've reimplemented those in a more direct manner, and return -EINVAL to userspace for everything else.

Please use imperative form.

Quoted 42 lines

v2:
- simplified struct nouveau_abi16_obj
- added a couple of comments

---
  drivers/gpu/drm/nouveau/Kbuild          |   1 -
  drivers/gpu/drm/nouveau/nouveau_abi16.c | 277 ++++++++++++++++++++----
  drivers/gpu/drm/nouveau/nouveau_abi16.h |   3 +-
  drivers/gpu/drm/nouveau/nouveau_drm.c   |   5 +-
  drivers/gpu/drm/nouveau/nouveau_nvif.c  |   1 -
  drivers/gpu/drm/nouveau/nouveau_usif.c  | 194 -----------------
  drivers/gpu/drm/nouveau/nouveau_usif.h  |  10 -
  7 files changed, 242 insertions(+), 249 deletions(-)

delete mode 100644 drivers/gpu/drm/nouveau/nouveau_usif.c delete mode 100644 drivers/gpu/drm/nouveau/nouveau_usif.h

drivers/gpu/drm/nouveau/Kbuild +0 -1
index c32c01827c1d..7b863355c5c6 100644
@@ -25,7 +25,6 @@ nouveau-$(CONFIG_COMPAT) += nouveau_ioc32.o
  nouveau-$(CONFIG_LEDS_CLASS) += nouveau_led.o
  nouveau-y += nouveau_nvif.o
  nouveau-$(CONFIG_NOUVEAU_PLATFORM_DRIVER) += nouveau_platform.o
-nouveau-y += nouveau_usif.o # userspace <-> nvif
  nouveau-y += nouveau_vga.o
 
  # DRM - memory management
drivers/gpu/drm/nouveau/nouveau_abi16.c +1 -0
index ac50c300d2eb..f80d777cee5d 100644
@@ -52,6 +52,7 @@ nouveau_abi16(struct drm_file *file_priv)
 
  			abi16->cli = cli;
  			INIT_LIST_HEAD(&abi16->channels);
+			INIT_LIST_HEAD(&abi16->objects);
 
  			/* allocate device object targeting client's default
  			 * device (ie. the one that belongs to the fd it

drivers/gpu/drm/nouveau/nouveau_abi16.c nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret) · line 92

Quoted 4 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +1 -0
@@ -88,6 +89,58 @@ nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret)
  	return ret;
  }
 
+/* Tracks objects created via nvif_ioctl_v0 APIs. */

Here I asked about some documentation on the semantical meaning of this object, as in "What does it represent?".

The fact this it is created via some generic nvif_ioctl_v0 interface may be part of an explanation, but with only that information I doubt that anyone who does not know already) is capabale to make any sense of this structure.

Try to answer the following questions:

1. What kind of object does it track? What do they represent?
2. For generic objects, what would be examples for specific ones?
3. Where do the objects originate from?
4. What is a "DEVICE" object and what is an "ENGOBJ"? Do we have documentation we can point to already for that?

Quoted 4 lines

If we'd want to go even more crazy, we could ask:
1. Who owns those objects, once created?
2. What are their lifetime rules?
3. How do we ensure we don't violate lifetime rules?

I hear what you're saying.  It just doesn't make sense here.  A lot of the questions you ask, particularly in the first section, relate to general concepts present throughout not only the entire driver, but GSP-RM's interfaces and even the HW itself.  Attaching all of this to a chunk of code simulating a tiny fraction of a bad idea that got exposed to userspace is not where this kind of information belongs.

I've spoken to you already about adding documentation to the remove-ioctl series as the layers are ripped out of each NVIF API, as well as some general hw/driver architecture documentation before I send a v2 of that series.  That will help clear up a lot of these type of questions.  Does that sound OK?

Quoted 589 lines
Quoted 236 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +176 -38
+struct nouveau_abi16_obj {
+	enum nouveau_abi16_obj_type {
+		DEVICE,
+		ENGOBJ,
+	} type;
+	u64 object;
+
+	struct nvif_object engobj;
+
+	struct list_head head; /* protected by nouveau_abi16.cli.mutex */
+};
+
+static struct nouveau_abi16_obj *
+nouveau_abi16_obj_find(struct nouveau_abi16 *abi16, u64 object)
+{
+	struct nouveau_abi16_obj *obj;
+
+	list_for_each_entry(obj, &abi16->objects, head) {
+		if (obj->object == object)
+			return obj;
+	}
+
+	return NULL;
+}
+
+static void
+nouveau_abi16_obj_del(struct nouveau_abi16_obj *obj)
+{
+	list_del(&obj->head);
+	kfree(obj);
+}
+
+static struct nouveau_abi16_obj *
+nouveau_abi16_obj_new(struct nouveau_abi16 *abi16, enum nouveau_abi16_obj_type type, u64 object)
+{
+	struct nouveau_abi16_obj *obj;
+
+	obj = nouveau_abi16_obj_find(abi16, object);
+	if (obj)
+		return ERR_PTR(-EEXIST);
+
+	obj = kzalloc(sizeof(*obj), GFP_KERNEL);
+	if (!obj)
+		return ERR_PTR(-ENOMEM);
+
+	obj->type = type;
+	obj->object = object;
+	list_add_tail(&obj->head, &abi16->objects);
+	return obj;
+}
+
  s32
  nouveau_abi16_swclass(struct nouveau_drm *drm)
  {
@@ -167,6 +220,12 @@ nouveau_abi16_fini(struct nouveau_abi16 *abi16)
  {
  	struct nouveau_cli *cli = abi16->cli;
  	struct nouveau_abi16_chan *chan, *temp;
+	struct nouveau_abi16_obj *obj, *tmp;
+
+	/* cleanup objects */
+	list_for_each_entry_safe(obj, tmp, &abi16->objects, head) {
+		nouveau_abi16_obj_del(obj);
+	}
 
  	/* cleanup channels */
  	list_for_each_entry_safe(chan, temp, &abi16->channels, head) {
@@ -458,44 +517,6 @@ nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel)
  	return NULL;
  }
 
-int
-nouveau_abi16_usif(struct drm_file *file_priv, void *data, u32 size)
-{
-	union {
-		struct nvif_ioctl_v0 v0;
-	} *args = data;
-	struct nouveau_abi16_chan *chan;
-	struct nouveau_abi16 *abi16;
-	int ret = -ENOSYS;
-
-	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
-		switch (args->v0.type) {
-		case NVIF_IOCTL_V0_NEW:
-		case NVIF_IOCTL_V0_MTHD:
-		case NVIF_IOCTL_V0_SCLASS:
-			break;
-		default:
-			return -EACCES;
-		}
-	} else
-		return ret;
-
-	if (!(abi16 = nouveau_abi16(file_priv)))
-		return -ENOMEM;
-
-	if (args->v0.token != ~0ULL) {
-		if (!(chan = nouveau_abi16_chan(abi16, args->v0.token)))
-			return -EINVAL;
-		args->v0.object = nvif_handle(&chan->chan->user);
-		args->v0.owner  = NVIF_IOCTL_V0_OWNER_ANY;
-		return 0;
-	}
-
-	args->v0.object = nvif_handle(&abi16->device.object);
-	args->v0.owner  = NVIF_IOCTL_V0_OWNER_ANY;
-	return 0;
-}
-
  int
  nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS)
  {
@@ -705,3 +726,183 @@ nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS)
 
  	return nouveau_abi16_put(abi16, ret);
  }
+
+static int
+nouveau_abi16_ioctl_mthd(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nouveau_cli *cli = abi16->cli;
+	struct nvif_ioctl_mthd_v0 *args;
+	struct nouveau_abi16_obj *obj;
+	struct nv_device_info_v0 *info;
+
+	if (ioctl->route || argc < sizeof(*args))
+		return -EINVAL;
+	args = (void *)ioctl->data;
+	argc -= sizeof(*args);
+
+	obj = nouveau_abi16_obj_find(abi16, ioctl->object);
+	if (!obj || obj->type != DEVICE)
+		return -EINVAL;
+
+	if (args->method != NV_DEVICE_V0_INFO ||
+	    argc != sizeof(*info))
+		return -EINVAL;
+
+	info = (void *)args->data;
+	if (info->version != 0x00)
+		return -EINVAL;
+
+	info = &cli->device.info;
+	memcpy(args->data, info, sizeof(*info));
+	return 0;
+}
+
+static int
+nouveau_abi16_ioctl_del(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nouveau_abi16_obj *obj;
+
+	if (ioctl->route || argc)
+		return -EINVAL;
+
+	obj = nouveau_abi16_obj_find(abi16, ioctl->object);
+	if (obj) {
+		if (obj->type == ENGOBJ)
+			nvif_object_dtor(&obj->engobj);
+		nouveau_abi16_obj_del(obj);
+	}
+
+	return 0;
+}
+
+static int
+nouveau_abi16_ioctl_new(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nvif_ioctl_new_v0 *args;
+	struct nouveau_abi16_chan *chan;
+	struct nouveau_abi16_obj *obj;
+	int ret;
+
+	if (argc < sizeof(*args))
+		return -EINVAL;
+	args = (void *)ioctl->data;
+	argc -= sizeof(*args);
+
+	if (args->version != 0)
+		return -EINVAL;
+
+	if (!ioctl->route) {
+		if (ioctl->object || args->oclass != NV_DEVICE)
+			return -EINVAL;
+
+		obj = nouveau_abi16_obj_new(abi16, DEVICE, args->object);
+		if (IS_ERR(obj))
+			return PTR_ERR(obj);
+
+		return 0;
+	}
+
+	chan = nouveau_abi16_chan(abi16, ioctl->token);
+	if (!chan)
+		return -EINVAL;
+
+	obj = nouveau_abi16_obj_new(abi16, ENGOBJ, args->object);
+	if (IS_ERR(obj))
+		return PTR_ERR(obj);
+
+	ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", args->handle, args->oclass,
+			       NULL, 0, &obj->engobj);
+	if (ret)
+		nouveau_abi16_obj_del(obj);
+
+	return ret;
+}
+
+static int
+nouveau_abi16_ioctl_sclass(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nvif_ioctl_sclass_v0 *args;
+	struct nouveau_abi16_chan *chan;
+	struct nvif_sclass *sclass;
+	int ret;
+
+	if (!ioctl->route || argc < sizeof(*args))
+		return -EINVAL;
+	args = (void *)ioctl->data;
+	argc -= sizeof(*args);
+
+	if (argc != args->count * sizeof(args->oclass[0]))
+		return -EINVAL;
+
+	chan = nouveau_abi16_chan(abi16, ioctl->token);
+	if (!chan)
+		return -EINVAL;
+
+	ret = nvif_object_sclass_get(&chan->chan->user, &sclass);
+	if (ret < 0)
+		return ret;
+
+	for (int i = 0; i < min_t(u8, args->count, ret); i++) {
+		args->oclass[i].oclass = sclass[i].oclass;
+		args->oclass[i].minver = sclass[i].minver;

drivers/gpu/drm/nouveau/nouveau_abi16.c nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS) · line 857

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +10 -0
+		args->oclass[i].maxver = sclass[i].maxver;
+	}
+	args->count = ret;
+
+	nvif_object_sclass_put(&sclass);
+	return 0;
+}
+
+int
+nouveau_abi16_ioctl(struct drm_file *filp, void __user *user, u32 size)

Actually, it would also be good to add documentation on what this uAPI provides and how it works. But since this patch just moves things over, I don't think it's required for this patch.

Quoted 339 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +51 -0
+{
+	struct nvif_ioctl_v0 *ioctl;
+	struct nouveau_abi16 *abi16;
+	u32 argc = size;
+	int ret;
+
+	if (argc < sizeof(*ioctl))
+		return -EINVAL;
+	argc -= sizeof(*ioctl);
+
+	ioctl = kmalloc(size, GFP_KERNEL);
+	if (!ioctl)
+		return -ENOMEM;
+
+	ret = -EFAULT;
+	if (copy_from_user(ioctl, user, size))
+		goto done_free;
+
+	if (ioctl->version != 0x00 ||
+	    (ioctl->route && ioctl->route != 0xff)) {
+		ret = -EINVAL;
+		goto done_free;
+	}
+
+	abi16 = nouveau_abi16_get(filp);
+	if (unlikely(!abi16)) {
+		ret = -ENOMEM;
+		goto done_free;
+	}
+
+	switch (ioctl->type) {
+	case NVIF_IOCTL_V0_SCLASS: ret = nouveau_abi16_ioctl_sclass(abi16, ioctl, argc); break;
+	case NVIF_IOCTL_V0_NEW   : ret = nouveau_abi16_ioctl_new   (abi16, ioctl, argc); break;
+	case NVIF_IOCTL_V0_DEL   : ret = nouveau_abi16_ioctl_del   (abi16, ioctl, argc); break;
+	case NVIF_IOCTL_V0_MTHD  : ret = nouveau_abi16_ioctl_mthd  (abi16, ioctl, argc); break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	nouveau_abi16_put(abi16, 0);
+
+	if (ret == 0) {
+		if (copy_to_user(user, ioctl, size))
+			ret = -EFAULT;
+	}
+
+done_free:
+	kfree(ioctl);
+	return ret;
+}
drivers/gpu/drm/nouveau/nouveau_abi16.h +2 -1
index 0a9121e63143..75a883a44e04 100644
@@ -34,13 +34,14 @@ struct nouveau_abi16 {
  	struct nvif_device device;
  	struct list_head channels;
  	u64 handles;
+	struct list_head objects;
  };
 
  struct nouveau_abi16 *nouveau_abi16_get(struct drm_file *);
  int  nouveau_abi16_put(struct nouveau_abi16 *, int);
  void nouveau_abi16_fini(struct nouveau_abi16 *);
  s32  nouveau_abi16_swclass(struct nouveau_drm *);
-int  nouveau_abi16_usif(struct drm_file *, void *data, u32 size);
+int nouveau_abi16_ioctl(struct drm_file *, void __user *user, u32 size);
 
  #define NOUVEAU_GEM_DOMAIN_VRAM      (1 << 1)
  #define NOUVEAU_GEM_DOMAIN_GART      (1 << 2)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -4
index a942d2c03d44..6726f463d2d3 100644
@@ -63,7 +63,6 @@
  #include "nouveau_abi16.h"
  #include "nouveau_fence.h"
  #include "nouveau_debugfs.h"
-#include "nouveau_usif.h"
  #include "nouveau_connector.h"
  #include "nouveau_platform.h"
  #include "nouveau_svm.h"
@@ -200,7 +199,6 @@ nouveau_cli_fini(struct nouveau_cli *cli)
  	flush_work(&cli->work);
  	WARN_ON(!list_empty(&cli->worker));
 
-	usif_client_fini(cli);
  	if (cli->sched)
  		nouveau_sched_destroy(&cli->sched);
  	if (uvmm)
@@ -249,7 +247,6 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
  	snprintf(cli->name, sizeof(cli->name), "%s", sname);
  	cli->drm = drm;
  	mutex_init(&cli->mutex);
-	usif_client_init(cli);
 
  	INIT_WORK(&cli->work, nouveau_cli_work);
  	INIT_LIST_HEAD(&cli->worker);
@@ -1267,7 +1264,7 @@ nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
  	switch (_IOC_NR(cmd) - DRM_COMMAND_BASE) {
  	case DRM_NOUVEAU_NVIF:
-		ret = usif_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
+		ret = nouveau_abi16_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
  		break;
  	default:
  		ret = drm_ioctl(file, cmd, arg);
drivers/gpu/drm/nouveau/nouveau_nvif.c +0 -1
index 1d49ebdfd5dc..9a7e3f64b79f 100644
@@ -35,7 +35,6 @@
  #include <nvif/ioctl.h>
 
  #include "nouveau_drv.h"
-#include "nouveau_usif.h"
 
  static void
  nvkm_client_unmap(void *priv, void __iomem *ptr, u32 size)
drivers/gpu/drm/nouveau/nouveau_usif.c deleted +0 -194
deleted file mode 100644
index 002d1479ba89..000000000000
@@ -1,194 +0,0 @@
-/*
- * Copyright 2014 Red Hat Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: Ben Skeggs <[email protected]>
- */
-
-#include "nouveau_drv.h"
-#include "nouveau_usif.h"
-#include "nouveau_abi16.h"
-
-#include <nvif/unpack.h>
-#include <nvif/client.h>
-#include <nvif/ioctl.h>
-
-#include <nvif/class.h>
-#include <nvif/cl0080.h>
-
-struct usif_object {
-	struct list_head head;
-	u8  route;
-	u64 token;
-};
-
-static void
-usif_object_dtor(struct usif_object *object)
-{
-	list_del(&object->head);
-	kfree(object);
-}
-
-static int
-usif_object_new(struct drm_file *f, void *data, u32 size, void *argv, u32 argc, bool parent_abi16)
-{
-	struct nouveau_cli *cli = nouveau_cli(f);
-	struct nvif_client *client = &cli->base;
-	union {
-		struct nvif_ioctl_new_v0 v0;
-	} *args = data;
-	struct usif_object *object;
-	int ret = -ENOSYS;
-
-	if ((ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true)))
-		return ret;
-
-	switch (args->v0.oclass) {
-	case NV_DMA_FROM_MEMORY:
-	case NV_DMA_TO_MEMORY:
-	case NV_DMA_IN_MEMORY:
-		return -EINVAL;
-	case NV_DEVICE: {
-		union {
-			struct nv_device_v0 v0;
-		} *args = data;
-
-		if ((ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false)))
-			return ret;
-
-		args->v0.priv = false;
-		break;
-	}
-	default:
-		if (!parent_abi16)
-			return -EINVAL;
-		break;
-	}
-
-	if (!(object = kmalloc(sizeof(*object), GFP_KERNEL)))
-		return -ENOMEM;
-	list_add(&object->head, &cli->objects);
-
-	object->route = args->v0.route;
-	object->token = args->v0.token;
-	args->v0.route = NVDRM_OBJECT_USIF;
-	args->v0.token = (unsigned long)(void *)object;
-	ret = nvif_client_ioctl(client, argv, argc);
-	if (ret) {
-		usif_object_dtor(object);
-		return ret;
-	}
-
-	args->v0.token = object->token;
-	args->v0.route = object->route;
-	return 0;
-}
-
-int
-usif_ioctl(struct drm_file *filp, void __user *user, u32 argc)
-{
-	struct nouveau_cli *cli = nouveau_cli(filp);
-	struct nvif_client *client = &cli->base;
-	void *data = kmalloc(argc, GFP_KERNEL);
-	u32   size = argc;
-	union {
-		struct nvif_ioctl_v0 v0;
-	} *argv = data;
-	struct usif_object *object;
-	bool abi16 = false;
-	u8 owner;
-	int ret;
-
-	if (ret = -ENOMEM, !argv)
-		goto done;
-	if (ret = -EFAULT, copy_from_user(argv, user, size))
-		goto done;
-
-	if (!(ret = nvif_unpack(-ENOSYS, &data, &size, argv->v0, 0, 0, true))) {
-		/* block access to objects not created via this interface */
-		owner = argv->v0.owner;
-		if (argv->v0.object == 0ULL &&
-		    argv->v0.type != NVIF_IOCTL_V0_DEL)
-			argv->v0.owner = NVDRM_OBJECT_ANY; /* except client */
-		else
-			argv->v0.owner = NVDRM_OBJECT_USIF;
-	} else
-		goto done;
-
-	/* USIF slightly abuses some return-only ioctl members in order
-	 * to provide interoperability with the older ABI16 objects
-	 */
-	mutex_lock(&cli->mutex);
-	if (argv->v0.route) {
-		if (ret = -EINVAL, argv->v0.route == 0xff)
-			ret = nouveau_abi16_usif(filp, argv, argc);
-		if (ret) {
-			mutex_unlock(&cli->mutex);
-			goto done;
-		}
-
-		abi16 = true;
-	}
-
-	switch (argv->v0.type) {
-	case NVIF_IOCTL_V0_NEW:
-		ret = usif_object_new(filp, data, size, argv, argc, abi16);
-		break;
-	default:
-		ret = nvif_client_ioctl(client, argv, argc);
-		break;
-	}
-	if (argv->v0.route == NVDRM_OBJECT_USIF) {
-		object = (void *)(unsigned long)argv->v0.token;
-		argv->v0.route = object->route;
-		argv->v0.token = object->token;
-		if (ret == 0 && argv->v0.type == NVIF_IOCTL_V0_DEL) {
-			list_del(&object->head);
-			kfree(object);
-		}
-	} else {
-		argv->v0.route = NVIF_IOCTL_V0_ROUTE_HIDDEN;
-		argv->v0.token = 0;
-	}
-	argv->v0.owner = owner;
-	mutex_unlock(&cli->mutex);
-
-	if (copy_to_user(user, argv, argc))
-		ret = -EFAULT;
-done:
-	kfree(argv);
-	return ret;
-}
-
-void
-usif_client_fini(struct nouveau_cli *cli)
-{
-	struct usif_object *object, *otemp;
-
-	list_for_each_entry_safe(object, otemp, &cli->objects, head) {
-		usif_object_dtor(object);
-	}
-}
-
-void
-usif_client_init(struct nouveau_cli *cli)
-{
-	INIT_LIST_HEAD(&cli->objects);
-}
drivers/gpu/drm/nouveau/nouveau_usif.h deleted +0 -10
deleted file mode 100644
index dc90d4a9d0d9..000000000000
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-#ifndef __NOUVEAU_USIF_H__
-#define __NOUVEAU_USIF_H__
-
-void usif_client_init(struct nouveau_cli *);
-void usif_client_fini(struct nouveau_cli *);
-int  usif_ioctl(struct drm_file *, void __user *, u32);
-int  usif_notify(const void *, u32, const void *, u32);
-
-#endif
Signature · 1 line
2.45.1
#28 lore raw

Re: [PATCH v2 08/37] drm/nouveau: handle limited nvif ioctl in abi16

Quoted 77 lines · Ben Skeggs
Quoted 70 lines · Danilo Krummrich
Quoted 10 lines · Ben Skeggs

nouveau_usif.c was already stripped right back a couple of years ago, limiting what userspace could do with it, and now I'd like to remove the nvkm side of these interfaces entirely, in order to make it less of a nightmare to add/change internal APIs in the future.

Unfortunately. Userspace uses some of this.

Fortunately, userspace only ever ended up using a fraction of the APIs, so I've reimplemented those in a more direct manner, and return -EINVAL to userspace for everything else.

Please use imperative form.

Quoted 39 lines

v2:
- simplified struct nouveau_abi16_obj
- added a couple of comments

---
  drivers/gpu/drm/nouveau/Kbuild          |   1 -
  drivers/gpu/drm/nouveau/nouveau_abi16.c | 277 ++++++++++++++++++++----
  drivers/gpu/drm/nouveau/nouveau_abi16.h |   3 +-
  drivers/gpu/drm/nouveau/nouveau_drm.c   |   5 +-
  drivers/gpu/drm/nouveau/nouveau_nvif.c  |   1 -
  drivers/gpu/drm/nouveau/nouveau_usif.c  | 194 -----------------
  drivers/gpu/drm/nouveau/nouveau_usif.h  |  10 -
  7 files changed, 242 insertions(+), 249 deletions(-)

delete mode 100644 drivers/gpu/drm/nouveau/nouveau_usif.c delete mode 100644 drivers/gpu/drm/nouveau/nouveau_usif.h

drivers/gpu/drm/nouveau/Kbuild +0 -1
index c32c01827c1d..7b863355c5c6 100644
@@ -25,7 +25,6 @@ nouveau-$(CONFIG_COMPAT) += nouveau_ioc32.o
  nouveau-$(CONFIG_LEDS_CLASS) += nouveau_led.o
  nouveau-y += nouveau_nvif.o
  nouveau-$(CONFIG_NOUVEAU_PLATFORM_DRIVER) += nouveau_platform.o
-nouveau-y += nouveau_usif.o # userspace <-> nvif
  nouveau-y += nouveau_vga.o
  # DRM - memory management
drivers/gpu/drm/nouveau/nouveau_abi16.c +1 -0
index ac50c300d2eb..f80d777cee5d 100644
@@ -52,6 +52,7 @@ nouveau_abi16(struct drm_file *file_priv)
  			abi16->cli = cli;
  			INIT_LIST_HEAD(&abi16->channels);
+			INIT_LIST_HEAD(&abi16->objects);
  			/* allocate device object targeting client's default
  			 * device (ie. the one that belongs to the fd it

drivers/gpu/drm/nouveau/nouveau_abi16.c nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret) · line 91

Quoted 3 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +1 -0
@@ -88,6 +89,58 @@ nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret)
  	return ret;
  }
+/* Tracks objects created via nvif_ioctl_v0 APIs. */

Here I asked about some documentation on the semantical meaning of this object, as in "What does it represent?".

The fact this it is created via some generic nvif_ioctl_v0 interface may be part of an explanation, but with only that information I doubt that anyone who does not know already) is capabale to make any sense of this structure.

Try to answer the following questions:

1. What kind of object does it track? What do they represent?
2. For generic objects, what would be examples for specific ones?
3. Where do the objects originate from?
4. What is a "DEVICE" object and what is an "ENGOBJ"? Do we have documentation we can point to already for that?

Quoted 4 lines

If we'd want to go even more crazy, we could ask:
1. Who owns those objects, once created?
2. What are their lifetime rules?
3. How do we ensure we don't violate lifetime rules?

Quoted 6 lines

I hear what you're saying.  It just doesn't make sense here.  A lot of the questions you ask, particularly in the first section, relate to general concepts present throughout not only the entire driver, but GSP-RM's interfaces and even the HW itself.  Attaching all of this to a chunk of code simulating a tiny fraction of a bad idea that got exposed to userspace is not where this kind of information belongs.

I'm not asking you to answer all those questions to the maximum extend possible, especially not in this random place.

Instead those questions are intended as a hint on what to think of when trying to write some documentation for this structure.

So, effectively you're saying that you can't explain what this structure is about, without explaining the whole driver architecture, GSP-RM, and even the HW.

And to a certain extend I agree, it is indeed a bit difficult, since we don't have general documentation we can tie a brief explanation back to, neither for the driver architecture, nor for this uAPI.

As you mention below, you plan to write up some general driver architecture documentation, that should cover the key concepts. It won't cover this specific structure however.

Please try to come up with a few lines for struct nouveau_abi16_obj specifically. When you get to the point where things should be covered by the general driver architecture documentation, just stop and leave it there.

Now, I understand that it may feel a bit random, but we have to start somewhere.

Quoted 587 lines

I've spoken to you already about adding documentation to the remove-ioctl series as the layers are ripped out of each NVIF API, as well as some general hw/driver architecture documentation before I send a v2 of that series.  That will help clear up a lot of these type of questions.  Does that sound OK?

Quoted 579 lines
Quoted 233 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +176 -38
+struct nouveau_abi16_obj {
+	enum nouveau_abi16_obj_type {
+		DEVICE,
+		ENGOBJ,
+	} type;
+	u64 object;
+
+	struct nvif_object engobj;
+
+	struct list_head head; /* protected by nouveau_abi16.cli.mutex */
+};
+
+static struct nouveau_abi16_obj *
+nouveau_abi16_obj_find(struct nouveau_abi16 *abi16, u64 object)
+{
+	struct nouveau_abi16_obj *obj;
+
+	list_for_each_entry(obj, &abi16->objects, head) {
+		if (obj->object == object)
+			return obj;
+	}
+
+	return NULL;
+}
+
+static void
+nouveau_abi16_obj_del(struct nouveau_abi16_obj *obj)
+{
+	list_del(&obj->head);
+	kfree(obj);
+}
+
+static struct nouveau_abi16_obj *
+nouveau_abi16_obj_new(struct nouveau_abi16 *abi16, enum nouveau_abi16_obj_type type, u64 object)
+{
+	struct nouveau_abi16_obj *obj;
+
+	obj = nouveau_abi16_obj_find(abi16, object);
+	if (obj)
+		return ERR_PTR(-EEXIST);
+
+	obj = kzalloc(sizeof(*obj), GFP_KERNEL);
+	if (!obj)
+		return ERR_PTR(-ENOMEM);
+
+	obj->type = type;
+	obj->object = object;
+	list_add_tail(&obj->head, &abi16->objects);
+	return obj;
+}
+
  s32
  nouveau_abi16_swclass(struct nouveau_drm *drm)
  {
@@ -167,6 +220,12 @@ nouveau_abi16_fini(struct nouveau_abi16 *abi16)
  {
  	struct nouveau_cli *cli = abi16->cli;
  	struct nouveau_abi16_chan *chan, *temp;
+	struct nouveau_abi16_obj *obj, *tmp;
+
+	/* cleanup objects */
+	list_for_each_entry_safe(obj, tmp, &abi16->objects, head) {
+		nouveau_abi16_obj_del(obj);
+	}
  	/* cleanup channels */
  	list_for_each_entry_safe(chan, temp, &abi16->channels, head) {
@@ -458,44 +517,6 @@ nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel)
  	return NULL;
  }
-int
-nouveau_abi16_usif(struct drm_file *file_priv, void *data, u32 size)
-{
-	union {
-		struct nvif_ioctl_v0 v0;
-	} *args = data;
-	struct nouveau_abi16_chan *chan;
-	struct nouveau_abi16 *abi16;
-	int ret = -ENOSYS;
-
-	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
-		switch (args->v0.type) {
-		case NVIF_IOCTL_V0_NEW:
-		case NVIF_IOCTL_V0_MTHD:
-		case NVIF_IOCTL_V0_SCLASS:
-			break;
-		default:
-			return -EACCES;
-		}
-	} else
-		return ret;
-
-	if (!(abi16 = nouveau_abi16(file_priv)))
-		return -ENOMEM;
-
-	if (args->v0.token != ~0ULL) {
-		if (!(chan = nouveau_abi16_chan(abi16, args->v0.token)))
-			return -EINVAL;
-		args->v0.object = nvif_handle(&chan->chan->user);
-		args->v0.owner  = NVIF_IOCTL_V0_OWNER_ANY;
-		return 0;
-	}
-
-	args->v0.object = nvif_handle(&abi16->device.object);
-	args->v0.owner  = NVIF_IOCTL_V0_OWNER_ANY;
-	return 0;
-}
-
  int
  nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS)
  {
@@ -705,3 +726,183 @@ nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS)
  	return nouveau_abi16_put(abi16, ret);
  }
+
+static int
+nouveau_abi16_ioctl_mthd(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nouveau_cli *cli = abi16->cli;
+	struct nvif_ioctl_mthd_v0 *args;
+	struct nouveau_abi16_obj *obj;
+	struct nv_device_info_v0 *info;
+
+	if (ioctl->route || argc < sizeof(*args))
+		return -EINVAL;
+	args = (void *)ioctl->data;
+	argc -= sizeof(*args);
+
+	obj = nouveau_abi16_obj_find(abi16, ioctl->object);
+	if (!obj || obj->type != DEVICE)
+		return -EINVAL;
+
+	if (args->method != NV_DEVICE_V0_INFO ||
+	    argc != sizeof(*info))
+		return -EINVAL;
+
+	info = (void *)args->data;
+	if (info->version != 0x00)
+		return -EINVAL;
+
+	info = &cli->device.info;
+	memcpy(args->data, info, sizeof(*info));
+	return 0;
+}
+
+static int
+nouveau_abi16_ioctl_del(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nouveau_abi16_obj *obj;
+
+	if (ioctl->route || argc)
+		return -EINVAL;
+
+	obj = nouveau_abi16_obj_find(abi16, ioctl->object);
+	if (obj) {
+		if (obj->type == ENGOBJ)
+			nvif_object_dtor(&obj->engobj);
+		nouveau_abi16_obj_del(obj);
+	}
+
+	return 0;
+}
+
+static int
+nouveau_abi16_ioctl_new(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nvif_ioctl_new_v0 *args;
+	struct nouveau_abi16_chan *chan;
+	struct nouveau_abi16_obj *obj;
+	int ret;
+
+	if (argc < sizeof(*args))
+		return -EINVAL;
+	args = (void *)ioctl->data;
+	argc -= sizeof(*args);
+
+	if (args->version != 0)
+		return -EINVAL;
+
+	if (!ioctl->route) {
+		if (ioctl->object || args->oclass != NV_DEVICE)
+			return -EINVAL;
+
+		obj = nouveau_abi16_obj_new(abi16, DEVICE, args->object);
+		if (IS_ERR(obj))
+			return PTR_ERR(obj);
+
+		return 0;
+	}
+
+	chan = nouveau_abi16_chan(abi16, ioctl->token);
+	if (!chan)
+		return -EINVAL;
+
+	obj = nouveau_abi16_obj_new(abi16, ENGOBJ, args->object);
+	if (IS_ERR(obj))
+		return PTR_ERR(obj);
+
+	ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", args->handle, args->oclass,
+			       NULL, 0, &obj->engobj);
+	if (ret)
+		nouveau_abi16_obj_del(obj);
+
+	return ret;
+}
+
+static int
+nouveau_abi16_ioctl_sclass(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
+{
+	struct nvif_ioctl_sclass_v0 *args;
+	struct nouveau_abi16_chan *chan;
+	struct nvif_sclass *sclass;
+	int ret;
+
+	if (!ioctl->route || argc < sizeof(*args))
+		return -EINVAL;
+	args = (void *)ioctl->data;
+	argc -= sizeof(*args);
+
+	if (argc != args->count * sizeof(args->oclass[0]))
+		return -EINVAL;
+
+	chan = nouveau_abi16_chan(abi16, ioctl->token);
+	if (!chan)
+		return -EINVAL;
+
+	ret = nvif_object_sclass_get(&chan->chan->user, &sclass);
+	if (ret < 0)
+		return ret;
+
+	for (int i = 0; i < min_t(u8, args->count, ret); i++) {
+		args->oclass[i].oclass = sclass[i].oclass;
+		args->oclass[i].minver = sclass[i].minver;

drivers/gpu/drm/nouveau/nouveau_abi16.c nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS) · line 856

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +10 -0
+		args->oclass[i].maxver = sclass[i].maxver;
+	}
+	args->count = ret;
+
+	nvif_object_sclass_put(&sclass);
+	return 0;
+}
+
+int
+nouveau_abi16_ioctl(struct drm_file *filp, void __user *user, u32 size)

Actually, it would also be good to add documentation on what this uAPI provides and how it works. But since this patch just moves things over, I don't think it's required for this patch.

Quoted 332 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +51 -0
+{
+	struct nvif_ioctl_v0 *ioctl;
+	struct nouveau_abi16 *abi16;
+	u32 argc = size;
+	int ret;
+
+	if (argc < sizeof(*ioctl))
+		return -EINVAL;
+	argc -= sizeof(*ioctl);
+
+	ioctl = kmalloc(size, GFP_KERNEL);
+	if (!ioctl)
+		return -ENOMEM;
+
+	ret = -EFAULT;
+	if (copy_from_user(ioctl, user, size))
+		goto done_free;
+
+	if (ioctl->version != 0x00 ||
+	    (ioctl->route && ioctl->route != 0xff)) {
+		ret = -EINVAL;
+		goto done_free;
+	}
+
+	abi16 = nouveau_abi16_get(filp);
+	if (unlikely(!abi16)) {
+		ret = -ENOMEM;
+		goto done_free;
+	}
+
+	switch (ioctl->type) {
+	case NVIF_IOCTL_V0_SCLASS: ret = nouveau_abi16_ioctl_sclass(abi16, ioctl, argc); break;
+	case NVIF_IOCTL_V0_NEW   : ret = nouveau_abi16_ioctl_new   (abi16, ioctl, argc); break;
+	case NVIF_IOCTL_V0_DEL   : ret = nouveau_abi16_ioctl_del   (abi16, ioctl, argc); break;
+	case NVIF_IOCTL_V0_MTHD  : ret = nouveau_abi16_ioctl_mthd  (abi16, ioctl, argc); break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	nouveau_abi16_put(abi16, 0);
+
+	if (ret == 0) {
+		if (copy_to_user(user, ioctl, size))
+			ret = -EFAULT;
+	}
+
+done_free:
+	kfree(ioctl);
+	return ret;
+}
drivers/gpu/drm/nouveau/nouveau_abi16.h +2 -1
index 0a9121e63143..75a883a44e04 100644
@@ -34,13 +34,14 @@ struct nouveau_abi16 {
  	struct nvif_device device;
  	struct list_head channels;
  	u64 handles;
+	struct list_head objects;
  };
  struct nouveau_abi16 *nouveau_abi16_get(struct drm_file *);
  int  nouveau_abi16_put(struct nouveau_abi16 *, int);
  void nouveau_abi16_fini(struct nouveau_abi16 *);
  s32  nouveau_abi16_swclass(struct nouveau_drm *);
-int  nouveau_abi16_usif(struct drm_file *, void *data, u32 size);
+int nouveau_abi16_ioctl(struct drm_file *, void __user *user, u32 size);
  #define NOUVEAU_GEM_DOMAIN_VRAM      (1 << 1)
  #define NOUVEAU_GEM_DOMAIN_GART      (1 << 2)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -4
index a942d2c03d44..6726f463d2d3 100644
@@ -63,7 +63,6 @@
  #include "nouveau_abi16.h"
  #include "nouveau_fence.h"
  #include "nouveau_debugfs.h"
-#include "nouveau_usif.h"
  #include "nouveau_connector.h"
  #include "nouveau_platform.h"
  #include "nouveau_svm.h"
@@ -200,7 +199,6 @@ nouveau_cli_fini(struct nouveau_cli *cli)
  	flush_work(&cli->work);
  	WARN_ON(!list_empty(&cli->worker));
-	usif_client_fini(cli);
  	if (cli->sched)
  		nouveau_sched_destroy(&cli->sched);
  	if (uvmm)
@@ -249,7 +247,6 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
  	snprintf(cli->name, sizeof(cli->name), "%s", sname);
  	cli->drm = drm;
  	mutex_init(&cli->mutex);
-	usif_client_init(cli);
  	INIT_WORK(&cli->work, nouveau_cli_work);
  	INIT_LIST_HEAD(&cli->worker);
@@ -1267,7 +1264,7 @@ nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  	switch (_IOC_NR(cmd) - DRM_COMMAND_BASE) {
  	case DRM_NOUVEAU_NVIF:
-		ret = usif_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
+		ret = nouveau_abi16_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
  		break;
  	default:
  		ret = drm_ioctl(file, cmd, arg);
drivers/gpu/drm/nouveau/nouveau_nvif.c +0 -1
index 1d49ebdfd5dc..9a7e3f64b79f 100644
@@ -35,7 +35,6 @@
  #include <nvif/ioctl.h>
  #include "nouveau_drv.h"
-#include "nouveau_usif.h"
  static void
  nvkm_client_unmap(void *priv, void __iomem *ptr, u32 size)
drivers/gpu/drm/nouveau/nouveau_usif.c deleted +0 -194
deleted file mode 100644
index 002d1479ba89..000000000000
@@ -1,194 +0,0 @@
-/*
- * Copyright 2014 Red Hat Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: Ben Skeggs <[email protected]>
- */
-
-#include "nouveau_drv.h"
-#include "nouveau_usif.h"
-#include "nouveau_abi16.h"
-
-#include <nvif/unpack.h>
-#include <nvif/client.h>
-#include <nvif/ioctl.h>
-
-#include <nvif/class.h>
-#include <nvif/cl0080.h>
-
-struct usif_object {
-	struct list_head head;
-	u8  route;
-	u64 token;
-};
-
-static void
-usif_object_dtor(struct usif_object *object)
-{
-	list_del(&object->head);
-	kfree(object);
-}
-
-static int
-usif_object_new(struct drm_file *f, void *data, u32 size, void *argv, u32 argc, bool parent_abi16)
-{
-	struct nouveau_cli *cli = nouveau_cli(f);
-	struct nvif_client *client = &cli->base;
-	union {
-		struct nvif_ioctl_new_v0 v0;
-	} *args = data;
-	struct usif_object *object;
-	int ret = -ENOSYS;
-
-	if ((ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true)))
-		return ret;
-
-	switch (args->v0.oclass) {
-	case NV_DMA_FROM_MEMORY:
-	case NV_DMA_TO_MEMORY:
-	case NV_DMA_IN_MEMORY:
-		return -EINVAL;
-	case NV_DEVICE: {
-		union {
-			struct nv_device_v0 v0;
-		} *args = data;
-
-		if ((ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false)))
-			return ret;
-
-		args->v0.priv = false;
-		break;
-	}
-	default:
-		if (!parent_abi16)
-			return -EINVAL;
-		break;
-	}
-
-	if (!(object = kmalloc(sizeof(*object), GFP_KERNEL)))
-		return -ENOMEM;
-	list_add(&object->head, &cli->objects);
-
-	object->route = args->v0.route;
-	object->token = args->v0.token;
-	args->v0.route = NVDRM_OBJECT_USIF;
-	args->v0.token = (unsigned long)(void *)object;
-	ret = nvif_client_ioctl(client, argv, argc);
-	if (ret) {
-		usif_object_dtor(object);
-		return ret;
-	}
-
-	args->v0.token = object->token;
-	args->v0.route = object->route;
-	return 0;
-}
-
-int
-usif_ioctl(struct drm_file *filp, void __user *user, u32 argc)
-{
-	struct nouveau_cli *cli = nouveau_cli(filp);
-	struct nvif_client *client = &cli->base;
-	void *data = kmalloc(argc, GFP_KERNEL);
-	u32   size = argc;
-	union {
-		struct nvif_ioctl_v0 v0;
-	} *argv = data;
-	struct usif_object *object;
-	bool abi16 = false;
-	u8 owner;
-	int ret;
-
-	if (ret = -ENOMEM, !argv)
-		goto done;
-	if (ret = -EFAULT, copy_from_user(argv, user, size))
-		goto done;
-
-	if (!(ret = nvif_unpack(-ENOSYS, &data, &size, argv->v0, 0, 0, true))) {
-		/* block access to objects not created via this interface */
-		owner = argv->v0.owner;
-		if (argv->v0.object == 0ULL &&
-		    argv->v0.type != NVIF_IOCTL_V0_DEL)
-			argv->v0.owner = NVDRM_OBJECT_ANY; /* except client */
-		else
-			argv->v0.owner = NVDRM_OBJECT_USIF;
-	} else
-		goto done;
-
-	/* USIF slightly abuses some return-only ioctl members in order
-	 * to provide interoperability with the older ABI16 objects
-	 */
-	mutex_lock(&cli->mutex);
-	if (argv->v0.route) {
-		if (ret = -EINVAL, argv->v0.route == 0xff)
-			ret = nouveau_abi16_usif(filp, argv, argc);
-		if (ret) {
-			mutex_unlock(&cli->mutex);
-			goto done;
-		}
-
-		abi16 = true;
-	}
-
-	switch (argv->v0.type) {
-	case NVIF_IOCTL_V0_NEW:
-		ret = usif_object_new(filp, data, size, argv, argc, abi16);
-		break;
-	default:
-		ret = nvif_client_ioctl(client, argv, argc);
-		break;
-	}
-	if (argv->v0.route == NVDRM_OBJECT_USIF) {
-		object = (void *)(unsigned long)argv->v0.token;
-		argv->v0.route = object->route;
-		argv->v0.token = object->token;
-		if (ret == 0 && argv->v0.type == NVIF_IOCTL_V0_DEL) {
-			list_del(&object->head);
-			kfree(object);
-		}
-	} else {
-		argv->v0.route = NVIF_IOCTL_V0_ROUTE_HIDDEN;
-		argv->v0.token = 0;
-	}
-	argv->v0.owner = owner;
-	mutex_unlock(&cli->mutex);
-
-	if (copy_to_user(user, argv, argc))
-		ret = -EFAULT;
-done:
-	kfree(argv);
-	return ret;
-}
-
-void
-usif_client_fini(struct nouveau_cli *cli)
-{
-	struct usif_object *object, *otemp;
-
-	list_for_each_entry_safe(object, otemp, &cli->objects, head) {
-		usif_object_dtor(object);
-	}
-}
-
-void
-usif_client_init(struct nouveau_cli *cli)
-{
-	INIT_LIST_HEAD(&cli->objects);
-}
drivers/gpu/drm/nouveau/nouveau_usif.h deleted +0 -10
deleted file mode 100644
index dc90d4a9d0d9..000000000000
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-#ifndef __NOUVEAU_USIF_H__
-#define __NOUVEAU_USIF_H__
-
-void usif_client_init(struct nouveau_cli *);
-void usif_client_fini(struct nouveau_cli *);
-int  usif_ioctl(struct drm_file *, void __user *, u32);
-int  usif_notify(const void *, u32, const void *, u32);
-
-#endif
Signature · 1 line
2.45.1
author
#29 lore raw

PATCH v2 9/37 drm/nouveau: remove abi16->device

In reply to Ben Skeggs

The previous commit removes the last remnants of userspace's own nvif instance, so this isn't needed anymore to hide the abi16 objects from userspace and we can use nouveau_cli.device instead.

---
 drivers/gpu/drm/nouveau/nouveau_abi16.c | 25 +++----------------------
 drivers/gpu/drm/nouveau/nouveau_abi16.h |  1 -
 2 files changed, 3 insertions(+), 23 deletions(-)
drivers/gpu/drm/nouveau/nouveau_abi16.c +3 -22
index f80d777cee5d..6f0548e57f9e 100644
@@ -46,25 +46,9 @@ nouveau_abi16(struct drm_file *file_priv)
 		struct nouveau_abi16 *abi16;
 		cli->abi16 = abi16 = kzalloc(sizeof(*abi16), GFP_KERNEL);
 		if (cli->abi16) {
-			struct nv_device_v0 args = {
-				.device = ~0ULL,
-			};
-
 			abi16->cli = cli;
 			INIT_LIST_HEAD(&abi16->channels);
 			INIT_LIST_HEAD(&abi16->objects);
-
-			/* allocate device object targeting client's default
-			 * device (ie. the one that belongs to the fd it
-			 * opened)
-			 */
-			if (nvif_device_ctor(&cli->base.object, "abi16Device",
-					     0, NV_DEVICE, &args, sizeof(args),
-					     &abi16->device) == 0)
-				return cli->abi16;
-
-			kfree(cli->abi16);
-			cli->abi16 = NULL;
 		}
 	}
 	return cli->abi16;
@@ -232,9 +216,6 @@ nouveau_abi16_fini(struct nouveau_abi16 *abi16)
 		nouveau_abi16_chan_fini(abi16, chan);
 	}
 
-	/* destroy the device object */
-	nvif_device_dtor(&abi16->device);
-
 	kfree(cli->abi16);
 	cli->abi16 = NULL;
 }
@@ -351,7 +332,7 @@ nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
 	struct nouveau_abi16_chan *chan;
-	struct nvif_device *device;
+	struct nvif_device *device = &cli->device;
 	u64 engine, runm;
 	int ret;
 
@@ -368,7 +349,6 @@ nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
 	 */
 	__nouveau_cli_disable_uvmm_noinit(cli);
 
-	device = &abi16->device;
 	engine = NV_DEVICE_HOST_RUNLIST_ENGINES_GR;
 
 	/* hack to allow channel engine type specification on kepler */
@@ -634,13 +614,14 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
 	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
 	struct nouveau_abi16_chan *chan;
 	struct nouveau_abi16_ntfy *ntfy;
-	struct nvif_device *device = &abi16->device;
+	struct nvif_device *device;
 	struct nvif_client *client;
 	struct nv_dma_v0 args = {};
 	int ret;
 
 	if (unlikely(!abi16))
 		return -ENOMEM;
+	device = &abi16->cli->device;
 
 	/* completely unnecessary for these chipsets... */
 	if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
drivers/gpu/drm/nouveau/nouveau_abi16.h +0 -1
index 75a883a44e04..4743459ea14c 100644
@@ -31,7 +31,6 @@ struct nouveau_abi16_chan {
 
 struct nouveau_abi16 {
 	struct nouveau_cli *cli;
-	struct nvif_device device;
 	struct list_head channels;
 	u64 handles;
 	struct list_head objects;
Signature · 1 line
2.45.1
author
#30 lore raw

PATCH v2 10/37 drm/nouveau: remove abi16->handles

In reply to Ben Skeggs

Hasn't been needed since 2015...

---
 drivers/gpu/drm/nouveau/nouveau_abi16.h | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_abi16.h +0 -1
index 4743459ea14c..af6b4e1cefd2 100644
@@ -32,7 +32,6 @@ struct nouveau_abi16_chan {
 struct nouveau_abi16 {
 	struct nouveau_cli *cli;
 	struct list_head channels;
-	u64 handles;
 	struct list_head objects;
 };
 
Signature · 1 line
2.45.1
author
#31 lore raw

PATCH v2 11/37 drm/nouveau/nvkm: remove detect/mmio/subdev_mask from device args

In reply to Ben Skeggs

All callers now pass "detect=true, mmio=true, subdev_mask=~0ULL", so remove the function arguments, and associated code.

---
 .../gpu/drm/nouveau/include/nvkm/core/pci.h   |   1 -
 .../gpu/drm/nouveau/include/nvkm/core/tegra.h |   1 -
 drivers/gpu/drm/nouveau/nouveau_drm.c         |   6 +-
 .../gpu/drm/nouveau/nvkm/engine/device/base.c | 422 +++++++++---------
 .../gpu/drm/nouveau/nvkm/engine/device/pci.c  |   4 +-
 .../gpu/drm/nouveau/nvkm/engine/device/priv.h |   1 -
 .../drm/nouveau/nvkm/engine/device/tegra.c    |   5 +-
 7 files changed, 209 insertions(+), 231 deletions(-)
drivers/gpu/drm/nouveau/include/nvkm/core/pci.h +0 -1
index b4b5df3e1610..7444c4d59e09 100644
@@ -10,6 +10,5 @@ struct nvkm_device_pci {
 };
 
 int nvkm_device_pci_new(struct pci_dev *, const char *cfg, const char *dbg,
-			bool detect, bool mmio, u64 subdev_mask,
 			struct nvkm_device **);
 #endif
drivers/gpu/drm/nouveau/include/nvkm/core/tegra.h +0 -1
index ccee53d4e4ec..22f74fc88cd7 100644
@@ -51,6 +51,5 @@ struct nvkm_device_tegra_func {
 int nvkm_device_tegra_new(const struct nvkm_device_tegra_func *,
 			  struct platform_device *,
 			  const char *cfg, const char *dbg,
-			  bool detect, bool mmio, u64 subdev_mask,
 			  struct nvkm_device **);
 #endif
drivers/gpu/drm/nouveau/nouveau_drm.c +2 -4
index 6726f463d2d3..694df7c050ef 100644
@@ -840,8 +840,7 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 	/* We need to check that the chipset is supported before booting
 	 * fbdev off the hardware, as there's no way to put it back.
 	 */
-	ret = nvkm_device_pci_new(pdev, nouveau_config, nouveau_debug,
-				  true, true, ~0ULL, &device);
+	ret = nvkm_device_pci_new(pdev, nouveau_config, nouveau_debug, &device);
 	if (ret)
 		return ret;
 
@@ -1387,8 +1386,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
 	struct nouveau_drm *drm;
 	int err;
 
-	err = nvkm_device_tegra_new(func, pdev, nouveau_config, nouveau_debug,
-				    true, true, ~0ULL, pdevice);
+	err = nvkm_device_tegra_new(func, pdev, nouveau_config, nouveau_debug, pdevice);
 	if (err)
 		goto err_free;
 
drivers/gpu/drm/nouveau/nvkm/engine/device/base.c +205 -217

478 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/device/pci.c +1 -3
index abccb2bb68a6..3ff6436007fa 100644
@@ -1626,7 +1626,6 @@ nvkm_device_pci_func = {
 
 int
 nvkm_device_pci_new(struct pci_dev *pci_dev, const char *cfg, const char *dbg,
-		    bool detect, bool mmio, u64 subdev_mask,
 		    struct nvkm_device **pdevice)
 {
 	const struct nvkm_device_quirk *quirk = NULL;
@@ -1680,8 +1679,7 @@ nvkm_device_pci_new(struct pci_dev *pci_dev, const char *cfg, const char *dbg,
 				    pci_dev->bus->number << 16 |
 				    PCI_SLOT(pci_dev->devfn) << 8 |
 				    PCI_FUNC(pci_dev->devfn), name,
-			       cfg, dbg, detect, mmio, subdev_mask,
-			       &pdev->device);
+			       cfg, dbg, &pdev->device);
 
 	if (ret)
 		return ret;
drivers/gpu/drm/nouveau/nvkm/engine/device/priv.h +0 -1
index bf3176bec18a..c182d9c3e4fa 100644
@@ -56,7 +56,6 @@ int  nvkm_device_ctor(const struct nvkm_device_func *,
 		      const struct nvkm_device_quirk *,
 		      struct device *, enum nvkm_device_type, u64 handle,
 		      const char *name, const char *cfg, const char *dbg,
-		      bool detect, bool mmio, u64 subdev_mask,
 		      struct nvkm_device *);
 int  nvkm_device_init(struct nvkm_device *);
 int  nvkm_device_fini(struct nvkm_device *, bool suspend);
drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c +1 -4
index 87caa4a72921..d1c294f00665 100644
@@ -237,7 +237,6 @@ int
 nvkm_device_tegra_new(const struct nvkm_device_tegra_func *func,
 		      struct platform_device *pdev,
 		      const char *cfg, const char *dbg,
-		      bool detect, bool mmio, u64 subdev_mask,
 		      struct nvkm_device **pdevice)
 {
 	struct nvkm_device_tegra *tdev;
@@ -311,8 +310,7 @@ nvkm_device_tegra_new(const struct nvkm_device_tegra_func *func,
 	tdev->gpu_speedo_id = tegra_sku_info.gpu_speedo_id;
 	ret = nvkm_device_ctor(&nvkm_device_tegra_func, NULL, &pdev->dev,
 			       NVKM_DEVICE_TEGRA, pdev->id, NULL,
-			       cfg, dbg, detect, mmio, subdev_mask,
-			       &tdev->device);
+			       cfg, dbg, &tdev->device);
 	if (ret)
 		goto powerdown;
 
@@ -333,7 +331,6 @@ int
 nvkm_device_tegra_new(const struct nvkm_device_tegra_func *func,
 		      struct platform_device *pdev,
 		      const char *cfg, const char *dbg,
-		      bool detect, bool mmio, u64 subdev_mask,
 		      struct nvkm_device **pdevice)
 {
 	return -ENOSYS;
Signature · 1 line
2.45.1
author
#32 lore raw

PATCH v2 12/37 drm/nouveau/nvkm: remove perfmon

In reply to Ben Skeggs

This has never really been used for anything, in part due to never having reclocking stable enough in general to attempt to implement dynamic clock changes based on load, etc.

To avoid having to rework its interfaces, remove it entirely.

---
 drivers/gpu/drm/nouveau/include/nvif/class.h  |   3 -
 drivers/gpu/drm/nouveau/include/nvif/if0002.h |  39 -
 drivers/gpu/drm/nouveau/include/nvif/if0003.h |  34 -
 .../drm/nouveau/include/nvkm/core/layout.h    |   1 -
 .../gpu/drm/nouveau/include/nvkm/engine/pm.h  |  29 -
 drivers/gpu/drm/nouveau/nvkm/engine/Kbuild    |   1 -
 .../gpu/drm/nouveau/nvkm/engine/device/base.c |  43 -
 .../gpu/drm/nouveau/nvkm/engine/device/priv.h |   1 -
 .../gpu/drm/nouveau/nvkm/engine/device/user.c |   3 +-
 drivers/gpu/drm/nouveau/nvkm/engine/pm/Kbuild |  11 -
 drivers/gpu/drm/nouveau/nvkm/engine/pm/base.c | 867 ------------------
 drivers/gpu/drm/nouveau/nvkm/engine/pm/g84.c  | 165 ----
 .../gpu/drm/nouveau/nvkm/engine/pm/gf100.c    | 243 -----
 .../gpu/drm/nouveau/nvkm/engine/pm/gf100.h    |  20 -
 .../gpu/drm/nouveau/nvkm/engine/pm/gf108.c    |  66 --
 .../gpu/drm/nouveau/nvkm/engine/pm/gf117.c    |  80 --
 .../gpu/drm/nouveau/nvkm/engine/pm/gk104.c    | 184 ----
 .../gpu/drm/nouveau/nvkm/engine/pm/gt200.c    | 157 ----
 .../gpu/drm/nouveau/nvkm/engine/pm/gt215.c    | 138 ---
 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv40.c | 123 ---
 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv40.h |  15 -
 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv50.c | 175 ----
 drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h | 105 ---
 23 files changed, 1 insertion(+), 2502 deletions(-)
 delete mode 100644 drivers/gpu/drm/nouveau/include/nvif/if0002.h
 delete mode 100644 drivers/gpu/drm/nouveau/include/nvif/if0003.h
 delete mode 100644 drivers/gpu/drm/nouveau/include/nvkm/engine/pm.h
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/Kbuild
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/base.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/g84.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gf100.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gf100.h
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gf108.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gf117.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gk104.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gt200.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/gt215.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv40.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv40.h
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/nv50.c
 delete mode 100644 drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h
drivers/gpu/drm/nouveau/include/nvif/class.h +0 -3
index e668ab1664f0..824e052dcc25 100644
@@ -7,9 +7,6 @@
 
 #define NVIF_CLASS_CONTROL                           /* if0001.h */ -0x00000001
 
-#define NVIF_CLASS_PERFMON                           /* if0002.h */ -0x00000002
-#define NVIF_CLASS_PERFDOM                           /* if0003.h */ -0x00000003
-
 #define NVIF_CLASS_SW_NV04                           /* if0004.h */ -0x00000004
 #define NVIF_CLASS_SW_NV10                           /* if0005.h */ -0x00000005
 #define NVIF_CLASS_SW_NV50                           /* if0005.h */ -0x00000006
drivers/gpu/drm/nouveau/include/nvif/if0002.h deleted +0 -39
deleted file mode 100644
index df2915d6a61e..000000000000
@@ -1,39 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-#ifndef __NVIF_IF0002_H__
-#define __NVIF_IF0002_H__
-
-#define NVIF_PERFMON_V0_QUERY_DOMAIN                                       0x00
-#define NVIF_PERFMON_V0_QUERY_SIGNAL                                       0x01
-#define NVIF_PERFMON_V0_QUERY_SOURCE                                       0x02
-
-struct nvif_perfmon_query_domain_v0 {
-	__u8  version;
-	__u8  id;
-	__u8  counter_nr;
-	__u8  iter;
-	__u16 signal_nr;
-	__u8  pad05[2];
-	char  name[64];
-};
-
-struct nvif_perfmon_query_signal_v0 {
-	__u8  version;
-	__u8  domain;
-	__u16 iter;
-	__u8  signal;
-	__u8  source_nr;
-	__u8  pad05[2];
-	char  name[64];
-};
-
-struct nvif_perfmon_query_source_v0 {
-	__u8  version;
-	__u8  domain;
-	__u8  signal;
-	__u8  iter;
-	__u8  pad04[4];
-	__u32 source;
-	__u32 mask;
-	char  name[64];
-};
-#endif
drivers/gpu/drm/nouveau/include/nvif/if0003.h deleted +0 -34
deleted file mode 100644
index 78467da07c37..000000000000
@@ -1,34 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-#ifndef __NVIF_IF0003_H__
-#define __NVIF_IF0003_H__
-
-struct nvif_perfdom_v0 {
-	__u8  version;
-	__u8  domain;
-	__u8  mode;
-	__u8  pad03[1];
-	struct {
-		__u8  signal[4];
-		__u64 source[4][8];
-		__u16 logic_op;
-	} ctr[4];
-};
-
-#define NVIF_PERFDOM_V0_INIT                                               0x00
-#define NVIF_PERFDOM_V0_SAMPLE                                             0x01
-#define NVIF_PERFDOM_V0_READ                                               0x02
-
-struct nvif_perfdom_init {
-};
-
-struct nvif_perfdom_sample {
-};
-
-struct nvif_perfdom_read_v0 {
-	__u8  version;
-	__u8  pad01[7];
-	__u32 ctr[4];
-	__u32 clk;
-	__u8  pad04[4];
-};
-#endif
drivers/gpu/drm/nouveau/include/nvkm/core/layout.h +0 -1
index 30c17db483cb..9d2a1abf64f9 100644
@@ -46,7 +46,6 @@ NVKM_LAYOUT_INST(NVKM_ENGINE_NVDEC   , struct nvkm_nvdec   ,    nvdec, 8)
 NVKM_LAYOUT_INST(NVKM_ENGINE_NVENC   , struct nvkm_nvenc   ,    nvenc, 3)
 NVKM_LAYOUT_INST(NVKM_ENGINE_NVJPG   , struct nvkm_engine  ,    nvjpg, 8)
 NVKM_LAYOUT_ONCE(NVKM_ENGINE_OFA     , struct nvkm_engine  ,      ofa)
-NVKM_LAYOUT_ONCE(NVKM_ENGINE_PM      , struct nvkm_pm      ,       pm)
 NVKM_LAYOUT_ONCE(NVKM_ENGINE_SEC     , struct nvkm_engine  ,      sec)
 NVKM_LAYOUT_ONCE(NVKM_ENGINE_SEC2    , struct nvkm_sec2    ,     sec2)
 NVKM_LAYOUT_ONCE(NVKM_ENGINE_SW      , struct nvkm_sw      ,       sw)
drivers/gpu/drm/nouveau/include/nvkm/engine/pm.h deleted +0 -29
deleted file mode 100644
index af89d46ea360..000000000000
@@ -1,29 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-#ifndef __NVKM_PM_H__
-#define __NVKM_PM_H__
-#include <core/engine.h>
-
-struct nvkm_pm {
-	const struct nvkm_pm_func *func;
-	struct nvkm_engine engine;
-
-	struct {
-		spinlock_t lock;
-		struct nvkm_object *object;
-	} client;
-
-	struct list_head domains;
-	struct list_head sources;
-	u32 sequence;
-};
-
-int nv40_pm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_pm **);
-int nv50_pm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_pm **);
-int g84_pm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_pm **);
-int gt200_pm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_pm **);
-int gt215_pm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_pm **);
-int gf100_pm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_pm **);
-int gf108_pm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_pm **);
-int gf117_pm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_pm **);
-int gk104_pm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_pm **);
-#endif
drivers/gpu/drm/nouveau/nvkm/engine/Kbuild +0 -1
index bfaaff645a34..2e48b0816670 100644
@@ -19,7 +19,6 @@ include $(src)/nvkm/engine/nvenc/Kbuild
 include $(src)/nvkm/engine/nvdec/Kbuild
 include $(src)/nvkm/engine/nvjpg/Kbuild
 include $(src)/nvkm/engine/ofa/Kbuild
-include $(src)/nvkm/engine/pm/Kbuild
 include $(src)/nvkm/engine/sec/Kbuild
 include $(src)/nvkm/engine/sec2/Kbuild
 include $(src)/nvkm/engine/sw/Kbuild
drivers/gpu/drm/nouveau/nvkm/engine/device/base.c +0 -43

301 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/device/priv.h +0 -1
index c182d9c3e4fa..e42b18820a95 100644
@@ -45,7 +45,6 @@
 #include <engine/nvdec.h>
 #include <engine/nvjpg.h>
 #include <engine/ofa.h>
-#include <engine/pm.h>
 #include <engine/sec.h>
 #include <engine/sec2.h>
 #include <engine/sw.h>
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c +1 -2
index 7fd4800a876a..d937c54e8dfa 100644
@@ -322,8 +322,7 @@ nvkm_udevice_child_get(struct nvkm_object *object, int index,
 	struct nvkm_engine *engine;
 	u64 mask = (1ULL << NVKM_ENGINE_DMAOBJ) |
 		   (1ULL << NVKM_ENGINE_FIFO) |
-		   (1ULL << NVKM_ENGINE_DISP) |
-		   (1ULL << NVKM_ENGINE_PM);
+		   (1ULL << NVKM_ENGINE_DISP);
 	const struct nvkm_device_oclass *sclass = NULL;
 	int i;
 
drivers/gpu/drm/nouveau/nvkm/engine/pm/Kbuild deleted +0 -11
deleted file mode 100644
index 2cc8a5f6fe0c..000000000000
@@ -1,11 +0,0 @@
-# SPDX-License-Identifier: MIT
-nvkm-y += nvkm/engine/pm/base.o
-nvkm-y += nvkm/engine/pm/nv40.o
-nvkm-y += nvkm/engine/pm/nv50.o
-nvkm-y += nvkm/engine/pm/g84.o
-nvkm-y += nvkm/engine/pm/gt200.o
-nvkm-y += nvkm/engine/pm/gt215.o
-nvkm-y += nvkm/engine/pm/gf100.o
-nvkm-y += nvkm/engine/pm/gf108.o
-nvkm-y += nvkm/engine/pm/gf117.o
-nvkm-y += nvkm/engine/pm/gk104.o
drivers/gpu/drm/nouveau/nvkm/engine/pm/base.c deleted +0 -867

867 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/pm/g84.c deleted +0 -165

165 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/pm/gf100.c deleted +0 -243

243 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/pm/gf100.h deleted +0 -20
deleted file mode 100644
index bc4b014c4e8e..000000000000
@@ -1,20 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-#ifndef __NVKM_PM_NVC0_H__
-#define __NVKM_PM_NVC0_H__
-#include "priv.h"
-
-struct gf100_pm_func {
-	const struct nvkm_specdom *doms_hub;
-	const struct nvkm_specdom *doms_gpc;
-	const struct nvkm_specdom *doms_part;
-};
-
-int gf100_pm_new_(const struct gf100_pm_func *, struct nvkm_device *, enum nvkm_subdev_type, int,
-		  struct nvkm_pm **);
-
-extern const struct nvkm_funcdom gf100_perfctr_func;
-extern const struct nvkm_specdom gf100_pm_gpc[];
-
-extern const struct nvkm_specsrc gf100_pbfb_sources[];
-extern const struct nvkm_specsrc gf100_pmfb_sources[];
-#endif
drivers/gpu/drm/nouveau/nvkm/engine/pm/gf108.c deleted +0 -66

66 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/pm/gf117.c deleted +0 -80

80 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/pm/gk104.c deleted +0 -184

184 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/pm/gt200.c deleted +0 -157

157 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/pm/gt215.c deleted +0 -138

138 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/pm/nv40.c deleted +0 -123

123 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/pm/nv40.h deleted +0 -15
deleted file mode 100644
index afb79843723d..000000000000
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-#ifndef __NVKM_PM_NV40_H__
-#define __NVKM_PM_NV40_H__
-#define nv40_pm(p) container_of((p), struct nv40_pm, base)
-#include "priv.h"
-
-struct nv40_pm {
-	struct nvkm_pm base;
-	u32 sequence;
-};
-
-int nv40_pm_new_(const struct nvkm_specdom *, struct nvkm_device *, enum nvkm_subdev_type, int,
-		 struct nvkm_pm **);
-extern const struct nvkm_funcdom nv40_perfctr_func;
-#endif
drivers/gpu/drm/nouveau/nvkm/engine/pm/nv50.c deleted +0 -175

175 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h deleted +0 -105

105 lines not on this page · raw message

Signature · 1 line
2.45.1
author
#33 lore raw

PATCH v2 13/37 drm/nouveau/nvkm: remove nvkm_client_search()

In reply to Ben Skeggs

Has been unused for a while now.

---
 drivers/gpu/drm/nouveau/include/nvkm/core/client.h |  1 -
 drivers/gpu/drm/nouveau/nvkm/core/client.c         | 13 -------------
 2 files changed, 14 deletions(-)
drivers/gpu/drm/nouveau/include/nvkm/core/client.h +0 -1
index 932c9fd0b2d8..15f27fdd877a 100644
@@ -22,7 +22,6 @@ struct nvkm_client {
 
 int  nvkm_client_new(const char *name, u64 device, const char *cfg, const char *dbg,
 		     int (*)(u64, void *, u32), struct nvkm_client **);
-struct nvkm_client *nvkm_client_search(struct nvkm_client *, u64 handle);
 
 /* logging for client-facing objects */
 #define nvif_printk(o,l,p,f,a...) do {                                         \
drivers/gpu/drm/nouveau/nvkm/core/client.c +0 -13
index c55662937ab2..48416c5039a1 100644
@@ -67,19 +67,6 @@ nvkm_uclient_sclass = {
 	.ctor = nvkm_uclient_new,
 };
 
-static const struct nvkm_object_func nvkm_client;
-struct nvkm_client *
-nvkm_client_search(struct nvkm_client *client, u64 handle)
-{
-	struct nvkm_object *object;
-
-	object = nvkm_object_search(client, handle, &nvkm_client);
-	if (IS_ERR(object))
-		return (void *)object;
-
-	return nvkm_client(object);
-}
-
 static int
 nvkm_client_mthd_devlist(struct nvkm_client *client, void *data, u32 size)
 {
Signature · 1 line
2.45.1
author
#34 lore raw

PATCH v2 14/37 drm/nouveau/nvif: remove support for userspace backends

In reply to Ben Skeggs

The tools that used libnvkm no longer exist.

---
 drivers/gpu/drm/nouveau/include/nvif/driver.h |  3 --
 drivers/gpu/drm/nouveau/nvif/driver.c         | 32 ++++---------------
 2 files changed, 7 insertions(+), 28 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/driver.h +0 -3
index 7a3af05f7f98..8d294ce3cf0a 100644
@@ -21,7 +21,4 @@ int nvif_driver_init(const char *drv, const char *cfg, const char *dbg,
 		     const char *name, u64 device, struct nvif_client *);
 
 extern const struct nvif_driver nvif_driver_nvkm;
-extern const struct nvif_driver nvif_driver_drm;
-extern const struct nvif_driver nvif_driver_lib;
-extern const struct nvif_driver nvif_driver_null;
 #endif
drivers/gpu/drm/nouveau/nvif/driver.c +7 -25
index 5e00dd07afed..acb708df2559 100644
@@ -24,35 +24,17 @@
 #include <nvif/driver.h>
 #include <nvif/client.h>
 
-static const struct nvif_driver *
-nvif_driver[] = {
-#ifdef __KERNEL__
-	&nvif_driver_nvkm,
-#else
-	&nvif_driver_drm,
-	&nvif_driver_lib,
-	&nvif_driver_null,
-#endif
-	NULL
-};
-
 int
 nvif_driver_init(const char *drv, const char *cfg, const char *dbg,
 		 const char *name, u64 device, struct nvif_client *client)
 {
-	int ret = -EINVAL, i;
+	int ret;
+
+	client->driver = &nvif_driver_nvkm;
 
-	for (i = 0; (client->driver = nvif_driver[i]); i++) {
-		if (!drv || !strcmp(client->driver->name, drv)) {
-			ret = client->driver->init(name, device, cfg, dbg,
-						   &client->object.priv);
-			if (ret == 0)
-				break;
-			client->driver->fini(client->object.priv);
-		}
-	}
+	ret = client->driver->init(name, device, cfg, dbg, &client->object.priv);
+	if (ret)
+		return ret;
 
-	if (ret == 0)
-		ret = nvif_client_ctor(client, name, device, client);
-	return ret;
+	return nvif_client_ctor(client, name, device, client);
 }
Signature · 1 line
2.45.1
author
#35 lore raw

PATCH v2 15/37 drm/nouveau/nvif: remove route/token

In reply to Ben Skeggs

These were a cludge used to prevent userspace's nvif ioctl from accessing objects created by the kernel for the same client.

That interface was removed in a previous patch, so these are no longer useful for anything.

---
 drivers/gpu/drm/nouveau/include/nvif/client.h |  1 -
 .../drm/nouveau/include/nvkm/core/object.h    |  2 --
 .../drm/nouveau/include/nvkm/core/oclass.h    |  2 --
 drivers/gpu/drm/nouveau/nouveau_abi16.c       |  8 --------
 drivers/gpu/drm/nouveau/nvif/client.c         |  1 -
 drivers/gpu/drm/nouveau/nvif/object.c         |  3 ---
 drivers/gpu/drm/nouveau/nvkm/core/client.c    |  2 --
 drivers/gpu/drm/nouveau/nvkm/core/ioctl.c     | 19 ++++---------------
 drivers/gpu/drm/nouveau/nvkm/core/object.c    |  2 --
 drivers/gpu/drm/nouveau/nvkm/core/uevent.c    |  4 ++--
 10 files changed, 6 insertions(+), 38 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/client.h +0 -1
index 5d9395e651b6..64b033222c56 100644
@@ -8,7 +8,6 @@ struct nvif_client {
 	struct nvif_object object;
 	const struct nvif_driver *driver;
 	u64 version;
-	u8 route;
 };
 
 int  nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device,
drivers/gpu/drm/nouveau/include/nvkm/core/object.h +0 -2
index ed1f66360782..d4f1c964ba31 100644
@@ -15,8 +15,6 @@ struct nvkm_object {
 
 	struct list_head head;
 	struct list_head tree;
-	u8  route;
-	u64 token;
 	u64 object;
 	struct rb_node node;
 };
drivers/gpu/drm/nouveau/include/nvkm/core/oclass.h +0 -2
index 8e1b945d38f3..cad05f0e7948 100644
@@ -21,8 +21,6 @@ struct nvkm_oclass {
 	const void *priv;
 	const void *engn;
 	u32 handle;
-	u8  route;
-	u64 token;
 	u64 object;
 	struct nvkm_client *client;
 	struct nvkm_object *parent;
drivers/gpu/drm/nouveau/nouveau_abi16.c +0 -8
index 6f0548e57f9e..704977530b6b 100644
@@ -521,7 +521,6 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
 	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
 	struct nouveau_abi16_chan *chan;
 	struct nouveau_abi16_ntfy *ntfy;
-	struct nvif_client *client;
 	struct nvif_sclass *sclass;
 	s32 oclass = 0;
 	int ret, i;
@@ -531,7 +530,6 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
 
 	if (init->handle == ~0)
 		return nouveau_abi16_put(abi16, -EINVAL);
-	client = &abi16->cli->base;
 
 	chan = nouveau_abi16_chan(abi16, init->channel);
 	if (!chan)
@@ -596,10 +594,8 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
 
 	list_add(&ntfy->head, &chan->notifiers);
 
-	client->route = NVDRM_OBJECT_ABI16;
 	ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", init->handle,
 			       oclass, NULL, 0, &ntfy->object);
-	client->route = NVDRM_OBJECT_NVIF;
 
 	if (ret)
 		nouveau_abi16_ntfy_fini(chan, ntfy);
@@ -615,7 +611,6 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
 	struct nouveau_abi16_chan *chan;
 	struct nouveau_abi16_ntfy *ntfy;
 	struct nvif_device *device;
-	struct nvif_client *client;
 	struct nv_dma_v0 args = {};
 	int ret;
 
@@ -626,7 +621,6 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
 	/* completely unnecessary for these chipsets... */
 	if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
 		return nouveau_abi16_put(abi16, -EINVAL);
-	client = &abi16->cli->base;
 
 	chan = nouveau_abi16_chan(abi16, info->channel);
 	if (!chan)
@@ -663,11 +657,9 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
 		args.limit += chan->ntfy->offset;
 	}
 
-	client->route = NVDRM_OBJECT_ABI16;
 	ret = nvif_object_ctor(&chan->chan->user, "abi16Ntfy", info->handle,
 			       NV_DMA_IN_MEMORY, &args, sizeof(args),
 			       &ntfy->object);
-	client->route = NVDRM_OBJECT_NVIF;
 	if (ret)
 		goto done;
 
drivers/gpu/drm/nouveau/nvif/client.c +0 -1
index 3a27245f467f..cd5439b73ac7 100644
@@ -79,7 +79,6 @@ nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device,
 
 	client->object.client = client;
 	client->object.handle = ~0;
-	client->route = NVIF_IOCTL_V0_ROUTE_NVIF;
 	client->driver = parent->driver;
 
 	if (ret == 0) {
drivers/gpu/drm/nouveau/nvif/object.c +0 -3
index 4d1aaee8fe15..2b3e05197846 100644
@@ -40,7 +40,6 @@ nvif_object_ioctl(struct nvif_object *object, void *data, u32 size, void **hack)
 			args->v0.object = nvif_handle(object);
 		else
 			args->v0.object = 0;
-		args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY;
 	} else
 		return -ENOSYS;
 
@@ -286,8 +285,6 @@ nvif_object_ctor(struct nvif_object *parent, const char *name, u32 handle,
 		args->ioctl.version = 0;
 		args->ioctl.type = NVIF_IOCTL_V0_NEW;
 		args->new.version = 0;
-		args->new.route = parent->client->route;
-		args->new.token = nvif_handle(object);
 		args->new.object = nvif_handle(object);
 		args->new.handle = handle;
 		args->new.oclass = oclass;
drivers/gpu/drm/nouveau/nvkm/core/client.c +0 -2
index 48416c5039a1..95cbb5b682f2 100644
@@ -51,8 +51,6 @@ nvkm_uclient_new(const struct nvkm_oclass *oclass, void *argv, u32 argc,
 
 	client->object.client = oclass->client;
 	client->object.handle = oclass->handle;
-	client->object.route  = oclass->route;
-	client->object.token  = oclass->token;
 	client->object.object = oclass->object;
 	client->debug = oclass->client->debug;
 	*pobject = &client->object;
drivers/gpu/drm/nouveau/nvkm/core/ioctl.c +4 -15
index 0b33287e43a7..39d5c9700867 100644
@@ -112,10 +112,9 @@ nvkm_ioctl_new(struct nvkm_client *client,
 
 	nvif_ioctl(parent, "new size %d\n", size);
 	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
-		nvif_ioctl(parent, "new vers %d handle %08x class %08x "
-				   "route %02x token %llx object %016llx\n",
+		nvif_ioctl(parent, "new vers %d handle %08x class %08x object %016llx\n",
 			   args->v0.version, args->v0.handle, args->v0.oclass,
-			   args->v0.route, args->v0.token, args->v0.object);
+			   args->v0.object);
 	} else
 		return ret;
 
@@ -127,8 +126,6 @@ nvkm_ioctl_new(struct nvkm_client *client,
 	do {
 		memset(&oclass, 0x00, sizeof(oclass));
 		oclass.handle = args->v0.handle;
-		oclass.route  = args->v0.route;
-		oclass.token  = args->v0.token;
 		oclass.object = args->v0.object;
 		oclass.client = client;
 		oclass.parent = parent;
@@ -331,7 +328,7 @@ nvkm_ioctl_v0[] = {
 
 static int
 nvkm_ioctl_path(struct nvkm_client *client, u64 handle, u32 type,
-		void *data, u32 size, u8 owner, u8 *route, u64 *token)
+		void *data, u32 size)
 {
 	struct nvkm_object *object;
 	int ret;
@@ -342,13 +339,6 @@ nvkm_ioctl_path(struct nvkm_client *client, u64 handle, u32 type,
 		return PTR_ERR(object);
 	}
 
-	if (owner != NVIF_IOCTL_V0_OWNER_ANY && owner != object->route) {
-		nvif_ioctl(&client->object, "route != owner\n");
-		return -EACCES;
-	}
-	*route = object->route;
-	*token = object->token;
-
 	if (ret = -EINVAL, type < ARRAY_SIZE(nvkm_ioctl_v0)) {
 		if (nvkm_ioctl_v0[type].version == 0)
 			ret = nvkm_ioctl_v0[type].func(client, object, data, size);
@@ -374,8 +364,7 @@ nvkm_ioctl(struct nvkm_client *client, void *data, u32 size, void **hack)
 			   args->v0.version, args->v0.type, args->v0.object,
 			   args->v0.owner);
 		ret = nvkm_ioctl_path(client, args->v0.object, args->v0.type,
-				      data, size, args->v0.owner,
-				      &args->v0.route, &args->v0.token);
+				      data, size);
 	}
 
 	if (ret != 1) {
drivers/gpu/drm/nouveau/nvkm/core/object.c +0 -2
index aea3ba72027a..580b8c7f25af 100644
@@ -313,8 +313,6 @@ nvkm_object_ctor(const struct nvkm_object_func *func,
 	object->engine = nvkm_engine_ref(oclass->engine);
 	object->oclass = oclass->base.oclass;
 	object->handle = oclass->handle;
-	object->route  = oclass->route;
-	object->token  = oclass->token;
 	object->object = oclass->object;
 	INIT_LIST_HEAD(&object->head);
 	INIT_LIST_HEAD(&object->tree);
drivers/gpu/drm/nouveau/nvkm/core/uevent.c +2 -2
index ba9d9edaec75..cc254c390a57 100644
@@ -116,9 +116,9 @@ nvkm_uevent_ntfy(struct nvkm_event_ntfy *ntfy, u32 bits)
 	struct nvkm_client *client = uevent->object.client;
 
 	if (uevent->func)
-		return uevent->func(uevent->parent, uevent->object.token, bits);
+		return uevent->func(uevent->parent, uevent->object.object, bits);
 
-	return client->event(uevent->object.token, NULL, 0);
+	return client->event(uevent->object.object, NULL, 0);
 }
 
 int
Signature · 1 line
2.45.1
#36 lore raw

Re: [PATCH v2 15/37] drm/nouveau/nvif: remove route/token

Quoted 5 lines · Ben Skeggs

These were a cludge used to prevent userspace's nvif ioctl from accessing objects created by the kernel for the same client.

That interface was removed in a previous patch, so these are no longer useful for anything.

It would probably be good to move this patch directly after the one it depends on.

Quoted 249 lines
---
 drivers/gpu/drm/nouveau/include/nvif/client.h |  1 -
 .../drm/nouveau/include/nvkm/core/object.h    |  2 --
 .../drm/nouveau/include/nvkm/core/oclass.h    |  2 --
 drivers/gpu/drm/nouveau/nouveau_abi16.c       |  8 --------
 drivers/gpu/drm/nouveau/nvif/client.c         |  1 -
 drivers/gpu/drm/nouveau/nvif/object.c         |  3 ---
 drivers/gpu/drm/nouveau/nvkm/core/client.c    |  2 --
 drivers/gpu/drm/nouveau/nvkm/core/ioctl.c     | 19 ++++---------------
 drivers/gpu/drm/nouveau/nvkm/core/object.c    |  2 --
 drivers/gpu/drm/nouveau/nvkm/core/uevent.c    |  4 ++--
 10 files changed, 6 insertions(+), 38 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/client.h +0 -1
index 5d9395e651b6..64b033222c56 100644
@@ -8,7 +8,6 @@ struct nvif_client {
 	struct nvif_object object;
 	const struct nvif_driver *driver;
 	u64 version;
-	u8 route;
 };
 
 int  nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device,
drivers/gpu/drm/nouveau/include/nvkm/core/object.h +0 -2
index ed1f66360782..d4f1c964ba31 100644
@@ -15,8 +15,6 @@ struct nvkm_object {
 
 	struct list_head head;
 	struct list_head tree;
-	u8  route;
-	u64 token;
 	u64 object;
 	struct rb_node node;
 };
drivers/gpu/drm/nouveau/include/nvkm/core/oclass.h +0 -2
index 8e1b945d38f3..cad05f0e7948 100644
@@ -21,8 +21,6 @@ struct nvkm_oclass {
 	const void *priv;
 	const void *engn;
 	u32 handle;
-	u8  route;
-	u64 token;
 	u64 object;
 	struct nvkm_client *client;
 	struct nvkm_object *parent;
drivers/gpu/drm/nouveau/nouveau_abi16.c +0 -8
index 6f0548e57f9e..704977530b6b 100644
@@ -521,7 +521,6 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
 	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
 	struct nouveau_abi16_chan *chan;
 	struct nouveau_abi16_ntfy *ntfy;
-	struct nvif_client *client;
 	struct nvif_sclass *sclass;
 	s32 oclass = 0;
 	int ret, i;
@@ -531,7 +530,6 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
 
 	if (init->handle == ~0)
 		return nouveau_abi16_put(abi16, -EINVAL);
-	client = &abi16->cli->base;
 
 	chan = nouveau_abi16_chan(abi16, init->channel);
 	if (!chan)
@@ -596,10 +594,8 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
 
 	list_add(&ntfy->head, &chan->notifiers);
 
-	client->route = NVDRM_OBJECT_ABI16;
 	ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", init->handle,
 			       oclass, NULL, 0, &ntfy->object);
-	client->route = NVDRM_OBJECT_NVIF;
 
 	if (ret)
 		nouveau_abi16_ntfy_fini(chan, ntfy);
@@ -615,7 +611,6 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
 	struct nouveau_abi16_chan *chan;
 	struct nouveau_abi16_ntfy *ntfy;
 	struct nvif_device *device;
-	struct nvif_client *client;
 	struct nv_dma_v0 args = {};
 	int ret;
 
@@ -626,7 +621,6 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
 	/* completely unnecessary for these chipsets... */
 	if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
 		return nouveau_abi16_put(abi16, -EINVAL);
-	client = &abi16->cli->base;
 
 	chan = nouveau_abi16_chan(abi16, info->channel);
 	if (!chan)
@@ -663,11 +657,9 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
 		args.limit += chan->ntfy->offset;
 	}
 
-	client->route = NVDRM_OBJECT_ABI16;
 	ret = nvif_object_ctor(&chan->chan->user, "abi16Ntfy", info->handle,
 			       NV_DMA_IN_MEMORY, &args, sizeof(args),
 			       &ntfy->object);
-	client->route = NVDRM_OBJECT_NVIF;
 	if (ret)
 		goto done;
 
drivers/gpu/drm/nouveau/nvif/client.c +0 -1
index 3a27245f467f..cd5439b73ac7 100644
@@ -79,7 +79,6 @@ nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device,
 
 	client->object.client = client;
 	client->object.handle = ~0;
-	client->route = NVIF_IOCTL_V0_ROUTE_NVIF;
 	client->driver = parent->driver;
 
 	if (ret == 0) {
drivers/gpu/drm/nouveau/nvif/object.c +0 -3
index 4d1aaee8fe15..2b3e05197846 100644
@@ -40,7 +40,6 @@ nvif_object_ioctl(struct nvif_object *object, void *data, u32 size, void **hack)
 			args->v0.object = nvif_handle(object);
 		else
 			args->v0.object = 0;
-		args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY;
 	} else
 		return -ENOSYS;
 
@@ -286,8 +285,6 @@ nvif_object_ctor(struct nvif_object *parent, const char *name, u32 handle,
 		args->ioctl.version = 0;
 		args->ioctl.type = NVIF_IOCTL_V0_NEW;
 		args->new.version = 0;
-		args->new.route = parent->client->route;
-		args->new.token = nvif_handle(object);
 		args->new.object = nvif_handle(object);
 		args->new.handle = handle;
 		args->new.oclass = oclass;
drivers/gpu/drm/nouveau/nvkm/core/client.c +0 -2
index 48416c5039a1..95cbb5b682f2 100644
@@ -51,8 +51,6 @@ nvkm_uclient_new(const struct nvkm_oclass *oclass, void *argv, u32 argc,
 
 	client->object.client = oclass->client;
 	client->object.handle = oclass->handle;
-	client->object.route  = oclass->route;
-	client->object.token  = oclass->token;
 	client->object.object = oclass->object;
 	client->debug = oclass->client->debug;
 	*pobject = &client->object;
drivers/gpu/drm/nouveau/nvkm/core/ioctl.c +4 -15
index 0b33287e43a7..39d5c9700867 100644
@@ -112,10 +112,9 @@ nvkm_ioctl_new(struct nvkm_client *client,
 
 	nvif_ioctl(parent, "new size %d\n", size);
 	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
-		nvif_ioctl(parent, "new vers %d handle %08x class %08x "
-				   "route %02x token %llx object %016llx\n",
+		nvif_ioctl(parent, "new vers %d handle %08x class %08x object %016llx\n",
 			   args->v0.version, args->v0.handle, args->v0.oclass,
-			   args->v0.route, args->v0.token, args->v0.object);
+			   args->v0.object);
 	} else
 		return ret;
 
@@ -127,8 +126,6 @@ nvkm_ioctl_new(struct nvkm_client *client,
 	do {
 		memset(&oclass, 0x00, sizeof(oclass));
 		oclass.handle = args->v0.handle;
-		oclass.route  = args->v0.route;
-		oclass.token  = args->v0.token;
 		oclass.object = args->v0.object;
 		oclass.client = client;
 		oclass.parent = parent;
@@ -331,7 +328,7 @@ nvkm_ioctl_v0[] = {
 
 static int
 nvkm_ioctl_path(struct nvkm_client *client, u64 handle, u32 type,
-		void *data, u32 size, u8 owner, u8 *route, u64 *token)
+		void *data, u32 size)
 {
 	struct nvkm_object *object;
 	int ret;
@@ -342,13 +339,6 @@ nvkm_ioctl_path(struct nvkm_client *client, u64 handle, u32 type,
 		return PTR_ERR(object);
 	}
 
-	if (owner != NVIF_IOCTL_V0_OWNER_ANY && owner != object->route) {
-		nvif_ioctl(&client->object, "route != owner\n");
-		return -EACCES;
-	}
-	*route = object->route;
-	*token = object->token;
-
 	if (ret = -EINVAL, type < ARRAY_SIZE(nvkm_ioctl_v0)) {
 		if (nvkm_ioctl_v0[type].version == 0)
 			ret = nvkm_ioctl_v0[type].func(client, object, data, size);
@@ -374,8 +364,7 @@ nvkm_ioctl(struct nvkm_client *client, void *data, u32 size, void **hack)
 			   args->v0.version, args->v0.type, args->v0.object,
 			   args->v0.owner);
 		ret = nvkm_ioctl_path(client, args->v0.object, args->v0.type,
-				      data, size, args->v0.owner,
-				      &args->v0.route, &args->v0.token);
+				      data, size);
 	}
 
 	if (ret != 1) {
drivers/gpu/drm/nouveau/nvkm/core/object.c +0 -2
index aea3ba72027a..580b8c7f25af 100644
@@ -313,8 +313,6 @@ nvkm_object_ctor(const struct nvkm_object_func *func,
 	object->engine = nvkm_engine_ref(oclass->engine);
 	object->oclass = oclass->base.oclass;
 	object->handle = oclass->handle;
-	object->route  = oclass->route;
-	object->token  = oclass->token;
 	object->object = oclass->object;
 	INIT_LIST_HEAD(&object->head);
 	INIT_LIST_HEAD(&object->tree);
drivers/gpu/drm/nouveau/nvkm/core/uevent.c +2 -2
index ba9d9edaec75..cc254c390a57 100644
@@ -116,9 +116,9 @@ nvkm_uevent_ntfy(struct nvkm_event_ntfy *ntfy, u32 bits)
 	struct nvkm_client *client = uevent->object.client;
 
 	if (uevent->func)
-		return uevent->func(uevent->parent, uevent->object.token, bits);
+		return uevent->func(uevent->parent, uevent->object.object, bits);
 
-	return client->event(uevent->object.token, NULL, 0);
+	return client->event(uevent->object.object, NULL, 0);
 }
 
 int
Signature · 1 line
2.45.1
author
#37 lore raw

Re: [PATCH v2 15/37] drm/nouveau/nvif: remove route/token

Quoted 8 lines · Danilo Krummrich
Quoted 5 lines · Ben Skeggs

These were a cludge used to prevent userspace's nvif ioctl from accessing objects created by the kernel for the same client.

That interface was removed in a previous patch, so these are no longer useful for anything.

It would probably be good to move this patch directly after the one it depends on.

Is this really necessary?  The ordering of this series is already incredibly fragile, with a bunch of chicken/egg situations that were tough to untangle.  Moreover, I don't see what real value it adds at this point.

Quoted 249 lines
Quoted 249 lines
---
  drivers/gpu/drm/nouveau/include/nvif/client.h |  1 -
  .../drm/nouveau/include/nvkm/core/object.h    |  2 --
  .../drm/nouveau/include/nvkm/core/oclass.h    |  2 --
  drivers/gpu/drm/nouveau/nouveau_abi16.c       |  8 --------
  drivers/gpu/drm/nouveau/nvif/client.c         |  1 -
  drivers/gpu/drm/nouveau/nvif/object.c         |  3 ---
  drivers/gpu/drm/nouveau/nvkm/core/client.c    |  2 --
  drivers/gpu/drm/nouveau/nvkm/core/ioctl.c     | 19 ++++---------------
  drivers/gpu/drm/nouveau/nvkm/core/object.c    |  2 --
  drivers/gpu/drm/nouveau/nvkm/core/uevent.c    |  4 ++--
  10 files changed, 6 insertions(+), 38 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/client.h +0 -1
index 5d9395e651b6..64b033222c56 100644
@@ -8,7 +8,6 @@ struct nvif_client {
  	struct nvif_object object;
  	const struct nvif_driver *driver;
  	u64 version;
-	u8 route;
  };
 
  int  nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device,
drivers/gpu/drm/nouveau/include/nvkm/core/object.h +0 -2
index ed1f66360782..d4f1c964ba31 100644
@@ -15,8 +15,6 @@ struct nvkm_object {
 
  	struct list_head head;
  	struct list_head tree;
-	u8  route;
-	u64 token;
  	u64 object;
  	struct rb_node node;
  };
drivers/gpu/drm/nouveau/include/nvkm/core/oclass.h +0 -2
index 8e1b945d38f3..cad05f0e7948 100644
@@ -21,8 +21,6 @@ struct nvkm_oclass {
  	const void *priv;
  	const void *engn;
  	u32 handle;
-	u8  route;
-	u64 token;
  	u64 object;
  	struct nvkm_client *client;
  	struct nvkm_object *parent;
drivers/gpu/drm/nouveau/nouveau_abi16.c +0 -8
index 6f0548e57f9e..704977530b6b 100644
@@ -521,7 +521,6 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
  	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
  	struct nouveau_abi16_chan *chan;
  	struct nouveau_abi16_ntfy *ntfy;
-	struct nvif_client *client;
  	struct nvif_sclass *sclass;
  	s32 oclass = 0;
  	int ret, i;
@@ -531,7 +530,6 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
 
  	if (init->handle == ~0)
  		return nouveau_abi16_put(abi16, -EINVAL);
-	client = &abi16->cli->base;
 
  	chan = nouveau_abi16_chan(abi16, init->channel);
  	if (!chan)
@@ -596,10 +594,8 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
 
  	list_add(&ntfy->head, &chan->notifiers);
 
-	client->route = NVDRM_OBJECT_ABI16;
  	ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", init->handle,
  			       oclass, NULL, 0, &ntfy->object);
-	client->route = NVDRM_OBJECT_NVIF;
 
  	if (ret)
  		nouveau_abi16_ntfy_fini(chan, ntfy);
@@ -615,7 +611,6 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
  	struct nouveau_abi16_chan *chan;
  	struct nouveau_abi16_ntfy *ntfy;
  	struct nvif_device *device;
-	struct nvif_client *client;
  	struct nv_dma_v0 args = {};
  	int ret;
 
@@ -626,7 +621,6 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
  	/* completely unnecessary for these chipsets... */
  	if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
  		return nouveau_abi16_put(abi16, -EINVAL);
-	client = &abi16->cli->base;
 
  	chan = nouveau_abi16_chan(abi16, info->channel);
  	if (!chan)
@@ -663,11 +657,9 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
  		args.limit += chan->ntfy->offset;
  	}
 
-	client->route = NVDRM_OBJECT_ABI16;
  	ret = nvif_object_ctor(&chan->chan->user, "abi16Ntfy", info->handle,
  			       NV_DMA_IN_MEMORY, &args, sizeof(args),
  			       &ntfy->object);
-	client->route = NVDRM_OBJECT_NVIF;
  	if (ret)
  		goto done;
 
drivers/gpu/drm/nouveau/nvif/client.c +0 -1
index 3a27245f467f..cd5439b73ac7 100644
@@ -79,7 +79,6 @@ nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device,
 
  	client->object.client = client;
  	client->object.handle = ~0;
-	client->route = NVIF_IOCTL_V0_ROUTE_NVIF;
  	client->driver = parent->driver;
 
  	if (ret == 0) {
drivers/gpu/drm/nouveau/nvif/object.c +0 -3
index 4d1aaee8fe15..2b3e05197846 100644
@@ -40,7 +40,6 @@ nvif_object_ioctl(struct nvif_object *object, void *data, u32 size, void **hack)
  			args->v0.object = nvif_handle(object);
  		else
  			args->v0.object = 0;
-		args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY;
  	} else
  		return -ENOSYS;
 
@@ -286,8 +285,6 @@ nvif_object_ctor(struct nvif_object *parent, const char *name, u32 handle,
  		args->ioctl.version = 0;
  		args->ioctl.type = NVIF_IOCTL_V0_NEW;
  		args->new.version = 0;
-		args->new.route = parent->client->route;
-		args->new.token = nvif_handle(object);
  		args->new.object = nvif_handle(object);
  		args->new.handle = handle;
  		args->new.oclass = oclass;
drivers/gpu/drm/nouveau/nvkm/core/client.c +0 -2
index 48416c5039a1..95cbb5b682f2 100644
@@ -51,8 +51,6 @@ nvkm_uclient_new(const struct nvkm_oclass *oclass, void *argv, u32 argc,
 
  	client->object.client = oclass->client;
  	client->object.handle = oclass->handle;
-	client->object.route  = oclass->route;
-	client->object.token  = oclass->token;
  	client->object.object = oclass->object;
  	client->debug = oclass->client->debug;
  	*pobject = &client->object;
drivers/gpu/drm/nouveau/nvkm/core/ioctl.c +4 -15
index 0b33287e43a7..39d5c9700867 100644
@@ -112,10 +112,9 @@ nvkm_ioctl_new(struct nvkm_client *client,
 
  	nvif_ioctl(parent, "new size %d\n", size);
  	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
-		nvif_ioctl(parent, "new vers %d handle %08x class %08x "
-				   "route %02x token %llx object %016llx\n",
+		nvif_ioctl(parent, "new vers %d handle %08x class %08x object %016llx\n",
  			   args->v0.version, args->v0.handle, args->v0.oclass,
-			   args->v0.route, args->v0.token, args->v0.object);
+			   args->v0.object);
  	} else
  		return ret;
 
@@ -127,8 +126,6 @@ nvkm_ioctl_new(struct nvkm_client *client,
  	do {
  		memset(&oclass, 0x00, sizeof(oclass));
  		oclass.handle = args->v0.handle;
-		oclass.route  = args->v0.route;
-		oclass.token  = args->v0.token;
  		oclass.object = args->v0.object;
  		oclass.client = client;
  		oclass.parent = parent;
@@ -331,7 +328,7 @@ nvkm_ioctl_v0[] = {
 
  static int
  nvkm_ioctl_path(struct nvkm_client *client, u64 handle, u32 type,
-		void *data, u32 size, u8 owner, u8 *route, u64 *token)
+		void *data, u32 size)
  {
  	struct nvkm_object *object;
  	int ret;
@@ -342,13 +339,6 @@ nvkm_ioctl_path(struct nvkm_client *client, u64 handle, u32 type,
  		return PTR_ERR(object);
  	}
 
-	if (owner != NVIF_IOCTL_V0_OWNER_ANY && owner != object->route) {
-		nvif_ioctl(&client->object, "route != owner\n");
-		return -EACCES;
-	}
-	*route = object->route;
-	*token = object->token;
-
  	if (ret = -EINVAL, type < ARRAY_SIZE(nvkm_ioctl_v0)) {
  		if (nvkm_ioctl_v0[type].version == 0)
  			ret = nvkm_ioctl_v0[type].func(client, object, data, size);
@@ -374,8 +364,7 @@ nvkm_ioctl(struct nvkm_client *client, void *data, u32 size, void **hack)
  			   args->v0.version, args->v0.type, args->v0.object,
  			   args->v0.owner);
  		ret = nvkm_ioctl_path(client, args->v0.object, args->v0.type,
-				      data, size, args->v0.owner,
-				      &args->v0.route, &args->v0.token);
+				      data, size);
  	}
 
  	if (ret != 1) {
drivers/gpu/drm/nouveau/nvkm/core/object.c +0 -2
index aea3ba72027a..580b8c7f25af 100644
@@ -313,8 +313,6 @@ nvkm_object_ctor(const struct nvkm_object_func *func,
  	object->engine = nvkm_engine_ref(oclass->engine);
  	object->oclass = oclass->base.oclass;
  	object->handle = oclass->handle;
-	object->route  = oclass->route;
-	object->token  = oclass->token;
  	object->object = oclass->object;
  	INIT_LIST_HEAD(&object->head);
  	INIT_LIST_HEAD(&object->tree);
drivers/gpu/drm/nouveau/nvkm/core/uevent.c +2 -2
index ba9d9edaec75..cc254c390a57 100644
@@ -116,9 +116,9 @@ nvkm_uevent_ntfy(struct nvkm_event_ntfy *ntfy, u32 bits)
  	struct nvkm_client *client = uevent->object.client;
 
  	if (uevent->func)
-		return uevent->func(uevent->parent, uevent->object.token, bits);
+		return uevent->func(uevent->parent, uevent->object.object, bits);
 
-	return client->event(uevent->object.token, NULL, 0);
+	return client->event(uevent->object.object, NULL, 0);
  }
 
  int
Signature · 1 line
2.45.1
#38 lore raw

Re: [PATCH v2 15/37] drm/nouveau/nvif: remove route/token

Quoted 6 lines · Ben Skeggs
Quoted 4 lines · Danilo Krummrich
Quoted 3 lines · Ben Skeggs

These were a cludge used to prevent userspace's nvif ioctl from accessing objects created by the kernel for the same client.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

That interface was removed in a previous patch, so these are no longer useful for anything.

It would probably be good to move this patch directly after the one it depends on.

Is this really necessary?  The ordering of this series is already incredibly fragile, with a bunch of chicken/egg situations that were tough to untangle.  Moreover, I don't see what real value it adds at this point.

Not for this series, but in general. If such large series are required, having directly related ones close to each other, makes it way easier to review.

Quoted 228 lines
Quoted 227 lines
Quoted 227 lines
---
  drivers/gpu/drm/nouveau/include/nvif/client.h |  1 -
  .../drm/nouveau/include/nvkm/core/object.h    |  2 --
  .../drm/nouveau/include/nvkm/core/oclass.h    |  2 --
  drivers/gpu/drm/nouveau/nouveau_abi16.c       |  8 --------
  drivers/gpu/drm/nouveau/nvif/client.c         |  1 -
  drivers/gpu/drm/nouveau/nvif/object.c         |  3 ---
  drivers/gpu/drm/nouveau/nvkm/core/client.c    |  2 --
  drivers/gpu/drm/nouveau/nvkm/core/ioctl.c     | 19 ++++---------------
  drivers/gpu/drm/nouveau/nvkm/core/object.c    |  2 --
  drivers/gpu/drm/nouveau/nvkm/core/uevent.c    |  4 ++--
  10 files changed, 6 insertions(+), 38 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/client.h +0 -1
index 5d9395e651b6..64b033222c56 100644
@@ -8,7 +8,6 @@ struct nvif_client {
  	struct nvif_object object;
  	const struct nvif_driver *driver;
  	u64 version;
-	u8 route;
  };
  int  nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device,
drivers/gpu/drm/nouveau/include/nvkm/core/object.h +0 -2
index ed1f66360782..d4f1c964ba31 100644
@@ -15,8 +15,6 @@ struct nvkm_object {
  	struct list_head head;
  	struct list_head tree;
-	u8  route;
-	u64 token;
  	u64 object;
  	struct rb_node node;
  };
drivers/gpu/drm/nouveau/include/nvkm/core/oclass.h +0 -2
index 8e1b945d38f3..cad05f0e7948 100644
@@ -21,8 +21,6 @@ struct nvkm_oclass {
  	const void *priv;
  	const void *engn;
  	u32 handle;
-	u8  route;
-	u64 token;
  	u64 object;
  	struct nvkm_client *client;
  	struct nvkm_object *parent;
drivers/gpu/drm/nouveau/nouveau_abi16.c +0 -8
index 6f0548e57f9e..704977530b6b 100644
@@ -521,7 +521,6 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
  	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
  	struct nouveau_abi16_chan *chan;
  	struct nouveau_abi16_ntfy *ntfy;
-	struct nvif_client *client;
  	struct nvif_sclass *sclass;
  	s32 oclass = 0;
  	int ret, i;
@@ -531,7 +530,6 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
  	if (init->handle == ~0)
  		return nouveau_abi16_put(abi16, -EINVAL);
-	client = &abi16->cli->base;
  	chan = nouveau_abi16_chan(abi16, init->channel);
  	if (!chan)
@@ -596,10 +594,8 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
  	list_add(&ntfy->head, &chan->notifiers);
-	client->route = NVDRM_OBJECT_ABI16;
  	ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", init->handle,
  			       oclass, NULL, 0, &ntfy->object);
-	client->route = NVDRM_OBJECT_NVIF;
  	if (ret)
  		nouveau_abi16_ntfy_fini(chan, ntfy);
@@ -615,7 +611,6 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
  	struct nouveau_abi16_chan *chan;
  	struct nouveau_abi16_ntfy *ntfy;
  	struct nvif_device *device;
-	struct nvif_client *client;
  	struct nv_dma_v0 args = {};
  	int ret;
@@ -626,7 +621,6 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
  	/* completely unnecessary for these chipsets... */
  	if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
  		return nouveau_abi16_put(abi16, -EINVAL);
-	client = &abi16->cli->base;
  	chan = nouveau_abi16_chan(abi16, info->channel);
  	if (!chan)
@@ -663,11 +657,9 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
  		args.limit += chan->ntfy->offset;
  	}
-	client->route = NVDRM_OBJECT_ABI16;
  	ret = nvif_object_ctor(&chan->chan->user, "abi16Ntfy", info->handle,
  			       NV_DMA_IN_MEMORY, &args, sizeof(args),
  			       &ntfy->object);
-	client->route = NVDRM_OBJECT_NVIF;
  	if (ret)
  		goto done;
drivers/gpu/drm/nouveau/nvif/client.c +0 -1
index 3a27245f467f..cd5439b73ac7 100644
@@ -79,7 +79,6 @@ nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device,
  	client->object.client = client;
  	client->object.handle = ~0;
-	client->route = NVIF_IOCTL_V0_ROUTE_NVIF;
  	client->driver = parent->driver;
  	if (ret == 0) {
drivers/gpu/drm/nouveau/nvif/object.c +0 -3
index 4d1aaee8fe15..2b3e05197846 100644
@@ -40,7 +40,6 @@ nvif_object_ioctl(struct nvif_object *object, void *data, u32 size, void **hack)
  			args->v0.object = nvif_handle(object);
  		else
  			args->v0.object = 0;
-		args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY;
  	} else
  		return -ENOSYS;
@@ -286,8 +285,6 @@ nvif_object_ctor(struct nvif_object *parent, const char *name, u32 handle,
  		args->ioctl.version = 0;
  		args->ioctl.type = NVIF_IOCTL_V0_NEW;
  		args->new.version = 0;
-		args->new.route = parent->client->route;
-		args->new.token = nvif_handle(object);
  		args->new.object = nvif_handle(object);
  		args->new.handle = handle;
  		args->new.oclass = oclass;
drivers/gpu/drm/nouveau/nvkm/core/client.c +0 -2
index 48416c5039a1..95cbb5b682f2 100644
@@ -51,8 +51,6 @@ nvkm_uclient_new(const struct nvkm_oclass *oclass, void *argv, u32 argc,
  	client->object.client = oclass->client;
  	client->object.handle = oclass->handle;
-	client->object.route  = oclass->route;
-	client->object.token  = oclass->token;
  	client->object.object = oclass->object;
  	client->debug = oclass->client->debug;
  	*pobject = &client->object;
drivers/gpu/drm/nouveau/nvkm/core/ioctl.c +4 -15
index 0b33287e43a7..39d5c9700867 100644
@@ -112,10 +112,9 @@ nvkm_ioctl_new(struct nvkm_client *client,
  	nvif_ioctl(parent, "new size %d\n", size);
  	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
-		nvif_ioctl(parent, "new vers %d handle %08x class %08x "
-				   "route %02x token %llx object %016llx\n",
+		nvif_ioctl(parent, "new vers %d handle %08x class %08x object %016llx\n",
  			   args->v0.version, args->v0.handle, args->v0.oclass,
-			   args->v0.route, args->v0.token, args->v0.object);
+			   args->v0.object);
  	} else
  		return ret;
@@ -127,8 +126,6 @@ nvkm_ioctl_new(struct nvkm_client *client,
  	do {
  		memset(&oclass, 0x00, sizeof(oclass));
  		oclass.handle = args->v0.handle;
-		oclass.route  = args->v0.route;
-		oclass.token  = args->v0.token;
  		oclass.object = args->v0.object;
  		oclass.client = client;
  		oclass.parent = parent;
@@ -331,7 +328,7 @@ nvkm_ioctl_v0[] = {
  static int
  nvkm_ioctl_path(struct nvkm_client *client, u64 handle, u32 type,
-		void *data, u32 size, u8 owner, u8 *route, u64 *token)
+		void *data, u32 size)
  {
  	struct nvkm_object *object;
  	int ret;
@@ -342,13 +339,6 @@ nvkm_ioctl_path(struct nvkm_client *client, u64 handle, u32 type,
  		return PTR_ERR(object);
  	}
-	if (owner != NVIF_IOCTL_V0_OWNER_ANY && owner != object->route) {
-		nvif_ioctl(&client->object, "route != owner\n");
-		return -EACCES;
-	}
-	*route = object->route;
-	*token = object->token;
-
  	if (ret = -EINVAL, type < ARRAY_SIZE(nvkm_ioctl_v0)) {
  		if (nvkm_ioctl_v0[type].version == 0)
  			ret = nvkm_ioctl_v0[type].func(client, object, data, size);
@@ -374,8 +364,7 @@ nvkm_ioctl(struct nvkm_client *client, void *data, u32 size, void **hack)
  			   args->v0.version, args->v0.type, args->v0.object,
  			   args->v0.owner);
  		ret = nvkm_ioctl_path(client, args->v0.object, args->v0.type,
-				      data, size, args->v0.owner,
-				      &args->v0.route, &args->v0.token);
+				      data, size);
  	}
  	if (ret != 1) {
drivers/gpu/drm/nouveau/nvkm/core/object.c +0 -2
index aea3ba72027a..580b8c7f25af 100644
@@ -313,8 +313,6 @@ nvkm_object_ctor(const struct nvkm_object_func *func,
  	object->engine = nvkm_engine_ref(oclass->engine);
  	object->oclass = oclass->base.oclass;
  	object->handle = oclass->handle;
-	object->route  = oclass->route;
-	object->token  = oclass->token;
  	object->object = oclass->object;
  	INIT_LIST_HEAD(&object->head);
  	INIT_LIST_HEAD(&object->tree);
drivers/gpu/drm/nouveau/nvkm/core/uevent.c +2 -2
index ba9d9edaec75..cc254c390a57 100644
@@ -116,9 +116,9 @@ nvkm_uevent_ntfy(struct nvkm_event_ntfy *ntfy, u32 bits)
  	struct nvkm_client *client = uevent->object.client;
  	if (uevent->func)
-		return uevent->func(uevent->parent, uevent->object.token, bits);
+		return uevent->func(uevent->parent, uevent->object.object, bits);
-	return client->event(uevent->object.token, NULL, 0);
+	return client->event(uevent->object.object, NULL, 0);
  }
  int
Signature · 1 line
2.45.1
author
#39 lore raw

PATCH v2 16/37 drm/nouveau/nvif: remove nvxx_object()

In reply to Ben Skeggs

This hasn't been used in a while.

Moves some io accessors to another include at the same time to fix a compile issue that resulted from <nvkm/core/object.h> no longer being included.

---
 drivers/gpu/drm/nouveau/include/nvif/object.h |  7 -------
 drivers/gpu/drm/nouveau/include/nvif/os.h     | 19 +++++++++++++++++++
 .../gpu/drm/nouveau/include/nvkm/core/os.h    | 19 -------------------
 3 files changed, 19 insertions(+), 26 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/object.h +0 -7
index f52399caee82..478cbb8f2dfe 100644
@@ -134,11 +134,4 @@ struct nvif_mclass {
 #define NVIF_MR32(p,A...) DRF_MR(NVIF_RD32_, NVIF_WR32_, u32, (p), 0, ##A)
 #define NVIF_MV32(p,A...) DRF_MV(NVIF_RD32_, NVIF_WR32_, u32, (p), 0, ##A)
 #define NVIF_MD32(p,A...) DRF_MD(NVIF_RD32_, NVIF_WR32_, u32, (p), 0, ##A)
-
-/*XXX*/
-#include <core/object.h>
-#define nvxx_object(a) ({                                                      \
-	struct nvif_object *_object = (a);                                     \
-	(struct nvkm_object *)_object->priv;                                   \
-})
 #endif
drivers/gpu/drm/nouveau/include/nvif/os.h +19 -0
index 429d0106c123..a2eaf3929ac3 100644
@@ -34,4 +34,23 @@
 
 #include <soc/tegra/fuse.h>
 #include <soc/tegra/pmc.h>
+
+#ifdef __BIG_ENDIAN
+#define ioread16_native ioread16be
+#define iowrite16_native iowrite16be
+#define ioread32_native  ioread32be
+#define iowrite32_native iowrite32be
+#else
+#define ioread16_native ioread16
+#define iowrite16_native iowrite16
+#define ioread32_native  ioread32
+#define iowrite32_native iowrite32
+#endif
+
+#define iowrite64_native(v,p) do {                                             \
+	u32 __iomem *_p = (u32 __iomem *)(p);                                  \
+	u64 _v = (v);                                                          \
+	iowrite32_native(lower_32_bits(_v), &_p[0]);                           \
+	iowrite32_native(upper_32_bits(_v), &_p[1]);                           \
+} while(0)
 #endif
drivers/gpu/drm/nouveau/include/nvkm/core/os.h +0 -19
index 3fd5c007a663..9b05612e6490 100644
@@ -3,25 +3,6 @@
 #define __NVKM_OS_H__
 #include <nvif/os.h>
 
-#ifdef __BIG_ENDIAN
-#define ioread16_native ioread16be
-#define iowrite16_native iowrite16be
-#define ioread32_native  ioread32be
-#define iowrite32_native iowrite32be
-#else
-#define ioread16_native ioread16
-#define iowrite16_native iowrite16
-#define ioread32_native  ioread32
-#define iowrite32_native iowrite32
-#endif
-
-#define iowrite64_native(v,p) do {                                             \
-	u32 __iomem *_p = (u32 __iomem *)(p);				       \
-	u64 _v = (v);							       \
-	iowrite32_native(lower_32_bits(_v), &_p[0]);			       \
-	iowrite32_native(upper_32_bits(_v), &_p[1]);			       \
-} while(0)
-
 struct nvkm_blob {
 	void *data;
 	u32 size;
Signature · 1 line
2.45.1
#40 lore raw

Re: [PATCH v2 16/37] drm/nouveau/nvif: remove nvxx_object()

Quoted 3 lines · Ben Skeggs

This hasn't been used in a while.

Moves some io accessors to another include at the same time to

Please don't just say something was moves somewhere, say where it was moved to.

Quoted 2 lines

fix a compile issue that resulted from <nvkm/core/object.h> no longer being included.

Saying "resulted" instead of "results" here sounds a bit like a previous commit introduced the issue, but it's actually this one. Please use present tense.

Quoted 85 lines
---
 drivers/gpu/drm/nouveau/include/nvif/object.h |  7 -------
 drivers/gpu/drm/nouveau/include/nvif/os.h     | 19 +++++++++++++++++++
 .../gpu/drm/nouveau/include/nvkm/core/os.h    | 19 -------------------
 3 files changed, 19 insertions(+), 26 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/object.h +0 -7
index f52399caee82..478cbb8f2dfe 100644
@@ -134,11 +134,4 @@ struct nvif_mclass {
 #define NVIF_MR32(p,A...) DRF_MR(NVIF_RD32_, NVIF_WR32_, u32, (p), 0, ##A)
 #define NVIF_MV32(p,A...) DRF_MV(NVIF_RD32_, NVIF_WR32_, u32, (p), 0, ##A)
 #define NVIF_MD32(p,A...) DRF_MD(NVIF_RD32_, NVIF_WR32_, u32, (p), 0, ##A)
-
-/*XXX*/
-#include <core/object.h>
-#define nvxx_object(a) ({                                                      \
-	struct nvif_object *_object = (a);                                     \
-	(struct nvkm_object *)_object->priv;                                   \
-})
 #endif
drivers/gpu/drm/nouveau/include/nvif/os.h +19 -0
index 429d0106c123..a2eaf3929ac3 100644
@@ -34,4 +34,23 @@
 
 #include <soc/tegra/fuse.h>
 #include <soc/tegra/pmc.h>
+
+#ifdef __BIG_ENDIAN
+#define ioread16_native ioread16be
+#define iowrite16_native iowrite16be
+#define ioread32_native  ioread32be
+#define iowrite32_native iowrite32be
+#else
+#define ioread16_native ioread16
+#define iowrite16_native iowrite16
+#define ioread32_native  ioread32
+#define iowrite32_native iowrite32
+#endif
+
+#define iowrite64_native(v,p) do {                                             \
+	u32 __iomem *_p = (u32 __iomem *)(p);                                  \
+	u64 _v = (v);                                                          \
+	iowrite32_native(lower_32_bits(_v), &_p[0]);                           \
+	iowrite32_native(upper_32_bits(_v), &_p[1]);                           \
+} while(0)
 #endif
drivers/gpu/drm/nouveau/include/nvkm/core/os.h +0 -19
index 3fd5c007a663..9b05612e6490 100644
@@ -3,25 +3,6 @@
 #define __NVKM_OS_H__
 #include <nvif/os.h>
 
-#ifdef __BIG_ENDIAN
-#define ioread16_native ioread16be
-#define iowrite16_native iowrite16be
-#define ioread32_native  ioread32be
-#define iowrite32_native iowrite32be
-#else
-#define ioread16_native ioread16
-#define iowrite16_native iowrite16
-#define ioread32_native  ioread32
-#define iowrite32_native iowrite32
-#endif
-
-#define iowrite64_native(v,p) do {                                             \
-	u32 __iomem *_p = (u32 __iomem *)(p);				       \
-	u64 _v = (v);							       \
-	iowrite32_native(lower_32_bits(_v), &_p[0]);			       \
-	iowrite32_native(upper_32_bits(_v), &_p[1]);			       \
-} while(0)
-
 struct nvkm_blob {
 	void *data;
 	u32 size;
Signature · 1 line
2.45.1
author
#41 lore raw

PATCH v2 17/37 drm/nouveau/nvif: remove nvxx_client()

In reply to Ben Skeggs

Make use of nouveau_cli.name instead of nvkm_client.name.

---
 drivers/gpu/drm/nouveau/include/nvif/client.h | 5 -----
 drivers/gpu/drm/nouveau/nouveau_chan.c        | 2 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c         | 3 ---
 drivers/gpu/drm/nouveau/nouveau_fence.c       | 2 +-
 4 files changed, 2 insertions(+), 10 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/client.h +0 -5
index 64b033222c56..5210007d7669 100644
@@ -18,9 +18,4 @@ int  nvif_client_suspend(struct nvif_client *);
 int  nvif_client_resume(struct nvif_client *);
 
 /*XXX*/
-#include <core/client.h>
-#define nvxx_client(a) ({                                                      \
-	struct nvif_client *_client = (a);                                     \
-	(struct nvkm_client *)_client->object.priv;                            \
-})
 #endif
drivers/gpu/drm/nouveau/nouveau_chan.c +1 -1
index 66fca95c10c7..ce04c40e6f8f 100644
@@ -78,7 +78,7 @@ nouveau_channel_idle(struct nouveau_channel *chan)
 
 		if (ret) {
 			NV_PRINTK(err, cli, "failed to idle channel %d [%s]\n",
-				  chan->chid, nvxx_client(&cli->base)->name);
+				  chan->chid, cli->name);
 			return ret;
 		}
 	}
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -3
index 694df7c050ef..e0e1fcfcab1e 100644
@@ -644,9 +644,6 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
 	if (ret)
 		goto fail_master;
 
-	nvxx_client(&drm->client.base)->debug =
-		nvkm_dbgopt(nouveau_debug, "DRM");
-
 	INIT_LIST_HEAD(&drm->clients);
 	mutex_init(&drm->clients_lock);
 	spin_lock_init(&drm->tile.lock);
drivers/gpu/drm/nouveau/nouveau_fence.c +1 -1
index ba469767a20f..1450fb8c57c3 100644
@@ -200,7 +200,7 @@ nouveau_fence_context_new(struct nouveau_channel *chan, struct nouveau_fence_cha
 	else if (chan == chan->drm->channel)
 		strcpy(fctx->name, "generic kernel channel");
 	else
-		strcpy(fctx->name, nvxx_client(&cli->base)->name);
+		strcpy(fctx->name, cli->name);
 
 	kref_init(&fctx->fence_ref);
 	if (!priv->uevent)
Signature · 1 line
2.45.1
author
#42 lore raw

PATCH v2 18/37 drm/nouveau/nvif: remove driver keep/fini

In reply to Ben Skeggs

These are remnants of code long gone. Remove them.

---
 drivers/gpu/drm/nouveau/include/nvif/driver.h | 2 --
 drivers/gpu/drm/nouveau/nouveau_nvif.c        | 1 -
 drivers/gpu/drm/nouveau/nvif/client.c         | 6 +-----
 3 files changed, 1 insertion(+), 8 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/driver.h +0 -2
index 8d294ce3cf0a..7b08ff769039 100644
@@ -8,13 +8,11 @@ struct nvif_driver {
 	const char *name;
 	int (*init)(const char *name, u64 device, const char *cfg,
 		    const char *dbg, void **priv);
-	void (*fini)(void *priv);
 	int (*suspend)(void *priv);
 	int (*resume)(void *priv);
 	int (*ioctl)(void *priv, void *data, u32 size, void **hack);
 	void __iomem *(*map)(void *priv, u64 handle, u32 size);
 	void (*unmap)(void *priv, void __iomem *ptr, u32 size);
-	bool keep;
 };
 
 int nvif_driver_init(const char *drv, const char *cfg, const char *dbg,
drivers/gpu/drm/nouveau/nouveau_nvif.c +0 -1
index 9a7e3f64b79f..adb802421fda 100644
@@ -97,5 +97,4 @@ nvif_driver_nvkm = {
 	.ioctl = nvkm_client_ioctl,
 	.map = nvkm_client_map,
 	.unmap = nvkm_client_unmap,
-	.keep = false,
 };
drivers/gpu/drm/nouveau/nvif/client.c +1 -5
index cd5439b73ac7..85ad5091e8e2 100644
@@ -51,11 +51,7 @@ void
 nvif_client_dtor(struct nvif_client *client)
 {
 	nvif_object_dtor(&client->object);
-	if (client->driver) {
-		if (client->driver->fini)
-			client->driver->fini(client->object.priv);
-		client->driver = NULL;
-	}
+	client->driver = NULL;
 }
 
 int
Signature · 1 line
2.45.1
author
#43 lore raw

PATCH v2 19/37 drm/nouveau/nvif: remove client device arg

In reply to Ben Skeggs

This was once used by userspace tools (with nvkm built as a library), as a way to select a "default device".

The DRM code doesn't need this at all as clients only have access to a single device already, so the value can be inherited from its parent.

---
 drivers/gpu/drm/nouveau/include/nvif/client.h | 3 +--
 drivers/gpu/drm/nouveau/include/nvif/if0000.h | 1 -
 drivers/gpu/drm/nouveau/nouveau_drm.c         | 4 +---
 drivers/gpu/drm/nouveau/nvif/client.c         | 5 ++---
 drivers/gpu/drm/nouveau/nvif/driver.c         | 2 +-
 drivers/gpu/drm/nouveau/nvkm/core/client.c    | 2 +-
 6 files changed, 6 insertions(+), 11 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/client.h +1 -2
index 5210007d7669..2c8e9bec3f79 100644
@@ -10,8 +10,7 @@ struct nvif_client {
 	u64 version;
 };
 
-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_ioctl(struct nvif_client *, void *, u32);
 int  nvif_client_suspend(struct nvif_client *);
drivers/gpu/drm/nouveau/include/nvif/if0000.h +0 -1
index f7b8f8f48760..a93f91d56a09 100644
@@ -5,7 +5,6 @@
 struct nvif_client_v0 {
 	__u8  version;
 	__u8  pad01[7];
-	__u64 device;
 	char  name[32];
 };
 
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -3
index e0e1fcfcab1e..8951a0805239 100644
@@ -241,7 +241,6 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 		{ NVIF_CLASS_VMM_NV04 , -1 },
 		{}
 	};
-	u64 device = nouveau_name(drm->dev->dev);
 	int ret;
 
 	snprintf(cli->name, sizeof(cli->name), "%s", sname);
@@ -254,8 +253,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 
 	if (cli != &drm->master) {
 		mutex_lock(&drm->master.lock);
-		ret = nvif_client_ctor(&drm->master.base, cli->name, device,
-				       &cli->base);
+		ret = nvif_client_ctor(&drm->master.base, cli->name, &cli->base);
 		mutex_unlock(&drm->master.lock);
 	}
 	if (ret) {
drivers/gpu/drm/nouveau/nvif/client.c +2 -3
index 85ad5091e8e2..bbfc80fcff43 100644
@@ -55,10 +55,9 @@ 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 };
+	struct nvif_client_v0 args = {};
 	struct {
 		struct nvif_ioctl_v0 ioctl;
 		struct nvif_ioctl_nop_v0 nop;
drivers/gpu/drm/nouveau/nvif/driver.c +1 -1
index acb708df2559..78706e97a6a2 100644
@@ -36,5 +36,5 @@ nvif_driver_init(const char *drv, const char *cfg, const char *dbg,
 	if (ret)
 		return ret;
 
-	return nvif_client_ctor(client, name, device, client);
+	return nvif_client_ctor(client, name, client);
 }
drivers/gpu/drm/nouveau/nvkm/core/client.c +1 -1
index 95cbb5b682f2..6baa3a4fa0a4 100644
@@ -42,7 +42,7 @@ nvkm_uclient_new(const struct nvkm_oclass *oclass, void *argv, u32 argc,
 
 	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, args->v0.device, NULL,
+		ret = nvkm_client_new(args->v0.name, oclass->client->device, NULL,
 				      NULL, oclass->client->event, &client);
 		if (ret)
 			return ret;
Signature · 1 line
2.45.1
#44 lore raw

Re: [PATCH v2 19/37] drm/nouveau/nvif: remove client device arg

Quoted 5 lines · Ben Skeggs

This was once used by userspace tools (with nvkm built as a library), as a way to select a "default device".

The DRM code doesn't need this at all as clients only have access to a single device already, so the value can be inherited from its parent.

"so inherit the value from its parent."

Quoted 103 lines
---
 drivers/gpu/drm/nouveau/include/nvif/client.h | 3 +--
 drivers/gpu/drm/nouveau/include/nvif/if0000.h | 1 -
 drivers/gpu/drm/nouveau/nouveau_drm.c         | 4 +---
 drivers/gpu/drm/nouveau/nvif/client.c         | 5 ++---
 drivers/gpu/drm/nouveau/nvif/driver.c         | 2 +-
 drivers/gpu/drm/nouveau/nvkm/core/client.c    | 2 +-
 6 files changed, 6 insertions(+), 11 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/client.h +1 -2
index 5210007d7669..2c8e9bec3f79 100644
@@ -10,8 +10,7 @@ struct nvif_client {
 	u64 version;
 };
 
-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_ioctl(struct nvif_client *, void *, u32);
 int  nvif_client_suspend(struct nvif_client *);
drivers/gpu/drm/nouveau/include/nvif/if0000.h +0 -1
index f7b8f8f48760..a93f91d56a09 100644
@@ -5,7 +5,6 @@
 struct nvif_client_v0 {
 	__u8  version;
 	__u8  pad01[7];
-	__u64 device;
 	char  name[32];
 };
 
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -3
index e0e1fcfcab1e..8951a0805239 100644
@@ -241,7 +241,6 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 		{ NVIF_CLASS_VMM_NV04 , -1 },
 		{}
 	};
-	u64 device = nouveau_name(drm->dev->dev);
 	int ret;
 
 	snprintf(cli->name, sizeof(cli->name), "%s", sname);
@@ -254,8 +253,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 
 	if (cli != &drm->master) {
 		mutex_lock(&drm->master.lock);
-		ret = nvif_client_ctor(&drm->master.base, cli->name, device,
-				       &cli->base);
+		ret = nvif_client_ctor(&drm->master.base, cli->name, &cli->base);
 		mutex_unlock(&drm->master.lock);
 	}
 	if (ret) {
drivers/gpu/drm/nouveau/nvif/client.c +2 -3
index 85ad5091e8e2..bbfc80fcff43 100644
@@ -55,10 +55,9 @@ 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 };
+	struct nvif_client_v0 args = {};
 	struct {
 		struct nvif_ioctl_v0 ioctl;
 		struct nvif_ioctl_nop_v0 nop;
drivers/gpu/drm/nouveau/nvif/driver.c +1 -1
index acb708df2559..78706e97a6a2 100644
@@ -36,5 +36,5 @@ nvif_driver_init(const char *drv, const char *cfg, const char *dbg,
 	if (ret)
 		return ret;
 
-	return nvif_client_ctor(client, name, device, client);
+	return nvif_client_ctor(client, name, client);
 }
drivers/gpu/drm/nouveau/nvkm/core/client.c +1 -1
index 95cbb5b682f2..6baa3a4fa0a4 100644
@@ -42,7 +42,7 @@ nvkm_uclient_new(const struct nvkm_oclass *oclass, void *argv, u32 argc,
 
 	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, args->v0.device, NULL,
+		ret = nvkm_client_new(args->v0.name, oclass->client->device, NULL,
 				      NULL, oclass->client->event, &client);
 		if (ret)
 			return ret;
Signature · 1 line
2.45.1
author
#45 lore raw

PATCH v2 20/37 drm/nouveau/nvif: remove client version

In reply to Ben Skeggs

This is not, and has never, been used for anything. Remove it.

---
 drivers/gpu/drm/nouveau/include/nvif/client.h |  2 --
 drivers/gpu/drm/nouveau/include/nvif/ioctl.h  |  7 -------
 drivers/gpu/drm/nouveau/nvif/client.c         | 20 +------------------
 drivers/gpu/drm/nouveau/nvkm/core/ioctl.c     | 13 +-----------
 4 files changed, 2 insertions(+), 40 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/client.h +0 -2
index 2c8e9bec3f79..03f1d564eb12 100644
@@ -7,12 +7,10 @@
 struct nvif_client {
 	struct nvif_object object;
 	const struct nvif_driver *driver;
-	u64 version;
 };
 
 int  nvif_client_ctor(struct nvif_client *parent, const char *name, struct nvif_client *);
 void nvif_client_dtor(struct nvif_client *);
-int  nvif_client_ioctl(struct nvif_client *, void *, u32);
 int  nvif_client_suspend(struct nvif_client *);
 int  nvif_client_resume(struct nvif_client *);
 
drivers/gpu/drm/nouveau/include/nvif/ioctl.h +0 -7
index 4e047bb1fc07..1e74245621e0 100644
@@ -2,11 +2,8 @@
 #ifndef __NVIF_IOCTL_H__
 #define __NVIF_IOCTL_H__
 
-#define NVIF_VERSION_LATEST                               0x0000000000000100ULL
-
 struct nvif_ioctl_v0 {
 	__u8  version;
-#define NVIF_IOCTL_V0_NOP                                                  0x00
 #define NVIF_IOCTL_V0_SCLASS                                               0x01
 #define NVIF_IOCTL_V0_NEW                                                  0x02
 #define NVIF_IOCTL_V0_DEL                                                  0x03
@@ -28,10 +25,6 @@ struct nvif_ioctl_v0 {
 	__u8  data[];		/* ioctl data (below) */
 };
 
-struct nvif_ioctl_nop_v0 {
-	__u64 version;
-};
-
 struct nvif_ioctl_sclass_v0 {
 	/* nvif_ioctl ... */
 	__u8  version;
drivers/gpu/drm/nouveau/nvif/client.c +1 -19
index bbfc80fcff43..fdf5054ed7d8 100644
@@ -29,12 +29,6 @@
 #include <nvif/class.h>
 #include <nvif/if0000.h>
 
-int
-nvif_client_ioctl(struct nvif_client *client, void *data, u32 size)
-{
-	return client->driver->ioctl(client->object.priv, data, size, NULL);
-}
-
 int
 nvif_client_suspend(struct nvif_client *client)
 {
@@ -58,10 +52,6 @@ int
 nvif_client_ctor(struct nvif_client *parent, const char *name, struct nvif_client *client)
 {
 	struct nvif_client_v0 args = {};
-	struct {
-		struct nvif_ioctl_v0 ioctl;
-		struct nvif_ioctl_nop_v0 nop;
-	} nop = {};
 	int ret;
 
 	strscpy_pad(args.name, name, sizeof(args.name));
@@ -75,13 +65,5 @@ nvif_client_ctor(struct nvif_client *parent, const char *name, struct nvif_clien
 	client->object.client = client;
 	client->object.handle = ~0;
 	client->driver = parent->driver;
-
-	if (ret == 0) {
-		ret = nvif_client_ioctl(client, &nop, sizeof(nop));
-		client->version = nop.nop.version;
-	}
-
-	if (ret)
-		nvif_client_dtor(client);
-	return ret;
+	return 0;
 }
drivers/gpu/drm/nouveau/nvkm/core/ioctl.c +1 -12
index 39d5c9700867..584fc43c0d75 100644
@@ -33,18 +33,7 @@ static int
 nvkm_ioctl_nop(struct nvkm_client *client,
 	       struct nvkm_object *object, void *data, u32 size)
 {
-	union {
-		struct nvif_ioctl_nop_v0 v0;
-	} *args = data;
-	int ret = -ENOSYS;
-
-	nvif_ioctl(object, "nop size %d\n", size);
-	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
-		nvif_ioctl(object, "nop vers %lld\n", args->v0.version);
-		args->v0.version = NVIF_VERSION_LATEST;
-	}
-
-	return ret;
+	return -ENOSYS;
 }
 
 #include <nvif/class.h>
Signature · 1 line
2.45.1
author
#46 lore raw

PATCH v2 21/37 drm/nouveau/nvif: remove client devlist

In reply to Ben Skeggs

This was once used by userspace tools (with nvkm built as a library), but is now unused.

---
 drivers/gpu/drm/nouveau/include/nvif/if0000.h |  9 -----
 .../drm/nouveau/include/nvkm/core/device.h    |  1 -
 drivers/gpu/drm/nouveau/nvkm/core/client.c    | 40 -------------------
 .../gpu/drm/nouveau/nvkm/engine/device/base.c | 14 -------
 4 files changed, 64 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/if0000.h +0 -9
index a93f91d56a09..c06383835337 100644
@@ -7,13 +7,4 @@ struct nvif_client_v0 {
 	__u8  pad01[7];
 	char  name[32];
 };
-
-#define NVIF_CLIENT_V0_DEVLIST                                             0x00
-
-struct nvif_client_devlist_v0 {
-	__u8  version;
-	__u8  count;
-	__u8  pad02[6];
-	__u64 device[];
-};
 #endif
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +0 -1
index f057d348221e..46afb877a296 100644
@@ -109,7 +109,6 @@ struct nvkm_device_chip {
 };
 
 struct nvkm_device *nvkm_device_find(u64 name);
-int nvkm_device_list(u64 *name, int size);
 
 /* privileged register interface accessor macros */
 #define nvkm_rd08(d,a) ioread8((d)->pri + (a))
drivers/gpu/drm/nouveau/nvkm/core/client.c +0 -40
index 6baa3a4fa0a4..5c87146b8508 100644
@@ -65,45 +65,6 @@ nvkm_uclient_sclass = {
 	.ctor = nvkm_uclient_new,
 };
 
-static int
-nvkm_client_mthd_devlist(struct nvkm_client *client, void *data, u32 size)
-{
-	union {
-		struct nvif_client_devlist_v0 v0;
-	} *args = data;
-	int ret = -ENOSYS;
-
-	nvif_ioctl(&client->object, "client devlist size %d\n", size);
-	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
-		nvif_ioctl(&client->object, "client devlist vers %d count %d\n",
-			   args->v0.version, args->v0.count);
-		if (size == sizeof(args->v0.device[0]) * args->v0.count) {
-			ret = nvkm_device_list(args->v0.device, args->v0.count);
-			if (ret >= 0) {
-				args->v0.count = ret;
-				ret = 0;
-			}
-		} else {
-			ret = -EINVAL;
-		}
-	}
-
-	return ret;
-}
-
-static int
-nvkm_client_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
-{
-	struct nvkm_client *client = nvkm_client(object);
-	switch (mthd) {
-	case NVIF_CLIENT_V0_DEVLIST:
-		return nvkm_client_mthd_devlist(client, data, size);
-	default:
-		break;
-	}
-	return -EINVAL;
-}
-
 static int
 nvkm_client_child_new(const struct nvkm_oclass *oclass,
 		      void *data, u32 size, struct nvkm_object **pobject)
@@ -145,7 +106,6 @@ static const struct nvkm_object_func
 nvkm_client = {
 	.dtor = nvkm_client_dtor,
 	.fini = nvkm_client_fini,
-	.mthd = nvkm_client_mthd,
 	.sclass = nvkm_client_child_get,
 };
 
drivers/gpu/drm/nouveau/nvkm/engine/device/base.c +0 -14
index 6ca1a4cb9cee..9093d89b16f3 100644
@@ -53,20 +53,6 @@ nvkm_device_find(u64 handle)
 	return device;
 }
 
-int
-nvkm_device_list(u64 *name, int size)
-{
-	struct nvkm_device *device;
-	int nr = 0;
-	mutex_lock(&nv_devices_mutex);
-	list_for_each_entry(device, &nv_devices, head) {
-		if (nr++ < size)
-			name[nr - 1] = device->handle;
-	}
-	mutex_unlock(&nv_devices_mutex);
-	return nr;
-}
-
 static const struct nvkm_device_chip
 nv4_chipset = {
 	.name = "NV04",
Signature · 1 line
2.45.1
author
#47 lore raw

PATCH v2 22/37 drm/nouveau/nvif: remove client fini

In reply to Ben Skeggs

Does nothing. Remove it.

---
 drivers/gpu/drm/nouveau/nvkm/core/client.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/gpu/drm/nouveau/nvkm/core/client.c +0 -7
index 5c87146b8508..72c88db627a5 100644
@@ -90,12 +90,6 @@ nvkm_client_child_get(struct nvkm_object *object, int index,
 	return 0;
 }
 
-static int
-nvkm_client_fini(struct nvkm_object *object, bool suspend)
-{
-	return 0;
-}
-
 static void *
 nvkm_client_dtor(struct nvkm_object *object)
 {
@@ -105,7 +99,6 @@ nvkm_client_dtor(struct nvkm_object *object)
 static const struct nvkm_object_func
 nvkm_client = {
 	.dtor = nvkm_client_dtor,
-	.fini = nvkm_client_fini,
 	.sclass = nvkm_client_child_get,
 };
 
Signature · 1 line
2.45.1
author
#48 lore raw

PATCH v2 23/37 drm/nouveau/nvif: remove device args

In reply to Ben Skeggs

These were once used by used by userspace tools (with nvkm built as a library), to access multiple GPUs from a single nvif_client.

The DRM code just uses the driver's default device, so we can remove the arguments.

---
 drivers/gpu/drm/nouveau/include/nvif/cl0080.h |  7 ----
 drivers/gpu/drm/nouveau/include/nvif/device.h |  3 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c         |  7 +---
 drivers/gpu/drm/nouveau/nvif/device.c         |  9 +++--
 .../gpu/drm/nouveau/nvkm/engine/device/user.c | 36 ++-----------------
 5 files changed, 9 insertions(+), 53 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/cl0080.h +0 -7
index fa161b74d967..ea937fa7bc55 100644
@@ -2,13 +2,6 @@
 #ifndef __NVIF_CL0080_H__
 #define __NVIF_CL0080_H__
 
-struct nv_device_v0 {
-	__u8  version;
-	__u8  priv;
-	__u8  pad02[6];
-	__u64 device;	/* device identifier, ~0 for client default */
-};
-
 #define NV_DEVICE_V0_INFO                                                  0x00
 #define NV_DEVICE_V0_TIME                                                  0x01
 
drivers/gpu/drm/nouveau/include/nvif/device.h +1 -2
index b0e59800a320..f7c1b3a43c84 100644
@@ -18,8 +18,7 @@ struct nvif_device {
 	struct nvif_user user;
 };
 
-int  nvif_device_ctor(struct nvif_object *, const char *name, u32 handle,
-		      s32 oclass, void *, u32, struct nvif_device *);
+int  nvif_device_ctor(struct nvif_client *, const char *name, struct nvif_device *);
 void nvif_device_dtor(struct nvif_device *);
 u64  nvif_device_time(struct nvif_device *);
 
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -6
index 8951a0805239..0beeff8552a2 100644
@@ -261,12 +261,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 		goto done;
 	}
 
-	ret = nvif_device_ctor(&cli->base.object, "drmDevice", 0, NV_DEVICE,
-			       &(struct nv_device_v0) {
-					.device = ~0,
-					.priv = true,
-			       }, sizeof(struct nv_device_v0),
-			       &cli->device);
+	ret = nvif_device_ctor(&cli->base, "drmDevice", &cli->device);
 	if (ret) {
 		NV_PRINTK(err, cli, "Device allocation failed: %d\n", ret);
 		goto done;
drivers/gpu/drm/nouveau/nvif/device.c +4 -5
index 8c3d883f3313..b14bccb9a93f 100644
@@ -21,8 +21,8 @@
  *
  * Authors: Ben Skeggs <[email protected]>
  */
-
 #include <nvif/device.h>
+#include <nvif/client.h>
 
 u64
 nvif_device_time(struct nvif_device *device)
@@ -48,11 +48,10 @@ nvif_device_dtor(struct nvif_device *device)
 }
 
 int
-nvif_device_ctor(struct nvif_object *parent, const char *name, u32 handle,
-		 s32 oclass, void *data, u32 size, struct nvif_device *device)
+nvif_device_ctor(struct nvif_client *client, const char *name, struct nvif_device *device)
 {
-	int ret = nvif_object_ctor(parent, name ? name : "nvifDevice", handle,
-				   oclass, data, size, &device->object);
+	int ret = nvif_object_ctor(&client->object, name ? name : "nvifDevice", 0,
+				   0x0080, NULL, 0, &device->object);
 	device->runlist = NULL;
 	device->user.func = NULL;
 	if (ret == 0) {
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c +3 -33
index d937c54e8dfa..65bd6712bce2 100644
@@ -357,7 +357,7 @@ nvkm_udevice_child_get(struct nvkm_object *object, int index,
 }
 
 static const struct nvkm_object_func
-nvkm_udevice_super = {
+nvkm_udevice = {
 	.init = nvkm_udevice_init,
 	.fini = nvkm_udevice_fini,
 	.mthd = nvkm_udevice_mthd,
@@ -371,50 +371,20 @@ nvkm_udevice_super = {
 	.sclass = nvkm_udevice_child_get,
 };
 
-static const struct nvkm_object_func
-nvkm_udevice = {
-	.init = nvkm_udevice_init,
-	.fini = nvkm_udevice_fini,
-	.mthd = nvkm_udevice_mthd,
-	.sclass = nvkm_udevice_child_get,
-};
-
 static int
 nvkm_udevice_new(const struct nvkm_oclass *oclass, void *data, u32 size,
 		 struct nvkm_object **pobject)
 {
-	union {
-		struct nv_device_v0 v0;
-	} *args = data;
 	struct nvkm_client *client = oclass->client;
-	struct nvkm_object *parent = &client->object;
-	const struct nvkm_object_func *func;
 	struct nvkm_udevice *udev;
-	int ret = -ENOSYS;
-
-	nvif_ioctl(parent, "create device size %d\n", size);
-	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
-		nvif_ioctl(parent, "create device v%d device %016llx\n",
-			   args->v0.version, args->v0.device);
-	} else
-		return ret;
-
-	/* give priviledged clients register access */
-	if (args->v0.priv)
-		func = &nvkm_udevice_super;
-	else
-		func = &nvkm_udevice;
 
 	if (!(udev = kzalloc(sizeof(*udev), GFP_KERNEL)))
 		return -ENOMEM;
-	nvkm_object_ctor(func, oclass, &udev->object);
+	nvkm_object_ctor(&nvkm_udevice, oclass, &udev->object);
 	*pobject = &udev->object;
 
 	/* find the device that matches what the client requested */
-	if (args->v0.device != ~0)
-		udev->device = nvkm_device_find(args->v0.device);
-	else
-		udev->device = nvkm_device_find(client->device);
+	udev->device = nvkm_device_find(client->device);
 	if (!udev->device)
 		return -ENODEV;
 
Signature · 1 line
2.45.1
#49 lore raw

Re: [PATCH v2 23/37] drm/nouveau/nvif: remove device args

Quoted 5 lines · Ben Skeggs

These were once used by used by userspace tools (with nvkm built as a library), to access multiple GPUs from a single nvif_client.

The DRM code just uses the driver's default device, so we can remove the arguments.

"so remove the argument."

Sorry for repeating that, I somehow missed the point to say "here and for subsequent commits".

Quoted 158 lines
---
 drivers/gpu/drm/nouveau/include/nvif/cl0080.h |  7 ----
 drivers/gpu/drm/nouveau/include/nvif/device.h |  3 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c         |  7 +---
 drivers/gpu/drm/nouveau/nvif/device.c         |  9 +++--
 .../gpu/drm/nouveau/nvkm/engine/device/user.c | 36 ++-----------------
 5 files changed, 9 insertions(+), 53 deletions(-)
drivers/gpu/drm/nouveau/include/nvif/cl0080.h +0 -7
index fa161b74d967..ea937fa7bc55 100644
@@ -2,13 +2,6 @@
 #ifndef __NVIF_CL0080_H__
 #define __NVIF_CL0080_H__
 
-struct nv_device_v0 {
-	__u8  version;
-	__u8  priv;
-	__u8  pad02[6];
-	__u64 device;	/* device identifier, ~0 for client default */
-};
-
 #define NV_DEVICE_V0_INFO                                                  0x00
 #define NV_DEVICE_V0_TIME                                                  0x01
 
drivers/gpu/drm/nouveau/include/nvif/device.h +1 -2
index b0e59800a320..f7c1b3a43c84 100644
@@ -18,8 +18,7 @@ struct nvif_device {
 	struct nvif_user user;
 };
 
-int  nvif_device_ctor(struct nvif_object *, const char *name, u32 handle,
-		      s32 oclass, void *, u32, struct nvif_device *);
+int  nvif_device_ctor(struct nvif_client *, const char *name, struct nvif_device *);
 void nvif_device_dtor(struct nvif_device *);
 u64  nvif_device_time(struct nvif_device *);
 
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -6
index 8951a0805239..0beeff8552a2 100644
@@ -261,12 +261,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 		goto done;
 	}
 
-	ret = nvif_device_ctor(&cli->base.object, "drmDevice", 0, NV_DEVICE,
-			       &(struct nv_device_v0) {
-					.device = ~0,
-					.priv = true,
-			       }, sizeof(struct nv_device_v0),
-			       &cli->device);
+	ret = nvif_device_ctor(&cli->base, "drmDevice", &cli->device);
 	if (ret) {
 		NV_PRINTK(err, cli, "Device allocation failed: %d\n", ret);
 		goto done;
drivers/gpu/drm/nouveau/nvif/device.c +4 -5
index 8c3d883f3313..b14bccb9a93f 100644
@@ -21,8 +21,8 @@
  *
  * Authors: Ben Skeggs <[email protected]>
  */
-
 #include <nvif/device.h>
+#include <nvif/client.h>
 
 u64
 nvif_device_time(struct nvif_device *device)
@@ -48,11 +48,10 @@ nvif_device_dtor(struct nvif_device *device)
 }
 
 int
-nvif_device_ctor(struct nvif_object *parent, const char *name, u32 handle,
-		 s32 oclass, void *data, u32 size, struct nvif_device *device)
+nvif_device_ctor(struct nvif_client *client, const char *name, struct nvif_device *device)
 {
-	int ret = nvif_object_ctor(parent, name ? name : "nvifDevice", handle,
-				   oclass, data, size, &device->object);
+	int ret = nvif_object_ctor(&client->object, name ? name : "nvifDevice", 0,
+				   0x0080, NULL, 0, &device->object);
 	device->runlist = NULL;
 	device->user.func = NULL;
 	if (ret == 0) {
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c +3 -33
index d937c54e8dfa..65bd6712bce2 100644
@@ -357,7 +357,7 @@ nvkm_udevice_child_get(struct nvkm_object *object, int index,
 }
 
 static const struct nvkm_object_func
-nvkm_udevice_super = {
+nvkm_udevice = {
 	.init = nvkm_udevice_init,
 	.fini = nvkm_udevice_fini,
 	.mthd = nvkm_udevice_mthd,
@@ -371,50 +371,20 @@ nvkm_udevice_super = {
 	.sclass = nvkm_udevice_child_get,
 };
 
-static const struct nvkm_object_func
-nvkm_udevice = {
-	.init = nvkm_udevice_init,
-	.fini = nvkm_udevice_fini,
-	.mthd = nvkm_udevice_mthd,
-	.sclass = nvkm_udevice_child_get,
-};
-
 static int
 nvkm_udevice_new(const struct nvkm_oclass *oclass, void *data, u32 size,
 		 struct nvkm_object **pobject)
 {
-	union {
-		struct nv_device_v0 v0;
-	} *args = data;
 	struct nvkm_client *client = oclass->client;
-	struct nvkm_object *parent = &client->object;
-	const struct nvkm_object_func *func;
 	struct nvkm_udevice *udev;
-	int ret = -ENOSYS;
-
-	nvif_ioctl(parent, "create device size %d\n", size);
-	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
-		nvif_ioctl(parent, "create device v%d device %016llx\n",
-			   args->v0.version, args->v0.device);
-	} else
-		return ret;
-
-	/* give priviledged clients register access */
-	if (args->v0.priv)
-		func = &nvkm_udevice_super;
-	else
-		func = &nvkm_udevice;
 
 	if (!(udev = kzalloc(sizeof(*udev), GFP_KERNEL)))
 		return -ENOMEM;
-	nvkm_object_ctor(func, oclass, &udev->object);
+	nvkm_object_ctor(&nvkm_udevice, oclass, &udev->object);
 	*pobject = &udev->object;
 
 	/* find the device that matches what the client requested */
-	if (args->v0.device != ~0)
-		udev->device = nvkm_device_find(args->v0.device);
-	else
-		udev->device = nvkm_device_find(client->device);
+	udev->device = nvkm_device_find(client->device);
 	if (!udev->device)
 		return -ENODEV;
 
Signature · 1 line
2.45.1
author
#50 lore raw

PATCH v2 24/37 drm/nouveau: always map device

In reply to Ben Skeggs

The next commit removes the nvif rd/wr methods from nvif_device, which were probably a bad idea, and mostly intended as a fallback if ioremap() failed (or wasn't available, as was the case in some tools I once used).

The nv04 KMS driver already mapped the device, because it's mostly been kept alive on life-support for many years and still directly bashes PRI a lot for modesetting.

Post-nv50, I tried pretty hard to keep PRI accesses out of the DRM code, but there's still a few random places where we do, and those were using the rd/wr paths prior to this commit.

This allocates and maps a new nvif_device (which will replace the usage of nouveau_drm.master.device later on), and replicates this pointer to all other possible users.

This will be cleaned up by the end of another patch series, after it's been made safe to do so.

---
 drivers/gpu/drm/nouveau/dispnv04/disp.c       |  5 -----
 drivers/gpu/drm/nouveau/include/nvif/device.h |  1 +
 drivers/gpu/drm/nouveau/nouveau_drm.c         | 16 ++++++++++++++++
 drivers/gpu/drm/nouveau/nouveau_drv.h         |  2 ++
 drivers/gpu/drm/nouveau/nvif/device.c         |  6 ++++++
 5 files changed, 25 insertions(+), 5 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/disp.c +0 -5
index 13705c5f1497..e8b27bb135e7 100644
@@ -189,7 +189,6 @@ static void
 nv04_display_destroy(struct drm_device *dev)
 {
 	struct nv04_display *disp = nv04_display(dev);
-	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_encoder *encoder;
 	struct nouveau_crtc *nv_crtc;
 
@@ -206,8 +205,6 @@ nv04_display_destroy(struct drm_device *dev)
 
 	nouveau_display(dev)->priv = NULL;
 	vfree(disp);
-
-	nvif_object_unmap(&drm->client.device.object);
 }
 
 int
@@ -229,8 +226,6 @@ nv04_display_create(struct drm_device *dev)
 
 	disp->drm = drm;
 
-	nvif_object_map(&drm->client.device.object, NULL, 0);
-
 	nouveau_display(dev)->priv = disp;
 	nouveau_display(dev)->dtor = nv04_display_destroy;
 	nouveau_display(dev)->init = nv04_display_init;
drivers/gpu/drm/nouveau/include/nvif/device.h +1 -0
index f7c1b3a43c84..fec76f4733a4 100644
@@ -20,6 +20,7 @@ struct nvif_device {
 
 int  nvif_device_ctor(struct nvif_client *, const char *name, struct nvif_device *);
 void nvif_device_dtor(struct nvif_device *);
+int  nvif_device_map(struct nvif_device *);
 u64  nvif_device_time(struct nvif_device *);
 
 /*XXX*/
drivers/gpu/drm/nouveau/nouveau_drm.c +16 -0
index 0beeff8552a2..936eb32fc8c4 100644
@@ -206,6 +206,7 @@ nouveau_cli_fini(struct nouveau_cli *cli)
 	nouveau_vmm_fini(&cli->svm);
 	nouveau_vmm_fini(&cli->vmm);
 	nvif_mmu_dtor(&cli->mmu);
+	cli->device.object.map.ptr = NULL;
 	nvif_device_dtor(&cli->device);
 	if (cli != &cli->drm->master) {
 		mutex_lock(&cli->drm->master.lock);
@@ -267,6 +268,8 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 		goto done;
 	}
 
+	cli->device.object.map.ptr = drm->device.object.map.ptr;
+
 	ret = nvif_mclass(&cli->device.object, mmus);
 	if (ret < 0) {
 		NV_PRINTK(err, cli, "No supported MMU class\n");
@@ -715,6 +718,7 @@ nouveau_drm_device_del(struct nouveau_drm *drm)
 	if (drm->dev)
 		drm_dev_put(drm->dev);
 
+	nvif_device_dtor(&drm->device);
 	nvif_client_dtor(&drm->master.base);
 	nvif_parent_dtor(&drm->parent);
 
@@ -742,6 +746,18 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
 	if (ret)
 		goto done;
 
+	ret = nvif_device_ctor(&drm->master.base, "drmDevice", &drm->device);
+	if (ret) {
+		NV_ERROR(drm, "Device allocation failed: %d\n", ret);
+		goto done;
+	}
+
+	ret = nvif_device_map(&drm->device);
+	if (ret) {
+		NV_ERROR(drm, "Failed to map PRI: %d\n", ret);
+		goto done;
+	}
+
 	drm->dev = drm_dev_alloc(drm_driver, parent);
 	if (IS_ERR(drm->dev)) {
 		ret = PTR_ERR(drm->dev);
drivers/gpu/drm/nouveau/nouveau_drv.h +2 -0
index e7d072a9a477..80ffe15ba76b 100644
@@ -203,6 +203,8 @@ u_memcpya(uint64_t user, unsigned int nmemb, unsigned int size)
 struct nouveau_drm {
 	struct nvkm_device *nvkm;
 	struct nvif_parent parent;
+	struct nvif_device device;
+
 	struct nouveau_cli master;
 	struct nouveau_cli client;
 	struct drm_device *dev;
drivers/gpu/drm/nouveau/nvif/device.c +6 -0
index b14bccb9a93f..24880931039f 100644
@@ -38,6 +38,12 @@ nvif_device_time(struct nvif_device *device)
 	return device->user.func->time(&device->user);
 }
 
+int
+nvif_device_map(struct nvif_device *device)
+{
+	return nvif_object_map(&device->object, NULL, 0);
+}
+
 void
 nvif_device_dtor(struct nvif_device *device)
 {
Signature · 1 line
2.45.1
author
#51 lore raw

PATCH v2 25/37 drm/nouveau/nvif: remove device rd/wr

In reply to Ben Skeggs

The device is always mapped now, so these are unneeded.

---
 .../drm/nouveau/include/nvkm/core/object.h    |  8 ---
 drivers/gpu/drm/nouveau/nvkm/core/ioctl.c     | 10 ----
 drivers/gpu/drm/nouveau/nvkm/core/object.c    | 32 -----------
 drivers/gpu/drm/nouveau/nvkm/core/oproxy.c    | 28 ----------
 .../gpu/drm/nouveau/nvkm/engine/device/user.c | 54 -------------------
 5 files changed, 132 deletions(-)
drivers/gpu/drm/nouveau/include/nvkm/core/object.h +0 -8
index d4f1c964ba31..c91abac44bd6 100644
@@ -33,11 +33,7 @@ struct nvkm_object_func {
 	int (*map)(struct nvkm_object *, void *argv, u32 argc,
 		   enum nvkm_object_map *, u64 *addr, u64 *size);
 	int (*unmap)(struct nvkm_object *);
-	int (*rd08)(struct nvkm_object *, u64 addr, u8 *data);
-	int (*rd16)(struct nvkm_object *, u64 addr, u16 *data);
 	int (*rd32)(struct nvkm_object *, u64 addr, u32 *data);
-	int (*wr08)(struct nvkm_object *, u64 addr, u8 data);
-	int (*wr16)(struct nvkm_object *, u64 addr, u16 data);
 	int (*wr32)(struct nvkm_object *, u64 addr, u32 data);
 	int (*bind)(struct nvkm_object *, struct nvkm_gpuobj *, int align,
 		    struct nvkm_gpuobj **);
@@ -61,11 +57,7 @@ int nvkm_object_ntfy(struct nvkm_object *, u32 mthd, struct nvkm_event **);
 int nvkm_object_map(struct nvkm_object *, void *argv, u32 argc,
 		    enum nvkm_object_map *, u64 *addr, u64 *size);
 int nvkm_object_unmap(struct nvkm_object *);
-int nvkm_object_rd08(struct nvkm_object *, u64 addr, u8  *data);
-int nvkm_object_rd16(struct nvkm_object *, u64 addr, u16 *data);
 int nvkm_object_rd32(struct nvkm_object *, u64 addr, u32 *data);
-int nvkm_object_wr08(struct nvkm_object *, u64 addr, u8   data);
-int nvkm_object_wr16(struct nvkm_object *, u64 addr, u16  data);
 int nvkm_object_wr32(struct nvkm_object *, u64 addr, u32  data);
 int nvkm_object_bind(struct nvkm_object *, struct nvkm_gpuobj *, int align,
 		     struct nvkm_gpuobj **);
drivers/gpu/drm/nouveau/nvkm/core/ioctl.c +0 -10
index 584fc43c0d75..95e9537e1d7c 100644
@@ -206,14 +206,6 @@ nvkm_ioctl_rd(struct nvkm_client *client,
 		nvif_ioctl(object, "rd vers %d size %d addr %016llx\n",
 			   args->v0.version, args->v0.size, args->v0.addr);
 		switch (args->v0.size) {
-		case 1:
-			ret = nvkm_object_rd08(object, args->v0.addr, &v.b08);
-			args->v0.data = v.b08;
-			break;
-		case 2:
-			ret = nvkm_object_rd16(object, args->v0.addr, &v.b16);
-			args->v0.data = v.b16;
-			break;
 		case 4:
 			ret = nvkm_object_rd32(object, args->v0.addr, &v.b32);
 			args->v0.data = v.b32;
@@ -246,8 +238,6 @@ nvkm_ioctl_wr(struct nvkm_client *client,
 		return ret;
 
 	switch (args->v0.size) {
-	case 1: return nvkm_object_wr08(object, args->v0.addr, args->v0.data);
-	case 2: return nvkm_object_wr16(object, args->v0.addr, args->v0.data);
 	case 4: return nvkm_object_wr32(object, args->v0.addr, args->v0.data);
 	default:
 		break;
drivers/gpu/drm/nouveau/nvkm/core/object.c +0 -32
index 580b8c7f25af..913c3bae51f7 100644
@@ -132,22 +132,6 @@ nvkm_object_unmap(struct nvkm_object *object)
 	return -ENODEV;
 }
 
-int
-nvkm_object_rd08(struct nvkm_object *object, u64 addr, u8 *data)
-{
-	if (likely(object->func->rd08))
-		return object->func->rd08(object, addr, data);
-	return -ENODEV;
-}
-
-int
-nvkm_object_rd16(struct nvkm_object *object, u64 addr, u16 *data)
-{
-	if (likely(object->func->rd16))
-		return object->func->rd16(object, addr, data);
-	return -ENODEV;
-}
-
 int
 nvkm_object_rd32(struct nvkm_object *object, u64 addr, u32 *data)
 {
@@ -156,22 +140,6 @@ nvkm_object_rd32(struct nvkm_object *object, u64 addr, u32 *data)
 	return -ENODEV;
 }
 
-int
-nvkm_object_wr08(struct nvkm_object *object, u64 addr, u8 data)
-{
-	if (likely(object->func->wr08))
-		return object->func->wr08(object, addr, data);
-	return -ENODEV;
-}
-
-int
-nvkm_object_wr16(struct nvkm_object *object, u64 addr, u16 data)
-{
-	if (likely(object->func->wr16))
-		return object->func->wr16(object, addr, data);
-	return -ENODEV;
-}
-
 int
 nvkm_object_wr32(struct nvkm_object *object, u64 addr, u32 data)
 {
drivers/gpu/drm/nouveau/nvkm/core/oproxy.c +0 -28
index 3385528da650..afc10ec256a7 100644
@@ -55,36 +55,12 @@ nvkm_oproxy_unmap(struct nvkm_object *object)
 	return nvkm_object_unmap(oproxy->object);
 }
 
-static int
-nvkm_oproxy_rd08(struct nvkm_object *object, u64 addr, u8 *data)
-{
-	return nvkm_object_rd08(nvkm_oproxy(object)->object, addr, data);
-}
-
-static int
-nvkm_oproxy_rd16(struct nvkm_object *object, u64 addr, u16 *data)
-{
-	return nvkm_object_rd16(nvkm_oproxy(object)->object, addr, data);
-}
-
 static int
 nvkm_oproxy_rd32(struct nvkm_object *object, u64 addr, u32 *data)
 {
 	return nvkm_object_rd32(nvkm_oproxy(object)->object, addr, data);
 }
 
-static int
-nvkm_oproxy_wr08(struct nvkm_object *object, u64 addr, u8 data)
-{
-	return nvkm_object_wr08(nvkm_oproxy(object)->object, addr, data);
-}
-
-static int
-nvkm_oproxy_wr16(struct nvkm_object *object, u64 addr, u16 data)
-{
-	return nvkm_object_wr16(nvkm_oproxy(object)->object, addr, data);
-}
-
 static int
 nvkm_oproxy_wr32(struct nvkm_object *object, u64 addr, u32 data)
 {
@@ -197,11 +173,7 @@ nvkm_oproxy_func = {
 	.ntfy = nvkm_oproxy_ntfy,
 	.map = nvkm_oproxy_map,
 	.unmap = nvkm_oproxy_unmap,
-	.rd08 = nvkm_oproxy_rd08,
-	.rd16 = nvkm_oproxy_rd16,
 	.rd32 = nvkm_oproxy_rd32,
-	.wr08 = nvkm_oproxy_wr08,
-	.wr16 = nvkm_oproxy_wr16,
 	.wr32 = nvkm_oproxy_wr32,
 	.bind = nvkm_oproxy_bind,
 	.sclass = nvkm_oproxy_sclass,
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c +0 -54

66 lines not on this page · raw message

Signature · 1 line
2.45.1
#52 lore raw

Re: [PATCH v2 25/37] drm/nouveau/nvif: remove device rd/wr

Quoted 1 line · Ben Skeggs

The device is always mapped now, so these are unneeded.

Instead of saying "now", please mention the change that makes this possible.

Quoted 244 lines
---
 .../drm/nouveau/include/nvkm/core/object.h    |  8 ---
 drivers/gpu/drm/nouveau/nvkm/core/ioctl.c     | 10 ----
 drivers/gpu/drm/nouveau/nvkm/core/object.c    | 32 -----------
 drivers/gpu/drm/nouveau/nvkm/core/oproxy.c    | 28 ----------
 .../gpu/drm/nouveau/nvkm/engine/device/user.c | 54 -------------------
 5 files changed, 132 deletions(-)
drivers/gpu/drm/nouveau/include/nvkm/core/object.h +0 -8
index d4f1c964ba31..c91abac44bd6 100644
@@ -33,11 +33,7 @@ struct nvkm_object_func {
 	int (*map)(struct nvkm_object *, void *argv, u32 argc,
 		   enum nvkm_object_map *, u64 *addr, u64 *size);
 	int (*unmap)(struct nvkm_object *);
-	int (*rd08)(struct nvkm_object *, u64 addr, u8 *data);
-	int (*rd16)(struct nvkm_object *, u64 addr, u16 *data);
 	int (*rd32)(struct nvkm_object *, u64 addr, u32 *data);
-	int (*wr08)(struct nvkm_object *, u64 addr, u8 data);
-	int (*wr16)(struct nvkm_object *, u64 addr, u16 data);
 	int (*wr32)(struct nvkm_object *, u64 addr, u32 data);
 	int (*bind)(struct nvkm_object *, struct nvkm_gpuobj *, int align,
 		    struct nvkm_gpuobj **);
@@ -61,11 +57,7 @@ int nvkm_object_ntfy(struct nvkm_object *, u32 mthd, struct nvkm_event **);
 int nvkm_object_map(struct nvkm_object *, void *argv, u32 argc,
 		    enum nvkm_object_map *, u64 *addr, u64 *size);
 int nvkm_object_unmap(struct nvkm_object *);
-int nvkm_object_rd08(struct nvkm_object *, u64 addr, u8  *data);
-int nvkm_object_rd16(struct nvkm_object *, u64 addr, u16 *data);
 int nvkm_object_rd32(struct nvkm_object *, u64 addr, u32 *data);
-int nvkm_object_wr08(struct nvkm_object *, u64 addr, u8   data);
-int nvkm_object_wr16(struct nvkm_object *, u64 addr, u16  data);
 int nvkm_object_wr32(struct nvkm_object *, u64 addr, u32  data);
 int nvkm_object_bind(struct nvkm_object *, struct nvkm_gpuobj *, int align,
 		     struct nvkm_gpuobj **);
drivers/gpu/drm/nouveau/nvkm/core/ioctl.c +0 -10
index 584fc43c0d75..95e9537e1d7c 100644
@@ -206,14 +206,6 @@ nvkm_ioctl_rd(struct nvkm_client *client,
 		nvif_ioctl(object, "rd vers %d size %d addr %016llx\n",
 			   args->v0.version, args->v0.size, args->v0.addr);
 		switch (args->v0.size) {
-		case 1:
-			ret = nvkm_object_rd08(object, args->v0.addr, &v.b08);
-			args->v0.data = v.b08;
-			break;
-		case 2:
-			ret = nvkm_object_rd16(object, args->v0.addr, &v.b16);
-			args->v0.data = v.b16;
-			break;
 		case 4:
 			ret = nvkm_object_rd32(object, args->v0.addr, &v.b32);
 			args->v0.data = v.b32;
@@ -246,8 +238,6 @@ nvkm_ioctl_wr(struct nvkm_client *client,
 		return ret;
 
 	switch (args->v0.size) {
-	case 1: return nvkm_object_wr08(object, args->v0.addr, args->v0.data);
-	case 2: return nvkm_object_wr16(object, args->v0.addr, args->v0.data);
 	case 4: return nvkm_object_wr32(object, args->v0.addr, args->v0.data);
 	default:
 		break;
drivers/gpu/drm/nouveau/nvkm/core/object.c +0 -32
index 580b8c7f25af..913c3bae51f7 100644
@@ -132,22 +132,6 @@ nvkm_object_unmap(struct nvkm_object *object)
 	return -ENODEV;
 }
 
-int
-nvkm_object_rd08(struct nvkm_object *object, u64 addr, u8 *data)
-{
-	if (likely(object->func->rd08))
-		return object->func->rd08(object, addr, data);
-	return -ENODEV;
-}
-
-int
-nvkm_object_rd16(struct nvkm_object *object, u64 addr, u16 *data)
-{
-	if (likely(object->func->rd16))
-		return object->func->rd16(object, addr, data);
-	return -ENODEV;
-}
-
 int
 nvkm_object_rd32(struct nvkm_object *object, u64 addr, u32 *data)
 {
@@ -156,22 +140,6 @@ nvkm_object_rd32(struct nvkm_object *object, u64 addr, u32 *data)
 	return -ENODEV;
 }
 
-int
-nvkm_object_wr08(struct nvkm_object *object, u64 addr, u8 data)
-{
-	if (likely(object->func->wr08))
-		return object->func->wr08(object, addr, data);
-	return -ENODEV;
-}
-
-int
-nvkm_object_wr16(struct nvkm_object *object, u64 addr, u16 data)
-{
-	if (likely(object->func->wr16))
-		return object->func->wr16(object, addr, data);
-	return -ENODEV;
-}
-
 int
 nvkm_object_wr32(struct nvkm_object *object, u64 addr, u32 data)
 {
drivers/gpu/drm/nouveau/nvkm/core/oproxy.c +0 -28
index 3385528da650..afc10ec256a7 100644
@@ -55,36 +55,12 @@ nvkm_oproxy_unmap(struct nvkm_object *object)
 	return nvkm_object_unmap(oproxy->object);
 }
 
-static int
-nvkm_oproxy_rd08(struct nvkm_object *object, u64 addr, u8 *data)
-{
-	return nvkm_object_rd08(nvkm_oproxy(object)->object, addr, data);
-}
-
-static int
-nvkm_oproxy_rd16(struct nvkm_object *object, u64 addr, u16 *data)
-{
-	return nvkm_object_rd16(nvkm_oproxy(object)->object, addr, data);
-}
-
 static int
 nvkm_oproxy_rd32(struct nvkm_object *object, u64 addr, u32 *data)
 {
 	return nvkm_object_rd32(nvkm_oproxy(object)->object, addr, data);
 }
 
-static int
-nvkm_oproxy_wr08(struct nvkm_object *object, u64 addr, u8 data)
-{
-	return nvkm_object_wr08(nvkm_oproxy(object)->object, addr, data);
-}
-
-static int
-nvkm_oproxy_wr16(struct nvkm_object *object, u64 addr, u16 data)
-{
-	return nvkm_object_wr16(nvkm_oproxy(object)->object, addr, data);
-}
-
 static int
 nvkm_oproxy_wr32(struct nvkm_object *object, u64 addr, u32 data)
 {
@@ -197,11 +173,7 @@ nvkm_oproxy_func = {
 	.ntfy = nvkm_oproxy_ntfy,
 	.map = nvkm_oproxy_map,
 	.unmap = nvkm_oproxy_unmap,
-	.rd08 = nvkm_oproxy_rd08,
-	.rd16 = nvkm_oproxy_rd16,
 	.rd32 = nvkm_oproxy_rd32,
-	.wr08 = nvkm_oproxy_wr08,
-	.wr16 = nvkm_oproxy_wr16,
 	.wr32 = nvkm_oproxy_wr32,
 	.bind = nvkm_oproxy_bind,
 	.sclass = nvkm_oproxy_sclass,
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c +0 -54
index 65bd6712bce2..d7f75b3a43c8 100644
@@ -202,54 +202,6 @@ nvkm_udevice_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
 	return -EINVAL;
 }
 
-static int
-nvkm_udevice_rd08(struct nvkm_object *object, u64 addr, u8 *data)
-{
-	struct nvkm_udevice *udev = nvkm_udevice(object);
-	*data = nvkm_rd08(udev->device, addr);
-	return 0;
-}
-
-static int
-nvkm_udevice_rd16(struct nvkm_object *object, u64 addr, u16 *data)
-{
-	struct nvkm_udevice *udev = nvkm_udevice(object);
-	*data = nvkm_rd16(udev->device, addr);
-	return 0;
-}
-
-static int
-nvkm_udevice_rd32(struct nvkm_object *object, u64 addr, u32 *data)
-{
-	struct nvkm_udevice *udev = nvkm_udevice(object);
-	*data = nvkm_rd32(udev->device, addr);
-	return 0;
-}
-
-static int
-nvkm_udevice_wr08(struct nvkm_object *object, u64 addr, u8 data)
-{
-	struct nvkm_udevice *udev = nvkm_udevice(object);
-	nvkm_wr08(udev->device, addr, data);
-	return 0;
-}
-
-static int
-nvkm_udevice_wr16(struct nvkm_object *object, u64 addr, u16 data)
-{
-	struct nvkm_udevice *udev = nvkm_udevice(object);
-	nvkm_wr16(udev->device, addr, data);
-	return 0;
-}
-
-static int
-nvkm_udevice_wr32(struct nvkm_object *object, u64 addr, u32 data)
-{
-	struct nvkm_udevice *udev = nvkm_udevice(object);
-	nvkm_wr32(udev->device, addr, data);
-	return 0;
-}
-
 static int
 nvkm_udevice_map(struct nvkm_object *object, void *argv, u32 argc,
 		 enum nvkm_object_map *type, u64 *addr, u64 *size)
@@ -362,12 +314,6 @@ nvkm_udevice = {
 	.fini = nvkm_udevice_fini,
 	.mthd = nvkm_udevice_mthd,
 	.map = nvkm_udevice_map,
-	.rd08 = nvkm_udevice_rd08,
-	.rd16 = nvkm_udevice_rd16,
-	.rd32 = nvkm_udevice_rd32,
-	.wr08 = nvkm_udevice_wr08,
-	.wr16 = nvkm_udevice_wr16,
-	.wr32 = nvkm_udevice_wr32,
 	.sclass = nvkm_udevice_child_get,
 };
 
Signature · 1 line
2.45.1
author
#53 lore raw

PATCH v2 26/37 drm/nouveau/nvif: remove disp chan rd/wr

In reply to Ben Skeggs

There's no good reason the ioremap() that results from nvif_object_map() should fail, so add a check that the map succeeded, and remove the rd/wr methods from display channel objects.

As this was the last user of rd/wr methods, the nvif plumbing is removed at the same time.

---
 drivers/gpu/drm/nouveau/dispnv50/disp.c       |  7 ++-
 drivers/gpu/drm/nouveau/include/nvif/ioctl.h  | 20 --------
 drivers/gpu/drm/nouveau/include/nvif/object.h | 17 ++-----
 .../drm/nouveau/include/nvkm/core/object.h    |  4 --
 drivers/gpu/drm/nouveau/nvif/object.c         | 37 --------------
 drivers/gpu/drm/nouveau/nvkm/core/ioctl.c     | 49 +------------------
 drivers/gpu/drm/nouveau/nvkm/core/object.c    | 16 ------
 drivers/gpu/drm/nouveau/nvkm/core/oproxy.c    | 14 ------
 .../gpu/drm/nouveau/nvkm/engine/disp/chan.c   | 24 ---------
 9 files changed, 10 insertions(+), 178 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/disp.c +5 -2
index 6750f66bb1ff..42375f757d7c 100644
@@ -93,8 +93,11 @@ nv50_chan_create(struct nvif_device *device, struct nvif_object *disp,
 				ret = nvif_object_ctor(disp, "kmsChan", 0,
 						       oclass[0], data, size,
 						       &chan->user);
-				if (ret == 0)
-					nvif_object_map(&chan->user, NULL, 0);
+				if (ret == 0) {
+					ret = nvif_object_map(&chan->user, NULL, 0);
+					if (ret)
+						nvif_object_dtor(&chan->user);
+				}
 				nvif_object_sclass_put(&sclass);
 				return ret;
 			}
drivers/gpu/drm/nouveau/include/nvif/ioctl.h +0 -20
index 1e74245621e0..e825c8a1d9ca 100644
@@ -8,8 +8,6 @@ struct nvif_ioctl_v0 {
 #define NVIF_IOCTL_V0_NEW                                                  0x02
 #define NVIF_IOCTL_V0_DEL                                                  0x03
 #define NVIF_IOCTL_V0_MTHD                                                 0x04
-#define NVIF_IOCTL_V0_RD                                                   0x05
-#define NVIF_IOCTL_V0_WR                                                   0x06
 #define NVIF_IOCTL_V0_MAP                                                  0x07
 #define NVIF_IOCTL_V0_UNMAP                                                0x08
 	__u8  type;
@@ -60,24 +58,6 @@ struct nvif_ioctl_mthd_v0 {
 	__u8  data[];		/* method data (class.h) */
 };
 
-struct nvif_ioctl_rd_v0 {
-	/* nvif_ioctl ... */
-	__u8  version;
-	__u8  size;
-	__u8  pad02[2];
-	__u32 data;
-	__u64 addr;
-};
-
-struct nvif_ioctl_wr_v0 {
-	/* nvif_ioctl ... */
-	__u8  version;
-	__u8  size;
-	__u8  pad02[2];
-	__u32 data;
-	__u64 addr;
-};
-
 struct nvif_ioctl_map_v0 {
 	/* nvif_ioctl ... */
 	__u8  version;
drivers/gpu/drm/nouveau/include/nvif/object.h +3 -14
index 478cbb8f2dfe..8d205b6af46a 100644
@@ -34,8 +34,6 @@ void nvif_object_dtor(struct nvif_object *);
 int  nvif_object_ioctl(struct nvif_object *, void *, u32, void **);
 int  nvif_object_sclass_get(struct nvif_object *, struct nvif_sclass **);
 void nvif_object_sclass_put(struct nvif_sclass **);
-u32  nvif_object_rd(struct nvif_object *, int, u64);
-void nvif_object_wr(struct nvif_object *, int, u64, u32);
 int  nvif_object_mthd(struct nvif_object *, u32, void *, u32);
 int  nvif_object_map_handle(struct nvif_object *, void *, u32,
 			    u64 *handle, u64 *length);
@@ -47,20 +45,11 @@ void nvif_object_unmap(struct nvif_object *);
 #define nvif_object(a) (a)->object
 
 #define nvif_rd(a,f,b,c) ({                                                    \
-	struct nvif_object *_object = (a);                                     \
-	u32 _data;                                                             \
-	if (likely(_object->map.ptr))                                          \
-		_data = f((u8 __iomem *)_object->map.ptr + (c));               \
-	else                                                                   \
-		_data = nvif_object_rd(_object, (b), (c));                     \
+	u32 _data = f((u8 __iomem *)(a)->map.ptr + (c));                       \
 	_data;                                                                 \
 })
 #define nvif_wr(a,f,b,c,d) ({                                                  \
-	struct nvif_object *_object = (a);                                     \
-	if (likely(_object->map.ptr))                                          \
-		f((d), (u8 __iomem *)_object->map.ptr + (c));                  \
-	else                                                                   \
-		nvif_object_wr(_object, (b), (c), (d));                        \
+	f((d), (u8 __iomem *)(a)->map.ptr + (c));                              \
 })
 #define nvif_rd08(a,b) ({ ((u8)nvif_rd((a), ioread8, 1, (b))); })
 #define nvif_rd16(a,b) ({ ((u16)nvif_rd((a), ioread16_native, 2, (b))); })
@@ -69,7 +58,7 @@ void nvif_object_unmap(struct nvif_object *);
 #define nvif_wr16(a,b,c) nvif_wr((a), iowrite16_native, 2, (b), (u16)(c))
 #define nvif_wr32(a,b,c) nvif_wr((a), iowrite32_native, 4, (b), (u32)(c))
 #define nvif_mask(a,b,c,d) ({                                                  \
-	struct nvif_object *__object = (a);                                    \
+	typeof(a) __object = (a);                                              \
 	u32 _addr = (b), _data = nvif_rd32(__object, _addr);                   \
 	nvif_wr32(__object, _addr, (_data & ~(c)) | (d));                      \
 	_data;                                                                 \
drivers/gpu/drm/nouveau/include/nvkm/core/object.h +0 -4
index c91abac44bd6..10107ef3ca49 100644
@@ -33,8 +33,6 @@ struct nvkm_object_func {
 	int (*map)(struct nvkm_object *, void *argv, u32 argc,
 		   enum nvkm_object_map *, u64 *addr, u64 *size);
 	int (*unmap)(struct nvkm_object *);
-	int (*rd32)(struct nvkm_object *, u64 addr, u32 *data);
-	int (*wr32)(struct nvkm_object *, u64 addr, u32 data);
 	int (*bind)(struct nvkm_object *, struct nvkm_gpuobj *, int align,
 		    struct nvkm_gpuobj **);
 	int (*sclass)(struct nvkm_object *, int index, struct nvkm_oclass *);
@@ -57,8 +55,6 @@ int nvkm_object_ntfy(struct nvkm_object *, u32 mthd, struct nvkm_event **);
 int nvkm_object_map(struct nvkm_object *, void *argv, u32 argc,
 		    enum nvkm_object_map *, u64 *addr, u64 *size);
 int nvkm_object_unmap(struct nvkm_object *);
-int nvkm_object_rd32(struct nvkm_object *, u64 addr, u32 *data);
-int nvkm_object_wr32(struct nvkm_object *, u64 addr, u32  data);
 int nvkm_object_bind(struct nvkm_object *, struct nvkm_gpuobj *, int align,
 		     struct nvkm_gpuobj **);
 
drivers/gpu/drm/nouveau/nvif/object.c +0 -37
index 2b3e05197846..8a2a7bfec2f8 100644
@@ -97,43 +97,6 @@ nvif_object_sclass_get(struct nvif_object *object, struct nvif_sclass **psclass)
 	return ret;
 }
 
-u32
-nvif_object_rd(struct nvif_object *object, int size, u64 addr)
-{
-	struct {
-		struct nvif_ioctl_v0 ioctl;
-		struct nvif_ioctl_rd_v0 rd;
-	} args = {
-		.ioctl.type = NVIF_IOCTL_V0_RD,
-		.rd.size = size,
-		.rd.addr = addr,
-	};
-	int ret = nvif_object_ioctl(object, &args, sizeof(args), NULL);
-	if (ret) {
-		/*XXX: warn? */
-		return 0;
-	}
-	return args.rd.data;
-}
-
-void
-nvif_object_wr(struct nvif_object *object, int size, u64 addr, u32 data)
-{
-	struct {
-		struct nvif_ioctl_v0 ioctl;
-		struct nvif_ioctl_wr_v0 wr;
-	} args = {
-		.ioctl.type = NVIF_IOCTL_V0_WR,
-		.wr.size = size,
-		.wr.addr = addr,
-		.wr.data = data,
-	};
-	int ret = nvif_object_ioctl(object, &args, sizeof(args), NULL);
-	if (ret) {
-		/*XXX: warn? */
-	}
-}
-
 int
 nvif_object_mthd(struct nvif_object *object, u32 mthd, void *data, u32 size)
 {
drivers/gpu/drm/nouveau/nvkm/core/ioctl.c +2 -47

61 lines not on this page · raw message

drivers/gpu/drm/nouveau/nvkm/core/object.c +0 -16
index 913c3bae51f7..390c265cf8af 100644
@@ -132,22 +132,6 @@ nvkm_object_unmap(struct nvkm_object *object)
 	return -ENODEV;
 }
 
-int
-nvkm_object_rd32(struct nvkm_object *object, u64 addr, u32 *data)
-{
-	if (likely(object->func->rd32))
-		return object->func->rd32(object, addr, data);
-	return -ENODEV;
-}
-
-int
-nvkm_object_wr32(struct nvkm_object *object, u64 addr, u32 data)
-{
-	if (likely(object->func->wr32))
-		return object->func->wr32(object, addr, data);
-	return -ENODEV;
-}
-
 int
 nvkm_object_bind(struct nvkm_object *object, struct nvkm_gpuobj *gpuobj,
 		 int align, struct nvkm_gpuobj **pgpuobj)
drivers/gpu/drm/nouveau/nvkm/core/oproxy.c +0 -14
index afc10ec256a7..5db80d1780f0 100644
@@ -55,18 +55,6 @@ nvkm_oproxy_unmap(struct nvkm_object *object)
 	return nvkm_object_unmap(oproxy->object);
 }
 
-static int
-nvkm_oproxy_rd32(struct nvkm_object *object, u64 addr, u32 *data)
-{
-	return nvkm_object_rd32(nvkm_oproxy(object)->object, addr, data);
-}
-
-static int
-nvkm_oproxy_wr32(struct nvkm_object *object, u64 addr, u32 data)
-{
-	return nvkm_object_wr32(nvkm_oproxy(object)->object, addr, data);
-}
-
 static int
 nvkm_oproxy_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
 		 int align, struct nvkm_gpuobj **pgpuobj)
@@ -173,8 +161,6 @@ nvkm_oproxy_func = {
 	.ntfy = nvkm_oproxy_ntfy,
 	.map = nvkm_oproxy_map,
 	.unmap = nvkm_oproxy_unmap,
-	.rd32 = nvkm_oproxy_rd32,
-	.wr32 = nvkm_oproxy_wr32,
 	.bind = nvkm_oproxy_bind,
 	.sclass = nvkm_oproxy_sclass,
 	.uevent = nvkm_oproxy_uevent,
drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.c +0 -24
index d5e18daed79f..4e43ee383c34 100644
@@ -26,28 +26,6 @@
 
 #include <nvif/if0014.h>
 
-static int
-nvkm_disp_chan_rd32(struct nvkm_object *object, u64 addr, u32 *data)
-{
-	struct nvkm_disp_chan *chan = nvkm_disp_chan(object);
-	struct nvkm_device *device = chan->disp->engine.subdev.device;
-	u64 size, base = chan->func->user(chan, &size);
-
-	*data = nvkm_rd32(device, base + addr);
-	return 0;
-}
-
-static int
-nvkm_disp_chan_wr32(struct nvkm_object *object, u64 addr, u32 data)
-{
-	struct nvkm_disp_chan *chan = nvkm_disp_chan(object);
-	struct nvkm_device *device = chan->disp->engine.subdev.device;
-	u64 size, base = chan->func->user(chan, &size);
-
-	nvkm_wr32(device, base + addr, data);
-	return 0;
-}
-
 static int
 nvkm_disp_chan_ntfy(struct nvkm_object *object, u32 type, struct nvkm_event **pevent)
 {
@@ -188,8 +166,6 @@ nvkm_disp_chan = {
 	.dtor = nvkm_disp_chan_dtor,
 	.init = nvkm_disp_chan_init,
 	.fini = nvkm_disp_chan_fini,
-	.rd32 = nvkm_disp_chan_rd32,
-	.wr32 = nvkm_disp_chan_wr32,
 	.ntfy = nvkm_disp_chan_ntfy,
 	.map = nvkm_disp_chan_map,
 	.sclass = nvkm_disp_chan_child_get,
Signature · 1 line
2.45.1
author
#54 lore raw

PATCH v2 27/37 drm/nouveau: move nvxx_* definitions to nouveau_drv.h

In reply to Ben Skeggs

These are some dodgy "convenience" macros for the DRM driver to peek into NVKM state. They're still used in a few places, but don't belong in nvif/device.h in any case.

Move them to nouveau_drv.h, and modify callers to pass a nouveau_drm instead of an nvif_device.

v2:
- use drm->nvkm pointer for nvxx_*() macros, removing some void*

---
 drivers/gpu/drm/nouveau/dispnv04/crtc.c       |  4 +-
 drivers/gpu/drm/nouveau/dispnv04/dac.c        |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/dfp.c        |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/disp.c       |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/disp.h       |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/hw.c         |  9 ++--
 drivers/gpu/drm/nouveau/dispnv04/tvnv04.c     |  4 +-
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c     |  6 +--
 drivers/gpu/drm/nouveau/dispnv50/disp.c       |  6 +--
 drivers/gpu/drm/nouveau/include/nvif/device.h | 33 -------------
 drivers/gpu/drm/nouveau/include/nvif/object.h |  2 +-
 drivers/gpu/drm/nouveau/nouveau_abi16.c       |  4 +-
 drivers/gpu/drm/nouveau/nouveau_bios.c        |  4 +-
 drivers/gpu/drm/nouveau/nouveau_bios.h        |  1 +
 drivers/gpu/drm/nouveau/nouveau_bo.c          |  8 ++--
 drivers/gpu/drm/nouveau/nouveau_chan.c        |  3 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c         |  3 +-
 drivers/gpu/drm/nouveau/nouveau_drv.h         | 27 +++++++++++
 drivers/gpu/drm/nouveau/nouveau_hwmon.c       | 46 +++++++++----------
 drivers/gpu/drm/nouveau/nouveau_led.c         |  2 +-
 drivers/gpu/drm/nouveau/nouveau_ttm.c         |  4 +-
 21 files changed, 83 insertions(+), 91 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/crtc.c +2 -2
index 4310ad71870b..e5067d5a4801 100644
@@ -118,8 +118,8 @@ static void nv_crtc_calc_state_ext(struct drm_crtc *crtc, struct drm_display_mod
 {
 	struct drm_device *dev = crtc->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
-	struct nvkm_clk *clk = nvxx_clk(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
+	struct nvkm_clk *clk = nvxx_clk(drm);
 	struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
 	struct nv04_mode_state *state = &nv04_display(dev)->mode_reg;
 	struct nv04_crtc_reg *regp = &state->crtc_reg[nv_crtc->index];
drivers/gpu/drm/nouveau/dispnv04/dac.c +1 -1
index d6b8e0cce2ac..2e12bf136607 100644
@@ -237,7 +237,7 @@ uint32_t nv17_dac_sample_load(struct drm_encoder *encoder)
 	struct drm_device *dev = encoder->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nvif_object *device = &nouveau_drm(dev)->client.device.object;
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
 	struct dcb_output *dcb = nouveau_encoder(encoder)->dcb;
 	uint32_t sample, testval, regoffset = nv04_dac_output_offset(encoder);
 	uint32_t saved_powerctrl_2 = 0, saved_powerctrl_4 = 0, saved_routput,
drivers/gpu/drm/nouveau/dispnv04/dfp.c +1 -1
index d5b129dc623b..504c421aa176 100644
@@ -626,7 +626,7 @@ static void nv04_tmds_slave_init(struct drm_encoder *encoder)
 	struct drm_device *dev = encoder->dev;
 	struct dcb_output *dcb = nouveau_encoder(encoder)->dcb;
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_PRI);
 	struct nvkm_i2c_bus_probe info[] = {
 		{
drivers/gpu/drm/nouveau/dispnv04/disp.c +1 -1
index e8b27bb135e7..e563a160571a 100644
@@ -211,7 +211,7 @@ int
 nv04_display_create(struct drm_device *dev)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct dcb_table *dcb = &drm->vbios.dcb;
 	struct drm_connector *connector, *ct;
 	struct drm_encoder *encoder;
drivers/gpu/drm/nouveau/dispnv04/disp.h +1 -1
index 11a6663758ec..85ec0f534392 100644
@@ -176,7 +176,7 @@ static inline void
 nouveau_bios_run_init_table(struct drm_device *dev, u16 table,
 			    struct dcb_output *outp, int crtc)
 {
-	nvbios_init(&nvxx_bios(&nouveau_drm(dev)->client.device)->subdev, table,
+	nvbios_init(&nvxx_bios(nouveau_drm(dev))->subdev, table,
 		init.outp = outp;
 		init.head = crtc;
 	);
drivers/gpu/drm/nouveau/dispnv04/hw.c +4 -5
index f7d35657aa64..8b376f9c8746 100644
@@ -166,7 +166,7 @@ nouveau_hw_get_pllvals(struct drm_device *dev, enum nvbios_pll_type plltype,
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nvif_object *device = &drm->client.device.object;
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
 	uint32_t reg1, pll1, pll2 = 0;
 	struct nvbios_pll pll_lim;
 	int ret;
@@ -258,9 +258,8 @@ nouveau_hw_fix_bad_vpll(struct drm_device *dev, int head)
 	 */
 
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvif_device *device = &drm->client.device;
-	struct nvkm_clk *clk = nvxx_clk(device);
-	struct nvkm_bios *bios = nvxx_bios(device);
+	struct nvkm_clk *clk = nvxx_clk(drm);
+	struct nvkm_bios *bios = nvxx_bios(drm);
 	struct nvbios_pll pll_lim;
 	struct nvkm_pll_vals pv;
 	enum nvbios_pll_type pll = head ? PLL_VPLL1 : PLL_VPLL0;
@@ -470,7 +469,7 @@ nv_load_state_ramdac(struct drm_device *dev, int head,
 		     struct nv04_mode_state *state)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_clk *clk = nvxx_clk(&drm->client.device);
+	struct nvkm_clk *clk = nvxx_clk(drm);
 	struct nv04_crtc_reg *regp = &state->crtc_reg[head];
 	uint32_t pllreg = head ? NV_RAMDAC_VPLL2 : NV_PRAMDAC_VPLL_COEFF;
 	int i;
drivers/gpu/drm/nouveau/dispnv04/tvnv04.c +2 -2
index de3ea731d6e6..d3014027a812 100644
@@ -53,7 +53,7 @@ static struct nvkm_i2c_bus_probe nv04_tv_encoder_info[] = {
 int nv04_tv_identify(struct drm_device *dev, int i2c_index)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, i2c_index);
 	if (bus) {
 		return nvkm_i2c_bus_probe(bus, "TV encoder",
@@ -205,7 +205,7 @@ nv04_tv_create(struct drm_connector *connector, struct dcb_output *entry)
 	struct drm_encoder *encoder;
 	struct drm_device *dev = connector->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, entry->i2c_index);
 	int type, ret;
 
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +3 -3
index 670c9739e5e1..c11f58033018 100644
@@ -47,7 +47,7 @@ static uint32_t nv42_tv_sample_load(struct drm_encoder *encoder)
 {
 	struct drm_device *dev = encoder->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
 	uint32_t testval, regoffset = nv04_dac_output_offset(encoder);
 	uint32_t gpio0, gpio1, fp_htotal, fp_hsync_start, fp_hsync_end,
 		fp_control, test_ctrl, dacclk, ctv_14, ctv_1c, ctv_6c;
@@ -131,7 +131,7 @@ static bool
 get_tv_detect_quirks(struct drm_device *dev, uint32_t *pin_mask)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 
 	if (device->quirk && device->quirk->tv_pin_mask) {
 		*pin_mask = device->quirk->tv_pin_mask;
@@ -363,7 +363,7 @@ static void  nv17_tv_dpms(struct drm_encoder *encoder, int mode)
 {
 	struct drm_device *dev = encoder->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
 	struct nv17_tv_state *regs = &to_tv_enc(encoder)->state;
 	struct nv17_tv_norm_params *tv_norm = get_tv_norm(encoder);
 
drivers/gpu/drm/nouveau/dispnv50/disp.c +3 -3
index 42375f757d7c..80803346b620 100644
@@ -561,7 +561,7 @@ nv50_dac_create(struct nouveau_encoder *nv_encoder)
 {
 	struct drm_connector *connector = &nv_encoder->conn->base;
 	struct nouveau_drm *drm = nouveau_drm(connector->dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct nvkm_i2c_bus *bus;
 	struct drm_encoder *encoder;
 	struct dcb_output *dcbe = nv_encoder->dcb;
@@ -1884,7 +1884,7 @@ nv50_sor_create(struct nouveau_encoder *nv_encoder)
 	struct drm_connector *connector = &nv_encoder->conn->base;
 	struct nouveau_connector *nv_connector = nouveau_connector(connector);
 	struct nouveau_drm *drm = nouveau_drm(connector->dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct drm_encoder *encoder;
 	struct dcb_output *dcbe = nv_encoder->dcb;
 	struct nv50_disp *disp = nv50_disp(connector->dev);
@@ -2051,7 +2051,7 @@ nv50_pior_create(struct nouveau_encoder *nv_encoder)
 	struct drm_device *dev = connector->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nv50_disp *disp = nv50_disp(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct nvkm_i2c_bus *bus = NULL;
 	struct nvkm_i2c_aux *aux = NULL;
 	struct i2c_adapter *ddc;
drivers/gpu/drm/nouveau/include/nvif/device.h +0 -33
index fec76f4733a4..7877a2a79da9 100644
@@ -22,37 +22,4 @@ int  nvif_device_ctor(struct nvif_client *, const char *name, struct nvif_device
 void nvif_device_dtor(struct nvif_device *);
 int  nvif_device_map(struct nvif_device *);
 u64  nvif_device_time(struct nvif_device *);
-
-/*XXX*/
-#include <subdev/bios.h>
-#include <subdev/fb.h>
-#include <subdev/bar.h>
-#include <subdev/gpio.h>
-#include <subdev/clk.h>
-#include <subdev/i2c.h>
-#include <subdev/timer.h>
-#include <subdev/therm.h>
-#include <subdev/pci.h>
-
-#define nvxx_device(a) ({                                                      \
-	struct nvif_device *_device = (a);                                     \
-	struct {                                                               \
-		struct nvkm_object object;                                     \
-		struct nvkm_device *device;                                    \
-	} *_udevice = _device->object.priv;                                    \
-	_udevice->device;                                                      \
-})
-#define nvxx_bios(a) nvxx_device(a)->bios
-#define nvxx_fb(a) nvxx_device(a)->fb
-#define nvxx_gpio(a) nvxx_device(a)->gpio
-#define nvxx_clk(a) nvxx_device(a)->clk
-#define nvxx_i2c(a) nvxx_device(a)->i2c
-#define nvxx_iccsense(a) nvxx_device(a)->iccsense
-#define nvxx_therm(a) nvxx_device(a)->therm
-#define nvxx_volt(a) nvxx_device(a)->volt
-
-#include <engine/fifo.h>
-#include <engine/gr.h>
-
-#define nvxx_gr(a) nvxx_device(a)->gr
 #endif
drivers/gpu/drm/nouveau/include/nvif/object.h +1 -1
index 8d205b6af46a..3534b241cad9 100644
@@ -15,7 +15,7 @@ struct nvif_object {
 	const char *name;
 	u32 handle;
 	s32 oclass;
-	void *priv; /*XXX: hack */
+	void *priv;
 	struct {
 		void __iomem *ptr;
 		u64 size;
drivers/gpu/drm/nouveau/nouveau_abi16.c +2 -2
index 704977530b6b..5d74c36a4ca5 100644
@@ -240,8 +240,8 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
 	struct nouveau_cli *cli = nouveau_cli(file_priv);
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nvif_device *device = &drm->client.device;
-	struct nvkm_device *nvkm_device = nvxx_device(&drm->client.device);
-	struct nvkm_gr *gr = nvxx_gr(device);
+	struct nvkm_device *nvkm_device = nvxx_device(drm);
+	struct nvkm_gr *gr = nvxx_gr(drm);
 	struct drm_nouveau_getparam *getparam = data;
 	struct pci_dev *pdev = to_pci_dev(dev->dev);
 
drivers/gpu/drm/nouveau/nouveau_bios.c +2 -2
index 79cfab53f80e..a8da6492efd3 100644
@@ -2020,7 +2020,7 @@ uint8_t *nouveau_bios_embedded_edid(struct drm_device *dev)
 static bool NVInitVBIOS(struct drm_device *dev)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
 	struct nvbios *legacy = &drm->vbios;
 
 	memset(legacy, 0, sizeof(struct nvbios));
@@ -2091,7 +2091,7 @@ nouveau_bios_init(struct drm_device *dev)
 
 	/* only relevant for PCI devices */
 	if (!dev_is_pci(dev->dev) ||
-	    nvkm_gsp_rm(nvxx_device(&drm->client.device)->gsp))
+	    nvkm_gsp_rm(nvxx_device(drm)->gsp))
 		return 0;
 
 	if (!NVInitVBIOS(dev))
drivers/gpu/drm/nouveau/nouveau_bios.h +1 -0
index 18eb061ccafb..62b5f5889041 100644
@@ -48,6 +48,7 @@ struct bit_entry {
 
 int bit_table(struct drm_device *, u8 id, struct bit_entry *);
 
+#include <subdev/bios.h>
 #include <subdev/bios/dcb.h>
 #include <subdev/bios/conn.h>
 
drivers/gpu/drm/nouveau/nouveau_bo.c +4 -4
index 0712d0b15170..6631d85ea749 100644
@@ -58,7 +58,7 @@ nv10_bo_update_tile_region(struct drm_device *dev, struct nouveau_drm_tile *reg,
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	int i = reg - drm->tile.reg;
-	struct nvkm_fb *fb = nvxx_fb(&drm->client.device);
+	struct nvkm_fb *fb = nvxx_fb(drm);
 	struct nvkm_fb_tile *tile = &fb->tile.region[i];
 
 	nouveau_fence_unref(&reg->fence);
@@ -109,7 +109,7 @@ nv10_bo_set_tiling(struct drm_device *dev, u32 addr,
 		   u32 size, u32 pitch, u32 zeta)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_fb *fb = nvxx_fb(&drm->client.device);
+	struct nvkm_fb *fb = nvxx_fb(drm);
 	struct nouveau_drm_tile *tile, *found = NULL;
 	int i;
 
@@ -1171,7 +1171,7 @@ static int
 nouveau_ttm_io_mem_reserve(struct ttm_device *bdev, struct ttm_resource *reg)
 {
 	struct nouveau_drm *drm = nouveau_bdev(bdev);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 	struct nouveau_mem *mem = nouveau_mem(reg);
 	struct nvif_mmu *mmu = &drm->client.mmu;
 	int ret;
@@ -1291,7 +1291,7 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
 {
 	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
 	struct nouveau_bo *nvbo = nouveau_bo(bo);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 	u32 mappable = device->func->resource_size(device, 1) >> PAGE_SHIFT;
 	int i, ret;
 
drivers/gpu/drm/nouveau/nouveau_chan.c +1 -2
index ce04c40e6f8f..0105d4704c3a 100644
@@ -218,8 +218,7 @@ nouveau_channel_prep(struct nouveau_drm *drm, struct nvif_device *device,
 			 */
 			args.target = NV_DMA_V0_TARGET_PCI;
 			args.access = NV_DMA_V0_ACCESS_RDWR;
-			args.start = nvxx_device(device)->func->
-				resource_addr(nvxx_device(device), 1);
+			args.start = nvxx_device(drm)->func->resource_addr(nvxx_device(drm), 1);
 			args.limit = args.start + device->info.ram_user - 1;
 		} else {
 			args.target = NV_DMA_V0_TARGET_VRAM;
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -2
index 936eb32fc8c4..5ff116bcbabf 100644
@@ -424,8 +424,7 @@ nouveau_accel_gr_init(struct nouveau_drm *drm)
 	 * any GPU where it's possible we'll end up using M2MF for BO moves.
 	 */
 	if (device->info.family < NV_DEVICE_INFO_V0_FERMI) {
-		ret = nvkm_gpuobj_new(nvxx_device(device), 32, 0, false, NULL,
-				      &drm->notify);
+		ret = nvkm_gpuobj_new(nvxx_device(drm), 32, 0, false, NULL, &drm->notify);
 		if (ret) {
 			NV_ERROR(drm, "failed to allocate notifier, %d\n", ret);
 			nouveau_accel_gr_fini(drm);
drivers/gpu/drm/nouveau/nouveau_drv.h +27 -0
index 80ffe15ba76b..a9e0a63c772e 100644
@@ -360,4 +360,31 @@ void nouveau_drm_device_remove(struct nouveau_drm *);
 
 extern int nouveau_modeset;
 
+/*XXX*/
+#include <subdev/bios.h>
+#include <subdev/fb.h>
+#include <subdev/gpio.h>
+#include <subdev/clk.h>
+#include <subdev/i2c.h>
+#include <subdev/timer.h>
+#include <subdev/therm.h>
+
+static inline struct nvkm_device *
+nvxx_device(struct nouveau_drm *drm)
+{
+	return drm->nvkm;
+}
+
+#define nvxx_bios(a) nvxx_device(a)->bios
+#define nvxx_fb(a) nvxx_device(a)->fb
+#define nvxx_gpio(a) nvxx_device(a)->gpio
+#define nvxx_clk(a) nvxx_device(a)->clk
+#define nvxx_i2c(a) nvxx_device(a)->i2c
+#define nvxx_iccsense(a) nvxx_device(a)->iccsense
+#define nvxx_therm(a) nvxx_device(a)->therm
+#define nvxx_volt(a) nvxx_device(a)->volt
+
+#include <engine/gr.h>
+
+#define nvxx_gr(a) nvxx_device(a)->gr
 #endif
drivers/gpu/drm/nouveau/nouveau_hwmon.c +23 -23

172 lines not on this page · raw message

drivers/gpu/drm/nouveau/nouveau_led.c +1 -1
index 2c5e0628da12..ac950518a820 100644
@@ -78,7 +78,7 @@ int
 nouveau_led_init(struct drm_device *dev)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
 	struct dcb_gpio_func logo_led;
 	int ret;
 
drivers/gpu/drm/nouveau/nouveau_ttm.c +2 -2
index 486f39f31a38..53553819bcac 100644
@@ -261,7 +261,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
 int
 nouveau_ttm_init(struct nouveau_drm *drm)
 {
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 	struct nvkm_pci *pci = device->pci;
 	struct nvif_mmu *mmu = &drm->client.mmu;
 	struct drm_device *dev = drm->dev;
@@ -348,7 +348,7 @@ nouveau_ttm_init(struct nouveau_drm *drm)
 void
 nouveau_ttm_fini(struct nouveau_drm *drm)
 {
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 
 	nouveau_ttm_fini_vram(drm);
 	nouveau_ttm_fini_gtt(drm);
Signature · 1 line
2.45.1
#55 lore raw

Re: [PATCH v2 27/37] drm/nouveau: move nvxx_* definitions to nouveau_drv.h

Quoted 397 lines · Ben Skeggs

These are some dodgy "convenience" macros for the DRM driver to peek into NVKM state. They're still used in a few places, but don't belong in nvif/device.h in any case.

Move them to nouveau_drv.h, and modify callers to pass a nouveau_drm instead of an nvif_device.

v2:
- use drm->nvkm pointer for nvxx_*() macros, removing some void*

---
 drivers/gpu/drm/nouveau/dispnv04/crtc.c       |  4 +-
 drivers/gpu/drm/nouveau/dispnv04/dac.c        |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/dfp.c        |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/disp.c       |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/disp.h       |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/hw.c         |  9 ++--
 drivers/gpu/drm/nouveau/dispnv04/tvnv04.c     |  4 +-
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c     |  6 +--
 drivers/gpu/drm/nouveau/dispnv50/disp.c       |  6 +--
 drivers/gpu/drm/nouveau/include/nvif/device.h | 33 -------------
 drivers/gpu/drm/nouveau/include/nvif/object.h |  2 +-
 drivers/gpu/drm/nouveau/nouveau_abi16.c       |  4 +-
 drivers/gpu/drm/nouveau/nouveau_bios.c        |  4 +-
 drivers/gpu/drm/nouveau/nouveau_bios.h        |  1 +
 drivers/gpu/drm/nouveau/nouveau_bo.c          |  8 ++--
 drivers/gpu/drm/nouveau/nouveau_chan.c        |  3 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c         |  3 +-
 drivers/gpu/drm/nouveau/nouveau_drv.h         | 27 +++++++++++
 drivers/gpu/drm/nouveau/nouveau_hwmon.c       | 46 +++++++++----------
 drivers/gpu/drm/nouveau/nouveau_led.c         |  2 +-
 drivers/gpu/drm/nouveau/nouveau_ttm.c         |  4 +-
 21 files changed, 83 insertions(+), 91 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/crtc.c +2 -2
index 4310ad71870b..e5067d5a4801 100644
@@ -118,8 +118,8 @@ static void nv_crtc_calc_state_ext(struct drm_crtc *crtc, struct drm_display_mod
 {
 	struct drm_device *dev = crtc->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
-	struct nvkm_clk *clk = nvxx_clk(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
+	struct nvkm_clk *clk = nvxx_clk(drm);
 	struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
 	struct nv04_mode_state *state = &nv04_display(dev)->mode_reg;
 	struct nv04_crtc_reg *regp = &state->crtc_reg[nv_crtc->index];
drivers/gpu/drm/nouveau/dispnv04/dac.c +1 -1
index d6b8e0cce2ac..2e12bf136607 100644
@@ -237,7 +237,7 @@ uint32_t nv17_dac_sample_load(struct drm_encoder *encoder)
 	struct drm_device *dev = encoder->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nvif_object *device = &nouveau_drm(dev)->client.device.object;
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
 	struct dcb_output *dcb = nouveau_encoder(encoder)->dcb;
 	uint32_t sample, testval, regoffset = nv04_dac_output_offset(encoder);
 	uint32_t saved_powerctrl_2 = 0, saved_powerctrl_4 = 0, saved_routput,
drivers/gpu/drm/nouveau/dispnv04/dfp.c +1 -1
index d5b129dc623b..504c421aa176 100644
@@ -626,7 +626,7 @@ static void nv04_tmds_slave_init(struct drm_encoder *encoder)
 	struct drm_device *dev = encoder->dev;
 	struct dcb_output *dcb = nouveau_encoder(encoder)->dcb;
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_PRI);
 	struct nvkm_i2c_bus_probe info[] = {
 		{
drivers/gpu/drm/nouveau/dispnv04/disp.c +1 -1
index e8b27bb135e7..e563a160571a 100644
@@ -211,7 +211,7 @@ int
 nv04_display_create(struct drm_device *dev)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct dcb_table *dcb = &drm->vbios.dcb;
 	struct drm_connector *connector, *ct;
 	struct drm_encoder *encoder;
drivers/gpu/drm/nouveau/dispnv04/disp.h +1 -1
index 11a6663758ec..85ec0f534392 100644
@@ -176,7 +176,7 @@ static inline void
 nouveau_bios_run_init_table(struct drm_device *dev, u16 table,
 			    struct dcb_output *outp, int crtc)
 {
-	nvbios_init(&nvxx_bios(&nouveau_drm(dev)->client.device)->subdev, table,
+	nvbios_init(&nvxx_bios(nouveau_drm(dev))->subdev, table,
 		init.outp = outp;
 		init.head = crtc;
 	);
drivers/gpu/drm/nouveau/dispnv04/hw.c +4 -5
index f7d35657aa64..8b376f9c8746 100644
@@ -166,7 +166,7 @@ nouveau_hw_get_pllvals(struct drm_device *dev, enum nvbios_pll_type plltype,
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nvif_object *device = &drm->client.device.object;
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
 	uint32_t reg1, pll1, pll2 = 0;
 	struct nvbios_pll pll_lim;
 	int ret;
@@ -258,9 +258,8 @@ nouveau_hw_fix_bad_vpll(struct drm_device *dev, int head)
 	 */
 
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvif_device *device = &drm->client.device;
-	struct nvkm_clk *clk = nvxx_clk(device);
-	struct nvkm_bios *bios = nvxx_bios(device);
+	struct nvkm_clk *clk = nvxx_clk(drm);
+	struct nvkm_bios *bios = nvxx_bios(drm);
 	struct nvbios_pll pll_lim;
 	struct nvkm_pll_vals pv;
 	enum nvbios_pll_type pll = head ? PLL_VPLL1 : PLL_VPLL0;
@@ -470,7 +469,7 @@ nv_load_state_ramdac(struct drm_device *dev, int head,
 		     struct nv04_mode_state *state)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_clk *clk = nvxx_clk(&drm->client.device);
+	struct nvkm_clk *clk = nvxx_clk(drm);
 	struct nv04_crtc_reg *regp = &state->crtc_reg[head];
 	uint32_t pllreg = head ? NV_RAMDAC_VPLL2 : NV_PRAMDAC_VPLL_COEFF;
 	int i;
drivers/gpu/drm/nouveau/dispnv04/tvnv04.c +2 -2
index de3ea731d6e6..d3014027a812 100644
@@ -53,7 +53,7 @@ static struct nvkm_i2c_bus_probe nv04_tv_encoder_info[] = {
 int nv04_tv_identify(struct drm_device *dev, int i2c_index)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, i2c_index);
 	if (bus) {
 		return nvkm_i2c_bus_probe(bus, "TV encoder",
@@ -205,7 +205,7 @@ nv04_tv_create(struct drm_connector *connector, struct dcb_output *entry)
 	struct drm_encoder *encoder;
 	struct drm_device *dev = connector->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, entry->i2c_index);
 	int type, ret;
 
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +3 -3
index 670c9739e5e1..c11f58033018 100644
@@ -47,7 +47,7 @@ static uint32_t nv42_tv_sample_load(struct drm_encoder *encoder)
 {
 	struct drm_device *dev = encoder->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
 	uint32_t testval, regoffset = nv04_dac_output_offset(encoder);
 	uint32_t gpio0, gpio1, fp_htotal, fp_hsync_start, fp_hsync_end,
 		fp_control, test_ctrl, dacclk, ctv_14, ctv_1c, ctv_6c;
@@ -131,7 +131,7 @@ static bool
 get_tv_detect_quirks(struct drm_device *dev, uint32_t *pin_mask)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 
 	if (device->quirk && device->quirk->tv_pin_mask) {
 		*pin_mask = device->quirk->tv_pin_mask;
@@ -363,7 +363,7 @@ static void  nv17_tv_dpms(struct drm_encoder *encoder, int mode)
 {
 	struct drm_device *dev = encoder->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
 	struct nv17_tv_state *regs = &to_tv_enc(encoder)->state;
 	struct nv17_tv_norm_params *tv_norm = get_tv_norm(encoder);
 
drivers/gpu/drm/nouveau/dispnv50/disp.c +3 -3
index 42375f757d7c..80803346b620 100644
@@ -561,7 +561,7 @@ nv50_dac_create(struct nouveau_encoder *nv_encoder)
 {
 	struct drm_connector *connector = &nv_encoder->conn->base;
 	struct nouveau_drm *drm = nouveau_drm(connector->dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct nvkm_i2c_bus *bus;
 	struct drm_encoder *encoder;
 	struct dcb_output *dcbe = nv_encoder->dcb;
@@ -1884,7 +1884,7 @@ nv50_sor_create(struct nouveau_encoder *nv_encoder)
 	struct drm_connector *connector = &nv_encoder->conn->base;
 	struct nouveau_connector *nv_connector = nouveau_connector(connector);
 	struct nouveau_drm *drm = nouveau_drm(connector->dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct drm_encoder *encoder;
 	struct dcb_output *dcbe = nv_encoder->dcb;
 	struct nv50_disp *disp = nv50_disp(connector->dev);
@@ -2051,7 +2051,7 @@ nv50_pior_create(struct nouveau_encoder *nv_encoder)
 	struct drm_device *dev = connector->dev;
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nv50_disp *disp = nv50_disp(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
 	struct nvkm_i2c_bus *bus = NULL;
 	struct nvkm_i2c_aux *aux = NULL;
 	struct i2c_adapter *ddc;
drivers/gpu/drm/nouveau/include/nvif/device.h +0 -33
index fec76f4733a4..7877a2a79da9 100644
@@ -22,37 +22,4 @@ int  nvif_device_ctor(struct nvif_client *, const char *name, struct nvif_device
 void nvif_device_dtor(struct nvif_device *);
 int  nvif_device_map(struct nvif_device *);
 u64  nvif_device_time(struct nvif_device *);
-
-/*XXX*/
-#include <subdev/bios.h>
-#include <subdev/fb.h>
-#include <subdev/bar.h>
-#include <subdev/gpio.h>
-#include <subdev/clk.h>
-#include <subdev/i2c.h>
-#include <subdev/timer.h>
-#include <subdev/therm.h>
-#include <subdev/pci.h>
-
-#define nvxx_device(a) ({                                                      \
-	struct nvif_device *_device = (a);                                     \
-	struct {                                                               \
-		struct nvkm_object object;                                     \
-		struct nvkm_device *device;                                    \
-	} *_udevice = _device->object.priv;                                    \
-	_udevice->device;                                                      \
-})
-#define nvxx_bios(a) nvxx_device(a)->bios
-#define nvxx_fb(a) nvxx_device(a)->fb
-#define nvxx_gpio(a) nvxx_device(a)->gpio
-#define nvxx_clk(a) nvxx_device(a)->clk
-#define nvxx_i2c(a) nvxx_device(a)->i2c
-#define nvxx_iccsense(a) nvxx_device(a)->iccsense
-#define nvxx_therm(a) nvxx_device(a)->therm
-#define nvxx_volt(a) nvxx_device(a)->volt
-
-#include <engine/fifo.h>
-#include <engine/gr.h>
-
-#define nvxx_gr(a) nvxx_device(a)->gr
 #endif
drivers/gpu/drm/nouveau/include/nvif/object.h +1 -1
index 8d205b6af46a..3534b241cad9 100644
@@ -15,7 +15,7 @@ struct nvif_object {
 	const char *name;
 	u32 handle;
 	s32 oclass;
-	void *priv; /*XXX: hack */
+	void *priv;
 	struct {
 		void __iomem *ptr;
 		u64 size;
drivers/gpu/drm/nouveau/nouveau_abi16.c +2 -2
index 704977530b6b..5d74c36a4ca5 100644
@@ -240,8 +240,8 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
 	struct nouveau_cli *cli = nouveau_cli(file_priv);
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nvif_device *device = &drm->client.device;
-	struct nvkm_device *nvkm_device = nvxx_device(&drm->client.device);
-	struct nvkm_gr *gr = nvxx_gr(device);
+	struct nvkm_device *nvkm_device = nvxx_device(drm);
+	struct nvkm_gr *gr = nvxx_gr(drm);
 	struct drm_nouveau_getparam *getparam = data;
 	struct pci_dev *pdev = to_pci_dev(dev->dev);
 
drivers/gpu/drm/nouveau/nouveau_bios.c +2 -2
index 79cfab53f80e..a8da6492efd3 100644
@@ -2020,7 +2020,7 @@ uint8_t *nouveau_bios_embedded_edid(struct drm_device *dev)
 static bool NVInitVBIOS(struct drm_device *dev)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
 	struct nvbios *legacy = &drm->vbios;
 
 	memset(legacy, 0, sizeof(struct nvbios));
@@ -2091,7 +2091,7 @@ nouveau_bios_init(struct drm_device *dev)
 
 	/* only relevant for PCI devices */
 	if (!dev_is_pci(dev->dev) ||
-	    nvkm_gsp_rm(nvxx_device(&drm->client.device)->gsp))
+	    nvkm_gsp_rm(nvxx_device(drm)->gsp))
 		return 0;
 
 	if (!NVInitVBIOS(dev))
drivers/gpu/drm/nouveau/nouveau_bios.h +1 -0
index 18eb061ccafb..62b5f5889041 100644
@@ -48,6 +48,7 @@ struct bit_entry {
 
 int bit_table(struct drm_device *, u8 id, struct bit_entry *);
 
+#include <subdev/bios.h>
 #include <subdev/bios/dcb.h>
 #include <subdev/bios/conn.h>
 
drivers/gpu/drm/nouveau/nouveau_bo.c +4 -4
index 0712d0b15170..6631d85ea749 100644
@@ -58,7 +58,7 @@ nv10_bo_update_tile_region(struct drm_device *dev, struct nouveau_drm_tile *reg,
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	int i = reg - drm->tile.reg;
-	struct nvkm_fb *fb = nvxx_fb(&drm->client.device);
+	struct nvkm_fb *fb = nvxx_fb(drm);
 	struct nvkm_fb_tile *tile = &fb->tile.region[i];
 
 	nouveau_fence_unref(&reg->fence);
@@ -109,7 +109,7 @@ nv10_bo_set_tiling(struct drm_device *dev, u32 addr,
 		   u32 size, u32 pitch, u32 zeta)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_fb *fb = nvxx_fb(&drm->client.device);
+	struct nvkm_fb *fb = nvxx_fb(drm);
 	struct nouveau_drm_tile *tile, *found = NULL;
 	int i;
 
@@ -1171,7 +1171,7 @@ static int
 nouveau_ttm_io_mem_reserve(struct ttm_device *bdev, struct ttm_resource *reg)
 {
 	struct nouveau_drm *drm = nouveau_bdev(bdev);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 	struct nouveau_mem *mem = nouveau_mem(reg);
 	struct nvif_mmu *mmu = &drm->client.mmu;
 	int ret;
@@ -1291,7 +1291,7 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
 {
 	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
 	struct nouveau_bo *nvbo = nouveau_bo(bo);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 	u32 mappable = device->func->resource_size(device, 1) >> PAGE_SHIFT;
 	int i, ret;
 
drivers/gpu/drm/nouveau/nouveau_chan.c +1 -2
index ce04c40e6f8f..0105d4704c3a 100644
@@ -218,8 +218,7 @@ nouveau_channel_prep(struct nouveau_drm *drm, struct nvif_device *device,
 			 */
 			args.target = NV_DMA_V0_TARGET_PCI;
 			args.access = NV_DMA_V0_ACCESS_RDWR;
-			args.start = nvxx_device(device)->func->
-				resource_addr(nvxx_device(device), 1);
+			args.start = nvxx_device(drm)->func->resource_addr(nvxx_device(drm), 1);
 			args.limit = args.start + device->info.ram_user - 1;
 		} else {
 			args.target = NV_DMA_V0_TARGET_VRAM;
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -2
index 936eb32fc8c4..5ff116bcbabf 100644
@@ -424,8 +424,7 @@ nouveau_accel_gr_init(struct nouveau_drm *drm)
 	 * any GPU where it's possible we'll end up using M2MF for BO moves.
 	 */
 	if (device->info.family < NV_DEVICE_INFO_V0_FERMI) {
-		ret = nvkm_gpuobj_new(nvxx_device(device), 32, 0, false, NULL,
-				      &drm->notify);
+		ret = nvkm_gpuobj_new(nvxx_device(drm), 32, 0, false, NULL, &drm->notify);
 		if (ret) {
 			NV_ERROR(drm, "failed to allocate notifier, %d\n", ret);
 			nouveau_accel_gr_fini(drm);
drivers/gpu/drm/nouveau/nouveau_drv.h +0 -0
index 80ffe15ba76b..a9e0a63c772e 100644

drivers/gpu/drm/nouveau/nouveau_drv.h void nouveau_drm_device_remove(struct nouveau_drm *); · line 363

Quoted 4 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
@@ -360,4 +360,31 @@ void nouveau_drm_device_remove(struct nouveau_drm *);
 
 extern int nouveau_modeset;
 
+/*XXX*/

What is the message of this here?

Quoted 12 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +12 -0
+#include <subdev/bios.h>
+#include <subdev/fb.h>
+#include <subdev/gpio.h>
+#include <subdev/clk.h>
+#include <subdev/i2c.h>
+#include <subdev/timer.h>
+#include <subdev/therm.h>
+
+static inline struct nvkm_device *
+nvxx_device(struct nouveau_drm *drm)
+{
+	return drm->nvkm;

drivers/gpu/drm/nouveau/nouveau_drv.h void nouveau_drm_device_remove(struct nouveau_drm *); · line 385

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +10 -0
+}
+
+#define nvxx_bios(a) nvxx_device(a)->bios
+#define nvxx_fb(a) nvxx_device(a)->fb
+#define nvxx_gpio(a) nvxx_device(a)->gpio
+#define nvxx_clk(a) nvxx_device(a)->clk
+#define nvxx_i2c(a) nvxx_device(a)->i2c
+#define nvxx_iccsense(a) nvxx_device(a)->iccsense
+#define nvxx_therm(a) nvxx_device(a)->therm
+#define nvxx_volt(a) nvxx_device(a)->volt

Why the "nvxx" prefix? Why not just "nvkm"?

Quoted 240 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +4 -0
+
+#include <engine/gr.h>
+
+#define nvxx_gr(a) nvxx_device(a)->gr
 #endif
drivers/gpu/drm/nouveau/nouveau_hwmon.c +23 -23
index db30a4c2cd4d..5c07a9ee8b77 100644
@@ -52,7 +52,7 @@ nouveau_hwmon_temp1_auto_point1_temp(struct device *d,
 {
 	struct drm_device *dev = dev_get_drvdata(d);
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
 	return sysfs_emit(buf, "%d\n",
 			  therm->attr_get(therm, NVKM_THERM_ATTR_THRS_FAN_BOOST) * 1000);
@@ -64,7 +64,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp(struct device *d,
 {
 	struct drm_device *dev = dev_get_drvdata(d);
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 	long value;
 
 	if (kstrtol(buf, 10, &value))
@@ -85,7 +85,7 @@ nouveau_hwmon_temp1_auto_point1_temp_hyst(struct device *d,
 {
 	struct drm_device *dev = dev_get_drvdata(d);
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
 	return sysfs_emit(buf, "%d\n",
 			  therm->attr_get(therm, NVKM_THERM_ATTR_THRS_FAN_BOOST_HYST) * 1000);
@@ -97,7 +97,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp_hyst(struct device *d,
 {
 	struct drm_device *dev = dev_get_drvdata(d);
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 	long value;
 
 	if (kstrtol(buf, 10, &value))
@@ -118,7 +118,7 @@ nouveau_hwmon_get_pwm1_max(struct device *d,
 {
 	struct drm_device *dev = dev_get_drvdata(d);
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 	int ret;
 
 	ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MAX_DUTY);
@@ -134,7 +134,7 @@ nouveau_hwmon_get_pwm1_min(struct device *d,
 {
 	struct drm_device *dev = dev_get_drvdata(d);
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 	int ret;
 
 	ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MIN_DUTY);
@@ -150,7 +150,7 @@ nouveau_hwmon_set_pwm1_min(struct device *d, struct device_attribute *a,
 {
 	struct drm_device *dev = dev_get_drvdata(d);
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 	long value;
 	int ret;
 
@@ -173,7 +173,7 @@ nouveau_hwmon_set_pwm1_max(struct device *d, struct device_attribute *a,
 {
 	struct drm_device *dev = dev_get_drvdata(d);
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 	long value;
 	int ret;
 
@@ -247,7 +247,7 @@ static umode_t
 nouveau_power_is_visible(const void *data, u32 attr, int channel)
 {
 	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
 
 	if (!iccsense || !iccsense->data_valid || list_empty(&iccsense->rails))
 		return 0;
@@ -272,7 +272,7 @@ static umode_t
 nouveau_temp_is_visible(const void *data, u32 attr, int channel)
 {
 	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
 	if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm) < 0)
 		return 0;
@@ -296,7 +296,7 @@ static umode_t
 nouveau_pwm_is_visible(const void *data, u32 attr, int channel)
 {
 	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
 	if (!therm || !therm->attr_get || !therm->fan_get ||
 	    therm->fan_get(therm) < 0)
@@ -315,7 +315,7 @@ static umode_t
 nouveau_input_is_visible(const void *data, u32 attr, int channel)
 {
 	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_volt *volt = nvxx_volt(drm);
 
 	if (!volt || nvkm_volt_get(volt) < 0)
 		return 0;
@@ -335,7 +335,7 @@ static umode_t
 nouveau_fan_is_visible(const void *data, u32 attr, int channel)
 {
 	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
 	if (!therm || !therm->attr_get || nvkm_therm_fan_sense(therm) < 0)
 		return 0;
@@ -367,7 +367,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val)
 {
 	struct drm_device *drm_dev = dev_get_drvdata(dev);
 	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 	int ret;
 
 	if (!therm || !therm->attr_get)
@@ -416,7 +416,7 @@ nouveau_fan_read(struct device *dev, u32 attr, int channel, long *val)
 {
 	struct drm_device *drm_dev = dev_get_drvdata(dev);
 	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
 	if (!therm)
 		return -EOPNOTSUPP;
@@ -439,7 +439,7 @@ nouveau_in_read(struct device *dev, u32 attr, int channel, long *val)
 {
 	struct drm_device *drm_dev = dev_get_drvdata(dev);
 	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_volt *volt = nvxx_volt(drm);
 	int ret;
 
 	if (!volt)
@@ -470,7 +470,7 @@ nouveau_pwm_read(struct device *dev, u32 attr, int channel, long *val)
 {
 	struct drm_device *drm_dev = dev_get_drvdata(dev);
 	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
 	if (!therm || !therm->attr_get || !therm->fan_get)
 		return -EOPNOTSUPP;
@@ -496,7 +496,7 @@ nouveau_power_read(struct device *dev, u32 attr, int channel, long *val)
 {
 	struct drm_device *drm_dev = dev_get_drvdata(dev);
 	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
 
 	if (!iccsense)
 		return -EOPNOTSUPP;
@@ -525,7 +525,7 @@ nouveau_temp_write(struct device *dev, u32 attr, int channel, long val)
 {
 	struct drm_device *drm_dev = dev_get_drvdata(dev);
 	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
 	if (!therm || !therm->attr_set)
 		return -EOPNOTSUPP;
@@ -559,7 +559,7 @@ nouveau_pwm_write(struct device *dev, u32 attr, int channel, long val)
 {
 	struct drm_device *drm_dev = dev_get_drvdata(dev);
 	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
 	if (!therm || !therm->attr_set)
 		return -EOPNOTSUPP;
@@ -664,9 +664,9 @@ nouveau_hwmon_init(struct drm_device *dev)
 {
 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
+	struct nvkm_therm *therm = nvxx_therm(drm);
+	struct nvkm_volt *volt = nvxx_volt(drm);
 	const struct attribute_group *special_groups[N_ATTR_GROUPS];
 	struct nouveau_hwmon *hwmon;
 	struct device *hwmon_dev;
drivers/gpu/drm/nouveau/nouveau_led.c +1 -1
index 2c5e0628da12..ac950518a820 100644
@@ -78,7 +78,7 @@ int
 nouveau_led_init(struct drm_device *dev)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
 	struct dcb_gpio_func logo_led;
 	int ret;
 
drivers/gpu/drm/nouveau/nouveau_ttm.c +2 -2
index 486f39f31a38..53553819bcac 100644
@@ -261,7 +261,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
 int
 nouveau_ttm_init(struct nouveau_drm *drm)
 {
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 	struct nvkm_pci *pci = device->pci;
 	struct nvif_mmu *mmu = &drm->client.mmu;
 	struct drm_device *dev = drm->dev;
@@ -348,7 +348,7 @@ nouveau_ttm_init(struct nouveau_drm *drm)
 void
 nouveau_ttm_fini(struct nouveau_drm *drm)
 {
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 
 	nouveau_ttm_fini_vram(drm);
 	nouveau_ttm_fini_gtt(drm);
Signature · 1 line
2.45.1
author
#56 lore raw

Re: [PATCH v2 27/37] drm/nouveau: move nvxx_* definitions to nouveau_drv.h

Quoted 399 lines · Danilo Krummrich
Quoted 398 lines · Ben Skeggs

These are some dodgy "convenience" macros for the DRM driver to peek into NVKM state. They're still used in a few places, but don't belong in nvif/device.h in any case.

Move them to nouveau_drv.h, and modify callers to pass a nouveau_drm instead of an nvif_device.

v2:
- use drm->nvkm pointer for nvxx_*() macros, removing some void*

---
  drivers/gpu/drm/nouveau/dispnv04/crtc.c       |  4 +-
  drivers/gpu/drm/nouveau/dispnv04/dac.c        |  2 +-
  drivers/gpu/drm/nouveau/dispnv04/dfp.c        |  2 +-
  drivers/gpu/drm/nouveau/dispnv04/disp.c       |  2 +-
  drivers/gpu/drm/nouveau/dispnv04/disp.h       |  2 +-
  drivers/gpu/drm/nouveau/dispnv04/hw.c         |  9 ++--
  drivers/gpu/drm/nouveau/dispnv04/tvnv04.c     |  4 +-
  drivers/gpu/drm/nouveau/dispnv04/tvnv17.c     |  6 +--
  drivers/gpu/drm/nouveau/dispnv50/disp.c       |  6 +--
  drivers/gpu/drm/nouveau/include/nvif/device.h | 33 -------------
  drivers/gpu/drm/nouveau/include/nvif/object.h |  2 +-
  drivers/gpu/drm/nouveau/nouveau_abi16.c       |  4 +-
  drivers/gpu/drm/nouveau/nouveau_bios.c        |  4 +-
  drivers/gpu/drm/nouveau/nouveau_bios.h        |  1 +
  drivers/gpu/drm/nouveau/nouveau_bo.c          |  8 ++--
  drivers/gpu/drm/nouveau/nouveau_chan.c        |  3 +-
  drivers/gpu/drm/nouveau/nouveau_drm.c         |  3 +-
  drivers/gpu/drm/nouveau/nouveau_drv.h         | 27 +++++++++++
  drivers/gpu/drm/nouveau/nouveau_hwmon.c       | 46 +++++++++----------
  drivers/gpu/drm/nouveau/nouveau_led.c         |  2 +-
  drivers/gpu/drm/nouveau/nouveau_ttm.c         |  4 +-
  21 files changed, 83 insertions(+), 91 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/crtc.c +2 -2
index 4310ad71870b..e5067d5a4801 100644
@@ -118,8 +118,8 @@ static void nv_crtc_calc_state_ext(struct drm_crtc *crtc, struct drm_display_mod
  {
  	struct drm_device *dev = crtc->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
-	struct nvkm_clk *clk = nvxx_clk(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
+	struct nvkm_clk *clk = nvxx_clk(drm);
  	struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  	struct nv04_mode_state *state = &nv04_display(dev)->mode_reg;
  	struct nv04_crtc_reg *regp = &state->crtc_reg[nv_crtc->index];
drivers/gpu/drm/nouveau/dispnv04/dac.c +1 -1
index d6b8e0cce2ac..2e12bf136607 100644
@@ -237,7 +237,7 @@ uint32_t nv17_dac_sample_load(struct drm_encoder *encoder)
  	struct drm_device *dev = encoder->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
  	struct nvif_object *device = &nouveau_drm(dev)->client.device.object;
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
  	struct dcb_output *dcb = nouveau_encoder(encoder)->dcb;
  	uint32_t sample, testval, regoffset = nv04_dac_output_offset(encoder);
  	uint32_t saved_powerctrl_2 = 0, saved_powerctrl_4 = 0, saved_routput,
drivers/gpu/drm/nouveau/dispnv04/dfp.c +1 -1
index d5b129dc623b..504c421aa176 100644
@@ -626,7 +626,7 @@ static void nv04_tmds_slave_init(struct drm_encoder *encoder)
  	struct drm_device *dev = encoder->dev;
  	struct dcb_output *dcb = nouveau_encoder(encoder)->dcb;
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_PRI);
  	struct nvkm_i2c_bus_probe info[] = {
  		{
drivers/gpu/drm/nouveau/dispnv04/disp.c +1 -1
index e8b27bb135e7..e563a160571a 100644
@@ -211,7 +211,7 @@ int
  nv04_display_create(struct drm_device *dev)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct dcb_table *dcb = &drm->vbios.dcb;
  	struct drm_connector *connector, *ct;
  	struct drm_encoder *encoder;
drivers/gpu/drm/nouveau/dispnv04/disp.h +1 -1
index 11a6663758ec..85ec0f534392 100644
@@ -176,7 +176,7 @@ static inline void
  nouveau_bios_run_init_table(struct drm_device *dev, u16 table,
  			    struct dcb_output *outp, int crtc)
  {
-	nvbios_init(&nvxx_bios(&nouveau_drm(dev)->client.device)->subdev, table,
+	nvbios_init(&nvxx_bios(nouveau_drm(dev))->subdev, table,
  		init.outp = outp;
  		init.head = crtc;
  	);
drivers/gpu/drm/nouveau/dispnv04/hw.c +4 -5
index f7d35657aa64..8b376f9c8746 100644
@@ -166,7 +166,7 @@ nouveau_hw_get_pllvals(struct drm_device *dev, enum nvbios_pll_type plltype,
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
  	struct nvif_object *device = &drm->client.device.object;
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
  	uint32_t reg1, pll1, pll2 = 0;
  	struct nvbios_pll pll_lim;
  	int ret;
@@ -258,9 +258,8 @@ nouveau_hw_fix_bad_vpll(struct drm_device *dev, int head)
  	 */
 
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvif_device *device = &drm->client.device;
-	struct nvkm_clk *clk = nvxx_clk(device);
-	struct nvkm_bios *bios = nvxx_bios(device);
+	struct nvkm_clk *clk = nvxx_clk(drm);
+	struct nvkm_bios *bios = nvxx_bios(drm);
  	struct nvbios_pll pll_lim;
  	struct nvkm_pll_vals pv;
  	enum nvbios_pll_type pll = head ? PLL_VPLL1 : PLL_VPLL0;
@@ -470,7 +469,7 @@ nv_load_state_ramdac(struct drm_device *dev, int head,
  		     struct nv04_mode_state *state)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_clk *clk = nvxx_clk(&drm->client.device);
+	struct nvkm_clk *clk = nvxx_clk(drm);
  	struct nv04_crtc_reg *regp = &state->crtc_reg[head];
  	uint32_t pllreg = head ? NV_RAMDAC_VPLL2 : NV_PRAMDAC_VPLL_COEFF;
  	int i;
drivers/gpu/drm/nouveau/dispnv04/tvnv04.c +2 -2
index de3ea731d6e6..d3014027a812 100644
@@ -53,7 +53,7 @@ static struct nvkm_i2c_bus_probe nv04_tv_encoder_info[] = {
  int nv04_tv_identify(struct drm_device *dev, int i2c_index)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, i2c_index);
  	if (bus) {
  		return nvkm_i2c_bus_probe(bus, "TV encoder",
@@ -205,7 +205,7 @@ nv04_tv_create(struct drm_connector *connector, struct dcb_output *entry)
  	struct drm_encoder *encoder;
  	struct drm_device *dev = connector->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, entry->i2c_index);
  	int type, ret;
 
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +3 -3
index 670c9739e5e1..c11f58033018 100644
@@ -47,7 +47,7 @@ static uint32_t nv42_tv_sample_load(struct drm_encoder *encoder)
  {
  	struct drm_device *dev = encoder->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
  	uint32_t testval, regoffset = nv04_dac_output_offset(encoder);
  	uint32_t gpio0, gpio1, fp_htotal, fp_hsync_start, fp_hsync_end,
  		fp_control, test_ctrl, dacclk, ctv_14, ctv_1c, ctv_6c;
@@ -131,7 +131,7 @@ static bool
  get_tv_detect_quirks(struct drm_device *dev, uint32_t *pin_mask)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 
  	if (device->quirk && device->quirk->tv_pin_mask) {
  		*pin_mask = device->quirk->tv_pin_mask;
@@ -363,7 +363,7 @@ static void  nv17_tv_dpms(struct drm_encoder *encoder, int mode)
  {
  	struct drm_device *dev = encoder->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
  	struct nv17_tv_state *regs = &to_tv_enc(encoder)->state;
  	struct nv17_tv_norm_params *tv_norm = get_tv_norm(encoder);
 
drivers/gpu/drm/nouveau/dispnv50/disp.c +3 -3
index 42375f757d7c..80803346b620 100644
@@ -561,7 +561,7 @@ nv50_dac_create(struct nouveau_encoder *nv_encoder)
  {
  	struct drm_connector *connector = &nv_encoder->conn->base;
  	struct nouveau_drm *drm = nouveau_drm(connector->dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct nvkm_i2c_bus *bus;
  	struct drm_encoder *encoder;
  	struct dcb_output *dcbe = nv_encoder->dcb;
@@ -1884,7 +1884,7 @@ nv50_sor_create(struct nouveau_encoder *nv_encoder)
  	struct drm_connector *connector = &nv_encoder->conn->base;
  	struct nouveau_connector *nv_connector = nouveau_connector(connector);
  	struct nouveau_drm *drm = nouveau_drm(connector->dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct drm_encoder *encoder;
  	struct dcb_output *dcbe = nv_encoder->dcb;
  	struct nv50_disp *disp = nv50_disp(connector->dev);
@@ -2051,7 +2051,7 @@ nv50_pior_create(struct nouveau_encoder *nv_encoder)
  	struct drm_device *dev = connector->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
  	struct nv50_disp *disp = nv50_disp(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct nvkm_i2c_bus *bus = NULL;
  	struct nvkm_i2c_aux *aux = NULL;
  	struct i2c_adapter *ddc;
drivers/gpu/drm/nouveau/include/nvif/device.h +0 -33
index fec76f4733a4..7877a2a79da9 100644
@@ -22,37 +22,4 @@ int  nvif_device_ctor(struct nvif_client *, const char *name, struct nvif_device
  void nvif_device_dtor(struct nvif_device *);
  int  nvif_device_map(struct nvif_device *);
  u64  nvif_device_time(struct nvif_device *);
-
-/*XXX*/
-#include <subdev/bios.h>
-#include <subdev/fb.h>
-#include <subdev/bar.h>
-#include <subdev/gpio.h>
-#include <subdev/clk.h>
-#include <subdev/i2c.h>
-#include <subdev/timer.h>
-#include <subdev/therm.h>
-#include <subdev/pci.h>
-
-#define nvxx_device(a) ({                                                      \
-	struct nvif_device *_device = (a);                                     \
-	struct {                                                               \
-		struct nvkm_object object;                                     \
-		struct nvkm_device *device;                                    \
-	} *_udevice = _device->object.priv;                                    \
-	_udevice->device;                                                      \
-})
-#define nvxx_bios(a) nvxx_device(a)->bios
-#define nvxx_fb(a) nvxx_device(a)->fb
-#define nvxx_gpio(a) nvxx_device(a)->gpio
-#define nvxx_clk(a) nvxx_device(a)->clk
-#define nvxx_i2c(a) nvxx_device(a)->i2c
-#define nvxx_iccsense(a) nvxx_device(a)->iccsense
-#define nvxx_therm(a) nvxx_device(a)->therm
-#define nvxx_volt(a) nvxx_device(a)->volt
-
-#include <engine/fifo.h>
-#include <engine/gr.h>
-
-#define nvxx_gr(a) nvxx_device(a)->gr
  #endif
drivers/gpu/drm/nouveau/include/nvif/object.h +1 -1
index 8d205b6af46a..3534b241cad9 100644
@@ -15,7 +15,7 @@ struct nvif_object {
  	const char *name;
  	u32 handle;
  	s32 oclass;
-	void *priv; /*XXX: hack */
+	void *priv;
  	struct {
  		void __iomem *ptr;
  		u64 size;
drivers/gpu/drm/nouveau/nouveau_abi16.c +2 -2
index 704977530b6b..5d74c36a4ca5 100644
@@ -240,8 +240,8 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
  	struct nouveau_cli *cli = nouveau_cli(file_priv);
  	struct nouveau_drm *drm = nouveau_drm(dev);
  	struct nvif_device *device = &drm->client.device;
-	struct nvkm_device *nvkm_device = nvxx_device(&drm->client.device);
-	struct nvkm_gr *gr = nvxx_gr(device);
+	struct nvkm_device *nvkm_device = nvxx_device(drm);
+	struct nvkm_gr *gr = nvxx_gr(drm);
  	struct drm_nouveau_getparam *getparam = data;
  	struct pci_dev *pdev = to_pci_dev(dev->dev);
 
drivers/gpu/drm/nouveau/nouveau_bios.c +2 -2
index 79cfab53f80e..a8da6492efd3 100644
@@ -2020,7 +2020,7 @@ uint8_t *nouveau_bios_embedded_edid(struct drm_device *dev)
  static bool NVInitVBIOS(struct drm_device *dev)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
  	struct nvbios *legacy = &drm->vbios;
 
  	memset(legacy, 0, sizeof(struct nvbios));
@@ -2091,7 +2091,7 @@ nouveau_bios_init(struct drm_device *dev)
 
  	/* only relevant for PCI devices */
  	if (!dev_is_pci(dev->dev) ||
-	    nvkm_gsp_rm(nvxx_device(&drm->client.device)->gsp))
+	    nvkm_gsp_rm(nvxx_device(drm)->gsp))
  		return 0;
 
  	if (!NVInitVBIOS(dev))
drivers/gpu/drm/nouveau/nouveau_bios.h +1 -0
index 18eb061ccafb..62b5f5889041 100644
@@ -48,6 +48,7 @@ struct bit_entry {
 
  int bit_table(struct drm_device *, u8 id, struct bit_entry *);
 
+#include <subdev/bios.h>
  #include <subdev/bios/dcb.h>
  #include <subdev/bios/conn.h>
 
drivers/gpu/drm/nouveau/nouveau_bo.c +4 -4
index 0712d0b15170..6631d85ea749 100644
@@ -58,7 +58,7 @@ nv10_bo_update_tile_region(struct drm_device *dev, struct nouveau_drm_tile *reg,
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
  	int i = reg - drm->tile.reg;
-	struct nvkm_fb *fb = nvxx_fb(&drm->client.device);
+	struct nvkm_fb *fb = nvxx_fb(drm);
  	struct nvkm_fb_tile *tile = &fb->tile.region[i];
 
  	nouveau_fence_unref(&reg->fence);
@@ -109,7 +109,7 @@ nv10_bo_set_tiling(struct drm_device *dev, u32 addr,
  		   u32 size, u32 pitch, u32 zeta)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_fb *fb = nvxx_fb(&drm->client.device);
+	struct nvkm_fb *fb = nvxx_fb(drm);
  	struct nouveau_drm_tile *tile, *found = NULL;
  	int i;
 
@@ -1171,7 +1171,7 @@ static int
  nouveau_ttm_io_mem_reserve(struct ttm_device *bdev, struct ttm_resource *reg)
  {
  	struct nouveau_drm *drm = nouveau_bdev(bdev);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
  	struct nouveau_mem *mem = nouveau_mem(reg);
  	struct nvif_mmu *mmu = &drm->client.mmu;
  	int ret;
@@ -1291,7 +1291,7 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
  {
  	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
  	struct nouveau_bo *nvbo = nouveau_bo(bo);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
  	u32 mappable = device->func->resource_size(device, 1) >> PAGE_SHIFT;
  	int i, ret;
 
drivers/gpu/drm/nouveau/nouveau_chan.c +1 -2
index ce04c40e6f8f..0105d4704c3a 100644
@@ -218,8 +218,7 @@ nouveau_channel_prep(struct nouveau_drm *drm, struct nvif_device *device,
  			 */
  			args.target = NV_DMA_V0_TARGET_PCI;
  			args.access = NV_DMA_V0_ACCESS_RDWR;
-			args.start = nvxx_device(device)->func->
-				resource_addr(nvxx_device(device), 1);
+			args.start = nvxx_device(drm)->func->resource_addr(nvxx_device(drm), 1);
  			args.limit = args.start + device->info.ram_user - 1;
  		} else {
  			args.target = NV_DMA_V0_TARGET_VRAM;
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -2
index 936eb32fc8c4..5ff116bcbabf 100644
@@ -424,8 +424,7 @@ nouveau_accel_gr_init(struct nouveau_drm *drm)
  	 * any GPU where it's possible we'll end up using M2MF for BO moves.
  	 */
  	if (device->info.family < NV_DEVICE_INFO_V0_FERMI) {
-		ret = nvkm_gpuobj_new(nvxx_device(device), 32, 0, false, NULL,
-				      &drm->notify);
+		ret = nvkm_gpuobj_new(nvxx_device(drm), 32, 0, false, NULL, &drm->notify);
  		if (ret) {
  			NV_ERROR(drm, "failed to allocate notifier, %d\n", ret);
  			nouveau_accel_gr_fini(drm);
drivers/gpu/drm/nouveau/nouveau_drv.h +0 -0
index 80ffe15ba76b..a9e0a63c772e 100644
@@ -360,4 +360,31 @@ void nouveau_drm_device_remove(struct nouveau_drm *);
 
Quoted 4 lines

drivers/gpu/drm/nouveau/nouveau_drv.h void nouveau_drm_device_remove(struct nouveau_drm *); · line 363

Quoted 3 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
  extern int nouveau_modeset;
 
+/*XXX*/

What is the message of this here?

This is moved over from its old location.

Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +15 -0
+#include <subdev/bios.h>
+#include <subdev/fb.h>
+#include <subdev/gpio.h>
+#include <subdev/clk.h>
+#include <subdev/i2c.h>
+#include <subdev/timer.h>
+#include <subdev/therm.h>
+
+static inline struct nvkm_device *
+nvxx_device(struct nouveau_drm *drm)
+{
+	return drm->nvkm;
+}
+
+#define nvxx_bios(a) nvxx_device(a)->bios
Quoted 8 lines

drivers/gpu/drm/nouveau/nouveau_drv.h void nouveau_drm_device_remove(struct nouveau_drm *); · line 385

Quoted 7 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +7 -0
+#define nvxx_fb(a) nvxx_device(a)->fb
+#define nvxx_gpio(a) nvxx_device(a)->gpio
+#define nvxx_clk(a) nvxx_device(a)->clk
+#define nvxx_i2c(a) nvxx_device(a)->i2c
+#define nvxx_iccsense(a) nvxx_device(a)->iccsense
+#define nvxx_therm(a) nvxx_device(a)->therm
+#define nvxx_volt(a) nvxx_device(a)->volt

Why the "nvxx" prefix? Why not just "nvkm"?

Because these aren't supposed to be used, and exist for the few locations that never got proper NVIF.  I've added info to the commit with some further explanation.

I've updated the branch on gitlab for this, and your commit message nitpicks.

Quoted 241 lines
Quoted 241 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +4 -0
+
+#include <engine/gr.h>
+
+#define nvxx_gr(a) nvxx_device(a)->gr
  #endif
drivers/gpu/drm/nouveau/nouveau_hwmon.c +23 -23
index db30a4c2cd4d..5c07a9ee8b77 100644
@@ -52,7 +52,7 @@ nouveau_hwmon_temp1_auto_point1_temp(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
  	return sysfs_emit(buf, "%d\n",
  			  therm->attr_get(therm, NVKM_THERM_ATTR_THRS_FAN_BOOST) * 1000);
@@ -64,7 +64,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	long value;
 
  	if (kstrtol(buf, 10, &value))
@@ -85,7 +85,7 @@ nouveau_hwmon_temp1_auto_point1_temp_hyst(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
  	return sysfs_emit(buf, "%d\n",
  			  therm->attr_get(therm, NVKM_THERM_ATTR_THRS_FAN_BOOST_HYST) * 1000);
@@ -97,7 +97,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp_hyst(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	long value;
 
  	if (kstrtol(buf, 10, &value))
@@ -118,7 +118,7 @@ nouveau_hwmon_get_pwm1_max(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	int ret;
 
  	ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MAX_DUTY);
@@ -134,7 +134,7 @@ nouveau_hwmon_get_pwm1_min(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	int ret;
 
  	ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MIN_DUTY);
@@ -150,7 +150,7 @@ nouveau_hwmon_set_pwm1_min(struct device *d, struct device_attribute *a,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	long value;
  	int ret;
 
@@ -173,7 +173,7 @@ nouveau_hwmon_set_pwm1_max(struct device *d, struct device_attribute *a,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	long value;
  	int ret;
 
@@ -247,7 +247,7 @@ static umode_t
  nouveau_power_is_visible(const void *data, u32 attr, int channel)
  {
  	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
 
  	if (!iccsense || !iccsense->data_valid || list_empty(&iccsense->rails))
  		return 0;
@@ -272,7 +272,7 @@ static umode_t
  nouveau_temp_is_visible(const void *data, u32 attr, int channel)
  {
  	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
  	if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm) < 0)
  		return 0;
@@ -296,7 +296,7 @@ static umode_t
  nouveau_pwm_is_visible(const void *data, u32 attr, int channel)
  {
  	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
  	if (!therm || !therm->attr_get || !therm->fan_get ||
  	    therm->fan_get(therm) < 0)
@@ -315,7 +315,7 @@ static umode_t
  nouveau_input_is_visible(const void *data, u32 attr, int channel)
  {
  	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_volt *volt = nvxx_volt(drm);
 
  	if (!volt || nvkm_volt_get(volt) < 0)
  		return 0;
@@ -335,7 +335,7 @@ static umode_t
  nouveau_fan_is_visible(const void *data, u32 attr, int channel)
  {
  	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
  	if (!therm || !therm->attr_get || nvkm_therm_fan_sense(therm) < 0)
  		return 0;
@@ -367,7 +367,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	int ret;
 
  	if (!therm || !therm->attr_get)
@@ -416,7 +416,7 @@ nouveau_fan_read(struct device *dev, u32 attr, int channel, long *val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
  	if (!therm)
  		return -EOPNOTSUPP;
@@ -439,7 +439,7 @@ nouveau_in_read(struct device *dev, u32 attr, int channel, long *val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_volt *volt = nvxx_volt(drm);
  	int ret;
 
  	if (!volt)
@@ -470,7 +470,7 @@ nouveau_pwm_read(struct device *dev, u32 attr, int channel, long *val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
  	if (!therm || !therm->attr_get || !therm->fan_get)
  		return -EOPNOTSUPP;
@@ -496,7 +496,7 @@ nouveau_power_read(struct device *dev, u32 attr, int channel, long *val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
 
  	if (!iccsense)
  		return -EOPNOTSUPP;
@@ -525,7 +525,7 @@ nouveau_temp_write(struct device *dev, u32 attr, int channel, long val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
  	if (!therm || !therm->attr_set)
  		return -EOPNOTSUPP;
@@ -559,7 +559,7 @@ nouveau_pwm_write(struct device *dev, u32 attr, int channel, long val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
 
  	if (!therm || !therm->attr_set)
  		return -EOPNOTSUPP;
@@ -664,9 +664,9 @@ nouveau_hwmon_init(struct drm_device *dev)
  {
  #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
+	struct nvkm_therm *therm = nvxx_therm(drm);
+	struct nvkm_volt *volt = nvxx_volt(drm);
  	const struct attribute_group *special_groups[N_ATTR_GROUPS];
  	struct nouveau_hwmon *hwmon;
  	struct device *hwmon_dev;
drivers/gpu/drm/nouveau/nouveau_led.c +1 -1
index 2c5e0628da12..ac950518a820 100644
@@ -78,7 +78,7 @@ int
  nouveau_led_init(struct drm_device *dev)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
  	struct dcb_gpio_func logo_led;
  	int ret;
 
drivers/gpu/drm/nouveau/nouveau_ttm.c +2 -2
index 486f39f31a38..53553819bcac 100644
@@ -261,7 +261,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
  int
  nouveau_ttm_init(struct nouveau_drm *drm)
  {
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
  	struct nvkm_pci *pci = device->pci;
  	struct nvif_mmu *mmu = &drm->client.mmu;
  	struct drm_device *dev = drm->dev;
@@ -348,7 +348,7 @@ nouveau_ttm_init(struct nouveau_drm *drm)
  void
  nouveau_ttm_fini(struct nouveau_drm *drm)
  {
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
 
  	nouveau_ttm_fini_vram(drm);
  	nouveau_ttm_fini_gtt(drm);
Signature · 1 line
2.45.1
#57 lore raw

Re: [PATCH v2 27/37] drm/nouveau: move nvxx_* definitions to nouveau_drv.h

Quoted 389 lines · Ben Skeggs
Quoted 379 lines · Danilo Krummrich
Quoted 378 lines · Ben Skeggs

These are some dodgy "convenience" macros for the DRM driver to peek into NVKM state. They're still used in a few places, but don't belong in nvif/device.h in any case.

Move them to nouveau_drv.h, and modify callers to pass a nouveau_drm instead of an nvif_device.

v2:
- use drm->nvkm pointer for nvxx_*() macros, removing some void*

---
  drivers/gpu/drm/nouveau/dispnv04/crtc.c       |  4 +-
  drivers/gpu/drm/nouveau/dispnv04/dac.c        |  2 +-
  drivers/gpu/drm/nouveau/dispnv04/dfp.c        |  2 +-
  drivers/gpu/drm/nouveau/dispnv04/disp.c       |  2 +-
  drivers/gpu/drm/nouveau/dispnv04/disp.h       |  2 +-
  drivers/gpu/drm/nouveau/dispnv04/hw.c         |  9 ++--
  drivers/gpu/drm/nouveau/dispnv04/tvnv04.c     |  4 +-
  drivers/gpu/drm/nouveau/dispnv04/tvnv17.c     |  6 +--
  drivers/gpu/drm/nouveau/dispnv50/disp.c       |  6 +--
  drivers/gpu/drm/nouveau/include/nvif/device.h | 33 -------------
  drivers/gpu/drm/nouveau/include/nvif/object.h |  2 +-
  drivers/gpu/drm/nouveau/nouveau_abi16.c       |  4 +-
  drivers/gpu/drm/nouveau/nouveau_bios.c        |  4 +-
  drivers/gpu/drm/nouveau/nouveau_bios.h        |  1 +
  drivers/gpu/drm/nouveau/nouveau_bo.c          |  8 ++--
  drivers/gpu/drm/nouveau/nouveau_chan.c        |  3 +-
  drivers/gpu/drm/nouveau/nouveau_drm.c         |  3 +-
  drivers/gpu/drm/nouveau/nouveau_drv.h         | 27 +++++++++++
  drivers/gpu/drm/nouveau/nouveau_hwmon.c       | 46 +++++++++----------
  drivers/gpu/drm/nouveau/nouveau_led.c         |  2 +-
  drivers/gpu/drm/nouveau/nouveau_ttm.c         |  4 +-
  21 files changed, 83 insertions(+), 91 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/crtc.c +2 -2
index 4310ad71870b..e5067d5a4801 100644
@@ -118,8 +118,8 @@ static void nv_crtc_calc_state_ext(struct drm_crtc *crtc, struct drm_display_mod
  {
  	struct drm_device *dev = crtc->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
-	struct nvkm_clk *clk = nvxx_clk(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
+	struct nvkm_clk *clk = nvxx_clk(drm);
  	struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  	struct nv04_mode_state *state = &nv04_display(dev)->mode_reg;
  	struct nv04_crtc_reg *regp = &state->crtc_reg[nv_crtc->index];
drivers/gpu/drm/nouveau/dispnv04/dac.c +1 -1
index d6b8e0cce2ac..2e12bf136607 100644
@@ -237,7 +237,7 @@ uint32_t nv17_dac_sample_load(struct drm_encoder *encoder)
  	struct drm_device *dev = encoder->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
  	struct nvif_object *device = &nouveau_drm(dev)->client.device.object;
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
  	struct dcb_output *dcb = nouveau_encoder(encoder)->dcb;
  	uint32_t sample, testval, regoffset = nv04_dac_output_offset(encoder);
  	uint32_t saved_powerctrl_2 = 0, saved_powerctrl_4 = 0, saved_routput,
drivers/gpu/drm/nouveau/dispnv04/dfp.c +1 -1
index d5b129dc623b..504c421aa176 100644
@@ -626,7 +626,7 @@ static void nv04_tmds_slave_init(struct drm_encoder *encoder)
  	struct drm_device *dev = encoder->dev;
  	struct dcb_output *dcb = nouveau_encoder(encoder)->dcb;
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_PRI);
  	struct nvkm_i2c_bus_probe info[] = {
  		{
drivers/gpu/drm/nouveau/dispnv04/disp.c +1 -1
index e8b27bb135e7..e563a160571a 100644
@@ -211,7 +211,7 @@ int
  nv04_display_create(struct drm_device *dev)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct dcb_table *dcb = &drm->vbios.dcb;
  	struct drm_connector *connector, *ct;
  	struct drm_encoder *encoder;
drivers/gpu/drm/nouveau/dispnv04/disp.h +1 -1
index 11a6663758ec..85ec0f534392 100644
@@ -176,7 +176,7 @@ static inline void
  nouveau_bios_run_init_table(struct drm_device *dev, u16 table,
  			    struct dcb_output *outp, int crtc)
  {
-	nvbios_init(&nvxx_bios(&nouveau_drm(dev)->client.device)->subdev, table,
+	nvbios_init(&nvxx_bios(nouveau_drm(dev))->subdev, table,
  		init.outp = outp;
  		init.head = crtc;
  	);
drivers/gpu/drm/nouveau/dispnv04/hw.c +4 -5
index f7d35657aa64..8b376f9c8746 100644
@@ -166,7 +166,7 @@ nouveau_hw_get_pllvals(struct drm_device *dev, enum nvbios_pll_type plltype,
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
  	struct nvif_object *device = &drm->client.device.object;
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
  	uint32_t reg1, pll1, pll2 = 0;
  	struct nvbios_pll pll_lim;
  	int ret;
@@ -258,9 +258,8 @@ nouveau_hw_fix_bad_vpll(struct drm_device *dev, int head)
  	 */
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvif_device *device = &drm->client.device;
-	struct nvkm_clk *clk = nvxx_clk(device);
-	struct nvkm_bios *bios = nvxx_bios(device);
+	struct nvkm_clk *clk = nvxx_clk(drm);
+	struct nvkm_bios *bios = nvxx_bios(drm);
  	struct nvbios_pll pll_lim;
  	struct nvkm_pll_vals pv;
  	enum nvbios_pll_type pll = head ? PLL_VPLL1 : PLL_VPLL0;
@@ -470,7 +469,7 @@ nv_load_state_ramdac(struct drm_device *dev, int head,
  		     struct nv04_mode_state *state)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_clk *clk = nvxx_clk(&drm->client.device);
+	struct nvkm_clk *clk = nvxx_clk(drm);
  	struct nv04_crtc_reg *regp = &state->crtc_reg[head];
  	uint32_t pllreg = head ? NV_RAMDAC_VPLL2 : NV_PRAMDAC_VPLL_COEFF;
  	int i;
drivers/gpu/drm/nouveau/dispnv04/tvnv04.c +2 -2
index de3ea731d6e6..d3014027a812 100644
@@ -53,7 +53,7 @@ static struct nvkm_i2c_bus_probe nv04_tv_encoder_info[] = {
  int nv04_tv_identify(struct drm_device *dev, int i2c_index)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, i2c_index);
  	if (bus) {
  		return nvkm_i2c_bus_probe(bus, "TV encoder",
@@ -205,7 +205,7 @@ nv04_tv_create(struct drm_connector *connector, struct dcb_output *entry)
  	struct drm_encoder *encoder;
  	struct drm_device *dev = connector->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, entry->i2c_index);
  	int type, ret;
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +3 -3
index 670c9739e5e1..c11f58033018 100644
@@ -47,7 +47,7 @@ static uint32_t nv42_tv_sample_load(struct drm_encoder *encoder)
  {
  	struct drm_device *dev = encoder->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
  	uint32_t testval, regoffset = nv04_dac_output_offset(encoder);
  	uint32_t gpio0, gpio1, fp_htotal, fp_hsync_start, fp_hsync_end,
  		fp_control, test_ctrl, dacclk, ctv_14, ctv_1c, ctv_6c;
@@ -131,7 +131,7 @@ static bool
  get_tv_detect_quirks(struct drm_device *dev, uint32_t *pin_mask)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
  	if (device->quirk && device->quirk->tv_pin_mask) {
  		*pin_mask = device->quirk->tv_pin_mask;
@@ -363,7 +363,7 @@ static void  nv17_tv_dpms(struct drm_encoder *encoder, int mode)
  {
  	struct drm_device *dev = encoder->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
  	struct nv17_tv_state *regs = &to_tv_enc(encoder)->state;
  	struct nv17_tv_norm_params *tv_norm = get_tv_norm(encoder);
drivers/gpu/drm/nouveau/dispnv50/disp.c +3 -3
index 42375f757d7c..80803346b620 100644
@@ -561,7 +561,7 @@ nv50_dac_create(struct nouveau_encoder *nv_encoder)
  {
  	struct drm_connector *connector = &nv_encoder->conn->base;
  	struct nouveau_drm *drm = nouveau_drm(connector->dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct nvkm_i2c_bus *bus;
  	struct drm_encoder *encoder;
  	struct dcb_output *dcbe = nv_encoder->dcb;
@@ -1884,7 +1884,7 @@ nv50_sor_create(struct nouveau_encoder *nv_encoder)
  	struct drm_connector *connector = &nv_encoder->conn->base;
  	struct nouveau_connector *nv_connector = nouveau_connector(connector);
  	struct nouveau_drm *drm = nouveau_drm(connector->dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct drm_encoder *encoder;
  	struct dcb_output *dcbe = nv_encoder->dcb;
  	struct nv50_disp *disp = nv50_disp(connector->dev);
@@ -2051,7 +2051,7 @@ nv50_pior_create(struct nouveau_encoder *nv_encoder)
  	struct drm_device *dev = connector->dev;
  	struct nouveau_drm *drm = nouveau_drm(dev);
  	struct nv50_disp *disp = nv50_disp(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
  	struct nvkm_i2c_bus *bus = NULL;
  	struct nvkm_i2c_aux *aux = NULL;
  	struct i2c_adapter *ddc;
drivers/gpu/drm/nouveau/include/nvif/device.h +0 -33
index fec76f4733a4..7877a2a79da9 100644
@@ -22,37 +22,4 @@ int  nvif_device_ctor(struct nvif_client *, const char *name, struct nvif_device
  void nvif_device_dtor(struct nvif_device *);
  int  nvif_device_map(struct nvif_device *);
  u64  nvif_device_time(struct nvif_device *);
-
-/*XXX*/
-#include <subdev/bios.h>
-#include <subdev/fb.h>
-#include <subdev/bar.h>
-#include <subdev/gpio.h>
-#include <subdev/clk.h>
-#include <subdev/i2c.h>
-#include <subdev/timer.h>
-#include <subdev/therm.h>
-#include <subdev/pci.h>
-
-#define nvxx_device(a) ({                                                      \
-	struct nvif_device *_device = (a);                                     \
-	struct {                                                               \
-		struct nvkm_object object;                                     \
-		struct nvkm_device *device;                                    \
-	} *_udevice = _device->object.priv;                                    \
-	_udevice->device;                                                      \
-})
-#define nvxx_bios(a) nvxx_device(a)->bios
-#define nvxx_fb(a) nvxx_device(a)->fb
-#define nvxx_gpio(a) nvxx_device(a)->gpio
-#define nvxx_clk(a) nvxx_device(a)->clk
-#define nvxx_i2c(a) nvxx_device(a)->i2c
-#define nvxx_iccsense(a) nvxx_device(a)->iccsense
-#define nvxx_therm(a) nvxx_device(a)->therm
-#define nvxx_volt(a) nvxx_device(a)->volt
-
-#include <engine/fifo.h>
-#include <engine/gr.h>
-
-#define nvxx_gr(a) nvxx_device(a)->gr
  #endif
drivers/gpu/drm/nouveau/include/nvif/object.h +1 -1
index 8d205b6af46a..3534b241cad9 100644
@@ -15,7 +15,7 @@ struct nvif_object {
  	const char *name;
  	u32 handle;
  	s32 oclass;
-	void *priv; /*XXX: hack */
+	void *priv;
  	struct {
  		void __iomem *ptr;
  		u64 size;
drivers/gpu/drm/nouveau/nouveau_abi16.c +2 -2
index 704977530b6b..5d74c36a4ca5 100644
@@ -240,8 +240,8 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
  	struct nouveau_cli *cli = nouveau_cli(file_priv);
  	struct nouveau_drm *drm = nouveau_drm(dev);
  	struct nvif_device *device = &drm->client.device;
-	struct nvkm_device *nvkm_device = nvxx_device(&drm->client.device);
-	struct nvkm_gr *gr = nvxx_gr(device);
+	struct nvkm_device *nvkm_device = nvxx_device(drm);
+	struct nvkm_gr *gr = nvxx_gr(drm);
  	struct drm_nouveau_getparam *getparam = data;
  	struct pci_dev *pdev = to_pci_dev(dev->dev);
drivers/gpu/drm/nouveau/nouveau_bios.c +2 -2
index 79cfab53f80e..a8da6492efd3 100644
@@ -2020,7 +2020,7 @@ uint8_t *nouveau_bios_embedded_edid(struct drm_device *dev)
  static bool NVInitVBIOS(struct drm_device *dev)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
  	struct nvbios *legacy = &drm->vbios;
  	memset(legacy, 0, sizeof(struct nvbios));
@@ -2091,7 +2091,7 @@ nouveau_bios_init(struct drm_device *dev)
  	/* only relevant for PCI devices */
  	if (!dev_is_pci(dev->dev) ||
-	    nvkm_gsp_rm(nvxx_device(&drm->client.device)->gsp))
+	    nvkm_gsp_rm(nvxx_device(drm)->gsp))
  		return 0;
  	if (!NVInitVBIOS(dev))
drivers/gpu/drm/nouveau/nouveau_bios.h +1 -0
index 18eb061ccafb..62b5f5889041 100644
@@ -48,6 +48,7 @@ struct bit_entry {
  int bit_table(struct drm_device *, u8 id, struct bit_entry *);
+#include <subdev/bios.h>
  #include <subdev/bios/dcb.h>
  #include <subdev/bios/conn.h>
drivers/gpu/drm/nouveau/nouveau_bo.c +4 -4
index 0712d0b15170..6631d85ea749 100644
@@ -58,7 +58,7 @@ nv10_bo_update_tile_region(struct drm_device *dev, struct nouveau_drm_tile *reg,
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
  	int i = reg - drm->tile.reg;
-	struct nvkm_fb *fb = nvxx_fb(&drm->client.device);
+	struct nvkm_fb *fb = nvxx_fb(drm);
  	struct nvkm_fb_tile *tile = &fb->tile.region[i];
  	nouveau_fence_unref(&reg->fence);
@@ -109,7 +109,7 @@ nv10_bo_set_tiling(struct drm_device *dev, u32 addr,
  		   u32 size, u32 pitch, u32 zeta)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_fb *fb = nvxx_fb(&drm->client.device);
+	struct nvkm_fb *fb = nvxx_fb(drm);
  	struct nouveau_drm_tile *tile, *found = NULL;
  	int i;
@@ -1171,7 +1171,7 @@ static int
  nouveau_ttm_io_mem_reserve(struct ttm_device *bdev, struct ttm_resource *reg)
  {
  	struct nouveau_drm *drm = nouveau_bdev(bdev);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
  	struct nouveau_mem *mem = nouveau_mem(reg);
  	struct nvif_mmu *mmu = &drm->client.mmu;
  	int ret;
@@ -1291,7 +1291,7 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
  {
  	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
  	struct nouveau_bo *nvbo = nouveau_bo(bo);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
  	u32 mappable = device->func->resource_size(device, 1) >> PAGE_SHIFT;
  	int i, ret;
drivers/gpu/drm/nouveau/nouveau_chan.c +1 -2
index ce04c40e6f8f..0105d4704c3a 100644
@@ -218,8 +218,7 @@ nouveau_channel_prep(struct nouveau_drm *drm, struct nvif_device *device,
  			 */
  			args.target = NV_DMA_V0_TARGET_PCI;
  			args.access = NV_DMA_V0_ACCESS_RDWR;
-			args.start = nvxx_device(device)->func->
-				resource_addr(nvxx_device(device), 1);
+			args.start = nvxx_device(drm)->func->resource_addr(nvxx_device(drm), 1);
  			args.limit = args.start + device->info.ram_user - 1;
  		} else {
  			args.target = NV_DMA_V0_TARGET_VRAM;
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -2
index 936eb32fc8c4..5ff116bcbabf 100644
@@ -424,8 +424,7 @@ nouveau_accel_gr_init(struct nouveau_drm *drm)
  	 * any GPU where it's possible we'll end up using M2MF for BO moves.
  	 */
  	if (device->info.family < NV_DEVICE_INFO_V0_FERMI) {
-		ret = nvkm_gpuobj_new(nvxx_device(device), 32, 0, false, NULL,
-				      &drm->notify);
+		ret = nvkm_gpuobj_new(nvxx_device(drm), 32, 0, false, NULL, &drm->notify);
  		if (ret) {
  			NV_ERROR(drm, "failed to allocate notifier, %d\n", ret);
  			nouveau_accel_gr_fini(drm);
Quoted 8 lines

drivers/gpu/drm/nouveau/nouveau_drv.h void nouveau_drm_device_remove(struct nouveau_drm *); · line 361

Quoted 7 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
index 80ffe15ba76b..a9e0a63c772e 100644
@@ -360,4 +360,31 @@ void nouveau_drm_device_remove(struct nouveau_drm *);
  extern int nouveau_modeset;
+/*XXX*/

What is the message of this here?

Quoted 1 line

This is moved over from its old location.

Just to clarify, because I think it came across this way in a few other patches. I try to avoid putting a question, when I actually look for an action. So, when I ask a question, no need to assume that I want something changed. :)

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +15 -0
+#include <subdev/bios.h>
+#include <subdev/fb.h>
+#include <subdev/gpio.h>
+#include <subdev/clk.h>
+#include <subdev/i2c.h>
+#include <subdev/timer.h>
+#include <subdev/therm.h>
+
+static inline struct nvkm_device *
+nvxx_device(struct nouveau_drm *drm)
+{
+	return drm->nvkm;
+}
+
+#define nvxx_bios(a) nvxx_device(a)->bios
Quoted 8 lines

drivers/gpu/drm/nouveau/nouveau_drv.h void nouveau_drm_device_remove(struct nouveau_drm *); · line 385

Quoted 7 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +7 -0
+#define nvxx_fb(a) nvxx_device(a)->fb
+#define nvxx_gpio(a) nvxx_device(a)->gpio
+#define nvxx_clk(a) nvxx_device(a)->clk
+#define nvxx_i2c(a) nvxx_device(a)->i2c
+#define nvxx_iccsense(a) nvxx_device(a)->iccsense
+#define nvxx_therm(a) nvxx_device(a)->therm
+#define nvxx_volt(a) nvxx_device(a)->volt

Why the "nvxx" prefix? Why not just "nvkm"?

Quoted 3 lines

Because these aren't supposed to be used, and exist for the few locations that never got proper NVIF.  I've added info to the commit with some further explanation.

Thanks for adding it, looks good!

One question regarding that, you write:

"Outside of the current use, these should not be relied on, and proper interfaces implemented instead."

What would a "proper" interface for those offer us / improve? And if the answer is nothing, why do we consider using nvkm_ structures directly a hack?

Quoted 224 lines

I've updated the branch on gitlab for this, and your commit message nitpicks.

Quoted 219 lines
Quoted 219 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +4 -0
+
+#include <engine/gr.h>
+
+#define nvxx_gr(a) nvxx_device(a)->gr
  #endif
drivers/gpu/drm/nouveau/nouveau_hwmon.c +23 -23
index db30a4c2cd4d..5c07a9ee8b77 100644
@@ -52,7 +52,7 @@ nouveau_hwmon_temp1_auto_point1_temp(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	return sysfs_emit(buf, "%d\n",
  			  therm->attr_get(therm, NVKM_THERM_ATTR_THRS_FAN_BOOST) * 1000);
@@ -64,7 +64,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	long value;
  	if (kstrtol(buf, 10, &value))
@@ -85,7 +85,7 @@ nouveau_hwmon_temp1_auto_point1_temp_hyst(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	return sysfs_emit(buf, "%d\n",
  			  therm->attr_get(therm, NVKM_THERM_ATTR_THRS_FAN_BOOST_HYST) * 1000);
@@ -97,7 +97,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp_hyst(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	long value;
  	if (kstrtol(buf, 10, &value))
@@ -118,7 +118,7 @@ nouveau_hwmon_get_pwm1_max(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	int ret;
  	ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MAX_DUTY);
@@ -134,7 +134,7 @@ nouveau_hwmon_get_pwm1_min(struct device *d,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	int ret;
  	ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MIN_DUTY);
@@ -150,7 +150,7 @@ nouveau_hwmon_set_pwm1_min(struct device *d, struct device_attribute *a,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	long value;
  	int ret;
@@ -173,7 +173,7 @@ nouveau_hwmon_set_pwm1_max(struct device *d, struct device_attribute *a,
  {
  	struct drm_device *dev = dev_get_drvdata(d);
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	long value;
  	int ret;
@@ -247,7 +247,7 @@ static umode_t
  nouveau_power_is_visible(const void *data, u32 attr, int channel)
  {
  	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
  	if (!iccsense || !iccsense->data_valid || list_empty(&iccsense->rails))
  		return 0;
@@ -272,7 +272,7 @@ static umode_t
  nouveau_temp_is_visible(const void *data, u32 attr, int channel)
  {
  	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm) < 0)
  		return 0;
@@ -296,7 +296,7 @@ static umode_t
  nouveau_pwm_is_visible(const void *data, u32 attr, int channel)
  {
  	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	if (!therm || !therm->attr_get || !therm->fan_get ||
  	    therm->fan_get(therm) < 0)
@@ -315,7 +315,7 @@ static umode_t
  nouveau_input_is_visible(const void *data, u32 attr, int channel)
  {
  	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_volt *volt = nvxx_volt(drm);
  	if (!volt || nvkm_volt_get(volt) < 0)
  		return 0;
@@ -335,7 +335,7 @@ static umode_t
  nouveau_fan_is_visible(const void *data, u32 attr, int channel)
  {
  	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	if (!therm || !therm->attr_get || nvkm_therm_fan_sense(therm) < 0)
  		return 0;
@@ -367,7 +367,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	int ret;
  	if (!therm || !therm->attr_get)
@@ -416,7 +416,7 @@ nouveau_fan_read(struct device *dev, u32 attr, int channel, long *val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	if (!therm)
  		return -EOPNOTSUPP;
@@ -439,7 +439,7 @@ nouveau_in_read(struct device *dev, u32 attr, int channel, long *val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_volt *volt = nvxx_volt(drm);
  	int ret;
  	if (!volt)
@@ -470,7 +470,7 @@ nouveau_pwm_read(struct device *dev, u32 attr, int channel, long *val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	if (!therm || !therm->attr_get || !therm->fan_get)
  		return -EOPNOTSUPP;
@@ -496,7 +496,7 @@ nouveau_power_read(struct device *dev, u32 attr, int channel, long *val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
  	if (!iccsense)
  		return -EOPNOTSUPP;
@@ -525,7 +525,7 @@ nouveau_temp_write(struct device *dev, u32 attr, int channel, long val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	if (!therm || !therm->attr_set)
  		return -EOPNOTSUPP;
@@ -559,7 +559,7 @@ nouveau_pwm_write(struct device *dev, u32 attr, int channel, long val)
  {
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
  	if (!therm || !therm->attr_set)
  		return -EOPNOTSUPP;
@@ -664,9 +664,9 @@ nouveau_hwmon_init(struct drm_device *dev)
  {
  #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
+	struct nvkm_therm *therm = nvxx_therm(drm);
+	struct nvkm_volt *volt = nvxx_volt(drm);
  	const struct attribute_group *special_groups[N_ATTR_GROUPS];
  	struct nouveau_hwmon *hwmon;
  	struct device *hwmon_dev;
drivers/gpu/drm/nouveau/nouveau_led.c +1 -1
index 2c5e0628da12..ac950518a820 100644
@@ -78,7 +78,7 @@ int
  nouveau_led_init(struct drm_device *dev)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
  	struct dcb_gpio_func logo_led;
  	int ret;
drivers/gpu/drm/nouveau/nouveau_ttm.c +2 -2
index 486f39f31a38..53553819bcac 100644
@@ -261,7 +261,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
  int
  nouveau_ttm_init(struct nouveau_drm *drm)
  {
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
  	struct nvkm_pci *pci = device->pci;
  	struct nvif_mmu *mmu = &drm->client.mmu;
  	struct drm_device *dev = drm->dev;
@@ -348,7 +348,7 @@ nouveau_ttm_init(struct nouveau_drm *drm)
  void
  nouveau_ttm_fini(struct nouveau_drm *drm)
  {
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
  	nouveau_ttm_fini_vram(drm);
  	nouveau_ttm_fini_gtt(drm);
Signature · 1 line
2.45.1
author
#58 lore raw

Re: [PATCH v2 27/37] drm/nouveau: move nvxx_* definitions to nouveau_drv.h

Quoted 423 lines · Danilo Krummrich
Quoted 389 lines · Ben Skeggs
Quoted 379 lines · Danilo Krummrich
Quoted 378 lines · Ben Skeggs

These are some dodgy "convenience" macros for the DRM driver to peek into NVKM state. They're still used in a few places, but don't belong in nvif/device.h in any case.

Move them to nouveau_drv.h, and modify callers to pass a nouveau_drm instead of an nvif_device.

v2:
- use drm->nvkm pointer for nvxx_*() macros, removing some void*

---
   drivers/gpu/drm/nouveau/dispnv04/crtc.c       |  4 +-
   drivers/gpu/drm/nouveau/dispnv04/dac.c        |  2 +-
   drivers/gpu/drm/nouveau/dispnv04/dfp.c        |  2 +-
   drivers/gpu/drm/nouveau/dispnv04/disp.c       |  2 +-
   drivers/gpu/drm/nouveau/dispnv04/disp.h       |  2 +-
   drivers/gpu/drm/nouveau/dispnv04/hw.c         |  9 ++--
   drivers/gpu/drm/nouveau/dispnv04/tvnv04.c     |  4 +-
   drivers/gpu/drm/nouveau/dispnv04/tvnv17.c     |  6 +--
   drivers/gpu/drm/nouveau/dispnv50/disp.c       |  6 +--
   drivers/gpu/drm/nouveau/include/nvif/device.h | 33 -------------
   drivers/gpu/drm/nouveau/include/nvif/object.h |  2 +-
   drivers/gpu/drm/nouveau/nouveau_abi16.c       |  4 +-
   drivers/gpu/drm/nouveau/nouveau_bios.c        |  4 +-
   drivers/gpu/drm/nouveau/nouveau_bios.h        |  1 +
   drivers/gpu/drm/nouveau/nouveau_bo.c          |  8 ++--
   drivers/gpu/drm/nouveau/nouveau_chan.c        |  3 +-
   drivers/gpu/drm/nouveau/nouveau_drm.c         |  3 +-
   drivers/gpu/drm/nouveau/nouveau_drv.h         | 27 +++++++++++
   drivers/gpu/drm/nouveau/nouveau_hwmon.c       | 46 +++++++++----------
   drivers/gpu/drm/nouveau/nouveau_led.c         |  2 +-
   drivers/gpu/drm/nouveau/nouveau_ttm.c         |  4 +-
   21 files changed, 83 insertions(+), 91 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/crtc.c +2 -2
index 4310ad71870b..e5067d5a4801 100644
@@ -118,8 +118,8 @@ static void nv_crtc_calc_state_ext(struct drm_crtc *crtc, struct drm_display_mod
   {
   	struct drm_device *dev = crtc->dev;
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
-	struct nvkm_clk *clk = nvxx_clk(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
+	struct nvkm_clk *clk = nvxx_clk(drm);
   	struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
   	struct nv04_mode_state *state = &nv04_display(dev)->mode_reg;
   	struct nv04_crtc_reg *regp = &state->crtc_reg[nv_crtc->index];
drivers/gpu/drm/nouveau/dispnv04/dac.c +1 -1
index d6b8e0cce2ac..2e12bf136607 100644
@@ -237,7 +237,7 @@ uint32_t nv17_dac_sample_load(struct drm_encoder *encoder)
   	struct drm_device *dev = encoder->dev;
   	struct nouveau_drm *drm = nouveau_drm(dev);
   	struct nvif_object *device = &nouveau_drm(dev)->client.device.object;
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
   	struct dcb_output *dcb = nouveau_encoder(encoder)->dcb;
   	uint32_t sample, testval, regoffset = nv04_dac_output_offset(encoder);
   	uint32_t saved_powerctrl_2 = 0, saved_powerctrl_4 = 0, saved_routput,
drivers/gpu/drm/nouveau/dispnv04/dfp.c +1 -1
index d5b129dc623b..504c421aa176 100644
@@ -626,7 +626,7 @@ static void nv04_tmds_slave_init(struct drm_encoder *encoder)
   	struct drm_device *dev = encoder->dev;
   	struct dcb_output *dcb = nouveau_encoder(encoder)->dcb;
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
   	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_PRI);
   	struct nvkm_i2c_bus_probe info[] = {
   		{
drivers/gpu/drm/nouveau/dispnv04/disp.c +1 -1
index e8b27bb135e7..e563a160571a 100644
@@ -211,7 +211,7 @@ int
   nv04_display_create(struct drm_device *dev)
   {
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
   	struct dcb_table *dcb = &drm->vbios.dcb;
   	struct drm_connector *connector, *ct;
   	struct drm_encoder *encoder;
drivers/gpu/drm/nouveau/dispnv04/disp.h +1 -1
index 11a6663758ec..85ec0f534392 100644
@@ -176,7 +176,7 @@ static inline void
   nouveau_bios_run_init_table(struct drm_device *dev, u16 table,
   			    struct dcb_output *outp, int crtc)
   {
-	nvbios_init(&nvxx_bios(&nouveau_drm(dev)->client.device)->subdev, table,
+	nvbios_init(&nvxx_bios(nouveau_drm(dev))->subdev, table,
   		init.outp = outp;
   		init.head = crtc;
   	);
drivers/gpu/drm/nouveau/dispnv04/hw.c +4 -5
index f7d35657aa64..8b376f9c8746 100644
@@ -166,7 +166,7 @@ nouveau_hw_get_pllvals(struct drm_device *dev, enum nvbios_pll_type plltype,
   {
   	struct nouveau_drm *drm = nouveau_drm(dev);
   	struct nvif_object *device = &drm->client.device.object;
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
   	uint32_t reg1, pll1, pll2 = 0;
   	struct nvbios_pll pll_lim;
   	int ret;
@@ -258,9 +258,8 @@ nouveau_hw_fix_bad_vpll(struct drm_device *dev, int head)
   	 */
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvif_device *device = &drm->client.device;
-	struct nvkm_clk *clk = nvxx_clk(device);
-	struct nvkm_bios *bios = nvxx_bios(device);
+	struct nvkm_clk *clk = nvxx_clk(drm);
+	struct nvkm_bios *bios = nvxx_bios(drm);
   	struct nvbios_pll pll_lim;
   	struct nvkm_pll_vals pv;
   	enum nvbios_pll_type pll = head ? PLL_VPLL1 : PLL_VPLL0;
@@ -470,7 +469,7 @@ nv_load_state_ramdac(struct drm_device *dev, int head,
   		     struct nv04_mode_state *state)
   {
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_clk *clk = nvxx_clk(&drm->client.device);
+	struct nvkm_clk *clk = nvxx_clk(drm);
   	struct nv04_crtc_reg *regp = &state->crtc_reg[head];
   	uint32_t pllreg = head ? NV_RAMDAC_VPLL2 : NV_PRAMDAC_VPLL_COEFF;
   	int i;
drivers/gpu/drm/nouveau/dispnv04/tvnv04.c +2 -2
index de3ea731d6e6..d3014027a812 100644
@@ -53,7 +53,7 @@ static struct nvkm_i2c_bus_probe nv04_tv_encoder_info[] = {
   int nv04_tv_identify(struct drm_device *dev, int i2c_index)
   {
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
   	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, i2c_index);
   	if (bus) {
   		return nvkm_i2c_bus_probe(bus, "TV encoder",
@@ -205,7 +205,7 @@ nv04_tv_create(struct drm_connector *connector, struct dcb_output *entry)
   	struct drm_encoder *encoder;
   	struct drm_device *dev = connector->dev;
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
   	struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, entry->i2c_index);
   	int type, ret;
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +3 -3
index 670c9739e5e1..c11f58033018 100644
@@ -47,7 +47,7 @@ static uint32_t nv42_tv_sample_load(struct drm_encoder *encoder)
   {
   	struct drm_device *dev = encoder->dev;
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
   	uint32_t testval, regoffset = nv04_dac_output_offset(encoder);
   	uint32_t gpio0, gpio1, fp_htotal, fp_hsync_start, fp_hsync_end,
   		fp_control, test_ctrl, dacclk, ctv_14, ctv_1c, ctv_6c;
@@ -131,7 +131,7 @@ static bool
   get_tv_detect_quirks(struct drm_device *dev, uint32_t *pin_mask)
   {
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
   	if (device->quirk && device->quirk->tv_pin_mask) {
   		*pin_mask = device->quirk->tv_pin_mask;
@@ -363,7 +363,7 @@ static void  nv17_tv_dpms(struct drm_encoder *encoder, int mode)
   {
   	struct drm_device *dev = encoder->dev;
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
   	struct nv17_tv_state *regs = &to_tv_enc(encoder)->state;
   	struct nv17_tv_norm_params *tv_norm = get_tv_norm(encoder);
drivers/gpu/drm/nouveau/dispnv50/disp.c +3 -3
index 42375f757d7c..80803346b620 100644
@@ -561,7 +561,7 @@ nv50_dac_create(struct nouveau_encoder *nv_encoder)
   {
   	struct drm_connector *connector = &nv_encoder->conn->base;
   	struct nouveau_drm *drm = nouveau_drm(connector->dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
   	struct nvkm_i2c_bus *bus;
   	struct drm_encoder *encoder;
   	struct dcb_output *dcbe = nv_encoder->dcb;
@@ -1884,7 +1884,7 @@ nv50_sor_create(struct nouveau_encoder *nv_encoder)
   	struct drm_connector *connector = &nv_encoder->conn->base;
   	struct nouveau_connector *nv_connector = nouveau_connector(connector);
   	struct nouveau_drm *drm = nouveau_drm(connector->dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
   	struct drm_encoder *encoder;
   	struct dcb_output *dcbe = nv_encoder->dcb;
   	struct nv50_disp *disp = nv50_disp(connector->dev);
@@ -2051,7 +2051,7 @@ nv50_pior_create(struct nouveau_encoder *nv_encoder)
   	struct drm_device *dev = connector->dev;
   	struct nouveau_drm *drm = nouveau_drm(dev);
   	struct nv50_disp *disp = nv50_disp(dev);
-	struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
+	struct nvkm_i2c *i2c = nvxx_i2c(drm);
   	struct nvkm_i2c_bus *bus = NULL;
   	struct nvkm_i2c_aux *aux = NULL;
   	struct i2c_adapter *ddc;
drivers/gpu/drm/nouveau/include/nvif/device.h +0 -33
index fec76f4733a4..7877a2a79da9 100644
@@ -22,37 +22,4 @@ int  nvif_device_ctor(struct nvif_client *, const char *name, struct nvif_device
   void nvif_device_dtor(struct nvif_device *);
   int  nvif_device_map(struct nvif_device *);
   u64  nvif_device_time(struct nvif_device *);
-
-/*XXX*/
-#include <subdev/bios.h>
-#include <subdev/fb.h>
-#include <subdev/bar.h>
-#include <subdev/gpio.h>
-#include <subdev/clk.h>
-#include <subdev/i2c.h>
-#include <subdev/timer.h>
-#include <subdev/therm.h>
-#include <subdev/pci.h>
-
-#define nvxx_device(a) ({                                                      \
-	struct nvif_device *_device = (a);                                     \
-	struct {                                                               \
-		struct nvkm_object object;                                     \
-		struct nvkm_device *device;                                    \
-	} *_udevice = _device->object.priv;                                    \
-	_udevice->device;                                                      \
-})
-#define nvxx_bios(a) nvxx_device(a)->bios
-#define nvxx_fb(a) nvxx_device(a)->fb
-#define nvxx_gpio(a) nvxx_device(a)->gpio
-#define nvxx_clk(a) nvxx_device(a)->clk
-#define nvxx_i2c(a) nvxx_device(a)->i2c
-#define nvxx_iccsense(a) nvxx_device(a)->iccsense
-#define nvxx_therm(a) nvxx_device(a)->therm
-#define nvxx_volt(a) nvxx_device(a)->volt
-
-#include <engine/fifo.h>
-#include <engine/gr.h>
-
-#define nvxx_gr(a) nvxx_device(a)->gr
   #endif
drivers/gpu/drm/nouveau/include/nvif/object.h +1 -1
index 8d205b6af46a..3534b241cad9 100644
@@ -15,7 +15,7 @@ struct nvif_object {
   	const char *name;
   	u32 handle;
   	s32 oclass;
-	void *priv; /*XXX: hack */
+	void *priv;
   	struct {
   		void __iomem *ptr;
   		u64 size;
drivers/gpu/drm/nouveau/nouveau_abi16.c +2 -2
index 704977530b6b..5d74c36a4ca5 100644
@@ -240,8 +240,8 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
   	struct nouveau_cli *cli = nouveau_cli(file_priv);
   	struct nouveau_drm *drm = nouveau_drm(dev);
   	struct nvif_device *device = &drm->client.device;
-	struct nvkm_device *nvkm_device = nvxx_device(&drm->client.device);
-	struct nvkm_gr *gr = nvxx_gr(device);
+	struct nvkm_device *nvkm_device = nvxx_device(drm);
+	struct nvkm_gr *gr = nvxx_gr(drm);
   	struct drm_nouveau_getparam *getparam = data;
   	struct pci_dev *pdev = to_pci_dev(dev->dev);
drivers/gpu/drm/nouveau/nouveau_bios.c +2 -2
index 79cfab53f80e..a8da6492efd3 100644
@@ -2020,7 +2020,7 @@ uint8_t *nouveau_bios_embedded_edid(struct drm_device *dev)
   static bool NVInitVBIOS(struct drm_device *dev)
   {
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
+	struct nvkm_bios *bios = nvxx_bios(drm);
   	struct nvbios *legacy = &drm->vbios;
   	memset(legacy, 0, sizeof(struct nvbios));
@@ -2091,7 +2091,7 @@ nouveau_bios_init(struct drm_device *dev)
   	/* only relevant for PCI devices */
   	if (!dev_is_pci(dev->dev) ||
-	    nvkm_gsp_rm(nvxx_device(&drm->client.device)->gsp))
+	    nvkm_gsp_rm(nvxx_device(drm)->gsp))
   		return 0;
   	if (!NVInitVBIOS(dev))
drivers/gpu/drm/nouveau/nouveau_bios.h +1 -0
index 18eb061ccafb..62b5f5889041 100644
@@ -48,6 +48,7 @@ struct bit_entry {
   int bit_table(struct drm_device *, u8 id, struct bit_entry *);
+#include <subdev/bios.h>
   #include <subdev/bios/dcb.h>
   #include <subdev/bios/conn.h>
drivers/gpu/drm/nouveau/nouveau_bo.c +4 -4
index 0712d0b15170..6631d85ea749 100644
@@ -58,7 +58,7 @@ nv10_bo_update_tile_region(struct drm_device *dev, struct nouveau_drm_tile *reg,
   {
   	struct nouveau_drm *drm = nouveau_drm(dev);
   	int i = reg - drm->tile.reg;
-	struct nvkm_fb *fb = nvxx_fb(&drm->client.device);
+	struct nvkm_fb *fb = nvxx_fb(drm);
   	struct nvkm_fb_tile *tile = &fb->tile.region[i];
   	nouveau_fence_unref(&reg->fence);
@@ -109,7 +109,7 @@ nv10_bo_set_tiling(struct drm_device *dev, u32 addr,
   		   u32 size, u32 pitch, u32 zeta)
   {
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_fb *fb = nvxx_fb(&drm->client.device);
+	struct nvkm_fb *fb = nvxx_fb(drm);
   	struct nouveau_drm_tile *tile, *found = NULL;
   	int i;
@@ -1171,7 +1171,7 @@ static int
   nouveau_ttm_io_mem_reserve(struct ttm_device *bdev, struct ttm_resource *reg)
   {
   	struct nouveau_drm *drm = nouveau_bdev(bdev);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
   	struct nouveau_mem *mem = nouveau_mem(reg);
   	struct nvif_mmu *mmu = &drm->client.mmu;
   	int ret;
@@ -1291,7 +1291,7 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
   {
   	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
   	struct nouveau_bo *nvbo = nouveau_bo(bo);
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
   	u32 mappable = device->func->resource_size(device, 1) >> PAGE_SHIFT;
   	int i, ret;
drivers/gpu/drm/nouveau/nouveau_chan.c +1 -2
index ce04c40e6f8f..0105d4704c3a 100644
@@ -218,8 +218,7 @@ nouveau_channel_prep(struct nouveau_drm *drm, struct nvif_device *device,
   			 */
   			args.target = NV_DMA_V0_TARGET_PCI;
   			args.access = NV_DMA_V0_ACCESS_RDWR;
-			args.start = nvxx_device(device)->func->
-				resource_addr(nvxx_device(device), 1);
+			args.start = nvxx_device(drm)->func->resource_addr(nvxx_device(drm), 1);
   			args.limit = args.start + device->info.ram_user - 1;
   		} else {
   			args.target = NV_DMA_V0_TARGET_VRAM;
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -2
index 936eb32fc8c4..5ff116bcbabf 100644
@@ -424,8 +424,7 @@ nouveau_accel_gr_init(struct nouveau_drm *drm)
   	 * any GPU where it's possible we'll end up using M2MF for BO moves.
   	 */
   	if (device->info.family < NV_DEVICE_INFO_V0_FERMI) {
-		ret = nvkm_gpuobj_new(nvxx_device(device), 32, 0, false, NULL,
-				      &drm->notify);
+		ret = nvkm_gpuobj_new(nvxx_device(drm), 32, 0, false, NULL, &drm->notify);
   		if (ret) {
   			NV_ERROR(drm, "failed to allocate notifier, %d\n", ret);
   			nouveau_accel_gr_fini(drm);
Quoted 8 lines

drivers/gpu/drm/nouveau/nouveau_drv.h void nouveau_drm_device_remove(struct nouveau_drm *); · line 361

Quoted 7 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
index 80ffe15ba76b..a9e0a63c772e 100644
@@ -360,4 +360,31 @@ void nouveau_drm_device_remove(struct nouveau_drm *);
   extern int nouveau_modeset;
+/*XXX*/

What is the message of this here?

Quoted 1 line

This is moved over from its old location.

Just to clarify, because I think it came across this way in a few other patches. I try to avoid putting a question, when I actually look for an action. So, when I ask a question, no need to assume that I want something changed. :)

Quoted 23 lines
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +15 -0
+#include <subdev/bios.h>
+#include <subdev/fb.h>
+#include <subdev/gpio.h>
+#include <subdev/clk.h>
+#include <subdev/i2c.h>
+#include <subdev/timer.h>
+#include <subdev/therm.h>
+
+static inline struct nvkm_device *
+nvxx_device(struct nouveau_drm *drm)
+{
+	return drm->nvkm;
+}
+
+#define nvxx_bios(a) nvxx_device(a)->bios
Quoted 8 lines

drivers/gpu/drm/nouveau/nouveau_drv.h void nouveau_drm_device_remove(struct nouveau_drm *); · line 385

Quoted 7 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +7 -0
+#define nvxx_fb(a) nvxx_device(a)->fb
+#define nvxx_gpio(a) nvxx_device(a)->gpio
+#define nvxx_clk(a) nvxx_device(a)->clk
+#define nvxx_i2c(a) nvxx_device(a)->i2c
+#define nvxx_iccsense(a) nvxx_device(a)->iccsense
+#define nvxx_therm(a) nvxx_device(a)->therm
+#define nvxx_volt(a) nvxx_device(a)->volt

Why the "nvxx" prefix? Why not just "nvkm"?

Quoted 3 lines

Because these aren't supposed to be used, and exist for the few locations that never got proper NVIF.  I've added info to the commit with some further explanation.

Thanks for adding it, looks good!

Quoted 7 lines

One question regarding that, you write:

"Outside of the current use, these should not be relied on, and proper interfaces implemented instead."

What would a "proper" interface for those offer us / improve? And if the answer is nothing, why do we consider using nvkm_ structures directly a hack?

I believe I answered this in the paragraph after the one you quoted.  I did modify slightly and mention NVIF, instead of "proper interfaces" though.

Quoted 222 lines
Quoted 222 lines

I've updated the branch on gitlab for this, and your commit message nitpicks.

Quoted 218 lines
Quoted 218 lines
drivers/gpu/drm/nouveau/nouveau_drv.h +4 -0
+
+#include <engine/gr.h>
+
+#define nvxx_gr(a) nvxx_device(a)->gr
   #endif
drivers/gpu/drm/nouveau/nouveau_hwmon.c +23 -23
index db30a4c2cd4d..5c07a9ee8b77 100644
@@ -52,7 +52,7 @@ nouveau_hwmon_temp1_auto_point1_temp(struct device *d,
   {
   	struct drm_device *dev = dev_get_drvdata(d);
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	return sysfs_emit(buf, "%d\n",
   			  therm->attr_get(therm, NVKM_THERM_ATTR_THRS_FAN_BOOST) * 1000);
@@ -64,7 +64,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp(struct device *d,
   {
   	struct drm_device *dev = dev_get_drvdata(d);
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	long value;
   	if (kstrtol(buf, 10, &value))
@@ -85,7 +85,7 @@ nouveau_hwmon_temp1_auto_point1_temp_hyst(struct device *d,
   {
   	struct drm_device *dev = dev_get_drvdata(d);
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	return sysfs_emit(buf, "%d\n",
   			  therm->attr_get(therm, NVKM_THERM_ATTR_THRS_FAN_BOOST_HYST) * 1000);
@@ -97,7 +97,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp_hyst(struct device *d,
   {
   	struct drm_device *dev = dev_get_drvdata(d);
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	long value;
   	if (kstrtol(buf, 10, &value))
@@ -118,7 +118,7 @@ nouveau_hwmon_get_pwm1_max(struct device *d,
   {
   	struct drm_device *dev = dev_get_drvdata(d);
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	int ret;
   	ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MAX_DUTY);
@@ -134,7 +134,7 @@ nouveau_hwmon_get_pwm1_min(struct device *d,
   {
   	struct drm_device *dev = dev_get_drvdata(d);
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	int ret;
   	ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MIN_DUTY);
@@ -150,7 +150,7 @@ nouveau_hwmon_set_pwm1_min(struct device *d, struct device_attribute *a,
   {
   	struct drm_device *dev = dev_get_drvdata(d);
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	long value;
   	int ret;
@@ -173,7 +173,7 @@ nouveau_hwmon_set_pwm1_max(struct device *d, struct device_attribute *a,
   {
   	struct drm_device *dev = dev_get_drvdata(d);
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	long value;
   	int ret;
@@ -247,7 +247,7 @@ static umode_t
   nouveau_power_is_visible(const void *data, u32 attr, int channel)
   {
   	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
   	if (!iccsense || !iccsense->data_valid || list_empty(&iccsense->rails))
   		return 0;
@@ -272,7 +272,7 @@ static umode_t
   nouveau_temp_is_visible(const void *data, u32 attr, int channel)
   {
   	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm) < 0)
   		return 0;
@@ -296,7 +296,7 @@ static umode_t
   nouveau_pwm_is_visible(const void *data, u32 attr, int channel)
   {
   	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	if (!therm || !therm->attr_get || !therm->fan_get ||
   	    therm->fan_get(therm) < 0)
@@ -315,7 +315,7 @@ static umode_t
   nouveau_input_is_visible(const void *data, u32 attr, int channel)
   {
   	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_volt *volt = nvxx_volt(drm);
   	if (!volt || nvkm_volt_get(volt) < 0)
   		return 0;
@@ -335,7 +335,7 @@ static umode_t
   nouveau_fan_is_visible(const void *data, u32 attr, int channel)
   {
   	struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	if (!therm || !therm->attr_get || nvkm_therm_fan_sense(therm) < 0)
   		return 0;
@@ -367,7 +367,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val)
   {
   	struct drm_device *drm_dev = dev_get_drvdata(dev);
   	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	int ret;
   	if (!therm || !therm->attr_get)
@@ -416,7 +416,7 @@ nouveau_fan_read(struct device *dev, u32 attr, int channel, long *val)
   {
   	struct drm_device *drm_dev = dev_get_drvdata(dev);
   	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	if (!therm)
   		return -EOPNOTSUPP;
@@ -439,7 +439,7 @@ nouveau_in_read(struct device *dev, u32 attr, int channel, long *val)
   {
   	struct drm_device *drm_dev = dev_get_drvdata(dev);
   	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_volt *volt = nvxx_volt(drm);
   	int ret;
   	if (!volt)
@@ -470,7 +470,7 @@ nouveau_pwm_read(struct device *dev, u32 attr, int channel, long *val)
   {
   	struct drm_device *drm_dev = dev_get_drvdata(dev);
   	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	if (!therm || !therm->attr_get || !therm->fan_get)
   		return -EOPNOTSUPP;
@@ -496,7 +496,7 @@ nouveau_power_read(struct device *dev, u32 attr, int channel, long *val)
   {
   	struct drm_device *drm_dev = dev_get_drvdata(dev);
   	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
   	if (!iccsense)
   		return -EOPNOTSUPP;
@@ -525,7 +525,7 @@ nouveau_temp_write(struct device *dev, u32 attr, int channel, long val)
   {
   	struct drm_device *drm_dev = dev_get_drvdata(dev);
   	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	if (!therm || !therm->attr_set)
   		return -EOPNOTSUPP;
@@ -559,7 +559,7 @@ nouveau_pwm_write(struct device *dev, u32 attr, int channel, long val)
   {
   	struct drm_device *drm_dev = dev_get_drvdata(dev);
   	struct nouveau_drm *drm = nouveau_drm(drm_dev);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
+	struct nvkm_therm *therm = nvxx_therm(drm);
   	if (!therm || !therm->attr_set)
   		return -EOPNOTSUPP;
@@ -664,9 +664,9 @@ nouveau_hwmon_init(struct drm_device *dev)
   {
   #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
-	struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
-	struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(drm);
+	struct nvkm_therm *therm = nvxx_therm(drm);
+	struct nvkm_volt *volt = nvxx_volt(drm);
   	const struct attribute_group *special_groups[N_ATTR_GROUPS];
   	struct nouveau_hwmon *hwmon;
   	struct device *hwmon_dev;
drivers/gpu/drm/nouveau/nouveau_led.c +1 -1
index 2c5e0628da12..ac950518a820 100644
@@ -78,7 +78,7 @@ int
   nouveau_led_init(struct drm_device *dev)
   {
   	struct nouveau_drm *drm = nouveau_drm(dev);
-	struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
+	struct nvkm_gpio *gpio = nvxx_gpio(drm);
   	struct dcb_gpio_func logo_led;
   	int ret;
drivers/gpu/drm/nouveau/nouveau_ttm.c +2 -2
index 486f39f31a38..53553819bcac 100644
@@ -261,7 +261,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
   int
   nouveau_ttm_init(struct nouveau_drm *drm)
   {
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
   	struct nvkm_pci *pci = device->pci;
   	struct nvif_mmu *mmu = &drm->client.mmu;
   	struct drm_device *dev = drm->dev;
@@ -348,7 +348,7 @@ nouveau_ttm_init(struct nouveau_drm *drm)
   void
   nouveau_ttm_fini(struct nouveau_drm *drm)
   {
-	struct nvkm_device *device = nvxx_device(&drm->client.device);
+	struct nvkm_device *device = nvxx_device(drm);
   	nouveau_ttm_fini_vram(drm);
   	nouveau_ttm_fini_gtt(drm);
Signature · 1 line
2.45.1
author
#59 lore raw

PATCH v2 28/37 drm/nouveau: add nvif_mmu to nouveau_drm

In reply to Ben Skeggs

This allocates a new nvif_mmu in nouveau_drm, and uses it for TTM backend memory allocations instead of nouveau_drm.master.mmu, which will be removed in a later commit.

---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 35 ++++++++++++++++-----------
 drivers/gpu/drm/nouveau/nouveau_drv.h |  1 +
 drivers/gpu/drm/nouveau/nouveau_mem.c | 12 ++++-----
 3 files changed, 28 insertions(+), 20 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +21 -14
index 5ff116bcbabf..07748cfab233 100644
@@ -227,13 +227,6 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 		{}
 	};
 	static const struct nvif_mclass
-	mmus[] = {
-		{ NVIF_CLASS_MMU_GF100, -1 },
-		{ NVIF_CLASS_MMU_NV50 , -1 },
-		{ NVIF_CLASS_MMU_NV04 , -1 },
-		{}
-	};
-	static const struct nvif_mclass
 	vmms[] = {
 		{ NVIF_CLASS_VMM_GP100, -1 },
 		{ NVIF_CLASS_VMM_GM200, -1 },
@@ -270,13 +263,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 
 	cli->device.object.map.ptr = drm->device.object.map.ptr;
 
-	ret = nvif_mclass(&cli->device.object, mmus);
-	if (ret < 0) {
-		NV_PRINTK(err, cli, "No supported MMU class\n");
-		goto done;
-	}
-
-	ret = nvif_mmu_ctor(&cli->device.object, "drmMmu", mmus[ret].oclass,
+	ret = nvif_mmu_ctor(&cli->device.object, "drmMmu", drm->mmu.object.oclass,
 			    &cli->mmu);
 	if (ret) {
 		NV_PRINTK(err, cli, "MMU allocation failed: %d\n", ret);
@@ -717,6 +704,7 @@ nouveau_drm_device_del(struct nouveau_drm *drm)
 	if (drm->dev)
 		drm_dev_put(drm->dev);
 
+	nvif_mmu_dtor(&drm->mmu);
 	nvif_device_dtor(&drm->device);
 	nvif_client_dtor(&drm->master.base);
 	nvif_parent_dtor(&drm->parent);
@@ -728,6 +716,13 @@ static struct nouveau_drm *
 nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,
 		       struct nvkm_device *device)
 {
+	static const struct nvif_mclass
+	mmus[] = {
+		{ NVIF_CLASS_MMU_GF100, -1 },
+		{ NVIF_CLASS_MMU_NV50 , -1 },
+		{ NVIF_CLASS_MMU_NV04 , -1 },
+		{}
+	};
 	struct nouveau_drm *drm;
 	int ret;
 
@@ -757,6 +752,18 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
 		goto done;
 	}
 
+	ret = nvif_mclass(&drm->device.object, mmus);
+	if (ret < 0) {
+		NV_ERROR(drm, "No supported MMU class\n");
+		goto done;
+	}
+
+	ret = nvif_mmu_ctor(&drm->device.object, "drmMmu", mmus[ret].oclass, &drm->mmu);
+	if (ret) {
+		NV_ERROR(drm, "MMU allocation failed: %d\n", ret);
+		goto done;
+	}
+
 	drm->dev = drm_dev_alloc(drm_driver, parent);
 	if (IS_ERR(drm->dev)) {
 		ret = PTR_ERR(drm->dev);
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
index a9e0a63c772e..2535a50b99f3 100644
@@ -204,6 +204,7 @@ struct nouveau_drm {
 	struct nvkm_device *nvkm;
 	struct nvif_parent parent;
 	struct nvif_device device;
+	struct nvif_mmu mmu;
 
 	struct nouveau_cli master;
 	struct nouveau_cli client;
drivers/gpu/drm/nouveau/nouveau_mem.c +6 -6
index 25f31d5169e5..67f93cf753ba 100644
@@ -91,7 +91,7 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_tt *tt)
 	struct nouveau_mem *mem = nouveau_mem(reg);
 	struct nouveau_cli *cli = mem->cli;
 	struct nouveau_drm *drm = cli->drm;
-	struct nvif_mmu *mmu = &cli->mmu;
+	struct nvif_mmu *mmu = &drm->mmu;
 	struct nvif_mem_ram_v0 args = {};
 	u8 type;
 	int ret;
@@ -115,7 +115,7 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_tt *tt)
 		args.dma = tt->dma_address;
 
 	mutex_lock(&drm->master.lock);
-	ret = nvif_mem_ctor_type(mmu, "ttmHostMem", cli->mem->oclass, type, PAGE_SHIFT,
+	ret = nvif_mem_ctor_type(mmu, "ttmHostMem", mmu->mem, type, PAGE_SHIFT,
 				 reg->size,
 				 &args, sizeof(args), &mem->mem);
 	mutex_unlock(&drm->master.lock);
@@ -128,14 +128,14 @@ nouveau_mem_vram(struct ttm_resource *reg, bool contig, u8 page)
 	struct nouveau_mem *mem = nouveau_mem(reg);
 	struct nouveau_cli *cli = mem->cli;
 	struct nouveau_drm *drm = cli->drm;
-	struct nvif_mmu *mmu = &cli->mmu;
+	struct nvif_mmu *mmu = &drm->mmu;
 	u64 size = ALIGN(reg->size, 1 << page);
 	int ret;
 
 	mutex_lock(&drm->master.lock);
-	switch (cli->mem->oclass) {
+	switch (mmu->mem) {
 	case NVIF_CLASS_MEM_GF100:
-		ret = nvif_mem_ctor_type(mmu, "ttmVram", cli->mem->oclass,
+		ret = nvif_mem_ctor_type(mmu, "ttmVram", mmu->mem,
 					 drm->ttm.type_vram, page, size,
 					 &(struct gf100_mem_v0) {
 						.contig = contig,
@@ -143,7 +143,7 @@ nouveau_mem_vram(struct ttm_resource *reg, bool contig, u8 page)
 					 &mem->mem);
 		break;
 	case NVIF_CLASS_MEM_NV50:
-		ret = nvif_mem_ctor_type(mmu, "ttmVram", cli->mem->oclass,
+		ret = nvif_mem_ctor_type(mmu, "ttmVram", mmu->mem,
 					 drm->ttm.type_vram, page, size,
 					 &(struct nv50_mem_v0) {
 						.bankswz = mmu->kind[mem->kind] == 2,
Signature · 1 line
2.45.1
#60 lore raw

Re: [PATCH v2 28/37] drm/nouveau: add nvif_mmu to nouveau_drm

Quoted 3 lines · Ben Skeggs

This allocates a new nvif_mmu in nouveau_drm, and uses it for TTM backend memory allocations instead of nouveau_drm.master.mmu, which will be removed in a later commit.

It would be good to make clear that this is part of a couple of commits that aim at removing nouveau_drm::master.

Also, can we get all related commits a bit closer to each other?

Quoted 146 lines
---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 35 ++++++++++++++++-----------
 drivers/gpu/drm/nouveau/nouveau_drv.h |  1 +
 drivers/gpu/drm/nouveau/nouveau_mem.c | 12 ++++-----
 3 files changed, 28 insertions(+), 20 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +21 -14
index 5ff116bcbabf..07748cfab233 100644
@@ -227,13 +227,6 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 		{}
 	};
 	static const struct nvif_mclass
-	mmus[] = {
-		{ NVIF_CLASS_MMU_GF100, -1 },
-		{ NVIF_CLASS_MMU_NV50 , -1 },
-		{ NVIF_CLASS_MMU_NV04 , -1 },
-		{}
-	};
-	static const struct nvif_mclass
 	vmms[] = {
 		{ NVIF_CLASS_VMM_GP100, -1 },
 		{ NVIF_CLASS_VMM_GM200, -1 },
@@ -270,13 +263,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 
 	cli->device.object.map.ptr = drm->device.object.map.ptr;
 
-	ret = nvif_mclass(&cli->device.object, mmus);
-	if (ret < 0) {
-		NV_PRINTK(err, cli, "No supported MMU class\n");
-		goto done;
-	}
-
-	ret = nvif_mmu_ctor(&cli->device.object, "drmMmu", mmus[ret].oclass,
+	ret = nvif_mmu_ctor(&cli->device.object, "drmMmu", drm->mmu.object.oclass,
 			    &cli->mmu);
 	if (ret) {
 		NV_PRINTK(err, cli, "MMU allocation failed: %d\n", ret);
@@ -717,6 +704,7 @@ nouveau_drm_device_del(struct nouveau_drm *drm)
 	if (drm->dev)
 		drm_dev_put(drm->dev);
 
+	nvif_mmu_dtor(&drm->mmu);
 	nvif_device_dtor(&drm->device);
 	nvif_client_dtor(&drm->master.base);
 	nvif_parent_dtor(&drm->parent);
@@ -728,6 +716,13 @@ static struct nouveau_drm *
 nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,
 		       struct nvkm_device *device)
 {
+	static const struct nvif_mclass
+	mmus[] = {
+		{ NVIF_CLASS_MMU_GF100, -1 },
+		{ NVIF_CLASS_MMU_NV50 , -1 },
+		{ NVIF_CLASS_MMU_NV04 , -1 },
+		{}
+	};
 	struct nouveau_drm *drm;
 	int ret;
 
@@ -757,6 +752,18 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
 		goto done;
 	}
 
+	ret = nvif_mclass(&drm->device.object, mmus);
+	if (ret < 0) {
+		NV_ERROR(drm, "No supported MMU class\n");
+		goto done;
+	}
+
+	ret = nvif_mmu_ctor(&drm->device.object, "drmMmu", mmus[ret].oclass, &drm->mmu);
+	if (ret) {
+		NV_ERROR(drm, "MMU allocation failed: %d\n", ret);
+		goto done;
+	}
+
 	drm->dev = drm_dev_alloc(drm_driver, parent);
 	if (IS_ERR(drm->dev)) {
 		ret = PTR_ERR(drm->dev);
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
index a9e0a63c772e..2535a50b99f3 100644
@@ -204,6 +204,7 @@ struct nouveau_drm {
 	struct nvkm_device *nvkm;
 	struct nvif_parent parent;
 	struct nvif_device device;
+	struct nvif_mmu mmu;
 
 	struct nouveau_cli master;
 	struct nouveau_cli client;
drivers/gpu/drm/nouveau/nouveau_mem.c +6 -6
index 25f31d5169e5..67f93cf753ba 100644
@@ -91,7 +91,7 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_tt *tt)
 	struct nouveau_mem *mem = nouveau_mem(reg);
 	struct nouveau_cli *cli = mem->cli;
 	struct nouveau_drm *drm = cli->drm;
-	struct nvif_mmu *mmu = &cli->mmu;
+	struct nvif_mmu *mmu = &drm->mmu;
 	struct nvif_mem_ram_v0 args = {};
 	u8 type;
 	int ret;
@@ -115,7 +115,7 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_tt *tt)
 		args.dma = tt->dma_address;
 
 	mutex_lock(&drm->master.lock);
-	ret = nvif_mem_ctor_type(mmu, "ttmHostMem", cli->mem->oclass, type, PAGE_SHIFT,
+	ret = nvif_mem_ctor_type(mmu, "ttmHostMem", mmu->mem, type, PAGE_SHIFT,
 				 reg->size,
 				 &args, sizeof(args), &mem->mem);
 	mutex_unlock(&drm->master.lock);
@@ -128,14 +128,14 @@ nouveau_mem_vram(struct ttm_resource *reg, bool contig, u8 page)
 	struct nouveau_mem *mem = nouveau_mem(reg);
 	struct nouveau_cli *cli = mem->cli;
 	struct nouveau_drm *drm = cli->drm;
-	struct nvif_mmu *mmu = &cli->mmu;
+	struct nvif_mmu *mmu = &drm->mmu;
 	u64 size = ALIGN(reg->size, 1 << page);
 	int ret;
 
 	mutex_lock(&drm->master.lock);
-	switch (cli->mem->oclass) {
+	switch (mmu->mem) {
 	case NVIF_CLASS_MEM_GF100:
-		ret = nvif_mem_ctor_type(mmu, "ttmVram", cli->mem->oclass,
+		ret = nvif_mem_ctor_type(mmu, "ttmVram", mmu->mem,
 					 drm->ttm.type_vram, page, size,
 					 &(struct gf100_mem_v0) {
 						.contig = contig,
@@ -143,7 +143,7 @@ nouveau_mem_vram(struct ttm_resource *reg, bool contig, u8 page)
 					 &mem->mem);
 		break;
 	case NVIF_CLASS_MEM_NV50:
-		ret = nvif_mem_ctor_type(mmu, "ttmVram", cli->mem->oclass,
+		ret = nvif_mem_ctor_type(mmu, "ttmVram", mmu->mem,
 					 drm->ttm.type_vram, page, size,
 					 &(struct nv50_mem_v0) {
 						.bankswz = mmu->kind[mem->kind] == 2,
Signature · 1 line
2.45.1
author
#61 lore raw

Re: [PATCH v2 28/37] drm/nouveau: add nvif_mmu to nouveau_drm

Quoted 6 lines · Danilo Krummrich
Quoted 3 lines · Ben Skeggs

This allocates a new nvif_mmu in nouveau_drm, and uses it for TTM backend memory allocations instead of nouveau_drm.master.mmu, which will be removed in a later commit.

It would be good to make clear that this is part of a couple of commits that aim at removing nouveau_drm::master.

Nearly the entire series relates to that in some manner. Nevertheless, I've slightly reworded the commit message.

Quoted 2 lines

Also, can we get all related commits a bit closer to each other?

They basically are.  Only a handful of commits could likely be moved around safely, and not in any way that'd result in any kind of perfect ordering like you're asking for.  It also invalidates the testing I've done to ensure things are bisectable.

Quoted 146 lines
Quoted 146 lines
---
  drivers/gpu/drm/nouveau/nouveau_drm.c | 35 ++++++++++++++++-----------
  drivers/gpu/drm/nouveau/nouveau_drv.h |  1 +
  drivers/gpu/drm/nouveau/nouveau_mem.c | 12 ++++-----
  3 files changed, 28 insertions(+), 20 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +21 -14
index 5ff116bcbabf..07748cfab233 100644
@@ -227,13 +227,6 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
  		{}
  	};
  	static const struct nvif_mclass
-	mmus[] = {
-		{ NVIF_CLASS_MMU_GF100, -1 },
-		{ NVIF_CLASS_MMU_NV50 , -1 },
-		{ NVIF_CLASS_MMU_NV04 , -1 },
-		{}
-	};
-	static const struct nvif_mclass
  	vmms[] = {
  		{ NVIF_CLASS_VMM_GP100, -1 },
  		{ NVIF_CLASS_VMM_GM200, -1 },
@@ -270,13 +263,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
 
  	cli->device.object.map.ptr = drm->device.object.map.ptr;
 
-	ret = nvif_mclass(&cli->device.object, mmus);
-	if (ret < 0) {
-		NV_PRINTK(err, cli, "No supported MMU class\n");
-		goto done;
-	}
-
-	ret = nvif_mmu_ctor(&cli->device.object, "drmMmu", mmus[ret].oclass,
+	ret = nvif_mmu_ctor(&cli->device.object, "drmMmu", drm->mmu.object.oclass,
  			    &cli->mmu);
  	if (ret) {
  		NV_PRINTK(err, cli, "MMU allocation failed: %d\n", ret);
@@ -717,6 +704,7 @@ nouveau_drm_device_del(struct nouveau_drm *drm)
  	if (drm->dev)
  		drm_dev_put(drm->dev);
 
+	nvif_mmu_dtor(&drm->mmu);
  	nvif_device_dtor(&drm->device);
  	nvif_client_dtor(&drm->master.base);
  	nvif_parent_dtor(&drm->parent);
@@ -728,6 +716,13 @@ static struct nouveau_drm *
  nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,
  		       struct nvkm_device *device)
  {
+	static const struct nvif_mclass
+	mmus[] = {
+		{ NVIF_CLASS_MMU_GF100, -1 },
+		{ NVIF_CLASS_MMU_NV50 , -1 },
+		{ NVIF_CLASS_MMU_NV04 , -1 },
+		{}
+	};
  	struct nouveau_drm *drm;
  	int ret;
 
@@ -757,6 +752,18 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
  		goto done;
  	}
 
+	ret = nvif_mclass(&drm->device.object, mmus);
+	if (ret < 0) {
+		NV_ERROR(drm, "No supported MMU class\n");
+		goto done;
+	}
+
+	ret = nvif_mmu_ctor(&drm->device.object, "drmMmu", mmus[ret].oclass, &drm->mmu);
+	if (ret) {
+		NV_ERROR(drm, "MMU allocation failed: %d\n", ret);
+		goto done;
+	}
+
  	drm->dev = drm_dev_alloc(drm_driver, parent);
  	if (IS_ERR(drm->dev)) {
  		ret = PTR_ERR(drm->dev);
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
index a9e0a63c772e..2535a50b99f3 100644
@@ -204,6 +204,7 @@ struct nouveau_drm {
  	struct nvkm_device *nvkm;
  	struct nvif_parent parent;
  	struct nvif_device device;
+	struct nvif_mmu mmu;
 
  	struct nouveau_cli master;
  	struct nouveau_cli client;
drivers/gpu/drm/nouveau/nouveau_mem.c +6 -6
index 25f31d5169e5..67f93cf753ba 100644
@@ -91,7 +91,7 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_tt *tt)
  	struct nouveau_mem *mem = nouveau_mem(reg);
  	struct nouveau_cli *cli = mem->cli;
  	struct nouveau_drm *drm = cli->drm;
-	struct nvif_mmu *mmu = &cli->mmu;
+	struct nvif_mmu *mmu = &drm->mmu;
  	struct nvif_mem_ram_v0 args = {};
  	u8 type;
  	int ret;
@@ -115,7 +115,7 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_tt *tt)
  		args.dma = tt->dma_address;
 
  	mutex_lock(&drm->master.lock);
-	ret = nvif_mem_ctor_type(mmu, "ttmHostMem", cli->mem->oclass, type, PAGE_SHIFT,
+	ret = nvif_mem_ctor_type(mmu, "ttmHostMem", mmu->mem, type, PAGE_SHIFT,
  				 reg->size,
  				 &args, sizeof(args), &mem->mem);
  	mutex_unlock(&drm->master.lock);
@@ -128,14 +128,14 @@ nouveau_mem_vram(struct ttm_resource *reg, bool contig, u8 page)
  	struct nouveau_mem *mem = nouveau_mem(reg);
  	struct nouveau_cli *cli = mem->cli;
  	struct nouveau_drm *drm = cli->drm;
-	struct nvif_mmu *mmu = &cli->mmu;
+	struct nvif_mmu *mmu = &drm->mmu;
  	u64 size = ALIGN(reg->size, 1 << page);
  	int ret;
 
  	mutex_lock(&drm->master.lock);
-	switch (cli->mem->oclass) {
+	switch (mmu->mem) {
  	case NVIF_CLASS_MEM_GF100:
-		ret = nvif_mem_ctor_type(mmu, "ttmVram", cli->mem->oclass,
+		ret = nvif_mem_ctor_type(mmu, "ttmVram", mmu->mem,
  					 drm->ttm.type_vram, page, size,
  					 &(struct gf100_mem_v0) {
  						.contig = contig,
@@ -143,7 +143,7 @@ nouveau_mem_vram(struct ttm_resource *reg, bool contig, u8 page)
  					 &mem->mem);
  		break;
  	case NVIF_CLASS_MEM_NV50:
-		ret = nvif_mem_ctor_type(mmu, "ttmVram", cli->mem->oclass,
+		ret = nvif_mem_ctor_type(mmu, "ttmVram", mmu->mem,
  					 drm->ttm.type_vram, page, size,
  					 &(struct nv50_mem_v0) {
  						.bankswz = mmu->kind[mem->kind] == 2,
Signature · 1 line
2.45.1
#62 lore raw

Re: [PATCH v2 28/37] drm/nouveau: add nvif_mmu to nouveau_drm

Quoted 11 lines · Ben Skeggs
Quoted 6 lines · Danilo Krummrich
Quoted 3 lines · Ben Skeggs

This allocates a new nvif_mmu in nouveau_drm, and uses it for TTM backend memory allocations instead of nouveau_drm.master.mmu, which will be removed in a later commit.

It would be good to make clear that this is part of a couple of commits that aim at removing nouveau_drm::master.

Nearly the entire series relates to that in some manner. Nevertheless, I've slightly reworded the commit message.

I think there are quite some unrelated ones. Otherwise I wonder why this series is titled "misc. cleanups and removal of unused apis" and the cover letter does not mention the removal of nouveau_drm::master at all.

Anyway, next time it would probably be good to partition things even more. For instance, have one series that only does the nouveau_drm::master removal and another one that only does the other misc cleanups.

Quoted 8 lines
Quoted 3 lines

Also, can we get all related commits a bit closer to each other?

They basically are.  Only a handful of commits could likely be moved around safely, and not in any way that'd result in any kind of perfect ordering like you're asking for.  It also invalidates the testing I've done to ensure things are bisectable.

It's not about perfect ordering, it's about making it easier to review and hence make the process less error prone. It's also less annoying for the author; when things are obvious, reviewers tend to ask less stupid questions. :)

Quoted 140 lines
Quoted 139 lines
Quoted 139 lines
---
  drivers/gpu/drm/nouveau/nouveau_drm.c | 35 ++++++++++++++++-----------
  drivers/gpu/drm/nouveau/nouveau_drv.h |  1 +
  drivers/gpu/drm/nouveau/nouveau_mem.c | 12 ++++-----
  3 files changed, 28 insertions(+), 20 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +21 -14
index 5ff116bcbabf..07748cfab233 100644
@@ -227,13 +227,6 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
  		{}
  	};
  	static const struct nvif_mclass
-	mmus[] = {
-		{ NVIF_CLASS_MMU_GF100, -1 },
-		{ NVIF_CLASS_MMU_NV50 , -1 },
-		{ NVIF_CLASS_MMU_NV04 , -1 },
-		{}
-	};
-	static const struct nvif_mclass
  	vmms[] = {
  		{ NVIF_CLASS_VMM_GP100, -1 },
  		{ NVIF_CLASS_VMM_GM200, -1 },
@@ -270,13 +263,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
  	cli->device.object.map.ptr = drm->device.object.map.ptr;
-	ret = nvif_mclass(&cli->device.object, mmus);
-	if (ret < 0) {
-		NV_PRINTK(err, cli, "No supported MMU class\n");
-		goto done;
-	}
-
-	ret = nvif_mmu_ctor(&cli->device.object, "drmMmu", mmus[ret].oclass,
+	ret = nvif_mmu_ctor(&cli->device.object, "drmMmu", drm->mmu.object.oclass,
  			    &cli->mmu);
  	if (ret) {
  		NV_PRINTK(err, cli, "MMU allocation failed: %d\n", ret);
@@ -717,6 +704,7 @@ nouveau_drm_device_del(struct nouveau_drm *drm)
  	if (drm->dev)
  		drm_dev_put(drm->dev);
+	nvif_mmu_dtor(&drm->mmu);
  	nvif_device_dtor(&drm->device);
  	nvif_client_dtor(&drm->master.base);
  	nvif_parent_dtor(&drm->parent);
@@ -728,6 +716,13 @@ static struct nouveau_drm *
  nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *parent,
  		       struct nvkm_device *device)
  {
+	static const struct nvif_mclass
+	mmus[] = {
+		{ NVIF_CLASS_MMU_GF100, -1 },
+		{ NVIF_CLASS_MMU_NV50 , -1 },
+		{ NVIF_CLASS_MMU_NV04 , -1 },
+		{}
+	};
  	struct nouveau_drm *drm;
  	int ret;
@@ -757,6 +752,18 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
  		goto done;
  	}
+	ret = nvif_mclass(&drm->device.object, mmus);
+	if (ret < 0) {
+		NV_ERROR(drm, "No supported MMU class\n");
+		goto done;
+	}
+
+	ret = nvif_mmu_ctor(&drm->device.object, "drmMmu", mmus[ret].oclass, &drm->mmu);
+	if (ret) {
+		NV_ERROR(drm, "MMU allocation failed: %d\n", ret);
+		goto done;
+	}
+
  	drm->dev = drm_dev_alloc(drm_driver, parent);
  	if (IS_ERR(drm->dev)) {
  		ret = PTR_ERR(drm->dev);
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
index a9e0a63c772e..2535a50b99f3 100644
@@ -204,6 +204,7 @@ struct nouveau_drm {
  	struct nvkm_device *nvkm;
  	struct nvif_parent parent;
  	struct nvif_device device;
+	struct nvif_mmu mmu;
  	struct nouveau_cli master;
  	struct nouveau_cli client;
drivers/gpu/drm/nouveau/nouveau_mem.c +6 -6
index 25f31d5169e5..67f93cf753ba 100644
@@ -91,7 +91,7 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_tt *tt)
  	struct nouveau_mem *mem = nouveau_mem(reg);
  	struct nouveau_cli *cli = mem->cli;
  	struct nouveau_drm *drm = cli->drm;
-	struct nvif_mmu *mmu = &cli->mmu;
+	struct nvif_mmu *mmu = &drm->mmu;
  	struct nvif_mem_ram_v0 args = {};
  	u8 type;
  	int ret;
@@ -115,7 +115,7 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_tt *tt)
  		args.dma = tt->dma_address;
  	mutex_lock(&drm->master.lock);
-	ret = nvif_mem_ctor_type(mmu, "ttmHostMem", cli->mem->oclass, type, PAGE_SHIFT,
+	ret = nvif_mem_ctor_type(mmu, "ttmHostMem", mmu->mem, type, PAGE_SHIFT,
  				 reg->size,
  				 &args, sizeof(args), &mem->mem);
  	mutex_unlock(&drm->master.lock);
@@ -128,14 +128,14 @@ nouveau_mem_vram(struct ttm_resource *reg, bool contig, u8 page)
  	struct nouveau_mem *mem = nouveau_mem(reg);
  	struct nouveau_cli *cli = mem->cli;
  	struct nouveau_drm *drm = cli->drm;
-	struct nvif_mmu *mmu = &cli->mmu;
+	struct nvif_mmu *mmu = &drm->mmu;
  	u64 size = ALIGN(reg->size, 1 << page);
  	int ret;
  	mutex_lock(&drm->master.lock);
-	switch (cli->mem->oclass) {
+	switch (mmu->mem) {
  	case NVIF_CLASS_MEM_GF100:
-		ret = nvif_mem_ctor_type(mmu, "ttmVram", cli->mem->oclass,
+		ret = nvif_mem_ctor_type(mmu, "ttmVram", mmu->mem,
  					 drm->ttm.type_vram, page, size,
  					 &(struct gf100_mem_v0) {
  						.contig = contig,
@@ -143,7 +143,7 @@ nouveau_mem_vram(struct ttm_resource *reg, bool contig, u8 page)
  					 &mem->mem);
  		break;
  	case NVIF_CLASS_MEM_NV50:
-		ret = nvif_mem_ctor_type(mmu, "ttmVram", cli->mem->oclass,
+		ret = nvif_mem_ctor_type(mmu, "ttmVram", mmu->mem,
  					 drm->ttm.type_vram, page, size,
  					 &(struct nv50_mem_v0) {
  						.bankswz = mmu->kind[mem->kind] == 2,
Signature · 1 line
2.45.1
author
#63 lore raw

PATCH v2 29/37 drm/nouveau: pass drm to nouveau_mem_new(), instead of cli

In reply to Ben Skeggs

The nouveau_cli pointer is only ever used to eventually access nouveau_drm, so just store it directly.

---
 drivers/gpu/drm/nouveau/nouveau_mem.c   | 18 ++++++++----------
 drivers/gpu/drm/nouveau/nouveau_mem.h   |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_sgdma.c |  2 +-
 drivers/gpu/drm/nouveau/nouveau_ttm.c   |  8 ++++----
 4 files changed, 15 insertions(+), 17 deletions(-)
drivers/gpu/drm/nouveau/nouveau_mem.c +8 -10
index 67f93cf753ba..b112b62dca3c 100644
@@ -78,19 +78,18 @@ nouveau_mem_map(struct nouveau_mem *mem,
 void
 nouveau_mem_fini(struct nouveau_mem *mem)
 {
-	nvif_vmm_put(&mem->cli->drm->client.vmm.vmm, &mem->vma[1]);
-	nvif_vmm_put(&mem->cli->drm->client.vmm.vmm, &mem->vma[0]);
-	mutex_lock(&mem->cli->drm->master.lock);
+	nvif_vmm_put(&mem->drm->client.vmm.vmm, &mem->vma[1]);
+	nvif_vmm_put(&mem->drm->client.vmm.vmm, &mem->vma[0]);
+	mutex_lock(&mem->drm->master.lock);
 	nvif_mem_dtor(&mem->mem);
-	mutex_unlock(&mem->cli->drm->master.lock);
+	mutex_unlock(&mem->drm->master.lock);
 }
 
 int
 nouveau_mem_host(struct ttm_resource *reg, struct ttm_tt *tt)
 {
 	struct nouveau_mem *mem = nouveau_mem(reg);
-	struct nouveau_cli *cli = mem->cli;
-	struct nouveau_drm *drm = cli->drm;
+	struct nouveau_drm *drm = mem->drm;
 	struct nvif_mmu *mmu = &drm->mmu;
 	struct nvif_mem_ram_v0 args = {};
 	u8 type;
@@ -126,8 +125,7 @@ int
 nouveau_mem_vram(struct ttm_resource *reg, bool contig, u8 page)
 {
 	struct nouveau_mem *mem = nouveau_mem(reg);
-	struct nouveau_cli *cli = mem->cli;
-	struct nouveau_drm *drm = cli->drm;
+	struct nouveau_drm *drm = mem->drm;
 	struct nvif_mmu *mmu = &drm->mmu;
 	u64 size = ALIGN(reg->size, 1 << page);
 	int ret;
@@ -173,7 +171,7 @@ nouveau_mem_del(struct ttm_resource_manager *man, struct ttm_resource *reg)
 }
 
 int
-nouveau_mem_new(struct nouveau_cli *cli, u8 kind, u8 comp,
+nouveau_mem_new(struct nouveau_drm *drm, u8 kind, u8 comp,
 		struct ttm_resource **res)
 {
 	struct nouveau_mem *mem;
@@ -181,7 +179,7 @@ nouveau_mem_new(struct nouveau_cli *cli, u8 kind, u8 comp,
 	if (!(mem = kzalloc(sizeof(*mem), GFP_KERNEL)))
 		return -ENOMEM;
 
-	mem->cli = cli;
+	mem->drm = drm;
 	mem->kind = kind;
 	mem->comp = comp;
 
drivers/gpu/drm/nouveau/nouveau_mem.h +2 -2
index 5365a3d3a17f..a070ee049f6b 100644
@@ -8,7 +8,7 @@ struct ttm_tt;
 
 struct nouveau_mem {
 	struct ttm_resource base;
-	struct nouveau_cli *cli;
+	struct nouveau_drm *drm;
 	u8 kind;
 	u8 comp;
 	struct nvif_mem mem;
@@ -21,7 +21,7 @@ nouveau_mem(struct ttm_resource *reg)
 	return container_of(reg, struct nouveau_mem, base);
 }
 
-int nouveau_mem_new(struct nouveau_cli *, u8 kind, u8 comp,
+int nouveau_mem_new(struct nouveau_drm *, u8 kind, u8 comp,
 		    struct ttm_resource **);
 void nouveau_mem_del(struct ttm_resource_manager *man,
 		     struct ttm_resource *);
drivers/gpu/drm/nouveau/nouveau_sgdma.c +1 -1
index b14895f75b3c..bd870028514b 100644
@@ -43,7 +43,7 @@ nouveau_sgdma_bind(struct ttm_device *bdev, struct ttm_tt *ttm, struct ttm_resou
 		return ret;
 
 	if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) {
-		ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]);
+		ret = nouveau_mem_map(mem, &drm->client.vmm.vmm, &mem->vma[0]);
 		if (ret) {
 			nouveau_mem_fini(mem);
 			return ret;
drivers/gpu/drm/nouveau/nouveau_ttm.c +4 -4
index 53553819bcac..e244927eb5d4 100644
@@ -73,7 +73,7 @@ nouveau_vram_manager_new(struct ttm_resource_manager *man,
 	if (drm->client.device.info.ram_size == 0)
 		return -ENOMEM;
 
-	ret = nouveau_mem_new(&drm->master, nvbo->kind, nvbo->comp, res);
+	ret = nouveau_mem_new(drm, nvbo->kind, nvbo->comp, res);
 	if (ret)
 		return ret;
 
@@ -105,7 +105,7 @@ nouveau_gart_manager_new(struct ttm_resource_manager *man,
 	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
 	int ret;
 
-	ret = nouveau_mem_new(&drm->master, nvbo->kind, nvbo->comp, res);
+	ret = nouveau_mem_new(drm, nvbo->kind, nvbo->comp, res);
 	if (ret)
 		return ret;
 
@@ -132,13 +132,13 @@ nv04_gart_manager_new(struct ttm_resource_manager *man,
 	struct nouveau_mem *mem;
 	int ret;
 
-	ret = nouveau_mem_new(&drm->master, nvbo->kind, nvbo->comp, res);
+	ret = nouveau_mem_new(drm, nvbo->kind, nvbo->comp, res);
 	if (ret)
 		return ret;
 
 	mem = nouveau_mem(*res);
 	ttm_resource_init(bo, place, *res);
-	ret = nvif_vmm_get(&mem->cli->vmm.vmm, PTES, false, 12, 0,
+	ret = nvif_vmm_get(&drm->client.vmm.vmm, PTES, false, 12, 0,
 			   (long)(*res)->size, &mem->vma[0]);
 	if (ret) {
 		nouveau_mem_del(man, *res);
Signature · 1 line
2.45.1
author
#64 lore raw

PATCH v2 30/37 drm/nouveau: pass drm to nv50_dmac_create(), rather than device+disp

In reply to Ben Skeggs

Both of these are stored in nouveau_drm already.

---
 drivers/gpu/drm/nouveau/dispnv50/base507c.c | 3 +--
 drivers/gpu/drm/nouveau/dispnv50/core507d.c | 2 +-
 drivers/gpu/drm/nouveau/dispnv50/disp.c     | 8 ++++----
 drivers/gpu/drm/nouveau/dispnv50/disp.h     | 2 +-
 drivers/gpu/drm/nouveau/dispnv50/ovly507e.c | 2 +-
 drivers/gpu/drm/nouveau/dispnv50/wimmc37b.c | 3 +--
 drivers/gpu/drm/nouveau/dispnv50/wndwc37e.c | 2 +-
 7 files changed, 10 insertions(+), 12 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/base507c.c +1 -2
index 70c62b861276..e36a473f2075 100644
@@ -307,7 +307,6 @@ base507c_new_(const struct nv50_wndw_func *func, const u32 *format,
 	struct nvif_disp_chan_v0 args = {
 		.id = head,
 	};
-	struct nouveau_display *disp = nouveau_display(drm->dev);
 	struct nv50_disp *disp50 = nv50_disp(drm->dev);
 	struct nv50_wndw *wndw;
 	int ret;
@@ -318,7 +317,7 @@ base507c_new_(const struct nv50_wndw_func *func, const u32 *format,
 	if (*pwndw = wndw, ret)
 		return ret;
 
-	ret = nv50_dmac_create(&drm->client.device, &disp->disp.object,
+	ret = nv50_dmac_create(drm,
 			       &oclass, head, &args, sizeof(args),
 			       disp50->sync->offset, &wndw->wndw);
 	if (ret) {
drivers/gpu/drm/nouveau/dispnv50/core507d.c +1 -1
index e5bb5ca950c8..85845e3dc7ba 100644
@@ -166,7 +166,7 @@ core507d_new_(const struct nv50_core_func *func, struct nouveau_drm *drm,
 		return -ENOMEM;
 	core->func = func;
 
-	ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
+	ret = nv50_dmac_create(drm,
 			       &oclass, 0, &args, sizeof(args),
 			       disp->sync->offset, &core->chan);
 	if (ret) {
drivers/gpu/drm/nouveau/dispnv50/disp.c +4 -4
index 80803346b620..deed18876c7d 100644
@@ -229,11 +229,12 @@ static int nv50_dmac_vram_pushbuf = -1;
 module_param_named(kms_vram_pushbuf, nv50_dmac_vram_pushbuf, int, 0400);
 
 int
-nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp,
+nv50_dmac_create(struct nouveau_drm *drm,
 		 const s32 *oclass, u8 head, void *data, u32 size, s64 syncbuf,
 		 struct nv50_dmac *dmac)
 {
-	struct nouveau_cli *cli = (void *)device->object.client;
+	struct nvif_device *device = &drm->device;
+	struct nvif_object *disp = &drm->display->disp.object;
 	struct nvif_disp_chan_v0 *args = data;
 	u8 type = NVIF_MEM_COHERENT;
 	int ret;
@@ -253,8 +254,7 @@ nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp,
 	    (nv50_dmac_vram_pushbuf < 0 && device->info.family == NV_DEVICE_INFO_V0_PASCAL))
 		type |= NVIF_MEM_VRAM;
 
-	ret = nvif_mem_ctor_map(&cli->mmu, "kmsChanPush", type, 0x1000,
-				&dmac->_push.mem);
+	ret = nvif_mem_ctor_map(&drm->mmu, "kmsChanPush", type, 0x1000, &dmac->_push.mem);
 	if (ret)
 		return ret;
 
drivers/gpu/drm/nouveau/dispnv50/disp.h +1 -1
index 5508a7cfd492..da3add95f354 100644
@@ -95,7 +95,7 @@ struct nv50_outp_atom {
 	} set, clr;
 };
 
-int nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp,
+int nv50_dmac_create(struct nouveau_drm *,
 		     const s32 *oclass, u8 head, void *data, u32 size,
 		     s64 syncbuf, struct nv50_dmac *dmac);
 void nv50_dmac_destroy(struct nv50_dmac *);
drivers/gpu/drm/nouveau/dispnv50/ovly507e.c +1 -1
index 797c1e4e0eaa..73fcfb27c32c 100644
@@ -159,7 +159,7 @@ ovly507e_new_(const struct nv50_wndw_func *func, const u32 *format,
 	if (*pwndw = wndw, ret)
 		return ret;
 
-	ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
+	ret = nv50_dmac_create(drm,
 			       &oclass, 0, &args, sizeof(args),
 			       disp->sync->offset, &wndw->wndw);
 	if (ret) {
drivers/gpu/drm/nouveau/dispnv50/wimmc37b.c +1 -2
index ee76b091d4ef..8cb5b79bacbf 100644
@@ -71,10 +71,9 @@ wimmc37b_init_(const struct nv50_wimm_func *func, struct nouveau_drm *drm,
 	struct nvif_disp_chan_v0 args = {
 		.id = wndw->id,
 	};
-	struct nv50_disp *disp = nv50_disp(drm->dev);
 	int ret;
 
-	ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
+	ret = nv50_dmac_create(drm,
 			       &oclass, 0, &args, sizeof(args), -1,
 			       &wndw->wimm);
 	if (ret) {
drivers/gpu/drm/nouveau/dispnv50/wndwc37e.c +1 -1
index b3deea5aca58..caf40977f455 100644
@@ -363,7 +363,7 @@ wndwc37e_new_(const struct nv50_wndw_func *func, struct nouveau_drm *drm,
 	if (*pwndw = wndw, ret)
 		return ret;
 
-	ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
+	ret = nv50_dmac_create(drm,
 			       &oclass, 0, &args, sizeof(args),
 			       disp->sync->offset, &wndw->wndw);
 	if (ret) {
Signature · 1 line
2.45.1
author
#65 lore raw

PATCH v2 31/37 drm/nouveau: pass cli to nouveau_channel_new() instead of drm+device

In reply to Ben Skeggs

Both of these are stored in nouveau_cli already, and also allows the removal of some void casts.

---
 drivers/gpu/drm/nouveau/dispnv04/crtc.c |  2 +-
 drivers/gpu/drm/nouveau/nouveau_abi16.c |  2 +-
 drivers/gpu/drm/nouveau/nouveau_bo.c    |  2 +-
 drivers/gpu/drm/nouveau/nouveau_chan.c  | 21 +++++++++++----------
 drivers/gpu/drm/nouveau/nouveau_chan.h  |  3 ++-
 drivers/gpu/drm/nouveau/nouveau_drm.c   |  4 ++--
 6 files changed, 18 insertions(+), 16 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/crtc.c +1 -1
index e5067d5a4801..41fd6e339221 100644
@@ -1157,7 +1157,7 @@ nv04_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
 	chan = drm->channel;
 	if (!chan)
 		return -ENODEV;
-	cli = (void *)chan->user.client;
+	cli = chan->cli;
 	push = chan->chan.push;
 
 	s = kzalloc(sizeof(*s), GFP_KERNEL);
drivers/gpu/drm/nouveau/nouveau_abi16.c +1 -1
index 5d74c36a4ca5..4239f7bedc32 100644
@@ -396,7 +396,7 @@ nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
 	list_add(&chan->head, &abi16->channels);
 
 	/* create channel object and initialise dma and fence management */
-	ret = nouveau_channel_new(drm, device, false, runm, init->fb_ctxdma_handle,
+	ret = nouveau_channel_new(cli, false, runm, init->fb_ctxdma_handle,
 				  init->tt_ctxdma_handle, &chan->chan);
 	if (ret)
 		goto done;
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -1
index 6631d85ea749..745b7d7503f7 100644
@@ -859,7 +859,7 @@ nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, int evict,
 {
 	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
 	struct nouveau_channel *chan = drm->ttm.chan;
-	struct nouveau_cli *cli = (void *)chan->user.client;
+	struct nouveau_cli *cli = chan->cli;
 	struct nouveau_fence *fence;
 	int ret;
 
drivers/gpu/drm/nouveau/nouveau_chan.c +11 -10
index 0105d4704c3a..e5c0d8526e46 100644
@@ -52,7 +52,7 @@ static int
 nouveau_channel_killed(struct nvif_event *event, void *repv, u32 repc)
 {
 	struct nouveau_channel *chan = container_of(event, typeof(*chan), kill);
-	struct nouveau_cli *cli = (void *)chan->user.client;
+	struct nouveau_cli *cli = chan->cli;
 
 	NV_PRINTK(warn, cli, "channel %d killed!\n", chan->chid);
 
@@ -66,7 +66,7 @@ int
 nouveau_channel_idle(struct nouveau_channel *chan)
 {
 	if (likely(chan && chan->fence && !atomic_read(&chan->killed))) {
-		struct nouveau_cli *cli = (void *)chan->user.client;
+		struct nouveau_cli *cli = chan->cli;
 		struct nouveau_fence *fence = NULL;
 		int ret;
 
@@ -142,10 +142,11 @@ nouveau_channel_wait(struct nvif_push *push, u32 size)
 }
 
 static int
-nouveau_channel_prep(struct nouveau_drm *drm, struct nvif_device *device,
+nouveau_channel_prep(struct nouveau_cli *cli,
 		     u32 size, struct nouveau_channel **pchan)
 {
-	struct nouveau_cli *cli = (void *)device->object.client;
+	struct nouveau_drm *drm = cli->drm;
+	struct nvif_device *device = &cli->device;
 	struct nv_dma_v0 args = {};
 	struct nouveau_channel *chan;
 	u32 target;
@@ -155,6 +156,7 @@ nouveau_channel_prep(struct nouveau_drm *drm, struct nvif_device *device,
 	if (!chan)
 		return -ENOMEM;
 
+	chan->cli = cli;
 	chan->device = device;
 	chan->drm = drm;
 	chan->vmm = nouveau_cli_vmm(cli);
@@ -253,7 +255,7 @@ nouveau_channel_prep(struct nouveau_drm *drm, struct nvif_device *device,
 }
 
 static int
-nouveau_channel_ctor(struct nouveau_drm *drm, struct nvif_device *device, bool priv, u64 runm,
+nouveau_channel_ctor(struct nouveau_cli *cli, bool priv, u64 runm,
 		     struct nouveau_channel **pchan)
 {
 	const struct nvif_mclass hosts[] = {
@@ -278,7 +280,7 @@ nouveau_channel_ctor(struct nouveau_drm *drm, struct nvif_device *device, bool p
 		struct nvif_chan_v0 chan;
 		char name[TASK_COMM_LEN+16];
 	} args;
-	struct nouveau_cli *cli = (void *)device->object.client;
+	struct nvif_device *device = &cli->device;
 	struct nouveau_channel *chan;
 	const u64 plength = 0x10000;
 	const u64 ioffset = plength;
@@ -297,7 +299,7 @@ nouveau_channel_ctor(struct nouveau_drm *drm, struct nvif_device *device, bool p
 		size = ioffset + ilength;
 
 	/* allocate dma push buffer */
-	ret = nouveau_channel_prep(drm, device, size, &chan);
+	ret = nouveau_channel_prep(cli, size, &chan);
 	*pchan = chan;
 	if (ret)
 		return ret;
@@ -492,13 +494,12 @@ nouveau_channel_init(struct nouveau_channel *chan, u32 vram, u32 gart)
 }
 
 int
-nouveau_channel_new(struct nouveau_drm *drm, struct nvif_device *device,
+nouveau_channel_new(struct nouveau_cli *cli,
 		    bool priv, u64 runm, u32 vram, u32 gart, struct nouveau_channel **pchan)
 {
-	struct nouveau_cli *cli = (void *)device->object.client;
 	int ret;
 
-	ret = nouveau_channel_ctor(drm, device, priv, runm, pchan);
+	ret = nouveau_channel_ctor(cli, priv, runm, pchan);
 	if (ret) {
 		NV_PRINTK(dbg, cli, "channel create, %d\n", ret);
 		return ret;
drivers/gpu/drm/nouveau/nouveau_chan.h +2 -1
index 5de2ef4e98c2..260febd634ee 100644
@@ -12,6 +12,7 @@ struct nouveau_channel {
 		struct nvif_push *push;
 	} chan;
 
+	struct nouveau_cli *cli;
 	struct nvif_device *device;
 	struct nouveau_drm *drm;
 	struct nouveau_vmm *vmm;
@@ -62,7 +63,7 @@ struct nouveau_channel {
 int nouveau_channels_init(struct nouveau_drm *);
 void nouveau_channels_fini(struct nouveau_drm *);
 
-int  nouveau_channel_new(struct nouveau_drm *, struct nvif_device *, bool priv, u64 runm,
+int  nouveau_channel_new(struct nouveau_cli *, bool priv, u64 runm,
 			 u32 vram, u32 gart, struct nouveau_channel **);
 void nouveau_channel_del(struct nouveau_channel **);
 int  nouveau_channel_idle(struct nouveau_channel *);
drivers/gpu/drm/nouveau/nouveau_drm.c +2 -2
index 07748cfab233..c6c9a528783a 100644
@@ -335,7 +335,7 @@ nouveau_accel_ce_init(struct nouveau_drm *drm)
 		return;
 	}
 
-	ret = nouveau_channel_new(drm, device, false, runm, NvDmaFB, NvDmaTT, &drm->cechan);
+	ret = nouveau_channel_new(&drm->client, false, runm, NvDmaFB, NvDmaTT, &drm->cechan);
 	if (ret)
 		NV_ERROR(drm, "failed to create ce channel, %d\n", ret);
 }
@@ -363,7 +363,7 @@ nouveau_accel_gr_init(struct nouveau_drm *drm)
 		return;
 	}
 
-	ret = nouveau_channel_new(drm, device, false, runm, NvDmaFB, NvDmaTT, &drm->channel);
+	ret = nouveau_channel_new(&drm->client, false, runm, NvDmaFB, NvDmaTT, &drm->channel);
 	if (ret) {
 		NV_ERROR(drm, "failed to create kernel channel, %d\n", ret);
 		nouveau_accel_gr_fini(drm);
Signature · 1 line
2.45.1
author
#66 lore raw

PATCH v2 32/37 drm/nouveau: remove nouveau_chan.device

In reply to Ben Skeggs

nouveau_chan.device is always the same as nouveau_chan.cli.device, so there's no need to store it separately.

---
 drivers/gpu/drm/nouveau/nouveau_chan.c | 6 +++---
 drivers/gpu/drm/nouveau/nouveau_chan.h | 1 -
 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/nouveau/nouveau_chan.c +3 -3
index e5c0d8526e46..b01535ea4ea3 100644
@@ -157,7 +157,6 @@ nouveau_channel_prep(struct nouveau_cli *cli,
 		return -ENOMEM;
 
 	chan->cli = cli;
-	chan->device = device;
 	chan->drm = drm;
 	chan->vmm = nouveau_cli_vmm(cli);
 	atomic_set(&chan->killed, 0);
@@ -364,8 +363,9 @@ nouveau_channel_ctor(struct nouveau_cli *cli, bool priv, u64 runm,
 static int
 nouveau_channel_init(struct nouveau_channel *chan, u32 vram, u32 gart)
 {
-	struct nvif_device *device = chan->device;
-	struct nouveau_drm *drm = chan->drm;
+	struct nouveau_cli *cli = chan->cli;
+	struct nouveau_drm *drm = cli->drm;
+	struct nvif_device *device = &cli->device;
 	struct nv_dma_v0 args = {};
 	int ret, i;
 
drivers/gpu/drm/nouveau/nouveau_chan.h +0 -1
index 260febd634ee..18a9cbfef8ca 100644
@@ -13,7 +13,6 @@ struct nouveau_channel {
 	} chan;
 
 	struct nouveau_cli *cli;
-	struct nvif_device *device;
 	struct nouveau_drm *drm;
 	struct nouveau_vmm *vmm;
 
Signature · 1 line
2.45.1