[PATCH V6 2/2] drm/vkms: Add support for virtual hardware mode

2021-09-01 Thread Sumera Priyadarsini
Add a virtual hardware or vblank-less mode as a module
to enable VKMS to emulate virtual hardware drivers. This means
no vertical blanking events occur and pageflips are completed
arbitrarily and when required for updating the frame.

Add a new drm_crtc_funcs struct, vkms_vblankless_crtc_funcs and a
drm_crtc_helper_funcs struct, vkms_vblankless_crtc_helper_funcs()
which hold the atomic helpers for virtual hardware mode.
The existing vkms_crtc_funcs struct and vkms_crtc_helper_funcs
struct hold atomic helpers for the default vblank mode.
This makes the code flow clearer and testing
virtual hardware mode easier.

Add a function vkms_crtc_composer() which calls the helper function,
vkms_composer_common() for plane composition in vblank-less mode.
vkms_crtc_composer() is directly called in the atomic hook in
vkms_crtc_atomic_begin().

However, some crc captures still use vblanks which causes the crc-based
igt tests to crash. So, no CRC functions are called in vblankless mode
for now and will be implemented in a later patch.

This patchset has been tested with the igt tests- kms_writeback, kms_atomic
, kms_lease, kms_flip, kms_pipe_get_crc and preserves results except for
subtests related to crc reads and vertical blanking, in which case,
tests are skipped.

The patch is based on Rodrigo Siqueira's
patch(https://patchwork.freedesktop.org/patch/316851/?series=48469&rev=3)
and the ensuing review.

Signed-off-by: Sumera Priyadarsini 
---
Changes in V6:
- Skip CRC functions in vblankless mode
- Refactor helper function names(Melissa)
Changes in V5:
- Move vkms_crtc_composer() to this patch(Melissa)
- Add more clarification for "vblank-less" mode(Pekka)
- Replace kzalloc() with kvmalloc() in compose_active_planes()
to fix memory allocation error for output frame
- Fix checkpatch warnings (Melissa)
Changes in V3:
- Refactor patchset(Melissa)
Changes in V2:
- Add atomic helper functions in a separate struct for virtual hardware
mode (Daniel)
- Remove spinlock across 'vkms_output->lock' in vkms_crtc.c(Daniel)
- Add vkms_composer_common() (Daniel)
---
 drivers/gpu/drm/vkms/vkms_composer.c  | 21 +++--
 drivers/gpu/drm/vkms/vkms_crtc.c  | 43 +--
 drivers/gpu/drm/vkms/vkms_drv.c   | 16 +++---
 drivers/gpu/drm/vkms/vkms_drv.h   |  2 ++
 drivers/gpu/drm/vkms/vkms_writeback.c |  3 +-
 5 files changed, 74 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c 
b/drivers/gpu/drm/vkms/vkms_composer.c
index bca746fb5b53..a009589b2c3a 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -176,11 +176,12 @@ static int compose_active_planes(void **vaddr_out,
 {
struct drm_framebuffer *fb = &primary_composer->fb;
struct drm_gem_object *gem_obj = drm_gem_fb_get_obj(fb, 0);
+
const void *vaddr;
int i;
 
if (!*vaddr_out) {
-   *vaddr_out = kzalloc(gem_obj->size, GFP_KERNEL);
+   *vaddr_out = kvmalloc(gem_obj->size, GFP_KERNEL);
if (!*vaddr_out) {
DRM_ERROR("Cannot allocate memory for output frame.");
return -ENOMEM;
@@ -229,7 +230,7 @@ int vkms_composer_common(struct vkms_crtc_state *crtc_state,
 
if (ret) {
if ((ret == -EINVAL || ret == -ENOMEM) && !wb_pending)
-   kfree(vaddr_out);
+   kvfree(vaddr_out);
return ret;
}
 
@@ -241,7 +242,7 @@ int vkms_composer_common(struct vkms_crtc_state *crtc_state,
crtc_state->wb_pending = false;
spin_unlock_irq(&out->composer_lock);
} else {
-   kfree(vaddr_out);
+   kvfree(vaddr_out);
}
 
return 0;
@@ -296,6 +297,20 @@ void vkms_composer_worker(struct work_struct *work)
drm_crtc_add_crc_entry(crtc, true, frame_start++, &crc32);
 }
 
+void vkms_crtc_composer(struct vkms_crtc_state *crtc_state)
+{
+   struct drm_crtc *crtc = crtc_state->base.crtc;
+   struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+   u32 crc32 = 0;
+   int ret;
+
+   ret = vkms_composer_common(crtc_state, out, crtc_state->wb_pending, 
&crc32);
+   if (ret == -EINVAL)
+   return;
+
+   drm_crtc_add_crc_entry(crtc, true, 0, &crc32);
+}
+
 static const char * const pipe_crc_sources[] = {"auto"};
 
 const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 57bbd32e9beb..4a933553e0e4 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -174,6 +174,15 @@ static const struct drm_crtc_funcs vkms_crtc_funcs = {
.verify_crc_source  = vkms_verify_crc_source,
 };
 
+static const struct drm_crtc_funcs vkms_vblan

[PATCH V6 1/2] drm/vkms: Refactor vkms_composer_worker() to prep for virtual_hw mode

2021-09-01 Thread Sumera Priyadarsini
Add a new function vkms_composer_common(). The actual plane
composition work has been moved to the helper function,
vkms_composer_common() which is called by vkms_composer_worker()
and will be called in the implementation of virtual_hw mode
as well.

Signed-off-by: Sumera Priyadarsini 
---
Changes in V5:
- Move vkms_crtc_composer() to the patch that introduces
virtual_hw mode (Melissa)
- Fix checkpatch errors(Melissa)
Changes in V4:
- Fix warning
Changes in V3:
- Refactor patchset (Melissa)
Change in V2:
- Add vkms_composer_common() (Daniel)
---
 drivers/gpu/drm/vkms/vkms_composer.c | 75 
 drivers/gpu/drm/vkms/vkms_drv.h  |  2 +
 2 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c 
b/drivers/gpu/drm/vkms/vkms_composer.c
index 9e8204be9a14..bca746fb5b53 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -206,6 +206,47 @@ static int compose_active_planes(void **vaddr_out,
return 0;
 }
 
+int vkms_composer_common(struct vkms_crtc_state *crtc_state,
+struct vkms_output *out, bool wb_pending, uint32_t 
*crc32)
+{
+   struct vkms_composer *primary_composer = NULL;
+   struct vkms_plane_state *act_plane = NULL;
+   void *vaddr_out = NULL;
+   int ret;
+
+   if (crtc_state->num_active_planes >= 1) {
+   act_plane = crtc_state->active_planes[0];
+   if (act_plane->base.base.plane->type == DRM_PLANE_TYPE_PRIMARY)
+   primary_composer = act_plane->composer;
+   }
+
+   if (!primary_composer)
+   return -EINVAL;
+   if (wb_pending)
+   vaddr_out = crtc_state->active_writeback->data[0].vaddr;
+
+   ret = compose_active_planes(&vaddr_out, primary_composer, crtc_state);
+
+   if (ret) {
+   if ((ret == -EINVAL || ret == -ENOMEM) && !wb_pending)
+   kfree(vaddr_out);
+   return ret;
+   }
+
+   *crc32 = compute_crc(vaddr_out, primary_composer);
+
+   if (wb_pending) {
+   drm_writeback_signal_completion(&out->wb_connector, 0);
+   spin_lock_irq(&out->composer_lock);
+   crtc_state->wb_pending = false;
+   spin_unlock_irq(&out->composer_lock);
+   } else {
+   kfree(vaddr_out);
+   }
+
+   return 0;
+}
+
 /**
  * vkms_composer_worker - ordered work_struct to compute CRC
  *
@@ -222,10 +263,7 @@ void vkms_composer_worker(struct work_struct *work)
composer_work);
struct drm_crtc *crtc = crtc_state->base.crtc;
struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
-   struct vkms_composer *primary_composer = NULL;
-   struct vkms_plane_state *act_plane = NULL;
bool crc_pending, wb_pending;
-   void *vaddr_out = NULL;
u32 crc32 = 0;
u64 frame_start, frame_end;
int ret;
@@ -247,37 +285,10 @@ void vkms_composer_worker(struct work_struct *work)
if (!crc_pending)
return;
 
-   if (crtc_state->num_active_planes >= 1) {
-   act_plane = crtc_state->active_planes[0];
-   if (act_plane->base.base.plane->type == DRM_PLANE_TYPE_PRIMARY)
-   primary_composer = act_plane->composer;
-   }
-
-   if (!primary_composer)
+   ret = vkms_composer_common(crtc_state, out, wb_pending, &crc32);
+   if (ret == -EINVAL)
return;
 
-   if (wb_pending)
-   vaddr_out = crtc_state->active_writeback->data[0].vaddr;
-
-   ret = compose_active_planes(&vaddr_out, primary_composer,
-   crtc_state);
-   if (ret) {
-   if (ret == -EINVAL && !wb_pending)
-   kfree(vaddr_out);
-   return;
-   }
-
-   crc32 = compute_crc(vaddr_out, primary_composer);
-
-   if (wb_pending) {
-   drm_writeback_signal_completion(&out->wb_connector, 0);
-   spin_lock_irq(&out->composer_lock);
-   crtc_state->wb_pending = false;
-   spin_unlock_irq(&out->composer_lock);
-   } else {
-   kfree(vaddr_out);
-   }
-
/*
 * The worker can fall behind the vblank hrtimer, make sure we catch up.
 */
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index d48c23d40ce5..6f5f63591c20 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -137,6 +137,8 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const 
char *source_name,
   size_t *values_cnt);
 
 /* Composer Support */
+int vkms_composer_common(struct vkms_crtc_state *crtc_state, struct 
vkms_output *out,
+boo

[PATCH V6 0/2] drm/vkms: Add virtual hardware module

2021-09-01 Thread Sumera Priyadarsini
This patchset adds support for emulating virtual hardware with VKMS.
The virtual hardware mode can be enabled by using the following command
while loading the module:
sudo modprobe vkms enable_virtual_hw=1

The first patch is prep work for adding virtual_hw mode and refactors
the plane composition in vkms by adding a helper function
vkms_composer_common() which can be used for both vblank mode
and virtual mode.

The second patch adds virtual hardware support as a module option.
It adds new atomic helper functions for the virtual mode
and uses the existing atomic helpers for vblank mode
This gives us two sets of drm_crtc_funcs and drm_crtc_helper_funcs
structs for both modes, making the code flow cleaner and
easier to debug.

This patchset has been tested with the igt tests- kms_writeback, kms_atomic,
kms_lease, kms_flip, kms_pipe_get_crc and preserves results except for
subtests related to crc reads and vertical blanking, in which case,
tests are skipped.

Sumera Priyadarsini (2):
  drm/vkms: Refactor vkms_composer_worker() to prep for virtual_hw mode
  drm/vkms: Add support for virtual hardware mode

 drivers/gpu/drm/vkms/vkms_composer.c  | 92 +--
 drivers/gpu/drm/vkms/vkms_crtc.c  | 43 -
 drivers/gpu/drm/vkms/vkms_drv.c   | 16 +++--
 drivers/gpu/drm/vkms/vkms_drv.h   |  4 ++
 drivers/gpu/drm/vkms/vkms_writeback.c |  3 +-
 5 files changed, 117 insertions(+), 41 deletions(-)

-- 
2.31.1



[PATCH V5 2/2] drm/vkms: Add support for virtual hardware mode

2021-08-01 Thread Sumera Priyadarsini
Add a virtual hardware or vblank-less mode as a module
to enable VKMS to emulate virtual hardware drivers. This means
no vertical blanking events occur and pageflips are completed
arbitrarily and when required for updating the frame.

Add a new drm_crtc_helper_funcs struct,
vkms_virtual_crtc_helper_funcs() which holds the atomic helpers
for virtual hardware mode. Rename the existing
vkms_crtc_helper_funcs struct to vkms_vblank_crtc_helper_funcs
which holds atomic helpers for the vblank mode.
This makes the code flow clearer and testing
virtual hardware mode.

Add a function vkms_crtc_composer() which calls the helper function,
vkms_composer_common() for plane composition in vblank-less mode.
vkms_crtc_composer() is directly called in the atomic hook in
vkms_crtc_atomic_begin().

However, some crc captures still use vblanks which causes the crc-based
igt tests to crash. Currently, I am unsure about how to approach the
one-shot implementation of crc reads so I am still working on that.

This patchset has been tested with the igt tests- kms_writeback, kms_atomic
, kms_lease, kms_flip, kms_pipe_get_crc and preserves results except for
subtests related to crc reads and skips tests that rely on vertical
blanking.

The patch is based on Rodrigo Siqueira's
patch(https://patchwork.freedesktop.org/patch/316851/?series=48469&rev=3)
and the ensuing review.

Signed-off-by: Sumera Priyadarsini 
---
Changes in V5:
- Move vkms_crtc_composer() to this patch(Melissa)
- Add more clarification for "vblank-less" mode(Pekka)
- Replace kzalloc() with kvmalloc() in compose_active_planes()
to fix memory allocation error for output frame
- Fix checkpatch warnings (Melissa)
Changes in V3:
- Refactor patchset(Melissa)
Changes in V2:
- Add atomic helper functions in a separate struct for virtual hardware
mode (Daniel)
- Remove spinlock across 'vkms_output->lock' in vkms_crtc.c(Daniel)
- Add vkms_composer_common() (Daniel)
---
 drivers/gpu/drm/vkms/vkms_composer.c | 21 ++--
 drivers/gpu/drm/vkms/vkms_crtc.c | 51 
 drivers/gpu/drm/vkms/vkms_drv.c  | 16 ++---
 drivers/gpu/drm/vkms/vkms_drv.h  |  2 ++
 4 files changed, 69 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c 
b/drivers/gpu/drm/vkms/vkms_composer.c
index bf3d576db225..2988d5b49eb6 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -176,11 +176,12 @@ static int compose_active_planes(void **vaddr_out,
 {
struct drm_framebuffer *fb = &primary_composer->fb;
struct drm_gem_object *gem_obj = drm_gem_fb_get_obj(fb, 0);
+
const void *vaddr;
int i;
 
if (!*vaddr_out) {
-   *vaddr_out = kzalloc(gem_obj->size, GFP_KERNEL);
+   *vaddr_out = kvmalloc(gem_obj->size, GFP_KERNEL);
if (!*vaddr_out) {
DRM_ERROR("Cannot allocate memory for output frame.");
return -ENOMEM;
@@ -229,7 +230,7 @@ int vkms_composer_common(struct vkms_crtc_state *crtc_state,
 
if (ret) {
if ((ret == -EINVAL || ret == -ENOMEM) && !wb_pending)
-   kfree(vaddr_out);
+   kvfree(vaddr_out);
return ret;
}
 
@@ -241,7 +242,7 @@ int vkms_composer_common(struct vkms_crtc_state *crtc_state,
crtc_state->wb_pending = false;
spin_unlock_irq(&out->composer_lock);
} else {
-   kfree(vaddr_out);
+   kvfree(vaddr_out);
}
 
return 0;
@@ -295,6 +296,20 @@ void vkms_composer_worker(struct work_struct *work)
drm_crtc_add_crc_entry(crtc, true, frame_start++, &crc32);
 }
 
+void vkms_crtc_composer(struct vkms_crtc_state *crtc_state)
+{
+   struct drm_crtc *crtc = crtc_state->base.crtc;
+   struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+   u32 crc32 = 0;
+   int ret;
+
+   ret = vkms_composer_common(crtc_state, out, crtc_state->wb_pending, 
&crc32);
+   if (ret == -EINVAL)
+   return;
+
+   drm_crtc_add_crc_entry(crtc, true, 0, &crc32);
+}
+
 static const char * const pipe_crc_sources[] = {"auto"};
 
 const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 57bbd32e9beb..8477b33c4d09 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -222,20 +222,20 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
return 0;
 }
 
-static void vkms_crtc_atomic_enable(struct drm_crtc *crtc,
-   struct drm_atomic_state *state)
+static void vkms_vblank_crtc_atomic_enable(struct drm_crtc *crtc,
+  struct drm_atomic_state *state)

[PATCH V5 1/2] drm/vkms: Refactor vkms_composer_worker() to prep for virtual_hw mode

2021-08-01 Thread Sumera Priyadarsini
Add a new function vkms_composer_common(). The actual plane
composition work has been moved to the helper function,
vkms_composer_common() which is called by vkms_composer_worker()
and will be called in the implementation of virtual_hw mode
as well.

Signed-off-by: Sumera Priyadarsini 
---
Changes in V5:
- Move vkms_crtc_composer() to the patch that introduces
virtual_hw mode (Melissa)
- Fix checkpatch errors(Melissa)
Changes in V4:
- Fix warning
Changes in V3:
- Refactor patchset (Melissa)
Change in V2:
- Add vkms_composer_common() (Daniel)
---
 drivers/gpu/drm/vkms/vkms_composer.c | 76 
 drivers/gpu/drm/vkms/vkms_drv.h  |  2 +
 2 files changed, 45 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c 
b/drivers/gpu/drm/vkms/vkms_composer.c
index ead8fff81f30..bf3d576db225 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -206,6 +206,47 @@ static int compose_active_planes(void **vaddr_out,
return 0;
 }
 
+int vkms_composer_common(struct vkms_crtc_state *crtc_state,
+struct vkms_output *out, bool wb_pending, uint32_t 
*crc32)
+{
+   struct vkms_composer *primary_composer = NULL;
+   struct vkms_plane_state *act_plane = NULL;
+   void *vaddr_out = NULL;
+   int ret;
+
+   if (crtc_state->num_active_planes >= 1) {
+   act_plane = crtc_state->active_planes[0];
+   if (act_plane->base.base.plane->type == DRM_PLANE_TYPE_PRIMARY)
+   primary_composer = act_plane->composer;
+   }
+
+   if (!primary_composer)
+   return -EINVAL;
+   if (wb_pending)
+   vaddr_out = crtc_state->active_writeback;
+
+   ret = compose_active_planes(&vaddr_out, primary_composer, crtc_state);
+
+   if (ret) {
+   if ((ret == -EINVAL || ret == -ENOMEM) && !wb_pending)
+   kfree(vaddr_out);
+   return ret;
+   }
+
+   *crc32 = compute_crc(vaddr_out, primary_composer);
+
+   if (wb_pending) {
+   drm_writeback_signal_completion(&out->wb_connector, 0);
+   spin_lock_irq(&out->composer_lock);
+   crtc_state->wb_pending = false;
+   spin_unlock_irq(&out->composer_lock);
+   } else {
+   kfree(vaddr_out);
+   }
+
+   return 0;
+}
+
 /**
  * vkms_composer_worker - ordered work_struct to compute CRC
  *
@@ -222,10 +263,7 @@ void vkms_composer_worker(struct work_struct *work)
composer_work);
struct drm_crtc *crtc = crtc_state->base.crtc;
struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
-   struct vkms_composer *primary_composer = NULL;
-   struct vkms_plane_state *act_plane = NULL;
bool crc_pending, wb_pending;
-   void *vaddr_out = NULL;
u32 crc32 = 0;
u64 frame_start, frame_end;
int ret;
@@ -247,37 +285,9 @@ void vkms_composer_worker(struct work_struct *work)
if (!crc_pending)
return;
 
-   if (crtc_state->num_active_planes >= 1) {
-   act_plane = crtc_state->active_planes[0];
-   if (act_plane->base.base.plane->type == DRM_PLANE_TYPE_PRIMARY)
-   primary_composer = act_plane->composer;
-   }
-
-   if (!primary_composer)
-   return;
-
-   if (wb_pending)
-   vaddr_out = crtc_state->active_writeback;
-
-   ret = compose_active_planes(&vaddr_out, primary_composer,
-   crtc_state);
-   if (ret) {
-   if (ret == -EINVAL && !wb_pending)
-   kfree(vaddr_out);
+   ret = vkms_composer_common(crtc_state, out, wb_pending, &crc32);
+   if (ret == -EINVAL)
return;
-   }
-
-   crc32 = compute_crc(vaddr_out, primary_composer);
-
-   if (wb_pending) {
-   drm_writeback_signal_completion(&out->wb_connector, 0);
-   spin_lock_irq(&out->composer_lock);
-   crtc_state->wb_pending = false;
-   spin_unlock_irq(&out->composer_lock);
-   } else {
-   kfree(vaddr_out);
-   }
-
/*
 * The worker can fall behind the vblank hrtimer, make sure we catch up.
 */
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 8c731b6dcba7..01beba424f18 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -132,6 +132,8 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const 
char *source_name,
   size_t *values_cnt);
 
 /* Composer Support */
+int vkms_composer_common(struct vkms_crtc_state *crtc_state, struct 
vkms_output *out,
+bool wb_pending, uint32_t *crcs);
 void vkms_composer_worker(struct work_struct *work);
 void vkms_set_composer(struct vkms_output *out, bool enabled);
 
-- 
2.31.1



[PATCH V5 0/2] drm/vkms: Add virtual hardware module

2021-08-01 Thread Sumera Priyadarsini
This patchset adds support for emulating virtual hardware with VKMS.
The virtual hardware mode can be enabled by using the following command
while loading the module:
sudo modprobe vkms enable_virtual_hw=1

The first patch is prep work for adding virtual_hw mode and refactors
the plane composition in vkms by adding a helper function vkms_composer_common()
which can be used for both vblank mode and virtual mode.

The second patch adds virtual hardware support as a module option. It
adds new atomic helper functions for the virtual mode
and modifies the existing atomic helpers for usage by the vblank mode
This gives us two sets of drm_crtc_helper_funcs struct for both modes,
making the code flow cleaner and easier to debug.

This patchset has been tested with the igt tests- kms_writeback, kms_atomic,
kms_lease, kms_flip, kms_pipe_get_crc and preserves results except for
subtests related to crc reads and skips tests that rely on vertical
blanking.

Sumera Priyadarsini (2):
  drm/vkms: Refactor vkms_composer_worker() to prep for virtual_hw mode
  drm/vkms: Add support for virtual hardware mode

 drivers/gpu/drm/vkms/vkms_composer.c | 93 ++--
 drivers/gpu/drm/vkms/vkms_crtc.c | 51 ++-
 drivers/gpu/drm/vkms/vkms_drv.c  | 16 +++--
 drivers/gpu/drm/vkms/vkms_drv.h  |  4 ++
 4 files changed, 112 insertions(+), 52 deletions(-)

-- 
2.31.1



Re: [PATCH 0/4] vkms: Switch to shadow-buffered plane state

2021-07-12 Thread Sumera Priyadarsini
On Mon, Jul 12, 2021 at 6:53 PM Thomas Zimmermann  wrote:
>
> Hi
>
> Am 12.07.21 um 13:56 schrieb Sumera Priyadarsini:
> > On Mon, Jul 5, 2021 at 1:16 PM Thomas Zimmermann  
> > wrote:
> >>
> >> Vkms copies each plane's framebuffer into the output buffer; essentially
> >> using a shadow buffer. DRM provides struct drm_shadow_plane_state, which
> >> handles the details of mapping/unmapping shadow buffers into memory for
> >> active planes.
> >>
> >> Convert vkms to the helpers. Makes vkms use shared code and gives more
> >> test exposure to shadow-plane helpers.
> >>
> >> Thomas Zimmermann (4):
> >>drm/gem: Export implementation of shadow-plane helpers
> >>drm/vkms: Inherit plane state from struct drm_shadow_plane_state
> >>drm/vkms: Let shadow-plane helpers prepare the plane's FB
> >>drm/vkms: Use dma-buf mapping from shadow-plane state for composing
> >>
> >>   drivers/gpu/drm/drm_gem_atomic_helper.c | 55 ++--
> >>   drivers/gpu/drm/vkms/vkms_composer.c| 26 ++-
> >>   drivers/gpu/drm/vkms/vkms_drv.h |  6 ++-
> >>   drivers/gpu/drm/vkms/vkms_plane.c   | 57 ++---
> >>   include/drm/drm_gem_atomic_helper.h |  6 +++
> >>   5 files changed, 86 insertions(+), 64 deletions(-)
> >>
> >>
> >> base-commit: 3d3b5479895dd6dd133571ded4318adf595708ba
> >> --
> >> 2.32.0
> >>
> > Hi,
> >
> > Thanks for the patches. The switch to shadow-plane helpers also solved
> > a bug that was causing a kernel
> > panic during some IGT kms_flip subtests on the vkms virtual hw patch.
>
> Melissa mention something like that as well and I don't really
> understand. Patch 3 removes an error message from the code, but is the
> actual bug also gone?

Yes, I think so. Earlier, while testing the vkms virtual hw patch, the
tests were
not just failing, but the vmap fail also preceeded a page fault which required a
whole restart. Check these logs around line 303:
https://pastebin.pl/view/03b750be.

I could be wrong but I think if the same bug was still present, then
the kernel panic
would also happen even if the error message was not being returned.

Cheers,
Sumera

>
> There's little difference between vkms' original code and the shared
> helper; except for the order of operations in prepare_fb. The shared
> helper synchronizes fences before mapping; vkms mapped first.
>
> (Maybe the shared helper should warn about failed vmaps as well. But
> that's for another patch.)
>
> Best regards
> Thomas
>
> >
> > Tested-by: Sumera Priyadarsini 
> >
> > Cheers,
> > Sumera
> >
>
> --
> Thomas Zimmermann
> Graphics Driver Developer
> SUSE Software Solutions Germany GmbH
> Maxfeldstr. 5, 90409 Nürnberg, Germany
> (HRB 36809, AG Nürnberg)
> Geschäftsführer: Felix Imendörffer
>


Re: [PATCH 0/4] vkms: Switch to shadow-buffered plane state

2021-07-12 Thread Sumera Priyadarsini
On Mon, Jul 5, 2021 at 1:16 PM Thomas Zimmermann  wrote:
>
> Vkms copies each plane's framebuffer into the output buffer; essentially
> using a shadow buffer. DRM provides struct drm_shadow_plane_state, which
> handles the details of mapping/unmapping shadow buffers into memory for
> active planes.
>
> Convert vkms to the helpers. Makes vkms use shared code and gives more
> test exposure to shadow-plane helpers.
>
> Thomas Zimmermann (4):
>   drm/gem: Export implementation of shadow-plane helpers
>   drm/vkms: Inherit plane state from struct drm_shadow_plane_state
>   drm/vkms: Let shadow-plane helpers prepare the plane's FB
>   drm/vkms: Use dma-buf mapping from shadow-plane state for composing
>
>  drivers/gpu/drm/drm_gem_atomic_helper.c | 55 ++--
>  drivers/gpu/drm/vkms/vkms_composer.c| 26 ++-
>  drivers/gpu/drm/vkms/vkms_drv.h |  6 ++-
>  drivers/gpu/drm/vkms/vkms_plane.c   | 57 ++---
>  include/drm/drm_gem_atomic_helper.h |  6 +++
>  5 files changed, 86 insertions(+), 64 deletions(-)
>
>
> base-commit: 3d3b5479895dd6dd133571ded4318adf595708ba
> --
> 2.32.0
>
Hi,

Thanks for the patches. The switch to shadow-plane helpers also solved
a bug that was causing a kernel
panic during some IGT kms_flip subtests on the vkms virtual hw patch.

Tested-by: Sumera Priyadarsini 

Cheers,
Sumera


[PATCH V4 2/2] drm/vkms: Add support for virtual hardware mode

2021-04-04 Thread Sumera Priyadarsini
Add a virtual hardware or vblank-less mode as a module to
enable VKMS to emulate virtual graphic drivers.

Add a new drm_crtc_helper_funcs struct,
vkms_virtual_crtc_helper_funcs() which holds the atomic helpers
for virtual hardware mode. Change the existing
vkms_crtc_helper_funcs struct to vkms_vblank_crtc_helper_funcs
which holds atomic helpers for the vblank mode.
This makes the code flow clearer and easier to test
virtual hardware mode.

The first patch of this patchset added the function vkms_crtc_composer()
for plane composition which is used in case of vblank-less mode and
is directly called in the atomic hook in vkms_crtc_atomic_begin().
However, some crc captures still use vblanks which causes the crc-based
igt tests to crash. Currently, I am unsure about how to approach the
one-shot implementation of crc reads so I am still working on that.

This patchset has been tested with the igt tests- kms_writeback, kms_atomic,
kms_lease, kms_flip, kms_pipe_get_crc and preserves results except for
subtests related to crc reads and skips tests that rely on vertical
blanking. This patchset must be tested after incorporating the
igt-tests patch:
https://lists.freedesktop.org/archives/igt-dev/2021-February/029355.html .

The patch is based on Rodrigo Siqueira's
patch(https://patchwork.freedesktop.org/patch/316851/?series=48469&rev=3)
and the ensuing review.

Signed-off-by: Sumera Priyadarsini 
---
Changes in V3:
- Refactor patchset(Melissa)
Changes in V2:
- Add atomic helper functions in a separate struct for virtual hardware
mode (Daniel)
- Remove spinlock across 'vkms_output->lock' in vkms_crtc.c(Daniel)
- Add vkms_composer_common() (Daniel)
---
 drivers/gpu/drm/vkms/vkms_crtc.c | 51 +++-
 drivers/gpu/drm/vkms/vkms_drv.c  | 18 +++
 drivers/gpu/drm/vkms/vkms_drv.h  |  1 +
 3 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 57bbd32e9beb..e6286f98d5b6 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -222,20 +222,20 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
return 0;
 }
 
-static void vkms_crtc_atomic_enable(struct drm_crtc *crtc,
-   struct drm_atomic_state *state)
+static void vkms_vblank_crtc_atomic_enable(struct drm_crtc *crtc,
+  struct drm_atomic_state *state)
 {
drm_crtc_vblank_on(crtc);
 }
 
-static void vkms_crtc_atomic_disable(struct drm_crtc *crtc,
-struct drm_atomic_state *state)
+static void vkms_vblank_crtc_atomic_disable(struct drm_crtc *crtc,
+   struct drm_atomic_state *state)
 {
drm_crtc_vblank_off(crtc);
 }
 
-static void vkms_crtc_atomic_begin(struct drm_crtc *crtc,
-  struct drm_atomic_state *state)
+static void vkms_vblank_crtc_atomic_begin(struct drm_crtc *crtc,
+   struct drm_atomic_state *state)
 {
struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
 
@@ -245,8 +245,8 @@ static void vkms_crtc_atomic_begin(struct drm_crtc *crtc,
spin_lock_irq(&vkms_output->lock);
 }
 
-static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
-  struct drm_atomic_state *state)
+static void vkms_vblank_crtc_atomic_flush(struct drm_crtc *crtc,
+   struct drm_atomic_state *state)
 {
struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
 
@@ -268,18 +268,38 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
spin_unlock_irq(&vkms_output->lock);
 }
 
-static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = {
+/*
+ * Crtc functions for virtual hardware/vblankless mode
+ */
+static void vkms_virtual_crtc_atomic_flush(struct drm_crtc *crtc,
+   struct drm_atomic_state *state)
+{
+   struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
+   struct vkms_crtc_state *vkms_state = to_vkms_crtc_state(crtc->state);
+
+   vkms_crtc_composer(vkms_state);
+
+   vkms_output->composer_state = to_vkms_crtc_state(crtc->state);
+}
+
+static const struct drm_crtc_helper_funcs vkms_vblank_crtc_helper_funcs = {
.atomic_check   = vkms_crtc_atomic_check,
-   .atomic_begin   = vkms_crtc_atomic_begin,
-   .atomic_flush   = vkms_crtc_atomic_flush,
-   .atomic_enable  = vkms_crtc_atomic_enable,
-   .atomic_disable = vkms_crtc_atomic_disable,
+   .atomic_begin   = vkms_vblank_crtc_atomic_begin,
+   .atomic_flush   = vkms_vblank_crtc_atomic_flush,
+   .atomic_enable  = vkms_vblank_crtc_atomic_enable,
+   .atomic_disable = vkms_vblank_crtc_atomic_disable,
+};
+
+static const struct drm_crtc_helper_funcs vkms_virtual_crtc_helper_funcs = {
+   .atomic_check   = vkms_crtc_atomic_check,
+   .atomic_flush   = vkms_virtual_crtc_a

[PATCH V4 1/2] drm/vkms: Refactor vkms_composer_worker() to prep for virtual_hw mode

2021-04-04 Thread Sumera Priyadarsini
Add two new functions vkms_composer_common() and vkms_crtc_composer().
The actual plane composition work has been moved to the helper function,
vkms_composer_common() which is called by both vkms_composer_worker()
and vkms_crtc_composer(). vkms_crtc_composer() can be used when we
implement virtual_hw mode.

Signed-off-by: Sumera Priyadarsini 
---
Changes in V4:
- Fix warning
Changes in V3:
- Refactor patchset (Melissa)
Change in V2:
- Add vkms_composer_common() (Daniel)
---
 drivers/gpu/drm/vkms/vkms_composer.c | 88 +---
 drivers/gpu/drm/vkms/vkms_drv.h  |  3 +
 2 files changed, 58 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c 
b/drivers/gpu/drm/vkms/vkms_composer.c
index 66c6842d70db..0d2bad3ff849 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -169,6 +169,44 @@ static int compose_planes(void **vaddr_out,
return 0;
 }
 
+int vkms_composer_common(struct vkms_crtc_state *crtc_state,
+struct vkms_output *out, bool wb_pending, uint32_t 
*crc32)
+{
+   struct vkms_composer *primary_composer = NULL;
+   struct vkms_composer *cursor_composer = NULL;
+   void *vaddr_out = NULL;
+   int ret;
+
+   if (crtc_state->num_active_planes >= 1)
+   primary_composer = crtc_state->active_planes[0]->composer;
+   if (crtc_state->num_active_planes == 2)
+   cursor_composer = crtc_state->active_planes[1]->composer;
+   if (!primary_composer)
+   return -EINVAL;
+   if (wb_pending)
+   vaddr_out = crtc_state->active_writeback;
+
+   ret = compose_planes(&vaddr_out, primary_composer, cursor_composer);
+   if (ret) {
+   if (ret == -EINVAL && !wb_pending)
+   kfree(vaddr_out);
+   return -EINVAL;
+   }
+
+   *crc32 = compute_crc(vaddr_out, primary_composer);
+
+   if (wb_pending) {
+   drm_writeback_signal_completion(&out->wb_connector, 0);
+   spin_lock_irq(&out->composer_lock);
+   crtc_state->wb_pending = false;
+   spin_unlock_irq(&out->composer_lock);
+   } else {
+   kfree(vaddr_out);
+   }
+
+   return 0;
+}
+
 /**
  * vkms_composer_worker - ordered work_struct to compute CRC
  *
@@ -185,12 +223,9 @@ void vkms_composer_worker(struct work_struct *work)
composer_work);
struct drm_crtc *crtc = crtc_state->base.crtc;
struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
-   struct vkms_composer *primary_composer = NULL;
-   struct vkms_composer *cursor_composer = NULL;
bool crc_pending, wb_pending;
-   void *vaddr_out = NULL;
-   u32 crc32 = 0;
u64 frame_start, frame_end;
+   u32 crc32 = 0;
int ret;
 
spin_lock_irq(&out->composer_lock);
@@ -210,36 +245,9 @@ void vkms_composer_worker(struct work_struct *work)
if (!crc_pending)
return;
 
-   if (crtc_state->num_active_planes >= 1)
-   primary_composer = crtc_state->active_planes[0]->composer;
-
-   if (crtc_state->num_active_planes == 2)
-   cursor_composer = crtc_state->active_planes[1]->composer;
-
-   if (!primary_composer)
-   return;
-
-   if (wb_pending)
-   vaddr_out = crtc_state->active_writeback;
-
-   ret = compose_planes(&vaddr_out, primary_composer, cursor_composer);
-   if (ret) {
-   if (ret == -EINVAL && !wb_pending)
-   kfree(vaddr_out);
+   ret = vkms_composer_common(crtc_state, out, wb_pending, &crc32);
+   if (ret == -EINVAL)
return;
-   }
-
-   crc32 = compute_crc(vaddr_out, primary_composer);
-
-   if (wb_pending) {
-   drm_writeback_signal_completion(&out->wb_connector, 0);
-   spin_lock_irq(&out->composer_lock);
-   crtc_state->wb_pending = false;
-   spin_unlock_irq(&out->composer_lock);
-   } else {
-   kfree(vaddr_out);
-   }
-
/*
 * The worker can fall behind the vblank hrtimer, make sure we catch up.
 */
@@ -247,6 +255,20 @@ void vkms_composer_worker(struct work_struct *work)
drm_crtc_add_crc_entry(crtc, true, frame_start++, &crc32);
 }
 
+void vkms_crtc_composer(struct vkms_crtc_state *crtc_state)
+{
+   struct drm_crtc *crtc = crtc_state->base.crtc;
+   struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+   u32 crc32 = 0;
+   int ret;
+
+   ret = vkms_composer_common(crtc_state, out, crtc_state->wb_pending, 
&crc32);
+   if (ret == -EINVAL)
+   return;
+
+   drm_crtc_add_crc_entry(crtc, true, 0, &crc32);
+}
+
 stat

[PATCH V4 0/2] Add virtual hardware module

2021-04-04 Thread Sumera Priyadarsini
This patchset adds support for emulating virtual hardware with VKMS.
The virtual hardware mode can be enabled by using the following command
while loading the module:
sudo modprobe vkms enable_virtual_hw=1

The first patch is prep work for adding virtual_hw mode and refactors
the plane composition in vkms by adding a helper function vkms_composer_common()
which can be used for both vblank mode and virtual mode.

The second patch adds virtual hardware support as a module option. It
adds new atomic helper functions for the virtual mode
and modifies the existing atomic helpers for usage by the vblank mode
This gives us two sets of drm_crtc_helper_funcs struct for both modes,
making the code flow cleaner and easier to debug.

This patchset has been tested with the igt tests- kms_writeback, kms_atomic,
kms_lease, kms_flip, kms_pipe_get_crc and preserves results except for
subtests related to crc reads and skips tests that rely on vertical
blanking. This patchset must be tested after incorporating the
igt-tests patch: 
https://lists.freedesktop.org/archives/igt-dev/2021-February/029355.html

Sumera Priyadarsini (2):
  drm/vkms: Refactor vkms_composer_worker() to prep for virtual_hw mode
  drm/vkms: Add support for virtual hardware mode

 drivers/gpu/drm/vkms/vkms_composer.c | 88 +---
 drivers/gpu/drm/vkms/vkms_crtc.c | 51 +++-
 drivers/gpu/drm/vkms/vkms_drv.c  | 18 --
 drivers/gpu/drm/vkms/vkms_drv.h  |  4 ++
 4 files changed, 109 insertions(+), 52 deletions(-)

-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH V3 1/2] drm/vkms: Refactor vkms_composer_worker() to prep for virtual_hw mode

2021-04-04 Thread Sumera Priyadarsini
On Sun, Apr 4, 2021 at 9:19 PM kernel test robot  wrote:
>
> Hi Sumera,
>
> Thank you for the patch! Perhaps something to improve:
>
> [auto build test WARNING on linus/master]
> [also build test WARNING on v5.12-rc5 next-20210401]
> [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/Sumera-Priyadarsini/Add-virtual-hardware-module/20210404-211300
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
> 2023a53bdf41b7646b1d384b6816af06309f73a5
> config: mips-randconfig-r025-20210404 (attached as .config)
> compiler: mipsel-linux-gcc (GCC) 9.3.0
> 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
> # 
> https://github.com/0day-ci/linux/commit/4bd5c27357dd86b6099f3f28db5db722ceeed582
> git remote add linux-review https://github.com/0day-ci/linux
> git fetch --no-tags linux-review 
> Sumera-Priyadarsini/Add-virtual-hardware-module/20210404-211300
> git checkout 4bd5c27357dd86b6099f3f28db5db722ceeed582
> # save the attached .config to linux build tree
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
> ARCH=mips
>
> 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/vkms/vkms_composer.c: In function 'vkms_composer_worker':
> >> drivers/gpu/drm/vkms/vkms_composer.c:226:20: warning: variable 
> >> 'wb_pending' set but not used [-Wunused-but-set-variable]
>  226 |  bool crc_pending, wb_pending;
>  |^~
>
>
> vim +/wb_pending +226 drivers/gpu/drm/vkms/vkms_composer.c
>
> 4bd5c27357dd86 drivers/gpu/drm/vkms/vkms_composer.c Sumera Priyadarsini 
> 2021-04-04  209
> 0ca33adb91c0a9 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-09-04  210  /**
> a4e7e98e90ebd9 drivers/gpu/drm/vkms/vkms_composer.c Rodrigo Siqueira
> 2019-06-25  211   * vkms_composer_worker - ordered work_struct to compute CRC
> 0ca33adb91c0a9 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-09-04  212   *
> 0ca33adb91c0a9 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-09-04  213   * @work: work_struct
> 0ca33adb91c0a9 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-09-04  214   *
> a4e7e98e90ebd9 drivers/gpu/drm/vkms/vkms_composer.c Rodrigo Siqueira
> 2019-06-25  215   * Work handler for composing and computing CRCs. 
> work_struct scheduled in
> 0ca33adb91c0a9 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-09-04  216   * an ordered workqueue that's periodically scheduled to run 
> by
> 0ca33adb91c0a9 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-09-04  217   * _vblank_handle() and flushed at 
> vkms_atomic_crtc_destroy_state().
> 0ca33adb91c0a9 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-09-04  218   */
> a4e7e98e90ebd9 drivers/gpu/drm/vkms/vkms_composer.c Rodrigo Siqueira
> 2019-06-25  219  void vkms_composer_worker(struct work_struct *work)
> 6c234fe37c5762 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-08-02  220  {
> 6c234fe37c5762 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-08-02  221 struct vkms_crtc_state *crtc_state = 
> container_of(work,
> 6c234fe37c5762 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-08-02  222 struct 
> vkms_crtc_state,
> a4e7e98e90ebd9 drivers/gpu/drm/vkms/vkms_composer.c Rodrigo Siqueira
> 2019-06-25  223 
> composer_work);
> 6c234fe37c5762 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-08-02  224 struct drm_crtc *crtc = crtc_state->base.crtc;
> 6c234fe37c5762 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-08-02  225 struct vkms_output *out = 
> drm_crtc_to_vkms_output(crtc);
> dbd9d80c1b2e03 drivers/gpu/drm/vkms/vkms_composer.c Rodrigo Siqueira
> 2020-08-30 @226 bool crc_pending, wb_pending;
> 0ca33adb91c0a9 drivers/gpu/drm/vkms/vkms_crc.c  Haneen Mohammed 
> 2018-09-04  227 u64 frame_start, frame_end;
> 4bd5c27357dd86 drivers/gpu/drm/vkms/vkms_composer.c Sumera Priyadarsini 
> 2021-04-04  228 u32 crc32 = 0;
> 953025763d1421 drivers/gpu/drm/vkms/v

[PATCH V3 2/2] drm/vkms: Add support for virtual hardware mode

2021-04-04 Thread Sumera Priyadarsini
Add a virtual hardware or vblank-less mode as a module to
enable VKMS to emulate virtual graphic drivers.

Add a new drm_crtc_helper_funcs struct,
vkms_virtual_crtc_helper_funcs() which holds the atomic helpers
for virtual hardware mode. Change the existing
vkms_crtc_helper_funcs struct to vkms_vblank_crtc_helper_funcs
which holds atomic helpers for the vblank mode.
This makes the code flow clearer and easier to test
virtual hardware mode.

The first patch of this patchset added the function vkms_crtc_composer()
for plane composition which is used in case of vblank-less mode and
is directly called in the atomic hook in vkms_crtc_atomic_begin().
However, some crc captures still use vblanks which causes the crc-based
igt tests to crash. Currently, I am unsure about how to approach the
one-shot implementation of crc reads so I am still working on that.

This patchset has been tested with the igt tests- kms_writeback, kms_atomic,
kms_lease, kms_flip, kms_pipe_get_crc and preserves results except for
subtests related to crc reads and skips tests that rely on vertical
blanking. This patchset must be tested after incorporating the
igt-tests patch:
https://lists.freedesktop.org/archives/igt-dev/2021-February/029355.html .

The patch is based on Rodrigo Siqueira's
patch(https://patchwork.freedesktop.org/patch/316851/?series=48469&rev=3)
and the ensuing review.

Signed-off-by: Sumera Priyadarsini 
---
Changes in V3:
- Refactor patchset(Melissa)
Changes in V2:
- Add atomic helper functions in a separate struct for virtual hardware
mode (Daniel)
- Remove spinlock across 'vkms_output->lock' in vkms_crtc.c(Daniel)
- Add vkms_composer_common() (Daniel)
---
 drivers/gpu/drm/vkms/vkms_crtc.c | 51 +++-
 drivers/gpu/drm/vkms/vkms_drv.c  | 18 +++
 drivers/gpu/drm/vkms/vkms_drv.h  |  1 +
 3 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 57bbd32e9beb..e6286f98d5b6 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -222,20 +222,20 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
return 0;
 }
 
-static void vkms_crtc_atomic_enable(struct drm_crtc *crtc,
-   struct drm_atomic_state *state)
+static void vkms_vblank_crtc_atomic_enable(struct drm_crtc *crtc,
+  struct drm_atomic_state *state)
 {
drm_crtc_vblank_on(crtc);
 }
 
-static void vkms_crtc_atomic_disable(struct drm_crtc *crtc,
-struct drm_atomic_state *state)
+static void vkms_vblank_crtc_atomic_disable(struct drm_crtc *crtc,
+   struct drm_atomic_state *state)
 {
drm_crtc_vblank_off(crtc);
 }
 
-static void vkms_crtc_atomic_begin(struct drm_crtc *crtc,
-  struct drm_atomic_state *state)
+static void vkms_vblank_crtc_atomic_begin(struct drm_crtc *crtc,
+   struct drm_atomic_state *state)
 {
struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
 
@@ -245,8 +245,8 @@ static void vkms_crtc_atomic_begin(struct drm_crtc *crtc,
spin_lock_irq(&vkms_output->lock);
 }
 
-static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
-  struct drm_atomic_state *state)
+static void vkms_vblank_crtc_atomic_flush(struct drm_crtc *crtc,
+   struct drm_atomic_state *state)
 {
struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
 
@@ -268,18 +268,38 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
spin_unlock_irq(&vkms_output->lock);
 }
 
-static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = {
+/*
+ * Crtc functions for virtual hardware/vblankless mode
+ */
+static void vkms_virtual_crtc_atomic_flush(struct drm_crtc *crtc,
+   struct drm_atomic_state *state)
+{
+   struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
+   struct vkms_crtc_state *vkms_state = to_vkms_crtc_state(crtc->state);
+
+   vkms_crtc_composer(vkms_state);
+
+   vkms_output->composer_state = to_vkms_crtc_state(crtc->state);
+}
+
+static const struct drm_crtc_helper_funcs vkms_vblank_crtc_helper_funcs = {
.atomic_check   = vkms_crtc_atomic_check,
-   .atomic_begin   = vkms_crtc_atomic_begin,
-   .atomic_flush   = vkms_crtc_atomic_flush,
-   .atomic_enable  = vkms_crtc_atomic_enable,
-   .atomic_disable = vkms_crtc_atomic_disable,
+   .atomic_begin   = vkms_vblank_crtc_atomic_begin,
+   .atomic_flush   = vkms_vblank_crtc_atomic_flush,
+   .atomic_enable  = vkms_vblank_crtc_atomic_enable,
+   .atomic_disable = vkms_vblank_crtc_atomic_disable,
+};
+
+static const struct drm_crtc_helper_funcs vkms_virtual_crtc_helper_funcs = {
+   .atomic_check   = vkms_crtc_atomic_check,
+   .atomic_flush   = vkms_virtual_crtc_a

[PATCH V3 1/2] drm/vkms: Refactor vkms_composer_worker() to prep for virtual_hw mode

2021-04-04 Thread Sumera Priyadarsini
Add two new functions vkms_composer_common() and vkms_crtc_composer().
The actual plane composition work has been moved to the helper function,
vkms_composer_common() which is called by both vkms_composer_worker()
and vkms_crtc_composer(). vkms_crtc_composer() can be used when we
implement virtual_hw mode.

Signed-off-by: Sumera Priyadarsini 
---

Changes in V3:
- Refactor patchset (Melissa)
Change in V2:
- Add vkms_composer_common() (Daniel)
---
 drivers/gpu/drm/vkms/vkms_composer.c | 88 +---
 drivers/gpu/drm/vkms/vkms_drv.h  |  3 +
 2 files changed, 58 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c 
b/drivers/gpu/drm/vkms/vkms_composer.c
index 66c6842d70db..91b33c9c2f47 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -169,6 +169,44 @@ static int compose_planes(void **vaddr_out,
return 0;
 }
 
+int vkms_composer_common(struct vkms_crtc_state *crtc_state,
+struct vkms_output *out, bool wb_pending, uint32_t 
*crc32)
+{
+   struct vkms_composer *primary_composer = NULL;
+   struct vkms_composer *cursor_composer = NULL;
+   void *vaddr_out = NULL;
+   int ret;
+
+   if (crtc_state->num_active_planes >= 1)
+   primary_composer = crtc_state->active_planes[0]->composer;
+   if (crtc_state->num_active_planes == 2)
+   cursor_composer = crtc_state->active_planes[1]->composer;
+   if (!primary_composer)
+   return -EINVAL;
+   if (wb_pending)
+   vaddr_out = crtc_state->active_writeback;
+
+   ret = compose_planes(&vaddr_out, primary_composer, cursor_composer);
+   if (ret) {
+   if (ret == -EINVAL && !wb_pending)
+   kfree(vaddr_out);
+   return -EINVAL;
+   }
+
+   *crc32 = compute_crc(vaddr_out, primary_composer);
+
+   if (wb_pending) {
+   drm_writeback_signal_completion(&out->wb_connector, 0);
+   spin_lock_irq(&out->composer_lock);
+   crtc_state->wb_pending = false;
+   spin_unlock_irq(&out->composer_lock);
+   } else {
+   kfree(vaddr_out);
+   }
+
+   return 0;
+}
+
 /**
  * vkms_composer_worker - ordered work_struct to compute CRC
  *
@@ -185,12 +223,9 @@ void vkms_composer_worker(struct work_struct *work)
composer_work);
struct drm_crtc *crtc = crtc_state->base.crtc;
struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
-   struct vkms_composer *primary_composer = NULL;
-   struct vkms_composer *cursor_composer = NULL;
bool crc_pending, wb_pending;
-   void *vaddr_out = NULL;
-   u32 crc32 = 0;
u64 frame_start, frame_end;
+   u32 crc32 = 0;
int ret;
 
spin_lock_irq(&out->composer_lock);
@@ -210,36 +245,9 @@ void vkms_composer_worker(struct work_struct *work)
if (!crc_pending)
return;
 
-   if (crtc_state->num_active_planes >= 1)
-   primary_composer = crtc_state->active_planes[0]->composer;
-
-   if (crtc_state->num_active_planes == 2)
-   cursor_composer = crtc_state->active_planes[1]->composer;
-
-   if (!primary_composer)
-   return;
-
-   if (wb_pending)
-   vaddr_out = crtc_state->active_writeback;
-
-   ret = compose_planes(&vaddr_out, primary_composer, cursor_composer);
-   if (ret) {
-   if (ret == -EINVAL && !wb_pending)
-   kfree(vaddr_out);
+   ret = vkms_composer_common(crtc_state, out, crtc_state->wb_pending, 
&crc32);
+   if (ret == -EINVAL)
return;
-   }
-
-   crc32 = compute_crc(vaddr_out, primary_composer);
-
-   if (wb_pending) {
-   drm_writeback_signal_completion(&out->wb_connector, 0);
-   spin_lock_irq(&out->composer_lock);
-   crtc_state->wb_pending = false;
-   spin_unlock_irq(&out->composer_lock);
-   } else {
-   kfree(vaddr_out);
-   }
-
/*
 * The worker can fall behind the vblank hrtimer, make sure we catch up.
 */
@@ -247,6 +255,20 @@ void vkms_composer_worker(struct work_struct *work)
drm_crtc_add_crc_entry(crtc, true, frame_start++, &crc32);
 }
 
+void vkms_crtc_composer(struct vkms_crtc_state *crtc_state)
+{
+   struct drm_crtc *crtc = crtc_state->base.crtc;
+   struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+   u32 crc32 = 0;
+   int ret;
+
+   ret = vkms_composer_common(crtc_state, out, crtc_state->wb_pending, 
&crc32);
+   if (ret == -EINVAL)
+   return;
+
+   drm_crtc_add_crc_entry(crtc, true, 0, &crc32);
+}
+
 static const c

[PATCH V3 0/2] Add virtual hardware module

2021-04-04 Thread Sumera Priyadarsini
This patchset adds support for emulating virtual hardware with VKMS.
The virtual hardware mode can be enabled by using the following command
while loading the module:
sudo modprobe vkms enable_virtual_hw=1

The first patch is prep work for adding virtual_hw mode and refactors
the plane composition in vkms by adding a helper function vkms_composer_common()
which can be used for both vblank mode and virtual mode.

The second patch adds virtual hardware support as a module option. The
second patch adds new atomic helper functions for the virtual mode
and modifies the existing atomic helpers for usage by the vblank mode
This gives us two sets of drm_crtc_helper_funcs struct for both modes,
making the code flow cleaner and easier to debug.

This patchset has been tested with the igt tests, kms_writeback, kms_atomic,
kms_lease, kms_flip, kms_pipe_get_crc and preserves results except for
subtests related to crc reads and skips tests that rely on vertical
blanking. This patchset must be tested after incorporating the
igt-tests patch: 
https://lists.freedesktop.org/archives/igt-dev/2021-February/029355.html 

Sumera Priyadarsini (2):
  drm/vkms: Refactor vkms_composer_worker() to prep for virtual_hw mode
  drm/vkms: Add support for virtual hardware mode

 drivers/gpu/drm/vkms/vkms_composer.c | 88 +---
 drivers/gpu/drm/vkms/vkms_crtc.c | 51 +++-
 drivers/gpu/drm/vkms/vkms_drv.c  | 18 --
 drivers/gpu/drm/vkms/vkms_drv.h  |  4 ++
 4 files changed, 109 insertions(+), 52 deletions(-)

-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH V2 2/2] drm/vkms: Add crtc atomic helper functions for virtual mode

2021-03-03 Thread Sumera Priyadarsini
Add a new drm_crtc_helper_funcs struct,
vkms_virtual_crtc_helper_funcs() which holds the atomic helpers
for virtual hardware mode. Change the existing
vkms_crtc_helper_funcs struct to vkms_vblank_crtc_helper_funcs
which holds atomic helpers for the vblank mode.

This patch makes the code flow clearer and easier to test
virtual hardware mode.

Signed-off-by: Sumera Priyadarsini 
---

Changes in V2:
- Add atomic helper functions in a separate struct for virtual hardware
mode (Daniel)
---
 drivers/gpu/drm/vkms/vkms_crtc.c | 69 ++--
 1 file changed, 39 insertions(+), 30 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 6cc8dc23bd5d..7d5562ab5ce6 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -221,48 +221,35 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
return 0;
 }
 
-static void vkms_crtc_atomic_enable(struct drm_crtc *crtc,
-   struct drm_atomic_state *state)
+static void vkms_vblank_crtc_atomic_enable(struct drm_crtc *crtc,
+struct drm_atomic_state *state)
 {
-   struct vkms_device *vkmsdev = drm_device_to_vkms_device(crtc->dev);
-
-   if (!vkmsdev->config->virtual_hw)
-   drm_crtc_vblank_on(crtc);
+   drm_crtc_vblank_on(crtc);
 }
 
-static void vkms_crtc_atomic_disable(struct drm_crtc *crtc,
+static void vkms_vblank_crtc_atomic_disable(struct drm_crtc *crtc,
 struct drm_atomic_state *state)
 {
-   struct vkms_device *vkmsdev = drm_device_to_vkms_device(crtc->dev);
-
-   if (!vkmsdev->config->virtual_hw)
-   drm_crtc_vblank_off(crtc);
+   drm_crtc_vblank_off(crtc);
 }
 
-static void vkms_crtc_atomic_begin(struct drm_crtc *crtc,
+static void vkms_vblank_crtc_atomic_begin(struct drm_crtc *crtc,
   struct drm_atomic_state *state)
 {
struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
-   struct vkms_device *vkmsdev = drm_device_to_vkms_device(crtc->dev);
 
/* This lock is held across the atomic commit to block vblank timer
 * from scheduling vkms_composer_worker until the composer is updated
 */
-   if (!vkmsdev->config->virtual_hw)
-   spin_lock_irq(&vkms_output->lock);
+   spin_lock_irq(&vkms_output->lock);
 }
 
-static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
+static void vkms_vblank_crtc_atomic_flush(struct drm_crtc *crtc,
   struct drm_atomic_state *state)
 {
struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
-   struct vkms_crtc_state *vkms_state = to_vkms_crtc_state(crtc->state);
-   struct vkms_device *vkmsdev = drm_device_to_vkms_device(crtc->dev);
-
-   if (vkmsdev->config->virtual_hw)
-   vkms_crtc_composer(vkms_state);
 
-   if (crtc->state->event && !vkmsdev->config->virtual_hw) {
+   if (crtc->state->event) {
spin_lock(&crtc->dev->event_lock);
 
if (drm_crtc_vblank_get(crtc) != 0)
@@ -277,22 +264,41 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
 
vkms_output->composer_state = to_vkms_crtc_state(crtc->state);
 
-   if (!vkmsdev->config->virtual_hw)
-   spin_unlock_irq(&vkms_output->lock);
+   spin_unlock_irq(&vkms_output->lock);
 }
 
-static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = {
+/*
+ * Crtc functions for virtual hardware/vblankless mode
+ */
+static void vkms_virtual_crtc_atomic_flush(struct drm_crtc *crtc,
+  struct drm_atomic_state *state)
+{
+   struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
+   struct vkms_crtc_state *vkms_state = to_vkms_crtc_state(crtc->state);
+
+   vkms_crtc_composer(vkms_state);
+
+   vkms_output->composer_state = to_vkms_crtc_state(crtc->state);
+}
+
+static const struct drm_crtc_helper_funcs vkms_vblank_crtc_helper_funcs = {
.atomic_check   = vkms_crtc_atomic_check,
-   .atomic_begin   = vkms_crtc_atomic_begin,
-   .atomic_flush   = vkms_crtc_atomic_flush,
-   .atomic_enable  = vkms_crtc_atomic_enable,
-   .atomic_disable = vkms_crtc_atomic_disable,
+   .atomic_begin   = vkms_vblank_crtc_atomic_begin,
+   .atomic_flush   = vkms_vblank_crtc_atomic_flush,
+   .atomic_enable  = vkms_vblank_crtc_atomic_enable,
+   .atomic_disable = vkms_vblank_crtc_atomic_disable,
+};
+
+static const struct drm_crtc_helper_funcs vkms_virtual_crtc_helper_funcs = {
+   .atomic_check   = vkms_crtc_atomic_check,
+   .atomic_flush   = vkms_virtual_crtc_atomic_flush,
 };
 
 int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
   struct drm_plane

[PATCH V2 1/2] drm/vkms: Add support for virtual hardware mode

2021-03-03 Thread Sumera Priyadarsini
Add a virtual hardware or vblank-less mode as a module to enable
VKMS to emulate virtual graphic drivers.

Two new functions vkms_composer_common() and vkms_crtc_composer() have
been added. The actual plane composition work has been moved to
vkms_composer_common() which is called by both vkms_composer_worker()
and vkms_crtc_composer(). vkms_crtc_composer() is used in case of
vblank mode and is called directly in the atomic hook in
vkms_atomic_begin(). However, some crc captures still use vblanks
which causes the crc-based igt tests to crash. Currently, I am unsure
about how to approach one-shot implementation of crc reads so I am
still working on that.

The patch is based on Rodrigo Siqueira's
patch(https://patchwork.freedesktop.org/patch/316851/?series=48469&rev=3)
and the ensuing review.

Signed-off-by: Sumera Priyadarsini 

Changes in V2:
- Remove spinlock across 'vkms_output->lock' in vkms_crtc.c(Daniel)
- Add vkms_composer_common() (Daniel)
---
 drivers/gpu/drm/vkms/vkms_composer.c | 88 +---
 drivers/gpu/drm/vkms/vkms_crtc.c | 24 ++--
 drivers/gpu/drm/vkms/vkms_drv.c  | 18 --
 drivers/gpu/drm/vkms/vkms_drv.h  |  4 ++
 4 files changed, 91 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c 
b/drivers/gpu/drm/vkms/vkms_composer.c
index 66c6842d70db..df5b946f001f 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -169,6 +169,44 @@ static int compose_planes(void **vaddr_out,
return 0;
 }
 
+int vkms_composer_common(struct vkms_crtc_state *crtc_state,
+ struct vkms_output *out, bool wb_pending, uint32_t 
*crc32)
+{
+   struct vkms_composer *primary_composer = NULL;
+   struct vkms_composer *cursor_composer = NULL;
+   void *vaddr_out = NULL;
+   int ret;
+
+   if (crtc_state->num_active_planes >= 1)
+   primary_composer = crtc_state->active_planes[0]->composer;
+   if (crtc_state->num_active_planes == 2)
+   cursor_composer = crtc_state->active_planes[1]->composer;
+   if (!primary_composer)
+   return -EINVAL;
+   if (wb_pending)
+   vaddr_out = crtc_state->active_writeback;
+
+   ret = compose_planes(&vaddr_out, primary_composer, cursor_composer);
+   if (ret) {
+   if (ret == -EINVAL && !wb_pending)
+   kfree(vaddr_out);
+   return -EINVAL;
+   }
+
+   *crc32 = compute_crc(vaddr_out, primary_composer);
+
+   if (wb_pending) {
+   drm_writeback_signal_completion(&out->wb_connector, 0);
+   spin_lock_irq(&out->composer_lock);
+   crtc_state->wb_pending = false;
+   spin_unlock_irq(&out->composer_lock);
+   } else {
+   kfree(vaddr_out);
+   }
+
+   return 0;
+}
+
 /**
  * vkms_composer_worker - ordered work_struct to compute CRC
  *
@@ -185,12 +223,9 @@ void vkms_composer_worker(struct work_struct *work)
composer_work);
struct drm_crtc *crtc = crtc_state->base.crtc;
struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
-   struct vkms_composer *primary_composer = NULL;
-   struct vkms_composer *cursor_composer = NULL;
bool crc_pending, wb_pending;
-   void *vaddr_out = NULL;
-   u32 crc32 = 0;
u64 frame_start, frame_end;
+   u32 crc32 = 0;
int ret;
 
spin_lock_irq(&out->composer_lock);
@@ -210,36 +245,9 @@ void vkms_composer_worker(struct work_struct *work)
if (!crc_pending)
return;
 
-   if (crtc_state->num_active_planes >= 1)
-   primary_composer = crtc_state->active_planes[0]->composer;
-
-   if (crtc_state->num_active_planes == 2)
-   cursor_composer = crtc_state->active_planes[1]->composer;
-
-   if (!primary_composer)
-   return;
-
-   if (wb_pending)
-   vaddr_out = crtc_state->active_writeback;
-
-   ret = compose_planes(&vaddr_out, primary_composer, cursor_composer);
-   if (ret) {
-   if (ret == -EINVAL && !wb_pending)
-   kfree(vaddr_out);
+   ret = vkms_composer_common(crtc_state, out, crtc_state->wb_pending, 
&crc32);
+   if (ret == -EINVAL)
return;
-   }
-
-   crc32 = compute_crc(vaddr_out, primary_composer);
-
-   if (wb_pending) {
-   drm_writeback_signal_completion(&out->wb_connector, 0);
-   spin_lock_irq(&out->composer_lock);
-   crtc_state->wb_pending = false;
-   spin_unlock_irq(&out->composer_lock);
-   } else {
-   kfree(vaddr_out);
-   }
-
/*
 * The worker can fall behind the vblank hrtimer

[PATCH V2 0/2] Add virtual hardware module

2021-03-03 Thread Sumera Priyadarsini
This patchset adds support for emulating virtual hardware with VKMS.
The virtual hardware mode can be enabled by using the following command
while loading the module:
sudo modprobe vkms enable_virtual_hw=1

The first patch adds virtual hardware support as a module option. The
second patch adds new atomic helper functions for the virtual mode
and modifies the existing atomic helpers for usage by the vblank mode
This gives us two sets of drm_crtc_helper_funcs struct for both modes,
making the code flow cleaner and easier to debug.

This patchset has been tested with the igt tests, kms_writeback, kms_atomic,
kms_lease, kms_flip, kms_pipe_get_crc and preserves results except for
subtests related to crc reads and skips tests that rely on vertical
blanking. This patchset must be tested after incorporating the
igt-tests patch: 
https://lists.freedesktop.org/archives/igt-dev/2021-February/029355.html .

Sumera Priyadarsini (2):
  drm/vkms: Add support for virtual hardware mode
  drm/vkms: Add crtc atomic helper functions for virtual mode

 drivers/gpu/drm/vkms/vkms_composer.c | 88 +---
 drivers/gpu/drm/vkms/vkms_crtc.c | 45 ++
 drivers/gpu/drm/vkms/vkms_drv.c  | 18 --
 drivers/gpu/drm/vkms/vkms_drv.h  |  4 ++
 4 files changed, 106 insertions(+), 49 deletions(-)

-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[RFC PATCH] drm/vkms: Add support for virtual hardware mode

2021-02-24 Thread Sumera Priyadarsini
Add a virtual hardware or vblank-less mode as a module to enable
VKMS to emulate virtual graphic drivers. This mode can be enabled
by setting enable_virtual_hw=1 at the time of loading VKMS.

A new function vkms_crtc_composer() has been added to bypass the
vblank mode and is called directly in the atomic hook in
vkms_atomic_begin(). However, some crc captures still use vblanks
which causes the crc-based igt tests to crash. Currently, I am unsure
about how to approach one-shot implementation of crc reads so I am
still working on that.

This patch has been tested with the igt tests, kms_writeback, kms_atomic,
kms_lease, kms_flip, kms_pipe_get_crc and preserves results except for
subtests related to crc reads and skips tests that rely on vertical
blanking. This patch must be tested after incorporating the
igt-tests patch: 
https://lists.freedesktop.org/archives/igt-dev/2021-February/029355.html .

The patch is based on Rodrigo Siqueira's
patch(https://patchwork.freedesktop.org/patch/316851/?series=48469&rev=3)
and the ensuing review.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/vkms/vkms_composer.c | 46 
 drivers/gpu/drm/vkms/vkms_crtc.c | 17 --
 drivers/gpu/drm/vkms/vkms_drv.c  | 18 ---
 drivers/gpu/drm/vkms/vkms_drv.h  |  2 ++
 4 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c 
b/drivers/gpu/drm/vkms/vkms_composer.c
index 66c6842d70db..7a8aaf5c 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -247,6 +247,52 @@ void vkms_composer_worker(struct work_struct *work)
drm_crtc_add_crc_entry(crtc, true, frame_start++, &crc32);
 }
 
+void vkms_crtc_composer(struct vkms_crtc_state *crtc_state)
+{
+   struct drm_crtc *crtc = crtc_state->base.crtc;
+   struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+   struct vkms_composer *primary_composer = NULL;
+   struct vkms_composer *cursor_composer = NULL;
+   void *vaddr_out = NULL;
+   u32 crc32 = 0;
+   int ret;
+   bool wb_pending;
+
+   wb_pending = crtc_state->wb_pending;
+
+   if (crtc_state->num_active_planes >= 1)
+   primary_composer = crtc_state->active_planes[0]->composer;
+
+   if (crtc_state->num_active_planes == 2)
+   cursor_composer = crtc_state->active_planes[1]->composer;
+
+   if (!primary_composer)
+   return;
+
+   if (wb_pending)
+   vaddr_out = crtc_state->active_writeback;
+
+   ret = compose_planes(&vaddr_out, primary_composer, cursor_composer);
+   if (ret) {
+   if (ret == -EINVAL && !wb_pending)
+   kfree(vaddr_out);
+   return;
+   }
+
+   crc32 = compute_crc(vaddr_out, primary_composer);
+
+   if (wb_pending) {
+   drm_writeback_signal_completion(&out->wb_connector, 0);
+   spin_lock_irq(&out->composer_lock);
+   crtc_state->wb_pending = false;
+   spin_unlock_irq(&out->composer_lock);
+   } else {
+   kfree(vaddr_out);
+   }
+
+   drm_crtc_add_crc_entry(crtc, true, 0, &crc32);
+}
+
 static const char * const pipe_crc_sources[] = {"auto"};
 
 const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 6164349cdf11..38de791a4882 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -224,13 +224,19 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
 static void vkms_crtc_atomic_enable(struct drm_crtc *crtc,
struct drm_atomic_state *state)
 {
-   drm_crtc_vblank_on(crtc);
+   struct vkms_device *vkmsdev = drm_device_to_vkms_device(crtc->dev);
+
+   if (!vkmsdev->config->virtual_hw)
+   drm_crtc_vblank_on(crtc);
 }
 
 static void vkms_crtc_atomic_disable(struct drm_crtc *crtc,
 struct drm_atomic_state *state)
 {
-   drm_crtc_vblank_off(crtc);
+   struct vkms_device *vkmsdev = drm_device_to_vkms_device(crtc->dev);
+
+   if (!vkmsdev->config->virtual_hw)
+   drm_crtc_vblank_off(crtc);
 }
 
 static void vkms_crtc_atomic_begin(struct drm_crtc *crtc,
@@ -248,8 +254,13 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
   struct drm_atomic_state *state)
 {
struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
+   struct vkms_crtc_state *vkms_state = to_vkms_crtc_state(crtc->state);
+   struct vkms_device *vkmsdev = drm_device_to_vkms_device(crtc->dev);
+
+   if (vkmsdev->config->virtual_hw)
+   vkms_crtc_composer(vkms_state);
 
-   if (crtc->state->event) {
+   

Re: [PATCH][next] drm/vkms: Fix missing kmalloc allocation failure check

2021-01-15 Thread Sumera Priyadarsini
On Fri, Jan 15, 2021 at 6:39 PM Colin King  wrote:
>
> From: Colin Ian King 
>
> Currently the kmalloc allocation for config is not being null
> checked and could potentially lead to a null pointer dereference.
> Fix this by adding the missing null check.
>
> Addresses-Coverity: ("Dereference null return value")
> Fixes: 2df7af93fdad ("drm/vkms: Add vkms_config type")
> Signed-off-by: Colin Ian King 

Good catch, thank you!

Reviewed-by: Sumera Priyadarsini 
> ---
>  drivers/gpu/drm/vkms/vkms_drv.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
> index 708f7f54001d..2173b82606f6 100644
> --- a/drivers/gpu/drm/vkms/vkms_drv.c
> +++ b/drivers/gpu/drm/vkms/vkms_drv.c
> @@ -188,7 +188,11 @@ static int vkms_create(struct vkms_config *config)
>
>  static int __init vkms_init(void)
>  {
> -   struct vkms_config *config = kmalloc(sizeof(*config), GFP_KERNEL);
> +   struct vkms_config *config;
> +
> +   config = kmalloc(sizeof(*config), GFP_KERNEL);
> +   if (!config)
> +   return -ENOMEM;
>
> default_config = config;
>
> --
> 2.29.2
>
regards,
Sumera
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH] drm/vblank: Fix typo in docs

2021-01-14 Thread Sumera Priyadarsini
Fix typo in intro chapter in drm_vblank.c.
Change 'sacn' to 'scan'.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/drm_vblank.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index d30e2f2b8f3c..30912d8f82a5 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -74,7 +74,7 @@
  *||   updates the
  *||   frame as it
  *||   travels down
- *||   ("sacn out")
+ *||   ("scan out")
  *|   Old frame|
  *||
  *||
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH V5 3/3] drm/vkms: Add information about module options

2021-01-11 Thread Sumera Priyadarsini
Update vkms documentation to contain usage of `modinfo`
command and steps to load vkms with module options enabled.

Signed-off-by: Sumera Priyadarsini 
---
 Documentation/gpu/vkms.rst | 12 
 1 file changed, 12 insertions(+)

diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst
index 9e030c74a82e..2c9b376da5ca 100644
--- a/Documentation/gpu/vkms.rst
+++ b/Documentation/gpu/vkms.rst
@@ -35,6 +35,18 @@ Now, to load the driver, use::
 On running the lsmod command now, the VKMS driver will appear listed.
 You can also observe the driver being loaded in the dmesg logs.
 
+The VKMS driver has optional features to simulate different kinds of hardware,
+which are exposed as module options. You can use the `modinfo` command
+to see the module options for vkms::
+
+  modinfo vkms
+
+Module options are helpful when testing, and enabling modules
+can be done while loading vkms. For example, to load vkms with cursor enabled,
+use::
+
+  sudo modprobe vkms enable_cursor=1
+
 To disable the driver, use ::
 
   sudo modprobe -r vkms
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH V5 2/3] drm/vkms: Add support for writeback module

2021-01-11 Thread Sumera Priyadarsini
Add enable_writeback feature to vkms_config as a module.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/vkms/vkms_drv.c| 5 +
 drivers/gpu/drm/vkms/vkms_drv.h| 1 +
 drivers/gpu/drm/vkms/vkms_output.c | 9 ++---
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index 6b33975a5cb2..708f7f54001d 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -40,6 +40,10 @@ static bool enable_cursor = true;
 module_param_named(enable_cursor, enable_cursor, bool, 0444);
 MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
 
+static bool enable_writeback = true;
+module_param_named(enable_writeback, enable_writeback, bool, 0444);
+MODULE_PARM_DESC(enable_writeback, "Enable/Disable writeback connector 
support");
+
 DEFINE_DRM_GEM_FOPS(vkms_driver_fops);
 
 static void vkms_release(struct drm_device *dev)
@@ -189,6 +193,7 @@ static int __init vkms_init(void)
default_config = config;
 
config->cursor = enable_cursor;
+   config->writeback = enable_writeback;
 
return vkms_create(config);
 }
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 6a27bd8875f2..b9b4e2bc11c0 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -83,6 +83,7 @@ struct vkms_output {
 struct vkms_device;
 
 struct vkms_config {
+   bool writeback;
bool cursor;
/* only set when instantiated */
struct vkms_device *dev;
diff --git a/drivers/gpu/drm/vkms/vkms_output.c 
b/drivers/gpu/drm/vkms/vkms_output.c
index 8f3ffb28b9d1..f5f6f15c362c 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -41,6 +41,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
struct drm_crtc *crtc = &output->crtc;
struct drm_plane *primary, *cursor = NULL;
int ret;
+   int writeback;
 
primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
if (IS_ERR(primary))
@@ -80,9 +81,11 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
goto err_attach;
}
 
-   ret = vkms_enable_writeback_connector(vkmsdev);
-   if (ret)
-   DRM_ERROR("Failed to init writeback connector\n");
+   if (vkmsdev->config->writeback) {
+   writeback = vkms_enable_writeback_connector(vkmsdev);
+   if (writeback)
+   DRM_ERROR("Failed to init writeback connector\n");
+   }
 
drm_mode_config_reset(dev);
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH V5 1/3] drm/vkms: Add vkms_config type

2021-01-11 Thread Sumera Priyadarsini
Currently, data for the device instance is held by vkms_device.
Add a separate type, vkms_config to contain configuration details
for the device and various modes to be later used by configfs.
This config data stays constant once the device is created.

Accordingly, add vkms_create and vkms_destroy to initialize/destroy
device through configfs. Currently, they are being called from vkms_init
and vkms_exit, but will be evoked from configfs later on. When configfs
is added, device configuration will be tracked by configfs and only vkms
device lifetime will be handled by vkms_init and vkms_exit functions.

Modify usage of enable_cursor feature to reflect the changes in
relevant files.

Co-developed-by: Daniel Vetter 
Signed-off-by: Daniel Vetter 
Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/vkms/vkms_drv.c| 40 --
 drivers/gpu/drm/vkms/vkms_drv.h| 12 +++--
 drivers/gpu/drm/vkms/vkms_output.c |  4 +--
 3 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index aef29393b811..6b33975a5cb2 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -34,9 +34,9 @@
 #define DRIVER_MAJOR   1
 #define DRIVER_MINOR   0
 
-static struct vkms_device *vkms_device;
+static struct vkms_config *default_config;
 
-bool enable_cursor = true;
+static bool enable_cursor = true;
 module_param_named(enable_cursor, enable_cursor, bool, 0444);
 MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
 
@@ -122,10 +122,11 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev)
return vkms_output_init(vkmsdev, 0);
 }
 
-static int __init vkms_init(void)
+static int vkms_create(struct vkms_config *config)
 {
int ret;
struct platform_device *pdev;
+   struct vkms_device *vkms_device;
 
pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
if (IS_ERR(pdev))
@@ -143,6 +144,8 @@ static int __init vkms_init(void)
goto out_devres;
}
vkms_device->platform = pdev;
+   vkms_device->config = config;
+   config->dev = vkms_device;
 
ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev,
   DMA_BIT_MASK(64));
@@ -179,21 +182,42 @@ static int __init vkms_init(void)
return ret;
 }
 
-static void __exit vkms_exit(void)
+static int __init vkms_init(void)
+{
+   struct vkms_config *config = kmalloc(sizeof(*config), GFP_KERNEL);
+
+   default_config = config;
+
+   config->cursor = enable_cursor;
+
+   return vkms_create(config);
+}
+
+static void vkms_destroy(struct vkms_config *config)
 {
struct platform_device *pdev;
 
-   if (!vkms_device) {
+   if (!config->dev) {
DRM_INFO("vkms_device is NULL.\n");
return;
}
 
-   pdev = vkms_device->platform;
+   pdev = config->dev->platform;
 
-   drm_dev_unregister(&vkms_device->drm);
-   drm_atomic_helper_shutdown(&vkms_device->drm);
+   drm_dev_unregister(&config->dev->drm);
+   drm_atomic_helper_shutdown(&config->dev->drm);
devres_release_group(&pdev->dev, NULL);
platform_device_unregister(pdev);
+
+   config->dev = NULL;
+}
+
+static void __exit vkms_exit(void)
+{
+   if (default_config->dev)
+   vkms_destroy(default_config);
+
+   kfree(default_config);
 }
 
 module_init(vkms_init);
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 5ed91ff08cb3..6a27bd8875f2 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -19,8 +19,6 @@
 #define XRES_MAX  8192
 #define YRES_MAX  8192
 
-extern bool enable_cursor;
-
 struct vkms_composer {
struct drm_framebuffer fb;
struct drm_rect src, dst;
@@ -82,10 +80,19 @@ struct vkms_output {
spinlock_t composer_lock;
 };
 
+struct vkms_device;
+
+struct vkms_config {
+   bool cursor;
+   /* only set when instantiated */
+   struct vkms_device *dev;
+};
+
 struct vkms_device {
struct drm_device drm;
struct platform_device *platform;
struct vkms_output output;
+   const struct vkms_config *config;
 };
 
 #define drm_crtc_to_vkms_output(target) \
@@ -124,3 +131,4 @@ void vkms_set_composer(struct vkms_output *out, bool 
enabled);
 int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
 
 #endif /* _VKMS_DRV_H_ */
+
diff --git a/drivers/gpu/drm/vkms/vkms_output.c 
b/drivers/gpu/drm/vkms/vkms_output.c
index 4a1848b0318f..8f3ffb28b9d1 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -46,7 +46,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
if (IS_ERR(primary))
return PTR_ERR(primary);
 
-   if (enable_cur

[PATCH V5 0/3] Decouple config data for configfs

2021-01-11 Thread Sumera Priyadarsini
This patchset aims to lay down some prep work before configfs can be
implemented for the vkms driver. The first patch in the series adds a
new type vkms_config to track device configuration. The second and third
patch add module testing support for writeback operations.

The first patch is developed by Daniel Vetter.

Daniel Vetter (1):
  drm/vkms: Add vkms_config type

Sumera Priyadarsini (3):
  drm/vkms: Add vkms_config type
  drm/vkms: Add support for writeback module
  drm/vkms: Add information about module options

 Documentation/gpu/vkms.rst | 12 
 drivers/gpu/drm/vkms/vkms_drv.c| 45 --
 drivers/gpu/drm/vkms/vkms_drv.h| 13 +++--
 drivers/gpu/drm/vkms/vkms_output.c | 13 +
 4 files changed, 68 insertions(+), 15 deletions(-)

---
Changes in v2:
 - add Co-developed-by tag
 
Changes in v3:
 - correct usage of Co-developed by tag(Melissa)
 - add enable_writeback_feature(Melissa)
 - modify commit message(Melissa)

Changes in v4:
 - split previous patch into patchset(Melissa)
 - fix checkpatch issue(Melissa)
 - update docs(Daniel)

Changes in v5:
 - modify docs patch(Daniel)
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH V4 3/3] drm/vkms: Add information about module options

2021-01-10 Thread Sumera Priyadarsini
Update vkms documentation to contain usage of `modinfo`
command and steps to load vkms with module options enabled.

Signed-off-by: Sumera Priyadarsini 
---
 Documentation/gpu/vkms.rst | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst
index 9e030c74a82e..45fe02f643a8 100644
--- a/Documentation/gpu/vkms.rst
+++ b/Documentation/gpu/vkms.rst
@@ -35,6 +35,16 @@ Now, to load the driver, use::
 On running the lsmod command now, the VKMS driver will appear listed.
 You can also observe the driver being loaded in the dmesg logs.
 
+You can use the `modinfo` command to see module options for vkms::
+
+  modinfo vkms
+
+Module options are helpful when testing, and enabling modules
+can be done while loading vkms. For example, to load vkms with cursor enabled,
+use::
+
+  sudo modprobe vkms enable_cursor=1
+
 To disable the driver, use ::
 
   sudo modprobe -r vkms
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH V4 2/3] drm/vkms: Add support for writeback module

2021-01-10 Thread Sumera Priyadarsini
Add enable_writeback feature to vkms_config as a module.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/vkms/vkms_drv.c| 5 +
 drivers/gpu/drm/vkms/vkms_drv.h| 1 +
 drivers/gpu/drm/vkms/vkms_output.c | 9 ++---
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index 6b33975a5cb2..708f7f54001d 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -40,6 +40,10 @@ static bool enable_cursor = true;
 module_param_named(enable_cursor, enable_cursor, bool, 0444);
 MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
 
+static bool enable_writeback = true;
+module_param_named(enable_writeback, enable_writeback, bool, 0444);
+MODULE_PARM_DESC(enable_writeback, "Enable/Disable writeback connector 
support");
+
 DEFINE_DRM_GEM_FOPS(vkms_driver_fops);
 
 static void vkms_release(struct drm_device *dev)
@@ -189,6 +193,7 @@ static int __init vkms_init(void)
default_config = config;
 
config->cursor = enable_cursor;
+   config->writeback = enable_writeback;
 
return vkms_create(config);
 }
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 6a27bd8875f2..b9b4e2bc11c0 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -83,6 +83,7 @@ struct vkms_output {
 struct vkms_device;
 
 struct vkms_config {
+   bool writeback;
bool cursor;
/* only set when instantiated */
struct vkms_device *dev;
diff --git a/drivers/gpu/drm/vkms/vkms_output.c 
b/drivers/gpu/drm/vkms/vkms_output.c
index 8f3ffb28b9d1..f5f6f15c362c 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -41,6 +41,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
struct drm_crtc *crtc = &output->crtc;
struct drm_plane *primary, *cursor = NULL;
int ret;
+   int writeback;
 
primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
if (IS_ERR(primary))
@@ -80,9 +81,11 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
goto err_attach;
}
 
-   ret = vkms_enable_writeback_connector(vkmsdev);
-   if (ret)
-   DRM_ERROR("Failed to init writeback connector\n");
+   if (vkmsdev->config->writeback) {
+   writeback = vkms_enable_writeback_connector(vkmsdev);
+   if (writeback)
+   DRM_ERROR("Failed to init writeback connector\n");
+   }
 
drm_mode_config_reset(dev);
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH V4 1/3] drm/vkms: Add vkms_config type

2021-01-10 Thread Sumera Priyadarsini
Currently, data for the device instance is held by vkms_device.
Add a separate type, vkms_config to contain configuration details
for the device and various modes to be later used by configfs.
This config data stays constant once the device is created.

Accordingly, add vkms_create and vkms_destroy to initialize/destroy
device through configfs. Currently, they are being called from vkms_init
and vkms_exit, but will be evoked from configfs later on. When configfs
is added, device configuration will be tracked by configfs and only vkms
device lifetime will be handled by vkms_init and vkms_exit functions.

Modify usage of enable_cursor feature to reflect the changes in
relevant files.

Co-developed-by: Daniel Vetter 
Signed-off-by: Daniel Vetter 
Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/vkms/vkms_drv.c| 40 --
 drivers/gpu/drm/vkms/vkms_drv.h| 12 +++--
 drivers/gpu/drm/vkms/vkms_output.c |  4 +--
 3 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index aef29393b811..6b33975a5cb2 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -34,9 +34,9 @@
 #define DRIVER_MAJOR   1
 #define DRIVER_MINOR   0
 
-static struct vkms_device *vkms_device;
+static struct vkms_config *default_config;
 
-bool enable_cursor = true;
+static bool enable_cursor = true;
 module_param_named(enable_cursor, enable_cursor, bool, 0444);
 MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
 
@@ -122,10 +122,11 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev)
return vkms_output_init(vkmsdev, 0);
 }
 
-static int __init vkms_init(void)
+static int vkms_create(struct vkms_config *config)
 {
int ret;
struct platform_device *pdev;
+   struct vkms_device *vkms_device;
 
pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
if (IS_ERR(pdev))
@@ -143,6 +144,8 @@ static int __init vkms_init(void)
goto out_devres;
}
vkms_device->platform = pdev;
+   vkms_device->config = config;
+   config->dev = vkms_device;
 
ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev,
   DMA_BIT_MASK(64));
@@ -179,21 +182,42 @@ static int __init vkms_init(void)
return ret;
 }
 
-static void __exit vkms_exit(void)
+static int __init vkms_init(void)
+{
+   struct vkms_config *config = kmalloc(sizeof(*config), GFP_KERNEL);
+
+   default_config = config;
+
+   config->cursor = enable_cursor;
+
+   return vkms_create(config);
+}
+
+static void vkms_destroy(struct vkms_config *config)
 {
struct platform_device *pdev;
 
-   if (!vkms_device) {
+   if (!config->dev) {
DRM_INFO("vkms_device is NULL.\n");
return;
}
 
-   pdev = vkms_device->platform;
+   pdev = config->dev->platform;
 
-   drm_dev_unregister(&vkms_device->drm);
-   drm_atomic_helper_shutdown(&vkms_device->drm);
+   drm_dev_unregister(&config->dev->drm);
+   drm_atomic_helper_shutdown(&config->dev->drm);
devres_release_group(&pdev->dev, NULL);
platform_device_unregister(pdev);
+
+   config->dev = NULL;
+}
+
+static void __exit vkms_exit(void)
+{
+   if (default_config->dev)
+   vkms_destroy(default_config);
+
+   kfree(default_config);
 }
 
 module_init(vkms_init);
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 5ed91ff08cb3..6a27bd8875f2 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -19,8 +19,6 @@
 #define XRES_MAX  8192
 #define YRES_MAX  8192
 
-extern bool enable_cursor;
-
 struct vkms_composer {
struct drm_framebuffer fb;
struct drm_rect src, dst;
@@ -82,10 +80,19 @@ struct vkms_output {
spinlock_t composer_lock;
 };
 
+struct vkms_device;
+
+struct vkms_config {
+   bool cursor;
+   /* only set when instantiated */
+   struct vkms_device *dev;
+};
+
 struct vkms_device {
struct drm_device drm;
struct platform_device *platform;
struct vkms_output output;
+   const struct vkms_config *config;
 };
 
 #define drm_crtc_to_vkms_output(target) \
@@ -124,3 +131,4 @@ void vkms_set_composer(struct vkms_output *out, bool 
enabled);
 int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
 
 #endif /* _VKMS_DRV_H_ */
+
diff --git a/drivers/gpu/drm/vkms/vkms_output.c 
b/drivers/gpu/drm/vkms/vkms_output.c
index 4a1848b0318f..8f3ffb28b9d1 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -46,7 +46,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
if (IS_ERR(primary))
return PTR_ERR(primary);
 
-   if (enable_cur

[PATCH V4 0/3] Decouple config data for configfs

2021-01-10 Thread Sumera Priyadarsini
This patchset aims to lay down some prep work before configfs can be
implemented for the vkms driver. The first patch in the series adds a
new type vkms_config to track device configuration. The second and third
patch add module testing support for writeback operations.

The first patch is developed by Daniel Vetter.

Daniel Vetter (1):
  drm/vkms: Add vkms_config type

Sumera Priyadarsini (3):
  drm/vkms: Add vkms_config type
  drm/vkms: Add support for writeback module
  drm/vkms: Add information about module options

 Documentation/gpu/vkms.rst | 10 +++
 drivers/gpu/drm/vkms/vkms_drv.c| 45 --
 drivers/gpu/drm/vkms/vkms_drv.h| 13 +++--
 drivers/gpu/drm/vkms/vkms_output.c | 13 +
 4 files changed, 66 insertions(+), 15 deletions(-)

---
Changes in v2:
 - add Co-developed-by tag
 
Changes in v3:
 - correct usage of Co-developed by tag(Melissa)
 - add enable_writeback_feature(Melissa)
 - modify commit message(Melissa)

Changes in v4:
 - split previous patch into patchset(Melissa)
 - fix checkpatch issue(Melissa)
 - update docs(Daniel)
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH V3] drm/vkms: Decouple config data for configfs

2021-01-05 Thread Sumera Priyadarsini
Currently, data for the device instance is held by vkms_device.
Add a separate type, vkms_config to contain configuration details
for the device and various modes to be later used by configfs.
This config data stays constant once the device is created.

Accordingly, add vkms_create and vkms_destroy to initialize/destroy
device through configfs. Currently, they are being called from vkms_init
and vkms_exit, but will be evoked from configfs later on. When configfs
is added, device configuration will be tracked by configfs and only vkms
device lifetime will be handled by vkms_init and vkms_exit functions.

Modify usage of enable_cursor feature to reflect the changes in
relevant files.

Add enable_writeback_connector feature to vkms_config type.

Co-developed-by: Daniel Vetter 
Signed-off-by: Daniel Vetter 
Signed-off-by: Sumera Priyadarsini 

---
Changes in v2:
- add Co-developed-by tag

Changes in v3:
- correct usage of Co-developed by tag(Melissa)
- add enable_writeback_feature(Melissa)
- modify commit message(Melissa)
---
 drivers/gpu/drm/vkms/vkms_drv.c| 45 --
 drivers/gpu/drm/vkms/vkms_drv.h| 12 ++--
 drivers/gpu/drm/vkms/vkms_output.c | 13 +
 3 files changed, 54 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index aef29393b811..fab964900dce 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -34,12 +34,16 @@
 #define DRIVER_MAJOR   1
 #define DRIVER_MINOR   0
 
-static struct vkms_device *vkms_device;
+static struct vkms_config *default_config;
 
-bool enable_cursor = true;
+static bool enable_cursor = true;
 module_param_named(enable_cursor, enable_cursor, bool, 0444);
 MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
 
+static bool enable_writeback_connector = true;
+module_param_named(enable_writeback_connector, enable_writeback_connector, 
bool, 0444);
+MODULE_PARM_DESC(enable_writeback_connector, "Enable/Disable writeback 
connector support");
+
 DEFINE_DRM_GEM_FOPS(vkms_driver_fops);
 
 static void vkms_release(struct drm_device *dev)
@@ -122,10 +126,11 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev)
return vkms_output_init(vkmsdev, 0);
 }
 
-static int __init vkms_init(void)
+static int vkms_create(struct vkms_config *config)
 {
int ret;
struct platform_device *pdev;
+   struct vkms_device *vkms_device;
 
pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
if (IS_ERR(pdev))
@@ -143,6 +148,8 @@ static int __init vkms_init(void)
goto out_devres;
}
vkms_device->platform = pdev;
+   vkms_device->config = config;
+   config->dev = vkms_device;
 
ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev,
   DMA_BIT_MASK(64));
@@ -179,21 +186,43 @@ static int __init vkms_init(void)
return ret;
 }
 
-static void __exit vkms_exit(void)
+static int __init vkms_init(void)
+{
+   struct vkms_config *config = kmalloc(sizeof(*config), GFP_KERNEL);
+
+   default_config = config;
+
+   config->cursor = enable_cursor;
+   config->writeback = enable_writeback_connector;
+
+   return vkms_create(config);
+}
+
+static void vkms_destroy(struct vkms_config *config)
 {
struct platform_device *pdev;
 
-   if (!vkms_device) {
+   if (!config->dev) {
DRM_INFO("vkms_device is NULL.\n");
return;
}
 
-   pdev = vkms_device->platform;
+   pdev = config->dev->platform;
 
-   drm_dev_unregister(&vkms_device->drm);
-   drm_atomic_helper_shutdown(&vkms_device->drm);
+   drm_dev_unregister(&config->dev->drm);
+   drm_atomic_helper_shutdown(&config->dev->drm);
devres_release_group(&pdev->dev, NULL);
platform_device_unregister(pdev);
+
+   config->dev = NULL;
+}
+
+static void __exit vkms_exit(void)
+{
+   if (default_config->dev)
+   vkms_destroy(default_config);
+
+   kfree(default_config);
 }
 
 module_init(vkms_init);
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 5ed91ff08cb3..caa1fafb6ca7 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -19,8 +19,6 @@
 #define XRES_MAX  8192
 #define YRES_MAX  8192
 
-extern bool enable_cursor;
-
 struct vkms_composer {
struct drm_framebuffer fb;
struct drm_rect src, dst;
@@ -82,10 +80,18 @@ struct vkms_output {
spinlock_t composer_lock;
 };
 
+struct vkms_device;
+struct vkms_config {
+   bool writeback;
+   bool cursor;
+   /* only set when instantiated */
+   struct vkms_device *dev;
+};
 struct vkms_device {
struct drm_device drm;
struct platform_device *platform;
struct vkms_output o

[PATCH V2] drm/vkms: Decouple config data for configfs

2021-01-02 Thread Sumera Priyadarsini
Currently, data for the device instance is held by vkms_device.
Add a separate type, vkms_config to contain configuration details
for the device and various modes to be later used by configfs.
This config data stays constant once the device is created.

Accordingly, add vkms_create and vkms_destroy to initialize/destroy
device through configfs. Currently, they are being called from vkms_init
and vkms_exit, but will be evoked from configfs later on. When configfs
is added, device configuration- enabling/disabling features will
be tracked by configfs and only vkms device lifetime will be kept track of
by vkms_init and vkms_exit functions.

Modify usage of enable_cursor feature to reflect the changes in
relevant files.

Signed-off-by: Sumera Priyadarsini 
Co-developed-by: Daniel Vetter 
---
Changes in v2:
- add Co-developed-by tag

---
 drivers/gpu/drm/vkms/vkms_drv.c| 40 --
 drivers/gpu/drm/vkms/vkms_drv.h| 11 +---
 drivers/gpu/drm/vkms/vkms_output.c |  4 +--
 3 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index aef29393b811..6b33975a5cb2 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -34,9 +34,9 @@
 #define DRIVER_MAJOR   1
 #define DRIVER_MINOR   0
 
-static struct vkms_device *vkms_device;
+static struct vkms_config *default_config;
 
-bool enable_cursor = true;
+static bool enable_cursor = true;
 module_param_named(enable_cursor, enable_cursor, bool, 0444);
 MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
 
@@ -122,10 +122,11 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev)
return vkms_output_init(vkmsdev, 0);
 }
 
-static int __init vkms_init(void)
+static int vkms_create(struct vkms_config *config)
 {
int ret;
struct platform_device *pdev;
+   struct vkms_device *vkms_device;
 
pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
if (IS_ERR(pdev))
@@ -143,6 +144,8 @@ static int __init vkms_init(void)
goto out_devres;
}
vkms_device->platform = pdev;
+   vkms_device->config = config;
+   config->dev = vkms_device;
 
ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev,
   DMA_BIT_MASK(64));
@@ -179,21 +182,42 @@ static int __init vkms_init(void)
return ret;
 }
 
-static void __exit vkms_exit(void)
+static int __init vkms_init(void)
+{
+   struct vkms_config *config = kmalloc(sizeof(*config), GFP_KERNEL);
+
+   default_config = config;
+
+   config->cursor = enable_cursor;
+
+   return vkms_create(config);
+}
+
+static void vkms_destroy(struct vkms_config *config)
 {
struct platform_device *pdev;
 
-   if (!vkms_device) {
+   if (!config->dev) {
DRM_INFO("vkms_device is NULL.\n");
return;
}
 
-   pdev = vkms_device->platform;
+   pdev = config->dev->platform;
 
-   drm_dev_unregister(&vkms_device->drm);
-   drm_atomic_helper_shutdown(&vkms_device->drm);
+   drm_dev_unregister(&config->dev->drm);
+   drm_atomic_helper_shutdown(&config->dev->drm);
devres_release_group(&pdev->dev, NULL);
platform_device_unregister(pdev);
+
+   config->dev = NULL;
+}
+
+static void __exit vkms_exit(void)
+{
+   if (default_config->dev)
+   vkms_destroy(default_config);
+
+   kfree(default_config);
 }
 
 module_init(vkms_init);
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 5ed91ff08cb3..2fa0c52f1dd8 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -19,8 +19,6 @@
 #define XRES_MAX  8192
 #define YRES_MAX  8192
 
-extern bool enable_cursor;
-
 struct vkms_composer {
struct drm_framebuffer fb;
struct drm_rect src, dst;
@@ -82,10 +80,17 @@ struct vkms_output {
spinlock_t composer_lock;
 };
 
+struct vkms_device;
+struct vkms_config {
+   bool cursor;
+   /* only set when instantiated */
+   struct vkms_device *dev;
+};
 struct vkms_device {
struct drm_device drm;
struct platform_device *platform;
struct vkms_output output;
+   const struct vkms_config *config;
 };
 
 #define drm_crtc_to_vkms_output(target) \
@@ -123,4 +128,4 @@ void vkms_set_composer(struct vkms_output *out, bool 
enabled);
 /* Writeback */
 int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
 
-#endif /* _VKMS_DRV_H_ */
+#endif /* _VKMS_DRV_H_ */
\ No newline at end of file
diff --git a/drivers/gpu/drm/vkms/vkms_output.c 
b/drivers/gpu/drm/vkms/vkms_output.c
index 4a1848b0318f..8f3ffb28b9d1 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -46,7 +46,7 @@ int vkms_output_init(struct vkms_d

[PATCH] drm/vkms: Decouple config data for configfs

2021-01-01 Thread Sumera Priyadarsini
Currently, data for the device instance is held by vkms_device.
Add a separate type, vkms_config to contain configuration details
for the device and various modes to be later used by configfs.
This config data stays constant once the device is created.

Accordingly, add vkms_create and vkms_destroy to initialize/destroy
device through configfs. Currently, they are being called from vkms_init
and vkms_exit, but will be evoked from configfs later on. When configfs
is added, device configuration- enabling/disabling features will
be tracked by configfs and only vkms device lifetime will be kept track of
by vkms_init and vkms_exit functions.

Modify usage of enable_cursor feature to reflect the changes in
relevant files.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/vkms/vkms_drv.c| 40 --
 drivers/gpu/drm/vkms/vkms_drv.h| 11 +---
 drivers/gpu/drm/vkms/vkms_output.c |  4 +--
 3 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index aef29393b811..6b33975a5cb2 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -34,9 +34,9 @@
 #define DRIVER_MAJOR   1
 #define DRIVER_MINOR   0
 
-static struct vkms_device *vkms_device;
+static struct vkms_config *default_config;
 
-bool enable_cursor = true;
+static bool enable_cursor = true;
 module_param_named(enable_cursor, enable_cursor, bool, 0444);
 MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
 
@@ -122,10 +122,11 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev)
return vkms_output_init(vkmsdev, 0);
 }
 
-static int __init vkms_init(void)
+static int vkms_create(struct vkms_config *config)
 {
int ret;
struct platform_device *pdev;
+   struct vkms_device *vkms_device;
 
pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
if (IS_ERR(pdev))
@@ -143,6 +144,8 @@ static int __init vkms_init(void)
goto out_devres;
}
vkms_device->platform = pdev;
+   vkms_device->config = config;
+   config->dev = vkms_device;
 
ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev,
   DMA_BIT_MASK(64));
@@ -179,21 +182,42 @@ static int __init vkms_init(void)
return ret;
 }
 
-static void __exit vkms_exit(void)
+static int __init vkms_init(void)
+{
+   struct vkms_config *config = kmalloc(sizeof(*config), GFP_KERNEL);
+
+   default_config = config;
+
+   config->cursor = enable_cursor;
+
+   return vkms_create(config);
+}
+
+static void vkms_destroy(struct vkms_config *config)
 {
struct platform_device *pdev;
 
-   if (!vkms_device) {
+   if (!config->dev) {
DRM_INFO("vkms_device is NULL.\n");
return;
}
 
-   pdev = vkms_device->platform;
+   pdev = config->dev->platform;
 
-   drm_dev_unregister(&vkms_device->drm);
-   drm_atomic_helper_shutdown(&vkms_device->drm);
+   drm_dev_unregister(&config->dev->drm);
+   drm_atomic_helper_shutdown(&config->dev->drm);
devres_release_group(&pdev->dev, NULL);
platform_device_unregister(pdev);
+
+   config->dev = NULL;
+}
+
+static void __exit vkms_exit(void)
+{
+   if (default_config->dev)
+   vkms_destroy(default_config);
+
+   kfree(default_config);
 }
 
 module_init(vkms_init);
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 5ed91ff08cb3..2fa0c52f1dd8 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -19,8 +19,6 @@
 #define XRES_MAX  8192
 #define YRES_MAX  8192
 
-extern bool enable_cursor;
-
 struct vkms_composer {
struct drm_framebuffer fb;
struct drm_rect src, dst;
@@ -82,10 +80,17 @@ struct vkms_output {
spinlock_t composer_lock;
 };
 
+struct vkms_device;
+struct vkms_config {
+   bool cursor;
+   /* only set when instantiated */
+   struct vkms_device *dev;
+};
 struct vkms_device {
struct drm_device drm;
struct platform_device *platform;
struct vkms_output output;
+   const struct vkms_config *config;
 };
 
 #define drm_crtc_to_vkms_output(target) \
@@ -123,4 +128,4 @@ void vkms_set_composer(struct vkms_output *out, bool 
enabled);
 /* Writeback */
 int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
 
-#endif /* _VKMS_DRV_H_ */
+#endif /* _VKMS_DRV_H_ */
\ No newline at end of file
diff --git a/drivers/gpu/drm/vkms/vkms_output.c 
b/drivers/gpu/drm/vkms/vkms_output.c
index 4a1848b0318f..8f3ffb28b9d1 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -46,7 +46,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
if (IS_ERR(primary))
 

[PATCH v3] drm/vkms: Add setup and testing information

2020-12-09 Thread Sumera Priyadarsini
Update the vkms documentation to contain steps to:

 - setup the vkms driver
 - run tests using igt

Signed-off-by: Sumera Priyadarsini 
___
Changes in v2:
 - Change heading to title case (Daniel)
 - Add examples to run tests directly (Daniel)
 - Add examples to run subtests (Melissa)

Changes in v3:
 - Add example using run-tests.sh script(Daniel)
---
 Documentation/gpu/vkms.rst | 70 ++
 1 file changed, 70 insertions(+)

diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst
index 13bab1d93bb3..9e030c74a82e 100644
--- a/Documentation/gpu/vkms.rst
+++ b/Documentation/gpu/vkms.rst
@@ -7,6 +7,76 @@
 .. kernel-doc:: drivers/gpu/drm/vkms/vkms_drv.c
:doc: vkms (Virtual Kernel Modesetting)
 
+Setup
+=
+
+The VKMS driver can be setup with the following steps:
+
+To check if VKMS is loaded, run::
+
+  lsmod | grep vkms
+
+This should list the VKMS driver. If no output is obtained, then
+you need to enable and/or load the VKMS driver.
+Ensure that the VKMS driver has been set as a loadable module in your
+kernel config file. Do::
+
+  make nconfig
+
+  Go to `Device Drivers> Graphics support`
+
+  Enable `Virtual KMS (EXPERIMENTAL)`
+
+Compile and build the kernel for the changes to get reflected.
+Now, to load the driver, use::
+
+  sudo modprobe vkms
+
+On running the lsmod command now, the VKMS driver will appear listed.
+You can also observe the driver being loaded in the dmesg logs.
+
+To disable the driver, use ::
+
+  sudo modprobe -r vkms
+
+Testing With IGT
+
+
+The IGT GPU Tools is a test suite used specifically for debugging and
+development of the DRM drivers.
+The IGT Tools can be installed from
+`here <https://gitlab.freedesktop.org/drm/igt-gpu-tools>`_ .
+
+The tests need to be run without a compositor, so you need to switch to text
+only mode. You can do this by::
+
+  sudo systemctl isolate multi-user.target
+
+To return to graphical mode, do::
+
+  sudo systemctl isolate graphical.target
+
+Once you are in text only mode, you can run tests using the --device switch
+or IGT_DEVICE variable to specify the device filter for the driver we want
+to test. IGT_DEVICE can also be used with the run-test.sh script to run the
+tests for a specific driver::
+
+  sudo ./build/tests/ --device "sys:/sys/devices/platform/vkms"
+  sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./build/tests/
+  sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./scripts/run-tests.sh -t 

+
+For example, to test the functionality of the writeback library,
+we can run the kms_writeback test::
+
+  sudo ./build/tests/kms_writeback --device "sys:/sys/devices/platform/vkms"
+  sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./build/tests/kms_writeback
+  sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./scripts/run-tests.sh -t 
kms_writeback
+
+You can also run subtests if you do not want to run the entire test::
+
+  sudo ./build/tests/kms_flip --run-subtest basic-plain-flip --device 
"sys:/sys/devices/platform/vkms"
+  sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./build/tests/kms_flip 
--run-subtest basic-plain-flip
+
 TODO
 
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH V2] drm/vkms: Add setup and testing information

2020-12-09 Thread Sumera Priyadarsini
On Wed, Dec 9, 2020 at 6:24 AM Daniel Vetter  wrote:
>
> On Wed, Dec 09, 2020 at 02:07:35AM +0530, Sumera Priyadarsini wrote:
> > Update the vkms documentation to contain steps to:
> >
> >  - setup the vkms driver
> >  - run tests using igt
> >
> > Signed-off-by: Sumera Priyadarsini 
> > ___
> > Changes in v2:
> >  - Change heading to title case (Daniel)
> >  - Add examples to run tests directly (Daniel)
> >  - Add examples to run subtests (Melissa)
> > ---
> >  Documentation/gpu/vkms.rst | 67 ++
> >  1 file changed, 67 insertions(+)
> >
> > diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst
> > index 13bab1d93bb3..d6739fbbe503 100644
> > --- a/Documentation/gpu/vkms.rst
> > +++ b/Documentation/gpu/vkms.rst
> > @@ -7,6 +7,73 @@
> >  .. kernel-doc:: drivers/gpu/drm/vkms/vkms_drv.c
> > :doc: vkms (Virtual Kernel Modesetting)
> >
> > +Setup
> > +=
> > +
> > +The VKMS driver can be setup with the following steps:
> > +
> > +To check if VKMS is loaded, run::
> > +
> > +  lsmod | grep vkms
> > +
> > +This should list the VKMS driver. If no output is obtained, then
> > +you need to enable and/or load the VKMS driver.
> > +Ensure that the VKMS driver has been set as a loadable module in your
> > +kernel config file. Do::
> > +
> > +  make nconfig
> > +
> > +  Go to `Device Drivers> Graphics support`
> > +
> > +  Enable `Virtual KMS (EXPERIMENTAL)`
> > +
> > +Compile and build the kernel for the changes to get reflected.
> > +Now, to load the driver, use::
> > +
> > +  sudo modprobe vkms
> > +
> > +On running the lsmod command now, the VKMS driver will appear listed.
> > +You can also observe the driver being loaded in the dmesg logs.
> > +
> > +To disable the driver, use ::
> > +
> > +  sudo modprobe -r vkms
> > +
> > +Testing With IGT
> > +
> > +
> > +The IGT GPU Tools is a test suite used specifically for debugging and
> > +development of the DRM drivers.
> > +The IGT Tools can be installed from
> > +`here <https://gitlab.freedesktop.org/drm/igt-gpu-tools>`_ .
> > +
> > +The tests need to be run without a compositor, so you need to switch to 
> > text
> > +only mode. You can do this by::
> > +
> > +  sudo systemctl isolate multi-user.target
> > +
> > +To return to graphical mode, do::
> > +
> > +  sudo systemctl isolate graphical.target
> > +
> > +Once you are in text only mode, you can run tests using the --device switch
> > +or IGT_DEVICE variable to specify the device filter for the driver we want
> > +to test::
> > +
> > +  sudo ./build/tests/ --device 
> > "sys:/sys/devices/platform/vkms"
> > +  sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./build/tests/ > test>
> > +
> > +For example, to test the functionality of the writeback library,
> > +we can run the kms_writeback test::
> > +
> > +  sudo ./build/tests/kms_writeback --device 
> > "sys:/sys/devices/platform/vkms"
> > +  sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" 
> > ./build/tests/kms_writeback
> > +
> > +You can also run subtests if you do not want to run the entire test::
> > +
> > +  sudo ./build/tests/kms_flip --run-subtest basic-plain-flip --device 
> > "sys:/sys/devices/platform/vkms"
> > +  sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./build/tests/kms_flip 
> > --run-subtest basic-plain-flip
>
> Does IGT_DEVICE also work with run-tests.sh? Aside from my curious
> question, patch looks good to me, thanks a lot.

Good catch, it does.

Melissa, IGT_FORCE_DRIVER also works. I think I was used test/kms_flip
earlier instead of
./build/test/kms_flip hence the fluke.

Should I add these also to the docs, was wondering if it will get too
confusing

>
> Reviewed-by: Daniel Vetter 
>
> > +
> >  TODO
> >  
> >
> > --
> > 2.25.1
> >
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
`sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./scripts/run-tests.sh -t kms_writeback`

[9445.317993] [1/4] kms_writeback (writeback-pixel-formats)
[9445.623499] [2/4] kms_writeback (writeback-invalid-parameters)
[9447.076263] [3/4] kms_writeback (writeback-fb-id)
[9447.371402] [4/4] kms_writeback (writeback-check-output)
Done.



`sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./build/tests/kms_writeback`

[PATCH V2] drm/vkms: Add setup and testing information

2020-12-08 Thread Sumera Priyadarsini
Update the vkms documentation to contain steps to:

 - setup the vkms driver
 - run tests using igt

Signed-off-by: Sumera Priyadarsini 
___
Changes in v2:
 - Change heading to title case (Daniel)
 - Add examples to run tests directly (Daniel)
 - Add examples to run subtests (Melissa)
---
 Documentation/gpu/vkms.rst | 67 ++
 1 file changed, 67 insertions(+)

diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst
index 13bab1d93bb3..d6739fbbe503 100644
--- a/Documentation/gpu/vkms.rst
+++ b/Documentation/gpu/vkms.rst
@@ -7,6 +7,73 @@
 .. kernel-doc:: drivers/gpu/drm/vkms/vkms_drv.c
:doc: vkms (Virtual Kernel Modesetting)
 
+Setup
+=
+
+The VKMS driver can be setup with the following steps:
+
+To check if VKMS is loaded, run::
+
+  lsmod | grep vkms
+
+This should list the VKMS driver. If no output is obtained, then
+you need to enable and/or load the VKMS driver.
+Ensure that the VKMS driver has been set as a loadable module in your
+kernel config file. Do::
+
+  make nconfig
+
+  Go to `Device Drivers> Graphics support`
+
+  Enable `Virtual KMS (EXPERIMENTAL)`
+
+Compile and build the kernel for the changes to get reflected.
+Now, to load the driver, use::
+
+  sudo modprobe vkms
+
+On running the lsmod command now, the VKMS driver will appear listed.
+You can also observe the driver being loaded in the dmesg logs.
+
+To disable the driver, use ::
+
+  sudo modprobe -r vkms
+
+Testing With IGT
+
+
+The IGT GPU Tools is a test suite used specifically for debugging and
+development of the DRM drivers.
+The IGT Tools can be installed from
+`here <https://gitlab.freedesktop.org/drm/igt-gpu-tools>`_ .
+
+The tests need to be run without a compositor, so you need to switch to text
+only mode. You can do this by::
+
+  sudo systemctl isolate multi-user.target
+
+To return to graphical mode, do::
+
+  sudo systemctl isolate graphical.target
+
+Once you are in text only mode, you can run tests using the --device switch
+or IGT_DEVICE variable to specify the device filter for the driver we want
+to test::
+
+  sudo ./build/tests/ --device "sys:/sys/devices/platform/vkms"
+  sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./build/tests/
+
+For example, to test the functionality of the writeback library,
+we can run the kms_writeback test::
+
+  sudo ./build/tests/kms_writeback --device "sys:/sys/devices/platform/vkms"
+  sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./build/tests/kms_writeback
+
+You can also run subtests if you do not want to run the entire test::
+
+  sudo ./build/tests/kms_flip --run-subtest basic-plain-flip --device 
"sys:/sys/devices/platform/vkms"
+  sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./build/tests/kms_flip 
--run-subtest basic-plain-flip
+
 TODO
 
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH] drm/vkms: Add setup and testing information

2020-12-03 Thread Sumera Priyadarsini
Update the vkms documentation to contain steps to:

 - setup the vkms driver
 - run tests using igt

Signed-off-by: Sumera Priyadarsini 
---
 Documentation/gpu/vkms.rst | 47 ++
 1 file changed, 47 insertions(+)

diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst
index 13bab1d93bb3..d6782174d23f 100644
--- a/Documentation/gpu/vkms.rst
+++ b/Documentation/gpu/vkms.rst
@@ -7,6 +7,53 @@
 .. kernel-doc:: drivers/gpu/drm/vkms/vkms_drv.c
:doc: vkms (Virtual Kernel Modesetting)
 
+SETUP
+=
+
+The VKMS driver can be setup with the following steps:
+
+To check if VKMS is loaded, run::
+
+  lsmod | grep vkms
+
+This should list the VKMS driver. If no output is obtained, then
+you need to enable and/or load the VKMS driver.
+Ensure that the VKMS driver has been set as a loadable module in your
+kernel config file. The following line should be present in the .config
+file in your kernel root::
+
+  CONFIG_DRM_VKMS=m
+
+Compile and build the kernel for the changes to get reflected.
+If your existing config already has VKMS available as a loadable module,
+then there is no need to build the kernel again.
+Now, to load the driver, use::
+
+  sudo modprobe vkms
+
+On running the lsmod command now, the VKMS driver will appear listed.
+You can also observe the driver being loaded in the dmesg logs.
+
+To disable the driver, use ::
+
+  sudo modprobe -r vkms
+
+TESTING WITH IGT
+
+
+The IGT GPU Tools is a test suite used specifically for debugging and
+development of the DRM drivers.
+The IGT Tools can be installed from
+`here <https://gitlab.freedesktop.org/drm/igt-gpu-tools>`_ .
+Once you have installed IGT, you can run tests using::
+
+  ./scripts/run-tests.sh -t 
+
+For example, to test the functionality of the igt_draw library,
+we can run the kms_draw_crc test::
+
+  ./scripts/run-tests.sh -t kms_draw_crc
+
 TODO
 
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [Outreachy kernel] [PATCH] drm/amdgpu: use DEFINE_DEBUGFS_ATTRIBUTE with debugfs_create_file_unsafe()

2020-11-01 Thread Sumera Priyadarsini
On Fri, 30 Oct, 2020, 1:32 PM Greg KH,  wrote:

> On Fri, Oct 30, 2020 at 01:27:16PM +0530, Deepak R Varma wrote:
> > On Fri, Oct 30, 2020 at 08:11:20AM +0100, Greg KH wrote:
> > > On Fri, Oct 30, 2020 at 08:52:45AM +0530, Deepak R Varma wrote:
> > > > Using DEFINE_DEBUGFS_ATTRIBUTE macro with
> debugfs_create_file_unsafe()
> > > > function in place of the debugfs_create_file() function will make the
> > > > file operation struct "reset" aware of the file's lifetime.
> Additional
> > > > details here:
> https://lists.archive.carbon60.com/linux/kernel/2369498
> > > >
> > > > Issue reported by Coccinelle script:
> > > > scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci
> > > >
> > > > Signed-off-by: Deepak R Varma 
> > > > ---
> > > > Please Note: This is a Outreachy project task patch.
> > > >
> > > >  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 20
> ++--
> > > >  1 file changed, 10 insertions(+), 10 deletions(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> > > > index 2d125b8b15ee..f076b1ba7319 100644
> > > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> > > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> > > > @@ -1551,29 +1551,29 @@ static int amdgpu_debugfs_sclk_set(void
> *data, u64 val)
> > > >   return 0;
> > > >  }
> > > >
> > > > -DEFINE_SIMPLE_ATTRIBUTE(fops_ib_preempt, NULL,
> > > > - amdgpu_debugfs_ib_preempt, "%llu\n");
> > > > +DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
> > > > +  amdgpu_debugfs_ib_preempt, "%llu\n");
> > >
> > > Are you sure this is ok?  Do these devices need this additional
> > > "protection"?  Do they have the problem that these macros were written
> > > for?
> > >
> > > Same for the other patches you just submitted here, I think you need to
> > > somehow "prove" that these changes are necessary, checkpatch isn't able
> > > to determine this all the time.
> >
> > Hi Greg,
> > Based on my understanding, the current function debugfs_create_file()
> > adds an overhead of lifetime managing proxy for such fop structs. This
> > should be applicable to these set of drivers as well. Hence I think this
> > change will be useful.
>
> Why do these drivers need these changes?  Are these files dynamically
> removed from the system at random times?
>
> There is a reason we didn't just do a global search/replace for this in
> the kernel when the new functions were added, so I don't know why
> checkpatch is now saying it must be done.
>

Hi,

Sorry to jump in on the thread this way, but what exactly does a 'lifetime
managing proxy' for file operations mean? I am trying to understand how
DEFINE_DEBUGFS_ATTRIBUTE changes things wrt debug_ fs file operations but
can't find many resources. :(

Please let me know if I should be asking this in a different mailing
list/irc instead.

The change seems to be suggested by a coccinelle script.

Regards,
Sumera


thanks,
>
> greg k-h
>
> --
> You received this message because you are subscribed to the Google Groups
> "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to outreachy-kernel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/outreachy-kernel/20201030080316.GA1612206%40kroah.com
> .
>
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[Outreachy][PATCH] drm/amdgpu: use true and false for bool initialisations

2020-10-27 Thread Sumera Priyadarsini
Bool initialisation should use 'true' and 'false' values instead of 0
and 1.

Modify amdgpu_amdkfd_gpuvm.c to initialise variable is_imported
to false instead of 0.

Issue found with Coccinelle.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 64d4b5ff95d6..ba4bd06bfcc5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1288,7 +1288,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
struct ttm_validate_buffer *bo_list_entry;
unsigned int mapped_to_gpu_memory;
int ret;
-   bool is_imported = 0;
+   bool is_imported = false;
 
mutex_lock(&mem->lock);
mapped_to_gpu_memory = mem->mapped_to_gpu_memory;
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

2020-10-23 Thread Sumera Priyadarsini
Using snprintf() for show() methods holds the risk of buffer overrun
as snprintf() does not know the PAGE_SIZE maximum of the temporary
buffer used to output sysfs content.

Modify amdgpu_psp.c to use sysfs_emit() instead which knows the
size of the temporary buffer.

Issue found with Coccinelle.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index d6c38e24f130..4d1d1e1b005d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -2621,7 +2621,7 @@ static ssize_t psp_usbc_pd_fw_sysfs_read(struct device 
*dev,
return ret;
}
 
-   return snprintf(buf, PAGE_SIZE, "%x\n", fw_ver);
+   return sysfs_emit(buf, PAGE_SIZE, "%x\n", fw_ver);
 }
 
 static ssize_t psp_usbc_pd_fw_sysfs_write(struct device *dev,
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit

2020-10-23 Thread Sumera Priyadarsini
Using snprintf() for show() methods holds the risk of buffer overrun
as snprintf() does not know the PAGE_SIZE maximum of the temporary
buffer used to output sysfs content.

This patchset is a series of Coccinelle cleanups across the staging
directory to convert snprintf with scnprintf in the relevant files.

Sumera Priyadarsini (5):
  gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
  gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
  gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
  gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
  gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c   | 8 
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c  | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c  | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [Outreachy kernel] [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

2020-10-23 Thread Sumera Priyadarsini
On Thu, Oct 22, 2020 at 7:24 PM Greg KH  wrote:

> On Thu, Oct 22, 2020 at 07:17:56PM +0530, Sumera Priyadarsini wrote:
> > Using snprintf() for show() methods holds the risk of buffer overrun
> > as snprintf() does not know the PAGE_SIZE maximum of the temporary
> > buffer used to output sysfs content.
> >
> > Modify amdgpu_psp.c to use sysfs_emit() instead which knows the
> > size of the temporary buffer.
> >
> > Issue found with Coccinelle.
> >
> > Signed-off-by: Sumera Priyadarsini 
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
> > index d6c38e24f130..4d1d1e1b005d 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
> > @@ -2621,7 +2621,7 @@ static ssize_t psp_usbc_pd_fw_sysfs_read(struct
> device *dev,
> >   return ret;
> >   }
> >
> > - return snprintf(buf, PAGE_SIZE, "%x\n", fw_ver);
> > + return sysfs_emit(buf, PAGE_SIZE, "%x\n", fw_ver);
>
> Did you build this code?  I don't think it is correct...
>

Yes, you are right. I compiled all of them again separately. I had based
them off the usual drm tree
but that is wrong because sysfs_emit has been added only in the 5.10. I
will send a v2 with the proper
corrections.

regards,
sumera


> thanks,
>
> greg k-h
>
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 3/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

2020-10-23 Thread Sumera Priyadarsini
Using snprintf() for show() methods holds the risk of buffer overrun
as snprintf() does not know the PAGE_SIZE maximum of the temporary
buffer used to output sysfs content.

Modify amdgpu_gtt_mgr.c to use sysfs_emit() instead which knows the
size of the temporary buffer.

Issue found with Coccinelle.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 1721739def84..441e07ee1967 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -49,7 +49,7 @@ static ssize_t amdgpu_mem_info_gtt_total_show(struct device 
*dev,
struct amdgpu_device *adev = drm_to_adev(ddev);
struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, 
TTM_PL_TT);
 
-   return snprintf(buf, PAGE_SIZE, "%llu\n",
+   return sysfs_emit(buf, PAGE_SIZE, "%llu\n",
man->size * PAGE_SIZE);
 }
 
@@ -68,7 +68,7 @@ static ssize_t amdgpu_mem_info_gtt_used_show(struct device 
*dev,
struct amdgpu_device *adev = drm_to_adev(ddev);
struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, 
TTM_PL_TT);
 
-   return snprintf(buf, PAGE_SIZE, "%llu\n",
+   return sysfs_emit(buf, PAGE_SIZE, "%llu\n",
amdgpu_gtt_mgr_usage(man));
 }
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 5/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

2020-10-23 Thread Sumera Priyadarsini
Using snprintf() for show() methods holds the risk of buffer overrun
as snprintf() does not know the PAGE_SIZE maximum of the temporary
buffer used to output sysfs content.

Modify amdgpu_ras.c to use sysfs_emit() instead which knows the
size of the temporary buffer.

Issue found with Coccinelle.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
index e5ea14774c0c..6d9901e1b4b0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
@@ -429,13 +429,13 @@ static ssize_t amdgpu_ras_sysfs_read(struct device *dev,
};
 
if (!amdgpu_ras_get_error_query_ready(obj->adev))
-   return snprintf(buf, PAGE_SIZE,
+   return sysfs_emit(buf, PAGE_SIZE,
"Query currently inaccessible\n");
 
if (amdgpu_ras_error_query(obj->adev, &info))
return -EINVAL;
 
-   return snprintf(buf, PAGE_SIZE, "%s: %lu\n%s: %lu\n",
+   return sysfs_emit(buf, PAGE_SIZE, "%s: %lu\n%s: %lu\n",
"ue", info.ue_count,
"ce", info.ce_count);
 }
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 2/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

2020-10-23 Thread Sumera Priyadarsini
Using snprintf() for show() methods holds the risk of buffer overrun
as snprintf() does not know the PAGE_SIZE maximum of the temporary
buffer used to output sysfs content.

Modify amdgpu_device.c to use sysfs_emit() instead which knows the
size of the temporary buffer.

Issue found with Coccinelle.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index f7307af76452..7eef6b20578f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -135,7 +135,7 @@ static ssize_t amdgpu_device_get_pcie_replay_count(struct 
device *dev,
struct amdgpu_device *adev = drm_to_adev(ddev);
uint64_t cnt = amdgpu_asic_get_pcie_replay_count(adev);
 
-   return snprintf(buf, PAGE_SIZE, "%llu\n", cnt);
+   return sysfs_emit(buf, PAGE_SIZE, "%llu\n", cnt);
 }
 
 static DEVICE_ATTR(pcie_replay_count, S_IRUGO,
@@ -159,7 +159,7 @@ static ssize_t amdgpu_device_get_product_name(struct device 
*dev,
struct drm_device *ddev = dev_get_drvdata(dev);
struct amdgpu_device *adev = drm_to_adev(ddev);
 
-   return snprintf(buf, PAGE_SIZE, "%s\n", adev->product_name);
+   return sysfs_emit(buf, PAGE_SIZE, "%s\n", adev->product_name);
 }
 
 static DEVICE_ATTR(product_name, S_IRUGO,
@@ -181,7 +181,7 @@ static ssize_t amdgpu_device_get_product_number(struct 
device *dev,
struct drm_device *ddev = dev_get_drvdata(dev);
struct amdgpu_device *adev = drm_to_adev(ddev);
 
-   return snprintf(buf, PAGE_SIZE, "%s\n", adev->product_number);
+   return sysfs_emit(buf, PAGE_SIZE, "%s\n", adev->product_number);
 }
 
 static DEVICE_ATTR(product_number, S_IRUGO,
@@ -203,7 +203,7 @@ static ssize_t amdgpu_device_get_serial_number(struct 
device *dev,
struct drm_device *ddev = dev_get_drvdata(dev);
struct amdgpu_device *adev = drm_to_adev(ddev);
 
-   return snprintf(buf, PAGE_SIZE, "%s\n", adev->serial);
+   return sysfs_emit(buf, PAGE_SIZE, "%s\n", adev->serial);
 }
 
 static DEVICE_ATTR(serial_number, S_IRUGO,
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 1/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

2020-10-23 Thread Sumera Priyadarsini
Using snprintf() for show() methods holds the risk of buffer overrun
as snprintf() does not know the PAGE_SIZE maximum of the temporary
buffer used to output sysfs content.

Modify amdgpu_atombios.c to use sysfs_emit() instead which knows the
size of the temporary buffer.

Issue found with Coccinelle.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
index 469352e2d6ec..3c19862c94c7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
@@ -1947,7 +1947,7 @@ static ssize_t amdgpu_atombios_get_vbios_version(struct 
device *dev,
struct amdgpu_device *adev = drm_to_adev(ddev);
struct atom_context *ctx = adev->mode_info.atom_context;
 
-   return snprintf(buf, PAGE_SIZE, "%s\n", ctx->vbios_version);
+   return sysfs_emit(buf, PAGE_SIZE, "%s\n", ctx->vbios_version);
 }
 
 static DEVICE_ATTR(vbios_version, 0444, amdgpu_atombios_get_vbios_version,
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[Outreachy kernel][PATCH] gpu: amd: Return boolean types instead of integer values

2020-10-22 Thread Sumera Priyadarsini
Return statements for functions returning bool should use truth
and false instead of 1 and 0 respectively.

Modify cik_event_interrupt.c to return false instead of 0.

Issue found with Coccinelle.

Signed-off-by: Sumera Priyadarsini 
---
 drivers/gpu/drm/amd/amdkfd/cik_event_interrupt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/cik_event_interrupt.c 
b/drivers/gpu/drm/amd/amdkfd/cik_event_interrupt.c
index 24b471734117..8e64c01565ac 100644
--- a/drivers/gpu/drm/amd/amdkfd/cik_event_interrupt.c
+++ b/drivers/gpu/drm/amd/amdkfd/cik_event_interrupt.c
@@ -66,12 +66,12 @@ static bool cik_event_interrupt_isr(struct kfd_dev *dev,
vmid  = (ihre->ring_id & 0xff00) >> 8;
if (vmid < dev->vm_info.first_vmid_kfd ||
vmid > dev->vm_info.last_vmid_kfd)
-   return 0;
+   return false;
 
/* If there is no valid PASID, it's likely a firmware bug */
pasid = (ihre->ring_id & 0x) >> 16;
if (WARN_ONCE(pasid == 0, "FW bug: No PASID in KFD interrupt"))
-   return 0;
+   return false;
 
/* Interrupt types we care about: various signals and faults.
 * They will be forwarded to a work queue (see below).
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel