[Bug 85696] [regression] r600g+nine: Bioshock shader failure after 7b1c0cbc90d456384b0950ad21faa3c61a6b43ff

2014-11-02 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=85696

--- Comment #3 from David Heidelberg (okias)  ---
Created attachment 108777
  --> https://bugs.freedesktop.org/attachment.cgi?id=108777=edit
debug_vs_ps_sbdry.txt

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 



[Bug 85580] [RadeonSI] Bad performance in TF2.

2014-11-02 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=85580

--- Comment #2 from Aaron B  ---
It has gotten better since I've re-compiled llvm and mesa, and moved back to
just 3.5. But it still drops down to the red in the source engine FPS counter a
lot still. It should be a regression, afaict, it never did it as often as it
does with llvm 3.5, current mesa, radeonsi.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20141102/c8d94bbb/attachment.html>


[Bug 72785] bfgminer --scrypt on 7xxx+

2014-11-02 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=72785

--- Comment #33 from Luke-Jr <luke-jr+freedesktopbugs at utopios.org> ---
Looks like clEnqueueNDRangeKernel is re-compiling (or at least optimising?) the
kernel, and taking a long time to do so. Isn't compiling supposed to be
done *once* by clBuildProgram?

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20141102/526e25d2/attachment.html>


[Bug 86891] AMD/ATI Tahiti XT 7970 - long lags/stutters in games

2014-11-02 Thread bugzilla-dae...@bugzilla.kernel.org
https://bugzilla.kernel.org/show_bug.cgi?id=86891

--- Comment #20 from Michael Mair-Keimberger  ---
Created attachment 156161
  --> https://bugzilla.kernel.org/attachment.cgi?id=156161=edit
vally screenshot

(In reply to Andy Furniss from comment #19)
> (In reply to Michael Mair-Keimberger from comment #18)
> > Created attachment 156051 [details]
> > picture with VRAM and GTT usage
> > 
> > (In reply to Michel Dänzer from comment #17)
> > > (In reply to Michael Mair-Keimberger from comment #15)
> > > > Unfortunately vally doesn't include GALLIUM_HUD when i'm taking
> > > > screenshot's. As a workaround i've made photos with my mobile. Hope 
> > > > that's
> > > > ok :)
> > > 
> > > That's fine, but we also need to see the VRAM and GTT graphs.
> > 
> > Sorry, completely forget about that.. 
> > Another picture with VRAM and GTT usage. I've used
> > `GALLIUM_HUD=fps,requested-VRAM+VRAM-usage,requested-GTT+GTT` to start the
> > benchmark.
> 
> Should be ...requested-GTT+GTT-usage
> 
> I used to have similar issues with valley, but for my setup/card (R9270X)
> they are fixed with current mesa + drm-next-3.19-wip.
> 
> One thing I always do is set CPUs to performance in case cpufreq messes
> things up - may be worth a try to see if it helps.
> 
> What setting(s)/res do you run valley with?
> 
> It may be less hassle for you to use a phone, but FWIW the way I get
> screenshots that include the HUD is to use xwd - for something fullscreen I
> would before starting valley from a different xterm/console/whatever do
> something like -
> 
> sleep 100 && xwd -root -out whatever.xwd 
> 
> then start valley and wait. To view "whatever.xwd" you can use xwud,to
> upload you could convert to another "normal" format. You need some image
> program to do this - I have ImageMagick installed and can just type in a
> terminal -
> 
> convert whatever.xwd whatever.png


It's fixed! (for me) - mesa git did the miracle :)

FYI - changing CPU's to performance didn't had any influence. I've made another
screenshot, this time with xwd (thanks for the tip btw) and with GTT-usage
(thangs for pointing that out - that was a copy paste error). Don't know if
it's still important but i'll upload it anyway.

Settings for vally are as followed:
Quality: Ultra
Stereo 3d: Disabled
Monitors: Single
Anti-aliasing: Off
Full Screen: Yes
Resolution: 2560x1600

-- 
You are receiving this mail because:
You are watching the assignee of the bug.


[Bug 86891] AMD/ATI Tahiti XT 7970 - long lags/stutters in games

2014-11-02 Thread bugzilla-dae...@bugzilla.kernel.org
https://bugzilla.kernel.org/show_bug.cgi?id=86891

--- Comment #21 from Michael Mair-Keimberger  ---
Just to clarify - the screenshot was made with mesa-10.3.2 and cpu's frequency
set to performance.

With mesa git i got following results:
FPS: 20.0
Score: 838
Min FPS: 7.4
Max FPS: 30.5

Pretty neat actually! I'll gonna make another benchmark with my patched kernel
(git revert 59bc1d8) and look if it has an influence in performance :)

-- 
You are receiving this mail because:
You are watching the assignee of the bug.


[Bug 85579] [bisected] piglit test crashes in spec/glsl-1.50/execution/geometry/max-input-components

2014-11-02 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=85579

--- Comment #9 from Marek Olšák  ---
I think there are 2 ways to fix this and we should do both:

1) Fix VGPR register spilling caused by indirect addressing into lots of
registers. LLVM crashes when it attempts to do that. Those registers are just
copies of shader inputs and outputs.

2)
Step A) Implement indirect addressing for VS outputs before GS and GS inputs.
This means that we cannot store outputs at the end of shaders (using
emit_epilogue), but we must store them when they occur as a destination
register (using emit_store).

(BTW my tessellation branch contains modifications to emit_store that make it
easier to re-implement it for shaders that use store instructions for outputs)

Step B) glsl_to_tgsi and/or some passes of the GLSL compiler may need to be
modified not to move ins/outs into temporaries. I think the only pass that does
that is the varying packing. The pass should be disabled or rewritten, because
its current implementation isn't gonna fly with our hardware and is often the
cause of unnecessary register spilling.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20141102/fcfd001a/attachment.html>


[Bug 83461] hdmi screen flicker/unusable

2014-11-02 Thread bugzilla-dae...@bugzilla.kernel.org
https://bugzilla.kernel.org/show_bug.cgi?id=83461

Christian König  changed:

   What|Removed |Added

 Attachment #155721|0   |1
is obsolete||

--- Comment #19 from Christian König  ---
Created attachment 156211
  --> https://bugzilla.kernel.org/attachment.cgi?id=156211=edit
Possible fix

Please try the attached patch. It's based on top of Alex drm-fixes-3.18 branch,
but should apply to older ones as well.

The problem seems to be that with a reference frequency of 14.32Mhz and a
reference divider of 14 we get 1.0228Mhz which is very close to the minimum
input frequency of 1Mhz.

-- 
You are receiving this mail because:
You are watching the assignee of the bug.


[Bug 72785] bfgminer --scrypt on 7xxx+

2014-11-02 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=72785

--- Comment #34 from Luke-Jr <luke-jr+freedesktopbugs at utopios.org> ---
(In reply to Luke-Jr from comment #33)
> Looks like clEnqueueNDRangeKernel is re-compiling (or at least optimising?)
> the kernel, and taking a long time to do so. Isn't compiling
> supposed to be done *once* by clBuildProgram?

Also, seems it pisses off the hardware really bad when it finishes (although I
only have a 5850 and 6xxx for testing at the moment):

[  855.257659] radeon :01:00.0: ring 3 stalled for more than 1msec
[  855.257670] radeon :01:00.0: GPU lockup (waiting for 0x963c
last fence id 0x963b on ring 3)
[  855.283709] dmar: DRHD: handling fault status reg 3
[  855.283730] dmar: DMAR:[DMA Read] Request device [01:00.0] fault addr
401df000 
DMAR:[fault reason 06] PTE Read access is not set
[  855.283734] radeon :01:00.0: Saved 514 dwords of commands on ring 0.
[  855.283757] radeon :01:00.0: GPU softreset: 0x000D
[  855.283762] radeon :01:00.0:   GRBM_STATUS   = 0xB0433828
[  855.283766] radeon :01:00.0:   GRBM_STATUS_SE0   = 0x0807
[  855.283770] radeon :01:00.0:   GRBM_STATUS_SE1   = 0x0007
[  855.283773] radeon :01:00.0:   SRBM_STATUS   = 0x20C0
[  855.283776] radeon :01:00.0:   SRBM_STATUS2  = 0x
[  855.283779] radeon :01:00.0:   R_008674_CP_STALLED_STAT1 = 0x
[  855.283783] radeon :01:00.0:   R_008678_CP_STALLED_STAT2 = 0x400C
[  855.283799] radeon :01:00.0:   R_00867C_CP_BUSY_STAT = 0x00050002
[  855.283803] radeon :01:00.0:   R_008680_CP_STAT  = 0x80268647
[  855.283813] radeon :01:00.0:   R_00D034_DMA_STATUS_REG   = 0x44483146
[  855.298675] radeon :01:00.0: GRBM_SOFT_RESET=0x7F6B
[  855.298731] radeon :01:00.0: SRBM_SOFT_RESET=0x00100100
[  855.299894] radeon :01:00.0:   GRBM_STATUS   = 0x3828
[  855.299898] radeon :01:00.0:   GRBM_STATUS_SE0   = 0x0007
[  855.299901] radeon :01:00.0:   GRBM_STATUS_SE1   = 0x0007
[  855.299904] radeon :01:00.0:   SRBM_STATUS   = 0x20C0
[  855.299908] radeon :01:00.0:   SRBM_STATUS2  = 0x
[  855.299911] radeon :01:00.0:   R_008674_CP_STALLED_STAT1 = 0x
[  855.299914] radeon :01:00.0:   R_008678_CP_STALLED_STAT2 = 0x
[  855.299918] radeon :01:00.0:   R_00867C_CP_BUSY_STAT = 0x
[  855.299921] radeon :01:00.0:   R_008680_CP_STAT  = 0x
[  855.299924] radeon :01:00.0:   R_00D034_DMA_STATUS_REG   = 0x44C83D57
[  855.299956] radeon :01:00.0: GPU reset succeeded, trying to resume
[  855.322535] [drm] enabling PCIE gen 2 link speeds, disable with
radeon.pcie_gen2=0
[  855.323757] [drm] PCIE GART of 1024M enabled (table at 0x00273000).
[  855.323855] radeon :01:00.0: WB enabled
[  855.323859] radeon :01:00.0: fence driver on ring 0 use gpu addr
0x4c00 and cpu addr 0x8800a7056c00
[  855.323862] radeon :01:00.0: fence driver on ring 3 use gpu addr
0x4c0c and cpu addr 0x8800a7056c0c
[  855.325391] radeon :01:00.0: fence driver on ring 5 use gpu addr
0x00072118 and cpu addr 0xc900052b2118
[  855.341736] [drm] ring test on 0 succeeded in 3 usecs
[  855.341750] [drm] ring test on 3 succeeded in 1 usecs
[  855.519119] [drm] ring test on 5 succeeded in 2 usecs
[  855.519135] [drm] UVD initialized successfully.
[  855.523058] [drm] ib test on ring 0 succeeded in 0 usecs
[  855.523143] [drm] ib test on ring 3 succeeded in 1 usecs
[  855.675747] [drm] ib test on ring 5 succeeded

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20141102/93eed0ee/attachment.html>


[PATCH 00/17] atomic modeset core<->driver interfaces and helpers

2014-11-02 Thread Daniel Vetter
Hi all,

So here's my atomic series, finally debugged. This is just the
core<->driver interface plus a big pile of helpers. Short recap of the main
ideas:

- There are essentially three helper libraries in this patch set:

  * Transitional helpers to use the new plane callbacks for legacy plane
updates and in the crtc helper's ->mode_set callback. These helpers are
only temporarily used to convert drivers to atomic, but they allow a
nice separation between changing the driver backend and switching to
the atomic commit logic.

  * Legacy helpers to implement all the legacy driver entry points
(page_flip, set_config, plane vfuncs) on top of the new atomic driver
interface. These are completely driver agnostic. The reason for having
the legacy support as helpers is that drivers can switch step-by-step.
And they could e.g. even keep the legacy page_flip code around for some
old platforms where converting to full-blown atomic isn't worth it.

  * Atomic helpers which implement the various new ->atomic_* driver
interfaces in terms of the revised crtc helper and new plane helper
hooks.

- The revised crtc helper implemenation essentially implements all the
  lessons learned in the i915 modeset rework (when using the atomic helpers
  only):

  * Enable/disable sequence for a given config are always the same and
callbacks are always called in the same order. This contrast starkly
with the crtc helpers, where the sequence of operations is heavily
dependent on the previous config.

One corollary of this is that if the configuration of a crtc only
partially changes (e.g. a connector moves in a cloned config) the
helper code will still disable/enable the full display pipeline. This
is the only way to ensure that the enable/disable sequence is always
the same.

  * It won't call disable or enable hooks more than once any more because
it lost track of state, thanks to the atomic state tracking. And if
drivers implement the ->reset hook properly (by either resetting the hw
or reading out the hw state into the atomic structures) this even
extends to the hardware state. So no more disable-me-harder kind of
nonsense.

  * The only lacking thing is the hw state readout/cross-check support, but
if drivers have hw state readout support in their ->reset handlers it's
simple to extend that to cross-check the hw state.

  * The crtc->mode_set callback is gone and its replacement only sets crtc
timings an no longer updates the primary plane state. This way we can
finally implement primary planes properly.

- The new plane helpers should be suitable enough for pretty much
  everything, and a perfect fit for hardware with GO bits. Even if they
  don't fit the atomic helper library is rather flexible and exports all
  the functions for the individual steps to drivers. So drivers can pick
  what matches and implement their own magic for everything.

- A big difference compared to all previous atomic series is that this one
  doesn't implement async commit in a generic way. Imo driver requirements
  for that are too diverse to create anything reasonable sane which would
  actually work on a reasonable amount of different drivers. Also, we've
  never had a helper library for page_flips even, so it's really hard to
  know what might work and what's stupid without a bit of experience.

  I think with the current flexibility for drivers to pick individual
  stages and existing helpers like drm_flip_queue it's rather easy though
  to implement proper async commit.

- There's a few other differences of minor importance to earlier atomic
  series:

  * Common/generic properties are parsed in the callers/core and not in
drivers, and passed to drivers by directly setting the right members in
atomic state structures. That greatly simplifies all the transitional
and legacy helpers an removes a lot of boilerplate code.

  * There's no crazy trylock mode used for the async commit since these
helpers don't do async commit. A simple ordered flip queue of atomic
state updates should be sufficient for preventing concurrent hw access
anyway, as long as synchronous updates stall correctly with e.g.
flush_work_queue or similar function.

  * These helpers reuse the existing ->mode_fixup hooks in the atomic_check
callback. Which means that drivers need to adapat and move a lot less code
into their atomic_check callbacks.

Now this isn't everything needed in the drm core and helpers for full
atomic support. But it's enough to start with converting drivers, and
except for actually testing multiplane and multicrtc updates also enough to
implement full atomic updates. Still missing are:

- Per-plane locking. Since these helpers here encapsulate the locking
  completely this should be fairly easy to implement.

- fbdev support for atomic_check/commit, so that multi-pipe finally works
  sanely.

- Adding and decoding 

[PATCH 01/17] drm: Move drm_crtc_init from drm_crtc.h to drm_plane_helper.h

2014-11-02 Thread Daniel Vetter
Just a bit of OCD cleanup on headers - this function isn't the core
interface any more but just a helper for drivers who haven't yet
transitioned to universal planes. Put the declaration at the right
spot and sprinkle necessary #includes over all drivers.

Maybe this helps to encourage driver maintainers to do the switch.

Cc: Matt Roper 
Reviewed-by: Matt Roper 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/armada/armada_crtc.c   | 1 +
 drivers/gpu/drm/ast/ast_mode.c | 1 +
 drivers/gpu/drm/bochs/bochs_kms.c  | 1 +
 drivers/gpu/drm/cirrus/cirrus_mode.c   | 1 +
 drivers/gpu/drm/gma500/psb_intel_display.c | 1 +
 drivers/gpu/drm/mgag200/mgag200_mode.c | 1 +
 drivers/gpu/drm/nouveau/dispnv04/crtc.c| 1 +
 drivers/gpu/drm/nouveau/nv50_display.c | 1 +
 drivers/gpu/drm/omapdrm/omap_crtc.c| 1 +
 drivers/gpu/drm/qxl/qxl_display.c  | 1 +
 drivers/gpu/drm/radeon/radeon_display.c| 1 +
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 1 +
 drivers/gpu/drm/shmobile/shmob_drm_crtc.c  | 1 +
 drivers/gpu/drm/sti/sti_drm_crtc.c | 1 +
 drivers/gpu/drm/tegra/dc.c | 1 +
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c   | 1 +
 drivers/gpu/drm/udl/udl_modeset.c  | 1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c| 1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c   | 1 +
 drivers/staging/imx-drm/imx-drm-core.c | 1 +
 include/drm/drm_crtc.h | 3 ---
 include/drm/drm_plane_helper.h | 4 
 22 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/armada/armada_crtc.c 
b/drivers/gpu/drm/armada/armada_crtc.c
index 9a0cc09e6653..0b164fb1c107 100644
--- a/drivers/gpu/drm/armada/armada_crtc.c
+++ b/drivers/gpu/drm/armada/armada_crtc.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "armada_crtc.h"
 #include "armada_drm.h"
 #include "armada_fb.h"
diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 19ada0bbe319..df986498d376 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "ast_drv.h"

 #include "ast_tables.h"
diff --git a/drivers/gpu/drm/bochs/bochs_kms.c 
b/drivers/gpu/drm/bochs/bochs_kms.c
index 6b7efcf363d6..5ffd4895d040 100644
--- a/drivers/gpu/drm/bochs/bochs_kms.c
+++ b/drivers/gpu/drm/bochs/bochs_kms.c
@@ -6,6 +6,7 @@
  */

 #include "bochs.h"
+#include 

 static int defx = 1024;
 static int defy = 768;
diff --git a/drivers/gpu/drm/cirrus/cirrus_mode.c 
b/drivers/gpu/drm/cirrus/cirrus_mode.c
index c7c5a9d91fa0..99d4a74ffeaf 100644
--- a/drivers/gpu/drm/cirrus/cirrus_mode.c
+++ b/drivers/gpu/drm/cirrus/cirrus_mode.c
@@ -16,6 +16,7 @@
  */
 #include 
 #include 
+#include 

 #include 

diff --git a/drivers/gpu/drm/gma500/psb_intel_display.c 
b/drivers/gpu/drm/gma500/psb_intel_display.c
index 87b50ba64ed4..b21a09451d1d 100644
--- a/drivers/gpu/drm/gma500/psb_intel_display.c
+++ b/drivers/gpu/drm/gma500/psb_intel_display.c
@@ -21,6 +21,7 @@
 #include 

 #include 
+#include 
 #include "framebuffer.h"
 #include "psb_drv.h"
 #include "psb_intel_drv.h"
diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c 
b/drivers/gpu/drm/mgag200/mgag200_mode.c
index 83485ab81ce8..9872ba9abf1a 100644
--- a/drivers/gpu/drm/mgag200/mgag200_mode.c
+++ b/drivers/gpu/drm/mgag200/mgag200_mode.c
@@ -15,6 +15,7 @@

 #include 
 #include 
+#include 

 #include "mgag200_drv.h"

diff --git a/drivers/gpu/drm/nouveau/dispnv04/crtc.c 
b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
index b90aa5c1f90a..07acb36235cd 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/crtc.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
@@ -26,6 +26,7 @@

 #include 
 #include 
+#include 

 #include "nouveau_drm.h"
 #include "nouveau_reg.h"
diff --git a/drivers/gpu/drm/nouveau/nv50_display.c 
b/drivers/gpu/drm/nouveau/nv50_display.c
index fdb3e1adea1e..a1fd99589ce3 100644
--- a/drivers/gpu/drm/nouveau/nv50_display.c
+++ b/drivers/gpu/drm/nouveau/nv50_display.c
@@ -26,6 +26,7 @@

 #include 
 #include 
+#include 
 #include 

 #include 
diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.c 
b/drivers/gpu/drm/omapdrm/omap_crtc.c
index 2d28dc337cfb..b0566a1ca28f 100644
--- a/drivers/gpu/drm/omapdrm/omap_crtc.c
+++ b/drivers/gpu/drm/omapdrm/omap_crtc.c
@@ -20,6 +20,7 @@
 #include "omap_drv.h"

 #include 
+#include 
 #include "drm_crtc.h"
 #include "drm_crtc_helper.h"

diff --git a/drivers/gpu/drm/qxl/qxl_display.c 
b/drivers/gpu/drm/qxl/qxl_display.c
index af9e78546688..b7b728e758b8 100644
--- a/drivers/gpu/drm/qxl/qxl_display.c
+++ b/drivers/gpu/drm/qxl/qxl_display.c
@@ -29,6 +29,7 @@
 #include "qxl_drv.h"
 #include "qxl_object.h"
 #include "drm_crtc_helper.h"
+#include 

 static bool qxl_head_enabled(struct qxl_head *head)
 {
diff --git a/drivers/gpu/drm/radeon/radeon_display.c 
b/drivers/gpu/drm/radeon/radeon_display.c
index 4eb37976f879..ad24536ee4ce 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ 

[PATCH 02/17] drm: Pull drm_crtc.h into the kerneldoc template

2014-11-02 Thread Daniel Vetter
While writing atomic docs I've noticed that I don't get any errors
for my screw-ups in drm_crtc.h. Fix this immediately.

This just does the bare minimum to get starts, lots of stuff isn't
properly documented yet unfortunately.

Signed-off-by: Daniel Vetter 
---
 Documentation/DocBook/drm.tmpl |  4 
 include/drm/drm_crtc.h | 26 +-
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/Documentation/DocBook/drm.tmpl b/Documentation/DocBook/drm.tmpl
index be35bc328b77..89829ae58e97 100644
--- a/Documentation/DocBook/drm.tmpl
+++ b/Documentation/DocBook/drm.tmpl
@@ -1827,6 +1827,10 @@ void intel_crt_init(struct drm_device *dev)
 !Edrivers/gpu/drm/drm_crtc.c
 
 
+  KMS Data Structures
+!Iinclude/drm/drm_crtc.h
+
+
   KMS Locking
 !Pdrivers/gpu/drm/drm_modeset_lock.c kms locking
 !Iinclude/drm/drm_modeset_lock.h
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 44c57d2a64ec..21a15850a4d5 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -142,7 +142,7 @@ struct drm_framebuffer_funcs {
int (*create_handle)(struct drm_framebuffer *fb,
 struct drm_file *file_priv,
 unsigned int *handle);
-   /**
+   /*
 * Optinal callback for the dirty fb ioctl.
 *
 * Userspace can notify the driver via this callback
@@ -226,7 +226,7 @@ struct drm_plane;
 struct drm_bridge;

 /**
- * drm_crtc_funcs - control CRTCs for a given device
+ * struct drm_crtc_funcs - control CRTCs for a given device
  * @save: save CRTC state
  * @restore: restore CRTC state
  * @reset: reset CRTC after state has been invalidated (e.g. resume)
@@ -290,7 +290,7 @@ struct drm_crtc_funcs {
 };

 /**
- * drm_crtc - central CRTC control structure
+ * struct drm_crtc - central CRTC control structure
  * @dev: parent DRM device
  * @head: list management
  * @mutex: per-CRTC locking
@@ -322,7 +322,7 @@ struct drm_crtc {
struct device_node *port;
struct list_head head;

-   /**
+   /*
 * crtc mutex
 *
 * This provides a read lock for the overall crtc state (mode, dpms
@@ -377,7 +377,7 @@ struct drm_crtc {


 /**
- * drm_connector_funcs - control connectors on a given device
+ * struct drm_connector_funcs - control connectors on a given device
  * @dpms: set power state (see drm_crtc_funcs above)
  * @save: save connector state
  * @restore: restore connector state
@@ -414,7 +414,7 @@ struct drm_connector_funcs {
 };

 /**
- * drm_encoder_funcs - encoder controls
+ * struct drm_encoder_funcs - encoder controls
  * @reset: reset state (e.g. at init or resume time)
  * @destroy: cleanup and free associated data
  *
@@ -428,7 +428,7 @@ struct drm_encoder_funcs {
 #define DRM_CONNECTOR_MAX_ENCODER 3

 /**
- * drm_encoder - central DRM encoder structure
+ * struct drm_encoder - central DRM encoder structure
  * @dev: parent DRM device
  * @head: list management
  * @base: base KMS object
@@ -472,7 +472,7 @@ struct drm_encoder {
 #define MAX_ELD_BYTES  128

 /**
- * drm_connector - central DRM connector control structure
+ * struct drm_connector - central DRM connector control structure
  * @dev: parent DRM device
  * @kdev: kernel device for sysfs attributes
  * @attr: sysfs attributes
@@ -566,7 +566,7 @@ struct drm_connector {
 };

 /**
- * drm_plane_funcs - driver plane control functions
+ * struct drm_plane_funcs - driver plane control functions
  * @update_plane: update the plane configuration
  * @disable_plane: shut down the plane
  * @destroy: clean up plane resources
@@ -594,7 +594,7 @@ enum drm_plane_type {
 };

 /**
- * drm_plane - central DRM plane control structure
+ * struct drm_plane - central DRM plane control structure
  * @dev: DRM device this plane belongs to
  * @head: for list management
  * @base: base mode object
@@ -632,7 +632,7 @@ struct drm_plane {
 };

 /**
- * drm_bridge_funcs - drm_bridge control functions
+ * struct drm_bridge_funcs - drm_bridge control functions
  * @attach: Called during drm_bridge_attach
  * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
  * @disable: Called right before encoder prepare, disables the bridge
@@ -658,7 +658,7 @@ struct drm_bridge_funcs {
 };

 /**
- * drm_bridge - central DRM bridge control structure
+ * struct drm_bridge - central DRM bridge control structure
  * @dev: DRM device this bridge belongs to
  * @head: list management
  * @base: base mode object
@@ -679,7 +679,7 @@ struct drm_bridge {
 };

 /**
- * drm_mode_set - new values for a CRTC config change
+ * struct drm_mode_set - new values for a CRTC config change
  * @head: list management
  * @fb: framebuffer to use for new config
  * @crtc: CRTC whose configuration we're about to change
-- 
2.1.1



[PATCH 03/17] drm: fixup kerneldoc in drm_crtc.h

2014-11-02 Thread Daniel Vetter
I've tried to cc all the people who have recently added new stuff
but forgotten to update documentation.

I've also decided not to bother documenting the massive property list
in struct drm_mode_config. If that beast keeps on growing we might want
to extract it into a separate structure which we won't document.

Cc: Thomas Wood 
Cc: Sean Paul 
Cc: Russell King 
Signed-off-by: Daniel Vetter 
---
 include/drm/drm_crtc.h | 51 +++---
 1 file changed, 36 insertions(+), 15 deletions(-)

diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 21a15850a4d5..a68e02be7e37 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -231,6 +231,7 @@ struct drm_bridge;
  * @restore: restore CRTC state
  * @reset: reset CRTC after state has been invalidated (e.g. resume)
  * @cursor_set: setup the cursor
+ * @cursor_set2: setup the cursor with hotspot, superseeds @cursor_set if set
  * @cursor_move: move the cursor
  * @gamma_set: specify color ramp for CRTC
  * @destroy: deinit and free object
@@ -292,11 +293,14 @@ struct drm_crtc_funcs {
 /**
  * struct drm_crtc - central CRTC control structure
  * @dev: parent DRM device
+ * @port: OF node used by drm_of_find_possible_crtcs()
  * @head: list management
  * @mutex: per-CRTC locking
  * @base: base KMS object for ID tracking etc.
  * @primary: primary plane for this CRTC
  * @cursor: cursor plane for this CRTC
+ * @cursor_x: current x position of the cursor, used for universal cursor 
planes
+ * @cursor_y: current y position of the cursor, used for universal cursor 
planes
  * @enabled: is this CRTC enabled?
  * @mode: current mode timings
  * @hwmode: mode timings as programmed to hw regs
@@ -309,10 +313,12 @@ struct drm_crtc_funcs {
  * @gamma_size: size of gamma ramp
  * @gamma_store: gamma ramp values
  * @framedur_ns: precise frame timing
- * @framedur_ns: precise line timing
+ * @linedur_ns: precise line timing
  * @pixeldur_ns: precise pixel timing
  * @helper_private: mid-layer private data
  * @properties: property tracking for this CRTC
+ * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
+ * legacy ioctls
  *
  * Each CRTC may have one or more connectors associated with it.  This 
structure
  * allows the CRTC to be controlled.
@@ -483,6 +489,7 @@ struct drm_encoder {
  * @connector_type_id: index into connector type enum
  * @interlace_allowed: can this connector handle interlaced modes?
  * @doublescan_allowed: can this connector handle doublescan?
+ * @stereo_allowed: can this connector handle stereo modes?
  * @modes: modes available on this connector (from fill_modes() + user)
  * @status: one of the drm_connector_status enums (connected, not, or unknown)
  * @probed_modes: list of modes derived directly from the display
@@ -490,10 +497,13 @@ struct drm_encoder {
  * @funcs: connector control functions
  * @edid_blob_ptr: DRM property containing EDID if present
  * @properties: property tracking for this connector
+ * @path_blob_ptr: DRM blob property data for the DP MST path property
  * @polled: a %DRM_CONNECTOR_POLL_ value for core driven polling
  * @dpms: current dpms state
  * @helper_private: mid-layer private data
+ * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
  * @force: a %DRM_FORCE_ state for forced mode sets
+ * @override_edid: has the EDID been overwritten through debugfs for testing?
  * @encoder_ids: valid encoders for this connector
  * @encoder: encoder driving this connector, if any
  * @eld: EDID-like data, if present
@@ -503,6 +513,8 @@ struct drm_encoder {
  * @video_latency: video latency info from ELD, if found
  * @audio_latency: audio latency info from ELD, if found
  * @null_edid_counter: track sinks that give us all zeros for the EDID
+ * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
+ * @debugfs_entry: debugfs directory for this connector
  *
  * Each connector may be connected to one or more CRTCs, or may be clonable by
  * another connector if they can share a CRTC.  Each connector also has a 
specific
@@ -570,6 +582,7 @@ struct drm_connector {
  * @update_plane: update the plane configuration
  * @disable_plane: shut down the plane
  * @destroy: clean up plane resources
+ * @reset: reset plane after state has been invalidated (e.g. resume)
  * @set_property: called when a property is changed
  */
 struct drm_plane_funcs {
@@ -603,6 +616,8 @@ enum drm_plane_type {
  * @format_count: number of formats supported
  * @crtc: currently bound CRTC
  * @fb: currently bound fb
+ * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used 
by
+ * drm_mode_set_config_internal() to implement correct refcounting.
  * @funcs: helper functions
  * @properties: property tracking for this plane
  * @type: type of plane (overlay, primary, cursor)
@@ -620,8 +635,6 @@ struct drm_plane {
struct drm_crtc *crtc;
struct 

[PATCH 04/17] drm/modeset_lock: document trylock_only in kerneldoc

2014-11-02 Thread Daniel Vetter
I've forgotten to do this in:

commit cb597bb3a2fbfc871cc1c703fb330d247bd21394
Author: Daniel Vetter 
Date:   Sun Jul 27 19:09:33 2014 +0200

drm: trylock modest locking for fbdev panics

Oops, fix this asap.

In my defense kerneldoc is really awful and there's no way it can pick
up structured comments per struct member. Which means we need both
since people won't scroll up even a few lines.

Signed-off-by: Daniel Vetter 
---
 include/drm/drm_modeset_lock.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/drm/drm_modeset_lock.h b/include/drm/drm_modeset_lock.h
index 75a5c45e21c7..28931a23d96c 100644
--- a/include/drm/drm_modeset_lock.h
+++ b/include/drm/drm_modeset_lock.h
@@ -33,6 +33,7 @@ struct drm_modeset_lock;
  * @ww_ctx: base acquire ctx
  * @contended: used internally for -EDEADLK handling
  * @locked: list of held locks
+ * @trylock_only: trylock mode used in atomic contexts/panic notifiers
  *
  * Each thread competing for a set of locks must use one acquire
  * ctx.  And if any lock fxn returns -EDEADLK, it must backoff and
-- 
2.1.1



[PATCH 05/17] drm: Add atomic driver interface definitions for objects

2014-11-02 Thread Daniel Vetter
Heavily based upon Rob Clark's atomic series.
- Dropped the connctor state from the crtc state, instead opting for a
  full-blown connector state. The only thing it has is the desired
  crtc, but drivers which have connector properties have now a
  data-structure to subclass.

- Rename create_state to duplicate_state. Especially for legacy ioctls
  we want updates on top of existing state, so we need a way to get at
  the current state. We need to be careful to clear the backpointers
  to the global state correctly though.

- Drop property values. Drivers with properties simply need to
  subclass the datastructures and track the decoded values in there. I
  also think that common properties (like rotation) should be decoded
  and stored in the core structures.

- Create a new set of ->atomic_set_prop functions, for smoother
  transitions from legacy to atomic operations.

- Pass the ->atomic_set_prop ioctl the right structure to avoid
  chasing pointers in drivers.

- Drop temporary boolean state for now until we resurrect them with
  the helper functions.

- Drop invert_dimensions. For now we don't need any checking since
  that's done by the higher-level legacy ioctls. But even then we
  should also add rotation/flip tracking to the core drm_crtc_state,
  not just whether the dimensions are inverted.

- Track crtc state with an enable/disable. That's equivalent to
  mode_valid, but a bit clearer that it means the entire crtc.

The global interface will follow in subsequent patches.

v2: We need to allow drivers to somehow set up the initial state and
clear it on resume. So add a plane->reset callback for that. Helpers
will be provided with default behaviour for all these.

v3: Split out the plane->reset into a separate patch.

v4: Improve kerneldoc in drm_crtc.h

v5: Remove unused inline functions for handling state objects, those
callbacks are now mandatory for full atomic support.

Signed-off-by: Daniel Vetter 
---
 include/drm/drm_crtc.h | 107 +
 1 file changed, 107 insertions(+)

diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index a68e02be7e37..9847009ad451 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -224,6 +224,25 @@ struct drm_encoder;
 struct drm_pending_vblank_event;
 struct drm_plane;
 struct drm_bridge;
+struct drm_atomic_state;
+
+/**
+ * struct drm_crtc_state - mutable crtc state
+ * @enable: whether the CRTC should be enabled, gates all other state
+ * @mode: current mode timings
+ * @event: optional pointer to a DRM event to signal upon completion of the
+ * state update
+ * @state: backpointer to global drm_atomic_state
+ */
+struct drm_crtc_state {
+   bool enable: 1;
+
+   struct drm_display_mode mode;
+
+   struct drm_pending_vblank_event *event;
+
+   struct drm_atomic_state *state;
+};

 /**
  * struct drm_crtc_funcs - control CRTCs for a given device
@@ -238,6 +257,9 @@ struct drm_bridge;
  * @set_property: called when a property is changed
  * @set_config: apply a new CRTC configuration
  * @page_flip: initiate a page flip
+ * @atomic_duplicate_state: duplicate the atomic state for this CRTC
+ * @atomic_destroy_state: destroy an atomic state for this CRTC
+ * @atomic_set_property: set a property on an atomic state for this CRTC
  *
  * The drm_crtc_funcs structure is the central CRTC management structure
  * in the DRM.  Each CRTC controls one or more connectors (note that the name
@@ -288,6 +310,15 @@ struct drm_crtc_funcs {

int (*set_property)(struct drm_crtc *crtc,
struct drm_property *property, uint64_t val);
+
+   /* atomic update handling */
+   struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
+   void (*atomic_destroy_state)(struct drm_crtc *crtc,
+struct drm_crtc_state *cstate);
+   int (*atomic_set_property)(struct drm_crtc *crtc,
+  struct drm_crtc_state *state,
+  struct drm_property *property,
+  uint64_t val);
 };

 /**
@@ -317,6 +348,7 @@ struct drm_crtc_funcs {
  * @pixeldur_ns: precise pixel timing
  * @helper_private: mid-layer private data
  * @properties: property tracking for this CRTC
+ * @state: current atomic state for this CRTC
  * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
  * legacy ioctls
  *
@@ -374,6 +406,8 @@ struct drm_crtc {

struct drm_object_properties properties;

+   struct drm_crtc_state *state;
+
/*
 * For legacy crtc ioctls so that atomic drivers can get at the locking
 * acquire context.
@@ -381,6 +415,16 @@ struct drm_crtc {
struct drm_modeset_acquire_ctx *acquire_ctx;
 };

+/**
+ * struct drm_connector_state - mutable connector state
+ * @crtc: crtc to connect connector to, NULL if disabled
+ * @state: backpointer to global drm_atomic_state
+ 

[PATCH 06/17] drm: Global atomic state handling

2014-11-02 Thread Daniel Vetter
Some differences compared to Rob's patches again:
- Dropped the committed and checked booleans. Checking will be
  internally enforced by always calling ->atomic_check before
  ->atomic_commit. And async handling needs to be solved differently
  because the current scheme completely side-steps ww mutex deadlock
  avoidance (and so either reinvents a new deadlock avoidance wheel or
  like the current code just deadlocks).

- State for connectors needed to be added, since now they have a
  full-blown drm_connector_state (so that drivers have something to
  attach their own stuff to).

- Refcounting is gone. I plane to solve async updates differently,
  since the lock-passing scheme doesn't cut it (since it abuses ww
  mutexes). Essentially what we need for async is a simple ownership
  transfer from the caller to the driver. That doesn't need full-blown
  refcounting.

- The acquire ctx is a pointer. Real atomic callers should have that
  on their stack, legacy entry points need to put the right one
  (obtained by drm_modeset_legacy_acuire_ctx) in there.

- I've dropped all hooks except check/commit. All the begin/end
  handling is done by core functions and is the same.

- commit/check are just thin wrappers that ensure that ->check is
  always called.

- To help out with locking in the legacy implementations I've added a
  helper to just grab all locks in the backoff case.

v2: Add notices that check/commit can fail with EDEADLK.

v3:
- More consistent naming for state_alloc.
- Add state_clear which is needed for backoff and retry.

v4: Planes/connectors can switch between crtcs, and we need to be
careful that we grab the state (and locks) for both the old and new
crtc. Improve the interface functions to ensure this.

v5: Add functions to grab affected connectors for a crtc and to recompute
the crtc->enable state. This is useful for both helper and atomic ioctl
code when e.g. removing a connector.

v6: Squash in fixup from Fengguang to use ERR_CAST.

v7: Add debug output.

v8: Make checkpatch happy about kcalloc argument ordering.

v9: Improve kerneldoc in drm_crtc.h

v10:
- Fix another kcalloc argument misorder I've missed.
- More polish for kerneldoc.

v11: Clarify the ownership rules for the state object. The new rule is
that a successful drm_atomic_commit (whether synchronous or asnyc)
always inherits the state and is responsible for the clean-up. That
way async and sync ->commit functions are more similar.

v12: A few bugfixes:
- Assign state->state pointers correctly when grabbing state objects -
  we need to link them up with the global state.
- Handle a NULL crtc in set_crtc_for_plane to simplify code flow a bit
  for the callers of this function.

Cc: Fengguang Wu 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/Makefile |   2 +-
 drivers/gpu/drm/drm_atomic.c | 588 +++
 include/drm/drm_atomic.h |  63 +
 include/drm/drm_crtc.h   |  35 +++
 4 files changed, 687 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_atomic.c
 create mode 100644 include/drm/drm_atomic.h

diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index a3149e20a249..2e89cd50c14f 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -14,7 +14,7 @@ drm-y   :=drm_auth.o drm_bufs.o drm_cache.o \
drm_info.o drm_debugfs.o drm_encoder_slave.o \
drm_trace_points.o drm_global.o drm_prime.o \
drm_rect.o drm_vma_manager.o drm_flip_work.o \
-   drm_modeset_lock.o
+   drm_modeset_lock.o drm_atomic.o

 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
new file mode 100644
index ..c6db8a48cad6
--- /dev/null
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -0,0 +1,588 @@
+/*
+ * Copyright (C) 2014 Red Hat
+ * Copyright (C) 2014 Intel Corp.
+ *
+ * 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, sublicense,
+ * 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 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 NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN 

[PATCH 07/17] drm: Add atomic/plane helpers

2014-11-02 Thread Daniel Vetter
This is the first cut of atomic helper code. As-is it's only useful to
implement a pure atomic interface for plane updates.

Later patches will integrate this with the crtc helpers so that full
atomic updates are possible. We also need a pile of helpers to aid
drivers in transitioning from the legacy world to the shiny new atomic
age. Finally we need helpers to implement legacy ioctls on top of the
atomic interface.

The design of the overall helpers<->driver interaction is fairly
simple, but has an unfortunate large interface:

- We have ->atomic_check callbacks for crtcs and planes. The idea is
  that connectors don't need any checking, and if they do they can
  adjust the relevant crtc driver-private state. So no connector hooks
  should be needed. Also the crtc helpers integration will do the
  ->best_encoder checks, so no need for that.

- Framebuffer pinning needs to be done before we can commit to the hw
  state. This is especially important for async updates where we must
  pin all buffers before returning to userspace, so that really only
  hw failures can happen in the asynchronous worker.

  Hence we add ->prepare_fb and ->cleanup_fb hooks for this resources
  management.

- The actual atomic plane commit can't fail (except hw woes), so has
  void return type. It has three stages:
  1. Prepare all affected crtcs with crtc->atomic_begin. Drivers can
 use this to unset the GO bit or similar latches to prevent plane
 updates.
  2. Update plane state by looping over all changed planes and calling
 plane->atomic_update. Presuming the hardware is sane and has GO
 bits drivers can simply bash the state into the hardware in this
 function. Other drivers might use this to precompute hw state for
 the final step.
  3. Finally latch the update for the next vblank with
 crtc->atomic_flush. Note that this function doesn't need to wait
 for the vblank to happen even for the synchronous case.

v2: Clear drm__state->state to NULL when swapping in state.

v3: Add TODO that we don't short-circuit plane updates for now. Likely
no one will care.

v4: Squash in a bit of polish that somehow landed in the wrong (later)
patche.

v5: Integrate atomic functions into the drm docbook and fixup the
kerneldoc.

v6: Fixup fixup patch squashing fumble.

v7: Don't touch the legacy plane state plane->fb and plane->crtc. This
is only used by the legacy ioctl code in the drm core, and that code
already takes care of updating the pointers in all relevant cases.
This is in stark contrast to connector->encoder->crtc links on the
modeset side, which we still need to set since the core doesn't touch
them.

Also some more kerneldoc polish.

v8: Drop outdated comment.

v9: Handle the state->state pointer correctly: Only clearing the
->state pointer when assigning the state to the kms object isn't good
enough. We also need to re-link the swapped out state into the
drm_atomic_state structure.

Signed-off-by: Daniel Vetter 
---
 Documentation/DocBook/drm.tmpl  |   4 +
 drivers/gpu/drm/Makefile|   2 +-
 drivers/gpu/drm/drm_atomic_helper.c | 355 
 include/drm/drm_atomic_helper.h |  44 +
 include/drm/drm_crtc.h  |   6 +
 include/drm/drm_crtc_helper.h   |   6 +
 include/drm/drm_plane_helper.h  |  22 +++
 7 files changed, 438 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_atomic_helper.c
 create mode 100644 include/drm/drm_atomic_helper.h

diff --git a/Documentation/DocBook/drm.tmpl b/Documentation/DocBook/drm.tmpl
index 89829ae58e97..ea0ef43b19e1 100644
--- a/Documentation/DocBook/drm.tmpl
+++ b/Documentation/DocBook/drm.tmpl
@@ -996,6 +996,10 @@ int max_width, max_height;
 !Edrivers/gpu/drm/drm_modes.c
 
 
+  Atomic Mode Setting Function Reference
+!Edrivers/gpu/drm/drm_atomic.c
+
+
   Frame Buffer Creation
   struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
 struct drm_file *file_priv,
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 2e89cd50c14f..96338e349a24 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -24,7 +24,7 @@ drm-$(CONFIG_DRM_PANEL) += drm_panel.o
 drm-$(CONFIG_OF) += drm_of.o

 drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
-   drm_plane_helper.o drm_dp_mst_topology.o
+   drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o
 drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
 drm_kms_helper-$(CONFIG_DRM_KMS_FB_HELPER) += drm_fb_helper.o
 drm_kms_helper-$(CONFIG_DRM_KMS_CMA_HELPER) += drm_fb_cma_helper.o
diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
new file mode 100644
index ..55a8eb2678b0
--- /dev/null
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -0,0 +1,355 @@
+/*
+ * Copyright (C) 2014 Red Hat
+ * Copyright (C) 2014 Intel Corp.
+ *
+ * Permission 

[PATCH 08/17] drm/plane-helper: transitional atomic plane helpers

2014-11-02 Thread Daniel Vetter
Converting a driver to the atomic interface can be a daunting
undertaking. One of the prerequisites is to have full universal planes
support.

To make that transition a bit easier this pathc provides plane helpers
which use the new atomic helper callbacks just only for the plane
changes. This way the plane update functionality can be tested without
being forced to convert everything at once.

Of course a real atomic update capable driver will implement the
all plane properties through the atomic interface, so these helpers
are mostly transitional. But they can be used to enable proper
universal plane support, especially once the crtc helpers have also
been adapted.

v2: Use ->atomic_duplicate_state if available.

v3: Don't forget to call ->atomic_destroy_state if available.

v4: Fixup kerneldoc, reported by Paulo.

v5: Extract a common plane_commit helper and fix some bugs in the
plane_state setup of the plane_disable implementation.

v6: Fix issues with the cleanup of the old fb. Since transitional
helpers can be mixed we need to assume that the old fb has been set up
by a legacy path (e.g. set_config or page_flip when the primary plane
is converted to use these functions already). Hence pass an additional
old_fb parameter to plane_commit to do that cleanup work correctly.

v7:
- Fix spurious WARNING (crtc helpers really love to disable stuff
  harder) and fix array index bonghits.
- Correctly handle the lack of plane->state object, necessary for
  transitional use.
- Don't indicate failure if drm_vblank_get doesn't work - that's
  expected when the pipe is in dpms off mode.

Cc: Paulo Zanoni 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_plane_helper.c | 172 -
 include/drm/drm_plane_helper.h |   8 ++
 2 files changed, 179 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_plane_helper.c 
b/drivers/gpu/drm/drm_plane_helper.c
index 827ec1a3040b..45aa8c98e3fb 100644
--- a/drivers/gpu/drm/drm_plane_helper.c
+++ b/drivers/gpu/drm/drm_plane_helper.c
@@ -27,7 +27,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 

 #define SUBPIXEL_MASK 0x

@@ -369,3 +369,173 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc 
*crtc,
return drm_crtc_init_with_planes(dev, crtc, primary, NULL, funcs);
 }
 EXPORT_SYMBOL(drm_crtc_init);
+
+static int
+plane_commit(struct drm_plane *plane, struct drm_plane_state *plane_state,
+struct drm_framebuffer *old_fb)
+{
+   struct drm_plane_helper_funcs *plane_funcs;
+   struct drm_crtc *crtc[2];
+   struct drm_crtc_helper_funcs *crtc_funcs[2];
+   int i, ret = 0;
+
+   plane_funcs = plane->helper_private;
+
+   /* Since this is a transitional helper we can't assume that plane->state
+* is always valid. Hence we need to use plane->crtc instead of
+* plane->state->crtc as the old crtc. */
+   crtc[0] = plane->crtc;
+   crtc[1] = crtc[0] != plane_state->crtc ? plane_state->crtc : NULL;
+
+   for (i = 0; i < 2; i++)
+   crtc_funcs[i] = crtc[i] ? crtc[i]->helper_private : NULL;
+
+   if (plane_funcs->atomic_check) {
+   ret = plane_funcs->atomic_check(plane, plane_state);
+   if (ret)
+   goto fail;
+   }
+
+   if (plane_funcs->prepare_fb && plane_state->fb) {
+   ret = plane_funcs->prepare_fb(plane, plane_state->fb);
+   if (ret)
+   goto fail;
+   }
+
+   /* Point of no return, commit sw state. */
+   swap(plane->state, plane_state);
+
+   for (i = 0; i < 2; i++) {
+   if (crtc_funcs[i] && crtc_funcs[i]->atomic_begin)
+   crtc_funcs[i]->atomic_begin(crtc[i]);
+   }
+
+   plane_funcs->atomic_update(plane);
+
+   for (i = 0; i < 2; i++) {
+   if (crtc_funcs[i] && crtc_funcs[i]->atomic_flush)
+   crtc_funcs[i]->atomic_flush(crtc[i]);
+   }
+
+   for (i = 0; i < 2; i++) {
+   if (!crtc[i])
+   continue;
+
+   /* There's no other way to figure out whether the crtc is 
running. */
+   ret = drm_crtc_vblank_get(crtc[i]);
+   if (ret == 0) {
+   drm_crtc_wait_one_vblank(crtc[i]);
+   drm_crtc_vblank_put(crtc[i]);
+   }
+
+   ret = 0;
+   }
+
+   if (plane_funcs->cleanup_fb && old_fb)
+   plane_funcs->cleanup_fb(plane, old_fb);
+fail:
+   if (plane_state) {
+   if (plane->funcs->atomic_destroy_state)
+   plane->funcs->atomic_destroy_state(plane, plane_state);
+   else
+   kfree(plane_state);
+   }
+
+   return ret;
+}
+
+/**
+ * drm_plane_helper_update() - Helper for primary plane update
+ * @plane: plane object to update
+ * @crtc: owning CRTC of owning plane
+ * @fb: framebuffer to flip onto plane
+ * @crtc_x: x 

[PATCH 09/17] drm/crtc-helper: Transitional functions using atomic plane helpers

2014-11-02 Thread Daniel Vetter
These two functions allow drivers to reuse their atomic plane helpers
functions for the primary plane to implement the interfaces required
by the crtc helpers for the legacy ->set_config callback.

This is purely transitional and won't be used once the driver is fully
converted. But it allows partial conversions to the atomic plane
helpers which are functional.

v2:
- Use ->atomic_duplicate_state if available.
- Don't forget to run crtc_funcs->atomic_check.

v3: Shift source coordinates correctly for 16.16 fixed point.

v4: Don't forget to call ->atomic_destroy_state if available.

v5: Fixup kerneldoc.

v6: Reuse the plane_commit function from the transitional plane
helpers to avoid too much duplication.

v7:
- Remove some stale comment.
- Correctly handle the lack of plane->state object, necessary for
  transitional use.

v8: Fixup an embarrassing h/vdisplay mixup.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_crtc_helper.c  | 110 +
 drivers/gpu/drm/drm_plane_helper.c |  10 ++--
 include/drm/drm_crtc.h |   4 ++
 include/drm/drm_crtc_helper.h  |   7 +++
 include/drm/drm_plane_helper.h |   4 ++
 5 files changed, 130 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc_helper.c 
b/drivers/gpu/drm/drm_crtc_helper.c
index 6c65a0a28fbd..95ecbb131053 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 

 MODULE_AUTHOR("David Airlie, Jesse Barnes");
@@ -888,3 +889,112 @@ void drm_helper_resume_force_mode(struct drm_device *dev)
drm_modeset_unlock_all(dev);
 }
 EXPORT_SYMBOL(drm_helper_resume_force_mode);
+
+/**
+ * drm_helper_crtc_mode_set - mode_set implementation for atomic plane helpers
+ * @crtc: DRM CRTC
+ * @mode: DRM display mode which userspace requested
+ * @adjusted_mode: DRM display mode adjusted by ->mode_fixup callbacks
+ * @x: x offset of the CRTC scanout area on the underlying framebuffer
+ * @y: y offset of the CRTC scanout area on the underlying framebuffer
+ * @old_fb: previous framebuffer
+ *
+ * This function implements a callback useable as the ->mode_set callback
+ * required by the crtc helpers. Besides the atomic plane helper functions for
+ * the primary plane the driver must also provide the ->mode_set_nofb callback
+ * to set up the crtc.
+ *
+ * This is a transitional helper useful for converting drivers to the atomic
+ * interfaces.
+ */
+int drm_helper_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)
+{
+   struct drm_crtc_state *crtc_state;
+   struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
+   int ret;
+
+   if (crtc->funcs->atomic_duplicate_state)
+   crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
+   else if (crtc->state)
+   crtc_state = kmemdup(crtc->state, sizeof(*crtc_state),
+GFP_KERNEL);
+   else
+   crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
+   if (!crtc_state)
+   return -ENOMEM;
+
+   crtc_state->enable = true;
+   crtc_state->planes_changed = true;
+   drm_mode_copy(_state->mode, mode);
+   drm_mode_copy(_state->adjusted_mode, adjusted_mode);
+
+   if (crtc_funcs->atomic_check) {
+   ret = crtc_funcs->atomic_check(crtc, crtc_state);
+   if (ret) {
+   kfree(crtc_state);
+
+   return ret;
+   }
+   }
+
+   swap(crtc->state, crtc_state);
+
+   crtc_funcs->mode_set_nofb(crtc);
+
+   if (crtc_state) {
+   if (crtc->funcs->atomic_destroy_state)
+   crtc->funcs->atomic_destroy_state(crtc, crtc_state);
+   else
+   kfree(crtc_state);
+   }
+
+   return drm_helper_crtc_mode_set_base(crtc, x, y, old_fb);
+}
+EXPORT_SYMBOL(drm_helper_crtc_mode_set);
+
+/**
+ * drm_helper_crtc_mode_set_base - mode_set_base implementation for atomic 
plane helpers
+ * @crtc: DRM CRTC
+ * @x: x offset of the CRTC scanout area on the underlying framebuffer
+ * @y: y offset of the CRTC scanout area on the underlying framebuffer
+ * @old_fb: previous framebuffer
+ *
+ * This function implements a callback useable as the ->mode_set_base used
+ * required by the crtc helpers. The driver must provide the atomic plane 
helper
+ * functions for the primary plane.
+ *
+ * This is a transitional helper useful for converting drivers to the atomic
+ * interfaces.
+ */
+int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
+ struct drm_framebuffer *old_fb)
+{
+   struct drm_plane_state *plane_state;
+   struct drm_plane *plane = crtc->primary;
+
+   if 

[PATCH 10/17] drm: Atomic crtc/connector updates using crtc/plane helper interfaces

2014-11-02 Thread Daniel Vetter
So this is finally the integration of the crtc and plane helper
interfaces into the atomic helper functions.

In the check function we now have a few steps:

- First we update the output routing and figure out which crtcs need a
  full mode set. Suitable encoders are selected using ->best_encoder,
  with the same semantics as the crtc helpers of implicitly disabling
  all connectors currently using the encoder.

- Then we pull all other connectors into the state update which feed
  from a crtc which changes. This must be done do catch mode changes
  and similar updates - atomic updates are differences on top of the
  current state.

- Then we call all the various ->mode_fixup to compute the adjusted
  mode. Note that here we have a slight semantic difference compared
  to the crtc helpers: We have not yet updated the encoder->crtc link
  when calling the encoder's ->mode_fixup function. But that's a
  requirement when converting to atomic since we want to prepare the
  entire state completely contained with the over drm_atomic_state
  structure. So this must be carefully checked when converting drivers
  over to atomic helpers.

- Finally we do call the atomic_check functions on planes and crtcs.

The commit function is also quite a beast:

- The only step that can fail is done first, namely pinning the
  framebuffers. After that we cross the point of no return, an async
  commit would push all that into the worker thread.

- The disabling of encoders and connectors is a bit tricky, since
  depending upon the final state we need to select different crtc
  helper functions.

- Software tracking is a bit clarified compared to the crtc helpers:
  We commit the software state before starting to touch the hardware,
  like crtc helpers. But since we just swap them we still have the old
  state (i.e. the current hw state) around, which is really handy to
  write simple disable functions. So no more
  drm_crtc_helper_disable_all_unused_functions kind of fun because
  we're leaving unused crtcs/encoders behind. Everything gets shut
  down in-order now, which is one of the key differences of the i915
  helpers compared to crtc helpers and a really nice additional
  guarantee.

- Like with the plane helpers the atomic commit function waits for one
  vblank to pass before calling the framebuffer cleanup function.

Compared to Rob's helper approach there's a bunch of upsides:

- All the interfaces which can fail are called in the ->check hook
  (i.e. ->best_match and the various ->mode_fixup hooks). This means
  that drivers can just reuse those functions and don't need to move
  everything into ->atomic_check callbacks. If drivers have no need
  for additional constraint checking beyong their existing crtc
  helper callbacks they don't need to do anything.

- The actual commit operation is properly stage: First we prepare
  framebuffers, which can potentially still fail (due to memory
  exhausting). This is important for the async case, where this must
  be done synchronously to correctly return errors.

- The output configuration changes (done with crtc helper functions)
  and the plane update (using atomic plane helpers) are correctly
  interleaved: First we shut down any crtcs that need changing, then
  we update planes and finally we enable everything again. Hardware
  without GO bits must be more careful with ordering, which this
  sequence enables.

- Also for hardware with shared output resources (like display PLLs)
  we first must shut down the old configuration before we can enable
  the new one. Otherwise we can hit an impossible intermediate state
  where there's not enough PLLs (which is the point behind atomic
  updates).

v2:
- Ensure that users of ->check update crtc_state->enable correctly.
- Update the legacy state in crtc/plane structures. Eventually we want
  to remove that, but for now the drm core still expects this (especially
  the plane->fb pointer).

v3: A few changes for better async handling:

- Reorder the software side state commit so that it happens all before
  we touch the hardware. This way async support becomes very easy
  since we can punt all the actual hw touching to a worker thread. And
  as long as we synchronize with that thread (flushing or cancelling,
  depending upon what the driver can handle) before we commit the next
  software state there's no need for any locking in the worker thread
  at all. Which greatly simplifies things.

  And as long as we synchronize with all relevant threads we can have
  a lot of them (e.g. per-crtc for per-crtc updates) running in
  parallel.

- Expose pre/post plane commit steps separately. We need to expose the
  actual hw commit step anyway for drivers to be able to implement
  asynchronous commit workers. But if we expose pre/post and plane
  commit steps individually we allow drivers to selectively use atomic
  helpers.

- I've forgotten to call encoder/bridge ->mode_set functions, fix
  this.

v4: Add debug output and fix a mixup 

[PATCH 11/17] drm/atomic-helper: implementatations for legacy interfaces

2014-11-02 Thread Daniel Vetter
Well, except page_flip since that requires async commit, which isn't
there yet.

For the functions which changes planes there's a bit of trickery
involved to keep the fb refcounting working. But otherwise fairly
straight-forward atomic updates.

The property setting functions are still a bit incomplete. Once we
have generic properties (e.g. rotation, but also all the properties
needed by the atomic ioctl) we need to filter those out and parse them
in the helper. Preferrably with the same function as used by the real
atomic ioctl implementation.

v2: Fixup kerneldoc, reported by Paulo.

v3: Add missing EXPORT_SYMBOL.

v4: We need to look at the crtc of the modeset, not some random
leftover one from a previous loop when udpating the connector->crtc
routing. Also push some local variables into inner loops to avoid
these kinds of bugs.

v5: Adjust semantics - drivers now own the atomic state upon
successfully synchronous commit.

v6: Use the set_crtc_for_plane function to assign the crtc, since
otherwise the book-keeping is off.

v7:
- Improve comments.
- Filter out the crtc of the ->set_config call when recomputing
  crtc_state->enabled: We should compute the same state, but not doing
  so will give us a good chance to catch bugs and inconsistencies -
  the atomic helper's atomic_check function re-validates this again.
- Fix the set_config implementation logic when disabling the crtc: We
  still need to update the output routing to disable all the
  connectors properly in the state. Caught by the atomic_check
  functions, so at least that part worked ;-) Also add some WARN_ONs
  to ensure ->set_config preconditions all apply.

v8: Fixup an embarrassing h/vdisplay mixup.

Cc: Paulo Zanoni 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_atomic_helper.c | 511 
 include/drm/drm_atomic_helper.h |  21 ++
 2 files changed, 532 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 887e1971c915..26fe60356a0f 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -1045,3 +1045,514 @@ void drm_atomic_helper_swap_state(struct drm_device 
*dev,
}
 }
 EXPORT_SYMBOL(drm_atomic_helper_swap_state);
+
+/**
+ * drm_atomic_helper_update_plane - Helper for primary plane update using 
atomic
+ * @plane: plane object to update
+ * @crtc: owning CRTC of owning plane
+ * @fb: framebuffer to flip onto plane
+ * @crtc_x: x offset of primary plane on crtc
+ * @crtc_y: y offset of primary plane on crtc
+ * @crtc_w: width of primary plane rectangle on crtc
+ * @crtc_h: height of primary plane rectangle on crtc
+ * @src_x: x offset of @fb for panning
+ * @src_y: y offset of @fb for panning
+ * @src_w: width of source rectangle in @fb
+ * @src_h: height of source rectangle in @fb
+ *
+ * Provides a default plane update handler using the atomic driver interface.
+ *
+ * RETURNS:
+ * Zero on success, error code on failure
+ */
+int drm_atomic_helper_update_plane(struct drm_plane *plane,
+  struct drm_crtc *crtc,
+  struct drm_framebuffer *fb,
+  int crtc_x, int crtc_y,
+  unsigned int crtc_w, unsigned int crtc_h,
+  uint32_t src_x, uint32_t src_y,
+  uint32_t src_w, uint32_t src_h)
+{
+   struct drm_atomic_state *state;
+   struct drm_plane_state *plane_state;
+   int ret = 0;
+
+   state = drm_atomic_state_alloc(plane->dev);
+   if (!state)
+   return -ENOMEM;
+
+   state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
+retry:
+   plane_state = drm_atomic_get_plane_state(state, plane);
+   if (IS_ERR(plane_state)) {
+   ret = PTR_ERR(plane_state);
+   if (ret == -EDEADLK)
+   goto backoff;
+   else
+   goto fail;
+   }
+
+   drm_atomic_set_crtc_for_plane(plane_state, crtc);
+   plane_state->fb = fb;
+   plane_state->crtc_x = crtc_x;
+   plane_state->crtc_y = crtc_y;
+   plane_state->crtc_h = crtc_h;
+   plane_state->crtc_w = crtc_w;
+   plane_state->src_x = src_x;
+   plane_state->src_y = src_y;
+   plane_state->src_h = src_h;
+   plane_state->src_w = src_w;
+
+   ret = drm_atomic_commit(state);
+   if (ret == -EDEADLK)
+   goto backoff;
+
+   /* Driver takes ownership of state on successful commit. */
+   if (ret == 0)
+   return 0;
+fail:
+   drm_atomic_state_free(state);
+
+   return ret;
+backoff:
+   drm_atomic_legacy_backoff(state);
+   drm_atomic_state_clear(state);
+
+   /*
+* Someone might have exchanged the framebuffer while we dropped locks
+* in the backoff code. We need to fix up the fb refcount tracking the
+* core does for us.
+*/
+   

[PATCH 12/17] drm/atomic: Integrate fence support

2014-11-02 Thread Daniel Vetter
This patch is for enabling async commits. It replaces an earlier
approach which added an async boolean paramter to the ->prepare_fb
callbacks. The idea is that prepare_fb picks up the right fence to
synchronize against, which is then used by the synchronous commit
helper. For async commits drivers can either register a callback to
the fence or simply do the synchronous wait in their async work queue.

v2: Remove unused variable.

v3: Only wait for fences after the point of no return in the part
of the commit function which can be run asynchronously. This is after
the atomic state has been swapped in, hence now check
plane->state->fence.

Also add a WARN_ON to make sure we don't try to wait on a fence when
there's no fb, just as a sanity check.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_atomic_helper.c | 23 +++
 include/drm/drm_crtc.h  |  3 +++
 2 files changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 26fe60356a0f..afdc376aa7e7 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 

 static void
 drm_atomic_helper_plane_changed(struct drm_atomic_state *state,
@@ -704,6 +705,26 @@ void drm_atomic_helper_commit_post_planes(struct 
drm_device *dev,
 }
 EXPORT_SYMBOL(drm_atomic_helper_commit_post_planes);

+static void wait_for_fences(struct drm_device *dev,
+   struct drm_atomic_state *state)
+{
+   int nplanes = dev->mode_config.num_total_plane;
+   int i;
+
+   for (i = 0; i < nplanes; i++) {
+   struct drm_plane *plane = state->planes[i];
+
+   if (!plane || !plane->state->fence)
+   continue;
+
+   WARN_ON(!plane->state->fb);
+
+   fence_wait(plane->state->fence, false);
+   fence_put(plane->state->fence);
+   plane->state->fence = NULL;
+   }
+}
+
 static void
 wait_for_vblanks(struct drm_device *dev, struct drm_atomic_state *old_state)
 {
@@ -801,6 +822,8 @@ int drm_atomic_helper_commit(struct drm_device *dev,
 * current layout.
 */

+   wait_for_fences(dev, state);
+
drm_atomic_helper_commit_pre_planes(dev, state);

drm_atomic_helper_commit_planes(dev, state);
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index ddff25eb34d4..5c34665ebb9d 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -42,6 +42,7 @@ struct drm_object_properties;
 struct drm_file;
 struct drm_clip_rect;
 struct device_node;
+struct fence;

 #define DRM_MODE_OBJECT_CRTC 0x
 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
@@ -659,6 +660,7 @@ struct drm_connector {
  * struct drm_plane_state - mutable plane state
  * @crtc: currently bound CRTC, NULL if disabled
  * @fb: currently bound fb
+ * @fence: optional fence to wait for before scanning out @fb
  * @crtc_x: left position of visible portion of plane on crtc
  * @crtc_y: upper position of visible portion of plane on crtc
  * @crtc_w: width of visible portion of plane on crtc
@@ -674,6 +676,7 @@ struct drm_connector {
 struct drm_plane_state {
struct drm_crtc *crtc;
struct drm_framebuffer *fb;
+   struct fence *fence;

/* Signed dest location allows it to be partially off screen */
int32_t crtc_x, crtc_y;
-- 
2.1.1



[PATCH 13/17] drm/atomic-helpers: document how to implement async commit

2014-11-02 Thread Daniel Vetter
No helper function to do it all yet provided since no driver has
support for driver core fences yet. Which we'd need to make the
implementation really generic.

v2: Clarify async howto a bit per the discussion With Rob Clark.

Cc: Rob Clark 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_atomic_helper.c | 38 +
 1 file changed, 38 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index afdc376aa7e7..92ae34bde44d 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -841,6 +841,44 @@ int drm_atomic_helper_commit(struct drm_device *dev,
 EXPORT_SYMBOL(drm_atomic_helper_commit);

 /**
+ * DOC: implementing async commit
+ *
+ * For now the atomic helpers don't support async commit directly. If there is
+ * real need it could be added though, using the dma-buf fence infrastructure
+ * for generic synchronization with outstanding rendering.
+ *
+ * For now drivers have to implement async commit themselves, with the 
following
+ * sequence being the recommended one:
+ *
+ * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function
+ * which commit needs to call which can fail, so we want to run it first and
+ * synchronously.
+ *
+ * 2. Synchronize with any outstanding asynchronous commit worker threads which
+ * might be affected the new state update. This can be done by either 
cancelling
+ * or flushing the work items, depending upon whether the driver can deal with
+ * cancelled updates. Note that it is important to ensure that the framebuffer
+ * cleanup is still done when cancelling.
+ *
+ * For sufficient parallelism it is recommended to have a work item per crtc
+ * (for updates which don't touch global state) and a global one. Then we only
+ * need to synchronize with the crtc work items for changed crtcs and the 
global
+ * work item, which allows nice concurrent updates on disjoint sets of crtcs.
+ *
+ * 3. The software state is updated synchronously with
+ * drm_atomic_helper_swap_state. Doing this under the protection of all modeset
+ * locks means concurrent callers never see inconsistent state. And doing this
+ * while it's guaranteed that no relevant async worker runs means that async
+ * workers do not need grab any locks. Actually they must not grab locks, for
+ * otherwise the work flushing will deadlock.
+ *
+ * 4. Schedule a work item to do all subsequent steps, using the split-out
+ * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and
+ * then cleaning up the framebuffers after the old framebuffer is no longer
+ * being displayed.
+ */
+
+/**
  * drm_atomic_helper_prepare_planes - prepare plane resources after commit
  * @dev: DRM device
  * @state: atomic state object with old state structures
-- 
2.1.1



[PATCH 14/17] drm/atomic-helper: implement ->page_flip

2014-11-02 Thread Daniel Vetter
Currently there is no way to implement async flips using atomic, that
essentially requires us to be able to cancel pending requests
mid-flight.

To be able to do that (and I guess we want this since vblank synced
updates whic opportunistically cancel still pending updates seem to be
wanted) we'd need to add a mandatory cancellation mode. Depending upon
the exact semantics we decide upon that could mean that userspace will
not get completion events, or will get them all stacked up.

So reject async updates for now. Also async updates usually means not
vblank synced at all, and I guess for drivers which want to support
this they should simply add a special pageflip handler (since usually
you need a special flip cmd to achieve this). That kind of async flip
is pretty much exclusively just used for games and benchmarks where
dropping just one frame means you'll get a headshot or something bad
like that ... And so slight amounts of tearing is acceptable.

v2: Fixup kerneldoc, reported by Paulo.

v3: Use the set_crtc_for_plane function to assign the crtc, since
otherwise the book-keeping is off.

v4: Update crtc->primary->fb since ->page_flip is the only driver
callback where the core won't do this itself. We might want to fix
this inconsistency eventually.

Cc: Paulo Zanoni 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_atomic_helper.c | 90 +
 include/drm/drm_atomic_helper.h |  5 +++
 2 files changed, 95 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 92ae34bde44d..70bd67cf86e3 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -1617,3 +1617,93 @@ backoff:
goto retry;
 }
 EXPORT_SYMBOL(drm_atomic_helper_connector_set_property);
+
+/**
+ * drm_atomic_helper_page_flip - execute a legacy page flip
+ * @crtc: DRM crtc
+ * @fb: DRM framebuffer
+ * @event: optional DRM event to signal upon completion
+ * @flags: flip flags for non-vblank sync'ed updates
+ *
+ * Provides a default page flip implementation using the atomic driver 
interface.
+ *
+ * Note that for now so called async page flips (i.e. updates which are not
+ * synchronized to vblank) are not supported, since the atomic interfaces have
+ * no provisions for this yet.
+ *
+ * Returns:
+ * Returns 0 on success, negative errno numbers on failure.
+ */
+int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
+   struct drm_framebuffer *fb,
+   struct drm_pending_vblank_event *event,
+   uint32_t flags)
+{
+   struct drm_plane *plane = crtc->primary;
+   struct drm_atomic_state *state;
+   struct drm_plane_state *plane_state;
+   struct drm_crtc_state *crtc_state;
+   int ret = 0;
+
+   if (flags & DRM_MODE_PAGE_FLIP_ASYNC)
+   return -EINVAL;
+
+   state = drm_atomic_state_alloc(plane->dev);
+   if (!state)
+   return -ENOMEM;
+
+   state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
+retry:
+   crtc_state = drm_atomic_get_crtc_state(state, crtc);
+   if (IS_ERR(crtc_state)) {
+   ret = PTR_ERR(crtc_state);
+   if (ret == -EDEADLK)
+   goto backoff;
+   else
+   goto fail;
+   }
+   crtc_state->event = event;
+
+   plane_state = drm_atomic_get_plane_state(state, plane);
+   if (IS_ERR(plane_state)) {
+   ret = PTR_ERR(plane_state);
+   if (ret == -EDEADLK)
+   goto backoff;
+   else
+   goto fail;
+   }
+
+   drm_atomic_set_crtc_for_plane(plane_state, crtc);
+   plane_state->fb = fb;
+
+   ret = drm_atomic_async_commit(state);
+   if (ret == -EDEADLK)
+   goto backoff;
+
+   /* Driver takes ownership of state on successful async commit. */
+   if (ret == 0) {
+   /* TODO: ->page_flip is the only driver callback where the core
+* doesn't update plane->fb. For now patch it up here. */
+   plane->fb = plane->state->fb;
+
+   return 0;
+   }
+
+fail:
+   drm_atomic_state_free(state);
+
+   return ret;
+backoff:
+   drm_atomic_legacy_backoff(state);
+   drm_atomic_state_clear(state);
+
+   /*
+* Someone might have exchanged the framebuffer while we dropped locks
+* in the backoff code. We need to fix up the fb refcount tracking the
+* core does for us.
+*/
+   plane->old_fb = plane->fb;
+
+   goto retry;
+}
+EXPORT_SYMBOL(drm_atomic_helper_page_flip);
diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
index 8cd6fe7a48e5..28a2f3a815fd 100644
--- a/include/drm/drm_atomic_helper.h
+++ b/include/drm/drm_atomic_helper.h
@@ -69,5 +69,10 @@ int drm_atomic_helper_plane_set_property(struct drm_plane 
*plane,
 int 

[PATCH 15/17] drm/atomic-helpers: functions for state duplicate/destroy/reset

2014-11-02 Thread Daniel Vetter
The atomic users and helpers assume that there is always a obj->state
structure around. Which means drivers need to somehow create that at
driver load time. Also it should obviously reset hardware state, so
needs to be reset upon resume.

Finally the destroy/duplicate_state functions are an awful lot of
boilerplate if the driver doesn't need anything beyond the default
state objects.

So add helper functions for all of this.

v2: Somehow the plane/connector versions got lost in the first
version.

v3: Add kerneldoc.

v4: Make duplicate_state functions a bit more robust, which is useful
for debugging state tracking issues when transitioning to atomic.

v5: Clear temporary variables in the crtc state when duplicating it,
like ->mode_changed or ->planes_changed. If we don't do this stale
values for these might pollute the next atomic modeset.

v6: Also clear crtc_state->event in case the driver didn't (yet) clear
this out.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_atomic_helper.c | 154 +++-
 include/drm/drm_atomic_helper.h |  19 +
 2 files changed, 170 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 70bd67cf86e3..bd38df3cbe55 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -1429,7 +1429,7 @@ EXPORT_SYMBOL(drm_atomic_helper_set_config);
 /**
  * drm_atomic_helper_crtc_set_property - helper for crtc prorties
  * @crtc: DRM crtc
- * @prorty: DRM property
+ * @property: DRM property
  * @val: value of property
  *
  * Provides a default plane disablle handler using the atomic driver interface.
@@ -1493,7 +1493,7 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_set_property);
 /**
  * drm_atomic_helper_plane_set_property - helper for plane prorties
  * @plane: DRM plane
- * @prorty: DRM property
+ * @property: DRM property
  * @val: value of property
  *
  * Provides a default plane disable handler using the atomic driver interface.
@@ -1557,7 +1557,7 @@ EXPORT_SYMBOL(drm_atomic_helper_plane_set_property);
 /**
  * drm_atomic_helper_connector_set_property - helper for connector prorties
  * @connector: DRM connector
- * @prorty: DRM property
+ * @property: DRM property
  * @val: value of property
  *
  * Provides a default plane disablle handler using the atomic driver interface.
@@ -1707,3 +1707,151 @@ backoff:
goto retry;
 }
 EXPORT_SYMBOL(drm_atomic_helper_page_flip);
+
+/**
+ * drm_atomic_helper_crtc_reset - default ->reset hook for CRTCs
+ * @crtc: drm CRTC
+ *
+ * Resets the atomic state for @crtc by freeing the state pointer and 
allocating
+ * a new empty state object.
+ */
+void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
+{
+   kfree(crtc->state);
+   crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL);
+}
+EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);
+
+/**
+ * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook
+ * @crtc: drm CRTC
+ *
+ * Default CRTC state duplicate hook for drivers which don't have their own
+ * subclassed CRTC state structure.
+ */
+struct drm_crtc_state *
+drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc)
+{
+   struct drm_crtc_state *state;
+
+   if (WARN_ON(!crtc->state))
+   return NULL;
+
+   state = kmemdup(crtc->state, sizeof(*crtc->state), GFP_KERNEL);
+
+   if (state) {
+   state->mode_changed = false;
+   state->planes_changed = false;
+   state->event = NULL;
+   }
+
+   return state;
+}
+EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
+
+/**
+ * drm_atomic_helper_crtc_destroy_state - default state destroy hook
+ * @crtc: drm CRTC
+ * @state: CRTC state object to release
+ *
+ * Default CRTC state destroy hook for drivers which don't have their own
+ * subclassed CRTC state structure.
+ */
+void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
+ struct drm_crtc_state *state)
+{
+   kfree(state);
+}
+EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
+
+/**
+ * drm_atomic_helper_plane_reset - default ->reset hook for planes
+ * @plane: drm plane
+ *
+ * Resets the atomic state for @plane by freeing the state pointer and
+ * allocating a new empty state object.
+ */
+void drm_atomic_helper_plane_reset(struct drm_plane *plane)
+{
+   kfree(plane->state);
+   plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
+}
+EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
+
+/**
+ * drm_atomic_helper_plane_duplicate_state - default state duplicate hook
+ * @plane: drm plane
+ *
+ * Default plane state duplicate hook for drivers which don't have their own
+ * subclassed plane state structure.
+ */
+struct drm_plane_state *
+drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane)
+{
+   if (WARN_ON(!plane->state))
+   return NULL;
+
+   return kmemdup(plane->state, sizeof(*plane->state), 

[PATCH 16/17] drm: Docbook integration and over sections for all the new helpers

2014-11-02 Thread Daniel Vetter
In all cases the text requires that new drivers are converted to the
atomic interfaces.

v2: Add overview for state handling.

Signed-off-by: Daniel Vetter 
---
 Documentation/DocBook/drm.tmpl  | 20 +++-
 drivers/gpu/drm/drm_atomic_helper.c | 36 
 drivers/gpu/drm/drm_crtc_helper.c   | 20 
 drivers/gpu/drm/drm_plane_helper.c  | 26 +-
 4 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/Documentation/DocBook/drm.tmpl b/Documentation/DocBook/drm.tmpl
index ea0ef43b19e1..5e3a11f5e941 100644
--- a/Documentation/DocBook/drm.tmpl
+++ b/Documentation/DocBook/drm.tmpl
@@ -2324,8 +2324,25 @@ void intel_crt_init(struct drm_device *dev)
   
 
 
+  Atomic Modeset Helper Functions Reference
+  
+   Overview
+!Pdrivers/gpu/drm/drm_atomic_helper.c overview
+  
+  
+   Implementing Asynchronous Atomic Commit
+!Pdrivers/gpu/drm/drm_atomic_helper.c implementing async commit
+  
+  
+   Atomic State Reset and Initialization
+!Pdrivers/gpu/drm/drm_atomic_helper.c atomic state reset and initialization
+  
+!Edrivers/gpu/drm/drm_atomic_helper.c
+
+
   Modeset Helper Functions Reference
 !Edrivers/gpu/drm/drm_crtc_helper.c
+!Pdrivers/gpu/drm/drm_crtc_helper.c overview
 
 
   Output Probing Helper Functions Reference
@@ -2379,7 +2396,8 @@ void intel_crt_init(struct drm_device *dev)
 
 
   Plane Helper Reference
-!Edrivers/gpu/drm/drm_plane_helper.c Plane Helpers
+!Edrivers/gpu/drm/drm_plane_helper.c
+!Pdrivers/gpu/drm/drm_plane_helper.c overview
 
   

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index bd38df3cbe55..d0ca681d6326 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -32,6 +32,27 @@
 #include 
 #include 

+/**
+ * DOC: overview
+ *
+ * This helper library provides implementations of check and commit functions 
on
+ * top of the CRTC modeset helper callbacks and the plane helper callbacks. It
+ * also provides convenience implementations for the atomic state handling
+ * callbacks for drivers which don't need to subclass the drm core structures 
to
+ * add their own additional internal state.
+ *
+ * This library also provides default implementations for the check callback in
+ * drm_atomic_helper_check and for the commit callback with
+ * drm_atomic_helper_commit. But the individual stages and callbacks are expose
+ * to allow drivers to mix and match and e.g. use the plane helpers only
+ * together with a driver private modeset implementation.
+ *
+ * This library also provides implementations for all the legacy driver
+ * interfaces on top of the atomic interface. See drm_atomic_helper_set_config,
+ * drm_atomic_helper_disable_plane, drm_atomic_helper_disable_plane and the
+ * various functions to implement set_property callbacks. New drivers must not
+ * implement these functions themselves but must use the provided helpers.
+ */
 static void
 drm_atomic_helper_plane_changed(struct drm_atomic_state *state,
struct drm_plane_state *plane_state,
@@ -1709,6 +1730,21 @@ backoff:
 EXPORT_SYMBOL(drm_atomic_helper_page_flip);

 /**
+ * DOC: atomic state reset and initialization
+ *
+ * Both the drm core and the atomic helpers assume that there is always the 
full
+ * and correct atomic software state for all connectors, CRTCs and planes
+ * available. Which is a bit a problem on driver load and also after system
+ * suspend. One way to solve this is to have a hardware state read-out
+ * infrastructure which reconstructs the full software state (e.g. the i915
+ * driver).
+ *
+ * The simpler solution is to just reset the software state to everything off,
+ * which is easiest to do by calling drm_mode_config_reset(). To facilitate 
this
+ * the atomic helpers provide default reset implementations for all hooks.
+ */
+
+/**
  * drm_atomic_helper_crtc_reset - default ->reset hook for CRTCs
  * @crtc: drm CRTC
  *
diff --git a/drivers/gpu/drm/drm_crtc_helper.c 
b/drivers/gpu/drm/drm_crtc_helper.c
index 46728a8ac622..33195e9adaab 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -41,6 +41,26 @@
 #include 
 #include 

+/**
+ * DOC: overview
+ *
+ * The CRTC modeset helper library provides a default set_config implementation
+ * in drm_crtc_helper_set_config(). Plus a few other convenience functions 
using
+ * the same callbacks which drivers can use to e.g. restore the modeset
+ * configuration on resume with drm_helper_resume_force_mode().
+ *
+ * The driver callbacks are mostly compatible with the atomic modeset helpers,
+ * except for the handling of the primary plane: Atomic helpers require that 
the
+ * primary plane is implemented as a real standalone plane and not directly 
tied
+ * to the CRTC state. For easier transition this library provides functions to
+ * 

[PATCH 17/17] drm/atomic: Refcounting for plane_state->fb

2014-11-02 Thread Daniel Vetter
So my original plan was that the drm core refcounts framebuffers like
with the legacy ioctls. But that doesn't work for a bunch of reasons:

- State objects might live longer than until the next fb change
  happens for a plane. For example delayed cleanup work only happens
  _after_ the pageflip ioctl has completed. So this definitely doesn't
  work without the plane state holding its own refernces.

- The other issue is transition from legacy to atomic implementations,
  where the driver works under a mix of both worlds. Which means
  legacy paths might not properly update the ->fb pointer under
  plane->state->fb. Which is a bit a problem when then someone comes
  around and _does_ try to clean it up when it's long gone.

The second issue is just a bit a transition bug, since drivers should
update plane->state->fb in all the paths that aren't converted yet.
But a bit more robustness for the transition cant' hurt - we pull
similar tricks with cleaning up the old fb in the transitional helpers
already.

The pattern for drivers that transition is

if (plane->state)
drm_atomic_set_fb_for_plane(plane->state, plane->fb);

inserted after the fb update has logically completed at the end of
->set_config (or ->set_base/mode_set if using the crtc helpers),
->page_flip, ->update_plane or any other entry point which updates
plane->fb.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_atomic.c| 27 +++
 drivers/gpu/drm/drm_atomic_helper.c | 25 +++--
 drivers/gpu/drm/drm_crtc_helper.c   |  7 ---
 drivers/gpu/drm/drm_plane_helper.c  | 14 +++---
 include/drm/drm_atomic.h|  2 ++
 5 files changed, 59 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index c6db8a48cad6..af34321b675d 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -366,6 +366,33 @@ drm_atomic_set_crtc_for_plane(struct drm_plane_state 
*plane_state,
 EXPORT_SYMBOL(drm_atomic_set_crtc_for_plane);

 /**
+ * drm_atomic_set_fb_for_plane - set crtc for plane
+ * @plane_state: atomic state object for the plane
+ * @fb: fb to use for the plane
+ *
+ * Changing the assigned crtc for a plane requires us to grab the lock and 
state
+ * for the new crtc, as needed. This function takes care of all these details
+ * besides updating the pointer in the state object itself.
+ */
+void
+drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
+   struct drm_framebuffer *fb)
+{
+   if (plane_state->fb)
+   drm_framebuffer_unreference(plane_state->fb);
+   if (fb)
+   drm_framebuffer_reference(fb);
+   plane_state->fb = fb;
+
+   if (fb)
+   DRM_DEBUG_KMS("Set [FB:%d] for plane state %p\n",
+ fb->base.id, plane_state);
+   else
+   DRM_DEBUG_KMS("Set [NOFB] for plane state %p\n", plane_state);
+}
+EXPORT_SYMBOL(drm_atomic_set_fb_for_plane);
+
+/**
  * drm_atomic_set_crtc_for_connector - set crtc for connector
  * @conn_state: atomic state object for the connector
  * @crtc: crtc to use for the connector
diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index d0ca681d6326..a5de60faedff 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -1175,7 +1175,7 @@ retry:
}

drm_atomic_set_crtc_for_plane(plane_state, crtc);
-   plane_state->fb = fb;
+   drm_atomic_set_fb_for_plane(plane_state, fb);
plane_state->crtc_x = crtc_x;
plane_state->crtc_y = crtc_y;
plane_state->crtc_h = crtc_h;
@@ -1242,7 +1242,7 @@ retry:
}

drm_atomic_set_crtc_for_plane(plane_state, NULL);
-   plane_state->fb = NULL;
+   drm_atomic_set_fb_for_plane(plane_state, NULL);
plane_state->crtc_x = 0;
plane_state->crtc_y = 0;
plane_state->crtc_h = 0;
@@ -1402,7 +1402,7 @@ retry:
}

drm_atomic_set_crtc_for_plane(primary_state, crtc);
-   primary_state->fb = set->fb;
+   drm_atomic_set_fb_for_plane(primary_state, set->fb);
primary_state->crtc_x = 0;
primary_state->crtc_y = 0;
primary_state->crtc_h = set->mode->vdisplay;
@@ -1695,7 +1695,7 @@ retry:
}

drm_atomic_set_crtc_for_plane(plane_state, crtc);
-   plane_state->fb = fb;
+   drm_atomic_set_fb_for_plane(plane_state, fb);

ret = drm_atomic_async_commit(state);
if (ret == -EDEADLK)
@@ -1809,6 +1809,9 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
  */
 void drm_atomic_helper_plane_reset(struct drm_plane *plane)
 {
+   if (plane->state && plane->state->fb)
+   drm_framebuffer_unreference(plane->state->fb);
+
kfree(plane->state);
plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
 }
@@ -1824,10 +1827,17 @@ 

[Bug 79980] Random radeonsi crashes

2014-11-02 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=79980

--- Comment #216 from Cilyan Olowen  ---
Not sure if it is related, but I have the same log on dmesg while playing
Minecraft with Radeon 6970 (Northern Island, if I'm not mistaken). Linux
3.17.1, temp sensor around 57°C, not critical.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20141102/fe829906/attachment.html>


[Bug 79980] Random radeonsi crashes

2014-11-02 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=79980

Cilyan Olowen  changed:

   What|Removed |Added

 CC||gaknar at gmail.com

--- Comment #217 from Cilyan Olowen  ---
Created attachment 108795
  --> https://bugs.freedesktop.org/attachment.cgi?id=108795=edit
Last 300 lines of dmesg on a Radeon 6970

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20141102/a3a54896/attachment.html>


[PATCH] drm: Pull drm_crtc.h into the kerneldoc template

2014-11-02 Thread Daniel Vetter
While writing atomic docs I've noticed that I don't get any errors
for my screw-ups in drm_crtc.h. Fix this immediately.

This just does the bare minimum to get starts, lots of stuff isn't
properly documented yet unfortunately.

v2: Fix adjacent spelling error Sean noticed.

Reviewed-by: Sean Paul 
Cc: Sean Paul 
Signed-off-by: Daniel Vetter 
---
 Documentation/DocBook/drm.tmpl |  4 
 include/drm/drm_crtc.h | 28 ++--
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/Documentation/DocBook/drm.tmpl b/Documentation/DocBook/drm.tmpl
index be35bc328b77..89829ae58e97 100644
--- a/Documentation/DocBook/drm.tmpl
+++ b/Documentation/DocBook/drm.tmpl
@@ -1827,6 +1827,10 @@ void intel_crt_init(struct drm_device *dev)
 !Edrivers/gpu/drm/drm_crtc.c
 
 
+  KMS Data Structures
+!Iinclude/drm/drm_crtc.h
+
+
   KMS Locking
 !Pdrivers/gpu/drm/drm_modeset_lock.c kms locking
 !Iinclude/drm/drm_modeset_lock.h
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 44c57d2a64ec..82bb55ff41a2 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -142,8 +142,8 @@ struct drm_framebuffer_funcs {
int (*create_handle)(struct drm_framebuffer *fb,
 struct drm_file *file_priv,
 unsigned int *handle);
-   /**
-* Optinal callback for the dirty fb ioctl.
+   /*
+* Optional callback for the dirty fb ioctl.
 *
 * Userspace can notify the driver via this callback
 * that a area of the framebuffer has changed and should
@@ -226,7 +226,7 @@ struct drm_plane;
 struct drm_bridge;

 /**
- * drm_crtc_funcs - control CRTCs for a given device
+ * struct drm_crtc_funcs - control CRTCs for a given device
  * @save: save CRTC state
  * @restore: restore CRTC state
  * @reset: reset CRTC after state has been invalidated (e.g. resume)
@@ -290,7 +290,7 @@ struct drm_crtc_funcs {
 };

 /**
- * drm_crtc - central CRTC control structure
+ * struct drm_crtc - central CRTC control structure
  * @dev: parent DRM device
  * @head: list management
  * @mutex: per-CRTC locking
@@ -322,7 +322,7 @@ struct drm_crtc {
struct device_node *port;
struct list_head head;

-   /**
+   /*
 * crtc mutex
 *
 * This provides a read lock for the overall crtc state (mode, dpms
@@ -377,7 +377,7 @@ struct drm_crtc {


 /**
- * drm_connector_funcs - control connectors on a given device
+ * struct drm_connector_funcs - control connectors on a given device
  * @dpms: set power state (see drm_crtc_funcs above)
  * @save: save connector state
  * @restore: restore connector state
@@ -414,7 +414,7 @@ struct drm_connector_funcs {
 };

 /**
- * drm_encoder_funcs - encoder controls
+ * struct drm_encoder_funcs - encoder controls
  * @reset: reset state (e.g. at init or resume time)
  * @destroy: cleanup and free associated data
  *
@@ -428,7 +428,7 @@ struct drm_encoder_funcs {
 #define DRM_CONNECTOR_MAX_ENCODER 3

 /**
- * drm_encoder - central DRM encoder structure
+ * struct drm_encoder - central DRM encoder structure
  * @dev: parent DRM device
  * @head: list management
  * @base: base KMS object
@@ -472,7 +472,7 @@ struct drm_encoder {
 #define MAX_ELD_BYTES  128

 /**
- * drm_connector - central DRM connector control structure
+ * struct drm_connector - central DRM connector control structure
  * @dev: parent DRM device
  * @kdev: kernel device for sysfs attributes
  * @attr: sysfs attributes
@@ -566,7 +566,7 @@ struct drm_connector {
 };

 /**
- * drm_plane_funcs - driver plane control functions
+ * struct drm_plane_funcs - driver plane control functions
  * @update_plane: update the plane configuration
  * @disable_plane: shut down the plane
  * @destroy: clean up plane resources
@@ -594,7 +594,7 @@ enum drm_plane_type {
 };

 /**
- * drm_plane - central DRM plane control structure
+ * struct drm_plane - central DRM plane control structure
  * @dev: DRM device this plane belongs to
  * @head: for list management
  * @base: base mode object
@@ -632,7 +632,7 @@ struct drm_plane {
 };

 /**
- * drm_bridge_funcs - drm_bridge control functions
+ * struct drm_bridge_funcs - drm_bridge control functions
  * @attach: Called during drm_bridge_attach
  * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
  * @disable: Called right before encoder prepare, disables the bridge
@@ -658,7 +658,7 @@ struct drm_bridge_funcs {
 };

 /**
- * drm_bridge - central DRM bridge control structure
+ * struct drm_bridge - central DRM bridge control structure
  * @dev: DRM device this bridge belongs to
  * @head: list management
  * @base: base mode object
@@ -679,7 +679,7 @@ struct drm_bridge {
 };

 /**
- * drm_mode_set - new values for a CRTC config change
+ * struct drm_mode_set - new values for a CRTC config change
  * @head: list management
  * @fb: framebuffer to use for new config
  * @crtc: CRTC whose configuration 

[PATCH 03/17] drm: fixup kerneldoc in drm_crtc.h

2014-11-02 Thread Daniel Vetter
On Sun, Nov 02, 2014 at 02:19:16PM +0100, Daniel Vetter wrote:
> I've tried to cc all the people who have recently added new stuff
> but forgotten to update documentation.
> 
> I've also decided not to bother documenting the massive property list
> in struct drm_mode_config. If that beast keeps on growing we might want
> to extract it into a separate structure which we won't document.
> 
> Cc: Thomas Wood 
> Cc: Sean Paul 
> Cc: Russell King 
> Signed-off-by: Daniel Vetter 

Oops, I've somehow lost Sean's r-b on this and the preceeding patch.
Resent the preceeding patch since that had one small change Sean requested
and added his r-b locally to both.
-Daniel

> ---
>  include/drm/drm_crtc.h | 51 
> +++---
>  1 file changed, 36 insertions(+), 15 deletions(-)
> 
> diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> index 21a15850a4d5..a68e02be7e37 100644
> --- a/include/drm/drm_crtc.h
> +++ b/include/drm/drm_crtc.h
> @@ -231,6 +231,7 @@ struct drm_bridge;
>   * @restore: restore CRTC state
>   * @reset: reset CRTC after state has been invalidated (e.g. resume)
>   * @cursor_set: setup the cursor
> + * @cursor_set2: setup the cursor with hotspot, superseeds @cursor_set if set
>   * @cursor_move: move the cursor
>   * @gamma_set: specify color ramp for CRTC
>   * @destroy: deinit and free object
> @@ -292,11 +293,14 @@ struct drm_crtc_funcs {
>  /**
>   * struct drm_crtc - central CRTC control structure
>   * @dev: parent DRM device
> + * @port: OF node used by drm_of_find_possible_crtcs()
>   * @head: list management
>   * @mutex: per-CRTC locking
>   * @base: base KMS object for ID tracking etc.
>   * @primary: primary plane for this CRTC
>   * @cursor: cursor plane for this CRTC
> + * @cursor_x: current x position of the cursor, used for universal cursor 
> planes
> + * @cursor_y: current y position of the cursor, used for universal cursor 
> planes
>   * @enabled: is this CRTC enabled?
>   * @mode: current mode timings
>   * @hwmode: mode timings as programmed to hw regs
> @@ -309,10 +313,12 @@ struct drm_crtc_funcs {
>   * @gamma_size: size of gamma ramp
>   * @gamma_store: gamma ramp values
>   * @framedur_ns: precise frame timing
> - * @framedur_ns: precise line timing
> + * @linedur_ns: precise line timing
>   * @pixeldur_ns: precise pixel timing
>   * @helper_private: mid-layer private data
>   * @properties: property tracking for this CRTC
> + * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
> + *   legacy ioctls
>   *
>   * Each CRTC may have one or more connectors associated with it.  This 
> structure
>   * allows the CRTC to be controlled.
> @@ -483,6 +489,7 @@ struct drm_encoder {
>   * @connector_type_id: index into connector type enum
>   * @interlace_allowed: can this connector handle interlaced modes?
>   * @doublescan_allowed: can this connector handle doublescan?
> + * @stereo_allowed: can this connector handle stereo modes?
>   * @modes: modes available on this connector (from fill_modes() + user)
>   * @status: one of the drm_connector_status enums (connected, not, or 
> unknown)
>   * @probed_modes: list of modes derived directly from the display
> @@ -490,10 +497,13 @@ struct drm_encoder {
>   * @funcs: connector control functions
>   * @edid_blob_ptr: DRM property containing EDID if present
>   * @properties: property tracking for this connector
> + * @path_blob_ptr: DRM blob property data for the DP MST path property
>   * @polled: a %DRM_CONNECTOR_POLL_ value for core driven polling
>   * @dpms: current dpms state
>   * @helper_private: mid-layer private data
> + * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
>   * @force: a %DRM_FORCE_ state for forced mode sets
> + * @override_edid: has the EDID been overwritten through debugfs for testing?
>   * @encoder_ids: valid encoders for this connector
>   * @encoder: encoder driving this connector, if any
>   * @eld: EDID-like data, if present
> @@ -503,6 +513,8 @@ struct drm_encoder {
>   * @video_latency: video latency info from ELD, if found
>   * @audio_latency: audio latency info from ELD, if found
>   * @null_edid_counter: track sinks that give us all zeros for the EDID
> + * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
> + * @debugfs_entry: debugfs directory for this connector
>   *
>   * Each connector may be connected to one or more CRTCs, or may be clonable 
> by
>   * another connector if they can share a CRTC.  Each connector also has a 
> specific
> @@ -570,6 +582,7 @@ struct drm_connector {
>   * @update_plane: update the plane configuration
>   * @disable_plane: shut down the plane
>   * @destroy: clean up plane resources
> + * @reset: reset plane after state has been invalidated (e.g. resume)
>   * @set_property: called when a property is changed
>   */
>  struct drm_plane_funcs {
> @@ -603,6 +616,8 @@ enum drm_plane_type {
>   * @format_count: number 

[Bug 85771] unable to handle kernel NULL pointer dereference in dce6_bandwidth_update

2014-11-02 Thread bugzilla-dae...@freedesktop.org
:
001407e0
[6.446296] Stack:
[6.446348]  880419b2  880419b21728
880419b21750
[6.446581]  880419b21060 880419b210e0 a04b87e4
880419b2
[6.446826]  000c 8800c4daf5e0 88041619e000
880419b21728
[6.447066] Call Trace:
[6.447131]  [] ? radeon_pm_compute_clocks+0x634/0x8e0
[radeon]
[6.447200]  [] ? radeon_set_dpm_state+0x6e/0xe0 [radeon]
[6.447255]  [] ? kernfs_fop_write+0xe3/0x160
[6.447307]  [] ? vfs_write+0xb2/0x1f0
[6.447359]  [] ? SyS_write+0x42/0xa0
[6.447412]  [] ? page_fault+0x28/0x30
[6.447467]  [] ? system_call_fastpath+0x1a/0x1f
[6.447518] Code: 95 90 20 00 00 85 d2 0f 8e ce 00 00 00 83 ea 01 48 8d 85
b0 04 00 00 45 31 e4 48 8d 8c d5 b8 04 00 00 66 0f 1f 44 00 00 48 8b 10 <80> ba
90 00 00 00 01 41 83 dc ff 48 83 c0 08 48 39 c8 75 e9 48 
[6.450591] RIP  [] dce6_bandwidth_update+0x43/0x100
[radeon]
[6.450709]  RSP 
[6.450759] CR2: 0090
[6.450826] ---[ end trace 8b1b9f8f098a5ef5 ]---
[6.450854] usb 4-1: new high-speed USB device number 2 using ehci-pci
[   96.090492] systemd-journald[224]: Received request to flush runtime journal
from PID 1
[   96.534178] RPC: Registered named UNIX socket transport module.
[   96.534244] RPC: Registered udp transport module.
[   96.534301] RPC: Registered tcp transport module.
[   96.534357] RPC: Registered tcp NFSv4.1 backchannel transport module.
[   96.537226] FS-Cache: Loaded
[   96.543651] FS-Cache: Netfs 'nfs' registered for caching
[   96.550885] Installing knfsd (copyright (C) 1996 okir at monad.swb.de).


This is with Linux 3.17.2. I can successfully boot the system with
radeon.modeset=0 boot option, and when I run run modprobe radeon modeset=1
after that, KMS is activated without any problem.

I am using this graphics card:

01:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc.
[AMD/ATI] Pitcairn PRO [Radeon HD 7850] [1002:6819]

Downstream bug report: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=767742

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20141102/4bafdaf9/attachment-0001.html>


[git pull] drm fixes

2014-11-02 Thread Dave Airlie

Hi Linus,

drm fixes, nothing too astounding or major, radeon, i915
vmwgfx, armada and exynos.

biggest ones:
vmwgfx has one big locking regression fix,
i915 has come displayport fixes
radeon has some stability and a memory alloc failure
armada and exynos have some vblank fixes.

Dave.

The following changes since commit f7e87a44ef60ad379e39b45437604141453bf0ec:

  Merge tag 'media/v3.18-rc2' of 
git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media (2014-10-27 
15:05:40 -0700)

are available in the git repository at:


  git://people.freedesktop.org/~airlied/linux drm-fixes

for you to fetch changes up to 66338feee458cb2b04e8f2b515b8d660e49ba29a:

  Merge branch 'exynos-drm-fixes' of 
git://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos into drm-fixes 
(2014-11-03 05:23:17 +1000)



Alex Deucher (3):
  drm/radeon/dpm: disable ulv support on SI
  drm/radeon: dpm fixes for asrock systems
  drm/radeon: remove invalid pci id

Andrzej Hajda (6):
  drm/exynos: init vblank with real number of crtcs
  drm/exynos: remove explicit encoder/connector de-initialization
  drm/exynos: propagate plane initialization errors
  drm/exynos: init kms poll at the end of initialization
  drm/exynos: enable vblank after DPMS on
  drm/exynos: correct connector->dpms field before resuming

Dan Carpenter (1):
  drm/radeon: remove some buggy dead code

Dave Airlie (5):
  Merge branch 'drm-armada-fixes' of 
git://ftp.arm.linux.org.uk/~rmk/linux-arm into drm-fixes
  Merge tag 'drm-intel-fixes-2014-10-30' of 
git://anongit.freedesktop.org/drm-intel into drm-fixes
  Merge branch 'drm-fixes-3.18' of 
git://people.freedesktop.org/~agd5f/linux into drm-fixes
  Merge branch 'vmwgfx-fixes-3.18' of 
git://people.freedesktop.org/~thomash/linux
  Merge branch 'exynos-drm-fixes' of 
git://git.kernel.org/.../daeinki/drm-exynos into drm-fixes

Inki Dae (1):
  drm/exynos: vidi: fix build warning

Jani Nikula (1):
  drm/i915/dp: only use training pattern 3 on platforms that support it

Michel Dänzer (1):
  drm/radeon: Use drm_malloc_ab instead of kmalloc_array

Rob Clark (1):
  drm/vmwgfx: fix lock breakage

Russell King (3):
  drm/armada: add IRQ support back
  drm/armada: fix page_flip refcounting leak
  drm/armada: convert to use vblank_on/off calls

Sinclair Yeh (1):
  drm/vmwgfx: Filter out modes those cannot be supported by the current 
VRAM size.

Thomas Hellstrom (1):
  drm/vmwgfx: Fix hash key computation

Ville Syrjälä (3):
  drm/i915: Do a dummy DPCD read before the actual read
  drm/i915: Ignore long hpds on eDP ports
  drm/i915: Fix GMBUSFREQ on vlv/chv

Wilfried Klaebe (1):
  radeon: clean up coding style differences in radeon_get_bios()

jens stein (1):
  drm/i915: Ignore VBT backlight check on Macbook 2, 1

 drivers/gpu/drm/armada/armada_crtc.c   | 21 +++
 drivers/gpu/drm/armada/armada_drv.c|  3 ++-
 drivers/gpu/drm/exynos/exynos_dp_core.c|  5 
 drivers/gpu/drm/exynos/exynos_drm_crtc.c   |  5 +++-
 drivers/gpu/drm/exynos/exynos_drm_dpi.c|  4 ---
 drivers/gpu/drm/exynos/exynos_drm_drv.c| 43 +-
 drivers/gpu/drm/exynos/exynos_drm_dsi.c|  4 ---
 drivers/gpu/drm/exynos/exynos_drm_vidi.c   |  4 ---
 drivers/gpu/drm/exynos/exynos_hdmi.c   |  6 -
 drivers/gpu/drm/i915/intel_display.c   |  5 +++-
 drivers/gpu/drm/i915/intel_dp.c| 24 +++--
 drivers/gpu/drm/radeon/evergreen.c |  4 +--
 drivers/gpu/drm/radeon/kv_dpm.c| 19 ++---
 drivers/gpu/drm/radeon/radeon_bios.c   |  6 ++---
 drivers/gpu/drm/radeon/radeon_cs.c |  2 +-
 drivers/gpu/drm/radeon/radeon_ring.c   |  4 +--
 drivers/gpu/drm/radeon/radeon_vm.c |  4 +--
 drivers/gpu/drm/radeon/si_dpm.c|  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c |  3 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c|  6 -
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c| 24 -
 include/drm/drm_pciids.h   |  1 -
 22 files changed, 116 insertions(+), 83 deletions(-)


[Bug 85771] unable to handle kernel NULL pointer dereference in dce6_bandwidth_update

2014-11-02 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=85771

--- Comment #1 from Ben Hutchings  ---
(In reply to Frederik Himpe from comment #0)
> [6.440842] BUG: unable to handle kernel NULL pointer dereference at
> 0090
> [6.441017] IP: [] dce6_bandwidth_update+0x43/0x100
> [radeon]
> [6.441143] PGD 0 
> [6.441241] Oops:  [#1] SMP 
> [6.441380] Modules linked in: snd_hda_codec_hdmi x86_pkg_temp_thermal
> evdev intel_powerclamp snd_hda_codec_realtek iTCO_wdt intel_rapl
> iTCO_vendor_support snd_hda_codec_generic acpi_cpufreq(-) coretemp kvm_intel
> kvm crc32_pclmul ghash_clmulni_intel aesni_intel aes_x86_64 lrw gf128mul
> glue_helper ablk_helper psmouse cryptd pcspkr serio_raw snd_hda_intel(+)
> snd_hda_controller sr_mod sg cdrom radeon(+) snd_hda_codec ttm snd_hwdep
> drm_kms_helper snd_pcm nuvoton_cir video intel_smartconnect drm rc_core
> battery tpm_tis i2c_algo_bit tpm i2c_i801 snd_timer ehci_pci ehci_hcd snd
> i2c_core xhci_hcd mei_me soundcore processor button mei usbcore lpc_ich
> ie31200_edac usb_common mfd_core edac_core thermal_sys fuse autofs4 btrfs
> xor raid6_pq dm_mod netconsole configfs sd_mod crc_t10dif crct10dif_generic
> ahci libahci crct10dif_pclmul crct10dif_common crc32c_intel libata scsi_mod
> r8169 mii shpchp
> [6.445512] CPU: 3 PID: 933 Comm: laptop_mode Not tainted 3.17.2.1 #1
[...]
> [6.447200]  [] ? radeon_set_dpm_state+0x6e/0xe0
> [radeon]
> [6.447255]  [] ? kernfs_fop_write+0xe3/0x160
> [6.447307]  [] ? vfs_write+0xb2/0x1f0
[...]

So this is triggered by laptop_mode writing to the dpm_state attribute. 
Presumably that doesn't happen if the driver fails to initialise at boot (as it
will with modeset=0) and is reloaded after booting.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20141102/34b2f6d0/attachment.html>


[Bug 85771] unable to handle kernel NULL pointer dereference in dce6_bandwidth_update

2014-11-02 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=85771

--- Comment #2 from Frederik Himpe  ---
Could this be the same bug?: https://bugzilla.kernel.org/show_bug.cgi?id=83611

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20141102/a9e7ab54/attachment.html>