aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-02-15 13:48:44 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-15 13:48:44 -0500
commit4ba63072b998cc31515cc6305c25f3b808b50c01 (patch)
tree779863511765c70bfd232f676b885f940ba88722
parente29876723f7cb7728f0d6a674d23f92673e9f112 (diff)
parent5fb31cd839c21130c0b2524ceb9244e98dfe10e3 (diff)
Merge tag 'char-misc-3.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char / misc patches from Greg KH: "Here's the big char/misc driver update for 3.20-rc1. Lots of little things in here, all described in the changelog. Nothing major or unusual, except maybe the binder selinux stuff, which was all acked by the proper selinux people and they thought it best to come through this tree. All of this has been in linux-next with no reported issues for a while" * tag 'char-misc-3.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (90 commits) coresight: fix function etm_writel_cp14() parameter order coresight-etm: remove check for unknown Kconfig macro coresight: fixing CPU hwid lookup in device tree coresight: remove the unnecessary function coresight_is_bit_set() coresight: fix the debug AMBA bus name coresight: remove the extra spaces coresight: fix the link between orphan connection and newly added device coresight: remove the unnecessary replicator property coresight: fix the replicator subtype value pdfdocs: Fix 'make pdfdocs' failure for 'uio-howto.tmpl' mcb: Fix error path of mcb_pci_probe virtio/console: verify device has config space ti-st: clean up data types (fix harmless memory corruption) mei: me: release hw from reset only during the reset flow mei: mask interrupt set bit on clean reset bit extcon: max77693: Constify struct regmap_config extcon: adc-jack: Release IIO channel on driver remove extcon: Remove duplicated include from extcon-class.c Drivers: hv: vmbus: hv_process_timer_expiration() can be static Drivers: hv: vmbus: serialize Offer and Rescind offer ...
-rw-r--r--Documentation/DocBook/uio-howto.tmpl14
-rw-r--r--Documentation/devicetree/bindings/arm/coresight.txt4
-rw-r--r--Documentation/devicetree/bindings/powerpc/fsl/lbc.txt18
-rw-r--r--Documentation/stable_kernel_rules.txt44
-rw-r--r--Documentation/trace/coresight.txt4
-rw-r--r--MAINTAINERS1
-rw-r--r--arch/powerpc/include/asm/fsl_lbc.h3
-rw-r--r--arch/x86/include/uapi/asm/hyperv.h11
-rw-r--r--drivers/android/binder.c26
-rw-r--r--drivers/char/Kconfig9
-rw-r--r--drivers/char/i8k.c316
-rw-r--r--drivers/char/mem.c22
-rw-r--r--drivers/char/virtio_console.c6
-rw-r--r--drivers/coresight/coresight-etb10.c14
-rw-r--r--drivers/coresight/coresight-etm3x.c24
-rw-r--r--drivers/coresight/coresight-funnel.c12
-rw-r--r--drivers/coresight/coresight-priv.h2
-rw-r--r--drivers/coresight/coresight-replicator.c2
-rw-r--r--drivers/coresight/coresight-tmc.c12
-rw-r--r--drivers/coresight/coresight-tpiu.c12
-rw-r--r--drivers/coresight/coresight.c11
-rw-r--r--drivers/coresight/of_coresight.c22
-rw-r--r--drivers/extcon/extcon-adc-jack.c1
-rw-r--r--drivers/extcon/extcon-class.c1
-rw-r--r--drivers/extcon/extcon-max77693.c2
-rw-r--r--drivers/hv/channel.c54
-rw-r--r--drivers/hv/channel_mgmt.c54
-rw-r--r--drivers/hv/connection.c6
-rw-r--r--drivers/hv/hv.c78
-rw-r--r--drivers/hv/hv_balloon.c88
-rw-r--r--drivers/hv/hv_fcopy.c27
-rw-r--r--drivers/hv/hyperv_vmbus.h21
-rw-r--r--drivers/hv/vmbus_drv.c37
-rw-r--r--drivers/mcb/mcb-pci.c18
-rw-r--r--drivers/misc/ad525x_dpot-spi.c4
-rw-r--r--drivers/misc/ad525x_dpot.c7
-rw-r--r--drivers/misc/genwqe/card_base.h1
-rw-r--r--drivers/misc/genwqe/card_sysfs.c1
-rw-r--r--drivers/misc/ioc4.c31
-rw-r--r--drivers/misc/mei/amthif.c14
-rw-r--r--drivers/misc/mei/bus.c69
-rw-r--r--drivers/misc/mei/client.c156
-rw-r--r--drivers/misc/mei/client.h17
-rw-r--r--drivers/misc/mei/debugfs.c32
-rw-r--r--drivers/misc/mei/hbm.c34
-rw-r--r--drivers/misc/mei/hw-me.c5
-rw-r--r--drivers/misc/mei/main.c22
-rw-r--r--drivers/misc/mei/mei_dev.h8
-rw-r--r--drivers/misc/mei/nfc.c2
-rw-r--r--drivers/misc/mei/wd.c1
-rw-r--r--drivers/misc/ti-st/st_core.c24
-rw-r--r--drivers/misc/ti-st/st_kim.c144
-rw-r--r--drivers/misc/ti-st/st_ll.c17
-rw-r--r--drivers/misc/vmw_vmci/vmci_driver.c2
-rw-r--r--drivers/misc/vmw_vmci/vmci_host.c13
-rw-r--r--drivers/pcmcia/Kconfig12
-rw-r--r--drivers/pcmcia/Makefile1
-rw-r--r--drivers/pcmcia/cistpl.c31
-rw-r--r--drivers/pcmcia/cs_internal.h6
-rw-r--r--drivers/pcmcia/ds.c3
-rw-r--r--drivers/pcmcia/rsrc_mgr.c5
-rw-r--r--drivers/pcmcia/rsrc_pci.c173
-rw-r--r--drivers/pnp/pnpbios/core.c3
-rw-r--r--drivers/uio/Kconfig20
-rw-r--r--drivers/uio/Makefile1
-rw-r--r--drivers/uio/uio_fsl_elbc_gpcm.c499
-rw-r--r--drivers/uio/uio_pci_generic.c3
-rw-r--r--drivers/vme/vme.c2
-rw-r--r--include/linux/coresight.h22
-rw-r--r--include/linux/hyperv.h38
-rw-r--r--include/linux/mei_cl_bus.h4
-rw-r--r--include/linux/security.h58
-rw-r--r--include/linux/ti_wilink_st.h13
-rw-r--r--security/capability.c27
-rw-r--r--security/security.c23
-rw-r--r--security/selinux/hooks.c73
-rw-r--r--security/selinux/include/classmap.h2
-rw-r--r--tools/hv/Makefile4
-rw-r--r--tools/hv/hv_fcopy_daemon.c10
-rw-r--r--tools/hv/hv_kvp_daemon.c41
80 files changed, 2127 insertions, 527 deletions
diff --git a/Documentation/DocBook/uio-howto.tmpl b/Documentation/DocBook/uio-howto.tmpl
index 1fdc246e4256..cd0e452dfed5 100644
--- a/Documentation/DocBook/uio-howto.tmpl
+++ b/Documentation/DocBook/uio-howto.tmpl
@@ -719,7 +719,7 @@ framework to set up sysfs files for this region. Simply leave it alone.
719 </para> 719 </para>
720</sect1> 720</sect1>
721 721
722<sect1 id="using uio_dmem_genirq"> 722<sect1 id="using-uio_dmem_genirq">
723<title>Using uio_dmem_genirq for platform devices</title> 723<title>Using uio_dmem_genirq for platform devices</title>
724 <para> 724 <para>
725 In addition to statically allocated memory ranges, they may also be 725 In addition to statically allocated memory ranges, they may also be
@@ -746,16 +746,16 @@ framework to set up sysfs files for this region. Simply leave it alone.
746 following elements: 746 following elements:
747 </para> 747 </para>
748 <itemizedlist> 748 <itemizedlist>
749 <listitem><varname>struct uio_info uioinfo</varname>: The same 749 <listitem><para><varname>struct uio_info uioinfo</varname>: The same
750 structure used as the <varname>uio_pdrv_genirq</varname> platform 750 structure used as the <varname>uio_pdrv_genirq</varname> platform
751 data</listitem> 751 data</para></listitem>
752 <listitem><varname>unsigned int *dynamic_region_sizes</varname>: 752 <listitem><para><varname>unsigned int *dynamic_region_sizes</varname>:
753 Pointer to list of sizes of dynamic memory regions to be mapped into 753 Pointer to list of sizes of dynamic memory regions to be mapped into
754 user space. 754 user space.
755 </listitem> 755 </para></listitem>
756 <listitem><varname>unsigned int num_dynamic_regions</varname>: 756 <listitem><para><varname>unsigned int num_dynamic_regions</varname>:
757 Number of elements in <varname>dynamic_region_sizes</varname> array. 757 Number of elements in <varname>dynamic_region_sizes</varname> array.
758 </listitem> 758 </para></listitem>
759 </itemizedlist> 759 </itemizedlist>
760 <para> 760 <para>
761 The dynamic regions defined in the platform data will be appended to 761 The dynamic regions defined in the platform data will be appended to
diff --git a/Documentation/devicetree/bindings/arm/coresight.txt b/Documentation/devicetree/bindings/arm/coresight.txt
index d790f49066f3..a3089359aaa6 100644
--- a/Documentation/devicetree/bindings/arm/coresight.txt
+++ b/Documentation/devicetree/bindings/arm/coresight.txt
@@ -38,8 +38,6 @@ its hardware characteristcs.
38 AMBA markee): 38 AMBA markee):
39 - "arm,coresight-replicator" 39 - "arm,coresight-replicator"
40 40
41 * id: a unique number that will identify this replicator.
42
43 * port or ports: same as above. 41 * port or ports: same as above.
44 42
45* Optional properties for ETM/PTMs: 43* Optional properties for ETM/PTMs:
@@ -94,8 +92,6 @@ Example:
94 * AMBA bus. As such no need to add "arm,primecell". 92 * AMBA bus. As such no need to add "arm,primecell".
95 */ 93 */
96 compatible = "arm,coresight-replicator"; 94 compatible = "arm,coresight-replicator";
97 /* this will show up in debugfs as "0.replicator" */
98 id = <0>;
99 95
100 ports { 96 ports {
101 #address-cells = <1>; 97 #address-cells = <1>;
diff --git a/Documentation/devicetree/bindings/powerpc/fsl/lbc.txt b/Documentation/devicetree/bindings/powerpc/fsl/lbc.txt
index 3300fec501c5..1c80fcedebb5 100644
--- a/Documentation/devicetree/bindings/powerpc/fsl/lbc.txt
+++ b/Documentation/devicetree/bindings/powerpc/fsl/lbc.txt
@@ -16,20 +16,28 @@ Example:
16 "fsl,pq2-localbus"; 16 "fsl,pq2-localbus";
17 #address-cells = <2>; 17 #address-cells = <2>;
18 #size-cells = <1>; 18 #size-cells = <1>;
19 reg = <f0010100 40>; 19 reg = <0xf0010100 0x40>;
20 20
21 ranges = <0 0 fe000000 02000000 21 ranges = <0x0 0x0 0xfe000000 0x02000000
22 1 0 f4500000 00008000>; 22 0x1 0x0 0xf4500000 0x00008000
23 0x2 0x0 0xfd810000 0x00010000>;
23 24
24 flash@0,0 { 25 flash@0,0 {
25 compatible = "jedec-flash"; 26 compatible = "jedec-flash";
26 reg = <0 0 2000000>; 27 reg = <0x0 0x0 0x2000000>;
27 bank-width = <4>; 28 bank-width = <4>;
28 device-width = <1>; 29 device-width = <1>;
29 }; 30 };
30 31
31 board-control@1,0 { 32 board-control@1,0 {
32 reg = <1 0 20>; 33 reg = <0x1 0x0 0x20>;
33 compatible = "fsl,mpc8272ads-bcsr"; 34 compatible = "fsl,mpc8272ads-bcsr";
34 }; 35 };
36
37 simple-periph@2,0 {
38 compatible = "fsl,elbc-gpcm-uio";
39 reg = <0x2 0x0 0x10000>;
40 elbc-gpcm-br = <0xfd810800>;
41 elbc-gpcm-or = <0xffff09f7>;
42 };
35 }; 43 };
diff --git a/Documentation/stable_kernel_rules.txt b/Documentation/stable_kernel_rules.txt
index aee73e78c7d4..02f8331edb8b 100644
--- a/Documentation/stable_kernel_rules.txt
+++ b/Documentation/stable_kernel_rules.txt
@@ -32,18 +32,42 @@ Procedure for submitting patches to the -stable tree:
32 - If the patch covers files in net/ or drivers/net please follow netdev stable 32 - If the patch covers files in net/ or drivers/net please follow netdev stable
33 submission guidelines as described in 33 submission guidelines as described in
34 Documentation/networking/netdev-FAQ.txt 34 Documentation/networking/netdev-FAQ.txt
35 - Send the patch, after verifying that it follows the above rules, to 35 - Security patches should not be handled (solely) by the -stable review
36 stable@vger.kernel.org. You must note the upstream commit ID in the 36 process but should follow the procedures in Documentation/SecurityBugs.
37 changelog of your submission, as well as the kernel version you wish 37
38 it to be applied to. 38For all other submissions, choose one of the following procedures:
39 - To have the patch automatically included in the stable tree, add the tag 39
40 --- Option 1 ---
41
42 To have the patch automatically included in the stable tree, add the tag
40 Cc: stable@vger.kernel.org 43 Cc: stable@vger.kernel.org
41 in the sign-off area. Once the patch is merged it will be applied to 44 in the sign-off area. Once the patch is merged it will be applied to
42 the stable tree without anything else needing to be done by the author 45 the stable tree without anything else needing to be done by the author
43 or subsystem maintainer. 46 or subsystem maintainer.
44 - If the patch requires other patches as prerequisites which can be 47
45 cherry-picked, then this can be specified in the following format in 48 --- Option 2 ---
46 the sign-off area: 49
50 After the patch has been merged to Linus' tree, send an email to
51 stable@vger.kernel.org containing the subject of the patch, the commit ID,
52 why you think it should be applied, and what kernel version you wish it to
53 be applied to.
54
55 --- Option 3 ---
56
57 Send the patch, after verifying that it follows the above rules, to
58 stable@vger.kernel.org. You must note the upstream commit ID in the
59 changelog of your submission, as well as the kernel version you wish
60 it to be applied to.
61
62Option 1 is probably the easiest and most common. Options 2 and 3 are more
63useful if the patch isn't deemed worthy at the time it is applied to a public
64git tree (for instance, because it deserves more regression testing first).
65Option 3 is especially useful if the patch needs some special handling to apply
66to an older kernel (e.g., if API's have changed in the meantime).
67
68Additionally, some patches submitted via Option 1 may have additional patch
69prerequisites which can be cherry-picked. This can be specified in the following
70format in the sign-off area:
47 71
48 Cc: <stable@vger.kernel.org> # 3.3.x: a1f84a3: sched: Check for idle 72 Cc: <stable@vger.kernel.org> # 3.3.x: a1f84a3: sched: Check for idle
49 Cc: <stable@vger.kernel.org> # 3.3.x: 1b9508f: sched: Rate-limit newidle 73 Cc: <stable@vger.kernel.org> # 3.3.x: 1b9508f: sched: Rate-limit newidle
@@ -57,13 +81,13 @@ Procedure for submitting patches to the -stable tree:
57 git cherry-pick fd21073 81 git cherry-pick fd21073
58 git cherry-pick <this commit> 82 git cherry-pick <this commit>
59 83
84Following the submission:
85
60 - The sender will receive an ACK when the patch has been accepted into the 86 - The sender will receive an ACK when the patch has been accepted into the
61 queue, or a NAK if the patch is rejected. This response might take a few 87 queue, or a NAK if the patch is rejected. This response might take a few
62 days, according to the developer's schedules. 88 days, according to the developer's schedules.
63 - If accepted, the patch will be added to the -stable queue, for review by 89 - If accepted, the patch will be added to the -stable queue, for review by
64 other developers and by the relevant subsystem maintainer. 90 other developers and by the relevant subsystem maintainer.
65 - Security patches should not be sent to this alias, but instead to the
66 documented security@kernel.org address.
67 91
68 92
69Review cycle: 93Review cycle:
diff --git a/Documentation/trace/coresight.txt b/Documentation/trace/coresight.txt
index bba7dbfc49ed..02361552a3ea 100644
--- a/Documentation/trace/coresight.txt
+++ b/Documentation/trace/coresight.txt
@@ -46,7 +46,7 @@ At typical coresight system would look like this:
46 | | . | ! | | . | ! | ! . | | SWD/ 46 | | . | ! | | . | ! | ! . | | SWD/
47 | | . | ! | | . | ! | ! . | | JTAG 47 | | . | ! | | . | ! | ! . | | JTAG
48 *****************************************************************<-| 48 *****************************************************************<-|
49 *************************** AMBA Debug ABP ************************ 49 *************************** AMBA Debug APB ************************
50 ***************************************************************** 50 *****************************************************************
51 | . ! . ! ! . | 51 | . ! . ! ! . |
52 | . * . * * . | 52 | . * . * * . |
@@ -79,7 +79,7 @@ At typical coresight system would look like this:
79 To trace port TPIU= Trace Port Interface Unit 79 To trace port TPIU= Trace Port Interface Unit
80 SWD = Serial Wire Debug 80 SWD = Serial Wire Debug
81 81
82While on target configuration of the components is done via the ABP bus, 82While on target configuration of the components is done via the APB bus,
83all trace data are carried out-of-band on the ATB bus. The CTM provides 83all trace data are carried out-of-band on the ATB bus. The CTM provides
84a way to aggregate and distribute signals between CoreSight components. 84a way to aggregate and distribute signals between CoreSight components.
85 85
diff --git a/MAINTAINERS b/MAINTAINERS
index d854959aa519..71a65389ca4d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3033,6 +3033,7 @@ F: drivers/platform/x86/dell-laptop.c
3033 3033
3034DELL LAPTOP SMM DRIVER 3034DELL LAPTOP SMM DRIVER
3035M: Guenter Roeck <linux@roeck-us.net> 3035M: Guenter Roeck <linux@roeck-us.net>
3036S: Maintained
3036F: drivers/char/i8k.c 3037F: drivers/char/i8k.c
3037F: include/uapi/linux/i8k.h 3038F: include/uapi/linux/i8k.h
3038 3039
diff --git a/arch/powerpc/include/asm/fsl_lbc.h b/arch/powerpc/include/asm/fsl_lbc.h
index 067fb0dca549..c7240a024b96 100644
--- a/arch/powerpc/include/asm/fsl_lbc.h
+++ b/arch/powerpc/include/asm/fsl_lbc.h
@@ -95,6 +95,9 @@ struct fsl_lbc_bank {
95#define OR_FCM_TRLX_SHIFT 2 95#define OR_FCM_TRLX_SHIFT 2
96#define OR_FCM_EHTR 0x00000002 96#define OR_FCM_EHTR 0x00000002
97#define OR_FCM_EHTR_SHIFT 1 97#define OR_FCM_EHTR_SHIFT 1
98
99#define OR_GPCM_AM 0xFFFF8000
100#define OR_GPCM_AM_SHIFT 15
98}; 101};
99 102
100struct fsl_lbc_regs { 103struct fsl_lbc_regs {
diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h
index 462efe746d77..90c458e66e13 100644
--- a/arch/x86/include/uapi/asm/hyperv.h
+++ b/arch/x86/include/uapi/asm/hyperv.h
@@ -187,6 +187,17 @@
187#define HV_X64_MSR_SINT14 0x4000009E 187#define HV_X64_MSR_SINT14 0x4000009E
188#define HV_X64_MSR_SINT15 0x4000009F 188#define HV_X64_MSR_SINT15 0x4000009F
189 189
190/*
191 * Synthetic Timer MSRs. Four timers per vcpu.
192 */
193#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0
194#define HV_X64_MSR_STIMER0_COUNT 0x400000B1
195#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2
196#define HV_X64_MSR_STIMER1_COUNT 0x400000B3
197#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4
198#define HV_X64_MSR_STIMER2_COUNT 0x400000B5
199#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6
200#define HV_X64_MSR_STIMER3_COUNT 0x400000B7
190 201
191#define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001 202#define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001
192#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12 203#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12
diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 8c43521d3f11..33b09b6568a4 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -37,6 +37,7 @@
37#include <linux/vmalloc.h> 37#include <linux/vmalloc.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/pid_namespace.h> 39#include <linux/pid_namespace.h>
40#include <linux/security.h>
40 41
41#ifdef CONFIG_ANDROID_BINDER_IPC_32BIT 42#ifdef CONFIG_ANDROID_BINDER_IPC_32BIT
42#define BINDER_IPC_32BIT 1 43#define BINDER_IPC_32BIT 1
@@ -1400,6 +1401,11 @@ static void binder_transaction(struct binder_proc *proc,
1400 return_error = BR_DEAD_REPLY; 1401 return_error = BR_DEAD_REPLY;
1401 goto err_dead_binder; 1402 goto err_dead_binder;
1402 } 1403 }
1404 if (security_binder_transaction(proc->tsk,
1405 target_proc->tsk) < 0) {
1406 return_error = BR_FAILED_REPLY;
1407 goto err_invalid_target_handle;
1408 }
1403 if (!(tr->flags & TF_ONE_WAY) && thread->transaction_stack) { 1409 if (!(tr->flags & TF_ONE_WAY) && thread->transaction_stack) {
1404 struct binder_transaction *tmp; 1410 struct binder_transaction *tmp;
1405 1411
@@ -1551,6 +1557,11 @@ static void binder_transaction(struct binder_proc *proc,
1551 return_error = BR_FAILED_REPLY; 1557 return_error = BR_FAILED_REPLY;
1552 goto err_binder_get_ref_for_node_failed; 1558 goto err_binder_get_ref_for_node_failed;
1553 } 1559 }
1560 if (security_binder_transfer_binder(proc->tsk,
1561 target_proc->tsk)) {
1562 return_error = BR_FAILED_REPLY;
1563 goto err_binder_get_ref_for_node_failed;
1564 }
1554 ref = binder_get_ref_for_node(target_proc, node); 1565 ref = binder_get_ref_for_node(target_proc, node);
1555 if (ref == NULL) { 1566 if (ref == NULL) {
1556 return_error = BR_FAILED_REPLY; 1567 return_error = BR_FAILED_REPLY;
@@ -1581,6 +1592,11 @@ static void binder_transaction(struct binder_proc *proc,
1581 return_error = BR_FAILED_REPLY; 1592 return_error = BR_FAILED_REPLY;
1582 goto err_binder_get_ref_failed; 1593 goto err_binder_get_ref_failed;
1583 } 1594 }
1595 if (security_binder_transfer_binder(proc->tsk,
1596 target_proc->tsk)) {
1597 return_error = BR_FAILED_REPLY;
1598 goto err_binder_get_ref_failed;
1599 }
1584 if (ref->node->proc == target_proc) { 1600 if (ref->node->proc == target_proc) {
1585 if (fp->type == BINDER_TYPE_HANDLE) 1601 if (fp->type == BINDER_TYPE_HANDLE)
1586 fp->type = BINDER_TYPE_BINDER; 1602 fp->type = BINDER_TYPE_BINDER;
@@ -1638,6 +1654,13 @@ static void binder_transaction(struct binder_proc *proc,
1638 return_error = BR_FAILED_REPLY; 1654 return_error = BR_FAILED_REPLY;
1639 goto err_fget_failed; 1655 goto err_fget_failed;
1640 } 1656 }
1657 if (security_binder_transfer_file(proc->tsk,
1658 target_proc->tsk,
1659 file) < 0) {
1660 fput(file);
1661 return_error = BR_FAILED_REPLY;
1662 goto err_get_unused_fd_failed;
1663 }
1641 target_fd = task_get_unused_fd_flags(target_proc, O_CLOEXEC); 1664 target_fd = task_get_unused_fd_flags(target_proc, O_CLOEXEC);
1642 if (target_fd < 0) { 1665 if (target_fd < 0) {
1643 fput(file); 1666 fput(file);
@@ -2675,6 +2698,9 @@ static int binder_ioctl_set_ctx_mgr(struct file *filp)
2675 ret = -EBUSY; 2698 ret = -EBUSY;
2676 goto out; 2699 goto out;
2677 } 2700 }
2701 ret = security_binder_set_context_mgr(proc->tsk);
2702 if (ret < 0)
2703 goto out;
2678 if (uid_valid(binder_context_mgr_uid)) { 2704 if (uid_valid(binder_context_mgr_uid)) {
2679 if (!uid_eq(binder_context_mgr_uid, curr_euid)) { 2705 if (!uid_eq(binder_context_mgr_uid, curr_euid)) {
2680 pr_err("BINDER_SET_CONTEXT_MGR bad uid %d != %d\n", 2706 pr_err("BINDER_SET_CONTEXT_MGR bad uid %d != %d\n",
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index efefd12a0f7b..a4af8221751e 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -6,6 +6,15 @@ menu "Character devices"
6 6
7source "drivers/tty/Kconfig" 7source "drivers/tty/Kconfig"
8 8
9config DEVMEM
10 bool "/dev/mem virtual device support"
11 default y
12 help
13 Say Y here if you want to support the /dev/mem device.
14 The /dev/mem device is used to access areas of physical
15 memory.
16 When in doubt, say "Y".
17
9config DEVKMEM 18config DEVKMEM
10 bool "/dev/kmem virtual device support" 19 bool "/dev/kmem virtual device support"
11 default y 20 default y
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index e34a019eb930..24cc4ed9a780 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -5,7 +5,8 @@
5 * 5 *
6 * Hwmon integration: 6 * Hwmon integration:
7 * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de> 7 * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de>
8 * Copyright (C) 2013 Guenter Roeck <linux@roeck-us.net> 8 * Copyright (C) 2013, 2014 Guenter Roeck <linux@roeck-us.net>
9 * Copyright (C) 2014 Pali Rohár <pali.rohar@gmail.com>
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify it 11 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the 12 * under the terms of the GNU General Public License as published by the
@@ -20,6 +21,7 @@
20 21
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 23
24#include <linux/delay.h>
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/types.h> 26#include <linux/types.h>
25#include <linux/init.h> 27#include <linux/init.h>
@@ -41,11 +43,15 @@
41#define I8K_SMM_SET_FAN 0x01a3 43#define I8K_SMM_SET_FAN 0x01a3
42#define I8K_SMM_GET_FAN 0x00a3 44#define I8K_SMM_GET_FAN 0x00a3
43#define I8K_SMM_GET_SPEED 0x02a3 45#define I8K_SMM_GET_SPEED 0x02a3
46#define I8K_SMM_GET_FAN_TYPE 0x03a3
47#define I8K_SMM_GET_NOM_SPEED 0x04a3
44#define I8K_SMM_GET_TEMP 0x10a3 48#define I8K_SMM_GET_TEMP 0x10a3
49#define I8K_SMM_GET_TEMP_TYPE 0x11a3
45#define I8K_SMM_GET_DELL_SIG1 0xfea3 50#define I8K_SMM_GET_DELL_SIG1 0xfea3
46#define I8K_SMM_GET_DELL_SIG2 0xffa3 51#define I8K_SMM_GET_DELL_SIG2 0xffa3
47 52
48#define I8K_FAN_MULT 30 53#define I8K_FAN_MULT 30
54#define I8K_FAN_MAX_RPM 30000
49#define I8K_MAX_TEMP 127 55#define I8K_MAX_TEMP 127
50 56
51#define I8K_FN_NONE 0x00 57#define I8K_FN_NONE 0x00
@@ -58,15 +64,13 @@
58#define I8K_POWER_AC 0x05 64#define I8K_POWER_AC 0x05
59#define I8K_POWER_BATTERY 0x01 65#define I8K_POWER_BATTERY 0x01
60 66
61#define I8K_TEMPERATURE_BUG 1
62
63static DEFINE_MUTEX(i8k_mutex); 67static DEFINE_MUTEX(i8k_mutex);
64static char bios_version[4]; 68static char bios_version[4];
65static struct device *i8k_hwmon_dev; 69static struct device *i8k_hwmon_dev;
66static u32 i8k_hwmon_flags; 70static u32 i8k_hwmon_flags;
67static int i8k_fan_mult; 71static uint i8k_fan_mult = I8K_FAN_MULT;
68static int i8k_pwm_mult; 72static uint i8k_pwm_mult;
69static int i8k_fan_max = I8K_FAN_HIGH; 73static uint i8k_fan_max = I8K_FAN_HIGH;
70 74
71#define I8K_HWMON_HAVE_TEMP1 (1 << 0) 75#define I8K_HWMON_HAVE_TEMP1 (1 << 0)
72#define I8K_HWMON_HAVE_TEMP2 (1 << 1) 76#define I8K_HWMON_HAVE_TEMP2 (1 << 1)
@@ -95,13 +99,13 @@ static bool power_status;
95module_param(power_status, bool, 0600); 99module_param(power_status, bool, 0600);
96MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k"); 100MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k");
97 101
98static int fan_mult = I8K_FAN_MULT; 102static uint fan_mult;
99module_param(fan_mult, int, 0); 103module_param(fan_mult, uint, 0);
100MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with"); 104MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
101 105
102static int fan_max = I8K_FAN_HIGH; 106static uint fan_max;
103module_param(fan_max, int, 0); 107module_param(fan_max, uint, 0);
104MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed"); 108MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
105 109
106static int i8k_open_fs(struct inode *inode, struct file *file); 110static int i8k_open_fs(struct inode *inode, struct file *file);
107static long i8k_ioctl(struct file *, unsigned int, unsigned long); 111static long i8k_ioctl(struct file *, unsigned int, unsigned long);
@@ -276,6 +280,28 @@ static int i8k_get_fan_speed(int fan)
276} 280}
277 281
278/* 282/*
283 * Read the fan type.
284 */
285static int i8k_get_fan_type(int fan)
286{
287 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, };
288
289 regs.ebx = fan & 0xff;
290 return i8k_smm(&regs) ? : regs.eax & 0xff;
291}
292
293/*
294 * Read the fan nominal rpm for specific fan speed.
295 */
296static int i8k_get_fan_nominal_speed(int fan, int speed)
297{
298 struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, };
299
300 regs.ebx = (fan & 0xff) | (speed << 8);
301 return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
302}
303
304/*
279 * Set the fan speed (off, low, high). Returns the new fan status. 305 * Set the fan speed (off, low, high). Returns the new fan status.
280 */ 306 */
281static int i8k_set_fan(int fan, int speed) 307static int i8k_set_fan(int fan, int speed)
@@ -288,42 +314,52 @@ static int i8k_set_fan(int fan, int speed)
288 return i8k_smm(&regs) ? : i8k_get_fan_status(fan); 314 return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
289} 315}
290 316
317static int i8k_get_temp_type(int sensor)
318{
319 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
320
321 regs.ebx = sensor & 0xff;
322 return i8k_smm(&regs) ? : regs.eax & 0xff;
323}
324
291/* 325/*
292 * Read the cpu temperature. 326 * Read the cpu temperature.
293 */ 327 */
294static int i8k_get_temp(int sensor) 328static int _i8k_get_temp(int sensor)
295{ 329{
296 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, }; 330 struct smm_regs regs = {
297 int rc; 331 .eax = I8K_SMM_GET_TEMP,
298 int temp; 332 .ebx = sensor & 0xff,
333 };
299 334
300#ifdef I8K_TEMPERATURE_BUG 335 return i8k_smm(&regs) ? : regs.eax & 0xff;
301 static int prev[4] = { I8K_MAX_TEMP+1, I8K_MAX_TEMP+1, I8K_MAX_TEMP+1, I8K_MAX_TEMP+1 }; 336}
302#endif
303 regs.ebx = sensor & 0xff;
304 rc = i8k_smm(&regs);
305 if (rc < 0)
306 return rc;
307 337
308 temp = regs.eax & 0xff; 338static int i8k_get_temp(int sensor)
339{
340 int temp = _i8k_get_temp(sensor);
309 341
310#ifdef I8K_TEMPERATURE_BUG
311 /* 342 /*
312 * Sometimes the temperature sensor returns 0x99, which is out of range. 343 * Sometimes the temperature sensor returns 0x99, which is out of range.
313 * In this case we return (once) the previous cached value. For example: 344 * In this case we retry (once) before returning an error.
314 # 1003655137 00000058 00005a4b 345 # 1003655137 00000058 00005a4b
315 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees 346 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
316 # 1003655139 00000054 00005c52 347 # 1003655139 00000054 00005c52
317 */ 348 */
318 if (temp > I8K_MAX_TEMP) { 349 if (temp == 0x99) {
319 temp = prev[sensor]; 350 msleep(100);
320 prev[sensor] = I8K_MAX_TEMP+1; 351 temp = _i8k_get_temp(sensor);
321 } else {
322 prev[sensor] = temp;
323 } 352 }
353 /*
354 * Return -ENODATA for all invalid temperatures.
355 *
356 * Known instances are the 0x99 value as seen above as well as
357 * 0xc1 (193), which may be returned when trying to read the GPU
358 * temperature if the system supports a GPU and it is currently
359 * turned off.
360 */
324 if (temp > I8K_MAX_TEMP) 361 if (temp > I8K_MAX_TEMP)
325 return -ERANGE; 362 return -ENODATA;
326#endif
327 363
328 return temp; 364 return temp;
329} 365}
@@ -493,6 +529,29 @@ static int i8k_open_fs(struct inode *inode, struct file *file)
493 * Hwmon interface 529 * Hwmon interface
494 */ 530 */
495 531
532static ssize_t i8k_hwmon_show_temp_label(struct device *dev,
533 struct device_attribute *devattr,
534 char *buf)
535{
536 static const char * const labels[] = {
537 "CPU",
538 "GPU",
539 "SODIMM",
540 "Other",
541 "Ambient",
542 "Other",
543 };
544 int index = to_sensor_dev_attr(devattr)->index;
545 int type;
546
547 type = i8k_get_temp_type(index);
548 if (type < 0)
549 return type;
550 if (type >= ARRAY_SIZE(labels))
551 type = ARRAY_SIZE(labels) - 1;
552 return sprintf(buf, "%s\n", labels[type]);
553}
554
496static ssize_t i8k_hwmon_show_temp(struct device *dev, 555static ssize_t i8k_hwmon_show_temp(struct device *dev,
497 struct device_attribute *devattr, 556 struct device_attribute *devattr,
498 char *buf) 557 char *buf)
@@ -501,13 +560,42 @@ static ssize_t i8k_hwmon_show_temp(struct device *dev,
501 int temp; 560 int temp;
502 561
503 temp = i8k_get_temp(index); 562 temp = i8k_get_temp(index);
504 if (temp == -ERANGE)
505 return -EINVAL;
506 if (temp < 0) 563 if (temp < 0)
507 return temp; 564 return temp;
508 return sprintf(buf, "%d\n", temp * 1000); 565 return sprintf(buf, "%d\n", temp * 1000);
509} 566}
510 567
568static ssize_t i8k_hwmon_show_fan_label(struct device *dev,
569 struct device_attribute *devattr,
570 char *buf)
571{
572 static const char * const labels[] = {
573 "Processor Fan",
574 "Motherboard Fan",
575 "Video Fan",
576 "Power Supply Fan",
577 "Chipset Fan",
578 "Other Fan",
579 };
580 int index = to_sensor_dev_attr(devattr)->index;
581 bool dock = false;
582 int type;
583
584 type = i8k_get_fan_type(index);
585 if (type < 0)
586 return type;
587
588 if (type & 0x10) {
589 dock = true;
590 type &= 0x0F;
591 }
592
593 if (type >= ARRAY_SIZE(labels))
594 type = (ARRAY_SIZE(labels) - 1);
595
596 return sprintf(buf, "%s%s\n", (dock ? "Docking " : ""), labels[type]);
597}
598
511static ssize_t i8k_hwmon_show_fan(struct device *dev, 599static ssize_t i8k_hwmon_show_fan(struct device *dev,
512 struct device_attribute *devattr, 600 struct device_attribute *devattr,
513 char *buf) 601 char *buf)
@@ -555,45 +643,66 @@ static ssize_t i8k_hwmon_set_pwm(struct device *dev,
555} 643}
556 644
557static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0); 645static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
646static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
647 0);
558static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1); 648static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
649static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
650 1);
559static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2); 651static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
652static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
653 2);
560static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3); 654static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
561static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL, 655static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
562 I8K_FAN_LEFT); 656 3);
657static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL, 0);
658static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL,
659 0);
563static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm, 660static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
564 i8k_hwmon_set_pwm, I8K_FAN_LEFT); 661 i8k_hwmon_set_pwm, 0);
565static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL, 662static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
566 I8K_FAN_RIGHT); 663 1);
664static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL,
665 1);
567static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm, 666static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
568 i8k_hwmon_set_pwm, I8K_FAN_RIGHT); 667 i8k_hwmon_set_pwm, 1);
569 668
570static struct attribute *i8k_attrs[] = { 669static struct attribute *i8k_attrs[] = {
571 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */ 670 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
572 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 1 */ 671 &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
573 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 2 */ 672 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
574 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 3 */ 673 &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */
575 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 4 */ 674 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */
576 &sensor_dev_attr_pwm1.dev_attr.attr, /* 5 */ 675 &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */
577 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 6 */ 676 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */
578 &sensor_dev_attr_pwm2.dev_attr.attr, /* 7 */ 677 &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */
678 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 8 */
679 &sensor_dev_attr_fan1_label.dev_attr.attr, /* 9 */
680 &sensor_dev_attr_pwm1.dev_attr.attr, /* 10 */
681 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 11 */
682 &sensor_dev_attr_fan2_label.dev_attr.attr, /* 12 */
683 &sensor_dev_attr_pwm2.dev_attr.attr, /* 13 */
579 NULL 684 NULL
580}; 685};
581 686
582static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr, 687static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
583 int index) 688 int index)
584{ 689{
585 if (index == 0 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1)) 690 if (index >= 0 && index <= 1 &&
691 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
586 return 0; 692 return 0;
587 if (index == 1 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2)) 693 if (index >= 2 && index <= 3 &&
694 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
588 return 0; 695 return 0;
589 if (index == 2 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3)) 696 if (index >= 4 && index <= 5 &&
697 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
590 return 0; 698 return 0;
591 if (index == 3 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4)) 699 if (index >= 6 && index <= 7 &&
700 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
592 return 0; 701 return 0;
593 if (index >= 4 && index <= 5 && 702 if (index >= 8 && index <= 10 &&
594 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1)) 703 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
595 return 0; 704 return 0;
596 if (index >= 6 && index <= 7 && 705 if (index >= 11 && index <= 13 &&
597 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2)) 706 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
598 return 0; 707 return 0;
599 708
@@ -612,28 +721,28 @@ static int __init i8k_init_hwmon(void)
612 721
613 i8k_hwmon_flags = 0; 722 i8k_hwmon_flags = 0;
614 723
615 /* CPU temperature attributes, if temperature reading is OK */ 724 /* CPU temperature attributes, if temperature type is OK */
616 err = i8k_get_temp(0); 725 err = i8k_get_temp_type(0);
617 if (err >= 0 || err == -ERANGE) 726 if (err >= 0)
618 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1; 727 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
619 /* check for additional temperature sensors */ 728 /* check for additional temperature sensors */
620 err = i8k_get_temp(1); 729 err = i8k_get_temp_type(1);
621 if (err >= 0 || err == -ERANGE) 730 if (err >= 0)
622 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2; 731 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
623 err = i8k_get_temp(2); 732 err = i8k_get_temp_type(2);
624 if (err >= 0 || err == -ERANGE) 733 if (err >= 0)
625 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3; 734 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
626 err = i8k_get_temp(3); 735 err = i8k_get_temp_type(3);
627 if (err >= 0 || err == -ERANGE) 736 if (err >= 0)
628 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4; 737 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
629 738
630 /* Left fan attributes, if left fan is present */ 739 /* First fan attributes, if fan type is OK */
631 err = i8k_get_fan_status(I8K_FAN_LEFT); 740 err = i8k_get_fan_type(0);
632 if (err >= 0) 741 if (err >= 0)
633 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1; 742 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
634 743
635 /* Right fan attributes, if right fan is present */ 744 /* Second fan attributes, if fan type is OK */
636 err = i8k_get_fan_status(I8K_FAN_RIGHT); 745 err = i8k_get_fan_type(1);
637 if (err >= 0) 746 if (err >= 0)
638 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2; 747 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
639 748
@@ -649,16 +758,15 @@ static int __init i8k_init_hwmon(void)
649} 758}
650 759
651struct i8k_config_data { 760struct i8k_config_data {
652 int fan_mult; 761 uint fan_mult;
653 int fan_max; 762 uint fan_max;
654}; 763};
655 764
656enum i8k_configs { 765enum i8k_configs {
657 DELL_LATITUDE_D520, 766 DELL_LATITUDE_D520,
658 DELL_LATITUDE_E6540,
659 DELL_PRECISION_490, 767 DELL_PRECISION_490,
660 DELL_STUDIO, 768 DELL_STUDIO,
661 DELL_XPS_M140, 769 DELL_XPS,
662}; 770};
663 771
664static const struct i8k_config_data i8k_config_data[] = { 772static const struct i8k_config_data i8k_config_data[] = {
@@ -666,10 +774,6 @@ static const struct i8k_config_data i8k_config_data[] = {
666 .fan_mult = 1, 774 .fan_mult = 1,
667 .fan_max = I8K_FAN_TURBO, 775 .fan_max = I8K_FAN_TURBO,
668 }, 776 },
669 [DELL_LATITUDE_E6540] = {
670 .fan_mult = 1,
671 .fan_max = I8K_FAN_HIGH,
672 },
673 [DELL_PRECISION_490] = { 777 [DELL_PRECISION_490] = {
674 .fan_mult = 1, 778 .fan_mult = 1,
675 .fan_max = I8K_FAN_TURBO, 779 .fan_max = I8K_FAN_TURBO,
@@ -678,7 +782,7 @@ static const struct i8k_config_data i8k_config_data[] = {
678 .fan_mult = 1, 782 .fan_mult = 1,
679 .fan_max = I8K_FAN_HIGH, 783 .fan_max = I8K_FAN_HIGH,
680 }, 784 },
681 [DELL_XPS_M140] = { 785 [DELL_XPS] = {
682 .fan_mult = 1, 786 .fan_mult = 1,
683 .fan_max = I8K_FAN_HIGH, 787 .fan_max = I8K_FAN_HIGH,
684 }, 788 },
@@ -715,22 +819,6 @@ static struct dmi_system_id i8k_dmi_table[] __initdata = {
715 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520], 819 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
716 }, 820 },
717 { 821 {
718 .ident = "Dell Latitude E6440",
719 .matches = {
720 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
721 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
722 },
723 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_E6540],
724 },
725 {
726 .ident = "Dell Latitude E6540",
727 .matches = {
728 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
729 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6540"),
730 },
731 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_E6540],
732 },
733 {
734 .ident = "Dell Latitude 2", 822 .ident = "Dell Latitude 2",
735 .matches = { 823 .matches = {
736 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 824 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
@@ -790,12 +878,20 @@ static struct dmi_system_id i8k_dmi_table[] __initdata = {
790 .driver_data = (void *)&i8k_config_data[DELL_STUDIO], 878 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
791 }, 879 },
792 { 880 {
881 .ident = "Dell XPS 13",
882 .matches = {
883 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
884 DMI_MATCH(DMI_PRODUCT_NAME, "XPS13"),
885 },
886 .driver_data = (void *)&i8k_config_data[DELL_XPS],
887 },
888 {
793 .ident = "Dell XPS M140", 889 .ident = "Dell XPS M140",
794 .matches = { 890 .matches = {
795 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 891 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
796 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"), 892 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
797 }, 893 },
798 .driver_data = (void *)&i8k_config_data[DELL_XPS_M140], 894 .driver_data = (void *)&i8k_config_data[DELL_XPS],
799 }, 895 },
800 { } 896 { }
801}; 897};
@@ -808,6 +904,7 @@ MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
808static int __init i8k_probe(void) 904static int __init i8k_probe(void)
809{ 905{
810 const struct dmi_system_id *id; 906 const struct dmi_system_id *id;
907 int fan, ret;
811 908
812 /* 909 /*
813 * Get DMI information 910 * Get DMI information
@@ -836,19 +933,40 @@ static int __init i8k_probe(void)
836 return -ENODEV; 933 return -ENODEV;
837 } 934 }
838 935
839 i8k_fan_mult = fan_mult; 936 /*
840 i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */ 937 * Set fan multiplier and maximal fan speed from dmi config
938 * Values specified in module parameters override values from dmi
939 */
841 id = dmi_first_match(i8k_dmi_table); 940 id = dmi_first_match(i8k_dmi_table);
842 if (id && id->driver_data) { 941 if (id && id->driver_data) {
843 const struct i8k_config_data *conf = id->driver_data; 942 const struct i8k_config_data *conf = id->driver_data;
844 943 if (!fan_mult && conf->fan_mult)
845 if (fan_mult == I8K_FAN_MULT && conf->fan_mult) 944 fan_mult = conf->fan_mult;
846 i8k_fan_mult = conf->fan_mult; 945 if (!fan_max && conf->fan_max)
847 if (fan_max == I8K_FAN_HIGH && conf->fan_max) 946 fan_max = conf->fan_max;
848 i8k_fan_max = conf->fan_max;
849 } 947 }
948
949 i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
850 i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max); 950 i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max);
851 951
952 if (!fan_mult) {
953 /*
954 * Autodetect fan multiplier based on nominal rpm
955 * If fan reports rpm value too high then set multiplier to 1
956 */
957 for (fan = 0; fan < 2; ++fan) {
958 ret = i8k_get_fan_nominal_speed(fan, i8k_fan_max);
959 if (ret < 0)
960 continue;
961 if (ret > I8K_FAN_MAX_RPM)
962 i8k_fan_mult = 1;
963 break;
964 }
965 } else {
966 /* Fan multiplier was specified in module param or in dmi */
967 i8k_fan_mult = fan_mult;
968 }
969
852 return 0; 970 return 0;
853} 971}
854 972
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 9a6b63783a94..297110c12635 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -28,7 +28,7 @@
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/aio.h> 29#include <linux/aio.h>
30 30
31#include <asm/uaccess.h> 31#include <linux/uaccess.h>
32 32
33#ifdef CONFIG_IA64 33#ifdef CONFIG_IA64
34# include <linux/efi.h> 34# include <linux/efi.h>
@@ -352,7 +352,6 @@ static int mmap_mem(struct file *file, struct vm_area_struct *vma)
352 return 0; 352 return 0;
353} 353}
354 354
355#ifdef CONFIG_DEVKMEM
356static int mmap_kmem(struct file *file, struct vm_area_struct *vma) 355static int mmap_kmem(struct file *file, struct vm_area_struct *vma)
357{ 356{
358 unsigned long pfn; 357 unsigned long pfn;
@@ -373,9 +372,7 @@ static int mmap_kmem(struct file *file, struct vm_area_struct *vma)
373 vma->vm_pgoff = pfn; 372 vma->vm_pgoff = pfn;
374 return mmap_mem(file, vma); 373 return mmap_mem(file, vma);
375} 374}
376#endif
377 375
378#ifdef CONFIG_DEVKMEM
379/* 376/*
380 * This function reads the *virtual* memory as seen by the kernel. 377 * This function reads the *virtual* memory as seen by the kernel.
381 */ 378 */
@@ -555,9 +552,7 @@ static ssize_t write_kmem(struct file *file, const char __user *buf,
555 *ppos = p; 552 *ppos = p;
556 return virtr + wrote ? : err; 553 return virtr + wrote ? : err;
557} 554}
558#endif
559 555
560#ifdef CONFIG_DEVPORT
561static ssize_t read_port(struct file *file, char __user *buf, 556static ssize_t read_port(struct file *file, char __user *buf,
562 size_t count, loff_t *ppos) 557 size_t count, loff_t *ppos)
563{ 558{
@@ -586,6 +581,7 @@ static ssize_t write_port(struct file *file, const char __user *buf,
586 return -EFAULT; 581 return -EFAULT;
587 while (count-- > 0 && i < 65536) { 582 while (count-- > 0 && i < 65536) {
588 char c; 583 char c;
584
589 if (__get_user(c, tmp)) { 585 if (__get_user(c, tmp)) {
590 if (tmp > buf) 586 if (tmp > buf)
591 break; 587 break;
@@ -598,7 +594,6 @@ static ssize_t write_port(struct file *file, const char __user *buf,
598 *ppos = i; 594 *ppos = i;
599 return tmp-buf; 595 return tmp-buf;
600} 596}
601#endif
602 597
603static ssize_t read_null(struct file *file, char __user *buf, 598static ssize_t read_null(struct file *file, char __user *buf,
604 size_t count, loff_t *ppos) 599 size_t count, loff_t *ppos)
@@ -642,6 +637,7 @@ static ssize_t read_iter_zero(struct kiocb *iocb, struct iov_iter *iter)
642 637
643 while (iov_iter_count(iter)) { 638 while (iov_iter_count(iter)) {
644 size_t chunk = iov_iter_count(iter), n; 639 size_t chunk = iov_iter_count(iter), n;
640
645 if (chunk > PAGE_SIZE) 641 if (chunk > PAGE_SIZE)
646 chunk = PAGE_SIZE; /* Just for latency reasons */ 642 chunk = PAGE_SIZE; /* Just for latency reasons */
647 n = iov_iter_zero(chunk, iter); 643 n = iov_iter_zero(chunk, iter);
@@ -726,7 +722,7 @@ static int open_port(struct inode *inode, struct file *filp)
726#define open_mem open_port 722#define open_mem open_port
727#define open_kmem open_mem 723#define open_kmem open_mem
728 724
729static const struct file_operations mem_fops = { 725static const struct file_operations __maybe_unused mem_fops = {
730 .llseek = memory_lseek, 726 .llseek = memory_lseek,
731 .read = read_mem, 727 .read = read_mem,
732 .write = write_mem, 728 .write = write_mem,
@@ -738,8 +734,7 @@ static const struct file_operations mem_fops = {
738#endif 734#endif
739}; 735};
740 736
741#ifdef CONFIG_DEVKMEM 737static const struct file_operations __maybe_unused kmem_fops = {
742static const struct file_operations kmem_fops = {
743 .llseek = memory_lseek, 738 .llseek = memory_lseek,
744 .read = read_kmem, 739 .read = read_kmem,
745 .write = write_kmem, 740 .write = write_kmem,
@@ -750,7 +745,6 @@ static const struct file_operations kmem_fops = {
750 .mmap_capabilities = memory_mmap_capabilities, 745 .mmap_capabilities = memory_mmap_capabilities,
751#endif 746#endif
752}; 747};
753#endif
754 748
755static const struct file_operations null_fops = { 749static const struct file_operations null_fops = {
756 .llseek = null_lseek, 750 .llseek = null_lseek,
@@ -761,14 +755,12 @@ static const struct file_operations null_fops = {
761 .splice_write = splice_write_null, 755 .splice_write = splice_write_null,
762}; 756};
763 757
764#ifdef CONFIG_DEVPORT 758static const struct file_operations __maybe_unused port_fops = {
765static const struct file_operations port_fops = {
766 .llseek = memory_lseek, 759 .llseek = memory_lseek,
767 .read = read_port, 760 .read = read_port,
768 .write = write_port, 761 .write = write_port,
769 .open = open_port, 762 .open = open_port,
770}; 763};
771#endif
772 764
773static const struct file_operations zero_fops = { 765static const struct file_operations zero_fops = {
774 .llseek = zero_lseek, 766 .llseek = zero_lseek,
@@ -795,7 +787,9 @@ static const struct memdev {
795 const struct file_operations *fops; 787 const struct file_operations *fops;
796 fmode_t fmode; 788 fmode_t fmode;
797} devlist[] = { 789} devlist[] = {
790#ifdef CONFIG_DEVMEM
798 [1] = { "mem", 0, &mem_fops, FMODE_UNSIGNED_OFFSET }, 791 [1] = { "mem", 0, &mem_fops, FMODE_UNSIGNED_OFFSET },
792#endif
799#ifdef CONFIG_DEVKMEM 793#ifdef CONFIG_DEVKMEM
800 [2] = { "kmem", 0, &kmem_fops, FMODE_UNSIGNED_OFFSET }, 794 [2] = { "kmem", 0, &kmem_fops, FMODE_UNSIGNED_OFFSET },
801#endif 795#endif
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index de03df9dd7c9..26afb56a8073 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1986,6 +1986,12 @@ static int virtcons_probe(struct virtio_device *vdev)
1986 bool multiport; 1986 bool multiport;
1987 bool early = early_put_chars != NULL; 1987 bool early = early_put_chars != NULL;
1988 1988
1989 if (!vdev->config->get) {
1990 dev_err(&vdev->dev, "%s failure: config access disabled\n",
1991 __func__);
1992 return -EINVAL;
1993 }
1994
1989 /* Ensure to read early_put_chars now */ 1995 /* Ensure to read early_put_chars now */
1990 barrier(); 1996 barrier();
1991 1997
diff --git a/drivers/coresight/coresight-etb10.c b/drivers/coresight/coresight-etb10.c
index c922d4aded8a..c9acd406f0d0 100644
--- a/drivers/coresight/coresight-etb10.c
+++ b/drivers/coresight/coresight-etb10.c
@@ -454,7 +454,7 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id)
454 if (ret) 454 if (ret)
455 return ret; 455 return ret;
456 456
457 drvdata->buffer_depth = etb_get_buffer_depth(drvdata); 457 drvdata->buffer_depth = etb_get_buffer_depth(drvdata);
458 clk_disable_unprepare(drvdata->clk); 458 clk_disable_unprepare(drvdata->clk);
459 459
460 if (drvdata->buffer_depth < 0) 460 if (drvdata->buffer_depth < 0)
@@ -521,17 +521,7 @@ static struct amba_driver etb_driver = {
521 .id_table = etb_ids, 521 .id_table = etb_ids,
522}; 522};
523 523
524static int __init etb_init(void) 524module_amba_driver(etb_driver);
525{
526 return amba_driver_register(&etb_driver);
527}
528module_init(etb_init);
529
530static void __exit etb_exit(void)
531{
532 amba_driver_unregister(&etb_driver);
533}
534module_exit(etb_exit);
535 525
536MODULE_LICENSE("GPL v2"); 526MODULE_LICENSE("GPL v2");
537MODULE_DESCRIPTION("CoreSight Embedded Trace Buffer driver"); 527MODULE_DESCRIPTION("CoreSight Embedded Trace Buffer driver");
diff --git a/drivers/coresight/coresight-etm3x.c b/drivers/coresight/coresight-etm3x.c
index d9e3ed6aa857..c965f5724abd 100644
--- a/drivers/coresight/coresight-etm3x.c
+++ b/drivers/coresight/coresight-etm3x.c
@@ -34,14 +34,8 @@
34 34
35#include "coresight-etm.h" 35#include "coresight-etm.h"
36 36
37#ifdef CONFIG_CORESIGHT_SOURCE_ETM_DEFAULT_ENABLE
38static int boot_enable = 1;
39#else
40static int boot_enable; 37static int boot_enable;
41#endif 38module_param_named(boot_enable, boot_enable, int, S_IRUGO);
42module_param_named(
43 boot_enable, boot_enable, int, S_IRUGO
44);
45 39
46/* The number of ETM/PTM currently registered */ 40/* The number of ETM/PTM currently registered */
47static int etm_count; 41static int etm_count;
@@ -573,7 +567,8 @@ static ssize_t mode_store(struct device *dev,
573 if (drvdata->mode & ETM_MODE_STALL) { 567 if (drvdata->mode & ETM_MODE_STALL) {
574 if (!(drvdata->etmccr & ETMCCR_FIFOFULL)) { 568 if (!(drvdata->etmccr & ETMCCR_FIFOFULL)) {
575 dev_warn(drvdata->dev, "stall mode not supported\n"); 569 dev_warn(drvdata->dev, "stall mode not supported\n");
576 return -EINVAL; 570 ret = -EINVAL;
571 goto err_unlock;
577 } 572 }
578 drvdata->ctrl |= ETMCR_STALL_MODE; 573 drvdata->ctrl |= ETMCR_STALL_MODE;
579 } else 574 } else
@@ -582,7 +577,8 @@ static ssize_t mode_store(struct device *dev,
582 if (drvdata->mode & ETM_MODE_TIMESTAMP) { 577 if (drvdata->mode & ETM_MODE_TIMESTAMP) {
583 if (!(drvdata->etmccer & ETMCCER_TIMESTAMP)) { 578 if (!(drvdata->etmccer & ETMCCER_TIMESTAMP)) {
584 dev_warn(drvdata->dev, "timestamp not supported\n"); 579 dev_warn(drvdata->dev, "timestamp not supported\n");
585 return -EINVAL; 580 ret = -EINVAL;
581 goto err_unlock;
586 } 582 }
587 drvdata->ctrl |= ETMCR_TIMESTAMP_EN; 583 drvdata->ctrl |= ETMCR_TIMESTAMP_EN;
588 } else 584 } else
@@ -595,6 +591,10 @@ static ssize_t mode_store(struct device *dev,
595 spin_unlock(&drvdata->spinlock); 591 spin_unlock(&drvdata->spinlock);
596 592
597 return size; 593 return size;
594
595err_unlock:
596 spin_unlock(&drvdata->spinlock);
597 return ret;
598} 598}
599static DEVICE_ATTR_RW(mode); 599static DEVICE_ATTR_RW(mode);
600 600
@@ -1743,7 +1743,11 @@ static void etm_init_arch_data(void *info)
1743 1743
1744static void etm_init_default_data(struct etm_drvdata *drvdata) 1744static void etm_init_default_data(struct etm_drvdata *drvdata)
1745{ 1745{
1746 static int etm3x_traceid; 1746 /*
1747 * A trace ID of value 0 is invalid, so let's start at some
1748 * random value that fits in 7 bits and will be just as good.
1749 */
1750 static int etm3x_traceid = 0x10;
1747 1751
1748 u32 flags = (1 << 0 | /* instruction execute*/ 1752 u32 flags = (1 << 0 | /* instruction execute*/
1749 3 << 3 | /* ARM instruction */ 1753 3 << 3 | /* ARM instruction */
diff --git a/drivers/coresight/coresight-funnel.c b/drivers/coresight/coresight-funnel.c
index 2108edffe1f4..3db36f70b666 100644
--- a/drivers/coresight/coresight-funnel.c
+++ b/drivers/coresight/coresight-funnel.c
@@ -252,17 +252,7 @@ static struct amba_driver funnel_driver = {
252 .id_table = funnel_ids, 252 .id_table = funnel_ids,
253}; 253};
254 254
255static int __init funnel_init(void) 255module_amba_driver(funnel_driver);
256{
257 return amba_driver_register(&funnel_driver);
258}
259module_init(funnel_init);
260
261static void __exit funnel_exit(void)
262{
263 amba_driver_unregister(&funnel_driver);
264}
265module_exit(funnel_exit);
266 256
267MODULE_LICENSE("GPL v2"); 257MODULE_LICENSE("GPL v2");
268MODULE_DESCRIPTION("CoreSight Funnel driver"); 258MODULE_DESCRIPTION("CoreSight Funnel driver");
diff --git a/drivers/coresight/coresight-priv.h b/drivers/coresight/coresight-priv.h
index 7b3372fca4f6..62fcd98cc7cf 100644
--- a/drivers/coresight/coresight-priv.h
+++ b/drivers/coresight/coresight-priv.h
@@ -57,7 +57,7 @@ extern int etm_readl_cp14(u32 off, unsigned int *val);
57extern int etm_writel_cp14(u32 off, u32 val); 57extern int etm_writel_cp14(u32 off, u32 val);
58#else 58#else
59static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; } 59static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
60static inline int etm_writel_cp14(u32 val, u32 off) { return 0; } 60static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
61#endif 61#endif
62 62
63#endif 63#endif
diff --git a/drivers/coresight/coresight-replicator.c b/drivers/coresight/coresight-replicator.c
index a2dfcf903551..cdf05537d574 100644
--- a/drivers/coresight/coresight-replicator.c
+++ b/drivers/coresight/coresight-replicator.c
@@ -87,7 +87,7 @@ static int replicator_probe(struct platform_device *pdev)
87 return -ENOMEM; 87 return -ENOMEM;
88 88
89 desc->type = CORESIGHT_DEV_TYPE_LINK; 89 desc->type = CORESIGHT_DEV_TYPE_LINK;
90 desc->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT; 90 desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
91 desc->ops = &replicator_cs_ops; 91 desc->ops = &replicator_cs_ops;
92 desc->pdata = pdev->dev.platform_data; 92 desc->pdata = pdev->dev.platform_data;
93 desc->dev = &pdev->dev; 93 desc->dev = &pdev->dev;
diff --git a/drivers/coresight/coresight-tmc.c b/drivers/coresight/coresight-tmc.c
index ce2c293f1707..3ff232f9ddf7 100644
--- a/drivers/coresight/coresight-tmc.c
+++ b/drivers/coresight/coresight-tmc.c
@@ -760,17 +760,7 @@ static struct amba_driver tmc_driver = {
760 .id_table = tmc_ids, 760 .id_table = tmc_ids,
761}; 761};
762 762
763static int __init tmc_init(void) 763module_amba_driver(tmc_driver);
764{
765 return amba_driver_register(&tmc_driver);
766}
767module_init(tmc_init);
768
769static void __exit tmc_exit(void)
770{
771 amba_driver_unregister(&tmc_driver);
772}
773module_exit(tmc_exit);
774 764
775MODULE_LICENSE("GPL v2"); 765MODULE_LICENSE("GPL v2");
776MODULE_DESCRIPTION("CoreSight Trace Memory Controller driver"); 766MODULE_DESCRIPTION("CoreSight Trace Memory Controller driver");
diff --git a/drivers/coresight/coresight-tpiu.c b/drivers/coresight/coresight-tpiu.c
index ae101082791a..3b33af2416bb 100644
--- a/drivers/coresight/coresight-tpiu.c
+++ b/drivers/coresight/coresight-tpiu.c
@@ -201,17 +201,7 @@ static struct amba_driver tpiu_driver = {
201 .id_table = tpiu_ids, 201 .id_table = tpiu_ids,
202}; 202};
203 203
204static int __init tpiu_init(void) 204module_amba_driver(tpiu_driver);
205{
206 return amba_driver_register(&tpiu_driver);
207}
208module_init(tpiu_init);
209
210static void __exit tpiu_exit(void)
211{
212 amba_driver_unregister(&tpiu_driver);
213}
214module_exit(tpiu_exit);
215 205
216MODULE_LICENSE("GPL v2"); 206MODULE_LICENSE("GPL v2");
217MODULE_DESCRIPTION("CoreSight Trace Port Interface Unit driver"); 207MODULE_DESCRIPTION("CoreSight Trace Port Interface Unit driver");
diff --git a/drivers/coresight/coresight.c b/drivers/coresight/coresight.c
index 6e0181f84425..c5def9382357 100644
--- a/drivers/coresight/coresight.c
+++ b/drivers/coresight/coresight.c
@@ -498,17 +498,18 @@ static int coresight_orphan_match(struct device *dev, void *data)
498 * Circle throuch all the connection of that component. If we find 498 * Circle throuch all the connection of that component. If we find
499 * an orphan connection whose name matches @csdev, link it. 499 * an orphan connection whose name matches @csdev, link it.
500 */ 500 */
501 for (i = 0; i < i_csdev->nr_outport; i++) { 501 for (i = 0; i < i_csdev->nr_outport; i++) {
502 conn = &i_csdev->conns[i]; 502 conn = &i_csdev->conns[i];
503 503
504 /* We have found at least one orphan connection */ 504 /* We have found at least one orphan connection */
505 if (conn->child_dev == NULL) { 505 if (conn->child_dev == NULL) {
506 /* Does it match this newly added device? */ 506 /* Does it match this newly added device? */
507 if (!strcmp(dev_name(&csdev->dev), conn->child_name)) 507 if (!strcmp(dev_name(&csdev->dev), conn->child_name)) {
508 conn->child_dev = csdev; 508 conn->child_dev = csdev;
509 } else { 509 } else {
510 /* Too bad, this component still has an orphan */ 510 /* This component still has an orphan */
511 still_orphan = true; 511 still_orphan = true;
512 }
512 } 513 }
513 } 514 }
514 515
diff --git a/drivers/coresight/of_coresight.c b/drivers/coresight/of_coresight.c
index 5030c0734508..c3efa418a86d 100644
--- a/drivers/coresight/of_coresight.c
+++ b/drivers/coresight/of_coresight.c
@@ -93,7 +93,7 @@ static int of_coresight_alloc_memory(struct device *dev,
93 if (!pdata->outports) 93 if (!pdata->outports)
94 return -ENOMEM; 94 return -ENOMEM;
95 95
96 /* Children connected to this component via @outport */ 96 /* Children connected to this component via @outports */
97 pdata->child_names = devm_kzalloc(dev, pdata->nr_outport * 97 pdata->child_names = devm_kzalloc(dev, pdata->nr_outport *
98 sizeof(*pdata->child_names), 98 sizeof(*pdata->child_names),
99 GFP_KERNEL); 99 GFP_KERNEL);
@@ -117,7 +117,7 @@ struct coresight_platform_data *of_get_coresight_platform_data(
117 struct coresight_platform_data *pdata; 117 struct coresight_platform_data *pdata;
118 struct of_endpoint endpoint, rendpoint; 118 struct of_endpoint endpoint, rendpoint;
119 struct device *rdev; 119 struct device *rdev;
120 struct device_node *cpu; 120 struct device_node *dn;
121 struct device_node *ep = NULL; 121 struct device_node *ep = NULL;
122 struct device_node *rparent = NULL; 122 struct device_node *rparent = NULL;
123 struct device_node *rport = NULL; 123 struct device_node *rport = NULL;
@@ -126,7 +126,7 @@ struct coresight_platform_data *of_get_coresight_platform_data(
126 if (!pdata) 126 if (!pdata)
127 return ERR_PTR(-ENOMEM); 127 return ERR_PTR(-ENOMEM);
128 128
129 /* Use device name as debugfs handle */ 129 /* Use device name as sysfs handle */
130 pdata->name = dev_name(dev); 130 pdata->name = dev_name(dev);
131 131
132 /* Get the number of input and output port for this component */ 132 /* Get the number of input and output port for this component */
@@ -174,7 +174,7 @@ struct coresight_platform_data *of_get_coresight_platform_data(
174 continue; 174 continue;
175 175
176 rdev = of_coresight_get_endpoint_device(rparent); 176 rdev = of_coresight_get_endpoint_device(rparent);
177 if (!dev) 177 if (!rdev)
178 continue; 178 continue;
179 179
180 pdata->child_names[i] = dev_name(rdev); 180 pdata->child_names[i] = dev_name(rdev);
@@ -186,14 +186,16 @@ struct coresight_platform_data *of_get_coresight_platform_data(
186 186
187 /* Affinity defaults to CPU0 */ 187 /* Affinity defaults to CPU0 */
188 pdata->cpu = 0; 188 pdata->cpu = 0;
189 cpu = of_parse_phandle(node, "cpu", 0); 189 dn = of_parse_phandle(node, "cpu", 0);
190 if (cpu) { 190 if (dn) {
191 const u32 *mpidr; 191 const u32 *cell;
192 int len, index; 192 int len, index;
193 u64 hwid;
193 194
194 mpidr = of_get_property(cpu, "reg", &len); 195 cell = of_get_property(dn, "reg", &len);
195 if (mpidr && len == 4) { 196 if (cell) {
196 index = get_logical_index(be32_to_cpup(mpidr)); 197 hwid = of_read_number(cell, of_n_addr_cells(dn));
198 index = get_logical_index(hwid);
197 if (index != -EINVAL) 199 if (index != -EINVAL)
198 pdata->cpu = index; 200 pdata->cpu = index;
199 } 201 }
diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c
index 5d7ab577fba9..2bb82e55065a 100644
--- a/drivers/extcon/extcon-adc-jack.c
+++ b/drivers/extcon/extcon-adc-jack.c
@@ -173,6 +173,7 @@ static int adc_jack_remove(struct platform_device *pdev)
173 173
174 free_irq(data->irq, data); 174 free_irq(data->irq, data);
175 cancel_work_sync(&data->handler.work); 175 cancel_work_sync(&data->handler.work);
176 iio_channel_release(data->chan);
176 177
177 return 0; 178 return 0;
178} 179}
diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c
index 043dcd9946c9..8319f25b7145 100644
--- a/drivers/extcon/extcon-class.c
+++ b/drivers/extcon/extcon-class.c
@@ -32,7 +32,6 @@
32#include <linux/of.h> 32#include <linux/of.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/sysfs.h> 34#include <linux/sysfs.h>
35#include <linux/of.h>
36 35
37/* 36/*
38 * extcon_cable_name suggests the standard cable names for commonly used 37 * extcon_cable_name suggests the standard cable names for commonly used
diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
index 740a14d35072..af165fd0c6f5 100644
--- a/drivers/extcon/extcon-max77693.c
+++ b/drivers/extcon/extcon-max77693.c
@@ -1033,7 +1033,7 @@ static irqreturn_t max77693_muic_irq_handler(int irq, void *data)
1033 return IRQ_HANDLED; 1033 return IRQ_HANDLED;
1034} 1034}
1035 1035
1036static struct regmap_config max77693_muic_regmap_config = { 1036static const struct regmap_config max77693_muic_regmap_config = {
1037 .reg_bits = 8, 1037 .reg_bits = 8,
1038 .val_bits = 8, 1038 .val_bits = 8,
1039}; 1039};
diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index 433f72a1c006..2978f5ee8d2a 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -73,14 +73,14 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
73 unsigned long flags; 73 unsigned long flags;
74 int ret, t, err = 0; 74 int ret, t, err = 0;
75 75
76 spin_lock_irqsave(&newchannel->sc_lock, flags); 76 spin_lock_irqsave(&newchannel->lock, flags);
77 if (newchannel->state == CHANNEL_OPEN_STATE) { 77 if (newchannel->state == CHANNEL_OPEN_STATE) {
78 newchannel->state = CHANNEL_OPENING_STATE; 78 newchannel->state = CHANNEL_OPENING_STATE;
79 } else { 79 } else {
80 spin_unlock_irqrestore(&newchannel->sc_lock, flags); 80 spin_unlock_irqrestore(&newchannel->lock, flags);
81 return -EINVAL; 81 return -EINVAL;
82 } 82 }
83 spin_unlock_irqrestore(&newchannel->sc_lock, flags); 83 spin_unlock_irqrestore(&newchannel->lock, flags);
84 84
85 newchannel->onchannel_callback = onchannelcallback; 85 newchannel->onchannel_callback = onchannelcallback;
86 newchannel->channel_callback_context = context; 86 newchannel->channel_callback_context = context;
@@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
366 unsigned long flags; 366 unsigned long flags;
367 int ret = 0; 367 int ret = 0;
368 368
369 next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle); 369 next_gpadl_handle =
370 atomic_inc(&vmbus_connection.next_gpadl_handle); 370 (atomic_inc_return(&vmbus_connection.next_gpadl_handle) - 1);
371 371
372 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount); 372 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
373 if (ret) 373 if (ret)
@@ -686,6 +686,50 @@ EXPORT_SYMBOL_GPL(vmbus_sendpacket_pagebuffer);
686/* 686/*
687 * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet 687 * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet
688 * using a GPADL Direct packet type. 688 * using a GPADL Direct packet type.
689 * The buffer includes the vmbus descriptor.
690 */
691int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel,
692 struct vmbus_packet_mpb_array *desc,
693 u32 desc_size,
694 void *buffer, u32 bufferlen, u64 requestid)
695{
696 int ret;
697 u32 packetlen;
698 u32 packetlen_aligned;
699 struct kvec bufferlist[3];
700 u64 aligned_data = 0;
701 bool signal = false;
702
703 packetlen = desc_size + bufferlen;
704 packetlen_aligned = ALIGN(packetlen, sizeof(u64));
705
706 /* Setup the descriptor */
707 desc->type = VM_PKT_DATA_USING_GPA_DIRECT;
708 desc->flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
709 desc->dataoffset8 = desc_size >> 3; /* in 8-bytes grandularity */
710 desc->length8 = (u16)(packetlen_aligned >> 3);
711 desc->transactionid = requestid;
712 desc->rangecount = 1;
713
714 bufferlist[0].iov_base = desc;
715 bufferlist[0].iov_len = desc_size;
716 bufferlist[1].iov_base = buffer;
717 bufferlist[1].iov_len = bufferlen;
718 bufferlist[2].iov_base = &aligned_data;
719 bufferlist[2].iov_len = (packetlen_aligned - packetlen);
720
721 ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal);
722
723 if (ret == 0 && signal)
724 vmbus_setevent(channel);
725
726 return ret;
727}
728EXPORT_SYMBOL_GPL(vmbus_sendpacket_mpb_desc);
729
730/*
731 * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet
732 * using a GPADL Direct packet type.
689 */ 733 */
690int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, 734int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
691 struct hv_multipage_buffer *multi_pagebuffer, 735 struct hv_multipage_buffer *multi_pagebuffer,
diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 2c59f030546b..3736f71bdec5 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -146,7 +146,7 @@ static struct vmbus_channel *alloc_channel(void)
146 return NULL; 146 return NULL;
147 147
148 spin_lock_init(&channel->inbound_lock); 148 spin_lock_init(&channel->inbound_lock);
149 spin_lock_init(&channel->sc_lock); 149 spin_lock_init(&channel->lock);
150 150
151 INIT_LIST_HEAD(&channel->sc_list); 151 INIT_LIST_HEAD(&channel->sc_list);
152 INIT_LIST_HEAD(&channel->percpu_list); 152 INIT_LIST_HEAD(&channel->percpu_list);
@@ -246,9 +246,9 @@ static void vmbus_process_rescind_offer(struct work_struct *work)
246 spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); 246 spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
247 } else { 247 } else {
248 primary_channel = channel->primary_channel; 248 primary_channel = channel->primary_channel;
249 spin_lock_irqsave(&primary_channel->sc_lock, flags); 249 spin_lock_irqsave(&primary_channel->lock, flags);
250 list_del(&channel->sc_list); 250 list_del(&channel->sc_list);
251 spin_unlock_irqrestore(&primary_channel->sc_lock, flags); 251 spin_unlock_irqrestore(&primary_channel->lock, flags);
252 } 252 }
253 free_channel(channel); 253 free_channel(channel);
254} 254}
@@ -279,9 +279,6 @@ static void vmbus_process_offer(struct work_struct *work)
279 int ret; 279 int ret;
280 unsigned long flags; 280 unsigned long flags;
281 281
282 /* The next possible work is rescind handling */
283 INIT_WORK(&newchannel->work, vmbus_process_rescind_offer);
284
285 /* Make sure this is a new offer */ 282 /* Make sure this is a new offer */
286 spin_lock_irqsave(&vmbus_connection.channel_lock, flags); 283 spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
287 284
@@ -323,9 +320,9 @@ static void vmbus_process_offer(struct work_struct *work)
323 * Process the sub-channel. 320 * Process the sub-channel.
324 */ 321 */
325 newchannel->primary_channel = channel; 322 newchannel->primary_channel = channel;
326 spin_lock_irqsave(&channel->sc_lock, flags); 323 spin_lock_irqsave(&channel->lock, flags);
327 list_add_tail(&newchannel->sc_list, &channel->sc_list); 324 list_add_tail(&newchannel->sc_list, &channel->sc_list);
328 spin_unlock_irqrestore(&channel->sc_lock, flags); 325 spin_unlock_irqrestore(&channel->lock, flags);
329 326
330 if (newchannel->target_cpu != get_cpu()) { 327 if (newchannel->target_cpu != get_cpu()) {
331 put_cpu(); 328 put_cpu();
@@ -341,11 +338,10 @@ static void vmbus_process_offer(struct work_struct *work)
341 if (channel->sc_creation_callback != NULL) 338 if (channel->sc_creation_callback != NULL)
342 channel->sc_creation_callback(newchannel); 339 channel->sc_creation_callback(newchannel);
343 340
344 return; 341 goto done_init_rescind;
345 } 342 }
346 343
347 free_channel(newchannel); 344 goto err_free_chan;
348 return;
349 } 345 }
350 346
351 /* 347 /*
@@ -364,6 +360,8 @@ static void vmbus_process_offer(struct work_struct *work)
364 &newchannel->offermsg.offer.if_type, 360 &newchannel->offermsg.offer.if_type,
365 &newchannel->offermsg.offer.if_instance, 361 &newchannel->offermsg.offer.if_instance,
366 newchannel); 362 newchannel);
363 if (!newchannel->device_obj)
364 goto err_free_chan;
367 365
368 /* 366 /*
369 * Add the new device to the bus. This will kick off device-driver 367 * Add the new device to the bus. This will kick off device-driver
@@ -379,9 +377,19 @@ static void vmbus_process_offer(struct work_struct *work)
379 list_del(&newchannel->listentry); 377 list_del(&newchannel->listentry);
380 spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); 378 spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
381 kfree(newchannel->device_obj); 379 kfree(newchannel->device_obj);
382 380 goto err_free_chan;
383 free_channel(newchannel);
384 } 381 }
382done_init_rescind:
383 spin_lock_irqsave(&newchannel->lock, flags);
384 /* The next possible work is rescind handling */
385 INIT_WORK(&newchannel->work, vmbus_process_rescind_offer);
386 /* Check if rescind offer was already received */
387 if (newchannel->rescind)
388 queue_work(newchannel->controlwq, &newchannel->work);
389 spin_unlock_irqrestore(&newchannel->lock, flags);
390 return;
391err_free_chan:
392 free_channel(newchannel);
385} 393}
386 394
387enum { 395enum {
@@ -516,6 +524,7 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
516{ 524{
517 struct vmbus_channel_rescind_offer *rescind; 525 struct vmbus_channel_rescind_offer *rescind;
518 struct vmbus_channel *channel; 526 struct vmbus_channel *channel;
527 unsigned long flags;
519 528
520 rescind = (struct vmbus_channel_rescind_offer *)hdr; 529 rescind = (struct vmbus_channel_rescind_offer *)hdr;
521 channel = relid2channel(rescind->child_relid); 530 channel = relid2channel(rescind->child_relid);
@@ -524,11 +533,20 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
524 /* Just return here, no channel found */ 533 /* Just return here, no channel found */
525 return; 534 return;
526 535
536 spin_lock_irqsave(&channel->lock, flags);
527 channel->rescind = true; 537 channel->rescind = true;
538 /*
539 * channel->work.func != vmbus_process_rescind_offer means we are still
540 * processing offer request and the rescind offer processing should be
541 * postponed. It will be done at the very end of vmbus_process_offer()
542 * as rescind flag is being checked there.
543 */
544 if (channel->work.func == vmbus_process_rescind_offer)
545 /* work is initialized for vmbus_process_rescind_offer() from
546 * vmbus_process_offer() where the channel got created */
547 queue_work(channel->controlwq, &channel->work);
528 548
529 /* work is initialized for vmbus_process_rescind_offer() from 549 spin_unlock_irqrestore(&channel->lock, flags);
530 * vmbus_process_offer() where the channel got created */
531 queue_work(channel->controlwq, &channel->work);
532} 550}
533 551
534/* 552/*
@@ -815,7 +833,7 @@ cleanup:
815struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary) 833struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary)
816{ 834{
817 struct list_head *cur, *tmp; 835 struct list_head *cur, *tmp;
818 int cur_cpu = hv_context.vp_index[smp_processor_id()]; 836 int cur_cpu;
819 struct vmbus_channel *cur_channel; 837 struct vmbus_channel *cur_channel;
820 struct vmbus_channel *outgoing_channel = primary; 838 struct vmbus_channel *outgoing_channel = primary;
821 int cpu_distance, new_cpu_distance; 839 int cpu_distance, new_cpu_distance;
@@ -823,6 +841,8 @@ struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary)
823 if (list_empty(&primary->sc_list)) 841 if (list_empty(&primary->sc_list))
824 return outgoing_channel; 842 return outgoing_channel;
825 843
844 cur_cpu = hv_context.vp_index[get_cpu()];
845 put_cpu();
826 list_for_each_safe(cur, tmp, &primary->sc_list) { 846 list_for_each_safe(cur, tmp, &primary->sc_list) {
827 cur_channel = list_entry(cur, struct vmbus_channel, sc_list); 847 cur_channel = list_entry(cur, struct vmbus_channel, sc_list);
828 if (cur_channel->state != CHANNEL_OPENED_STATE) 848 if (cur_channel->state != CHANNEL_OPENED_STATE)
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index e206619b946e..a63a795300b9 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -80,8 +80,10 @@ static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo,
80 msg->interrupt_page = virt_to_phys(vmbus_connection.int_page); 80 msg->interrupt_page = virt_to_phys(vmbus_connection.int_page);
81 msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]); 81 msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]);
82 msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]); 82 msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]);
83 if (version == VERSION_WIN8_1) 83 if (version == VERSION_WIN8_1) {
84 msg->target_vcpu = hv_context.vp_index[smp_processor_id()]; 84 msg->target_vcpu = hv_context.vp_index[get_cpu()];
85 put_cpu();
86 }
85 87
86 /* 88 /*
87 * Add to list before we send the request since we may 89 * Add to list before we send the request since we may
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 3e4235c7a47f..50e51a51ff8b 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -28,7 +28,9 @@
28#include <linux/hyperv.h> 28#include <linux/hyperv.h>
29#include <linux/version.h> 29#include <linux/version.h>
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/clockchips.h>
31#include <asm/hyperv.h> 32#include <asm/hyperv.h>
33#include <asm/mshyperv.h>
32#include "hyperv_vmbus.h" 34#include "hyperv_vmbus.h"
33 35
34/* The one and only */ 36/* The one and only */
@@ -37,6 +39,10 @@ struct hv_context hv_context = {
37 .hypercall_page = NULL, 39 .hypercall_page = NULL,
38}; 40};
39 41
42#define HV_TIMER_FREQUENCY (10 * 1000 * 1000) /* 100ns period */
43#define HV_MAX_MAX_DELTA_TICKS 0xffffffff
44#define HV_MIN_DELTA_TICKS 1
45
40/* 46/*
41 * query_hypervisor_info - Get version info of the windows hypervisor 47 * query_hypervisor_info - Get version info of the windows hypervisor
42 */ 48 */
@@ -144,6 +150,8 @@ int hv_init(void)
144 sizeof(int) * NR_CPUS); 150 sizeof(int) * NR_CPUS);
145 memset(hv_context.event_dpc, 0, 151 memset(hv_context.event_dpc, 0,
146 sizeof(void *) * NR_CPUS); 152 sizeof(void *) * NR_CPUS);
153 memset(hv_context.clk_evt, 0,
154 sizeof(void *) * NR_CPUS);
147 155
148 max_leaf = query_hypervisor_info(); 156 max_leaf = query_hypervisor_info();
149 157
@@ -258,10 +266,63 @@ u16 hv_signal_event(void *con_id)
258 return status; 266 return status;
259} 267}
260 268
269static int hv_ce_set_next_event(unsigned long delta,
270 struct clock_event_device *evt)
271{
272 cycle_t current_tick;
273
274 WARN_ON(evt->mode != CLOCK_EVT_MODE_ONESHOT);
275
276 rdmsrl(HV_X64_MSR_TIME_REF_COUNT, current_tick);
277 current_tick += delta;
278 wrmsrl(HV_X64_MSR_STIMER0_COUNT, current_tick);
279 return 0;
280}
281
282static void hv_ce_setmode(enum clock_event_mode mode,
283 struct clock_event_device *evt)
284{
285 union hv_timer_config timer_cfg;
286
287 switch (mode) {
288 case CLOCK_EVT_MODE_PERIODIC:
289 /* unsupported */
290 break;
291
292 case CLOCK_EVT_MODE_ONESHOT:
293 timer_cfg.enable = 1;
294 timer_cfg.auto_enable = 1;
295 timer_cfg.sintx = VMBUS_MESSAGE_SINT;
296 wrmsrl(HV_X64_MSR_STIMER0_CONFIG, timer_cfg.as_uint64);
297 break;
298
299 case CLOCK_EVT_MODE_UNUSED:
300 case CLOCK_EVT_MODE_SHUTDOWN:
301 wrmsrl(HV_X64_MSR_STIMER0_COUNT, 0);
302 wrmsrl(HV_X64_MSR_STIMER0_CONFIG, 0);
303 break;
304 case CLOCK_EVT_MODE_RESUME:
305 break;
306 }
307}
308
309static void hv_init_clockevent_device(struct clock_event_device *dev, int cpu)
310{
311 dev->name = "Hyper-V clockevent";
312 dev->features = CLOCK_EVT_FEAT_ONESHOT;
313 dev->cpumask = cpumask_of(cpu);
314 dev->rating = 1000;
315 dev->owner = THIS_MODULE;
316
317 dev->set_mode = hv_ce_setmode;
318 dev->set_next_event = hv_ce_set_next_event;
319}
320
261 321
262int hv_synic_alloc(void) 322int hv_synic_alloc(void)
263{ 323{
264 size_t size = sizeof(struct tasklet_struct); 324 size_t size = sizeof(struct tasklet_struct);
325 size_t ced_size = sizeof(struct clock_event_device);
265 int cpu; 326 int cpu;
266 327
267 for_each_online_cpu(cpu) { 328 for_each_online_cpu(cpu) {
@@ -272,6 +333,13 @@ int hv_synic_alloc(void)
272 } 333 }
273 tasklet_init(hv_context.event_dpc[cpu], vmbus_on_event, cpu); 334 tasklet_init(hv_context.event_dpc[cpu], vmbus_on_event, cpu);
274 335
336 hv_context.clk_evt[cpu] = kzalloc(ced_size, GFP_ATOMIC);
337 if (hv_context.clk_evt[cpu] == NULL) {
338 pr_err("Unable to allocate clock event device\n");
339 goto err;
340 }
341 hv_init_clockevent_device(hv_context.clk_evt[cpu], cpu);
342
275 hv_context.synic_message_page[cpu] = 343 hv_context.synic_message_page[cpu] =
276 (void *)get_zeroed_page(GFP_ATOMIC); 344 (void *)get_zeroed_page(GFP_ATOMIC);
277 345
@@ -305,6 +373,7 @@ err:
305static void hv_synic_free_cpu(int cpu) 373static void hv_synic_free_cpu(int cpu)
306{ 374{
307 kfree(hv_context.event_dpc[cpu]); 375 kfree(hv_context.event_dpc[cpu]);
376 kfree(hv_context.clk_evt[cpu]);
308 if (hv_context.synic_event_page[cpu]) 377 if (hv_context.synic_event_page[cpu])
309 free_page((unsigned long)hv_context.synic_event_page[cpu]); 378 free_page((unsigned long)hv_context.synic_event_page[cpu]);
310 if (hv_context.synic_message_page[cpu]) 379 if (hv_context.synic_message_page[cpu])
@@ -388,6 +457,15 @@ void hv_synic_init(void *arg)
388 hv_context.vp_index[cpu] = (u32)vp_index; 457 hv_context.vp_index[cpu] = (u32)vp_index;
389 458
390 INIT_LIST_HEAD(&hv_context.percpu_list[cpu]); 459 INIT_LIST_HEAD(&hv_context.percpu_list[cpu]);
460
461 /*
462 * Register the per-cpu clockevent source.
463 */
464 if (ms_hyperv.features & HV_X64_MSR_SYNTIMER_AVAILABLE)
465 clockevents_config_and_register(hv_context.clk_evt[cpu],
466 HV_TIMER_FREQUENCY,
467 HV_MIN_DELTA_TICKS,
468 HV_MAX_MAX_DELTA_TICKS);
391 return; 469 return;
392} 470}
393 471
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index b958ded8ac7e..ff169386b2c7 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -533,6 +533,9 @@ struct hv_dynmem_device {
533 */ 533 */
534 struct task_struct *thread; 534 struct task_struct *thread;
535 535
536 struct mutex ha_region_mutex;
537 struct completion waiter_event;
538
536 /* 539 /*
537 * A list of hot-add regions. 540 * A list of hot-add regions.
538 */ 541 */
@@ -549,7 +552,59 @@ struct hv_dynmem_device {
549static struct hv_dynmem_device dm_device; 552static struct hv_dynmem_device dm_device;
550 553
551static void post_status(struct hv_dynmem_device *dm); 554static void post_status(struct hv_dynmem_device *dm);
555
552#ifdef CONFIG_MEMORY_HOTPLUG 556#ifdef CONFIG_MEMORY_HOTPLUG
557static void acquire_region_mutex(bool trylock)
558{
559 if (trylock) {
560 reinit_completion(&dm_device.waiter_event);
561 while (!mutex_trylock(&dm_device.ha_region_mutex))
562 wait_for_completion(&dm_device.waiter_event);
563 } else {
564 mutex_lock(&dm_device.ha_region_mutex);
565 }
566}
567
568static void release_region_mutex(bool trylock)
569{
570 if (trylock) {
571 mutex_unlock(&dm_device.ha_region_mutex);
572 } else {
573 mutex_unlock(&dm_device.ha_region_mutex);
574 complete(&dm_device.waiter_event);
575 }
576}
577
578static int hv_memory_notifier(struct notifier_block *nb, unsigned long val,
579 void *v)
580{
581 switch (val) {
582 case MEM_GOING_ONLINE:
583 acquire_region_mutex(true);
584 break;
585
586 case MEM_ONLINE:
587 case MEM_CANCEL_ONLINE:
588 release_region_mutex(true);
589 if (dm_device.ha_waiting) {
590 dm_device.ha_waiting = false;
591 complete(&dm_device.ol_waitevent);
592 }
593 break;
594
595 case MEM_GOING_OFFLINE:
596 case MEM_OFFLINE:
597 case MEM_CANCEL_OFFLINE:
598 break;
599 }
600 return NOTIFY_OK;
601}
602
603static struct notifier_block hv_memory_nb = {
604 .notifier_call = hv_memory_notifier,
605 .priority = 0
606};
607
553 608
554static void hv_bring_pgs_online(unsigned long start_pfn, unsigned long size) 609static void hv_bring_pgs_online(unsigned long start_pfn, unsigned long size)
555{ 610{
@@ -591,6 +646,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,
591 init_completion(&dm_device.ol_waitevent); 646 init_completion(&dm_device.ol_waitevent);
592 dm_device.ha_waiting = true; 647 dm_device.ha_waiting = true;
593 648
649 release_region_mutex(false);
594 nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn)); 650 nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn));
595 ret = add_memory(nid, PFN_PHYS((start_pfn)), 651 ret = add_memory(nid, PFN_PHYS((start_pfn)),
596 (HA_CHUNK << PAGE_SHIFT)); 652 (HA_CHUNK << PAGE_SHIFT));
@@ -619,6 +675,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,
619 * have not been "onlined" within the allowed time. 675 * have not been "onlined" within the allowed time.
620 */ 676 */
621 wait_for_completion_timeout(&dm_device.ol_waitevent, 5*HZ); 677 wait_for_completion_timeout(&dm_device.ol_waitevent, 5*HZ);
678 acquire_region_mutex(false);
622 post_status(&dm_device); 679 post_status(&dm_device);
623 } 680 }
624 681
@@ -632,11 +689,6 @@ static void hv_online_page(struct page *pg)
632 unsigned long cur_start_pgp; 689 unsigned long cur_start_pgp;
633 unsigned long cur_end_pgp; 690 unsigned long cur_end_pgp;
634 691
635 if (dm_device.ha_waiting) {
636 dm_device.ha_waiting = false;
637 complete(&dm_device.ol_waitevent);
638 }
639
640 list_for_each(cur, &dm_device.ha_region_list) { 692 list_for_each(cur, &dm_device.ha_region_list) {
641 has = list_entry(cur, struct hv_hotadd_state, list); 693 has = list_entry(cur, struct hv_hotadd_state, list);
642 cur_start_pgp = (unsigned long) 694 cur_start_pgp = (unsigned long)
@@ -834,6 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
834 resp.hdr.size = sizeof(struct dm_hot_add_response); 886 resp.hdr.size = sizeof(struct dm_hot_add_response);
835 887
836#ifdef CONFIG_MEMORY_HOTPLUG 888#ifdef CONFIG_MEMORY_HOTPLUG
889 acquire_region_mutex(false);
837 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page; 890 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
838 pfn_cnt = dm->ha_wrk.ha_page_range.finfo.page_cnt; 891 pfn_cnt = dm->ha_wrk.ha_page_range.finfo.page_cnt;
839 892
@@ -865,6 +918,7 @@ static void hot_add_req(struct work_struct *dummy)
865 if (do_hot_add) 918 if (do_hot_add)
866 resp.page_count = process_hot_add(pg_start, pfn_cnt, 919 resp.page_count = process_hot_add(pg_start, pfn_cnt,
867 rg_start, rg_sz); 920 rg_start, rg_sz);
921 release_region_mutex(false);
868#endif 922#endif
869 /* 923 /*
870 * The result field of the response structure has the 924 * The result field of the response structure has the
@@ -928,9 +982,8 @@ static unsigned long compute_balloon_floor(void)
928 * 128 72 (1/2) 982 * 128 72 (1/2)
929 * 512 168 (1/4) 983 * 512 168 (1/4)
930 * 2048 360 (1/8) 984 * 2048 360 (1/8)
931 * 8192 552 (1/32) 985 * 8192 768 (1/16)
932 * 32768 1320 986 * 32768 1536 (1/32)
933 * 131072 4392
934 */ 987 */
935 if (totalram_pages < MB2PAGES(128)) 988 if (totalram_pages < MB2PAGES(128))
936 min_pages = MB2PAGES(8) + (totalram_pages >> 1); 989 min_pages = MB2PAGES(8) + (totalram_pages >> 1);
@@ -938,8 +991,10 @@ static unsigned long compute_balloon_floor(void)
938 min_pages = MB2PAGES(40) + (totalram_pages >> 2); 991 min_pages = MB2PAGES(40) + (totalram_pages >> 2);
939 else if (totalram_pages < MB2PAGES(2048)) 992 else if (totalram_pages < MB2PAGES(2048))
940 min_pages = MB2PAGES(104) + (totalram_pages >> 3); 993 min_pages = MB2PAGES(104) + (totalram_pages >> 3);
994 else if (totalram_pages < MB2PAGES(8192))
995 min_pages = MB2PAGES(256) + (totalram_pages >> 4);
941 else 996 else
942 min_pages = MB2PAGES(296) + (totalram_pages >> 5); 997 min_pages = MB2PAGES(512) + (totalram_pages >> 5);
943#undef MB2PAGES 998#undef MB2PAGES
944 return min_pages; 999 return min_pages;
945} 1000}
@@ -1171,7 +1226,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
1171 1226
1172 for (i = 0; i < range_count; i++) { 1227 for (i = 0; i < range_count; i++) {
1173 free_balloon_pages(dm, &range_array[i]); 1228 free_balloon_pages(dm, &range_array[i]);
1174 post_status(&dm_device); 1229 complete(&dm_device.config_event);
1175 } 1230 }
1176 1231
1177 if (req->more_pages == 1) 1232 if (req->more_pages == 1)
@@ -1195,19 +1250,16 @@ static void balloon_onchannelcallback(void *context);
1195static int dm_thread_func(void *dm_dev) 1250static int dm_thread_func(void *dm_dev)
1196{ 1251{
1197 struct hv_dynmem_device *dm = dm_dev; 1252 struct hv_dynmem_device *dm = dm_dev;
1198 int t;
1199 1253
1200 while (!kthread_should_stop()) { 1254 while (!kthread_should_stop()) {
1201 t = wait_for_completion_interruptible_timeout( 1255 wait_for_completion_interruptible_timeout(
1202 &dm_device.config_event, 1*HZ); 1256 &dm_device.config_event, 1*HZ);
1203 /* 1257 /*
1204 * The host expects us to post information on the memory 1258 * The host expects us to post information on the memory
1205 * pressure every second. 1259 * pressure every second.
1206 */ 1260 */
1207 1261 reinit_completion(&dm_device.config_event);
1208 if (t == 0) 1262 post_status(dm);
1209 post_status(dm);
1210
1211 } 1263 }
1212 1264
1213 return 0; 1265 return 0;
@@ -1387,7 +1439,9 @@ static int balloon_probe(struct hv_device *dev,
1387 dm_device.next_version = DYNMEM_PROTOCOL_VERSION_WIN7; 1439 dm_device.next_version = DYNMEM_PROTOCOL_VERSION_WIN7;
1388 init_completion(&dm_device.host_event); 1440 init_completion(&dm_device.host_event);
1389 init_completion(&dm_device.config_event); 1441 init_completion(&dm_device.config_event);
1442 init_completion(&dm_device.waiter_event);
1390 INIT_LIST_HEAD(&dm_device.ha_region_list); 1443 INIT_LIST_HEAD(&dm_device.ha_region_list);
1444 mutex_init(&dm_device.ha_region_mutex);
1391 INIT_WORK(&dm_device.balloon_wrk.wrk, balloon_up); 1445 INIT_WORK(&dm_device.balloon_wrk.wrk, balloon_up);
1392 INIT_WORK(&dm_device.ha_wrk.wrk, hot_add_req); 1446 INIT_WORK(&dm_device.ha_wrk.wrk, hot_add_req);
1393 dm_device.host_specified_ha_region = false; 1447 dm_device.host_specified_ha_region = false;
@@ -1401,6 +1455,7 @@ static int balloon_probe(struct hv_device *dev,
1401 1455
1402#ifdef CONFIG_MEMORY_HOTPLUG 1456#ifdef CONFIG_MEMORY_HOTPLUG
1403 set_online_page_callback(&hv_online_page); 1457 set_online_page_callback(&hv_online_page);
1458 register_memory_notifier(&hv_memory_nb);
1404#endif 1459#endif
1405 1460
1406 hv_set_drvdata(dev, &dm_device); 1461 hv_set_drvdata(dev, &dm_device);
@@ -1519,6 +1574,7 @@ static int balloon_remove(struct hv_device *dev)
1519 kfree(send_buffer); 1574 kfree(send_buffer);
1520#ifdef CONFIG_MEMORY_HOTPLUG 1575#ifdef CONFIG_MEMORY_HOTPLUG
1521 restore_online_page_callback(&hv_online_page); 1576 restore_online_page_callback(&hv_online_page);
1577 unregister_memory_notifier(&hv_memory_nb);
1522#endif 1578#endif
1523 list_for_each_safe(cur, tmp, &dm->ha_region_list) { 1579 list_for_each_safe(cur, tmp, &dm->ha_region_list) {
1524 has = list_entry(cur, struct hv_hotadd_state, list); 1580 has = list_entry(cur, struct hv_hotadd_state, list);
diff --git a/drivers/hv/hv_fcopy.c b/drivers/hv/hv_fcopy.c
index 23b2ce294c4c..cd453e4b2a07 100644
--- a/drivers/hv/hv_fcopy.c
+++ b/drivers/hv/hv_fcopy.c
@@ -86,6 +86,18 @@ static void fcopy_work_func(struct work_struct *dummy)
86 * process the pending transaction. 86 * process the pending transaction.
87 */ 87 */
88 fcopy_respond_to_host(HV_E_FAIL); 88 fcopy_respond_to_host(HV_E_FAIL);
89
90 /* In the case the user-space daemon crashes, hangs or is killed, we
91 * need to down the semaphore, otherwise, after the daemon starts next
92 * time, the obsolete data in fcopy_transaction.message or
93 * fcopy_transaction.fcopy_msg will be used immediately.
94 *
95 * NOTE: fcopy_read() happens to get the semaphore (very rare)? We're
96 * still OK, because we've reported the failure to the host.
97 */
98 if (down_trylock(&fcopy_transaction.read_sema))
99 ;
100
89} 101}
90 102
91static int fcopy_handle_handshake(u32 version) 103static int fcopy_handle_handshake(u32 version)
@@ -344,6 +356,14 @@ static int fcopy_open(struct inode *inode, struct file *f)
344 return 0; 356 return 0;
345} 357}
346 358
359/* XXX: there are still some tricky corner cases, e.g.,
360 * 1) In a SMP guest, when fcopy_release() runs between
361 * schedule_delayed_work() and fcopy_send_data(), there is
362 * still a chance an obsolete message will be queued.
363 *
364 * 2) When the fcopy daemon is running, if we unload the driver,
365 * we'll notice a kernel oops when we kill the daemon later.
366 */
347static int fcopy_release(struct inode *inode, struct file *f) 367static int fcopy_release(struct inode *inode, struct file *f)
348{ 368{
349 /* 369 /*
@@ -351,6 +371,13 @@ static int fcopy_release(struct inode *inode, struct file *f)
351 */ 371 */
352 in_hand_shake = true; 372 in_hand_shake = true;
353 opened = false; 373 opened = false;
374
375 if (cancel_delayed_work_sync(&fcopy_work)) {
376 /* We haven't up()-ed the semaphore(very rare)? */
377 if (down_trylock(&fcopy_transaction.read_sema))
378 ;
379 fcopy_respond_to_host(HV_E_FAIL);
380 }
354 return 0; 381 return 0;
355} 382}
356 383
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index c386d8dc7223..44b1c9424712 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -178,6 +178,23 @@ struct hv_message_header {
178 }; 178 };
179}; 179};
180 180
181/*
182 * Timer configuration register.
183 */
184union hv_timer_config {
185 u64 as_uint64;
186 struct {
187 u64 enable:1;
188 u64 periodic:1;
189 u64 lazy:1;
190 u64 auto_enable:1;
191 u64 reserved_z0:12;
192 u64 sintx:4;
193 u64 reserved_z1:44;
194 };
195};
196
197
181/* Define timer message payload structure. */ 198/* Define timer message payload structure. */
182struct hv_timer_message_payload { 199struct hv_timer_message_payload {
183 u32 timer_index; 200 u32 timer_index;
@@ -519,6 +536,10 @@ struct hv_context {
519 * buffer to post messages to the host. 536 * buffer to post messages to the host.
520 */ 537 */
521 void *post_msg_page[NR_CPUS]; 538 void *post_msg_page[NR_CPUS];
539 /*
540 * Support PV clockevent device.
541 */
542 struct clock_event_device *clk_evt[NR_CPUS];
522}; 543};
523 544
524extern struct hv_context hv_context; 545extern struct hv_context hv_context;
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index bb3725b672cf..f518b8d7a5b5 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -32,6 +32,7 @@
32#include <linux/completion.h> 32#include <linux/completion.h>
33#include <linux/hyperv.h> 33#include <linux/hyperv.h>
34#include <linux/kernel_stat.h> 34#include <linux/kernel_stat.h>
35#include <linux/clockchips.h>
35#include <asm/hyperv.h> 36#include <asm/hyperv.h>
36#include <asm/hypervisor.h> 37#include <asm/hypervisor.h>
37#include <asm/mshyperv.h> 38#include <asm/mshyperv.h>
@@ -578,6 +579,34 @@ static void vmbus_onmessage_work(struct work_struct *work)
578 kfree(ctx); 579 kfree(ctx);
579} 580}
580 581
582static void hv_process_timer_expiration(struct hv_message *msg, int cpu)
583{
584 struct clock_event_device *dev = hv_context.clk_evt[cpu];
585
586 if (dev->event_handler)
587 dev->event_handler(dev);
588
589 msg->header.message_type = HVMSG_NONE;
590
591 /*
592 * Make sure the write to MessageType (ie set to
593 * HVMSG_NONE) happens before we read the
594 * MessagePending and EOMing. Otherwise, the EOMing
595 * will not deliver any more messages since there is
596 * no empty slot
597 */
598 mb();
599
600 if (msg->header.message_flags.msg_pending) {
601 /*
602 * This will cause message queue rescan to
603 * possibly deliver another msg from the
604 * hypervisor
605 */
606 wrmsrl(HV_X64_MSR_EOM, 0);
607 }
608}
609
581static void vmbus_on_msg_dpc(unsigned long data) 610static void vmbus_on_msg_dpc(unsigned long data)
582{ 611{
583 int cpu = smp_processor_id(); 612 int cpu = smp_processor_id();
@@ -667,8 +696,12 @@ static void vmbus_isr(void)
667 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; 696 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
668 697
669 /* Check if there are actual msgs to be processed */ 698 /* Check if there are actual msgs to be processed */
670 if (msg->header.message_type != HVMSG_NONE) 699 if (msg->header.message_type != HVMSG_NONE) {
671 tasklet_schedule(&msg_dpc); 700 if (msg->header.message_type == HVMSG_TIMER_EXPIRED)
701 hv_process_timer_expiration(msg, cpu);
702 else
703 tasklet_schedule(&msg_dpc);
704 }
672} 705}
673 706
674/* 707/*
diff --git a/drivers/mcb/mcb-pci.c b/drivers/mcb/mcb-pci.c
index 5e1bd5db02c8..0af7361e377f 100644
--- a/drivers/mcb/mcb-pci.c
+++ b/drivers/mcb/mcb-pci.c
@@ -51,7 +51,7 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
51 priv->mapbase = pci_resource_start(pdev, 0); 51 priv->mapbase = pci_resource_start(pdev, 0);
52 if (!priv->mapbase) { 52 if (!priv->mapbase) {
53 dev_err(&pdev->dev, "No PCI resource\n"); 53 dev_err(&pdev->dev, "No PCI resource\n");
54 goto err_start; 54 goto out_disable;
55 } 55 }
56 56
57 res = request_mem_region(priv->mapbase, CHAM_HEADER_SIZE, 57 res = request_mem_region(priv->mapbase, CHAM_HEADER_SIZE,
@@ -59,14 +59,14 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
59 if (IS_ERR(res)) { 59 if (IS_ERR(res)) {
60 dev_err(&pdev->dev, "Failed to request PCI memory\n"); 60 dev_err(&pdev->dev, "Failed to request PCI memory\n");
61 ret = PTR_ERR(res); 61 ret = PTR_ERR(res);
62 goto err_start; 62 goto out_disable;
63 } 63 }
64 64
65 priv->base = ioremap(priv->mapbase, CHAM_HEADER_SIZE); 65 priv->base = ioremap(priv->mapbase, CHAM_HEADER_SIZE);
66 if (!priv->base) { 66 if (!priv->base) {
67 dev_err(&pdev->dev, "Cannot ioremap\n"); 67 dev_err(&pdev->dev, "Cannot ioremap\n");
68 ret = -ENOMEM; 68 ret = -ENOMEM;
69 goto err_ioremap; 69 goto out_release;
70 } 70 }
71 71
72 flags = pci_resource_flags(pdev, 0); 72 flags = pci_resource_flags(pdev, 0);
@@ -74,7 +74,7 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
74 ret = -ENOTSUPP; 74 ret = -ENOTSUPP;
75 dev_err(&pdev->dev, 75 dev_err(&pdev->dev,
76 "IO mapped PCI devices are not supported\n"); 76 "IO mapped PCI devices are not supported\n");
77 goto err_ioremap; 77 goto out_release;
78 } 78 }
79 79
80 pci_set_drvdata(pdev, priv); 80 pci_set_drvdata(pdev, priv);
@@ -82,14 +82,14 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
82 priv->bus = mcb_alloc_bus(&pdev->dev); 82 priv->bus = mcb_alloc_bus(&pdev->dev);
83 if (IS_ERR(priv->bus)) { 83 if (IS_ERR(priv->bus)) {
84 ret = PTR_ERR(priv->bus); 84 ret = PTR_ERR(priv->bus);
85 goto err_drvdata; 85 goto out_iounmap;
86 } 86 }
87 87
88 priv->bus->get_irq = mcb_pci_get_irq; 88 priv->bus->get_irq = mcb_pci_get_irq;
89 89
90 ret = chameleon_parse_cells(priv->bus, priv->mapbase, priv->base); 90 ret = chameleon_parse_cells(priv->bus, priv->mapbase, priv->base);
91 if (ret < 0) 91 if (ret < 0)
92 goto err_drvdata; 92 goto out_iounmap;
93 num_cells = ret; 93 num_cells = ret;
94 94
95 dev_dbg(&pdev->dev, "Found %d cells\n", num_cells); 95 dev_dbg(&pdev->dev, "Found %d cells\n", num_cells);
@@ -98,11 +98,11 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
98 98
99 return 0; 99 return 0;
100 100
101err_drvdata: 101out_iounmap:
102 iounmap(priv->base); 102 iounmap(priv->base);
103err_ioremap: 103out_release:
104 pci_release_region(pdev, 0); 104 pci_release_region(pdev, 0);
105err_start: 105out_disable:
106 pci_disable_device(pdev); 106 pci_disable_device(pdev);
107 return ret; 107 return ret;
108} 108}
diff --git a/drivers/misc/ad525x_dpot-spi.c b/drivers/misc/ad525x_dpot-spi.c
index 9da04ede04f3..f4c82eafa8e5 100644
--- a/drivers/misc/ad525x_dpot-spi.c
+++ b/drivers/misc/ad525x_dpot-spi.c
@@ -15,18 +15,21 @@
15static int write8(void *client, u8 val) 15static int write8(void *client, u8 val)
16{ 16{
17 u8 data = val; 17 u8 data = val;
18
18 return spi_write(client, &data, 1); 19 return spi_write(client, &data, 1);
19} 20}
20 21
21static int write16(void *client, u8 reg, u8 val) 22static int write16(void *client, u8 reg, u8 val)
22{ 23{
23 u8 data[2] = {reg, val}; 24 u8 data[2] = {reg, val};
25
24 return spi_write(client, data, 2); 26 return spi_write(client, data, 2);
25} 27}
26 28
27static int write24(void *client, u8 reg, u16 val) 29static int write24(void *client, u8 reg, u16 val)
28{ 30{
29 u8 data[3] = {reg, val >> 8, val}; 31 u8 data[3] = {reg, val >> 8, val};
32
30 return spi_write(client, data, 3); 33 return spi_write(client, data, 3);
31} 34}
32 35
@@ -34,6 +37,7 @@ static int read8(void *client)
34{ 37{
35 int ret; 38 int ret;
36 u8 data; 39 u8 data;
40
37 ret = spi_read(client, &data, 1); 41 ret = spi_read(client, &data, 1);
38 if (ret < 0) 42 if (ret < 0)
39 return ret; 43 return ret;
diff --git a/drivers/misc/ad525x_dpot.c b/drivers/misc/ad525x_dpot.c
index a43053daad0e..15e88078ba1e 100644
--- a/drivers/misc/ad525x_dpot.c
+++ b/drivers/misc/ad525x_dpot.c
@@ -176,6 +176,7 @@ static s32 dpot_read_i2c(struct dpot_data *dpot, u8 reg)
176{ 176{
177 int value; 177 int value;
178 unsigned ctrl = 0; 178 unsigned ctrl = 0;
179
179 switch (dpot->uid) { 180 switch (dpot->uid) {
180 case DPOT_UID(AD5246_ID): 181 case DPOT_UID(AD5246_ID):
181 case DPOT_UID(AD5247_ID): 182 case DPOT_UID(AD5247_ID):
@@ -333,7 +334,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
333 case DPOT_UID(AD5246_ID): 334 case DPOT_UID(AD5246_ID):
334 case DPOT_UID(AD5247_ID): 335 case DPOT_UID(AD5247_ID):
335 return dpot_write_d8(dpot, value); 336 return dpot_write_d8(dpot, value);
336 break;
337 337
338 case DPOT_UID(AD5245_ID): 338 case DPOT_UID(AD5245_ID):
339 case DPOT_UID(AD5241_ID): 339 case DPOT_UID(AD5241_ID):
@@ -345,7 +345,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
345 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? 345 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ?
346 0 : DPOT_AD5282_RDAC_AB; 346 0 : DPOT_AD5282_RDAC_AB;
347 return dpot_write_r8d8(dpot, ctrl, value); 347 return dpot_write_r8d8(dpot, ctrl, value);
348 break;
349 case DPOT_UID(AD5171_ID): 348 case DPOT_UID(AD5171_ID):
350 case DPOT_UID(AD5273_ID): 349 case DPOT_UID(AD5273_ID):
351 if (reg & DPOT_ADDR_OTP) { 350 if (reg & DPOT_ADDR_OTP) {
@@ -355,7 +354,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
355 ctrl = DPOT_AD5273_FUSE; 354 ctrl = DPOT_AD5273_FUSE;
356 } 355 }
357 return dpot_write_r8d8(dpot, ctrl, value); 356 return dpot_write_r8d8(dpot, ctrl, value);
358 break;
359 case DPOT_UID(AD5172_ID): 357 case DPOT_UID(AD5172_ID):
360 case DPOT_UID(AD5173_ID): 358 case DPOT_UID(AD5173_ID):
361 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? 359 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ?
@@ -367,7 +365,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
367 ctrl |= DPOT_AD5170_2_3_FUSE; 365 ctrl |= DPOT_AD5170_2_3_FUSE;
368 } 366 }
369 return dpot_write_r8d8(dpot, ctrl, value); 367 return dpot_write_r8d8(dpot, ctrl, value);
370 break;
371 case DPOT_UID(AD5170_ID): 368 case DPOT_UID(AD5170_ID):
372 if (reg & DPOT_ADDR_OTP) { 369 if (reg & DPOT_ADDR_OTP) {
373 tmp = dpot_read_r8d16(dpot, tmp); 370 tmp = dpot_read_r8d16(dpot, tmp);
@@ -376,7 +373,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
376 ctrl = DPOT_AD5170_2_3_FUSE; 373 ctrl = DPOT_AD5170_2_3_FUSE;
377 } 374 }
378 return dpot_write_r8d8(dpot, ctrl, value); 375 return dpot_write_r8d8(dpot, ctrl, value);
379 break;
380 case DPOT_UID(AD5272_ID): 376 case DPOT_UID(AD5272_ID):
381 case DPOT_UID(AD5274_ID): 377 case DPOT_UID(AD5274_ID):
382 dpot_write_r8d8(dpot, DPOT_AD5270_1_2_4_CTRLREG << 2, 378 dpot_write_r8d8(dpot, DPOT_AD5270_1_2_4_CTRLREG << 2,
@@ -391,7 +387,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
391 387
392 return dpot_write_r8d8(dpot, (DPOT_AD5270_1_2_4_RDAC << 2) | 388 return dpot_write_r8d8(dpot, (DPOT_AD5270_1_2_4_RDAC << 2) |
393 (value >> 8), value & 0xFF); 389 (value >> 8), value & 0xFF);
394 break;
395 default: 390 default:
396 if (reg & DPOT_ADDR_CMD) 391 if (reg & DPOT_ADDR_CMD)
397 return dpot_write_d8(dpot, reg); 392 return dpot_write_d8(dpot, reg);
diff --git a/drivers/misc/genwqe/card_base.h b/drivers/misc/genwqe/card_base.h
index c64d7cad1085..e7353449874b 100644
--- a/drivers/misc/genwqe/card_base.h
+++ b/drivers/misc/genwqe/card_base.h
@@ -34,7 +34,6 @@
34#include <linux/semaphore.h> 34#include <linux/semaphore.h>
35#include <linux/uaccess.h> 35#include <linux/uaccess.h>
36#include <linux/io.h> 36#include <linux/io.h>
37#include <linux/version.h>
38#include <linux/debugfs.h> 37#include <linux/debugfs.h>
39#include <linux/slab.h> 38#include <linux/slab.h>
40 39
diff --git a/drivers/misc/genwqe/card_sysfs.c b/drivers/misc/genwqe/card_sysfs.c
index 2c33fbca9225..6ab31eff0536 100644
--- a/drivers/misc/genwqe/card_sysfs.c
+++ b/drivers/misc/genwqe/card_sysfs.c
@@ -24,7 +24,6 @@
24 * debugging, please also see the debugfs interfaces of this driver. 24 * debugging, please also see the debugfs interfaces of this driver.
25 */ 25 */
26 26
27#include <linux/version.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/types.h> 28#include <linux/types.h>
30#include <linux/module.h> 29#include <linux/module.h>
diff --git a/drivers/misc/ioc4.c b/drivers/misc/ioc4.c
index 3336ddca45ac..8758d033db23 100644
--- a/drivers/misc/ioc4.c
+++ b/drivers/misc/ioc4.c
@@ -144,9 +144,9 @@ ioc4_clock_calibrate(struct ioc4_driver_data *idd)
144{ 144{
145 union ioc4_int_out int_out; 145 union ioc4_int_out int_out;
146 union ioc4_gpcr gpcr; 146 union ioc4_gpcr gpcr;
147 unsigned int state, last_state = 1; 147 unsigned int state, last_state;
148 uint64_t start, end, period; 148 uint64_t start, end, period;
149 unsigned int count = 0; 149 unsigned int count;
150 150
151 /* Enable output */ 151 /* Enable output */
152 gpcr.raw = 0; 152 gpcr.raw = 0;
@@ -167,19 +167,20 @@ ioc4_clock_calibrate(struct ioc4_driver_data *idd)
167 mmiowb(); 167 mmiowb();
168 168
169 /* Check square wave period averaged over some number of cycles */ 169 /* Check square wave period averaged over some number of cycles */
170 do { 170 start = ktime_get_ns();
171 int_out.raw = readl(&idd->idd_misc_regs->int_out.raw); 171 state = 1; /* make sure the first read isn't a rising edge */
172 state = int_out.fields.int_out; 172 for (count = 0; count <= IOC4_CALIBRATE_END; count++) {
173 if (!last_state && state) { 173 do { /* wait for a rising edge */
174 count++; 174 last_state = state;
175 if (count == IOC4_CALIBRATE_END) { 175 int_out.raw = readl(&idd->idd_misc_regs->int_out.raw);
176 end = ktime_get_ns(); 176 state = int_out.fields.int_out;
177 break; 177 } while (last_state || !state);
178 } else if (count == IOC4_CALIBRATE_DISCARD) 178
179 start = ktime_get_ns(); 179 /* discard the first few cycles */
180 } 180 if (count == IOC4_CALIBRATE_DISCARD)
181 last_state = state; 181 start = ktime_get_ns();
182 } while (1); 182 }
183 end = ktime_get_ns();
183 184
184 /* Calculation rearranged to preserve intermediate precision. 185 /* Calculation rearranged to preserve intermediate precision.
185 * Logically: 186 * Logically:
diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c
index 79f53941779d..c4cb9a984a5f 100644
--- a/drivers/misc/mei/amthif.c
+++ b/drivers/misc/mei/amthif.c
@@ -97,23 +97,25 @@ int mei_amthif_host_init(struct mei_device *dev)
97 /* allocate storage for ME message buffer */ 97 /* allocate storage for ME message buffer */
98 msg_buf = kcalloc(dev->iamthif_mtu, 98 msg_buf = kcalloc(dev->iamthif_mtu,
99 sizeof(unsigned char), GFP_KERNEL); 99 sizeof(unsigned char), GFP_KERNEL);
100 if (!msg_buf) 100 if (!msg_buf) {
101 return -ENOMEM; 101 ret = -ENOMEM;
102 goto out;
103 }
102 104
103 dev->iamthif_msg_buf = msg_buf; 105 dev->iamthif_msg_buf = msg_buf;
104 106
105 ret = mei_cl_link(cl, MEI_IAMTHIF_HOST_CLIENT_ID); 107 ret = mei_cl_link(cl, MEI_IAMTHIF_HOST_CLIENT_ID);
106
107 if (ret < 0) { 108 if (ret < 0) {
108 dev_err(dev->dev, 109 dev_err(dev->dev, "amthif: failed cl_link %d\n", ret);
109 "amthif: failed link client %d\n", ret); 110 goto out;
110 return ret;
111 } 111 }
112 112
113 ret = mei_cl_connect(cl, NULL); 113 ret = mei_cl_connect(cl, NULL);
114 114
115 dev->iamthif_state = MEI_IAMTHIF_IDLE; 115 dev->iamthif_state = MEI_IAMTHIF_IDLE;
116 116
117out:
118 mei_me_cl_put(me_cl);
117 return ret; 119 return ret;
118} 120}
119 121
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index b3a72bca5242..be767f4db26a 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -224,46 +224,53 @@ void mei_cl_driver_unregister(struct mei_cl_driver *driver)
224} 224}
225EXPORT_SYMBOL_GPL(mei_cl_driver_unregister); 225EXPORT_SYMBOL_GPL(mei_cl_driver_unregister);
226 226
227static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, 227static ssize_t ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
228 bool blocking) 228 bool blocking)
229{ 229{
230 struct mei_device *dev; 230 struct mei_device *dev;
231 struct mei_me_client *me_cl; 231 struct mei_me_client *me_cl = NULL;
232 struct mei_cl_cb *cb; 232 struct mei_cl_cb *cb = NULL;
233 int rets; 233 ssize_t rets;
234 234
235 if (WARN_ON(!cl || !cl->dev)) 235 if (WARN_ON(!cl || !cl->dev))
236 return -ENODEV; 236 return -ENODEV;
237 237
238 dev = cl->dev; 238 dev = cl->dev;
239 239
240 if (cl->state != MEI_FILE_CONNECTED) 240 mutex_lock(&dev->device_lock);
241 return -ENODEV; 241 if (cl->state != MEI_FILE_CONNECTED) {
242 rets = -ENODEV;
243 goto out;
244 }
242 245
243 /* Check if we have an ME client device */ 246 /* Check if we have an ME client device */
244 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id); 247 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
245 if (!me_cl) 248 if (!me_cl) {
246 return -ENOTTY; 249 rets = -ENOTTY;
250 goto out;
251 }
247 252
248 if (length > me_cl->props.max_msg_length) 253 if (length > me_cl->props.max_msg_length) {
249 return -EFBIG; 254 rets = -EFBIG;
255 goto out;
256 }
250 257
251 cb = mei_io_cb_init(cl, NULL); 258 cb = mei_io_cb_init(cl, NULL);
252 if (!cb) 259 if (!cb) {
253 return -ENOMEM; 260 rets = -ENOMEM;
261 goto out;
262 }
254 263
255 rets = mei_io_cb_alloc_req_buf(cb, length); 264 rets = mei_io_cb_alloc_req_buf(cb, length);
256 if (rets < 0) { 265 if (rets < 0)
257 mei_io_cb_free(cb); 266 goto out;
258 return rets;
259 }
260 267
261 memcpy(cb->request_buffer.data, buf, length); 268 memcpy(cb->request_buffer.data, buf, length);
262 269
263 mutex_lock(&dev->device_lock);
264
265 rets = mei_cl_write(cl, cb, blocking); 270 rets = mei_cl_write(cl, cb, blocking);
266 271
272out:
273 mei_me_cl_put(me_cl);
267 mutex_unlock(&dev->device_lock); 274 mutex_unlock(&dev->device_lock);
268 if (rets < 0) 275 if (rets < 0)
269 mei_io_cb_free(cb); 276 mei_io_cb_free(cb);
@@ -271,12 +278,12 @@ static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
271 return rets; 278 return rets;
272} 279}
273 280
274int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length) 281ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
275{ 282{
276 struct mei_device *dev; 283 struct mei_device *dev;
277 struct mei_cl_cb *cb; 284 struct mei_cl_cb *cb;
278 size_t r_length; 285 size_t r_length;
279 int err; 286 ssize_t rets;
280 287
281 if (WARN_ON(!cl || !cl->dev)) 288 if (WARN_ON(!cl || !cl->dev))
282 return -ENODEV; 289 return -ENODEV;
@@ -286,11 +293,9 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
286 mutex_lock(&dev->device_lock); 293 mutex_lock(&dev->device_lock);
287 294
288 if (!cl->read_cb) { 295 if (!cl->read_cb) {
289 err = mei_cl_read_start(cl, length); 296 rets = mei_cl_read_start(cl, length);
290 if (err < 0) { 297 if (rets < 0)
291 mutex_unlock(&dev->device_lock); 298 goto out;
292 return err;
293 }
294 } 299 }
295 300
296 if (cl->reading_state != MEI_READ_COMPLETE && 301 if (cl->reading_state != MEI_READ_COMPLETE &&
@@ -313,13 +318,13 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
313 cb = cl->read_cb; 318 cb = cl->read_cb;
314 319
315 if (cl->reading_state != MEI_READ_COMPLETE) { 320 if (cl->reading_state != MEI_READ_COMPLETE) {
316 r_length = 0; 321 rets = 0;
317 goto out; 322 goto out;
318 } 323 }
319 324
320 r_length = min_t(size_t, length, cb->buf_idx); 325 r_length = min_t(size_t, length, cb->buf_idx);
321
322 memcpy(buf, cb->response_buffer.data, r_length); 326 memcpy(buf, cb->response_buffer.data, r_length);
327 rets = r_length;
323 328
324 mei_io_cb_free(cb); 329 mei_io_cb_free(cb);
325 cl->reading_state = MEI_IDLE; 330 cl->reading_state = MEI_IDLE;
@@ -328,20 +333,20 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
328out: 333out:
329 mutex_unlock(&dev->device_lock); 334 mutex_unlock(&dev->device_lock);
330 335
331 return r_length; 336 return rets;
332} 337}
333 338
334inline int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length) 339inline ssize_t __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length)
335{ 340{
336 return ___mei_cl_send(cl, buf, length, 0); 341 return ___mei_cl_send(cl, buf, length, 0);
337} 342}
338 343
339inline int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length) 344inline ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length)
340{ 345{
341 return ___mei_cl_send(cl, buf, length, 1); 346 return ___mei_cl_send(cl, buf, length, 1);
342} 347}
343 348
344int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length) 349ssize_t mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length)
345{ 350{
346 struct mei_cl *cl = device->cl; 351 struct mei_cl *cl = device->cl;
347 352
@@ -355,7 +360,7 @@ int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length)
355} 360}
356EXPORT_SYMBOL_GPL(mei_cl_send); 361EXPORT_SYMBOL_GPL(mei_cl_send);
357 362
358int mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length) 363ssize_t mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length)
359{ 364{
360 struct mei_cl *cl = device->cl; 365 struct mei_cl *cl = device->cl;
361 366
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 1382d551d7ed..dfbddfe1c7a0 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -27,7 +27,63 @@
27#include "client.h" 27#include "client.h"
28 28
29/** 29/**
30 * mei_me_cl_init - initialize me client
31 *
32 * @me_cl: me client
33 */
34void mei_me_cl_init(struct mei_me_client *me_cl)
35{
36 INIT_LIST_HEAD(&me_cl->list);
37 kref_init(&me_cl->refcnt);
38}
39
40/**
41 * mei_me_cl_get - increases me client refcount
42 *
43 * @me_cl: me client
44 *
45 * Locking: called under "dev->device_lock" lock
46 *
47 * Return: me client or NULL
48 */
49struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl)
50{
51 if (me_cl)
52 kref_get(&me_cl->refcnt);
53
54 return me_cl;
55}
56
57/**
58 * mei_me_cl_release - unlink and free me client
59 *
60 * Locking: called under "dev->device_lock" lock
61 *
62 * @ref: me_client refcount
63 */
64static void mei_me_cl_release(struct kref *ref)
65{
66 struct mei_me_client *me_cl =
67 container_of(ref, struct mei_me_client, refcnt);
68 list_del(&me_cl->list);
69 kfree(me_cl);
70}
71/**
72 * mei_me_cl_put - decrease me client refcount and free client if necessary
73 *
74 * Locking: called under "dev->device_lock" lock
75 *
76 * @me_cl: me client
77 */
78void mei_me_cl_put(struct mei_me_client *me_cl)
79{
80 if (me_cl)
81 kref_put(&me_cl->refcnt, mei_me_cl_release);
82}
83
84/**
30 * mei_me_cl_by_uuid - locate me client by uuid 85 * mei_me_cl_by_uuid - locate me client by uuid
86 * increases ref count
31 * 87 *
32 * @dev: mei device 88 * @dev: mei device
33 * @uuid: me client uuid 89 * @uuid: me client uuid
@@ -43,13 +99,14 @@ struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev,
43 99
44 list_for_each_entry(me_cl, &dev->me_clients, list) 100 list_for_each_entry(me_cl, &dev->me_clients, list)
45 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0) 101 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0)
46 return me_cl; 102 return mei_me_cl_get(me_cl);
47 103
48 return NULL; 104 return NULL;
49} 105}
50 106
51/** 107/**
52 * mei_me_cl_by_id - locate me client by client id 108 * mei_me_cl_by_id - locate me client by client id
109 * increases ref count
53 * 110 *
54 * @dev: the device structure 111 * @dev: the device structure
55 * @client_id: me client id 112 * @client_id: me client id
@@ -65,12 +122,14 @@ struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
65 122
66 list_for_each_entry(me_cl, &dev->me_clients, list) 123 list_for_each_entry(me_cl, &dev->me_clients, list)
67 if (me_cl->client_id == client_id) 124 if (me_cl->client_id == client_id)
68 return me_cl; 125 return mei_me_cl_get(me_cl);
126
69 return NULL; 127 return NULL;
70} 128}
71 129
72/** 130/**
73 * mei_me_cl_by_uuid_id - locate me client by client id and uuid 131 * mei_me_cl_by_uuid_id - locate me client by client id and uuid
132 * increases ref count
74 * 133 *
75 * @dev: the device structure 134 * @dev: the device structure
76 * @uuid: me client uuid 135 * @uuid: me client uuid
@@ -88,31 +147,67 @@ struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
88 list_for_each_entry(me_cl, &dev->me_clients, list) 147 list_for_each_entry(me_cl, &dev->me_clients, list)
89 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 && 148 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 &&
90 me_cl->client_id == client_id) 149 me_cl->client_id == client_id)
91 return me_cl; 150 return mei_me_cl_get(me_cl);
151
92 return NULL; 152 return NULL;
93} 153}
94 154
95/** 155/**
96 * mei_me_cl_remove - remove me client matching uuid and client_id 156 * mei_me_cl_rm_by_uuid - remove all me clients matching uuid
97 * 157 *
98 * @dev: the device structure 158 * @dev: the device structure
99 * @uuid: me client uuid 159 * @uuid: me client uuid
100 * @client_id: me client address 160 *
161 * Locking: called under "dev->device_lock" lock
101 */ 162 */
102void mei_me_cl_remove(struct mei_device *dev, const uuid_le *uuid, u8 client_id) 163void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid)
103{ 164{
104 struct mei_me_client *me_cl, *next; 165 struct mei_me_client *me_cl, *next;
105 166
167 dev_dbg(dev->dev, "remove %pUl\n", uuid);
168 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list)
169 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0)
170 mei_me_cl_put(me_cl);
171}
172
173/**
174 * mei_me_cl_rm_by_uuid_id - remove all me clients matching client id
175 *
176 * @dev: the device structure
177 * @uuid: me client uuid
178 * @id: me client id
179 *
180 * Locking: called under "dev->device_lock" lock
181 */
182void mei_me_cl_rm_by_uuid_id(struct mei_device *dev, const uuid_le *uuid, u8 id)
183{
184 struct mei_me_client *me_cl, *next;
185 const uuid_le *pn;
186
187 dev_dbg(dev->dev, "remove %pUl %d\n", uuid, id);
106 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) { 188 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) {
107 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 && 189 pn = &me_cl->props.protocol_name;
108 me_cl->client_id == client_id) { 190 if (me_cl->client_id == id && uuid_le_cmp(*uuid, *pn) == 0)
109 list_del(&me_cl->list); 191 mei_me_cl_put(me_cl);
110 kfree(me_cl);
111 break;
112 }
113 } 192 }
114} 193}
115 194
195/**
196 * mei_me_cl_rm_all - remove all me clients
197 *
198 * @dev: the device structure
199 *
200 * Locking: called under "dev->device_lock" lock
201 */
202void mei_me_cl_rm_all(struct mei_device *dev)
203{
204 struct mei_me_client *me_cl, *next;
205
206 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list)
207 mei_me_cl_put(me_cl);
208}
209
210
116 211
117/** 212/**
118 * mei_cl_cmp_id - tells if the clients are the same 213 * mei_cl_cmp_id - tells if the clients are the same
@@ -695,6 +790,7 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
695{ 790{
696 struct mei_device *dev; 791 struct mei_device *dev;
697 struct mei_me_client *me_cl; 792 struct mei_me_client *me_cl;
793 int rets = 0;
698 794
699 if (WARN_ON(!cl || !cl->dev)) 795 if (WARN_ON(!cl || !cl->dev))
700 return -EINVAL; 796 return -EINVAL;
@@ -704,18 +800,19 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
704 if (cl->mei_flow_ctrl_creds > 0) 800 if (cl->mei_flow_ctrl_creds > 0)
705 return 1; 801 return 1;
706 802
707 me_cl = mei_me_cl_by_id(dev, cl->me_client_id); 803 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
708 if (!me_cl) { 804 if (!me_cl) {
709 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); 805 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
710 return -ENOENT; 806 return -ENOENT;
711 } 807 }
712 808
713 if (me_cl->mei_flow_ctrl_creds) { 809 if (me_cl->mei_flow_ctrl_creds > 0) {
810 rets = 1;
714 if (WARN_ON(me_cl->props.single_recv_buf == 0)) 811 if (WARN_ON(me_cl->props.single_recv_buf == 0))
715 return -EINVAL; 812 rets = -EINVAL;
716 return 1;
717 } 813 }
718 return 0; 814 mei_me_cl_put(me_cl);
815 return rets;
719} 816}
720 817
721/** 818/**
@@ -732,28 +829,36 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl)
732{ 829{
733 struct mei_device *dev; 830 struct mei_device *dev;
734 struct mei_me_client *me_cl; 831 struct mei_me_client *me_cl;
832 int rets;
735 833
736 if (WARN_ON(!cl || !cl->dev)) 834 if (WARN_ON(!cl || !cl->dev))
737 return -EINVAL; 835 return -EINVAL;
738 836
739 dev = cl->dev; 837 dev = cl->dev;
740 838
741 me_cl = mei_me_cl_by_id(dev, cl->me_client_id); 839 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
742 if (!me_cl) { 840 if (!me_cl) {
743 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); 841 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
744 return -ENOENT; 842 return -ENOENT;
745 } 843 }
746 844
747 if (me_cl->props.single_recv_buf) { 845 if (me_cl->props.single_recv_buf) {
748 if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0)) 846 if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0)) {
749 return -EINVAL; 847 rets = -EINVAL;
848 goto out;
849 }
750 me_cl->mei_flow_ctrl_creds--; 850 me_cl->mei_flow_ctrl_creds--;
751 } else { 851 } else {
752 if (WARN_ON(cl->mei_flow_ctrl_creds <= 0)) 852 if (WARN_ON(cl->mei_flow_ctrl_creds <= 0)) {
753 return -EINVAL; 853 rets = -EINVAL;
854 goto out;
855 }
754 cl->mei_flow_ctrl_creds--; 856 cl->mei_flow_ctrl_creds--;
755 } 857 }
756 return 0; 858 rets = 0;
859out:
860 mei_me_cl_put(me_cl);
861 return rets;
757} 862}
758 863
759/** 864/**
@@ -788,6 +893,9 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
788 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); 893 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
789 return -ENOTTY; 894 return -ENOTTY;
790 } 895 }
896 /* always allocate at least client max message */
897 length = max_t(size_t, length, me_cl->props.max_msg_length);
898 mei_me_cl_put(me_cl);
791 899
792 rets = pm_runtime_get(dev->dev); 900 rets = pm_runtime_get(dev->dev);
793 if (rets < 0 && rets != -EINPROGRESS) { 901 if (rets < 0 && rets != -EINPROGRESS) {
@@ -802,8 +910,6 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
802 goto out; 910 goto out;
803 } 911 }
804 912
805 /* always allocate at least client max message */
806 length = max_t(size_t, length, me_cl->props.max_msg_length);
807 rets = mei_io_cb_alloc_resp_buf(cb, length); 913 rets = mei_io_cb_alloc_resp_buf(cb, length);
808 if (rets) 914 if (rets)
809 goto out; 915 goto out;
diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h
index d9d0c1525259..cfcde8e97fc4 100644
--- a/drivers/misc/mei/client.h
+++ b/drivers/misc/mei/client.h
@@ -24,15 +24,22 @@
24 24
25#include "mei_dev.h" 25#include "mei_dev.h"
26 26
27/*
28 * reference counting base function
29 */
30void mei_me_cl_init(struct mei_me_client *me_cl);
31void mei_me_cl_put(struct mei_me_client *me_cl);
32struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl);
33
27struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev, 34struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev,
28 const uuid_le *cuuid); 35 const uuid_le *uuid);
29struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id); 36struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
30
31struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev, 37struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
32 const uuid_le *uuid, u8 client_id); 38 const uuid_le *uuid, u8 client_id);
33 39void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid);
34void mei_me_cl_remove(struct mei_device *dev, 40void mei_me_cl_rm_by_uuid_id(struct mei_device *dev,
35 const uuid_le *uuid, u8 client_id); 41 const uuid_le *uuid, u8 id);
42void mei_me_cl_rm_all(struct mei_device *dev);
36 43
37/* 44/*
38 * MEI IO Functions 45 * MEI IO Functions
diff --git a/drivers/misc/mei/debugfs.c b/drivers/misc/mei/debugfs.c
index b60b4263cf0f..b125380ee871 100644
--- a/drivers/misc/mei/debugfs.c
+++ b/drivers/misc/mei/debugfs.c
@@ -21,20 +21,22 @@
21#include <linux/mei.h> 21#include <linux/mei.h>
22 22
23#include "mei_dev.h" 23#include "mei_dev.h"
24#include "client.h"
24#include "hw.h" 25#include "hw.h"
25 26
26static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf, 27static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
27 size_t cnt, loff_t *ppos) 28 size_t cnt, loff_t *ppos)
28{ 29{
29 struct mei_device *dev = fp->private_data; 30 struct mei_device *dev = fp->private_data;
30 struct mei_me_client *me_cl; 31 struct mei_me_client *me_cl, *n;
31 size_t bufsz = 1; 32 size_t bufsz = 1;
32 char *buf; 33 char *buf;
33 int i = 0; 34 int i = 0;
34 int pos = 0; 35 int pos = 0;
35 int ret; 36 int ret;
36 37
37#define HDR " |id|fix| UUID |con|msg len|sb|\n" 38#define HDR \
39" |id|fix| UUID |con|msg len|sb|refc|\n"
38 40
39 mutex_lock(&dev->device_lock); 41 mutex_lock(&dev->device_lock);
40 42
@@ -54,16 +56,22 @@ static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
54 if (dev->dev_state != MEI_DEV_ENABLED) 56 if (dev->dev_state != MEI_DEV_ENABLED)
55 goto out; 57 goto out;
56 58
57 list_for_each_entry(me_cl, &dev->me_clients, list) { 59 list_for_each_entry_safe(me_cl, n, &dev->me_clients, list) {
58 60
59 pos += scnprintf(buf + pos, bufsz - pos, 61 me_cl = mei_me_cl_get(me_cl);
60 "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|\n", 62 if (me_cl) {
61 i++, me_cl->client_id, 63 pos += scnprintf(buf + pos, bufsz - pos,
62 me_cl->props.fixed_address, 64 "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|\n",
63 &me_cl->props.protocol_name, 65 i++, me_cl->client_id,
64 me_cl->props.max_number_of_connections, 66 me_cl->props.fixed_address,
65 me_cl->props.max_msg_length, 67 &me_cl->props.protocol_name,
66 me_cl->props.single_recv_buf); 68 me_cl->props.max_number_of_connections,
69 me_cl->props.max_msg_length,
70 me_cl->props.single_recv_buf,
71 atomic_read(&me_cl->refcnt.refcount));
72 }
73
74 mei_me_cl_put(me_cl);
67 } 75 }
68out: 76out:
69 mutex_unlock(&dev->device_lock); 77 mutex_unlock(&dev->device_lock);
diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c
index 239d7f5d6a92..c8412d41e4f1 100644
--- a/drivers/misc/mei/hbm.c
+++ b/drivers/misc/mei/hbm.c
@@ -105,21 +105,6 @@ void mei_hbm_idle(struct mei_device *dev)
105} 105}
106 106
107/** 107/**
108 * mei_me_cl_remove_all - remove all me clients
109 *
110 * @dev: the device structure
111 */
112static void mei_me_cl_remove_all(struct mei_device *dev)
113{
114 struct mei_me_client *me_cl, *next;
115
116 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) {
117 list_del(&me_cl->list);
118 kfree(me_cl);
119 }
120}
121
122/**
123 * mei_hbm_reset - reset hbm counters and book keeping data structurs 108 * mei_hbm_reset - reset hbm counters and book keeping data structurs
124 * 109 *
125 * @dev: the device structure 110 * @dev: the device structure
@@ -128,7 +113,7 @@ void mei_hbm_reset(struct mei_device *dev)
128{ 113{
129 dev->me_client_index = 0; 114 dev->me_client_index = 0;
130 115
131 mei_me_cl_remove_all(dev); 116 mei_me_cl_rm_all(dev);
132 117
133 mei_hbm_idle(dev); 118 mei_hbm_idle(dev);
134} 119}
@@ -339,11 +324,16 @@ static int mei_hbm_me_cl_add(struct mei_device *dev,
339 struct hbm_props_response *res) 324 struct hbm_props_response *res)
340{ 325{
341 struct mei_me_client *me_cl; 326 struct mei_me_client *me_cl;
327 const uuid_le *uuid = &res->client_properties.protocol_name;
328
329 mei_me_cl_rm_by_uuid(dev, uuid);
342 330
343 me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL); 331 me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL);
344 if (!me_cl) 332 if (!me_cl)
345 return -ENOMEM; 333 return -ENOMEM;
346 334
335 mei_me_cl_init(me_cl);
336
347 me_cl->props = res->client_properties; 337 me_cl->props = res->client_properties;
348 me_cl->client_id = res->me_addr; 338 me_cl->client_id = res->me_addr;
349 me_cl->mei_flow_ctrl_creds = 0; 339 me_cl->mei_flow_ctrl_creds = 0;
@@ -484,6 +474,7 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev,
484 struct hbm_flow_control *flow) 474 struct hbm_flow_control *flow)
485{ 475{
486 struct mei_me_client *me_cl; 476 struct mei_me_client *me_cl;
477 int rets;
487 478
488 me_cl = mei_me_cl_by_id(dev, flow->me_addr); 479 me_cl = mei_me_cl_by_id(dev, flow->me_addr);
489 if (!me_cl) { 480 if (!me_cl) {
@@ -492,14 +483,19 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev,
492 return -ENOENT; 483 return -ENOENT;
493 } 484 }
494 485
495 if (WARN_ON(me_cl->props.single_recv_buf == 0)) 486 if (WARN_ON(me_cl->props.single_recv_buf == 0)) {
496 return -EINVAL; 487 rets = -EINVAL;
488 goto out;
489 }
497 490
498 me_cl->mei_flow_ctrl_creds++; 491 me_cl->mei_flow_ctrl_creds++;
499 dev_dbg(dev->dev, "recv flow ctrl msg ME %d (single) creds = %d.\n", 492 dev_dbg(dev->dev, "recv flow ctrl msg ME %d (single) creds = %d.\n",
500 flow->me_addr, me_cl->mei_flow_ctrl_creds); 493 flow->me_addr, me_cl->mei_flow_ctrl_creds);
501 494
502 return 0; 495 rets = 0;
496out:
497 mei_me_cl_put(me_cl);
498 return rets;
503} 499}
504 500
505/** 501/**
diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index 06ff0a2ec960..f8fd503dfbd6 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -242,7 +242,7 @@ static int mei_me_hw_reset(struct mei_device *dev, bool intr_enable)
242 if ((hcsr & H_RST) == H_RST) { 242 if ((hcsr & H_RST) == H_RST) {
243 dev_warn(dev->dev, "H_RST is set = 0x%08X", hcsr); 243 dev_warn(dev->dev, "H_RST is set = 0x%08X", hcsr);
244 hcsr &= ~H_RST; 244 hcsr &= ~H_RST;
245 mei_me_reg_write(hw, H_CSR, hcsr); 245 mei_hcsr_set(hw, hcsr);
246 hcsr = mei_hcsr_read(hw); 246 hcsr = mei_hcsr_read(hw);
247 } 247 }
248 248
@@ -335,6 +335,7 @@ static int mei_me_hw_ready_wait(struct mei_device *dev)
335 return -ETIME; 335 return -ETIME;
336 } 336 }
337 337
338 mei_me_hw_reset_release(dev);
338 dev->recvd_hw_ready = false; 339 dev->recvd_hw_ready = false;
339 return 0; 340 return 0;
340} 341}
@@ -731,9 +732,7 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
731 /* check if we need to start the dev */ 732 /* check if we need to start the dev */
732 if (!mei_host_is_ready(dev)) { 733 if (!mei_host_is_ready(dev)) {
733 if (mei_hw_is_ready(dev)) { 734 if (mei_hw_is_ready(dev)) {
734 mei_me_hw_reset_release(dev);
735 dev_dbg(dev->dev, "we need to start the dev.\n"); 735 dev_dbg(dev->dev, "we need to start the dev.\n");
736
737 dev->recvd_hw_ready = true; 736 dev->recvd_hw_ready = true;
738 wake_up(&dev->wait_hw_ready); 737 wake_up(&dev->wait_hw_ready);
739 } else { 738 } else {
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index ae56ba6ca0e3..3c019c0e60eb 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -303,7 +303,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
303 size_t length, loff_t *offset) 303 size_t length, loff_t *offset)
304{ 304{
305 struct mei_cl *cl = file->private_data; 305 struct mei_cl *cl = file->private_data;
306 struct mei_me_client *me_cl; 306 struct mei_me_client *me_cl = NULL;
307 struct mei_cl_cb *write_cb = NULL; 307 struct mei_cl_cb *write_cb = NULL;
308 struct mei_device *dev; 308 struct mei_device *dev;
309 unsigned long timeout = 0; 309 unsigned long timeout = 0;
@@ -399,12 +399,14 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
399 "amthif write failed with status = %d\n", rets); 399 "amthif write failed with status = %d\n", rets);
400 goto out; 400 goto out;
401 } 401 }
402 mei_me_cl_put(me_cl);
402 mutex_unlock(&dev->device_lock); 403 mutex_unlock(&dev->device_lock);
403 return length; 404 return length;
404 } 405 }
405 406
406 rets = mei_cl_write(cl, write_cb, false); 407 rets = mei_cl_write(cl, write_cb, false);
407out: 408out:
409 mei_me_cl_put(me_cl);
408 mutex_unlock(&dev->device_lock); 410 mutex_unlock(&dev->device_lock);
409 if (rets < 0) 411 if (rets < 0)
410 mei_io_cb_free(write_cb); 412 mei_io_cb_free(write_cb);
@@ -433,24 +435,19 @@ static int mei_ioctl_connect_client(struct file *file,
433 cl = file->private_data; 435 cl = file->private_data;
434 dev = cl->dev; 436 dev = cl->dev;
435 437
436 if (dev->dev_state != MEI_DEV_ENABLED) { 438 if (dev->dev_state != MEI_DEV_ENABLED)
437 rets = -ENODEV; 439 return -ENODEV;
438 goto end;
439 }
440 440
441 if (cl->state != MEI_FILE_INITIALIZING && 441 if (cl->state != MEI_FILE_INITIALIZING &&
442 cl->state != MEI_FILE_DISCONNECTED) { 442 cl->state != MEI_FILE_DISCONNECTED)
443 rets = -EBUSY; 443 return -EBUSY;
444 goto end;
445 }
446 444
447 /* find ME client we're trying to connect to */ 445 /* find ME client we're trying to connect to */
448 me_cl = mei_me_cl_by_uuid(dev, &data->in_client_uuid); 446 me_cl = mei_me_cl_by_uuid(dev, &data->in_client_uuid);
449 if (!me_cl || me_cl->props.fixed_address) { 447 if (!me_cl || me_cl->props.fixed_address) {
450 dev_dbg(dev->dev, "Cannot connect to FW Client UUID = %pUl\n", 448 dev_dbg(dev->dev, "Cannot connect to FW Client UUID = %pUl\n",
451 &data->in_client_uuid); 449 &data->in_client_uuid);
452 rets = -ENOTTY; 450 return -ENOTTY;
453 goto end;
454 } 451 }
455 452
456 cl->me_client_id = me_cl->client_id; 453 cl->me_client_id = me_cl->client_id;
@@ -487,17 +484,16 @@ static int mei_ioctl_connect_client(struct file *file,
487 goto end; 484 goto end;
488 } 485 }
489 486
490
491 /* prepare the output buffer */ 487 /* prepare the output buffer */
492 client = &data->out_client_properties; 488 client = &data->out_client_properties;
493 client->max_msg_length = me_cl->props.max_msg_length; 489 client->max_msg_length = me_cl->props.max_msg_length;
494 client->protocol_version = me_cl->props.protocol_version; 490 client->protocol_version = me_cl->props.protocol_version;
495 dev_dbg(dev->dev, "Can connect?\n"); 491 dev_dbg(dev->dev, "Can connect?\n");
496 492
497
498 rets = mei_cl_connect(cl, file); 493 rets = mei_cl_connect(cl, file);
499 494
500end: 495end:
496 mei_me_cl_put(me_cl);
501 return rets; 497 return rets;
502} 498}
503 499
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index 3dad74a8d496..6c6ce9381535 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -172,12 +172,14 @@ struct mei_fw_status {
172 * struct mei_me_client - representation of me (fw) client 172 * struct mei_me_client - representation of me (fw) client
173 * 173 *
174 * @list: link in me client list 174 * @list: link in me client list
175 * @refcnt: struct reference count
175 * @props: client properties 176 * @props: client properties
176 * @client_id: me client id 177 * @client_id: me client id
177 * @mei_flow_ctrl_creds: flow control credits 178 * @mei_flow_ctrl_creds: flow control credits
178 */ 179 */
179struct mei_me_client { 180struct mei_me_client {
180 struct list_head list; 181 struct list_head list;
182 struct kref refcnt;
181 struct mei_client_properties props; 183 struct mei_client_properties props;
182 u8 client_id; 184 u8 client_id;
183 u8 mei_flow_ctrl_creds; 185 u8 mei_flow_ctrl_creds;
@@ -345,9 +347,9 @@ struct mei_cl_device *mei_cl_add_device(struct mei_device *dev,
345 struct mei_cl_ops *ops); 347 struct mei_cl_ops *ops);
346void mei_cl_remove_device(struct mei_cl_device *device); 348void mei_cl_remove_device(struct mei_cl_device *device);
347 349
348int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length); 350ssize_t __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length);
349int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length); 351ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length);
350int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length); 352ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length);
351void mei_cl_bus_rx_event(struct mei_cl *cl); 353void mei_cl_bus_rx_event(struct mei_cl *cl);
352void mei_cl_bus_remove_devices(struct mei_device *dev); 354void mei_cl_bus_remove_devices(struct mei_device *dev);
353int mei_cl_bus_init(void); 355int mei_cl_bus_init(void);
diff --git a/drivers/misc/mei/nfc.c b/drivers/misc/mei/nfc.c
index 60ca9240368e..bb61a119b8bb 100644
--- a/drivers/misc/mei/nfc.c
+++ b/drivers/misc/mei/nfc.c
@@ -521,6 +521,7 @@ int mei_nfc_host_init(struct mei_device *dev)
521 521
522 cl_info->me_client_id = me_cl->client_id; 522 cl_info->me_client_id = me_cl->client_id;
523 cl_info->cl_uuid = me_cl->props.protocol_name; 523 cl_info->cl_uuid = me_cl->props.protocol_name;
524 mei_me_cl_put(me_cl);
524 525
525 ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY); 526 ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY);
526 if (ret) 527 if (ret)
@@ -539,6 +540,7 @@ int mei_nfc_host_init(struct mei_device *dev)
539 540
540 cl->me_client_id = me_cl->client_id; 541 cl->me_client_id = me_cl->client_id;
541 cl->cl_uuid = me_cl->props.protocol_name; 542 cl->cl_uuid = me_cl->props.protocol_name;
543 mei_me_cl_put(me_cl);
542 544
543 ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY); 545 ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY);
544 if (ret) 546 if (ret)
diff --git a/drivers/misc/mei/wd.c b/drivers/misc/mei/wd.c
index b1d892cea94d..475f1dea45bf 100644
--- a/drivers/misc/mei/wd.c
+++ b/drivers/misc/mei/wd.c
@@ -76,6 +76,7 @@ int mei_wd_host_init(struct mei_device *dev)
76 76
77 cl->me_client_id = me_cl->client_id; 77 cl->me_client_id = me_cl->client_id;
78 cl->cl_uuid = me_cl->props.protocol_name; 78 cl->cl_uuid = me_cl->props.protocol_name;
79 mei_me_cl_put(me_cl);
79 80
80 ret = mei_cl_link(cl, MEI_WD_HOST_CLIENT_ID); 81 ret = mei_cl_link(cl, MEI_WD_HOST_CLIENT_ID);
81 82
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index 54be83d3efdd..c8c6a363069c 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -343,12 +343,26 @@ void st_int_recv(void *disc_data,
343 /* Unknow packet? */ 343 /* Unknow packet? */
344 default: 344 default:
345 type = *ptr; 345 type = *ptr;
346 if (st_gdata->list[type] == NULL) {
347 pr_err("chip/interface misbehavior dropping"
348 " frame starting with 0x%02x", type);
349 goto done;
350 346
347 /* Default case means non-HCILL packets,
348 * possibilities are packets for:
349 * (a) valid protocol - Supported Protocols within
350 * the ST_MAX_CHANNELS.
351 * (b) registered protocol - Checked by
352 * "st_gdata->list[type] == NULL)" are supported
353 * protocols only.
354 * Rules out any invalid protocol and
355 * unregistered protocols with channel ID < 16.
356 */
357
358 if ((type >= ST_MAX_CHANNELS) ||
359 (st_gdata->list[type] == NULL)) {
360 pr_err("chip/interface misbehavior: "
361 "dropping frame starting "
362 "with 0x%02x\n", type);
363 goto done;
351 } 364 }
365
352 st_gdata->rx_skb = alloc_skb( 366 st_gdata->rx_skb = alloc_skb(
353 st_gdata->list[type]->max_frame_size, 367 st_gdata->list[type]->max_frame_size,
354 GFP_ATOMIC); 368 GFP_ATOMIC);
@@ -893,5 +907,3 @@ void st_core_exit(struct st_data_s *st_gdata)
893 kfree(st_gdata); 907 kfree(st_gdata);
894 } 908 }
895} 909}
896
897
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index e4b7ee4f57b8..18e7a03985d4 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -36,7 +36,8 @@
36#include <linux/skbuff.h> 36#include <linux/skbuff.h>
37#include <linux/ti_wilink_st.h> 37#include <linux/ti_wilink_st.h>
38#include <linux/module.h> 38#include <linux/module.h>
39 39#include <linux/of.h>
40#include <linux/of_device.h>
40 41
41#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */ 42#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */
42static struct platform_device *st_kim_devices[MAX_ST_DEVICES]; 43static struct platform_device *st_kim_devices[MAX_ST_DEVICES];
@@ -44,6 +45,9 @@ static struct platform_device *st_kim_devices[MAX_ST_DEVICES];
44/**********************************************************************/ 45/**********************************************************************/
45/* internal functions */ 46/* internal functions */
46 47
48struct ti_st_plat_data *dt_pdata;
49static struct ti_st_plat_data *get_platform_data(struct device *dev);
50
47/** 51/**
48 * st_get_plat_device - 52 * st_get_plat_device -
49 * function which returns the reference to the platform device 53 * function which returns the reference to the platform device
@@ -215,6 +219,7 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
215{ 219{
216 unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0; 220 unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0;
217 const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 }; 221 const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 };
222 long timeout;
218 223
219 pr_debug("%s", __func__); 224 pr_debug("%s", __func__);
220 225
@@ -224,10 +229,11 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
224 return -EIO; 229 return -EIO;
225 } 230 }
226 231
227 if (!wait_for_completion_interruptible_timeout( 232 timeout = wait_for_completion_interruptible_timeout(
228 &kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) { 233 &kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME));
229 pr_err(" waiting for ver info- timed out "); 234 if (timeout <= 0) {
230 return -ETIMEDOUT; 235 pr_err(" waiting for ver info- timed out or received signal");
236 return timeout ? -ERESTARTSYS : -ETIMEDOUT;
231 } 237 }
232 reinit_completion(&kim_gdata->kim_rcvd); 238 reinit_completion(&kim_gdata->kim_rcvd);
233 /* the positions 12 & 13 in the response buffer provide with the 239 /* the positions 12 & 13 in the response buffer provide with the
@@ -391,13 +397,14 @@ static long download_firmware(struct kim_data_s *kim_gdata)
391 break; 397 break;
392 case ACTION_WAIT_EVENT: /* wait */ 398 case ACTION_WAIT_EVENT: /* wait */
393 pr_debug("W"); 399 pr_debug("W");
394 if (!wait_for_completion_interruptible_timeout( 400 err = wait_for_completion_interruptible_timeout(
395 &kim_gdata->kim_rcvd, 401 &kim_gdata->kim_rcvd,
396 msecs_to_jiffies(CMD_RESP_TIME))) { 402 msecs_to_jiffies(CMD_RESP_TIME));
397 pr_err("response timeout during fw download "); 403 if (err <= 0) {
404 pr_err("response timeout/signaled during fw download ");
398 /* timed out */ 405 /* timed out */
399 release_firmware(kim_gdata->fw_entry); 406 release_firmware(kim_gdata->fw_entry);
400 return -ETIMEDOUT; 407 return err ? -ERESTARTSYS : -ETIMEDOUT;
401 } 408 }
402 reinit_completion(&kim_gdata->kim_rcvd); 409 reinit_completion(&kim_gdata->kim_rcvd);
403 break; 410 break;
@@ -462,7 +469,12 @@ long st_kim_start(void *kim_data)
462 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 469 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
463 470
464 pr_info(" %s", __func__); 471 pr_info(" %s", __func__);
465 pdata = kim_gdata->kim_pdev->dev.platform_data; 472 if (kim_gdata->kim_pdev->dev.of_node) {
473 pr_debug("use device tree data");
474 pdata = dt_pdata;
475 } else {
476 pdata = kim_gdata->kim_pdev->dev.platform_data;
477 }
466 478
467 do { 479 do {
468 /* platform specific enabling code here */ 480 /* platform specific enabling code here */
@@ -522,12 +534,18 @@ long st_kim_stop(void *kim_data)
522{ 534{
523 long err = 0; 535 long err = 0;
524 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 536 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
525 struct ti_st_plat_data *pdata = 537 struct ti_st_plat_data *pdata;
526 kim_gdata->kim_pdev->dev.platform_data;
527 struct tty_struct *tty = kim_gdata->core_data->tty; 538 struct tty_struct *tty = kim_gdata->core_data->tty;
528 539
529 reinit_completion(&kim_gdata->ldisc_installed); 540 reinit_completion(&kim_gdata->ldisc_installed);
530 541
542 if (kim_gdata->kim_pdev->dev.of_node) {
543 pr_debug("use device tree data");
544 pdata = dt_pdata;
545 } else
546 pdata = kim_gdata->kim_pdev->dev.platform_data;
547
548
531 if (tty) { /* can be called before ldisc is installed */ 549 if (tty) { /* can be called before ldisc is installed */
532 /* Flush any pending characters in the driver and discipline. */ 550 /* Flush any pending characters in the driver and discipline. */
533 tty_ldisc_flush(tty); 551 tty_ldisc_flush(tty);
@@ -620,7 +638,7 @@ static ssize_t show_baud_rate(struct device *dev,
620 struct device_attribute *attr, char *buf) 638 struct device_attribute *attr, char *buf)
621{ 639{
622 struct kim_data_s *kim_data = dev_get_drvdata(dev); 640 struct kim_data_s *kim_data = dev_get_drvdata(dev);
623 return sprintf(buf, "%ld\n", kim_data->baud_rate); 641 return sprintf(buf, "%d\n", kim_data->baud_rate);
624} 642}
625 643
626static ssize_t show_flow_cntrl(struct device *dev, 644static ssize_t show_flow_cntrl(struct device *dev,
@@ -676,12 +694,16 @@ void st_kim_ref(struct st_data_s **core_data, int id)
676 struct kim_data_s *kim_gdata; 694 struct kim_data_s *kim_gdata;
677 /* get kim_gdata reference from platform device */ 695 /* get kim_gdata reference from platform device */
678 pdev = st_get_plat_device(id); 696 pdev = st_get_plat_device(id);
679 if (!pdev) { 697 if (!pdev)
680 *core_data = NULL; 698 goto err;
681 return;
682 }
683 kim_gdata = platform_get_drvdata(pdev); 699 kim_gdata = platform_get_drvdata(pdev);
700 if (!kim_gdata)
701 goto err;
702
684 *core_data = kim_gdata->core_data; 703 *core_data = kim_gdata->core_data;
704 return;
705err:
706 *core_data = NULL;
685} 707}
686 708
687static int kim_version_open(struct inode *i, struct file *f) 709static int kim_version_open(struct inode *i, struct file *f)
@@ -715,13 +737,53 @@ static const struct file_operations list_debugfs_fops = {
715 * board-*.c file 737 * board-*.c file
716 */ 738 */
717 739
740static const struct of_device_id kim_of_match[] = {
741{
742 .compatible = "kim",
743 },
744 {}
745};
746MODULE_DEVICE_TABLE(of, kim_of_match);
747
748static struct ti_st_plat_data *get_platform_data(struct device *dev)
749{
750 struct device_node *np = dev->of_node;
751 const u32 *dt_property;
752 int len;
753
754 dt_pdata = kzalloc(sizeof(*dt_pdata), GFP_KERNEL);
755
756 if (!dt_pdata)
757 pr_err("Can't allocate device_tree platform data\n");
758
759 dt_property = of_get_property(np, "dev_name", &len);
760 if (dt_property)
761 memcpy(&dt_pdata->dev_name, dt_property, len);
762 of_property_read_u32(np, "nshutdown_gpio",
763 &dt_pdata->nshutdown_gpio);
764 of_property_read_u32(np, "flow_cntrl", &dt_pdata->flow_cntrl);
765 of_property_read_u32(np, "baud_rate", &dt_pdata->baud_rate);
766
767 return dt_pdata;
768}
769
718static struct dentry *kim_debugfs_dir; 770static struct dentry *kim_debugfs_dir;
719static int kim_probe(struct platform_device *pdev) 771static int kim_probe(struct platform_device *pdev)
720{ 772{
721 struct kim_data_s *kim_gdata; 773 struct kim_data_s *kim_gdata;
722 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 774 struct ti_st_plat_data *pdata;
723 int err; 775 int err;
724 776
777 if (pdev->dev.of_node)
778 pdata = get_platform_data(&pdev->dev);
779 else
780 pdata = pdev->dev.platform_data;
781
782 if (pdata == NULL) {
783 dev_err(&pdev->dev, "Platform Data is missing\n");
784 return -ENXIO;
785 }
786
725 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) { 787 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) {
726 /* multiple devices could exist */ 788 /* multiple devices could exist */
727 st_kim_devices[pdev->id] = pdev; 789 st_kim_devices[pdev->id] = pdev;
@@ -750,14 +812,14 @@ static int kim_probe(struct platform_device *pdev)
750 kim_gdata->nshutdown = pdata->nshutdown_gpio; 812 kim_gdata->nshutdown = pdata->nshutdown_gpio;
751 err = gpio_request(kim_gdata->nshutdown, "kim"); 813 err = gpio_request(kim_gdata->nshutdown, "kim");
752 if (unlikely(err)) { 814 if (unlikely(err)) {
753 pr_err(" gpio %ld request failed ", kim_gdata->nshutdown); 815 pr_err(" gpio %d request failed ", kim_gdata->nshutdown);
754 return err; 816 return err;
755 } 817 }
756 818
757 /* Configure nShutdown GPIO as output=0 */ 819 /* Configure nShutdown GPIO as output=0 */
758 err = gpio_direction_output(kim_gdata->nshutdown, 0); 820 err = gpio_direction_output(kim_gdata->nshutdown, 0);
759 if (unlikely(err)) { 821 if (unlikely(err)) {
760 pr_err(" unable to configure gpio %ld", kim_gdata->nshutdown); 822 pr_err(" unable to configure gpio %d", kim_gdata->nshutdown);
761 return err; 823 return err;
762 } 824 }
763 /* get reference of pdev for request_firmware 825 /* get reference of pdev for request_firmware
@@ -781,8 +843,7 @@ static int kim_probe(struct platform_device *pdev)
781 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL); 843 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL);
782 if (!kim_debugfs_dir) { 844 if (!kim_debugfs_dir) {
783 pr_err(" debugfs entries creation failed "); 845 pr_err(" debugfs entries creation failed ");
784 err = -EIO; 846 return 0;
785 goto err_debugfs_dir;
786 } 847 }
787 848
788 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir, 849 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir,
@@ -791,9 +852,6 @@ static int kim_probe(struct platform_device *pdev)
791 kim_gdata, &list_debugfs_fops); 852 kim_gdata, &list_debugfs_fops);
792 return 0; 853 return 0;
793 854
794err_debugfs_dir:
795 sysfs_remove_group(&pdev->dev.kobj, &uim_attr_grp);
796
797err_sysfs_group: 855err_sysfs_group:
798 st_core_exit(kim_gdata->core_data); 856 st_core_exit(kim_gdata->core_data);
799 857
@@ -806,9 +864,16 @@ err_core_init:
806static int kim_remove(struct platform_device *pdev) 864static int kim_remove(struct platform_device *pdev)
807{ 865{
808 /* free the GPIOs requested */ 866 /* free the GPIOs requested */
809 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 867 struct ti_st_plat_data *pdata;
810 struct kim_data_s *kim_gdata; 868 struct kim_data_s *kim_gdata;
811 869
870 if (pdev->dev.of_node) {
871 pr_debug("use device tree data");
872 pdata = dt_pdata;
873 } else {
874 pdata = pdev->dev.platform_data;
875 }
876
812 kim_gdata = platform_get_drvdata(pdev); 877 kim_gdata = platform_get_drvdata(pdev);
813 878
814 /* Free the Bluetooth/FM/GPIO 879 /* Free the Bluetooth/FM/GPIO
@@ -826,27 +891,44 @@ static int kim_remove(struct platform_device *pdev)
826 891
827 kfree(kim_gdata); 892 kfree(kim_gdata);
828 kim_gdata = NULL; 893 kim_gdata = NULL;
894 kfree(dt_pdata);
895 dt_pdata = NULL;
896
829 return 0; 897 return 0;
830} 898}
831 899
832static int kim_suspend(struct platform_device *pdev, pm_message_t state) 900static int kim_suspend(struct platform_device *pdev, pm_message_t state)
833{ 901{
834 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 902 struct ti_st_plat_data *pdata;
903
904 if (pdev->dev.of_node) {
905 pr_debug("use device tree data");
906 pdata = dt_pdata;
907 } else {
908 pdata = pdev->dev.platform_data;
909 }
835 910
836 if (pdata->suspend) 911 if (pdata->suspend)
837 return pdata->suspend(pdev, state); 912 return pdata->suspend(pdev, state);
838 913
839 return -EOPNOTSUPP; 914 return 0;
840} 915}
841 916
842static int kim_resume(struct platform_device *pdev) 917static int kim_resume(struct platform_device *pdev)
843{ 918{
844 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 919 struct ti_st_plat_data *pdata;
920
921 if (pdev->dev.of_node) {
922 pr_debug("use device tree data");
923 pdata = dt_pdata;
924 } else {
925 pdata = pdev->dev.platform_data;
926 }
845 927
846 if (pdata->resume) 928 if (pdata->resume)
847 return pdata->resume(pdev); 929 return pdata->resume(pdev);
848 930
849 return -EOPNOTSUPP; 931 return 0;
850} 932}
851 933
852/**********************************************************************/ 934/**********************************************************************/
@@ -858,6 +940,8 @@ static struct platform_driver kim_platform_driver = {
858 .resume = kim_resume, 940 .resume = kim_resume,
859 .driver = { 941 .driver = {
860 .name = "kim", 942 .name = "kim",
943 .owner = THIS_MODULE,
944 .of_match_table = of_match_ptr(kim_of_match),
861 }, 945 },
862}; 946};
863 947
diff --git a/drivers/misc/ti-st/st_ll.c b/drivers/misc/ti-st/st_ll.c
index 93b4d67cc4a3..518e1b7f2f95 100644
--- a/drivers/misc/ti-st/st_ll.c
+++ b/drivers/misc/ti-st/st_ll.c
@@ -26,6 +26,7 @@
26#include <linux/ti_wilink_st.h> 26#include <linux/ti_wilink_st.h>
27 27
28/**********************************************************************/ 28/**********************************************************************/
29
29/* internal functions */ 30/* internal functions */
30static void send_ll_cmd(struct st_data_s *st_data, 31static void send_ll_cmd(struct st_data_s *st_data,
31 unsigned char cmd) 32 unsigned char cmd)
@@ -53,7 +54,13 @@ static void ll_device_want_to_sleep(struct st_data_s *st_data)
53 54
54 /* communicate to platform about chip asleep */ 55 /* communicate to platform about chip asleep */
55 kim_data = st_data->kim_data; 56 kim_data = st_data->kim_data;
56 pdata = kim_data->kim_pdev->dev.platform_data; 57 if (kim_data->kim_pdev->dev.of_node) {
58 pr_debug("use device tree data");
59 pdata = dt_pdata;
60 } else {
61 pdata = kim_data->kim_pdev->dev.platform_data;
62 }
63
57 if (pdata->chip_asleep) 64 if (pdata->chip_asleep)
58 pdata->chip_asleep(NULL); 65 pdata->chip_asleep(NULL);
59} 66}
@@ -86,7 +93,13 @@ static void ll_device_want_to_wakeup(struct st_data_s *st_data)
86 93
87 /* communicate to platform about chip wakeup */ 94 /* communicate to platform about chip wakeup */
88 kim_data = st_data->kim_data; 95 kim_data = st_data->kim_data;
89 pdata = kim_data->kim_pdev->dev.platform_data; 96 if (kim_data->kim_pdev->dev.of_node) {
97 pr_debug("use device tree data");
98 pdata = dt_pdata;
99 } else {
100 pdata = kim_data->kim_pdev->dev.platform_data;
101 }
102
90 if (pdata->chip_awake) 103 if (pdata->chip_awake)
91 pdata->chip_awake(NULL); 104 pdata->chip_awake(NULL);
92} 105}
diff --git a/drivers/misc/vmw_vmci/vmci_driver.c b/drivers/misc/vmw_vmci/vmci_driver.c
index 3dee7ae123e7..032d35cf93ca 100644
--- a/drivers/misc/vmw_vmci/vmci_driver.c
+++ b/drivers/misc/vmw_vmci/vmci_driver.c
@@ -113,5 +113,5 @@ module_exit(vmci_drv_exit);
113 113
114MODULE_AUTHOR("VMware, Inc."); 114MODULE_AUTHOR("VMware, Inc.");
115MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface."); 115MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface.");
116MODULE_VERSION("1.1.0.0-k"); 116MODULE_VERSION("1.1.1.0-k");
117MODULE_LICENSE("GPL v2"); 117MODULE_LICENSE("GPL v2");
diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c
index 1723a6e4f2e8..66fc9921fc85 100644
--- a/drivers/misc/vmw_vmci/vmci_host.c
+++ b/drivers/misc/vmw_vmci/vmci_host.c
@@ -218,13 +218,12 @@ static int drv_cp_harray_to_user(void __user *user_buf_uva,
218} 218}
219 219
220/* 220/*
221 * Sets up a given context for notify to work. Calls drv_map_bool_ptr() 221 * Sets up a given context for notify to work. Maps the notify
222 * which maps the notify boolean in user VA in kernel space. 222 * boolean in user VA into kernel space.
223 */ 223 */
224static int vmci_host_setup_notify(struct vmci_ctx *context, 224static int vmci_host_setup_notify(struct vmci_ctx *context,
225 unsigned long uva) 225 unsigned long uva)
226{ 226{
227 struct page *page;
228 int retval; 227 int retval;
229 228
230 if (context->notify_page) { 229 if (context->notify_page) {
@@ -243,14 +242,16 @@ static int vmci_host_setup_notify(struct vmci_ctx *context,
243 /* 242 /*
244 * Lock physical page backing a given user VA. 243 * Lock physical page backing a given user VA.
245 */ 244 */
246 retval = get_user_pages_fast(PAGE_ALIGN(uva), 1, 1, &page); 245 retval = get_user_pages_fast(uva, 1, 1, &context->notify_page);
247 if (retval != 1) 246 if (retval != 1) {
247 context->notify_page = NULL;
248 return VMCI_ERROR_GENERIC; 248 return VMCI_ERROR_GENERIC;
249 }
249 250
250 /* 251 /*
251 * Map the locked page and set up notify pointer. 252 * Map the locked page and set up notify pointer.
252 */ 253 */
253 context->notify = kmap(page) + (uva & (PAGE_SIZE - 1)); 254 context->notify = kmap(context->notify_page) + (uva & (PAGE_SIZE - 1));
254 vmci_ctx_check_signal_notify(context); 255 vmci_ctx_check_signal_notify(context);
255 256
256 return VMCI_SUCCESS; 257 return VMCI_SUCCESS;
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index 910e90bf16c6..8843a678f200 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -69,7 +69,8 @@ config YENTA
69 tristate "CardBus yenta-compatible bridge support" 69 tristate "CardBus yenta-compatible bridge support"
70 depends on PCI 70 depends on PCI
71 select CARDBUS if !EXPERT 71 select CARDBUS if !EXPERT
72 select PCCARD_NONSTATIC if PCMCIA != n 72 select PCCARD_NONSTATIC if PCMCIA != n && ISA
73 select PCCARD_PCI if PCMCIA !=n && !ISA
73 ---help--- 74 ---help---
74 This option enables support for CardBus host bridges. Virtually 75 This option enables support for CardBus host bridges. Virtually
75 all modern PCMCIA bridges are CardBus compatible. A "bridge" is 76 all modern PCMCIA bridges are CardBus compatible. A "bridge" is
@@ -109,7 +110,8 @@ config YENTA_TOSHIBA
109config PD6729 110config PD6729
110 tristate "Cirrus PD6729 compatible bridge support" 111 tristate "Cirrus PD6729 compatible bridge support"
111 depends on PCMCIA && PCI 112 depends on PCMCIA && PCI
112 select PCCARD_NONSTATIC 113 select PCCARD_NONSTATIC if PCMCIA != n && ISA
114 select PCCARD_PCI if PCMCIA !=n && !ISA
113 help 115 help
114 This provides support for the Cirrus PD6729 PCI-to-PCMCIA bridge 116 This provides support for the Cirrus PD6729 PCI-to-PCMCIA bridge
115 device, found in some older laptops and PCMCIA card readers. 117 device, found in some older laptops and PCMCIA card readers.
@@ -117,7 +119,8 @@ config PD6729
117config I82092 119config I82092
118 tristate "i82092 compatible bridge support" 120 tristate "i82092 compatible bridge support"
119 depends on PCMCIA && PCI 121 depends on PCMCIA && PCI
120 select PCCARD_NONSTATIC 122 select PCCARD_NONSTATIC if PCMCIA != n && ISA
123 select PCCARD_PCI if PCMCIA !=n && !ISA
121 help 124 help
122 This provides support for the Intel I82092AA PCI-to-PCMCIA bridge device, 125 This provides support for the Intel I82092AA PCI-to-PCMCIA bridge device,
123 found in some older laptops and more commonly in evaluation boards for the 126 found in some older laptops and more commonly in evaluation boards for the
@@ -287,6 +290,9 @@ config ELECTRA_CF
287 Say Y here to support the CompactFlash controller on the 290 Say Y here to support the CompactFlash controller on the
288 PA Semi Electra eval board. 291 PA Semi Electra eval board.
289 292
293config PCCARD_PCI
294 bool
295
290config PCCARD_NONSTATIC 296config PCCARD_NONSTATIC
291 bool 297 bool
292 298
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index 27e94b30cf96..f1a7ca04d89e 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_PCMCIA) += pcmcia.o
12pcmcia_rsrc-y += rsrc_mgr.o 12pcmcia_rsrc-y += rsrc_mgr.o
13pcmcia_rsrc-$(CONFIG_PCCARD_NONSTATIC) += rsrc_nonstatic.o 13pcmcia_rsrc-$(CONFIG_PCCARD_NONSTATIC) += rsrc_nonstatic.o
14pcmcia_rsrc-$(CONFIG_PCCARD_IODYN) += rsrc_iodyn.o 14pcmcia_rsrc-$(CONFIG_PCCARD_IODYN) += rsrc_iodyn.o
15pcmcia_rsrc-$(CONFIG_PCCARD_PCI) += rsrc_pci.o
15obj-$(CONFIG_PCCARD) += pcmcia_rsrc.o 16obj-$(CONFIG_PCCARD) += pcmcia_rsrc.o
16 17
17 18
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index 884a984216fe..64d0515b76bd 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -168,9 +168,12 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
168 } else { 168 } else {
169 u_int inc = 1, card_offset, flags; 169 u_int inc = 1, card_offset, flags;
170 170
171 if (addr > CISTPL_MAX_CIS_SIZE) 171 if (addr > CISTPL_MAX_CIS_SIZE) {
172 dev_dbg(&s->dev, 172 dev_dbg(&s->dev,
173 "attempt to read CIS mem at addr %#x", addr); 173 "attempt to read CIS mem at addr %#x", addr);
174 memset(ptr, 0xff, len);
175 return -1;
176 }
174 177
175 flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0); 178 flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0);
176 if (attr) { 179 if (attr) {
@@ -1383,7 +1386,7 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info)
1383 if (!s) 1386 if (!s)
1384 return -EINVAL; 1387 return -EINVAL;
1385 1388
1386 if (s->functions) { 1389 if (s->functions || !(s->state & SOCKET_PRESENT)) {
1387 WARN_ON(1); 1390 WARN_ON(1);
1388 return -EINVAL; 1391 return -EINVAL;
1389 } 1392 }
@@ -1448,10 +1451,26 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info)
1448done: 1451done:
1449 /* invalidate CIS cache on failure */ 1452 /* invalidate CIS cache on failure */
1450 if (!dev_ok || !ident_ok || !count) { 1453 if (!dev_ok || !ident_ok || !count) {
1451 mutex_lock(&s->ops_mutex); 1454#if defined(CONFIG_MTD_PCMCIA_ANONYMOUS)
1452 destroy_cis_cache(s); 1455 /* Set up as an anonymous card. If we don't have anonymous
1453 mutex_unlock(&s->ops_mutex); 1456 memory support then just error the card as there is no
1454 ret = -EIO; 1457 point trying to second guess.
1458
1459 Note: some cards have just a device entry, it may be
1460 worth extending support to cover these in future */
1461 if (!dev_ok || !ident_ok) {
1462 dev_info(&s->dev, "no CIS, assuming an anonymous memory card.\n");
1463 pcmcia_replace_cis(s, "\xFF", 1);
1464 count = 1;
1465 ret = 0;
1466 } else
1467#endif
1468 {
1469 mutex_lock(&s->ops_mutex);
1470 destroy_cis_cache(s);
1471 mutex_unlock(&s->ops_mutex);
1472 ret = -EIO;
1473 }
1455 } 1474 }
1456 1475
1457 if (info) 1476 if (info)
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h
index 7f1953f78b12..e86cd6b31773 100644
--- a/drivers/pcmcia/cs_internal.h
+++ b/drivers/pcmcia/cs_internal.h
@@ -80,9 +80,9 @@ struct pccard_resource_ops {
80 * Stuff internal to module "pcmcia_rsrc": 80 * Stuff internal to module "pcmcia_rsrc":
81 */ 81 */
82extern int static_init(struct pcmcia_socket *s); 82extern int static_init(struct pcmcia_socket *s);
83extern struct resource *pcmcia_make_resource(unsigned long start, 83extern struct resource *pcmcia_make_resource(resource_size_t start,
84 unsigned long end, 84 resource_size_t end,
85 int flags, const char *name); 85 unsigned long flags, const char *name);
86 86
87/* 87/*
88 * Stuff internal to module "pcmcia_core": 88 * Stuff internal to module "pcmcia_core":
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 757119b87146..d3baf0bfca9f 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -667,6 +667,9 @@ static void pcmcia_requery(struct pcmcia_socket *s)
667{ 667{
668 int has_pfc; 668 int has_pfc;
669 669
670 if (!(s->state & SOCKET_PRESENT))
671 return;
672
670 if (s->functions == 0) { 673 if (s->functions == 0) {
671 pcmcia_card_add(s); 674 pcmcia_card_add(s);
672 return; 675 return;
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index aa628ed0e9f4..df2cb70aef5b 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -30,8 +30,9 @@ int static_init(struct pcmcia_socket *s)
30 return 0; 30 return 0;
31} 31}
32 32
33struct resource *pcmcia_make_resource(unsigned long start, unsigned long end, 33struct resource *pcmcia_make_resource(resource_size_t start,
34 int flags, const char *name) 34 resource_size_t end,
35 unsigned long flags, const char *name)
35{ 36{
36 struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL); 37 struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL);
37 38
diff --git a/drivers/pcmcia/rsrc_pci.c b/drivers/pcmcia/rsrc_pci.c
new file mode 100644
index 000000000000..1f67b3ba70fb
--- /dev/null
+++ b/drivers/pcmcia/rsrc_pci.c
@@ -0,0 +1,173 @@
1#include <linux/slab.h>
2#include <linux/module.h>
3#include <linux/kernel.h>
4#include <linux/pci.h>
5
6#include <pcmcia/ss.h>
7#include <pcmcia/cistpl.h>
8#include "cs_internal.h"
9
10
11struct pcmcia_align_data {
12 unsigned long mask;
13 unsigned long offset;
14};
15
16static resource_size_t pcmcia_align(void *align_data,
17 const struct resource *res,
18 resource_size_t size, resource_size_t align)
19{
20 struct pcmcia_align_data *data = align_data;
21 resource_size_t start;
22
23 start = (res->start & ~data->mask) + data->offset;
24 if (start < res->start)
25 start += data->mask + 1;
26 return start;
27}
28
29static struct resource *find_io_region(struct pcmcia_socket *s,
30 unsigned long base, int num,
31 unsigned long align)
32{
33 struct resource *res = pcmcia_make_resource(0, num, IORESOURCE_IO,
34 dev_name(&s->dev));
35 struct pcmcia_align_data data;
36 int ret;
37
38 data.mask = align - 1;
39 data.offset = base & data.mask;
40
41 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1,
42 base, 0, pcmcia_align, &data);
43 if (ret != 0) {
44 kfree(res);
45 res = NULL;
46 }
47 return res;
48}
49
50static int res_pci_find_io(struct pcmcia_socket *s, unsigned int attr,
51 unsigned int *base, unsigned int num,
52 unsigned int align, struct resource **parent)
53{
54 int i, ret = 0;
55
56 /* Check for an already-allocated window that must conflict with
57 * what was asked for. It is a hack because it does not catch all
58 * potential conflicts, just the most obvious ones.
59 */
60 for (i = 0; i < MAX_IO_WIN; i++) {
61 if (!s->io[i].res)
62 continue;
63
64 if (!*base)
65 continue;
66
67 if ((s->io[i].res->start & (align-1)) == *base)
68 return -EBUSY;
69 }
70
71 for (i = 0; i < MAX_IO_WIN; i++) {
72 struct resource *res = s->io[i].res;
73 unsigned int try;
74
75 if (res && (res->flags & IORESOURCE_BITS) !=
76 (attr & IORESOURCE_BITS))
77 continue;
78
79 if (!res) {
80 if (align == 0)
81 align = 0x10000;
82
83 res = s->io[i].res = find_io_region(s, *base, num,
84 align);
85 if (!res)
86 return -EINVAL;
87
88 *base = res->start;
89 s->io[i].res->flags =
90 ((res->flags & ~IORESOURCE_BITS) |
91 (attr & IORESOURCE_BITS));
92 s->io[i].InUse = num;
93 *parent = res;
94 return 0;
95 }
96
97 /* Try to extend top of window */
98 try = res->end + 1;
99 if ((*base == 0) || (*base == try)) {
100 ret = adjust_resource(s->io[i].res, res->start,
101 resource_size(res) + num);
102 if (ret)
103 continue;
104 *base = try;
105 s->io[i].InUse += num;
106 *parent = res;
107 return 0;
108 }
109
110 /* Try to extend bottom of window */
111 try = res->start - num;
112 if ((*base == 0) || (*base == try)) {
113 ret = adjust_resource(s->io[i].res,
114 res->start - num,
115 resource_size(res) + num);
116 if (ret)
117 continue;
118 *base = try;
119 s->io[i].InUse += num;
120 *parent = res;
121 return 0;
122 }
123 }
124 return -EINVAL;
125}
126
127static struct resource *res_pci_find_mem(u_long base, u_long num,
128 u_long align, int low, struct pcmcia_socket *s)
129{
130 struct resource *res = pcmcia_make_resource(0, num, IORESOURCE_MEM,
131 dev_name(&s->dev));
132 struct pcmcia_align_data data;
133 unsigned long min;
134 int ret;
135
136 if (align < 0x20000)
137 align = 0x20000;
138 data.mask = align - 1;
139 data.offset = base & data.mask;
140
141 min = 0;
142 if (!low)
143 min = 0x100000UL;
144
145 ret = pci_bus_alloc_resource(s->cb_dev->bus,
146 res, num, 1, min, 0,
147 pcmcia_align, &data);
148
149 if (ret != 0) {
150 kfree(res);
151 res = NULL;
152 }
153 return res;
154}
155
156
157static int res_pci_init(struct pcmcia_socket *s)
158{
159 if (!s->cb_dev || !(s->features & SS_CAP_PAGE_REGS)) {
160 dev_err(&s->dev, "not supported by res_pci\n");
161 return -EOPNOTSUPP;
162 }
163 return 0;
164}
165
166struct pccard_resource_ops pccard_nonstatic_ops = {
167 .validate_mem = NULL,
168 .find_io = res_pci_find_io,
169 .find_mem = res_pci_find_mem,
170 .init = res_pci_init,
171 .exit = NULL,
172};
173EXPORT_SYMBOL(pccard_nonstatic_ops);
diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c
index 074569e77d22..facd43b8516c 100644
--- a/drivers/pnp/pnpbios/core.c
+++ b/drivers/pnp/pnpbios/core.c
@@ -181,7 +181,8 @@ static int pnp_dock_thread(void *unused)
181 break; 181 break;
182 default: 182 default:
183 pnpbios_print_status("pnp_dock_thread", status); 183 pnpbios_print_status("pnp_dock_thread", status);
184 continue; 184 printk(KERN_WARNING "PnPBIOS: disabling dock monitoring.\n");
185 complete_and_exit(&unload_sem, 0);
185 } 186 }
186 if (d != docked) { 187 if (d != docked) {
187 if (pnp_dock_event(d, &now) == 0) { 188 if (pnp_dock_event(d, &now) == 0) {
diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig
index 5a90914d856d..8a15c323c030 100644
--- a/drivers/uio/Kconfig
+++ b/drivers/uio/Kconfig
@@ -104,6 +104,26 @@ config UIO_NETX
104 To compile this driver as a module, choose M here; the module 104 To compile this driver as a module, choose M here; the module
105 will be called uio_netx. 105 will be called uio_netx.
106 106
107config UIO_FSL_ELBC_GPCM
108 tristate "eLBC/GPCM driver"
109 depends on FSL_LBC
110 help
111 Generic driver for accessing a peripheral connected to an eLBC port
112 that is running in GPCM mode. GPCM is an interface for simple lower
113 performance memories and memory-mapped devices. For devices using
114 FCM or UPM eLBC modes, other device-specific drivers are available.
115
116config UIO_FSL_ELBC_GPCM_NETX5152
117 bool "eLBC/GPCM netX 51/52 support"
118 depends on UIO_FSL_ELBC_GPCM
119 help
120 This will add support for netX 51/52 devices connected via eLBC/GPCM.
121 In particular, it implements interrupt handling. This can be used
122 together with the userspace netX stack from Hilscher.
123
124 Information about this hardware can be found at:
125 http://www.hilscher.com/netx
126
107config UIO_PRUSS 127config UIO_PRUSS
108 tristate "Texas Instruments PRUSS driver" 128 tristate "Texas Instruments PRUSS driver"
109 depends on ARCH_DAVINCI_DA850 129 depends on ARCH_DAVINCI_DA850
diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile
index d3218bde3aeb..8560dad52d0f 100644
--- a/drivers/uio/Makefile
+++ b/drivers/uio/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_UIO_PCI_GENERIC) += uio_pci_generic.o
8obj-$(CONFIG_UIO_NETX) += uio_netx.o 8obj-$(CONFIG_UIO_NETX) += uio_netx.o
9obj-$(CONFIG_UIO_PRUSS) += uio_pruss.o 9obj-$(CONFIG_UIO_PRUSS) += uio_pruss.o
10obj-$(CONFIG_UIO_MF624) += uio_mf624.o 10obj-$(CONFIG_UIO_MF624) += uio_mf624.o
11obj-$(CONFIG_UIO_FSL_ELBC_GPCM) += uio_fsl_elbc_gpcm.o
diff --git a/drivers/uio/uio_fsl_elbc_gpcm.c b/drivers/uio/uio_fsl_elbc_gpcm.c
new file mode 100644
index 000000000000..b6cac91c2ced
--- /dev/null
+++ b/drivers/uio/uio_fsl_elbc_gpcm.c
@@ -0,0 +1,499 @@
1/* uio_fsl_elbc_gpcm: UIO driver for eLBC/GPCM peripherals
2
3 Copyright (C) 2014 Linutronix GmbH
4 Author: John Ogness <john.ogness@linutronix.de>
5
6 This driver provides UIO access to memory of a peripheral connected
7 to the Freescale enhanced local bus controller (eLBC) interface
8 using the general purpose chip-select mode (GPCM).
9
10 Here is an example of the device tree entries:
11
12 localbus@ffe05000 {
13 ranges = <0x2 0x0 0x0 0xff810000 0x10000>;
14
15 dpm@2,0 {
16 compatible = "fsl,elbc-gpcm-uio";
17 reg = <0x2 0x0 0x10000>;
18 elbc-gpcm-br = <0xff810800>;
19 elbc-gpcm-or = <0xffff09f7>;
20 interrupt-parent = <&mpic>;
21 interrupts = <4 1>;
22 device_type = "netx5152";
23 uio_name = "netx_custom";
24 netx5152,init-win0-offset = <0x0>;
25 };
26 };
27
28 Only the entries reg (to identify bank) and elbc-gpcm-* (initial BR/OR
29 values) are required. The entries interrupt*, device_type, and uio_name
30 are optional (as well as any type-specific options such as
31 netx5152,init-win0-offset). As long as no interrupt handler is needed,
32 this driver can be used without any type-specific implementation.
33
34 The netx5152 type has been tested to work with the netX 51/52 hardware
35 from Hilscher using the Hilscher userspace netX stack.
36
37 The netx5152 type should serve as a model to add new type-specific
38 devices as needed.
39*/
40
41#include <linux/module.h>
42#include <linux/device.h>
43#include <linux/string.h>
44#include <linux/slab.h>
45#include <linux/platform_device.h>
46#include <linux/uio_driver.h>
47#include <linux/of_address.h>
48#include <linux/of_irq.h>
49
50#include <asm/fsl_lbc.h>
51
52#define MAX_BANKS 8
53
54struct fsl_elbc_gpcm {
55 struct device *dev;
56 struct fsl_lbc_regs __iomem *lbc;
57 u32 bank;
58 const char *name;
59
60 void (*init)(struct uio_info *info);
61 void (*shutdown)(struct uio_info *info, bool init_err);
62 irqreturn_t (*irq_handler)(int irq, struct uio_info *info);
63};
64
65static ssize_t reg_show(struct device *dev, struct device_attribute *attr,
66 char *buf);
67static ssize_t reg_store(struct device *dev, struct device_attribute *attr,
68 const char *buf, size_t count);
69
70DEVICE_ATTR(reg_br, S_IRUGO|S_IWUSR|S_IWGRP, reg_show, reg_store);
71DEVICE_ATTR(reg_or, S_IRUGO|S_IWUSR|S_IWGRP, reg_show, reg_store);
72
73static ssize_t reg_show(struct device *dev, struct device_attribute *attr,
74 char *buf)
75{
76 struct platform_device *pdev = to_platform_device(dev);
77 struct uio_info *info = platform_get_drvdata(pdev);
78 struct fsl_elbc_gpcm *priv = info->priv;
79 struct fsl_lbc_bank *bank = &priv->lbc->bank[priv->bank];
80
81 if (attr == &dev_attr_reg_br) {
82 return scnprintf(buf, PAGE_SIZE, "0x%08x\n",
83 in_be32(&bank->br));
84
85 } else if (attr == &dev_attr_reg_or) {
86 return scnprintf(buf, PAGE_SIZE, "0x%08x\n",
87 in_be32(&bank->or));
88 }
89
90 return 0;
91}
92
93static ssize_t reg_store(struct device *dev, struct device_attribute *attr,
94 const char *buf, size_t count)
95{
96 struct platform_device *pdev = to_platform_device(dev);
97 struct uio_info *info = platform_get_drvdata(pdev);
98 struct fsl_elbc_gpcm *priv = info->priv;
99 struct fsl_lbc_bank *bank = &priv->lbc->bank[priv->bank];
100 unsigned long val;
101 u32 reg_br_cur;
102 u32 reg_or_cur;
103 u32 reg_new;
104
105 /* parse use input */
106 if (kstrtoul(buf, 0, &val) != 0)
107 return -EINVAL;
108 reg_new = (u32)val;
109
110 /* read current values */
111 reg_br_cur = in_be32(&bank->br);
112 reg_or_cur = in_be32(&bank->or);
113
114 if (attr == &dev_attr_reg_br) {
115 /* not allowed to change effective base address */
116 if ((reg_br_cur & reg_or_cur & BR_BA) !=
117 (reg_new & reg_or_cur & BR_BA)) {
118 return -EINVAL;
119 }
120
121 /* not allowed to change mode */
122 if ((reg_new & BR_MSEL) != BR_MS_GPCM)
123 return -EINVAL;
124
125 /* write new value (force valid) */
126 out_be32(&bank->br, reg_new | BR_V);
127
128 } else if (attr == &dev_attr_reg_or) {
129 /* not allowed to change access mask */
130 if ((reg_or_cur & OR_GPCM_AM) != (reg_new & OR_GPCM_AM))
131 return -EINVAL;
132
133 /* write new value */
134 out_be32(&bank->or, reg_new);
135
136 } else {
137 return -EINVAL;
138 }
139
140 return count;
141}
142
143#ifdef CONFIG_UIO_FSL_ELBC_GPCM_NETX5152
144#define DPM_HOST_WIN0_OFFSET 0xff00
145#define DPM_HOST_INT_STAT0 0xe0
146#define DPM_HOST_INT_EN0 0xf0
147#define DPM_HOST_INT_MASK 0xe600ffff
148#define DPM_HOST_INT_GLOBAL_EN 0x80000000
149
150static irqreturn_t netx5152_irq_handler(int irq, struct uio_info *info)
151{
152 void __iomem *reg_int_en = info->mem[0].internal_addr +
153 DPM_HOST_WIN0_OFFSET +
154 DPM_HOST_INT_EN0;
155 void __iomem *reg_int_stat = info->mem[0].internal_addr +
156 DPM_HOST_WIN0_OFFSET +
157 DPM_HOST_INT_STAT0;
158
159 /* check if an interrupt is enabled and active */
160 if ((ioread32(reg_int_en) & ioread32(reg_int_stat) &
161 DPM_HOST_INT_MASK) == 0) {
162 return IRQ_NONE;
163 }
164
165 /* disable interrupts */
166 iowrite32(ioread32(reg_int_en) & ~DPM_HOST_INT_GLOBAL_EN, reg_int_en);
167
168 return IRQ_HANDLED;
169}
170
171static void netx5152_init(struct uio_info *info)
172{
173 unsigned long win0_offset = DPM_HOST_WIN0_OFFSET;
174 struct fsl_elbc_gpcm *priv = info->priv;
175 const void *prop;
176
177 /* get an optional initial win0 offset */
178 prop = of_get_property(priv->dev->of_node,
179 "netx5152,init-win0-offset", NULL);
180 if (prop)
181 win0_offset = of_read_ulong(prop, 1);
182
183 /* disable interrupts */
184 iowrite32(0, info->mem[0].internal_addr + win0_offset +
185 DPM_HOST_INT_EN0);
186}
187
188static void netx5152_shutdown(struct uio_info *info, bool init_err)
189{
190 if (init_err)
191 return;
192
193 /* disable interrupts */
194 iowrite32(0, info->mem[0].internal_addr + DPM_HOST_WIN0_OFFSET +
195 DPM_HOST_INT_EN0);
196}
197#endif
198
199static void setup_periph(struct fsl_elbc_gpcm *priv,
200 const char *type)
201{
202#ifdef CONFIG_UIO_FSL_ELBC_GPCM_NETX5152
203 if (strcmp(type, "netx5152") == 0) {
204 priv->irq_handler = netx5152_irq_handler;
205 priv->init = netx5152_init;
206 priv->shutdown = netx5152_shutdown;
207 priv->name = "netX 51/52";
208 return;
209 }
210#endif
211}
212
213static int check_of_data(struct fsl_elbc_gpcm *priv,
214 struct resource *res,
215 u32 reg_br, u32 reg_or)
216{
217 /* check specified bank */
218 if (priv->bank >= MAX_BANKS) {
219 dev_err(priv->dev, "invalid bank\n");
220 return -ENODEV;
221 }
222
223 /* check specified mode (BR_MS_GPCM is 0) */
224 if ((reg_br & BR_MSEL) != BR_MS_GPCM) {
225 dev_err(priv->dev, "unsupported mode\n");
226 return -ENODEV;
227 }
228
229 /* check specified mask vs. resource size */
230 if ((~(reg_or & OR_GPCM_AM) + 1) != resource_size(res)) {
231 dev_err(priv->dev, "address mask / size mismatch\n");
232 return -ENODEV;
233 }
234
235 /* check specified address */
236 if ((reg_br & reg_or & BR_BA) != fsl_lbc_addr(res->start)) {
237 dev_err(priv->dev, "base address mismatch\n");
238 return -ENODEV;
239 }
240
241 return 0;
242}
243
244static int get_of_data(struct fsl_elbc_gpcm *priv, struct device_node *node,
245 struct resource *res, u32 *reg_br,
246 u32 *reg_or, unsigned int *irq, char **name)
247{
248 const char *dt_name;
249 const char *type;
250 int ret;
251
252 /* get the memory resource */
253 ret = of_address_to_resource(node, 0, res);
254 if (ret) {
255 dev_err(priv->dev, "failed to get resource\n");
256 return ret;
257 }
258
259 /* get the bank number */
260 ret = of_property_read_u32(node, "reg", &priv->bank);
261 if (ret) {
262 dev_err(priv->dev, "failed to get bank number\n");
263 return ret;
264 }
265
266 /* get BR value to set */
267 ret = of_property_read_u32(node, "elbc-gpcm-br", reg_br);
268 if (ret) {
269 dev_err(priv->dev, "missing elbc-gpcm-br value\n");
270 return ret;
271 }
272
273 /* get OR value to set */
274 ret = of_property_read_u32(node, "elbc-gpcm-or", reg_or);
275 if (ret) {
276 dev_err(priv->dev, "missing elbc-gpcm-or value\n");
277 return ret;
278 }
279
280 /* get optional peripheral type */
281 priv->name = "generic";
282 if (of_property_read_string(node, "device_type", &type) == 0)
283 setup_periph(priv, type);
284
285 /* get optional irq value */
286 *irq = irq_of_parse_and_map(node, 0);
287
288 /* sanity check device tree data */
289 ret = check_of_data(priv, res, *reg_br, *reg_or);
290 if (ret)
291 return ret;
292
293 /* get optional uio name */
294 if (of_property_read_string(node, "uio_name", &dt_name) != 0)
295 dt_name = "eLBC_GPCM";
296 *name = kstrdup(dt_name, GFP_KERNEL);
297 if (!*name)
298 return -ENOMEM;
299
300 return 0;
301}
302
303static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev)
304{
305 struct device_node *node = pdev->dev.of_node;
306 struct fsl_elbc_gpcm *priv;
307 struct uio_info *info;
308 char *uio_name = NULL;
309 struct resource res;
310 unsigned int irq;
311 u32 reg_br_cur;
312 u32 reg_or_cur;
313 u32 reg_br_new;
314 u32 reg_or_new;
315 int ret;
316
317 if (!fsl_lbc_ctrl_dev || !fsl_lbc_ctrl_dev->regs)
318 return -ENODEV;
319
320 /* allocate private data */
321 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
322 if (!priv)
323 return -ENOMEM;
324 priv->dev = &pdev->dev;
325 priv->lbc = fsl_lbc_ctrl_dev->regs;
326
327 /* get device tree data */
328 ret = get_of_data(priv, node, &res, &reg_br_new, &reg_or_new,
329 &irq, &uio_name);
330 if (ret)
331 goto out_err0;
332
333 /* allocate UIO structure */
334 info = kzalloc(sizeof(*info), GFP_KERNEL);
335 if (!info) {
336 ret = -ENOMEM;
337 goto out_err0;
338 }
339
340 /* get current BR/OR values */
341 reg_br_cur = in_be32(&priv->lbc->bank[priv->bank].br);
342 reg_or_cur = in_be32(&priv->lbc->bank[priv->bank].or);
343
344 /* if bank already configured, make sure it matches */
345 if ((reg_br_cur & BR_V)) {
346 if ((reg_br_cur & BR_MSEL) != BR_MS_GPCM ||
347 (reg_br_cur & reg_or_cur & BR_BA)
348 != fsl_lbc_addr(res.start)) {
349 dev_err(priv->dev,
350 "bank in use by another peripheral\n");
351 ret = -ENODEV;
352 goto out_err1;
353 }
354
355 /* warn if behavior settings changing */
356 if ((reg_br_cur & ~(BR_BA | BR_V)) !=
357 (reg_br_new & ~(BR_BA | BR_V))) {
358 dev_warn(priv->dev,
359 "modifying BR settings: 0x%08x -> 0x%08x",
360 reg_br_cur, reg_br_new);
361 }
362 if ((reg_or_cur & ~OR_GPCM_AM) != (reg_or_new & ~OR_GPCM_AM)) {
363 dev_warn(priv->dev,
364 "modifying OR settings: 0x%08x -> 0x%08x",
365 reg_or_cur, reg_or_new);
366 }
367 }
368
369 /* configure the bank (force base address and GPCM) */
370 reg_br_new &= ~(BR_BA | BR_MSEL);
371 reg_br_new |= fsl_lbc_addr(res.start) | BR_MS_GPCM | BR_V;
372 out_be32(&priv->lbc->bank[priv->bank].or, reg_or_new);
373 out_be32(&priv->lbc->bank[priv->bank].br, reg_br_new);
374
375 /* map the memory resource */
376 info->mem[0].internal_addr = ioremap(res.start, resource_size(&res));
377 if (!info->mem[0].internal_addr) {
378 dev_err(priv->dev, "failed to map chip region\n");
379 ret = -ENODEV;
380 goto out_err1;
381 }
382
383 /* set all UIO data */
384 if (node->name)
385 info->mem[0].name = kstrdup(node->name, GFP_KERNEL);
386 info->mem[0].addr = res.start;
387 info->mem[0].size = resource_size(&res);
388 info->mem[0].memtype = UIO_MEM_PHYS;
389 info->priv = priv;
390 info->name = uio_name;
391 info->version = "0.0.1";
392 if (irq != NO_IRQ) {
393 if (priv->irq_handler) {
394 info->irq = irq;
395 info->irq_flags = IRQF_SHARED;
396 info->handler = priv->irq_handler;
397 } else {
398 irq = NO_IRQ;
399 dev_warn(priv->dev, "ignoring irq, no handler\n");
400 }
401 }
402
403 if (priv->init)
404 priv->init(info);
405
406 /* register UIO device */
407 if (uio_register_device(priv->dev, info) != 0) {
408 dev_err(priv->dev, "UIO registration failed\n");
409 ret = -ENODEV;
410 goto out_err2;
411 }
412
413 /* store private data */
414 platform_set_drvdata(pdev, info);
415
416 /* create sysfs files */
417 ret = device_create_file(priv->dev, &dev_attr_reg_br);
418 if (ret)
419 goto out_err3;
420 ret = device_create_file(priv->dev, &dev_attr_reg_or);
421 if (ret)
422 goto out_err4;
423
424 dev_info(priv->dev,
425 "eLBC/GPCM device (%s) at 0x%llx, bank %d, irq=%d\n",
426 priv->name, (unsigned long long)res.start, priv->bank,
427 irq != NO_IRQ ? irq : -1);
428
429 return 0;
430out_err4:
431 device_remove_file(priv->dev, &dev_attr_reg_br);
432out_err3:
433 platform_set_drvdata(pdev, NULL);
434 uio_unregister_device(info);
435out_err2:
436 if (priv->shutdown)
437 priv->shutdown(info, true);
438 iounmap(info->mem[0].internal_addr);
439out_err1:
440 kfree(info->mem[0].name);
441 kfree(info);
442out_err0:
443 kfree(uio_name);
444 kfree(priv);
445 return ret;
446}
447
448static int uio_fsl_elbc_gpcm_remove(struct platform_device *pdev)
449{
450 struct uio_info *info = platform_get_drvdata(pdev);
451 struct fsl_elbc_gpcm *priv = info->priv;
452
453 device_remove_file(priv->dev, &dev_attr_reg_or);
454 device_remove_file(priv->dev, &dev_attr_reg_br);
455 platform_set_drvdata(pdev, NULL);
456 uio_unregister_device(info);
457 if (priv->shutdown)
458 priv->shutdown(info, false);
459 iounmap(info->mem[0].internal_addr);
460 kfree(info->mem[0].name);
461 kfree(info->name);
462 kfree(info);
463 kfree(priv);
464
465 return 0;
466
467}
468
469static const struct of_device_id uio_fsl_elbc_gpcm_match[] = {
470 { .compatible = "fsl,elbc-gpcm-uio", },
471 {}
472};
473
474static struct platform_driver uio_fsl_elbc_gpcm_driver = {
475 .driver = {
476 .name = "fsl,elbc-gpcm-uio",
477 .owner = THIS_MODULE,
478 .of_match_table = uio_fsl_elbc_gpcm_match,
479 },
480 .probe = uio_fsl_elbc_gpcm_probe,
481 .remove = uio_fsl_elbc_gpcm_remove,
482};
483
484static int __init uio_fsl_elbc_gpcm_init(void)
485{
486 return platform_driver_register(&uio_fsl_elbc_gpcm_driver);
487}
488
489static void __exit uio_fsl_elbc_gpcm_exit(void)
490{
491 platform_driver_unregister(&uio_fsl_elbc_gpcm_driver);
492}
493
494module_init(uio_fsl_elbc_gpcm_init);
495module_exit(uio_fsl_elbc_gpcm_exit);
496
497MODULE_LICENSE("GPL");
498MODULE_AUTHOR("John Ogness <john.ogness@linutronix.de>");
499MODULE_DESCRIPTION("Freescale Enhanced Local Bus Controller GPCM driver");
diff --git a/drivers/uio/uio_pci_generic.c b/drivers/uio/uio_pci_generic.c
index 077ae12269ce..d0b508b68f3c 100644
--- a/drivers/uio/uio_pci_generic.c
+++ b/drivers/uio/uio_pci_generic.c
@@ -91,7 +91,8 @@ static int probe(struct pci_dev *pdev,
91 gdev->info.handler = irqhandler; 91 gdev->info.handler = irqhandler;
92 gdev->pdev = pdev; 92 gdev->pdev = pdev;
93 93
94 if (uio_register_device(&pdev->dev, &gdev->info)) 94 err = uio_register_device(&pdev->dev, &gdev->info);
95 if (err)
95 goto err_register; 96 goto err_register;
96 pci_set_drvdata(pdev, gdev); 97 pci_set_drvdata(pdev, gdev);
97 98
diff --git a/drivers/vme/vme.c b/drivers/vme/vme.c
index 7516030037a1..d95fb848dd03 100644
--- a/drivers/vme/vme.c
+++ b/drivers/vme/vme.c
@@ -502,7 +502,7 @@ int vme_master_get(struct vme_resource *resource, int *enabled,
502 image = list_entry(resource->entry, struct vme_master_resource, list); 502 image = list_entry(resource->entry, struct vme_master_resource, list);
503 503
504 if (bridge->master_get == NULL) { 504 if (bridge->master_get == NULL) {
505 printk(KERN_WARNING "vme_master_set not supported\n"); 505 printk(KERN_WARNING "%s not supported\n", __func__);
506 return -EINVAL; 506 return -EINVAL;
507 } 507 }
508 508
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index 5d3c54311f7a..3486b9082adb 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -179,15 +179,6 @@ struct coresight_device {
179#define sink_ops(csdev) csdev->ops->sink_ops 179#define sink_ops(csdev) csdev->ops->sink_ops
180#define link_ops(csdev) csdev->ops->link_ops 180#define link_ops(csdev) csdev->ops->link_ops
181 181
182#define CORESIGHT_DEBUGFS_ENTRY(__name, __entry_name, \
183 __mode, __get, __set, __fmt) \
184DEFINE_SIMPLE_ATTRIBUTE(__name ## _ops, __get, __set, __fmt); \
185static const struct coresight_ops_entry __name ## _entry = { \
186 .name = __entry_name, \
187 .mode = __mode, \
188 .ops = &__name ## _ops \
189}
190
191/** 182/**
192 * struct coresight_ops_sink - basic operations for a sink 183 * struct coresight_ops_sink - basic operations for a sink
193 * Operations available for sinks 184 * Operations available for sinks
@@ -236,13 +227,8 @@ coresight_register(struct coresight_desc *desc);
236extern void coresight_unregister(struct coresight_device *csdev); 227extern void coresight_unregister(struct coresight_device *csdev);
237extern int coresight_enable(struct coresight_device *csdev); 228extern int coresight_enable(struct coresight_device *csdev);
238extern void coresight_disable(struct coresight_device *csdev); 229extern void coresight_disable(struct coresight_device *csdev);
239extern int coresight_is_bit_set(u32 val, int position, int value);
240extern int coresight_timeout(void __iomem *addr, u32 offset, 230extern int coresight_timeout(void __iomem *addr, u32 offset,
241 int position, int value); 231 int position, int value);
242#ifdef CONFIG_OF
243extern struct coresight_platform_data *of_get_coresight_platform_data(
244 struct device *dev, struct device_node *node);
245#endif
246#else 232#else
247static inline struct coresight_device * 233static inline struct coresight_device *
248coresight_register(struct coresight_desc *desc) { return NULL; } 234coresight_register(struct coresight_desc *desc) { return NULL; }
@@ -250,14 +236,16 @@ static inline void coresight_unregister(struct coresight_device *csdev) {}
250static inline int 236static inline int
251coresight_enable(struct coresight_device *csdev) { return -ENOSYS; } 237coresight_enable(struct coresight_device *csdev) { return -ENOSYS; }
252static inline void coresight_disable(struct coresight_device *csdev) {} 238static inline void coresight_disable(struct coresight_device *csdev) {}
253static inline int coresight_is_bit_set(u32 val, int position, int value)
254 { return 0; }
255static inline int coresight_timeout(void __iomem *addr, u32 offset, 239static inline int coresight_timeout(void __iomem *addr, u32 offset,
256 int position, int value) { return 1; } 240 int position, int value) { return 1; }
241#endif
242
257#ifdef CONFIG_OF 243#ifdef CONFIG_OF
244extern struct coresight_platform_data *of_get_coresight_platform_data(
245 struct device *dev, struct device_node *node);
246#else
258static inline struct coresight_platform_data *of_get_coresight_platform_data( 247static inline struct coresight_platform_data *of_get_coresight_platform_data(
259 struct device *dev, struct device_node *node) { return NULL; } 248 struct device *dev, struct device_node *node) { return NULL; }
260#endif 249#endif
261#endif
262 250
263#endif 251#endif
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 476c685ca6f9..5a2ba674795e 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -57,6 +57,18 @@ struct hv_multipage_buffer {
57 u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT]; 57 u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
58}; 58};
59 59
60/*
61 * Multiple-page buffer array; the pfn array is variable size:
62 * The number of entries in the PFN array is determined by
63 * "len" and "offset".
64 */
65struct hv_mpb_array {
66 /* Length and Offset determines the # of pfns in the array */
67 u32 len;
68 u32 offset;
69 u64 pfn_array[];
70};
71
60/* 0x18 includes the proprietary packet header */ 72/* 0x18 includes the proprietary packet header */
61#define MAX_PAGE_BUFFER_PACKET (0x18 + \ 73#define MAX_PAGE_BUFFER_PACKET (0x18 + \
62 (sizeof(struct hv_page_buffer) * \ 74 (sizeof(struct hv_page_buffer) * \
@@ -722,7 +734,12 @@ struct vmbus_channel {
722 */ 734 */
723 void (*sc_creation_callback)(struct vmbus_channel *new_sc); 735 void (*sc_creation_callback)(struct vmbus_channel *new_sc);
724 736
725 spinlock_t sc_lock; 737 /*
738 * The spinlock to protect the structure. It is being used to protect
739 * test-and-set access to various attributes of the structure as well
740 * as all sc_list operations.
741 */
742 spinlock_t lock;
726 /* 743 /*
727 * All Sub-channels of a primary channel are linked here. 744 * All Sub-channels of a primary channel are linked here.
728 */ 745 */
@@ -814,6 +831,18 @@ struct vmbus_channel_packet_multipage_buffer {
814 struct hv_multipage_buffer range; 831 struct hv_multipage_buffer range;
815} __packed; 832} __packed;
816 833
834/* The format must be the same as struct vmdata_gpa_direct */
835struct vmbus_packet_mpb_array {
836 u16 type;
837 u16 dataoffset8;
838 u16 length8;
839 u16 flags;
840 u64 transactionid;
841 u32 reserved;
842 u32 rangecount; /* Always 1 in this case */
843 struct hv_mpb_array range;
844} __packed;
845
817 846
818extern int vmbus_open(struct vmbus_channel *channel, 847extern int vmbus_open(struct vmbus_channel *channel,
819 u32 send_ringbuffersize, 848 u32 send_ringbuffersize,
@@ -845,6 +874,13 @@ extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
845 u32 bufferlen, 874 u32 bufferlen,
846 u64 requestid); 875 u64 requestid);
847 876
877extern int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel,
878 struct vmbus_packet_mpb_array *mpb,
879 u32 desc_size,
880 void *buffer,
881 u32 bufferlen,
882 u64 requestid);
883
848extern int vmbus_establish_gpadl(struct vmbus_channel *channel, 884extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
849 void *kbuffer, 885 void *kbuffer,
850 u32 size, 886 u32 size,
diff --git a/include/linux/mei_cl_bus.h b/include/linux/mei_cl_bus.h
index 164aad1f9f12..0819d36a3a74 100644
--- a/include/linux/mei_cl_bus.h
+++ b/include/linux/mei_cl_bus.h
@@ -25,8 +25,8 @@ int __mei_cl_driver_register(struct mei_cl_driver *driver,
25 25
26void mei_cl_driver_unregister(struct mei_cl_driver *driver); 26void mei_cl_driver_unregister(struct mei_cl_driver *driver);
27 27
28int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length); 28ssize_t mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length);
29int mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length); 29ssize_t mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length);
30 30
31typedef void (*mei_cl_event_cb_t)(struct mei_cl_device *device, 31typedef void (*mei_cl_event_cb_t)(struct mei_cl_device *device,
32 u32 events, void *context); 32 u32 events, void *context);
diff --git a/include/linux/security.h b/include/linux/security.h
index ba96471c11ba..a1b7dbd127ff 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -1281,6 +1281,25 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
1281 * @alter contains the flag indicating whether changes are to be made. 1281 * @alter contains the flag indicating whether changes are to be made.
1282 * Return 0 if permission is granted. 1282 * Return 0 if permission is granted.
1283 * 1283 *
1284 * @binder_set_context_mgr
1285 * Check whether @mgr is allowed to be the binder context manager.
1286 * @mgr contains the task_struct for the task being registered.
1287 * Return 0 if permission is granted.
1288 * @binder_transaction
1289 * Check whether @from is allowed to invoke a binder transaction call
1290 * to @to.
1291 * @from contains the task_struct for the sending task.
1292 * @to contains the task_struct for the receiving task.
1293 * @binder_transfer_binder
1294 * Check whether @from is allowed to transfer a binder reference to @to.
1295 * @from contains the task_struct for the sending task.
1296 * @to contains the task_struct for the receiving task.
1297 * @binder_transfer_file
1298 * Check whether @from is allowed to transfer @file to @to.
1299 * @from contains the task_struct for the sending task.
1300 * @file contains the struct file being transferred.
1301 * @to contains the task_struct for the receiving task.
1302 *
1284 * @ptrace_access_check: 1303 * @ptrace_access_check:
1285 * Check permission before allowing the current process to trace the 1304 * Check permission before allowing the current process to trace the
1286 * @child process. 1305 * @child process.
@@ -1441,6 +1460,14 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
1441struct security_operations { 1460struct security_operations {
1442 char name[SECURITY_NAME_MAX + 1]; 1461 char name[SECURITY_NAME_MAX + 1];
1443 1462
1463 int (*binder_set_context_mgr) (struct task_struct *mgr);
1464 int (*binder_transaction) (struct task_struct *from,
1465 struct task_struct *to);
1466 int (*binder_transfer_binder) (struct task_struct *from,
1467 struct task_struct *to);
1468 int (*binder_transfer_file) (struct task_struct *from,
1469 struct task_struct *to, struct file *file);
1470
1444 int (*ptrace_access_check) (struct task_struct *child, unsigned int mode); 1471 int (*ptrace_access_check) (struct task_struct *child, unsigned int mode);
1445 int (*ptrace_traceme) (struct task_struct *parent); 1472 int (*ptrace_traceme) (struct task_struct *parent);
1446 int (*capget) (struct task_struct *target, 1473 int (*capget) (struct task_struct *target,
@@ -1739,6 +1766,13 @@ extern void __init security_fixup_ops(struct security_operations *ops);
1739 1766
1740 1767
1741/* Security operations */ 1768/* Security operations */
1769int security_binder_set_context_mgr(struct task_struct *mgr);
1770int security_binder_transaction(struct task_struct *from,
1771 struct task_struct *to);
1772int security_binder_transfer_binder(struct task_struct *from,
1773 struct task_struct *to);
1774int security_binder_transfer_file(struct task_struct *from,
1775 struct task_struct *to, struct file *file);
1742int security_ptrace_access_check(struct task_struct *child, unsigned int mode); 1776int security_ptrace_access_check(struct task_struct *child, unsigned int mode);
1743int security_ptrace_traceme(struct task_struct *parent); 1777int security_ptrace_traceme(struct task_struct *parent);
1744int security_capget(struct task_struct *target, 1778int security_capget(struct task_struct *target,
@@ -1927,6 +1961,30 @@ static inline int security_init(void)
1927 return 0; 1961 return 0;
1928} 1962}
1929 1963
1964static inline int security_binder_set_context_mgr(struct task_struct *mgr)
1965{
1966 return 0;
1967}
1968
1969static inline int security_binder_transaction(struct task_struct *from,
1970 struct task_struct *to)
1971{
1972 return 0;
1973}
1974
1975static inline int security_binder_transfer_binder(struct task_struct *from,
1976 struct task_struct *to)
1977{
1978 return 0;
1979}
1980
1981static inline int security_binder_transfer_file(struct task_struct *from,
1982 struct task_struct *to,
1983 struct file *file)
1984{
1985 return 0;
1986}
1987
1930static inline int security_ptrace_access_check(struct task_struct *child, 1988static inline int security_ptrace_access_check(struct task_struct *child,
1931 unsigned int mode) 1989 unsigned int mode)
1932{ 1990{
diff --git a/include/linux/ti_wilink_st.h b/include/linux/ti_wilink_st.h
index 884d6263e962..c78dcfeaf25f 100644
--- a/include/linux/ti_wilink_st.h
+++ b/include/linux/ti_wilink_st.h
@@ -86,6 +86,7 @@ struct st_proto_s {
86extern long st_register(struct st_proto_s *); 86extern long st_register(struct st_proto_s *);
87extern long st_unregister(struct st_proto_s *); 87extern long st_unregister(struct st_proto_s *);
88 88
89extern struct ti_st_plat_data *dt_pdata;
89 90
90/* 91/*
91 * header information used by st_core.c 92 * header information used by st_core.c
@@ -261,7 +262,7 @@ struct kim_data_s {
261 struct completion kim_rcvd, ldisc_installed; 262 struct completion kim_rcvd, ldisc_installed;
262 char resp_buffer[30]; 263 char resp_buffer[30];
263 const struct firmware *fw_entry; 264 const struct firmware *fw_entry;
264 long nshutdown; 265 unsigned nshutdown;
265 unsigned long rx_state; 266 unsigned long rx_state;
266 unsigned long rx_count; 267 unsigned long rx_count;
267 struct sk_buff *rx_skb; 268 struct sk_buff *rx_skb;
@@ -269,8 +270,8 @@ struct kim_data_s {
269 struct chip_version version; 270 struct chip_version version;
270 unsigned char ldisc_install; 271 unsigned char ldisc_install;
271 unsigned char dev_name[UART_DEV_NAME_LEN + 1]; 272 unsigned char dev_name[UART_DEV_NAME_LEN + 1];
272 unsigned char flow_cntrl; 273 unsigned flow_cntrl;
273 unsigned long baud_rate; 274 unsigned baud_rate;
274}; 275};
275 276
276/** 277/**
@@ -436,10 +437,10 @@ struct gps_event_hdr {
436 * 437 *
437 */ 438 */
438struct ti_st_plat_data { 439struct ti_st_plat_data {
439 long nshutdown_gpio; 440 u32 nshutdown_gpio;
440 unsigned char dev_name[UART_DEV_NAME_LEN]; /* uart name */ 441 unsigned char dev_name[UART_DEV_NAME_LEN]; /* uart name */
441 unsigned char flow_cntrl; /* flow control flag */ 442 u32 flow_cntrl; /* flow control flag */
442 unsigned long baud_rate; 443 u32 baud_rate;
443 int (*suspend)(struct platform_device *, pm_message_t); 444 int (*suspend)(struct platform_device *, pm_message_t);
444 int (*resume)(struct platform_device *); 445 int (*resume)(struct platform_device *);
445 int (*chip_enable) (struct kim_data_s *); 446 int (*chip_enable) (struct kim_data_s *);
diff --git a/security/capability.c b/security/capability.c
index d68c57a62bcf..070dd46f62f4 100644
--- a/security/capability.c
+++ b/security/capability.c
@@ -12,6 +12,29 @@
12 12
13#include <linux/security.h> 13#include <linux/security.h>
14 14
15static int cap_binder_set_context_mgr(struct task_struct *mgr)
16{
17 return 0;
18}
19
20static int cap_binder_transaction(struct task_struct *from,
21 struct task_struct *to)
22{
23 return 0;
24}
25
26static int cap_binder_transfer_binder(struct task_struct *from,
27 struct task_struct *to)
28{
29 return 0;
30}
31
32static int cap_binder_transfer_file(struct task_struct *from,
33 struct task_struct *to, struct file *file)
34{
35 return 0;
36}
37
15static int cap_syslog(int type) 38static int cap_syslog(int type)
16{ 39{
17 return 0; 40 return 0;
@@ -930,6 +953,10 @@ static void cap_audit_rule_free(void *lsmrule)
930 953
931void __init security_fixup_ops(struct security_operations *ops) 954void __init security_fixup_ops(struct security_operations *ops)
932{ 955{
956 set_to_cap_if_null(ops, binder_set_context_mgr);
957 set_to_cap_if_null(ops, binder_transaction);
958 set_to_cap_if_null(ops, binder_transfer_binder);
959 set_to_cap_if_null(ops, binder_transfer_file);
933 set_to_cap_if_null(ops, ptrace_access_check); 960 set_to_cap_if_null(ops, ptrace_access_check);
934 set_to_cap_if_null(ops, ptrace_traceme); 961 set_to_cap_if_null(ops, ptrace_traceme);
935 set_to_cap_if_null(ops, capget); 962 set_to_cap_if_null(ops, capget);
diff --git a/security/security.c b/security/security.c
index a0442b20f001..e81d5bbe7363 100644
--- a/security/security.c
+++ b/security/security.c
@@ -135,6 +135,29 @@ int __init register_security(struct security_operations *ops)
135 135
136/* Security operations */ 136/* Security operations */
137 137
138int security_binder_set_context_mgr(struct task_struct *mgr)
139{
140 return security_ops->binder_set_context_mgr(mgr);
141}
142
143int security_binder_transaction(struct task_struct *from,
144 struct task_struct *to)
145{
146 return security_ops->binder_transaction(from, to);
147}
148
149int security_binder_transfer_binder(struct task_struct *from,
150 struct task_struct *to)
151{
152 return security_ops->binder_transfer_binder(from, to);
153}
154
155int security_binder_transfer_file(struct task_struct *from,
156 struct task_struct *to, struct file *file)
157{
158 return security_ops->binder_transfer_file(from, to, file);
159}
160
138int security_ptrace_access_check(struct task_struct *child, unsigned int mode) 161int security_ptrace_access_check(struct task_struct *child, unsigned int mode)
139{ 162{
140#ifdef CONFIG_SECURITY_YAMA_STACKED 163#ifdef CONFIG_SECURITY_YAMA_STACKED
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 87a915656eab..29c39e0b03ed 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1920,6 +1920,74 @@ static inline u32 open_file_to_av(struct file *file)
1920 1920
1921/* Hook functions begin here. */ 1921/* Hook functions begin here. */
1922 1922
1923static int selinux_binder_set_context_mgr(struct task_struct *mgr)
1924{
1925 u32 mysid = current_sid();
1926 u32 mgrsid = task_sid(mgr);
1927
1928 return avc_has_perm(mysid, mgrsid, SECCLASS_BINDER,
1929 BINDER__SET_CONTEXT_MGR, NULL);
1930}
1931
1932static int selinux_binder_transaction(struct task_struct *from,
1933 struct task_struct *to)
1934{
1935 u32 mysid = current_sid();
1936 u32 fromsid = task_sid(from);
1937 u32 tosid = task_sid(to);
1938 int rc;
1939
1940 if (mysid != fromsid) {
1941 rc = avc_has_perm(mysid, fromsid, SECCLASS_BINDER,
1942 BINDER__IMPERSONATE, NULL);
1943 if (rc)
1944 return rc;
1945 }
1946
1947 return avc_has_perm(fromsid, tosid, SECCLASS_BINDER, BINDER__CALL,
1948 NULL);
1949}
1950
1951static int selinux_binder_transfer_binder(struct task_struct *from,
1952 struct task_struct *to)
1953{
1954 u32 fromsid = task_sid(from);
1955 u32 tosid = task_sid(to);
1956
1957 return avc_has_perm(fromsid, tosid, SECCLASS_BINDER, BINDER__TRANSFER,
1958 NULL);
1959}
1960
1961static int selinux_binder_transfer_file(struct task_struct *from,
1962 struct task_struct *to,
1963 struct file *file)
1964{
1965 u32 sid = task_sid(to);
1966 struct file_security_struct *fsec = file->f_security;
1967 struct inode *inode = file->f_path.dentry->d_inode;
1968 struct inode_security_struct *isec = inode->i_security;
1969 struct common_audit_data ad;
1970 int rc;
1971
1972 ad.type = LSM_AUDIT_DATA_PATH;
1973 ad.u.path = file->f_path;
1974
1975 if (sid != fsec->sid) {
1976 rc = avc_has_perm(sid, fsec->sid,
1977 SECCLASS_FD,
1978 FD__USE,
1979 &ad);
1980 if (rc)
1981 return rc;
1982 }
1983
1984 if (unlikely(IS_PRIVATE(inode)))
1985 return 0;
1986
1987 return avc_has_perm(sid, isec->sid, isec->sclass, file_to_av(file),
1988 &ad);
1989}
1990
1923static int selinux_ptrace_access_check(struct task_struct *child, 1991static int selinux_ptrace_access_check(struct task_struct *child,
1924 unsigned int mode) 1992 unsigned int mode)
1925{ 1993{
@@ -5797,6 +5865,11 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
5797static struct security_operations selinux_ops = { 5865static struct security_operations selinux_ops = {
5798 .name = "selinux", 5866 .name = "selinux",
5799 5867
5868 .binder_set_context_mgr = selinux_binder_set_context_mgr,
5869 .binder_transaction = selinux_binder_transaction,
5870 .binder_transfer_binder = selinux_binder_transfer_binder,
5871 .binder_transfer_file = selinux_binder_transfer_file,
5872
5800 .ptrace_access_check = selinux_ptrace_access_check, 5873 .ptrace_access_check = selinux_ptrace_access_check,
5801 .ptrace_traceme = selinux_ptrace_traceme, 5874 .ptrace_traceme = selinux_ptrace_traceme,
5802 .capget = selinux_capget, 5875 .capget = selinux_capget,
diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h
index be491a74c1ed..eccd61b3de8a 100644
--- a/security/selinux/include/classmap.h
+++ b/security/selinux/include/classmap.h
@@ -151,5 +151,7 @@ struct security_class_mapping secclass_map[] = {
151 { "kernel_service", { "use_as_override", "create_files_as", NULL } }, 151 { "kernel_service", { "use_as_override", "create_files_as", NULL } },
152 { "tun_socket", 152 { "tun_socket",
153 { COMMON_SOCK_PERMS, "attach_queue", NULL } }, 153 { COMMON_SOCK_PERMS, "attach_queue", NULL } },
154 { "binder", { "impersonate", "call", "set_context_mgr", "transfer",
155 NULL } },
154 { NULL } 156 { NULL }
155 }; 157 };
diff --git a/tools/hv/Makefile b/tools/hv/Makefile
index bd22f786a60c..99ffe61051a7 100644
--- a/tools/hv/Makefile
+++ b/tools/hv/Makefile
@@ -5,9 +5,9 @@ PTHREAD_LIBS = -lpthread
5WARNINGS = -Wall -Wextra 5WARNINGS = -Wall -Wextra
6CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) 6CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS)
7 7
8all: hv_kvp_daemon hv_vss_daemon 8all: hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon
9%: %.c 9%: %.c
10 $(CC) $(CFLAGS) -o $@ $^ 10 $(CC) $(CFLAGS) -o $@ $^
11 11
12clean: 12clean:
13 $(RM) hv_kvp_daemon hv_vss_daemon 13 $(RM) hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon
diff --git a/tools/hv/hv_fcopy_daemon.c b/tools/hv/hv_fcopy_daemon.c
index f437d739f37d..9445d8f264a4 100644
--- a/tools/hv/hv_fcopy_daemon.c
+++ b/tools/hv/hv_fcopy_daemon.c
@@ -43,15 +43,9 @@ static int hv_start_fcopy(struct hv_start_fcopy *smsg)
43 int error = HV_E_FAIL; 43 int error = HV_E_FAIL;
44 char *q, *p; 44 char *q, *p;
45 45
46 /*
47 * If possile append a path seperator to the path.
48 */
49 if (strlen((char *)smsg->path_name) < (W_MAX_PATH - 2))
50 strcat((char *)smsg->path_name, "/");
51
52 p = (char *)smsg->path_name; 46 p = (char *)smsg->path_name;
53 snprintf(target_fname, sizeof(target_fname), "%s/%s", 47 snprintf(target_fname, sizeof(target_fname), "%s/%s",
54 (char *)smsg->path_name, smsg->file_name); 48 (char *)smsg->path_name, (char *)smsg->file_name);
55 49
56 syslog(LOG_INFO, "Target file name: %s", target_fname); 50 syslog(LOG_INFO, "Target file name: %s", target_fname);
57 /* 51 /*
@@ -137,7 +131,7 @@ void print_usage(char *argv[])
137 131
138int main(int argc, char *argv[]) 132int main(int argc, char *argv[])
139{ 133{
140 int fd, fcopy_fd, len; 134 int fcopy_fd, len;
141 int error; 135 int error;
142 int daemonize = 1, long_index = 0, opt; 136 int daemonize = 1, long_index = 0, opt;
143 int version = FCOPY_CURRENT_VERSION; 137 int version = FCOPY_CURRENT_VERSION;
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 6a6432a20a1d..408bb076a234 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -147,7 +147,6 @@ static void kvp_release_lock(int pool)
147static void kvp_update_file(int pool) 147static void kvp_update_file(int pool)
148{ 148{
149 FILE *filep; 149 FILE *filep;
150 size_t bytes_written;
151 150
152 /* 151 /*
153 * We are going to write our in-memory registry out to 152 * We are going to write our in-memory registry out to
@@ -163,8 +162,7 @@ static void kvp_update_file(int pool)
163 exit(EXIT_FAILURE); 162 exit(EXIT_FAILURE);
164 } 163 }
165 164
166 bytes_written = fwrite(kvp_file_info[pool].records, 165 fwrite(kvp_file_info[pool].records, sizeof(struct kvp_record),
167 sizeof(struct kvp_record),
168 kvp_file_info[pool].num_records, filep); 166 kvp_file_info[pool].num_records, filep);
169 167
170 if (ferror(filep) || fclose(filep)) { 168 if (ferror(filep) || fclose(filep)) {
@@ -310,7 +308,7 @@ static int kvp_file_init(void)
310 return 0; 308 return 0;
311} 309}
312 310
313static int kvp_key_delete(int pool, const char *key, int key_size) 311static int kvp_key_delete(int pool, const __u8 *key, int key_size)
314{ 312{
315 int i; 313 int i;
316 int j, k; 314 int j, k;
@@ -353,8 +351,8 @@ static int kvp_key_delete(int pool, const char *key, int key_size)
353 return 1; 351 return 1;
354} 352}
355 353
356static int kvp_key_add_or_modify(int pool, const char *key, int key_size, const char *value, 354static int kvp_key_add_or_modify(int pool, const __u8 *key, int key_size,
357 int value_size) 355 const __u8 *value, int value_size)
358{ 356{
359 int i; 357 int i;
360 int num_records; 358 int num_records;
@@ -407,7 +405,7 @@ static int kvp_key_add_or_modify(int pool, const char *key, int key_size, const
407 return 0; 405 return 0;
408} 406}
409 407
410static int kvp_get_value(int pool, const char *key, int key_size, char *value, 408static int kvp_get_value(int pool, const __u8 *key, int key_size, __u8 *value,
411 int value_size) 409 int value_size)
412{ 410{
413 int i; 411 int i;
@@ -439,8 +437,8 @@ static int kvp_get_value(int pool, const char *key, int key_size, char *value,
439 return 1; 437 return 1;
440} 438}
441 439
442static int kvp_pool_enumerate(int pool, int index, char *key, int key_size, 440static int kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size,
443 char *value, int value_size) 441 __u8 *value, int value_size)
444{ 442{
445 struct kvp_record *record; 443 struct kvp_record *record;
446 444
@@ -661,7 +659,7 @@ static char *kvp_if_name_to_mac(char *if_name)
661 char *p, *x; 659 char *p, *x;
662 char buf[256]; 660 char buf[256];
663 char addr_file[256]; 661 char addr_file[256];
664 int i; 662 unsigned int i;
665 char *mac_addr = NULL; 663 char *mac_addr = NULL;
666 664
667 snprintf(addr_file, sizeof(addr_file), "%s%s%s", "/sys/class/net/", 665 snprintf(addr_file, sizeof(addr_file), "%s%s%s", "/sys/class/net/",
@@ -700,7 +698,7 @@ static char *kvp_mac_to_if_name(char *mac)
700 char buf[256]; 698 char buf[256];
701 char *kvp_net_dir = "/sys/class/net/"; 699 char *kvp_net_dir = "/sys/class/net/";
702 char dev_id[256]; 700 char dev_id[256];
703 int i; 701 unsigned int i;
704 702
705 dir = opendir(kvp_net_dir); 703 dir = opendir(kvp_net_dir);
706 if (dir == NULL) 704 if (dir == NULL)
@@ -750,7 +748,7 @@ static char *kvp_mac_to_if_name(char *mac)
750 748
751 749
752static void kvp_process_ipconfig_file(char *cmd, 750static void kvp_process_ipconfig_file(char *cmd,
753 char *config_buf, int len, 751 char *config_buf, unsigned int len,
754 int element_size, int offset) 752 int element_size, int offset)
755{ 753{
756 char buf[256]; 754 char buf[256];
@@ -768,7 +766,7 @@ static void kvp_process_ipconfig_file(char *cmd,
768 if (offset == 0) 766 if (offset == 0)
769 memset(config_buf, 0, len); 767 memset(config_buf, 0, len);
770 while ((p = fgets(buf, sizeof(buf), file)) != NULL) { 768 while ((p = fgets(buf, sizeof(buf), file)) != NULL) {
771 if ((len - strlen(config_buf)) < (element_size + 1)) 769 if (len < strlen(config_buf) + element_size + 1)
772 break; 770 break;
773 771
774 x = strchr(p, '\n'); 772 x = strchr(p, '\n');
@@ -916,7 +914,7 @@ static int kvp_process_ip_address(void *addrp,
916 914
917static int 915static int
918kvp_get_ip_info(int family, char *if_name, int op, 916kvp_get_ip_info(int family, char *if_name, int op,
919 void *out_buffer, int length) 917 void *out_buffer, unsigned int length)
920{ 918{
921 struct ifaddrs *ifap; 919 struct ifaddrs *ifap;
922 struct ifaddrs *curp; 920 struct ifaddrs *curp;
@@ -1019,8 +1017,7 @@ kvp_get_ip_info(int family, char *if_name, int op,
1019 weight += hweight32(&w[i]); 1017 weight += hweight32(&w[i]);
1020 1018
1021 sprintf(cidr_mask, "/%d", weight); 1019 sprintf(cidr_mask, "/%d", weight);
1022 if ((length - sn_offset) < 1020 if (length < sn_offset + strlen(cidr_mask) + 1)
1023 (strlen(cidr_mask) + 1))
1024 goto gather_ipaddr; 1021 goto gather_ipaddr;
1025 1022
1026 if (sn_offset == 0) 1023 if (sn_offset == 0)
@@ -1308,16 +1305,17 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
1308 if (error) 1305 if (error)
1309 goto setval_error; 1306 goto setval_error;
1310 1307
1308 /*
1309 * The dhcp_enabled flag is only for IPv4. In the case the host only
1310 * injects an IPv6 address, the flag is true, but we still need to
1311 * proceed to parse and pass the IPv6 information to the
1312 * disto-specific script hv_set_ifconfig.
1313 */
1311 if (new_val->dhcp_enabled) { 1314 if (new_val->dhcp_enabled) {
1312 error = kvp_write_file(file, "BOOTPROTO", "", "dhcp"); 1315 error = kvp_write_file(file, "BOOTPROTO", "", "dhcp");
1313 if (error) 1316 if (error)
1314 goto setval_error; 1317 goto setval_error;
1315 1318
1316 /*
1317 * We are done!.
1318 */
1319 goto setval_done;
1320
1321 } else { 1319 } else {
1322 error = kvp_write_file(file, "BOOTPROTO", "", "none"); 1320 error = kvp_write_file(file, "BOOTPROTO", "", "none");
1323 if (error) 1321 if (error)
@@ -1345,7 +1343,6 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
1345 if (error) 1343 if (error)
1346 goto setval_error; 1344 goto setval_error;
1347 1345
1348setval_done:
1349 fclose(file); 1346 fclose(file);
1350 1347
1351 /* 1348 /*