[PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v4)

2021-07-27 Thread Ryan Taylor
Modify the VKMS driver into an api that dce_virtual can use to create
virtual displays that obey drm's atomic modesetting api.

v2: Made local functions static.

v3: Switched vkms_output kzalloc for kcalloc.
Cleanup patches by moving display mode fixes to this patch.

v4: Update atomic_check and atomic_update to comply with new kms api.

Reported-by: kernel test robot 
Suggested-by: Alex Deucher 
Signed-off-by: Ryan Taylor 
---
 drivers/gpu/drm/amd/amdgpu/Makefile  |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h  |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 446 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h |  29 ++
 drivers/gpu/drm/amd/amdgpu/dce_virtual.c |  23 +-
 7 files changed, 493 insertions(+), 11 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index f089794bbdd5..30cbcd5ce1cc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -120,6 +120,7 @@ amdgpu-y += \
 amdgpu-y += \
dce_v10_0.o \
dce_v11_0.o \
+   amdgpu_vkms.o \
dce_virtual.o
 
 # add GFX block
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index d10baa3338bc..96e895d6be35 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -916,6 +916,7 @@ struct amdgpu_device {
 
/* display */
boolenable_virtual_display;
+   struct amdgpu_vkms_output   *amdgpu_vkms_output;
struct amdgpu_mode_info mode_info;
/* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
struct work_struct  hotplug_work;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index bbc6bfadafd6..06e2a461f610 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -1230,7 +1230,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
int ret, retry = 0;
bool supports_atomic = false;
 
-   if (!amdgpu_virtual_display &&
+   if (amdgpu_virtual_display ||
amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))
supports_atomic = true;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index 09b048647523..5a143ca02cf9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -344,7 +344,7 @@ int amdgpu_fbdev_init(struct amdgpu_device *adev)
}
 
/* disable all the possible outputs/crtcs before entering KMS mode */
-   if (!amdgpu_device_has_dc_support(adev))
+   if (!amdgpu_device_has_dc_support(adev) && !amdgpu_virtual_display)
drm_helper_disable_unused_functions(adev_to_drm(adev));
 
drm_fb_helper_initial_config(>helper, bpp_sel);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
new file mode 100644
index ..e2810b22bb43
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
@@ -0,0 +1,446 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include 
+#include 
+#include 
+
+#include "amdgpu.h"
+#include "amdgpu_vkms.h"
+#include "amdgpu_display.h"
+
+/**
+ * DOC: amdgpu_vkms
+ *
+ * The amdgpu vkms interface provides a virtual KMS interface for several use
+ * cases: devices without display hardware, platforms where the actual display
+ * hardware is not useful (e.g., servers), SR-IOV virtual functions, device
+ * emulation/simulation, and device bring up prior to display hardware being
+ * usable. We previously emulated a legacy KMS interface, but there was a 
desire
+ * to move to the atomic KMS interface. The vkms driver did everything we
+ * needed, but we wanted KMS support natively in the driver without buffer
+ * sharing and the ability to support an instance of VKMS per device. We first
+ * looked at splitting vkms into a stub driver and a helper module that other
+ * drivers could use to implement a virtual display, but this strategy ended up
+ * being messy due to driver specific callbacks needed for buffer management.
+ * Ultimately, it proved easier to import the vkms code as it mostly used core
+ * drm helpers anyway.
+ */
+
+static const u32 amdgpu_vkms_formats[] = {
+   DRM_FORMAT_XRGB,
+};
+
+static enum hrtimer_restart amdgpu_vkms_vblank_simulate(struct hrtimer *timer)
+{
+   struct amdgpu_vkms_output *output = container_of(timer,
+struct 
amdgpu_vkms_output,
+vblank_hrtimer);
+   struct drm_crtc *crtc = >crtc;
+   u64 ret_overrun;
+   bool 

Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)

2021-07-26 Thread Taylor, Ryan
[AMD Official Use Only]

Sounds good, Thanks for clarifying. Thanks for the input Guchun.

Best,
Ryan

From: Alex Deucher 
Sent: Monday, July 26, 2021 9:58 AM
To: Taylor, Ryan 
Cc: Chen, Guchun ; kernel test robot ; 
Daniel Vetter ; Siqueira, Rodrigo 
; amd-gfx list ; 
Melissa Wen ; Maling list - DRI developers 

Subject: Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)

On Mon, Jul 26, 2021 at 12:39 PM Taylor, Ryan  wrote:
>
> [AMD Official Use Only]
>
>
> Given that amdgpu_vkms contains code from both dce_virtual and vkms should 
> the identifier be changed to GPL-2.0+ OR MIT like in amdgpu_res_cursor.h?

Most of the code is from vkms so match vkms.

Alex


>
> Best,
> Ryan
> 
> From: Alex Deucher 
> Sent: Monday, July 26, 2021 9:21 AM
> To: Chen, Guchun 
> Cc: Taylor, Ryan ; kernel test robot ; 
> Daniel Vetter ; Siqueira, Rodrigo 
> ; amd-gfx list ; 
> Melissa Wen ; Maling list - DRI developers 
> 
> Subject: Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)
>
> On Fri, Jul 23, 2021 at 10:07 PM Chen, Guchun  wrote:
> >
> > [Public]
> >
> > Look copy right statement is missed in both amdgpu_vkms.c and amdgpu_vkms.h.
>
> It's there, it just uses the newer SPDX license identifier.
>
> Alex
>
>
> >
> > Regards,
> > Guchun
> >
> > -Original Message-
> > From: amd-gfx  On Behalf Of Alex 
> > Deucher
> > Sent: Friday, July 23, 2021 10:32 PM
> > To: Taylor, Ryan 
> > Cc: kernel test robot ; Daniel Vetter 
> > ; Siqueira, Rodrigo ; 
> > amd-gfx list ; Melissa Wen 
> > ; Maling list - DRI developers 
> > 
> > Subject: Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)
> >
> > On Wed, Jul 21, 2021 at 1:07 PM Ryan Taylor  wrote:
> > >
> > > Modify the VKMS driver into an api that dce_virtual can use to create
> > > virtual displays that obey drm's atomic modesetting api.
> > >
> > > v2: Made local functions static.
> > >
> > > Reported-by: kernel test robot 
> > > Signed-off-by: Ryan Taylor 
> > > ---
> > >  drivers/gpu/drm/amd/amdgpu/Makefile  |   1 +
> > >  drivers/gpu/drm/amd/amdgpu/amdgpu.h  |   1 +
> > >  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  |   2 +-
> > >  drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   |   2 +-
> > >  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 411
> > > +++  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h |
> > > 29 ++  drivers/gpu/drm/amd/amdgpu/dce_virtual.c |  23 +-
> > >  7 files changed, 458 insertions(+), 11 deletions(-)  create mode
> > > 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> > >  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h
> > >
> > > diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
> > > b/drivers/gpu/drm/amd/amdgpu/Makefile
> > > index f089794bbdd5..30cbcd5ce1cc 100644
> > > --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> > > +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> > > @@ -120,6 +120,7 @@ amdgpu-y += \
> > >  amdgpu-y += \
> > > dce_v10_0.o \
> > > dce_v11_0.o \
> > > +   amdgpu_vkms.o \
> > > dce_virtual.o
> > >
> > >  # add GFX block
> > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > > b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > > index 54cf647bd018..d0a2f2ed433d 100644
> > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > > @@ -919,6 +919,7 @@ struct amdgpu_device {
> > >
> > > /* display */
> > > boolenable_virtual_display;
> > > +   struct amdgpu_vkms_output   *amdgpu_vkms_output;
> > > struct amdgpu_mode_info mode_info;
> > > /* For pre-DCE11. DCE11 and later are in "struct 
> > > amdgpu_device->dm" */
> > > struct work_struct  hotplug_work;
> > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > > b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > > index d0c935cf4f0f..1b016e5bc75f 100644
> > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > > @@ -1230,7 +1230,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
> > > int ret, retry = 0;
> > > bool supports_atomic = false;
> > >
> > > -   if (!amdgpu_virtual_display &&
> > > +

Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)

2021-07-26 Thread Taylor, Ryan
[AMD Official Use Only]

Given that amdgpu_vkms contains code from both dce_virtual and vkms should the 
identifier be changed to GPL-2.0+ OR MIT like in amdgpu_res_cursor.h?

Best,
Ryan

From: Alex Deucher 
Sent: Monday, July 26, 2021 9:21 AM
To: Chen, Guchun 
Cc: Taylor, Ryan ; kernel test robot ; 
Daniel Vetter ; Siqueira, Rodrigo 
; amd-gfx list ; 
Melissa Wen ; Maling list - DRI developers 

Subject: Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)

On Fri, Jul 23, 2021 at 10:07 PM Chen, Guchun  wrote:
>
> [Public]
>
> Look copy right statement is missed in both amdgpu_vkms.c and amdgpu_vkms.h.

It's there, it just uses the newer SPDX license identifier.

Alex


>
> Regards,
> Guchun
>
> -Original Message-
> From: amd-gfx  On Behalf Of Alex 
> Deucher
> Sent: Friday, July 23, 2021 10:32 PM
> To: Taylor, Ryan 
> Cc: kernel test robot ; Daniel Vetter 
> ; Siqueira, Rodrigo ; 
> amd-gfx list ; Melissa Wen 
> ; Maling list - DRI developers 
> 
> Subject: Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)
>
> On Wed, Jul 21, 2021 at 1:07 PM Ryan Taylor  wrote:
> >
> > Modify the VKMS driver into an api that dce_virtual can use to create
> > virtual displays that obey drm's atomic modesetting api.
> >
> > v2: Made local functions static.
> >
> > Reported-by: kernel test robot 
> > Signed-off-by: Ryan Taylor 
> > ---
> >  drivers/gpu/drm/amd/amdgpu/Makefile  |   1 +
> >  drivers/gpu/drm/amd/amdgpu/amdgpu.h  |   1 +
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  |   2 +-
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   |   2 +-
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 411
> > +++  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h |
> > 29 ++  drivers/gpu/drm/amd/amdgpu/dce_virtual.c |  23 +-
> >  7 files changed, 458 insertions(+), 11 deletions(-)  create mode
> > 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> >  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
> > b/drivers/gpu/drm/amd/amdgpu/Makefile
> > index f089794bbdd5..30cbcd5ce1cc 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> > +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> > @@ -120,6 +120,7 @@ amdgpu-y += \
> >  amdgpu-y += \
> > dce_v10_0.o \
> > dce_v11_0.o \
> > +   amdgpu_vkms.o \
> > dce_virtual.o
> >
> >  # add GFX block
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > index 54cf647bd018..d0a2f2ed433d 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > @@ -919,6 +919,7 @@ struct amdgpu_device {
> >
> > /* display */
> > boolenable_virtual_display;
> > +   struct amdgpu_vkms_output   *amdgpu_vkms_output;
> > struct amdgpu_mode_info mode_info;
> > /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" 
> > */
> > struct work_struct  hotplug_work;
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > index d0c935cf4f0f..1b016e5bc75f 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > @@ -1230,7 +1230,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
> > int ret, retry = 0;
> > bool supports_atomic = false;
> >
> > -   if (!amdgpu_virtual_display &&
> > +   if (amdgpu_virtual_display ||
> > amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))
> > supports_atomic = true;
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > index 09b048647523..5a143ca02cf9 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > @@ -344,7 +344,7 @@ int amdgpu_fbdev_init(struct amdgpu_device *adev)
> > }
> >
> > /* disable all the possible outputs/crtcs before entering KMS mode 
> > */
> > -   if (!amdgpu_device_has_dc_support(adev))
> > +   if (!amdgpu_device_has_dc_support(adev) &&
> > + !amdgpu_virtual_display)
> >
> > drm_helper_disable_unused_functions(adev_to_drm(adev));
> >
> > drm_fb_helper_initial_config(>helper, bpp_sel); diff
> > --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> > b/drivers/gpu/drm/amd/a

Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)

2021-07-26 Thread Alex Deucher
On Mon, Jul 26, 2021 at 12:39 PM Taylor, Ryan  wrote:
>
> [AMD Official Use Only]
>
>
> Given that amdgpu_vkms contains code from both dce_virtual and vkms should 
> the identifier be changed to GPL-2.0+ OR MIT like in amdgpu_res_cursor.h?

Most of the code is from vkms so match vkms.

Alex


>
> Best,
> Ryan
> 
> From: Alex Deucher 
> Sent: Monday, July 26, 2021 9:21 AM
> To: Chen, Guchun 
> Cc: Taylor, Ryan ; kernel test robot ; 
> Daniel Vetter ; Siqueira, Rodrigo 
> ; amd-gfx list ; 
> Melissa Wen ; Maling list - DRI developers 
> 
> Subject: Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)
>
> On Fri, Jul 23, 2021 at 10:07 PM Chen, Guchun  wrote:
> >
> > [Public]
> >
> > Look copy right statement is missed in both amdgpu_vkms.c and amdgpu_vkms.h.
>
> It's there, it just uses the newer SPDX license identifier.
>
> Alex
>
>
> >
> > Regards,
> > Guchun
> >
> > -Original Message-
> > From: amd-gfx  On Behalf Of Alex 
> > Deucher
> > Sent: Friday, July 23, 2021 10:32 PM
> > To: Taylor, Ryan 
> > Cc: kernel test robot ; Daniel Vetter 
> > ; Siqueira, Rodrigo ; 
> > amd-gfx list ; Melissa Wen 
> > ; Maling list - DRI developers 
> > 
> > Subject: Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)
> >
> > On Wed, Jul 21, 2021 at 1:07 PM Ryan Taylor  wrote:
> > >
> > > Modify the VKMS driver into an api that dce_virtual can use to create
> > > virtual displays that obey drm's atomic modesetting api.
> > >
> > > v2: Made local functions static.
> > >
> > > Reported-by: kernel test robot 
> > > Signed-off-by: Ryan Taylor 
> > > ---
> > >  drivers/gpu/drm/amd/amdgpu/Makefile  |   1 +
> > >  drivers/gpu/drm/amd/amdgpu/amdgpu.h  |   1 +
> > >  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  |   2 +-
> > >  drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   |   2 +-
> > >  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 411
> > > +++  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h |
> > > 29 ++  drivers/gpu/drm/amd/amdgpu/dce_virtual.c |  23 +-
> > >  7 files changed, 458 insertions(+), 11 deletions(-)  create mode
> > > 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> > >  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h
> > >
> > > diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
> > > b/drivers/gpu/drm/amd/amdgpu/Makefile
> > > index f089794bbdd5..30cbcd5ce1cc 100644
> > > --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> > > +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> > > @@ -120,6 +120,7 @@ amdgpu-y += \
> > >  amdgpu-y += \
> > > dce_v10_0.o \
> > > dce_v11_0.o \
> > > +   amdgpu_vkms.o \
> > > dce_virtual.o
> > >
> > >  # add GFX block
> > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > > b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > > index 54cf647bd018..d0a2f2ed433d 100644
> > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > > @@ -919,6 +919,7 @@ struct amdgpu_device {
> > >
> > > /* display */
> > > boolenable_virtual_display;
> > > +   struct amdgpu_vkms_output   *amdgpu_vkms_output;
> > > struct amdgpu_mode_info mode_info;
> > > /* For pre-DCE11. DCE11 and later are in "struct 
> > > amdgpu_device->dm" */
> > > struct work_struct  hotplug_work;
> > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > > b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > > index d0c935cf4f0f..1b016e5bc75f 100644
> > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > > @@ -1230,7 +1230,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
> > > int ret, retry = 0;
> > > bool supports_atomic = false;
> > >
> > > -   if (!amdgpu_virtual_display &&
> > > +   if (amdgpu_virtual_display ||
> > > amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))
> > > supports_atomic = true;
> > >
> > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > > b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > > index 09b048647523..5a143ca02cf9 100644
> > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > >

Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)

2021-07-26 Thread Alex Deucher
On Fri, Jul 23, 2021 at 10:07 PM Chen, Guchun  wrote:
>
> [Public]
>
> Look copy right statement is missed in both amdgpu_vkms.c and amdgpu_vkms.h.

It's there, it just uses the newer SPDX license identifier.

Alex


>
> Regards,
> Guchun
>
> -Original Message-
> From: amd-gfx  On Behalf Of Alex 
> Deucher
> Sent: Friday, July 23, 2021 10:32 PM
> To: Taylor, Ryan 
> Cc: kernel test robot ; Daniel Vetter 
> ; Siqueira, Rodrigo ; 
> amd-gfx list ; Melissa Wen 
> ; Maling list - DRI developers 
> 
> Subject: Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)
>
> On Wed, Jul 21, 2021 at 1:07 PM Ryan Taylor  wrote:
> >
> > Modify the VKMS driver into an api that dce_virtual can use to create
> > virtual displays that obey drm's atomic modesetting api.
> >
> > v2: Made local functions static.
> >
> > Reported-by: kernel test robot 
> > Signed-off-by: Ryan Taylor 
> > ---
> >  drivers/gpu/drm/amd/amdgpu/Makefile  |   1 +
> >  drivers/gpu/drm/amd/amdgpu/amdgpu.h  |   1 +
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  |   2 +-
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   |   2 +-
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 411
> > +++  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h |
> > 29 ++  drivers/gpu/drm/amd/amdgpu/dce_virtual.c |  23 +-
> >  7 files changed, 458 insertions(+), 11 deletions(-)  create mode
> > 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> >  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
> > b/drivers/gpu/drm/amd/amdgpu/Makefile
> > index f089794bbdd5..30cbcd5ce1cc 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> > +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> > @@ -120,6 +120,7 @@ amdgpu-y += \
> >  amdgpu-y += \
> > dce_v10_0.o \
> > dce_v11_0.o \
> > +   amdgpu_vkms.o \
> > dce_virtual.o
> >
> >  # add GFX block
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > index 54cf647bd018..d0a2f2ed433d 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > @@ -919,6 +919,7 @@ struct amdgpu_device {
> >
> > /* display */
> > boolenable_virtual_display;
> > +   struct amdgpu_vkms_output   *amdgpu_vkms_output;
> > struct amdgpu_mode_info mode_info;
> > /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" 
> > */
> > struct work_struct  hotplug_work;
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > index d0c935cf4f0f..1b016e5bc75f 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > @@ -1230,7 +1230,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
> > int ret, retry = 0;
> > bool supports_atomic = false;
> >
> > -   if (!amdgpu_virtual_display &&
> > +   if (amdgpu_virtual_display ||
> > amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))
> > supports_atomic = true;
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > index 09b048647523..5a143ca02cf9 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > @@ -344,7 +344,7 @@ int amdgpu_fbdev_init(struct amdgpu_device *adev)
> > }
> >
> > /* disable all the possible outputs/crtcs before entering KMS mode 
> > */
> > -   if (!amdgpu_device_has_dc_support(adev))
> > +   if (!amdgpu_device_has_dc_support(adev) &&
> > + !amdgpu_virtual_display)
> >
> > drm_helper_disable_unused_functions(adev_to_drm(adev));
> >
> > drm_fb_helper_initial_config(>helper, bpp_sel); diff
> > --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> > new file mode 100644
> > index ..d5c1f1c58f5f
> > --- /dev/null
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> > @@ -0,0 +1,411 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +
> > +#include 
> > +#include  #include 
> > +
> > +#include "amdgpu.h"
> > +#include "amdgpu_vkms.h"
> > +#include "amdgpu_display.h"
> > +
> > +/*

RE: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)

2021-07-24 Thread Chen, Guchun
[Public]

Look copy right statement is missed in both amdgpu_vkms.c and amdgpu_vkms.h.

Regards,
Guchun

-Original Message-
From: amd-gfx  On Behalf Of Alex Deucher
Sent: Friday, July 23, 2021 10:32 PM
To: Taylor, Ryan 
Cc: kernel test robot ; Daniel Vetter ; 
Siqueira, Rodrigo ; amd-gfx list 
; Melissa Wen ; Maling 
list - DRI developers 
Subject: Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)

On Wed, Jul 21, 2021 at 1:07 PM Ryan Taylor  wrote:
>
> Modify the VKMS driver into an api that dce_virtual can use to create 
> virtual displays that obey drm's atomic modesetting api.
>
> v2: Made local functions static.
>
> Reported-by: kernel test robot 
> Signed-off-by: Ryan Taylor 
> ---
>  drivers/gpu/drm/amd/amdgpu/Makefile  |   1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h  |   1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  |   2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   |   2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 411 
> +++  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h |  
> 29 ++  drivers/gpu/drm/amd/amdgpu/dce_virtual.c |  23 +-
>  7 files changed, 458 insertions(+), 11 deletions(-)  create mode 
> 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
>  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
> b/drivers/gpu/drm/amd/amdgpu/Makefile
> index f089794bbdd5..30cbcd5ce1cc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> @@ -120,6 +120,7 @@ amdgpu-y += \
>  amdgpu-y += \
> dce_v10_0.o \
> dce_v11_0.o \
> +   amdgpu_vkms.o \
> dce_virtual.o
>
>  # add GFX block
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 54cf647bd018..d0a2f2ed433d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -919,6 +919,7 @@ struct amdgpu_device {
>
> /* display */
> boolenable_virtual_display;
> +   struct amdgpu_vkms_output   *amdgpu_vkms_output;
> struct amdgpu_mode_info mode_info;
> /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
> struct work_struct  hotplug_work;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index d0c935cf4f0f..1b016e5bc75f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -1230,7 +1230,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
> int ret, retry = 0;
> bool supports_atomic = false;
>
> -   if (!amdgpu_virtual_display &&
> +   if (amdgpu_virtual_display ||
> amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))
> supports_atomic = true;
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> index 09b048647523..5a143ca02cf9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> @@ -344,7 +344,7 @@ int amdgpu_fbdev_init(struct amdgpu_device *adev)
> }
>
> /* disable all the possible outputs/crtcs before entering KMS mode */
> -   if (!amdgpu_device_has_dc_support(adev))
> +   if (!amdgpu_device_has_dc_support(adev) && 
> + !amdgpu_virtual_display)
> 
> drm_helper_disable_unused_functions(adev_to_drm(adev));
>
> drm_fb_helper_initial_config(>helper, bpp_sel); diff 
> --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> new file mode 100644
> index ..d5c1f1c58f5f
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> @@ -0,0 +1,411 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +#include 
> +#include  #include 
> +
> +#include "amdgpu.h"
> +#include "amdgpu_vkms.h"
> +#include "amdgpu_display.h"
> +
> +/**
> + * DOC: amdgpu_vkms
> + *
> + * The amdgpu vkms interface provides a virtual KMS interface for 
> +several use
> + * cases: devices without display hardware, platforms where the 
> +actual display
> + * hardware is not useful (e.g., servers), SR-IOV virtual functions, 
> +device
> + * emulation/simulation, and device bring up prior to display 
> +hardware being
> + * usable. We previously emulated a legacy KMS interface, but there 
> +was a desire
> + * to move to the atomic KMS interface. The vkms driver did 
> +everything we
> + * needed, but we wanted KMS support natively in the driver without 
> +buffer
> + * sharing 

Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)

2021-07-23 Thread Alex Deucher
On Wed, Jul 21, 2021 at 1:07 PM Ryan Taylor  wrote:
>
> Modify the VKMS driver into an api that dce_virtual can use to create
> virtual displays that obey drm's atomic modesetting api.
>
> v2: Made local functions static.
>
> Reported-by: kernel test robot 
> Signed-off-by: Ryan Taylor 
> ---
>  drivers/gpu/drm/amd/amdgpu/Makefile  |   1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h  |   1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  |   2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   |   2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 411 +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h |  29 ++
>  drivers/gpu/drm/amd/amdgpu/dce_virtual.c |  23 +-
>  7 files changed, 458 insertions(+), 11 deletions(-)
>  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
>  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
> b/drivers/gpu/drm/amd/amdgpu/Makefile
> index f089794bbdd5..30cbcd5ce1cc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> @@ -120,6 +120,7 @@ amdgpu-y += \
>  amdgpu-y += \
> dce_v10_0.o \
> dce_v11_0.o \
> +   amdgpu_vkms.o \
> dce_virtual.o
>
>  # add GFX block
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 54cf647bd018..d0a2f2ed433d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -919,6 +919,7 @@ struct amdgpu_device {
>
> /* display */
> boolenable_virtual_display;
> +   struct amdgpu_vkms_output   *amdgpu_vkms_output;
> struct amdgpu_mode_info mode_info;
> /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
> struct work_struct  hotplug_work;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index d0c935cf4f0f..1b016e5bc75f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -1230,7 +1230,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
> int ret, retry = 0;
> bool supports_atomic = false;
>
> -   if (!amdgpu_virtual_display &&
> +   if (amdgpu_virtual_display ||
> amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))
> supports_atomic = true;
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> index 09b048647523..5a143ca02cf9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> @@ -344,7 +344,7 @@ int amdgpu_fbdev_init(struct amdgpu_device *adev)
> }
>
> /* disable all the possible outputs/crtcs before entering KMS mode */
> -   if (!amdgpu_device_has_dc_support(adev))
> +   if (!amdgpu_device_has_dc_support(adev) && !amdgpu_virtual_display)
> drm_helper_disable_unused_functions(adev_to_drm(adev));
>
> drm_fb_helper_initial_config(>helper, bpp_sel);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> new file mode 100644
> index ..d5c1f1c58f5f
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> @@ -0,0 +1,411 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +#include 
> +#include 
> +#include 
> +
> +#include "amdgpu.h"
> +#include "amdgpu_vkms.h"
> +#include "amdgpu_display.h"
> +
> +/**
> + * DOC: amdgpu_vkms
> + *
> + * The amdgpu vkms interface provides a virtual KMS interface for several use
> + * cases: devices without display hardware, platforms where the actual 
> display
> + * hardware is not useful (e.g., servers), SR-IOV virtual functions, device
> + * emulation/simulation, and device bring up prior to display hardware being
> + * usable. We previously emulated a legacy KMS interface, but there was a 
> desire
> + * to move to the atomic KMS interface. The vkms driver did everything we
> + * needed, but we wanted KMS support natively in the driver without buffer
> + * sharing and the ability to support an instance of VKMS per device. We 
> first
> + * looked at splitting vkms into a stub driver and a helper module that other
> + * drivers could use to implement a virtual display, but this strategy ended 
> up
> + * being messy due to driver specific callbacks needed for buffer management.
> + * Ultimately, it proved easier to import the vkms code as it mostly used 
> core
> + * drm helpers anyway.
> + */
> +
> +static const u32 amdgpu_vkms_formats[] = {
> +   DRM_FORMAT_XRGB,
> +};
> +
> +static enum hrtimer_restart amdgpu_vkms_vblank_simulate(struct hrtimer 
> *timer)
> +{
> +   struct amdgpu_vkms_output *output = container_of(timer,
> +struct 
> amdgpu_vkms_output,
> +

[PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)

2021-07-21 Thread Ryan Taylor
Modify the VKMS driver into an api that dce_virtual can use to create
virtual displays that obey drm's atomic modesetting api.

v2: Made local functions static.

Reported-by: kernel test robot 
Signed-off-by: Ryan Taylor 
---
 drivers/gpu/drm/amd/amdgpu/Makefile  |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h  |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 411 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h |  29 ++
 drivers/gpu/drm/amd/amdgpu/dce_virtual.c |  23 +-
 7 files changed, 458 insertions(+), 11 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index f089794bbdd5..30cbcd5ce1cc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -120,6 +120,7 @@ amdgpu-y += \
 amdgpu-y += \
dce_v10_0.o \
dce_v11_0.o \
+   amdgpu_vkms.o \
dce_virtual.o
 
 # add GFX block
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 54cf647bd018..d0a2f2ed433d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -919,6 +919,7 @@ struct amdgpu_device {
 
/* display */
boolenable_virtual_display;
+   struct amdgpu_vkms_output   *amdgpu_vkms_output;
struct amdgpu_mode_info mode_info;
/* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
struct work_struct  hotplug_work;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index d0c935cf4f0f..1b016e5bc75f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -1230,7 +1230,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
int ret, retry = 0;
bool supports_atomic = false;
 
-   if (!amdgpu_virtual_display &&
+   if (amdgpu_virtual_display ||
amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))
supports_atomic = true;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index 09b048647523..5a143ca02cf9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -344,7 +344,7 @@ int amdgpu_fbdev_init(struct amdgpu_device *adev)
}
 
/* disable all the possible outputs/crtcs before entering KMS mode */
-   if (!amdgpu_device_has_dc_support(adev))
+   if (!amdgpu_device_has_dc_support(adev) && !amdgpu_virtual_display)
drm_helper_disable_unused_functions(adev_to_drm(adev));
 
drm_fb_helper_initial_config(>helper, bpp_sel);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
new file mode 100644
index ..d5c1f1c58f5f
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
@@ -0,0 +1,411 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include 
+#include 
+#include 
+
+#include "amdgpu.h"
+#include "amdgpu_vkms.h"
+#include "amdgpu_display.h"
+
+/**
+ * DOC: amdgpu_vkms
+ *
+ * The amdgpu vkms interface provides a virtual KMS interface for several use
+ * cases: devices without display hardware, platforms where the actual display
+ * hardware is not useful (e.g., servers), SR-IOV virtual functions, device
+ * emulation/simulation, and device bring up prior to display hardware being
+ * usable. We previously emulated a legacy KMS interface, but there was a 
desire
+ * to move to the atomic KMS interface. The vkms driver did everything we
+ * needed, but we wanted KMS support natively in the driver without buffer
+ * sharing and the ability to support an instance of VKMS per device. We first
+ * looked at splitting vkms into a stub driver and a helper module that other
+ * drivers could use to implement a virtual display, but this strategy ended up
+ * being messy due to driver specific callbacks needed for buffer management.
+ * Ultimately, it proved easier to import the vkms code as it mostly used core
+ * drm helpers anyway.
+ */
+
+static const u32 amdgpu_vkms_formats[] = {
+   DRM_FORMAT_XRGB,
+};
+
+static enum hrtimer_restart amdgpu_vkms_vblank_simulate(struct hrtimer *timer)
+{
+   struct amdgpu_vkms_output *output = container_of(timer,
+struct 
amdgpu_vkms_output,
+vblank_hrtimer);
+   struct drm_crtc *crtc = >crtc;
+   u64 ret_overrun;
+   bool ret;
+
+   ret_overrun = hrtimer_forward_now(>vblank_hrtimer,
+ output->period_ns);
+   WARN_ON(ret_overrun != 1);
+
+   ret = drm_crtc_handle_vblank(crtc);
+   

Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms

2021-07-12 Thread kernel test robot
Hi Ryan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on next-20210712]
[also build test ERROR on v5.14-rc1]
[cannot apply to drm-intel/for-linux-next drm-tip/drm-tip 
drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next linus/master 
drm/drm-next v5.14-rc1 v5.13 v5.13-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Ryan-Taylor/drm-amdgpu-modernize-virtual-display-feature/20210713-034827
base:db503865b9ba6284edfee3825846a464cc4f4c61
config: x86_64-randconfig-a013-20210712 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 
8d69635ed9ecf36fd0ca85906bfde17949671cbe)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# 
https://github.com/0day-ci/linux/commit/96f64e3b91a195cc37720de206b86c3f0378abbb
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Ryan-Taylor/drm-amdgpu-modernize-virtual-display-feature/20210713-034827
git checkout 96f64e3b91a195cc37720de206b86c3f0378abbb
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All error/warnings (new ones prefixed by >>):

>> drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:156:5: warning: no previous 
>> prototype for function 'amdgpu_vkms_crtc_init' [-Wmissing-prototypes]
   int amdgpu_vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
   ^
   drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:156:1: note: declare 'static' if 
the function is not intended to be used outside of this translation unit
   int amdgpu_vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
   ^
   static 
>> drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:323:20: error: incompatible 
>> function pointer types initializing 'void (*)(struct drm_plane *, struct 
>> drm_atomic_state *)' with an expression of type 'void (struct drm_plane *, 
>> struct drm_plane_state *)' [-Werror,-Wincompatible-function-pointer-types]
   .atomic_update  = amdgpu_vkms_plane_atomic_update,
 ^~~
>> drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:324:19: error: incompatible 
>> function pointer types initializing 'int (*)(struct drm_plane *, struct 
>> drm_atomic_state *)' with an expression of type 'int (struct drm_plane *, 
>> struct drm_plane_state *)' [-Werror,-Wincompatible-function-pointer-types]
   .atomic_check   = amdgpu_vkms_plane_atomic_check,
 ^~
>> drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:329:19: warning: no previous 
>> prototype for function 'amdgpu_vkms_plane_init' [-Wmissing-prototypes]
   struct drm_plane *amdgpu_vkms_plane_init(struct drm_device *dev,
 ^
   drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:329:1: note: declare 'static' if 
the function is not intended to be used outside of this translation unit
   struct drm_plane *amdgpu_vkms_plane_init(struct drm_device *dev,
   ^
   static 
   2 warnings and 2 errors generated.


vim +323 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c

   155  
 > 156  int amdgpu_vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
   157struct drm_plane *primary, struct drm_plane 
*cursor)
   158  {
   159  int ret;
   160  
   161  ret = drm_crtc_init_with_planes(dev, crtc, primary, cursor,
   162  _vkms_crtc_funcs, NULL);
   163  if (ret) {
   164  DRM_ERROR("Failed to init CRTC\n");
   165  return ret;
   166  }
   167  
   168  drm_crtc_helper_add(crtc, _vkms_crtc_helper_funcs);
   169  
   170  return ret;
   171  }
   172  
   173  static const struct drm_connector_funcs amdgpu_vkms_connector_funcs = {
   174  .fill_modes = drm_helper_probe_single_connector_modes,
   175  .destroy = drm_connector_cleanup,
   176  .reset = drm_atomic_helper_connector_reset,
   177  .atomic_duplicate_state = 
drm_atomic_helper_connector_duplicate_state,
   178  .atomic_destroy_state = 
drm_atomic_helper_connector_destroy_state,
   179  };
   180  
   181  static int amdgpu_vkms_conn_get_modes(struct drm_connector *connector)
   182  {
   183  int count;
   184  
   185  count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
   186  

Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms

2021-07-12 Thread kernel test robot
Hi Ryan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on next-20210712]
[also build test WARNING on v5.14-rc1]
[cannot apply to drm-intel/for-linux-next drm-tip/drm-tip 
drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next linus/master 
drm/drm-next v5.14-rc1 v5.13 v5.13-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Ryan-Taylor/drm-amdgpu-modernize-virtual-display-feature/20210713-034827
base:db503865b9ba6284edfee3825846a464cc4f4c61
config: i386-randconfig-r013-20210712 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# 
https://github.com/0day-ci/linux/commit/96f64e3b91a195cc37720de206b86c3f0378abbb
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Ryan-Taylor/drm-amdgpu-modernize-virtual-display-feature/20210713-034827
git checkout 96f64e3b91a195cc37720de206b86c3f0378abbb
# save the attached .config to linux build tree
make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:156:5: warning: no previous 
>> prototype for 'amdgpu_vkms_crtc_init' [-Wmissing-prototypes]
 156 | int amdgpu_vkms_crtc_init(struct drm_device *dev, struct drm_crtc 
*crtc,
 | ^
   drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:323:20: error: initialization of 
'void (*)(struct drm_plane *, struct drm_atomic_state *)' from incompatible 
pointer type 'void (*)(struct drm_plane *, struct drm_plane_state *)' 
[-Werror=incompatible-pointer-types]
 323 |  .atomic_update  = amdgpu_vkms_plane_atomic_update,
 |^~~
   drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:323:20: note: (near initialization 
for 'amdgpu_vkms_primary_helper_funcs.atomic_update')
   drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:324:19: error: initialization of 
'int (*)(struct drm_plane *, struct drm_atomic_state *)' from incompatible 
pointer type 'int (*)(struct drm_plane *, struct drm_plane_state *)' 
[-Werror=incompatible-pointer-types]
 324 |  .atomic_check  = amdgpu_vkms_plane_atomic_check,
 |   ^~
   drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:324:19: note: (near initialization 
for 'amdgpu_vkms_primary_helper_funcs.atomic_check')
>> drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c:329:19: warning: no previous 
>> prototype for 'amdgpu_vkms_plane_init' [-Wmissing-prototypes]
 329 | struct drm_plane *amdgpu_vkms_plane_init(struct drm_device *dev,
 |   ^~
   cc1: some warnings being treated as errors


vim +/amdgpu_vkms_crtc_init +156 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c

   155  
 > 156  int amdgpu_vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
   157struct drm_plane *primary, struct drm_plane 
*cursor)
   158  {
   159  int ret;
   160  
   161  ret = drm_crtc_init_with_planes(dev, crtc, primary, cursor,
   162  _vkms_crtc_funcs, NULL);
   163  if (ret) {
   164  DRM_ERROR("Failed to init CRTC\n");
   165  return ret;
   166  }
   167  
   168  drm_crtc_helper_add(crtc, _vkms_crtc_helper_funcs);
   169  
   170  return ret;
   171  }
   172  
   173  static const struct drm_connector_funcs amdgpu_vkms_connector_funcs = {
   174  .fill_modes = drm_helper_probe_single_connector_modes,
   175  .destroy = drm_connector_cleanup,
   176  .reset = drm_atomic_helper_connector_reset,
   177  .atomic_duplicate_state = 
drm_atomic_helper_connector_duplicate_state,
   178  .atomic_destroy_state = 
drm_atomic_helper_connector_destroy_state,
   179  };
   180  
   181  static int amdgpu_vkms_conn_get_modes(struct drm_connector *connector)
   182  {
   183  int count;
   184  
   185  count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
   186  drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
   187  
   188  return count;
   189  }
   190  
   191  static const struct drm_connector_helper_funcs 
amdgpu_vkms_conn_helper_funcs = {
   192  .get_modes= amdgpu_vkms_conn_get_modes,
   193  };
   194  
   195  static const struct drm_plane_funcs amdgpu_vkms_plane_funcs = {
   196  .update_plane   = drm_atomic_helper_update_plane,
   197  .disable_plane  = drm_atomic_helper_disable_plane,
   198  .destroy= drm_plane_cleanup,
   199  .reset  = 

[PATCH 1/3] drm/amdgpu: create amdgpu_vkms

2021-07-12 Thread Ryan Taylor
Modify the VKMS driver into an api that dce_virtual can use to create
virtual displays that obey drm's atomic modesetting api.

Signed-off-by: Ryan Taylor 
---
 drivers/gpu/drm/amd/amdgpu/Makefile  |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h  |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 410 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h |  29 ++
 drivers/gpu/drm/amd/amdgpu/dce_virtual.c |  23 +-
 7 files changed, 457 insertions(+), 11 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 7d292485ca7c..dfcf3b39a2f6 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -119,6 +119,7 @@ amdgpu-y += \
 amdgpu-y += \
dce_v10_0.o \
dce_v11_0.o \
+   amdgpu_vkms.o \
dce_virtual.o
 
 # add GFX block
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index d14b4968a026..a0198963fc8a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -912,6 +912,7 @@ struct amdgpu_device {
 
/* display */
boolenable_virtual_display;
+   struct amdgpu_vkms_output   *amdgpu_vkms_output;
struct amdgpu_mode_info mode_info;
/* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
struct work_struct  hotplug_work;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 179f2d01a082..5c774d6625e4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -1222,7 +1222,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
int ret, retry = 0;
bool supports_atomic = false;
 
-   if (!amdgpu_virtual_display &&
+   if (amdgpu_virtual_display ||
amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))
supports_atomic = true;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index 09b048647523..5a143ca02cf9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -344,7 +344,7 @@ int amdgpu_fbdev_init(struct amdgpu_device *adev)
}
 
/* disable all the possible outputs/crtcs before entering KMS mode */
-   if (!amdgpu_device_has_dc_support(adev))
+   if (!amdgpu_device_has_dc_support(adev) && !amdgpu_virtual_display)
drm_helper_disable_unused_functions(adev_to_drm(adev));
 
drm_fb_helper_initial_config(>helper, bpp_sel);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
new file mode 100644
index ..58bd0d7b4602
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
@@ -0,0 +1,410 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include 
+#include 
+#include 
+
+#include "amdgpu.h"
+#include "amdgpu_vkms.h"
+#include "amdgpu_display.h"
+
+/**
+ * DOC: amdgpu_vkms
+ *
+ * The amdgpu vkms interface provides a virtual KMS interface for several use
+ * cases: devices without display hardware, platforms where the actual display
+ * hardware is not useful (e.g., servers), SR-IOV virtual functions, device
+ * emulation/simulation, and device bring up prior to display hardware being
+ * usable. We previously emulated a legacy KMS interface, but there was a 
desire
+ * to move to the atomic KMS interface. The vkms driver did everything we
+ * needed, but we wanted KMS support natively in the driver without buffer
+ * sharing and the ability to support an instance of VKMS per device. We first
+ * looked at splitting vkms into a stub driver and a helper module that other
+ * drivers could use to implement a virtual display, but this strategy ended up
+ * being messy due to driver specific callbacks needed for buffer management.
+ * Ultimately, it proved easier to import the vkms code as it mostly used core
+ * drm helpers anyway.
+ */
+
+static const u32 amdgpu_vkms_formats[] = {
+   DRM_FORMAT_XRGB,
+};
+
+static enum hrtimer_restart amdgpu_vkms_vblank_simulate(struct hrtimer *timer)
+{
+   struct amdgpu_vkms_output *output = container_of(timer,
+struct 
amdgpu_vkms_output,
+vblank_hrtimer);
+   struct drm_crtc *crtc = >crtc;
+   u64 ret_overrun;
+   bool ret;
+
+   ret_overrun = hrtimer_forward_now(>vblank_hrtimer,
+ output->period_ns);
+   WARN_ON(ret_overrun != 1);
+
+   ret = drm_crtc_handle_vblank(crtc);
+   if (!ret)
+   DRM_ERROR("amdgpu_vkms failure on