platform/kernel/linux-3.10.git
9 years agotreewide: Fix typos in printk
Masanari Iida [Sun, 8 Dec 2013 15:22:53 +0000 (00:22 +0900)]
treewide: Fix typos in printk

Correct spelling typo in various part of kernel

Signed-off-by: Masanari Iida <standby24x7@gmail.com>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
9 years agoi2c: exynos5: Remove incorrect clk_disable_unprepare
Sachin Kamat [Wed, 6 Nov 2013 09:39:18 +0000 (15:09 +0530)]
i2c: exynos5: Remove incorrect clk_disable_unprepare

clk_disable_unprepare in remove causes an imbalance and hence gives
the below crash on module remove. While at it also remove some
duplicate code from probe.

/ $ rmmod i2c-exynos5
[    6.996374] ------------[ cut here ]------------
[    6.999523] WARNING: CPU: 2 PID: 1137 at drivers/clk/clk.c:842 clk_disable+0x18/0x24()
[    7.007403] Modules linked in: i2c_exynos5(-)
[    7.011747] CPU: 2 PID: 1137 Comm: rmmod Not tainted 3.12.0-next-20131105-00083-g16f4799-dirty #21
[    7.020696] [<c0014e0c>] (unwind_backtrace+0x0/0xf4) from [<c0011784>] (show_stack+0x10/0x14)
[    7.029190] [<c0011784>] (show_stack+0x10/0x14) from [<c037acd4>] (dump_stack+0x7c/0xb0)
[    7.037255] [<c037acd4>] (dump_stack+0x7c/0xb0) from [<c001e0ac>] (warn_slowpath_common+0x6c/0x88)
[    7.046190] [<c001e0ac>] (warn_slowpath_common+0x6c/0x88) from [<c001e164>] (warn_slowpath_null+0x1c/0x24)
[    7.055818] [<c001e164>] (warn_slowpath_null+0x1c/0x24) from [<c02dcde4>] (clk_disable+0x18/0x24)
[    7.064670] [<c02dcde4>] (clk_disable+0x18/0x24) from [<bf0002d4>] (exynos5_i2c_remove+0x1c/0x34 [i2c_exynos5])
[    7.074736] [<bf0002d4>] (exynos5_i2c_remove+0x1c/0x34 [i2c_exynos5]) from [<c02274a8>] (__device_release_driver+0x58/0xb0)
[    7.085836] [<c02274a8>] (__device_release_driver+0x58/0xb0) from [<c0227b88>] (driver_detach+0xac/0xb0)
[    7.095291] [<c0227b88>] (driver_detach+0xac/0xb0) from [<c02271c0>] (bus_remove_driver+0x4c/0xa0)
[    7.104227] [<c02271c0>] (bus_remove_driver+0x4c/0xa0) from [<c00725dc>] (SyS_delete_module+0x124/0x194)
[    7.113682] [<c00725dc>] (SyS_delete_module+0x124/0x194) from [<c000e2e0>] (ret_fast_syscall+0x0/0x30)
[    7.122957] ---[ end trace 23bb6e4e0bf52196 ]---

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Acked-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
9 years agoi2c: exynos5: add High Speed I2C controller driver
Naveen Krishna Ch [Wed, 16 Oct 2013 05:30:42 +0000 (11:00 +0530)]
i2c: exynos5: add High Speed I2C controller driver

Adds support for High Speed I2C driver found in Exynos5 and
later SoCs from Samsung.

Driver only supports Device Tree method.

Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Signed-off-by: Taekgyun Ko <taeggyun.ko@samsung.com>
Reviewed-by: Simon Glass <sjg@google.com>
Signed-off-by: Yuvaraj Kumar C D <yuvaraj.cd@samsung.com>
Signed-off-by: Andrew Bresticker <abrestic@google.com>
[wsa: rebased to v3.12-rc4 (no of_i2c.h anymore)]
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
9 years agodrm/exynos: add support for apb mapped phys in hdmi driver
Rahul Sharma [Fri, 9 May 2014 06:34:18 +0000 (15:34 +0900)]
drm/exynos: add support for apb mapped phys in hdmi driver

Previous SoCs have hdmi phys which are accessible through
dedicated i2c lines. Newer SoCs have Apb mapped hdmi phys.
Hdmi driver is modified to support apb mapped phys.

Signed-off-by: Rahul Sharma <Rahul.Sharma@samsung.com>
Signed-off-by: Inki Dae <inki.dae@samsung.com>
9 years agosched: replace INIT_COMPLETION with reinit_completion
Wolfram Sang [Thu, 14 Nov 2013 22:32:01 +0000 (14:32 -0800)]
sched: replace INIT_COMPLETION with reinit_completion

For the casual device driver writer, it is hard to remember when to use
init_completion (to init a completion structure) or INIT_COMPLETION (to
*reinit* a completion structure).  Furthermore, while all other
completion functions exepct a pointer as a parameter, INIT_COMPLETION
does not.  To make it easier to remember which function to use and to
make code more readable, introduce a new inline function with the proper
name and consistent argument type.  Update the kernel-doc for
init_completion while we are here.

Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Acked-by: Linus Walleij <linus.walleij@linaro.org> (personally at LCE13)
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
9 years agoARM: EXYNOS: Fix core ID used by platsmp and hotplug code
Tomasz Figa [Tue, 15 Jul 2014 17:59:18 +0000 (02:59 +0900)]
ARM: EXYNOS: Fix core ID used by platsmp and hotplug code

When CPU topology is specified in device tree, cpu_logical_map() does
not return core ID anymore, but rather full MPIDR value. This breaks
existing calculation of PMU register offsets on Exynos SoCs.

This patch fixes the problem by adjusting the code to use only core ID
bits of the value returned by cpu_logical_map() to allow CPU topology to
be specified in device tree on Exynos SoCs.

Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
Signed-off-by: Olof Johansson <olof@lixom.net>
9 years agoARM: EXYNOS: Add generic cpu power control functions for exynos SoCs
Leela Krishna Amudala [Thu, 15 May 2014 19:23:24 +0000 (04:23 +0900)]
ARM: EXYNOS: Add generic cpu power control functions for exynos SoCs

Add generic cpu power control functions for exynos based
SoCS for cpu power up/down and to know the cpu status.

Signed-off-by: Leela Krishna Amudala <leela.krishna@linaro.org>
Signed-off-by: Abhilash Kesavan <a.kesavan@samsung.com>
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
9 years agoclocksource: mct: extend mct to support 8 local interrupts for Exynos5420
Chander Kashyap [Sun, 1 Dec 2013 22:48:23 +0000 (07:48 +0900)]
clocksource: mct: extend mct to support 8 local interrupts for Exynos5420

Exynos5420 is octa-core SoC from Samsung. Hence extend exynos-mct clocksource
driver to support 8 local interrupts.

Also extend dts entries for 8 interrupts.

Signed-off-by: Chander Kashyap <chander.kashyap@linaro.org>
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
9 years agoclocksource: exynos_mct: use (request/free)_irq calls for local timer registration
Chander Kashyap [Tue, 18 Jun 2013 15:29:35 +0000 (00:29 +0900)]
clocksource: exynos_mct: use (request/free)_irq calls for local timer registration

Replace the (setup/remove)_irq calls for local timer registration with
(request/free)_irq calls. This generalizes the local timer registration API.
Suggested by Mark Rutland.

Signed-off-by: Chander Kashyap <chander.kashyap@linaro.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
9 years agoserial: samsung: select EXYNOS specific driver data if ARCH_EXYNOS is defined
Chander Kashyap [Tue, 18 Jun 2013 15:29:34 +0000 (00:29 +0900)]
serial: samsung: select EXYNOS specific driver data if ARCH_EXYNOS is defined

All EXYNOS4/5 SoCs share a common driver data in the samsung serial
driver. Hence, let the driver data inclusion be based on ARCH_EXYNOS
instead of SOC specific definition.

Signed-off-by: Chander Kashyap <chander.kashyap@linaro.org>
Reviewed-by: Tomasz Figa <t.figa@samsung.com>
Reviewed by: Girish K S <ks.giri@samsung.com>
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
9 years agopinctrl: exynos: add exynos5420 SoC specific data
Leela Krishna Amudala [Wed, 19 Jun 2013 13:16:26 +0000 (22:16 +0900)]
pinctrl: exynos: add exynos5420 SoC specific data

Add Samsung EXYNOS5420 SoC specific data to enable pinctrl
support for all platforms based on EXYNOS5420.

Signed-off-by: Leela Krishna Amudala <l.krishna@samsung.com>
Reviewed-by: Doug Anderson <dianders@chromium.org>
Acked-by: Tomasz Figa <t.figa@samsung.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by : Sunil Joshi <joshi@samsung.com>
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
9 years agommc: dw_mmc: move the platform specific init call 17/32017/2
Yuvaraj Kumar C D [Fri, 30 Aug 2013 15:12:19 +0000 (00:12 +0900)]
mmc: dw_mmc: move the platform specific init call

Current platform specific private data initialization call
dw_mci_exynos_priv_init() can be used to do platform specific
initialization of SMU and others in future. So the drv_data->init
call has moved to dw_mci_probe().

Change-Id: I02dbf3360a283d7a25e171e1f97832c01837d5d1
Signed-off-by: Yuvaraj Kumar C D <yuvaraj.cd@samsung.com>
Tested-by: Alim Akhtar <alim.akhtar@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Acked-by: Seungwon Jeon <tgih.jun@samsung.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
9 years agommc: dw_mmc: exynos: configure SMU in exynos5420 16/32016/2
Yuvaraj Kumar C D [Fri, 30 Aug 2013 15:12:35 +0000 (00:12 +0900)]
mmc: dw_mmc: exynos: configure SMU in exynos5420

Exynos5420 Mobile Storage Host controller has Security Management
Unit (SMU) for channel 0 and channel 1 (mainly for eMMC).
This time, SMU configuration is set for non-encryption mode.

Change-Id: I405651fd5aee1c572d39e05400a048bf724be4ad
Signed-off-by: Yuvaraj Kumar C D <yuvaraj.cd@samsung.com>
Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Acked-by: Seungwon Jeon <tgih.jun@samsung.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
9 years agommc: dw_mmc: exynos: move the exynos private init 15/32015/2
Yuvaraj Kumar C D [Fri, 30 Aug 2013 15:11:57 +0000 (00:11 +0900)]
mmc: dw_mmc: exynos: move the exynos private init

Currently platform specific private data initialization is done by
dw_mci_exynos_priv_init and dw_mci_exynos_parse_dt. As we already have
separate platform specific device tree parser dw_mci_exynos_parse_dt,
move the dw_mci_exynos_priv_init code to dw_mci_exynos_parse_dt.
We can use the dw_mci_exynos_priv_init to do some actual platform
specific initialization of SMU and etc.

Change-Id: Iad20178598423b69d029e33ee1e3d77a76fbd888
Signed-off-by: Yuvaraj Kumar C D <yuvaraj.cd@samsung.com>
Tested-by: Alim Akhtar <alim.akhtar@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Acked-by: Seungwon Jeon <tgih.jun@samsung.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
9 years agommc: dw_mmc: exynos: Add a new compatible string for exynos5420 14/32014/2
Yuvaraj Kumar C D [Fri, 24 May 2013 10:04:32 +0000 (15:34 +0530)]
mmc: dw_mmc: exynos: Add a new compatible string for exynos5420

The Exynos5420 has a DWMMC controller which is different from prior
versions.This patch adds a new compatible string for Exynos5420.

Change-Id: I9191ebc65d2e308a43980a81d4a2b0c48c771ca0
Signed-off-by: Abhilash Kesavan <a.kesavan@samsung.com>
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
Signed-off-by: Yuvaraj Kumar C D <yuvaraj.cd@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
9 years agoirqchip: exynos-combiner: remove hard-coded irq_base value 13/32013/2
Chander Kashyap [Sun, 20 Oct 2013 21:01:40 +0000 (06:01 +0900)]
irqchip: exynos-combiner: remove hard-coded irq_base value

Replace irq_domain_add_simple with "irq_domain_add_linear" in order to use
linear irq domain, and to remove hardcoded irq_base_value.

Change-Id: I2b8235d77f6545ac24b41d3bce8f24c60d829a39
Signed-off-by: Chander Kashyap <chander.kashyap@linaro.org>
Reviewed-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
9 years agosensorhub: remove unnecessary kfree during driver shutdown 62/31762/1 accepted/tizen/common/20141215.134117 accepted/tizen/mobile/20141216.083708 accepted/tizen/tv/20141217.085627 accepted/tizen/wearable/20141217.085804 submit/tizen/20141215.004633
Seung-Woo Kim [Tue, 9 Dec 2014 12:53:53 +0000 (21:53 +0900)]
sensorhub: remove unnecessary kfree during driver shutdown

The ssp_data pointer is allocated with devm_kzalloc, so freeing it
is not necessary.

Change-Id: Idd26ba71e9c343d61e7b5aa01b21a2f2c3ae9b00
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
9 years agodma-buf/dmabuf-sync: disable dmabuf sync module 05/31505/1
Inki Dae [Fri, 5 Dec 2014 11:44:32 +0000 (20:44 +0900)]
dma-buf/dmabuf-sync: disable dmabuf sync module

This module has a resource free bug so this patch disables
dmabuf sync module until the bug is fixed.

Change-Id: Ic84c88e3d5dbead1c25bf4b238b8ef5f51045099
Signed-off-by: Inki Dae <inki.dae@samsung.com>
9 years agomisc: modem_if: replace memcpy for string to strncpy to fix overflow 92/31492/1
Seung-Woo Kim [Fri, 5 Dec 2014 10:23:57 +0000 (19:23 +0900)]
misc: modem_if: replace memcpy for string to strncpy to fix overflow

The memcpy with string source and size larger than string length
causes data overflow. So this patch replaces memcpy to strncpy to
fix data overflow.

Change-Id: Ibc326bdf0a1235c67013576ab9d8f170e8711344
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
9 years agoregulator: core: Fix regualtor_ena_gpio_free not to access pin after freeing 53/31453/1
Seung-Woo Kim [Thu, 4 Dec 2014 09:19:19 +0000 (18:19 +0900)]
regulator: core: Fix regualtor_ena_gpio_free not to access pin after freeing

After freeing pin from regulator_ena_gpio_free, loop can access
the pin. So this patch fixes not to access pin after freeing.

Change-Id: I690860751e45b1513fb9171bba1c0bb7e89c0446
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
9 years agoinput: keyboard: mcs_touchkey: add sentinel into array of of_device_id 74/31374/1
Seung-Woo Kim [Thu, 4 Dec 2014 11:19:30 +0000 (20:19 +0900)]
input: keyboard: mcs_touchkey: add sentinel into array of of_device_id

Without sentinel, of_match_node() to array causes out-of-bound
memory access. So this patch adds sentinel into array.

Change-Id: Icfe3d8c2fdb0faa006f413e7c080b6d713eab08c
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
9 years agosensorhub: Add size check before setting message
Seung-Woo Kim [Tue, 2 Dec 2014 13:35:48 +0000 (22:35 +0900)]
sensorhub: Add size check before setting message

User can send wrong message size, so before setting message value,
the size should be checked to prevent buffer overflow.

Change-Id: Ia3ebdbd45b357054b6fad05c7f251a0b770172db
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
9 years agoinput: touchscreen: mms128: fix allocation size for conf data 03/31203/1
Seung-Woo Kim [Tue, 2 Dec 2014 12:48:24 +0000 (21:48 +0900)]
input: touchscreen: mms128: fix allocation size for conf data

The data in config_fw has header, data blocks and end block. The
data count in the config_fw is the number of data blocks except
end block. Without considering end block, this causes buffer
overflow. So this patch fixes allocation size considering end block.

Change-Id: I053e251a21ba8befb03a1db233e4e2d9dbf1b795
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
9 years agodmxdev: don't use before checking file->private_data 34/27934/2
Mauro Carvalho Chehab [Wed, 3 Sep 2014 17:32:26 +0000 (14:32 -0300)]
dmxdev: don't use before checking file->private_data

As reported by smatch:
drivers/media/dvb-core/dmxdev.c:1091 dvb_demux_poll() warn: variable dereferenced before check 'dmxdevfilter' (see line 1088)

This was introduced by changeset d102cac8097c.

We need to test before using it.

Change-Id: I4e51d508c466b915338bd0a88a7afb49f4dbeb4d
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Signed-off-by: Changbing Xiong <cb.xiong@samsung.com>
9 years agos5p-jpeg: Fix possible NULL pointer dereference in s_fmt 14/31014/1
Jacek Anaszewski [Fri, 28 Nov 2014 13:08:07 +0000 (14:08 +0100)]
s5p-jpeg: Fix possible NULL pointer dereference in s_fmt

Some formats are not supported in encoding or decoding
mode for given type of buffer (e.g. V4L2_PIX_FMT_JPEG
is supported on output buffer only while in decoding
mode). Make S_FMT failing if not suitable format
is found.

Change-Id: I35c94e38b1b11e2c379f4b2e1f61eedab2bc0a9d
Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
9 years agomfd: sec-core: fix build break 13/31013/1
Marek Szyprowski [Fri, 28 Nov 2014 13:28:33 +0000 (14:28 +0100)]
mfd: sec-core: fix build break

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: I5c074dce7e89cbe8ba93872f4edce97431e864cc

9 years agocpufreq: exynos: fix potential initialization error due to signed vs. unsigned comparison 10/31010/1
Marek Szyprowski [Fri, 28 Nov 2014 12:56:08 +0000 (13:56 +0100)]
cpufreq: exynos: fix potential initialization error due to signed vs. unsigned comparison

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: Ia9ce7abb542b7dd82a9bc9b23e94728b57f95e59

9 years agomfd: sec-core: fix potential NULL ptr dereference 09/31009/1
Marek Szyprowski [Fri, 28 Nov 2014 12:50:26 +0000 (13:50 +0100)]
mfd: sec-core: fix potential NULL ptr dereference

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: I26aec009f6b61c077c6de1a96cca7a5132851dbf

9 years agoASoC: samsung: Add NULL check in i2s.c 56/30156/3
Sachin Kamat [Fri, 24 Jan 2014 10:53:22 +0000 (16:23 +0530)]
ASoC: samsung: Add NULL check in i2s.c

'res' could be NULL from one of the operations above (line 1243). Thus
check 'res' for NULL before releasing the region to avoid null pointer
dereference.

Change-Id: Iade84bccdfb1858c55ccf4cc5ef5ece3d51d9e00
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
9 years agoASoC: samsung: dma: Fix the memory resource leakage issue 41/30141/2
Huang Chao [Wed, 12 Nov 2014 03:44:32 +0000 (11:44 +0800)]
ASoC: samsung: dma: Fix the memory resource leakage issue

After we use kzalloc to allocate memory and make chan point
to this block resource, then dma_request_slave_channel will
overwrite the pointer chan, which can result to memory leak
where chan points to.

Change-Id: Ie659df4e1855abc3f57ac3c54e97a6a448dac26e
Signed-off-by: Huang Chao <chao7.huang@samsung.com>
9 years agodma-buf/dmabuf-sync: fix referece dropping 37/30937/2 accepted/tizen/common/20141127.143546 accepted/tizen/mobile/20141201.013959 submit/tizen/20141127.130559
Inki Dae [Thu, 27 Nov 2014 11:09:08 +0000 (20:09 +0900)]
dma-buf/dmabuf-sync: fix referece dropping

Cancel fence free worker if there is no any task or dma device.
And do not drop a reference of dmabuf at fence free worker,
which is over-dropping.

Change-Id: Ib7378d4efc68a8f7ee7a161296f6a9c0e78f77a7
Signed-off-by: Inki Dae <inki.dae@samsung.com>
9 years agoinput: keyboard: mcs_touchkey: use strcpy for assign device name 07/30907/2
Beomho Seo [Thu, 27 Nov 2014 02:36:33 +0000 (11:36 +0900)]
input: keyboard: mcs_touchkey: use strcpy for assign device name

This patch use strcpy() for assign input device name.

Change-Id: I2d363de2b0fe88d771ed71a861f7880a73dc6dac
Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
9 years agoexynos: fimc-is: Support for V4L2 controls 72/30072/2
Beata Michalska [Fri, 25 Jul 2014 14:45:58 +0000 (16:45 +0200)]
exynos: fimc-is: Support for V4L2 controls

Add support for FIMC ISP and SCALERC v4l2 controls

Change-Id: I360597cbaed60a24f3184df3c5617f868fd02749
Signed-off-by: Beata Michalska <b.michalska@samsung.com>
9 years agoexynos: fimc-is: Internal buffer list cleanup 71/30071/2
Beata Michalska [Wed, 23 Jul 2014 13:34:25 +0000 (15:34 +0200)]
exynos: fimc-is: Internal buffer list cleanup

As the driver maintaines separate buffer lists per each
video device which are beyond control of v4l2/vb2
framework, those lists should be properly handled
and cleared once the buffers are no longer
available. The changes introduced allow controlling
state of each queued buffer and removing it from
internal buffer lists when needed.

Signed-off-by: Beata Michalska <b.michalska@samsung.com>
Change-Id: I4dea7df3910d6836edee1387c5a1147649043b81

9 years agoARM: dts: exynos3250-rinato: support for FIMC-IS 70/30070/2
Beata Michalska [Wed, 5 Nov 2014 14:58:31 +0000 (15:58 +0100)]
ARM: dts: exynos3250-rinato: support for FIMC-IS

Signed-off-by: Beata Michalska <b.michalska@samsung.com>
Change-Id: Idf7390055df5c6760986daa59e46d0fc9bb32812

9 years agoexynos3: fimc-is: Add support for FIMC IS on Exynos3250 69/30069/2
Beata Michalska [Mon, 14 Jul 2014 17:32:39 +0000 (19:32 +0200)]
exynos3: fimc-is: Add support for FIMC IS on Exynos3250

The changes introduced provide support for FIMC-IS
subsystem avalilable on Exynos3250.
They cover the differences in both: the hardware itself
as well as the subtle discrepancies between the firmwares
controlling the FIMC IS on both SoCs.
Regarding the above mentioned firmware variations:
the initial driver has been extended with a simplified
interface handling those variations thus living the core
driver independent of the actual firmware version.
Missing code paths have been added to cover handling some of
the most probable failures/errors.

Signed-off-by: Beata Michalska <b.michalska@samsung.com>
Change-Id: Ie07312013a6a0ee14b88803360f0832d0ad4038d

9 years agoexynos5: fimc-is: Code cleanup 68/30068/2
Beata Michalska [Mon, 14 Jul 2014 14:19:04 +0000 (16:19 +0200)]
exynos5: fimc-is: Code cleanup

- Code cleanup for Exynos5/3 media device driver
- Proper locking for vb2 buffers for both FIMC ISP
  and FIMC SCC v4l2 subdevices
- Improved handling VIDIOC_REQBUFS ioctl

Signed-off-by: Beata Michalska <b.michalska@samsung.com>
Change-Id: If7ee3f7861678169c2c0f0fc217d3507b3e3d4fc

9 years agoexynos: fimc-lite: Capture frame end event notification 67/30067/2
Beata Michalska [Mon, 14 Jul 2014 12:47:09 +0000 (14:47 +0200)]
exynos: fimc-lite: Capture frame end event notification

This patch adds notifying v4l2 subdevs upon capture
frame end event.

Signed-off-by: Beata Michalska <b.michalska@samsung.com>
Change-Id: Id3e81b4692a6f2cfc91ffde7050a3ae6db719971

9 years agoexynos: mipi-csis: Fix clock handling for exynos3250 66/30066/2
Beata Michalska [Mon, 14 Jul 2014 12:27:29 +0000 (14:27 +0200)]
exynos: mipi-csis: Fix clock handling for exynos3250

In case of Exynos3250 only gate clock is required
thus all the remaining mipi-csis clocks are considered
as optional.

Signed-off-by: Beata Michalska <b.michalska@samsung.com>
Change-Id: Ibadffe49739add39f156737cbb723b24a5dd4ff5

9 years agoexynos: mipi-csis: Fix handling csis events/errors 65/30065/2
Beata Michalska [Tue, 4 Mar 2014 09:37:09 +0000 (10:37 +0100)]
exynos: mipi-csis: Fix handling csis events/errors

Particular interrupt source mask should specify
each and every possible event/error reflecting the
s5pcsis_events table content.

Change-Id: I3149364cf219d8ec2c13297a8890537585ae77ca
Signed-off-by: Beata Michalska <b.michalska@samsung.com>
9 years agoexynos5: fimc-is: Add driver data entry for S5K68B1 sensor 64/30064/2
Sylwester Nawrocki [Fri, 7 Feb 2014 20:10:39 +0000 (21:10 +0100)]
exynos5: fimc-is: Add driver data entry for S5K68B1 sensor

Change-Id: I7e1c466c6622b39c2999e2245c7815e6517dd157
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
9 years agoexynos5-is: Make sclk_bayer clock handling optional 63/30063/2
Sylwester Nawrocki [Fri, 21 Feb 2014 18:28:36 +0000 (19:28 +0100)]
exynos5-is: Make sclk_bayer clock handling optional

There is no sclk_bayer clock on exynos3250.
Some flag at the variant data could be added later to handle
properly error from clk calls.

Change-Id: I249169e1a7c451db6805dee7d01dd95816f329e0
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
9 years agoexynos5-is: Allow initialization when fimc-is is a master node 62/30062/2
Sylwester Nawrocki [Fri, 21 Feb 2014 18:36:18 +0000 (19:36 +0100)]
exynos5-is: Allow initialization when fimc-is is a master node

Change platform sub-devices registration method so the driver
can support exynos3250 DT binding, i.e. initialize when fimc-is
is the complex root node, not "camera".

This also merges exynos5-fimc-is and exynos-mdevice into single
kernel module called exynos-iss.ko.

Change-Id: Ie340fd7a3e1f7b5dba2c71963c920f324fab4e5a
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
9 years ago[media] Add driver for exynos5 FIMC-IS subsystem 61/30061/2
Arun Kumar K [Tue, 5 Nov 2013 12:13:19 +0000 (17:43 +0530)]
[media] Add driver for exynos5 FIMC-IS subsystem

This driver is for the FIMC-IS IP available in Samsung Exynos5
SoC onwards.

exynos5-fimc-is: Add common driver header files

This patch adds all the common header files used by the fimc-is
driver. It includes the commands for interfacing with the firmware
and error codes from IS firmware, metadata and command parameter
definitions.

exynos5-fimc-is: Add register definition and context header

This patch adds the register definition file for the fimc-is driver
and also the header file containing the main context for the driver.

exynos5-fimc-is: Add isp subdev

fimc-is driver takes video data input from the ISP video node
which is added in this patch. This node accepts Bayer input
buffers which is given from the IS sensors.

exynos5-fimc-is: Add scaler subdev

FIMC-IS has two hardware scalers named as scaler-codec and
scaler-preview. This patch adds the common code handling the
video nodes and subdevs of both the scalers.

exynos5-fimc-is: Add sensor interface

Some sensors to be used with fimc-is are exclusively controlled
by the fimc-is firmware. This minimal sensor driver provides
the required info for the firmware to configure the sensors
sitting on I2C bus.

exynos5-fimc-is: Add the hardware pipeline control

This patch adds the crucial hardware pipeline control for the
fimc-is driver. All the subdev nodes will call this pipeline
interfaces to reach the hardware. Responsibilities of this module
involves configuring and maintaining the hardware pipeline involving
multiple sub-ips like ISP, DRC, Scalers, ODC, 3DNR, FD etc.

exynos5-fimc-is: Add the hardware interface module

The hardware interface module finally sends the commands to the
FIMC-IS firmware and runs the interrupt handler for getting the
responses.

Signed-off-by: Arun Kumar K <arun.kk@samsung.com>
Signed-off-by: Kilyeon Im <kilyeon.im@samsung.com>
Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
exynos5-is: Add Kconfig and Makefile

Adds Kconfig and Makefile for exynos5-is driver files.

[b.michalska@samsung.com: Implementation adjusted
to current version of V4L2 framework:
- updated prototype for stop_streaming v4l2 capture ops
- vb2_queue struct's field tiemstamp_type updated
to timestamp_flags]

Change-Id: I066a86151048b4b5871bd3732773b87219f04fd1
Signed-off-by: Shaik Ameer Basha <shaik.ameer@samsung.com>
Signed-off-by: Arun Kumar K <arun.kk@samsung.com>
Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
9 years ago[media] Add Exynos5 FIMC-IS device tree bindings documentation 60/30060/2
Arun Kumar K [Tue, 5 Nov 2013 12:13:18 +0000 (17:43 +0530)]
[media] Add Exynos5 FIMC-IS device tree bindings documentation

The patch adds the DT binding documentation for Samsung
Exynos5 SoC series imaging subsystem (FIMC-IS).

Change-Id: Iee71e3cce25f2983ee9cf74c5f8648b18af2a1d9
Signed-off-by: Arun Kumar K <arun.kk@samsung.com>
Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
9 years agoexynos5-is: Add media device driver for exynos5 SoCs camera subsystem 59/30059/2
Shaik Ameer Basha [Tue, 5 Nov 2013 11:19:15 +0000 (16:49 +0530)]
exynos5-is: Add media device driver for exynos5 SoCs camera subsystem

This patch adds a top level media device driver for the Exynos5 SoC series
camera subsystem. The driver currently supports processing pipelines
involving following IP blocks:

* MIPI-CSIS
  MIPI CSI-2 bus front-end to the FIMC-LITE, image sensors with MIPI CSI-2
  bus should be linked with FIMC-LITE through this sub-device.

* FIMC-LITE
  Supports capture interface from device (Sensor, MIPI-CSIS) to memory.
  Supports interconnection (through internal data FIFO links) between
  devices like MIPI-CSIS and FIMC-IS.

* FIMC-IS
  Camera ISP with multiple image processing and peripheral devices like
  I2C or SPI bus controllers.

The G-Scaler IP is not yet supported.

The media device creates two kinds of pipelines for connecting the above
mentioned IP blocks.
The pipeline0 contains Sensor, MIPI-CSIS and FIMC-LITE devices and allows
to capture image data from external sensor to memory.
Pipeline1 uses FIMC-IS components for image processing operations on the
captured raw image data and provides scaled YUV image data at its output.

Pipeline0
 +--------+     +-----------+     +-----------+     +--------+
 | Sensor | --> | MIPI-CSIS | --> | FIMC-LITE | --> | Memory |
 +--------+     +-----------+     +-----------+     +--------+

Pipeline1
 +--------+     +---------+     +-----------+     +-----------+
 | Memory | --> |   ISP   | --> |    SCC    | --> |    SCP    |
 +--------+     +---------+     +-----------+     +-----------+

Signed-off-by: Shaik Ameer Basha <shaik.ameer@samsung.com>
Signed-off-by: Arun Kumar K <arun.kk@samsung.com>
[s.nawrocki@samsung.com: improved the commit description,
 removed inclusion of nonexistent <linux/of_i2c.h> header]
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Change-Id: Icccb5c45cebe4b46790a1bdce436c00090924d7a

9 years ago[media] exynos5-is: Add DT binding documentation 58/30058/2
Shaik Ameer Basha [Tue, 5 Nov 2013 11:19:14 +0000 (16:49 +0530)]
[media] exynos5-is: Add DT binding documentation

The patch adds the DT binding doc for exynos5 SoC camera
subsystem.

Change-Id: Iaec580ca240554989f243a618989599195f7b5f5
Signed-off-by: Shaik Ameer Basha <shaik.ameer@samsung.com>
Signed-off-by: Arun Kumar K <arun.kk@samsung.com>
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
9 years agoexynos: mipi-csis: Add suport for Exynos3250 57/30057/2
Beata Michalska [Fri, 21 Feb 2014 15:51:57 +0000 (16:51 +0100)]
exynos: mipi-csis: Add suport for Exynos3250

Adapt current implementation to cover differences
in MIPI CSIS registers layout.

Change-Id: I092394f722c019dbb80ac833dc41256566388e8e
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Beata Michalska <b.michalska@samsung.com>
9 years agoexynos: fimc-lite: Add support for exynos3250 56/30056/2
Beata Michalska [Fri, 7 Nov 2014 17:20:07 +0000 (18:20 +0100)]
exynos: fimc-lite: Add support for exynos3250

Add support for enabling/disabling local output
path along with disabling interrupts upon capture
being stopped.

Change-Id: I8ed2e100138f567dbd10c2eb5083b12110a3c799
Signed-off-by: Beata Michalska <b.michalska@samsung.com>
9 years agoexynos: fimc-lite: Add compatible string for exynos3250 55/30055/2
Sylwester Nawrocki [Mon, 10 Feb 2014 11:12:03 +0000 (12:12 +0100)]
exynos: fimc-lite: Add compatible string for exynos3250

Allow driver initialization on exynos3250. Further changes
of the IP handling will be added in subsequent patches.

Change-Id: Ifb4571b8173c34a8677c6dba6d23ddfcac63bb2b
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
9 years agoV4L: Add driver for Samsung S5K8B1YX image sensor 54/30054/2
Sylwester Nawrocki [Thu, 20 Feb 2014 10:50:31 +0000 (11:50 +0100)]
V4L: Add driver for Samsung S5K8B1YX image sensor

This patch adds a stub driver for Samsung S5K8B2YX raw image sensor.
There is currently no I2C communication done in this driver. It can
be added if required. This driver was tested only with Exynos FIMC-IS
subsystem (camera ISP), which communicates with the sensor over I2C
bus in firmware.

Change-Id: I40ea0b1d6bbb139b85f60941343fd8207f4ece8a
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
9 years agodma-buf/dmabuf-sync: add dmabuf_sync_reference_reservation function 91/30791/2 accepted/tizen/common/20141126.162632 accepted/tizen/mobile/20141126.082557 submit/tizen/20141126.081420
Inki Dae [Tue, 25 Nov 2014 09:01:36 +0000 (18:01 +0900)]
dma-buf/dmabuf-sync: add dmabuf_sync_reference_reservation function

This patch adds dmabuf_sync_reference_reservation function that
can get/drop a reference to all fences added to reservation_object of
a given dmabuf object, and calls it before blocked and after waked up
to avoid null pointer dereference.

Change-Id: I32f31b5a54e233d4a06b9915d26b04cda4e31d01
Signed-off-by: Inki Dae <inki.dae@samsung.com>
9 years agodrm/exynos: add dmabuf sync support for page flip 61/30761/7
Inki Dae [Tue, 25 Nov 2014 06:07:23 +0000 (15:07 +0900)]
drm/exynos: add dmabuf sync support for page flip

This patch adds dmabuf sync support for page flip.

With this patch, a dma buffer shared with cpu or other
dma devices, which buffer is accessed by display or
HDMI controllers, could be synchronized implicitly.

Change-Id: I7bd88b293d4d99b87488c0c1c8b07cb72acfb5e6
Signed-off-by: Inki Dae <inki.dae@samsung.com>
9 years agodma-buf/dmabuf-sync: fix request order check 60/30760/2
Inki Dae [Tue, 25 Nov 2014 05:25:12 +0000 (14:25 +0900)]
dma-buf/dmabuf-sync: fix request order check

This patch fixes infinite loop issue which could be incurred
when same task requested sync before previous sync of
the same task is signaled.

For this, it checks if the context of a given sync object is
same as previous one.

Change-Id: I214a3011de4a8513d9aea5f5d56d85acf3ffae7e
Signed-off-by: Inki Dae <inki.dae@samsung.com>
9 years agocpufreq: stats: fix index of last entity in load_table 49/30749/1
Seung-Woo Kim [Mon, 24 Nov 2014 06:38:01 +0000 (15:38 +0900)]
cpufreq: stats: fix index of last entity in load_table

Array load_table should be pointed with last entity index instead
of maximum count in array.

Change-Id: I097421908cdfc875679d84900f46e907833daca3
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
9 years agodrm/exynos: remove all codes relevant to dmabuf-sync 32/30732/1 accepted/tizen/common/20141124.171414 submit/tizen/20141124.161713
Inki Dae [Mon, 24 Nov 2014 16:12:11 +0000 (01:12 +0900)]
drm/exynos: remove all codes relevant to dmabuf-sync

This patch removes existing codes relevant to dmabuf-sync.
For dmabuf-sync support, new codes will be added later.

Change-Id: I1f794f95941519d8ef791f6fda01ab5f1e32807a
Signed-off-by: Inki Dae <inki.dae@samsung.com>
9 years agopackaging: squash patches from upstream to HEAD-10 accepted/tizen/common/20141124.153414 submit/tizen/20141124.132219
Chanho Park [Mon, 24 Nov 2014 11:34:39 +0000 (20:34 +0900)]
packaging: squash patches from upstream to HEAD-10

This patch make one squashed patches from upstream to HEAD - 10 patches.
This can fix argument list long error on qemu build environment

Change-Id: I17e17a43d0516cdbb5383a1e0e8f479d68719d61
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
9 years agodevfreq: exynos4: Add sentinel into array to fix out-of-bound access 68/30568/3 submit/tizen/20141121.110247 submit/tizen/20141123.134900 submit/tizen_common/20141124.090428
Seung-Woo Kim [Thu, 20 Nov 2014 09:05:49 +0000 (18:05 +0900)]
devfreq: exynos4: Add sentinel into array to fix out-of-bound access

Without sentinel, of_match_node() to array causes out-of-bound
memory access. So this patch adds sentinel into
exynos4_busfreq_match.

Change-Id: Iec2390fd367a22e6388eb97fae21eafc3836e206
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
9 years agoselftests: dma-buf: add selftest for dmabuf-sync
Chanho Park [Mon, 17 Nov 2014 13:22:48 +0000 (22:22 +0900)]
selftests: dma-buf: add selftest for dmabuf-sync

Change-Id: Id5c0cf374ae497dc1c9825109de7dbc5c14ee4dc
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
9 years agodma-buf: add dma-buf-test driver
Chanho Park [Mon, 17 Nov 2014 13:21:37 +0000 (22:21 +0900)]
dma-buf: add dma-buf-test driver

Change-Id: Ia7d3608d3ec033453147c1bb500aca144ee42902
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
9 years agodma-buf: add fcntl system call support
Inki Dae [Thu, 20 Nov 2014 13:30:18 +0000 (22:30 +0900)]
dma-buf: add fcntl system call support

This patch adds lock callback to dmabuf framework. And this callback
will be called by fcntl request.

With this patch, fcntl system call can be used by userspace application
for they can use dmabuf sync mechanism.

Change-Id: Id3631cbc21e84c986e2efe040881e401ade180e8
Signed-off-by: Inki Dae <inki.dae@samsung.com>
9 years agodma-buf/dmabuf-sync: add dmabuf sync framework
Inki Dae [Thu, 20 Nov 2014 13:29:39 +0000 (22:29 +0900)]
dma-buf/dmabuf-sync: add dmabuf sync framework

The DMA Buffer synchronization API provides buffer synchronization
mechanism based on DMA buffer sharing machanism[1], dmafence and
reservation frameworks[2];
i.e., buffer access control to CPU and DMA, and easy-to-use interfaces
for device drivers and user application. And this API can be used
for all dma devices using system memory as dma buffer, especially
for most ARM based SoCs.

For more details, please refer to Documentation/dma-buf-syc.txt

[1] http://lwn.net/Articles/470339/
[2] https://lkml.org/lkml/2014/2/24/824

Change-Id: I3b2084a3c331fc06992fa8d2a4c71378e88b10b5
Signed-off-by: Inki Dae <inki.dae@samsung.com>
9 years agolocal: drm/exynos: fix dmabuf variable name
Chanho Park [Fri, 22 Aug 2014 08:53:34 +0000 (17:53 +0900)]
local: drm/exynos: fix dmabuf variable name

Change-Id: Ie106e49107d687d053259fa35f889374a8cc0924
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
9 years agogpu/drm: fix compile error since backported
Chanho Park [Fri, 22 Aug 2014 08:41:21 +0000 (17:41 +0900)]
gpu/drm: fix compile error since backported

Change-Id: I5c9a62578057b164898c8f7880d0566e813dba65
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
9 years agodrm/vma: add access management helpers
David Herrmann [Sun, 25 Aug 2013 16:28:57 +0000 (18:28 +0200)]
drm/vma: add access management helpers

The VMA offset manager uses a device-global address-space. Hence, any
user can currently map any offset-node they want. They only need to guess
the right offset. If we wanted per open-file offset spaces, we'd either
need VM_NONLINEAR mappings or multiple "struct address_space" trees. As
both doesn't really scale, we implement access management in the VMA
manager itself.

We use an rb-tree to store open-files for each VMA node. On each mmap
call, GEM, TTM or the drivers must check whether the current user is
allowed to map this file.

We add a separate lock for each node as there is no generic lock available
for the caller to protect the node easily.

As we currently don't know whether an object may be used for mmap(), we
have to do access management for all objects. If it turns out to slow down
handle creation/deletion significantly, we can optimize it in several
ways:
 - Most times only a single filp is added per bo so we could use a static
   "struct file *main_filp" which is checked/added/removed first before we
   fall back to the rbtree+drm_vma_offset_file.
   This could be even done lockless with rcu.
 - Let user-space pass a hint whether mmap() should be supported on the
   bo and avoid access-management if not.
 - .. there are probably more ideas once we have benchmarks ..

v2: add drm_vma_node_verify_access() helper

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/mm: add "best_match" flag to drm_mm_insert_node()
David Herrmann [Sat, 27 Jul 2013 11:36:27 +0000 (13:36 +0200)]
drm/mm: add "best_match" flag to drm_mm_insert_node()

Add a "best_match" flag similar to the drm_mm_search_*() helpers so we
can convert TTM to use them in follow up patches. We can also inline the
non-generic helpers and move them into the header to allow compile-time
optimizations.

To make calls to drm_mm_{search,insert}_node() more readable, this
converts the boolean argument to a flagset. There are pending patches that
add additional flags for top-down allocators and more.

v2:
 - use flag parameter instead of boolean "best_match"
 - convert *_search_free() helpers to also use flags argument

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Conflicts:
drivers/gpu/drm/i915/i915_gem.c

Change-Id: I77640db74616de3c9ae874531f71bbd81b89d5fa

9 years agodrm/vma: provide drm_vma_node_unmap() helper
David Herrmann [Wed, 24 Jul 2013 19:10:03 +0000 (21:10 +0200)]
drm/vma: provide drm_vma_node_unmap() helper

Instead of unmapping the nodes in TTM and GEM users manually, we provide
a generic wrapper which does the correct thing for all vma-nodes.

v2: remove bdev->dev_mapping test in ttm_bo_unmap_virtual_unlocked() as
ttm_mem_io_free_vm() does nothing in that case (io_reserved_vm is 0).
v4: Fix docbook comments
v5: use drm_vma_node_size()

Cc: Dave Airlie <airlied@redhat.com>
Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@gmail.com>
Conflicts:
drivers/gpu/drm/ttm/ttm_bo.c

Change-Id: I4be1eeef8e5b4e81b5966449e2bf3691d8270aae

9 years agodrm: add unified vma offset manager
David Herrmann [Wed, 24 Jul 2013 19:06:15 +0000 (21:06 +0200)]
drm: add unified vma offset manager

If we want to map GPU memory into user-space, we need to linearize the
addresses to not confuse mm-core. Currently, GEM and TTM both implement
their own offset-managers to assign a pgoff to each object for user-space
CPU access. GEM uses a hash-table, TTM uses an rbtree.

This patch provides a unified implementation that can be used to replace
both. TTM allows partial mmaps with a given offset, so we cannot use
hashtables as the start address may not be known at mmap time. Hence, we
use the rbtree-implementation of TTM.

We could easily update drm_mm to use an rbtree instead of a linked list
for it's object list and thus drop the rbtree from the vma-manager.
However, this would slow down drm_mm object allocation for all other
use-cases (rbtree insertion) and add another 4-8 bytes to each mm node.
Hence, use the separate tree but allow for later migration.

This is a rewrite of the 2012-proposal by David Airlie <airlied@linux.ie>

v2:
 - fix Docbook integration
 - drop drm_mm_node_linked() and use drm_mm_node_allocated()
 - remove unjustified likely/unlikely usage (but keep for rbtree paths)
 - remove BUG_ON() as drm_mm already does that
 - clarify page-based vs. byte-based addresses
 - use drm_vma_node_reset() for initialization, too
v4:
 - allow external locking via drm_vma_offset_un/lock_lookup()
 - add locked lookup helper drm_vma_offset_lookup_locked()
v5:
 - fix drm_vma_offset_lookup() to correctly validate range-mismatches
   (fix (offset > start + pages))
 - fix drm_vma_offset_exact_lookup() to actually do what it says
 - remove redundant vm_pages member (add drm_vma_node_size() helper)
 - remove unneeded goto
 - fix documentation

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@gmail.com>
Conflicts:
Documentation/DocBook/drm.tmpl
drivers/gpu/drm/Makefile

Change-Id: If3427d06b0f9b24c65268912bb75c1b90fe9ad26

9 years agolocal: fence: use smp_mb__before_atomic_inc
Chanho Park [Fri, 22 Aug 2014 08:31:30 +0000 (17:31 +0900)]
local: fence: use smp_mb__before_atomic_inc

The smp_mb__before_atomic is hard to merge it because there is too many
precedence patches. Thus, just use smp_mb__before_atomic_inc because it always
convert to smb_mb.

Change-Id: Ia31d488eaf218cc4585d9256457855e1a9d6b321
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
9 years agodrm/gem: completely close gem_open vs. gem_close races
Daniel Vetter [Wed, 14 Aug 2013 22:02:45 +0000 (00:02 +0200)]
drm/gem: completely close gem_open vs. gem_close races

The gem flink name holds a reference onto the object itself, and this
self-reference would prevent an flink'ed object from every being
freed. To break that loop we remove the flink name when the last
userspace handle disappears, i.e. when obj->handle_count reaches 0.

Now in gem_open we drop the dev->object_name_lock between the flink
name lookup and actually adding the handle. This means a concurrent
gem_close of the last handle could result in the flink name getting
reaped right inbetween, i.e.

Thread 1 Thread 2
gem_open gem_close

flink -> obj lookup
handle_count drops to 0
remove flink name
create_handle
handle_count++

If someone now flinks this object again, we'll get a new flink name.

We can close this race by removing the lock dropping and making the
entire lookup+handle_create sequence atomic. Unfortunately to still be
able to share the handle_create logic this requires a
handle_create_tail function which drops the lock - we can't hold the
object_name_lock while calling into a driver's ->gem_open callback.

Note that for flink fixing this race isn't really important, since
racing gem_open against gem_close is clearly a userspace bug. And no
matter how the race ends, we won't leak any references.

But with dma-buf where the userspace dma-buf fd itself is refcounted
this is a valid sequence and hence we should fix it. Therefore this
patch here is just a warm-up exercise (and for consistency between
flink buffer sharing and dma-buf buffer sharing with self-imports).

Also note that this extension of the critical section in gem_open
protected by dev->object_name_lock only works because it's now a
mutex: A spinlock would conflict with the potential memory allocation
in idr_preload().

This is exercises by igt/gem_flink_race/flink_name.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/gem: switch dev->object_name_lock to a mutex
Daniel Vetter [Wed, 14 Aug 2013 22:02:44 +0000 (00:02 +0200)]
drm/gem: switch dev->object_name_lock to a mutex

I want to wrap the creation of a dma-buf from a gem object in it,
so that the obj->export_dma_buf cache can be atomically filled in.

Instead of creating a new mutex just for that variable I've figured
I can reuse the existing dev->object_name_lock, especially since
the new semantics will exactly mirror the flink obj->name already
protected by that lock.

v2: idr_preload/idr_preload_end is now an atomic section, so need to
move the mutex locking outside.

[airlied: fix up conflict with patch to make debugfs use lock]

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Conflicts:
drivers/gpu/drm/drm_info.c

Change-Id: Ic4ca630b9c6092c942208ee9a04409d4f6561fc0

9 years agodrm/gem: make drm_gem_object_handle_unreference_unlocked static
Daniel Vetter [Wed, 14 Aug 2013 22:02:39 +0000 (00:02 +0200)]
drm/gem: make drm_gem_object_handle_unreference_unlocked static

No one outside of drm should use this, the official interfaces are
drm_gem_handle_create and drm_gem_handle_delete. The handle refcounting
is purely an implementation detail of gem.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/gem: fix up flink name create race
Daniel Vetter [Wed, 14 Aug 2013 22:02:37 +0000 (00:02 +0200)]
drm/gem: fix up flink name create race

This is the 2nd attempt, I've always been a bit dissatisified with the
tricky nature of the first one:

http://lists.freedesktop.org/archives/dri-devel/2012-July/025451.html

The issue is that the flink ioctl can race with calling gem_close on
the last gem handle. In that case we'll end up with a zero handle
count, but an flink name (and it's corresponding reference). Which
results in a neat space leak.

In my first attempt I've solved this by rechecking the handle count.
But fundamentally the issue is that ->handle_count isn't your usual
refcount - it can be resurrected from 0 among other things.

For those special beasts atomic_t often suggest way more ordering that
it actually guarantees. To prevent being tricked by those hairy
semantics take the easy way out and simply protect the handle with the
existing dev->object_name_lock.

With that change implemented it's dead easy to fix the flink vs. gem
close reace: When we try to create the name we simply have to check
whether there's still officially a gem handle around and if not refuse
to create the flink name. Since the handle count decrement and flink
name destruction is now also protected by that lock the reace is gone
and we can't ever leak the flink reference again.

Outside of the drm core only the exynos driver looks at the handle
count, and tbh I have no idea why (it's just for debug dmesg output
luckily).

I've considered inlining the drm_gem_object_handle_free, but I plan to
add more name-like things (like the exported dma_buf) to this scheme,
so it's clearer to leave the handle freeing in its own function.

This is exercised by the new gem_flink_race i-g-t testcase, which on
my snb leaks gem objects at a rate of roughly 1k objects/s.

v2: Fix up the error path handling in handle_create and make it more
robust by simply calling object_handle_unreference.

v3: Fix up the handle_unreference logic bug - atomic_dec_and_test
retursn 1 for 0. Oops.

v4: Squash in inlining of drm_gem_object_handle_reference as suggested
by Dave Airlie and add a note that we now have a testcase.

Cc: Dave Airlie <airlied@gmail.com>
Cc: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/gem: WARN about unbalanced handle refcounts
Daniel Vetter [Wed, 14 Aug 2013 22:02:36 +0000 (00:02 +0200)]
drm/gem: WARN about unbalanced handle refcounts

Trying to drop a reference we don't have is a pretty serious bug.
Trying to paper over it is an even worse offense.

So scream into dmesg with a big WARN in case that ever happens.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/gem: remove bogus NULL check from drm_gem_object_handle_unreference_unlocked
Daniel Vetter [Wed, 14 Aug 2013 22:02:35 +0000 (00:02 +0200)]
drm/gem: remove bogus NULL check from drm_gem_object_handle_unreference_unlocked

Calling this function with a NULL object is simply a bug, so papering
over a NULL object not a good idea.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/gem: move drm_gem_object_handle_unreference_unlocked into drm_gem.c
Daniel Vetter [Wed, 14 Aug 2013 22:02:34 +0000 (00:02 +0200)]
drm/gem: move drm_gem_object_handle_unreference_unlocked into drm_gem.c

We have three callers of this function now and it's neither
performance critical nor really small. So an inline function feels
like overkill and unecessarily separates the different parts of the
code.

Since all callers of drm_gem_object_handle_free are now in drm_gem.c
we can make that static (and remove the unused EXPORT_SYMBOL). To
avoid a forward declaration move it (and drm_gem_object_free_bug) up a
bit.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/gem: remove drm_gem_object_handle_unreference
Daniel Vetter [Tue, 16 Jul 2013 07:11:56 +0000 (09:11 +0200)]
drm/gem: remove drm_gem_object_handle_unreference

It's unused, everyone is using the _unlocked variant only.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Rob Clark <robdclark@gmail.com>
Signed-off-by: Dave Airlie <airlied@gmail.com>
9 years agodrm/gem: add shmem get/put page helpers
Rob Clark [Wed, 7 Aug 2013 17:41:24 +0000 (13:41 -0400)]
drm/gem: add shmem get/put page helpers

Basically just extracting some code duplicated in gma500, omapdrm, udl,
and upcoming msm driver.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/gem: add drm_gem_create_mmap_offset_size()
Rob Clark [Wed, 7 Aug 2013 17:41:23 +0000 (13:41 -0400)]
drm/gem: add drm_gem_create_mmap_offset_size()

Variant of drm_gem_create_mmap_offset() which doesn't make the
assumption that virtual size and physical size (obj->size) are the same.
This is needed in omapdrm to deal with tiled buffers.  And lets us get
rid of a duplicated and slightly modified version of
drm_gem_create_mmap_offset() in omapdrm.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/gem: create drm_gem_dumb_destroy
Daniel Vetter [Tue, 16 Jul 2013 07:12:04 +0000 (09:12 +0200)]
drm/gem: create drm_gem_dumb_destroy

All the gem based kms drivers really want the same function to
destroy a dumb framebuffer backing storage object.

So give it to them and roll it out in all drivers.

This still leaves the option open for kms drivers which don't use GEM
for backing storage, but it does decently simplify matters for gem
drivers.

Acked-by: Inki Dae <inki.dae@samsung.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Ben Skeggs <skeggsb@gmail.com>
Reviwed-by: Rob Clark <robdclark@gmail.com>
Cc: Alex Deucher <alexdeucher@gmail.com>
Acked-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Conflicts:
drivers/gpu/drm/rcar-du/rcar_du_drv.c

Change-Id: I991aad3f0745732f203a85ff8b5f43e328c045a6

9 years agodrm/gem: fix mmap vma size calculations
David Herrmann [Fri, 26 Jul 2013 10:09:32 +0000 (12:09 +0200)]
drm/gem: fix mmap vma size calculations

The VMA manager is page-size based so drm_vma_node_size() returns the size
in pages. However, drm_gem_mmap_obj() requires the size in bytes. Apply
PAGE_SHIFT so we no longer get EINVAL during mmaps due to too small
buffers.

This bug was introduced in commit:
  0de23977cfeb5b357ec884ba15417ae118ff9e9b
  "drm/gem: convert to new unified vma manager"

Fixes i915 gtt mmap failure reported by Sedat Dilek in:
  Re: linux-next: Tree for Jul 25 [ call-trace: drm | drm-intel related? ]

Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reported-by: Sedat Dilek <sedat.dilek@gmail.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: Dave Airlie <airlied@gmail.com>
9 years agodrm/gem: convert to new unified vma manager
David Herrmann [Wed, 24 Jul 2013 19:07:52 +0000 (21:07 +0200)]
drm/gem: convert to new unified vma manager

Use the new vma manager instead of the old hashtable. Also convert all
drivers to use the new convenience helpers. This drops all the
(map_list.hash.key << PAGE_SHIFT) non-sense.

Locking and access-management is exactly the same as before with an
additional lock inside of the vma-manager, which strictly wouldn't be
needed for gem.

v2:
 - rebase on drm-next
 - init nodes via drm_vma_node_reset() in drm_gem.c
v3:
 - fix tegra
v4:
 - remove duplicate if (drm_vma_node_has_offset()) checks
 - inline now trivial drm_vma_node_offset_addr() calls
v5:
 - skip node-reset on gem-init due to kzalloc()
 - do not allow mapping gem-objects with offsets (backwards compat)
 - remove unneccessary casts

Cc: Inki Dae <inki.dae@samsung.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Acked-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@gmail.com>
9 years agodrm/gem: simplify object initialization
David Herrmann [Thu, 11 Jul 2013 09:56:32 +0000 (11:56 +0200)]
drm/gem: simplify object initialization

drm_gem_object_init() and drm_gem_private_object_init() do exactly the
same (except for shmem alloc) so make the first use the latter to reduce
code duplication.

Also drop the return code from drm_gem_private_object_init(). It seems
unlikely that we will extend it any time soon so no reason to keep it
around. This simplifies code paths in drivers, too.

Last but not least, fix gma500 to call drm_gem_object_release() before
freeing objects that were allocated via drm_gem_private_object_init().
That isn't actually necessary for now, but might be in the future.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Acked-by: Rob Clark <robdclark@gmail.com>
Signed-off-by: Dave Airlie <airlied@gmail.com>
9 years agodrm: make drm_mm_init() return void
David Herrmann [Mon, 1 Jul 2013 18:32:58 +0000 (20:32 +0200)]
drm: make drm_mm_init() return void

There is no reason to return "int" as this function never fails.
Furthermore, several drivers (ast, sis) already depend on this.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/gem: add mutex lock when using drm_gem_mmap_obj
YoungJun Cho [Wed, 26 Jun 2013 23:39:58 +0000 (08:39 +0900)]
drm/gem: add mutex lock when using drm_gem_mmap_obj

The drm_gem_mmap_obj() has to be protected with dev->struct_mutex,
but some caller functions do not. So it adds mutex lock to missing
callers and adds assertion to check whether drm_gem_mmap_obj() is
called with mutex lock or not.

Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Conflicts:
drivers/gpu/drm/drm_gem_cma_helper.c
drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c

Change-Id: Icb683c218b3455f113c073c33166faab5a7fcc4c

9 years agodrm/gem: Split drm_gem_mmap() into object search and object mapping
Laurent Pinchart [Tue, 16 Apr 2013 12:14:52 +0000 (14:14 +0200)]
drm/gem: Split drm_gem_mmap() into object search and object mapping

The drm_gem_mmap() function first finds the GEM object to be mapped
based on the fake mmap offset and then maps the object. Split the object
mapping code into a standalone drm_gem_mmap_obj() function that can be
used to implement dma-buf mmap() operations.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Rob Clark <robdclark@gmail.com>
9 years agodrm/prime: Simplify drm_gem_remove_prime_handles
Daniel Vetter [Wed, 14 Aug 2013 22:02:47 +0000 (00:02 +0200)]
drm/prime: Simplify drm_gem_remove_prime_handles

with the reworking semantics and locking of the obj->dma_buf pointer
this pointer is always set as long as there's still a gem handle
around and a dma_buf associated with this gem object.

Also, the per file-priv lookup-cache for dma-buf importing is also
unified between foreign and native objects.

Hence we don't need to special case the clean any more and can simply
drop the clause which only runs for foreing objects, i.e. with
obj->import_attach set.

Note that with this change (actually with the previous one to always
set up obj->dma_buf even for foreign objects) it is no longer required
to set obj->import_attach when importing a foreing object. So update
comments accordingly, too.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agoseqcount: Add lockdep functionality to seqcount/seqlock structures
John Stultz [Mon, 7 Oct 2013 22:51:59 +0000 (15:51 -0700)]
seqcount: Add lockdep functionality to seqcount/seqlock structures

Currently seqlocks and seqcounts don't support lockdep.

After running across a seqcount related deadlock in the timekeeping
code, I used a less-refined and more focused variant of this patch
to narrow down the cause of the issue.

This is a first-pass attempt to properly enable lockdep functionality
on seqlocks and seqcounts.

Since seqcounts are used in the vdso gettimeofday code, I've provided
non-lockdep accessors for those needs.

I've also handled one case where there were nested seqlock writers
and there may be more edge cases.

Comments and feedback would be appreciated!

Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Link: http://lkml.kernel.org/r/1381186321-4906-3-git-send-email-john.stultz@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
9 years agoseqlock: Add a new locking reader type
Waiman Long [Thu, 12 Sep 2013 14:55:34 +0000 (10:55 -0400)]
seqlock: Add a new locking reader type

The sequence lock (seqlock) was originally designed for the cases where
the readers do not need to block the writers by making the readers retry
the read operation when the data change.

Since then, the use cases have been expanded to include situations where
a thread does not need to change the data (effectively a reader) at all
but have to take the writer lock because it can't tolerate changes to
the protected structure.  Some examples are the d_path() function and
the getcwd() syscall in fs/dcache.c where the functions take the writer
lock on rename_lock even though they don't need to change anything in
the protected data structure at all.  This is inefficient as a reader is
now blocking other sequence number reading readers from moving forward
by pretending to be a writer.

This patch tries to eliminate this inefficiency by introducing a new
type of locking reader to the seqlock locking mechanism.  This new
locking reader will try to take an exclusive lock preventing other
writers and locking readers from going forward.  However, it won't
affect the progress of the other sequence number reading readers as the
sequence number won't be changed.

Signed-off-by: Waiman Long <Waiman.Long@hp.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
9 years agolockdep: Introduce lock_acquire_exclusive()/shared() helper macros
Michel Lespinasse [Mon, 8 Jul 2013 21:23:49 +0000 (14:23 -0700)]
lockdep: Introduce lock_acquire_exclusive()/shared() helper macros

In lockdep.h, the spinlock/mutex/rwsem/rwlock/lock_map acquire macros have
different definitions based on the value of CONFIG_PROVE_LOCKING.  We have
separate ifdefs for each of these definitions, which seems redundant.

Introduce lock_acquire_{exclusive,shared,shared_recursive} helpers which
will have different definitions based on CONFIG_PROVE_LOCKING.  Then all
other helper macros can be defined based on the above ones, which reduces
the amount of ifdefined code.

Signed-off-by: Michel Lespinasse <walken@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/20130708212350.6DD1931C15E@corp2gmr1-1.hot.corp.google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
9 years agoreservation: add suppport for read-only access using rcu
Maarten Lankhorst [Tue, 1 Jul 2014 10:58:00 +0000 (12:58 +0200)]
reservation: add suppport for read-only access using rcu

This adds some extra functions to deal with rcu.

reservation_object_get_fences_rcu() will obtain the list of shared
and exclusive fences without obtaining the ww_mutex.

reservation_object_wait_timeout_rcu() will wait on all fences of the
reservation_object, without obtaining the ww_mutex.

reservation_object_test_signaled_rcu() will test if all fences of the
reservation_object are signaled without using the ww_mutex.

reservation_object_get_excl and reservation_object_get_list require
the reservation object to be held, updating requires
write_seqcount_begin/end. If only the exclusive fence is needed,
rcu_dereference followed by fence_get_rcu can be used, if the shared
fences are needed it's recommended to use the supplied functions.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Acked-by: Sumit Semwal <sumit.semwal@linaro.org>
Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-By: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agoreservation: update api and add some helpers
Maarten Lankhorst [Tue, 1 Jul 2014 10:57:54 +0000 (12:57 +0200)]
reservation: update api and add some helpers

Move the list of shared fences to a struct, and return it in
reservation_object_get_list().
Add reservation_object_get_excl to get the exclusive fence.

Add reservation_object_reserve_shared(), which reserves space
in the reservation_object for 1 more shared fence.

reservation_object_add_shared_fence() and
reservation_object_add_excl_fence() are used to assign a new
fence to a reservation_object pointer, to complete a reservation.

Changes since v1:
- Add reservation_object_get_excl, reorder code a bit.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Acked-by: Sumit Semwal <sumit.semwal@linaro.org>
Acked-by: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agodma-buf: add poll support, v3
Maarten Lankhorst [Tue, 1 Jul 2014 10:57:43 +0000 (12:57 +0200)]
dma-buf: add poll support, v3

Thanks to Fengguang Wu for spotting a missing static cast.

v2:
- Kill unused variable need_shared.
v3:
- Clarify the BUG() in dma_buf_release some more. (Rob Clark)

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Acked-by: Sumit Semwal <sumit.semwal@linaro.org>
Acked-by: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
Conflicts:
drivers/dma-buf/dma-buf.c

Change-Id: I6c0d192dfd53809a16d3564e3863c1d1f0f348c7

9 years agoreservation: add support for fences to enable cross-device synchronisation
Maarten Lankhorst [Tue, 1 Jul 2014 10:57:37 +0000 (12:57 +0200)]
reservation: add support for fences to enable cross-device synchronisation

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Acked-by: Sumit Semwal <sumit.semwal@linaro.org>
Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Rob Clark <robdclark@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agomutex: Move ww_mutex definitions to ww_mutex.h
Maarten Lankhorst [Fri, 5 Jul 2013 07:29:32 +0000 (09:29 +0200)]
mutex: Move ww_mutex definitions to ww_mutex.h

Move the definitions for wound/wait mutexes out to a separate
header, ww_mutex.h. This reduces clutter in mutex.h, and
increases readability.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Rik van Riel <riel@redhat.com>
Acked-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Cc: Dave Airlie <airlied@gmail.com>
Link: http://lkml.kernel.org/r/51D675DC.3000907@canonical.com
[ Tidied up the code a bit. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
9 years agodma-buf: use reservation objects
Maarten Lankhorst [Tue, 1 Jul 2014 10:57:26 +0000 (12:57 +0200)]
dma-buf: use reservation objects

This allows reservation objects to be used in dma-buf. it's required
for implementing polling support on the fences that belong to a dma-buf.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Acked-by: Mauro Carvalho Chehab <m.chehab@samsung.com> #drivers/media/v4l2-core/
Acked-by: Thomas Hellstrom <thellstrom@vmware.com> #drivers/gpu/drm/ttm
Acked-by: Sumit Semwal <sumit.semwal@linaro.org>
Acked-by: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Vincent Stehlé <vincent.stehle@laposte.net> #drivers/gpu/drm/armada/
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
Conflicts:
drivers/gpu/drm/armada/armada_gem.c
drivers/gpu/drm/drm_prime.c
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c
drivers/gpu/drm/i915/i915_gem_dmabuf.c
drivers/gpu/drm/nouveau/nouveau_drm.c
drivers/gpu/drm/nouveau/nouveau_gem.h
drivers/gpu/drm/nouveau/nouveau_prime.c
drivers/gpu/drm/radeon/radeon_drv.c
drivers/gpu/drm/tegra/gem.c
drivers/gpu/drm/ttm/ttm_object.c
drivers/staging/android/ion/ion.c

Change-Id: I44fbb1f41500deaf9067eb5d7e1c6ed758231d69

9 years agodrm/prime: double lock typo
Dan Carpenter [Fri, 23 Aug 2013 20:46:02 +0000 (23:46 +0300)]
drm/prime: double lock typo

There is a typo so deadlocks on error instead of unlocking.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@gmail.com>
9 years agodrm/prime: Always add exported buffers to the handle cache
Daniel Vetter [Wed, 14 Aug 2013 22:02:49 +0000 (00:02 +0200)]
drm/prime: Always add exported buffers to the handle cache

... not only when the dma-buf is freshly created. In contrived
examples someone else could have exported/imported the dma-buf already
and handed us the gem object with a flink name. If such on object gets
reexported as a dma_buf we won't have it in the handle cache already,
which breaks the guarantee that for dma-buf imports we always hand
back an existing handle if there is one.

This is exercised by igt/prime_self_import/with_one_bo_two_files

Now if we extend the locked sections just a notch more we can also
plug th racy buf/handle cache setup in handle_to_fd:

If evil userspace races a concurrent gem close against a prime export
operation we can end up tearing down the gem handle before the dma buf
handle cache is set up. When handle_to_fd gets around to adding the
handle to the cache there will be no one left to clean it up,
effectily leaking the bo (and the dma-buf, since the handle cache
holds a ref on the dma-buf):

Thread A Thread B

handle_to_fd:

lookup gem object from handle
creates new dma_buf

gem_close on the same handle
obj->dma_buf is set, but file priv buf
handle cache has no entry

obj->handle_count drops to 0

drm_prime_add_buf_handle sets up the handle cache

-> We have a dma-buf reference in the handle cache, but since the
handle_count of the gem object already dropped to 0 no on will clean
it up. When closing the drm device fd we'll hit the WARN_ON in
drm_prime_destroy_file_private.

The important change is to extend the critical section of the
filp->prime.lock to cover the gem handle lookup. This serializes with
a concurrent gem handle close.

This leak is exercised by igt/prime_self_import/export-vs-gem_close-race

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/prime: make drm_prime_lookup_buf_handle static
Daniel Vetter [Wed, 14 Aug 2013 22:02:48 +0000 (00:02 +0200)]
drm/prime: make drm_prime_lookup_buf_handle static

... and move it to the top of the function to avoid a forward
declaration.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
9 years agodrm/prime: proper locking+refcounting for obj->dma_buf link
Daniel Vetter [Wed, 14 Aug 2013 22:02:46 +0000 (00:02 +0200)]
drm/prime: proper locking+refcounting for obj->dma_buf link

The export dma-buf cache is semantically similar to an flink name. So
semantically it makes sense to treat it the same and remove the name
(i.e. the dma_buf pointer) and its references when the last gem handle
disappears.

Again we need to be careful, but double so: Not just could someone
race and export with a gem close ioctl (so we need to recheck
obj->handle_count again when assigning the new name), but multiple
exports can also race against each another. This is prevented by
holding the dev->object_name_lock across the entire section which
touches obj->dma_buf.

With the new scheme we also need to reinstate the obj->dma_buf link at
import time (in case the only reference userspace has held in-between
was through the dma-buf fd and not through any native gem handle). For
simplicity we don't check whether it's a native object but
unconditionally set up that link - with the new scheme of removing the
obj->dma_buf reference when the last handle disappears we can do that.

To make it clear that this is not just for exported buffers anymore
als rename it from export_dma_buf to dma_buf.

To make sure that now one can race a fd_to_handle or handle_to_fd with
gem_close we use the same tricks as in flink of extending the
dev->object_name_locking critical section. With this change we finally
have a guaranteed 1:1 relationship (at least for native objects)
between gem objects and dma-bufs, even accounting for races (which can
happen since the dma-buf itself holds a reference while in-flight).

This prevent igt/prime_self_import/export-vs-gem_close-race from
Oopsing the kernel. There is still a leak though since the per-file
priv dma-buf/handle cache handling is racy. That will be fixed in a
later patch.

v2: Remove the bogus dma_buf_put from the export_and_register_object
failure path if we've raced with the handle count dropping to 0.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
Conflicts:
drivers/gpu/drm/drm_gem.c

Change-Id: I915b0e73cedffa0ba358cf00510e19dccfcb4703