Commit Graph

298 Commits

Author SHA1 Message Date
Mateusz Guzik
21b737495b Introduce __read_mostly and __exclusive_cache_line macros.
The intended use is to annotate frequently used globals which either rarely
change (and thus can be grouped in the same cacheline) or are an atomic counter
(which means it may benefit from being the only variable in the cacheline).

Linker script support is provided only for amd64. Architectures without it risk
having other variables put in, i.e. as if they were not annotated. This is
harmless from correctness point of view.

Reviewed by:	bde (previous version)
MFC after:	1 month
2017-01-27 14:53:09 +00:00
Michal Meloun
02fe53a49f Import drm_patform.c, an implementation of non-PCI based attachment
for graphics drivers.
It will be used in upcoming driver for Nvidia Tegra boards.

MFC after: 1 month
2016-12-26 14:28:23 +00:00
Michal Meloun
15e5bf1942 Fix late monitor hotplug event.
If system starts without attached monitor, DRM create framebuffer
for VT console. Later, when monitor is attached, the hotplug event must
issue full modeset procedure to setup CRTC.
In original code, this was done in drm_fb_helper_set_par(), but we don't
have this function implemented yet. Use unrolled version of
drm_fb_helper_set_par() to ensure same functionality.

MFC after: 1 month
2016-12-26 11:20:40 +00:00
Konstantin Belousov
8266737023 Fix bug in r309712, do not leak gem object pin count in case of error
or retry.

Reported and tested by:	Michael Butler <imb@protected-networks.net>
Sponsored by:	The FreeBSD Foundation
MFC after:	16 days
2016-12-13 19:04:05 +00:00
Konstantin Belousov
29edde94ac Use the populate() driver paging method for i915 driver.
In particular, the fault access type is accounted for when the
aperture page is moved to GTT domain.  On the other hand, the current
pager structure is left intact, most important, only one page is
instantiated per populate call.

Reviewed by:	alc
Sponsored by:	The FreeBSD Foundation
MFC after:	3 weeks
2016-12-08 11:39:08 +00:00
Michal Meloun
aa1f683bf3 Allow DRM2 code to be built on platforms without AGP.
This patch is taken from original drm-3.8 code.

Differential Revision: https://reviews.freebsd.org/D8454
MFC after: 3 weeks
2016-11-13 13:31:23 +00:00
Konstantin Belousov
5975e53d40 Fix a race in vm_page_busy_sleep(9).
Suppose that we have an exclusively busy page, and a thread which can
accept shared-busy page.  In this case, typical code waiting for the
page xbusy state to pass is
again:
	VM_OBJECT_WLOCK(object);
	...
	if (vm_page_xbusied(m)) {
		vm_page_lock(m);
 		VM_OBJECT_WUNLOCK(object);    <---1
		vm_page_busy_sleep(p, "vmopax");
 		goto again;
	}

Suppose that the xbusy state owner locked the object, unbusied the
page and unlocked the object after we are at the line [1], but before we
executed the load of the busy_lock word in vm_page_busy_sleep().  If it
happens that there is still no waiters recorded for the busy state,
the xbusy owner did not acquired the page lock, so it proceeded.

More, suppose that some other thread happen to share-busy the page
after xbusy state was relinquished but before the m->busy_lock is read
in vm_page_busy_sleep().  Again, that thread only needs vm_object lock
to proceed.  Then, vm_page_busy_sleep() reads busy_lock value equal to
the VPB_SHARERS_WORD(1).

In this case, all tests in vm_page_busy_sleep(9) pass and we are going
to sleep, despite the page being share-busied.

Update check for m->busy_lock == VPB_UNBUSIED in vm_page_busy_sleep(9)
to also accept shared-busy state if we only wait for the xbusy state to
pass.

Merge sequential if()s with the same 'then' clause in
vm_page_busy_sleep().

Note that the current code does not share-busy pages from parallel
threads, the only way to have more that one sbusy owner is right now
is to recurse.

Reported and tested by:	pho (previous version)
Reviewed by:	alc, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D8196
2016-10-13 14:41:05 +00:00
Dimitry Andric
402e32a8af Define drmP.h's __OS_HAS_AGP and __OS_HAS_MTRR macros in a defined and
portable way.

Reviewed by:	dumbbell
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D7770
2016-09-03 13:33:28 +00:00
Enji Cooper
e5619a893e Always panic if an invalid capability is passed to capable(..) instead of
just with INVARIANTS

rwatson's point was valid in the sense that if the data passed at runtime is
invalid, it should always trip the invariant, not just in the debug case.
This is a deterrent against malicious input, or input caused by hardware
errors.

MFC after: 4 days
X-MFC with: r302577
Requested by: rwatson
Sponsored by: EMC / Isilon Storage Division
2016-07-14 13:55:38 +00:00
Enji Cooper
e3c76b36f6 Add missing default case to capable(..) function definition
By definition (enum __drm_capabilities), cases other than CAP_SYS_ADMIN
aren't possible. Add in a KASSERT safety belt and return false in
!INVARIANTS case if an invalid value is passed in, as it would be a
programmer error.

This fixes a -Wreturn-type error with gcc 5.3.0.

Differential Revision:	https://reviews.freebsd.org/D7188
MFC after:	1 week
Reported by:	devel/amd64-gcc (5.3.0)
Reviewed by:	dumbbell
Sponsored by:	EMC / Isilon Storage Division
2016-07-11 17:01:07 +00:00
Enji Cooper
75f09ab639 Remove redundant declarations for intel_fbc_enabled(..) and
i915_gem_dump_object(..) to fix -Wredundant-decls warning

MFC after:	1 week
PR:		209924
Reported by:	Mark Millard <markmi@dsl-only.net>
Tested with:	devel/amd64-gcc (5.3.0)
Sponsored by:	EMC / Isilon Storage Division
2016-07-11 15:50:06 +00:00
Enji Cooper
966d9ae5b6 Remove redundant declaration for radeon_pm_acpi_event_handler(..) to fix
-Wredundant-decls warning

MFC after:	1 week
PR:		209924
Reported by:	Mark Millard <markmi@dsl-only.net>
Tested with:	devel/amd64-gcc (5.3.0)
Sponsored by:	EMC / Isilon Storage Division
2016-07-11 15:47:43 +00:00
Adrian Chadd
57dbe10e6d [drm] fix up hex_dump_to_buffer to not overflow linebuf.
That check wasn't enough to handle appending a two byte character
following it.

This prevented my T400 (Intel Core 2 Duo P8400) from attaching;
it would panic from a stack overflow detection.
2016-06-03 05:01:35 +00:00
Eitan Adler
cef367e6a1 Don't repeat the the word 'the'
(one manual change to fix grammar)

Confirmed With: db
Approved by: secteam (not really, but this is a comment typo fix)
2016-05-17 12:52:31 +00:00
Hans Petter Selasky
6a55ff4866 Ensure waiting loops terminate during cold boot. This fixes boot with
MacBookPro and i915kms_load="YES" in /boot/loader.conf.

A lowlevel timeout in one of the display ports caused an infinite wait
because a ticks/jiffies comparison was constant. The clock subsystem
which makes ticks/jiffies increment is started after the initial
driver probing is done. Refer to sys/kernel.h and SI_SUB_DRIVERS vs
SI_SUB_CLOCKS .

Discussed with:	kmacy @
2016-05-10 18:18:29 +00:00
Pedro F. Giffuni
453130d9bf sys/dev: minor spelling fixes.
Most affect comments, very few have user-visible effects.
2016-05-03 03:41:25 +00:00
John Baldwin
8a08b7d36b Revert bus_get_cpus() for now.
I really thought I had run this through the tinderbox before committing,
but many places need <sys/types.h> -> <sys/param.h> for <sys/bus.h> now.
2016-05-03 01:17:40 +00:00
John Baldwin
bc153c692f Add a new bus method to fetch device-specific CPU sets.
bus_get_cpus() returns a specified set of CPUs for a device.  It accepts
an enum for the second parameter that indicates the type of cpuset to
request.  Currently two valus are supported:

 - LOCAL_CPUS (on x86 this returns all the CPUs in the package closest to
   the device when DEVICE_NUMA is enabled)
 - INTR_CPUS (like LOCAL_CPUS but only returns 1 SMT thread for each core)

For systems that do not support NUMA (or if it is not enabled in the kernel
config), LOCAL_CPUS fails with EINVAL.  INTR_CPUS is mapped to 'all_cpus'
by default.  The idea is that INTR_CPUS should always return a valid set.

Device drivers which want to use per-CPU interrupts should start using
INTR_CPUS instead of simply assigning interrupts to all available CPUs.
In the future we may wish to add tunables to control the policy of
INTR_CPUS (e.g. should it be local-only or global, should it ignore
SMT threads or not).

The x86 nexus driver exposes the internal set of interrupt CPUs from the
the x86 interrupt code via INTR_CPUS.

The ACPI bus driver and PCI bridge drivers use _PXM to return a suitable
LOCAL_CPUS set when _PXM exists and DEVICE_NUMA is enabled.  They also and
the global INTR_CPUS set from the nexus driver with the per-domain set from
_PXM to generate a local INTR_CPUS set for child devices.

Reviewed by:	wblock (manpage)
Differential Revision:	https://reviews.freebsd.org/D5519
2016-05-02 18:00:38 +00:00
Pedro F. Giffuni
b790c1938d etc: minor spelling fixes.
Mostly comments but also some user-visible strings.

MFC after:	2 weeks
2016-05-02 16:47:28 +00:00
Conrad Meyer
1a7dfcc5a3 i915kms: Fix memory leak if a CRT is detected
Reported by:	Coverity
CID:		1090729
Sponsored by:	EMC / Isilon Storage Division
2016-04-20 03:48:57 +00:00
Conrad Meyer
1940692911 drm2(4): Fix double-free in low-memory error path
Reallocf frees 'block'; don't attempt to free it again.

Reported by:	Coverity
CID:		1091165
Sponsored by:	EMC / Isilon Storage Division
2016-04-20 03:45:45 +00:00
Conrad Meyer
cd1cdbb58b i915kms intel_pm: Read from actual tsc_freq instead of uninitialized local
The local of the same name would alias the global, but we didn't even include
the header that defines tsc_freq.  Include it and rename the local.

Reported by:	Coverity
CID:		1331559
Sponsored by:	EMC / Isilon Storage Division
2016-04-20 02:58:22 +00:00
Pedro F. Giffuni
74b8d63dcc Cleanup unnecessary semicolons from the kernel.
Found with devel/coccinelle.
2016-04-10 23:07:00 +00:00
Konstantin Belousov
58a236093c Handle the driver KPI change from r292373. Ensure that managed device
pagers fault routines always return with a result page, be it the
proper and valid result page, or initially passed freshly allocated
placeholder.  Do not free the passed in page until we are able to
provide the replacement, and do not assign NULL to *mres.

Reported and tested by:	dumbbell
Reviewed by:	royger (who also verified that Xen code is safe)
Sponsored by:	The FreeBSD Foundation
2016-03-24 09:56:53 +00:00
Ed Maste
7fd08d3b59 i915: disable GEN6_MBCTL write in gen6_init_clock_gating
This write came from Linux commit b4ae3f22d238 which has been implicated
in Sandy Bridge power consumption issues (albeit under different
conditions on Linux). Disabling it restores normal power consumption on
my Sandy Bridge laptop (Thinkpad X220).

PR:		207889
Reviewed by:	cem, dumbbell
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D5665
2016-03-21 00:59:30 +00:00
Bjoern A. Zeeb
a3f2eca5d7 Fix the printf for PAE kernels where it'd be long long to unbreak
the build.
2016-03-14 16:19:50 +00:00
Jean-Sébastien Pédron
33a4a11703 drm/i915: Import Linux commit 168f83660211b9e059e3bc0638daaa01e9ea0b71
This makes sure the default context of each ring is cleaned up with the
ring itself and fixes a memory leak.

Author: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Date:   Fri May 3 16:29:08 2013 +0300

    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)

    Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com>
    Reviewed-by: Ben Widawsky <ben@bwidawsk.net>
    Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Obtained from:	Linux
2016-03-12 20:05:23 +00:00
Jean-Sébastien Pédron
77e6a4072b drm/i915: Call i915_gem_gtt_fini() when the device is detached
This fixes several memory leaks. Apparently, this problem exists in
Linux 3.8 but the code changed in Linux 3.9 so it may be fixed upstream
already. Still, this is something we need to pay attention to.
2016-03-12 11:57:32 +00:00
Jean-Sébastien Pédron
538cf7be5e drm/i915: Fix page fault handler failure
... when __wait_seqno() is interrupted by a signal. In this case,
__wait_seqno() returns -ERESTARTSYS. Like we already do in drm_ioctl(),
we need to convert this error to a common code such as -EINTR, so the
page fault handler is restarted.

Reported by:	Frederic Chardon <chardon.frederic@gmail.com>
Tested by:	Frederic Chardon <chardon.frederic@gmail.com>
2016-03-12 11:54:58 +00:00
Jean-Sébastien Pédron
645e6cf5cc drm/i915: Fix malloc type in i915_gem_object_bind_to_gtt()
drm_mm.c expects DRM_MEM_MM, not DRM_I915_GEM.
2016-03-11 21:00:14 +00:00
Jean-Sébastien Pédron
85cfd0daea drm: Fix dev->ioctl_count references leak
This fixes the following error:
kernel: error: [drm:pid1167:drm_release] *ERROR* Device busy: 2

Because of that, drm_lastclose() was not called, leading to a few memory
leaks once the driver was unloaded.

MFC after:	1 week
2016-03-11 18:59:15 +00:00
Jean-Sébastien Pédron
740be6d755 drm/i915: Update to match Linux 3.8.13
This update brings initial support for Haswell GPUs.

Tested by:	Many users of FreeBSD, PC-BSD and HardenedBSD
Relnotes:	yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D5554
2016-03-08 20:33:02 +00:00
John Baldwin
cbc4d2db75 Remove taskqueue_enqueue_fast().
taskqueue_enqueue() was changed to support both fast and non-fast
taskqueues 10 years ago in r154167.  It has been a compat shim ever
since.  It's time for the compat shim to go.

Submitted by:	Howard Su <howard0su@gmail.com>
Reviewed by:	sephe
Differential Revision:	https://reviews.freebsd.org/D5131
2016-03-01 17:47:32 +00:00
Svatopluk Kraus
d6849317c5 As <machine/param.h> is included from <sys/param.h>, there is no need
to include it explicitly when <sys/param.h> is already included.

Reviewed by:	alc, kib
Differential Revision:	https://reviews.freebsd.org/D5378
2016-02-22 09:04:36 +00:00
Svatopluk Kraus
a1e1814d76 As <machine/pmap.h> is included from <vm/pmap.h>, there is no need to
include it explicitly when <vm/pmap.h> is already included.

Reviewed by:	alc, kib
Differential Revision:	https://reviews.freebsd.org/D5373
2016-02-22 09:02:20 +00:00
Jean-Sébastien Pédron
fe8e65ae3d drm: Revert the part of r288653 about M_WAITOK vs M_NOWAIT
Using M_NOWAIT could lead to transient failures with ioctls.

Suggested by:	kib
2016-01-13 20:35:02 +00:00
Jean-Sébastien Pédron
bd2ebb612d drm/i915: Further reduce the diff with Linux 3.8
There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.
2016-01-13 19:52:25 +00:00
Alan Cox
c869e67208 Introduce a new mechanism for relocating virtual pages to a new physical
address and use this mechanism when:

1. kmem_alloc_{attr,contig}() can't find suitable free pages in the physical
   memory allocator's free page lists.  This replaces the long-standing
   approach of scanning the inactive and inactive queues, converting clean
   pages into PG_CACHED pages and laundering dirty pages.  In contrast, the
   new mechanism does not use PG_CACHED pages nor does it trigger a large
   number of I/O operations.

2. on 32-bit MIPS processors, uma_small_alloc() and the pmap can't find
   free pages in the physical memory allocator's free page lists that are
   covered by the direct map.  Tested by: adrian

3. ttm_bo_global_init() and ttm_vm_page_alloc_dma32() can't find suitable
   free pages in the physical memory allocator's free page lists.

In the coming months, I expect that this new mechanism will be applied in
other places.  For example, balloon drivers should use relocation to
minimize fragmentation of the guest physical address space.

Make vm_phys_alloc_contig() a little smarter (and more efficient in some
cases).  Specifically, use vm_phys_segs[] earlier to avoid scanning free
page lists that can't possibly contain suitable pages.

Reviewed by:	kib, markj
Glanced at:	jhb
Discussed with:	jeff
Sponsored by:	EMC / Isilon Storage Division
Differential Revision:	https://reviews.freebsd.org/D4444
2015-12-19 18:42:50 +00:00
John Baldwin
544f167747 t seems certain Intel GPUs use GPIO bitbanging over a child device
instead of GMBUS access for I2C transfers.  The GMBUS driver falls back
to this mode when a transfer times out.  However, the first transfer to
timeout was sending the request back to itself resulting in an panic due
to recursing on a lock.  Fix it to forward the request on to the proper
device.  This appears to have been accidentally changed in r277487.

Reported by:	Joe Maloney <jmaloney@pcbsd.org>
Reviewed by:	adrian, dumbbell, imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D4599
2015-12-17 20:33:20 +00:00
Gleb Smirnoff
b0cd20172d A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and
  unlike before, all pages will be kept busied on return, like it was
  done before with the 'reqpage' only. Now the reqpage goes away. With
  new interface it is easier to implement code protected from race
  conditions.

  Such arrayed requests for now should be preceeded by a call to
  vm_pager_haspage() to make sure that request is possible. This
  could be improved later, making vm_pager_haspage() obsolete.

  Strenghtening the promises on the business of the array of pages
  allows us to remove such hacks as swp_pager_free_nrpage() and
  vm_pager_free_nonreq().

o New KPI accepts two integer pointers that may optionally point at
  values for read ahead and read behind, that a pager may do, if it
  can. These pages are completely owned by pager, and not controlled
  by the caller.

  This shifts the UFS-specific readahead logic from vm_fault.c, which
  should be file system agnostic, into vnode_pager.c. It also removes
  one VOP_BMAP() request per hard fault.

Discussed with:	kib, alc, jeff, scottl
Sponsored by:	Nginx, Inc.
Sponsored by:	Netflix
2015-12-16 21:30:45 +00:00
Jean-Sébastien Pédron
75fcfd2d4b drm/i915: Reduce diff with Linux 3.8
There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.

MFC after:	2 months
2015-11-28 17:38:27 +00:00
Jean-Sébastien Pédron
99ebb75d84 drm/i915: Further reduce the diff in i915_dma.c
MFC after:	2 months
2015-11-28 17:37:41 +00:00
Jean-Sébastien Pédron
31f37716a0 drm/i915: Reduce diff with Linux 3.8
There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.

MFC after:	2 months
2015-11-28 15:22:46 +00:00
Jean-Sébastien Pédron
47ba4673a4 drm/i915: Reduce diff with Linux 3.8
There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.

MFC after:	2 months
2015-11-08 19:29:34 +00:00
Jean-Sébastien Pédron
1db7984861 drm/i915: Reduce diff with Linux 3.8
There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.

MFC after:	2 months
2015-11-01 19:55:32 +00:00
Jean-Sébastien Pédron
25a984748c drm/i915: Reduce diff with Linux 3.8
There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.

MFC after:	2 months
2015-10-31 15:09:31 +00:00
Jean-Sébastien Pédron
48332b1c7a drm/i915: Reduce diff with Linux 3.8
There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.

MFC after:	2 months
2015-10-27 21:23:19 +00:00
Jean-Sébastien Pédron
a47d72b7ca drm/i915: Reduce diff with Linux 3.8
There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.

MFC after:	2 months
2015-10-27 20:34:30 +00:00
Jean-Sébastien Pédron
57e192dd23 drm/i915: Reduce diff with Linux 3.8
There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.

MFC after:	2 month
2015-10-25 14:57:53 +00:00
Jean-Sébastien Pédron
170a938721 drm/i915: Reduce diff with Linux 3.8
There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.

MFC after:	2 months
2015-10-25 14:42:56 +00:00
John Baldwin
d836c868a8 i915_gem_do_execbuffer() holds the pages backing each relocation region for
various reasons while executing user commands.  After these commands are
completed, the pages backing the relocation regions are unheld.

Since relocation regions do not have to be page aligned, the code in
validate_exec_list() allocates 2 extra page pointers in the array of
held pages populated by vm_fault_quick_hold_pages().  However, the cleanup
code that unheld the pages always assumed that only the buffer size /
PAGE_SIZE pages were used.  This meant that non-page aligned buffers would
not unheld the last 1 or 2 pages in the list.  Fix this by saving the
number of held pages returned by vm_fault_quick_hold_pages() for each
relocation region and using this count during cleanup.

Reviewed by:	dumbbell, kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D3965
2015-10-21 20:49:45 +00:00
Jean-Sébastien Pédron
c223ad05c4 drm/i915: Reduce diff with Linux 3.8
There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.

MFC after:	2 months
2015-10-17 14:48:39 +00:00
Jean-Sébastien Pédron
c165a9c7e6 drm/i915: Remove "Attempting to unbind pinned buffer" message
This error message is removed in later versions of Linux and currently,
it spams users.

PR:		200712
MFC after:	1 week
2015-10-10 07:43:02 +00:00
Adrian Chadd
3d9902ab4a Remove gen3 check introduced in r286653.
kib spotted this and noticed it's not correct.

Submitted by:	kib
Reviewed by:	dumbbell
2015-10-06 20:58:45 +00:00
Adrian Chadd
280bcab3d0 drm2: a few minor fixes after r280183
* Remove obsolete drm_agp_*_memory() prototypes.
* Fix comment in drm_fops.c (outisde -> outside).
* Fix some formatting issues in drm_stub.c (spaces -> tabs).
* Add missing case statement (gen == 3) in intel_gpu_reset().
* Restore pci_enable_busmaster() call in the init path (fixes gpu hang on i945GM).
* Replace M_WAITOK with M_NOWAIT when the return value of malloc is checked (may be incorrect).

Submitted by:	<s3erios@gmail.com>
Reviewed by:	dumbbell
Approved by:	dumbbell
Differential Revision:	https://reviews.freebsd.org/D3413
2015-10-04 07:45:36 +00:00
John Baldwin
2ad026889e Most error cases in i915_gem_do_execbuffer() jump to one of two labels to
release resources (such as unholding pages) when errors occur.  Some
recently added error checks return immediately instead of jumping to a
label resulting in leaks.  Fix these to jump to a label to do cleanup
instead.

Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D3745
2015-10-01 16:59:07 +00:00
Bjoern A. Zeeb
9293cfeb42 Hide an unused in FreeBSD function behind #ifdef linux to get rid of
the compile time warning.

Reviewed by:		gnn
MFC after:		2 weeks
Differential Revision:	https://reviews.freebsd.org/D3710
2015-09-22 15:32:27 +00:00
Andriy Gapon
8f875df090 radeon_suspend_kms: don't mess with pci state that's managed by the bus
The pci bus driver handles the power state, it also manages
configuration state saving and restoring for its child devices.  Thus a
PCI device driver does not have to worry about those things.  In fact, I
observe a hard system hang when trying to suspend a system with active
radeonkms driver where both the bus driver and radeonkms driver try to
do the same thing.  I suspect that it could be because of an access to a
PCI configuration register after the device is placed into D3 state.

Reviewed by:	dumbbell, jhb
MFC after:	13 days
Differential Revision:	https://reviews.freebsd.org/D3561
2015-09-11 15:51:20 +00:00
Jean-Sébastien Pédron
7bead7ac28 drm/ttm: Drain taskqueue if taskqueue_cancel_timeout() returned an error
Before, this was done if `pending` was true. This is not what the
manpage suggests and not what was done elsewhere in the same file.
2015-09-08 19:41:19 +00:00
Baptiste Daroussin
dc6c827749 Reduce diff with linux 3.8.13 on i915 headers 2015-09-05 23:22:59 +00:00
Baptiste Daroussin
21bba0ead0 Mark ValleyView/Bay Trail as not supported 2015-08-29 00:05:39 +00:00
Baptiste Daroussin
de84ba19e3 More fixes to the new macros 2015-08-27 05:39:32 +00:00
Baptiste Daroussin
43eb73d456 Fix typo in new macros 2015-08-27 05:27:18 +00:00
Baptiste Daroussin
612c465eed Merge i915_emit_box_p and i915_emit_box as done in linux 3.8
Reviewed by:	dumbbell
Differential Revision:	https://reviews.freebsd.org/D3495
2015-08-26 22:19:53 +00:00
Baptiste Daroussin
81a1afdcc9 Back out a change which should not have been committed yet 2015-08-26 22:09:12 +00:00
Baptiste Daroussin
bcdb2347c5 backout a change that should not have crept in 2015-08-26 22:00:40 +00:00
Baptiste Daroussin
736a911f22 Reduce diff against linux 3.8
Reviewed by:	dumbbell
Differential Revision:	https://reviews.freebsd.org/D3492
2015-08-26 21:35:16 +00:00
Baptiste Daroussin
85b8a32aea Reduce diff with linux 3.8.13 on i915_drv.c
While here update the list of devices id to match the one in linux 3.8.13

Reviewed by:	dumbbell
Differential Revision:	https://reviews.freebsd.org/D3489
2015-08-26 21:33:43 +00:00
Baptiste Daroussin
95fb5cf717 Add more DRM_* debug macros from linux 3.8.13 2015-08-26 21:31:04 +00:00
Baptiste Daroussin
e402f9113b Synchronize i915_reg.h with linux 3.8.13 version
Keep a couple of old macros that will be removed lated when the rest of the code
will be updated to 3.8.13 equivalent.
Chase the renamed macros

Reviewed by:	dumbbell
Differential Revision:	https://reviews.freebsd.org/D3487
2015-08-26 21:17:48 +00:00
Baptiste Daroussin
5b5117af3b Reduce diff on i915_dma.c against linux 3.8.13
No functional changes

Discussed with:	dumbbell
Reviewed by:	dumbbell
2015-08-26 13:23:56 +00:00
Koop Mast
d8f4b93526 Instead of defining the actualy user and group id in the drmP.h files
define GID_VIDEO in sys/conf.h, and use it together with UID_ROOT
to define DRM_DEV_UID and DRM_DEV_GID in the drmP.h files.

So there is one place where the UID's and GID's are defined.

Submitted by:	ed@
Reviewed by:	ed@, dumbbell@
Differential Revision:	https://reviews.freebsd.org/D3360
2015-08-11 16:51:44 +00:00
Koop Mast
34c7eb57ed Add a new group named 'video' with the id of 44. And make drm create
devices in /dev/dri/ with this new group.

This will allow ports and users to more easily access to these devices
for OpenGL and OpenCL support.

Reviewed by:	dumbbell@
Approved by:	dumbbell@
Differential Revision:	https://reviews.freebsd.org/D1260
2015-08-09 12:58:56 +00:00
Jean-Sébastien Pédron
133362912c drm/i915: Sort functions in i915_gem.c to match Linux 3.8's ordering
While here, reduce the style diff with Linux.

There is no functional change. The goal is to ease the future update to
Linux 3.8's i915 driver.

MFC after:	2 months
2015-07-28 21:47:37 +00:00
Andriy Gapon
2f1653808a ttm_vm_page_alloc: use vm_page_alloc for pages without dma32 restriction
This change re-organizes code a little bit to extract common pieces
of ttm_alloc_new_pages() and ttm_get_pages() into dedicated functions.
Also, for requests without address restrictions regular vm_page_alloc()
is used.
Lastly, when vm_page_alloc_contig() fails we call VM_WAIT before calling
vm_pageout_grow_cache() to ensure that there is enough free pages at all.

Reviewed by:	kib
MFC after:	15 days
2015-06-15 13:43:23 +00:00
Gleb Smirnoff
0fe299de4b A miss from r284310. vm_pager_get_pages() updates the array, so there is
no need for vm_page_lookup().
2015-06-12 13:15:14 +00:00
Mateusz Guzik
f6f6d24062 Implement lockless resource limits.
Use the same scheme implemented to manage credentials.

Code needing to look at process's credentials (as opposed to thred's) is
provided with *_proc variants of relevant functions.

Places which possibly had to take the proc lock anyway still use the proc
pointer to access limits.
2015-06-10 10:48:12 +00:00
John Baldwin
7077c42623 Add a new file operations hook for mmap operations. File type-specific
logic is now placed in the mmap hook implementation rather than requiring
it to be placed in sys/vm/vm_mmap.c.  This hook allows new file types to
support mmap() as well as potentially allowing mmap() for existing file
types that do not currently support any mapping.

The vm_mmap() function is now split up into two functions.  A new
vm_mmap_object() function handles the "back half" of vm_mmap() and accepts
a referenced VM object to map rather than a (handle, handle_type) tuple.
vm_mmap() is now reduced to converting a (handle, handle_type) tuple to a
a VM object and then calling vm_mmap_object() to handle the actual mapping.
The vm_mmap() function remains for use by other parts of the kernel
(e.g. device drivers and exec) but now only supports mapping vnodes,
character devices, and anonymous memory.

The mmap() system call invokes vm_mmap_object() directly with a NULL object
for anonymous mappings.  For mappings using a file descriptor, the
descriptors fo_mmap() hook is invoked instead.  The fo_mmap() hook is
responsible for performing type-specific checks and adjustments to
arguments as well as possibly modifying mapping parameters such as flags
or the object offset.  The fo_mmap() hook routines then call
vm_mmap_object() to handle the actual mapping.

The fo_mmap() hook is optional.  If it is not set, then fo_mmap() will
fail with ENODEV.  A fo_mmap() hook is implemented for regular files,
character devices, and shared memory objects (created via shm_open()).

While here, consistently use the VM_PROT_* constants for the vm_prot_t
type for the 'prot' variable passed to vm_mmap() and vm_mmap_object()
as well as the vm_mmap_vnode() and vm_mmap_cdev() helper routines.
Previously some places were using the mmap()-specific PROT_* constants
instead.  While this happens to work because PROT_xx == VM_PROT_xx,
using VM_PROT_* is more correct.

Differential Revision:	https://reviews.freebsd.org/D2658
Reviewed by:	alc (glanced over), kib
MFC after:	1 month
Sponsored by:	Chelsio
2015-06-04 19:41:15 +00:00
Jung-uk Kim
fd90e2ed54 CALLOUT_MPSAFE has lost its meaning since r141428, i.e., for more than ten
years for head.  However, it is continuously misused as the mpsafe argument
for callout_init(9).  Deprecate the flag and clean up callout_init() calls
to make them more consistent.

Differential Revision:	https://reviews.freebsd.org/D2613
Reviewed by:	jhb
MFC after:	2 weeks
2015-05-22 17:05:21 +00:00
Jean-Sébastien Pédron
7b5702f3df drm: Import Linux commit 9bc3cd5673d84d29272fa7181a4dfca83cbb48c1
Author: Ville Syrjälä <ville.syrjala@linux.intel.com>
Date:   Fri May 31 12:17:08 2013 +0000

    drm: Sort connector modes based on vrefresh

    Keeping the modes sorted by vrefresh before the pixel clock makes the
    mode list somehow more pleasing to the eye.

    Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

PR:		198936
Obtained from:	Linux
MFC after:	1 month
MFC with:	r280183
2015-03-29 18:45:51 +00:00
Gleb Smirnoff
0ac23e997d Fix build.
Reviewed by:	dumbbell
2015-03-17 19:13:11 +00:00
Jean-Sébastien Pédron
455fa6518a drm: Update the device-independent code to match Linux 3.8.13
This update brings few features:
    o  Support for the setmaster/dropmaster ioctls. For instance, they
       are used to run multiple X servers simultaneously.
    o  Support for minor devices. The only user-visible change is a new
       entry in /dev/dri but it is useless at the moment. This is a
       first step to support render nodes [1].

The main benefit is to greatly reduce the diff with Linux (at the
expense of an unreadable commit diff). Hopefully, next upgrades will be
easier.

No updates were made to the drivers, beside adapting them to API
changes.

[1] https://en.wikipedia.org/wiki/Direct_Rendering_Manager#Render_nodes

Tested by:	Many people
MFC after:	1 month
Relnotes:	yes
2015-03-17 18:50:33 +00:00
Jason A. Harmening
edf3c81a5c Using parent DMA tag in drm_pci_alloc(). This can allow drm2 devices to work with Intel DMAR enabled for the system, as long as DMAR is disabled for the drm2 device.
Approved by:	kib (mentor)
MFC after:	1 week
2015-03-12 14:18:36 +00:00
Jean-Sébastien Pédron
bc346eefbd drm: Import Linux commit b7ea85a4fed37835eec78a7be3039c8dc22b8178
Author: Huacai Chen <chenhc@lemote.com>
Date:   Tue May 21 06:23:43 2013 +0000

    drm: fix a use-after-free when GPU acceleration disabled

    When GPU acceleration is disabled, drm_vblank_cleanup() will free the
    vblank-related data, such as vblank_refcount, vblank_inmodeset, etc.
    But we found that drm_vblank_post_modeset() may be called after the
    cleanup, which use vblank_refcount and vblank_inmodeset. And this will
    cause a kernel panic.

    Fix this by return immediately if dev->num_crtcs is zero. This is the
    same thing that drm_vblank_pre_modeset() does.

    Call trace of a drm_vblank_post_modeset() after drm_vblank_cleanup():
    [   62.628906] [<ffffffff804868d0>] drm_vblank_post_modeset+0x34/0xb4
    [   62.628906] [<ffffffff804c7008>] atombios_crtc_dpms+0xb4/0x174
    [   62.628906] [<ffffffff804c70e0>] atombios_crtc_commit+0x18/0x38
    [   62.628906] [<ffffffff8047f038>] drm_crtc_helper_set_mode+0x304/0x3cc
    [   62.628906] [<ffffffff8047f92c>] drm_crtc_helper_set_config+0x6d8/0x988
    [   62.628906] [<ffffffff8047dd40>] drm_fb_helper_set_par+0x94/0x104
    [   62.628906] [<ffffffff80439d14>] fbcon_init+0x424/0x57c
    [   62.628906] [<ffffffff8046a638>] visual_init+0xb8/0x118
    [   62.628906] [<ffffffff8046b9f8>] take_over_console+0x238/0x384
    [   62.628906] [<ffffffff80436df8>] fbcon_takeover+0x7c/0xdc
    [   62.628906] [<ffffffff8024fa20>] notifier_call_chain+0x44/0x94
    [   62.628906] [<ffffffff8024fcbc>] __blocking_notifier_call_chain+0x48/0x68
    [   62.628906] [<ffffffff8042d990>] register_framebuffer+0x228/0x260
    [   62.628906] [<ffffffff8047e010>] drm_fb_helper_single_fb_probe+0x260/0x314
    [   62.628906] [<ffffffff8047e2c4>] drm_fb_helper_initial_config+0x200/0x234
    [   62.628906] [<ffffffff804e5560>] radeon_fbdev_init+0xd4/0xf4
    [   62.628906] [<ffffffff804e0e08>] radeon_modeset_init+0x9bc/0xa18
    [   62.628906] [<ffffffff804bfc14>] radeon_driver_load_kms+0xdc/0x12c
    [   62.628906] [<ffffffff8048b548>] drm_get_pci_dev+0x148/0x238
    [   62.628906] [<ffffffff80423564>] local_pci_probe+0x5c/0xd0
    [   62.628906] [<ffffffff80241ac4>] work_for_cpu_fn+0x1c/0x30
    [   62.628906] [<ffffffff802427c8>] process_one_work+0x274/0x3bc
    [   62.628906] [<ffffffff80242934>] process_scheduled_works+0x24/0x44
    [   62.628906] [<ffffffff8024515c>] worker_thread+0x31c/0x3f4
    [   62.628906] [<ffffffff802497a8>] kthread+0x88/0x90
    [   62.628906] [<ffffffff80206794>] kernel_thread_helper+0x10/0x18

    Signed-off-by: Huacai Chen <chenhc@lemote.com>
    Signed-off-by: Binbin Zhou <zhoubb@lemote.com>
    Cc: <stable@vger.kernel.org>
    Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
    Acked-by: Paul Menzel <paulepanter@users.sourceforge.net>
    Signed-off-by: Dave Airlie <airlied@gmail.com>

Reported by:	J.R. Oldroyd <fbsd@opal.com>
MFC after:	2 weeks
2015-03-04 20:43:46 +00:00
Jean-Sébastien Pédron
76e2f97656 vt(4): Add support to "downgrade" from eg. vt_fb to vt_vga
The main purpose of this feature is to be able to unload a KMS driver.

When going back from the current vt(4) backend to the previous backend,
the previous backend is reinitialized with the special VDF_DOWNGRADE
flag set. Then the current driver is terminated with the new "vd_fini"
callback.

In the case of vt_fb and vt_vga, this allows the former to pass the
vgapci device vt_fb used to vt_vga so the device can be rePOSTed.

Differential Revision:	https://reviews.freebsd.org/D687
2015-03-01 12:54:22 +00:00
Dimitry Andric
a6ebe06637 After r278004 was committed, Bruce Evans noted that the casts were
actually completely unnecessary, here:

https://lists.freebsd.org/pipermail/svn-src-all/2015-February/098478.html

Remove the casts, and just assign &xxx_io_mc_regs[0][0] directly.

Reviewed by:	dumbbell
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D1748
2015-02-09 07:56:50 +00:00
Ed Maste
d050b80397 Remove duplicate intel_fbc_enabled prototype
Fixed upstream in Linux commit 7ff0ebcc1e30e3216c8c62ee71f59ac830b10364

Differential Revision:	https://reviews.freebsd.org/D1762
Reviewed by:	hselasky, kib
Sponsored by:	The FreeBSD Foundation
2015-02-03 15:41:09 +00:00
Konstantin Belousov
98173b7fa7 If the vm_page_alloc_contig() failed in the ttm page allocators, do
what other callers of vm_page_alloc_contig() do, retry after
vm_pageout_grow_cache().

Sponsored by:	The FreeBSD Foundation
2015-02-03 13:45:06 +00:00
Konstantin Belousov
668259c84d Do not access gmbus_ports array past its end.
Reported and tested by:	hselasky
Sponsored by:	The FreeBSD Foundation
2015-02-03 13:43:03 +00:00
Konstantin Belousov
35669caf93 Followup to r278147. Two more sign errors.
Noted by:	hps
Sponsored by:	The FreeBSD Foundation
2015-02-03 11:34:18 +00:00
Konstantin Belousov
cbc34301ba Fix sign for the error code returned from the driver-specific code.
Noted by:	hps
Sponsored by:	The FreeBSD Foundation
2015-02-03 10:46:07 +00:00
Konstantin Belousov
ae18989eb9 Do not attach to the unsupported chipsets, unless magic tunable is
frobbed.

Sponsored by:	The FreeBSD Foundation
2015-02-03 10:30:41 +00:00
Dimitry Andric
5d3fc1ff66 Constify a number of accesses in drm2's radeon drivers to avoid
-Wcast-qual warnings.  No functional change.

Reviewed by:	dumbbell
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D1727
2015-01-31 22:18:52 +00:00
Adrian Chadd
29fa5c67e4 Fix backlight for ivybridge based laptops (and whatever else comes through
this codepath.)

(1<<30) is documented as BLM_PCH_OVERRIDE_ENABLE, which the current
i915 driver in Linux only sets for broadwell chips.

This fixes the backlight control on the Lenovo X230.

Approved by:	kib
Obtained from:	Linux 7aa1e7f06d6ea1bce3b27630d50769d13da28b1a
2015-01-31 02:13:25 +00:00
Konstantin Belousov
47671d1bab An update for the i915 GPU driver, which brings the code up to Linux
commit 4d93914ae3db4a897ead4b.  Some related drm infrastructure
changes are imported as needed.

Biggest update is the rewrite of the i915 gem io to more closely
follow Linux model, althought the mechanism used by FreeBSD port is
different.

Sponsored by:	The FreeBSD Foundation
MFC after:	2 month
2015-01-21 16:10:37 +00:00
Gleb Kurtsou
dde58752db Adjust printf format specifiers for dev_t and ino_t in kernel.
ino_t and dev_t are about to become uint64_t.

Reviewed by:	kib, mckusick
2014-12-17 07:27:19 +00:00
Eygene Ryabinkin
317d2b1e5c DRM2: fix off-by-one overflow in ioctl processing
Call to the driver-specific ioctl used to process ioctl number
that will lead to the out-of-bounds access to the ioctl handler
array.

PR:		193367
Approved by:	kib
MFC after:	1 week
2014-11-28 12:14:59 +00:00
Jean-Sébastien Pédron
d591845e63 drm/radeon: Lower priority of a message related to invalid EDID
Like in r259717, the prority goes from "error" to "debug" to avoid
spamming logs when the connectors are polled.

PR:		194770
Submitted by:	Larry Rosenman <ler@lerctr.org>
MFC after:	1 week
2014-11-16 17:53:48 +00:00
Jean-Sébastien Pédron
c15af11534 drm: When reading connector mode tunables, list connectors
... and their associated tunables. This gives a way to know the list of
available connectors, no matter the driver.

The problem is that xrandr(1) can list connectors but it uses a
different naming.

MFC after:	1 week
2014-11-03 14:35:07 +00:00
Jean-Sébastien Pédron
4a60312011 drm: Take vt(4) default mode from loader tunables
By default, vt(4) gets the "preferred mode" from DRM, when using a DRM
video driver as its backend. The preferred mode is usually the native
screen resolution.

Now, if this mode isn't appropriate, a user can use loader tunables to
select a mode. The tunables are read in the following order:
    1. kern.vt.fb.modes.$connector_name
    2. kern.vt.fb.default_mode

For example, to set a 1024x768 mode, no matter the connector:
    kern.vt.fb.default_mode="1024x768"

To set a 800x600 mode only on the laptop builtin screen:
    kern.vt.fb.modes.LVDS-1="800x600"

MFC after:	1 week
2014-11-03 10:42:27 +00:00