Re: [Nouveau] [PATCH] drm/nouveau: Remove support for legacy contexts/buffers

2023-01-12 Thread Karol Herbst
On Thu, Jan 12, 2023 at 2:39 PM Thomas Zimmermann  wrote:
>
> Remove nouveau's support for legacy contexts and buffers. It was
> required by libdrm earlier than 2.4.33, released in March 2012. A
> previous attempt in 2013 to remove the functionality [1] had to be
> reverted [2] as there were still users left. Libdrm 2.4.33 is now
> almost 11 years old and it is time for userspace to move on.
>
> With the nouveau code gone, we can also remove the driver-feature
> bit DRIVER_KMS_LEGACY_CONTEXT.
>
> Signed-off-by: Thomas Zimmermann 
> Link: 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7c510133d93dd6f15ca040733ba7b2891ed61fd1
>  # 1
> Link: 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c21eb21cb50d58e7cbdcb8b9e7ff68b85cfa5095
>  # 2

Reviewed-by: Karol Herbst 

let's hope there are no users left :)


> ---
>  drivers/gpu/drm/drm_bufs.c| 12 +++--
>  drivers/gpu/drm/drm_context.c | 36 +--
>  drivers/gpu/drm/nouveau/Kconfig   | 12 -
>  drivers/gpu/drm/nouveau/nouveau_drm.c | 10 +++-
>  include/drm/drm_drv.h |  7 --
>  5 files changed, 19 insertions(+), 58 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> index fcca21e8efac..86700560fea2 100644
> --- a/drivers/gpu/drm/drm_bufs.c
> +++ b/drivers/gpu/drm/drm_bufs.c
> @@ -423,8 +423,7 @@ int drm_legacy_addmap_ioctl(struct drm_device *dev, void 
> *data,
> if (!(capable(CAP_SYS_ADMIN) || map->type == _DRM_AGP || map->type == 
> _DRM_SHM))
> return -EPERM;
>
> -   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
> -   !drm_core_check_feature(dev, DRIVER_LEGACY))
> +   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
> return -EOPNOTSUPP;
>
> err = drm_addmap_core(dev, map->offset, map->size, map->type,
> @@ -469,8 +468,7 @@ int drm_legacy_getmap_ioctl(struct drm_device *dev, void 
> *data,
> int idx;
> int i;
>
> -   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
> -   !drm_core_check_feature(dev, DRIVER_LEGACY))
> +   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
> return -EOPNOTSUPP;
>
> idx = map->offset;
> @@ -570,8 +568,7 @@ EXPORT_SYMBOL(drm_legacy_rmmap_locked);
>
>  void drm_legacy_rmmap(struct drm_device *dev, struct drm_local_map *map)
>  {
> -   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
> -   !drm_core_check_feature(dev, DRIVER_LEGACY))
> +   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
> return;
>
> mutex_lock(>struct_mutex);
> @@ -628,8 +625,7 @@ int drm_legacy_rmmap_ioctl(struct drm_device *dev, void 
> *data,
> struct drm_map_list *r_list;
> int ret;
>
> -   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
> -   !drm_core_check_feature(dev, DRIVER_LEGACY))
> +   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
> return -EOPNOTSUPP;
>
> mutex_lock(>struct_mutex);
> diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c
> index c6e6a3e7219a..a0fc779e5e1e 100644
> --- a/drivers/gpu/drm/drm_context.c
> +++ b/drivers/gpu/drm/drm_context.c
> @@ -59,8 +59,7 @@ struct drm_ctx_list {
>   */
>  void drm_legacy_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
>  {
> -   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
> -   !drm_core_check_feature(dev, DRIVER_LEGACY))
> +   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
> return;
>
> mutex_lock(>struct_mutex);
> @@ -97,8 +96,7 @@ static int drm_legacy_ctxbitmap_next(struct drm_device * 
> dev)
>   */
>  void drm_legacy_ctxbitmap_init(struct drm_device * dev)
>  {
> -   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
> -   !drm_core_check_feature(dev, DRIVER_LEGACY))
> +   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
> return;
>
> idr_init(>ctx_idr);
> @@ -114,8 +112,7 @@ void drm_legacy_ctxbitmap_init(struct drm_device * dev)
>   */
>  void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev)
>  {
> -   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
> -   !drm_core_check_feature(dev, DRIVER_LEGACY))
> +   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
> return;
>
> mutex_lock(>struct_mutex);
> @@ -136,8 +133,7 @@ void drm_legacy_ctxbitmap_flush(struct drm_device *dev, 
> struct drm_file *file)
>  {
> struct drm_ctx_list *pos, *tmp;
>
> -   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
> -   !drm_core_check_feature(dev, DRIVER_LEGACY))
> +   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
> return;
>
> mutex_lock(>ctxlist_mutex);
> @@ -182,8 +178,7 @@ int 

Re: [Nouveau] [PATCH][next] drm/nouveau/nvkm: Replace zero-length array with flexible-array member

2023-01-12 Thread Kees Cook
On Mon, Jan 09, 2023 at 07:39:30PM -0600, Gustavo A. R. Silva wrote:
> Zero-length arrays are deprecated[1] and we are moving towards
> adopting C99 flexible-array members instead. So, replace zero-length
> array declaration in struct nvfw_hs_load_header_v2 with flex-array
> member.
> 
> This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
> routines on memcpy() and help us make progress towards globally
> enabling -fstrict-flex-arrays=3 [2].
> 
> Link: 
> https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
>  [1]
> Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [2]
> Link: https://github.com/KSPP/linux/issues/78
> Signed-off-by: Gustavo A. R. Silva 

Reviewed-by: Kees Cook 

-- 
Kees Cook


[Nouveau] [PATCH v2 1/3] drm/i915: Allow switching away via vga-switcheroo if uninitialized

2023-01-12 Thread Thomas Zimmermann
Always allow switching away via vga-switcheroo if the display is
uninitalized. Instead prevent switching to i915 if the device has
not been initialized.

This issue was introduced by commit 5df7bd130818 ("drm/i915: skip
display initialization when there is no display") protected, which
protects code paths from being executed on uninitialized devices.
In the case of vga-switcheroo, we want to allow a switch away from
i915's device. So run vga_switcheroo_process_delayed_switch() and
test in the switcheroo callbacks if the i915 device is available.

Fixes: 5df7bd130818 ("drm/i915: skip display initialization when there is no 
display")
Signed-off-by: Thomas Zimmermann 
Cc: Radhakrishna Sripada 
Cc: Lucas De Marchi 
Cc: José Roberto de Souza 
Cc: Jani Nikula 
Cc: Ville Syrjälä 
Cc: Jani Nikula 
Cc: Joonas Lahtinen 
Cc: Rodrigo Vivi 
Cc: Tvrtko Ursulin 
Cc: "Ville Syrjälä" 
Cc: Manasi Navare 
Cc: Stanislav Lisovskiy 
Cc: Imre Deak 
Cc: "Jouni Högander" 
Cc: Uma Shankar 
Cc: Ankit Nautiyal 
Cc: "Jason A. Donenfeld" 
Cc: Matt Roper 
Cc: Ramalingam C 
Cc: Thomas Zimmermann 
Cc: Andi Shyti 
Cc: Andrzej Hajda 
Cc: "José Roberto de Souza" 
Cc: Julia Lawall 
Cc: intel-...@lists.freedesktop.org
Cc:  # v5.14+
---
 drivers/gpu/drm/i915/i915_driver.c | 3 +--
 drivers/gpu/drm/i915/i915_switcheroo.c | 6 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_driver.c 
b/drivers/gpu/drm/i915/i915_driver.c
index c1e427ba57ae..33e231b120c1 100644
--- a/drivers/gpu/drm/i915/i915_driver.c
+++ b/drivers/gpu/drm/i915/i915_driver.c
@@ -1075,8 +1075,7 @@ static void i915_driver_lastclose(struct drm_device *dev)
 
intel_fbdev_restore_mode(dev);
 
-   if (HAS_DISPLAY(i915))
-   vga_switcheroo_process_delayed_switch();
+   vga_switcheroo_process_delayed_switch();
 }
 
 static void i915_driver_postclose(struct drm_device *dev, struct drm_file 
*file)
diff --git a/drivers/gpu/drm/i915/i915_switcheroo.c 
b/drivers/gpu/drm/i915/i915_switcheroo.c
index 23777d500cdf..f45bd6b6cede 100644
--- a/drivers/gpu/drm/i915/i915_switcheroo.c
+++ b/drivers/gpu/drm/i915/i915_switcheroo.c
@@ -19,6 +19,10 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev,
dev_err(>dev, "DRM not initialized, aborting switch.\n");
return;
}
+   if (!HAS_DISPLAY(i915)) {
+   dev_err(>dev, "Device state not initialized, aborting 
switch.\n");
+   return;
+   }
 
if (state == VGA_SWITCHEROO_ON) {
drm_info(>drm, "switched on\n");
@@ -44,7 +48,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
 * locking inversion with the driver load path. And the access here is
 * completely racy anyway. So don't bother with locking for now.
 */
-   return i915 && atomic_read(>drm.open_count) == 0;
+   return i915 && HAS_DISPLAY(i915) && atomic_read(>drm.open_count) 
== 0;
 }
 
 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
-- 
2.39.0



[Nouveau] [PATCH v2 3/3] drm: Call vga_switcheroo_process_delayed_switch() in drm_lastclose

2023-01-12 Thread Thomas Zimmermann
Several lastclose helpers call vga_switcheroo_process_delayed_switch().
It's better to call the helper from drm_lastclose() after the kernel
client's screen has been restored. This way, all drivers can benefit
without having to implement their own lastclose helper. For drivers
without vga-switcheroo, vga_switcheroo_process_delayed_switch() does
nothing.

There was an earlier patchset to do something similar. [1]

v2:
* handle vga_switcheroo_client_fb_set() in a separate patch
* also update i915, nouveau and radeon
* remove unnecessary include statements
* update vga-switcheroo docs

Suggested-by: Alexander Deucher 
Signed-off-by: Thomas Zimmermann 
Reviewed-by: Daniel Vetter 
Reviewed-by: Alex Deucher 
Link: 
https://lore.kernel.org/amd-gfx/20221020143603.563929-1-alexander.deuc...@amd.com/
 # 1
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |  2 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 13 -
 drivers/gpu/drm/drm_file.c  |  3 +++
 drivers/gpu/drm/i915/i915_driver.c  | 25 ++---
 drivers/gpu/drm/nouveau/nouveau_drm.c   |  1 -
 drivers/gpu/drm/nouveau/nouveau_vga.c   |  7 ---
 drivers/gpu/drm/nouveau/nouveau_vga.h   |  1 -
 drivers/gpu/drm/radeon/radeon_drv.c |  2 +-
 drivers/gpu/drm/radeon/radeon_drv.h |  1 -
 drivers/gpu/drm/radeon/radeon_kms.c | 18 --
 drivers/gpu/vga/vga_switcheroo.c|  4 ++--
 12 files changed, 8 insertions(+), 70 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 63c921c55fb9..7120b9b6e580 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1330,7 +1330,6 @@ extern const int amdgpu_max_kms_ioctl;
 
 int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags);
 void amdgpu_driver_unload_kms(struct drm_device *dev);
-void amdgpu_driver_lastclose_kms(struct drm_device *dev);
 int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
 void amdgpu_driver_postclose_kms(struct drm_device *dev,
 struct drm_file *file_priv);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 1353ffd08988..783c1e284a22 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -34,7 +34,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -2785,7 +2784,6 @@ static const struct drm_driver amdgpu_kms_driver = {
DRIVER_SYNCOBJ_TIMELINE,
.open = amdgpu_driver_open_kms,
.postclose = amdgpu_driver_postclose_kms,
-   .lastclose = amdgpu_driver_lastclose_kms,
.ioctls = amdgpu_ioctls_kms,
.num_ioctls = ARRAY_SIZE(amdgpu_ioctls_kms),
.dumb_create = amdgpu_mode_dumb_create,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 7aa7e52ca784..a37be02fb2fc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -34,7 +34,6 @@
 #include "amdgpu_vce.h"
 #include "atom.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -1104,18 +1103,6 @@ int amdgpu_info_ioctl(struct drm_device *dev, void 
*data, struct drm_file *filp)
 /*
  * Outdated mess for old drm with Xorg being in charge (void function now).
  */
-/**
- * amdgpu_driver_lastclose_kms - drm callback for last close
- *
- * @dev: drm dev pointer
- *
- * Switch vga_switcheroo state after last close (all asics).
- */
-void amdgpu_driver_lastclose_kms(struct drm_device *dev)
-{
-   drm_fb_helper_lastclose(dev);
-   vga_switcheroo_process_delayed_switch();
-}
 
 /**
  * amdgpu_driver_open_kms - drm callback for open
diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
index a51ff8cee049..314c309db9a3 100644
--- a/drivers/gpu/drm/drm_file.c
+++ b/drivers/gpu/drm/drm_file.c
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -460,6 +461,8 @@ void drm_lastclose(struct drm_device * dev)
drm_legacy_dev_reinit(dev);
 
drm_client_dev_restore(dev);
+
+   vga_switcheroo_process_delayed_switch();
 }
 
 /**
diff --git a/drivers/gpu/drm/i915/i915_driver.c 
b/drivers/gpu/drm/i915/i915_driver.c
index 33e231b120c1..bf6ad8620970 100644
--- a/drivers/gpu/drm/i915/i915_driver.c
+++ b/drivers/gpu/drm/i915/i915_driver.c
@@ -29,6 +29,7 @@
 
 #include 
 #include 
+#include  /* for FBINFO_STATE_ */
 #include 
 #include 
 #include 
@@ -37,7 +38,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include 
@@ -1057,27 +1057,6 @@ static int i915_driver_open(struct drm_device *dev, 
struct drm_file *file)
return 0;
 }
 
-/**
- * i915_driver_lastclose - clean up after all DRM clients have exited
- * @dev: DRM device
- *
- * Take care of cleaning up after all DRM clients have exited.  In the
- * 

[Nouveau] [PATCH v2 0/3] drm: Generic fbdev and vga-switcheroo

2023-01-12 Thread Thomas Zimmermann
(was: drm/fb-helper: Set framebuffer for vga-switcheroo clients)

This patch has now turned into a little series. The first two patches
are bug fixes for the existing code. The third patch cleans up the
drivers.

Patch 1 fixes i915 to do the correct thing if the device has not been
initialized yet. Switching to the device is only possible after the
initialization, but switching away is always possible.

Patch 2 is the original patch without the amdgpu changes. Installs
the fbdev framebuffer in vga-switcheroo for the PCI device. Does
nothing for drivers without vga-switcheroo.

Patch 3 cleans up vga_switcheroo_process_delayed_switch() in amdgpu
and the other related drivers (i.e., i915, nouveau and radeon). The
call is now located at the end of drm_lastclose() and drivers do not
need their own lastclose helpers any longer.

I kept the r-bs from v1, but patch 1 is entirely new and patch 3 has
significantly grown in size.

Thomas Zimmermann (3):
  drm/i915: Allow switching away via vga-switcheroo if uninitialized
  drm/fb-helper: Set framebuffer for vga-switcheroo clients
  drm: Call vga_switcheroo_process_delayed_switch() in drm_lastclose

 drivers/gpu/drm/amd/amdgpu/amdgpu.h |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |  2 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 13 -
 drivers/gpu/drm/drm_fb_helper.c |  8 
 drivers/gpu/drm/drm_file.c  |  3 +++
 drivers/gpu/drm/i915/i915_driver.c  | 26 ++---
 drivers/gpu/drm/i915/i915_switcheroo.c  |  6 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c   |  1 -
 drivers/gpu/drm/nouveau/nouveau_vga.c   |  7 ---
 drivers/gpu/drm/nouveau/nouveau_vga.h   |  1 -
 drivers/gpu/drm/radeon/radeon_drv.c |  2 +-
 drivers/gpu/drm/radeon/radeon_drv.h |  1 -
 drivers/gpu/drm/radeon/radeon_kms.c | 18 -
 drivers/gpu/vga/vga_switcheroo.c|  4 ++--
 14 files changed, 21 insertions(+), 72 deletions(-)


base-commit: ac04152253dccfb02dcedfa0c57443122cf79314
-- 
2.39.0



Re: [Nouveau] [PATCH] drm/nouveau: Remove support for legacy contexts/buffers

2023-01-12 Thread Thomas Zimmermann
If this patch gets accepted, I'd like to merge it via drm-misc-next 
together with the legacy-driver removal patches.


Am 12.01.23 um 14:38 schrieb Thomas Zimmermann:

Remove nouveau's support for legacy contexts and buffers. It was
required by libdrm earlier than 2.4.33, released in March 2012. A
previous attempt in 2013 to remove the functionality [1] had to be
reverted [2] as there were still users left. Libdrm 2.4.33 is now
almost 11 years old and it is time for userspace to move on.

With the nouveau code gone, we can also remove the driver-feature
bit DRIVER_KMS_LEGACY_CONTEXT.

Signed-off-by: Thomas Zimmermann 
Link: 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7c510133d93dd6f15ca040733ba7b2891ed61fd1
 # 1
Link: 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c21eb21cb50d58e7cbdcb8b9e7ff68b85cfa5095
 # 2
---
  drivers/gpu/drm/drm_bufs.c| 12 +++--
  drivers/gpu/drm/drm_context.c | 36 +--
  drivers/gpu/drm/nouveau/Kconfig   | 12 -
  drivers/gpu/drm/nouveau/nouveau_drm.c | 10 +++-
  include/drm/drm_drv.h |  7 --
  5 files changed, 19 insertions(+), 58 deletions(-)

diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index fcca21e8efac..86700560fea2 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -423,8 +423,7 @@ int drm_legacy_addmap_ioctl(struct drm_device *dev, void 
*data,
if (!(capable(CAP_SYS_ADMIN) || map->type == _DRM_AGP || map->type == 
_DRM_SHM))
return -EPERM;
  
-	if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&

-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return -EOPNOTSUPP;
  
  	err = drm_addmap_core(dev, map->offset, map->size, map->type,

@@ -469,8 +468,7 @@ int drm_legacy_getmap_ioctl(struct drm_device *dev, void 
*data,
int idx;
int i;
  
-	if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&

-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return -EOPNOTSUPP;
  
  	idx = map->offset;

@@ -570,8 +568,7 @@ EXPORT_SYMBOL(drm_legacy_rmmap_locked);
  
  void drm_legacy_rmmap(struct drm_device *dev, struct drm_local_map *map)

  {
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return;
  
  	mutex_lock(>struct_mutex);

@@ -628,8 +625,7 @@ int drm_legacy_rmmap_ioctl(struct drm_device *dev, void 
*data,
struct drm_map_list *r_list;
int ret;
  
-	if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&

-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return -EOPNOTSUPP;
  
  	mutex_lock(>struct_mutex);

diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c
index c6e6a3e7219a..a0fc779e5e1e 100644
--- a/drivers/gpu/drm/drm_context.c
+++ b/drivers/gpu/drm/drm_context.c
@@ -59,8 +59,7 @@ struct drm_ctx_list {
   */
  void drm_legacy_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
  {
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return;
  
  	mutex_lock(>struct_mutex);

@@ -97,8 +96,7 @@ static int drm_legacy_ctxbitmap_next(struct drm_device * dev)
   */
  void drm_legacy_ctxbitmap_init(struct drm_device * dev)
  {
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return;
  
  	idr_init(>ctx_idr);

@@ -114,8 +112,7 @@ void drm_legacy_ctxbitmap_init(struct drm_device * dev)
   */
  void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev)
  {
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return;
  
  	mutex_lock(>struct_mutex);

@@ -136,8 +133,7 @@ void drm_legacy_ctxbitmap_flush(struct drm_device *dev, 
struct drm_file *file)
  {
struct drm_ctx_list *pos, *tmp;
  
-	if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&

-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return;
  
  	mutex_lock(>ctxlist_mutex);

@@ -182,8 +178,7 @@ int drm_legacy_getsareactx(struct drm_device *dev, void 
*data,
struct drm_local_map *map;
struct drm_map_list *_entry;
  
-	if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&

-   

[Nouveau] [PATCH] drm/nouveau: Remove support for legacy contexts/buffers

2023-01-12 Thread Thomas Zimmermann
Remove nouveau's support for legacy contexts and buffers. It was
required by libdrm earlier than 2.4.33, released in March 2012. A
previous attempt in 2013 to remove the functionality [1] had to be
reverted [2] as there were still users left. Libdrm 2.4.33 is now
almost 11 years old and it is time for userspace to move on.

With the nouveau code gone, we can also remove the driver-feature
bit DRIVER_KMS_LEGACY_CONTEXT.

Signed-off-by: Thomas Zimmermann 
Link: 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7c510133d93dd6f15ca040733ba7b2891ed61fd1
 # 1
Link: 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c21eb21cb50d58e7cbdcb8b9e7ff68b85cfa5095
 # 2
---
 drivers/gpu/drm/drm_bufs.c| 12 +++--
 drivers/gpu/drm/drm_context.c | 36 +--
 drivers/gpu/drm/nouveau/Kconfig   | 12 -
 drivers/gpu/drm/nouveau/nouveau_drm.c | 10 +++-
 include/drm/drm_drv.h |  7 --
 5 files changed, 19 insertions(+), 58 deletions(-)

diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index fcca21e8efac..86700560fea2 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -423,8 +423,7 @@ int drm_legacy_addmap_ioctl(struct drm_device *dev, void 
*data,
if (!(capable(CAP_SYS_ADMIN) || map->type == _DRM_AGP || map->type == 
_DRM_SHM))
return -EPERM;
 
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return -EOPNOTSUPP;
 
err = drm_addmap_core(dev, map->offset, map->size, map->type,
@@ -469,8 +468,7 @@ int drm_legacy_getmap_ioctl(struct drm_device *dev, void 
*data,
int idx;
int i;
 
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return -EOPNOTSUPP;
 
idx = map->offset;
@@ -570,8 +568,7 @@ EXPORT_SYMBOL(drm_legacy_rmmap_locked);
 
 void drm_legacy_rmmap(struct drm_device *dev, struct drm_local_map *map)
 {
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return;
 
mutex_lock(>struct_mutex);
@@ -628,8 +625,7 @@ int drm_legacy_rmmap_ioctl(struct drm_device *dev, void 
*data,
struct drm_map_list *r_list;
int ret;
 
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return -EOPNOTSUPP;
 
mutex_lock(>struct_mutex);
diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c
index c6e6a3e7219a..a0fc779e5e1e 100644
--- a/drivers/gpu/drm/drm_context.c
+++ b/drivers/gpu/drm/drm_context.c
@@ -59,8 +59,7 @@ struct drm_ctx_list {
  */
 void drm_legacy_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
 {
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return;
 
mutex_lock(>struct_mutex);
@@ -97,8 +96,7 @@ static int drm_legacy_ctxbitmap_next(struct drm_device * dev)
  */
 void drm_legacy_ctxbitmap_init(struct drm_device * dev)
 {
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return;
 
idr_init(>ctx_idr);
@@ -114,8 +112,7 @@ void drm_legacy_ctxbitmap_init(struct drm_device * dev)
  */
 void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev)
 {
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return;
 
mutex_lock(>struct_mutex);
@@ -136,8 +133,7 @@ void drm_legacy_ctxbitmap_flush(struct drm_device *dev, 
struct drm_file *file)
 {
struct drm_ctx_list *pos, *tmp;
 
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return;
 
mutex_lock(>ctxlist_mutex);
@@ -182,8 +178,7 @@ int drm_legacy_getsareactx(struct drm_device *dev, void 
*data,
struct drm_local_map *map;
struct drm_map_list *_entry;
 
-   if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
-   !drm_core_check_feature(dev, DRIVER_LEGACY))
+   if (!drm_core_check_feature(dev, DRIVER_LEGACY))
return -EOPNOTSUPP;