2018-10-18 17:03:32 +02:00
// SPDX-License-Identifier: MIT
2017-07-06 16:06:01 +02:00
/*
* Copyright ( C ) 2013 - 2017 Oracle Corporation
* This file is based on ast_mode . c
* Copyright 2012 Red Hat Inc .
* Parts based on xf86 - video - ast
* Copyright ( c ) 2005 ASPEED Technology Inc .
* Authors : Dave Airlie < airlied @ redhat . com >
* Michael Thayer < michael . thayer @ oracle . com ,
* Hans de Goede < hdegoede @ redhat . com >
*/
2020-11-03 10:30:11 +01:00
# include <linux/dma-buf-map.h>
2017-07-06 16:06:01 +02:00
# include <linux/export.h>
2019-01-26 13:25:23 +01:00
2018-09-29 14:18:20 +02:00
# include <drm/drm_atomic.h>
2018-09-29 14:18:15 +02:00
# include <drm/drm_atomic_helper.h>
2019-10-11 15:48:06 +02:00
# include <drm/drm_fb_helper.h>
2019-01-26 13:25:23 +01:00
# include <drm/drm_fourcc.h>
2021-02-09 13:10:42 +01:00
# include <drm/drm_gem_atomic_helper.h>
2019-10-11 15:48:08 +02:00
# include <drm/drm_gem_framebuffer_helper.h>
2019-01-17 22:03:34 +01:00
# include <drm/drm_plane_helper.h>
# include <drm/drm_probe_helper.h>
2017-07-06 16:06:01 +02:00
2019-01-26 13:25:23 +01:00
# include "hgsmi_channels.h"
2017-07-06 16:06:01 +02:00
# include "vbox_drv.h"
# include "vboxvideo.h"
2018-10-18 17:03:31 +02:00
/*
2017-07-06 16:06:01 +02:00
* Set a graphics mode . Poke any required values into registers , do an HGSMI
* mode set and tell the host we support advanced graphics functions .
*/
2018-09-29 14:18:14 +02:00
static void vbox_do_modeset ( struct drm_crtc * crtc )
2017-07-06 16:06:01 +02:00
{
2018-09-29 14:18:18 +02:00
struct drm_framebuffer * fb = crtc - > primary - > state - > fb ;
2017-07-06 16:06:01 +02:00
struct vbox_crtc * vbox_crtc = to_vbox_crtc ( crtc ) ;
struct vbox_private * vbox ;
int width , height , bpp , pitch ;
u16 flags ;
s32 x_offset , y_offset ;
2020-04-15 09:39:39 +02:00
vbox = to_vbox_dev ( crtc - > dev ) ;
2018-09-29 14:18:14 +02:00
width = vbox_crtc - > width ? vbox_crtc - > width : 640 ;
height = vbox_crtc - > height ? vbox_crtc - > height : 480 ;
2018-09-29 14:18:18 +02:00
bpp = fb ? fb - > format - > cpp [ 0 ] * 8 : 32 ;
pitch = fb ? fb - > pitches [ 0 ] : width * bpp / 8 ;
2018-09-29 14:18:14 +02:00
x_offset = vbox - > single_framebuffer ? vbox_crtc - > x : vbox_crtc - > x_hint ;
y_offset = vbox - > single_framebuffer ? vbox_crtc - > y : vbox_crtc - > y_hint ;
2017-07-06 16:06:01 +02:00
/*
* This is the old way of setting graphics modes . It assumed one screen
* and a frame - buffer at the start of video RAM . On older versions of
* VirtualBox , certain parts of the code still assume that the first
* screen is programmed this way , so try to fake it .
*/
2018-09-29 14:18:18 +02:00
if ( vbox_crtc - > crtc_id = = 0 & & fb & &
2017-07-06 16:06:01 +02:00
vbox_crtc - > fb_offset / pitch < 0xffff - crtc - > y & &
vbox_crtc - > fb_offset % ( bpp / 8 ) = = 0 ) {
vbox_write_ioport ( VBE_DISPI_INDEX_XRES , width ) ;
vbox_write_ioport ( VBE_DISPI_INDEX_YRES , height ) ;
vbox_write_ioport ( VBE_DISPI_INDEX_VIRT_WIDTH , pitch * 8 / bpp ) ;
2018-09-29 14:18:18 +02:00
vbox_write_ioport ( VBE_DISPI_INDEX_BPP , bpp ) ;
2017-07-06 16:06:01 +02:00
vbox_write_ioport ( VBE_DISPI_INDEX_ENABLE , VBE_DISPI_ENABLED ) ;
2019-03-05 17:24:49 +02:00
vbox_write_ioport ( VBE_DISPI_INDEX_X_OFFSET ,
2018-09-29 14:18:14 +02:00
vbox_crtc - > fb_offset % pitch / bpp * 8 + vbox_crtc - > x ) ;
2017-07-06 16:06:01 +02:00
vbox_write_ioport ( VBE_DISPI_INDEX_Y_OFFSET ,
2018-09-29 14:18:14 +02:00
vbox_crtc - > fb_offset / pitch + vbox_crtc - > y ) ;
2017-07-06 16:06:01 +02:00
}
flags = VBVA_SCREEN_F_ACTIVE ;
2018-10-18 17:03:28 +02:00
flags | = ( fb & & crtc - > state - > enable ) ? 0 : VBVA_SCREEN_F_BLANK ;
2017-07-06 16:06:01 +02:00
flags | = vbox_crtc - > disconnected ? VBVA_SCREEN_F_DISABLED : 0 ;
hgsmi_process_display_info ( vbox - > guest_pool , vbox_crtc - > crtc_id ,
x_offset , y_offset ,
2018-09-29 14:18:14 +02:00
vbox_crtc - > x * bpp / 8 +
vbox_crtc - > y * pitch ,
2018-09-29 14:18:21 +02:00
pitch , width , height , bpp , flags ) ;
2017-07-06 16:06:01 +02:00
}
static int vbox_set_view ( struct drm_crtc * crtc )
{
struct vbox_crtc * vbox_crtc = to_vbox_crtc ( crtc ) ;
2020-04-15 09:39:39 +02:00
struct vbox_private * vbox = to_vbox_dev ( crtc - > dev ) ;
2017-07-06 16:06:01 +02:00
struct vbva_infoview * p ;
/*
* Tell the host about the view . This design originally targeted the
* Windows XP driver architecture and assumed that each screen would
* have a dedicated frame buffer with the command buffer following it ,
* the whole being a " view " . The host works out which screen a command
* buffer belongs to by checking whether it is in the first view , then
* whether it is in the second and so on . The first match wins . We
* cheat around this by making the first view be the managed memory
* plus the first command buffer , the second the same plus the second
* buffer and so on .
*/
p = hgsmi_buffer_alloc ( vbox - > guest_pool , sizeof ( * p ) ,
HGSMI_CH_VBVA , VBVA_INFO_VIEW ) ;
if ( ! p )
return - ENOMEM ;
p - > view_index = vbox_crtc - > crtc_id ;
p - > view_offset = vbox_crtc - > fb_offset ;
p - > view_size = vbox - > available_vram_size - vbox_crtc - > fb_offset +
vbox_crtc - > crtc_id * VBVA_MIN_BUFFER_SIZE ;
p - > max_screen_size = vbox - > available_vram_size - vbox_crtc - > fb_offset ;
hgsmi_buffer_submit ( vbox - > guest_pool , p ) ;
hgsmi_buffer_free ( vbox - > guest_pool , p ) ;
return 0 ;
}
/*
* Try to map the layout of virtual screens to the range of the input device .
* Return true if we need to re - set the crtc modes due to screen offset
* changes .
*/
static bool vbox_set_up_input_mapping ( struct vbox_private * vbox )
{
struct drm_crtc * crtci ;
struct drm_connector * connectori ;
2018-09-29 14:18:11 +02:00
struct drm_framebuffer * fb , * fb1 = NULL ;
2017-07-06 16:06:01 +02:00
bool single_framebuffer = true ;
bool old_single_framebuffer = vbox - > single_framebuffer ;
u16 width = 0 , height = 0 ;
/*
* Are we using an X . Org - style single large frame - buffer for all crtcs ?
* If so then screen layout can be deduced from the crtc offsets .
* Same fall - back if this is the fbdev frame - buffer .
*/
2018-09-18 19:44:30 +02:00
list_for_each_entry ( crtci , & vbox - > ddev . mode_config . crtc_list , head ) {
2018-09-29 14:18:18 +02:00
fb = crtci - > primary - > state - > fb ;
2018-09-29 14:18:11 +02:00
if ( ! fb )
continue ;
2017-07-06 16:06:01 +02:00
if ( ! fb1 ) {
2018-09-29 14:18:11 +02:00
fb1 = fb ;
2019-10-11 15:48:06 +02:00
if ( fb1 = = vbox - > ddev . fb_helper - > fb )
2017-07-06 16:06:01 +02:00
break ;
2018-09-29 14:18:11 +02:00
} else if ( fb ! = fb1 ) {
2017-07-06 16:06:01 +02:00
single_framebuffer = false ;
}
}
2018-09-29 14:18:11 +02:00
if ( ! fb1 )
return false ;
2017-07-06 16:06:01 +02:00
if ( single_framebuffer ) {
2018-09-18 19:44:36 +02:00
vbox - > single_framebuffer = true ;
2018-09-29 14:18:11 +02:00
vbox - > input_mapping_width = fb1 - > width ;
vbox - > input_mapping_height = fb1 - > height ;
2018-09-18 19:44:36 +02:00
return old_single_framebuffer ! = vbox - > single_framebuffer ;
2017-07-06 16:06:01 +02:00
}
/* Otherwise calculate the total span of all screens. */
2018-09-18 19:44:30 +02:00
list_for_each_entry ( connectori , & vbox - > ddev . mode_config . connector_list ,
2017-07-06 16:06:01 +02:00
head ) {
struct vbox_connector * vbox_connector =
to_vbox_connector ( connectori ) ;
struct vbox_crtc * vbox_crtc = vbox_connector - > vbox_crtc ;
width = max_t ( u16 , width , vbox_crtc - > x_hint +
vbox_connector - > mode_hint . width ) ;
height = max_t ( u16 , height , vbox_crtc - > y_hint +
vbox_connector - > mode_hint . height ) ;
}
vbox - > single_framebuffer = false ;
vbox - > input_mapping_width = width ;
vbox - > input_mapping_height = height ;
return old_single_framebuffer ! = vbox - > single_framebuffer ;
}
2018-09-18 19:44:35 +02:00
static void vbox_crtc_set_base_and_mode ( struct drm_crtc * crtc ,
struct drm_framebuffer * fb ,
int x , int y )
2018-09-11 09:15:41 +02:00
{
2019-10-11 15:48:08 +02:00
struct drm_gem_vram_object * gbo = drm_gem_vram_of_gem ( fb - > obj [ 0 ] ) ;
2020-04-15 09:39:39 +02:00
struct vbox_private * vbox = to_vbox_dev ( crtc - > dev ) ;
2018-09-11 09:15:41 +02:00
struct vbox_crtc * vbox_crtc = to_vbox_crtc ( crtc ) ;
2018-09-29 14:18:20 +02:00
bool needs_modeset = drm_atomic_crtc_needs_modeset ( crtc - > state ) ;
2017-07-06 16:06:01 +02:00
2018-09-11 09:15:41 +02:00
mutex_lock ( & vbox - > hw_mutex ) ;
2018-10-18 17:03:29 +02:00
if ( crtc - > state - > enable ) {
vbox_crtc - > width = crtc - > state - > mode . hdisplay ;
vbox_crtc - > height = crtc - > state - > mode . vdisplay ;
}
2018-09-29 14:18:14 +02:00
vbox_crtc - > x = x ;
vbox_crtc - > y = y ;
2019-05-08 10:26:27 +02:00
vbox_crtc - > fb_offset = drm_gem_vram_offset ( gbo ) ;
2018-09-11 09:15:41 +02:00
/* vbox_do_modeset() checks vbox->single_framebuffer so update it now */
2018-09-29 14:18:20 +02:00
if ( needs_modeset & & vbox_set_up_input_mapping ( vbox ) ) {
2017-07-06 16:06:01 +02:00
struct drm_crtc * crtci ;
2018-09-18 19:44:30 +02:00
list_for_each_entry ( crtci , & vbox - > ddev . mode_config . crtc_list ,
2017-07-06 16:06:01 +02:00
head ) {
2018-09-11 09:15:42 +02:00
if ( crtci = = crtc )
continue ;
2018-09-29 14:18:14 +02:00
vbox_do_modeset ( crtci ) ;
2017-07-06 16:06:01 +02:00
}
}
2018-09-11 09:15:41 +02:00
vbox_set_view ( crtc ) ;
2018-09-29 14:18:14 +02:00
vbox_do_modeset ( crtc ) ;
2017-07-06 16:06:01 +02:00
2018-09-29 14:18:20 +02:00
if ( needs_modeset )
2018-09-11 09:15:41 +02:00
hgsmi_update_input_mapping ( vbox - > guest_pool , 0 , 0 ,
vbox - > input_mapping_width ,
vbox - > input_mapping_height ) ;
mutex_unlock ( & vbox - > hw_mutex ) ;
2017-07-06 16:06:01 +02:00
}
2018-09-29 14:18:22 +02:00
static void vbox_crtc_atomic_enable ( struct drm_crtc * crtc ,
drm/atomic: Pass the full state to CRTC atomic enable/disable
If the CRTC driver ever needs to access the full DRM state, it can't do so
at atomic_enable / atomic_disable time since drm_atomic_helper_swap_state
will have cleared the pointer from the struct drm_crtc_state to the struct
drm_atomic_state before calling those hooks.
In order to allow that, let's pass the full DRM state to atomic_enable and
atomic_disable. The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
disable_outputs(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_disable(crtc, crtc_state);
+ FUNCS->atomic_disable(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_enable(crtc, crtc_state);
+ FUNCS->atomic_enable(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_enable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_disable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_enable = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/845aa10ef171fc0ea060495efef142a0c13f7870.1602161031.git-series.maxime@cerno.tech
2020-10-08 14:44:08 +02:00
struct drm_atomic_state * state )
2017-07-06 16:06:01 +02:00
{
2018-09-29 14:18:16 +02:00
}
2018-09-18 19:44:35 +02:00
2018-09-29 14:18:22 +02:00
static void vbox_crtc_atomic_disable ( struct drm_crtc * crtc ,
drm/atomic: Pass the full state to CRTC atomic enable/disable
If the CRTC driver ever needs to access the full DRM state, it can't do so
at atomic_enable / atomic_disable time since drm_atomic_helper_swap_state
will have cleared the pointer from the struct drm_crtc_state to the struct
drm_atomic_state before calling those hooks.
In order to allow that, let's pass the full DRM state to atomic_enable and
atomic_disable. The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
disable_outputs(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_disable(crtc, crtc_state);
+ FUNCS->atomic_disable(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_enable(crtc, crtc_state);
+ FUNCS->atomic_enable(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_enable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_disable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_enable = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/845aa10ef171fc0ea060495efef142a0c13f7870.1602161031.git-series.maxime@cerno.tech
2020-10-08 14:44:08 +02:00
struct drm_atomic_state * state )
2017-07-06 16:06:01 +02:00
{
}
2018-09-29 14:18:16 +02:00
static void vbox_crtc_atomic_flush ( struct drm_crtc * crtc ,
drm/atomic: Pass the full state to CRTC atomic begin and flush
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's start convert all the remaining helpers to provide a consistent
interface, starting with the CRTC's atomic_begin and atomic_flush.
The conversion was done using the coccinelle script below, built tested on
all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier old_crtc_state, old_state;
identifier crtc;
identifier f;
@@
f(struct drm_crtc_state *old_crtc_state)
{
...
struct drm_atomic_state *old_state = old_crtc_state->state;
<...
- FUNCS->atomic_begin(crtc, old_crtc_state);
+ FUNCS->atomic_begin(crtc, old_state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier old_crtc_state, old_state;
identifier crtc;
identifier f;
@@
f(struct drm_crtc_state *old_crtc_state)
{
...
struct drm_atomic_state *old_state = old_crtc_state->state;
<...
- FUNCS->atomic_flush(crtc, old_crtc_state);
+ FUNCS->atomic_flush(crtc, old_state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
identifier dev, state;
identifier f;
@@
f(struct drm_device *dev, struct drm_atomic_state *state, ...)
{
<...
- FUNCS->atomic_begin(crtc, crtc_state);
+ FUNCS->atomic_begin(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
identifier dev, state;
identifier f;
@@
f(struct drm_device *dev, struct drm_atomic_state *state, ...)
{
<...
- FUNCS->atomic_flush(crtc, crtc_state);
+ FUNCS->atomic_flush(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_begin)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_begin)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_flush)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_flush)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_begin = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_flush = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@@
identifier old_state;
identifier crtc;
@@
void vc4_hvs_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@@
identifier old_state;
identifier crtc;
@@
void vc4_hvs_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
);
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{
...
}
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
);
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{
...
}
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
);
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20201028123222.1732139-2-maxime@cerno.tech
2020-10-28 13:32:22 +01:00
struct drm_atomic_state * state )
2017-07-06 16:06:01 +02:00
{
}
static const struct drm_crtc_helper_funcs vbox_crtc_helper_funcs = {
2018-09-29 14:18:22 +02:00
. atomic_enable = vbox_crtc_atomic_enable ,
. atomic_disable = vbox_crtc_atomic_disable ,
2018-09-29 14:18:16 +02:00
. atomic_flush = vbox_crtc_atomic_flush ,
2017-07-06 16:06:01 +02:00
} ;
static void vbox_crtc_destroy ( struct drm_crtc * crtc )
{
drm_crtc_cleanup ( crtc ) ;
kfree ( crtc ) ;
}
static const struct drm_crtc_funcs vbox_crtc_funcs = {
2018-09-29 14:18:19 +02:00
. set_config = drm_atomic_helper_set_config ,
2018-09-29 14:18:20 +02:00
. page_flip = drm_atomic_helper_page_flip ,
2017-07-06 16:06:01 +02:00
/* .gamma_set = vbox_crtc_gamma_set, */
. destroy = vbox_crtc_destroy ,
2018-09-29 14:18:17 +02:00
. reset = drm_atomic_helper_crtc_reset ,
. atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state ,
. atomic_destroy_state = drm_atomic_helper_crtc_destroy_state ,
2017-07-06 16:06:01 +02:00
} ;
2018-09-29 14:18:16 +02:00
static int vbox_primary_atomic_check ( struct drm_plane * plane ,
drm/atomic: Pass the full state to planes atomic_check
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert all the remaining helpers to provide a consistent
interface, starting with the planes atomic_check.
The conversion was done using the coccinelle script below plus some
manual changes for vmwgfx, built tested on all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
int (*atomic_check)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier dev;
identifier plane, plane_state, state;
@@
f(struct drm_device *dev, struct drm_atomic_state *state)
{
<+...
- FUNCS->atomic_check(plane, plane_state)
+ FUNCS->atomic_check(plane, state)
...+>
}
@ ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
... when != new_plane_state
}
@ adds_new_state depends on plane_atomic_func && !ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
+ struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *new_plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-4-maxime@cerno.tech
2021-02-19 13:00:24 +01:00
struct drm_atomic_state * state )
2018-09-29 14:18:16 +02:00
{
drm/atomic: Pass the full state to planes atomic_check
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert all the remaining helpers to provide a consistent
interface, starting with the planes atomic_check.
The conversion was done using the coccinelle script below plus some
manual changes for vmwgfx, built tested on all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
int (*atomic_check)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier dev;
identifier plane, plane_state, state;
@@
f(struct drm_device *dev, struct drm_atomic_state *state)
{
<+...
- FUNCS->atomic_check(plane, plane_state)
+ FUNCS->atomic_check(plane, state)
...+>
}
@ ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
... when != new_plane_state
}
@ adds_new_state depends on plane_atomic_func && !ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
+ struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *new_plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-4-maxime@cerno.tech
2021-02-19 13:00:24 +01:00
struct drm_plane_state * new_state = drm_atomic_get_new_plane_state ( state ,
plane ) ;
2018-09-29 14:18:23 +02:00
struct drm_crtc_state * crtc_state = NULL ;
if ( new_state - > crtc ) {
drm: Use the state pointer directly in planes atomic_check
Now that atomic_check takes the global atomic state as a parameter, we
don't need to go through the pointer in the plane state.
This was done using the following coccinelle script:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
static struct drm_plane_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
- struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
<... when != plane_state
- plane_state->state
+ state
...>
}
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
<...
- plane_state->state
+ state
...>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-5-maxime@cerno.tech
2021-02-19 13:00:25 +01:00
crtc_state = drm_atomic_get_existing_crtc_state ( state ,
new_state - > crtc ) ;
2018-09-29 14:18:23 +02:00
if ( WARN_ON ( ! crtc_state ) )
return - EINVAL ;
}
return drm_atomic_helper_check_plane_state ( new_state , crtc_state ,
DRM_PLANE_HELPER_NO_SCALING ,
DRM_PLANE_HELPER_NO_SCALING ,
false , true ) ;
2018-09-29 14:18:16 +02:00
}
static void vbox_primary_atomic_update ( struct drm_plane * plane ,
drm/atomic: Pass the full state to planes atomic disable and update
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert the remaining helpers to provide a consistent interface,
this time with the planes atomic_update and atomic_disable.
The conversion was done using the coccinelle script below, built tested on
all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_update)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_disable)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier crtc_state;
identifier plane, plane_state, state;
expression e;
@@
f(struct drm_crtc_state *crtc_state)
{
...
struct drm_atomic_state *state = e;
<+...
(
- FUNCS->atomic_disable(plane, plane_state)
+ FUNCS->atomic_disable(plane, state)
|
- FUNCS->atomic_update(plane, plane_state)
+ FUNCS->atomic_update(plane, state)
)
...+>
}
@@
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *state)
+ struct drm_plane_state *old_plane_state)
{
<...
- state
+ old_plane_state
...>
}
@ ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on plane_atomic_func && !ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *plane_state)
{
+ struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
<+...
- plane_state->state
+ state
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-9-maxime@cerno.tech
2021-02-19 13:00:29 +01:00
struct drm_atomic_state * state )
2018-09-29 14:18:16 +02:00
{
drm: Use state helper instead of the plane state pointer
Many drivers reference the plane->state pointer in order to get the
current plane state in their atomic_update or atomic_disable hooks,
which would be the new plane state in the global atomic state since
_swap_state happened when those hooks are run.
Use the drm_atomic_get_new_plane_state helper to get that state to make it
more obvious.
This was made using the coccinelle script below:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
)
@ adds_new_state @
identifier plane_atomic_func.func;
identifier plane, state;
identifier new_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state)
{
...
- struct drm_plane_state *new_state = plane->state;
+ struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane);
...
}
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20210219120032.260676-1-maxime@cerno.tech
2021-02-19 13:00:30 +01:00
struct drm_plane_state * new_state = drm_atomic_get_new_plane_state ( state ,
plane ) ;
drm: Store new plane state in a variable for atomic_update and disable
In order to store the new plane state in a subsequent helper, let's move
the plane->state dereferences into a variable.
This was done using the following coccinelle script, plus some hand
changes for vmwgfx:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
)
@ has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
+ struct drm_plane_state *new_state = plane->state;
<+...
- plane->state
+ new_state
...+>
}
@ has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
+ struct drm_plane_state *new_plane_state = plane->state;
<+...
- plane->state
+ new_plane_state
...+>
}
@ has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
+ struct drm_plane_state *new_s = plane->state;
<+...
- plane->state
+ new_s
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20210219120032.260676-1-maxime@cerno.tech
2021-02-19 13:00:27 +01:00
struct drm_crtc * crtc = new_state - > crtc ;
struct drm_framebuffer * fb = new_state - > fb ;
2020-04-15 09:39:39 +02:00
struct vbox_private * vbox = to_vbox_dev ( fb - > dev ) ;
2019-10-11 15:48:07 +02:00
struct drm_mode_rect * clips ;
uint32_t num_clips , i ;
2018-09-29 14:18:16 +02:00
2018-10-18 17:03:29 +02:00
vbox_crtc_set_base_and_mode ( crtc , fb ,
drm: Store new plane state in a variable for atomic_update and disable
In order to store the new plane state in a subsequent helper, let's move
the plane->state dereferences into a variable.
This was done using the following coccinelle script, plus some hand
changes for vmwgfx:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
)
@ has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
+ struct drm_plane_state *new_state = plane->state;
<+...
- plane->state
+ new_state
...+>
}
@ has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
+ struct drm_plane_state *new_plane_state = plane->state;
<+...
- plane->state
+ new_plane_state
...+>
}
@ has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
+ struct drm_plane_state *new_s = plane->state;
<+...
- plane->state
+ new_s
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20210219120032.260676-1-maxime@cerno.tech
2021-02-19 13:00:27 +01:00
new_state - > src_x > > 16 ,
new_state - > src_y > > 16 ) ;
2019-10-11 15:48:07 +02:00
/* Send information about dirty rectangles to VBVA. */
drm: Store new plane state in a variable for atomic_update and disable
In order to store the new plane state in a subsequent helper, let's move
the plane->state dereferences into a variable.
This was done using the following coccinelle script, plus some hand
changes for vmwgfx:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
)
@ has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
+ struct drm_plane_state *new_state = plane->state;
<+...
- plane->state
+ new_state
...+>
}
@ has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
+ struct drm_plane_state *new_plane_state = plane->state;
<+...
- plane->state
+ new_plane_state
...+>
}
@ has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
+ struct drm_plane_state *new_s = plane->state;
<+...
- plane->state
+ new_s
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20210219120032.260676-1-maxime@cerno.tech
2021-02-19 13:00:27 +01:00
clips = drm_plane_get_damage_clips ( new_state ) ;
num_clips = drm_plane_get_damage_clips_count ( new_state ) ;
2019-10-11 15:48:07 +02:00
if ( ! num_clips )
return ;
mutex_lock ( & vbox - > hw_mutex ) ;
for ( i = 0 ; i < num_clips ; + + i , + + clips ) {
struct vbva_cmd_hdr cmd_hdr ;
unsigned int crtc_id = to_vbox_crtc ( crtc ) - > crtc_id ;
cmd_hdr . x = ( s16 ) clips - > x1 ;
cmd_hdr . y = ( s16 ) clips - > y1 ;
cmd_hdr . w = ( u16 ) clips - > x2 - clips - > x1 ;
cmd_hdr . h = ( u16 ) clips - > y2 - clips - > y1 ;
if ( ! vbva_buffer_begin_update ( & vbox - > vbva_info [ crtc_id ] ,
vbox - > guest_pool ) )
continue ;
vbva_write ( & vbox - > vbva_info [ crtc_id ] , vbox - > guest_pool ,
& cmd_hdr , sizeof ( cmd_hdr ) ) ;
vbva_buffer_end_update ( & vbox - > vbva_info [ crtc_id ] ) ;
}
mutex_unlock ( & vbox - > hw_mutex ) ;
2018-09-29 14:18:16 +02:00
}
2018-10-10 20:17:05 +00:00
static void vbox_primary_atomic_disable ( struct drm_plane * plane ,
drm/atomic: Pass the full state to planes atomic disable and update
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert the remaining helpers to provide a consistent interface,
this time with the planes atomic_update and atomic_disable.
The conversion was done using the coccinelle script below, built tested on
all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_update)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_disable)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier crtc_state;
identifier plane, plane_state, state;
expression e;
@@
f(struct drm_crtc_state *crtc_state)
{
...
struct drm_atomic_state *state = e;
<+...
(
- FUNCS->atomic_disable(plane, plane_state)
+ FUNCS->atomic_disable(plane, state)
|
- FUNCS->atomic_update(plane, plane_state)
+ FUNCS->atomic_update(plane, state)
)
...+>
}
@@
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *state)
+ struct drm_plane_state *old_plane_state)
{
<...
- state
+ old_plane_state
...>
}
@ ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on plane_atomic_func && !ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *plane_state)
{
+ struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
<+...
- plane_state->state
+ state
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-9-maxime@cerno.tech
2021-02-19 13:00:29 +01:00
struct drm_atomic_state * state )
2018-09-29 14:18:16 +02:00
{
drm/atomic: Pass the full state to planes atomic disable and update
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert the remaining helpers to provide a consistent interface,
this time with the planes atomic_update and atomic_disable.
The conversion was done using the coccinelle script below, built tested on
all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_update)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_disable)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier crtc_state;
identifier plane, plane_state, state;
expression e;
@@
f(struct drm_crtc_state *crtc_state)
{
...
struct drm_atomic_state *state = e;
<+...
(
- FUNCS->atomic_disable(plane, plane_state)
+ FUNCS->atomic_disable(plane, state)
|
- FUNCS->atomic_update(plane, plane_state)
+ FUNCS->atomic_update(plane, state)
)
...+>
}
@@
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *state)
+ struct drm_plane_state *old_plane_state)
{
<...
- state
+ old_plane_state
...>
}
@ ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on plane_atomic_func && !ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *plane_state)
{
+ struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
<+...
- plane_state->state
+ state
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-9-maxime@cerno.tech
2021-02-19 13:00:29 +01:00
struct drm_plane_state * old_state = drm_atomic_get_old_plane_state ( state ,
plane ) ;
2018-09-29 14:18:16 +02:00
struct drm_crtc * crtc = old_state - > crtc ;
/* vbox_do_modeset checks plane->state->fb and will disable if NULL */
2018-10-18 17:03:29 +02:00
vbox_crtc_set_base_and_mode ( crtc , old_state - > fb ,
2018-09-29 14:18:16 +02:00
old_state - > src_x > > 16 ,
old_state - > src_y > > 16 ) ;
}
2018-09-29 14:18:15 +02:00
static int vbox_cursor_atomic_check ( struct drm_plane * plane ,
drm/atomic: Pass the full state to planes atomic_check
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert all the remaining helpers to provide a consistent
interface, starting with the planes atomic_check.
The conversion was done using the coccinelle script below plus some
manual changes for vmwgfx, built tested on all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
int (*atomic_check)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier dev;
identifier plane, plane_state, state;
@@
f(struct drm_device *dev, struct drm_atomic_state *state)
{
<+...
- FUNCS->atomic_check(plane, plane_state)
+ FUNCS->atomic_check(plane, state)
...+>
}
@ ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
... when != new_plane_state
}
@ adds_new_state depends on plane_atomic_func && !ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
+ struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *new_plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-4-maxime@cerno.tech
2021-02-19 13:00:24 +01:00
struct drm_atomic_state * state )
2018-09-29 14:18:15 +02:00
{
drm/atomic: Pass the full state to planes atomic_check
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert all the remaining helpers to provide a consistent
interface, starting with the planes atomic_check.
The conversion was done using the coccinelle script below plus some
manual changes for vmwgfx, built tested on all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
int (*atomic_check)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier dev;
identifier plane, plane_state, state;
@@
f(struct drm_device *dev, struct drm_atomic_state *state)
{
<+...
- FUNCS->atomic_check(plane, plane_state)
+ FUNCS->atomic_check(plane, state)
...+>
}
@ ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
... when != new_plane_state
}
@ adds_new_state depends on plane_atomic_func && !ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
+ struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *new_plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-4-maxime@cerno.tech
2021-02-19 13:00:24 +01:00
struct drm_plane_state * new_state = drm_atomic_get_new_plane_state ( state ,
plane ) ;
2018-09-29 14:18:23 +02:00
struct drm_crtc_state * crtc_state = NULL ;
2018-09-29 14:18:15 +02:00
u32 width = new_state - > crtc_w ;
u32 height = new_state - > crtc_h ;
2018-09-29 14:18:23 +02:00
int ret ;
if ( new_state - > crtc ) {
drm: Use the state pointer directly in planes atomic_check
Now that atomic_check takes the global atomic state as a parameter, we
don't need to go through the pointer in the plane state.
This was done using the following coccinelle script:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
static struct drm_plane_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
- struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
<... when != plane_state
- plane_state->state
+ state
...>
}
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
<...
- plane_state->state
+ state
...>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-5-maxime@cerno.tech
2021-02-19 13:00:25 +01:00
crtc_state = drm_atomic_get_existing_crtc_state ( state ,
new_state - > crtc ) ;
2018-09-29 14:18:23 +02:00
if ( WARN_ON ( ! crtc_state ) )
return - EINVAL ;
}
ret = drm_atomic_helper_check_plane_state ( new_state , crtc_state ,
DRM_PLANE_HELPER_NO_SCALING ,
DRM_PLANE_HELPER_NO_SCALING ,
true , true ) ;
if ( ret )
return ret ;
2018-09-29 14:18:15 +02:00
if ( ! new_state - > fb )
return 0 ;
if ( width > VBOX_MAX_CURSOR_WIDTH | | height > VBOX_MAX_CURSOR_HEIGHT | |
width = = 0 | | height = = 0 )
return - EINVAL ;
return 0 ;
}
2018-10-18 17:03:31 +02:00
/*
2018-09-29 14:18:15 +02:00
* Copy the ARGB image and generate the mask , which is needed in case the host
* does not support ARGB cursors . The mask is a 1 BPP bitmap with the bit set
* if the corresponding alpha value in the ARGB image is greater than 0xF0 .
*/
static void copy_cursor_image ( u8 * src , u8 * dst , u32 width , u32 height ,
size_t mask_size )
{
size_t line_size = ( width + 7 ) / 8 ;
u32 i , j ;
memcpy ( dst + mask_size , src , width * height * 4 ) ;
for ( i = 0 ; i < height ; + + i )
for ( j = 0 ; j < width ; + + j )
if ( ( ( u32 * ) src ) [ i * width + j ] > 0xf0000000 )
dst [ i * line_size + j / 8 ] | = ( 0x80 > > ( j % 8 ) ) ;
}
static void vbox_cursor_atomic_update ( struct drm_plane * plane ,
drm/atomic: Pass the full state to planes atomic disable and update
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert the remaining helpers to provide a consistent interface,
this time with the planes atomic_update and atomic_disable.
The conversion was done using the coccinelle script below, built tested on
all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_update)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_disable)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier crtc_state;
identifier plane, plane_state, state;
expression e;
@@
f(struct drm_crtc_state *crtc_state)
{
...
struct drm_atomic_state *state = e;
<+...
(
- FUNCS->atomic_disable(plane, plane_state)
+ FUNCS->atomic_disable(plane, state)
|
- FUNCS->atomic_update(plane, plane_state)
+ FUNCS->atomic_update(plane, state)
)
...+>
}
@@
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *state)
+ struct drm_plane_state *old_plane_state)
{
<...
- state
+ old_plane_state
...>
}
@ ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on plane_atomic_func && !ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *plane_state)
{
+ struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
<+...
- plane_state->state
+ state
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-9-maxime@cerno.tech
2021-02-19 13:00:29 +01:00
struct drm_atomic_state * state )
2018-09-29 14:18:15 +02:00
{
drm/atomic: Pass the full state to planes atomic disable and update
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert the remaining helpers to provide a consistent interface,
this time with the planes atomic_update and atomic_disable.
The conversion was done using the coccinelle script below, built tested on
all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_update)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_disable)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier crtc_state;
identifier plane, plane_state, state;
expression e;
@@
f(struct drm_crtc_state *crtc_state)
{
...
struct drm_atomic_state *state = e;
<+...
(
- FUNCS->atomic_disable(plane, plane_state)
+ FUNCS->atomic_disable(plane, state)
|
- FUNCS->atomic_update(plane, plane_state)
+ FUNCS->atomic_update(plane, state)
)
...+>
}
@@
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *state)
+ struct drm_plane_state *old_plane_state)
{
<...
- state
+ old_plane_state
...>
}
@ ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on plane_atomic_func && !ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *plane_state)
{
+ struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
<+...
- plane_state->state
+ state
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-9-maxime@cerno.tech
2021-02-19 13:00:29 +01:00
struct drm_plane_state * old_state = drm_atomic_get_old_plane_state ( state ,
plane ) ;
drm: Use state helper instead of the plane state pointer
Many drivers reference the plane->state pointer in order to get the
current plane state in their atomic_update or atomic_disable hooks,
which would be the new plane state in the global atomic state since
_swap_state happened when those hooks are run.
Use the drm_atomic_get_new_plane_state helper to get that state to make it
more obvious.
This was made using the coccinelle script below:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
)
@ adds_new_state @
identifier plane_atomic_func.func;
identifier plane, state;
identifier new_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state)
{
...
- struct drm_plane_state *new_state = plane->state;
+ struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane);
...
}
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20210219120032.260676-1-maxime@cerno.tech
2021-02-19 13:00:30 +01:00
struct drm_plane_state * new_state = drm_atomic_get_new_plane_state ( state ,
plane ) ;
2018-09-29 14:18:15 +02:00
struct vbox_private * vbox =
container_of ( plane - > dev , struct vbox_private , ddev ) ;
drm: Store new plane state in a variable for atomic_update and disable
In order to store the new plane state in a subsequent helper, let's move
the plane->state dereferences into a variable.
This was done using the following coccinelle script, plus some hand
changes for vmwgfx:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
)
@ has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
+ struct drm_plane_state *new_state = plane->state;
<+...
- plane->state
+ new_state
...+>
}
@ has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
+ struct drm_plane_state *new_plane_state = plane->state;
<+...
- plane->state
+ new_plane_state
...+>
}
@ has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
+ struct drm_plane_state *new_s = plane->state;
<+...
- plane->state
+ new_s
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20210219120032.260676-1-maxime@cerno.tech
2021-02-19 13:00:27 +01:00
struct vbox_crtc * vbox_crtc = to_vbox_crtc ( new_state - > crtc ) ;
struct drm_framebuffer * fb = new_state - > fb ;
u32 width = new_state - > crtc_w ;
u32 height = new_state - > crtc_h ;
2021-02-09 13:10:42 +01:00
struct drm_shadow_plane_state * shadow_plane_state =
drm: Store new plane state in a variable for atomic_update and disable
In order to store the new plane state in a subsequent helper, let's move
the plane->state dereferences into a variable.
This was done using the following coccinelle script, plus some hand
changes for vmwgfx:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
)
@ has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
+ struct drm_plane_state *new_state = plane->state;
<+...
- plane->state
+ new_state
...+>
}
@ has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
+ struct drm_plane_state *new_plane_state = plane->state;
<+...
- plane->state
+ new_plane_state
...+>
}
@ has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
+ struct drm_plane_state *new_s = plane->state;
<+...
- plane->state
+ new_s
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20210219120032.260676-1-maxime@cerno.tech
2021-02-19 13:00:27 +01:00
to_drm_shadow_plane_state ( new_state ) ;
2021-08-03 14:59:27 +02:00
struct dma_buf_map map = shadow_plane_state - > data [ 0 ] ;
2021-02-09 13:10:42 +01:00
u8 * src = map . vaddr ; /* TODO: Use mapping abstraction properly */
2018-09-29 14:18:15 +02:00
size_t data_size , mask_size ;
u32 flags ;
/*
* VirtualBox uses the host windowing system to draw the cursor so
* moves are a no - op , we only need to upload new cursor sprites .
*/
if ( fb = = old_state - > fb )
return ;
mutex_lock ( & vbox - > hw_mutex ) ;
vbox_crtc - > cursor_enabled = true ;
/*
* The mask must be calculated based on the alpha
* channel , one bit per ARGB word , and must be 32 - bit
* padded .
*/
mask_size = ( ( width + 7 ) / 8 * height + 3 ) & ~ 3 ;
data_size = width * height * 4 + mask_size ;
copy_cursor_image ( src , vbox - > cursor_data , width , height , mask_size ) ;
flags = VBOX_MOUSE_POINTER_VISIBLE | VBOX_MOUSE_POINTER_SHAPE |
VBOX_MOUSE_POINTER_ALPHA ;
hgsmi_update_pointer_shape ( vbox - > guest_pool , flags ,
min_t ( u32 , max ( fb - > hot_x , 0 ) , width ) ,
min_t ( u32 , max ( fb - > hot_y , 0 ) , height ) ,
width , height , vbox - > cursor_data , data_size ) ;
mutex_unlock ( & vbox - > hw_mutex ) ;
}
2018-10-10 20:17:05 +00:00
static void vbox_cursor_atomic_disable ( struct drm_plane * plane ,
drm/atomic: Pass the full state to planes atomic disable and update
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert the remaining helpers to provide a consistent interface,
this time with the planes atomic_update and atomic_disable.
The conversion was done using the coccinelle script below, built tested on
all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_update)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_disable)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier crtc_state;
identifier plane, plane_state, state;
expression e;
@@
f(struct drm_crtc_state *crtc_state)
{
...
struct drm_atomic_state *state = e;
<+...
(
- FUNCS->atomic_disable(plane, plane_state)
+ FUNCS->atomic_disable(plane, state)
|
- FUNCS->atomic_update(plane, plane_state)
+ FUNCS->atomic_update(plane, state)
)
...+>
}
@@
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *state)
+ struct drm_plane_state *old_plane_state)
{
<...
- state
+ old_plane_state
...>
}
@ ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on plane_atomic_func && !ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *plane_state)
{
+ struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
<+...
- plane_state->state
+ state
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-9-maxime@cerno.tech
2021-02-19 13:00:29 +01:00
struct drm_atomic_state * state )
2018-09-29 14:18:15 +02:00
{
drm/atomic: Pass the full state to planes atomic disable and update
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert the remaining helpers to provide a consistent interface,
this time with the planes atomic_update and atomic_disable.
The conversion was done using the coccinelle script below, built tested on
all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_update)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_disable)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier crtc_state;
identifier plane, plane_state, state;
expression e;
@@
f(struct drm_crtc_state *crtc_state)
{
...
struct drm_atomic_state *state = e;
<+...
(
- FUNCS->atomic_disable(plane, plane_state)
+ FUNCS->atomic_disable(plane, state)
|
- FUNCS->atomic_update(plane, plane_state)
+ FUNCS->atomic_update(plane, state)
)
...+>
}
@@
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *state)
+ struct drm_plane_state *old_plane_state)
{
<...
- state
+ old_plane_state
...>
}
@ ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on plane_atomic_func && !ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *plane_state)
{
+ struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
<+...
- plane_state->state
+ state
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-9-maxime@cerno.tech
2021-02-19 13:00:29 +01:00
struct drm_plane_state * old_state = drm_atomic_get_old_plane_state ( state ,
plane ) ;
2018-09-29 14:18:15 +02:00
struct vbox_private * vbox =
container_of ( plane - > dev , struct vbox_private , ddev ) ;
struct vbox_crtc * vbox_crtc = to_vbox_crtc ( old_state - > crtc ) ;
bool cursor_enabled = false ;
struct drm_crtc * crtci ;
mutex_lock ( & vbox - > hw_mutex ) ;
vbox_crtc - > cursor_enabled = false ;
list_for_each_entry ( crtci , & vbox - > ddev . mode_config . crtc_list , head ) {
if ( to_vbox_crtc ( crtci ) - > cursor_enabled )
cursor_enabled = true ;
}
if ( ! cursor_enabled )
hgsmi_update_pointer_shape ( vbox - > guest_pool , 0 , 0 , 0 ,
0 , 0 , NULL , 0 ) ;
mutex_unlock ( & vbox - > hw_mutex ) ;
}
2018-11-22 02:49:05 -08:00
static const u32 vbox_cursor_plane_formats [ ] = {
2018-09-29 14:18:15 +02:00
DRM_FORMAT_ARGB8888 ,
} ;
static const struct drm_plane_helper_funcs vbox_cursor_helper_funcs = {
. atomic_check = vbox_cursor_atomic_check ,
. atomic_update = vbox_cursor_atomic_update ,
. atomic_disable = vbox_cursor_atomic_disable ,
2021-02-09 13:10:42 +01:00
DRM_GEM_SHADOW_PLANE_HELPER_FUNCS ,
2018-09-29 14:18:15 +02:00
} ;
static const struct drm_plane_funcs vbox_cursor_plane_funcs = {
2018-09-29 14:18:19 +02:00
. update_plane = drm_atomic_helper_update_plane ,
. disable_plane = drm_atomic_helper_disable_plane ,
2018-09-29 14:18:15 +02:00
. destroy = drm_primary_helper_destroy ,
2021-02-09 13:10:42 +01:00
DRM_GEM_SHADOW_PLANE_FUNCS ,
2018-09-29 14:18:15 +02:00
} ;
2018-11-22 02:49:05 -08:00
static const u32 vbox_primary_plane_formats [ ] = {
2018-09-18 19:44:33 +02:00
DRM_FORMAT_XRGB8888 ,
DRM_FORMAT_ARGB8888 ,
} ;
2018-09-29 14:18:16 +02:00
static const struct drm_plane_helper_funcs vbox_primary_helper_funcs = {
. atomic_check = vbox_primary_atomic_check ,
. atomic_update = vbox_primary_atomic_update ,
. atomic_disable = vbox_primary_atomic_disable ,
2021-06-22 18:55:06 +02:00
DRM_GEM_VRAM_PLANE_HELPER_FUNCS ,
2018-09-29 14:18:16 +02:00
} ;
2018-09-18 19:44:33 +02:00
static const struct drm_plane_funcs vbox_primary_plane_funcs = {
2018-09-29 14:18:19 +02:00
. update_plane = drm_atomic_helper_update_plane ,
. disable_plane = drm_atomic_helper_disable_plane ,
2018-09-18 19:44:33 +02:00
. destroy = drm_primary_helper_destroy ,
2018-09-29 14:18:17 +02:00
. reset = drm_atomic_helper_plane_reset ,
. atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state ,
. atomic_destroy_state = drm_atomic_helper_plane_destroy_state ,
2018-09-18 19:44:33 +02:00
} ;
static struct drm_plane * vbox_create_plane ( struct vbox_private * vbox ,
unsigned int possible_crtcs ,
enum drm_plane_type type )
{
const struct drm_plane_helper_funcs * helper_funcs = NULL ;
const struct drm_plane_funcs * funcs ;
struct drm_plane * plane ;
2018-11-22 02:49:05 -08:00
const u32 * formats ;
2018-09-18 19:44:33 +02:00
int num_formats ;
int err ;
if ( type = = DRM_PLANE_TYPE_PRIMARY ) {
funcs = & vbox_primary_plane_funcs ;
formats = vbox_primary_plane_formats ;
2018-09-29 14:18:16 +02:00
helper_funcs = & vbox_primary_helper_funcs ;
2018-09-18 19:44:33 +02:00
num_formats = ARRAY_SIZE ( vbox_primary_plane_formats ) ;
2018-09-29 14:18:15 +02:00
} else if ( type = = DRM_PLANE_TYPE_CURSOR ) {
funcs = & vbox_cursor_plane_funcs ;
formats = vbox_cursor_plane_formats ;
helper_funcs = & vbox_cursor_helper_funcs ;
num_formats = ARRAY_SIZE ( vbox_cursor_plane_formats ) ;
2018-09-18 19:44:33 +02:00
} else {
return ERR_PTR ( - EINVAL ) ;
}
plane = kzalloc ( sizeof ( * plane ) , GFP_KERNEL ) ;
if ( ! plane )
return ERR_PTR ( - ENOMEM ) ;
err = drm_universal_plane_init ( & vbox - > ddev , plane , possible_crtcs ,
funcs , formats , num_formats ,
NULL , type , NULL ) ;
if ( err )
goto free_plane ;
drm_plane_helper_add ( plane , helper_funcs ) ;
return plane ;
free_plane :
kfree ( plane ) ;
return ERR_PTR ( - EINVAL ) ;
}
2017-07-06 16:06:01 +02:00
static struct vbox_crtc * vbox_crtc_init ( struct drm_device * dev , unsigned int i )
{
2018-09-18 19:44:33 +02:00
struct vbox_private * vbox =
container_of ( dev , struct vbox_private , ddev ) ;
2018-09-29 14:18:15 +02:00
struct drm_plane * cursor = NULL ;
2017-07-06 16:06:01 +02:00
struct vbox_crtc * vbox_crtc ;
2018-09-18 19:44:33 +02:00
struct drm_plane * primary ;
2018-09-29 14:18:15 +02:00
u32 caps = 0 ;
2018-09-18 19:44:33 +02:00
int ret ;
2017-07-06 16:06:01 +02:00
2018-09-29 14:18:15 +02:00
ret = hgsmi_query_conf ( vbox - > guest_pool ,
VBOX_VBVA_CONF32_CURSOR_CAPABILITIES , & caps ) ;
if ( ret )
return ERR_PTR ( ret ) ;
2017-07-06 16:06:01 +02:00
vbox_crtc = kzalloc ( sizeof ( * vbox_crtc ) , GFP_KERNEL ) ;
if ( ! vbox_crtc )
2018-09-18 19:44:33 +02:00
return ERR_PTR ( - ENOMEM ) ;
primary = vbox_create_plane ( vbox , 1 < < i , DRM_PLANE_TYPE_PRIMARY ) ;
if ( IS_ERR ( primary ) ) {
ret = PTR_ERR ( primary ) ;
goto free_mem ;
}
2017-07-06 16:06:01 +02:00
2018-09-29 14:18:15 +02:00
if ( ( caps & VBOX_VBVA_CURSOR_CAPABILITY_HARDWARE ) ) {
cursor = vbox_create_plane ( vbox , 1 < < i , DRM_PLANE_TYPE_CURSOR ) ;
if ( IS_ERR ( cursor ) ) {
ret = PTR_ERR ( cursor ) ;
goto clean_primary ;
}
} else {
DRM_WARN ( " VirtualBox host is too old, no cursor support \n " ) ;
}
2017-07-06 16:06:01 +02:00
vbox_crtc - > crtc_id = i ;
2018-09-29 14:18:15 +02:00
ret = drm_crtc_init_with_planes ( dev , & vbox_crtc - > base , primary , cursor ,
2018-09-18 19:44:33 +02:00
& vbox_crtc_funcs , NULL ) ;
if ( ret )
2018-09-29 14:18:15 +02:00
goto clean_cursor ;
2018-09-18 19:44:33 +02:00
2017-07-06 16:06:01 +02:00
drm_mode_crtc_set_gamma_size ( & vbox_crtc - > base , 256 ) ;
drm_crtc_helper_add ( & vbox_crtc - > base , & vbox_crtc_helper_funcs ) ;
return vbox_crtc ;
2018-09-18 19:44:33 +02:00
2018-09-29 14:18:15 +02:00
clean_cursor :
if ( cursor ) {
drm_plane_cleanup ( cursor ) ;
kfree ( cursor ) ;
}
2018-09-18 19:44:33 +02:00
clean_primary :
drm_plane_cleanup ( primary ) ;
kfree ( primary ) ;
free_mem :
kfree ( vbox_crtc ) ;
return ERR_PTR ( ret ) ;
2017-07-06 16:06:01 +02:00
}
static void vbox_encoder_destroy ( struct drm_encoder * encoder )
{
drm_encoder_cleanup ( encoder ) ;
kfree ( encoder ) ;
}
static const struct drm_encoder_funcs vbox_enc_funcs = {
. destroy = vbox_encoder_destroy ,
} ;
static struct drm_encoder * vbox_encoder_init ( struct drm_device * dev ,
unsigned int i )
{
struct vbox_encoder * vbox_encoder ;
vbox_encoder = kzalloc ( sizeof ( * vbox_encoder ) , GFP_KERNEL ) ;
if ( ! vbox_encoder )
return NULL ;
drm_encoder_init ( dev , & vbox_encoder - > base , & vbox_enc_funcs ,
DRM_MODE_ENCODER_DAC , NULL ) ;
vbox_encoder - > base . possible_crtcs = 1 < < i ;
return & vbox_encoder - > base ;
}
2018-10-18 17:03:31 +02:00
/*
2017-07-06 16:06:01 +02:00
* Generate EDID data with a mode - unique serial number for the virtual
2018-10-18 17:03:31 +02:00
* monitor to try to persuade Unity that different modes correspond to
* different monitors and it should not try to force the same resolution on
* them .
2017-07-06 16:06:01 +02:00
*/
static void vbox_set_edid ( struct drm_connector * connector , int width ,
int height )
{
enum { EDID_SIZE = 128 } ;
unsigned char edid [ EDID_SIZE ] = {
0x00 , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0x00 , /* header */
0x58 , 0x58 , /* manufacturer (VBX) */
0x00 , 0x00 , /* product code */
0x00 , 0x00 , 0x00 , 0x00 , /* serial number goes here */
0x01 , /* week of manufacture */
0x00 , /* year of manufacture */
0x01 , 0x03 , /* EDID version */
0x80 , /* capabilities - digital */
0x00 , /* horiz. res in cm, zero for projectors */
0x00 , /* vert. res in cm */
0x78 , /* display gamma (120 == 2.2). */
0xEE , /* features (standby, suspend, off, RGB, std */
/* colour space, preferred timing mode) */
0xEE , 0x91 , 0xA3 , 0x54 , 0x4C , 0x99 , 0x26 , 0x0F , 0x50 , 0x54 ,
/* chromaticity for standard colour space. */
0x00 , 0x00 , 0x00 , /* no default timings */
0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 ,
0x01 , 0x01 ,
0x01 , 0x01 , 0x01 , 0x01 , /* no standard timings */
0x00 , 0x00 , 0x00 , 0x06 , 0x00 , 0x00 , 0x06 , 0x00 , 0x02 , 0x02 ,
0x02 , 0x02 ,
/* descriptor block 1 goes below */
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
/* descriptor block 2, monitor ranges */
0x00 , 0x00 , 0x00 , 0xFD , 0x00 ,
0x00 , 0xC8 , 0x00 , 0xC8 , 0x64 , 0x00 , 0x0A , 0x20 , 0x20 , 0x20 ,
0x20 , 0x20 ,
/* 0-200Hz vertical, 0-200KHz horizontal, 1000MHz pixel clock */
0x20 ,
/* descriptor block 3, monitor name */
0x00 , 0x00 , 0x00 , 0xFC , 0x00 ,
' V ' , ' B ' , ' O ' , ' X ' , ' ' , ' m ' , ' o ' , ' n ' , ' i ' , ' t ' , ' o ' , ' r ' ,
' \n ' ,
/* descriptor block 4: dummy data */
0x00 , 0x00 , 0x00 , 0x10 , 0x00 ,
0x0A , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 ,
0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 ,
0x20 ,
0x00 , /* number of extensions */
0x00 /* checksum goes here */
} ;
int clock = ( width + 6 ) * ( height + 6 ) * 60 / 10000 ;
unsigned int i , sum = 0 ;
edid [ 12 ] = width & 0xff ;
edid [ 13 ] = width > > 8 ;
edid [ 14 ] = height & 0xff ;
edid [ 15 ] = height > > 8 ;
edid [ 54 ] = clock & 0xff ;
edid [ 55 ] = clock > > 8 ;
edid [ 56 ] = width & 0xff ;
edid [ 58 ] = ( width > > 4 ) & 0xf0 ;
edid [ 59 ] = height & 0xff ;
edid [ 61 ] = ( height > > 4 ) & 0xf0 ;
for ( i = 0 ; i < EDID_SIZE - 1 ; + + i )
sum + = edid [ i ] ;
edid [ EDID_SIZE - 1 ] = ( 0x100 - ( sum & 0xFF ) ) & 0xFF ;
2018-07-09 10:40:06 +02:00
drm_connector_update_edid_property ( connector , ( struct edid * ) edid ) ;
2017-07-06 16:06:01 +02:00
}
static int vbox_get_modes ( struct drm_connector * connector )
{
struct vbox_connector * vbox_connector = NULL ;
struct drm_display_mode * mode = NULL ;
struct vbox_private * vbox = NULL ;
unsigned int num_modes = 0 ;
int preferred_width , preferred_height ;
vbox_connector = to_vbox_connector ( connector ) ;
2020-04-15 09:39:39 +02:00
vbox = to_vbox_dev ( connector - > dev ) ;
2019-03-04 17:47:22 +01:00
2017-07-06 16:06:01 +02:00
hgsmi_report_flags_location ( vbox - > guest_pool , GUEST_HEAP_OFFSET ( vbox ) +
HOST_FLAGS_OFFSET ) ;
if ( vbox_connector - > vbox_crtc - > crtc_id = = 0 )
vbox_report_caps ( vbox ) ;
2019-03-04 17:47:22 +01:00
2017-07-06 16:06:01 +02:00
num_modes = drm_add_modes_noedid ( connector , 2560 , 1600 ) ;
preferred_width = vbox_connector - > mode_hint . width ?
vbox_connector - > mode_hint . width : 1024 ;
preferred_height = vbox_connector - > mode_hint . height ?
vbox_connector - > mode_hint . height : 768 ;
mode = drm_cvt_mode ( connector - > dev , preferred_width , preferred_height ,
60 , false , false , false ) ;
if ( mode ) {
mode - > type | = DRM_MODE_TYPE_PREFERRED ;
drm_mode_probed_add ( connector , mode ) ;
+ + num_modes ;
}
vbox_set_edid ( connector , preferred_width , preferred_height ) ;
2017-10-12 20:10:25 +02:00
if ( vbox_connector - > vbox_crtc - > x_hint ! = - 1 )
drm_object_property_set_value ( & connector - > base ,
2018-09-18 19:44:30 +02:00
vbox - > ddev . mode_config . suggested_x_property ,
2017-10-12 20:10:25 +02:00
vbox_connector - > vbox_crtc - > x_hint ) ;
else
drm_object_property_set_value ( & connector - > base ,
2018-09-18 19:44:30 +02:00
vbox - > ddev . mode_config . suggested_x_property , 0 ) ;
2017-10-12 20:10:25 +02:00
if ( vbox_connector - > vbox_crtc - > y_hint ! = - 1 )
drm_object_property_set_value ( & connector - > base ,
2018-09-18 19:44:30 +02:00
vbox - > ddev . mode_config . suggested_y_property ,
2017-10-12 20:10:25 +02:00
vbox_connector - > vbox_crtc - > y_hint ) ;
else
drm_object_property_set_value ( & connector - > base ,
2018-09-18 19:44:30 +02:00
vbox - > ddev . mode_config . suggested_y_property , 0 ) ;
2017-07-06 16:06:01 +02:00
return num_modes ;
}
static void vbox_connector_destroy ( struct drm_connector * connector )
{
drm_connector_unregister ( connector ) ;
drm_connector_cleanup ( connector ) ;
kfree ( connector ) ;
}
static enum drm_connector_status
vbox_connector_detect ( struct drm_connector * connector , bool force )
{
struct vbox_connector * vbox_connector ;
vbox_connector = to_vbox_connector ( connector ) ;
return vbox_connector - > mode_hint . disconnected ?
connector_status_disconnected : connector_status_connected ;
}
static int vbox_fill_modes ( struct drm_connector * connector , u32 max_x ,
u32 max_y )
{
struct vbox_connector * vbox_connector ;
struct drm_device * dev ;
struct drm_display_mode * mode , * iterator ;
vbox_connector = to_vbox_connector ( connector ) ;
dev = vbox_connector - > base . dev ;
list_for_each_entry_safe ( mode , iterator , & connector - > modes , head ) {
list_del ( & mode - > head ) ;
drm_mode_destroy ( dev , mode ) ;
}
return drm_helper_probe_single_connector_modes ( connector , max_x , max_y ) ;
}
static const struct drm_connector_helper_funcs vbox_connector_helper_funcs = {
. get_modes = vbox_get_modes ,
} ;
static const struct drm_connector_funcs vbox_connector_funcs = {
. detect = vbox_connector_detect ,
. fill_modes = vbox_fill_modes ,
. destroy = vbox_connector_destroy ,
2018-09-29 14:18:19 +02:00
. reset = drm_atomic_helper_connector_reset ,
. atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state ,
. atomic_destroy_state = drm_atomic_helper_connector_destroy_state ,
2017-07-06 16:06:01 +02:00
} ;
static int vbox_connector_init ( struct drm_device * dev ,
struct vbox_crtc * vbox_crtc ,
struct drm_encoder * encoder )
{
struct vbox_connector * vbox_connector ;
struct drm_connector * connector ;
vbox_connector = kzalloc ( sizeof ( * vbox_connector ) , GFP_KERNEL ) ;
if ( ! vbox_connector )
return - ENOMEM ;
connector = & vbox_connector - > base ;
vbox_connector - > vbox_crtc = vbox_crtc ;
drm_connector_init ( dev , connector , & vbox_connector_funcs ,
DRM_MODE_CONNECTOR_VGA ) ;
drm_connector_helper_add ( connector , & vbox_connector_helper_funcs ) ;
connector - > interlace_allowed = 0 ;
connector - > doublescan_allowed = 0 ;
drm_mode_create_suggested_offset_properties ( dev ) ;
drm_object_attach_property ( & connector - > base ,
2017-10-12 20:10:25 +02:00
dev - > mode_config . suggested_x_property , 0 ) ;
2017-07-06 16:06:01 +02:00
drm_object_attach_property ( & connector - > base ,
2017-10-12 20:10:25 +02:00
dev - > mode_config . suggested_y_property , 0 ) ;
2017-07-06 16:06:01 +02:00
2018-07-09 10:40:07 +02:00
drm_connector_attach_encoder ( connector , encoder ) ;
2017-07-06 16:06:01 +02:00
return 0 ;
}
2018-09-18 19:44:28 +02:00
static const struct drm_mode_config_funcs vbox_mode_funcs = {
2019-10-28 14:31:59 +01:00
. fb_create = drm_gem_fb_create_with_dirty ,
2020-02-03 16:52:58 +01:00
. mode_valid = drm_vram_helper_mode_valid ,
2018-09-29 14:18:19 +02:00
. atomic_check = drm_atomic_helper_check ,
. atomic_commit = drm_atomic_helper_commit ,
2018-09-18 19:44:28 +02:00
} ;
2018-09-18 19:44:30 +02:00
int vbox_mode_init ( struct vbox_private * vbox )
2017-07-06 16:06:01 +02:00
{
2018-09-18 19:44:30 +02:00
struct drm_device * dev = & vbox - > ddev ;
2017-07-06 16:06:01 +02:00
struct drm_encoder * encoder ;
struct vbox_crtc * vbox_crtc ;
unsigned int i ;
int ret ;
2018-09-18 19:44:28 +02:00
drm_mode_config_init ( dev ) ;
dev - > mode_config . funcs = ( void * ) & vbox_mode_funcs ;
2018-09-29 14:18:15 +02:00
dev - > mode_config . min_width = 0 ;
dev - > mode_config . min_height = 0 ;
2018-09-18 19:44:28 +02:00
dev - > mode_config . preferred_depth = 24 ;
dev - > mode_config . max_width = VBE_DISPI_MAX_XRES ;
dev - > mode_config . max_height = VBE_DISPI_MAX_YRES ;
2017-07-06 16:06:01 +02:00
for ( i = 0 ; i < vbox - > num_crtcs ; + + i ) {
vbox_crtc = vbox_crtc_init ( dev , i ) ;
2018-09-18 19:44:33 +02:00
if ( IS_ERR ( vbox_crtc ) ) {
ret = PTR_ERR ( vbox_crtc ) ;
2018-09-18 19:44:28 +02:00
goto err_drm_mode_cleanup ;
}
2017-07-06 16:06:01 +02:00
encoder = vbox_encoder_init ( dev , i ) ;
2018-09-18 19:44:28 +02:00
if ( ! encoder ) {
ret = - ENOMEM ;
goto err_drm_mode_cleanup ;
}
2017-07-06 16:06:01 +02:00
ret = vbox_connector_init ( dev , vbox_crtc , encoder ) ;
if ( ret )
2018-09-18 19:44:28 +02:00
goto err_drm_mode_cleanup ;
2017-07-06 16:06:01 +02:00
}
2018-09-29 14:18:17 +02:00
drm_mode_config_reset ( dev ) ;
2017-07-06 16:06:01 +02:00
return 0 ;
2018-09-18 19:44:28 +02:00
err_drm_mode_cleanup :
drm_mode_config_cleanup ( dev ) ;
return ret ;
2017-07-06 16:06:01 +02:00
}
2018-09-18 19:44:30 +02:00
void vbox_mode_fini ( struct vbox_private * vbox )
2017-07-06 16:06:01 +02:00
{
2018-09-18 19:44:30 +02:00
drm_mode_config_cleanup ( & vbox - > ddev ) ;
2017-07-06 16:06:01 +02:00
}