2019-02-06 22:01:16 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
|
|
|
2018-05-14 22:33:46 +08:00
|
|
|
#ifndef _VKMS_DRV_H_
|
|
|
|
#define _VKMS_DRV_H_
|
|
|
|
|
2019-06-30 14:19:01 +08:00
|
|
|
#include <linux/hrtimer.h>
|
|
|
|
|
2018-05-17 07:56:21 +08:00
|
|
|
#include <drm/drm.h>
|
2018-07-12 10:01:47 +08:00
|
|
|
#include <drm/drm_gem.h>
|
2018-05-17 07:56:21 +08:00
|
|
|
#include <drm/drm_encoder.h>
|
|
|
|
|
2018-09-06 13:17:16 +08:00
|
|
|
#define XRES_MIN 20
|
|
|
|
#define YRES_MIN 20
|
2018-07-12 10:02:14 +08:00
|
|
|
|
|
|
|
#define XRES_DEF 1024
|
|
|
|
#define YRES_DEF 768
|
|
|
|
|
|
|
|
#define XRES_MAX 8192
|
|
|
|
#define YRES_MAX 8192
|
|
|
|
|
2018-09-06 13:19:11 +08:00
|
|
|
extern bool enable_cursor;
|
|
|
|
|
2019-06-26 09:37:05 +08:00
|
|
|
struct vkms_composer {
|
2018-08-02 09:10:26 +08:00
|
|
|
struct drm_framebuffer fb;
|
2018-09-06 13:18:26 +08:00
|
|
|
struct drm_rect src, dst;
|
|
|
|
unsigned int offset;
|
|
|
|
unsigned int pitch;
|
|
|
|
unsigned int cpp;
|
2018-08-02 09:10:26 +08:00
|
|
|
};
|
|
|
|
|
2018-08-02 09:08:22 +08:00
|
|
|
/**
|
|
|
|
* vkms_plane_state - Driver specific plane state
|
|
|
|
* @base: base plane state
|
2019-06-26 09:37:05 +08:00
|
|
|
* @composer: data required for composing computation
|
2018-08-02 09:08:22 +08:00
|
|
|
*/
|
|
|
|
struct vkms_plane_state {
|
|
|
|
struct drm_plane_state base;
|
2019-06-26 09:37:05 +08:00
|
|
|
struct vkms_composer *composer;
|
2018-08-02 09:08:22 +08:00
|
|
|
};
|
|
|
|
|
2018-07-25 00:31:05 +08:00
|
|
|
/**
|
|
|
|
* vkms_crtc_state - Driver specific CRTC state
|
|
|
|
* @base: base CRTC state
|
2019-06-26 09:37:05 +08:00
|
|
|
* @composer_work: work struct to compose and add CRC entries
|
2018-09-04 05:18:17 +08:00
|
|
|
* @n_frame_start: start frame number for computed CRC
|
|
|
|
* @n_frame_end: end frame number for computed CRC
|
2018-07-25 00:31:05 +08:00
|
|
|
*/
|
|
|
|
struct vkms_crtc_state {
|
|
|
|
struct drm_crtc_state base;
|
2019-06-26 09:37:05 +08:00
|
|
|
struct work_struct composer_work;
|
drm/vkms: Fix crc worker races
The issue we have is that the crc worker might fall behind. We've
tried to handle this by tracking both the earliest frame for which it
still needs to compute a crc, and the last one. Plus when the
crtc_state changes, we have a new work item, which are all run in
order due to the ordered workqueue we allocate for each vkms crtc.
Trouble is there's been a few small issues in the current code:
- we need to capture frame_end in the vblank hrtimer, not in the
worker. The worker might run much later, and then we generate a lot
of crc for which there's already a different worker queued up.
- frame number might be 0, so create a new crc_pending boolean to
track this without confusion.
- we need to atomically grab frame_start/end and clear it, so do that
all in one go. This is not going to create a new race, because if we
race with the hrtimer then our work will be re-run.
- only race that can happen is the following:
1. worker starts
2. hrtimer runs and updates frame_end
3. worker grabs frame_start/end, already reading the new frame_end,
and clears crc_pending
4. hrtimer calls queue_work()
5. worker completes
6. worker gets re-run, crc_pending is false
Explain this case a bit better by rewording the comment.
v2: Demote warning level output to debug when we fail to requeue, this
is expected under high load when the crc worker can't quite keep up.
Cc: Shayenne Moura <shayenneluzmoura@gmail.com>
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Tested-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190606222751.32567-2-daniel.vetter@ffwll.ch
2019-06-07 06:27:42 +08:00
|
|
|
|
drm/vkms: totally reworked crc data tracking
The crc computation worker needs to be able to get at some data
structures and framebuffer mappings, while potentially more atomic
updates are going on. The solution thus far is to copy relevant bits
around, but that's very tedious.
Here's a new approach, which tries to be more clever, but relies on a
few not-so-obvious things:
- crtc_state is always updated when a plane_state changes. Therefore
we can just stuff plane_state pointers into a crtc_state. That
solves the problem of easily getting at the needed plane_states.
- with the flushing changes from previous patches the above also holds
without races due to the next atomic update being a bit eager with
cleaning up pending work - we always wait for all crc work items to
complete before unmapping framebuffers.
- we also need to make sure that the hrtimer fires off the right
worker. Keep a new distinct crc_state pointer, under the
vkms_output->lock protection for this. Note that crtc->state is
updated very early in the atomic commit, way before we arm the
vblank event - the vblank event should always match the buffers we
use to compute the crc. This also solves an issue in the hrtimer,
where we've accessed drm_crtc->state without holding the right locks
(we held none - oops).
- in the worker itself we can then just access the plane states we
need, again solving a bunch of ordering and locking issues.
Accessing plane->state requires locks, accessing the private
vkms_crtc_state->active_planes pointer only requires that the memory
doesn't get freed too early.
The idea behind vkms_crtc_state->active_planes is that this would
contain all visible planes, in z-order, as a first step towards a more
generic blending implementation.
Note that this patch also fixes races between prepare_fb/cleanup_fb
and the crc worker accessing ->vaddr.
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Tested-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190606222751.32567-10-daniel.vetter@ffwll.ch
2019-06-07 06:27:50 +08:00
|
|
|
int num_active_planes;
|
|
|
|
/* stack of active planes for crc computation, should be in z order */
|
|
|
|
struct vkms_plane_state **active_planes;
|
|
|
|
|
2019-06-26 09:37:05 +08:00
|
|
|
/* below three are protected by vkms_output.composer_lock */
|
drm/vkms: Fix crc worker races
The issue we have is that the crc worker might fall behind. We've
tried to handle this by tracking both the earliest frame for which it
still needs to compute a crc, and the last one. Plus when the
crtc_state changes, we have a new work item, which are all run in
order due to the ordered workqueue we allocate for each vkms crtc.
Trouble is there's been a few small issues in the current code:
- we need to capture frame_end in the vblank hrtimer, not in the
worker. The worker might run much later, and then we generate a lot
of crc for which there's already a different worker queued up.
- frame number might be 0, so create a new crc_pending boolean to
track this without confusion.
- we need to atomically grab frame_start/end and clear it, so do that
all in one go. This is not going to create a new race, because if we
race with the hrtimer then our work will be re-run.
- only race that can happen is the following:
1. worker starts
2. hrtimer runs and updates frame_end
3. worker grabs frame_start/end, already reading the new frame_end,
and clears crc_pending
4. hrtimer calls queue_work()
5. worker completes
6. worker gets re-run, crc_pending is false
Explain this case a bit better by rewording the comment.
v2: Demote warning level output to debug when we fail to requeue, this
is expected under high load when the crc worker can't quite keep up.
Cc: Shayenne Moura <shayenneluzmoura@gmail.com>
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Tested-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190606222751.32567-2-daniel.vetter@ffwll.ch
2019-06-07 06:27:42 +08:00
|
|
|
bool crc_pending;
|
2018-09-04 05:18:17 +08:00
|
|
|
u64 frame_start;
|
|
|
|
u64 frame_end;
|
2018-07-25 00:31:05 +08:00
|
|
|
};
|
|
|
|
|
2018-05-17 07:56:21 +08:00
|
|
|
struct vkms_output {
|
|
|
|
struct drm_crtc crtc;
|
|
|
|
struct drm_encoder encoder;
|
|
|
|
struct drm_connector connector;
|
2018-07-12 10:02:26 +08:00
|
|
|
struct hrtimer vblank_hrtimer;
|
|
|
|
ktime_t period_ns;
|
|
|
|
struct drm_pending_vblank_event *event;
|
2019-06-26 09:37:05 +08:00
|
|
|
/* ordered wq for composer_work */
|
|
|
|
struct workqueue_struct *composer_workq;
|
|
|
|
/* protects concurrent access to composer */
|
2018-08-02 09:10:26 +08:00
|
|
|
spinlock_t lock;
|
2019-06-07 06:27:44 +08:00
|
|
|
|
drm/vkms: totally reworked crc data tracking
The crc computation worker needs to be able to get at some data
structures and framebuffer mappings, while potentially more atomic
updates are going on. The solution thus far is to copy relevant bits
around, but that's very tedious.
Here's a new approach, which tries to be more clever, but relies on a
few not-so-obvious things:
- crtc_state is always updated when a plane_state changes. Therefore
we can just stuff plane_state pointers into a crtc_state. That
solves the problem of easily getting at the needed plane_states.
- with the flushing changes from previous patches the above also holds
without races due to the next atomic update being a bit eager with
cleaning up pending work - we always wait for all crc work items to
complete before unmapping framebuffers.
- we also need to make sure that the hrtimer fires off the right
worker. Keep a new distinct crc_state pointer, under the
vkms_output->lock protection for this. Note that crtc->state is
updated very early in the atomic commit, way before we arm the
vblank event - the vblank event should always match the buffers we
use to compute the crc. This also solves an issue in the hrtimer,
where we've accessed drm_crtc->state without holding the right locks
(we held none - oops).
- in the worker itself we can then just access the plane states we
need, again solving a bunch of ordering and locking issues.
Accessing plane->state requires locks, accessing the private
vkms_crtc_state->active_planes pointer only requires that the memory
doesn't get freed too early.
The idea behind vkms_crtc_state->active_planes is that this would
contain all visible planes, in z-order, as a first step towards a more
generic blending implementation.
Note that this patch also fixes races between prepare_fb/cleanup_fb
and the crc worker accessing ->vaddr.
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Tested-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190606222751.32567-10-daniel.vetter@ffwll.ch
2019-06-07 06:27:50 +08:00
|
|
|
/* protected by @lock */
|
2019-06-26 09:37:05 +08:00
|
|
|
bool composer_enabled;
|
|
|
|
struct vkms_crtc_state *composer_state;
|
drm/vkms: totally reworked crc data tracking
The crc computation worker needs to be able to get at some data
structures and framebuffer mappings, while potentially more atomic
updates are going on. The solution thus far is to copy relevant bits
around, but that's very tedious.
Here's a new approach, which tries to be more clever, but relies on a
few not-so-obvious things:
- crtc_state is always updated when a plane_state changes. Therefore
we can just stuff plane_state pointers into a crtc_state. That
solves the problem of easily getting at the needed plane_states.
- with the flushing changes from previous patches the above also holds
without races due to the next atomic update being a bit eager with
cleaning up pending work - we always wait for all crc work items to
complete before unmapping framebuffers.
- we also need to make sure that the hrtimer fires off the right
worker. Keep a new distinct crc_state pointer, under the
vkms_output->lock protection for this. Note that crtc->state is
updated very early in the atomic commit, way before we arm the
vblank event - the vblank event should always match the buffers we
use to compute the crc. This also solves an issue in the hrtimer,
where we've accessed drm_crtc->state without holding the right locks
(we held none - oops).
- in the worker itself we can then just access the plane states we
need, again solving a bunch of ordering and locking issues.
Accessing plane->state requires locks, accessing the private
vkms_crtc_state->active_planes pointer only requires that the memory
doesn't get freed too early.
The idea behind vkms_crtc_state->active_planes is that this would
contain all visible planes, in z-order, as a first step towards a more
generic blending implementation.
Note that this patch also fixes races between prepare_fb/cleanup_fb
and the crc worker accessing ->vaddr.
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Tested-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190606222751.32567-10-daniel.vetter@ffwll.ch
2019-06-07 06:27:50 +08:00
|
|
|
|
2019-06-26 09:37:05 +08:00
|
|
|
spinlock_t composer_lock;
|
2018-05-17 07:56:21 +08:00
|
|
|
};
|
2018-05-14 22:33:46 +08:00
|
|
|
|
|
|
|
struct vkms_device {
|
|
|
|
struct drm_device drm;
|
|
|
|
struct platform_device *platform;
|
2018-05-17 07:56:21 +08:00
|
|
|
struct vkms_output output;
|
2018-05-14 22:33:46 +08:00
|
|
|
};
|
|
|
|
|
2018-07-12 10:01:47 +08:00
|
|
|
struct vkms_gem_object {
|
|
|
|
struct drm_gem_object gem;
|
|
|
|
struct mutex pages_lock; /* Page lock used in page fault handler */
|
|
|
|
struct page **pages;
|
2018-07-25 00:26:59 +08:00
|
|
|
unsigned int vmap_count;
|
|
|
|
void *vaddr;
|
2018-07-12 10:01:47 +08:00
|
|
|
};
|
|
|
|
|
2018-07-12 10:02:26 +08:00
|
|
|
#define drm_crtc_to_vkms_output(target) \
|
|
|
|
container_of(target, struct vkms_output, crtc)
|
|
|
|
|
|
|
|
#define drm_device_to_vkms_device(target) \
|
|
|
|
container_of(target, struct vkms_device, drm)
|
|
|
|
|
2018-07-25 00:26:59 +08:00
|
|
|
#define drm_gem_to_vkms_gem(target)\
|
|
|
|
container_of(target, struct vkms_gem_object, gem)
|
|
|
|
|
2018-07-25 00:31:05 +08:00
|
|
|
#define to_vkms_crtc_state(target)\
|
|
|
|
container_of(target, struct vkms_crtc_state, base)
|
|
|
|
|
2018-08-02 09:08:22 +08:00
|
|
|
#define to_vkms_plane_state(target)\
|
|
|
|
container_of(target, struct vkms_plane_state, base)
|
|
|
|
|
2018-07-12 10:02:26 +08:00
|
|
|
/* CRTC */
|
2018-05-17 07:56:21 +08:00
|
|
|
int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
|
|
|
|
struct drm_plane *primary, struct drm_plane *cursor);
|
|
|
|
|
2018-07-12 10:02:26 +08:00
|
|
|
bool vkms_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
|
|
|
|
int *max_error, ktime_t *vblank_time,
|
|
|
|
bool in_vblank_irq);
|
|
|
|
|
2019-06-26 09:36:18 +08:00
|
|
|
int vkms_output_init(struct vkms_device *vkmsdev, int index);
|
2018-05-17 07:56:21 +08:00
|
|
|
|
2018-09-06 13:17:16 +08:00
|
|
|
struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev,
|
2019-06-26 09:36:18 +08:00
|
|
|
enum drm_plane_type type, int index);
|
2018-05-17 07:56:21 +08:00
|
|
|
|
2018-07-12 10:01:47 +08:00
|
|
|
/* Gem stuff */
|
|
|
|
struct drm_gem_object *vkms_gem_create(struct drm_device *dev,
|
|
|
|
struct drm_file *file,
|
|
|
|
u32 *handle,
|
|
|
|
u64 size);
|
|
|
|
|
2018-07-26 22:45:49 +08:00
|
|
|
vm_fault_t vkms_gem_fault(struct vm_fault *vmf);
|
2018-07-12 10:01:47 +08:00
|
|
|
|
|
|
|
int vkms_dumb_create(struct drm_file *file, struct drm_device *dev,
|
|
|
|
struct drm_mode_create_dumb *args);
|
|
|
|
|
|
|
|
void vkms_gem_free_object(struct drm_gem_object *obj);
|
|
|
|
|
2018-07-25 00:26:59 +08:00
|
|
|
int vkms_gem_vmap(struct drm_gem_object *obj);
|
|
|
|
|
|
|
|
void vkms_gem_vunmap(struct drm_gem_object *obj);
|
|
|
|
|
2018-08-02 09:10:26 +08:00
|
|
|
/* CRC Support */
|
2019-06-13 20:18:02 +08:00
|
|
|
const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
|
|
|
|
size_t *count);
|
2018-08-21 16:38:56 +08:00
|
|
|
int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name);
|
2018-08-21 16:38:55 +08:00
|
|
|
int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
|
|
|
|
size_t *values_cnt);
|
2019-06-26 09:37:05 +08:00
|
|
|
|
|
|
|
/* Composer Support */
|
|
|
|
void vkms_composer_worker(struct work_struct *work);
|
2018-08-02 09:10:26 +08:00
|
|
|
|
2018-05-14 22:33:46 +08:00
|
|
|
#endif /* _VKMS_DRV_H_ */
|