drm: Make sure we limit the disabled plane search to crtc

This patch fixes a small bug in the primary plane disable helper where
it intended to search planes attached to the current crtc, but it ended
up searching the entire plane list. This resulted in failure when there
was another crtc with an active plane.

BUG=chromium:336809
TEST=Tested on snow & peppy

Change-Id: I96f39cdef71260bd7f87c0f7eb1b0c9f309ced62
Signed-off-by: Sean Paul <seanpaul@chromium.org>
drm/exynos: Add a hack to appease userspace & atomic helpers

This patch adds a small hack to the plane initialization of the
exynos planes such that the "default window" has a possible_crtcs
of 0 and an overlay plane type. This ensures that userspace will
not select the plane for cursor use, but allows the planes to be
included in the drm layer plane loops which disable planes.

This will be removed once we no longer use the primary plane helpers
and properly implement it ourselves.

BUG=chromium:336809
TEST=Tested on snow & peppy

Change-Id: I0f22326935572617259e7f3b6a0e5c6bafd492b2
Revert "UPSTREAM: drm: add atomic fxns"

This reverts commit f00d233ca55617368ff908e545777b72365a2bb3.

There's a new version, it'll be better to roll this back and add
the new one.

BUG=chromium:336809
TEST=Tested on snow & peppy

Signed-off-by: Sean Paul <seanpaul@chromium.org>

Conflicts:
	drivers/gpu/drm/Makefile
	drivers/gpu/drm/cirrus/cirrus_drv.c
	drivers/gpu/drm/exynos/exynos_drm_connector.c
	drivers/gpu/drm/exynos/exynos_drm_drv.c
	drivers/gpu/drm/exynos/exynos_drm_plane.c
	drivers/gpu/drm/i915/i915_drv.c
	drivers/gpu/drm/mgag200/mgag200_drv.c
	drivers/gpu/drm/radeon/radeon_drv.c
	drivers/gpu/drm/shmobile/shmob_drm_drv.c

Change-Id: I631a1feb87025a7af8e8c39f413cd3852c83c61c
BACKPORT-PARTIAL: DRM: Armada: Add Armada DRM driver

This patch adds support for the pair of LCD controllers on the Marvell
Armada 510 SoCs.  This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU
acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crt via DRM planes
- page flipping of the main scanout buffers
- DRM prime for buffer export/import

This driver is trivial to extend to other Armada SoCs.

Included in this commit is the core driver with no output support; output
support is platform and encoder driver dependent.

Tested-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Reviewed-by: Rob Clark <robdclark@gmail.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit 96f60e37dc66091bde8d5de136ff6fda09f2d799)
[seanpaul stripped out armada, just kept drm core changes]
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Change-Id: I45a4fe4482da27a30a33d8efad64e8df9010bfa5
UPSTREAM: drm: fix typo

Signed-off-by: Rob Clark <robdclark@gmail.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit 6e8e797d41a34ee3680c39e60955e5ba05eb10bf)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Change-Id: I65da391a78d59eac2a7879a2b74276c47e45a18a
UPSTREAM: drm: add atomic fxns

The 'atomic' mechanism allows for multiple properties to be updated,
checked, and commited atomically.  This will be the basis of atomic-
modeset and nuclear-pageflip.

The basic flow is:

   state = dev->atomic_begin();
   for (... one or more ...)
      obj->set_property(obj, state, prop, value);
   if (dev->atomic_check(state))
      dev->atomic_commit(state);
   dev->atomic_end(state);

The split of check and commit steps is to allow for ioctls with a
test-only flag (which would skip the commit step).

Signed-off-by: Rob Clark <robdclark@gmail.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit 6dcab9fdbd2d66c13c5351ae3fc64899df02f275)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Conflicts:
	drivers/gpu/drm/Makefile
	drivers/gpu/drm/drm_crtc.c
	drivers/gpu/drm/exynos/exynos_drm_plane.c
	drivers/gpu/drm/gma500/psb_drv.c
	drivers/gpu/drm/msm/msm_drv.c
	drivers/gpu/drm/msm/msm_drv.h
	drivers/gpu/drm/vmwgfx/vmwgfx_drv.c

Change-Id: I4dbfad93a081d78ce67d4733ec3558833036c4b9
UPSTREAM: drm: convert crtc to ww_mutex

For atomic, it will be quite convenient to not have to care so much
about locking order.  And 'state' gives us a convenient place to stash a
ww_ctx for any sort of update that needs to grab multiple crtc locks.

Because we will want to eventually make locking even more fine grained
(giving locks to planes, connectors, etc), split out drm_modeset_lock
so that the atomic state won't eventually have to keep separate lists of
locked planes/crtcs/etc.

The state keeps track of which locks it has aquired, and for the benefit
of NONBLOCK operations, supports transfering "locked" resources to
driver worker/thread to complete the asynchronous state change.

Signed-off-by: Rob Clark <robdclark@gmail.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit c5e2b568f0701531dd369889be26990d1052a880)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Conflicts:
	drivers/gpu/drm/i915/intel_display.c
	drivers/gpu/drm/omapdrm/omap_crtc.c
	include/drm/drmP.h

Change-Id: I580a25e7317cbb5442b067fc3a88c3dc7fd4fd12
UPSTREAM: drm: add object property type

An object property is an id (idr) for a drm mode object.  This
will allow a property to be used set/get a framebuffer, CRTC, etc.

Signed-off-by: Rob Clark <robdclark@gmail.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit 32a9e40c002a041f3400e103a8564011f04f0b67)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Conflicts:
	drivers/gpu/drm/drm_crtc.c

Change-Id: I574fcb9ed2331f3bfc6881c685d8d14a179fb3a0
UPSTREAM: drm: add signed-range property type

Like range, but values are signed.

Signed-off-by: Rob Clark <robdclark@gmail.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit efd2d0787f9dc930b4d64805af98541d543df543)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Conflicts:
	drivers/gpu/drm/drm_crtc.c
	include/drm/drm_crtc.h

Change-Id: I6ee0af62d601881e4840a85b8c85f028cb8b12a5
UPSTREAM: drm: helpers to find mode objects

Add a few more useful helpers to find mode objects.

Signed-off-by: Rob Clark <robdclark@gmail.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit a77d54322f86e5ae718ee7143a5bb9dfd8d121d5)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Conflicts:
	drivers/gpu/drm/drm_crtc.c
	include/drm/drm_crtc.h

Change-Id: I3826e799ff88d4441ffc44851a181c234cf3c8a9
UPSTREAM: drm: split propvals out and blob property support

Split property values out into a different struct, so we can later
move property values into state structs.  This will allow the
property values to stay in sync w/ the state updates which are
either discarded or atomically committed.

And since we are touching all the same code, add support for mutable
blob properties, which will also be needed for atomic modeset.

Signed-off-by: Rob Clark <robdclark@gmail.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit 8f4e128a7604be46e8643ee30cef7721aee9a85e)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Conflicts:
	drivers/gpu/drm/nouveau/dispnv04/tvnv17.c
	drivers/gpu/drm/omapdrm/omap_drv.c
	drivers/gpu/drm/rcar-du/rcar_du_lvdscon.c
	drivers/gpu/drm/rcar-du/rcar_du_vgacon.c
	include/drm/drm_crtc.h

Change-Id: Ibba82d8c03900214b90d0671a35fd1a577a77834
UPSTREAM: drm: Allow drm_mode_object_find() to look up an object of any type

To avoid having to pass object types from userspace for atomic mode
setting ioctl, allow drm_mode_object_find() to look up an object of any
type. This will only work as long as the all object types share the ID
space.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit e5e92c6764bd102f3f4a9247838e8c09af351d38)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Change-Id: I13ff523ac875bc6789b395ed0334eb633a93ce42
UPSTREAM: drm: Refactor object property check code

Refactor the code to check whether an object has a specific property
to a new function.

v1: original
v2: rebase on atomic -- Rob Clark
v3: EINVAL->ENOENT

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit f15b984eab182d730ec52bf77aad0495e8fab391)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Change-Id: I1666a998180d75751df9eb845150c31102732799
UPSTREAM: drm: allow FB's in drm_mode_object_find

We do actually want to permit FB's in atomic case, since FB will be
looked up like any other object property value in a few code paths
(like property value validation).

So split out into an internal function without the WARN_ON() which
we can use in those special cases.

Signed-off-by: Rob Clark <robdclark@gmail.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit 1358cd58fc90e673397511988954c1c55e606412)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Change-Id: I1666a998180d75751df9eb845150c3110273279b
drm/i915: Remove WARN for mode_config.mutex in ironlake_panel_vdd_off_sync

BUG=chromium:336809
TEST=Tested on snow & peppy

Change-Id: I155bf463e04929c7e1bfec7842da386f35697450
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Change-Id: I1666a998180d75751df9eb845150c3110273279c
UPSTREAM: drm: convert plane to properties/state

Break the mutable state of a plane out into a separate structure
and use atomic properties mechanism to set plane attributes.  This
makes it easier to have some helpers for plane->set_property()
and for checking for invalid params.  The idea is that individual
drivers can wrap the state struct in their own struct which adds
driver specific parameters, for easy build-up of state across
multiple set_property() calls and for easy atomic commit or roll-
back.

The same should be done for CRTC, encoder, and connector, but this
patch only includes the first part (plane).

Signed-off-by: Rob Clark <robdclark@gmail.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit 9188a34824494db62f894f4cf5cb847f30f4b03d)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Conflicts:
	drivers/gpu/drm/armada/armada_overlay.c
	drivers/gpu/drm/drm_crtc.c
	drivers/gpu/drm/exynos/exynos_drm_plane.c
	drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c
	drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c
	drivers/gpu/drm/nouveau/dispnv04/overlay.c
	drivers/gpu/drm/omapdrm/omap_drv.c
	drivers/gpu/drm/omapdrm/omap_plane.c
	drivers/gpu/drm/rcar-du/rcar_du_plane.c
	include/drm/drm_crtc.h

Change-Id: Ibcd4a10fafb9ab50af1f51916e23150eea9d9075
UPSTREAM: drm: convert crtc to properties/state

Break the mutable state of a crtc out into a separate structure
and use atomic properties mechanism to set crtc attributes.  This
makes it easier to have some helpers for crtc->set_property()
and for checking for invalid params.  The idea is that individual
drivers can wrap the state struct in their own struct which adds
driver specific parameters, for easy build-up of state across
multiple set_property() calls and for easy atomic commit or roll-
back.

Signed-off-by: Rob Clark <robdclark@gmail.com>

BUG=chromium:336809
TEST=Tested on snow & peppy

(cherry picked from commit c7979e4d26489df8e5112691ae4a1a16286e3607)
Signed-off-by: Sean Paul <seanpaul@chromium.org>

Conflicts:
	drivers/gpu/drm/armada/armada_crtc.c
	drivers/gpu/drm/drm_crtc.c
	drivers/gpu/drm/gma500/cdv_intel_display.c
	drivers/gpu/drm/gma500/psb_intel_display.c
	drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c
	drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
	drivers/gpu/drm/nouveau/dispnv04/crtc.c
	drivers/gpu/drm/nouveau/nv50_display.c
	drivers/gpu/drm/omapdrm/omap_crtc.c
	drivers/gpu/drm/omapdrm/omap_drv.c
	drivers/gpu/drm/qxl/qxl_display.c
	drivers/gpu/drm/radeon/radeon_display.c
	drivers/gpu/drm/rcar-du/rcar_du_crtc.c
	drivers/gpu/drm/tilcdc/tilcdc_crtc.c
	include/drm/drm_crtc.h

Change-Id: I266c9bdc87f8c94bdec1ddae8b024f086bed0de1
drm: Fix up the atomic legacy paths so they work

BUG=chromium:336809
TEST=Tested on snow & peppy

Change-Id: Icd864ac52da9c973202f3ac4629824ef5eec2ac9
Signed-off-by: Sean Paul <seanpaul@chromium.org>
UPSTREAM: drm: Atomic modeset ioctl

The atomic modeset ioctl cna be used to push any number of new values
for object properties. The driver can then check the full device
configuration as single unit, and try to apply the changes atomically.

The ioctl simply takes a list of object IDs and property IDs and their
values. For setting values to blob properties, the property value
indicates the length of the data, and the actual data is passed via
another blob pointer.

The caller can demand non-blocking operation from the ioctl, and if the
driver can't satisfy that requirement an error will be returned.

The caller can also request to receive asynchronous completion events
after the operation has reached the hardware. An event is sent for each
object specified by the caller, whether or not the actual state of
that object changed. Each event also carries a framebuffer ID, which
indicates to user space that the specified object is no longer
accessing that framebuffer.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Rob Clark <robdclark@gmail.com>

BUG=chromium:336809
TEST=Tested on daisy, no regressions noted

Change-Id: Idf782bd0c7fdaf7fe7fcd64bf2379fa59efd0aed
Signed-off-by: Sean Paul <seanpaul@chromium.org>
CONFIG: Don't compile vidi for the time being

Change-Id: I75f5549260b53eb68bfea0ae8f3977eeb16ecd83