<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
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?</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Best,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Ryan<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Alex Deucher <alexdeucher@gmail.com><br>
<b>Sent:</b> Monday, July 26, 2021 9:21 AM<br>
<b>To:</b> Chen, Guchun <Guchun.Chen@amd.com><br>
<b>Cc:</b> Taylor, Ryan <Ryan.Taylor@amd.com>; kernel test robot <lkp@intel.com>; Daniel Vetter <daniel.vetter@ffwll.ch>; Siqueira, Rodrigo <Rodrigo.Siqueira@amd.com>; amd-gfx list <amd-gfx@lists.freedesktop.org>; Melissa Wen <melissa.srw@gmail.com>; Maling
 list - DRI developers <dri-devel@lists.freedesktop.org><br>
<b>Subject:</b> Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On Fri, Jul 23, 2021 at 10:07 PM Chen, Guchun <Guchun.Chen@amd.com> wrote:<br>
><br>
> [Public]<br>
><br>
> Look copy right statement is missed in both amdgpu_vkms.c and amdgpu_vkms.h.<br>
<br>
It's there, it just uses the newer SPDX license identifier.<br>
<br>
Alex<br>
<br>
<br>
><br>
> Regards,<br>
> Guchun<br>
><br>
> -----Original Message-----<br>
> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Alex Deucher<br>
> Sent: Friday, July 23, 2021 10:32 PM<br>
> To: Taylor, Ryan <Ryan.Taylor@amd.com><br>
> Cc: kernel test robot <lkp@intel.com>; Daniel Vetter <daniel.vetter@ffwll.ch>; Siqueira, Rodrigo <Rodrigo.Siqueira@amd.com>; amd-gfx list <amd-gfx@lists.freedesktop.org>; Melissa Wen <melissa.srw@gmail.com>; Maling list - DRI developers <dri-devel@lists.freedesktop.org><br>
> Subject: Re: [PATCH 1/3] drm/amdgpu: create amdgpu_vkms (v2)<br>
><br>
> On Wed, Jul 21, 2021 at 1:07 PM Ryan Taylor <Ryan.Taylor@amd.com> wrote:<br>
> ><br>
> > Modify the VKMS driver into an api that dce_virtual can use to create<br>
> > virtual displays that obey drm's atomic modesetting api.<br>
> ><br>
> > v2: Made local functions static.<br>
> ><br>
> > Reported-by: kernel test robot <lkp@intel.com><br>
> > Signed-off-by: Ryan Taylor <Ryan.Taylor@amd.com><br>
> > ---<br>
> >  drivers/gpu/drm/amd/amdgpu/Makefile      |   1 +<br>
> >  drivers/gpu/drm/amd/amdgpu/amdgpu.h      |   1 +<br>
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  |   2 +-<br>
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   |   2 +-<br>
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 411<br>
> > +++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h |<br>
> > 29 ++  drivers/gpu/drm/amd/amdgpu/dce_virtual.c |  23 +-<br>
> >  7 files changed, 458 insertions(+), 11 deletions(-)  create mode<br>
> > 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c<br>
> >  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h<br>
> ><br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile<br>
> > b/drivers/gpu/drm/amd/amdgpu/Makefile<br>
> > index f089794bbdd5..30cbcd5ce1cc 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/Makefile<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/Makefile<br>
> > @@ -120,6 +120,7 @@ amdgpu-y += \<br>
> >  amdgpu-y += \<br>
> >         dce_v10_0.o \<br>
> >         dce_v11_0.o \<br>
> > +       amdgpu_vkms.o \<br>
> >         dce_virtual.o<br>
> ><br>
> >  # add GFX block<br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> > index 54cf647bd018..d0a2f2ed433d 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> > @@ -919,6 +919,7 @@ struct amdgpu_device {<br>
> ><br>
> >         /* display */<br>
> >         bool                            enable_virtual_display;<br>
> > +       struct amdgpu_vkms_output       *amdgpu_vkms_output;<br>
> >         struct amdgpu_mode_info         mode_info;<br>
> >         /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */<br>
> >         struct work_struct              hotplug_work;<br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
> > index d0c935cf4f0f..1b016e5bc75f 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
> > @@ -1230,7 +1230,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,<br>
> >         int ret, retry = 0;<br>
> >         bool supports_atomic = false;<br>
> ><br>
> > -       if (!amdgpu_virtual_display &&<br>
> > +       if (amdgpu_virtual_display ||<br>
> >             amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))<br>
> >                 supports_atomic = true;<br>
> ><br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c<br>
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c<br>
> > index 09b048647523..5a143ca02cf9 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c<br>
> > @@ -344,7 +344,7 @@ int amdgpu_fbdev_init(struct amdgpu_device *adev)<br>
> >         }<br>
> ><br>
> >         /* disable all the possible outputs/crtcs before entering KMS mode */<br>
> > -       if (!amdgpu_device_has_dc_support(adev))<br>
> > +       if (!amdgpu_device_has_dc_support(adev) &&<br>
> > + !amdgpu_virtual_display)<br>
> ><br>
> > drm_helper_disable_unused_functions(adev_to_drm(adev));<br>
> ><br>
> >         drm_fb_helper_initial_config(&rfbdev->helper, bpp_sel); diff<br>
> > --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c<br>
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c<br>
> > new file mode 100644<br>
> > index 000000000000..d5c1f1c58f5f<br>
> > --- /dev/null<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c<br>
> > @@ -0,0 +1,411 @@<br>
> > +// SPDX-License-Identifier: GPL-2.0+<br>
> > +<br>
> > +#include <drm/drm_atomic_helper.h><br>
> > +#include <drm/drm_simple_kms_helper.h> #include <drm/drm_vblank.h><br>
> > +<br>
> > +#include "amdgpu.h"<br>
> > +#include "amdgpu_vkms.h"<br>
> > +#include "amdgpu_display.h"<br>
> > +<br>
> > +/**<br>
> > + * DOC: amdgpu_vkms<br>
> > + *<br>
> > + * The amdgpu vkms interface provides a virtual KMS interface for<br>
> > +several use<br>
> > + * cases: devices without display hardware, platforms where the<br>
> > +actual display<br>
> > + * hardware is not useful (e.g., servers), SR-IOV virtual functions,<br>
> > +device<br>
> > + * emulation/simulation, and device bring up prior to display<br>
> > +hardware being<br>
> > + * usable. We previously emulated a legacy KMS interface, but there<br>
> > +was a desire<br>
> > + * to move to the atomic KMS interface. The vkms driver did<br>
> > +everything we<br>
> > + * needed, but we wanted KMS support natively in the driver without<br>
> > +buffer<br>
> > + * sharing and the ability to support an instance of VKMS per device.<br>
> > +We first<br>
> > + * looked at splitting vkms into a stub driver and a helper module<br>
> > +that other<br>
> > + * drivers could use to implement a virtual display, but this<br>
> > +strategy ended up<br>
> > + * being messy due to driver specific callbacks needed for buffer management.<br>
> > + * Ultimately, it proved easier to import the vkms code as it mostly<br>
> > +used core<br>
> > + * drm helpers anyway.<br>
> > + */<br>
> > +<br>
> > +static const u32 amdgpu_vkms_formats[] = {<br>
> > +       DRM_FORMAT_XRGB8888,<br>
> > +};<br>
> > +<br>
> > +static enum hrtimer_restart amdgpu_vkms_vblank_simulate(struct<br>
> > +hrtimer *timer) {<br>
> > +       struct amdgpu_vkms_output *output = container_of(timer,<br>
> > +                                                        struct amdgpu_vkms_output,<br>
> > +                                                        vblank_hrtimer);<br>
> > +       struct drm_crtc *crtc = &output->crtc;<br>
> > +       u64 ret_overrun;<br>
> > +       bool ret;<br>
> > +<br>
> > +       ret_overrun = hrtimer_forward_now(&output->vblank_hrtimer,<br>
> > +                                         output->period_ns);<br>
> > +       WARN_ON(ret_overrun != 1);<br>
> > +<br>
> > +       ret = drm_crtc_handle_vblank(crtc);<br>
> > +       if (!ret)<br>
> > +               DRM_ERROR("amdgpu_vkms failure on handling vblank");<br>
> > +<br>
> > +       return HRTIMER_RESTART;<br>
> > +}<br>
> > +<br>
> > +static int amdgpu_vkms_enable_vblank(struct drm_crtc *crtc) {<br>
> > +       struct drm_device *dev = crtc->dev;<br>
> > +       unsigned int pipe = drm_crtc_index(crtc);<br>
> > +       struct drm_vblank_crtc *vblank = &dev->vblank[pipe];<br>
> > +       struct amdgpu_vkms_output *out =<br>
> > +drm_crtc_to_amdgpu_vkms_output(crtc);<br>
> > +<br>
> > +       drm_calc_timestamping_constants(crtc, &crtc->mode);<br>
> > +<br>
> > +       hrtimer_init(&out->vblank_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);<br>
> > +       out->vblank_hrtimer.function = &amdgpu_vkms_vblank_simulate;<br>
> > +       out->period_ns = ktime_set(0, vblank->framedur_ns);<br>
> > +       hrtimer_start(&out->vblank_hrtimer, out->period_ns,<br>
> > + HRTIMER_MODE_REL);<br>
> > +<br>
> > +       return 0;<br>
> > +}<br>
> > +<br>
> > +static void amdgpu_vkms_disable_vblank(struct drm_crtc *crtc) {<br>
> > +       struct amdgpu_vkms_output *out =<br>
> > +drm_crtc_to_amdgpu_vkms_output(crtc);<br>
> > +<br>
> > +       hrtimer_cancel(&out->vblank_hrtimer);<br>
> > +}<br>
> > +<br>
> > +static bool amdgpu_vkms_get_vblank_timestamp(struct drm_crtc *crtc,<br>
> > +                                            int *max_error,<br>
> > +                                            ktime_t *vblank_time,<br>
> > +                                            bool in_vblank_irq) {<br>
> > +       struct drm_device *dev = crtc->dev;<br>
> > +       unsigned int pipe = crtc->index;<br>
> > +       struct amdgpu_vkms_output *output = drm_crtc_to_amdgpu_vkms_output(crtc);<br>
> > +       struct drm_vblank_crtc *vblank = &dev->vblank[pipe];<br>
> > +<br>
> > +       if (!READ_ONCE(vblank->enabled)) {<br>
> > +               *vblank_time = ktime_get();<br>
> > +               return true;<br>
> > +       }<br>
> > +<br>
> > +       *vblank_time = READ_ONCE(output->vblank_hrtimer.node.expires);<br>
> > +<br>
> > +       if (WARN_ON(*vblank_time == vblank->time))<br>
> > +               return true;<br>
> > +<br>
> > +       /*<br>
> > +        * To prevent races we roll the hrtimer forward before we do any<br>
> > +        * interrupt processing - this is how real hw works (the interrupt is<br>
> > +        * only generated after all the vblank registers are updated) and what<br>
> > +        * the vblank core expects. Therefore we need to always correct the<br>
> > +        * timestampe by one frame.<br>
> > +        */<br>
> > +       *vblank_time -= output->period_ns;<br>
> > +<br>
> > +       return true;<br>
> > +}<br>
> > +<br>
> > +static const struct drm_crtc_funcs amdgpu_vkms_crtc_funcs = {<br>
> > +       .set_config             = drm_atomic_helper_set_config,<br>
> > +       .destroy                = drm_crtc_cleanup,<br>
> > +       .page_flip              = drm_atomic_helper_page_flip,<br>
> > +       .reset                  = drm_atomic_helper_crtc_reset,<br>
> > +       .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,<br>
> > +       .atomic_destroy_state   = drm_atomic_helper_crtc_destroy_state,<br>
> > +       .enable_vblank          = amdgpu_vkms_enable_vblank,<br>
> > +       .disable_vblank         = amdgpu_vkms_disable_vblank,<br>
> > +       .get_vblank_timestamp   = amdgpu_vkms_get_vblank_timestamp,<br>
> > +};<br>
> > +<br>
> > +static void amdgpu_vkms_crtc_atomic_enable(struct drm_crtc *crtc,<br>
> > +                                          struct drm_atomic_state<br>
> > +*state) {<br>
> > +       drm_crtc_vblank_on(crtc);<br>
> > +}<br>
> > +<br>
> > +static void amdgpu_vkms_crtc_atomic_disable(struct drm_crtc *crtc,<br>
> > +                                           struct drm_atomic_state<br>
> > +*state) {<br>
> > +       drm_crtc_vblank_off(crtc);<br>
> > +}<br>
> > +<br>
> > +static void amdgpu_vkms_crtc_atomic_flush(struct drm_crtc *crtc,<br>
> > +                                         struct drm_atomic_state<br>
> > +*state) {<br>
> > +       if (crtc->state->event) {<br>
> > +               spin_lock(&crtc->dev->event_lock);<br>
> > +<br>
> > +               if (drm_crtc_vblank_get(crtc) != 0)<br>
> > +                       drm_crtc_send_vblank_event(crtc, crtc->state->event);<br>
> > +               else<br>
> > +                       drm_crtc_arm_vblank_event(crtc,<br>
> > + crtc->state->event);<br>
> > +<br>
> > +               spin_unlock(&crtc->dev->event_lock);<br>
> > +<br>
> > +               crtc->state->event = NULL;<br>
> > +       }<br>
> > +}<br>
> > +<br>
> > +static const struct drm_crtc_helper_funcs amdgpu_vkms_crtc_helper_funcs = {<br>
> > +       .atomic_flush   = amdgpu_vkms_crtc_atomic_flush,<br>
> > +       .atomic_enable  = amdgpu_vkms_crtc_atomic_enable,<br>
> > +       .atomic_disable = amdgpu_vkms_crtc_atomic_disable, };<br>
> > +<br>
> > +static int amdgpu_vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,<br>
> > +                         struct drm_plane *primary, struct drm_plane<br>
> > +*cursor) {<br>
> > +       int ret;<br>
> > +<br>
> > +       ret = drm_crtc_init_with_planes(dev, crtc, primary, cursor,<br>
> > +                                       &amdgpu_vkms_crtc_funcs, NULL);<br>
> > +       if (ret) {<br>
> > +               DRM_ERROR("Failed to init CRTC\n");<br>
> > +               return ret;<br>
> > +       }<br>
> > +<br>
> > +       drm_crtc_helper_add(crtc, &amdgpu_vkms_crtc_helper_funcs);<br>
> > +<br>
> > +       return ret;<br>
> > +}<br>
> > +<br>
> > +static const struct drm_connector_funcs amdgpu_vkms_connector_funcs = {<br>
> > +       .fill_modes = drm_helper_probe_single_connector_modes,<br>
> > +       .destroy = drm_connector_cleanup,<br>
> > +       .reset = drm_atomic_helper_connector_reset,<br>
> > +       .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,<br>
> > +       .atomic_destroy_state =<br>
> > +drm_atomic_helper_connector_destroy_state,<br>
> > +};<br>
> > +<br>
> > +static int amdgpu_vkms_conn_get_modes(struct drm_connector<br>
> > +*connector) {<br>
> > +       int count;<br>
> > +<br>
> > +       count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);<br>
> > +       drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);<br>
> > +<br>
> > +       return count;<br>
> > +}<br>
> > +<br>
> > +static const struct drm_connector_helper_funcs amdgpu_vkms_conn_helper_funcs = {<br>
> > +       .get_modes    = amdgpu_vkms_conn_get_modes,<br>
> > +};<br>
> > +<br>
> > +static const struct drm_plane_funcs amdgpu_vkms_plane_funcs = {<br>
> > +       .update_plane           = drm_atomic_helper_update_plane,<br>
> > +       .disable_plane          = drm_atomic_helper_disable_plane,<br>
> > +       .destroy                = drm_plane_cleanup,<br>
> > +       .reset                  = drm_atomic_helper_plane_reset,<br>
> > +       .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,<br>
> > +       .atomic_destroy_state   = drm_atomic_helper_plane_destroy_state,<br>
> > +};<br>
> > +<br>
> > +static void amdgpu_vkms_plane_atomic_update(struct drm_plane *plane,<br>
> > +                                           struct drm_plane_state<br>
> > +*old_state) {<br>
> > +       return;<br>
> > +}<br>
> > +<br>
> > +static int amdgpu_vkms_plane_atomic_check(struct drm_plane *plane,<br>
> > +                                         struct drm_plane_state<br>
> > +*state) {<br>
> > +       struct drm_crtc_state *crtc_state;<br>
> > +       bool can_position = false;<br>
> > +       int ret;<br>
> > +<br>
> > +       if (!state->fb || WARN_ON(!state->crtc))<br>
> > +               return 0;<br>
> > +<br>
> > +       crtc_state = drm_atomic_get_crtc_state(state->state, state->crtc);<br>
> > +       if (IS_ERR(crtc_state))<br>
> > +               return PTR_ERR(crtc_state);<br>
> > +<br>
> > +       ret = drm_atomic_helper_check_plane_state(state, crtc_state,<br>
> > +                                                 DRM_PLANE_HELPER_NO_SCALING,<br>
> > +                                                 DRM_PLANE_HELPER_NO_SCALING,<br>
> > +                                                 can_position, true);<br>
> > +       if (ret != 0)<br>
> > +               return ret;<br>
> > +<br>
> > +       /* for now primary plane must be visible and full screen */<br>
> > +       if (!state->visible && !can_position)<br>
> > +               return -EINVAL;<br>
> > +<br>
> > +       return 0;<br>
> > +}<br>
> > +<br>
> > +static int amdgpu_vkms_prepare_fb(struct drm_plane *plane,<br>
> > +                                 struct drm_plane_state *new_state) {<br>
> > +       struct amdgpu_framebuffer *afb;<br>
> > +       struct drm_gem_object *obj;<br>
> > +       struct amdgpu_device *adev;<br>
> > +       struct amdgpu_bo *rbo;<br>
> > +       struct list_head list;<br>
> > +       struct ttm_validate_buffer tv;<br>
> > +       struct ww_acquire_ctx ticket;<br>
> > +       uint32_t domain;<br>
> > +       int r;<br>
> > +<br>
> > +       if (!new_state->fb) {<br>
> > +               DRM_DEBUG_KMS("No FB bound\n");<br>
> > +               return 0;<br>
> > +       }<br>
> > +       afb = to_amdgpu_framebuffer(new_state->fb);<br>
> > +       obj = new_state->fb->obj[0];<br>
> > +       rbo = gem_to_amdgpu_bo(obj);<br>
> > +       adev = amdgpu_ttm_adev(rbo->tbo.bdev);<br>
> > +       INIT_LIST_HEAD(&list);<br>
> > +<br>
> > +       tv.bo = &rbo->tbo;<br>
> > +       tv.num_shared = 1;<br>
> > +       list_add(&tv.head, &list);<br>
> > +<br>
> > +       r = ttm_eu_reserve_buffers(&ticket, &list, false, NULL);<br>
> > +       if (r) {<br>
> > +               dev_err(adev->dev, "fail to reserve bo (%d)\n", r);<br>
> > +               return r;<br>
> > +       }<br>
> > +<br>
> > +       if (plane->type != DRM_PLANE_TYPE_CURSOR)<br>
> > +               domain = amdgpu_display_supported_domains(adev, rbo->flags);<br>
> > +       else<br>
> > +               domain = AMDGPU_GEM_DOMAIN_VRAM;<br>
> > +<br>
> > +       r = amdgpu_bo_pin(rbo, domain);<br>
> > +       if (unlikely(r != 0)) {<br>
> > +               if (r != -ERESTARTSYS)<br>
> > +                       DRM_ERROR("Failed to pin framebuffer with error %d\n", r);<br>
> > +               ttm_eu_backoff_reservation(&ticket, &list);<br>
> > +               return r;<br>
> > +       }<br>
> > +<br>
> > +       r = amdgpu_ttm_alloc_gart(&rbo->tbo);<br>
> > +       if (unlikely(r != 0)) {<br>
> > +               amdgpu_bo_unpin(rbo);<br>
> > +               ttm_eu_backoff_reservation(&ticket, &list);<br>
> > +               DRM_ERROR("%p bind failed\n", rbo);<br>
> > +               return r;<br>
> > +       }<br>
> > +<br>
> > +       ttm_eu_backoff_reservation(&ticket, &list);<br>
> > +<br>
> > +       afb->address = amdgpu_bo_gpu_offset(rbo);<br>
> > +<br>
> > +       amdgpu_bo_ref(rbo);<br>
> > +<br>
> > +       return 0;<br>
> > +}<br>
> > +<br>
> > +static void amdgpu_vkms_cleanup_fb(struct drm_plane *plane,<br>
> > +                                  struct drm_plane_state *old_state)<br>
> > +{<br>
> > +       struct amdgpu_bo *rbo;<br>
> > +       int r;<br>
> > +<br>
> > +       if (!old_state->fb)<br>
> > +               return;<br>
> > +<br>
> > +       rbo = gem_to_amdgpu_bo(old_state->fb->obj[0]);<br>
> > +       r = amdgpu_bo_reserve(rbo, false);<br>
> > +       if (unlikely(r)) {<br>
> > +               DRM_ERROR("failed to reserve rbo before unpin\n");<br>
> > +               return;<br>
> > +       }<br>
> > +<br>
> > +       amdgpu_bo_unpin(rbo);<br>
> > +       amdgpu_bo_unreserve(rbo);<br>
> > +       amdgpu_bo_unref(&rbo);<br>
> > +}<br>
> > +<br>
> > +static const struct drm_plane_helper_funcs amdgpu_vkms_primary_helper_funcs = {<br>
> > +       .atomic_update          = amdgpu_vkms_plane_atomic_update,<br>
> > +       .atomic_check           = amdgpu_vkms_plane_atomic_check,<br>
> > +       .prepare_fb             = amdgpu_vkms_prepare_fb,<br>
> > +       .cleanup_fb             = amdgpu_vkms_cleanup_fb,<br>
> > +};<br>
> > +<br>
> > +static struct drm_plane *amdgpu_vkms_plane_init(struct drm_device *dev,<br>
> > +                                               enum drm_plane_type type,<br>
> > +                                               int index) {<br>
> > +       struct drm_plane *plane;<br>
> > +       int ret;<br>
> > +<br>
> > +       plane = kzalloc(sizeof(*plane), GFP_KERNEL);<br>
> > +       if (!plane)<br>
> > +               return ERR_PTR(-ENOMEM);<br>
> > +<br>
> > +       ret = drm_universal_plane_init(dev, plane, 1 << index,<br>
> > +                                      &amdgpu_vkms_plane_funcs,<br>
> > +                                      amdgpu_vkms_formats,<br>
> > +                                      ARRAY_SIZE(amdgpu_vkms_formats),<br>
> > +                                      NULL, type, NULL);<br>
> > +       if (ret) {<br>
> > +               kfree(plane);<br>
> > +               return ERR_PTR(ret);<br>
> > +       }<br>
> > +<br>
> > +       drm_plane_helper_add(plane,<br>
> > + &amdgpu_vkms_primary_helper_funcs);<br>
> > +<br>
> > +       return plane;<br>
> > +}<br>
> > +<br>
> > +int amdgpu_vkms_output_init(struct drm_device *dev,<br>
> > +                           struct amdgpu_vkms_output *output, int<br>
> > +index) {<br>
> > +       struct drm_connector *connector = &output->connector;<br>
> > +       struct drm_encoder *encoder = &output->encoder;<br>
> > +       struct drm_crtc *crtc = &output->crtc;<br>
> > +       struct drm_plane *primary, *cursor = NULL;<br>
> > +       int ret;<br>
> > +<br>
> > +       primary = amdgpu_vkms_plane_init(dev, DRM_PLANE_TYPE_PRIMARY, index);<br>
> > +       if (IS_ERR(primary))<br>
> > +               return PTR_ERR(primary);<br>
> > +<br>
> > +       ret = amdgpu_vkms_crtc_init(dev, crtc, primary, cursor);<br>
> > +       if (ret)<br>
> > +               goto err_crtc;<br>
> > +<br>
> > +       ret = drm_connector_init(dev, connector, &amdgpu_vkms_connector_funcs,<br>
> > +                                DRM_MODE_CONNECTOR_VIRTUAL);<br>
> > +       if (ret) {<br>
> > +               DRM_ERROR("Failed to init connector\n");<br>
> > +               goto err_connector;<br>
> > +       }<br>
> > +<br>
> > +       drm_connector_helper_add(connector,<br>
> > + &amdgpu_vkms_conn_helper_funcs);<br>
> > +<br>
> > +       ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_VIRTUAL);<br>
> > +       if (ret) {<br>
> > +               DRM_ERROR("Failed to init encoder\n");<br>
> > +               goto err_encoder;<br>
> > +       }<br>
> > +       encoder->possible_crtcs = 1 << index;<br>
> > +<br>
> > +       ret = drm_connector_attach_encoder(connector, encoder);<br>
> > +       if (ret) {<br>
> > +               DRM_ERROR("Failed to attach connector to encoder\n");<br>
> > +               goto err_attach;<br>
> > +       }<br>
> > +<br>
> > +       drm_mode_config_reset(dev);<br>
> > +<br>
> > +       return 0;<br>
> > +<br>
> > +err_attach:<br>
> > +       drm_encoder_cleanup(encoder);<br>
> > +<br>
> > +err_encoder:<br>
> > +       drm_connector_cleanup(connector);<br>
> > +<br>
> > +err_connector:<br>
> > +       drm_crtc_cleanup(crtc);<br>
> > +<br>
> > +err_crtc:<br>
> > +       drm_plane_cleanup(primary);<br>
> > +<br>
> > +       return ret;<br>
> > +}<br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h<br>
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h<br>
> > new file mode 100644<br>
> > index 000000000000..5dab51fbecf3<br>
> > --- /dev/null<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h<br>
> > @@ -0,0 +1,29 @@<br>
> > +/* SPDX-License-Identifier: GPL-2.0+ */<br>
> > +<br>
> > +#ifndef _AMDGPU_VKMS_H_<br>
> > +#define _AMDGPU_VKMS_H_<br>
> > +<br>
> > +#define XRES_DEF  1024<br>
> > +#define YRES_DEF   764<br>
><br>
> Squash in the 768 fix here.<br>
><br>
> > +<br>
> > +#define XRES_MAX  16384<br>
> > +#define YRES_MAX  16384<br>
> > +<br>
> > +#define drm_crtc_to_amdgpu_vkms_output(target) \<br>
> > +       container_of(target, struct amdgpu_vkms_output, crtc)<br>
> > +<br>
> > +extern const struct amdgpu_ip_block_version amdgpu_vkms_ip_block;<br>
> > +<br>
> > +struct amdgpu_vkms_output {<br>
> > +       struct drm_crtc crtc;<br>
> > +       struct drm_encoder encoder;<br>
> > +       struct drm_connector connector;<br>
> > +       struct hrtimer vblank_hrtimer;<br>
> > +       ktime_t period_ns;<br>
> > +       struct drm_pending_vblank_event *event; };<br>
> > +<br>
> > +int amdgpu_vkms_output_init(struct drm_device *dev,<br>
> > +                           struct amdgpu_vkms_output *output, int<br>
> > +index);<br>
> > +<br>
> > +#endif /* _AMDGPU_VKMS_H_ */<br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/dce_virtual.c<br>
> > b/drivers/gpu/drm/amd/amdgpu/dce_virtual.c<br>
> > index 7e0d8c092c7e..642c77533157 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/dce_virtual.c<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/dce_virtual.c<br>
> > @@ -22,6 +22,7 @@<br>
> >   */<br>
> ><br>
> >  #include <drm/drm_vblank.h><br>
> > +#include <drm/drm_atomic_helper.h><br>
> ><br>
> >  #include "amdgpu.h"<br>
> >  #include "amdgpu_pm.h"<br>
> > @@ -40,6 +41,7 @@<br>
> >  #include "dce_virtual.h"<br>
> >  #include "ivsrcid/ivsrcid_vislands30.h"<br>
> >  #include "amdgpu_display.h"<br>
> > +#include "amdgpu_vkms.h"<br>
> ><br>
> >  #define DCE_VIRTUAL_VBLANK_PERIOD 16666666<br>
> ><br>
> > @@ -374,6 +376,12 @@ static const struct drm_connector_funcs dce_virtual_connector_funcs = {<br>
> >         .force = dce_virtual_force,<br>
> >  };<br>
> ><br>
> > +const struct drm_mode_config_funcs dce_virtual_mode_funcs = {<br>
> > +       .fb_create = amdgpu_display_user_framebuffer_create,<br>
> > +       .atomic_check = drm_atomic_helper_check,<br>
> > +       .atomic_commit = drm_atomic_helper_commit, };<br>
> > +<br>
> >  static int dce_virtual_sw_init(void *handle)  {<br>
> >         int r, i;<br>
> > @@ -385,10 +393,10 @@ static int dce_virtual_sw_init(void *handle)<br>
> ><br>
> >         adev_to_drm(adev)->max_vblank_count = 0;<br>
> ><br>
> > -       adev_to_drm(adev)->mode_config.funcs = &amdgpu_mode_funcs;<br>
> > +       adev_to_drm(adev)->mode_config.funcs =<br>
> > + &dce_virtual_mode_funcs;<br>
> ><br>
> > -       adev_to_drm(adev)->mode_config.max_width = 16384;<br>
> > -       adev_to_drm(adev)->mode_config.max_height = 16384;<br>
> > +       adev_to_drm(adev)->mode_config.max_width = XRES_MAX;<br>
> > +       adev_to_drm(adev)->mode_config.max_height = YRES_MAX;<br>
> ><br>
> >         adev_to_drm(adev)->mode_config.preferred_depth = 24;<br>
> >         adev_to_drm(adev)->mode_config.prefer_shadow = 1; @@ -399,15<br>
> > +407,11 @@ static int dce_virtual_sw_init(void *handle)<br>
> >         if (r)<br>
> >                 return r;<br>
> ><br>
> > -       adev_to_drm(adev)->mode_config.max_width = 16384;<br>
> > -       adev_to_drm(adev)->mode_config.max_height = 16384;<br>
> > +       adev->amdgpu_vkms_output = kzalloc(sizeof(struct<br>
> > + amdgpu_vkms_output) * adev->mode_info.num_crtc, GFP_KERNEL);<br>
><br>
> You can use kcalloc here.<br>
><br>
> ><br>
> >         /* allocate crtcs, encoders, connectors */<br>
> >         for (i = 0; i < adev->mode_info.num_crtc; i++) {<br>
> > -               r = dce_virtual_crtc_init(adev, i);<br>
> > -               if (r)<br>
> > -                       return r;<br>
> > -               r = dce_virtual_connector_encoder_init(adev, i);<br>
> > +               r = amdgpu_vkms_output_init(adev_to_drm(adev),<br>
> > + &adev->amdgpu_vkms_output[i], i);<br>
> >                 if (r)<br>
> >                         return r;<br>
> >         }<br>
> > @@ -428,6 +432,7 @@ static int dce_virtual_sw_fini(void *handle)<br>
> ><br>
> > hrtimer_cancel(&adev->mode_info.crtcs[i]->vblank_timer);<br>
> ><br>
> >         kfree(adev->mode_info.bios_hardcoded_edid);<br>
> > +       kfree(adev->amdgpu_vkms_output);<br>
> ><br>
> >         drm_kms_helper_poll_fini(adev_to_drm(adev));<br>
> ><br>
> > --<br>
> > 2.32.0<br>
> ><br>
> > _______________________________________________<br>
> > amd-gfx mailing list<br>
> > amd-gfx@lists.freedesktop.org<br>
> > <a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist">
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist</a><br>
> > s.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Cgu<br>
> > chun.chen%40amd.com%7Ce4b064b3485c4865df8608d94de6a58e%7C3dd8961fe4884<br>
> > e608e11a82d994e183d%7C0%7C0%7C637626475284480052%7CUnknown%7CTWFpbGZsb<br>
> > 3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%<br>
> > 7C1000&amp;sdata=0bbTKflaP2RPk%2BpboaNNiwffbEw1pW0zkqcxzPWjzmI%3D&amp;<br>
> > reserved=0<br>
> _______________________________________________<br>
> amd-gfx mailing list<br>
> amd-gfx@lists.freedesktop.org<br>
> <a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7CRyan.Taylor%40amd.com%7Ce0a16eb27da04a035cb608d950516493%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637629133975706919%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=KCe92Ic79b8lkS6h4GoZhRdhwehzleQrSH8OKlinX8I%3D&amp;reserved=0">
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7CRyan.Taylor%40amd.com%7Ce0a16eb27da04a035cb608d950516493%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637629133975706919%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=KCe92Ic79b8lkS6h4GoZhRdhwehzleQrSH8OKlinX8I%3D&amp;reserved=0</a><br>
</div>
</span></font></div>
</div>
</body>
</html>