drm/i915/ctx: Remove bad invariant

It's not that the assertion is incorrect, but rather that we can call
do_destroy early in loading, and we will falsely BUG().

Since contexts have been in for a while now, and in the internal APIs
are pretty stable, it should be fairly safe to remove this.

v2: Remove unused dev_priv, and dev

BUG=chrome-os-partner:22147
TEST=Sanity Test on Link(unable to repro)

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
(cherry picked from commit f73f760725636b9d0c3786273e185b053516d1eb)
Signed-off-by: David Sodman <dsodman@chromium.org>

Change-Id: I54acf1b0fd3f7c756cfeb8f33a664cc8a30a0b64
Previous-Reviewed-on: https://chromium-review.googlesource.com/181023
(cherry picked from commit 4dba2d1eaf074a1a0623f5dd414af264a74ec6d8)
Reviewed-on: https://chromium-review.googlesource.com/181979
Reviewed-by: David Sodman <dsodman@chromium.org>
Commit-Queue: David Sodman <dsodman@chromium.org>
Tested-by: David Sodman <dsodman@chromium.org>
drm/i915: Use MLC (l3$) for context objects

Enabling context support increases SwapBuffers latency by about 20%
(measured on an i7-3720qm). We can offset that loss slightly by enabling
faster caching for the contexts. As they are not backed by any
particular cache (such as the sampler or render caches) our only option
is to select the generic mid-level cache. This reduces the latency of
the swap by about 5%.

Oddly this effect can be observed running smokin-guns on IVB at
1280x1024:
Using BLT copies for swaps: 151.67 fps
Using Render copies for swaps (unpatched):  141.70 fps
With contexts disabled: 150.23 fps
With contexts in L3$: 150.77 fps

BUG=chrome-os-partner:22147
TEST=Sanity Test on Link(unable to repro)

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Ben Widawsky <ben@bwidawsk.net>
Cc: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
(cherry picked from commit 4615d4c9e27eda42c3e965f208a4b4065841498c)
Signed-off-by: David Sodman <dsodman@chromium.org>

Change-Id: Ica27260e59fc0afbb76cf31c333c09ae7ecea23d
Previous-Reviewed-on: https://chromium-review.googlesource.com/181025
(cherry picked from commit 879d8ce8330fea9869c31f291149b3014d3ce9be)
Reviewed-on: https://chromium-review.googlesource.com/181968
Reviewed-by: David Sodman <dsodman@chromium.org>
Commit-Queue: David Sodman <dsodman@chromium.org>
Tested-by: David Sodman <dsodman@chromium.org>
drm/i915: reference count for i915_hw_contexts

Enabling PPGTT and also the need to track which context was guilty of
gpu hang (arb robustness enabling) have put pressure for struct i915_hw_context
to be more than just a placeholder for hw context state.

In order to track object lifetime properly in a multi peer usage, add reference
counting for i915_hw_context.

v2: track i915_hw_context pointers instead of using ctx_ids
(from Chris Wilson)

v3 (Ben): Get rid of do_release() and handle refcounting more compactly.
(recommended by Chis)

v4: kref_* put inside static inlines (Daniel Vetter)
remove code duplication on freeing context (Chris Wilson)

v5: idr_remove and ctx->file_priv = NULL in destroy ioctl (Chris)
This actually will cause a problem if one destroys a context and later
refers to the idea of the context (multiple contexts may have the same
id, but only 1 will exist in the idr).

v6: Strip out the request related stuff. Reworded commit message.
Got rid of do_destroy and introduced i915_gem_context_release_handle,
suggested by Chris Wilson.

v7: idr_remove can't be called inside idr_for_each (Chris Wilson)

BUG=chrome-os-partner:22147
TEST=Sanity Test on Link(unable to repro)

Conflicts:
	drivers/gpu/drm/i915/i915_gem_context.c

Signed-off-by: Ben Widawsky <ben@bwidawsk.net> (v5)
Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com> (v7)
[danvet: Squash sob lines, the patch ping-ponged between Ben and Mika
a bit ...]
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

(cherry picked from commit dce3271b1ee05ca01ebdde50d613d7b33ef178a9)
Signed-off-by: David Sodman <dsodman@chromium.org>

Change-Id: Iadece8d5e909c54caaa926a1c9eecd42b96ee174
Previous-Reviewed-on: https://chromium-review.googlesource.com/181026
(cherry picked from commit fd935cb088330e36b38c17ccaa5537d74accb127)
Reviewed-on: https://chromium-review.googlesource.com/182020
Reviewed-by: David Sodman <dsodman@chromium.org>
Commit-Queue: David Sodman <dsodman@chromium.org>
Tested-by: David Sodman <dsodman@chromium.org>
drm/i915: unreference default context on module unload

Before module unload is called, gpu_idle() will switch
to default context. This will increment ref count of base
object as the default context is 'running' on module unload
time. Unreference the drm object so that when context
is freed, base object is freed as well.

v2: added comment to explain the refcounts (Ben Widawsky)

BUG=chrome-os-partner:22147
TEST=Sanity Test on Link(unable to repro)

Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
(cherry picked from commit 168f83660211b9e059e3bc0638daaa01e9ea0b71)
Signed-off-by: David Sodman <dsodman@chromium.org>

Change-Id: Id887bf6143329c9581c852e519ee57548a2a5ae3
Previous-Reviewed-on: https://chromium-review.googlesource.com/181027
(cherry picked from commit 2737bedf6213cb9c7d84389604b8153e64d68bd4)
Reviewed-on: https://chromium-review.googlesource.com/181969
Reviewed-by: David Sodman <dsodman@chromium.org>
Commit-Queue: David Sodman <dsodman@chromium.org>
Tested-by: David Sodman <dsodman@chromium.org>
drm/i915: put context upon switching

In order to be notified of when the context and all of its associated
objects is idle (for if the context maps to a ppgtt) we need a callback
from the retire handler. We can arrange this by using the kref_get/put
of the context for request tracking and by inserting a request to
demarque the switch away from the old context.

BUG=chrome-os-partner:22147
TEST=Sanity Test on Link(unable to repro)

[Ben: fixed minor error to patch compile, AND s/last_context/from/]
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

(cherry picked from commit 112522f6789581824903f6f72082b5b841a7f0f9)
Signed-off-by: David Sodman <dsodman@chromium.org>

Change-Id: Ia0367621844f597136802c0b54e40e16064abc48
Previous-Reviewed-on: https://chromium-review.googlesource.com/181029
(cherry picked from commit 9baa5c5ae6e7a5a1ba08a34852b135c0bebdddf1)
Reviewed-on: https://chromium-review.googlesource.com/182002
Reviewed-by: David Sodman <dsodman@chromium.org>
Commit-Queue: David Sodman <dsodman@chromium.org>
Tested-by: David Sodman <dsodman@chromium.org>
Revert "drm/i195: Fix potential dangling pointer on context switch"

This reverts commit ec358f03f0704c8d0f359b2150cb4b7dfb2a4c71.

BUG=chrome-os-partner:22147
TEST=Sanity test on Link(unable to repro)

Change-Id: Iac3c84044b68e8ed4d3329607e857f83afd5e7f5
Signed-off-by: David Sodman <dsodman@chromium.org>
Previous-Reviewed-on: https://chromium-review.googlesource.com/181040
(cherry picked from commit d84982a5da9e7ddc455b5ef650b41b1644fca530)
Reviewed-on: https://chromium-review.googlesource.com/182003
drm/exynos: remove duplicate adjusted modes

change adjust_modes() to adjust_mode() and process only one mode in it.
modes, that when adjusted, would result in duplicate of existing "native"
mode are not adjusted and reported as invalid from get_mode_type().
adjust_mode is now called from mode_valid() before check_mode().

TEST=connect Daisy to Optoma projector. It should use 1280x720 mode.
BUG=chrome-os-partner:24203

Change-Id: I9706a1941ee166d3fe0fa25674f048c435e6a705
Signed-off-by: Dominik Behr <dbehr@chromium.org>
Previous-Reviewed-on: https://chromium-review.googlesource.com/179744
(cherry picked from commit 676947eeee566d3f04e2d35d6a17c89ef5ce0859)
Reviewed-on: https://chromium-review.googlesource.com/182026
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
CHERRY-PICK: drm/exynos: Ensure mixer vsync irqs are enabled/disabled properly

This patch does the following:
- Ensures int_en always tracks the desired vsync state
- Clears MXR_INT_EN on power off to avoid the interrupts firing too
  early on poweron when we enable the clocks
- Refrains from enabling vsync until all window state has been restored

All together, this will avoid turning on vsync too early such that we
have inconsistent window state which causes iommu faults. Or, at least
that's the theory.

BUG=chrome-os-partner:24923,chromium:332599,chromium:331138
TEST=tested on daisy - hotplug/suspend-resume/resolution change

Change-Id: Iabeae6240dfd031a407a8517f5f74fc2cf97cdc1
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/181987
(cherry picked from commit 9b6142c03130fda219bc0682acf715d46d1fd852)
Reviewed-on: https://chromium-review.googlesource.com/182192
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
drm/exynos: exclude modes from adjustment comparison

The mode adjustment logic is checking whether a "native" mode with the same
resolution as adjusted mode already exists. But it can be an another
adjusted mode (possibly with different refresh rate) or a mode with
unsupported pixel clock. This change introduces a private flag
EXYNOS_MODE_ADJUSTED which is set when the mode is adjusted and skips the
comparison with adjusted modes and also checks whether the comparison target
mode is valid using check_mode(). This solves problem with two scenarios.
One, already encountered is when 1024x768@75 is adjusted to 1024x720@75 and
prevents 1024x768@60 from also being adjusted to 1024x720@60 with both of
them being pruned later. Second is where "native" mode with unsupported
pixel clock could prevent of adjustment of another mode to the same
resolution.

BUG=chromium:331423
TEST=connect Daisy to HP LP2465 monitor. 1024x720 mode should be available.

Change-Id: I8e3fcab58ebe991f556cefe56e228399cbe793e5
Signed-off-by: Dominik Behr <dbehr@chromium.org>
Previous-Reviewed-on: https://chromium-review.googlesource.com/181420
(cherry picked from commit 00618d731cadd818d39fdde4c0a9e159467774b6)
Reviewed-on: https://chromium-review.googlesource.com/182218
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
CHROMIUM: alsa/soc: do not set AUI transmit when setting up infoframe

hdmi_reg_infoframe called from hdmi_conf_init unconditionally enables
sending AUI infoframe on every vsync. This register is also controlled
from hdmi_audio_control which is supposed to control HDMI audio.
Setting it from hdmi_reg_infoframe overrides hdmi_audio_control causing
HDMI audio to be always enabled, even on DVI monitors, which causes some
of them to blank when audio is playing in Chrome OS. This change removes
the unconditional setting of HDMI AUI transmit from hdmi_reg_infoframe
so hdmi_audio_control is really in control.
As a bonus, it also adds use of defines instead of literals for HDMI AUI
enable/disable in hdmi_audio_control.

BUG=chromium:331938
TEST=connect DVI monitor and play sound, it should not blank
Signed-off-by: Dominik Behr <dbehr@chromium.org>

Change-Id: Ibb299597e57b294beb57299bc132786f7f9af7a7
Previous-Reviewed-on: https://chromium-review.googlesource.com/181967
(cherry picked from commit 91e8af6f1b61dc6f32d87823232c9520926820e6)
Reviewed-on: https://chromium-review.googlesource.com/182224
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Tested-by: Dominik Behr <dbehr@chromium.org>
drm/exynos: add phy settings for rb modes

This patch adds new phy setting for pixel clocks
73.25MHz,88.75MHz, 115.5MHz, and 119MHz which
are used for enabling reduced blanking modes like
1680x1050 etc.

BUG=chrome-os-partner:24846
TEST=connect 1080p monitor to Pit,
verified listing of 1680x1050@119000000

Change-Id: Id3c3f0d36063fa932fcf96af1a12968288d016e8
Signed-off-by: Shirish S <s.shirish@samsung.com>
Previous-Reviewed-on: https://chromium-review.googlesource.com/182034
(cherry picked from commit dbd7eb95eb74d30ff5e21ebb622ff98152a9073c)
Reviewed-on: https://chromium-review.googlesource.com/182225
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Tested-by: Dominik Behr <dbehr@chromium.org>