RE: [Intel-gfx] [RFC 3/3] drm/i915: Set colorspace by enabling Infoframe

2018-09-26 Thread Shankar, Uma


>-Original Message-
>From: Maarten Lankhorst [mailto:maarten.lankho...@linux.intel.com]
>Sent: Wednesday, September 26, 2018 2:41 PM
>To: Shankar, Uma ; intel-...@lists.freedesktop.org;
>dri-devel@lists.freedesktop.org
>Cc: Syrjala, Ville ; Lankhorst, Maarten
>
>Subject: Re: [Intel-gfx] [RFC 3/3] drm/i915: Set colorspace by enabling 
>Infoframe
>
>Op 24-07-18 om 17:45 schreef Uma Shankar:
>> Based on colorspace property value create an infoframe with
>> appropriate colorspace. This can be used to send an infoframe packet
>> with proper colorspace value set which will help to enable wider color
>> gamut like BT2020 on sink.
>>
>> Signed-off-by: Uma Shankar 
>> ---
>>  drivers/gpu/drm/i915/intel_hdmi.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/i915/intel_hdmi.c
>> b/drivers/gpu/drm/i915/intel_hdmi.c
>> index 7fb96e2..319da1b 100644
>> --- a/drivers/gpu/drm/i915/intel_hdmi.c
>> +++ b/drivers/gpu/drm/i915/intel_hdmi.c
>> @@ -491,6 +491,8 @@ static void intel_hdmi_set_avi_infoframe(struct
>drm_encoder *encoder,
>>  else
>>  frame.avi.colorspace = HDMI_COLORSPACE_RGB;
>>
>> +frame.avi.extended_colorimetry = conn_state->colorspace;
>> +
>>  drm_hdmi_avi_infoframe_quant_range(, adjusted_mode,
>> crtc_state->limited_color_range ?
>>
>HDMI_QUANTIZATION_RANGE_LIMITED :
>
>I would merge this with the previous patch, to be honest.
>
>If it was non-trivial I would suggest splitting it up. :)

Ok Sure, will merge them.

>~Maarten

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


RE: [Intel-gfx] [RFC 1/3] drm: Add colorspace property

2018-09-26 Thread Shankar, Uma


>-Original Message-
>From: Ville Syrjälä [mailto:ville.syrj...@linux.intel.com]
>Sent: Wednesday, September 26, 2018 3:12 PM
>To: Maarten Lankhorst 
>Cc: Shankar, Uma ; Adam Jackson
>; intel-...@lists.freedesktop.org; dri-
>de...@lists.freedesktop.org; Syrjala, Ville ; 
>Lankhorst,
>Maarten 
>Subject: Re: [Intel-gfx] [RFC 1/3] drm: Add colorspace property
>
>On Wed, Sep 26, 2018 at 11:08:37AM +0200, Maarten Lankhorst wrote:
>> Op 01-08-18 om 16:01 schreef Shankar, Uma:
>> >
>> >> -Original Message-
>> >> From: Adam Jackson [mailto:a...@redhat.com]
>> >> Sent: Wednesday, August 1, 2018 1:24 AM
>> >> To: Shankar, Uma ;
>> >> intel-...@lists.freedesktop.org; dri-devel@lists.freedesktop.org
>> >> Cc: Syrjala, Ville ; Lankhorst, Maarten
>> >> 
>> >> Subject: Re: [RFC 1/3] drm: Add colorspace property
>> >>
>> >> On Tue, 2018-07-24 at 21:15 +0530, Uma Shankar wrote:
>> >>
>> >>> --- a/include/uapi/drm/drm_mode.h
>> >>> +++ b/include/uapi/drm/drm_mode.h
>> >>> @@ -209,6 +209,17 @@
>> >>>  #define DRM_MODE_CONTENT_PROTECTION_DESIRED 1
>> >>>  #define DRM_MODE_CONTENT_PROTECTION_ENABLED 2
>> >>>
>> >>> +enum extended_colorimetry {
>> >>> +EXTENDED_COLORIMETRY_XV_YCC_601 = 0,
>> >>> +EXTENDED_COLORIMETRY_XV_YCC_709,
>> >>> +EXTENDED_COLORIMETRY_S_YCC_601,
>> >>> +EXTENDED_COLORIMETRY_ADOBE_YCC_601,
>> >>> +EXTENDED_COLORIMETRY_ADOBE_RGB,
>> >>> +EXTENDED_COLORIMETRY_BT2020_RGB,
>> >>> +EXTENDED_COLORIMETRY_BT2020_YCC,
>> >>> +EXTENDED_COLORIMETRY_BT2020_CYCC, };
>> >> This doesn't give any way to distinguish "not set" from BT.601,
>> >> which I'm not sure I like.
>> > This enum gives a list of all possible colorspace which can be set on the 
>> > sink
>device.
>> > The compositors/userspace can choose one of them, based on the
>> > capabilities of sink as well as based on rendering/blending policies
>> > which are designed to take advantage of hardware resources available.
>> >
>> > If you suggest to add something like NO_COLORSPACE_SET = -1, I can
>> > add that to this enum list.
>> I would add a default, but not sure I would introduce a new enum.
>> hdmi_extended_colorimetry is already available.
>
>Yeah, there should be a default entry for "driver automagically picks something
>suitable".
>

Ok got it, will add a default option to the list.

>I think the enum prop should also be some kind of superset of all
>CEA-861 normal+extended colorimetry options and DP MSA+VSC SDP colorimetry
>options. The current list seems a bit incomplete to me.
>

So should I keep this enum and append DP MSA +VSC SDP options to the list ?
We can then have encoder specific enums separate from this global colorpsace
enum. 

>--
>Ville Syrjälä
>Intel
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [GIT PULL] drm-hisilicon-next-2018-09-26

2018-09-26 Thread Dave Airlie
On Wed, 26 Sep 2018 at 15:58, Xinliang Liu  wrote:
>
> Hi Dave,
> A few changes for 4.20. Please pull.
> - A crash fix founded in recent linux-next from John Garry
> - One sparse warning fix from Souptick Joarder
> - Some xxx_unref cleanup from Thomas Zimmermann
>
> Thanks,
> Xinliang
>
>
> The following changes since commit 36c9c3c91128e2b892c9be0dd9ee9bd82cbe82ad:
>
>   Merge branch 'drm-next-4.20' of
> git://people.freedesktop.org/~agd5f/linux into drm-next (2018-09-21
> 09:52:53 +1000)
>
> are available in the git repository at:
>
>
>   g...@github.com:xin3liang/linux.git tags/drm-hisilicon-next-2018-09-26

Any idea why this url is on a second line with a blank line?

It's stopping scripts from picking this up for patchwork, is something
editing the pull? can you remove it?

I can process this one manually, just annoying.

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


[Bug 106164] dal_gpio_open_ex+0x34/0x180 [amdgpu]

2018-09-26 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=106164

higu...@gmx.net changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #1 from higu...@gmx.net ---
looks like a dupe from Bug 105725

i'm too using slackware, even rebuild kernels are based on the default
slackware kernel .config file

*** This bug has been marked as a duplicate of bug 105725 ***

-- 
You are receiving this mail because:
You are the assignee for the bug.___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[Bug 105725] WARNING: CPU: 0 PID: 487 at drivers/gpu/drm/amd/amdgpu/../display /dc/gpio/gpio_base.c:64 dal_gpio_open_ex+0xc/0x30 [amdgpu]

2018-09-26 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=105725

--- Comment #11 from higu...@gmx.net ---
*** Bug 106164 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are the assignee for the bug.___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 2/2] drm/i915: Do not get aux power for disconnected DP ports

2018-09-26 Thread Souza, Jose
On Tue, 2018-09-25 at 11:16 +0300, Jani Nikula wrote:
> On Mon, 24 Sep 2018, José Roberto de Souza 
> wrote:
> > For ICL type-c ports there is a aux power restriction, it can only
> > be
> > enabled while there is sink connected.
> > 
> > BSpec: 21750
> > 
> > Cc: Maarten Lankhorst 
> > Signed-off-by: José Roberto de Souza 
> > ---
> >  drivers/gpu/drm/i915/intel_dp.c | 19 ++-
> >  1 file changed, 14 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/intel_dp.c
> > b/drivers/gpu/drm/i915/intel_dp.c
> > index 6b4c19123f2a..48fd38cd4ba4 100644
> > --- a/drivers/gpu/drm/i915/intel_dp.c
> > +++ b/drivers/gpu/drm/i915/intel_dp.c
> > @@ -5019,19 +5019,27 @@ intel_dp_long_pulse(struct intel_connector
> > *connector,
> > struct intel_dp *intel_dp = intel_attached_dp(
> > >base);
> > enum drm_connector_status status;
> > u8 sink_irq_vector = 0;
> > +   bool got_aux_power;
> >  
> > WARN_ON(!drm_modeset_is_locked(_priv-
> > >drm.mode_config.connection_mutex));
> >  
> > +   /* Can't disconnect eDP */
> > +   if (!intel_dp_is_edp(intel_dp) &&
> > +   !intel_digital_port_connected(_to_dig_port(intel_dp)-
> > >base)) {
> > +   status = connector_status_disconnected;
> > +   got_aux_power = false;
> > +   goto port_disconnected;
> > +   }
> > +
> > intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
> > +   got_aux_power = true;
> >  
> > -   /* Can't disconnect eDP */
> > if (intel_dp_is_edp(intel_dp))
> > status = edp_detect(intel_dp);
> > -   else if
> > (intel_digital_port_connected(_to_dig_port(intel_dp)->base))
> > -   status = intel_dp_detect_dpcd(intel_dp);
> > else
> > -   status = connector_status_disconnected;
> > +   status = intel_dp_detect_dpcd(intel_dp);
> 
> 
> I think this change makes an already difficult to read function too
> complicated. The goto does not help. Please rething the approach.

Okay, I will send a patch making improvements in this function in other
patch, then rewrite this one.

Thanks

> 
> BR,
> Jani.
> 
> >  
> > +port_disconnected:
> > if (status == connector_status_disconnected) {
> > memset(_dp->compliance, 0, sizeof(intel_dp-
> > >compliance));
> >  
> > @@ -5122,7 +5130,8 @@ intel_dp_long_pulse(struct intel_connector
> > *connector,
> > if (status != connector_status_connected && !intel_dp->is_mst)
> > intel_dp_unset_edid(intel_dp);
> >  
> > -   intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
> > +   if (got_aux_power)
> > +   intel_display_power_put(dev_priv, intel_dp-
> > >aux_power_domain);
> > return status;
> >  }
> 
> 
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [Intel-gfx] [PATCH 2/2] drm/i915: Do not get aux power for disconnected DP ports

2018-09-26 Thread Souza, Jose
On Tue, 2018-09-25 at 15:17 +0300, Ville Syrjälä wrote:
> On Mon, Sep 24, 2018 at 06:16:49PM -0700, José Roberto de Souza
> wrote:
> > For ICL type-c ports there is a aux power restriction, it can only
> > be
> > enabled while there is sink connected.
> 
> That can't be entirely true because it's super racy. I was talking
> with Imre about this mess at some point, and IIRC we came up with
> some half decent theories on how we might handle this mess in a
> sane manner. IIRC it was something along the lines of: the tbt vs.
> other mode knob defines which power well we can enable, and so
> while we're doing something with the port in one mode or the other
> we must not try to use the port in the other mode. Ie. we need to
> properly track which mode the port is in and if there's an event
> that requires switching modes we have to wait until the previous
> use of the other mode has stopped.

I can't think how would we use the same TBT3 port in TBT3 and USB-C
mode without going to the disconnection and connection flow.

This statment about aux power restriction is on BSec also in the past
we were having some timeouts warnings while waiting for USB-C/TBT aux
power wells to be turn or off, Imre fixed that by not adding
POWER_DOMAIN_INIT to those power well domains.

> 
> > 
> > BSpec: 21750
> > 
> > Cc: Maarten Lankhorst 
> > Signed-off-by: José Roberto de Souza 
> > ---
> >  drivers/gpu/drm/i915/intel_dp.c | 19 ++-
> >  1 file changed, 14 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/intel_dp.c
> > b/drivers/gpu/drm/i915/intel_dp.c
> > index 6b4c19123f2a..48fd38cd4ba4 100644
> > --- a/drivers/gpu/drm/i915/intel_dp.c
> > +++ b/drivers/gpu/drm/i915/intel_dp.c
> > @@ -5019,19 +5019,27 @@ intel_dp_long_pulse(struct intel_connector
> > *connector,
> > struct intel_dp *intel_dp = intel_attached_dp(
> > >base);
> > enum drm_connector_status status;
> > u8 sink_irq_vector = 0;
> > +   bool got_aux_power;
> >  
> > WARN_ON(!drm_modeset_is_locked(_priv-
> > >drm.mode_config.connection_mutex));
> >  
> > +   /* Can't disconnect eDP */
> > +   if (!intel_dp_is_edp(intel_dp) &&
> > +   !intel_digital_port_connected(_to_dig_port(intel_dp)-
> > >base)) {
> > +   status = connector_status_disconnected;
> > +   got_aux_power = false;
> > +   goto port_disconnected;
> > +   }
> > +
> > intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
> > +   got_aux_power = true;
> >  
> > -   /* Can't disconnect eDP */
> > if (intel_dp_is_edp(intel_dp))
> > status = edp_detect(intel_dp);
> > -   else if
> > (intel_digital_port_connected(_to_dig_port(intel_dp)->base))
> > -   status = intel_dp_detect_dpcd(intel_dp);
> > else
> > -   status = connector_status_disconnected;
> > +   status = intel_dp_detect_dpcd(intel_dp);
> >  
> > +port_disconnected:
> > if (status == connector_status_disconnected) {
> > memset(_dp->compliance, 0, sizeof(intel_dp-
> > >compliance));
> >  
> > @@ -5122,7 +5130,8 @@ intel_dp_long_pulse(struct intel_connector
> > *connector,
> > if (status != connector_status_connected && !intel_dp->is_mst)
> > intel_dp_unset_edid(intel_dp);
> >  
> > -   intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
> > +   if (got_aux_power)
> > +   intel_display_power_put(dev_priv, intel_dp-
> > >aux_power_domain);
> > return status;
> >  }
> >  
> > -- 
> > 2.19.0
> > 
> > ___
> > Intel-gfx mailing list
> > intel-...@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
> 
> 
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[Bug 107333] Display Not Detected If Powered Off When amdgpu.dc=1

2018-09-26 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=107333

--- Comment #3 from Matias N. Goldberg  ---
I think I'm having the same problem.

I'll first describe my symptoms (all of them happening with DC=1):

Case 1:
1. Boot System
2. Monitors must be off by the time GRUB inits the kernel.
3. Wait until everything's up
4. Turn on monitor(s)
5. Monitor(s) will go to sleep because they're not receiving any signal

Workaround:
Ctrl+Alt+F1 to go into terminal, monitor now goes on. Type: sudo service
lightdm restart

Case 2:
1. Suspend the system
2. Turn off the monitors
3. Resume the system
4. Turn on monitor(s)
5. Monitor(s) will go to sleep
6. Trying Ctrl+Alt+F1 then Ctrl+Alt+F7 will show the dreaded "Session is Locked
You'll be redirected to the unlock dialog in a few seconds" but after a few
seconds the monitors go to sleep again and lightdm never unlocks.

Workaround:
Ctrl+Alt+F1 to go into terminal, monitor now goes on. Type: sudo loginctl
unlock-sessions

Case 3:
1. Login to XFCE
2. Set "Extend Displays"
3. Turn off the secondary monitors (I have 2). All is OK. The extended desktop
still works even though I cannot see it (expected behavior)
4. Turn off the main monitor too.
5. After turning on main monitor, now xfce will be set to "Mirror Displays"
instead

Workaround:
Super Key + P then select "Extend to the right" again.

Except for case 3 in which a secondary monitor is needed, it doesn't seem like
having 2 monitors affects the symptoms.

It's as if the kernel changes something that makes xfce & lightdm go nuts when
all monitors go off.

My environment:
Xubuntu 18.04
XFCE 4.12
Kernel 4.18.9
libdrm-2.4.94
Device: Radeon RX 560 Series (POLARIS11, DRM 3.26.0, 4.18.9, LLVM 7.0.0)
(0x67ff)
Version: 18.2.0

Radeon RX 560 2GB Gigabyte
Main LG FLATRON E2342 Monitor connected via HDMI
Secondary LG FLATRON E2341 Monitor connected via DVI

Booting with amdgpu.dc=0 fixes these issues.

This is the output of xrandr when both monitors are off and amdgpu.dc=0
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
DisplayPort-0 disconnected (normal left inverted right x axis y axis)
HDMI-A-0 connected primary 1920x1080+0+0 (normal left inverted right x axis y
axis) 510mm x 290mm
   1920x1080 60.00*+  50.0059.94  
   1920x1080i60.0050.0059.94  
   1680x1050 59.88  
   1400x1050 59.95  
   1600x900  60.00  
   1280x1024 60.02  
   1440x900  59.90  
   1280x800  59.91  
   1152x864  75.00  
   1280x720  60.0050.0059.94  
   1024x768  60.00  
   800x600   60.32  
   720x576   50.00  
   720x480   60.0059.94  
   640x480   60.0059.94  
DVI-D-0 connected (normal left inverted right x axis y axis)
   1920x1080 60.00 +
   1680x1050 59.88  
   1280x1024 75.0260.02  
   1280x960  60.00  
   1152x864  75.00  
   1024x768  75.0360.00  
   832x624   74.55  
   800x600   75.0060.3256.25  
   640x480   75.0059.94  


This is the output of xrandr when both monitors are off and amdgpu.dc=1

Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
DisplayPort-0 disconnected (normal left inverted right x axis y axis)
HDMI-A-0 disconnected primary (normal left inverted right x axis y axis)
DVI-D-0 connected (normal left inverted right x axis y axis)
   1920x1080 60.00 +
   1680x1050 59.88  
   1280x1024 75.0260.02  
   1440x900  60.00  
   1280x960  60.00  
   1280x800  60.00  
   1152x864  75.00  
   1280x720  60.00  
   1024x768  75.0360.00  
   832x624   74.55  
   800x600   75.0060.3256.25  
   640x480   75.0059.94  
   720x400   70.08 


Notice the HDMI monitor is now listed as disconnected.

Perhaps this is a case of "not our bug" and software should accommodate for
"hotpluggable monitors".
However if that's the case, this is still a problem when the new behavior
breaks basic desktop system software on boot and resume-from-suspend; and I'd
suggest either DRM should report a state of connected-but-off (if it's not
already there, then this is a driver bug), or there should be an extra kernel
param to not list powered-off monitors as disconnected, without having to
disable amdgpu.dc.

Cheers

-- 
You are receiving this mail because:
You are the assignee for the bug.___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v2 5/8] dt-bindings: display: add data-enable polarity property

2018-09-26 Thread Rob Herring
On Wed, 12 Sep 2018 11:32:19 -0700, Stefan Agner wrote:
> Allow to specify the data-enable polarity required by a dumb VGA
> DAC converting parallel RGB to VGA.
> 
> Signed-off-by: Stefan Agner 
> ---
>  .../devicetree/bindings/display/bridge/dumb-vga-dac.txt | 2 ++
>  1 file changed, 2 insertions(+)
> 

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


[PATCH 1/2] drm/fsl-dcu: drop unused drm_crtc_index()

2018-09-26 Thread Stefan Agner
The result of drm_crtc_index() is unused. Remove the call and
the unused variable.

Signed-off-by: Stefan Agner 
---
This is a split version of a patch posted a while ago:
https://lore.kernel.org/patchwork/patch/903786/

 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c 
b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
index 0e3752437e44..05d1c9977395 100644
--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
+++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
@@ -85,9 +85,8 @@ static void fsl_dcu_drm_crtc_mode_set_nofb(struct drm_crtc 
*crtc)
struct fsl_dcu_drm_device *fsl_dev = dev->dev_private;
struct drm_connector *con = _dev->connector.base;
struct drm_display_mode *mode = >state->mode;
-   unsigned int hbp, hfp, hsw, vbp, vfp, vsw, index, pol = 0;
+   unsigned int hbp, hfp, hsw, vbp, vfp, vsw, pol = 0;
 
-   index = drm_crtc_index(crtc);
clk_set_rate(fsl_dev->pix_clk, mode->clock * 1000);
 
/* Configure timings: */
-- 
2.19.0

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


[PATCH 2/2] drm/fsl-dcu: use drm_display_mode_to_videomode to calculate timing parameters

2018-09-26 Thread Stefan Agner
From: Satendra Singh Thakur 

Use the drm_display_mode_to_videomode function to calculate front/
back porches and sync length.

Cc: Madhur Verma 
Cc: Hemanshu Srivastava 
Signed-off-by: Satendra Singh Thakur 
Signed-off-by: Stefan Agner 
---
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c | 32 ++
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c 
b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
index 05d1c9977395..18afc94e4dff 100644
--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
+++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "fsl_dcu_drm_crtc.h"
 #include "fsl_dcu_drm_drv.h"
@@ -85,39 +86,34 @@ static void fsl_dcu_drm_crtc_mode_set_nofb(struct drm_crtc 
*crtc)
struct fsl_dcu_drm_device *fsl_dev = dev->dev_private;
struct drm_connector *con = _dev->connector.base;
struct drm_display_mode *mode = >state->mode;
-   unsigned int hbp, hfp, hsw, vbp, vfp, vsw, pol = 0;
+   unsigned int pol = 0;
+   struct videomode vm;
 
clk_set_rate(fsl_dev->pix_clk, mode->clock * 1000);
 
-   /* Configure timings: */
-   hbp = mode->htotal - mode->hsync_end;
-   hfp = mode->hsync_start - mode->hdisplay;
-   hsw = mode->hsync_end - mode->hsync_start;
-   vbp = mode->vtotal - mode->vsync_end;
-   vfp = mode->vsync_start - mode->vdisplay;
-   vsw = mode->vsync_end - mode->vsync_start;
+   drm_display_mode_to_videomode(mode, );
 
/* INV_PXCK as default (most display sample data on rising edge) */
if (!(con->display_info.bus_flags & DRM_BUS_FLAG_PIXDATA_POSEDGE))
pol |= DCU_SYN_POL_INV_PXCK;
 
-   if (mode->flags & DRM_MODE_FLAG_NHSYNC)
+   if (vm.flags & DISPLAY_FLAGS_HSYNC_LOW)
pol |= DCU_SYN_POL_INV_HS_LOW;
 
-   if (mode->flags & DRM_MODE_FLAG_NVSYNC)
+   if (vm.flags & DISPLAY_FLAGS_VSYNC_LOW)
pol |= DCU_SYN_POL_INV_VS_LOW;
 
regmap_write(fsl_dev->regmap, DCU_HSYN_PARA,
-DCU_HSYN_PARA_BP(hbp) |
-DCU_HSYN_PARA_PW(hsw) |
-DCU_HSYN_PARA_FP(hfp));
+DCU_HSYN_PARA_BP(vm.hback_porch) |
+DCU_HSYN_PARA_PW(vm.hsync_len) |
+DCU_HSYN_PARA_FP(vm.hfront_porch));
regmap_write(fsl_dev->regmap, DCU_VSYN_PARA,
-DCU_VSYN_PARA_BP(vbp) |
-DCU_VSYN_PARA_PW(vsw) |
-DCU_VSYN_PARA_FP(vfp));
+DCU_VSYN_PARA_BP(vm.vback_porch) |
+DCU_VSYN_PARA_PW(vm.vsync_len) |
+DCU_VSYN_PARA_FP(vm.vfront_porch));
regmap_write(fsl_dev->regmap, DCU_DISP_SIZE,
-DCU_DISP_SIZE_DELTA_Y(mode->vdisplay) |
-DCU_DISP_SIZE_DELTA_X(mode->hdisplay));
+DCU_DISP_SIZE_DELTA_Y(vm.vactive) |
+DCU_DISP_SIZE_DELTA_X(vm.hactive));
regmap_write(fsl_dev->regmap, DCU_SYN_POL, pol);
regmap_write(fsl_dev->regmap, DCU_BGND, DCU_BGND_R(0) |
 DCU_BGND_G(0) | DCU_BGND_B(0));
-- 
2.19.0

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


Re: [PATCH v3 09/11] drm/fsl-dcu: Use drm_fb_cma_fbdev_init/fini()

2018-09-26 Thread Stefan Agner
On 08.12.2017 20:37, Noralf Trønnes wrote:
> Use drm_fb_cma_fbdev_init() and drm_fb_cma_fbdev_fini() which relies on
> the fact that drm_device holds a pointer to the drm_fb_helper structure.
> This means that the driver doesn't have to keep track of that.
> Also use the drm_fb_helper functions directly.
> Remove console.h inclusion which was forgotten when converting to the
> suspend/resume helpers.

Just realized this never made it upstream. I guess its still valid and
could be applied?

--
Stefan

> 
> Cc: Stefan Agner 
> Cc: Alison Wang 
> Signed-off-by: Noralf Trønnes 
> ---
>  drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c | 26 ++
>  drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h |  1 -
>  2 files changed, 6 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> index 80232321a244..e487a2002783 100644
> --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> @@ -11,7 +11,6 @@
>  
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> @@ -25,6 +24,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -89,19 +89,15 @@ static int fsl_dcu_load(struct drm_device *dev,
> unsigned long flags)
>   "Invalid legacyfb_depth.  Defaulting to 24bpp\n");
>   legacyfb_depth = 24;
>   }
> - fsl_dev->fbdev = drm_fbdev_cma_init(dev, legacyfb_depth, 1);
> - if (IS_ERR(fsl_dev->fbdev)) {
> - ret = PTR_ERR(fsl_dev->fbdev);
> - fsl_dev->fbdev = NULL;
> + ret = drm_fb_cma_fbdev_init(dev, legacyfb_depth, 1);
> + if (ret)
>   goto done;
> - }
>  
>   return 0;
>  done:
>   drm_kms_helper_poll_fini(dev);
>  
> - if (fsl_dev->fbdev)
> - drm_fbdev_cma_fini(fsl_dev->fbdev);
> + drm_fb_cma_fbdev_fini(dev);
>  
>   drm_mode_config_cleanup(dev);
>   drm_irq_uninstall(dev);
> @@ -112,13 +108,10 @@ static int fsl_dcu_load(struct drm_device *dev,
> unsigned long flags)
>  
>  static void fsl_dcu_unload(struct drm_device *dev)
>  {
> - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private;
> -
>   drm_atomic_helper_shutdown(dev);
>   drm_kms_helper_poll_fini(dev);
>  
> - if (fsl_dev->fbdev)
> - drm_fbdev_cma_fini(fsl_dev->fbdev);
> + drm_fb_cma_fbdev_fini(dev);
>  
>   drm_mode_config_cleanup(dev);
>   drm_irq_uninstall(dev);
> @@ -147,19 +140,12 @@ static irqreturn_t fsl_dcu_drm_irq(int irq, void *arg)
>   return IRQ_HANDLED;
>  }
>  
> -static void fsl_dcu_drm_lastclose(struct drm_device *dev)
> -{
> - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private;
> -
> - drm_fbdev_cma_restore_mode(fsl_dev->fbdev);
> -}
> -
>  DEFINE_DRM_GEM_CMA_FOPS(fsl_dcu_drm_fops);
>  
>  static struct drm_driver fsl_dcu_drm_driver = {
>   .driver_features= DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET
>   | DRIVER_PRIME | DRIVER_ATOMIC,
> - .lastclose  = fsl_dcu_drm_lastclose,
> + .lastclose  = drm_fb_helper_lastclose,
>   .load   = fsl_dcu_load,
>   .unload = fsl_dcu_unload,
>   .irq_handler= fsl_dcu_drm_irq,
> diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h
> b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h
> index 93bfb98012d4..cb87bb74cb87 100644
> --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h
> +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h
> @@ -191,7 +191,6 @@ struct fsl_dcu_drm_device {
>   /*protects hardware register*/
>   spinlock_t irq_lock;
>   struct drm_device *drm;
> - struct drm_fbdev_cma *fbdev;
>   struct drm_crtc crtc;
>   struct drm_encoder encoder;
>   struct fsl_dcu_drm_connector connector;
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [RESEND PATCH] drm/fsl-dcu: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Stefan Agner
On 26.09.2018 13:43, Thomas Zimmermann wrote:
> This patch unifies the naming of DRM functions for reference counting
> of struct drm_device. The resulting code is more aligned with the rest
> of the Linux kernel interfaces.

Applied!

--
Stefan

> 
> Signed-off-by: Thomas Zimmermann 
> ---
>  drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> index 80232321a244..0496be5212e1 100644
> --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> @@ -353,12 +353,12 @@ static int fsl_dcu_drm_probe(struct platform_device 
> *pdev)
> 
>   ret = drm_dev_register(drm, 0);
>   if (ret < 0)
> - goto unref;
> + goto put;
> 
>   return 0;
> 
> -unref:
> - drm_dev_unref(drm);
> +put:
> + drm_dev_put(drm);
>  unregister_pix_clk:
>   clk_unregister(fsl_dev->pix_clk);
>  disable_clk:
> @@ -371,7 +371,7 @@ static int fsl_dcu_drm_remove(struct platform_device 
> *pdev)
>   struct fsl_dcu_drm_device *fsl_dev = platform_get_drvdata(pdev);
> 
>   drm_dev_unregister(fsl_dev->drm);
> - drm_dev_unref(fsl_dev->drm);
> + drm_dev_put(fsl_dev->drm);
>   clk_disable_unprepare(fsl_dev->clk);
>   clk_unregister(fsl_dev->pix_clk);
> 
> --
> 2.19.0
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [RESEND 0/5] drm/mxsfb: Fix runtime PM for unpowering lcdif block

2018-09-26 Thread Stefan Agner
On 20.09.2018 18:39, Sean Paul wrote:
> On Thu, Sep 20, 2018 at 11:59 AM Leonard Crestez
>  wrote:
>>
>> On Mon, 2018-09-17 at 16:37 -0700, Stefan Agner wrote:
>> > On 17.09.2018 12:16, Sean Paul wrote:
>> > > On Mon, Sep 17, 2018 at 04:42:10PM +0300, Leonard Crestez wrote:
>> > > > Adding lcdif nodes to a power domain currently doesn't work, it results
>> > > > in black/corrupted screens or hangs. While the driver does enable
>> > > > runtime pm it does not deal correctly with the block being unpowered.
>> > > >
>> > > > All patches in this series have review tags from a while ago and I
>> > > > tested them again on top of next-20180913. No changes
>> > > >
>> > > > This series stalled so I reached out to Marek on IRC and he was
>> > > > surprised to be listed as maintainer
>> > >
>> > > Hopefully not too surprised since Marek added themself to MAINTAINERS 
>> > > when
>> > > adding the driver :-)
>> >
>> > There have been some confusion about the DRM development processes
>> > around the mxsfb already in the past.
>> >
>> > > I suppose we should probably move this to drm-misc since it qualifies as 
>> > > a
>> > > "small driver" and needs a home. Looking through git history shows the 
>> > > last
>> > > mxsfb-specific change was back in 02/17. Everything else has been 
>> > > drm-wide
>> > > refactors. Thoughts?
>> > >
>> > > Marek/Leonard: Care to sign up to be listed as a reviewers?
>> >
>> > drm-misc seems to make sense. I volunteer to be listed as reviewer or 
>> > co-maintainer.
>>
>> This gets +1 from me, you were very helpful during review.
>>
>> Next would be for one of the drm-misc maintainers to post a change for
>> the MAINTAINER file and also merge my series?
>>
> 
> I've posted the MAINTAINERS patch here:
> https://lists.freedesktop.org/archives/dri-devel/2018-September/190414.html
> 
> Once I get some Acks, we can merge that and one of Stefan or Marek can apply 
> the
> patchset to drm-misc.

Applied, fixed a white space issue in patch 4 and pushed to drm-misc.

Thanks Sean for helping out here!

And thanks Leonard for working on this and push for its inclusion!

--
Stefan

> 
> Sean
> 
>> --
>> Regards,
>> Leonard
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 15/15] staging: vboxvideo: Use more drm_fb_helper functions

2018-09-26 Thread Hans de Goede
Store fbhelper and afb struct directly in vbox_private and use
drm_fb_helper_fbdev_setup to replace vbox_fbdev_init, note we cannot use
drm_fb_helper_fbdev_teardown since we use a private framebuffer for the
fbdev.

And replace vbox_driver_lastclose with drm_fb_helper_lastclose.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_drv.c  | 10 +++-
 drivers/staging/vboxvideo/vbox_drv.h  | 28 +++
 drivers/staging/vboxvideo/vbox_fb.c   | 70 ++-
 drivers/staging/vboxvideo/vbox_main.c | 12 -
 drivers/staging/vboxvideo/vbox_mode.c |  2 +-
 5 files changed, 31 insertions(+), 91 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_drv.c 
b/drivers/staging/vboxvideo/vbox_drv.c
index c3e14107da0d..257030460fb6 100644
--- a/drivers/staging/vboxvideo/vbox_drv.c
+++ b/drivers/staging/vboxvideo/vbox_drv.c
@@ -49,6 +49,10 @@ static const struct pci_device_id pciidlist[] = {
 };
 MODULE_DEVICE_TABLE(pci, pciidlist);
 
+static struct drm_fb_helper_funcs vbox_fb_helper_funcs = {
+   .fb_probe = vboxfb_create,
+};
+
 static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id 
*ent)
 {
struct vbox_private *vbox;
@@ -92,7 +96,9 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
if (ret)
goto err_mode_fini;
 
-   ret = vbox_fbdev_init(vbox);
+   ret = drm_fb_helper_fbdev_setup(>ddev, >fb_helper,
+   _fb_helper_funcs, 32,
+   vbox->num_crtcs);
if (ret)
goto err_irq_fini;
 
@@ -257,7 +263,7 @@ static struct drm_driver driver = {
DRIVER_PRIME | DRIVER_ATOMIC,
.dev_priv_size = 0,
 
-   .lastclose = vbox_driver_lastclose,
+   .lastclose = drm_fb_helper_lastclose,
.master_set = vbox_master_set,
.master_drop = vbox_master_drop,
 
diff --git a/drivers/staging/vboxvideo/vbox_drv.h 
b/drivers/staging/vboxvideo/vbox_drv.h
index 9cc20c182df1..73395a7536c5 100644
--- a/drivers/staging/vboxvideo/vbox_drv.h
+++ b/drivers/staging/vboxvideo/vbox_drv.h
@@ -72,11 +72,16 @@
sizeof(struct hgsmi_host_flags))
 #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
 
-struct vbox_fbdev;
+struct vbox_framebuffer {
+   struct drm_framebuffer base;
+   struct drm_gem_object *obj;
+};
 
 struct vbox_private {
/* Must be first; or we must define our own release callback */
struct drm_device ddev;
+   struct drm_fb_helper fb_helper;
+   struct vbox_framebuffer afb;
 
u8 __iomem *guest_heap;
u8 __iomem *vbva_buffers;
@@ -91,8 +96,6 @@ struct vbox_private {
/** Array of structures for receiving mode hints. */
struct vbva_modehint *last_mode_hints;
 
-   struct vbox_fbdev *fbdev;
-
int fb_mtrr;
 
struct {
@@ -122,8 +125,6 @@ struct vbox_private {
 #undef CURSOR_PIXEL_COUNT
 #undef CURSOR_DATA_SIZE
 
-void vbox_driver_lastclose(struct drm_device *dev);
-
 struct vbox_gem_object;
 
 struct vbox_connector {
@@ -171,20 +172,6 @@ struct vbox_encoder {
struct drm_encoder base;
 };
 
-struct vbox_framebuffer {
-   struct drm_framebuffer base;
-   struct drm_gem_object *obj;
-};
-
-struct vbox_fbdev {
-   struct drm_fb_helper helper;
-   struct vbox_framebuffer afb;
-   int size;
-   struct ttm_bo_kmap_obj mapping;
-   int x1, y1, x2, y2; /* dirty rect */
-   spinlock_t dirty_lock;
-};
-
 #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
 #define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
 #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
@@ -212,7 +199,8 @@ int vbox_framebuffer_init(struct vbox_private *vbox,
  const struct DRM_MODE_FB_CMD *mode_cmd,
  struct drm_gem_object *obj);
 
-int vbox_fbdev_init(struct vbox_private *vbox);
+int vboxfb_create(struct drm_fb_helper *helper,
+ struct drm_fb_helper_surface_size *sizes);
 void vbox_fbdev_fini(struct vbox_private *vbox);
 
 struct vbox_bo {
diff --git a/drivers/staging/vboxvideo/vbox_fb.c 
b/drivers/staging/vboxvideo/vbox_fb.c
index 8a9d56762659..ee25f3a03934 100644
--- a/drivers/staging/vboxvideo/vbox_fb.c
+++ b/drivers/staging/vboxvideo/vbox_fb.c
@@ -66,13 +66,11 @@ static struct fb_ops vboxfb_ops = {
.fb_debug_leave = drm_fb_helper_debug_leave,
 };
 
-static int vboxfb_create(struct drm_fb_helper *helper,
-struct drm_fb_helper_surface_size *sizes)
+int vboxfb_create(struct drm_fb_helper *helper,
+ struct drm_fb_helper_surface_size *sizes)
 {
-   struct vbox_fbdev *fbdev =
-   container_of(helper, struct vbox_fbdev, helper);
-   struct vbox_private *vbox = container_of(fbdev->helper.dev,
-struct vbox_private, ddev);
+   struct vbox_private *vbox 

[PATCH 13/15] staging: vboxvideo: Call drm_atomic_helper_check_plane_state from atomic_check

2018-09-26 Thread Hans de Goede
Extend our planes atomic_check callbacks to be more thorough by calling
the drm_atomic_helper_check_plane_state helper.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_mode.c | 30 ++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index 72fc6614179a..4993a6cf6770 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -280,7 +280,19 @@ static const struct drm_crtc_funcs vbox_crtc_funcs = {
 static int vbox_primary_atomic_check(struct drm_plane *plane,
 struct drm_plane_state *new_state)
 {
-   return 0;
+   struct drm_crtc_state *crtc_state = NULL;
+
+   if (new_state->crtc) {
+   crtc_state = drm_atomic_get_existing_crtc_state(
+   new_state->state, new_state->crtc);
+   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);
 }
 
 static void vbox_primary_atomic_update(struct drm_plane *plane,
@@ -337,8 +349,24 @@ static void vbox_primary_cleanup_fb(struct drm_plane 
*plane,
 static int vbox_cursor_atomic_check(struct drm_plane *plane,
struct drm_plane_state *new_state)
 {
+   struct drm_crtc_state *crtc_state = NULL;
u32 width = new_state->crtc_w;
u32 height = new_state->crtc_h;
+   int ret;
+
+   if (new_state->crtc) {
+   crtc_state = drm_atomic_get_existing_crtc_state(
+   new_state->state, new_state->crtc);
+   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;
 
if (!new_state->fb)
return 0;
-- 
2.19.0

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


[PATCH 14/15] staging: vboxvideo: Drop unnecessary drm_connector_helper_funcs callbacks

2018-09-26 Thread Hans de Goede
vbox_mode_valid always returns MODE_OK, which is also the default if no
mode_valid callback is defined.

vbox_best_single_encoder chains to drm_encoder_find, the drm-core will
call drm_encoder_find itself if there is no best_encoder call back.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_mode.c | 20 
 1 file changed, 20 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index 4993a6cf6770..756544b53600 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -651,18 +651,6 @@ static void vbox_encoder_destroy(struct drm_encoder 
*encoder)
kfree(encoder);
 }
 
-static struct drm_encoder *vbox_best_single_encoder(struct drm_connector
-   *connector)
-{
-   int enc_id = connector->encoder_ids[0];
-
-   /* pick the encoder ids */
-   if (enc_id)
-   return drm_encoder_find(connector->dev, NULL, enc_id);
-
-   return NULL;
-}
-
 static const struct drm_encoder_funcs vbox_enc_funcs = {
.destroy = vbox_encoder_destroy,
 };
@@ -820,12 +808,6 @@ static int vbox_get_modes(struct drm_connector *connector)
return num_modes;
 }
 
-static enum drm_mode_status vbox_mode_valid(struct drm_connector *connector,
-  struct drm_display_mode *mode)
-{
-   return MODE_OK;
-}
-
 static void vbox_connector_destroy(struct drm_connector *connector)
 {
drm_connector_unregister(connector);
@@ -862,9 +844,7 @@ static int vbox_fill_modes(struct drm_connector *connector, 
u32 max_x,
 }
 
 static const struct drm_connector_helper_funcs vbox_connector_helper_funcs = {
-   .mode_valid = vbox_mode_valid,
.get_modes = vbox_get_modes,
-   .best_encoder = vbox_best_single_encoder,
 };
 
 static const struct drm_connector_funcs vbox_connector_funcs = {
-- 
2.19.0

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


[PATCH 09/15] staging: vboxvideo: Atomic phase 3: Switch last bits over to atomic

2018-09-26 Thread Hans de Goede
Now that the state objects are wired up, we can:

1) Move to the final atomic handlers
2) Wire up atomic set_config helper
3) Switch to drm_mode_config_helper_suspend/resume for suspend/resume
4) Enable atomic modesetting ioctl

This is all done in one commit because doing this piecemeal leads to
an intermediate state which triggers WARN_ONs in the atomic code because
e.g. plane->fb is still being set.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/TODO|  1 -
 drivers/staging/vboxvideo/vbox_drv.c  | 40 +--
 drivers/staging/vboxvideo/vbox_mode.c | 35 +++
 3 files changed, 17 insertions(+), 59 deletions(-)

diff --git a/drivers/staging/vboxvideo/TODO b/drivers/staging/vboxvideo/TODO
index 468eea856ca6..2e0f99c3f10c 100644
--- a/drivers/staging/vboxvideo/TODO
+++ b/drivers/staging/vboxvideo/TODO
@@ -1,5 +1,4 @@
 TODO:
--Move the driver over to the atomic API
 -Get a full review from the drm-maintainers on dri-devel done on this driver
 -Extend this TODO with the results of that review
 
diff --git a/drivers/staging/vboxvideo/vbox_drv.c 
b/drivers/staging/vboxvideo/vbox_drv.c
index c6a53b0ad66c..c3e14107da0d 100644
--- a/drivers/staging/vboxvideo/vbox_drv.c
+++ b/drivers/staging/vboxvideo/vbox_drv.c
@@ -132,35 +132,16 @@ static void vbox_pci_remove(struct pci_dev *pdev)
drm_dev_put(>ddev);
 }
 
-static int vbox_drm_freeze(struct vbox_private *vbox)
-{
-   drm_kms_helper_poll_disable(>ddev);
-
-   pci_save_state(vbox->ddev.pdev);
-
-   drm_fb_helper_set_suspend_unlocked(>fbdev->helper, true);
-
-   return 0;
-}
-
-static int vbox_drm_thaw(struct vbox_private *vbox)
-{
-   drm_mode_config_reset(>ddev);
-   drm_helper_resume_force_mode(>ddev);
-   drm_fb_helper_set_suspend_unlocked(>fbdev->helper, false);
-
-   return 0;
-}
-
 static int vbox_pm_suspend(struct device *dev)
 {
struct vbox_private *vbox = dev_get_drvdata(dev);
int error;
 
-   error = vbox_drm_freeze(vbox);
+   error = drm_mode_config_helper_suspend(>ddev);
if (error)
return error;
 
+   pci_save_state(vbox->ddev.pdev);
pci_disable_device(vbox->ddev.pdev);
pci_set_power_state(vbox->ddev.pdev, PCI_D3hot);
 
@@ -170,39 +151,32 @@ static int vbox_pm_suspend(struct device *dev)
 static int vbox_pm_resume(struct device *dev)
 {
struct vbox_private *vbox = dev_get_drvdata(dev);
-   int ret;
 
if (pci_enable_device(vbox->ddev.pdev))
return -EIO;
 
-   ret = vbox_drm_thaw(vbox);
-   if (ret)
-   return ret;
-
-   drm_kms_helper_poll_enable(>ddev);
-
-   return 0;
+   return drm_mode_config_helper_resume(>ddev);
 }
 
 static int vbox_pm_freeze(struct device *dev)
 {
struct vbox_private *vbox = dev_get_drvdata(dev);
 
-   return vbox_drm_freeze(vbox);
+   return drm_mode_config_helper_suspend(>ddev);
 }
 
 static int vbox_pm_thaw(struct device *dev)
 {
struct vbox_private *vbox = dev_get_drvdata(dev);
 
-   return vbox_drm_thaw(vbox);
+   return drm_mode_config_helper_resume(>ddev);
 }
 
 static int vbox_pm_poweroff(struct device *dev)
 {
struct vbox_private *vbox = dev_get_drvdata(dev);
 
-   return vbox_drm_freeze(vbox);
+   return drm_mode_config_helper_suspend(>ddev);
 }
 
 static const struct dev_pm_ops vbox_pm_ops = {
@@ -280,7 +254,7 @@ static void vbox_master_drop(struct drm_device *dev, struct 
drm_file *file_priv)
 static struct drm_driver driver = {
.driver_features =
DRIVER_MODESET | DRIVER_GEM | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
-   DRIVER_PRIME,
+   DRIVER_PRIME | DRIVER_ATOMIC,
.dev_priv_size = 0,
 
.lastclose = vbox_driver_lastclose,
diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index 54e6aac784f7..69a1e6c163b9 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -148,13 +148,6 @@ static void vbox_crtc_dpms(struct drm_crtc *crtc, int mode)
mutex_unlock(>hw_mutex);
 }
 
-static bool vbox_crtc_mode_fixup(struct drm_crtc *crtc,
-const struct drm_display_mode *mode,
-struct drm_display_mode *adjusted_mode)
-{
-   return true;
-}
-
 /*
  * 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
@@ -260,19 +253,10 @@ static void vbox_crtc_disable(struct drm_crtc *crtc)
 {
 }
 
-static void vbox_crtc_prepare(struct drm_crtc *crtc)
-{
-}
-
 static void vbox_crtc_commit(struct drm_crtc *crtc)
 {
 }
 
-static void vbox_crtc_mode_set_nofb(struct drm_crtc *crtc)
-{
-   /* We always set the mode when we set the fb/base */
-}
-
 static void vbox_crtc_atomic_flush(struct drm_crtc *crtc,
   struct drm_crtc_state 

[PATCH 08/15] staging: vboxvideo: Atomic phase 2: Stop using plane->fb and crtc->*

2018-09-26 Thread Hans de Goede
Once we are fully atomic plane->fb will always be NULL and we also
should not access things like crtc->enabled and crt->[hw]mode.

Now that we've wired up the state object handlers, we always have a
plane_state and crtc_state so change the code referencing plane->fb and
crtc->* to use the data from the plane_state and crt_state instead.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_drv.h  |  1 -
 drivers/staging/vboxvideo/vbox_main.c | 16 +++-
 drivers/staging/vboxvideo/vbox_mode.c | 15 +++
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_drv.h 
b/drivers/staging/vboxvideo/vbox_drv.h
index 7fc668ff4465..fccb3851d6a3 100644
--- a/drivers/staging/vboxvideo/vbox_drv.h
+++ b/drivers/staging/vboxvideo/vbox_drv.h
@@ -199,7 +199,6 @@ int vbox_mode_init(struct vbox_private *vbox);
 void vbox_mode_fini(struct vbox_private *vbox);
 
 #define DRM_MODE_FB_CMD drm_mode_fb_cmd2
-#define CRTC_FB(crtc) ((crtc)->primary->fb)
 
 void vbox_enable_accel(struct vbox_private *vbox);
 void vbox_disable_accel(struct vbox_private *vbox);
diff --git a/drivers/staging/vboxvideo/vbox_main.c 
b/drivers/staging/vboxvideo/vbox_main.c
index 95100c5976e4..3b82d483ab51 100644
--- a/drivers/staging/vboxvideo/vbox_main.c
+++ b/drivers/staging/vboxvideo/vbox_main.c
@@ -102,24 +102,30 @@ void vbox_framebuffer_dirty_rectangles(struct 
drm_framebuffer *fb,
   unsigned int num_rects)
 {
struct vbox_private *vbox = fb->dev->dev_private;
+   struct drm_display_mode *mode;
struct drm_crtc *crtc;
+   int crtc_x, crtc_y;
unsigned int i;
 
mutex_lock(>hw_mutex);
list_for_each_entry(crtc, >dev->mode_config.crtc_list, head) {
-   if (CRTC_FB(crtc) != fb)
+   if (crtc->primary->state->fb != fb)
continue;
 
+   mode = >state->mode;
+   crtc_x = crtc->primary->state->src_x >> 16;
+   crtc_y = crtc->primary->state->src_y >> 16;
+
vbox_enable_accel(vbox);
 
for (i = 0; i < num_rects; ++i) {
struct vbva_cmd_hdr cmd_hdr;
unsigned int crtc_id = to_vbox_crtc(crtc)->crtc_id;
 
-   if ((rects[i].x1 > crtc->x + crtc->hwmode.hdisplay) ||
-   (rects[i].y1 > crtc->y + crtc->hwmode.vdisplay) ||
-   (rects[i].x2 < crtc->x) ||
-   (rects[i].y2 < crtc->y))
+   if ((rects[i].x1 > crtc_x + mode->hdisplay) ||
+   (rects[i].y1 > crtc_y + mode->vdisplay) ||
+   (rects[i].x2 < crtc_x) ||
+   (rects[i].y2 < crtc_y))
continue;
 
cmd_hdr.x = (s16)rects[i].x1;
diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index cb897b672752..54e6aac784f7 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -46,6 +46,7 @@
  */
 static void vbox_do_modeset(struct drm_crtc *crtc)
 {
+   struct drm_framebuffer *fb = crtc->primary->state->fb;
struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
struct vbox_private *vbox;
int width, height, bpp, pitch;
@@ -55,8 +56,8 @@ static void vbox_do_modeset(struct drm_crtc *crtc)
vbox = crtc->dev->dev_private;
width = vbox_crtc->width ? vbox_crtc->width : 640;
height = vbox_crtc->height ? vbox_crtc->height : 480;
-   bpp = crtc->enabled ? CRTC_FB(crtc)->format->cpp[0] * 8 : 32;
-   pitch = crtc->enabled ? CRTC_FB(crtc)->pitches[0] : width * bpp / 8;
+   bpp = fb ? fb->format->cpp[0] * 8 : 32;
+   pitch = fb ? fb->pitches[0] : width * bpp / 8;
x_offset = vbox->single_framebuffer ? vbox_crtc->x : vbox_crtc->x_hint;
y_offset = vbox->single_framebuffer ? vbox_crtc->y : vbox_crtc->y_hint;
 
@@ -66,14 +67,13 @@ static void vbox_do_modeset(struct drm_crtc *crtc)
 * VirtualBox, certain parts of the code still assume that the first
 * screen is programmed this way, so try to fake it.
 */
-   if (vbox_crtc->crtc_id == 0 && crtc->enabled &&
+   if (vbox_crtc->crtc_id == 0 && fb &&
vbox_crtc->fb_offset / pitch < 0x - 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);
-   vbox_write_ioport(VBE_DISPI_INDEX_BPP,
- CRTC_FB(crtc)->format->cpp[0] * 8);
+   vbox_write_ioport(VBE_DISPI_INDEX_BPP, bpp);
vbox_write_ioport(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED);
vbox_write_ioport(
 

[PATCH 12/15] staging: vboxvideo: Replace crtc_helper enable/disable functions

2018-09-26 Thread Hans de Goede
Replace vbox_crtc_commit and vbox_crtc_disable with
vbox_crtc_atomic_[en|dis]able which are the preferred callbacks for
these for atomic drivers.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_mode.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index 49ff9c4a6302..72fc6614179a 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -229,11 +229,13 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc 
*crtc,
mutex_unlock(>hw_mutex);
 }
 
-static void vbox_crtc_disable(struct drm_crtc *crtc)
+static void vbox_crtc_atomic_enable(struct drm_crtc *crtc,
+   struct drm_crtc_state *old_crtc_state)
 {
 }
 
-static void vbox_crtc_commit(struct drm_crtc *crtc)
+static void vbox_crtc_atomic_disable(struct drm_crtc *crtc,
+struct drm_crtc_state *old_crtc_state)
 {
 }
 
@@ -254,8 +256,8 @@ static void vbox_crtc_atomic_flush(struct drm_crtc *crtc,
 }
 
 static const struct drm_crtc_helper_funcs vbox_crtc_helper_funcs = {
-   .disable = vbox_crtc_disable,
-   .commit = vbox_crtc_commit,
+   .atomic_enable = vbox_crtc_atomic_enable,
+   .atomic_disable = vbox_crtc_atomic_disable,
.atomic_flush = vbox_crtc_atomic_flush,
 };
 
-- 
2.19.0

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


[PATCH 11/15] staging: vboxvideo: Fix DPMS support after atomic conversion

2018-09-26 Thread Hans de Goede
Atomic modesetting does not use the traditional dpms call backs, instead
we should check crtc_state->active.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_drv.h  |  1 -
 drivers/staging/vboxvideo/vbox_mode.c | 28 ++-
 2 files changed, 2 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_drv.h 
b/drivers/staging/vboxvideo/vbox_drv.h
index fccb3851d6a3..9cc20c182df1 100644
--- a/drivers/staging/vboxvideo/vbox_drv.h
+++ b/drivers/staging/vboxvideo/vbox_drv.h
@@ -139,7 +139,6 @@ struct vbox_connector {
 
 struct vbox_crtc {
struct drm_crtc base;
-   bool blanked;
bool disconnected;
unsigned int crtc_id;
u32 fb_offset;
diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index c4ec3fa49782..49ff9c4a6302 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -84,14 +84,13 @@ static void vbox_do_modeset(struct drm_crtc *crtc)
}
 
flags = VBVA_SCREEN_F_ACTIVE;
-   flags |= (fb && !vbox_crtc->blanked) ? 0 : VBVA_SCREEN_F_BLANK;
+   flags |= (fb && crtc->state->active) ? 0 : VBVA_SCREEN_F_BLANK;
flags |= vbox_crtc->disconnected ? VBVA_SCREEN_F_DISABLED : 0;
hgsmi_process_display_info(vbox->guest_pool, vbox_crtc->crtc_id,
   x_offset, y_offset,
   vbox_crtc->x * bpp / 8 +
vbox_crtc->y * pitch,
-  pitch, width, height,
-  vbox_crtc->blanked ? 0 : bpp, flags);
+  pitch, width, height, bpp, flags);
 }
 
 static int vbox_set_view(struct drm_crtc *crtc)
@@ -128,27 +127,6 @@ static int vbox_set_view(struct drm_crtc *crtc)
return 0;
 }
 
-static void vbox_crtc_dpms(struct drm_crtc *crtc, int mode)
-{
-   struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
-   struct vbox_private *vbox = crtc->dev->dev_private;
-
-   switch (mode) {
-   case DRM_MODE_DPMS_ON:
-   vbox_crtc->blanked = false;
-   break;
-   case DRM_MODE_DPMS_STANDBY:
-   case DRM_MODE_DPMS_SUSPEND:
-   case DRM_MODE_DPMS_OFF:
-   vbox_crtc->blanked = true;
-   break;
-   }
-
-   mutex_lock(>hw_mutex);
-   vbox_do_modeset(crtc);
-   mutex_unlock(>hw_mutex);
-}
-
 /*
  * 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
@@ -276,7 +254,6 @@ static void vbox_crtc_atomic_flush(struct drm_crtc *crtc,
 }
 
 static const struct drm_crtc_helper_funcs vbox_crtc_helper_funcs = {
-   .dpms = vbox_crtc_dpms,
.disable = vbox_crtc_disable,
.commit = vbox_crtc_commit,
.atomic_flush = vbox_crtc_atomic_flush,
@@ -861,7 +838,6 @@ static const struct drm_connector_helper_funcs 
vbox_connector_helper_funcs = {
 };
 
 static const struct drm_connector_funcs vbox_connector_funcs = {
-   .dpms = drm_helper_connector_dpms,
.detect = vbox_connector_detect,
.fill_modes = vbox_fill_modes,
.destroy = vbox_connector_destroy,
-- 
2.19.0

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


[PATCH 10/15] staging: vboxvideo: Restore page-flip support

2018-09-26 Thread Hans de Goede
Restore page-flip support now that the atomic conversion is complete.

Since the mode parameter to vbox_crtc_set_base_and_mode() now never
is NULL call drm_atomic_crtc_needs_modeset() to check if we need to
check for input-mapping changes, to avoid doing unnecesarry work on
a flip. And hookup the drm_atomic_helper_page_flip helper to implement
the page_flip callback.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_mode.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index 69a1e6c163b9..c4ec3fa49782 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -32,6 +32,7 @@
  *  Hans de Goede 
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -217,6 +218,7 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc 
*crtc,
struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(fb)->obj);
struct vbox_private *vbox = crtc->dev->dev_private;
struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
+   bool needs_modeset = drm_atomic_crtc_needs_modeset(crtc->state);
 
mutex_lock(>hw_mutex);
 
@@ -227,7 +229,7 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc 
*crtc,
vbox_crtc->fb_offset = vbox_bo_gpu_offset(bo);
 
/* vbox_do_modeset() checks vbox->single_framebuffer so update it now */
-   if (mode && vbox_set_up_input_mapping(vbox)) {
+   if (needs_modeset && vbox_set_up_input_mapping(vbox)) {
struct drm_crtc *crtci;
 
list_for_each_entry(crtci, >ddev.mode_config.crtc_list,
@@ -241,7 +243,7 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc 
*crtc,
vbox_set_view(crtc);
vbox_do_modeset(crtc);
 
-   if (mode)
+   if (needs_modeset)
hgsmi_update_input_mapping(vbox->guest_pool, 0, 0,
   vbox->input_mapping_width,
   vbox->input_mapping_height);
@@ -288,6 +290,7 @@ static void vbox_crtc_destroy(struct drm_crtc *crtc)
 
 static const struct drm_crtc_funcs vbox_crtc_funcs = {
.set_config = drm_atomic_helper_set_config,
+   .page_flip = drm_atomic_helper_page_flip,
/* .gamma_set = vbox_crtc_gamma_set, */
.destroy = vbox_crtc_destroy,
.reset = drm_atomic_helper_crtc_reset,
-- 
2.19.0

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


[PATCH 01/15] staging: vboxvideo: Cleanup vbox_set_up_input_mapping()

2018-09-26 Thread Hans de Goede
This cleanups 2 things:

1) The first time we loop over the crtc-s, to compare framebuffers, fb1 may
get set to NULL by the fb1 = CRTC_FB(crtci); statement and then we call
to_vbox_framebuffer() on it. The result of this call is only used for
an address comparison, so we don't end up dereferencing the bad pointer,
but still it is better to not do this.

2) Since we already figure out the first crtc with a fb in the first loop
and store that in fb1, there is no need to loop over the crtc-s again just
to find the first crtc with a fb again.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_mode.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index bef99664d030..4f5d28aeca95 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -169,7 +169,7 @@ static bool vbox_set_up_input_mapping(struct vbox_private 
*vbox)
 {
struct drm_crtc *crtci;
struct drm_connector *connectori;
-   struct drm_framebuffer *fb1 = NULL;
+   struct drm_framebuffer *fb, *fb1 = NULL;
bool single_framebuffer = true;
bool old_single_framebuffer = vbox->single_framebuffer;
u16 width = 0, height = 0;
@@ -180,25 +180,25 @@ static bool vbox_set_up_input_mapping(struct vbox_private 
*vbox)
 * Same fall-back if this is the fbdev frame-buffer.
 */
list_for_each_entry(crtci, >ddev.mode_config.crtc_list, head) {
+   fb = CRTC_FB(crtci);
+   if (!fb)
+   continue;
+
if (!fb1) {
-   fb1 = CRTC_FB(crtci);
+   fb1 = fb;
if (to_vbox_framebuffer(fb1) == >fbdev->afb)
break;
-   } else if (CRTC_FB(crtci) && fb1 != CRTC_FB(crtci)) {
+   } else if (fb != fb1) {
single_framebuffer = false;
}
}
+   if (!fb1)
+   return false;
+
if (single_framebuffer) {
vbox->single_framebuffer = true;
-   list_for_each_entry(crtci, >ddev.mode_config.crtc_list,
-   head) {
-   if (!CRTC_FB(crtci))
-   continue;
-
-   vbox->input_mapping_width = CRTC_FB(crtci)->width;
-   vbox->input_mapping_height = CRTC_FB(crtci)->height;
-   break;
-   }
+   vbox->input_mapping_width = fb1->width;
+   vbox->input_mapping_height = fb1->height;
return old_single_framebuffer != vbox->single_framebuffer;
}
/* Otherwise calculate the total span of all screens. */
-- 
2.19.0

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


[PATCH 07/15] staging: vboxvideo: Atomic phase 2: Wire up state object handlers

2018-09-26 Thread Hans de Goede
Wire up state object handlers for the crtc-s and the planes, call
drm_mode_config_reset() after creating all the crtc-s and encoders and
remove the legacy drm_helper_disable_unused_functions() call.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_fb.c   |  3 ---
 drivers/staging/vboxvideo/vbox_mode.c | 15 ++-
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_fb.c 
b/drivers/staging/vboxvideo/vbox_fb.c
index b8b42f9aafae..8a9d56762659 100644
--- a/drivers/staging/vboxvideo/vbox_fb.c
+++ b/drivers/staging/vboxvideo/vbox_fb.c
@@ -216,9 +216,6 @@ int vbox_fbdev_init(struct vbox_private *vbox)
if (ret)
goto err_fini;
 
-   /* disable all the possible outputs/crtcs before entering KMS mode */
-   drm_helper_disable_unused_functions(dev);
-
ret = drm_fb_helper_initial_config(>helper, 32);
if (ret)
goto err_fini;
diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index e560e36e7953..cb897b672752 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -301,10 +301,6 @@ static const struct drm_crtc_helper_funcs 
vbox_crtc_helper_funcs = {
.atomic_flush = vbox_crtc_atomic_flush,
 };
 
-static void vbox_crtc_reset(struct drm_crtc *crtc)
-{
-}
-
 static void vbox_crtc_destroy(struct drm_crtc *crtc)
 {
drm_crtc_cleanup(crtc);
@@ -312,10 +308,12 @@ static void vbox_crtc_destroy(struct drm_crtc *crtc)
 }
 
 static const struct drm_crtc_funcs vbox_crtc_funcs = {
-   .reset = vbox_crtc_reset,
.set_config = drm_crtc_helper_set_config,
/* .gamma_set = vbox_crtc_gamma_set, */
.destroy = vbox_crtc_destroy,
+   .reset = drm_atomic_helper_crtc_reset,
+   .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
+   .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
 };
 
 static int vbox_primary_atomic_check(struct drm_plane *plane,
@@ -527,6 +525,9 @@ static const struct drm_plane_funcs vbox_cursor_plane_funcs 
= {
.update_plane   = drm_plane_helper_update,
.disable_plane  = drm_plane_helper_disable,
.destroy= drm_primary_helper_destroy,
+   .reset  = drm_atomic_helper_plane_reset,
+   .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
+   .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
 };
 
 static const uint32_t vbox_primary_plane_formats[] = {
@@ -546,6 +547,9 @@ static const struct drm_plane_funcs 
vbox_primary_plane_funcs = {
.update_plane   = drm_plane_helper_update,
.disable_plane  = drm_primary_helper_disable,
.destroy= drm_primary_helper_destroy,
+   .reset  = drm_atomic_helper_plane_reset,
+   .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
+   .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
 };
 
 static struct drm_plane *vbox_create_plane(struct vbox_private *vbox,
@@ -982,6 +986,7 @@ int vbox_mode_init(struct vbox_private *vbox)
goto err_drm_mode_cleanup;
}
 
+   drm_mode_config_reset(dev);
return 0;
 
 err_drm_mode_cleanup:
-- 
2.19.0

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


[PATCH 06/15] staging: vboxvideo: Atomic phase 1: Use drm_plane_helpers for primary plane

2018-09-26 Thread Hans de Goede
Use drm_plane_helpers for the primary plane and replace our custom
mode_set callback with drm_helper_crtc_mode_set.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_mode.c | 116 --
 1 file changed, 90 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index 75e112d33cf0..e560e36e7953 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -257,50 +257,48 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc 
*crtc,
mutex_unlock(>hw_mutex);
 }
 
-static int vbox_crtc_mode_set(struct drm_crtc *crtc,
- struct drm_display_mode *mode,
- struct drm_display_mode *adjusted_mode,
- int x, int y, struct drm_framebuffer *old_fb)
+static void vbox_crtc_disable(struct drm_crtc *crtc)
 {
-   struct drm_framebuffer *new_fb = CRTC_FB(crtc);
-   struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(new_fb)->obj);
-   int ret;
-
-   ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM);
-   if (ret) {
-   DRM_WARN("Error %d pinning new fb, out of video mem?\n", ret);
-   return ret;
-   }
-
-   vbox_crtc_set_base_and_mode(crtc, new_fb, mode, x, y);
-
-   if (old_fb) {
-   bo = gem_to_vbox_bo(to_vbox_framebuffer(old_fb)->obj);
-   vbox_bo_unpin(bo);
-   }
+}
 
-   return 0;
+static void vbox_crtc_prepare(struct drm_crtc *crtc)
+{
 }
 
-static void vbox_crtc_disable(struct drm_crtc *crtc)
+static void vbox_crtc_commit(struct drm_crtc *crtc)
 {
 }
 
-static void vbox_crtc_prepare(struct drm_crtc *crtc)
+static void vbox_crtc_mode_set_nofb(struct drm_crtc *crtc)
 {
+   /* We always set the mode when we set the fb/base */
 }
 
-static void vbox_crtc_commit(struct drm_crtc *crtc)
+static void vbox_crtc_atomic_flush(struct drm_crtc *crtc,
+  struct drm_crtc_state *old_crtc_state)
 {
+   struct drm_pending_vblank_event *event;
+   unsigned long flags;
+
+   if (crtc->state && crtc->state->event) {
+   event = crtc->state->event;
+   crtc->state->event = NULL;
+
+   spin_lock_irqsave(>dev->event_lock, flags);
+   drm_crtc_send_vblank_event(crtc, event);
+   spin_unlock_irqrestore(>dev->event_lock, flags);
+   }
 }
 
 static const struct drm_crtc_helper_funcs vbox_crtc_helper_funcs = {
.dpms = vbox_crtc_dpms,
.mode_fixup = vbox_crtc_mode_fixup,
-   .mode_set = vbox_crtc_mode_set,
+   .mode_set = drm_helper_crtc_mode_set,
+   .mode_set_nofb = vbox_crtc_mode_set_nofb,
.disable = vbox_crtc_disable,
.prepare = vbox_crtc_prepare,
.commit = vbox_crtc_commit,
+   .atomic_flush = vbox_crtc_atomic_flush,
 };
 
 static void vbox_crtc_reset(struct drm_crtc *crtc)
@@ -320,6 +318,63 @@ static const struct drm_crtc_funcs vbox_crtc_funcs = {
.destroy = vbox_crtc_destroy,
 };
 
+static int vbox_primary_atomic_check(struct drm_plane *plane,
+struct drm_plane_state *new_state)
+{
+   return 0;
+}
+
+static void vbox_primary_atomic_update(struct drm_plane *plane,
+  struct drm_plane_state *old_state)
+{
+   struct drm_crtc *crtc = plane->state->crtc;
+   struct drm_framebuffer *fb = plane->state->fb;
+
+   vbox_crtc_set_base_and_mode(crtc, fb, >state->mode,
+   plane->state->src_x >> 16,
+   plane->state->src_y >> 16);
+}
+
+void vbox_primary_atomic_disable(struct drm_plane *plane,
+struct drm_plane_state *old_state)
+{
+   struct drm_crtc *crtc = old_state->crtc;
+
+   /* vbox_do_modeset checks plane->state->fb and will disable if NULL */
+   vbox_crtc_set_base_and_mode(crtc, old_state->fb, >state->mode,
+   old_state->src_x >> 16,
+   old_state->src_y >> 16);
+}
+
+static int vbox_primary_prepare_fb(struct drm_plane *plane,
+  struct drm_plane_state *new_state)
+{
+   struct vbox_bo *bo;
+   int ret;
+
+   if (!new_state->fb)
+   return 0;
+
+   bo = gem_to_vbox_bo(to_vbox_framebuffer(new_state->fb)->obj);
+   ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM);
+   if (ret)
+   DRM_WARN("Error %d pinning new fb, out of video mem?\n", ret);
+
+   return ret;
+}
+
+static void vbox_primary_cleanup_fb(struct drm_plane *plane,
+   struct drm_plane_state *old_state)
+{
+   struct vbox_bo *bo;
+
+   if (!old_state->fb)
+   return;
+
+   bo = gem_to_vbox_bo(to_vbox_framebuffer(old_state->fb)->obj);
+   vbox_bo_unpin(bo);
+}
+
 static int vbox_cursor_atomic_check(struct 

[PATCH 05/15] staging: vboxvideo: Atomic phase 1: convert cursor to universal plane

2018-09-26 Thread Hans de Goede
In preparation for atomic conversion, let's use the transitional atomic
helpers drm_plane_helper_update/disable.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_drv.h  |   5 -
 drivers/staging/vboxvideo/vbox_mode.c | 386 +-
 2 files changed, 186 insertions(+), 205 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_drv.h 
b/drivers/staging/vboxvideo/vbox_drv.h
index 34c4d7fc6c8e..7fc668ff4465 100644
--- a/drivers/staging/vboxvideo/vbox_drv.h
+++ b/drivers/staging/vboxvideo/vbox_drv.h
@@ -116,11 +116,6 @@ struct vbox_private {
 * encompassing all screen ones or is the fbdev console active?
 */
bool single_framebuffer;
-   u32 cursor_width;
-   u32 cursor_height;
-   u32 cursor_hot_x;
-   u32 cursor_hot_y;
-   size_t cursor_data_size;
u8 cursor_data[CURSOR_DATA_SIZE];
 };
 
diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index e85b27f95def..75e112d33cf0 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -34,16 +34,12 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "vbox_drv.h"
 #include "vboxvideo.h"
 #include "hgsmi_channels.h"
 
-static int vbox_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
-   u32 handle, u32 width, u32 height,
-   s32 hot_x, s32 hot_y);
-static int vbox_cursor_move(struct drm_crtc *crtc, int x, int y);
-
 /**
  * Set a graphics mode.  Poke any required values into registers, do an HGSMI
  * mode set and tell the host we support advanced graphics functions.
@@ -318,14 +314,166 @@ static void vbox_crtc_destroy(struct drm_crtc *crtc)
 }
 
 static const struct drm_crtc_funcs vbox_crtc_funcs = {
-   .cursor_move = vbox_cursor_move,
-   .cursor_set2 = vbox_cursor_set2,
.reset = vbox_crtc_reset,
.set_config = drm_crtc_helper_set_config,
/* .gamma_set = vbox_crtc_gamma_set, */
.destroy = vbox_crtc_destroy,
 };
 
+static int vbox_cursor_atomic_check(struct drm_plane *plane,
+   struct drm_plane_state *new_state)
+{
+   u32 width = new_state->crtc_w;
+   u32 height = new_state->crtc_h;
+
+   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;
+}
+
+/**
+ * Copy the ARGB image and generate the mask, which is needed in case the host
+ * does not support ARGB cursors.  The mask is a 1BPP 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] > 0xf000)
+   dst[i * line_size + j / 8] |= (0x80 >> (j % 8));
+}
+
+static void vbox_cursor_atomic_update(struct drm_plane *plane,
+ struct drm_plane_state *old_state)
+{
+   struct vbox_private *vbox =
+   container_of(plane->dev, struct vbox_private, ddev);
+   struct vbox_crtc *vbox_crtc = to_vbox_crtc(plane->state->crtc);
+   struct drm_framebuffer *fb = plane->state->fb;
+   struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(fb)->obj);
+   u32 width = plane->state->crtc_w;
+   u32 height = plane->state->crtc_h;
+   size_t data_size, mask_size;
+   u32 flags;
+   u8 *src;
+
+   /*
+* 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(>hw_mutex);
+
+   vbox_crtc->cursor_enabled = true;
+
+   /* pinning is done in prepare/cleanup framebuffer */
+   src = vbox_bo_kmap(bo);
+   if (IS_ERR(src)) {
+   DRM_WARN("Could not kmap cursor bo, skipping update\n");
+   return;
+   }
+
+   /*
+* 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);
+   vbox_bo_kunmap(bo);
+
+   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, 

[PATCH 02/15] staging: vboxvideo: Remove empty encoder_helper_funcs

2018-09-26 Thread Hans de Goede
All the encoder_helper_funcs are optional, and even setting the
drm_encoder_helper_funcs vtable itself is optional and may be left out
when not using any of the helper funcs, so lets drop all of this.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_mode.c | 34 ---
 1 file changed, 34 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index 4f5d28aeca95..babb02a1ebf2 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -466,39 +466,6 @@ static const struct drm_encoder_funcs vbox_enc_funcs = {
.destroy = vbox_encoder_destroy,
 };
 
-static void vbox_encoder_dpms(struct drm_encoder *encoder, int mode)
-{
-}
-
-static bool vbox_mode_fixup(struct drm_encoder *encoder,
-   const struct drm_display_mode *mode,
-   struct drm_display_mode *adjusted_mode)
-{
-   return true;
-}
-
-static void vbox_encoder_mode_set(struct drm_encoder *encoder,
- struct drm_display_mode *mode,
- struct drm_display_mode *adjusted_mode)
-{
-}
-
-static void vbox_encoder_prepare(struct drm_encoder *encoder)
-{
-}
-
-static void vbox_encoder_commit(struct drm_encoder *encoder)
-{
-}
-
-static const struct drm_encoder_helper_funcs vbox_enc_helper_funcs = {
-   .dpms = vbox_encoder_dpms,
-   .mode_fixup = vbox_mode_fixup,
-   .prepare = vbox_encoder_prepare,
-   .commit = vbox_encoder_commit,
-   .mode_set = vbox_encoder_mode_set,
-};
-
 static struct drm_encoder *vbox_encoder_init(struct drm_device *dev,
 unsigned int i)
 {
@@ -510,7 +477,6 @@ static struct drm_encoder *vbox_encoder_init(struct 
drm_device *dev,
 
drm_encoder_init(dev, _encoder->base, _enc_funcs,
 DRM_MODE_ENCODER_DAC, NULL);
-   drm_encoder_helper_add(_encoder->base, _enc_helper_funcs);
 
vbox_encoder->base.possible_crtcs = 1 << i;
return _encoder->base;
-- 
2.19.0

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


[PATCH 04/15] staging: vboxvideo: Cache mode width, height and crtc panning in vbox_crtc

2018-09-26 Thread Hans de Goede
When setting a mode we not only pass the mode to the hypervisor,
but also information on how to map / translate input coordinates
for the emulated USB tablet.  This input-mapping may change when
the mode on *another* crtc changes.

This means that sometimes we must do a modeset on other crtc-s then
the one being changed to update the input-mapping. Including crtc-s
which may be disabled inside the guest (shown as a black window
on the host unless closed by the user).

With atomic modesetting the mode-info of disabled crtcs gets zeroed
yet we need it when updating the input-map to avoid resizing the
window as a side effect of a mode_set on another crtc.

This commit adds caching of the mode info into out private vbox_crtc
struct so that we always have the info at hand when we need it.

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_drv.h  | 20 +++
 drivers/staging/vboxvideo/vbox_mode.c | 28 +++
 2 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_drv.h 
b/drivers/staging/vboxvideo/vbox_drv.h
index 6c52cbd9e91e..34c4d7fc6c8e 100644
--- a/drivers/staging/vboxvideo/vbox_drv.h
+++ b/drivers/staging/vboxvideo/vbox_drv.h
@@ -151,6 +151,26 @@ struct vbox_crtc {
bool cursor_enabled;
u32 x_hint;
u32 y_hint;
+   /*
+* When setting a mode we not only pass the mode to the hypervisor,
+* but also information on how to map / translate input coordinates
+* for the emulated USB tablet.  This input-mapping may change when
+* the mode on *another* crtc changes.
+*
+* This means that sometimes we must do a modeset on other crtc-s then
+* the one being changed to update the input-mapping. Including crtc-s
+* which may be disabled inside the guest (shown as a black window
+* on the host unless closed by the user).
+*
+* With atomic modesetting the mode-info of disabled crtcs gets zeroed
+* yet we need it when updating the input-map to avoid resizing the
+* window as a side effect of a mode_set on another crtc. Therefor we
+* cache the info of the last mode below.
+*/
+   u32 width;
+   u32 height;
+   u32 x;
+   u32 y;
 };
 
 struct vbox_encoder {
diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index adb6bcf989d1..e85b27f95def 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -48,8 +48,7 @@ static int vbox_cursor_move(struct drm_crtc *crtc, int x, int 
y);
  * Set a graphics mode.  Poke any required values into registers, do an HGSMI
  * mode set and tell the host we support advanced graphics functions.
  */
-static void vbox_do_modeset(struct drm_crtc *crtc,
-   const struct drm_display_mode *mode)
+static void vbox_do_modeset(struct drm_crtc *crtc)
 {
struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
struct vbox_private *vbox;
@@ -58,12 +57,12 @@ static void vbox_do_modeset(struct drm_crtc *crtc,
s32 x_offset, y_offset;
 
vbox = crtc->dev->dev_private;
-   width = mode->hdisplay ? mode->hdisplay : 640;
-   height = mode->vdisplay ? mode->vdisplay : 480;
+   width = vbox_crtc->width ? vbox_crtc->width : 640;
+   height = vbox_crtc->height ? vbox_crtc->height : 480;
bpp = crtc->enabled ? CRTC_FB(crtc)->format->cpp[0] * 8 : 32;
pitch = crtc->enabled ? CRTC_FB(crtc)->pitches[0] : width * bpp / 8;
-   x_offset = vbox->single_framebuffer ? crtc->x : vbox_crtc->x_hint;
-   y_offset = vbox->single_framebuffer ? crtc->y : vbox_crtc->y_hint;
+   x_offset = vbox->single_framebuffer ? vbox_crtc->x : vbox_crtc->x_hint;
+   y_offset = vbox->single_framebuffer ? vbox_crtc->y : vbox_crtc->y_hint;
 
/*
 * This is the old way of setting graphics modes.  It assumed one screen
@@ -82,9 +81,9 @@ static void vbox_do_modeset(struct drm_crtc *crtc,
vbox_write_ioport(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED);
vbox_write_ioport(
VBE_DISPI_INDEX_X_OFFSET,
-   vbox_crtc->fb_offset % pitch / bpp * 8 + crtc->x);
+   vbox_crtc->fb_offset % pitch / bpp * 8 + vbox_crtc->x);
vbox_write_ioport(VBE_DISPI_INDEX_Y_OFFSET,
- vbox_crtc->fb_offset / pitch + crtc->y);
+ vbox_crtc->fb_offset / pitch + vbox_crtc->y);
}
 
flags = VBVA_SCREEN_F_ACTIVE;
@@ -93,7 +92,8 @@ static void vbox_do_modeset(struct drm_crtc *crtc,
flags |= vbox_crtc->disconnected ? VBVA_SCREEN_F_DISABLED : 0;
hgsmi_process_display_info(vbox->guest_pool, vbox_crtc->crtc_id,
   x_offset, y_offset,
-  crtc->x * bpp / 8 + crtc->y * pitch,
+ 

[PATCH 03/15] staging: vboxvideo: Temporarily remove page_flip support

2018-09-26 Thread Hans de Goede
drm_mode_page_flip_ioctl() cannot deal with the in between phase of
the transitioning to atomic modeset support. Once we start using
drm_helper_crtc_mode_set(), we start setting plane->state on the primary
plane. But we are not fully atomic yet so then set both plane-state->fb
and plane->fb.

If both plane-state->fb and plane->fb are set drm_mode_page_flip_ioctl()
gets confused and stops calling drm_framebuffer_get() on the new fb while
still calling drm_framebuffer_put() on the old fb.

The current page_flip implementation expects drm_mode_page_flip_ioctl()
to take care of both and once we switch to drm_atomic_helper_page_flip()
that will expect neither to be done, taking care of both itself.

So for the transition we need to remove page_flip support and then after
the transition is complete and we set DRIVER_ATOMIC in our driver_features,
we can start using drm_atomic_helper_page_flip().

Signed-off-by: Hans de Goede 
---
 drivers/staging/vboxvideo/vbox_mode.c | 35 ---
 1 file changed, 35 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_mode.c 
b/drivers/staging/vboxvideo/vbox_mode.c
index babb02a1ebf2..adb6bcf989d1 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -282,40 +282,6 @@ static int vbox_crtc_mode_set(struct drm_crtc *crtc,
return 0;
 }
 
-static int vbox_crtc_page_flip(struct drm_crtc *crtc,
-  struct drm_framebuffer *fb,
-  struct drm_pending_vblank_event *event,
-  uint32_t page_flip_flags,
-  struct drm_modeset_acquire_ctx *ctx)
-{
-   struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(fb)->obj);
-   struct drm_framebuffer *old_fb = CRTC_FB(crtc);
-   unsigned long flags;
-   int rc;
-
-   rc = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM);
-   if (rc) {
-   DRM_WARN("Error %d pinning new fb, out of video mem?\n", rc);
-   return rc;
-   }
-
-   vbox_crtc_set_base_and_mode(crtc, fb, NULL, 0, 0);
-
-   if (old_fb) {
-   bo = gem_to_vbox_bo(to_vbox_framebuffer(old_fb)->obj);
-   vbox_bo_unpin(bo);
-   }
-
-   spin_lock_irqsave(>dev->event_lock, flags);
-
-   if (event)
-   drm_crtc_send_vblank_event(crtc, event);
-
-   spin_unlock_irqrestore(>dev->event_lock, flags);
-
-   return 0;
-}
-
 static void vbox_crtc_disable(struct drm_crtc *crtc)
 {
 }
@@ -353,7 +319,6 @@ static const struct drm_crtc_funcs vbox_crtc_funcs = {
.reset = vbox_crtc_reset,
.set_config = drm_crtc_helper_set_config,
/* .gamma_set = vbox_crtc_gamma_set, */
-   .page_flip = vbox_crtc_page_flip,
.destroy = vbox_crtc_destroy,
 };
 
-- 
2.19.0

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


[PATCH 01/15] staging: vboxvideo: Convert to atomic modesetting API

2018-09-26 Thread Hans de Goede
Hi All,

This series converts the vboxvideo driver to the modesetting API, once this
is merged I will submit a patch to move the driver out of staging and into
drivers/gpu/drm.

This series consists of 3 parts:

1) More cleanups / prep work for atomic conversion
2) The actual atomic conversion, this is modelled after the atomic conversion
   of the qxl driver done by Gabriel Krisman Bertazi. Gabriel if you are
   reading this, thank you for providing a roadmap how to go about this.
3) Restore some features which were lost by the atomic conversion +
   more cleanups

Regards,

Hans

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


[PATCH] drm/imx: fix build failure without CONFIG_DRM_FBDEV_EMULATION

2018-09-26 Thread Arnd Bergmann
The variable is declared in an #ifdef section, but the user is
now unconditional, which leads to a build failure:

drivers/gpu/drm/imx/imx-drm-core.c: In function 'imx_drm_bind':
drivers/gpu/drm/imx/imx-drm-core.c:264:6: error: 'legacyfb_depth' undeclared 
(first use in this function); did you mean 'lockdep_depth'?

Remove the remaining #ifdef as well.

Fixes: f53705fd9803 ("drm/imx: Use drm_fbdev_generic_setup()")
Signed-off-by: Arnd Bergmann 
---
 drivers/gpu/drm/imx/imx-drm-core.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/gpu/drm/imx/imx-drm-core.c 
b/drivers/gpu/drm/imx/imx-drm-core.c
index a70f3131a377..0e6942f21a4e 100644
--- a/drivers/gpu/drm/imx/imx-drm-core.c
+++ b/drivers/gpu/drm/imx/imx-drm-core.c
@@ -35,10 +35,8 @@
 
 #define MAX_CRTC   4
 
-#if IS_ENABLED(CONFIG_DRM_FBDEV_EMULATION)
 static int legacyfb_depth = 16;
 module_param(legacyfb_depth, int, 0444);
-#endif
 
 DEFINE_DRM_GEM_CMA_FOPS(imx_drm_driver_fops);
 
-- 
2.18.0

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


[Bug 106940] Black screen on KMS with 4.18.0-rc1 with Kaveri+Topaz, amdgpu, dc=1

2018-09-26 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=106940

--- Comment #42 from SET  ---
(In reply to Andrey Arapov from comment #41)
> Not sure if that helps, but could you try reverting this commit?
> https://github.com/torvalds/linux/commit/
> e03fd3f300f6184c1264186a4c815e93bf658abb
> 

Reverted that commit, still a black screen with 4.19-rc4 in the above context.
Using radeon for a useful laptop.

-- 
You are receiving this mail because:
You are the assignee for the bug.___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH] drm/ttm, drm/vmwgfx: Move the lock- and object functionality to the vmwgfx driver

2018-09-26 Thread Thomas Hellstrom
No other driver is using this functionality so move it out of TTM and
into the vmwgfx driver. Update includes and remove exports.
Also annotate to remove false static analyzer lock balance warnings.

Cc: Christian König 
Signed-off-by: Thomas Hellstrom 
---
 drivers/gpu/drm/ttm/Makefile  |  4 ++--
 drivers/gpu/drm/vmwgfx/Makefile   |  3 ++-
 drivers/gpu/drm/{ttm => vmwgfx}/ttm_lock.c| 13 ++--
 .../ttm => drivers/gpu/drm/vmwgfx}/ttm_lock.h |  0
 drivers/gpu/drm/{ttm => vmwgfx}/ttm_object.c  | 20 +++
 .../gpu/drm/vmwgfx}/ttm_object.h  |  3 +--
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c|  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h   |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_prime.c |  2 +-
 10 files changed, 15 insertions(+), 38 deletions(-)
 rename drivers/gpu/drm/{ttm => vmwgfx}/ttm_lock.c (95%)
 rename {include/drm/ttm => drivers/gpu/drm/vmwgfx}/ttm_lock.h (100%)
 rename drivers/gpu/drm/{ttm => vmwgfx}/ttm_object.c (96%)
 rename {include/drm/ttm => drivers/gpu/drm/vmwgfx}/ttm_object.h (99%)

diff --git a/drivers/gpu/drm/ttm/Makefile b/drivers/gpu/drm/ttm/Makefile
index a60e560804e0..01fc670ce7a2 100644
--- a/drivers/gpu/drm/ttm/Makefile
+++ b/drivers/gpu/drm/ttm/Makefile
@@ -4,8 +4,8 @@
 
 ttm-y := ttm_memory.o ttm_tt.o ttm_bo.o \
ttm_bo_util.o ttm_bo_vm.o ttm_module.o \
-   ttm_object.o ttm_lock.o ttm_execbuf_util.o ttm_page_alloc.o \
-   ttm_bo_manager.o ttm_page_alloc_dma.o
+   ttm_execbuf_util.o ttm_page_alloc.o ttm_bo_manager.o \
+   ttm_page_alloc_dma.o
 ttm-$(CONFIG_AGP) += ttm_agp_backend.o
 
 obj-$(CONFIG_DRM_TTM) += ttm.o
diff --git a/drivers/gpu/drm/vmwgfx/Makefile b/drivers/gpu/drm/vmwgfx/Makefile
index 09b2aa08363e..22fdc07e03ad 100644
--- a/drivers/gpu/drm/vmwgfx/Makefile
+++ b/drivers/gpu/drm/vmwgfx/Makefile
@@ -7,6 +7,7 @@ vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o 
vmwgfx_drv.o \
vmwgfx_surface.o vmwgfx_prime.o vmwgfx_mob.o vmwgfx_shader.o \
vmwgfx_cmdbuf_res.o vmwgfx_cmdbuf.o vmwgfx_stdu.o \
vmwgfx_cotable.o vmwgfx_so.o vmwgfx_binding.o vmwgfx_msg.o \
-   vmwgfx_simple_resource.o vmwgfx_va.o vmwgfx_blit.o
+   vmwgfx_simple_resource.o vmwgfx_va.o vmwgfx_blit.o \
+   ttm_object.o ttm_lock.o
 
 obj-$(CONFIG_DRM_VMWGFX) := vmwgfx.o
diff --git a/drivers/gpu/drm/ttm/ttm_lock.c b/drivers/gpu/drm/vmwgfx/ttm_lock.c
similarity index 95%
rename from drivers/gpu/drm/ttm/ttm_lock.c
rename to drivers/gpu/drm/vmwgfx/ttm_lock.c
index 20694b8a01ca..0d59f5a19e17 100644
--- a/drivers/gpu/drm/ttm/ttm_lock.c
+++ b/drivers/gpu/drm/vmwgfx/ttm_lock.c
@@ -29,13 +29,13 @@
  * Authors: Thomas Hellstrom 
  */
 
-#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
+#include "ttm_lock.h"
+#include "ttm_object.h"
 
 #define TTM_WRITE_LOCK_PENDING(1 << 0)
 #define TTM_VT_LOCK_PENDING   (1 << 1)
@@ -52,7 +52,6 @@ void ttm_lock_init(struct ttm_lock *lock)
lock->kill_takers = false;
lock->signal = SIGKILL;
 }
-EXPORT_SYMBOL(ttm_lock_init);
 
 void ttm_read_unlock(struct ttm_lock *lock)
 {
@@ -61,7 +60,6 @@ void ttm_read_unlock(struct ttm_lock *lock)
wake_up_all(>queue);
spin_unlock(>lock);
 }
-EXPORT_SYMBOL(ttm_read_unlock);
 
 static bool __ttm_read_lock(struct ttm_lock *lock)
 {
@@ -92,7 +90,6 @@ int ttm_read_lock(struct ttm_lock *lock, bool interruptible)
wait_event(lock->queue, __ttm_read_lock(lock));
return ret;
 }
-EXPORT_SYMBOL(ttm_read_lock);
 
 static bool __ttm_read_trylock(struct ttm_lock *lock, bool *locked)
 {
@@ -144,7 +141,6 @@ void ttm_write_unlock(struct ttm_lock *lock)
wake_up_all(>queue);
spin_unlock(>lock);
 }
-EXPORT_SYMBOL(ttm_write_unlock);
 
 static bool __ttm_write_lock(struct ttm_lock *lock)
 {
@@ -185,7 +181,6 @@ int ttm_write_lock(struct ttm_lock *lock, bool 
interruptible)
 
return ret;
 }
-EXPORT_SYMBOL(ttm_write_lock);
 
 static int __ttm_vt_unlock(struct ttm_lock *lock)
 {
@@ -262,14 +257,12 @@ int ttm_vt_lock(struct ttm_lock *lock,
 
return ret;
 }
-EXPORT_SYMBOL(ttm_vt_lock);
 
 int ttm_vt_unlock(struct ttm_lock *lock)
 {
return ttm_ref_object_base_unref(lock->vt_holder,
 lock->base.hash.key, TTM_REF_USAGE);
 }
-EXPORT_SYMBOL(ttm_vt_unlock);
 
 void ttm_suspend_unlock(struct ttm_lock *lock)
 {
@@ -278,7 +271,6 @@ void ttm_suspend_unlock(struct ttm_lock *lock)
wake_up_all(>queue);
spin_unlock(>lock);
 }
-EXPORT_SYMBOL(ttm_suspend_unlock);
 
 static bool __ttm_suspend_lock(struct ttm_lock *lock)
 {
@@ -300,4 +292,3 @@ void ttm_suspend_lock(struct ttm_lock *lock)
 {
wait_event(lock->queue, __ttm_suspend_lock(lock));
 }
-EXPORT_SYMBOL(ttm_suspend_lock);
diff --git a/include/drm/ttm/ttm_lock.h b/drivers/gpu/drm/vmwgfx/ttm_lock.h
similarity index 100%
rename from 

[radeon-alex:drm-next-4.20-wip 53/66] drivers/gpu//drm/etnaviv/etnaviv_sched.c:108:35: error: 'struct drm_sched_job' has no member named 'work_tdr'

2018-09-26 Thread kbuild test robot
tree:   git://people.freedesktop.org/~agd5f/linux.git drm-next-4.20-wip
head:   1ab9810fb590adf8f5a26271cc639ccfb98cb9eb
commit: d730e7e9d36a4a0e7e7c9efbf5c735bf0098358d [53/66] drm/scheduler: remove 
timeout work_struct from drm_sched_job
config: arm-allmodconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout d730e7e9d36a4a0e7e7c9efbf5c735bf0098358d
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=arm 

All errors (new ones prefixed by >>):

   drivers/gpu//drm/etnaviv/etnaviv_sched.c: In function 
'etnaviv_sched_timedout_job':
>> drivers/gpu//drm/etnaviv/etnaviv_sched.c:108:35: error: 'struct 
>> drm_sched_job' has no member named 'work_tdr'
  schedule_delayed_work(_job->work_tdr,
  ^~

vim +108 drivers/gpu//drm/etnaviv/etnaviv_sched.c

e93b6dee Lucas Stach 2017-12-04   84  
e93b6dee Lucas Stach 2017-12-04   85  static void 
etnaviv_sched_timedout_job(struct drm_sched_job *sched_job)
e93b6dee Lucas Stach 2017-12-04   86  {
6d7a20c0 Lucas Stach 2017-12-06   87struct etnaviv_gem_submit *submit = 
to_etnaviv_submit(sched_job);
6d7a20c0 Lucas Stach 2017-12-06   88struct etnaviv_gpu *gpu = submit->gpu;
2c83a726 Lucas Stach 2018-06-27   89u32 dma_addr;
2c83a726 Lucas Stach 2018-06-27   90int change;
2c83a726 Lucas Stach 2018-06-27   91  
2c83a726 Lucas Stach 2018-06-27   92/*
2c83a726 Lucas Stach 2018-06-27   93 * If the GPU managed to complete this 
jobs fence, the timout is
2c83a726 Lucas Stach 2018-06-27   94 * spurious. Bail out.
2c83a726 Lucas Stach 2018-06-27   95 */
2c83a726 Lucas Stach 2018-06-27   96if (fence_completed(gpu, 
submit->out_fence->seqno))
2c83a726 Lucas Stach 2018-06-27   97return;
2c83a726 Lucas Stach 2018-06-27   98  
2c83a726 Lucas Stach 2018-06-27   99/*
2c83a726 Lucas Stach 2018-06-27  100 * If the GPU is still making forward 
progress on the front-end (which
2c83a726 Lucas Stach 2018-06-27  101 * should never loop) we shift out the 
timeout to give it a chance to
2c83a726 Lucas Stach 2018-06-27  102 * finish the job.
2c83a726 Lucas Stach 2018-06-27  103 */
2c83a726 Lucas Stach 2018-06-27  104dma_addr = gpu_read(gpu, 
VIVS_FE_DMA_ADDRESS);
2c83a726 Lucas Stach 2018-06-27  105change = dma_addr - 
gpu->hangcheck_dma_addr;
2c83a726 Lucas Stach 2018-06-27  106if (change < 0 || change > 16) {
2c83a726 Lucas Stach 2018-06-27  107gpu->hangcheck_dma_addr = 
dma_addr;
2c83a726 Lucas Stach 2018-06-27 @108
schedule_delayed_work(_job->work_tdr,
2c83a726 Lucas Stach 2018-06-27  109  
sched_job->sched->timeout);
2c83a726 Lucas Stach 2018-06-27  110return;
2c83a726 Lucas Stach 2018-06-27  111}
6d7a20c0 Lucas Stach 2017-12-06  112  
6d7a20c0 Lucas Stach 2017-12-06  113/* block scheduler */
6d7a20c0 Lucas Stach 2017-12-06  114kthread_park(gpu->sched.thread);
6d7a20c0 Lucas Stach 2017-12-06  115drm_sched_hw_job_reset(>sched, 
sched_job);
6d7a20c0 Lucas Stach 2017-12-06  116  
6d7a20c0 Lucas Stach 2017-12-06  117/* get the GPU back into the init state 
*/
6d7a20c0 Lucas Stach 2017-12-06  118etnaviv_core_dump(gpu);
6d7a20c0 Lucas Stach 2017-12-06  119etnaviv_gpu_recover_hang(gpu);
6d7a20c0 Lucas Stach 2017-12-06  120  
6d7a20c0 Lucas Stach 2017-12-06  121/* restart scheduler after GPU is 
usable again */
6d7a20c0 Lucas Stach 2017-12-06  122drm_sched_job_recovery(>sched);
6d7a20c0 Lucas Stach 2017-12-06  123kthread_unpark(gpu->sched.thread);
e93b6dee Lucas Stach 2017-12-04  124  }
e93b6dee Lucas Stach 2017-12-04  125  

:: The code at line 108 was first introduced by commit
:: 2c83a726d6fbb5d130d8f2edd82a258adb675ac3 drm/etnaviv: bring back 
progress check in job timeout handler

:: TO: Lucas Stach 
:: CC: Lucas Stach 

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] pci: Add a few new IDs for Intel GPU "spurious interrupt" quirk

2018-09-26 Thread Bjorn Helgaas
[+cc Intel DRM maintainers, etc]

On Wed, Sep 26, 2018 at 08:14:01AM -0700, Bin Meng wrote:
> Add more PCI IDs to the Intel GPU "spurious interrupt" quirk table,
> which are known to break.

Do you have a reference for this?  Any public bug reports, bugzilla,
Intel spec reference or errata?  "Which are known to break" is pretty
vague.

> See commit f67fd55fa96f ("PCI: Add quirk for still enabled interrupts
> on Intel Sandy Bridge GPUs"), and commit 7c82126a94e6 ("PCI: Add new
> ID for Intel GPU "spurious interrupt" quirk") for some history.
> 
> Based on current findings, it is highly possible that all Intel
> 1st/2nd/3rd generation Core processors' IGD has such quirk.

Can you include a reference to these "current findings"?  I assume you
have bug reports that include the device IDs you're adding?  If not,
how did you build this list of new IDs?

The function comment added by f67fd55fa96f ("PCI: Add quirk for still
enabled interrupts on Intel Sandy Bridge GPUs") suggests that this is
actually a BIOS issue, not a hardware erratum, i.e., I don't see
anything there that suggests a hardware defect.

But there must be a hole somewhere -- the kernel can't be expected to
disable interrupts in device-specific ways when there's no driver
loaded.  Maybe it's simply a BIOS defect or maybe there's some
interrupt or _PRT-related setup we're missing.

> Signed-off-by: Bin Meng 
> Cc:  # v3.4+
> ---
> 
>  drivers/pci/quirks.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
> index 6bc27b7..c0673a7 100644
> --- a/drivers/pci/quirks.c
> +++ b/drivers/pci/quirks.c
> @@ -3190,7 +3190,11 @@ static void disable_igfx_irq(struct pci_dev *dev)
>  
>   pci_iounmap(dev, regs);
>  }
> +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0042, disable_igfx_irq);
> +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0046, disable_igfx_irq);
> +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x004a, disable_igfx_irq);
>  DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0102, disable_igfx_irq);
> +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0106, disable_igfx_irq);
>  DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x010a, disable_igfx_irq);
>  DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0152, disable_igfx_irq);
>  
> -- 
> 2.7.4
> 
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] video/fbdev/stifb: Fix spelling mistake in fall-through annotation

2018-09-26 Thread Bartlomiej Zolnierkiewicz

On 09/03/2018 10:07 PM, Gustavo A. R. Silva wrote:
> Replace "fall though" with a proper "fall through" annotation.
> 
> This fix is part of the ongoing efforts to enabling
> -Wimplicit-fallthrough
> 
> Addresses-Coverity-ID: 402013 ("Missing break in switch")
> Signed-off-by: Gustavo A. R. Silva 

Patch queued for 4.19, thanks.

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R Institute Poland
Samsung Electronics
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH -next 10/18] drm/ttm: Make the object handles idr-generated

2018-09-26 Thread Christian König

Am 26.09.2018 um 18:46 schrieb Thomas Hellstrom:

On 09/26/2018 06:36 PM, Christian König wrote:

Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:

Instead of generating user-space object handles based on a, possibly
processed, hash of the kernel address of the object, use idr to 
generate

and lookup those handles. This might improve somewhat on security since
we loose all connections to the object's kernel address. Also idr is
designed to do just this.

As a todo-item, since user-space handles are now generated in sequence,
we can probably use a much simpler hash function to hash them.

Cc: Christian König 
Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
Reviewed-by: Deepak Rawat 


Well NAK. I already proposed completely removing ttm_lock.c and 
ttm_object.c because vmwgfx is the only user of it.


Please move that functionality into the driver since it isn't TTM 
specific after all.


Christian. 
Actually, I thought that was already done in -next, but it wasn't. I 
vaguely recall seeing some patches doing that, but I might remember 
incorrectly or they were never pushed.


I asked for your opinion, but never got a response :)


I'll move those files over.


Great thanks,
Christian.



/Thomas



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


Re: [PATCH -next 12/18] drm/ttm: Export ttm_bo_reference_unless_doomed()

2018-09-26 Thread Christian König

Am 26.09.2018 um 18:43 schrieb Thomas Hellstrom:

On 09/26/2018 06:35 PM, Christian König wrote:

Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:
Export ttm_bo_reference_unless_doomed() to be used when looking up 
buffer

objects that are removed from the lookup structure in the destructor.

Cc: Christian König 
Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
  drivers/gpu/drm/ttm/ttm_bo_vm.c |  3 +--
  include/drm/ttm/ttm_bo_api.h    | 18 ++
  2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c 
b/drivers/gpu/drm/ttm/ttm_bo_vm.c

index 6fe91c1b692d..ec4b09366213 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -409,8 +409,7 @@ static struct ttm_buffer_object 
*ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
  node = drm_vma_offset_lookup_locked(>vma_manager, 
offset, pages);

  if (likely(node)) {
  bo = container_of(node, struct ttm_buffer_object, vma_node);
-    if (!kref_get_unless_zero(>kref))
-    bo = NULL;
+    bo = ttm_bo_reference_unless_doomed(bo);
  }
drm_vma_offset_unlock_lookup(>vma_manager);
diff --git a/include/drm/ttm/ttm_bo_api.h 
b/include/drm/ttm/ttm_bo_api.h

index 8c19470785e2..b6bf6b086576 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)
  return bo;
  }
  +/**
+ * ttm_bo_reference_unless_doomed - reference a struct 
ttm_buffer_object unless

+ * its refcount has already reached zero.
+ * @bo: The buffer object.
+ *
+ * Used to reference a TTM buffer object in lookups where the 
object is removed
+ * from the lookup structure during the destructor and for RCU 
lookups.

+ *
+ * Returns: @bo if the referencing was successful, NULL otherwise.
+ */
+static inline __must_check struct ttm_buffer_object *
+ttm_bo_reference_unless_doomed(struct ttm_buffer_object *bo)


Please name that ttm_bo_get_rcu(), we are in the process of renaming 
ttm_bo_reference into ttm_bo_get as well.


Could we call it ttm_bo_get_unless_doomed() or 
ttm_bo_get_unless_zero() to be even more consistent. (It's not 
restricted to rcu as the VM usage shows). Also "doomed" is more 
relevant for objects, "zero" is more relevant for the refcount itself?


ttm_bo_get_unless_zero() is fine with me as well.

Christian.



/Thomas





Christian.


+{
+    if (!kref_get_unless_zero(>kref))
+    return NULL;
+    return bo;
+}
+
  /**
   * ttm_bo_wait - wait for buffer idle.
   *






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


Re: [PATCH -next 10/18] drm/ttm: Make the object handles idr-generated

2018-09-26 Thread Thomas Hellstrom

On 09/26/2018 06:36 PM, Christian König wrote:

Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:

Instead of generating user-space object handles based on a, possibly
processed, hash of the kernel address of the object, use idr to generate
and lookup those handles. This might improve somewhat on security since
we loose all connections to the object's kernel address. Also idr is
designed to do just this.

As a todo-item, since user-space handles are now generated in sequence,
we can probably use a much simpler hash function to hash them.

Cc: Christian König 
Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
Reviewed-by: Deepak Rawat 


Well NAK. I already proposed completely removing ttm_lock.c and 
ttm_object.c because vmwgfx is the only user of it.


Please move that functionality into the driver since it isn't TTM 
specific after all.


Christian. 
Actually, I thought that was already done in -next, but it wasn't. I 
vaguely recall seeing some patches doing that, but I might remember 
incorrectly or they were never pushed.


I'll move those files over.

/Thomas

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


Re: [PATCH -next 12/18] drm/ttm: Export ttm_bo_reference_unless_doomed()

2018-09-26 Thread Thomas Hellstrom

On 09/26/2018 06:35 PM, Christian König wrote:

Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:
Export ttm_bo_reference_unless_doomed() to be used when looking up 
buffer

objects that are removed from the lookup structure in the destructor.

Cc: Christian König 
Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
  drivers/gpu/drm/ttm/ttm_bo_vm.c |  3 +--
  include/drm/ttm/ttm_bo_api.h    | 18 ++
  2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c 
b/drivers/gpu/drm/ttm/ttm_bo_vm.c

index 6fe91c1b692d..ec4b09366213 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -409,8 +409,7 @@ static struct ttm_buffer_object 
*ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
  node = drm_vma_offset_lookup_locked(>vma_manager, offset, 
pages);

  if (likely(node)) {
  bo = container_of(node, struct ttm_buffer_object, vma_node);
-    if (!kref_get_unless_zero(>kref))
-    bo = NULL;
+    bo = ttm_bo_reference_unless_doomed(bo);
  }
    drm_vma_offset_unlock_lookup(>vma_manager);
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 8c19470785e2..b6bf6b086576 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)
  return bo;
  }
  +/**
+ * ttm_bo_reference_unless_doomed - reference a struct 
ttm_buffer_object unless

+ * its refcount has already reached zero.
+ * @bo: The buffer object.
+ *
+ * Used to reference a TTM buffer object in lookups where the object 
is removed

+ * from the lookup structure during the destructor and for RCU lookups.
+ *
+ * Returns: @bo if the referencing was successful, NULL otherwise.
+ */
+static inline __must_check struct ttm_buffer_object *
+ttm_bo_reference_unless_doomed(struct ttm_buffer_object *bo)


Please name that ttm_bo_get_rcu(), we are in the process of renaming 
ttm_bo_reference into ttm_bo_get as well.


Could we call it ttm_bo_get_unless_doomed() or ttm_bo_get_unless_zero() 
to be even more consistent. (It's not restricted to rcu as the VM usage 
shows). Also "doomed" is more relevant for objects, "zero" is more 
relevant for the refcount itself?


/Thomas





Christian.


+{
+    if (!kref_get_unless_zero(>kref))
+    return NULL;
+    return bo;
+}
+
  /**
   * ttm_bo_wait - wait for buffer idle.
   *




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


Re: [PATCH] DRM: VBLANK: provide valid timestamp for EVENT_FLIP

2018-09-26 Thread Ville Syrjälä
On Wed, Sep 26, 2018 at 05:25:35PM +0300, Eugeniy Paltsev wrote:
> If driver/HW doesn't support vblank functionality (for example
> UDL driver, ARCPGU driver, ...) we always have vblank->time == 0.
> In result we always provide zero timestamp for
> DRM_EVENT_FLIP_COMPLETE. This breaks userspace apps (for example
> weston) which relies on timestamp value.
> 
> Setup time to provide valid timestamp for DRM_EVENT_FLIP_COMPLETE
> event.
> 
> Cc: sta...@vger.kernel.org
> Signed-off-by: Eugeniy Paltsev 
> ---
>  drivers/gpu/drm/drm_vblank.c | 9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index 28cdcf76b6f9..0d19aca48782 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -911,6 +911,15 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
>  
>   if (dev->num_crtcs > 0) {

If those drivers don't support vblank stuff why are they calling
drm_vblank_init() w/ num_crtcs > 0? If they didn't they'd take the
else branch which already does what you want.

>   seq = drm_vblank_count_and_time(dev, pipe, );
> +
> + /*
> +  * If driver/HW doesn't support vblank functionality we
> +  * always have vblank->time == 0. Setup time to provide valid
> +  * timestamp for DRM_EVENT_FLIP_COMPLETE event.
> +  */
> + if (!now && e->event.base.type == DRM_EVENT_FLIP_COMPLETE)
> + now = ktime_get();
> +
>   } else {
>   seq = 0;
>  
> -- 
> 2.14.4
> 
> ___
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Ville Syrjälä
Intel
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH -next 10/18] drm/ttm: Make the object handles idr-generated

2018-09-26 Thread Christian König

Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:

Instead of generating user-space object handles based on a, possibly
processed, hash of the kernel address of the object, use idr to generate
and lookup those handles. This might improve somewhat on security since
we loose all connections to the object's kernel address. Also idr is
designed to do just this.

As a todo-item, since user-space handles are now generated in sequence,
we can probably use a much simpler hash function to hash them.

Cc: Christian König 
Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
Reviewed-by: Deepak Rawat 


Well NAK. I already proposed completely removing ttm_lock.c and 
ttm_object.c because vmwgfx is the only user of it.


Please move that functionality into the driver since it isn't TTM 
specific after all.


Christian.


---
  drivers/gpu/drm/ttm/ttm_lock.c  |  2 +-
  drivers/gpu/drm/ttm/ttm_object.c| 42 -
  drivers/gpu/drm/vmwgfx/vmwgfx_bo.c  |  7 +++--
  drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 12 +++
  drivers/gpu/drm/vmwgfx/vmwgfx_fence.c   |  7 +++--
  drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h   |  5 +++
  drivers/gpu/drm/vmwgfx/vmwgfx_shader.c  | 16 +++---
  drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c |  5 +--
  drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 18 +--
  include/drm/ttm/ttm_object.h| 13 ++--
  10 files changed, 65 insertions(+), 62 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_lock.c b/drivers/gpu/drm/ttm/ttm_lock.c
index 20694b8a01ca..214cf73241d9 100644
--- a/drivers/gpu/drm/ttm/ttm_lock.c
+++ b/drivers/gpu/drm/ttm/ttm_lock.c
@@ -267,7 +267,7 @@ EXPORT_SYMBOL(ttm_vt_lock);
  int ttm_vt_unlock(struct ttm_lock *lock)
  {
return ttm_ref_object_base_unref(lock->vt_holder,
-lock->base.hash.key, TTM_REF_USAGE);
+lock->base.handle, TTM_REF_USAGE);
  }
  EXPORT_SYMBOL(ttm_vt_unlock);
  
diff --git a/drivers/gpu/drm/ttm/ttm_object.c b/drivers/gpu/drm/ttm/ttm_object.c

index 74f1b1eb1f8e..0782c6280d9b 100644
--- a/drivers/gpu/drm/ttm/ttm_object.c
+++ b/drivers/gpu/drm/ttm/ttm_object.c
@@ -95,6 +95,7 @@ struct ttm_object_device {
struct dma_buf_ops ops;
void (*dmabuf_release)(struct dma_buf *dma_buf);
size_t dma_buf_size;
+   struct idr idr;
  };
  
  /**

@@ -172,14 +173,15 @@ int ttm_base_object_init(struct ttm_object_file *tfile,
base->ref_obj_release = ref_obj_release;
base->object_type = object_type;
kref_init(>refcount);
+   idr_preload(GFP_KERNEL);
spin_lock(>object_lock);
-   ret = drm_ht_just_insert_please_rcu(>object_hash,
-   >hash,
-   (unsigned long)base, 31, 0, 0);
+   ret = idr_alloc(>idr, base, 0, 0, GFP_NOWAIT);
spin_unlock(>object_lock);
-   if (unlikely(ret != 0))
-   goto out_err0;
+   idr_preload_end();
+   if (ret < 0)
+   return ret;
  
+	base->handle = ret;

ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL, false);
if (unlikely(ret != 0))
goto out_err1;
@@ -189,9 +191,8 @@ int ttm_base_object_init(struct ttm_object_file *tfile,
return 0;
  out_err1:
spin_lock(>object_lock);
-   (void)drm_ht_remove_item_rcu(>object_hash, >hash);
+   idr_remove(>idr, base->handle);
spin_unlock(>object_lock);
-out_err0:
return ret;
  }
  EXPORT_SYMBOL(ttm_base_object_init);
@@ -203,7 +204,7 @@ static void ttm_release_base(struct kref *kref)
struct ttm_object_device *tdev = base->tfile->tdev;
  
  	spin_lock(>object_lock);

-   (void)drm_ht_remove_item_rcu(>object_hash, >hash);
+   idr_remove(>idr, base->handle);
spin_unlock(>object_lock);
  
  	/*

@@ -252,19 +253,13 @@ EXPORT_SYMBOL(ttm_base_object_lookup);
  struct ttm_base_object *
  ttm_base_object_lookup_for_ref(struct ttm_object_device *tdev, uint32_t key)
  {
-   struct ttm_base_object *base = NULL;
-   struct drm_hash_item *hash;
-   struct drm_open_hash *ht = >object_hash;
-   int ret;
+   struct ttm_base_object *base;
  
  	rcu_read_lock();

-   ret = drm_ht_find_item_rcu(ht, key, );
+   base = idr_find(>idr, key);
  
-	if (likely(ret == 0)) {

-   base = drm_hash_entry(hash, struct ttm_base_object, hash);
-   if (!kref_get_unless_zero(>refcount))
-   base = NULL;
-   }
+   if (base && !kref_get_unless_zero(>refcount))
+   base = NULL;
rcu_read_unlock();
  
  	return base;

@@ -289,7 +284,7 @@ bool ttm_ref_object_exists(struct ttm_object_file *tfile,
struct ttm_ref_object *ref;
  
  	rcu_read_lock();

-   if (unlikely(drm_ht_find_item_rcu(ht, base->hash.key, ) != 0))
+   if 

Re: [PATCH -next 12/18] drm/ttm: Export ttm_bo_reference_unless_doomed()

2018-09-26 Thread Christian König

Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:

Export ttm_bo_reference_unless_doomed() to be used when looking up buffer
objects that are removed from the lookup structure in the destructor.

Cc: Christian König 
Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
  drivers/gpu/drm/ttm/ttm_bo_vm.c |  3 +--
  include/drm/ttm/ttm_bo_api.h| 18 ++
  2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 6fe91c1b692d..ec4b09366213 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -409,8 +409,7 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct 
ttm_bo_device *bdev,
node = drm_vma_offset_lookup_locked(>vma_manager, offset, pages);
if (likely(node)) {
bo = container_of(node, struct ttm_buffer_object, vma_node);
-   if (!kref_get_unless_zero(>kref))
-   bo = NULL;
+   bo = ttm_bo_reference_unless_doomed(bo);
}
  
  	drm_vma_offset_unlock_lookup(>vma_manager);

diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 8c19470785e2..b6bf6b086576 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)
return bo;
  }
  
+/**

+ * ttm_bo_reference_unless_doomed - reference a struct ttm_buffer_object unless
+ * its refcount has already reached zero.
+ * @bo: The buffer object.
+ *
+ * Used to reference a TTM buffer object in lookups where the object is removed
+ * from the lookup structure during the destructor and for RCU lookups.
+ *
+ * Returns: @bo if the referencing was successful, NULL otherwise.
+ */
+static inline __must_check struct ttm_buffer_object *
+ttm_bo_reference_unless_doomed(struct ttm_buffer_object *bo)


Please name that ttm_bo_get_rcu(), we are in the process of renaming 
ttm_bo_reference into ttm_bo_get as well.


Christian.


+{
+   if (!kref_get_unless_zero(>kref))
+   return NULL;
+   return bo;
+}
+
  /**
   * ttm_bo_wait - wait for buffer idle.
   *


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


Re: [Freedreno] [PATCH v3 2/3] drm/msm: Replace drm_gem_object_{un/reference} with put, get functions

2018-09-26 Thread Jordan Crouse
On Wed, Sep 26, 2018 at 01:48:58PM +0200, Thomas Zimmermann wrote:
> This patch unifies the naming of DRM functions for reference counting
> of struct drm_gem_object. The resulting code is more aligned with the
> rest of the Linux kernel interfaces.

Reviewed-by: Jordan Crouse 

> Signed-off-by: Thomas Zimmermann 
> ---
>  drivers/gpu/drm/msm/adreno/a5xx_debugfs.c | 4 ++--
>  drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 2 +-
>  drivers/gpu/drm/msm/adreno/a5xx_power.c   | 2 +-
>  drivers/gpu/drm/msm/adreno/a5xx_preempt.c | 2 +-
>  drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 2 +-
>  drivers/gpu/drm/msm/msm_gem_submit.c  | 4 ++--
>  6 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c 
> b/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c
> index 059ec7d394d0..d2127b1c4ece 100644
> --- a/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c
> +++ b/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c
> @@ -132,14 +132,14 @@ reset_set(void *data, u64 val)
>   if (a5xx_gpu->pm4_bo) {
>   if (a5xx_gpu->pm4_iova)
>   msm_gem_put_iova(a5xx_gpu->pm4_bo, gpu->aspace);
> - drm_gem_object_unreference(a5xx_gpu->pm4_bo);
> + drm_gem_object_put(a5xx_gpu->pm4_bo);
>   a5xx_gpu->pm4_bo = NULL;
>   }
>  
>   if (a5xx_gpu->pfp_bo) {
>   if (a5xx_gpu->pfp_iova)
>   msm_gem_put_iova(a5xx_gpu->pfp_bo, gpu->aspace);
> - drm_gem_object_unreference(a5xx_gpu->pfp_bo);
> + drm_gem_object_put(a5xx_gpu->pfp_bo);
>   a5xx_gpu->pfp_bo = NULL;
>   }
>  
> diff --git a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c 
> b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
> index ab1d9308c311..6a6849309b6a 100644
> --- a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
> +++ b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
> @@ -1234,7 +1234,7 @@ static void a5xx_crashdumper_free(struct msm_gpu *gpu,
>   msm_gem_put_iova(dumper->bo, gpu->aspace);
>   msm_gem_put_vaddr(dumper->bo);
>  
> - drm_gem_object_unreference(dumper->bo);
> + drm_gem_object_put(dumper->bo);
>  }
>  
>  static int a5xx_crashdumper_run(struct msm_gpu *gpu,
> diff --git a/drivers/gpu/drm/msm/adreno/a5xx_power.c 
> b/drivers/gpu/drm/msm/adreno/a5xx_power.c
> index e9c0e56dbec0..7a41e1c147e4 100644
> --- a/drivers/gpu/drm/msm/adreno/a5xx_power.c
> +++ b/drivers/gpu/drm/msm/adreno/a5xx_power.c
> @@ -323,7 +323,7 @@ void a5xx_gpmu_ucode_init(struct msm_gpu *gpu)
>   if (a5xx_gpu->gpmu_iova)
>   msm_gem_put_iova(a5xx_gpu->gpmu_bo, gpu->aspace);
>   if (a5xx_gpu->gpmu_bo)
> - drm_gem_object_unreference(a5xx_gpu->gpmu_bo);
> + drm_gem_object_put(a5xx_gpu->gpmu_bo);
>  
>   a5xx_gpu->gpmu_bo = NULL;
>   a5xx_gpu->gpmu_iova = 0;
> diff --git a/drivers/gpu/drm/msm/adreno/a5xx_preempt.c 
> b/drivers/gpu/drm/msm/adreno/a5xx_preempt.c
> index 970c7963ae29..f3c21f827a4d 100644
> --- a/drivers/gpu/drm/msm/adreno/a5xx_preempt.c
> +++ b/drivers/gpu/drm/msm/adreno/a5xx_preempt.c
> @@ -272,7 +272,7 @@ void a5xx_preempt_fini(struct msm_gpu *gpu)
>   if (a5xx_gpu->preempt_iova[i])
>   msm_gem_put_iova(a5xx_gpu->preempt_bo[i], gpu->aspace);
>  
> - drm_gem_object_unreference(a5xx_gpu->preempt_bo[i]);
> + drm_gem_object_put(a5xx_gpu->preempt_bo[i]);
>   a5xx_gpu->preempt_bo[i] = NULL;
>   }
>  }
> diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c 
> b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
> index c629f742a1d1..1a5d7a53752c 100644
> --- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
> +++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
> @@ -744,7 +744,7 @@ static void a6xx_destroy(struct msm_gpu *gpu)
>   if (a6xx_gpu->sqe_bo) {
>   if (a6xx_gpu->sqe_iova)
>   msm_gem_put_iova(a6xx_gpu->sqe_bo, gpu->aspace);
> - drm_gem_object_unreference_unlocked(a6xx_gpu->sqe_bo);
> + drm_gem_object_put_unlocked(a6xx_gpu->sqe_bo);
>   }
>  
>   a6xx_gmu_remove(a6xx_gpu);
> diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c 
> b/drivers/gpu/drm/msm/msm_gem_submit.c
> index 7bd83e0afa97..7a7923e6220d 100644
> --- a/drivers/gpu/drm/msm/msm_gem_submit.c
> +++ b/drivers/gpu/drm/msm/msm_gem_submit.c
> @@ -144,7 +144,7 @@ static int submit_lookup_objects(struct msm_gem_submit 
> *submit,
>   goto out_unlock;
>   }
>  
> - drm_gem_object_reference(obj);
> + drm_gem_object_get(obj);
>  
>   submit->bos[i].obj = msm_obj;
>  
> @@ -396,7 +396,7 @@ static void submit_cleanup(struct msm_gem_submit *submit)
>   struct msm_gem_object *msm_obj = submit->bos[i].obj;
>   submit_unlock_unpin_bo(submit, i, false);
>   list_del_init(_obj->submit_entry);
> - drm_gem_object_unreference(_obj->base);
> + drm_gem_object_put(_obj->base);
>   }
>  
>   

[PATCH -next 14/18] drm/vmwgfx: Look up user buffer objects without taking a reference

2018-09-26 Thread Thomas Hellstrom
Identically to how we look up ttm base objects witout reference, provide
the same functionality to vmw user buffer objects which derive from them.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c  | 41 +
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 12 +++
 2 files changed, 53 insertions(+)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
index d80801d41f69..2defb8b751ae 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
@@ -921,6 +921,47 @@ int vmw_user_bo_lookup(struct ttm_object_file *tfile,
return 0;
 }
 
+/**
+ * vmw_user_bo_noref_lookup - Look up a vmw user buffer object without 
reference
+ * @tfile: The TTM object file the handle is registered with.
+ * @handle: The user buffer object handle.
+ *
+ * This function looks up a struct vmw_user_bo and returns a pointer to the
+ * struct vmw_buffer_object it derives from without refcounting the pointer.
+ * The returned pointer is only valid until vmw_user_bo_noref_release() is
+ * called, and the object pointed to by the returned pointer may be doomed.
+ * Any persistent usage of the object requires a refcount to be taken using
+ * ttm_bo_reference_unless_doomed(). Iff this function returns successfully it
+ * needs to be paired with vmw_user_bo_noref_release() and no sleeping-
+ * or scheduling functions may be called inbetween these function calls.
+ *
+ * Return: A struct vmw_buffer_object pointer if successful or negative
+ * error pointer on failure.
+ */
+struct vmw_buffer_object *
+vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle)
+{
+   struct vmw_user_buffer_object *vmw_user_bo;
+   struct ttm_base_object *base;
+
+   base = ttm_base_object_noref_lookup(tfile, handle);
+   if (!base) {
+   DRM_ERROR("Invalid buffer object handle 0x%08lx.\n",
+ (unsigned long)handle);
+   return ERR_PTR(-ESRCH);
+   }
+
+   if (unlikely(ttm_base_object_type(base) != ttm_buffer_type)) {
+   ttm_base_object_noref_release();
+   DRM_ERROR("Invalid buffer object handle 0x%08lx.\n",
+ (unsigned long)handle);
+   return ERR_PTR(-EINVAL);
+   }
+
+   vmw_user_bo = container_of(base, struct vmw_user_buffer_object,
+  prime.base);
+   return _user_bo->vbo;
+}
 
 /**
  * vmw_user_bo_reference - Open a handle to a vmw user buffer object.
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index dc6a3151fb06..ebb2ae86d900 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -772,6 +772,18 @@ extern void vmw_bo_unmap(struct vmw_buffer_object *vbo);
 extern void vmw_bo_move_notify(struct ttm_buffer_object *bo,
   struct ttm_mem_reg *mem);
 extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo);
+extern struct vmw_buffer_object *
+vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle);
+
+/**
+ * vmw_user_bo_noref_release - release a buffer object pointer looked up
+ * without reference
+ */
+static inline void vmw_user_bo_noref_release(void)
+{
+   ttm_base_object_noref_release();
+}
+
 
 /**
  * Misc Ioctl functionality - vmwgfx_ioctl.c
-- 
2.14.4

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


[PATCH -next 18/18] drm/vmwgfx: Make user resource lookups reference-free during validation

2018-09-26 Thread Thomas Hellstrom
Make the process of looking up a user resource and adding it to the
validation list reference-free unless when it's actually added to the
validation list where a single reference is taken.
This saves two locked atomic operations per command stream buffer object
handle lookup, unless there is a lookup cache hit.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h  |  18 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c  | 267 ---
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c |  35 
 3 files changed, 187 insertions(+), 133 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index ebb2ae86d900..2283bfb97f81 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -337,8 +337,6 @@ struct vmw_ctx_validation_info;
  * @last_query_ctx: Last context that submitted a query
  * @needs_post_query_barrier: Whether a query barrier is needed after
  * command submission
- * @error_resource: Pointer to hold a reference to the resource causing
- * an error
  * @staged_bindings: Cached per-context binding tracker
  * @staged_bindings_inuse: Whether the cached per-context binding tracker
  * is in use
@@ -365,7 +363,6 @@ struct vmw_sw_context{
struct vmw_res_cache_entry res_cache[vmw_res_max];
struct vmw_resource *last_query_ctx;
bool needs_post_query_barrier;
-   struct vmw_resource *error_resource;
struct vmw_ctx_binding_state *staged_bindings;
bool staged_bindings_inuse;
struct list_head staged_cmd_res;
@@ -698,6 +695,12 @@ extern int vmw_user_resource_lookup_handle(
uint32_t handle,
const struct vmw_user_resource_conv *converter,
struct vmw_resource **p_res);
+extern struct vmw_resource *
+vmw_user_resource_noref_lookup_handle(struct vmw_private *dev_priv,
+ struct ttm_object_file *tfile,
+ uint32_t handle,
+ const struct vmw_user_resource_conv *
+ converter);
 extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
  struct drm_file *file_priv);
 extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
@@ -716,6 +719,15 @@ extern int vmw_query_readback_all(struct vmw_buffer_object 
*dx_query_mob);
 extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
 extern void vmw_resource_unbind_list(struct vmw_buffer_object *vbo);
 
+/**
+ * vmw_user_resource_noref_release - release a user resource pointer looked up
+ * without reference
+ */
+static inline void vmw_user_resource_noref_release(void)
+{
+   ttm_base_object_noref_release();
+}
+
 /**
  * Buffer object helper functions - vmwgfx_bo.c
  */
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index dfa2d19274d5..5a6b70ba137a 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -230,16 +230,55 @@ static int vmw_cmd_ctx_first_setup(struct vmw_private 
*dev_priv,
 }
 
 /**
- * vmw_resource_val_add - Add a resource to the software context's
- * resource list if it's not already on it.
+ * vmw_execbuf_res_size - calculate extra size fore the resource validation
+ * node
+ * @dev_priv: Pointer to the device private struct.
+ * @res_type: The resource type.
  *
- * @sw_context: Pointer to the software context.
+ * Guest-backed contexts and DX contexts require extra size to store
+ * execbuf private information in the validation node. Typically the
+ * binding manager associated data structures.
+ *
+ * Returns: The extra size requirement based on resource type.
+ */
+static unsigned int vmw_execbuf_res_size(struct vmw_private *dev_priv,
+enum vmw_res_type res_type)
+{
+   return (res_type == vmw_res_dx_context ||
+   (res_type == vmw_res_context && dev_priv->has_mob)) ?
+   sizeof(struct vmw_ctx_validation_info) : 0;
+}
+
+/**
+ * vmw_execbuf_rcache_update - Update a resource-node cache entry
+ *
+ * @rcache: Pointer to the entry to update.
  * @res: Pointer to the resource.
- * @p_node On successful return points to a valid pointer to a
- * struct vmw_resource_val_node, if non-NULL on entry.
+ * @private: Pointer to the execbuf-private space in the resource
+ * validation node.
  */
-static int vmw_resource_val_add(struct vmw_sw_context *sw_context,
-   struct vmw_resource *res)
+static void vmw_execbuf_rcache_update(struct vmw_res_cache_entry *rcache,
+ struct vmw_resource *res,
+ void *private)
+{
+   rcache->res = res;
+   rcache->private = private;
+   rcache->valid = 1;
+   rcache->valid_handle = 0;
+}
+
+/**
+ * vmw_execbuf_res_noref_val_add - Add 

[PATCH -next 13/18] drm/vmwgfx: Adapt validation code for reference-free lookups

2018-09-26 Thread Thomas Hellstrom
Adapt the validation code so that vmw_validation_add[res|bo] can be called
under an rcu read lock (non-sleeping) and with rcu-only protected resource-
or buffer object pointers.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.c | 61 --
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.h | 19 +-
 2 files changed, 74 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
index 3158fe161b2d..a5204d1a07d7 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
@@ -94,11 +94,12 @@ struct vmw_validation_res_node {
  *
  * Return: Pointer to the allocated memory on success. NULL on failure.
  */
-void *vmw_validation_mem_alloc(struct vmw_validation_context *ctx, size_t size)
+void *vmw_validation_mem_alloc(struct vmw_validation_context *ctx,
+  unsigned int size)
 {
void *addr;
 
-   size = ALIGN(size, sizeof(long));
+   size = vmw_validation_align(size);
if (size > PAGE_SIZE)
return NULL;
 
@@ -262,7 +263,9 @@ int vmw_validation_add_bo(struct vmw_validation_context 
*ctx,
}
}
val_buf = _node->base;
-   val_buf->bo = ttm_bo_reference(>base);
+   val_buf->bo = ttm_bo_reference_unless_doomed(>base);
+   if (!val_buf->bo)
+   return -ESRCH;
val_buf->shared = false;
list_add_tail(_buf->head, >bo_list);
bo_node->as_mob = as_mob;
@@ -313,7 +316,10 @@ int vmw_validation_add_resource(struct 
vmw_validation_context *ctx,
return ret;
}
}
-   node->res = vmw_resource_reference(res);
+   node->res = vmw_resource_reference_unless_doomed(res);
+   if (!node->res)
+   return -ESRCH;
+
node->first_usage = 1;
if (!res->dev_priv->has_mob) {
list_add_tail(>head, >resource_list);
@@ -715,3 +721,50 @@ void vmw_validation_done(struct vmw_validation_context 
*ctx,
mutex_unlock(ctx->res_mutex);
vmw_validation_unref_lists(ctx);
 }
+
+/**
+ * vmw_validation_preload_bo - Preload the validation memory allocator for a
+ * call to vmw_validation_add_bo().
+ * @ctx: Pointer to the validation context.
+ *
+ * Iff this function returns successfully, the next call to
+ * vmw_validation_add_bo() is guaranteed not to sleep. An error is not fatal
+ * but voids the guarantee.
+ *
+ * Returns: Zero if successful, %-EINVAL otherwise.
+ */
+int vmw_validation_preload_bo(struct vmw_validation_context *ctx)
+{
+   unsigned int size = sizeof(struct vmw_validation_bo_node);
+
+   if (!vmw_validation_mem_alloc(ctx, size))
+   return -ENOMEM;
+
+   ctx->mem_size_left += size;
+   return 0;
+}
+
+/**
+ * vmw_validation_preload_res - Preload the validation memory allocator for a
+ * call to vmw_validation_add_res().
+ * @ctx: Pointer to the validation context.
+ * @size: Size of the validation node extra data. See below.
+ *
+ * Iff this function returns successfully, the next call to
+ * vmw_validation_add_res() with the same or smaller @size is guaranteed not to
+ * sleep. An error is not fatal but voids the guarantee.
+ *
+ * Returns: Zero if successful, %-EINVAL otherwise.
+ */
+int vmw_validation_preload_res(struct vmw_validation_context *ctx,
+  unsigned int size)
+{
+   size = vmw_validation_align(sizeof(struct vmw_validation_res_node) +
+   size) +
+   vmw_validation_align(sizeof(struct vmw_validation_bo_node));
+   if (!vmw_validation_mem_alloc(ctx, size))
+   return -ENOMEM;
+
+   ctx->mem_size_left += size;
+   return 0;
+}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
index 0eb2d02d0c0c..b57e3292c386 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
@@ -177,6 +177,18 @@ vmw_validation_context_init(struct vmw_validation_context 
*ctx)
INIT_LIST_HEAD(>bo_list);
 }
 
+/**
+ * vmw_validation_align - Align a validation memory allocation
+ * @val: The size to be aligned
+ *
+ * Returns: @val aligned to the granularity used by the validation memory
+ * allocator.
+ */
+static inline unsigned int vmw_validation_align(unsigned int val)
+{
+   return ALIGN(val, sizeof(long));
+}
+
 int vmw_validation_add_bo(struct vmw_validation_context *ctx,
  struct vmw_buffer_object *vbo,
  bool as_mob, bool cpu_blit);
@@ -207,6 +219,9 @@ void vmw_validation_revert(struct vmw_validation_context 
*ctx);
 void vmw_validation_done(struct vmw_validation_context *ctx,
 struct vmw_fence_obj *fence);
 

[PATCH -next 15/18] drm/vmwgfx: Make buffer object lookups reference-free during validation

2018-09-26 Thread Thomas Hellstrom
Make the process of looking up a buffer object and adding it to the
validation list reference-free unless when it's actually added to the
validation list where a single reference is taken.
This saves two locked atomic operations per command stream buffer object
handle lookup.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 85 -
 1 file changed, 30 insertions(+), 55 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index 641b75110dc6..15e83b39e26d 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -1137,7 +1137,7 @@ static void vmw_query_bo_switch_commit(struct vmw_private 
*dev_priv,
  * @sw_context: The software context used for this command batch validation.
  * @id: Pointer to the user-space handle to be translated.
  * @vmw_bo_p: Points to a location that, on successful return will carry
- * a reference-counted pointer to the DMA buffer identified by the
+ * a non-reference-counted pointer to the buffer object identified by the
  * user-space handle in @id.
  *
  * This function saves information needed to translate a user-space buffer
@@ -1152,38 +1152,34 @@ static int vmw_translate_mob_ptr(struct vmw_private 
*dev_priv,
 SVGAMobId *id,
 struct vmw_buffer_object **vmw_bo_p)
 {
-   struct vmw_buffer_object *vmw_bo = NULL;
+   struct vmw_buffer_object *vmw_bo;
uint32_t handle = *id;
struct vmw_relocation *reloc;
int ret;
 
-   ret = vmw_user_bo_lookup(sw_context->fp->tfile, handle, _bo, NULL);
-   if (unlikely(ret != 0)) {
+   vmw_validation_preload_bo(sw_context->ctx);
+   vmw_bo = vmw_user_bo_noref_lookup(sw_context->fp->tfile, handle);
+   if (IS_ERR(vmw_bo)) {
DRM_ERROR("Could not find or use MOB buffer.\n");
-   ret = -EINVAL;
-   goto out_no_reloc;
+   return PTR_ERR(vmw_bo);
}
 
+   ret = vmw_validation_add_bo(sw_context->ctx, vmw_bo, true, false);
+   vmw_user_bo_noref_release();
+   if (unlikely(ret != 0))
+   return ret;
+
reloc = vmw_validation_mem_alloc(sw_context->ctx, sizeof(*reloc));
if (!reloc)
-   goto out_no_reloc;
+   return -ENOMEM;
 
reloc->mob_loc = id;
reloc->vbo = vmw_bo;
 
-   ret = vmw_validation_add_bo(sw_context->ctx, vmw_bo, true, false);
-   if (unlikely(ret != 0))
-   goto out_no_reloc;
-
*vmw_bo_p = vmw_bo;
list_add_tail(>head, _context->bo_relocations);
 
return 0;
-
-out_no_reloc:
-   vmw_bo_unreference(_bo);
-   *vmw_bo_p = NULL;
-   return ret;
 }
 
 /**
@@ -1194,7 +1190,7 @@ static int vmw_translate_mob_ptr(struct vmw_private 
*dev_priv,
  * @sw_context: The software context used for this command batch validation.
  * @ptr: Pointer to the user-space handle to be translated.
  * @vmw_bo_p: Points to a location that, on successful return will carry
- * a reference-counted pointer to the DMA buffer identified by the
+ * a non-reference-counted pointer to the DMA buffer identified by the
  * user-space handle in @id.
  *
  * This function saves information needed to translate a user-space buffer
@@ -1210,38 +1206,33 @@ static int vmw_translate_guest_ptr(struct vmw_private 
*dev_priv,
   SVGAGuestPtr *ptr,
   struct vmw_buffer_object **vmw_bo_p)
 {
-   struct vmw_buffer_object *vmw_bo = NULL;
+   struct vmw_buffer_object *vmw_bo;
uint32_t handle = ptr->gmrId;
struct vmw_relocation *reloc;
int ret;
 
-   ret = vmw_user_bo_lookup(sw_context->fp->tfile, handle, _bo, NULL);
-   if (unlikely(ret != 0)) {
+   vmw_validation_preload_bo(sw_context->ctx);
+   vmw_bo = vmw_user_bo_noref_lookup(sw_context->fp->tfile, handle);
+   if (IS_ERR(vmw_bo)) {
DRM_ERROR("Could not find or use GMR region.\n");
-   ret = -EINVAL;
-   goto out_no_reloc;
+   return PTR_ERR(vmw_bo);
}
 
+   ret = vmw_validation_add_bo(sw_context->ctx, vmw_bo, false, false);
+   vmw_user_bo_noref_release();
+   if (unlikely(ret != 0))
+   return ret;
+
reloc = vmw_validation_mem_alloc(sw_context->ctx, sizeof(*reloc));
if (!reloc)
-   goto out_no_reloc;
+   return -ENOMEM;
 
reloc->location = ptr;
reloc->vbo = vmw_bo;
-
-   ret = vmw_validation_add_bo(sw_context->ctx, vmw_bo, false, false);
-   if (unlikely(ret != 0))
-   goto out_no_reloc;
-
*vmw_bo_p = vmw_bo;
list_add_tail(>head, _context->bo_relocations);
 
return 0;
-
-out_no_reloc:
-   vmw_bo_unreference(_bo);
-   *vmw_bo_p = NULL;
-   return ret;

[PATCH -next 12/18] drm/ttm: Export ttm_bo_reference_unless_doomed()

2018-09-26 Thread Thomas Hellstrom
Export ttm_bo_reference_unless_doomed() to be used when looking up buffer
objects that are removed from the lookup structure in the destructor.

Cc: Christian König 
Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/ttm/ttm_bo_vm.c |  3 +--
 include/drm/ttm/ttm_bo_api.h| 18 ++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 6fe91c1b692d..ec4b09366213 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -409,8 +409,7 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct 
ttm_bo_device *bdev,
node = drm_vma_offset_lookup_locked(>vma_manager, offset, pages);
if (likely(node)) {
bo = container_of(node, struct ttm_buffer_object, vma_node);
-   if (!kref_get_unless_zero(>kref))
-   bo = NULL;
+   bo = ttm_bo_reference_unless_doomed(bo);
}
 
drm_vma_offset_unlock_lookup(>vma_manager);
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 8c19470785e2..b6bf6b086576 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)
return bo;
 }
 
+/**
+ * ttm_bo_reference_unless_doomed - reference a struct ttm_buffer_object unless
+ * its refcount has already reached zero.
+ * @bo: The buffer object.
+ *
+ * Used to reference a TTM buffer object in lookups where the object is removed
+ * from the lookup structure during the destructor and for RCU lookups.
+ *
+ * Returns: @bo if the referencing was successful, NULL otherwise.
+ */
+static inline __must_check struct ttm_buffer_object *
+ttm_bo_reference_unless_doomed(struct ttm_buffer_object *bo)
+{
+   if (!kref_get_unless_zero(>kref))
+   return NULL;
+   return bo;
+}
+
 /**
  * ttm_bo_wait - wait for buffer idle.
  *
-- 
2.14.4

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


[PATCH -next 16/18] drm/vmwgfx: Don't refcount command-buffer managed resource lookups during command buffer validation

2018-09-26 Thread Thomas Hellstrom
The typical pattern of these lookups are
-Lookup
-Put on validate list if not already there.
-Unreference
And since we are the exclusive user of the context during lookup time,
we can be sure that the resource will stay alive during the sequence.
So avoid taking a reference during lookup, and also avoid unreferencing
when done.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c |  3 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c| 69 +++---
 2 files changed, 27 insertions(+), 45 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c
index 3b75af9bf85f..4ac55fc2bf97 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c
@@ -89,8 +89,7 @@ vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
if (unlikely(ret != 0))
return ERR_PTR(ret);
 
-   return vmw_resource_reference
-   (drm_hash_entry(hash, struct vmw_cmdbuf_res, hash)->res);
+   return drm_hash_entry(hash, struct vmw_cmdbuf_res, hash)->res;
 }
 
 /**
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index 15e83b39e26d..13db7efcb89c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -314,10 +314,14 @@ static int vmw_view_res_val_add(struct vmw_sw_context 
*sw_context,
  *
  * The view is represented by a view id and the DX context it's created on,
  * or scheduled for creation on. If there is no DX context set, the function
- * will return -EINVAL. Otherwise returns 0 on success and -EINVAL on failure.
+ * will return an -EINVAL error pointer.
+ *
+ * Returns: Unreferenced pointer to the resource on success, negative error
+ * pointer on failure.
  */
-static int vmw_view_id_val_add(struct vmw_sw_context *sw_context,
-  enum vmw_view_type view_type, u32 id)
+static struct vmw_resource *
+vmw_view_id_val_add(struct vmw_sw_context *sw_context,
+   enum vmw_view_type view_type, u32 id)
 {
struct vmw_ctx_validation_info *ctx_node = sw_context->dx_ctx_node;
struct vmw_resource *view;
@@ -325,17 +329,18 @@ static int vmw_view_id_val_add(struct vmw_sw_context 
*sw_context,
 
if (!ctx_node) {
DRM_ERROR("DX Context not set.\n");
-   return -EINVAL;
+   return ERR_PTR(-EINVAL);
}
 
view = vmw_view_lookup(sw_context->man, view_type, id);
if (IS_ERR(view))
-   return PTR_ERR(view);
+   return view;
 
ret = vmw_view_res_val_add(sw_context, view);
-   vmw_resource_unreference();
+   if (ret)
+   return ERR_PTR(ret);
 
-   return ret;
+   return view;
 }
 
 /**
@@ -740,34 +745,24 @@ static int vmw_view_bindings_add(struct vmw_sw_context 
*sw_context,
 u32 first_slot)
 {
struct vmw_ctx_validation_info *ctx_node = sw_context->dx_ctx_node;
-   struct vmw_cmdbuf_res_manager *man;
u32 i;
-   int ret;
 
if (!ctx_node) {
DRM_ERROR("DX Context not set.\n");
return -EINVAL;
}
 
-   man = sw_context->man;
for (i = 0; i < num_views; ++i) {
struct vmw_ctx_bindinfo_view binding;
struct vmw_resource *view = NULL;
 
if (view_ids[i] != SVGA3D_INVALID_ID) {
-   view = vmw_view_lookup(man, view_type, view_ids[i]);
+   view = vmw_view_id_val_add(sw_context, view_type,
+  view_ids[i]);
if (IS_ERR(view)) {
DRM_ERROR("View not found.\n");
return PTR_ERR(view);
}
-
-   ret = vmw_view_res_val_add(sw_context, view);
-   if (ret) {
-   DRM_ERROR("Could not add view to "
- "validation list.\n");
-   vmw_resource_unreference();
-   return ret;
-   }
}
binding.bi.ctx = ctx_node->ctx;
binding.bi.res = view;
@@ -776,8 +771,6 @@ static int vmw_view_bindings_add(struct vmw_sw_context 
*sw_context,
binding.slot = first_slot + i;
vmw_binding_add(ctx_node->staged, ,
shader_slot, binding.slot);
-   if (view)
-   vmw_resource_unreference();
}
 
return 0;
@@ -2136,11 +2129,8 @@ static int vmw_cmd_set_shader(struct vmw_private 
*dev_priv,
cmd->body.type);
 
if (!IS_ERR(res)) {
-   struct vmw_resource *tmp_res = res;

[PATCH -next 11/18] drm/ttm: Look up objects without taking a reference

2018-09-26 Thread Thomas Hellstrom
Typically when we look up objects under the rcu lock, we take a reference
to make sure the returned object pointer is valid.
Now provide a function to look up an object and instead of taking a
reference to it, keep the rcu lock held when returning the object pointer.
This means that the object pointer is valid as long as the rcu lock is
held, but the object may be doomed (its refcount may be zero). Any
persistent usage of the object pointer outside of the rcu lock requires
a reference to be taken using kref_get_unless_zero().

Cc: Christian König 
Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/ttm/ttm_object.c | 35 +++
 include/drm/ttm/ttm_object.h | 15 +++
 2 files changed, 50 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_object.c b/drivers/gpu/drm/ttm/ttm_object.c
index 0782c6280d9b..f1a5ea0babef 100644
--- a/drivers/gpu/drm/ttm/ttm_object.c
+++ b/drivers/gpu/drm/ttm/ttm_object.c
@@ -228,6 +228,41 @@ void ttm_base_object_unref(struct ttm_base_object **p_base)
 }
 EXPORT_SYMBOL(ttm_base_object_unref);
 
+/**
+ * ttm_base_object_noref_lookup - look up a base object without reference
+ * @tfile: The struct ttm_object_file the object is registered with.
+ * @key: The object handle.
+ *
+ * This function looks up a ttm base object and returns a pointer to it
+ * without refcounting the pointer. The returned pointer is only valid
+ * until ttm_base_object_noref_release() is called, and the object
+ * pointed to by the returned pointer may be doomed. Any persistent usage
+ * of the object requires a refcount to be taken using kref_get_unless_zero().
+ * Iff this function returns successfully it needs to be paired with
+ * ttm_base_object_noref_release() and no sleeping- or scheduling functions
+ * may be called inbetween these function callse.
+ *
+ * Return: A pointer to the object if successful or NULL otherwise.
+ */
+struct ttm_base_object *
+ttm_base_object_noref_lookup(struct ttm_object_file *tfile, uint32_t key)
+{
+   struct drm_hash_item *hash;
+   struct drm_open_hash *ht = >ref_hash[TTM_REF_USAGE];
+   int ret;
+
+   rcu_read_lock();
+   ret = drm_ht_find_item_rcu(ht, key, );
+   if (ret) {
+   rcu_read_unlock();
+   return NULL;
+   }
+
+   __release(RCU);
+   return drm_hash_entry(hash, struct ttm_ref_object, hash)->obj;
+}
+EXPORT_SYMBOL(ttm_base_object_noref_lookup);
+
 struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file *tfile,
   uint32_t key)
 {
diff --git a/include/drm/ttm/ttm_object.h b/include/drm/ttm/ttm_object.h
index 6204acc2ebf4..e35538475840 100644
--- a/include/drm/ttm/ttm_object.h
+++ b/include/drm/ttm/ttm_object.h
@@ -358,4 +358,19 @@ extern int ttm_prime_handle_to_fd(struct ttm_object_file 
*tfile,
  * per idr.
  */
 #define TTM_OBJ_EXTRA_SIZE 128
+
+struct ttm_base_object *
+ttm_base_object_noref_lookup(struct ttm_object_file *tfile, uint32_t key);
+
+/**
+ * ttm_base_object_noref_release - release a base object pointer looked up
+ * without reference
+ *
+ * Releases a base object pointer looked up with 
ttm_base_object_noref_lookup().
+ */
+static inline void ttm_base_object_noref_release(void)
+{
+   __acquire(RCU);
+   rcu_read_unlock();
+}
 #endif
-- 
2.14.4

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


[PATCH -next 17/18] drm/vmwgfx: Don't refcount cotable lookups during command buffer validation

2018-09-26 Thread Thomas Hellstrom
The typical pattern of these lookups are
-Lookup
-Put on validate list if not already there.
-Unreference
And since we are the exclusive user of the context during lookup time,
we can be sure that the resource will stay alive during the sequence.
So avoid taking a reference during lookup, and also avoid unreferencing
when done. There are two users outside of command buffer validation and
those are refcounted explicitly.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 5 ++---
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 5 -
 drivers/gpu/drm/vmwgfx/vmwgfx_shader.c  | 3 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_so.c  | 3 ++-
 4 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
index 24d7c81081ae..14bd760a62fd 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
@@ -861,9 +861,8 @@ struct vmw_resource *vmw_context_cotable(struct 
vmw_resource *ctx,
if (cotable_type >= SVGA_COTABLE_DX10_MAX)
return ERR_PTR(-EINVAL);
 
-   return vmw_resource_reference
-   (container_of(ctx, struct vmw_user_context, res)->
-cotables[cotable_type]);
+   return container_of(ctx, struct vmw_user_context, res)->
+   cotables[cotable_type];
 }
 
 /**
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index 13db7efcb89c..dfa2d19274d5 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -372,7 +372,6 @@ static int vmw_resource_context_res_add(struct vmw_private 
*dev_priv,
continue;
 
ret = vmw_resource_val_add(sw_context, res);
-   vmw_resource_unreference();
if (unlikely(ret != 0))
return ret;
}
@@ -1266,7 +1265,6 @@ static int vmw_cmd_dx_define_query(struct vmw_private 
*dev_priv,
 
cotable_res = vmw_context_cotable(ctx_node->ctx, SVGA_COTABLE_DXQUERY);
ret = vmw_cotable_notify(cotable_res, cmd->q.queryId);
-   vmw_resource_unreference(_res);
 
return ret;
 }
@@ -2578,7 +2576,6 @@ static int vmw_cmd_dx_view_define(struct vmw_private 
*dev_priv,
 
res = vmw_context_cotable(ctx_node->ctx, vmw_view_cotables[view_type]);
ret = vmw_cotable_notify(res, cmd->defined_id);
-   vmw_resource_unreference();
if (unlikely(ret != 0))
return ret;
 
@@ -2675,7 +2672,6 @@ static int vmw_cmd_dx_so_define(struct vmw_private 
*dev_priv,
res = vmw_context_cotable(ctx_node->ctx, vmw_so_cotables[so_type]);
cmd = container_of(header, typeof(*cmd), header);
ret = vmw_cotable_notify(res, cmd->defined_id);
-   vmw_resource_unreference();
 
return ret;
 }
@@ -2806,7 +2802,6 @@ static int vmw_cmd_dx_define_shader(struct vmw_private 
*dev_priv,
 
res = vmw_context_cotable(ctx_node->ctx, SVGA_COTABLE_DXSHADER);
ret = vmw_cotable_notify(res, cmd->body.shaderId);
-   vmw_resource_unreference();
if (ret)
return ret;
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
index 6915c8258e6b..bf32fe446219 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
@@ -636,7 +636,8 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
 
res = >res;
shader->ctx = ctx;
-   shader->cotable = vmw_context_cotable(ctx, SVGA_COTABLE_DXSHADER);
+   shader->cotable = vmw_resource_reference
+   (vmw_context_cotable(ctx, SVGA_COTABLE_DXSHADER));
shader->id = user_key;
shader->committed = false;
INIT_LIST_HEAD(>cotable_head);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
index aaabb87ac3af..bc8bb690f1ea 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
@@ -366,7 +366,8 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
res = >res;
view->ctx = ctx;
view->srf = vmw_resource_reference(srf);
-   view->cotable = vmw_context_cotable(ctx, vmw_view_cotables[view_type]);
+   view->cotable = vmw_resource_reference
+   (vmw_context_cotable(ctx, vmw_view_cotables[view_type]));
view->view_type = view_type;
view->view_id = user_key;
view->cmd_size = cmd_size;
-- 
2.14.4

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


[PATCH -next 07/18] drm/vmwgfx: Replace unconditional mutex unlocked warnings with lockdep counterpart

2018-09-26 Thread Thomas Hellstrom
Replace instances of WARN_ON[_ONCE](!mutex_is_held()) with
lockdep_assert_held(). This makes sure the checking process actually
holds the mutex and also removes the checks from release builds

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
Reviewed-by: Deepak Rawat 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c | 4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c
index e7e4655d3f36..48d1380a952e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c
@@ -660,7 +660,7 @@ static void __vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man 
*man)
 {
struct vmw_cmdbuf_header *cur = man->cur;
 
-   WARN_ON(!mutex_is_locked(>cur_mutex));
+   lockdep_assert_held_once(>cur_mutex);
 
if (!cur)
return;
@@ -1045,7 +1045,7 @@ static void vmw_cmdbuf_commit_cur(struct vmw_cmdbuf_man 
*man,
 {
struct vmw_cmdbuf_header *cur = man->cur;
 
-   WARN_ON(!mutex_is_locked(>cur_mutex));
+   lockdep_assert_held_once(>cur_mutex);
 
WARN_ON(size > cur->reserved);
man->cur_pos += size;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
index fe4842ca3b6e..e03431aef3d0 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
@@ -562,7 +562,7 @@ void vmw_dx_shader_cotable_list_scrub(struct vmw_private 
*dev_priv,
 {
struct vmw_dx_shader *entry, *next;
 
-   WARN_ON_ONCE(!mutex_is_locked(_priv->binding_mutex));
+   lockdep_assert_held_once(_priv->binding_mutex);
 
list_for_each_entry_safe(entry, next, list, cotable_head) {
WARN_ON(vmw_dx_shader_scrub(>res));
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
index e9b6b7baa009..a01de4845eb7 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
@@ -208,7 +208,7 @@ static int vmw_view_destroy(struct vmw_resource *res)
union vmw_view_destroy body;
} *cmd;
 
-   WARN_ON_ONCE(!mutex_is_locked(_priv->binding_mutex));
+   lockdep_assert_held_once(_priv->binding_mutex);
vmw_binding_res_list_scrub(>binding_head);
 
if (!view->committed || res->id == -1)
@@ -439,7 +439,7 @@ void vmw_view_cotable_list_destroy(struct vmw_private 
*dev_priv,
 {
struct vmw_view *entry, *next;
 
-   WARN_ON_ONCE(!mutex_is_locked(_priv->binding_mutex));
+   lockdep_assert_held_once(_priv->binding_mutex);
 
list_for_each_entry_safe(entry, next, list, cotable_head)
WARN_ON(vmw_view_destroy(>res));
@@ -459,7 +459,7 @@ void vmw_view_surface_list_destroy(struct vmw_private 
*dev_priv,
 {
struct vmw_view *entry, *next;
 
-   WARN_ON_ONCE(!mutex_is_locked(_priv->binding_mutex));
+   lockdep_assert_held_once(_priv->binding_mutex);
 
list_for_each_entry_safe(entry, next, list, srf_head)
WARN_ON(vmw_view_destroy(>res));
-- 
2.14.4

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


[PATCH -next 05/18] drm/vmwgfx: Use a validation context allocator for relocations and validations

2018-09-26 Thread Thomas Hellstrom
A common trait of these objects are that they are allocated during the
command validation phase and freed after command submission. Furthermore
they are accessed by a single thread only. So provide a simple unprotected
stack-like allocator from which these objects can be allocated. Their
memory is freed with the validation context when the command submission
is done.

Note that the mm subsystem maintains a per-cpu cache of single pages to
make single page allocation and freeing efficient.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h| 12 +---
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c| 80 ++
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.c | 92 --
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.h | 12 +++-
 4 files changed, 132 insertions(+), 64 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 5ff50972c3a1..2f46e5613dfb 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -205,12 +205,6 @@ struct vmw_fifo_state {
bool dx;
 };
 
-struct vmw_relocation {
-   SVGAMobId *mob_loc;
-   SVGAGuestPtr *location;
-   struct vmw_buffer_object *vbo;
-};
-
 /**
  * struct vmw_res_cache_entry - resource information cache entry
  * @handle: User-space handle of a resource.
@@ -303,12 +297,11 @@ struct vmw_ctx_validation_info;
  * than from user-space
  * @fp: If @kernel is false, points to the file of the client. Otherwise
  * NULL
- * @relocs: Array of buffer object relocations
- * @cur_reloc: Cursor pointing to the current relocation
  * @cmd_bounce: Command bounce buffer used for command validation before
  * copying to fifo space
  * @cmd_bounce_size: Current command bounce buffer size
  * @cur_query_bo: Current buffer object used as query result buffer
+ * @bo_relocations: List of buffer object relocations
  * @res_relocations: List of resource relocations
  * @buf_start: Pointer to start of memory where command validation takes
  * place
@@ -335,11 +328,10 @@ struct vmw_sw_context{
bool res_ht_initialized;
bool kernel;
struct vmw_fpriv *fp;
-   struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
-   uint32_t cur_reloc;
uint32_t *cmd_bounce;
uint32_t cmd_bounce_size;
struct vmw_buffer_object *cur_query_bo;
+   struct list_head bo_relocations;
struct list_head res_relocations;
uint32_t *buf_start;
struct vmw_res_cache_entry res_cache[vmw_res_max];
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index 85821a5b227c..da341cc6ff47 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -35,6 +35,21 @@
 
 #define VMW_RES_HT_ORDER 12
 
+/*
+ * struct vmw_relocation - Buffer object relocation
+ *
+ * @head: List head for the command submission context's relocation list
+ * @mob_loc: Pointer to location for mob id to be modified
+ * @location: Pointer to location for guest pointer to be modified
+ * @vbo: Non ref-counted pointer to buffer object
+ */
+struct vmw_relocation {
+   struct list_head head;
+   SVGAMobId *mob_loc;
+   SVGAGuestPtr *location;
+   struct vmw_buffer_object *vbo;
+};
+
 /**
  * enum vmw_resource_relocation_type - Relocation type for resources
  *
@@ -132,11 +147,9 @@ static size_t vmw_ptr_diff(void *a, void *b)
 static void vmw_execbuf_bindings_commit(struct vmw_sw_context *sw_context,
bool backoff)
 {
-   struct vmw_ctx_validation_info *entry, *next;
-
-   list_for_each_entry_safe(entry, next, _context->ctx_list, head) {
-   list_del(>head);
+   struct vmw_ctx_validation_info *entry;
 
+   list_for_each_entry(entry, _context->ctx_list, head) {
if (!backoff)
vmw_binding_state_commit(entry->cur, entry->staged);
if (entry->staged != sw_context->staged_bindings)
@@ -144,6 +157,9 @@ static void vmw_execbuf_bindings_commit(struct 
vmw_sw_context *sw_context,
else
sw_context->staged_bindings_inuse = false;
}
+
+   /* List entries are freed with the validation context */
+   INIT_LIST_HEAD(_context->ctx_list);
 }
 
 /**
@@ -397,7 +413,7 @@ static int vmw_resource_context_res_add(struct vmw_private 
*dev_priv,
  * id that needs fixup is located. Granularity is one byte.
  * @rel_type: Relocation type.
  */
-static int vmw_resource_relocation_add(struct list_head *list,
+static int vmw_resource_relocation_add(struct vmw_sw_context *sw_context,
   const struct vmw_resource *res,
   unsigned long offset,
   enum vmw_resource_relocation_type
@@ -405,7 +421,7 @@ static int vmw_resource_relocation_add(struct 

[PATCH -next 10/18] drm/ttm: Make the object handles idr-generated

2018-09-26 Thread Thomas Hellstrom
Instead of generating user-space object handles based on a, possibly
processed, hash of the kernel address of the object, use idr to generate
and lookup those handles. This might improve somewhat on security since
we loose all connections to the object's kernel address. Also idr is
designed to do just this.

As a todo-item, since user-space handles are now generated in sequence,
we can probably use a much simpler hash function to hash them.

Cc: Christian König 
Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
Reviewed-by: Deepak Rawat 
---
 drivers/gpu/drm/ttm/ttm_lock.c  |  2 +-
 drivers/gpu/drm/ttm/ttm_object.c| 42 -
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c  |  7 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 12 +++
 drivers/gpu/drm/vmwgfx/vmwgfx_fence.c   |  7 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h   |  5 +++
 drivers/gpu/drm/vmwgfx/vmwgfx_shader.c  | 16 +++---
 drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c |  5 +--
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 18 +--
 include/drm/ttm/ttm_object.h| 13 ++--
 10 files changed, 65 insertions(+), 62 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_lock.c b/drivers/gpu/drm/ttm/ttm_lock.c
index 20694b8a01ca..214cf73241d9 100644
--- a/drivers/gpu/drm/ttm/ttm_lock.c
+++ b/drivers/gpu/drm/ttm/ttm_lock.c
@@ -267,7 +267,7 @@ EXPORT_SYMBOL(ttm_vt_lock);
 int ttm_vt_unlock(struct ttm_lock *lock)
 {
return ttm_ref_object_base_unref(lock->vt_holder,
-lock->base.hash.key, TTM_REF_USAGE);
+lock->base.handle, TTM_REF_USAGE);
 }
 EXPORT_SYMBOL(ttm_vt_unlock);
 
diff --git a/drivers/gpu/drm/ttm/ttm_object.c b/drivers/gpu/drm/ttm/ttm_object.c
index 74f1b1eb1f8e..0782c6280d9b 100644
--- a/drivers/gpu/drm/ttm/ttm_object.c
+++ b/drivers/gpu/drm/ttm/ttm_object.c
@@ -95,6 +95,7 @@ struct ttm_object_device {
struct dma_buf_ops ops;
void (*dmabuf_release)(struct dma_buf *dma_buf);
size_t dma_buf_size;
+   struct idr idr;
 };
 
 /**
@@ -172,14 +173,15 @@ int ttm_base_object_init(struct ttm_object_file *tfile,
base->ref_obj_release = ref_obj_release;
base->object_type = object_type;
kref_init(>refcount);
+   idr_preload(GFP_KERNEL);
spin_lock(>object_lock);
-   ret = drm_ht_just_insert_please_rcu(>object_hash,
-   >hash,
-   (unsigned long)base, 31, 0, 0);
+   ret = idr_alloc(>idr, base, 0, 0, GFP_NOWAIT);
spin_unlock(>object_lock);
-   if (unlikely(ret != 0))
-   goto out_err0;
+   idr_preload_end();
+   if (ret < 0)
+   return ret;
 
+   base->handle = ret;
ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL, false);
if (unlikely(ret != 0))
goto out_err1;
@@ -189,9 +191,8 @@ int ttm_base_object_init(struct ttm_object_file *tfile,
return 0;
 out_err1:
spin_lock(>object_lock);
-   (void)drm_ht_remove_item_rcu(>object_hash, >hash);
+   idr_remove(>idr, base->handle);
spin_unlock(>object_lock);
-out_err0:
return ret;
 }
 EXPORT_SYMBOL(ttm_base_object_init);
@@ -203,7 +204,7 @@ static void ttm_release_base(struct kref *kref)
struct ttm_object_device *tdev = base->tfile->tdev;
 
spin_lock(>object_lock);
-   (void)drm_ht_remove_item_rcu(>object_hash, >hash);
+   idr_remove(>idr, base->handle);
spin_unlock(>object_lock);
 
/*
@@ -252,19 +253,13 @@ EXPORT_SYMBOL(ttm_base_object_lookup);
 struct ttm_base_object *
 ttm_base_object_lookup_for_ref(struct ttm_object_device *tdev, uint32_t key)
 {
-   struct ttm_base_object *base = NULL;
-   struct drm_hash_item *hash;
-   struct drm_open_hash *ht = >object_hash;
-   int ret;
+   struct ttm_base_object *base;
 
rcu_read_lock();
-   ret = drm_ht_find_item_rcu(ht, key, );
+   base = idr_find(>idr, key);
 
-   if (likely(ret == 0)) {
-   base = drm_hash_entry(hash, struct ttm_base_object, hash);
-   if (!kref_get_unless_zero(>refcount))
-   base = NULL;
-   }
+   if (base && !kref_get_unless_zero(>refcount))
+   base = NULL;
rcu_read_unlock();
 
return base;
@@ -289,7 +284,7 @@ bool ttm_ref_object_exists(struct ttm_object_file *tfile,
struct ttm_ref_object *ref;
 
rcu_read_lock();
-   if (unlikely(drm_ht_find_item_rcu(ht, base->hash.key, ) != 0))
+   if (unlikely(drm_ht_find_item_rcu(ht, base->handle, ) != 0))
goto out_false;
 
/*
@@ -340,7 +335,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,
 
while (ret == -EINVAL) {
rcu_read_lock();
-   ret = drm_ht_find_item_rcu(ht, 

[PATCH -next 08/18] drm/vmwgfx: Remove the resource avail field

2018-09-26 Thread Thomas Hellstrom
This field was previously used to prevent a lookup of a resource before its
constructor had run to its end. This was mainly intended for an interface
that is now removed that allowed looking up a resource by its device id.

Currently all affected resources are added to the lookup mechanism (its
TTM prime object is initialized) late in the constructor where it's OK to
look up the resource.

This means we can change the device resource_lock to an ordinary spinlock
instead of an rwlock and remove a locking sequence during lookup.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
Reviewed-by: Deepak Rawat 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c |  6 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 44 ---
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c| 75 -
 drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h   |  2 -
 drivers/gpu/drm/vmwgfx/vmwgfx_shader.c  |  4 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_so.c  |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c |  2 +-
 10 files changed, 68 insertions(+), 73 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
index 7c3cb8efd11a..4d502567d24c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
@@ -217,9 +217,7 @@ static int vmw_gb_context_init(struct vmw_private *dev_priv,
}
}
 
-
-
-   vmw_resource_activate(res, vmw_hw_context_destroy);
+   res->hw_destroy = vmw_hw_context_destroy;
return 0;
 
 out_cotables:
@@ -274,7 +272,7 @@ static int vmw_context_init(struct vmw_private *dev_priv,
 
vmw_fifo_commit(dev_priv, sizeof(*cmd));
vmw_fifo_resource_inc(dev_priv);
-   vmw_resource_activate(res, vmw_hw_context_destroy);
+   res->hw_destroy = vmw_hw_context_destroy;
return 0;
 
 out_early:
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
index 1d45714e1d5a..44f3f6f107d3 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
@@ -615,7 +615,7 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private 
*dev_priv,
vcotbl->type = type;
vcotbl->ctx = ctx;
 
-   vmw_resource_activate(>res, vmw_hw_cotable_destroy);
+   vcotbl->res.hw_destroy = vmw_hw_cotable_destroy;
 
return >res;
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index bb6dbbe18835..7755e297dabc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -667,8 +667,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned 
long chipset)
mutex_init(_priv->binding_mutex);
mutex_init(_priv->requested_layout_mutex);
mutex_init(_priv->global_kms_state_mutex);
-   rwlock_init(_priv->resource_lock);
ttm_lock_init(_priv->reservation_sem);
+   spin_lock_init(_priv->resource_lock);
spin_lock_init(_priv->hw_lock);
spin_lock_init(_priv->waiter_lock);
spin_lock_init(_priv->cap_lock);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 2f46e5613dfb..dc6a3151fb06 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -113,21 +113,49 @@ struct vmw_validate_buffer {
 };
 
 struct vmw_res_func;
+
+
+/**
+ * struct vmw-resource - base class for hardware resources
+ *
+ * @kref: For refcounting.
+ * @dev_priv: Pointer to the device private for this resource. Immutable.
+ * @id: Device id. Protected by @dev_priv::resource_lock.
+ * @backup_size: Backup buffer size. Immutable.
+ * @res_dirty: Resource contains data not yet in the backup buffer. Protected
+ * by resource reserved.
+ * @backup_dirty: Backup buffer contains data not yet in the HW resource.
+ * Protecte by resource reserved.
+ * @backup: The backup buffer if any. Protected by resource reserved.
+ * @backup_offset: Offset into the backup buffer if any. Protected by resource
+ * reserved. Note that only a few resource types can have a @backup_offset
+ * different from zero.
+ * @pin_count: The pin count for this resource. A pinned resource has a
+ * pin-count greater than zero. It is not on the resource LRU lists and its
+ * backup buffer is pinned. Hence it can't be evicted.
+ * @func: Method vtable for this resource. Immutable.
+ * @lru_head: List head for the LRU list. Protected by 
@dev_priv::resource_lock.
+ * @mob_head: List head for the MOB backup list. Protected by @backup reserved.
+ * @binding_head: List head for the context binding list. Protected by
+ * the @dev_priv::binding_mutex
+ * @res_free: The resource destructor.
+ * @hw_destroy: Callback to destroy the resource on the device, as 

[PATCH -next 06/18] drm/vmwgfx: Reduce the size of buffer object relocations

2018-09-26 Thread Thomas Hellstrom
With the new allocator this leads to less consumed memory for each
user-space command submission

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Deepak Rawat 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index da341cc6ff47..641b75110dc6 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -39,15 +39,17 @@
  * struct vmw_relocation - Buffer object relocation
  *
  * @head: List head for the command submission context's relocation list
+ * @vbo: Non ref-counted pointer to buffer object
  * @mob_loc: Pointer to location for mob id to be modified
  * @location: Pointer to location for guest pointer to be modified
- * @vbo: Non ref-counted pointer to buffer object
  */
 struct vmw_relocation {
struct list_head head;
-   SVGAMobId *mob_loc;
-   SVGAGuestPtr *location;
struct vmw_buffer_object *vbo;
+   union {
+   SVGAMobId *mob_loc;
+   SVGAGuestPtr *location;
+   };
 };
 
 /**
@@ -1167,7 +1169,6 @@ static int vmw_translate_mob_ptr(struct vmw_private 
*dev_priv,
goto out_no_reloc;
 
reloc->mob_loc = id;
-   reloc->location = NULL;
reloc->vbo = vmw_bo;
 
ret = vmw_validation_add_bo(sw_context->ctx, vmw_bo, true, false);
-- 
2.14.4

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


[PATCH -next 09/18] drm/vmwgfx: Remove the user resource destructor check

2018-09-26 Thread Thomas Hellstrom
We were checking that the resource destructor matched that of the
intended object type, to make sure the looked up resource was of the
right type.

But we already have an object type check in place which makes sure the
resource is of the right type.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
Reviewed-by: Deepak Rawat 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 55df79eccd57..cf48d0b157f6 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -219,9 +219,6 @@ int vmw_user_resource_lookup_handle(struct vmw_private 
*dev_priv,
goto out_bad_resource;
 
res = converter->base_obj_to_res(base);
-   if (res->res_free != converter->res_free)
-   goto out_bad_resource;
-
kref_get(>kref);
 
*p_res = res;
-- 
2.14.4

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


[PATCH -next 04/18] drm/vmwgfx: Use new validation interface for the modesetting code v2

2018-09-26 Thread Thomas Hellstrom
Strip the old KMS helpers and use the new validation interface also in
the modesetting code.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Deepak Rawat  #v1
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  | 199 ---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |  24 ++---
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c |  48 ++---
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  31 --
 4 files changed, 86 insertions(+), 216 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index ab424358b8cb..05fb16733c5c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -2557,88 +2557,31 @@ int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
 }
 
 /**
- * vmw_kms_helper_buffer_prepare - Reserve and validate a buffer object before
- * command submission.
- *
- * @dev_priv. Pointer to a device private structure.
- * @buf: The buffer object
- * @interruptible: Whether to perform waits as interruptible.
- * @validate_as_mob: Whether the buffer should be validated as a MOB. If false,
- * The buffer will be validated as a GMR. Already pinned buffers will not be
- * validated.
- *
- * Returns 0 on success, negative error code on failure, -ERESTARTSYS if
- * interrupted by a signal.
+ * vmw_kms_helper_validation_finish - Helper for post KMS command submission
+ * cleanup and fencing
+ * @dev_priv: Pointer to the device-private struct
+ * @file_priv: Pointer identifying the client when user-space fencing is used
+ * @ctx: Pointer to the validation context
+ * @out_fence: If non-NULL, returned refcounted fence-pointer
+ * @user_fence_rep: If non-NULL, pointer to user-space address area
+ * in which to copy user-space fence info
  */
-int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
- struct vmw_buffer_object *buf,
- bool interruptible,
- bool validate_as_mob,
- bool for_cpu_blit)
-{
-   struct ttm_operation_ctx ctx = {
-   .interruptible = interruptible,
-   .no_wait_gpu = false};
-   struct ttm_buffer_object *bo = >base;
-   int ret;
-
-   ttm_bo_reserve(bo, false, false, NULL);
-   if (for_cpu_blit)
-   ret = ttm_bo_validate(bo, _nonfixed_placement, );
-   else
-   ret = vmw_validation_bo_validate_single(bo, interruptible,
-   validate_as_mob);
-   if (ret)
-   ttm_bo_unreserve(bo);
-
-   return ret;
-}
-
-/**
- * vmw_kms_helper_buffer_revert - Undo the actions of
- * vmw_kms_helper_buffer_prepare.
- *
- * @res: Pointer to the buffer object.
- *
- * Helper to be used if an error forces the caller to undo the actions of
- * vmw_kms_helper_buffer_prepare.
- */
-void vmw_kms_helper_buffer_revert(struct vmw_buffer_object *buf)
-{
-   if (buf)
-   ttm_bo_unreserve(>base);
-}
-
-/**
- * vmw_kms_helper_buffer_finish - Unreserve and fence a buffer object after
- * kms command submission.
- *
- * @dev_priv: Pointer to a device private structure.
- * @file_priv: Pointer to a struct drm_file representing the caller's
- * connection. Must be set to NULL if @user_fence_rep is NULL, and conversely
- * if non-NULL, @user_fence_rep must be non-NULL.
- * @buf: The buffer object.
- * @out_fence:  Optional pointer to a fence pointer. If non-NULL, a
- * ref-counted fence pointer is returned here.
- * @user_fence_rep: Optional pointer to a user-space provided struct
- * drm_vmw_fence_rep. If provided, @file_priv must also be provided and the
- * function copies fence data to user-space in a fail-safe manner.
- */
-void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
- struct drm_file *file_priv,
- struct vmw_buffer_object *buf,
- struct vmw_fence_obj **out_fence,
- struct drm_vmw_fence_rep __user *
- user_fence_rep)
-{
-   struct vmw_fence_obj *fence;
+void vmw_kms_helper_validation_finish(struct vmw_private *dev_priv,
+ struct drm_file *file_priv,
+ struct vmw_validation_context *ctx,
+ struct vmw_fence_obj **out_fence,
+ struct drm_vmw_fence_rep __user *
+ user_fence_rep)
+{
+   struct vmw_fence_obj *fence = NULL;
uint32_t handle;
int ret;
 
-   ret = vmw_execbuf_fence_commands(file_priv, dev_priv, ,
-file_priv ?  : NULL);
-   if (buf)
-   vmw_bo_fence_single(>base, fence);
+   if (file_priv || user_fence_rep || vmw_validation_has_bos(ctx) ||
+   out_fence)
+   ret = 

[PATCH -next 03/18] drm/vmwgfx: Adapt execbuf to the new validation api

2018-09-26 Thread Thomas Hellstrom
Strip the old execbuf validation functionality and use the new API instead.
Also use the new API for a now removed execbuf function that was called
from the kms code.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h |  65 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 885 +++-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c |   4 +-
 3 files changed, 360 insertions(+), 594 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index f1a5de351d80..5ff50972c3a1 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -28,6 +28,7 @@
 #ifndef _VMWGFX_DRV_H_
 #define _VMWGFX_DRV_H_
 
+#include "vmwgfx_validation.h"
 #include "vmwgfx_reg.h"
 #include 
 #include 
@@ -207,26 +208,27 @@ struct vmw_fifo_state {
 struct vmw_relocation {
SVGAMobId *mob_loc;
SVGAGuestPtr *location;
-   uint32_t index;
+   struct vmw_buffer_object *vbo;
 };
 
 /**
  * struct vmw_res_cache_entry - resource information cache entry
- *
+ * @handle: User-space handle of a resource.
+ * @res: Non-ref-counted pointer to the resource.
+ * @valid_handle: Whether the @handle member is valid.
  * @valid: Whether the entry is valid, which also implies that the execbuf
  * code holds a reference to the resource, and it's placed on the
  * validation list.
- * @handle: User-space handle of a resource.
- * @res: Non-ref-counted pointer to the resource.
  *
  * Used to avoid frequent repeated user-space handle lookups of the
  * same resource.
  */
 struct vmw_res_cache_entry {
-   bool valid;
uint32_t handle;
struct vmw_resource *res;
-   struct vmw_resource_val_node *node;
+   void *private;
+   unsigned short valid_handle;
+   unsigned short valid;
 };
 
 /**
@@ -291,21 +293,52 @@ enum vmw_display_unit_type {
vmw_du_screen_target
 };
 
+struct vmw_validation_context;
+struct vmw_ctx_validation_info;
 
+/**
+ * struct vmw_sw_context - Command submission context
+ * @res_ht: Pointer hash table used to find validation duplicates
+ * @kernel: Whether the command buffer originates from kernel code rather
+ * than from user-space
+ * @fp: If @kernel is false, points to the file of the client. Otherwise
+ * NULL
+ * @relocs: Array of buffer object relocations
+ * @cur_reloc: Cursor pointing to the current relocation
+ * @cmd_bounce: Command bounce buffer used for command validation before
+ * copying to fifo space
+ * @cmd_bounce_size: Current command bounce buffer size
+ * @cur_query_bo: Current buffer object used as query result buffer
+ * @res_relocations: List of resource relocations
+ * @buf_start: Pointer to start of memory where command validation takes
+ * place
+ * @res_cache: Cache of recently looked up resources
+ * @last_query_ctx: Last context that submitted a query
+ * @needs_post_query_barrier: Whether a query barrier is needed after
+ * command submission
+ * @error_resource: Pointer to hold a reference to the resource causing
+ * an error
+ * @staged_bindings: Cached per-context binding tracker
+ * @staged_bindings_inuse: Whether the cached per-context binding tracker
+ * is in use
+ * @staged_cmd_res: List of staged command buffer managed resources in this
+ * command buffer
+ * @ctx_list: List of context resources referenced in this command buffer
+ * @dx_ctx_node: Validation metadata of the current DX context
+ * @dx_query_mob: The MOB used for DX queries
+ * @dx_query_ctx: The DX context used for the last DX query
+ * @man: Pointer to the command buffer managed resource manager
+ * @ctx: The validation context
+ */
 struct vmw_sw_context{
struct drm_open_hash res_ht;
bool res_ht_initialized;
-   bool kernel; /**< is the called made from the kernel */
+   bool kernel;
struct vmw_fpriv *fp;
-   struct list_head validate_nodes;
struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
uint32_t cur_reloc;
-   struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
-   uint32_t cur_val_buf;
uint32_t *cmd_bounce;
uint32_t cmd_bounce_size;
-   struct list_head resource_list;
-   struct list_head ctx_resource_list; /* For contexts and cotables */
struct vmw_buffer_object *cur_query_bo;
struct list_head res_relocations;
uint32_t *buf_start;
@@ -316,10 +349,12 @@ struct vmw_sw_context{
struct vmw_ctx_binding_state *staged_bindings;
bool staged_bindings_inuse;
struct list_head staged_cmd_res;
-   struct vmw_resource_val_node *dx_ctx_node;
+   struct list_head ctx_list;
+   struct vmw_ctx_validation_info *dx_ctx_node;
struct vmw_buffer_object *dx_query_mob;
struct vmw_resource *dx_query_ctx;
struct vmw_cmdbuf_res_manager *man;
+   struct vmw_validation_context *ctx;
 };
 
 struct vmw_legacy_display;
@@ -864,10 +899,6 @@ extern void 

[PATCH -next 02/18] drm/vmwgfx: Modify the resource validation interface

2018-09-26 Thread Thomas Hellstrom
Allow selecting interruptible or uninterruptible waits to match
expectations of callers.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Deepak Rawat 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h|  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c|  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c|  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c   | 13 -
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.c |  2 +-
 5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 1abe21758b0d..f1a5de351d80 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -628,7 +628,7 @@ extern void vmw_resource_unreference(struct vmw_resource 
**p_res);
 extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
 extern struct vmw_resource *
 vmw_resource_reference_unless_doomed(struct vmw_resource *res);
-extern int vmw_resource_validate(struct vmw_resource *res);
+extern int vmw_resource_validate(struct vmw_resource *res, bool intr);
 extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
bool no_backup);
 extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index 1f134570b759..cfc87313a431 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -659,7 +659,7 @@ static int vmw_resources_validate(struct vmw_sw_context 
*sw_context)
struct vmw_resource *res = val->res;
struct vmw_buffer_object *backup = res->backup;
 
-   ret = vmw_resource_validate(res);
+   ret = vmw_resource_validate(res, true);
if (unlikely(ret != 0)) {
if (ret != -ERESTARTSYS)
DRM_ERROR("Failed to validate resource.\n");
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 0c25bb8faf80..e5659bf28ee1 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -2713,7 +2713,7 @@ int vmw_kms_helper_resource_prepare(struct vmw_resource 
*res,
 
ctx->buf = vmw_bo_reference(res->backup);
}
-   ret = vmw_resource_validate(res);
+   ret = vmw_resource_validate(res, interruptible);
if (ret)
goto out_revert;
return 0;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 92003ea5a219..315b3d60567d 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -587,15 +587,18 @@ static int vmw_resource_do_evict(struct ww_acquire_ctx 
*ticket,
 /**
  * vmw_resource_validate - Make a resource up-to-date and visible
  * to the device.
- *
- * @res:The resource to make visible to the device.
+ * @res: The resource to make visible to the device.
+ * @intr: Perform waits interruptible if possible.
  *
  * On succesful return, any backup DMA buffer pointed to by @res->backup will
  * be reserved and validated.
  * On hardware resource shortage, this function will repeatedly evict
  * resources of the same type until the validation succeeds.
+ *
+ * Return: Zero on success, -ERESTARTSYS if interrupted, negative error code
+ * on failure.
  */
-int vmw_resource_validate(struct vmw_resource *res)
+int vmw_resource_validate(struct vmw_resource *res, bool intr)
 {
int ret;
struct vmw_resource *evict_res;
@@ -633,7 +636,7 @@ int vmw_resource_validate(struct vmw_resource *res)
write_unlock(_priv->resource_lock);
 
/* Trylock backup buffers with a NULL ticket. */
-   ret = vmw_resource_do_evict(NULL, evict_res, true);
+   ret = vmw_resource_do_evict(NULL, evict_res, intr);
if (unlikely(ret != 0)) {
write_lock(_priv->resource_lock);
list_add_tail(_res->lru_head, lru_list);
@@ -914,7 +917,7 @@ int vmw_resource_pin(struct vmw_resource *res, bool 
interruptible)
/* Do we really need to pin the MOB as well? */
vmw_bo_pin_reserved(vbo, true);
}
-   ret = vmw_resource_validate(res);
+   ret = vmw_resource_validate(res, interruptible);
if (vbo)
ttm_bo_unreserve(>base);
if (ret)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
index 5bc00eafe381..dbb58cce0987 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
@@ -479,7 +479,7 @@ int vmw_validation_res_validate(struct 
vmw_validation_context *ctx, bool intr)
struct 

[PATCH -next 01/18] drm/vmwgfx: Add a validation module v2

2018-09-26 Thread Thomas Hellstrom
Isolate the functionality needed for reservation, validation and fencing
of vmwgfx buffer objects and resources and publish an API for this.

Signed-off-by: Thomas Hellstrom 
Reviewed-by: Sinclair Yeh 
Reviewed-by: Deepak Rawat  #v1
---
 drivers/gpu/drm/vmwgfx/Makefile|   3 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.c | 659 +
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.h | 202 +
 3 files changed, 863 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
 create mode 100644 drivers/gpu/drm/vmwgfx/vmwgfx_validation.h

diff --git a/drivers/gpu/drm/vmwgfx/Makefile b/drivers/gpu/drm/vmwgfx/Makefile
index 09b2aa08363e..2d64503bf719 100644
--- a/drivers/gpu/drm/vmwgfx/Makefile
+++ b/drivers/gpu/drm/vmwgfx/Makefile
@@ -7,6 +7,7 @@ vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o 
vmwgfx_drv.o \
vmwgfx_surface.o vmwgfx_prime.o vmwgfx_mob.o vmwgfx_shader.o \
vmwgfx_cmdbuf_res.o vmwgfx_cmdbuf.o vmwgfx_stdu.o \
vmwgfx_cotable.o vmwgfx_so.o vmwgfx_binding.o vmwgfx_msg.o \
-   vmwgfx_simple_resource.o vmwgfx_va.o vmwgfx_blit.o
+   vmwgfx_simple_resource.o vmwgfx_va.o vmwgfx_blit.o \
+   vmwgfx_validation.o
 
 obj-$(CONFIG_DRM_VMWGFX) := vmwgfx.o
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
new file mode 100644
index ..5bc00eafe381
--- /dev/null
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c
@@ -0,0 +1,659 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+/**
+ *
+ * Copyright © 2018 VMware, Inc., Palo Alto, CA., USA
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **/
+#include 
+#include "vmwgfx_validation.h"
+#include "vmwgfx_drv.h"
+
+/**
+ * struct vmw_validation_bo_node - Buffer object validation metadata.
+ * @base: Metadata used for TTM reservation- and validation.
+ * @hash: A hash entry used for the duplicate detection hash table.
+ * @as_mob: Validate as mob.
+ * @cpu_blit: Validate for cpu blit access.
+ *
+ * Bit fields are used since these structures are allocated and freed in
+ * large numbers and space conservation is desired.
+ */
+struct vmw_validation_bo_node {
+   struct ttm_validate_buffer base;
+   struct drm_hash_item hash;
+   u32 as_mob : 1;
+   u32 cpu_blit : 1;
+};
+
+/**
+ * struct vmw_validation_res_node - Resource validation metadata.
+ * @head: List head for the resource validation list.
+ * @hash: A hash entry used for the duplicate detection hash table.
+ * @res: Reference counted resource pointer.
+ * @new_backup: Non ref-counted pointer to new backup buffer to be assigned
+ * to a resource.
+ * @new_backup_offset: Offset into the new backup mob for resources that can
+ * share MOBs.
+ * @no_buffer_needed: Kernel does not need to allocate a MOB during validation,
+ * the command stream provides a mob bind operation.
+ * @switching_backup: The validation process is switching backup MOB.
+ * @first_usage: True iff the resource has been seen only once in the current
+ * validation batch.
+ * @reserved: Whether the resource is currently reserved by this process.
+ * @private: Optionally additional memory for caller-private data.
+ *
+ * Bit fields are used since these structures are allocated and freed in
+ * large numbers and space conservation is desired.
+ */
+struct vmw_validation_res_node {
+   struct list_head head;
+   struct drm_hash_item hash;
+   struct vmw_resource *res;
+   struct vmw_buffer_object *new_backup;
+   unsigned long new_backup_offset;
+   u32 no_buffer_needed : 1;
+   u32 switching_backup : 1;
+   u32 first_usage : 1;
+   u32 reserved : 1;
+

Re: uvesafb: Fix URLs in the documentation

2018-09-26 Thread Bartlomiej Zolnierkiewicz

On 09/22/2018 05:45 AM, Randy Dunlap wrote:
> Hi,

Hi,

> I just noticed that the uvesafb.txt file needs to be updated
> and then I found that Adam Jackson sent a patch for it last October.
> 
> patch:
> https://marc.info/?l=linux-fbdev=150765722422257=2

I was not on Cc: so I managed to miss it somehow.. :(

> patchwork:
> https://patchwork.kernel.org/patch/9996857/

I don't use the legacy fbdev patchwork (I don't even have
access to it).

> What happened here?  anything?
> 
> Anyway, for Adam's patch:
> Reviewed-by: Randy Dunlap 

Patch queued for 4.19, thanks.

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R Institute Poland
Samsung Electronics
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] efifb: BGRT: Add nobgrt option

2018-09-26 Thread Bartlomiej Zolnierkiewicz

On 09/13/2018 08:51 AM, David Herrmann wrote:
> Hi
> 
> On Wed, Sep 12, 2018 at 11:12 AM Hans de Goede  wrote:
>>
>> In some setups restoring the BGRT logo is undesirable, allow passing
>> video=efifb:nobgrt on the kernel commandline to disable it.
>>
>> Cc: David Herrmann 
>> Reported-by: David Herrmann 
>> Signed-off-by: Hans de Goede 
>> ---
>>  drivers/video/fbdev/efifb.c | 6 ++
>>  1 file changed, 6 insertions(+)
> 
> Reviewed-by: David Herrmann 

Patch queued for 4.19, thanks.

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R Institute Poland
Samsung Electronics
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v2] drm/scheduler: remove timeout work_struct from drm_sched_job

2018-09-26 Thread Nayan Deshmukh
Hi Christian,


On Wed, Sep 26, 2018, 10:13 AM Christian König <
ckoenig.leichtzumer...@gmail.com> wrote:

> Am 26.09.2018 um 09:39 schrieb Lucas Stach:
> > Hi Nayan,
> >
> > Am Mittwoch, den 26.09.2018, 02:09 +0900 schrieb Nayan Deshmukh:
> >> having a delayed work item per job is redundant as we only need one
> >> per scheduler to track the time out the currently executing job.
> >>
> >> v2: the first element of the ring mirror list is the currently
> >> executing job so we don't need a additional variable for it
> >>
> >> Signed-off-by: Nayan Deshmukh 
> >> Suggested-by: Christian König 
> >> ---
> >>   drivers/gpu/drm/scheduler/sched_main.c | 31
> ---
> >>   include/drm/gpu_scheduler.h|  6 +++---
> >>   2 files changed, 19 insertions(+), 18 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/scheduler/sched_main.c
> b/drivers/gpu/drm/scheduler/sched_main.c
> >> index 9ca741f3a0bc..4e8505d51795 100644
> >> --- a/drivers/gpu/drm/scheduler/sched_main.c
> >> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> >> @@ -197,19 +197,15 @@ static void drm_sched_job_finish(struct
> work_struct *work)
> >>   * manages to find this job as the next job in the list, the fence
> >>   * signaled check below will prevent the timeout to be restarted.
> >>   */
> >> -cancel_delayed_work_sync(_job->work_tdr);
> >> +cancel_delayed_work_sync(>work_tdr);
> >>
> >>  spin_lock(>job_list_lock);
> >> -/* queue TDR for next job */
> >> -if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
> >> -!list_is_last(_job->node, >ring_mirror_list)) {
> >> -struct drm_sched_job *next = list_next_entry(s_job, node);
> >> -
> >> -if (!dma_fence_is_signaled(>s_fence->finished))
> >> -schedule_delayed_work(>work_tdr,
> sched->timeout);
> >> -}
> >>  /* remove job from ring_mirror_list */
> >>  list_del(_job->node);
> >> +/* queue TDR for next job */
> >> +if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
> >> +!list_empty(>ring_mirror_list))
> >> +schedule_delayed_work(>work_tdr, sched->timeout);
> >>  spin_unlock(>job_list_lock);
> >>
> >>  dma_fence_put(_job->s_fence->finished);
> >> @@ -236,16 +232,21 @@ static void drm_sched_job_begin(struct
> drm_sched_job *s_job)
> >>  if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
> >>  list_first_entry_or_null(>ring_mirror_list,
> >>   struct drm_sched_job, node) == s_job)
> >> -schedule_delayed_work(_job->work_tdr, sched->timeout);
> >> +schedule_delayed_work(>work_tdr, sched->timeout);
> >>  spin_unlock(>job_list_lock);
> >>   }
> >>
> >>   static void drm_sched_job_timedout(struct work_struct *work)
> >>   {
> >> -struct drm_sched_job *job = container_of(work, struct
> drm_sched_job,
> >> - work_tdr.work);
> >> +struct drm_gpu_scheduler *sched;
> >> +struct drm_sched_job *job;
> >> +
> >> +sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work
> );
> >> +job = list_first_entry_or_null(>ring_mirror_list,
> >> +   struct drm_sched_job, node);
> >>
> >> -job->sched->ops->timedout_job(job);
> >> +if (job)
> >> +job->sched->ops->timedout_job(job);
> > I don't think this is fully robust. Jobs are only removed from the
> > ring_mirror_list once the job_finish worker has run. If execution of
> > this worker is delayed for any reason (though it's really unlikely for
> > a delay as long as the job timeout to happen) you are blaming the wrong
> > job here.
> >
> > So I think what you need to to is find the first job in the ring mirror
> > list with an unsignaled finish fence to robustly find the stuck job.
>
> Yeah, that is a known problem I've pointed out as well.
>
> The issue is we have bug reports that this happened before the patch,
> but I'm not 100% sure how.
>
> My suggestion is to move a good part of the logic from
> drm_sched_hw_job_reset() and drm_sched_job_recovery() into
> drm_sched_job_timedout().
>
> E.g. we first call dma_fence_remove_callback() for each job and actually
> check the return value if the fence was already signaled.
>
> If we find a signaled fence we abort and add the callback back to the
> ones where we removed it.
>
> Nayan do you want to take care of this or should I take a look?
>
I can take care of it.

Regards,
Nayan

>
> Regards,
> Christian.
>
> >
> > Regards,
> > Lucas
> >
> >>   }
> >>
> >>   /**
> >> @@ -315,7 +316,7 @@ void drm_sched_job_recovery(struct
> drm_gpu_scheduler *sched)
> >>  s_job = list_first_entry_or_null(>ring_mirror_list,
> >>   struct drm_sched_job, node);
> >>  if (s_job && sched->timeout != MAX_SCHEDULE_TIMEOUT)
> >> -schedule_delayed_work(_job->work_tdr, sched->timeout);
> >> +schedule_delayed_work(>work_tdr, sched->timeout);
> >>
> 

Re: [PATCH] fbdev/omapfb: fix omapfb_memory_read infoleak

2018-09-26 Thread Bartlomiej Zolnierkiewicz

[ added dri-devel@lists.freedesktop.org to Cc: ]

On 09/12/2018 09:30 AM, Tomi Valkeinen wrote:
> OMAPFB_MEMORY_READ ioctl reads pixels from the LCD's memory and copies
> them to a userspace buffer. The code has two issues:
> 
> - The user provided width and height could be large enough to overflow
>   the calculations
> - The copy_to_user() can copy uninitialized memory to the userspace,
>   which might contain sensitive kernel information.
> 
> Fix these by limiting the width & height parameters, and only copying
> the amount of data that we actually received from the LCD.
> 
> Signed-off-by: Tomi Valkeinen 
> Reported-by: Jann Horn 
> Cc: sta...@vger.kernel.org
> Cc: secur...@kernel.org
> Cc: Will Deacon 
> Cc: Jann Horn 
> Cc: Tony Lindgren 

Patch queued for 4.19, thanks.

> ---
>  drivers/video/fbdev/omap2/omapfb/omapfb-ioctl.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/video/fbdev/omap2/omapfb/omapfb-ioctl.c 
> b/drivers/video/fbdev/omap2/omapfb/omapfb-ioctl.c
> index ef69273074ba..a3edb20ea4c3 100644
> --- a/drivers/video/fbdev/omap2/omapfb/omapfb-ioctl.c
> +++ b/drivers/video/fbdev/omap2/omapfb/omapfb-ioctl.c
> @@ -496,6 +496,9 @@ static int omapfb_memory_read(struct fb_info *fbi,
>   if (!access_ok(VERIFY_WRITE, mr->buffer, mr->buffer_size))
>   return -EFAULT;
>  
> + if (mr->w > 4096 || mr->h > 4096)
> + return -EINVAL;
> +
>   if (mr->w * mr->h * 3 > mr->buffer_size)
>   return -EINVAL;
>  
> @@ -509,7 +512,7 @@ static int omapfb_memory_read(struct fb_info *fbi,
>   mr->x, mr->y, mr->w, mr->h);
>  
>   if (r > 0) {
> - if (copy_to_user(mr->buffer, buf, mr->buffer_size))
> + if (copy_to_user(mr->buffer, buf, r))
>   r = -EFAULT;
>   }

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R Institute Poland
Samsung Electronics
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] pxa168fb: prepare the clock

2018-09-26 Thread Bartlomiej Zolnierkiewicz

[ added dri-devel@lists.freedesktop.org to Cc: ]

On 09/10/2018 02:03 PM, Lubomir Rintel wrote:

Some description (besides kernel warning itself) saying what the patch is
actually doing would be nice so I've updated the patch with:

Add missing prepare/unprepare operations for fbi->clk,
this fixes following kernel warning:

while merging it.

>   [ cut here ]
>   WARNING: CPU: 0 PID: 1 at drivers/clk/clk.c:874 clk_core_enable+0x2c/0x1b0
>   Enabling unprepared disp0_clk
>   Modules linked in:
>   CPU: 0 PID: 1 Comm: swapper Not tainted 
> 4.18.0-rc8-00032-g02b43ddd4f21-dirty #25
>   Hardware name: Marvell MMP2 (Device Tree Support)
>   [] (unwind_backtrace) from [] (show_stack+0x10/0x14)
>   [] (show_stack) from [] (__warn+0xd8/0xf0)
>   [] (__warn) from [] (warn_slowpath_fmt+0x44/0x6c)
>   [] (warn_slowpath_fmt) from [] 
> (clk_core_enable+0x2c/0x1b0)
>   [] (clk_core_enable) from [] 
> (clk_core_enable_lock+0x18/0x2c)
>   [] (clk_core_enable_lock) from [] 
> (pxa168fb_probe+0x464/0x6ac)
>   [] (pxa168fb_probe) from [] 
> (platform_drv_probe+0x48/0x94)
>   [] (platform_drv_probe) from [] 
> (driver_probe_device+0x328/0x470)
>   [] (driver_probe_device) from [] 
> (__driver_attach+0xb0/0x124)
>   [] (__driver_attach) from [] 
> (bus_for_each_dev+0x64/0xa0)
>   [] (bus_for_each_dev) from [] 
> (bus_add_driver+0x1b8/0x230)
>   [] (bus_add_driver) from [] (driver_register+0xac/0xf0)
>   [] (driver_register) from [] 
> (do_one_initcall+0xb8/0x1f0)
>   [] (do_one_initcall) from [] 
> (kernel_init_freeable+0x294/0x2e0)
>   [] (kernel_init_freeable) from [] 
> (kernel_init+0x8/0x10c)
>   [] (kernel_init) from [] (ret_from_fork+0x14/0x2c)
>   Exception stack(0xd008bfb0 to 0xd008bff8)
>   bfa0:    
> 
>   bfc0:        
> 
>   bfe0:     0013 
>   ---[ end trace c0af40f9e2ed7cb4 ]---
> 
> Signed-off-by: Lubomir Rintel 

Patch queued for 4.19, thanks.

> ---
>  drivers/video/fbdev/pxa168fb.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/fbdev/pxa168fb.c b/drivers/video/fbdev/pxa168fb.c
> index def3a501acd6..d059d04c63ac 100644
> --- a/drivers/video/fbdev/pxa168fb.c
> +++ b/drivers/video/fbdev/pxa168fb.c
> @@ -712,7 +712,7 @@ static int pxa168fb_probe(struct platform_device *pdev)
>   /*
>* enable controller clock
>*/
> - clk_enable(fbi->clk);
> + clk_prepare_enable(fbi->clk);
>  
>   pxa168fb_set_par(info);
>  
> @@ -767,7 +767,7 @@ static int pxa168fb_probe(struct platform_device *pdev)
>  failed_free_cmap:
>   fb_dealloc_cmap(>cmap);
>  failed_free_clk:
> - clk_disable(fbi->clk);
> + clk_disable_unprepare(fbi->clk);
>  failed_free_fbmem:
>   dma_free_coherent(fbi->dev, info->fix.smem_len,
>   info->screen_base, fbi->fb_start_dma);
> @@ -807,7 +807,7 @@ static int pxa168fb_remove(struct platform_device *pdev)
>   dma_free_wc(fbi->dev, PAGE_ALIGN(info->fix.smem_len),
>   info->screen_base, info->fix.smem_start);
>  
> - clk_disable(fbi->clk);
> + clk_disable_unprepare(fbi->clk);
>  
>   framebuffer_release(info);

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R Institute Poland
Samsung Electronics
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v1] drm/tegra: Detach devices from IOMMU DMA domain on arm32

2018-09-26 Thread Thierry Reding
On Sun, Aug 19, 2018 at 05:24:20PM +0300, Dmitry Osipenko wrote:
> All Tegra DRM devices are getting attached to an implicit IOMMU DMA
> domain if CONFIG_ARM_DMA_USE_IOMMU=y. Since Tegra DRM driver manages IOMMU
> by itself, the devices must be detached from the implicit domain using
> arch-specific IOMMU-API. Note that this works only for arm32 and not for
> arm64, which will remain broken if CONFIG_IOMMU_DMA is enabled.
> 
> Signed-off-by: Dmitry Osipenko 
> ---
>  drivers/gpu/drm/tegra/drm.c | 12 
>  1 file changed, 12 insertions(+)

Applied, thanks.

Thierry


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


Re: [PATCH v3] gpu: host1x: Detach Host1x from IOMMU DMA domain on arm32

2018-09-26 Thread Thierry Reding
On Thu, Aug 30, 2018 at 03:12:47AM +0300, Dmitry Osipenko wrote:
> Host1x is getting attached to an implicit IOMMU DMA domain if
> CONFIG_ARM_DMA_USE_IOMMU=y. Since Host1x driver manages IOMMU by
> itself, Host1x device must be detached from the implicit domain using
> arch-specific IOMMU-API.
> 
> Signed-off-by: Dmitry Osipenko 
> ---
> 
> Changelog:
> 
> v2: Correctly placed the detachment code, now Host1x is detached regardless
> of the firewall state.
> 
> v3: Compiles now.
> 
>  drivers/gpu/host1x/dev.c | 13 -
>  1 file changed, 12 insertions(+), 1 deletion(-)

Applied, thanks.

Thierry


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


Re: [PATCH v2] drm/tegra: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Thierry Reding
On Wed, Sep 26, 2018 at 01:56:40PM +0200, Thomas Zimmermann wrote:
> This patch unifies the naming of DRM functions for reference counting
> of struct drm_device. The resulting code is more aligned with the rest
> of the Linux kernel interfaces.
> 
> v2:
>   * rebased onto 'drm/tegra: kick out simplefb'
> 
> Signed-off-by: Thomas Zimmermann 
> ---
>  drivers/gpu/drm/tegra/drm.c | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)

Applied, thanks.

Thierry


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


[PATCH v4 4/4] drm/tinydrm: Switch from CMA to shmem buffers

2018-09-26 Thread Noralf Trønnes
This move makes tinydrm useful for more drivers. tinydrm doesn't need
continuous memory, but at the time it was convenient to use the CMA
library. The spi core can do dma on is_vmalloc() addresses making this
possible.

Cc: David Lechner 
Signed-off-by: Noralf Trønnes 
Acked-by: David Lechner 
Tested-by: David Lechner 
---

Changes since version 3:
- Use the new drm_gem_vmap() and drm_gem_vunmap() instead of directly
  calling the shmem variants.

 drivers/gpu/drm/tinydrm/Kconfig|  2 +-
 drivers/gpu/drm/tinydrm/core/tinydrm-core.c| 92 +++---
 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c |  5 ++
 drivers/gpu/drm/tinydrm/ili9225.c  | 14 ++--
 drivers/gpu/drm/tinydrm/ili9341.c  |  6 +-
 drivers/gpu/drm/tinydrm/mi0283qt.c |  6 +-
 drivers/gpu/drm/tinydrm/mipi-dbi.c | 38 ---
 drivers/gpu/drm/tinydrm/repaper.c  | 24 +++
 drivers/gpu/drm/tinydrm/st7586.c   | 15 +++--
 drivers/gpu/drm/tinydrm/st7735r.c  |  6 +-
 include/drm/tinydrm/tinydrm.h  | 36 +++---
 11 files changed, 91 insertions(+), 153 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index 16f4b5c91f1b..aa0cabba5ace 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -2,7 +2,7 @@ menuconfig DRM_TINYDRM
tristate "Support for simple displays"
depends on DRM
select DRM_KMS_HELPER
-   select DRM_KMS_CMA_HELPER
+   select DRM_GEM_SHMEM_HELPER
help
  Choose this option if you have a tinydrm supported display.
  If M is selected the module will be called tinydrm.
diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-core.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-core.c
index 255341ee4eb9..38ba361d1af2 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-core.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-core.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -23,7 +24,7 @@
  *
  * It is based on _simple_display_pipe coupled with a _connector which
  * has only one fixed _display_mode. The framebuffers are backed by the
- * cma helper and have support for framebuffer flushing (dirty).
+ * shmem buffers and have support for framebuffer flushing (dirty).
  * fbdev support is also included.
  *
  */
@@ -37,84 +38,41 @@
  */
 
 /**
- * tinydrm_gem_cma_prime_import_sg_table - Produce a CMA GEM object from
- * another driver's scatter/gather table of pinned pages
- * @drm: DRM device to import into
- * @attach: DMA-BUF attachment
- * @sgt: Scatter/gather table of pinned pages
+ * tinydrm_fb_destroy - Destroy framebuffer
+ * @fb: Framebuffer
  *
- * This function imports a scatter/gather table exported via DMA-BUF by
- * another driver using drm_gem_cma_prime_import_sg_table(). It sets the
- * kernel virtual address on the CMA object. Drivers should use this as their
- * _driver->gem_prime_import_sg_table callback if they need the virtual
- * address. tinydrm_gem_cma_free_object() should be used in combination with
- * this function.
- *
- * Returns:
- * A pointer to a newly created GEM object or an ERR_PTR-encoded negative
- * error code on failure.
+ * This function unmaps the virtual address on the backing buffer and destroys 
the framebuffer.
+ * Drivers should use this as their _framebuffer_funcs->destroy callback.
  */
-struct drm_gem_object *
-tinydrm_gem_cma_prime_import_sg_table(struct drm_device *drm,
- struct dma_buf_attachment *attach,
- struct sg_table *sgt)
+void tinydrm_fb_destroy(struct drm_framebuffer *fb)
 {
-   struct drm_gem_cma_object *cma_obj;
-   struct drm_gem_object *obj;
-   void *vaddr;
+   struct drm_gem_object *gem = drm_gem_fb_get_obj(fb, 0);
+   struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(gem);
 
-   vaddr = dma_buf_vmap(attach->dmabuf);
-   if (!vaddr) {
-   DRM_ERROR("Failed to vmap PRIME buffer\n");
-   return ERR_PTR(-ENOMEM);
-   }
-
-   obj = drm_gem_cma_prime_import_sg_table(drm, attach, sgt);
-   if (IS_ERR(obj)) {
-   dma_buf_vunmap(attach->dmabuf, vaddr);
-   return obj;
-   }
-
-   cma_obj = to_drm_gem_cma_obj(obj);
-   cma_obj->vaddr = vaddr;
-
-   return obj;
+   drm_gem_vunmap(gem, shmem->vaddr);
+   drm_gem_fb_destroy(fb);
 }
-EXPORT_SYMBOL(tinydrm_gem_cma_prime_import_sg_table);
-
-/**
- * tinydrm_gem_cma_free_object - Free resources associated with a CMA GEM
- *   object
- * @gem_obj: GEM object to free
- *
- * This function frees the backing memory of the CMA GEM object, cleans up the
- * GEM object state and frees the memory used to store the object itself using
- * drm_gem_cma_free_object(). It also handles PRIME buffers which has the 
kernel
- * virtual address set 

[PATCH v4 0/4] drm: Add shmem GEM library

2018-09-26 Thread Noralf Trønnes
This patchset adds a library for shmem backed GEM objects and makes use
of it in tinydrm.

Thomas gave me some feedback that made me realise that the cachemodes
pattern I had picked up from some other drivers didn't apply to shmem
buffers in the way I though it did. So it's removed.

I recently did an RFC to see if it made sense to add a vtable to GEM
objects. Daniel welcomed that so I've included it here.

Noralf.

Changes since version 3:
- Drop cache modes (Thomas Hellstrom)
- Add a GEM object attached vtable

Changes since version 2:
- Grammar (Sam Ravnborg)
- s/drm_gem_shmem_put_pages_unlocked/drm_gem_shmem_put_pages_locked/
(Sam Ravnborg)
- Add debug ouput in error path (Sam Ravnborg)

Changes since version 1:
- Fix missing argument in docs (kbuild test robot)
- Fix: sparse: expression using sizeof(void) (kbuild test robot)
- Rebasing gave a new checkpatch warning, so I changed to bitfields:
CHECK: Avoid using bool structure members because of possible alignment
issues - see: https://lkml.org/lkml/2017/11/21/384
#834: FILE: include/drm/drm_gem_shmem_helper.h:84:
+   bool pages_mark_dirty_on_put;
#841: FILE: include/drm/drm_gem_shmem_helper.h:91:
+   bool pages_mark_accessed_on_put;

Noralf Trønnes (4):
  drm/driver: Add defaults for .gem_prime_export/import callbacks
  drm/gem: Add drm_gem_object_funcs
  drm: Add library for shmem backed GEM objects
  drm/tinydrm: Switch from CMA to shmem buffers

 Documentation/gpu/drm-kms-helpers.rst  |  12 +
 Documentation/gpu/todo.rst |   7 +
 drivers/gpu/drm/Kconfig|   6 +
 drivers/gpu/drm/Makefile   |   1 +
 drivers/gpu/drm/drm_client.c   |  12 +-
 drivers/gpu/drm/drm_fb_helper.c|   8 +-
 drivers/gpu/drm/drm_gem.c  | 109 -
 drivers/gpu/drm/drm_gem_shmem_helper.c | 586 +
 drivers/gpu/drm/drm_prime.c|  50 ++-
 drivers/gpu/drm/tinydrm/Kconfig|   2 +-
 drivers/gpu/drm/tinydrm/core/tinydrm-core.c|  92 ++--
 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c |   5 +
 drivers/gpu/drm/tinydrm/ili9225.c  |  14 +-
 drivers/gpu/drm/tinydrm/ili9341.c  |   6 +-
 drivers/gpu/drm/tinydrm/mi0283qt.c |   6 +-
 drivers/gpu/drm/tinydrm/mipi-dbi.c |  38 +-
 drivers/gpu/drm/tinydrm/repaper.c  |  24 +-
 drivers/gpu/drm/tinydrm/st7586.c   |  15 +-
 drivers/gpu/drm/tinydrm/st7735r.c  |   6 +-
 include/drm/drm_drv.h  |   4 +
 include/drm/drm_gem.h  | 140 ++
 include/drm/drm_gem_shmem_helper.h | 153 +++
 include/drm/tinydrm/tinydrm.h  |  36 +-
 23 files changed, 1139 insertions(+), 193 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_gem_shmem_helper.c
 create mode 100644 include/drm/drm_gem_shmem_helper.h

-- 
2.15.1

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


[PATCH v4 3/4] drm: Add library for shmem backed GEM objects

2018-09-26 Thread Noralf Trønnes
This adds a library for shmem backed GEM objects.

Signed-off-by: Noralf Trønnes 
---

Changes since version 3:
- Drop cache modes (Thomas Hellstrom)
- Add a GEM attached vtable

 Documentation/gpu/drm-kms-helpers.rst  |  12 +
 drivers/gpu/drm/Kconfig|   6 +
 drivers/gpu/drm/Makefile   |   1 +
 drivers/gpu/drm/drm_gem_shmem_helper.c | 586 +
 include/drm/drm_gem_shmem_helper.h | 153 +
 5 files changed, 758 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_gem_shmem_helper.c
 create mode 100644 include/drm/drm_gem_shmem_helper.h

diff --git a/Documentation/gpu/drm-kms-helpers.rst 
b/Documentation/gpu/drm-kms-helpers.rst
index f9cfcdcdf024..bc24b1b5216a 100644
--- a/Documentation/gpu/drm-kms-helpers.rst
+++ b/Documentation/gpu/drm-kms-helpers.rst
@@ -326,3 +326,15 @@ Legacy CRTC/Modeset Helper Functions Reference
 
 .. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c
:export:
+
+SHMEM GEM Helper Reference
+==
+
+.. kernel-doc:: drivers/gpu/drm/drm_gem_shmem_helper.c
+   :doc: overview
+
+.. kernel-doc:: include/drm/drm_gem_shmem_helper.h
+   :internal:
+
+.. kernel-doc:: drivers/gpu/drm/drm_gem_shmem_helper.c
+   :export:
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index cb88528e7b10..db588ae44bcc 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -157,6 +157,12 @@ config DRM_KMS_CMA_HELPER
help
  Choose this if you need the KMS CMA helper functions
 
+config DRM_GEM_SHMEM_HELPER
+   bool
+   depends on DRM
+   help
+ Choose this if you need the GEM shmem helper functions
+
 config DRM_VM
bool
depends on DRM && MMU
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index bc6a16a3c36e..13777f22dc25 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -25,6 +25,7 @@ drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o
 drm-$(CONFIG_DRM_VM) += drm_vm.o
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
+drm-$(CONFIG_DRM_GEM_SHMEM_HELPER) += drm_gem_shmem_helper.o
 drm-$(CONFIG_PCI) += ati_pcigart.o
 drm-$(CONFIG_DRM_PANEL) += drm_panel.o
 drm-$(CONFIG_OF) += drm_of.o
diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c 
b/drivers/gpu/drm/drm_gem_shmem_helper.c
new file mode 100644
index ..7471856d34ac
--- /dev/null
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -0,0 +1,586 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2018 Noralf Trønnes
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * DOC: overview
+ *
+ * This library provides helpers for GEM objects backed by shmem buffers
+ * allocated using anonymous pageable memory.
+ */
+
+static const struct drm_gem_object_funcs drm_gem_shmem_funcs = {
+   .free = drm_gem_shmem_free_object,
+   .print_info = drm_gem_shmem_print_info,
+   .pin = drm_gem_shmem_pin,
+   .unpin = drm_gem_shmem_unpin,
+   .get_sg_table = drm_gem_shmem_get_sg_table,
+   .vmap = drm_gem_shmem_vmap,
+   .vunmap = drm_gem_shmem_vunmap,
+   .prime_mmap = drm_gem_shmem_prime_mmap,
+   .vm_ops = _gem_shmem_vm_ops,
+};
+
+/**
+ * drm_gem_shmem_create - Allocate an object with the given size
+ * @dev: DRM device
+ * @size: Size of the object to allocate
+ *
+ * This function creates a shmem GEM object.
+ *
+ * Returns:
+ * A struct drm_gem_shmem_object * on success or an ERR_PTR()-encoded negative
+ * error code on failure.
+ */
+struct drm_gem_shmem_object *drm_gem_shmem_create(struct drm_device *dev, 
size_t size)
+{
+   struct drm_gem_shmem_object *shmem;
+   struct drm_gem_object *obj;
+   int ret;
+
+   size = PAGE_ALIGN(size);
+
+   if (dev->driver->gem_create_object)
+   obj = dev->driver->gem_create_object(dev, size);
+   else
+   obj = kzalloc(sizeof(*shmem), GFP_KERNEL);
+   if (!obj)
+   return ERR_PTR(-ENOMEM);
+
+   if (!obj->funcs)
+   obj->funcs = _gem_shmem_funcs;
+
+   ret = drm_gem_object_init(dev, obj, size);
+   if (ret)
+   goto err_free;
+
+   ret = drm_gem_create_mmap_offset(obj);
+   if (ret)
+   goto err_release;
+
+   shmem = to_drm_gem_shmem_obj(obj);
+   mutex_init(>pages_lock);
+   mutex_init(>vmap_lock);
+
+   return shmem;
+
+err_release:
+   drm_gem_object_release(obj);
+err_free:
+   kfree(shmem);
+
+   return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(drm_gem_shmem_create);
+
+/**
+ * drm_gem_shmem_free_object - Free resources associated with a shmem GEM 
object
+ * @obj: GEM object to free
+ *
+ * This function cleans up the GEM object state and frees the memory used to
+ * store the object itself.
+ */
+void drm_gem_shmem_free_object(struct drm_gem_object *obj)
+{
+   struct drm_gem_shmem_object *shmem = 

[PATCH v4 2/4] drm/gem: Add drm_gem_object_funcs

2018-09-26 Thread Noralf Trønnes
This adds an optional function table on GEM objects.
The main benefit is for drivers that support more than one type of
memory (shmem,vram,cma) for their buffers depending on the hardware it
runs on. With the callbacks attached to the GEM object itself, it is
easier to have core helpers for the the various buffer types. The driver
only has to make the decision about buffer type on GEM object creation
and all other callbacks can be handled by the chosen helper.

drm_driver->gem_prime_res_obj has not been added since there's a todo to
put a reservation_object into drm_gem_object.

Signed-off-by: Noralf Trønnes 
---

Changes since RFC:
- drm_gem_object_funcs.map -> .prime_map let it only do PRIME mmap like
  the function it superseeds (Daniel Vetter)
- Flip around the if ladders and make obj->funcs the first choice
  highlighting the fact that this the new default way of doing it
  (Daniel Vetter)

 drivers/gpu/drm/drm_client.c|  12 ++--
 drivers/gpu/drm/drm_fb_helper.c |   8 ++-
 drivers/gpu/drm/drm_gem.c   | 109 ---
 drivers/gpu/drm/drm_prime.c |  42 ++--
 include/drm/drm_gem.h   | 140 
 5 files changed, 272 insertions(+), 39 deletions(-)

diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
index 17d9a64e885e..eca7331762e4 100644
--- a/drivers/gpu/drm/drm_client.c
+++ b/drivers/gpu/drm/drm_client.c
@@ -80,8 +80,7 @@ int drm_client_new(struct drm_device *dev, struct 
drm_client_dev *client,
 {
int ret;
 
-   if (!drm_core_check_feature(dev, DRIVER_MODESET) ||
-   !dev->driver->dumb_create || !dev->driver->gem_prime_vmap)
+   if (!drm_core_check_feature(dev, DRIVER_MODESET) || 
!dev->driver->dumb_create)
return -EOPNOTSUPP;
 
if (funcs && !try_module_get(funcs->owner))
@@ -212,8 +211,7 @@ static void drm_client_buffer_delete(struct 
drm_client_buffer *buffer)
 {
struct drm_device *dev = buffer->client->dev;
 
-   if (buffer->vaddr && dev->driver->gem_prime_vunmap)
-   dev->driver->gem_prime_vunmap(buffer->gem, buffer->vaddr);
+   drm_gem_vunmap(buffer->gem, buffer->vaddr);
 
if (buffer->gem)
drm_gem_object_put_unlocked(buffer->gem);
@@ -266,9 +264,9 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 
width, u32 height, u
 * fd_install step out of the driver backend hooks, to make that
 * final step optional for internal users.
 */
-   vaddr = dev->driver->gem_prime_vmap(obj);
-   if (!vaddr) {
-   ret = -ENOMEM;
+   vaddr = drm_gem_vmap(obj);
+   if (IS_ERR(vaddr)) {
+   ret = PTR_ERR(vaddr);
goto err_delete;
}
 
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index bf2190c5add5..0af405beceda 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -3010,9 +3011,12 @@ static void drm_fbdev_fb_destroy(struct fb_info *info)
 static int drm_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
struct drm_fb_helper *fb_helper = info->par;
+   struct drm_gem_object *obj = fb_helper->buffer->gem;
 
-   if (fb_helper->dev->driver->gem_prime_mmap)
-   return 
fb_helper->dev->driver->gem_prime_mmap(fb_helper->buffer->gem, vma);
+   if (obj->funcs && obj->funcs->prime_mmap)
+   return obj->funcs->prime_mmap(obj, vma);
+   else if (obj->dev->driver->gem_prime_mmap)
+   return obj->dev->driver->gem_prime_mmap(obj, vma);
else
return -ENODEV;
 }
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 512078ebd97b..dcea6f8229a4 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -257,7 +257,9 @@ drm_gem_object_release_handle(int id, void *ptr, void *data)
struct drm_gem_object *obj = ptr;
struct drm_device *dev = obj->dev;
 
-   if (dev->driver->gem_close_object)
+   if (obj->funcs && obj->funcs->close)
+   obj->funcs->close(obj, file_priv);
+   else if (dev->driver->gem_close_object)
dev->driver->gem_close_object(obj, file_priv);
 
if (drm_core_check_feature(dev, DRIVER_PRIME))
@@ -410,7 +412,11 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
if (ret)
goto err_remove;
 
-   if (dev->driver->gem_open_object) {
+   if (obj->funcs && obj->funcs->open) {
+   ret = obj->funcs->open(obj, file_priv);
+   if (ret)
+   goto err_revoke;
+   } else if (dev->driver->gem_open_object) {
ret = dev->driver->gem_open_object(obj, file_priv);
if (ret)
goto err_revoke;
@@ -835,7 +841,9 @@ drm_gem_object_free(struct kref *kref)
 

[PATCH v4 1/4] drm/driver: Add defaults for .gem_prime_export/import callbacks

2018-09-26 Thread Noralf Trønnes
The majority of drivers use drm_gem_prime_export() and
drm_gem_prime_import() for these callbacks so let's make them the
default.

Signed-off-by: Noralf Trønnes 
---
 Documentation/gpu/todo.rst  |  7 +++
 drivers/gpu/drm/drm_prime.c | 10 --
 include/drm/drm_drv.h   |  4 
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
index 77c2b3c25565..39748e22dea8 100644
--- a/Documentation/gpu/todo.rst
+++ b/Documentation/gpu/todo.rst
@@ -234,6 +234,13 @@ efficient.
 
 Contact: Daniel Vetter
 
+Defaults for .gem_prime_import and export
+-
+
+Most drivers don't need to set drm_driver->gem_prime_import and
+->gem_prime_export now that drm_gem_prime_import() and drm_gem_prime_export()
+are the default.
+
 Core refactorings
 =
 
diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 3f0205fc0a1a..6721571749ff 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -559,7 +559,10 @@ static struct dma_buf *export_and_register_object(struct 
drm_device *dev,
return dmabuf;
}
 
-   dmabuf = dev->driver->gem_prime_export(dev, obj, flags);
+   if (dev->driver->gem_prime_export)
+   dmabuf = dev->driver->gem_prime_export(dev, obj, flags);
+   else
+   dmabuf = drm_gem_prime_export(dev, obj, flags);
if (IS_ERR(dmabuf)) {
/* normally the created dma-buf takes ownership of the ref,
 * but if that fails then drop the ref
@@ -792,7 +795,10 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 
/* never seen this one, need to import */
mutex_lock(>object_name_lock);
-   obj = dev->driver->gem_prime_import(dev, dma_buf);
+   if (dev->driver->gem_prime_import)
+   obj = dev->driver->gem_prime_import(dev, dma_buf);
+   else
+   obj = drm_gem_prime_import(dev, dma_buf);
if (IS_ERR(obj)) {
ret = PTR_ERR(obj);
goto out_unlock;
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index 8830e3de3a86..1162145f7f68 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -471,6 +471,8 @@ struct drm_driver {
 * @gem_prime_export:
 *
 * export GEM -> dmabuf
+*
+* This defaults to drm_gem_prime_export() if not set.
 */
struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
struct drm_gem_object *obj, int flags);
@@ -478,6 +480,8 @@ struct drm_driver {
 * @gem_prime_import:
 *
 * import dmabuf -> GEM
+*
+* This defaults to drm_gem_prime_import() if not set.
 */
struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
struct dma_buf *dma_buf);
-- 
2.15.1

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


Re: [PATCH] drm/syncobj: Don't leak fences when WAIT_FOR_SUBMIT is set

2018-09-26 Thread Sean Paul
On Wed, Sep 26, 2018 at 02:17:03AM -0500, Jason Ekstrand wrote:
> We attempt to get fences earlier in the hopes that everything will
> already have fences and no callbacks will be needed.  If we do succeed
> in getting a fence, getting one a second time will result in a duplicate
> ref with no unref.  This is causing memory leaks in Vulkan applications
> that create a lot of fences; playing for a few hours can, apparently,
> bring down the system.
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107899
> Signed-off-by: Jason Ekstrand 

Pushed to drm-misc-fixes, thanks!

Sean

> Cc: sta...@vger.kernel.org
> ---
>  drivers/gpu/drm/drm_syncobj.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index adb3cb27d31e..759278fef35a 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -97,6 +97,8 @@ static int drm_syncobj_fence_get_or_add_callback(struct 
> drm_syncobj *syncobj,
>  {
>   int ret;
>  
> + WARN_ON(*fence);
> +
>   *fence = drm_syncobj_fence_get(syncobj);
>   if (*fence)
>   return 1;
> @@ -743,6 +745,9 @@ static signed long drm_syncobj_array_wait_timeout(struct 
> drm_syncobj **syncobjs,
>  
>   if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
>   for (i = 0; i < count; ++i) {
> + if (entries[i].fence)
> + continue;
> +
>   drm_syncobj_fence_get_or_add_callback(syncobjs[i],
> [i].fence,
> 
> [i].syncobj_cb,
> -- 
> 2.17.1
> 
> ___
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Sean Paul, Software Engineer, Google / Chromium OS
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] gpu: host1x: Remove redundant of_dma_configure() call

2018-09-26 Thread Robin Murphy

On 26/09/18 15:13, Thierry Reding wrote:

On Wed, Sep 26, 2018 at 04:10:54PM +0200, Thierry Reding wrote:

On Wed, Sep 12, 2018 at 05:47:54PM +0100, Robin Murphy wrote:

Now that the Host1x bus_type implements a .dma_configure callback,
subdevices should automatically get configured for DMA as their drivers
bind, so there's no need to also force it at device creation time.

CC: Thierry Reding 
CC: Mikko Perttunen 
Signed-off-by: Robin Murphy 
---

I *believe* my reasoning is correct here, but please shout if it's not.

  drivers/gpu/host1x/bus.c | 2 --
  1 file changed, 2 deletions(-)


Applied, thanks.


Actually I was a little too quick on the trigger there. I don't think we
can remove this here because the of_dma_configure() in this call
configures the logical "compound" child device, whereas the
.dma_configure callback configures the physical device.


Right, that's what I couldn't quite get my head around - I have the 
impression that the logical devices belong to host1x_bus_type and the 
physical ones to platform_bus_type, and thus each should be covered by 
the respective .dma_configure implementations, but I always end up 
getting lost and confused in Host1x, and having no hardware to hand to 
run easy tests on doesn't help much either.


What I'm really trying to do here is minimise the potential impact of a 
possible future patch mucking with of_dma_configure()'s interface, so 
it's not the end of the world if this call ends up staying, it just 
means I might be after one more ack at some point ;)


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


[PATCH] DRM: VBLANK: provide valid timestamp for EVENT_FLIP

2018-09-26 Thread Eugeniy Paltsev
If driver/HW doesn't support vblank functionality (for example
UDL driver, ARCPGU driver, ...) we always have vblank->time == 0.
In result we always provide zero timestamp for
DRM_EVENT_FLIP_COMPLETE. This breaks userspace apps (for example
weston) which relies on timestamp value.

Setup time to provide valid timestamp for DRM_EVENT_FLIP_COMPLETE
event.

Cc: sta...@vger.kernel.org
Signed-off-by: Eugeniy Paltsev 
---
 drivers/gpu/drm/drm_vblank.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 28cdcf76b6f9..0d19aca48782 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -911,6 +911,15 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 
if (dev->num_crtcs > 0) {
seq = drm_vblank_count_and_time(dev, pipe, );
+
+   /*
+* If driver/HW doesn't support vblank functionality we
+* always have vblank->time == 0. Setup time to provide valid
+* timestamp for DRM_EVENT_FLIP_COMPLETE event.
+*/
+   if (!now && e->event.base.type == DRM_EVENT_FLIP_COMPLETE)
+   now = ktime_get();
+
} else {
seq = 0;
 
-- 
2.14.4

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


Re: [PATCH] MAINTAINERS: Move fsl-dcu driver to drm-misc tree

2018-09-26 Thread Stefan Agner
On 26.09.2018 15:39, Sean Paul wrote:
> On Wed, Sep 26, 2018 at 02:50:34PM +0200, Stefan Agner wrote:
>> The driver is mostly in maintenance mode.
> 
> Is the status still Supported, then?
> 

Yeah Supported as defined in MAINTAINERS is still accurate. Its just
that we do not add features at that point.

>> Using drm-misc is a
>> good fit and should make maintenance a bit easier.
>>
>> Signed-off-by: Stefan Agner 
> 
> Acked-by: Sean Paul 
> 

Thanks.

--
Stefan

>> ---
>>  MAINTAINERS | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 02a39617ec82..6646a3d098a1 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -4822,6 +4822,7 @@ F: drivers/gpu/drm/fsl-dcu/
>>  F:  Documentation/devicetree/bindings/display/fsl,dcu.txt
>>  F:  Documentation/devicetree/bindings/display/fsl,tcon.txt
>>  F:  Documentation/devicetree/bindings/display/panel/nec,nl4827hc19-05b.txt
>> +T:  git git://anongit.freedesktop.org/drm/drm-misc
>>
>>  DRM DRIVERS FOR FREESCALE IMX
>>  M:  Philipp Zabel 
>> --
>> 2.19.0
>>
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] gpu: host1x: Remove redundant of_dma_configure() call

2018-09-26 Thread Thierry Reding
On Wed, Sep 26, 2018 at 04:10:54PM +0200, Thierry Reding wrote:
> On Wed, Sep 12, 2018 at 05:47:54PM +0100, Robin Murphy wrote:
> > Now that the Host1x bus_type implements a .dma_configure callback,
> > subdevices should automatically get configured for DMA as their drivers
> > bind, so there's no need to also force it at device creation time.
> > 
> > CC: Thierry Reding 
> > CC: Mikko Perttunen 
> > Signed-off-by: Robin Murphy 
> > ---
> > 
> > I *believe* my reasoning is correct here, but please shout if it's not.
> > 
> >  drivers/gpu/host1x/bus.c | 2 --
> >  1 file changed, 2 deletions(-)
> 
> Applied, thanks.

Actually I was a little too quick on the trigger there. I don't think we
can remove this here because the of_dma_configure() in this call
configures the logical "compound" child device, whereas the
.dma_configure callback configures the physical device.

Thierry


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


Re: [PATCH] gpu: host1x: Remove redundant of_dma_configure() call

2018-09-26 Thread Thierry Reding
On Wed, Sep 12, 2018 at 05:47:54PM +0100, Robin Murphy wrote:
> Now that the Host1x bus_type implements a .dma_configure callback,
> subdevices should automatically get configured for DMA as their drivers
> bind, so there's no need to also force it at device creation time.
> 
> CC: Thierry Reding 
> CC: Mikko Perttunen 
> Signed-off-by: Robin Murphy 
> ---
> 
> I *believe* my reasoning is correct here, but please shout if it's not.
> 
>  drivers/gpu/host1x/bus.c | 2 --
>  1 file changed, 2 deletions(-)

Applied, thanks.

Thierry


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


Re: [PATCH] MAINTAINERS: Move fsl-dcu driver to drm-misc tree

2018-09-26 Thread Sean Paul
On Wed, Sep 26, 2018 at 02:50:34PM +0200, Stefan Agner wrote:
> The driver is mostly in maintenance mode. 

Is the status still Supported, then?

> Using drm-misc is a
> good fit and should make maintenance a bit easier.
> 
> Signed-off-by: Stefan Agner 

Acked-by: Sean Paul 

> ---
>  MAINTAINERS | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 02a39617ec82..6646a3d098a1 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -4822,6 +4822,7 @@ F:  drivers/gpu/drm/fsl-dcu/
>  F:   Documentation/devicetree/bindings/display/fsl,dcu.txt
>  F:   Documentation/devicetree/bindings/display/fsl,tcon.txt
>  F:   Documentation/devicetree/bindings/display/panel/nec,nl4827hc19-05b.txt
> +T:   git git://anongit.freedesktop.org/drm/drm-misc
>  
>  DRM DRIVERS FOR FREESCALE IMX
>  M:   Philipp Zabel 
> -- 
> 2.19.0
> 

-- 
Sean Paul, Software Engineer, Google / Chromium OS
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [RESEND PATCH] drm/udl: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Sean Paul
On Wed, Sep 26, 2018 at 02:02:12PM +0200, Thomas Zimmermann wrote:
> This patch unifies the naming of DRM functions for reference counting
> of struct drm_device. The resulting code is more aligned with the rest
> of the Linux kernel interfaces.
> 
> Signed-off-by: Thomas Zimmermann 

Applied to drm-misc-next.

Thanks for your patch!

Sean

> ---
>  drivers/gpu/drm/udl/udl_drv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c
> index 9ef515df724b..a63e3011e971 100644
> --- a/drivers/gpu/drm/udl/udl_drv.c
> +++ b/drivers/gpu/drm/udl/udl_drv.c
> @@ -94,7 +94,7 @@ static int udl_usb_probe(struct usb_interface *interface,
>   return 0;
> 
>  err_free:
> - drm_dev_unref(dev);
> + drm_dev_put(dev);
>   return r;
>  }
> 
> --
> 2.19.0
> 

-- 
Sean Paul, Software Engineer, Google / Chromium OS
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] drm/omap: fix use of freed memory

2018-09-26 Thread Laurent Pinchart
Hi Tomi,

Thank you for the patch.

On Wednesday, 26 September 2018 13:05:59 EEST Tomi Valkeinen wrote:
> omap_connector_destroy() does:
> 
> kfree(omap_connector);
> omapdss_device_put(omap_connector->output);
> omapdss_device_put(omap_connector->display);
> 
> Fix this by moving the kfree after the omapdss_device_puts.
> 
> This bug was introduced in 949ea2ef3fed4e1d0f9b80ec21ed81a9833ac248
> 
> Signed-off-by: Tomi Valkeinen 

Reviewed-by: Laurent Pinchart 

Sorry for introducing the bug in the first place.

> ---
>  drivers/gpu/drm/omapdrm/omap_connector.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/omapdrm/omap_connector.c
> b/drivers/gpu/drm/omapdrm/omap_connector.c index 98f5ca29444a..b81302c4bf9e
> 100644
> --- a/drivers/gpu/drm/omapdrm/omap_connector.c
> +++ b/drivers/gpu/drm/omapdrm/omap_connector.c
> @@ -164,10 +164,11 @@ static void omap_connector_destroy(struct
> drm_connector *connector)
> 
>   drm_connector_unregister(connector);
>   drm_connector_cleanup(connector);
> - kfree(omap_connector);
> 
>   omapdss_device_put(omap_connector->output);
>   omapdss_device_put(omap_connector->display);
> +
> + kfree(omap_connector);
>  }
> 
>  #define MAX_EDID  512

-- 
Regards,

Laurent Pinchart



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


Re: [RESEND PATCH] drm/shmobile: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Laurent Pinchart
Hi Thomas,

On Wednesday, 26 September 2018 15:26:38 EEST Thomas Zimmermann wrote:
> Hi,
> 
> thanks for reviewing the patch and the one for rcar-du. Please also add
> them to your tree.

I took both patches in my tree. Thank you.

> Am 26.09.18 um 14:14 schrieb Kieran Bingham:
> > On 26/09/18 12:55, Thomas Zimmermann wrote:
> >> This patch unifies the naming of DRM functions for reference counting
> >> of struct drm_device. The resulting code is more aligned with the rest
> >> of the Linux kernel interfaces.
> >> 
> >> Signed-off-by: Thomas Zimmermann 
> >> Reviewed-by: Simon Horman 
> > 
> > Reviewed-by: Kieran Bingham 
> > 
> >> ---
> >> 
> >>  drivers/gpu/drm/shmobile/shmob_drm_drv.c | 4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >> 
> >> diff --git a/drivers/gpu/drm/shmobile/shmob_drm_drv.c
> >> b/drivers/gpu/drm/shmobile/shmob_drm_drv.c index
> >> 6ececad6f845..8554102a6ead 100644
> >> --- a/drivers/gpu/drm/shmobile/shmob_drm_drv.c
> >> +++ b/drivers/gpu/drm/shmobile/shmob_drm_drv.c
> >> @@ -194,7 +194,7 @@ static int shmob_drm_remove(struct platform_device
> >> *pdev)
> >>drm_kms_helper_poll_fini(ddev);
> >>drm_mode_config_cleanup(ddev);
> >>drm_irq_uninstall(ddev);
> >> -  drm_dev_unref(ddev);
> >> +  drm_dev_put(ddev);
> >> 
> >>return 0;
> >>  }
> >> 
> >> @@ -290,7 +290,7 @@ static int shmob_drm_probe(struct platform_device
> >> *pdev)
> >>drm_kms_helper_poll_fini(ddev);
> >>drm_mode_config_cleanup(ddev);
> >>  
> >>  err_free_drm_dev:
> >> -  drm_dev_unref(ddev);
> >> +  drm_dev_put(ddev);
> >>return ret;
> >>  }
> >> 

-- 
Regards,

Laurent Pinchart



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


[PATCH] MAINTAINERS: Move fsl-dcu driver to drm-misc tree

2018-09-26 Thread Stefan Agner
The driver is mostly in maintenance mode. Using drm-misc is a
good fit and should make maintenance a bit easier.

Signed-off-by: Stefan Agner 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 02a39617ec82..6646a3d098a1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4822,6 +4822,7 @@ F:drivers/gpu/drm/fsl-dcu/
 F: Documentation/devicetree/bindings/display/fsl,dcu.txt
 F: Documentation/devicetree/bindings/display/fsl,tcon.txt
 F: Documentation/devicetree/bindings/display/panel/nec,nl4827hc19-05b.txt
+T: git git://anongit.freedesktop.org/drm/drm-misc
 
 DRM DRIVERS FOR FREESCALE IMX
 M: Philipp Zabel 
-- 
2.19.0

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


Re: [PATCH] drm/rockchip: vop: add rk3188 hs_start interrupt as dsp_hold equivalent

2018-09-26 Thread Sandy Huang

Hi heiko,
nice solution.

Reviewed-by: Sandy Huang 

在 2018/9/23 20:37, Heiko Stuebner 写道:

The hs_start interrupt on rk3188 fires at the start of a new frame, so
serves essentially the same purpose as the dsp_hold_valid irq in checking
when the last frame got delivered when going to standby. So define it
to fix a hang on atomic_disable of the vop because the completion never
really completed before.

Fixes: 428e15cc41e3 ("drm/rockchip: vop: add rk3188 vop definitions")
Signed-off-by: Heiko Stuebner 
---
  drivers/gpu/drm/rockchip/rockchip_vop_reg.c | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c 
b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
index c482da41bb5d..226bb2a1720e 100644
--- a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
+++ b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
@@ -465,7 +465,11 @@ static const struct vop_win_data rk3188_vop_win_data[] = {
  };
  
  static const int rk3188_vop_intrs[] = {

-   0,
+   /*
+* hs_start interrupt fires at frame-start, so serves
+* the same purpose as dsp_hold in the driver.
+*/
+   DSP_HOLD_VALID_INTR,
FS_INTR,
LINE_FLAG_INTR,
BUS_ERROR_INTR,



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


Re: [PATCH] drm/rockchip: vop: add rk3188 hs_start interrupt as dsp_hold equivalent

2018-09-26 Thread Sandy Huang

Hi heiko,
nice solution.

Reviewed-by: Sandy Huang 

在 2018/9/23 20:37, Heiko Stuebner 写道:

The hs_start interrupt on rk3188 fires at the start of a new frame, so
serves essentially the same purpose as the dsp_hold_valid irq in checking
when the last frame got delivered when going to standby. So define it
to fix a hang on atomic_disable of the vop because the completion never
really completed before.

Fixes: 428e15cc41e3 ("drm/rockchip: vop: add rk3188 vop definitions")
Signed-off-by: Heiko Stuebner 
---
  drivers/gpu/drm/rockchip/rockchip_vop_reg.c | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c 
b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
index c482da41bb5d..226bb2a1720e 100644
--- a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
+++ b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
@@ -465,7 +465,11 @@ static const struct vop_win_data rk3188_vop_win_data[] = {
  };
  
  static const int rk3188_vop_intrs[] = {

-   0,
+   /*
+* hs_start interrupt fires at frame-start, so serves
+* the same purpose as dsp_hold in the driver.
+*/
+   DSP_HOLD_VALID_INTR,
FS_INTR,
LINE_FLAG_INTR,
BUS_ERROR_INTR,



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


Re: [RESEND PATCH] drm/shmobile: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Thomas Zimmermann
Hi,

thanks for reviewing the patch and the one for rcar-du. Please also add
them to your tree.

Best regards
Thomas

Am 26.09.18 um 14:14 schrieb Kieran Bingham:
> Hi Thomas,
> 
> Thank you for the patch,
> 
> On 26/09/18 12:55, Thomas Zimmermann wrote:
>> This patch unifies the naming of DRM functions for reference counting
>> of struct drm_device. The resulting code is more aligned with the rest
>> of the Linux kernel interfaces.
>>
>> Signed-off-by: Thomas Zimmermann 
>> Reviewed-by: Simon Horman 
> 
> Reviewed-by: Kieran Bingham 
> 
>> ---
>>  drivers/gpu/drm/shmobile/shmob_drm_drv.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/shmobile/shmob_drm_drv.c 
>> b/drivers/gpu/drm/shmobile/shmob_drm_drv.c
>> index 6ececad6f845..8554102a6ead 100644
>> --- a/drivers/gpu/drm/shmobile/shmob_drm_drv.c
>> +++ b/drivers/gpu/drm/shmobile/shmob_drm_drv.c
>> @@ -194,7 +194,7 @@ static int shmob_drm_remove(struct platform_device *pdev)
>>  drm_kms_helper_poll_fini(ddev);
>>  drm_mode_config_cleanup(ddev);
>>  drm_irq_uninstall(ddev);
>> -drm_dev_unref(ddev);
>> +drm_dev_put(ddev);
>>
>>  return 0;
>>  }
>> @@ -290,7 +290,7 @@ static int shmob_drm_probe(struct platform_device *pdev)
>>  drm_kms_helper_poll_fini(ddev);
>>  drm_mode_config_cleanup(ddev);
>>  err_free_drm_dev:
>> -drm_dev_unref(ddev);
>> +drm_dev_put(ddev);
>>
>>  return ret;
>>  }
>> --
>> 2.19.0
>>
> 
> ___
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstr. 5, D-90409 Nürnberg
Tel: +49-911-74053-0; Fax: +49-911-7417755;  https://www.suse.com/
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard,
Graham Norton, HRB 21284 (AG Nürnberg)



signature.asc
Description: OpenPGP digital signature
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [RESEND PATCH] drm/tve200: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Thomas Zimmermann
Hi

Am 26.09.18 um 14:14 schrieb Linus Walleij:
> On Wed, Sep 26, 2018 at 2:00 PM Thomas Zimmermann  wrote:
> 
>> This patch unifies the naming of DRM functions for reference counting
>> of struct drm_device. The resulting code is more aligned with the rest
>> of the Linux kernel interfaces.
>>
>> Signed-off-by: Thomas Zimmermann 
>> Reviewed-by: Linus Walleij 
> 
> Since you are resending it, do you need help to have it applied?

Yes. Could you please help with merging the patch? Thanks.

Best regards
Thomas

> Yours,
> Linus Walleij
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstr. 5, D-90409 Nürnberg
Tel: +49-911-74053-0; Fax: +49-911-7417755;  https://www.suse.com/
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard,
Graham Norton, HRB 21284 (AG Nürnberg)



signature.asc
Description: OpenPGP digital signature
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [RESEND PATCH] drm/shmobile: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Kieran Bingham
Hi Thomas,

Thank you for the patch,

On 26/09/18 12:55, Thomas Zimmermann wrote:
> This patch unifies the naming of DRM functions for reference counting
> of struct drm_device. The resulting code is more aligned with the rest
> of the Linux kernel interfaces.
> 
> Signed-off-by: Thomas Zimmermann 
> Reviewed-by: Simon Horman 

Reviewed-by: Kieran Bingham 

> ---
>  drivers/gpu/drm/shmobile/shmob_drm_drv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/shmobile/shmob_drm_drv.c 
> b/drivers/gpu/drm/shmobile/shmob_drm_drv.c
> index 6ececad6f845..8554102a6ead 100644
> --- a/drivers/gpu/drm/shmobile/shmob_drm_drv.c
> +++ b/drivers/gpu/drm/shmobile/shmob_drm_drv.c
> @@ -194,7 +194,7 @@ static int shmob_drm_remove(struct platform_device *pdev)
>   drm_kms_helper_poll_fini(ddev);
>   drm_mode_config_cleanup(ddev);
>   drm_irq_uninstall(ddev);
> - drm_dev_unref(ddev);
> + drm_dev_put(ddev);
> 
>   return 0;
>  }
> @@ -290,7 +290,7 @@ static int shmob_drm_probe(struct platform_device *pdev)
>   drm_kms_helper_poll_fini(ddev);
>   drm_mode_config_cleanup(ddev);
>  err_free_drm_dev:
> - drm_dev_unref(ddev);
> + drm_dev_put(ddev);
> 
>   return ret;
>  }
> --
> 2.19.0
> 

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


Re: [RESEND PATCH] drm/tve200: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Linus Walleij
On Wed, Sep 26, 2018 at 2:00 PM Thomas Zimmermann  wrote:

> This patch unifies the naming of DRM functions for reference counting
> of struct drm_device. The resulting code is more aligned with the rest
> of the Linux kernel interfaces.
>
> Signed-off-by: Thomas Zimmermann 
> Reviewed-by: Linus Walleij 

Since you are resending it, do you need help to have it applied?

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


Re: [RESEND PATCH] drm/rcar-du: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Kieran Bingham
Hi Thomas,

Thank you for the patch,

On 26/09/18 12:53, Thomas Zimmermann wrote:
> This patch unifies the naming of DRM functions for reference counting
> of struct drm_device. The resulting code is more aligned with the rest
> of the Linux kernel interfaces.> Signed-off-by: Thomas Zimmermann 
> 

Looks good to me.

Reviewed-by: Kieran Bingham 

> ---
>  drivers/gpu/drm/rcar-du/rcar_du_drv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c 
> b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
> index 0954ecd2f943..476d4d427044 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
> @@ -413,7 +413,7 @@ static int rcar_du_remove(struct platform_device *pdev)
>   drm_kms_helper_poll_fini(ddev);
>   drm_mode_config_cleanup(ddev);
> 
> - drm_dev_unref(ddev);
> + drm_dev_put(ddev);
> 
>   return 0;
>  }
> --
> 2.19.0
> 

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


Re: 4096x2160 monitor has EDID reporting 3840x2160

2018-09-26 Thread Ville Syrjälä
On Wed, Sep 26, 2018 at 02:27:54PM +0300, Jani Nikula wrote:
> On Mon, 24 Sep 2018, Brian Vincent  wrote:
> > Thank you for your reply.  I took your advice and tried it.  None of it
> > really surprises me.
> >
> > The problem seems pretty simple.  There is simply nothing in the EDID that
> > mentions that it's a 4096x2160 monitor.  From looking at the code, I don't
> > see any possible code path that would allow it to somehow discover a mode
> > higher than what the EDID reports.  Even if I did hit the code path that
> > infers new modes, the function valid_inferred_mode will reject any
> > resolution that's higher.  Is there a mechanism for discovering these
> > higher modes that I'm missing?
> >
> > I'm willing to work on a patch that would make this monitor "just work".
> > What I'm interested in is what a patch for this would even look like.  I
> > assume this would need to be added as a "quirk" since the EDID is factually
> > wrong.
> 
> Let's debug this a bit further first. Also, I think an EDID firmware
> (i.e. providing an override EDID from userspace using drm.edid_firmware
> module parameter) would be preferrable to quirking. But first things
> first.
> 
> > Here's the relevant logs:
> 
> We can't see from this short snippet if some modes were pruned
> earlier. A full dmesg would be preferred.
> 
> > Here's my parsed EDID:
> 
> The binary EDID would be preferrable, because the parsed EDID is always
> limited by the parser.
> 
> It would be best to attach such details to a bug report rather than
> pollute the list. Would you mind filing a bug over at [1], referencing
> this thread, and attaching the details there?

[1] https://bugs.freedesktop.org/enter_bug.cgi?product=DRI=DRM/Intel

-- 
Ville Syrjälä
Intel
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[RESEND PATCH] drm/zte: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Thomas Zimmermann
This patch unifies the naming of DRM functions for reference counting
of struct drm_device. The resulting code is more aligned with the rest
of the Linux kernel interfaces.

Signed-off-by: Thomas Zimmermann 
Acked-by: Shawn Guo 
---
 drivers/gpu/drm/zte/zx_drm_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/zte/zx_drm_drv.c b/drivers/gpu/drm/zte/zx_drm_drv.c
index 11ef17c2d1c1..5b6f1eda52e0 100644
--- a/drivers/gpu/drm/zte/zx_drm_drv.c
+++ b/drivers/gpu/drm/zte/zx_drm_drv.c
@@ -114,7 +114,7 @@ static int zx_drm_bind(struct device *dev)
component_unbind_all(dev, drm);
 out_unregister:
dev_set_drvdata(dev, NULL);
-   drm_dev_unref(drm);
+   drm_dev_put(drm);
return ret;
 }

@@ -127,7 +127,7 @@ static void zx_drm_unbind(struct device *dev)
drm_mode_config_cleanup(drm);
component_unbind_all(dev, drm);
dev_set_drvdata(dev, NULL);
-   drm_dev_unref(drm);
+   drm_dev_put(drm);
 }

 static const struct component_master_ops zx_drm_master_ops = {
--
2.19.0

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


[RESEND PATCH] drm/udl: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Thomas Zimmermann
This patch unifies the naming of DRM functions for reference counting
of struct drm_device. The resulting code is more aligned with the rest
of the Linux kernel interfaces.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/udl/udl_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c
index 9ef515df724b..a63e3011e971 100644
--- a/drivers/gpu/drm/udl/udl_drv.c
+++ b/drivers/gpu/drm/udl/udl_drv.c
@@ -94,7 +94,7 @@ static int udl_usb_probe(struct usb_interface *interface,
return 0;

 err_free:
-   drm_dev_unref(dev);
+   drm_dev_put(dev);
return r;
 }

--
2.19.0

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


[RESEND PATCH] drm/tve200: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Thomas Zimmermann
This patch unifies the naming of DRM functions for reference counting
of struct drm_device. The resulting code is more aligned with the rest
of the Linux kernel interfaces.

Signed-off-by: Thomas Zimmermann 
Reviewed-by: Linus Walleij 
---
 drivers/gpu/drm/tve200/tve200_drv.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/tve200/tve200_drv.c 
b/drivers/gpu/drm/tve200/tve200_drv.c
index 72efcecb44f7..90f24b5a95b3 100644
--- a/drivers/gpu/drm/tve200/tve200_drv.c
+++ b/drivers/gpu/drm/tve200/tve200_drv.c
@@ -191,12 +191,12 @@ static int tve200_probe(struct platform_device *pdev)
if (IS_ERR(priv->pclk)) {
dev_err(dev, "unable to get PCLK\n");
ret = PTR_ERR(priv->pclk);
-   goto dev_unref;
+   goto dev_put;
}
ret = clk_prepare_enable(priv->pclk);
if (ret) {
dev_err(dev, "failed to enable PCLK\n");
-   goto dev_unref;
+   goto dev_put;
}

/* This clock is for the pixels (27MHz) */
@@ -248,8 +248,8 @@ static int tve200_probe(struct platform_device *pdev)

 clk_disable:
clk_disable_unprepare(priv->pclk);
-dev_unref:
-   drm_dev_unref(drm);
+dev_put:
+   drm_dev_put(drm);
return ret;
 }

@@ -263,7 +263,7 @@ static int tve200_remove(struct platform_device *pdev)
drm_panel_bridge_remove(priv->bridge);
drm_mode_config_cleanup(drm);
clk_disable_unprepare(priv->pclk);
-   drm_dev_unref(drm);
+   drm_dev_put(drm);

return 0;
 }
--
2.19.0

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


[PATCH v2] drm/tegra: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Thomas Zimmermann
This patch unifies the naming of DRM functions for reference counting
of struct drm_device. The resulting code is more aligned with the rest
of the Linux kernel interfaces.

v2:
* rebased onto 'drm/tegra: kick out simplefb'

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/tegra/drm.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
index b424bc911b95..8cdb610561ba 100644
--- a/drivers/gpu/drm/tegra/drm.c
+++ b/drivers/gpu/drm/tegra/drm.c
@@ -1189,16 +1189,16 @@ static int host1x_drm_probe(struct host1x_device *dev)
 
err = drm_fb_helper_remove_conflicting_framebuffers(NULL, "tegradrmfb", 
false);
if (err < 0)
-   goto unref;
+   goto put;
 
err = drm_dev_register(drm, 0);
if (err < 0)
-   goto unref;
+   goto put;
 
return 0;
 
-unref:
-   drm_dev_unref(drm);
+put:
+   drm_dev_put(drm);
return err;
 }
 
@@ -1207,7 +1207,7 @@ static int host1x_drm_remove(struct host1x_device *dev)
struct drm_device *drm = dev_get_drvdata(>dev);
 
drm_dev_unregister(drm);
-   drm_dev_unref(drm);
+   drm_dev_put(drm);
 
return 0;
 }
-- 
2.19.0

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


[RESEND PATCH] drm/shmobile: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Thomas Zimmermann
This patch unifies the naming of DRM functions for reference counting
of struct drm_device. The resulting code is more aligned with the rest
of the Linux kernel interfaces.

Signed-off-by: Thomas Zimmermann 
Reviewed-by: Simon Horman 
---
 drivers/gpu/drm/shmobile/shmob_drm_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/shmobile/shmob_drm_drv.c 
b/drivers/gpu/drm/shmobile/shmob_drm_drv.c
index 6ececad6f845..8554102a6ead 100644
--- a/drivers/gpu/drm/shmobile/shmob_drm_drv.c
+++ b/drivers/gpu/drm/shmobile/shmob_drm_drv.c
@@ -194,7 +194,7 @@ static int shmob_drm_remove(struct platform_device *pdev)
drm_kms_helper_poll_fini(ddev);
drm_mode_config_cleanup(ddev);
drm_irq_uninstall(ddev);
-   drm_dev_unref(ddev);
+   drm_dev_put(ddev);

return 0;
 }
@@ -290,7 +290,7 @@ static int shmob_drm_probe(struct platform_device *pdev)
drm_kms_helper_poll_fini(ddev);
drm_mode_config_cleanup(ddev);
 err_free_drm_dev:
-   drm_dev_unref(ddev);
+   drm_dev_put(ddev);

return ret;
 }
--
2.19.0

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


[RESEND PATCH] drm/rcar-du: Replace drm_dev_unref with drm_dev_put

2018-09-26 Thread Thomas Zimmermann
This patch unifies the naming of DRM functions for reference counting
of struct drm_device. The resulting code is more aligned with the rest
of the Linux kernel interfaces.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/rcar-du/rcar_du_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c 
b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
index 0954ecd2f943..476d4d427044 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
@@ -413,7 +413,7 @@ static int rcar_du_remove(struct platform_device *pdev)
drm_kms_helper_poll_fini(ddev);
drm_mode_config_cleanup(ddev);

-   drm_dev_unref(ddev);
+   drm_dev_put(ddev);

return 0;
 }
--
2.19.0

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


  1   2   >