aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/removed/devfs2
-rw-r--r--Documentation/ABI/stable/sysfs-driver-usb-usbtmc10
-rw-r--r--Documentation/ABI/testing/sysfs-class2
-rw-r--r--Documentation/ABI/testing/sysfs-devices2
-rw-r--r--Documentation/ABI/testing/sysfs-devices-soc58
-rw-r--r--Documentation/ABI/testing/sysfs-driver-samsung-laptop2
-rw-r--r--Documentation/dynamic-debug-howto.txt30
-rw-r--r--Documentation/filesystems/debugfs.txt5
-rw-r--r--Documentation/ioctl/ioctl-number.txt2
-rw-r--r--Documentation/ko_KR/HOWTO2
-rw-r--r--Documentation/kobject.txt2
-rw-r--r--Documentation/zh_CN/HOWTO2
-rw-r--r--arch/x86/Kconfig3
-rw-r--r--arch/x86/crypto/aesni-intel_glue.c12
-rw-r--r--arch/x86/crypto/crc32c-intel.c11
-rw-r--r--arch/x86/crypto/ghash-clmulni-intel_glue.c12
-rw-r--r--arch/x86/include/asm/cpu_device_id.h13
-rw-r--r--arch/x86/include/asm/cpufeature.h1
-rw-r--r--arch/x86/kernel/cpu/Makefile1
-rw-r--r--arch/x86/kernel/cpu/match.c91
-rw-r--r--arch/x86/kernel/cpu/scattered.c1
-rw-r--r--arch/x86/kernel/microcode_core.c15
-rw-r--r--drivers/acpi/processor_driver.c1
-rw-r--r--drivers/acpi/processor_perflib.c22
-rw-r--r--drivers/base/Kconfig3
-rw-r--r--drivers/base/Makefile1
-rw-r--r--drivers/base/base.h6
-rw-r--r--drivers/base/bus.c6
-rw-r--r--drivers/base/core.c2
-rw-r--r--drivers/base/cpu.c11
-rw-r--r--drivers/base/dd.c148
-rw-r--r--drivers/base/driver.c35
-rw-r--r--drivers/base/soc.c183
-rw-r--r--drivers/cpufreq/cpufreq-nforce2.c8
-rw-r--r--drivers/cpufreq/e_powersaver.c20
-rw-r--r--drivers/cpufreq/elanfreq.c14
-rw-r--r--drivers/cpufreq/gx-suspmod.c9
-rw-r--r--drivers/cpufreq/longhaul.c8
-rw-r--r--drivers/cpufreq/longrun.c13
-rw-r--r--drivers/cpufreq/p4-clockmod.c17
-rw-r--r--drivers/cpufreq/powernow-k6.c12
-rw-r--r--drivers/cpufreq/powernow-k7.c14
-rw-r--r--drivers/cpufreq/powernow-k8.c19
-rw-r--r--drivers/cpufreq/sc520_freq.c14
-rw-r--r--drivers/cpufreq/speedstep-centrino.c24
-rw-r--r--drivers/cpufreq/speedstep-ich.c15
-rw-r--r--drivers/cpufreq/speedstep-lib.c1
-rw-r--r--drivers/cpufreq/speedstep-smi.c15
-rw-r--r--drivers/crypto/padlock-aes.c9
-rw-r--r--drivers/crypto/padlock-sha.c16
-rw-r--r--drivers/hid/hid-core.c6
-rw-r--r--drivers/hv/channel_mgmt.c87
-rw-r--r--drivers/hv/hv.c4
-rw-r--r--drivers/hv/hv_kvp.c253
-rw-r--r--drivers/hv/hv_kvp.h184
-rw-r--r--drivers/hv/hv_util.c3
-rw-r--r--drivers/hv/hyperv_vmbus.h5
-rw-r--r--drivers/hwmon/coretemp.c17
-rw-r--r--drivers/hwmon/via-cputemp.c16
-rw-r--r--drivers/idle/intel_idle.c112
-rw-r--r--drivers/input/gameport/gameport.c1
-rw-r--r--drivers/input/serio/serio.c1
-rw-r--r--drivers/media/video/cx18/cx18-alsa-main.c1
-rw-r--r--drivers/media/video/ivtv/ivtvfb.c2
-rw-r--r--drivers/media/video/s5p-fimc/fimc-mdevice.c5
-rw-r--r--drivers/media/video/s5p-tv/mixer_video.c1
-rw-r--r--drivers/net/phy/phy_device.c6
-rw-r--r--drivers/pci/pci-driver.c52
-rw-r--r--drivers/pci/xen-pcifront.c3
-rw-r--r--drivers/pcmcia/ds.c11
-rw-r--r--drivers/power/Kconfig14
-rw-r--r--drivers/power/Makefile1
-rw-r--r--drivers/power/ds2781_battery.c874
-rw-r--r--drivers/regulator/core.c4
-rw-r--r--drivers/s390/cio/ccwgroup.c2
-rw-r--r--drivers/s390/cio/device.c8
-rw-r--r--drivers/s390/net/smsgiucv_app.c9
-rw-r--r--drivers/ssb/main.c20
-rw-r--r--drivers/usb/core/driver.c66
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c12
-rw-r--r--drivers/w1/masters/w1-gpio.c3
-rw-r--r--drivers/w1/slaves/Kconfig13
-rw-r--r--drivers/w1/slaves/Makefile1
-rw-r--r--drivers/w1/slaves/w1_bq27000.c36
-rw-r--r--drivers/w1/slaves/w1_ds2781.c201
-rw-r--r--drivers/w1/slaves/w1_ds2781.h136
-rw-r--r--drivers/w1/w1_family.h1
-rw-r--r--fs/debugfs/inode.c149
-rw-r--r--fs/sysfs/dir.c224
-rw-r--r--fs/sysfs/inode.c11
-rw-r--r--fs/sysfs/mount.c2
-rw-r--r--fs/sysfs/sysfs.h17
-rw-r--r--include/acpi/processor.h1
-rw-r--r--include/linux/connector.h1
-rw-r--r--include/linux/cpu.h7
-rw-r--r--include/linux/device.h10
-rw-r--r--include/linux/dynamic_debug.h19
-rw-r--r--include/linux/errno.h1
-rw-r--r--include/linux/hyperv.h173
-rw-r--r--include/linux/mod_devicetable.h21
-rw-r--r--include/linux/netdevice.h8
-rw-r--r--include/linux/pci.h13
-rw-r--r--include/linux/printk.h8
-rw-r--r--include/linux/sys_soc.h37
-rw-r--r--lib/dma-debug.c3
-rw-r--r--lib/dynamic_debug.c270
-rw-r--r--lib/kobject_uevent.c19
-rw-r--r--scripts/mod/file2alias.c25
-rw-r--r--tools/hv/hv_kvp_daemon.c458
109 files changed, 3568 insertions, 1005 deletions
diff --git a/Documentation/ABI/removed/devfs b/Documentation/ABI/removed/devfs
index 8ffd28bf6598..0020c49933c4 100644
--- a/Documentation/ABI/removed/devfs
+++ b/Documentation/ABI/removed/devfs
@@ -1,6 +1,6 @@
1What: devfs 1What: devfs
2Date: July 2005 (scheduled), finally removed in kernel v2.6.18 2Date: July 2005 (scheduled), finally removed in kernel v2.6.18
3Contact: Greg Kroah-Hartman <gregkh@suse.de> 3Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4Description: 4Description:
5 devfs has been unmaintained for a number of years, has unfixable 5 devfs has been unmaintained for a number of years, has unfixable
6 races, contains a naming policy within the kernel that is 6 races, contains a naming policy within the kernel that is
diff --git a/Documentation/ABI/stable/sysfs-driver-usb-usbtmc b/Documentation/ABI/stable/sysfs-driver-usb-usbtmc
index 9a75fb22187d..23a43b8207e6 100644
--- a/Documentation/ABI/stable/sysfs-driver-usb-usbtmc
+++ b/Documentation/ABI/stable/sysfs-driver-usb-usbtmc
@@ -1,7 +1,7 @@
1What: /sys/bus/usb/drivers/usbtmc/devices/*/interface_capabilities 1What: /sys/bus/usb/drivers/usbtmc/devices/*/interface_capabilities
2What: /sys/bus/usb/drivers/usbtmc/devices/*/device_capabilities 2What: /sys/bus/usb/drivers/usbtmc/devices/*/device_capabilities
3Date: August 2008 3Date: August 2008
4Contact: Greg Kroah-Hartman <gregkh@suse.de> 4Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
5Description: 5Description:
6 These files show the various USB TMC capabilities as described 6 These files show the various USB TMC capabilities as described
7 by the device itself. The full description of the bitfields 7 by the device itself. The full description of the bitfields
@@ -15,7 +15,7 @@ Description:
15What: /sys/bus/usb/drivers/usbtmc/devices/*/usb488_interface_capabilities 15What: /sys/bus/usb/drivers/usbtmc/devices/*/usb488_interface_capabilities
16What: /sys/bus/usb/drivers/usbtmc/devices/*/usb488_device_capabilities 16What: /sys/bus/usb/drivers/usbtmc/devices/*/usb488_device_capabilities
17Date: August 2008 17Date: August 2008
18Contact: Greg Kroah-Hartman <gregkh@suse.de> 18Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19Description: 19Description:
20 These files show the various USB TMC capabilities as described 20 These files show the various USB TMC capabilities as described
21 by the device itself. The full description of the bitfields 21 by the device itself. The full description of the bitfields
@@ -29,7 +29,7 @@ Description:
29 29
30What: /sys/bus/usb/drivers/usbtmc/devices/*/TermChar 30What: /sys/bus/usb/drivers/usbtmc/devices/*/TermChar
31Date: August 2008 31Date: August 2008
32Contact: Greg Kroah-Hartman <gregkh@suse.de> 32Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33Description: 33Description:
34 This file is the TermChar value to be sent to the USB TMC 34 This file is the TermChar value to be sent to the USB TMC
35 device as described by the document, "Universal Serial Bus Test 35 device as described by the document, "Universal Serial Bus Test
@@ -42,7 +42,7 @@ Description:
42 42
43What: /sys/bus/usb/drivers/usbtmc/devices/*/TermCharEnabled 43What: /sys/bus/usb/drivers/usbtmc/devices/*/TermCharEnabled
44Date: August 2008 44Date: August 2008
45Contact: Greg Kroah-Hartman <gregkh@suse.de> 45Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
46Description: 46Description:
47 This file determines if the TermChar is to be sent to the 47 This file determines if the TermChar is to be sent to the
48 device on every transaction or not. For more details about 48 device on every transaction or not. For more details about
@@ -53,7 +53,7 @@ Description:
53 53
54What: /sys/bus/usb/drivers/usbtmc/devices/*/auto_abort 54What: /sys/bus/usb/drivers/usbtmc/devices/*/auto_abort
55Date: August 2008 55Date: August 2008
56Contact: Greg Kroah-Hartman <gregkh@suse.de> 56Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
57Description: 57Description:
58 This file determines if the the transaction of the USB TMC 58 This file determines if the the transaction of the USB TMC
59 device is to be automatically aborted if there is any error. 59 device is to be automatically aborted if there is any error.
diff --git a/Documentation/ABI/testing/sysfs-class b/Documentation/ABI/testing/sysfs-class
index 4b0cb891e46e..676530fcf747 100644
--- a/Documentation/ABI/testing/sysfs-class
+++ b/Documentation/ABI/testing/sysfs-class
@@ -1,6 +1,6 @@
1What: /sys/class/ 1What: /sys/class/
2Date: Febuary 2006 2Date: Febuary 2006
3Contact: Greg Kroah-Hartman <gregkh@suse.de> 3Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4Description: 4Description:
5 The /sys/class directory will consist of a group of 5 The /sys/class directory will consist of a group of
6 subdirectories describing individual classes of devices 6 subdirectories describing individual classes of devices
diff --git a/Documentation/ABI/testing/sysfs-devices b/Documentation/ABI/testing/sysfs-devices
index 6a25671ee5f6..5fcc94358b8d 100644
--- a/Documentation/ABI/testing/sysfs-devices
+++ b/Documentation/ABI/testing/sysfs-devices
@@ -1,6 +1,6 @@
1What: /sys/devices 1What: /sys/devices
2Date: February 2006 2Date: February 2006
3Contact: Greg Kroah-Hartman <gregkh@suse.de> 3Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4Description: 4Description:
5 The /sys/devices tree contains a snapshot of the 5 The /sys/devices tree contains a snapshot of the
6 internal state of the kernel device tree. Devices will 6 internal state of the kernel device tree. Devices will
diff --git a/Documentation/ABI/testing/sysfs-devices-soc b/Documentation/ABI/testing/sysfs-devices-soc
new file mode 100644
index 000000000000..6d9cc253f2b2
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-soc
@@ -0,0 +1,58 @@
1What: /sys/devices/socX
2Date: January 2012
3contact: Lee Jones <lee.jones@linaro.org>
4Description:
5 The /sys/devices/ directory contains a sub-directory for each
6 System-on-Chip (SoC) device on a running platform. Information
7 regarding each SoC can be obtained by reading sysfs files. This
8 functionality is only available if implemented by the platform.
9
10 The directory created for each SoC will also house information
11 about devices which are commonly contained in /sys/devices/platform.
12 It has been agreed that if an SoC device exists, its supported
13 devices would be better suited to appear as children of that SoC.
14
15What: /sys/devices/socX/machine
16Date: January 2012
17contact: Lee Jones <lee.jones@linaro.org>
18Description:
19 Read-only attribute common to all SoCs. Contains the SoC machine
20 name (e.g. Ux500).
21
22What: /sys/devices/socX/family
23Date: January 2012
24contact: Lee Jones <lee.jones@linaro.org>
25Description:
26 Read-only attribute common to all SoCs. Contains SoC family name
27 (e.g. DB8500).
28
29What: /sys/devices/socX/soc_id
30Date: January 2012
31contact: Lee Jones <lee.jones@linaro.org>
32Description:
33 Read-only attribute supported by most SoCs. In the case of
34 ST-Ericsson's chips this contains the SoC serial number.
35
36What: /sys/devices/socX/revision
37Date: January 2012
38contact: Lee Jones <lee.jones@linaro.org>
39Description:
40 Read-only attribute supported by most SoCs. Contains the SoC's
41 manufacturing revision number.
42
43What: /sys/devices/socX/process
44Date: January 2012
45contact: Lee Jones <lee.jones@linaro.org>
46Description:
47 Read-only attribute supported ST-Ericsson's silicon. Contains the
48 the process by which the silicon chip was manufactured.
49
50What: /sys/bus/soc
51Date: January 2012
52contact: Lee Jones <lee.jones@linaro.org>
53Description:
54 The /sys/bus/soc/ directory contains the usual sub-folders
55 expected under most buses. /sys/bus/soc/devices is of particular
56 interest, as it contains a symlink for each SoC device found on
57 the system. Each symlink points back into the aforementioned
58 /sys/devices/socX devices.
diff --git a/Documentation/ABI/testing/sysfs-driver-samsung-laptop b/Documentation/ABI/testing/sysfs-driver-samsung-laptop
index 0a810231aad4..e82e7c2b8f80 100644
--- a/Documentation/ABI/testing/sysfs-driver-samsung-laptop
+++ b/Documentation/ABI/testing/sysfs-driver-samsung-laptop
@@ -1,7 +1,7 @@
1What: /sys/devices/platform/samsung/performance_level 1What: /sys/devices/platform/samsung/performance_level
2Date: January 1, 2010 2Date: January 1, 2010
3KernelVersion: 2.6.33 3KernelVersion: 2.6.33
4Contact: Greg Kroah-Hartman <gregkh@suse.de> 4Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
5Description: Some Samsung laptops have different "performance levels" 5Description: Some Samsung laptops have different "performance levels"
6 that are can be modified by a function key, and by this 6 that are can be modified by a function key, and by this
7 sysfs file. These values don't always make a whole lot 7 sysfs file. These values don't always make a whole lot
diff --git a/Documentation/dynamic-debug-howto.txt b/Documentation/dynamic-debug-howto.txt
index f959909d7154..74e6c7782678 100644
--- a/Documentation/dynamic-debug-howto.txt
+++ b/Documentation/dynamic-debug-howto.txt
@@ -12,7 +12,7 @@ dynamically enabled per-callsite.
12Dynamic debug has even more useful features: 12Dynamic debug has even more useful features:
13 13
14 * Simple query language allows turning on and off debugging statements by 14 * Simple query language allows turning on and off debugging statements by
15 matching any combination of: 15 matching any combination of 0 or 1 of:
16 16
17 - source filename 17 - source filename
18 - function name 18 - function name
@@ -79,31 +79,24 @@ Command Language Reference
79========================== 79==========================
80 80
81At the lexical level, a command comprises a sequence of words separated 81At the lexical level, a command comprises a sequence of words separated
82by whitespace characters. Note that newlines are treated as word 82by spaces or tabs. So these are all equivalent:
83separators and do *not* end a command or allow multiple commands to
84be done together. So these are all equivalent:
85 83
86nullarbor:~ # echo -c 'file svcsock.c line 1603 +p' > 84nullarbor:~ # echo -c 'file svcsock.c line 1603 +p' >
87 <debugfs>/dynamic_debug/control 85 <debugfs>/dynamic_debug/control
88nullarbor:~ # echo -c ' file svcsock.c line 1603 +p ' > 86nullarbor:~ # echo -c ' file svcsock.c line 1603 +p ' >
89 <debugfs>/dynamic_debug/control 87 <debugfs>/dynamic_debug/control
90nullarbor:~ # echo -c 'file svcsock.c\nline 1603 +p' >
91 <debugfs>/dynamic_debug/control
92nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' > 88nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
93 <debugfs>/dynamic_debug/control 89 <debugfs>/dynamic_debug/control
94 90
95Commands are bounded by a write() system call. If you want to do 91Command submissions are bounded by a write() system call.
96multiple commands you need to do a separate "echo" for each, like: 92Multiple commands can be written together, separated by ';' or '\n'.
97 93
98nullarbor:~ # echo 'file svcsock.c line 1603 +p' > /proc/dprintk ;\ 94 ~# echo "func pnpacpi_get_resources +p; func pnp_assign_mem +p" \
99> echo 'file svcsock.c line 1563 +p' > /proc/dprintk 95 > <debugfs>/dynamic_debug/control
100 96
101or even like: 97If your query set is big, you can batch them too:
102 98
103nullarbor:~ # ( 99 ~# cat query-batch-file > <debugfs>/dynamic_debug/control
104> echo 'file svcsock.c line 1603 +p' ;\
105> echo 'file svcsock.c line 1563 +p' ;\
106> ) > /proc/dprintk
107 100
108At the syntactical level, a command comprises a sequence of match 101At the syntactical level, a command comprises a sequence of match
109specifications, followed by a flags change specification. 102specifications, followed by a flags change specification.
@@ -144,11 +137,12 @@ func
144 func svc_tcp_accept 137 func svc_tcp_accept
145 138
146file 139file
147 The given string is compared against either the full 140 The given string is compared against either the full pathname, the
148 pathname or the basename of the source file of each 141 src-root relative pathname, or the basename of the source file of
149 callsite. Examples: 142 each callsite. Examples:
150 143
151 file svcsock.c 144 file svcsock.c
145 file kernel/freezer.c
152 file /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svcsock.c 146 file /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svcsock.c
153 147
154module 148module
diff --git a/Documentation/filesystems/debugfs.txt b/Documentation/filesystems/debugfs.txt
index 6872c91bce35..4e2575873187 100644
--- a/Documentation/filesystems/debugfs.txt
+++ b/Documentation/filesystems/debugfs.txt
@@ -14,7 +14,10 @@ Debugfs is typically mounted with a command like:
14 14
15 mount -t debugfs none /sys/kernel/debug 15 mount -t debugfs none /sys/kernel/debug
16 16
17(Or an equivalent /etc/fstab line). 17(Or an equivalent /etc/fstab line).
18The debugfs root directory is accessible by anyone by default. To
19restrict access to the tree the "uid", "gid" and "mode" mount
20options can be used.
18 21
19Note that the debugfs API is exported GPL-only to modules. 22Note that the debugfs API is exported GPL-only to modules.
20 23
diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 4840334ea97b..5dbd9066ed16 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -189,7 +189,7 @@ Code Seq#(hex) Include File Comments
189'Y' all linux/cyclades.h 189'Y' all linux/cyclades.h
190'Z' 14-15 drivers/message/fusion/mptctl.h 190'Z' 14-15 drivers/message/fusion/mptctl.h
191'[' 00-07 linux/usb/tmc.h USB Test and Measurement Devices 191'[' 00-07 linux/usb/tmc.h USB Test and Measurement Devices
192 <mailto:gregkh@suse.de> 192 <mailto:gregkh@linuxfoundation.org>
193'a' all linux/atm*.h, linux/sonet.h ATM on linux 193'a' all linux/atm*.h, linux/sonet.h ATM on linux
194 <http://lrcwww.epfl.ch/> 194 <http://lrcwww.epfl.ch/>
195'b' 00-FF conflict! bit3 vme host bridge 195'b' 00-FF conflict! bit3 vme host bridge
diff --git a/Documentation/ko_KR/HOWTO b/Documentation/ko_KR/HOWTO
index ab5189ae3428..2f48f205fedc 100644
--- a/Documentation/ko_KR/HOWTO
+++ b/Documentation/ko_KR/HOWTO
@@ -354,7 +354,7 @@ Andrew Mortonì— ì˜í•´ ë°°í¬ëœ 실험ì ì¸ ì»¤ë„ íŒ¨ì¹˜ë“¤ì´ë‹¤. Andrew는
354 git.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git 354 git.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git
355 355
356 quilt trees: 356 quilt trees:
357 - USB, PCI, Driver Core, and I2C, Greg Kroah-Hartman < gregkh@suse.de> 357 - USB, PCI, Driver Core, and I2C, Greg Kroah-Hartman < gregkh@linuxfoundation.org>
358 kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/ 358 kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/
359 - x86-64, partly i386, Andi Kleen < ak@suse.de> 359 - x86-64, partly i386, Andi Kleen < ak@suse.de>
360 ftp.firstfloor.org:/pub/ak/x86_64/quilt/ 360 ftp.firstfloor.org:/pub/ak/x86_64/quilt/
diff --git a/Documentation/kobject.txt b/Documentation/kobject.txt
index 3ab2472509cb..49578cf1aea5 100644
--- a/Documentation/kobject.txt
+++ b/Documentation/kobject.txt
@@ -1,6 +1,6 @@
1Everything you never wanted to know about kobjects, ksets, and ktypes 1Everything you never wanted to know about kobjects, ksets, and ktypes
2 2
3Greg Kroah-Hartman <gregkh@suse.de> 3Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4 4
5Based on an original article by Jon Corbet for lwn.net written October 1, 5Based on an original article by Jon Corbet for lwn.net written October 1,
62003 and located at http://lwn.net/Articles/51437/ 62003 and located at http://lwn.net/Articles/51437/
diff --git a/Documentation/zh_CN/HOWTO b/Documentation/zh_CN/HOWTO
index faf976c0c731..7fba5aab9ef9 100644
--- a/Documentation/zh_CN/HOWTO
+++ b/Documentation/zh_CN/HOWTO
@@ -316,7 +316,7 @@ linux-kernel邮件列表中æä¾›å馈,告诉大家你é‡åˆ°äº†é—®é¢˜è¿˜æ˜¯ä¸
316 git.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git 316 git.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git
317 317
318 使用quilt管ç†çš„è¡¥ä¸é›†ï¼š 318 使用quilt管ç†çš„è¡¥ä¸é›†ï¼š
319 - USB, PCI, 驱动程åºæ ¸å¿ƒå’ŒI2C, Greg Kroah-Hartman <gregkh@suse.de> 319 - USB, PCI, 驱动程åºæ ¸å¿ƒå’ŒI2C, Greg Kroah-Hartman <gregkh@linuxfoundation.org>
320 kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/ 320 kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/
321 - x86-64, 部分i386, Andi Kleen <ak@suse.de> 321 - x86-64, 部分i386, Andi Kleen <ak@suse.de>
322 ftp.firstfloor.org:/pub/ak/x86_64/quilt/ 322 ftp.firstfloor.org:/pub/ak/x86_64/quilt/
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 09675d3e0ac3..d523a6c36835 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -180,6 +180,9 @@ config ARCH_HAS_DEFAULT_IDLE
180config ARCH_HAS_CACHE_LINE_SIZE 180config ARCH_HAS_CACHE_LINE_SIZE
181 def_bool y 181 def_bool y
182 182
183config ARCH_HAS_CPU_AUTOPROBE
184 def_bool y
185
183config HAVE_SETUP_PER_CPU_AREA 186config HAVE_SETUP_PER_CPU_AREA
184 def_bool y 187 def_bool y
185 188
diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
index 545d0ce59818..b3350bd32c60 100644
--- a/arch/x86/crypto/aesni-intel_glue.c
+++ b/arch/x86/crypto/aesni-intel_glue.c
@@ -28,6 +28,7 @@
28#include <crypto/aes.h> 28#include <crypto/aes.h>
29#include <crypto/cryptd.h> 29#include <crypto/cryptd.h>
30#include <crypto/ctr.h> 30#include <crypto/ctr.h>
31#include <asm/cpu_device_id.h>
31#include <asm/i387.h> 32#include <asm/i387.h>
32#include <asm/aes.h> 33#include <asm/aes.h>
33#include <crypto/scatterwalk.h> 34#include <crypto/scatterwalk.h>
@@ -1253,14 +1254,19 @@ static struct crypto_alg __rfc4106_alg = {
1253}; 1254};
1254#endif 1255#endif
1255 1256
1257
1258static const struct x86_cpu_id aesni_cpu_id[] = {
1259 X86_FEATURE_MATCH(X86_FEATURE_AES),
1260 {}
1261};
1262MODULE_DEVICE_TABLE(x86cpu, aesni_cpu_id);
1263
1256static int __init aesni_init(void) 1264static int __init aesni_init(void)
1257{ 1265{
1258 int err; 1266 int err;
1259 1267
1260 if (!cpu_has_aes) { 1268 if (!x86_match_cpu(aesni_cpu_id))
1261 printk(KERN_INFO "Intel AES-NI instructions are not detected.\n");
1262 return -ENODEV; 1269 return -ENODEV;
1263 }
1264 1270
1265 if ((err = crypto_fpu_init())) 1271 if ((err = crypto_fpu_init()))
1266 goto fpu_err; 1272 goto fpu_err;
diff --git a/arch/x86/crypto/crc32c-intel.c b/arch/x86/crypto/crc32c-intel.c
index b9d00261703c..493f959261f7 100644
--- a/arch/x86/crypto/crc32c-intel.c
+++ b/arch/x86/crypto/crc32c-intel.c
@@ -31,6 +31,7 @@
31#include <crypto/internal/hash.h> 31#include <crypto/internal/hash.h>
32 32
33#include <asm/cpufeature.h> 33#include <asm/cpufeature.h>
34#include <asm/cpu_device_id.h>
34 35
35#define CHKSUM_BLOCK_SIZE 1 36#define CHKSUM_BLOCK_SIZE 1
36#define CHKSUM_DIGEST_SIZE 4 37#define CHKSUM_DIGEST_SIZE 4
@@ -173,13 +174,17 @@ static struct shash_alg alg = {
173 } 174 }
174}; 175};
175 176
177static const struct x86_cpu_id crc32c_cpu_id[] = {
178 X86_FEATURE_MATCH(X86_FEATURE_XMM4_2),
179 {}
180};
181MODULE_DEVICE_TABLE(x86cpu, crc32c_cpu_id);
176 182
177static int __init crc32c_intel_mod_init(void) 183static int __init crc32c_intel_mod_init(void)
178{ 184{
179 if (cpu_has_xmm4_2) 185 if (!x86_match_cpu(crc32c_cpu_id))
180 return crypto_register_shash(&alg);
181 else
182 return -ENODEV; 186 return -ENODEV;
187 return crypto_register_shash(&alg);
183} 188}
184 189
185static void __exit crc32c_intel_mod_fini(void) 190static void __exit crc32c_intel_mod_fini(void)
diff --git a/arch/x86/crypto/ghash-clmulni-intel_glue.c b/arch/x86/crypto/ghash-clmulni-intel_glue.c
index 976aa64d9a20..b4bf0a63b520 100644
--- a/arch/x86/crypto/ghash-clmulni-intel_glue.c
+++ b/arch/x86/crypto/ghash-clmulni-intel_glue.c
@@ -20,6 +20,7 @@
20#include <crypto/gf128mul.h> 20#include <crypto/gf128mul.h>
21#include <crypto/internal/hash.h> 21#include <crypto/internal/hash.h>
22#include <asm/i387.h> 22#include <asm/i387.h>
23#include <asm/cpu_device_id.h>
23 24
24#define GHASH_BLOCK_SIZE 16 25#define GHASH_BLOCK_SIZE 16
25#define GHASH_DIGEST_SIZE 16 26#define GHASH_DIGEST_SIZE 16
@@ -294,15 +295,18 @@ static struct ahash_alg ghash_async_alg = {
294 }, 295 },
295}; 296};
296 297
298static const struct x86_cpu_id pcmul_cpu_id[] = {
299 X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ), /* Pickle-Mickle-Duck */
300 {}
301};
302MODULE_DEVICE_TABLE(x86cpu, pcmul_cpu_id);
303
297static int __init ghash_pclmulqdqni_mod_init(void) 304static int __init ghash_pclmulqdqni_mod_init(void)
298{ 305{
299 int err; 306 int err;
300 307
301 if (!cpu_has_pclmulqdq) { 308 if (!x86_match_cpu(pcmul_cpu_id))
302 printk(KERN_INFO "Intel PCLMULQDQ-NI instructions are not"
303 " detected.\n");
304 return -ENODEV; 309 return -ENODEV;
305 }
306 310
307 err = crypto_register_shash(&ghash_alg); 311 err = crypto_register_shash(&ghash_alg);
308 if (err) 312 if (err)
diff --git a/arch/x86/include/asm/cpu_device_id.h b/arch/x86/include/asm/cpu_device_id.h
new file mode 100644
index 000000000000..ff501e511d91
--- /dev/null
+++ b/arch/x86/include/asm/cpu_device_id.h
@@ -0,0 +1,13 @@
1#ifndef _CPU_DEVICE_ID
2#define _CPU_DEVICE_ID 1
3
4/*
5 * Declare drivers belonging to specific x86 CPUs
6 * Similar in spirit to pci_device_id and related PCI functions
7 */
8
9#include <linux/mod_devicetable.h>
10
11extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
12
13#endif
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 8d67d428b0f9..dcb839eebc76 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -177,6 +177,7 @@
177#define X86_FEATURE_PLN (7*32+ 5) /* Intel Power Limit Notification */ 177#define X86_FEATURE_PLN (7*32+ 5) /* Intel Power Limit Notification */
178#define X86_FEATURE_PTS (7*32+ 6) /* Intel Package Thermal Status */ 178#define X86_FEATURE_PTS (7*32+ 6) /* Intel Package Thermal Status */
179#define X86_FEATURE_DTS (7*32+ 7) /* Digital Thermal Sensor */ 179#define X86_FEATURE_DTS (7*32+ 7) /* Digital Thermal Sensor */
180#define X86_FEATURE_HW_PSTATE (7*32+ 8) /* AMD HW-PState */
180 181
181/* Virtualization flags: Linux defined, word 8 */ 182/* Virtualization flags: Linux defined, word 8 */
182#define X86_FEATURE_TPR_SHADOW (8*32+ 0) /* Intel TPR Shadow */ 183#define X86_FEATURE_TPR_SHADOW (8*32+ 0) /* Intel TPR Shadow */
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
index 25f24dccdcfa..6ab6aa2fdfdd 100644
--- a/arch/x86/kernel/cpu/Makefile
+++ b/arch/x86/kernel/cpu/Makefile
@@ -16,6 +16,7 @@ obj-y := intel_cacheinfo.o scattered.o topology.o
16obj-y += proc.o capflags.o powerflags.o common.o 16obj-y += proc.o capflags.o powerflags.o common.o
17obj-y += vmware.o hypervisor.o sched.o mshyperv.o 17obj-y += vmware.o hypervisor.o sched.o mshyperv.o
18obj-y += rdrand.o 18obj-y += rdrand.o
19obj-y += match.o
19 20
20obj-$(CONFIG_X86_32) += bugs.o 21obj-$(CONFIG_X86_32) += bugs.o
21obj-$(CONFIG_X86_64) += bugs_64.o 22obj-$(CONFIG_X86_64) += bugs_64.o
diff --git a/arch/x86/kernel/cpu/match.c b/arch/x86/kernel/cpu/match.c
new file mode 100644
index 000000000000..5502b289341b
--- /dev/null
+++ b/arch/x86/kernel/cpu/match.c
@@ -0,0 +1,91 @@
1#include <asm/cpu_device_id.h>
2#include <asm/processor.h>
3#include <linux/cpu.h>
4#include <linux/module.h>
5#include <linux/slab.h>
6
7/**
8 * x86_match_cpu - match current CPU again an array of x86_cpu_ids
9 * @match: Pointer to array of x86_cpu_ids. Last entry terminated with
10 * {}.
11 *
12 * Return the entry if the current CPU matches the entries in the
13 * passed x86_cpu_id match table. Otherwise NULL. The match table
14 * contains vendor (X86_VENDOR_*), family, model and feature bits or
15 * respective wildcard entries.
16 *
17 * A typical table entry would be to match a specific CPU
18 * { X86_VENDOR_INTEL, 6, 0x12 }
19 * or to match a specific CPU feature
20 * { X86_FEATURE_MATCH(X86_FEATURE_FOOBAR) }
21 *
22 * Fields can be wildcarded with %X86_VENDOR_ANY, %X86_FAMILY_ANY,
23 * %X86_MODEL_ANY, %X86_FEATURE_ANY or 0 (except for vendor)
24 *
25 * Arrays used to match for this should also be declared using
26 * MODULE_DEVICE_TABLE(x86_cpu, ...)
27 *
28 * This always matches against the boot cpu, assuming models and features are
29 * consistent over all CPUs.
30 */
31const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)
32{
33 const struct x86_cpu_id *m;
34 struct cpuinfo_x86 *c = &boot_cpu_data;
35
36 for (m = match; m->vendor | m->family | m->model | m->feature; m++) {
37 if (m->vendor != X86_VENDOR_ANY && c->x86_vendor != m->vendor)
38 continue;
39 if (m->family != X86_FAMILY_ANY && c->x86 != m->family)
40 continue;
41 if (m->model != X86_MODEL_ANY && c->x86_model != m->model)
42 continue;
43 if (m->feature != X86_FEATURE_ANY && !cpu_has(c, m->feature))
44 continue;
45 return m;
46 }
47 return NULL;
48}
49EXPORT_SYMBOL(x86_match_cpu);
50
51ssize_t arch_print_cpu_modalias(struct device *dev,
52 struct device_attribute *attr,
53 char *bufptr)
54{
55 int size = PAGE_SIZE;
56 int i, n;
57 char *buf = bufptr;
58
59 n = snprintf(buf, size, "x86cpu:vendor:%04X:family:%04X:"
60 "model:%04X:feature:",
61 boot_cpu_data.x86_vendor,
62 boot_cpu_data.x86,
63 boot_cpu_data.x86_model);
64 size -= n;
65 buf += n;
66 size -= 1;
67 for (i = 0; i < NCAPINTS*32; i++) {
68 if (boot_cpu_has(i)) {
69 n = snprintf(buf, size, ",%04X", i);
70 if (n >= size) {
71 WARN(1, "x86 features overflow page\n");
72 break;
73 }
74 size -= n;
75 buf += n;
76 }
77 }
78 *buf++ = '\n';
79 return buf - bufptr;
80}
81
82int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env)
83{
84 char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
85 if (buf) {
86 arch_print_cpu_modalias(NULL, NULL, buf);
87 add_uevent_var(env, "MODALIAS=%s", buf);
88 kfree(buf);
89 }
90 return 0;
91}
diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c
index c7f64e6f537a..addf9e82a7f2 100644
--- a/arch/x86/kernel/cpu/scattered.c
+++ b/arch/x86/kernel/cpu/scattered.c
@@ -40,6 +40,7 @@ void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c)
40 { X86_FEATURE_EPB, CR_ECX, 3, 0x00000006, 0 }, 40 { X86_FEATURE_EPB, CR_ECX, 3, 0x00000006, 0 },
41 { X86_FEATURE_XSAVEOPT, CR_EAX, 0, 0x0000000d, 1 }, 41 { X86_FEATURE_XSAVEOPT, CR_EAX, 0, 0x0000000d, 1 },
42 { X86_FEATURE_CPB, CR_EDX, 9, 0x80000007, 0 }, 42 { X86_FEATURE_CPB, CR_EDX, 9, 0x80000007, 0 },
43 { X86_FEATURE_HW_PSTATE, CR_EDX, 7, 0x80000007, 0 },
43 { X86_FEATURE_NPT, CR_EDX, 0, 0x8000000a, 0 }, 44 { X86_FEATURE_NPT, CR_EDX, 0, 0x8000000a, 0 },
44 { X86_FEATURE_LBRV, CR_EDX, 1, 0x8000000a, 0 }, 45 { X86_FEATURE_LBRV, CR_EDX, 1, 0x8000000a, 0 },
45 { X86_FEATURE_SVML, CR_EDX, 2, 0x8000000a, 0 }, 46 { X86_FEATURE_SVML, CR_EDX, 2, 0x8000000a, 0 },
diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
index fda91c307104..87a0f8688301 100644
--- a/arch/x86/kernel/microcode_core.c
+++ b/arch/x86/kernel/microcode_core.c
@@ -86,6 +86,7 @@
86 86
87#include <asm/microcode.h> 87#include <asm/microcode.h>
88#include <asm/processor.h> 88#include <asm/processor.h>
89#include <asm/cpu_device_id.h>
89 90
90MODULE_DESCRIPTION("Microcode Update Driver"); 91MODULE_DESCRIPTION("Microcode Update Driver");
91MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>"); 92MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>");
@@ -504,6 +505,20 @@ static struct notifier_block __refdata mc_cpu_notifier = {
504 .notifier_call = mc_cpu_callback, 505 .notifier_call = mc_cpu_callback,
505}; 506};
506 507
508#ifdef MODULE
509/* Autoload on Intel and AMD systems */
510static const struct x86_cpu_id microcode_id[] = {
511#ifdef CONFIG_MICROCODE_INTEL
512 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, },
513#endif
514#ifdef CONFIG_MICROCODE_AMD
515 { X86_VENDOR_AMD, X86_FAMILY_ANY, X86_MODEL_ANY, },
516#endif
517 {}
518};
519MODULE_DEVICE_TABLE(x86cpu, microcode_id);
520#endif
521
507static int __init microcode_init(void) 522static int __init microcode_init(void)
508{ 523{
509 struct cpuinfo_x86 *c = &cpu_data(0); 524 struct cpuinfo_x86 *c = &cpu_data(0);
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 8ae05ce18500..2801b418d7bb 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -474,6 +474,7 @@ static __ref int acpi_processor_start(struct acpi_processor *pr)
474 474
475#ifdef CONFIG_CPU_FREQ 475#ifdef CONFIG_CPU_FREQ
476 acpi_processor_ppc_has_changed(pr, 0); 476 acpi_processor_ppc_has_changed(pr, 0);
477 acpi_processor_load_module(pr);
477#endif 478#endif
478 acpi_processor_get_throttling_info(pr); 479 acpi_processor_get_throttling_info(pr);
479 acpi_processor_get_limit_info(pr); 480 acpi_processor_get_limit_info(pr);
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 85b32376dad7..0af48a8554cd 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -240,6 +240,28 @@ void acpi_processor_ppc_exit(void)
240 acpi_processor_ppc_status &= ~PPC_REGISTERED; 240 acpi_processor_ppc_status &= ~PPC_REGISTERED;
241} 241}
242 242
243/*
244 * Do a quick check if the systems looks like it should use ACPI
245 * cpufreq. We look at a _PCT method being available, but don't
246 * do a whole lot of sanity checks.
247 */
248void acpi_processor_load_module(struct acpi_processor *pr)
249{
250 static int requested;
251 acpi_status status = 0;
252 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
253
254 if (!arch_has_acpi_pdc() || requested)
255 return;
256 status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer);
257 if (!ACPI_FAILURE(status)) {
258 printk(KERN_INFO PREFIX "Requesting acpi_cpufreq\n");
259 request_module_nowait("acpi_cpufreq");
260 requested = 1;
261 }
262 kfree(buffer.pointer);
263}
264
243static int acpi_processor_get_performance_control(struct acpi_processor *pr) 265static int acpi_processor_get_performance_control(struct acpi_processor *pr)
244{ 266{
245 int result = 0; 267 int result = 0;
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 7be9f79018e9..9aa618acfe97 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -176,6 +176,9 @@ config GENERIC_CPU_DEVICES
176 bool 176 bool
177 default n 177 default n
178 178
179config SOC_BUS
180 bool
181
179source "drivers/base/regmap/Kconfig" 182source "drivers/base/regmap/Kconfig"
180 183
181config DMA_SHARED_BUFFER 184config DMA_SHARED_BUFFER
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 610f9997a403..b6d1b9c4200c 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_MODULES) += module.o
19endif 19endif
20obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o 20obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o
21obj-$(CONFIG_REGMAP) += regmap/ 21obj-$(CONFIG_REGMAP) += regmap/
22obj-$(CONFIG_SOC_BUS) += soc.o
22 23
23ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG 24ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
24 25
diff --git a/drivers/base/base.h b/drivers/base/base.h
index b858dfd9a37c..6ee17bb391a9 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -59,6 +59,10 @@ struct driver_private {
59 * @knode_parent - node in sibling list 59 * @knode_parent - node in sibling list
60 * @knode_driver - node in driver list 60 * @knode_driver - node in driver list
61 * @knode_bus - node in bus list 61 * @knode_bus - node in bus list
62 * @deferred_probe - entry in deferred_probe_list which is used to retry the
63 * binding of drivers which were unable to get all the resources needed by
64 * the device; typically because it depends on another driver getting
65 * probed first.
62 * @driver_data - private pointer for driver specific info. Will turn into a 66 * @driver_data - private pointer for driver specific info. Will turn into a
63 * list soon. 67 * list soon.
64 * @device - pointer back to the struct class that this structure is 68 * @device - pointer back to the struct class that this structure is
@@ -71,6 +75,7 @@ struct device_private {
71 struct klist_node knode_parent; 75 struct klist_node knode_parent;
72 struct klist_node knode_driver; 76 struct klist_node knode_driver;
73 struct klist_node knode_bus; 77 struct klist_node knode_bus;
78 struct list_head deferred_probe;
74 void *driver_data; 79 void *driver_data;
75 struct device *device; 80 struct device *device;
76}; 81};
@@ -105,6 +110,7 @@ extern void bus_remove_driver(struct device_driver *drv);
105 110
106extern void driver_detach(struct device_driver *drv); 111extern void driver_detach(struct device_driver *drv);
107extern int driver_probe_device(struct device_driver *drv, struct device *dev); 112extern int driver_probe_device(struct device_driver *drv, struct device *dev);
113extern void driver_deferred_probe_del(struct device *dev);
108static inline int driver_match_device(struct device_driver *drv, 114static inline int driver_match_device(struct device_driver *drv,
109 struct device *dev) 115 struct device *dev)
110{ 116{
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 40fb12288ce2..26a06b801b5b 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -1194,13 +1194,15 @@ EXPORT_SYMBOL_GPL(subsys_interface_register);
1194 1194
1195void subsys_interface_unregister(struct subsys_interface *sif) 1195void subsys_interface_unregister(struct subsys_interface *sif)
1196{ 1196{
1197 struct bus_type *subsys = sif->subsys; 1197 struct bus_type *subsys;
1198 struct subsys_dev_iter iter; 1198 struct subsys_dev_iter iter;
1199 struct device *dev; 1199 struct device *dev;
1200 1200
1201 if (!sif) 1201 if (!sif || !sif->subsys)
1202 return; 1202 return;
1203 1203
1204 subsys = sif->subsys;
1205
1204 mutex_lock(&subsys->p->mutex); 1206 mutex_lock(&subsys->p->mutex);
1205 list_del_init(&sif->node); 1207 list_del_init(&sif->node);
1206 if (sif->remove_dev) { 1208 if (sif->remove_dev) {
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 74dda4f697f9..7050a75dde38 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -921,6 +921,7 @@ int device_private_init(struct device *dev)
921 dev->p->device = dev; 921 dev->p->device = dev;
922 klist_init(&dev->p->klist_children, klist_children_get, 922 klist_init(&dev->p->klist_children, klist_children_get,
923 klist_children_put); 923 klist_children_put);
924 INIT_LIST_HEAD(&dev->p->deferred_probe);
924 return 0; 925 return 0;
925} 926}
926 927
@@ -1188,6 +1189,7 @@ void device_del(struct device *dev)
1188 device_remove_file(dev, &uevent_attr); 1189 device_remove_file(dev, &uevent_attr);
1189 device_remove_attrs(dev); 1190 device_remove_attrs(dev);
1190 bus_remove_device(dev); 1191 bus_remove_device(dev);
1192 driver_deferred_probe_del(dev);
1191 1193
1192 /* 1194 /*
1193 * Some platform devices are driven without driver attached 1195 * Some platform devices are driven without driver attached
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 4dabf5077c48..adf937bf4091 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -11,6 +11,7 @@
11#include <linux/device.h> 11#include <linux/device.h>
12#include <linux/node.h> 12#include <linux/node.h>
13#include <linux/gfp.h> 13#include <linux/gfp.h>
14#include <linux/slab.h>
14#include <linux/percpu.h> 15#include <linux/percpu.h>
15 16
16#include "base.h" 17#include "base.h"
@@ -244,6 +245,9 @@ int __cpuinit register_cpu(struct cpu *cpu, int num)
244 cpu->dev.id = num; 245 cpu->dev.id = num;
245 cpu->dev.bus = &cpu_subsys; 246 cpu->dev.bus = &cpu_subsys;
246 cpu->dev.release = cpu_device_release; 247 cpu->dev.release = cpu_device_release;
248#ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
249 cpu->dev.bus->uevent = arch_cpu_uevent;
250#endif
247 error = device_register(&cpu->dev); 251 error = device_register(&cpu->dev);
248 if (!error && cpu->hotpluggable) 252 if (!error && cpu->hotpluggable)
249 register_cpu_control(cpu); 253 register_cpu_control(cpu);
@@ -268,6 +272,10 @@ struct device *get_cpu_device(unsigned cpu)
268} 272}
269EXPORT_SYMBOL_GPL(get_cpu_device); 273EXPORT_SYMBOL_GPL(get_cpu_device);
270 274
275#ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
276static DEVICE_ATTR(modalias, 0444, arch_print_cpu_modalias, NULL);
277#endif
278
271static struct attribute *cpu_root_attrs[] = { 279static struct attribute *cpu_root_attrs[] = {
272#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE 280#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
273 &dev_attr_probe.attr, 281 &dev_attr_probe.attr,
@@ -278,6 +286,9 @@ static struct attribute *cpu_root_attrs[] = {
278 &cpu_attrs[2].attr.attr, 286 &cpu_attrs[2].attr.attr,
279 &dev_attr_kernel_max.attr, 287 &dev_attr_kernel_max.attr,
280 &dev_attr_offline.attr, 288 &dev_attr_offline.attr,
289#ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
290 &dev_attr_modalias.attr,
291#endif
281 NULL 292 NULL
282}; 293};
283 294
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 142e3d600f14..1b1cbb571d38 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -28,6 +28,141 @@
28#include "base.h" 28#include "base.h"
29#include "power/power.h" 29#include "power/power.h"
30 30
31/*
32 * Deferred Probe infrastructure.
33 *
34 * Sometimes driver probe order matters, but the kernel doesn't always have
35 * dependency information which means some drivers will get probed before a
36 * resource it depends on is available. For example, an SDHCI driver may
37 * first need a GPIO line from an i2c GPIO controller before it can be
38 * initialized. If a required resource is not available yet, a driver can
39 * request probing to be deferred by returning -EPROBE_DEFER from its probe hook
40 *
41 * Deferred probe maintains two lists of devices, a pending list and an active
42 * list. A driver returning -EPROBE_DEFER causes the device to be added to the
43 * pending list. A successful driver probe will trigger moving all devices
44 * from the pending to the active list so that the workqueue will eventually
45 * retry them.
46 *
47 * The deferred_probe_mutex must be held any time the deferred_probe_*_list
48 * of the (struct device*)->p->deferred_probe pointers are manipulated
49 */
50static DEFINE_MUTEX(deferred_probe_mutex);
51static LIST_HEAD(deferred_probe_pending_list);
52static LIST_HEAD(deferred_probe_active_list);
53static struct workqueue_struct *deferred_wq;
54
55/**
56 * deferred_probe_work_func() - Retry probing devices in the active list.
57 */
58static void deferred_probe_work_func(struct work_struct *work)
59{
60 struct device *dev;
61 struct device_private *private;
62 /*
63 * This block processes every device in the deferred 'active' list.
64 * Each device is removed from the active list and passed to
65 * bus_probe_device() to re-attempt the probe. The loop continues
66 * until every device in the active list is removed and retried.
67 *
68 * Note: Once the device is removed from the list and the mutex is
69 * released, it is possible for the device get freed by another thread
70 * and cause a illegal pointer dereference. This code uses
71 * get/put_device() to ensure the device structure cannot disappear
72 * from under our feet.
73 */
74 mutex_lock(&deferred_probe_mutex);
75 while (!list_empty(&deferred_probe_active_list)) {
76 private = list_first_entry(&deferred_probe_active_list,
77 typeof(*dev->p), deferred_probe);
78 dev = private->device;
79 list_del_init(&private->deferred_probe);
80
81 get_device(dev);
82
83 /*
84 * Drop the mutex while probing each device; the probe path may
85 * manipulate the deferred list
86 */
87 mutex_unlock(&deferred_probe_mutex);
88 dev_dbg(dev, "Retrying from deferred list\n");
89 bus_probe_device(dev);
90 mutex_lock(&deferred_probe_mutex);
91
92 put_device(dev);
93 }
94 mutex_unlock(&deferred_probe_mutex);
95}
96static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
97
98static void driver_deferred_probe_add(struct device *dev)
99{
100 mutex_lock(&deferred_probe_mutex);
101 if (list_empty(&dev->p->deferred_probe)) {
102 dev_dbg(dev, "Added to deferred list\n");
103 list_add(&dev->p->deferred_probe, &deferred_probe_pending_list);
104 }
105 mutex_unlock(&deferred_probe_mutex);
106}
107
108void driver_deferred_probe_del(struct device *dev)
109{
110 mutex_lock(&deferred_probe_mutex);
111 if (!list_empty(&dev->p->deferred_probe)) {
112 dev_dbg(dev, "Removed from deferred list\n");
113 list_del_init(&dev->p->deferred_probe);
114 }
115 mutex_unlock(&deferred_probe_mutex);
116}
117
118static bool driver_deferred_probe_enable = false;
119/**
120 * driver_deferred_probe_trigger() - Kick off re-probing deferred devices
121 *
122 * This functions moves all devices from the pending list to the active
123 * list and schedules the deferred probe workqueue to process them. It
124 * should be called anytime a driver is successfully bound to a device.
125 */
126static void driver_deferred_probe_trigger(void)
127{
128 if (!driver_deferred_probe_enable)
129 return;
130
131 /*
132 * A successful probe means that all the devices in the pending list
133 * should be triggered to be reprobed. Move all the deferred devices
134 * into the active list so they can be retried by the workqueue
135 */
136 mutex_lock(&deferred_probe_mutex);
137 list_splice_tail_init(&deferred_probe_pending_list,
138 &deferred_probe_active_list);
139 mutex_unlock(&deferred_probe_mutex);
140
141 /*
142 * Kick the re-probe thread. It may already be scheduled, but it is
143 * safe to kick it again.
144 */
145 queue_work(deferred_wq, &deferred_probe_work);
146}
147
148/**
149 * deferred_probe_initcall() - Enable probing of deferred devices
150 *
151 * We don't want to get in the way when the bulk of drivers are getting probed.
152 * Instead, this initcall makes sure that deferred probing is delayed until
153 * late_initcall time.
154 */
155static int deferred_probe_initcall(void)
156{
157 deferred_wq = create_singlethread_workqueue("deferwq");
158 if (WARN_ON(!deferred_wq))
159 return -ENOMEM;
160
161 driver_deferred_probe_enable = true;
162 driver_deferred_probe_trigger();
163 return 0;
164}
165late_initcall(deferred_probe_initcall);
31 166
32static void driver_bound(struct device *dev) 167static void driver_bound(struct device *dev)
33{ 168{
@@ -42,6 +177,13 @@ static void driver_bound(struct device *dev)
42 177
43 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices); 178 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
44 179
180 /*
181 * Make sure the device is no longer in one of the deferred lists and
182 * kick off retrying all pending devices
183 */
184 driver_deferred_probe_del(dev);
185 driver_deferred_probe_trigger();
186
45 if (dev->bus) 187 if (dev->bus)
46 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, 188 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
47 BUS_NOTIFY_BOUND_DRIVER, dev); 189 BUS_NOTIFY_BOUND_DRIVER, dev);
@@ -142,7 +284,11 @@ probe_failed:
142 driver_sysfs_remove(dev); 284 driver_sysfs_remove(dev);
143 dev->driver = NULL; 285 dev->driver = NULL;
144 286
145 if (ret != -ENODEV && ret != -ENXIO) { 287 if (ret == -EPROBE_DEFER) {
288 /* Driver requested deferred probing */
289 dev_info(dev, "Driver %s requests probe deferral\n", drv->name);
290 driver_deferred_probe_add(dev);
291 } else if (ret != -ENODEV && ret != -ENXIO) {
146 /* driver matched but the probe failed */ 292 /* driver matched but the probe failed */
147 printk(KERN_WARNING 293 printk(KERN_WARNING
148 "%s: probe of %s failed with error %d\n", 294 "%s: probe of %s failed with error %d\n",
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index b631f7c59453..60e4f77ca662 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -153,34 +153,6 @@ int driver_add_kobj(struct device_driver *drv, struct kobject *kobj,
153} 153}
154EXPORT_SYMBOL_GPL(driver_add_kobj); 154EXPORT_SYMBOL_GPL(driver_add_kobj);
155 155
156/**
157 * get_driver - increment driver reference count.
158 * @drv: driver.
159 */
160struct device_driver *get_driver(struct device_driver *drv)
161{
162 if (drv) {
163 struct driver_private *priv;
164 struct kobject *kobj;
165
166 kobj = kobject_get(&drv->p->kobj);
167 priv = to_driver(kobj);
168 return priv->driver;
169 }
170 return NULL;
171}
172EXPORT_SYMBOL_GPL(get_driver);
173
174/**
175 * put_driver - decrement driver's refcount.
176 * @drv: driver.
177 */
178void put_driver(struct device_driver *drv)
179{
180 kobject_put(&drv->p->kobj);
181}
182EXPORT_SYMBOL_GPL(put_driver);
183
184static int driver_add_groups(struct device_driver *drv, 156static int driver_add_groups(struct device_driver *drv,
185 const struct attribute_group **groups) 157 const struct attribute_group **groups)
186{ 158{
@@ -234,7 +206,6 @@ int driver_register(struct device_driver *drv)
234 206
235 other = driver_find(drv->name, drv->bus); 207 other = driver_find(drv->name, drv->bus);
236 if (other) { 208 if (other) {
237 put_driver(other);
238 printk(KERN_ERR "Error: Driver '%s' is already registered, " 209 printk(KERN_ERR "Error: Driver '%s' is already registered, "
239 "aborting...\n", drv->name); 210 "aborting...\n", drv->name);
240 return -EBUSY; 211 return -EBUSY;
@@ -275,7 +246,9 @@ EXPORT_SYMBOL_GPL(driver_unregister);
275 * Call kset_find_obj() to iterate over list of drivers on 246 * Call kset_find_obj() to iterate over list of drivers on
276 * a bus to find driver by name. Return driver if found. 247 * a bus to find driver by name. Return driver if found.
277 * 248 *
278 * Note that kset_find_obj increments driver's reference count. 249 * This routine provides no locking to prevent the driver it returns
250 * from being unregistered or unloaded while the caller is using it.
251 * The caller is responsible for preventing this.
279 */ 252 */
280struct device_driver *driver_find(const char *name, struct bus_type *bus) 253struct device_driver *driver_find(const char *name, struct bus_type *bus)
281{ 254{
@@ -283,6 +256,8 @@ struct device_driver *driver_find(const char *name, struct bus_type *bus)
283 struct driver_private *priv; 256 struct driver_private *priv;
284 257
285 if (k) { 258 if (k) {
259 /* Drop reference added by kset_find_obj() */
260 kobject_put(k);
286 priv = to_driver(k); 261 priv = to_driver(k);
287 return priv->driver; 262 return priv->driver;
288 } 263 }
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
new file mode 100644
index 000000000000..05f150382da8
--- /dev/null
+++ b/drivers/base/soc.c
@@ -0,0 +1,183 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2011
3 *
4 * Author: Lee Jones <lee.jones@linaro.org> for ST-Ericsson.
5 * License terms: GNU General Public License (GPL), version 2
6 */
7
8#include <linux/sysfs.h>
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/stat.h>
12#include <linux/slab.h>
13#include <linux/idr.h>
14#include <linux/spinlock.h>
15#include <linux/sys_soc.h>
16#include <linux/err.h>
17
18static DEFINE_IDR(soc_ida);
19static DEFINE_SPINLOCK(soc_lock);
20
21static ssize_t soc_info_get(struct device *dev,
22 struct device_attribute *attr,
23 char *buf);
24
25struct soc_device {
26 struct device dev;
27 struct soc_device_attribute *attr;
28 int soc_dev_num;
29};
30
31static struct bus_type soc_bus_type = {
32 .name = "soc",
33};
34
35static DEVICE_ATTR(machine, S_IRUGO, soc_info_get, NULL);
36static DEVICE_ATTR(family, S_IRUGO, soc_info_get, NULL);
37static DEVICE_ATTR(soc_id, S_IRUGO, soc_info_get, NULL);
38static DEVICE_ATTR(revision, S_IRUGO, soc_info_get, NULL);
39
40struct device *soc_device_to_device(struct soc_device *soc_dev)
41{
42 return &soc_dev->dev;
43}
44
45static mode_t soc_attribute_mode(struct kobject *kobj,
46 struct attribute *attr,
47 int index)
48{
49 struct device *dev = container_of(kobj, struct device, kobj);
50 struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
51
52 if ((attr == &dev_attr_machine.attr)
53 && (soc_dev->attr->machine != NULL))
54 return attr->mode;
55 if ((attr == &dev_attr_family.attr)
56 && (soc_dev->attr->family != NULL))
57 return attr->mode;
58 if ((attr == &dev_attr_revision.attr)
59 && (soc_dev->attr->revision != NULL))
60 return attr->mode;
61 if ((attr == &dev_attr_soc_id.attr)
62 && (soc_dev->attr->soc_id != NULL))
63 return attr->mode;
64
65 /* Unknown or unfilled attribute. */
66 return 0;
67}
68
69static ssize_t soc_info_get(struct device *dev,
70 struct device_attribute *attr,
71 char *buf)
72{
73 struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
74
75 if (attr == &dev_attr_machine)
76 return sprintf(buf, "%s\n", soc_dev->attr->machine);
77 if (attr == &dev_attr_family)
78 return sprintf(buf, "%s\n", soc_dev->attr->family);
79 if (attr == &dev_attr_revision)
80 return sprintf(buf, "%s\n", soc_dev->attr->revision);
81 if (attr == &dev_attr_soc_id)
82 return sprintf(buf, "%s\n", soc_dev->attr->soc_id);
83
84 return -EINVAL;
85
86}
87
88static struct attribute *soc_attr[] = {
89 &dev_attr_machine.attr,
90 &dev_attr_family.attr,
91 &dev_attr_soc_id.attr,
92 &dev_attr_revision.attr,
93 NULL,
94};
95
96static const struct attribute_group soc_attr_group = {
97 .attrs = soc_attr,
98 .is_visible = soc_attribute_mode,
99};
100
101static const struct attribute_group *soc_attr_groups[] = {
102 &soc_attr_group,
103 NULL,
104};
105
106static void soc_release(struct device *dev)
107{
108 struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
109
110 kfree(soc_dev);
111}
112
113struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr)
114{
115 struct soc_device *soc_dev;
116 int ret;
117
118 soc_dev = kzalloc(sizeof(*soc_dev), GFP_KERNEL);
119 if (!soc_dev) {
120 ret = -ENOMEM;
121 goto out1;
122 }
123
124 /* Fetch a unique (reclaimable) SOC ID. */
125 do {
126 if (!ida_pre_get(&soc_ida, GFP_KERNEL)) {
127 ret = -ENOMEM;
128 goto out2;
129 }
130
131 spin_lock(&soc_lock);
132 ret = ida_get_new(&soc_ida, &soc_dev->soc_dev_num);
133 spin_unlock(&soc_lock);
134
135 } while (ret == -EAGAIN);
136
137 if (ret)
138 goto out2;
139
140 soc_dev->attr = soc_dev_attr;
141 soc_dev->dev.bus = &soc_bus_type;
142 soc_dev->dev.groups = soc_attr_groups;
143 soc_dev->dev.release = soc_release;
144
145 dev_set_name(&soc_dev->dev, "soc%d", soc_dev->soc_dev_num);
146
147 ret = device_register(&soc_dev->dev);
148 if (ret)
149 goto out3;
150
151 return soc_dev;
152
153out3:
154 ida_remove(&soc_ida, soc_dev->soc_dev_num);
155out2:
156 kfree(soc_dev);
157out1:
158 return ERR_PTR(ret);
159}
160
161/* Ensure soc_dev->attr is freed prior to calling soc_device_unregister. */
162void soc_device_unregister(struct soc_device *soc_dev)
163{
164 ida_remove(&soc_ida, soc_dev->soc_dev_num);
165
166 device_unregister(&soc_dev->dev);
167}
168
169static int __init soc_bus_register(void)
170{
171 spin_lock_init(&soc_lock);
172
173 return bus_register(&soc_bus_type);
174}
175core_initcall(soc_bus_register);
176
177static void __exit soc_bus_unregister(void)
178{
179 ida_destroy(&soc_ida);
180
181 bus_unregister(&soc_bus_type);
182}
183module_exit(soc_bus_unregister);
diff --git a/drivers/cpufreq/cpufreq-nforce2.c b/drivers/cpufreq/cpufreq-nforce2.c
index 7bac808804f3..13d311ee08b3 100644
--- a/drivers/cpufreq/cpufreq-nforce2.c
+++ b/drivers/cpufreq/cpufreq-nforce2.c
@@ -385,6 +385,14 @@ static struct cpufreq_driver nforce2_driver = {
385 .owner = THIS_MODULE, 385 .owner = THIS_MODULE,
386}; 386};
387 387
388#ifdef MODULE
389static DEFINE_PCI_DEVICE_TABLE(nforce2_ids) = {
390 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2 },
391 {}
392};
393MODULE_DEVICE_TABLE(pci, nforce2_ids);
394#endif
395
388/** 396/**
389 * nforce2_detect_chipset - detect the Southbridge which contains FSB PLL logic 397 * nforce2_detect_chipset - detect the Southbridge which contains FSB PLL logic
390 * 398 *
diff --git a/drivers/cpufreq/e_powersaver.c b/drivers/cpufreq/e_powersaver.c
index 4bd6815d317b..3fffbe6025cd 100644
--- a/drivers/cpufreq/e_powersaver.c
+++ b/drivers/cpufreq/e_powersaver.c
@@ -16,6 +16,7 @@
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18 18
19#include <asm/cpu_device_id.h>
19#include <asm/msr.h> 20#include <asm/msr.h>
20#include <asm/tsc.h> 21#include <asm/tsc.h>
21 22
@@ -437,18 +438,19 @@ static struct cpufreq_driver eps_driver = {
437 .attr = eps_attr, 438 .attr = eps_attr,
438}; 439};
439 440
441
442/* This driver will work only on Centaur C7 processors with
443 * Enhanced SpeedStep/PowerSaver registers */
444static const struct x86_cpu_id eps_cpu_id[] = {
445 { X86_VENDOR_CENTAUR, 6, X86_MODEL_ANY, X86_FEATURE_EST },
446 {}
447};
448MODULE_DEVICE_TABLE(x86cpu, eps_cpu_id);
449
440static int __init eps_init(void) 450static int __init eps_init(void)
441{ 451{
442 struct cpuinfo_x86 *c = &cpu_data(0); 452 if (!x86_match_cpu(eps_cpu_id) || boot_cpu_data.x86_model < 10)
443
444 /* This driver will work only on Centaur C7 processors with
445 * Enhanced SpeedStep/PowerSaver registers */
446 if (c->x86_vendor != X86_VENDOR_CENTAUR
447 || c->x86 != 6 || c->x86_model < 10)
448 return -ENODEV;
449 if (!cpu_has(c, X86_FEATURE_EST))
450 return -ENODEV; 453 return -ENODEV;
451
452 if (cpufreq_register_driver(&eps_driver)) 454 if (cpufreq_register_driver(&eps_driver))
453 return -EINVAL; 455 return -EINVAL;
454 return 0; 456 return 0;
diff --git a/drivers/cpufreq/elanfreq.c b/drivers/cpufreq/elanfreq.c
index c587db472a75..960671fd3d7e 100644
--- a/drivers/cpufreq/elanfreq.c
+++ b/drivers/cpufreq/elanfreq.c
@@ -23,6 +23,7 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/cpufreq.h> 24#include <linux/cpufreq.h>
25 25
26#include <asm/cpu_device_id.h>
26#include <asm/msr.h> 27#include <asm/msr.h>
27#include <linux/timex.h> 28#include <linux/timex.h>
28#include <linux/io.h> 29#include <linux/io.h>
@@ -277,17 +278,16 @@ static struct cpufreq_driver elanfreq_driver = {
277 .attr = elanfreq_attr, 278 .attr = elanfreq_attr,
278}; 279};
279 280
281static const struct x86_cpu_id elan_id[] = {
282 { X86_VENDOR_AMD, 4, 10, },
283 {}
284};
285MODULE_DEVICE_TABLE(x86cpu, elan_id);
280 286
281static int __init elanfreq_init(void) 287static int __init elanfreq_init(void)
282{ 288{
283 struct cpuinfo_x86 *c = &cpu_data(0); 289 if (!x86_match_cpu(elan_id))
284
285 /* Test if we have the right hardware */
286 if ((c->x86_vendor != X86_VENDOR_AMD) ||
287 (c->x86 != 4) || (c->x86_model != 10)) {
288 printk(KERN_INFO "elanfreq: error: no Elan processor found!\n");
289 return -ENODEV; 290 return -ENODEV;
290 }
291 return cpufreq_register_driver(&elanfreq_driver); 291 return cpufreq_register_driver(&elanfreq_driver);
292} 292}
293 293
diff --git a/drivers/cpufreq/gx-suspmod.c b/drivers/cpufreq/gx-suspmod.c
index ffe1f2c92ed3..456bee058fe6 100644
--- a/drivers/cpufreq/gx-suspmod.c
+++ b/drivers/cpufreq/gx-suspmod.c
@@ -82,6 +82,7 @@
82#include <linux/errno.h> 82#include <linux/errno.h>
83#include <linux/slab.h> 83#include <linux/slab.h>
84 84
85#include <asm/cpu_device_id.h>
85#include <asm/processor-cyrix.h> 86#include <asm/processor-cyrix.h>
86 87
87/* PCI config registers, all at F0 */ 88/* PCI config registers, all at F0 */
@@ -171,6 +172,7 @@ static struct pci_device_id gx_chipset_tbl[] __initdata = {
171 { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5510), }, 172 { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5510), },
172 { 0, }, 173 { 0, },
173}; 174};
175MODULE_DEVICE_TABLE(pci, gx_chipset_tbl);
174 176
175static void gx_write_byte(int reg, int value) 177static void gx_write_byte(int reg, int value)
176{ 178{
@@ -185,13 +187,6 @@ static __init struct pci_dev *gx_detect_chipset(void)
185{ 187{
186 struct pci_dev *gx_pci = NULL; 188 struct pci_dev *gx_pci = NULL;
187 189
188 /* check if CPU is a MediaGX or a Geode. */
189 if ((boot_cpu_data.x86_vendor != X86_VENDOR_NSC) &&
190 (boot_cpu_data.x86_vendor != X86_VENDOR_CYRIX)) {
191 pr_debug("error: no MediaGX/Geode processor found!\n");
192 return NULL;
193 }
194
195 /* detect which companion chip is used */ 190 /* detect which companion chip is used */
196 for_each_pci_dev(gx_pci) { 191 for_each_pci_dev(gx_pci) {
197 if ((pci_match_id(gx_chipset_tbl, gx_pci)) != NULL) 192 if ((pci_match_id(gx_chipset_tbl, gx_pci)) != NULL)
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index f47d26e2a135..53ddbc760af7 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -35,6 +35,7 @@
35#include <linux/acpi.h> 35#include <linux/acpi.h>
36 36
37#include <asm/msr.h> 37#include <asm/msr.h>
38#include <asm/cpu_device_id.h>
38#include <acpi/processor.h> 39#include <acpi/processor.h>
39 40
40#include "longhaul.h" 41#include "longhaul.h"
@@ -951,12 +952,17 @@ static struct cpufreq_driver longhaul_driver = {
951 .attr = longhaul_attr, 952 .attr = longhaul_attr,
952}; 953};
953 954
955static const struct x86_cpu_id longhaul_id[] = {
956 { X86_VENDOR_CENTAUR, 6 },
957 {}
958};
959MODULE_DEVICE_TABLE(x86cpu, longhaul_id);
954 960
955static int __init longhaul_init(void) 961static int __init longhaul_init(void)
956{ 962{
957 struct cpuinfo_x86 *c = &cpu_data(0); 963 struct cpuinfo_x86 *c = &cpu_data(0);
958 964
959 if (c->x86_vendor != X86_VENDOR_CENTAUR || c->x86 != 6) 965 if (!x86_match_cpu(longhaul_id))
960 return -ENODEV; 966 return -ENODEV;
961 967
962#ifdef CONFIG_SMP 968#ifdef CONFIG_SMP
diff --git a/drivers/cpufreq/longrun.c b/drivers/cpufreq/longrun.c
index 34ea359b370e..8bc9f5fbbaeb 100644
--- a/drivers/cpufreq/longrun.c
+++ b/drivers/cpufreq/longrun.c
@@ -14,6 +14,7 @@
14 14
15#include <asm/msr.h> 15#include <asm/msr.h>
16#include <asm/processor.h> 16#include <asm/processor.h>
17#include <asm/cpu_device_id.h>
17 18
18static struct cpufreq_driver longrun_driver; 19static struct cpufreq_driver longrun_driver;
19 20
@@ -288,6 +289,12 @@ static struct cpufreq_driver longrun_driver = {
288 .owner = THIS_MODULE, 289 .owner = THIS_MODULE,
289}; 290};
290 291
292static const struct x86_cpu_id longrun_ids[] = {
293 { X86_VENDOR_TRANSMETA, X86_FAMILY_ANY, X86_MODEL_ANY,
294 X86_FEATURE_LONGRUN },
295 {}
296};
297MODULE_DEVICE_TABLE(x86cpu, longrun_ids);
291 298
292/** 299/**
293 * longrun_init - initializes the Transmeta Crusoe LongRun CPUFreq driver 300 * longrun_init - initializes the Transmeta Crusoe LongRun CPUFreq driver
@@ -296,12 +303,8 @@ static struct cpufreq_driver longrun_driver = {
296 */ 303 */
297static int __init longrun_init(void) 304static int __init longrun_init(void)
298{ 305{
299 struct cpuinfo_x86 *c = &cpu_data(0); 306 if (!x86_match_cpu(longrun_ids))
300
301 if (c->x86_vendor != X86_VENDOR_TRANSMETA ||
302 !cpu_has(c, X86_FEATURE_LONGRUN))
303 return -ENODEV; 307 return -ENODEV;
304
305 return cpufreq_register_driver(&longrun_driver); 308 return cpufreq_register_driver(&longrun_driver);
306} 309}
307 310
diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
index 6be3e0760c26..827629c9aad7 100644
--- a/drivers/cpufreq/p4-clockmod.c
+++ b/drivers/cpufreq/p4-clockmod.c
@@ -31,6 +31,7 @@
31#include <asm/processor.h> 31#include <asm/processor.h>
32#include <asm/msr.h> 32#include <asm/msr.h>
33#include <asm/timer.h> 33#include <asm/timer.h>
34#include <asm/cpu_device_id.h>
34 35
35#include "speedstep-lib.h" 36#include "speedstep-lib.h"
36 37
@@ -289,21 +290,25 @@ static struct cpufreq_driver p4clockmod_driver = {
289 .attr = p4clockmod_attr, 290 .attr = p4clockmod_attr,
290}; 291};
291 292
293static const struct x86_cpu_id cpufreq_p4_id[] = {
294 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_ACC },
295 {}
296};
297
298/*
299 * Intentionally no MODULE_DEVICE_TABLE here: this driver should not
300 * be auto loaded. Please don't add one.
301 */
292 302
293static int __init cpufreq_p4_init(void) 303static int __init cpufreq_p4_init(void)
294{ 304{
295 struct cpuinfo_x86 *c = &cpu_data(0);
296 int ret; 305 int ret;
297 306
298 /* 307 /*
299 * THERM_CONTROL is architectural for IA32 now, so 308 * THERM_CONTROL is architectural for IA32 now, so
300 * we can rely on the capability checks 309 * we can rely on the capability checks
301 */ 310 */
302 if (c->x86_vendor != X86_VENDOR_INTEL) 311 if (!x86_match_cpu(cpufreq_p4_id) || !boot_cpu_has(X86_FEATURE_ACPI))
303 return -ENODEV;
304
305 if (!test_cpu_cap(c, X86_FEATURE_ACPI) ||
306 !test_cpu_cap(c, X86_FEATURE_ACC))
307 return -ENODEV; 312 return -ENODEV;
308 313
309 ret = cpufreq_register_driver(&p4clockmod_driver); 314 ret = cpufreq_register_driver(&p4clockmod_driver);
diff --git a/drivers/cpufreq/powernow-k6.c b/drivers/cpufreq/powernow-k6.c
index b3379d6a5c57..af23e0b9ec92 100644
--- a/drivers/cpufreq/powernow-k6.c
+++ b/drivers/cpufreq/powernow-k6.c
@@ -16,6 +16,7 @@
16#include <linux/timex.h> 16#include <linux/timex.h>
17#include <linux/io.h> 17#include <linux/io.h>
18 18
19#include <asm/cpu_device_id.h>
19#include <asm/msr.h> 20#include <asm/msr.h>
20 21
21#define POWERNOW_IOPORT 0xfff0 /* it doesn't matter where, as long 22#define POWERNOW_IOPORT 0xfff0 /* it doesn't matter where, as long
@@ -210,6 +211,12 @@ static struct cpufreq_driver powernow_k6_driver = {
210 .attr = powernow_k6_attr, 211 .attr = powernow_k6_attr,
211}; 212};
212 213
214static const struct x86_cpu_id powernow_k6_ids[] = {
215 { X86_VENDOR_AMD, 5, 12 },
216 { X86_VENDOR_AMD, 5, 13 },
217 {}
218};
219MODULE_DEVICE_TABLE(x86cpu, powernow_k6_ids);
213 220
214/** 221/**
215 * powernow_k6_init - initializes the k6 PowerNow! CPUFreq driver 222 * powernow_k6_init - initializes the k6 PowerNow! CPUFreq driver
@@ -220,10 +227,7 @@ static struct cpufreq_driver powernow_k6_driver = {
220 */ 227 */
221static int __init powernow_k6_init(void) 228static int __init powernow_k6_init(void)
222{ 229{
223 struct cpuinfo_x86 *c = &cpu_data(0); 230 if (!x86_match_cpu(powernow_k6_ids))
224
225 if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 5) ||
226 ((c->x86_model != 12) && (c->x86_model != 13)))
227 return -ENODEV; 231 return -ENODEV;
228 232
229 if (!request_region(POWERNOW_IOPORT, 16, "PowerNow!")) { 233 if (!request_region(POWERNOW_IOPORT, 16, "PowerNow!")) {
diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c
index d71d9f372359..cf7e1ee005a2 100644
--- a/drivers/cpufreq/powernow-k7.c
+++ b/drivers/cpufreq/powernow-k7.c
@@ -28,6 +28,7 @@
28#include <asm/timer.h> /* Needed for recalibrate_cpu_khz() */ 28#include <asm/timer.h> /* Needed for recalibrate_cpu_khz() */
29#include <asm/msr.h> 29#include <asm/msr.h>
30#include <asm/system.h> 30#include <asm/system.h>
31#include <asm/cpu_device_id.h>
31 32
32#ifdef CONFIG_X86_POWERNOW_K7_ACPI 33#ifdef CONFIG_X86_POWERNOW_K7_ACPI
33#include <linux/acpi.h> 34#include <linux/acpi.h>
@@ -110,18 +111,19 @@ static int check_fsb(unsigned int fsbspeed)
110 return delta < 5; 111 return delta < 5;
111} 112}
112 113
114static const struct x86_cpu_id powernow_k7_cpuids[] = {
115 { X86_VENDOR_AMD, 6, },
116 {}
117};
118MODULE_DEVICE_TABLE(x86cpu, powernow_k7_cpuids);
119
113static int check_powernow(void) 120static int check_powernow(void)
114{ 121{
115 struct cpuinfo_x86 *c = &cpu_data(0); 122 struct cpuinfo_x86 *c = &cpu_data(0);
116 unsigned int maxei, eax, ebx, ecx, edx; 123 unsigned int maxei, eax, ebx, ecx, edx;
117 124
118 if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 6)) { 125 if (!x86_match_cpu(powernow_k7_cpuids))
119#ifdef MODULE
120 printk(KERN_INFO PFX "This module only works with "
121 "AMD K7 CPUs\n");
122#endif
123 return 0; 126 return 0;
124 }
125 127
126 /* Get maximum capabilities */ 128 /* Get maximum capabilities */
127 maxei = cpuid_eax(0x80000000); 129 maxei = cpuid_eax(0x80000000);
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index 8f9b2ceeec85..c0e816468e30 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -40,6 +40,7 @@
40#include <linux/delay.h> 40#include <linux/delay.h>
41 41
42#include <asm/msr.h> 42#include <asm/msr.h>
43#include <asm/cpu_device_id.h>
43 44
44#include <linux/acpi.h> 45#include <linux/acpi.h>
45#include <linux/mutex.h> 46#include <linux/mutex.h>
@@ -520,6 +521,15 @@ static int core_voltage_post_transition(struct powernow_k8_data *data,
520 return 0; 521 return 0;
521} 522}
522 523
524static const struct x86_cpu_id powernow_k8_ids[] = {
525 /* IO based frequency switching */
526 { X86_VENDOR_AMD, 0xf },
527 /* MSR based frequency switching supported */
528 X86_FEATURE_MATCH(X86_FEATURE_HW_PSTATE),
529 {}
530};
531MODULE_DEVICE_TABLE(x86cpu, powernow_k8_ids);
532
523static void check_supported_cpu(void *_rc) 533static void check_supported_cpu(void *_rc)
524{ 534{
525 u32 eax, ebx, ecx, edx; 535 u32 eax, ebx, ecx, edx;
@@ -527,13 +537,7 @@ static void check_supported_cpu(void *_rc)
527 537
528 *rc = -ENODEV; 538 *rc = -ENODEV;
529 539
530 if (__this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_AMD)
531 return;
532
533 eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); 540 eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
534 if (((eax & CPUID_XFAM) != CPUID_XFAM_K8) &&
535 ((eax & CPUID_XFAM) < CPUID_XFAM_10H))
536 return;
537 541
538 if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) { 542 if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) {
539 if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) || 543 if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) ||
@@ -1553,6 +1557,9 @@ static int __cpuinit powernowk8_init(void)
1553 unsigned int i, supported_cpus = 0, cpu; 1557 unsigned int i, supported_cpus = 0, cpu;
1554 int rv; 1558 int rv;
1555 1559
1560 if (!x86_match_cpu(powernow_k8_ids))
1561 return -ENODEV;
1562
1556 for_each_online_cpu(i) { 1563 for_each_online_cpu(i) {
1557 int rc; 1564 int rc;
1558 smp_call_function_single(i, check_supported_cpu, &rc, 1); 1565 smp_call_function_single(i, check_supported_cpu, &rc, 1);
diff --git a/drivers/cpufreq/sc520_freq.c b/drivers/cpufreq/sc520_freq.c
index 1e205e6b1727..e42e073cd9b8 100644
--- a/drivers/cpufreq/sc520_freq.c
+++ b/drivers/cpufreq/sc520_freq.c
@@ -22,6 +22,7 @@
22#include <linux/timex.h> 22#include <linux/timex.h>
23#include <linux/io.h> 23#include <linux/io.h>
24 24
25#include <asm/cpu_device_id.h>
25#include <asm/msr.h> 26#include <asm/msr.h>
26 27
27#define MMCR_BASE 0xfffef000 /* The default base address */ 28#define MMCR_BASE 0xfffef000 /* The default base address */
@@ -150,18 +151,19 @@ static struct cpufreq_driver sc520_freq_driver = {
150 .attr = sc520_freq_attr, 151 .attr = sc520_freq_attr,
151}; 152};
152 153
154static const struct x86_cpu_id sc520_ids[] = {
155 { X86_VENDOR_AMD, 4, 9 },
156 {}
157};
158MODULE_DEVICE_TABLE(x86cpu, sc520_ids);
153 159
154static int __init sc520_freq_init(void) 160static int __init sc520_freq_init(void)
155{ 161{
156 struct cpuinfo_x86 *c = &cpu_data(0);
157 int err; 162 int err;
158 163
159 /* Test if we have the right hardware */ 164 if (!x86_match_cpu(sc520_ids))
160 if (c->x86_vendor != X86_VENDOR_AMD ||
161 c->x86 != 4 || c->x86_model != 9) {
162 pr_debug("no Elan SC520 processor found!\n");
163 return -ENODEV; 165 return -ENODEV;
164 } 166
165 cpuctl = ioremap((unsigned long)(MMCR_BASE + OFFS_CPUCTL), 1); 167 cpuctl = ioremap((unsigned long)(MMCR_BASE + OFFS_CPUCTL), 1);
166 if (!cpuctl) { 168 if (!cpuctl) {
167 printk(KERN_ERR "sc520_freq: error: failed to remap memory\n"); 169 printk(KERN_ERR "sc520_freq: error: failed to remap memory\n");
diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
index 6ea3455def21..3a953d519f46 100644
--- a/drivers/cpufreq/speedstep-centrino.c
+++ b/drivers/cpufreq/speedstep-centrino.c
@@ -25,6 +25,7 @@
25#include <asm/msr.h> 25#include <asm/msr.h>
26#include <asm/processor.h> 26#include <asm/processor.h>
27#include <asm/cpufeature.h> 27#include <asm/cpufeature.h>
28#include <asm/cpu_device_id.h>
28 29
29#define PFX "speedstep-centrino: " 30#define PFX "speedstep-centrino: "
30#define MAINTAINER "cpufreq@vger.kernel.org" 31#define MAINTAINER "cpufreq@vger.kernel.org"
@@ -595,6 +596,24 @@ static struct cpufreq_driver centrino_driver = {
595 .owner = THIS_MODULE, 596 .owner = THIS_MODULE,
596}; 597};
597 598
599/*
600 * This doesn't replace the detailed checks above because
601 * the generic CPU IDs don't have a way to match for steppings
602 * or ASCII model IDs.
603 */
604static const struct x86_cpu_id centrino_ids[] = {
605 { X86_VENDOR_INTEL, 6, 9, X86_FEATURE_EST },
606 { X86_VENDOR_INTEL, 6, 13, X86_FEATURE_EST },
607 { X86_VENDOR_INTEL, 6, 13, X86_FEATURE_EST },
608 { X86_VENDOR_INTEL, 6, 13, X86_FEATURE_EST },
609 { X86_VENDOR_INTEL, 15, 3, X86_FEATURE_EST },
610 { X86_VENDOR_INTEL, 15, 4, X86_FEATURE_EST },
611 {}
612};
613#if 0
614/* Autoload or not? Do not for now. */
615MODULE_DEVICE_TABLE(x86cpu, centrino_ids);
616#endif
598 617
599/** 618/**
600 * centrino_init - initializes the Enhanced SpeedStep CPUFreq driver 619 * centrino_init - initializes the Enhanced SpeedStep CPUFreq driver
@@ -612,11 +631,8 @@ static struct cpufreq_driver centrino_driver = {
612 */ 631 */
613static int __init centrino_init(void) 632static int __init centrino_init(void)
614{ 633{
615 struct cpuinfo_x86 *cpu = &cpu_data(0); 634 if (!x86_match_cpu(centrino_ids))
616
617 if (!cpu_has(cpu, X86_FEATURE_EST))
618 return -ENODEV; 635 return -ENODEV;
619
620 return cpufreq_register_driver(&centrino_driver); 636 return cpufreq_register_driver(&centrino_driver);
621} 637}
622 638
diff --git a/drivers/cpufreq/speedstep-ich.c b/drivers/cpufreq/speedstep-ich.c
index a748ce782fee..7432b3a72cd4 100644
--- a/drivers/cpufreq/speedstep-ich.c
+++ b/drivers/cpufreq/speedstep-ich.c
@@ -25,6 +25,8 @@
25#include <linux/pci.h> 25#include <linux/pci.h>
26#include <linux/sched.h> 26#include <linux/sched.h>
27 27
28#include <asm/cpu_device_id.h>
29
28#include "speedstep-lib.h" 30#include "speedstep-lib.h"
29 31
30 32
@@ -388,6 +390,16 @@ static struct cpufreq_driver speedstep_driver = {
388 .attr = speedstep_attr, 390 .attr = speedstep_attr,
389}; 391};
390 392
393static const struct x86_cpu_id ss_smi_ids[] = {
394 { X86_VENDOR_INTEL, 6, 0xb, },
395 { X86_VENDOR_INTEL, 6, 0x8, },
396 { X86_VENDOR_INTEL, 15, 2 },
397 {}
398};
399#if 0
400/* Autoload or not? Do not for now. */
401MODULE_DEVICE_TABLE(x86cpu, ss_smi_ids);
402#endif
391 403
392/** 404/**
393 * speedstep_init - initializes the SpeedStep CPUFreq driver 405 * speedstep_init - initializes the SpeedStep CPUFreq driver
@@ -398,6 +410,9 @@ static struct cpufreq_driver speedstep_driver = {
398 */ 410 */
399static int __init speedstep_init(void) 411static int __init speedstep_init(void)
400{ 412{
413 if (!x86_match_cpu(ss_smi_ids))
414 return -ENODEV;
415
401 /* detect processor */ 416 /* detect processor */
402 speedstep_processor = speedstep_detect_processor(); 417 speedstep_processor = speedstep_detect_processor();
403 if (!speedstep_processor) { 418 if (!speedstep_processor) {
diff --git a/drivers/cpufreq/speedstep-lib.c b/drivers/cpufreq/speedstep-lib.c
index 8af2d2fd9d51..7047821a7f8a 100644
--- a/drivers/cpufreq/speedstep-lib.c
+++ b/drivers/cpufreq/speedstep-lib.c
@@ -249,6 +249,7 @@ EXPORT_SYMBOL_GPL(speedstep_get_frequency);
249 * DETECT SPEEDSTEP-CAPABLE PROCESSOR * 249 * DETECT SPEEDSTEP-CAPABLE PROCESSOR *
250 *********************************************************************/ 250 *********************************************************************/
251 251
252/* Keep in sync with the x86_cpu_id tables in the different modules */
252unsigned int speedstep_detect_processor(void) 253unsigned int speedstep_detect_processor(void)
253{ 254{
254 struct cpuinfo_x86 *c = &cpu_data(0); 255 struct cpuinfo_x86 *c = &cpu_data(0);
diff --git a/drivers/cpufreq/speedstep-smi.c b/drivers/cpufreq/speedstep-smi.c
index c76ead3490bf..6a457fcaaad5 100644
--- a/drivers/cpufreq/speedstep-smi.c
+++ b/drivers/cpufreq/speedstep-smi.c
@@ -20,6 +20,7 @@
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/io.h> 21#include <linux/io.h>
22#include <asm/ist.h> 22#include <asm/ist.h>
23#include <asm/cpu_device_id.h>
23 24
24#include "speedstep-lib.h" 25#include "speedstep-lib.h"
25 26
@@ -379,6 +380,17 @@ static struct cpufreq_driver speedstep_driver = {
379 .attr = speedstep_attr, 380 .attr = speedstep_attr,
380}; 381};
381 382
383static const struct x86_cpu_id ss_smi_ids[] = {
384 { X86_VENDOR_INTEL, 6, 0xb, },
385 { X86_VENDOR_INTEL, 6, 0x8, },
386 { X86_VENDOR_INTEL, 15, 2 },
387 {}
388};
389#if 0
390/* Not auto loaded currently */
391MODULE_DEVICE_TABLE(x86cpu, ss_smi_ids);
392#endif
393
382/** 394/**
383 * speedstep_init - initializes the SpeedStep CPUFreq driver 395 * speedstep_init - initializes the SpeedStep CPUFreq driver
384 * 396 *
@@ -388,6 +400,9 @@ static struct cpufreq_driver speedstep_driver = {
388 */ 400 */
389static int __init speedstep_init(void) 401static int __init speedstep_init(void)
390{ 402{
403 if (!x86_match_cpu(ss_smi_ids))
404 return -ENODEV;
405
391 speedstep_processor = speedstep_detect_processor(); 406 speedstep_processor = speedstep_detect_processor();
392 407
393 switch (speedstep_processor) { 408 switch (speedstep_processor) {
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 29b9469f8378..37b2e9406af6 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -19,6 +19,7 @@
19#include <linux/percpu.h> 19#include <linux/percpu.h>
20#include <linux/smp.h> 20#include <linux/smp.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <asm/cpu_device_id.h>
22#include <asm/byteorder.h> 23#include <asm/byteorder.h>
23#include <asm/processor.h> 24#include <asm/processor.h>
24#include <asm/i387.h> 25#include <asm/i387.h>
@@ -503,12 +504,18 @@ static struct crypto_alg cbc_aes_alg = {
503 } 504 }
504}; 505};
505 506
507static struct x86_cpu_id padlock_cpu_id[] = {
508 X86_FEATURE_MATCH(X86_FEATURE_XCRYPT),
509 {}
510};
511MODULE_DEVICE_TABLE(x86cpu, padlock_cpu_id);
512
506static int __init padlock_init(void) 513static int __init padlock_init(void)
507{ 514{
508 int ret; 515 int ret;
509 struct cpuinfo_x86 *c = &cpu_data(0); 516 struct cpuinfo_x86 *c = &cpu_data(0);
510 517
511 if (!cpu_has_xcrypt) 518 if (!x86_match_cpu(padlock_cpu_id))
512 return -ENODEV; 519 return -ENODEV;
513 520
514 if (!cpu_has_xcrypt_enabled) { 521 if (!cpu_has_xcrypt_enabled) {
diff --git a/drivers/crypto/padlock-sha.c b/drivers/crypto/padlock-sha.c
index 06bdb4b2c6a6..9266c0e25492 100644
--- a/drivers/crypto/padlock-sha.c
+++ b/drivers/crypto/padlock-sha.c
@@ -22,6 +22,7 @@
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/scatterlist.h> 24#include <linux/scatterlist.h>
25#include <asm/cpu_device_id.h>
25#include <asm/i387.h> 26#include <asm/i387.h>
26 27
27struct padlock_sha_desc { 28struct padlock_sha_desc {
@@ -526,6 +527,12 @@ static struct shash_alg sha256_alg_nano = {
526 } 527 }
527}; 528};
528 529
530static struct x86_cpu_id padlock_sha_ids[] = {
531 X86_FEATURE_MATCH(X86_FEATURE_PHE),
532 {}
533};
534MODULE_DEVICE_TABLE(x86cpu, padlock_sha_ids);
535
529static int __init padlock_init(void) 536static int __init padlock_init(void)
530{ 537{
531 int rc = -ENODEV; 538 int rc = -ENODEV;
@@ -533,15 +540,8 @@ static int __init padlock_init(void)
533 struct shash_alg *sha1; 540 struct shash_alg *sha1;
534 struct shash_alg *sha256; 541 struct shash_alg *sha256;
535 542
536 if (!cpu_has_phe) { 543 if (!x86_match_cpu(padlock_sha_ids) || !cpu_has_phe_enabled)
537 printk(KERN_NOTICE PFX "VIA PadLock Hash Engine not detected.\n");
538 return -ENODEV;
539 }
540
541 if (!cpu_has_phe_enabled) {
542 printk(KERN_NOTICE PFX "VIA PadLock detected, but not enabled. Hmm, strange...\n");
543 return -ENODEV; 544 return -ENODEV;
544 }
545 545
546 /* Register the newly added algorithm module if on * 546 /* Register the newly added algorithm module if on *
547 * VIA Nano processor, or else just do as before */ 547 * VIA Nano processor, or else just do as before */
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index af08ce7207d9..bce53fa0e166 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1619,11 +1619,7 @@ static ssize_t store_new_id(struct device_driver *drv, const char *buf,
1619 list_add_tail(&dynid->list, &hdrv->dyn_list); 1619 list_add_tail(&dynid->list, &hdrv->dyn_list);
1620 spin_unlock(&hdrv->dyn_lock); 1620 spin_unlock(&hdrv->dyn_lock);
1621 1621
1622 ret = 0; 1622 ret = driver_attach(&hdrv->driver);
1623 if (get_driver(&hdrv->driver)) {
1624 ret = driver_attach(&hdrv->driver);
1625 put_driver(&hdrv->driver);
1626 }
1627 1623
1628 return ret ? : count; 1624 return ret ? : count;
1629} 1625}
diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 36484db36baf..9ffbfc575a0c 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -37,81 +37,6 @@ struct vmbus_channel_message_table_entry {
37 void (*message_handler)(struct vmbus_channel_message_header *msg); 37 void (*message_handler)(struct vmbus_channel_message_header *msg);
38}; 38};
39 39
40#define MAX_MSG_TYPES 4
41#define MAX_NUM_DEVICE_CLASSES_SUPPORTED 8
42
43static const uuid_le
44 supported_device_classes[MAX_NUM_DEVICE_CLASSES_SUPPORTED] = {
45 /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
46 /* Storage - SCSI */
47 {
48 .b = {
49 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
50 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f
51 }
52 },
53
54 /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */
55 /* Network */
56 {
57 .b = {
58 0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46,
59 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E
60 }
61 },
62
63 /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
64 /* Input */
65 {
66 .b = {
67 0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
68 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A
69 }
70 },
71
72 /* {32412632-86cb-44a2-9b5c-50d1417354f5} */
73 /* IDE */
74 {
75 .b = {
76 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44,
77 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5
78 }
79 },
80 /* 0E0B6031-5213-4934-818B-38D90CED39DB */
81 /* Shutdown */
82 {
83 .b = {
84 0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49,
85 0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB
86 }
87 },
88 /* {9527E630-D0AE-497b-ADCE-E80AB0175CAF} */
89 /* TimeSync */
90 {
91 .b = {
92 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49,
93 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf
94 }
95 },
96 /* {57164f39-9115-4e78-ab55-382f3bd5422d} */
97 /* Heartbeat */
98 {
99 .b = {
100 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
101 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d
102 }
103 },
104 /* {A9A0F4E7-5A45-4d96-B827-8A841E8C03E6} */
105 /* KVP */
106 {
107 .b = {
108 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d,
109 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6
110 }
111 },
112
113};
114
115 40
116/** 41/**
117 * vmbus_prep_negotiate_resp() - Create default response for Hyper-V Negotiate message 42 * vmbus_prep_negotiate_resp() - Create default response for Hyper-V Negotiate message
@@ -321,20 +246,8 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
321 struct vmbus_channel *newchannel; 246 struct vmbus_channel *newchannel;
322 uuid_le *guidtype; 247 uuid_le *guidtype;
323 uuid_le *guidinstance; 248 uuid_le *guidinstance;
324 int i;
325 int fsupported = 0;
326 249
327 offer = (struct vmbus_channel_offer_channel *)hdr; 250 offer = (struct vmbus_channel_offer_channel *)hdr;
328 for (i = 0; i < MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++) {
329 if (!uuid_le_cmp(offer->offer.if_type,
330 supported_device_classes[i])) {
331 fsupported = 1;
332 break;
333 }
334 }
335
336 if (!fsupported)
337 return;
338 251
339 guidtype = &offer->offer.if_type; 252 guidtype = &offer->offer.if_type;
340 guidinstance = &offer->offer.if_instance; 253 guidinstance = &offer->offer.if_instance;
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 12aa97f31f93..15956bd48b48 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -155,9 +155,9 @@ int hv_init(void)
155 union hv_x64_msr_hypercall_contents hypercall_msr; 155 union hv_x64_msr_hypercall_contents hypercall_msr;
156 void *virtaddr = NULL; 156 void *virtaddr = NULL;
157 157
158 memset(hv_context.synic_event_page, 0, sizeof(void *) * MAX_NUM_CPUS); 158 memset(hv_context.synic_event_page, 0, sizeof(void *) * NR_CPUS);
159 memset(hv_context.synic_message_page, 0, 159 memset(hv_context.synic_message_page, 0,
160 sizeof(void *) * MAX_NUM_CPUS); 160 sizeof(void *) * NR_CPUS);
161 161
162 if (!query_hypervisor_presence()) 162 if (!query_hypervisor_presence())
163 goto cleanup; 163 goto cleanup;
diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c
index 0e8343f585bb..6186025209ce 100644
--- a/drivers/hv/hv_kvp.c
+++ b/drivers/hv/hv_kvp.c
@@ -28,8 +28,6 @@
28#include <linux/workqueue.h> 28#include <linux/workqueue.h>
29#include <linux/hyperv.h> 29#include <linux/hyperv.h>
30 30
31#include "hv_kvp.h"
32
33 31
34 32
35/* 33/*
@@ -44,9 +42,10 @@
44static struct { 42static struct {
45 bool active; /* transaction status - active or not */ 43 bool active; /* transaction status - active or not */
46 int recv_len; /* number of bytes received. */ 44 int recv_len; /* number of bytes received. */
47 int index; /* current index */ 45 struct hv_kvp_msg *kvp_msg; /* current message */
48 struct vmbus_channel *recv_channel; /* chn we got the request */ 46 struct vmbus_channel *recv_channel; /* chn we got the request */
49 u64 recv_req_id; /* request ID. */ 47 u64 recv_req_id; /* request ID. */
48 void *kvp_context; /* for the channel callback */
50} kvp_transaction; 49} kvp_transaction;
51 50
52static void kvp_send_key(struct work_struct *dummy); 51static void kvp_send_key(struct work_struct *dummy);
@@ -73,15 +72,20 @@ kvp_register(void)
73{ 72{
74 73
75 struct cn_msg *msg; 74 struct cn_msg *msg;
75 struct hv_kvp_msg *kvp_msg;
76 char *version;
76 77
77 msg = kzalloc(sizeof(*msg) + strlen(HV_DRV_VERSION) + 1 , GFP_ATOMIC); 78 msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg), GFP_ATOMIC);
78 79
79 if (msg) { 80 if (msg) {
81 kvp_msg = (struct hv_kvp_msg *)msg->data;
82 version = kvp_msg->body.kvp_register.version;
80 msg->id.idx = CN_KVP_IDX; 83 msg->id.idx = CN_KVP_IDX;
81 msg->id.val = CN_KVP_VAL; 84 msg->id.val = CN_KVP_VAL;
82 msg->seq = KVP_REGISTER; 85
83 strcpy(msg->data, HV_DRV_VERSION); 86 kvp_msg->kvp_hdr.operation = KVP_OP_REGISTER;
84 msg->len = strlen(HV_DRV_VERSION) + 1; 87 strcpy(version, HV_DRV_VERSION);
88 msg->len = sizeof(struct hv_kvp_msg);
85 cn_netlink_send(msg, 0, GFP_ATOMIC); 89 cn_netlink_send(msg, 0, GFP_ATOMIC);
86 kfree(msg); 90 kfree(msg);
87 } 91 }
@@ -103,23 +107,28 @@ kvp_work_func(struct work_struct *dummy)
103static void 107static void
104kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) 108kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
105{ 109{
106 struct hv_ku_msg *message; 110 struct hv_kvp_msg *message;
111 struct hv_kvp_msg_enumerate *data;
107 112
108 message = (struct hv_ku_msg *)msg->data; 113 message = (struct hv_kvp_msg *)msg->data;
109 if (msg->seq == KVP_REGISTER) { 114 switch (message->kvp_hdr.operation) {
115 case KVP_OP_REGISTER:
110 pr_info("KVP: user-mode registering done.\n"); 116 pr_info("KVP: user-mode registering done.\n");
111 kvp_register(); 117 kvp_register();
112 } 118 kvp_transaction.active = false;
119 hv_kvp_onchannelcallback(kvp_transaction.kvp_context);
120 break;
113 121
114 if (msg->seq == KVP_USER_SET) { 122 default:
123 data = &message->body.kvp_enum_data;
115 /* 124 /*
116 * Complete the transaction by forwarding the key value 125 * Complete the transaction by forwarding the key value
117 * to the host. But first, cancel the timeout. 126 * to the host. But first, cancel the timeout.
118 */ 127 */
119 if (cancel_delayed_work_sync(&kvp_work)) 128 if (cancel_delayed_work_sync(&kvp_work))
120 kvp_respond_to_host(message->kvp_key, 129 kvp_respond_to_host(data->data.key,
121 message->kvp_value, 130 data->data.value,
122 !strlen(message->kvp_key)); 131 !strlen(data->data.key));
123 } 132 }
124} 133}
125 134
@@ -127,19 +136,105 @@ static void
127kvp_send_key(struct work_struct *dummy) 136kvp_send_key(struct work_struct *dummy)
128{ 137{
129 struct cn_msg *msg; 138 struct cn_msg *msg;
130 int index = kvp_transaction.index; 139 struct hv_kvp_msg *message;
140 struct hv_kvp_msg *in_msg;
141 __u8 operation = kvp_transaction.kvp_msg->kvp_hdr.operation;
142 __u8 pool = kvp_transaction.kvp_msg->kvp_hdr.pool;
143 __u32 val32;
144 __u64 val64;
131 145
132 msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg) , GFP_ATOMIC); 146 msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg) , GFP_ATOMIC);
147 if (!msg)
148 return;
133 149
134 if (msg) { 150 msg->id.idx = CN_KVP_IDX;
135 msg->id.idx = CN_KVP_IDX; 151 msg->id.val = CN_KVP_VAL;
136 msg->id.val = CN_KVP_VAL; 152
137 msg->seq = KVP_KERNEL_GET; 153 message = (struct hv_kvp_msg *)msg->data;
138 ((struct hv_ku_msg *)msg->data)->kvp_index = index; 154 message->kvp_hdr.operation = operation;
139 msg->len = sizeof(struct hv_ku_msg); 155 message->kvp_hdr.pool = pool;
140 cn_netlink_send(msg, 0, GFP_ATOMIC); 156 in_msg = kvp_transaction.kvp_msg;
141 kfree(msg); 157
158 /*
159 * The key/value strings sent from the host are encoded in
160 * in utf16; convert it to utf8 strings.
161 * The host assures us that the utf16 strings will not exceed
162 * the max lengths specified. We will however, reserve room
163 * for the string terminating character - in the utf16s_utf8s()
164 * function we limit the size of the buffer where the converted
165 * string is placed to HV_KVP_EXCHANGE_MAX_*_SIZE -1 to gaurantee
166 * that the strings can be properly terminated!
167 */
168
169 switch (message->kvp_hdr.operation) {
170 case KVP_OP_SET:
171 switch (in_msg->body.kvp_set.data.value_type) {
172 case REG_SZ:
173 /*
174 * The value is a string - utf16 encoding.
175 */
176 message->body.kvp_set.data.value_size =
177 utf16s_to_utf8s(
178 (wchar_t *)in_msg->body.kvp_set.data.value,
179 in_msg->body.kvp_set.data.value_size,
180 UTF16_LITTLE_ENDIAN,
181 message->body.kvp_set.data.value,
182 HV_KVP_EXCHANGE_MAX_VALUE_SIZE - 1) + 1;
183 break;
184
185 case REG_U32:
186 /*
187 * The value is a 32 bit scalar.
188 * We save this as a utf8 string.
189 */
190 val32 = in_msg->body.kvp_set.data.value_u32;
191 message->body.kvp_set.data.value_size =
192 sprintf(message->body.kvp_set.data.value,
193 "%d", val32) + 1;
194 break;
195
196 case REG_U64:
197 /*
198 * The value is a 64 bit scalar.
199 * We save this as a utf8 string.
200 */
201 val64 = in_msg->body.kvp_set.data.value_u64;
202 message->body.kvp_set.data.value_size =
203 sprintf(message->body.kvp_set.data.value,
204 "%llu", val64) + 1;
205 break;
206
207 }
208 case KVP_OP_GET:
209 message->body.kvp_set.data.key_size =
210 utf16s_to_utf8s(
211 (wchar_t *)in_msg->body.kvp_set.data.key,
212 in_msg->body.kvp_set.data.key_size,
213 UTF16_LITTLE_ENDIAN,
214 message->body.kvp_set.data.key,
215 HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1;
216 break;
217
218 case KVP_OP_DELETE:
219 message->body.kvp_delete.key_size =
220 utf16s_to_utf8s(
221 (wchar_t *)in_msg->body.kvp_delete.key,
222 in_msg->body.kvp_delete.key_size,
223 UTF16_LITTLE_ENDIAN,
224 message->body.kvp_delete.key,
225 HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1;
226 break;
227
228 case KVP_OP_ENUMERATE:
229 message->body.kvp_enum_data.index =
230 in_msg->body.kvp_enum_data.index;
231 break;
142 } 232 }
233
234 msg->len = sizeof(struct hv_kvp_msg);
235 cn_netlink_send(msg, 0, GFP_ATOMIC);
236 kfree(msg);
237
143 return; 238 return;
144} 239}
145 240
@@ -151,10 +246,11 @@ static void
151kvp_respond_to_host(char *key, char *value, int error) 246kvp_respond_to_host(char *key, char *value, int error)
152{ 247{
153 struct hv_kvp_msg *kvp_msg; 248 struct hv_kvp_msg *kvp_msg;
154 struct hv_kvp_msg_enumerate *kvp_data; 249 struct hv_kvp_exchg_msg_value *kvp_data;
155 char *key_name; 250 char *key_name;
156 struct icmsg_hdr *icmsghdrp; 251 struct icmsg_hdr *icmsghdrp;
157 int keylen, valuelen; 252 int keylen = 0;
253 int valuelen = 0;
158 u32 buf_len; 254 u32 buf_len;
159 struct vmbus_channel *channel; 255 struct vmbus_channel *channel;
160 u64 req_id; 256 u64 req_id;
@@ -181,6 +277,9 @@ kvp_respond_to_host(char *key, char *value, int error)
181 277
182 kvp_transaction.active = false; 278 kvp_transaction.active = false;
183 279
280 icmsghdrp = (struct icmsg_hdr *)
281 &recv_buffer[sizeof(struct vmbuspipe_hdr)];
282
184 if (channel->onchannel_callback == NULL) 283 if (channel->onchannel_callback == NULL)
185 /* 284 /*
186 * We have raced with util driver being unloaded; 285 * We have raced with util driver being unloaded;
@@ -188,41 +287,67 @@ kvp_respond_to_host(char *key, char *value, int error)
188 */ 287 */
189 return; 288 return;
190 289
191 icmsghdrp = (struct icmsg_hdr *)
192 &recv_buffer[sizeof(struct vmbuspipe_hdr)];
193 kvp_msg = (struct hv_kvp_msg *)
194 &recv_buffer[sizeof(struct vmbuspipe_hdr) +
195 sizeof(struct icmsg_hdr)];
196 kvp_data = &kvp_msg->kvp_data;
197 key_name = key;
198 290
199 /* 291 /*
200 * If the error parameter is set, terminate the host's enumeration. 292 * If the error parameter is set, terminate the host's enumeration
293 * on this pool.
201 */ 294 */
202 if (error) { 295 if (error) {
203 /* 296 /*
204 * We don't support this index or the we have timedout; 297 * Something failed or the we have timedout;
205 * terminate the host-side iteration by returning an error. 298 * terminate the current host-side iteration.
206 */ 299 */
207 icmsghdrp->status = HV_E_FAIL; 300 icmsghdrp->status = HV_S_CONT;
208 goto response_done; 301 goto response_done;
209 } 302 }
210 303
304 icmsghdrp->status = HV_S_OK;
305
306 kvp_msg = (struct hv_kvp_msg *)
307 &recv_buffer[sizeof(struct vmbuspipe_hdr) +
308 sizeof(struct icmsg_hdr)];
309
310 switch (kvp_transaction.kvp_msg->kvp_hdr.operation) {
311 case KVP_OP_GET:
312 kvp_data = &kvp_msg->body.kvp_get.data;
313 goto copy_value;
314
315 case KVP_OP_SET:
316 case KVP_OP_DELETE:
317 goto response_done;
318
319 default:
320 break;
321 }
322
323 kvp_data = &kvp_msg->body.kvp_enum_data.data;
324 key_name = key;
325
211 /* 326 /*
212 * The windows host expects the key/value pair to be encoded 327 * The windows host expects the key/value pair to be encoded
213 * in utf16. 328 * in utf16. Ensure that the key/value size reported to the host
329 * will be less than or equal to the MAX size (including the
330 * terminating character).
214 */ 331 */
215 keylen = utf8s_to_utf16s(key_name, strlen(key_name), UTF16_HOST_ENDIAN, 332 keylen = utf8s_to_utf16s(key_name, strlen(key_name), UTF16_HOST_ENDIAN,
216 (wchar_t *) kvp_data->data.key, 333 (wchar_t *) kvp_data->key,
217 HV_KVP_EXCHANGE_MAX_KEY_SIZE / 2); 334 (HV_KVP_EXCHANGE_MAX_KEY_SIZE / 2) - 2);
218 kvp_data->data.key_size = 2*(keylen + 1); /* utf16 encoding */ 335 kvp_data->key_size = 2*(keylen + 1); /* utf16 encoding */
336
337copy_value:
219 valuelen = utf8s_to_utf16s(value, strlen(value), UTF16_HOST_ENDIAN, 338 valuelen = utf8s_to_utf16s(value, strlen(value), UTF16_HOST_ENDIAN,
220 (wchar_t *) kvp_data->data.value, 339 (wchar_t *) kvp_data->value,
221 HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2); 340 (HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2) - 2);
222 kvp_data->data.value_size = 2*(valuelen + 1); /* utf16 encoding */ 341 kvp_data->value_size = 2*(valuelen + 1); /* utf16 encoding */
223 342
224 kvp_data->data.value_type = REG_SZ; /* all our values are strings */ 343 /*
225 icmsghdrp->status = HV_S_OK; 344 * If the utf8s to utf16s conversion failed; notify host
345 * of the error.
346 */
347 if ((keylen < 0) || (valuelen < 0))
348 icmsghdrp->status = HV_E_FAIL;
349
350 kvp_data->value_type = REG_SZ; /* all our values are strings */
226 351
227response_done: 352response_done:
228 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE; 353 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE;
@@ -249,11 +374,18 @@ void hv_kvp_onchannelcallback(void *context)
249 u64 requestid; 374 u64 requestid;
250 375
251 struct hv_kvp_msg *kvp_msg; 376 struct hv_kvp_msg *kvp_msg;
252 struct hv_kvp_msg_enumerate *kvp_data;
253 377
254 struct icmsg_hdr *icmsghdrp; 378 struct icmsg_hdr *icmsghdrp;
255 struct icmsg_negotiate *negop = NULL; 379 struct icmsg_negotiate *negop = NULL;
256 380
381 if (kvp_transaction.active) {
382 /*
383 * We will defer processing this callback once
384 * the current transaction is complete.
385 */
386 kvp_transaction.kvp_context = context;
387 return;
388 }
257 389
258 vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE, &recvlen, &requestid); 390 vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE, &recvlen, &requestid);
259 391
@@ -268,29 +400,16 @@ void hv_kvp_onchannelcallback(void *context)
268 sizeof(struct vmbuspipe_hdr) + 400 sizeof(struct vmbuspipe_hdr) +
269 sizeof(struct icmsg_hdr)]; 401 sizeof(struct icmsg_hdr)];
270 402
271 kvp_data = &kvp_msg->kvp_data;
272
273 /*
274 * We only support the "get" operation on
275 * "KVP_POOL_AUTO" pool.
276 */
277
278 if ((kvp_msg->kvp_hdr.pool != KVP_POOL_AUTO) ||
279 (kvp_msg->kvp_hdr.operation !=
280 KVP_OP_ENUMERATE)) {
281 icmsghdrp->status = HV_E_FAIL;
282 goto callback_done;
283 }
284
285 /* 403 /*
286 * Stash away this global state for completing the 404 * Stash away this global state for completing the
287 * transaction; note transactions are serialized. 405 * transaction; note transactions are serialized.
288 */ 406 */
407
289 kvp_transaction.recv_len = recvlen; 408 kvp_transaction.recv_len = recvlen;
290 kvp_transaction.recv_channel = channel; 409 kvp_transaction.recv_channel = channel;
291 kvp_transaction.recv_req_id = requestid; 410 kvp_transaction.recv_req_id = requestid;
292 kvp_transaction.active = true; 411 kvp_transaction.active = true;
293 kvp_transaction.index = kvp_data->index; 412 kvp_transaction.kvp_msg = kvp_msg;
294 413
295 /* 414 /*
296 * Get the information from the 415 * Get the information from the
@@ -308,8 +427,6 @@ void hv_kvp_onchannelcallback(void *context)
308 427
309 } 428 }
310 429
311callback_done:
312
313 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION 430 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
314 | ICMSGHDRFLAG_RESPONSE; 431 | ICMSGHDRFLAG_RESPONSE;
315 432
@@ -330,6 +447,14 @@ hv_kvp_init(struct hv_util_service *srv)
330 return err; 447 return err;
331 recv_buffer = srv->recv_buffer; 448 recv_buffer = srv->recv_buffer;
332 449
450 /*
451 * When this driver loads, the user level daemon that
452 * processes the host requests may not yet be running.
453 * Defer processing channel callbacks until the daemon
454 * has registered.
455 */
456 kvp_transaction.active = true;
457
333 return 0; 458 return 0;
334} 459}
335 460
diff --git a/drivers/hv/hv_kvp.h b/drivers/hv/hv_kvp.h
deleted file mode 100644
index 9b765d7df838..000000000000
--- a/drivers/hv/hv_kvp.h
+++ /dev/null
@@ -1,184 +0,0 @@
1/*
2 * An implementation of HyperV key value pair (KVP) functionality for Linux.
3 *
4 *
5 * Copyright (C) 2010, Novell, Inc.
6 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
15 * NON INFRINGEMENT. See the GNU General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23#ifndef _KVP_H
24#define _KVP_H_
25
26/*
27 * Maximum value size - used for both key names and value data, and includes
28 * any applicable NULL terminators.
29 *
30 * Note: This limit is somewhat arbitrary, but falls easily within what is
31 * supported for all native guests (back to Win 2000) and what is reasonable
32 * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
33 * limited to 255 character key names.
34 *
35 * MSDN recommends not storing data values larger than 2048 bytes in the
36 * registry.
37 *
38 * Note: This value is used in defining the KVP exchange message - this value
39 * cannot be modified without affecting the message size and compatibility.
40 */
41
42/*
43 * bytes, including any null terminators
44 */
45#define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
46
47
48/*
49 * Maximum key size - the registry limit for the length of an entry name
50 * is 256 characters, including the null terminator
51 */
52
53#define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
54
55/*
56 * In Linux, we implement the KVP functionality in two components:
57 * 1) The kernel component which is packaged as part of the hv_utils driver
58 * is responsible for communicating with the host and responsible for
59 * implementing the host/guest protocol. 2) A user level daemon that is
60 * responsible for data gathering.
61 *
62 * Host/Guest Protocol: The host iterates over an index and expects the guest
63 * to assign a key name to the index and also return the value corresponding to
64 * the key. The host will have atmost one KVP transaction outstanding at any
65 * given point in time. The host side iteration stops when the guest returns
66 * an error. Microsoft has specified the following mapping of key names to
67 * host specified index:
68 *
69 * Index Key Name
70 * 0 FullyQualifiedDomainName
71 * 1 IntegrationServicesVersion
72 * 2 NetworkAddressIPv4
73 * 3 NetworkAddressIPv6
74 * 4 OSBuildNumber
75 * 5 OSName
76 * 6 OSMajorVersion
77 * 7 OSMinorVersion
78 * 8 OSVersion
79 * 9 ProcessorArchitecture
80 *
81 * The Windows host expects the Key Name and Key Value to be encoded in utf16.
82 *
83 * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
84 * data gathering functionality in a user mode daemon. The user level daemon
85 * is also responsible for binding the key name to the index as well. The
86 * kernel and user-level daemon communicate using a connector channel.
87 *
88 * The user mode component first registers with the
89 * the kernel component. Subsequently, the kernel component requests, data
90 * for the specified keys. In response to this message the user mode component
91 * fills in the value corresponding to the specified key. We overload the
92 * sequence field in the cn_msg header to define our KVP message types.
93 *
94 *
95 * The kernel component simply acts as a conduit for communication between the
96 * Windows host and the user-level daemon. The kernel component passes up the
97 * index received from the Host to the user-level daemon. If the index is
98 * valid (supported), the corresponding key as well as its
99 * value (both are strings) is returned. If the index is invalid
100 * (not supported), a NULL key string is returned.
101 */
102
103/*
104 *
105 * The following definitions are shared with the user-mode component; do not
106 * change any of this without making the corresponding changes in
107 * the KVP user-mode component.
108 */
109
110#define CN_KVP_VAL 0x1 /* This supports queries from the kernel */
111#define CN_KVP_USER_VAL 0x2 /* This supports queries from the user */
112
113enum hv_ku_op {
114 KVP_REGISTER = 0, /* Register the user mode component */
115 KVP_KERNEL_GET, /* Kernel is requesting the value */
116 KVP_KERNEL_SET, /* Kernel is providing the value */
117 KVP_USER_GET, /* User is requesting the value */
118 KVP_USER_SET /* User is providing the value */
119};
120
121struct hv_ku_msg {
122 __u32 kvp_index; /* Key index */
123 __u8 kvp_key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; /* Key name */
124 __u8 kvp_value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; /* Key value */
125};
126
127
128
129
130#ifdef __KERNEL__
131
132/*
133 * Registry value types.
134 */
135
136#define REG_SZ 1
137
138enum hv_kvp_exchg_op {
139 KVP_OP_GET = 0,
140 KVP_OP_SET,
141 KVP_OP_DELETE,
142 KVP_OP_ENUMERATE,
143 KVP_OP_COUNT /* Number of operations, must be last. */
144};
145
146enum hv_kvp_exchg_pool {
147 KVP_POOL_EXTERNAL = 0,
148 KVP_POOL_GUEST,
149 KVP_POOL_AUTO,
150 KVP_POOL_AUTO_EXTERNAL,
151 KVP_POOL_AUTO_INTERNAL,
152 KVP_POOL_COUNT /* Number of pools, must be last. */
153};
154
155struct hv_kvp_hdr {
156 u8 operation;
157 u8 pool;
158};
159
160struct hv_kvp_exchg_msg_value {
161 u32 value_type;
162 u32 key_size;
163 u32 value_size;
164 u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
165 u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
166};
167
168struct hv_kvp_msg_enumerate {
169 u32 index;
170 struct hv_kvp_exchg_msg_value data;
171};
172
173struct hv_kvp_msg {
174 struct hv_kvp_hdr kvp_hdr;
175 struct hv_kvp_msg_enumerate kvp_data;
176};
177
178int hv_kvp_init(struct hv_util_service *);
179void hv_kvp_deinit(void);
180void hv_kvp_onchannelcallback(void *);
181
182#endif /* __KERNEL__ */
183#endif /* _KVP_H */
184
diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
index 55d58f21e6d4..dbb8b8eec210 100644
--- a/drivers/hv/hv_util.c
+++ b/drivers/hv/hv_util.c
@@ -28,9 +28,6 @@
28#include <linux/reboot.h> 28#include <linux/reboot.h>
29#include <linux/hyperv.h> 29#include <linux/hyperv.h>
30 30
31#include "hv_kvp.h"
32
33
34static void shutdown_onchannelcallback(void *context); 31static void shutdown_onchannelcallback(void *context);
35static struct hv_util_service util_shutdown = { 32static struct hv_util_service util_shutdown = {
36 .util_cb = shutdown_onchannelcallback, 33 .util_cb = shutdown_onchannelcallback,
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 6d7d286d5440..699f0d8e59ed 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -457,7 +457,6 @@ static const uuid_le VMBUS_SERVICE_ID = {
457 }, 457 },
458}; 458};
459 459
460#define MAX_NUM_CPUS 32
461 460
462 461
463struct hv_input_signal_event_buffer { 462struct hv_input_signal_event_buffer {
@@ -483,8 +482,8 @@ struct hv_context {
483 /* 8-bytes aligned of the buffer above */ 482 /* 8-bytes aligned of the buffer above */
484 struct hv_input_signal_event *signal_event_param; 483 struct hv_input_signal_event *signal_event_param;
485 484
486 void *synic_message_page[MAX_NUM_CPUS]; 485 void *synic_message_page[NR_CPUS];
487 void *synic_event_page[MAX_NUM_CPUS]; 486 void *synic_event_page[NR_CPUS];
488}; 487};
489 488
490extern struct hv_context hv_context; 489extern struct hv_context hv_context;
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index a6c6ec36615e..249ac460e3d9 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -39,6 +39,7 @@
39#include <linux/moduleparam.h> 39#include <linux/moduleparam.h>
40#include <asm/msr.h> 40#include <asm/msr.h>
41#include <asm/processor.h> 41#include <asm/processor.h>
42#include <asm/cpu_device_id.h>
42 43
43#define DRVNAME "coretemp" 44#define DRVNAME "coretemp"
44 45
@@ -759,13 +760,23 @@ static struct notifier_block coretemp_cpu_notifier __refdata = {
759 .notifier_call = coretemp_cpu_callback, 760 .notifier_call = coretemp_cpu_callback,
760}; 761};
761 762
763static const struct x86_cpu_id coretemp_ids[] = {
764 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_DTS },
765 {}
766};
767MODULE_DEVICE_TABLE(x86cpu, coretemp_ids);
768
762static int __init coretemp_init(void) 769static int __init coretemp_init(void)
763{ 770{
764 int i, err = -ENODEV; 771 int i, err = -ENODEV;
765 772
766 /* quick check if we run Intel */ 773 /*
767 if (cpu_data(0).x86_vendor != X86_VENDOR_INTEL) 774 * CPUID.06H.EAX[0] indicates whether the CPU has thermal
768 goto exit; 775 * sensors. We check this bit only, all the early CPUs
776 * without thermal sensors will be filtered out.
777 */
778 if (!x86_match_cpu(coretemp_ids))
779 return -ENODEV;
769 780
770 err = platform_driver_register(&coretemp_driver); 781 err = platform_driver_register(&coretemp_driver);
771 if (err) 782 if (err)
diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
index 8eac67d769fa..8689664ef03c 100644
--- a/drivers/hwmon/via-cputemp.c
+++ b/drivers/hwmon/via-cputemp.c
@@ -37,6 +37,7 @@
37#include <linux/cpu.h> 37#include <linux/cpu.h>
38#include <asm/msr.h> 38#include <asm/msr.h>
39#include <asm/processor.h> 39#include <asm/processor.h>
40#include <asm/cpu_device_id.h>
40 41
41#define DRVNAME "via_cputemp" 42#define DRVNAME "via_cputemp"
42 43
@@ -308,15 +309,20 @@ static struct notifier_block via_cputemp_cpu_notifier __refdata = {
308 .notifier_call = via_cputemp_cpu_callback, 309 .notifier_call = via_cputemp_cpu_callback,
309}; 310};
310 311
312static const struct x86_cpu_id cputemp_ids[] = {
313 { X86_VENDOR_CENTAUR, 6, 0xa, }, /* C7 A */
314 { X86_VENDOR_CENTAUR, 6, 0xd, }, /* C7 D */
315 { X86_VENDOR_CENTAUR, 6, 0xf, }, /* Nano */
316 {}
317};
318MODULE_DEVICE_TABLE(x86cpu, cputemp_ids);
319
311static int __init via_cputemp_init(void) 320static int __init via_cputemp_init(void)
312{ 321{
313 int i, err; 322 int i, err;
314 323
315 if (cpu_data(0).x86_vendor != X86_VENDOR_CENTAUR) { 324 if (!x86_match_cpu(cputemp_ids))
316 printk(KERN_DEBUG DRVNAME ": Not a VIA CPU\n"); 325 return -ENODEV;
317 err = -ENODEV;
318 goto exit;
319 }
320 326
321 err = platform_driver_register(&via_cputemp_driver); 327 err = platform_driver_register(&via_cputemp_driver);
322 if (err) 328 if (err)
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index 54ab97bae042..1c15e9b33575 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -62,6 +62,7 @@
62#include <linux/notifier.h> 62#include <linux/notifier.h>
63#include <linux/cpu.h> 63#include <linux/cpu.h>
64#include <linux/module.h> 64#include <linux/module.h>
65#include <asm/cpu_device_id.h>
65#include <asm/mwait.h> 66#include <asm/mwait.h>
66#include <asm/msr.h> 67#include <asm/msr.h>
67 68
@@ -81,6 +82,17 @@ static unsigned int mwait_substates;
81/* Reliable LAPIC Timer States, bit 1 for C1 etc. */ 82/* Reliable LAPIC Timer States, bit 1 for C1 etc. */
82static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */ 83static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
83 84
85struct idle_cpu {
86 struct cpuidle_state *state_table;
87
88 /*
89 * Hardware C-state auto-demotion may not always be optimal.
90 * Indicate which enable bits to clear here.
91 */
92 unsigned long auto_demotion_disable_flags;
93};
94
95static const struct idle_cpu *icpu;
84static struct cpuidle_device __percpu *intel_idle_cpuidle_devices; 96static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
85static int intel_idle(struct cpuidle_device *dev, 97static int intel_idle(struct cpuidle_device *dev,
86 struct cpuidle_driver *drv, int index); 98 struct cpuidle_driver *drv, int index);
@@ -88,12 +100,6 @@ static int intel_idle(struct cpuidle_device *dev,
88static struct cpuidle_state *cpuidle_state_table; 100static struct cpuidle_state *cpuidle_state_table;
89 101
90/* 102/*
91 * Hardware C-state auto-demotion may not always be optimal.
92 * Indicate which enable bits to clear here.
93 */
94static unsigned long long auto_demotion_disable_flags;
95
96/*
97 * Set this flag for states where the HW flushes the TLB for us 103 * Set this flag for states where the HW flushes the TLB for us
98 * and so we don't need cross-calls to keep it consistent. 104 * and so we don't need cross-calls to keep it consistent.
99 * If this flag is set, SW flushes the TLB, so even if the 105 * If this flag is set, SW flushes the TLB, so even if the
@@ -319,27 +325,68 @@ static void auto_demotion_disable(void *dummy)
319 unsigned long long msr_bits; 325 unsigned long long msr_bits;
320 326
321 rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits); 327 rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
322 msr_bits &= ~auto_demotion_disable_flags; 328 msr_bits &= ~(icpu->auto_demotion_disable_flags);
323 wrmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits); 329 wrmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
324} 330}
325 331
332static const struct idle_cpu idle_cpu_nehalem = {
333 .state_table = nehalem_cstates,
334 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
335};
336
337static const struct idle_cpu idle_cpu_atom = {
338 .state_table = atom_cstates,
339};
340
341static const struct idle_cpu idle_cpu_lincroft = {
342 .state_table = atom_cstates,
343 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
344};
345
346static const struct idle_cpu idle_cpu_snb = {
347 .state_table = snb_cstates,
348};
349
350#define ICPU(model, cpu) \
351 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&cpu }
352
353static const struct x86_cpu_id intel_idle_ids[] = {
354 ICPU(0x1a, idle_cpu_nehalem),
355 ICPU(0x1e, idle_cpu_nehalem),
356 ICPU(0x1f, idle_cpu_nehalem),
357 ICPU(0x25, idle_cpu_nehalem),
358 ICPU(0x2c, idle_cpu_nehalem),
359 ICPU(0x2e, idle_cpu_nehalem),
360 ICPU(0x1c, idle_cpu_atom),
361 ICPU(0x26, idle_cpu_lincroft),
362 ICPU(0x2f, idle_cpu_nehalem),
363 ICPU(0x2a, idle_cpu_snb),
364 ICPU(0x2d, idle_cpu_snb),
365 {}
366};
367MODULE_DEVICE_TABLE(x86cpu, intel_idle_ids);
368
326/* 369/*
327 * intel_idle_probe() 370 * intel_idle_probe()
328 */ 371 */
329static int intel_idle_probe(void) 372static int intel_idle_probe(void)
330{ 373{
331 unsigned int eax, ebx, ecx; 374 unsigned int eax, ebx, ecx;
375 const struct x86_cpu_id *id;
332 376
333 if (max_cstate == 0) { 377 if (max_cstate == 0) {
334 pr_debug(PREFIX "disabled\n"); 378 pr_debug(PREFIX "disabled\n");
335 return -EPERM; 379 return -EPERM;
336 } 380 }
337 381
338 if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) 382 id = x86_match_cpu(intel_idle_ids);
339 return -ENODEV; 383 if (!id) {
340 384 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
341 if (!boot_cpu_has(X86_FEATURE_MWAIT)) 385 boot_cpu_data.x86 == 6)
386 pr_debug(PREFIX "does not run on family %d model %d\n",
387 boot_cpu_data.x86, boot_cpu_data.x86_model);
342 return -ENODEV; 388 return -ENODEV;
389 }
343 390
344 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF) 391 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
345 return -ENODEV; 392 return -ENODEV;
@@ -353,43 +400,8 @@ static int intel_idle_probe(void)
353 400
354 pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates); 401 pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
355 402
356 403 icpu = (const struct idle_cpu *)id->driver_data;
357 if (boot_cpu_data.x86 != 6) /* family 6 */ 404 cpuidle_state_table = icpu->state_table;
358 return -ENODEV;
359
360 switch (boot_cpu_data.x86_model) {
361
362 case 0x1A: /* Core i7, Xeon 5500 series */
363 case 0x1E: /* Core i7 and i5 Processor - Lynnfield Jasper Forest */
364 case 0x1F: /* Core i7 and i5 Processor - Nehalem */
365 case 0x2E: /* Nehalem-EX Xeon */
366 case 0x2F: /* Westmere-EX Xeon */
367 case 0x25: /* Westmere */
368 case 0x2C: /* Westmere */
369 cpuidle_state_table = nehalem_cstates;
370 auto_demotion_disable_flags =
371 (NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE);
372 break;
373
374 case 0x1C: /* 28 - Atom Processor */
375 cpuidle_state_table = atom_cstates;
376 break;
377
378 case 0x26: /* 38 - Lincroft Atom Processor */
379 cpuidle_state_table = atom_cstates;
380 auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE;
381 break;
382
383 case 0x2A: /* SNB */
384 case 0x2D: /* SNB Xeon */
385 cpuidle_state_table = snb_cstates;
386 break;
387
388 default:
389 pr_debug(PREFIX "does not run on family %d model %d\n",
390 boot_cpu_data.x86, boot_cpu_data.x86_model);
391 return -ENODEV;
392 }
393 405
394 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */ 406 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
395 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE; 407 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
@@ -470,7 +482,7 @@ static int intel_idle_cpuidle_driver_init(void)
470 drv->state_count += 1; 482 drv->state_count += 1;
471 } 483 }
472 484
473 if (auto_demotion_disable_flags) 485 if (icpu->auto_demotion_disable_flags)
474 on_each_cpu(auto_demotion_disable, NULL, 1); 486 on_each_cpu(auto_demotion_disable, NULL, 1);
475 487
476 return 0; 488 return 0;
@@ -522,7 +534,7 @@ int intel_idle_cpu_init(int cpu)
522 return -EIO; 534 return -EIO;
523 } 535 }
524 536
525 if (auto_demotion_disable_flags) 537 if (icpu->auto_demotion_disable_flags)
526 smp_call_function_single(cpu, auto_demotion_disable, NULL, 1); 538 smp_call_function_single(cpu, auto_demotion_disable, NULL, 1);
527 539
528 return 0; 540 return 0;
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
index c351aa421f8f..da739d9d1905 100644
--- a/drivers/input/gameport/gameport.c
+++ b/drivers/input/gameport/gameport.c
@@ -449,7 +449,6 @@ static ssize_t gameport_rebind_driver(struct device *dev, struct device_attribut
449 } else if ((drv = driver_find(buf, &gameport_bus)) != NULL) { 449 } else if ((drv = driver_find(buf, &gameport_bus)) != NULL) {
450 gameport_disconnect_port(gameport); 450 gameport_disconnect_port(gameport);
451 error = gameport_bind_driver(gameport, to_gameport_driver(drv)); 451 error = gameport_bind_driver(gameport, to_gameport_driver(drv));
452 put_driver(drv);
453 } else { 452 } else {
454 error = -EINVAL; 453 error = -EINVAL;
455 } 454 }
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index ba70058e2be3..d0f7533dbf88 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -441,7 +441,6 @@ static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *
441 } else if ((drv = driver_find(buf, &serio_bus)) != NULL) { 441 } else if ((drv = driver_find(buf, &serio_bus)) != NULL) {
442 serio_disconnect_port(serio); 442 serio_disconnect_port(serio);
443 error = serio_bind_driver(serio, to_serio_driver(drv)); 443 error = serio_bind_driver(serio, to_serio_driver(drv));
444 put_driver(drv);
445 serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT); 444 serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT);
446 } else { 445 } else {
447 error = -EINVAL; 446 error = -EINVAL;
diff --git a/drivers/media/video/cx18/cx18-alsa-main.c b/drivers/media/video/cx18/cx18-alsa-main.c
index a1e6c2a32478..e118361c2e7b 100644
--- a/drivers/media/video/cx18/cx18-alsa-main.c
+++ b/drivers/media/video/cx18/cx18-alsa-main.c
@@ -285,7 +285,6 @@ static void __exit cx18_alsa_exit(void)
285 285
286 drv = driver_find("cx18", &pci_bus_type); 286 drv = driver_find("cx18", &pci_bus_type);
287 ret = driver_for_each_device(drv, NULL, NULL, cx18_alsa_exit_callback); 287 ret = driver_for_each_device(drv, NULL, NULL, cx18_alsa_exit_callback);
288 put_driver(drv);
289 288
290 cx18_ext_init = NULL; 289 cx18_ext_init = NULL;
291 printk(KERN_INFO "cx18-alsa: module unload complete\n"); 290 printk(KERN_INFO "cx18-alsa: module unload complete\n");
diff --git a/drivers/media/video/ivtv/ivtvfb.c b/drivers/media/video/ivtv/ivtvfb.c
index d0fbfcf7133d..e5e7fa9e737b 100644
--- a/drivers/media/video/ivtv/ivtvfb.c
+++ b/drivers/media/video/ivtv/ivtvfb.c
@@ -1293,7 +1293,6 @@ static int __init ivtvfb_init(void)
1293 1293
1294 drv = driver_find("ivtv", &pci_bus_type); 1294 drv = driver_find("ivtv", &pci_bus_type);
1295 err = driver_for_each_device(drv, NULL, &registered, ivtvfb_callback_init); 1295 err = driver_for_each_device(drv, NULL, &registered, ivtvfb_callback_init);
1296 put_driver(drv);
1297 if (!registered) { 1296 if (!registered) {
1298 printk(KERN_ERR "ivtvfb: no cards found\n"); 1297 printk(KERN_ERR "ivtvfb: no cards found\n");
1299 return -ENODEV; 1298 return -ENODEV;
@@ -1310,7 +1309,6 @@ static void ivtvfb_cleanup(void)
1310 1309
1311 drv = driver_find("ivtv", &pci_bus_type); 1310 drv = driver_find("ivtv", &pci_bus_type);
1312 err = driver_for_each_device(drv, NULL, NULL, ivtvfb_callback_cleanup); 1311 err = driver_for_each_device(drv, NULL, NULL, ivtvfb_callback_cleanup);
1313 put_driver(drv);
1314} 1312}
1315 1313
1316module_init(ivtvfb_init); 1314module_init(ivtvfb_init);
diff --git a/drivers/media/video/s5p-fimc/fimc-mdevice.c b/drivers/media/video/s5p-fimc/fimc-mdevice.c
index 8ea4ee116e46..63eccb55728f 100644
--- a/drivers/media/video/s5p-fimc/fimc-mdevice.c
+++ b/drivers/media/video/s5p-fimc/fimc-mdevice.c
@@ -344,16 +344,13 @@ static int fimc_md_register_platform_entities(struct fimc_md *fmd)
344 return -ENODEV; 344 return -ENODEV;
345 ret = driver_for_each_device(driver, NULL, fmd, 345 ret = driver_for_each_device(driver, NULL, fmd,
346 fimc_register_callback); 346 fimc_register_callback);
347 put_driver(driver);
348 if (ret) 347 if (ret)
349 return ret; 348 return ret;
350 349
351 driver = driver_find(CSIS_DRIVER_NAME, &platform_bus_type); 350 driver = driver_find(CSIS_DRIVER_NAME, &platform_bus_type);
352 if (driver) { 351 if (driver)
353 ret = driver_for_each_device(driver, NULL, fmd, 352 ret = driver_for_each_device(driver, NULL, fmd,
354 csis_register_callback); 353 csis_register_callback);
355 put_driver(driver);
356 }
357 return ret; 354 return ret;
358} 355}
359 356
diff --git a/drivers/media/video/s5p-tv/mixer_video.c b/drivers/media/video/s5p-tv/mixer_video.c
index 7884baeff76a..f7ca5cc143c6 100644
--- a/drivers/media/video/s5p-tv/mixer_video.c
+++ b/drivers/media/video/s5p-tv/mixer_video.c
@@ -58,7 +58,6 @@ static struct v4l2_subdev *find_and_register_subdev(
58 } 58 }
59 59
60done: 60done:
61 put_driver(drv);
62 return sd; 61 return sd;
63} 62}
64 63
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index f320f466f03b..e8c42d6a7d1c 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -915,9 +915,7 @@ static int phy_probe(struct device *dev)
915 915
916 phydev = to_phy_device(dev); 916 phydev = to_phy_device(dev);
917 917
918 /* Make sure the driver is held. 918 drv = phydev->dev.driver;
919 * XXX -- Is this correct? */
920 drv = get_driver(phydev->dev.driver);
921 phydrv = to_phy_driver(drv); 919 phydrv = to_phy_driver(drv);
922 phydev->drv = phydrv; 920 phydev->drv = phydrv;
923 921
@@ -957,8 +955,6 @@ static int phy_remove(struct device *dev)
957 955
958 if (phydev->drv->remove) 956 if (phydev->drv->remove)
959 phydev->drv->remove(phydev); 957 phydev->drv->remove(phydev);
960
961 put_driver(dev->driver);
962 phydev->drv = NULL; 958 phydev->drv = NULL;
963 959
964 return 0; 960 return 0;
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 3623d65f8b86..8d9616b821ca 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -72,9 +72,7 @@ int pci_add_dynid(struct pci_driver *drv,
72 list_add_tail(&dynid->node, &drv->dynids.list); 72 list_add_tail(&dynid->node, &drv->dynids.list);
73 spin_unlock(&drv->dynids.lock); 73 spin_unlock(&drv->dynids.lock);
74 74
75 get_driver(&drv->driver);
76 retval = driver_attach(&drv->driver); 75 retval = driver_attach(&drv->driver);
77 put_driver(&drv->driver);
78 76
79 return retval; 77 return retval;
80} 78}
@@ -190,43 +188,34 @@ store_remove_id(struct device_driver *driver, const char *buf, size_t count)
190static DRIVER_ATTR(remove_id, S_IWUSR, NULL, store_remove_id); 188static DRIVER_ATTR(remove_id, S_IWUSR, NULL, store_remove_id);
191 189
192static int 190static int
193pci_create_newid_file(struct pci_driver *drv) 191pci_create_newid_files(struct pci_driver *drv)
194{ 192{
195 int error = 0; 193 int error = 0;
196 if (drv->probe != NULL)
197 error = driver_create_file(&drv->driver, &driver_attr_new_id);
198 return error;
199}
200
201static void pci_remove_newid_file(struct pci_driver *drv)
202{
203 driver_remove_file(&drv->driver, &driver_attr_new_id);
204}
205 194
206static int 195 if (drv->probe != NULL) {
207pci_create_removeid_file(struct pci_driver *drv) 196 error = driver_create_file(&drv->driver, &driver_attr_new_id);
208{ 197 if (error == 0) {
209 int error = 0; 198 error = driver_create_file(&drv->driver,
210 if (drv->probe != NULL) 199 &driver_attr_remove_id);
211 error = driver_create_file(&drv->driver,&driver_attr_remove_id); 200 if (error)
201 driver_remove_file(&drv->driver,
202 &driver_attr_new_id);
203 }
204 }
212 return error; 205 return error;
213} 206}
214 207
215static void pci_remove_removeid_file(struct pci_driver *drv) 208static void pci_remove_newid_files(struct pci_driver *drv)
216{ 209{
217 driver_remove_file(&drv->driver, &driver_attr_remove_id); 210 driver_remove_file(&drv->driver, &driver_attr_remove_id);
211 driver_remove_file(&drv->driver, &driver_attr_new_id);
218} 212}
219#else /* !CONFIG_HOTPLUG */ 213#else /* !CONFIG_HOTPLUG */
220static inline int pci_create_newid_file(struct pci_driver *drv) 214static inline int pci_create_newid_files(struct pci_driver *drv)
221{ 215{
222 return 0; 216 return 0;
223} 217}
224static inline void pci_remove_newid_file(struct pci_driver *drv) {} 218static inline void pci_remove_newid_files(struct pci_driver *drv) {}
225static inline int pci_create_removeid_file(struct pci_driver *drv)
226{
227 return 0;
228}
229static inline void pci_remove_removeid_file(struct pci_driver *drv) {}
230#endif 219#endif
231 220
232/** 221/**
@@ -1138,18 +1127,12 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner,
1138 if (error) 1127 if (error)
1139 goto out; 1128 goto out;
1140 1129
1141 error = pci_create_newid_file(drv); 1130 error = pci_create_newid_files(drv);
1142 if (error) 1131 if (error)
1143 goto out_newid; 1132 goto out_newid;
1144
1145 error = pci_create_removeid_file(drv);
1146 if (error)
1147 goto out_removeid;
1148out: 1133out:
1149 return error; 1134 return error;
1150 1135
1151out_removeid:
1152 pci_remove_newid_file(drv);
1153out_newid: 1136out_newid:
1154 driver_unregister(&drv->driver); 1137 driver_unregister(&drv->driver);
1155 goto out; 1138 goto out;
@@ -1168,8 +1151,7 @@ out_newid:
1168void 1151void
1169pci_unregister_driver(struct pci_driver *drv) 1152pci_unregister_driver(struct pci_driver *drv)
1170{ 1153{
1171 pci_remove_removeid_file(drv); 1154 pci_remove_newid_files(drv);
1172 pci_remove_newid_file(drv);
1173 driver_unregister(&drv->driver); 1155 driver_unregister(&drv->driver);
1174 pci_free_dynids(drv); 1156 pci_free_dynids(drv);
1175} 1157}
diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index 1620088a0e7e..401090110922 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -593,7 +593,7 @@ static pci_ers_result_t pcifront_common_process(int cmd,
593 } 593 }
594 pdrv = pcidev->driver; 594 pdrv = pcidev->driver;
595 595
596 if (get_driver(&pdrv->driver)) { 596 if (pdrv) {
597 if (pdrv->err_handler && pdrv->err_handler->error_detected) { 597 if (pdrv->err_handler && pdrv->err_handler->error_detected) {
598 dev_dbg(&pcidev->dev, 598 dev_dbg(&pcidev->dev,
599 "trying to call AER service\n"); 599 "trying to call AER service\n");
@@ -623,7 +623,6 @@ static pci_ers_result_t pcifront_common_process(int cmd,
623 } 623 }
624 } 624 }
625 } 625 }
626 put_driver(&pdrv->driver);
627 } 626 }
628 if (!flag) 627 if (!flag)
629 result = PCI_ERS_RESULT_NONE; 628 result = PCI_ERS_RESULT_NONE;
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 1932029de48d..079629bff957 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -127,10 +127,7 @@ pcmcia_store_new_id(struct device_driver *driver, const char *buf, size_t count)
127 list_add_tail(&dynid->node, &pdrv->dynids.list); 127 list_add_tail(&dynid->node, &pdrv->dynids.list);
128 mutex_unlock(&pdrv->dynids.lock); 128 mutex_unlock(&pdrv->dynids.lock);
129 129
130 if (get_driver(&pdrv->drv)) { 130 retval = driver_attach(&pdrv->drv);
131 retval = driver_attach(&pdrv->drv);
132 put_driver(&pdrv->drv);
133 }
134 131
135 if (retval) 132 if (retval)
136 return retval; 133 return retval;
@@ -160,6 +157,11 @@ pcmcia_create_newid_file(struct pcmcia_driver *drv)
160 return error; 157 return error;
161} 158}
162 159
160static void
161pcmcia_remove_newid_file(struct pcmcia_driver *drv)
162{
163 driver_remove_file(&drv->drv, &driver_attr_new_id);
164}
163 165
164/** 166/**
165 * pcmcia_register_driver - register a PCMCIA driver with the bus core 167 * pcmcia_register_driver - register a PCMCIA driver with the bus core
@@ -204,6 +206,7 @@ EXPORT_SYMBOL(pcmcia_register_driver);
204void pcmcia_unregister_driver(struct pcmcia_driver *driver) 206void pcmcia_unregister_driver(struct pcmcia_driver *driver)
205{ 207{
206 pr_debug("unregistering driver %s\n", driver->name); 208 pr_debug("unregistering driver %s\n", driver->name);
209 pcmcia_remove_newid_file(driver);
207 driver_unregister(&driver->drv); 210 driver_unregister(&driver->drv);
208 pcmcia_free_dynids(driver); 211 pcmcia_free_dynids(driver);
209} 212}
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 3a8daf858742..459f66437fe9 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -76,6 +76,20 @@ config BATTERY_DS2780
76 help 76 help
77 Say Y here to enable support for batteries with ds2780 chip. 77 Say Y here to enable support for batteries with ds2780 chip.
78 78
79config BATTERY_DS2781
80 tristate "2781 battery driver"
81 depends on HAS_IOMEM
82 select W1
83 select W1_SLAVE_DS2781
84 help
85 If you enable this you will have the DS2781 battery driver support.
86
87 The battery monitor chip is used in many batteries/devices
88 as the one who is responsible for charging/discharging/monitoring
89 Li+ batteries.
90
91 If you are unsure, say N.
92
79config BATTERY_DS2782 93config BATTERY_DS2782
80 tristate "DS2782/DS2786 standalone gas-gauge" 94 tristate "DS2782/DS2786 standalone gas-gauge"
81 depends on I2C 95 depends on I2C
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index e429008eaf10..c590fa533406 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_TEST_POWER) += test_power.o
16 16
17obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o 17obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o
18obj-$(CONFIG_BATTERY_DS2780) += ds2780_battery.o 18obj-$(CONFIG_BATTERY_DS2780) += ds2780_battery.o
19obj-$(CONFIG_BATTERY_DS2781) += ds2781_battery.o
19obj-$(CONFIG_BATTERY_DS2782) += ds2782_battery.o 20obj-$(CONFIG_BATTERY_DS2782) += ds2782_battery.o
20obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o 21obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o
21obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o 22obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o
diff --git a/drivers/power/ds2781_battery.c b/drivers/power/ds2781_battery.c
new file mode 100644
index 000000000000..ca0d653d0a7a
--- /dev/null
+++ b/drivers/power/ds2781_battery.c
@@ -0,0 +1,874 @@
1/*
2 * 1-wire client/driver for the Maxim/Dallas DS2781 Stand-Alone Fuel Gauge IC
3 *
4 * Author: Renata Sayakhova <renata@oktetlabs.ru>
5 *
6 * Based on ds2780_battery drivers
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/slab.h>
16#include <linux/param.h>
17#include <linux/pm.h>
18#include <linux/platform_device.h>
19#include <linux/power_supply.h>
20#include <linux/idr.h>
21
22#include "../w1/w1.h"
23#include "../w1/slaves/w1_ds2781.h"
24
25/* Current unit measurement in uA for a 1 milli-ohm sense resistor */
26#define DS2781_CURRENT_UNITS 1563
27/* Charge unit measurement in uAh for a 1 milli-ohm sense resistor */
28#define DS2781_CHARGE_UNITS 6250
29/* Number of bytes in user EEPROM space */
30#define DS2781_USER_EEPROM_SIZE (DS2781_EEPROM_BLOCK0_END - \
31 DS2781_EEPROM_BLOCK0_START + 1)
32/* Number of bytes in parameter EEPROM space */
33#define DS2781_PARAM_EEPROM_SIZE (DS2781_EEPROM_BLOCK1_END - \
34 DS2781_EEPROM_BLOCK1_START + 1)
35
36struct ds2781_device_info {
37 struct device *dev;
38 struct power_supply bat;
39 struct device *w1_dev;
40 struct task_struct *mutex_holder;
41};
42
43enum current_types {
44 CURRENT_NOW,
45 CURRENT_AVG,
46};
47
48static const char model[] = "DS2781";
49static const char manufacturer[] = "Maxim/Dallas";
50
51static inline struct ds2781_device_info *
52to_ds2781_device_info(struct power_supply *psy)
53{
54 return container_of(psy, struct ds2781_device_info, bat);
55}
56
57static inline struct power_supply *to_power_supply(struct device *dev)
58{
59 return dev_get_drvdata(dev);
60}
61
62static inline int ds2781_battery_io(struct ds2781_device_info *dev_info,
63 char *buf, int addr, size_t count, int io)
64{
65 if (dev_info->mutex_holder == current)
66 return w1_ds2781_io_nolock(dev_info->w1_dev, buf, addr,
67 count, io);
68 else
69 return w1_ds2781_io(dev_info->w1_dev, buf, addr, count, io);
70}
71
72int w1_ds2781_read(struct ds2781_device_info *dev_info, char *buf,
73 int addr, size_t count)
74{
75 return ds2781_battery_io(dev_info, buf, addr, count, 0);
76}
77
78static inline int ds2781_read8(struct ds2781_device_info *dev_info, u8 *val,
79 int addr)
80{
81 return ds2781_battery_io(dev_info, val, addr, sizeof(u8), 0);
82}
83
84static int ds2781_read16(struct ds2781_device_info *dev_info, s16 *val,
85 int addr)
86{
87 int ret;
88 u8 raw[2];
89
90 ret = ds2781_battery_io(dev_info, raw, addr, sizeof(raw), 0);
91 if (ret < 0)
92 return ret;
93
94 *val = (raw[0] << 8) | raw[1];
95
96 return 0;
97}
98
99static inline int ds2781_read_block(struct ds2781_device_info *dev_info,
100 u8 *val, int addr, size_t count)
101{
102 return ds2781_battery_io(dev_info, val, addr, count, 0);
103}
104
105static inline int ds2781_write(struct ds2781_device_info *dev_info, u8 *val,
106 int addr, size_t count)
107{
108 return ds2781_battery_io(dev_info, val, addr, count, 1);
109}
110
111static inline int ds2781_store_eeprom(struct device *dev, int addr)
112{
113 return w1_ds2781_eeprom_cmd(dev, addr, W1_DS2781_COPY_DATA);
114}
115
116static inline int ds2781_recall_eeprom(struct device *dev, int addr)
117{
118 return w1_ds2781_eeprom_cmd(dev, addr, W1_DS2781_RECALL_DATA);
119}
120
121static int ds2781_save_eeprom(struct ds2781_device_info *dev_info, int reg)
122{
123 int ret;
124
125 ret = ds2781_store_eeprom(dev_info->w1_dev, reg);
126 if (ret < 0)
127 return ret;
128
129 ret = ds2781_recall_eeprom(dev_info->w1_dev, reg);
130 if (ret < 0)
131 return ret;
132
133 return 0;
134}
135
136/* Set sense resistor value in mhos */
137static int ds2781_set_sense_register(struct ds2781_device_info *dev_info,
138 u8 conductance)
139{
140 int ret;
141
142 ret = ds2781_write(dev_info, &conductance,
143 DS2781_RSNSP, sizeof(u8));
144 if (ret < 0)
145 return ret;
146
147 return ds2781_save_eeprom(dev_info, DS2781_RSNSP);
148}
149
150/* Get RSGAIN value from 0 to 1.999 in steps of 0.001 */
151static int ds2781_get_rsgain_register(struct ds2781_device_info *dev_info,
152 u16 *rsgain)
153{
154 return ds2781_read16(dev_info, rsgain, DS2781_RSGAIN_MSB);
155}
156
157/* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */
158static int ds2781_set_rsgain_register(struct ds2781_device_info *dev_info,
159 u16 rsgain)
160{
161 int ret;
162 u8 raw[] = {rsgain >> 8, rsgain & 0xFF};
163
164 ret = ds2781_write(dev_info, raw,
165 DS2781_RSGAIN_MSB, sizeof(raw));
166 if (ret < 0)
167 return ret;
168
169 return ds2781_save_eeprom(dev_info, DS2781_RSGAIN_MSB);
170}
171
172static int ds2781_get_voltage(struct ds2781_device_info *dev_info,
173 int *voltage_uV)
174{
175 int ret;
176 char val[2];
177 int voltage_raw;
178
179 ret = w1_ds2781_read(dev_info, val, DS2781_VOLT_MSB, 2 * sizeof(u8));
180 if (ret < 0)
181 return ret;
182 /*
183 * The voltage value is located in 10 bits across the voltage MSB
184 * and LSB registers in two's compliment form
185 * Sign bit of the voltage value is in bit 7 of the voltage MSB register
186 * Bits 9 - 3 of the voltage value are in bits 6 - 0 of the
187 * voltage MSB register
188 * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the
189 * voltage LSB register
190 */
191 voltage_raw = (val[0] << 3) |
192 (val[1] >> 5);
193
194 /* DS2781 reports voltage in units of 9.76mV, but the battery class
195 * reports in units of uV, so convert by multiplying by 9760. */
196 *voltage_uV = voltage_raw * 9760;
197
198 return 0;
199}
200
201static int ds2781_get_temperature(struct ds2781_device_info *dev_info,
202 int *temp)
203{
204 int ret;
205 char val[2];
206 int temp_raw;
207
208 ret = w1_ds2781_read(dev_info, val, DS2781_TEMP_MSB, 2 * sizeof(u8));
209 if (ret < 0)
210 return ret;
211 /*
212 * The temperature value is located in 10 bits across the temperature
213 * MSB and LSB registers in two's compliment form
214 * Sign bit of the temperature value is in bit 7 of the temperature
215 * MSB register
216 * Bits 9 - 3 of the temperature value are in bits 6 - 0 of the
217 * temperature MSB register
218 * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the
219 * temperature LSB register
220 */
221 temp_raw = ((val[0]) << 3) |
222 (val[1] >> 5);
223 *temp = temp_raw + (temp_raw / 4);
224
225 return 0;
226}
227
228static int ds2781_get_current(struct ds2781_device_info *dev_info,
229 enum current_types type, int *current_uA)
230{
231 int ret, sense_res;
232 s16 current_raw;
233 u8 sense_res_raw, reg_msb;
234
235 /*
236 * The units of measurement for current are dependent on the value of
237 * the sense resistor.
238 */
239 ret = ds2781_read8(dev_info, &sense_res_raw, DS2781_RSNSP);
240 if (ret < 0)
241 return ret;
242
243 if (sense_res_raw == 0) {
244 dev_err(dev_info->dev, "sense resistor value is 0\n");
245 return -EINVAL;
246 }
247 sense_res = 1000 / sense_res_raw;
248
249 if (type == CURRENT_NOW)
250 reg_msb = DS2781_CURRENT_MSB;
251 else if (type == CURRENT_AVG)
252 reg_msb = DS2781_IAVG_MSB;
253 else
254 return -EINVAL;
255
256 /*
257 * The current value is located in 16 bits across the current MSB
258 * and LSB registers in two's compliment form
259 * Sign bit of the current value is in bit 7 of the current MSB register
260 * Bits 14 - 8 of the current value are in bits 6 - 0 of the current
261 * MSB register
262 * Bits 7 - 0 of the current value are in bits 7 - 0 of the current
263 * LSB register
264 */
265 ret = ds2781_read16(dev_info, &current_raw, reg_msb);
266 if (ret < 0)
267 return ret;
268
269 *current_uA = current_raw * (DS2781_CURRENT_UNITS / sense_res);
270 return 0;
271}
272
273static int ds2781_get_accumulated_current(struct ds2781_device_info *dev_info,
274 int *accumulated_current)
275{
276 int ret, sense_res;
277 s16 current_raw;
278 u8 sense_res_raw;
279
280 /*
281 * The units of measurement for accumulated current are dependent on
282 * the value of the sense resistor.
283 */
284 ret = ds2781_read8(dev_info, &sense_res_raw, DS2781_RSNSP);
285 if (ret < 0)
286 return ret;
287
288 if (sense_res_raw == 0) {
289 dev_err(dev_info->dev, "sense resistor value is 0\n");
290 return -EINVAL;
291 }
292 sense_res = 1000 / sense_res_raw;
293
294 /*
295 * The ACR value is located in 16 bits across the ACR MSB and
296 * LSB registers
297 * Bits 15 - 8 of the ACR value are in bits 7 - 0 of the ACR
298 * MSB register
299 * Bits 7 - 0 of the ACR value are in bits 7 - 0 of the ACR
300 * LSB register
301 */
302 ret = ds2781_read16(dev_info, &current_raw, DS2781_ACR_MSB);
303 if (ret < 0)
304 return ret;
305
306 *accumulated_current = current_raw * (DS2781_CHARGE_UNITS / sense_res);
307 return 0;
308}
309
310static int ds2781_get_capacity(struct ds2781_device_info *dev_info,
311 int *capacity)
312{
313 int ret;
314 u8 raw;
315
316 ret = ds2781_read8(dev_info, &raw, DS2781_RARC);
317 if (ret < 0)
318 return ret;
319
320 *capacity = raw;
321 return 0;
322}
323
324static int ds2781_get_status(struct ds2781_device_info *dev_info, int *status)
325{
326 int ret, current_uA, capacity;
327
328 ret = ds2781_get_current(dev_info, CURRENT_NOW, &current_uA);
329 if (ret < 0)
330 return ret;
331
332 ret = ds2781_get_capacity(dev_info, &capacity);
333 if (ret < 0)
334 return ret;
335
336 if (power_supply_am_i_supplied(&dev_info->bat)) {
337 if (capacity == 100)
338 *status = POWER_SUPPLY_STATUS_FULL;
339 else if (current_uA > 50000)
340 *status = POWER_SUPPLY_STATUS_CHARGING;
341 else
342 *status = POWER_SUPPLY_STATUS_NOT_CHARGING;
343 } else {
344 *status = POWER_SUPPLY_STATUS_DISCHARGING;
345 }
346 return 0;
347}
348
349static int ds2781_get_charge_now(struct ds2781_device_info *dev_info,
350 int *charge_now)
351{
352 int ret;
353 u16 charge_raw;
354
355 /*
356 * The RAAC value is located in 16 bits across the RAAC MSB and
357 * LSB registers
358 * Bits 15 - 8 of the RAAC value are in bits 7 - 0 of the RAAC
359 * MSB register
360 * Bits 7 - 0 of the RAAC value are in bits 7 - 0 of the RAAC
361 * LSB register
362 */
363 ret = ds2781_read16(dev_info, &charge_raw, DS2781_RAAC_MSB);
364 if (ret < 0)
365 return ret;
366
367 *charge_now = charge_raw * 1600;
368 return 0;
369}
370
371static int ds2781_get_control_register(struct ds2781_device_info *dev_info,
372 u8 *control_reg)
373{
374 return ds2781_read8(dev_info, control_reg, DS2781_CONTROL);
375}
376
377static int ds2781_set_control_register(struct ds2781_device_info *dev_info,
378 u8 control_reg)
379{
380 int ret;
381
382 ret = ds2781_write(dev_info, &control_reg,
383 DS2781_CONTROL, sizeof(u8));
384 if (ret < 0)
385 return ret;
386
387 return ds2781_save_eeprom(dev_info, DS2781_CONTROL);
388}
389
390static int ds2781_battery_get_property(struct power_supply *psy,
391 enum power_supply_property psp,
392 union power_supply_propval *val)
393{
394 int ret = 0;
395 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
396
397 switch (psp) {
398 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
399 ret = ds2781_get_voltage(dev_info, &val->intval);
400 break;
401
402 case POWER_SUPPLY_PROP_TEMP:
403 ret = ds2781_get_temperature(dev_info, &val->intval);
404 break;
405
406 case POWER_SUPPLY_PROP_MODEL_NAME:
407 val->strval = model;
408 break;
409
410 case POWER_SUPPLY_PROP_MANUFACTURER:
411 val->strval = manufacturer;
412 break;
413
414 case POWER_SUPPLY_PROP_CURRENT_NOW:
415 ret = ds2781_get_current(dev_info, CURRENT_NOW, &val->intval);
416 break;
417
418 case POWER_SUPPLY_PROP_CURRENT_AVG:
419 ret = ds2781_get_current(dev_info, CURRENT_AVG, &val->intval);
420 break;
421
422 case POWER_SUPPLY_PROP_STATUS:
423 ret = ds2781_get_status(dev_info, &val->intval);
424 break;
425
426 case POWER_SUPPLY_PROP_CAPACITY:
427 ret = ds2781_get_capacity(dev_info, &val->intval);
428 break;
429
430 case POWER_SUPPLY_PROP_CHARGE_COUNTER:
431 ret = ds2781_get_accumulated_current(dev_info, &val->intval);
432 break;
433
434 case POWER_SUPPLY_PROP_CHARGE_NOW:
435 ret = ds2781_get_charge_now(dev_info, &val->intval);
436 break;
437
438 default:
439 ret = -EINVAL;
440 }
441
442 return ret;
443}
444
445static enum power_supply_property ds2781_battery_props[] = {
446 POWER_SUPPLY_PROP_STATUS,
447 POWER_SUPPLY_PROP_VOLTAGE_NOW,
448 POWER_SUPPLY_PROP_TEMP,
449 POWER_SUPPLY_PROP_MODEL_NAME,
450 POWER_SUPPLY_PROP_MANUFACTURER,
451 POWER_SUPPLY_PROP_CURRENT_NOW,
452 POWER_SUPPLY_PROP_CURRENT_AVG,
453 POWER_SUPPLY_PROP_CAPACITY,
454 POWER_SUPPLY_PROP_CHARGE_COUNTER,
455 POWER_SUPPLY_PROP_CHARGE_NOW,
456};
457
458static ssize_t ds2781_get_pmod_enabled(struct device *dev,
459 struct device_attribute *attr,
460 char *buf)
461{
462 int ret;
463 u8 control_reg;
464 struct power_supply *psy = to_power_supply(dev);
465 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
466
467 /* Get power mode */
468 ret = ds2781_get_control_register(dev_info, &control_reg);
469 if (ret < 0)
470 return ret;
471
472 return sprintf(buf, "%d\n",
473 !!(control_reg & DS2781_CONTROL_PMOD));
474}
475
476static ssize_t ds2781_set_pmod_enabled(struct device *dev,
477 struct device_attribute *attr,
478 const char *buf,
479 size_t count)
480{
481 int ret;
482 u8 control_reg, new_setting;
483 struct power_supply *psy = to_power_supply(dev);
484 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
485
486 /* Set power mode */
487 ret = ds2781_get_control_register(dev_info, &control_reg);
488 if (ret < 0)
489 return ret;
490
491 ret = kstrtou8(buf, 0, &new_setting);
492 if (ret < 0)
493 return ret;
494
495 if ((new_setting != 0) && (new_setting != 1)) {
496 dev_err(dev_info->dev, "Invalid pmod setting (0 or 1)\n");
497 return -EINVAL;
498 }
499
500 if (new_setting)
501 control_reg |= DS2781_CONTROL_PMOD;
502 else
503 control_reg &= ~DS2781_CONTROL_PMOD;
504
505 ret = ds2781_set_control_register(dev_info, control_reg);
506 if (ret < 0)
507 return ret;
508
509 return count;
510}
511
512static ssize_t ds2781_get_sense_resistor_value(struct device *dev,
513 struct device_attribute *attr,
514 char *buf)
515{
516 int ret;
517 u8 sense_resistor;
518 struct power_supply *psy = to_power_supply(dev);
519 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
520
521 ret = ds2781_read8(dev_info, &sense_resistor, DS2781_RSNSP);
522 if (ret < 0)
523 return ret;
524
525 ret = sprintf(buf, "%d\n", sense_resistor);
526 return ret;
527}
528
529static ssize_t ds2781_set_sense_resistor_value(struct device *dev,
530 struct device_attribute *attr,
531 const char *buf,
532 size_t count)
533{
534 int ret;
535 u8 new_setting;
536 struct power_supply *psy = to_power_supply(dev);
537 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
538
539 ret = kstrtou8(buf, 0, &new_setting);
540 if (ret < 0)
541 return ret;
542
543 ret = ds2781_set_sense_register(dev_info, new_setting);
544 if (ret < 0)
545 return ret;
546
547 return count;
548}
549
550static ssize_t ds2781_get_rsgain_setting(struct device *dev,
551 struct device_attribute *attr,
552 char *buf)
553{
554 int ret;
555 u16 rsgain;
556 struct power_supply *psy = to_power_supply(dev);
557 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
558
559 ret = ds2781_get_rsgain_register(dev_info, &rsgain);
560 if (ret < 0)
561 return ret;
562
563 return sprintf(buf, "%d\n", rsgain);
564}
565
566static ssize_t ds2781_set_rsgain_setting(struct device *dev,
567 struct device_attribute *attr,
568 const char *buf,
569 size_t count)
570{
571 int ret;
572 u16 new_setting;
573 struct power_supply *psy = to_power_supply(dev);
574 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
575
576 ret = kstrtou16(buf, 0, &new_setting);
577 if (ret < 0)
578 return ret;
579
580 /* Gain can only be from 0 to 1.999 in steps of .001 */
581 if (new_setting > 1999) {
582 dev_err(dev_info->dev, "Invalid rsgain setting (0 - 1999)\n");
583 return -EINVAL;
584 }
585
586 ret = ds2781_set_rsgain_register(dev_info, new_setting);
587 if (ret < 0)
588 return ret;
589
590 return count;
591}
592
593static ssize_t ds2781_get_pio_pin(struct device *dev,
594 struct device_attribute *attr,
595 char *buf)
596{
597 int ret;
598 u8 sfr;
599 struct power_supply *psy = to_power_supply(dev);
600 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
601
602 ret = ds2781_read8(dev_info, &sfr, DS2781_SFR);
603 if (ret < 0)
604 return ret;
605
606 ret = sprintf(buf, "%d\n", sfr & DS2781_SFR_PIOSC);
607 return ret;
608}
609
610static ssize_t ds2781_set_pio_pin(struct device *dev,
611 struct device_attribute *attr,
612 const char *buf,
613 size_t count)
614{
615 int ret;
616 u8 new_setting;
617 struct power_supply *psy = to_power_supply(dev);
618 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
619
620 ret = kstrtou8(buf, 0, &new_setting);
621 if (ret < 0)
622 return ret;
623
624 if ((new_setting != 0) && (new_setting != 1)) {
625 dev_err(dev_info->dev, "Invalid pio_pin setting (0 or 1)\n");
626 return -EINVAL;
627 }
628
629 ret = ds2781_write(dev_info, &new_setting,
630 DS2781_SFR, sizeof(u8));
631 if (ret < 0)
632 return ret;
633
634 return count;
635}
636
637static ssize_t ds2781_read_param_eeprom_bin(struct file *filp,
638 struct kobject *kobj,
639 struct bin_attribute *bin_attr,
640 char *buf, loff_t off, size_t count)
641{
642 struct device *dev = container_of(kobj, struct device, kobj);
643 struct power_supply *psy = to_power_supply(dev);
644 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
645
646 count = min_t(loff_t, count,
647 DS2781_EEPROM_BLOCK1_END -
648 DS2781_EEPROM_BLOCK1_START + 1 - off);
649
650 return ds2781_read_block(dev_info, buf,
651 DS2781_EEPROM_BLOCK1_START + off, count);
652}
653
654static ssize_t ds2781_write_param_eeprom_bin(struct file *filp,
655 struct kobject *kobj,
656 struct bin_attribute *bin_attr,
657 char *buf, loff_t off, size_t count)
658{
659 struct device *dev = container_of(kobj, struct device, kobj);
660 struct power_supply *psy = to_power_supply(dev);
661 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
662 int ret;
663
664 count = min_t(loff_t, count,
665 DS2781_EEPROM_BLOCK1_END -
666 DS2781_EEPROM_BLOCK1_START + 1 - off);
667
668 ret = ds2781_write(dev_info, buf,
669 DS2781_EEPROM_BLOCK1_START + off, count);
670 if (ret < 0)
671 return ret;
672
673 ret = ds2781_save_eeprom(dev_info, DS2781_EEPROM_BLOCK1_START);
674 if (ret < 0)
675 return ret;
676
677 return count;
678}
679
680static struct bin_attribute ds2781_param_eeprom_bin_attr = {
681 .attr = {
682 .name = "param_eeprom",
683 .mode = S_IRUGO | S_IWUSR,
684 },
685 .size = DS2781_EEPROM_BLOCK1_END - DS2781_EEPROM_BLOCK1_START + 1,
686 .read = ds2781_read_param_eeprom_bin,
687 .write = ds2781_write_param_eeprom_bin,
688};
689
690static ssize_t ds2781_read_user_eeprom_bin(struct file *filp,
691 struct kobject *kobj,
692 struct bin_attribute *bin_attr,
693 char *buf, loff_t off, size_t count)
694{
695 struct device *dev = container_of(kobj, struct device, kobj);
696 struct power_supply *psy = to_power_supply(dev);
697 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
698
699 count = min_t(loff_t, count,
700 DS2781_EEPROM_BLOCK0_END -
701 DS2781_EEPROM_BLOCK0_START + 1 - off);
702
703 return ds2781_read_block(dev_info, buf,
704 DS2781_EEPROM_BLOCK0_START + off, count);
705
706}
707
708static ssize_t ds2781_write_user_eeprom_bin(struct file *filp,
709 struct kobject *kobj,
710 struct bin_attribute *bin_attr,
711 char *buf, loff_t off, size_t count)
712{
713 struct device *dev = container_of(kobj, struct device, kobj);
714 struct power_supply *psy = to_power_supply(dev);
715 struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
716 int ret;
717
718 count = min_t(loff_t, count,
719 DS2781_EEPROM_BLOCK0_END -
720 DS2781_EEPROM_BLOCK0_START + 1 - off);
721
722 ret = ds2781_write(dev_info, buf,
723 DS2781_EEPROM_BLOCK0_START + off, count);
724 if (ret < 0)
725 return ret;
726
727 ret = ds2781_save_eeprom(dev_info, DS2781_EEPROM_BLOCK0_START);
728 if (ret < 0)
729 return ret;
730
731 return count;
732}
733
734static struct bin_attribute ds2781_user_eeprom_bin_attr = {
735 .attr = {
736 .name = "user_eeprom",
737 .mode = S_IRUGO | S_IWUSR,
738 },
739 .size = DS2781_EEPROM_BLOCK0_END - DS2781_EEPROM_BLOCK0_START + 1,
740 .read = ds2781_read_user_eeprom_bin,
741 .write = ds2781_write_user_eeprom_bin,
742};
743
744static DEVICE_ATTR(pmod_enabled, S_IRUGO | S_IWUSR, ds2781_get_pmod_enabled,
745 ds2781_set_pmod_enabled);
746static DEVICE_ATTR(sense_resistor_value, S_IRUGO | S_IWUSR,
747 ds2781_get_sense_resistor_value, ds2781_set_sense_resistor_value);
748static DEVICE_ATTR(rsgain_setting, S_IRUGO | S_IWUSR, ds2781_get_rsgain_setting,
749 ds2781_set_rsgain_setting);
750static DEVICE_ATTR(pio_pin, S_IRUGO | S_IWUSR, ds2781_get_pio_pin,
751 ds2781_set_pio_pin);
752
753
754static struct attribute *ds2781_attributes[] = {
755 &dev_attr_pmod_enabled.attr,
756 &dev_attr_sense_resistor_value.attr,
757 &dev_attr_rsgain_setting.attr,
758 &dev_attr_pio_pin.attr,
759 NULL
760};
761
762static const struct attribute_group ds2781_attr_group = {
763 .attrs = ds2781_attributes,
764};
765
766static int __devinit ds2781_battery_probe(struct platform_device *pdev)
767{
768 int ret = 0;
769 struct ds2781_device_info *dev_info;
770
771 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
772 if (!dev_info) {
773 ret = -ENOMEM;
774 goto fail;
775 }
776
777 platform_set_drvdata(pdev, dev_info);
778
779 dev_info->dev = &pdev->dev;
780 dev_info->w1_dev = pdev->dev.parent;
781 dev_info->bat.name = dev_name(&pdev->dev);
782 dev_info->bat.type = POWER_SUPPLY_TYPE_BATTERY;
783 dev_info->bat.properties = ds2781_battery_props;
784 dev_info->bat.num_properties = ARRAY_SIZE(ds2781_battery_props);
785 dev_info->bat.get_property = ds2781_battery_get_property;
786 dev_info->mutex_holder = current;
787
788 ret = power_supply_register(&pdev->dev, &dev_info->bat);
789 if (ret) {
790 dev_err(dev_info->dev, "failed to register battery\n");
791 goto fail_free_info;
792 }
793
794 ret = sysfs_create_group(&dev_info->bat.dev->kobj, &ds2781_attr_group);
795 if (ret) {
796 dev_err(dev_info->dev, "failed to create sysfs group\n");
797 goto fail_unregister;
798 }
799
800 ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj,
801 &ds2781_param_eeprom_bin_attr);
802 if (ret) {
803 dev_err(dev_info->dev,
804 "failed to create param eeprom bin file");
805 goto fail_remove_group;
806 }
807
808 ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj,
809 &ds2781_user_eeprom_bin_attr);
810 if (ret) {
811 dev_err(dev_info->dev,
812 "failed to create user eeprom bin file");
813 goto fail_remove_bin_file;
814 }
815
816 dev_info->mutex_holder = NULL;
817
818 return 0;
819
820fail_remove_bin_file:
821 sysfs_remove_bin_file(&dev_info->bat.dev->kobj,
822 &ds2781_param_eeprom_bin_attr);
823fail_remove_group:
824 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2781_attr_group);
825fail_unregister:
826 power_supply_unregister(&dev_info->bat);
827fail_free_info:
828 kfree(dev_info);
829fail:
830 return ret;
831}
832
833static int __devexit ds2781_battery_remove(struct platform_device *pdev)
834{
835 struct ds2781_device_info *dev_info = platform_get_drvdata(pdev);
836
837 dev_info->mutex_holder = current;
838
839 /* remove attributes */
840 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2781_attr_group);
841
842 power_supply_unregister(&dev_info->bat);
843
844 kfree(dev_info);
845 return 0;
846}
847
848static struct platform_driver ds2781_battery_driver = {
849 .driver = {
850 .name = "ds2781-battery",
851 },
852 .probe = ds2781_battery_probe,
853 .remove = __devexit_p(ds2781_battery_remove),
854};
855
856static int __init ds2781_battery_init(void)
857{
858 return platform_driver_register(&ds2781_battery_driver);
859}
860
861static void __exit ds2781_battery_exit(void)
862{
863 platform_driver_unregister(&ds2781_battery_driver);
864}
865
866module_init(ds2781_battery_init);
867module_exit(ds2781_battery_exit);
868
869
870MODULE_LICENSE("GPL");
871MODULE_AUTHOR("Renata Sayakhova <renata@oktetlabs.ru>");
872MODULE_DESCRIPTION("Maxim/Dallas DS2781 Stand-Alone Fuel Gauage IC driver");
873MODULE_ALIAS("platform:ds2781-battery");
874
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index e9a83f84adaf..fcde037b3461 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1210,7 +1210,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
1210{ 1210{
1211 struct regulator_dev *rdev; 1211 struct regulator_dev *rdev;
1212 struct regulator_map *map; 1212 struct regulator_map *map;
1213 struct regulator *regulator = ERR_PTR(-ENODEV); 1213 struct regulator *regulator = ERR_PTR(-EPROBE_DEFER);
1214 const char *devname = NULL; 1214 const char *devname = NULL;
1215 int ret; 1215 int ret;
1216 1216
@@ -2834,7 +2834,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2834 2834
2835 if (!r) { 2835 if (!r) {
2836 dev_err(dev, "Failed to find supply %s\n", supply); 2836 dev_err(dev, "Failed to find supply %s\n", supply);
2837 ret = -ENODEV; 2837 ret = -EPROBE_DEFER;
2838 goto scrub; 2838 goto scrub;
2839 } 2839 }
2840 2840
diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index 4f1989d27b1f..5f1dc6fb5708 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -580,7 +580,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
580 struct device *dev; 580 struct device *dev;
581 581
582 /* We don't want ccwgroup devices to live longer than their driver. */ 582 /* We don't want ccwgroup devices to live longer than their driver. */
583 get_driver(&cdriver->driver);
584 while ((dev = driver_find_device(&cdriver->driver, NULL, NULL, 583 while ((dev = driver_find_device(&cdriver->driver, NULL, NULL,
585 __ccwgroup_match_all))) { 584 __ccwgroup_match_all))) {
586 struct ccwgroup_device *gdev = to_ccwgroupdev(dev); 585 struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
@@ -592,7 +591,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
592 mutex_unlock(&gdev->reg_mutex); 591 mutex_unlock(&gdev->reg_mutex);
593 put_device(dev); 592 put_device(dev);
594 } 593 }
595 put_driver(&cdriver->driver);
596 driver_unregister(&cdriver->driver); 594 driver_unregister(&cdriver->driver);
597} 595}
598EXPORT_SYMBOL(ccwgroup_driver_unregister); 596EXPORT_SYMBOL(ccwgroup_driver_unregister);
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 47269858ecb6..02d015259461 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -1676,15 +1676,9 @@ struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
1676 const char *bus_id) 1676 const char *bus_id)
1677{ 1677{
1678 struct device *dev; 1678 struct device *dev;
1679 struct device_driver *drv;
1680 1679
1681 drv = get_driver(&cdrv->driver); 1680 dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
1682 if (!drv)
1683 return NULL;
1684
1685 dev = driver_find_device(drv, NULL, (void *)bus_id,
1686 __ccwdev_check_busid); 1681 __ccwdev_check_busid);
1687 put_driver(drv);
1688 1682
1689 return dev ? to_ccwdev(dev) : NULL; 1683 return dev ? to_ccwdev(dev) : NULL;
1690} 1684}
diff --git a/drivers/s390/net/smsgiucv_app.c b/drivers/s390/net/smsgiucv_app.c
index 4d2ea4000422..32515a201bbc 100644
--- a/drivers/s390/net/smsgiucv_app.c
+++ b/drivers/s390/net/smsgiucv_app.c
@@ -168,7 +168,7 @@ static int __init smsgiucv_app_init(void)
168 rc = dev_set_name(smsg_app_dev, KMSG_COMPONENT); 168 rc = dev_set_name(smsg_app_dev, KMSG_COMPONENT);
169 if (rc) { 169 if (rc) {
170 kfree(smsg_app_dev); 170 kfree(smsg_app_dev);
171 goto fail_put_driver; 171 goto fail;
172 } 172 }
173 smsg_app_dev->bus = &iucv_bus; 173 smsg_app_dev->bus = &iucv_bus;
174 smsg_app_dev->parent = iucv_root; 174 smsg_app_dev->parent = iucv_root;
@@ -177,7 +177,7 @@ static int __init smsgiucv_app_init(void)
177 rc = device_register(smsg_app_dev); 177 rc = device_register(smsg_app_dev);
178 if (rc) { 178 if (rc) {
179 put_device(smsg_app_dev); 179 put_device(smsg_app_dev);
180 goto fail_put_driver; 180 goto fail;
181 } 181 }
182 182
183 /* convert sender to uppercase characters */ 183 /* convert sender to uppercase characters */
@@ -191,12 +191,11 @@ static int __init smsgiucv_app_init(void)
191 rc = smsg_register_callback(SMSG_PREFIX, smsg_app_callback); 191 rc = smsg_register_callback(SMSG_PREFIX, smsg_app_callback);
192 if (rc) { 192 if (rc) {
193 device_unregister(smsg_app_dev); 193 device_unregister(smsg_app_dev);
194 goto fail_put_driver; 194 goto fail;
195 } 195 }
196 196
197 rc = 0; 197 rc = 0;
198fail_put_driver: 198fail:
199 put_driver(smsgiucv_drv);
200 return rc; 199 return rc;
201} 200}
202module_init(smsgiucv_app_init); 201module_init(smsgiucv_app_init);
diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index bb6317fb925c..ff109ae94767 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -140,19 +140,6 @@ static void ssb_device_put(struct ssb_device *dev)
140 put_device(dev->dev); 140 put_device(dev->dev);
141} 141}
142 142
143static inline struct ssb_driver *ssb_driver_get(struct ssb_driver *drv)
144{
145 if (drv)
146 get_driver(&drv->drv);
147 return drv;
148}
149
150static inline void ssb_driver_put(struct ssb_driver *drv)
151{
152 if (drv)
153 put_driver(&drv->drv);
154}
155
156static int ssb_device_resume(struct device *dev) 143static int ssb_device_resume(struct device *dev)
157{ 144{
158 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); 145 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
@@ -250,11 +237,9 @@ int ssb_devices_freeze(struct ssb_bus *bus, struct ssb_freeze_context *ctx)
250 ssb_device_put(sdev); 237 ssb_device_put(sdev);
251 continue; 238 continue;
252 } 239 }
253 sdrv = ssb_driver_get(drv_to_ssb_drv(sdev->dev->driver)); 240 sdrv = drv_to_ssb_drv(sdev->dev->driver);
254 if (!sdrv || SSB_WARN_ON(!sdrv->remove)) { 241 if (SSB_WARN_ON(!sdrv->remove))
255 ssb_device_put(sdev);
256 continue; 242 continue;
257 }
258 sdrv->remove(sdev); 243 sdrv->remove(sdev);
259 ctx->device_frozen[i] = 1; 244 ctx->device_frozen[i] = 1;
260 } 245 }
@@ -293,7 +278,6 @@ int ssb_devices_thaw(struct ssb_freeze_context *ctx)
293 dev_name(sdev->dev)); 278 dev_name(sdev->dev));
294 result = err; 279 result = err;
295 } 280 }
296 ssb_driver_put(sdrv);
297 ssb_device_put(sdev); 281 ssb_device_put(sdev);
298 } 282 }
299 283
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index d40ff9568813..4fee024ecc9b 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -71,10 +71,7 @@ ssize_t usb_store_new_id(struct usb_dynids *dynids,
71 list_add_tail(&dynid->node, &dynids->list); 71 list_add_tail(&dynid->node, &dynids->list);
72 spin_unlock(&dynids->lock); 72 spin_unlock(&dynids->lock);
73 73
74 if (get_driver(driver)) { 74 retval = driver_attach(driver);
75 retval = driver_attach(driver);
76 put_driver(driver);
77 }
78 75
79 if (retval) 76 if (retval)
80 return retval; 77 return retval;
@@ -132,43 +129,39 @@ store_remove_id(struct device_driver *driver, const char *buf, size_t count)
132} 129}
133static DRIVER_ATTR(remove_id, S_IWUSR, NULL, store_remove_id); 130static DRIVER_ATTR(remove_id, S_IWUSR, NULL, store_remove_id);
134 131
135static int usb_create_newid_file(struct usb_driver *usb_drv) 132static int usb_create_newid_files(struct usb_driver *usb_drv)
136{ 133{
137 int error = 0; 134 int error = 0;
138 135
139 if (usb_drv->no_dynamic_id) 136 if (usb_drv->no_dynamic_id)
140 goto exit; 137 goto exit;
141 138
142 if (usb_drv->probe != NULL) 139 if (usb_drv->probe != NULL) {
143 error = driver_create_file(&usb_drv->drvwrap.driver, 140 error = driver_create_file(&usb_drv->drvwrap.driver,
144 &driver_attr_new_id); 141 &driver_attr_new_id);
142 if (error == 0) {
143 error = driver_create_file(&usb_drv->drvwrap.driver,
144 &driver_attr_remove_id);
145 if (error)
146 driver_remove_file(&usb_drv->drvwrap.driver,
147 &driver_attr_new_id);
148 }
149 }
145exit: 150exit:
146 return error; 151 return error;
147} 152}
148 153
149static void usb_remove_newid_file(struct usb_driver *usb_drv) 154static void usb_remove_newid_files(struct usb_driver *usb_drv)
150{ 155{
151 if (usb_drv->no_dynamic_id) 156 if (usb_drv->no_dynamic_id)
152 return; 157 return;
153 158
154 if (usb_drv->probe != NULL) 159 if (usb_drv->probe != NULL) {
155 driver_remove_file(&usb_drv->drvwrap.driver, 160 driver_remove_file(&usb_drv->drvwrap.driver,
156 &driver_attr_new_id);
157}
158
159static int
160usb_create_removeid_file(struct usb_driver *drv)
161{
162 int error = 0;
163 if (drv->probe != NULL)
164 error = driver_create_file(&drv->drvwrap.driver,
165 &driver_attr_remove_id); 161 &driver_attr_remove_id);
166 return error; 162 driver_remove_file(&usb_drv->drvwrap.driver,
167} 163 &driver_attr_new_id);
168 164 }
169static void usb_remove_removeid_file(struct usb_driver *drv)
170{
171 driver_remove_file(&drv->drvwrap.driver, &driver_attr_remove_id);
172} 165}
173 166
174static void usb_free_dynids(struct usb_driver *usb_drv) 167static void usb_free_dynids(struct usb_driver *usb_drv)
@@ -183,22 +176,12 @@ static void usb_free_dynids(struct usb_driver *usb_drv)
183 spin_unlock(&usb_drv->dynids.lock); 176 spin_unlock(&usb_drv->dynids.lock);
184} 177}
185#else 178#else
186static inline int usb_create_newid_file(struct usb_driver *usb_drv) 179static inline int usb_create_newid_files(struct usb_driver *usb_drv)
187{ 180{
188 return 0; 181 return 0;
189} 182}
190 183
191static void usb_remove_newid_file(struct usb_driver *usb_drv) 184static void usb_remove_newid_files(struct usb_driver *usb_drv)
192{
193}
194
195static int
196usb_create_removeid_file(struct usb_driver *drv)
197{
198 return 0;
199}
200
201static void usb_remove_removeid_file(struct usb_driver *drv)
202{ 185{
203} 186}
204 187
@@ -875,22 +858,16 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner,
875 858
876 usbfs_update_special(); 859 usbfs_update_special();
877 860
878 retval = usb_create_newid_file(new_driver); 861 retval = usb_create_newid_files(new_driver);
879 if (retval) 862 if (retval)
880 goto out_newid; 863 goto out_newid;
881 864
882 retval = usb_create_removeid_file(new_driver);
883 if (retval)
884 goto out_removeid;
885
886 pr_info("%s: registered new interface driver %s\n", 865 pr_info("%s: registered new interface driver %s\n",
887 usbcore_name, new_driver->name); 866 usbcore_name, new_driver->name);
888 867
889out: 868out:
890 return retval; 869 return retval;
891 870
892out_removeid:
893 usb_remove_newid_file(new_driver);
894out_newid: 871out_newid:
895 driver_unregister(&new_driver->drvwrap.driver); 872 driver_unregister(&new_driver->drvwrap.driver);
896 873
@@ -917,10 +894,9 @@ void usb_deregister(struct usb_driver *driver)
917 pr_info("%s: deregistering interface driver %s\n", 894 pr_info("%s: deregistering interface driver %s\n",
918 usbcore_name, driver->name); 895 usbcore_name, driver->name);
919 896
920 usb_remove_removeid_file(driver); 897 usb_remove_newid_files(driver);
921 usb_remove_newid_file(driver);
922 usb_free_dynids(driver);
923 driver_unregister(&driver->drvwrap.driver); 898 driver_unregister(&driver->drvwrap.driver);
899 usb_free_dynids(driver);
924 900
925 usbfs_update_special(); 901 usbfs_update_special();
926} 902}
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 64e1f7c67b08..c68e4270457a 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -171,14 +171,4 @@ MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
171MODULE_LICENSE("Dual BSD/GPL"); 171MODULE_LICENSE("Dual BSD/GPL");
172MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer"); 172MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
173 173
174static int __devinit dwc3_pci_init(void) 174module_pci_driver(dwc3_pci_driver);
175{
176 return pci_register_driver(&dwc3_pci_driver);
177}
178module_init(dwc3_pci_init);
179
180static void __exit dwc3_pci_exit(void)
181{
182 pci_unregister_driver(&dwc3_pci_driver);
183}
184module_exit(dwc3_pci_exit);
diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
index fcbe742188a5..df600d14974d 100644
--- a/drivers/w1/masters/w1-gpio.c
+++ b/drivers/w1/masters/w1-gpio.c
@@ -13,12 +13,11 @@
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/w1-gpio.h> 15#include <linux/w1-gpio.h>
16#include <linux/gpio.h>
16 17
17#include "../w1.h" 18#include "../w1.h"
18#include "../w1_int.h" 19#include "../w1_int.h"
19 20
20#include <asm/gpio.h>
21
22static void w1_gpio_write_bit_dir(void *data, u8 bit) 21static void w1_gpio_write_bit_dir(void *data, u8 bit)
23{ 22{
24 struct w1_gpio_platform_data *pdata = data; 23 struct w1_gpio_platform_data *pdata = data;
diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig
index d0cb01b42012..eb9e376d6244 100644
--- a/drivers/w1/slaves/Kconfig
+++ b/drivers/w1/slaves/Kconfig
@@ -81,6 +81,19 @@ config W1_SLAVE_DS2780
81 81
82 If you are unsure, say N. 82 If you are unsure, say N.
83 83
84config W1_SLAVE_DS2781
85 tristate "Dallas 2781 battery monitor chip"
86 depends on W1
87 help
88 If you enable this you will have the DS2781 battery monitor
89 chip support.
90
91 The battery monitor chip is used in many batteries/devices
92 as the one who is responsible for charging/discharging/monitoring
93 Li+ batteries.
94
95 If you are unsure, say N.
96
84config W1_SLAVE_BQ27000 97config W1_SLAVE_BQ27000
85 tristate "BQ27000 slave support" 98 tristate "BQ27000 slave support"
86 depends on W1 99 depends on W1
diff --git a/drivers/w1/slaves/Makefile b/drivers/w1/slaves/Makefile
index 1f31e9fb0b25..c4f1859fb520 100644
--- a/drivers/w1/slaves/Makefile
+++ b/drivers/w1/slaves/Makefile
@@ -10,4 +10,5 @@ obj-$(CONFIG_W1_SLAVE_DS2431) += w1_ds2431.o
10obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o 10obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o
11obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o 11obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o
12obj-$(CONFIG_W1_SLAVE_DS2780) += w1_ds2780.o 12obj-$(CONFIG_W1_SLAVE_DS2780) += w1_ds2780.o
13obj-$(CONFIG_W1_SLAVE_DS2781) += w1_ds2781.o
13obj-$(CONFIG_W1_SLAVE_BQ27000) += w1_bq27000.o 14obj-$(CONFIG_W1_SLAVE_BQ27000) += w1_bq27000.o
diff --git a/drivers/w1/slaves/w1_bq27000.c b/drivers/w1/slaves/w1_bq27000.c
index 8f4c91f6c680..52ad812fa1e7 100644
--- a/drivers/w1/slaves/w1_bq27000.c
+++ b/drivers/w1/slaves/w1_bq27000.c
@@ -15,6 +15,7 @@
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/mutex.h> 17#include <linux/mutex.h>
18#include <linux/power/bq27x00_battery.h>
18 19
19#include "../w1.h" 20#include "../w1.h"
20#include "../w1_int.h" 21#include "../w1_int.h"
@@ -25,46 +26,37 @@
25 26
26static int F_ID; 27static int F_ID;
27 28
28void w1_bq27000_write(struct device *dev, u8 buf, u8 reg) 29static int w1_bq27000_read(struct device *dev, unsigned int reg)
29{
30 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
31
32 if (!dev) {
33 pr_info("Could not obtain slave dev ptr\n");
34 return;
35 }
36
37 w1_write_8(sl->master, HDQ_CMD_WRITE | reg);
38 w1_write_8(sl->master, buf);
39}
40EXPORT_SYMBOL(w1_bq27000_write);
41
42int w1_bq27000_read(struct device *dev, u8 reg)
43{ 30{
44 u8 val; 31 u8 val;
45 struct w1_slave *sl = container_of(dev, struct w1_slave, dev); 32 struct w1_slave *sl = container_of(dev->parent, struct w1_slave, dev);
46
47 if (!dev)
48 return 0;
49 33
34 mutex_lock(&sl->master->mutex);
50 w1_write_8(sl->master, HDQ_CMD_READ | reg); 35 w1_write_8(sl->master, HDQ_CMD_READ | reg);
51 val = w1_read_8(sl->master); 36 val = w1_read_8(sl->master);
37 mutex_unlock(&sl->master->mutex);
52 38
53 return val; 39 return val;
54} 40}
55EXPORT_SYMBOL(w1_bq27000_read); 41
42static struct bq27000_platform_data bq27000_battery_info = {
43 .read = w1_bq27000_read,
44 .name = "bq27000-battery",
45};
56 46
57static int w1_bq27000_add_slave(struct w1_slave *sl) 47static int w1_bq27000_add_slave(struct w1_slave *sl)
58{ 48{
59 int ret; 49 int ret;
60 int id = 1;
61 struct platform_device *pdev; 50 struct platform_device *pdev;
62 51
63 pdev = platform_device_alloc("bq27000-battery", id); 52 pdev = platform_device_alloc("bq27000-battery", -1);
64 if (!pdev) { 53 if (!pdev) {
65 ret = -ENOMEM; 54 ret = -ENOMEM;
66 return ret; 55 return ret;
67 } 56 }
57 ret = platform_device_add_data(pdev,
58 &bq27000_battery_info,
59 sizeof(bq27000_battery_info));
68 pdev->dev.parent = &sl->dev; 60 pdev->dev.parent = &sl->dev;
69 61
70 ret = platform_device_add(pdev); 62 ret = platform_device_add(pdev);
diff --git a/drivers/w1/slaves/w1_ds2781.c b/drivers/w1/slaves/w1_ds2781.c
new file mode 100644
index 000000000000..0d0c7985293f
--- /dev/null
+++ b/drivers/w1/slaves/w1_ds2781.c
@@ -0,0 +1,201 @@
1/*
2 * 1-Wire implementation for the ds2781 chip
3 *
4 * Author: Renata Sayakhova <renata@oktetlabs.ru>
5 *
6 * Based on w1-ds2780 driver
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/device.h>
17#include <linux/types.h>
18#include <linux/platform_device.h>
19#include <linux/mutex.h>
20#include <linux/idr.h>
21
22#include "../w1.h"
23#include "../w1_int.h"
24#include "../w1_family.h"
25#include "w1_ds2781.h"
26
27static int w1_ds2781_do_io(struct device *dev, char *buf, int addr,
28 size_t count, int io)
29{
30 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
31
32 if (addr > DS2781_DATA_SIZE || addr < 0)
33 return 0;
34
35 count = min_t(int, count, DS2781_DATA_SIZE - addr);
36
37 if (w1_reset_select_slave(sl) == 0) {
38 if (io) {
39 w1_write_8(sl->master, W1_DS2781_WRITE_DATA);
40 w1_write_8(sl->master, addr);
41 w1_write_block(sl->master, buf, count);
42 } else {
43 w1_write_8(sl->master, W1_DS2781_READ_DATA);
44 w1_write_8(sl->master, addr);
45 count = w1_read_block(sl->master, buf, count);
46 }
47 }
48
49 return count;
50}
51
52int w1_ds2781_io(struct device *dev, char *buf, int addr, size_t count,
53 int io)
54{
55 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
56 int ret;
57
58 if (!dev)
59 return -ENODEV;
60
61 mutex_lock(&sl->master->mutex);
62
63 ret = w1_ds2781_do_io(dev, buf, addr, count, io);
64
65 mutex_unlock(&sl->master->mutex);
66
67 return ret;
68}
69EXPORT_SYMBOL(w1_ds2781_io);
70
71int w1_ds2781_io_nolock(struct device *dev, char *buf, int addr, size_t count,
72 int io)
73{
74 int ret;
75
76 if (!dev)
77 return -ENODEV;
78
79 ret = w1_ds2781_do_io(dev, buf, addr, count, io);
80
81 return ret;
82}
83EXPORT_SYMBOL(w1_ds2781_io_nolock);
84
85int w1_ds2781_eeprom_cmd(struct device *dev, int addr, int cmd)
86{
87 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
88
89 if (!dev)
90 return -EINVAL;
91
92 mutex_lock(&sl->master->mutex);
93
94 if (w1_reset_select_slave(sl) == 0) {
95 w1_write_8(sl->master, cmd);
96 w1_write_8(sl->master, addr);
97 }
98
99 mutex_unlock(&sl->master->mutex);
100 return 0;
101}
102EXPORT_SYMBOL(w1_ds2781_eeprom_cmd);
103
104static ssize_t w1_ds2781_read_bin(struct file *filp,
105 struct kobject *kobj,
106 struct bin_attribute *bin_attr,
107 char *buf, loff_t off, size_t count)
108{
109 struct device *dev = container_of(kobj, struct device, kobj);
110 return w1_ds2781_io(dev, buf, off, count, 0);
111}
112
113static struct bin_attribute w1_ds2781_bin_attr = {
114 .attr = {
115 .name = "w1_slave",
116 .mode = S_IRUGO,
117 },
118 .size = DS2781_DATA_SIZE,
119 .read = w1_ds2781_read_bin,
120};
121
122static DEFINE_IDA(bat_ida);
123
124static int w1_ds2781_add_slave(struct w1_slave *sl)
125{
126 int ret;
127 int id;
128 struct platform_device *pdev;
129
130 id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL);
131 if (id < 0) {
132 ret = id;
133 goto noid;
134 }
135
136 pdev = platform_device_alloc("ds2781-battery", id);
137 if (!pdev) {
138 ret = -ENOMEM;
139 goto pdev_alloc_failed;
140 }
141 pdev->dev.parent = &sl->dev;
142
143 ret = platform_device_add(pdev);
144 if (ret)
145 goto pdev_add_failed;
146
147 ret = sysfs_create_bin_file(&sl->dev.kobj, &w1_ds2781_bin_attr);
148 if (ret)
149 goto bin_attr_failed;
150
151 dev_set_drvdata(&sl->dev, pdev);
152
153 return 0;
154
155bin_attr_failed:
156pdev_add_failed:
157 platform_device_unregister(pdev);
158pdev_alloc_failed:
159 ida_simple_remove(&bat_ida, id);
160noid:
161 return ret;
162}
163
164static void w1_ds2781_remove_slave(struct w1_slave *sl)
165{
166 struct platform_device *pdev = dev_get_drvdata(&sl->dev);
167 int id = pdev->id;
168
169 platform_device_unregister(pdev);
170 ida_simple_remove(&bat_ida, id);
171 sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2781_bin_attr);
172}
173
174static struct w1_family_ops w1_ds2781_fops = {
175 .add_slave = w1_ds2781_add_slave,
176 .remove_slave = w1_ds2781_remove_slave,
177};
178
179static struct w1_family w1_ds2781_family = {
180 .fid = W1_FAMILY_DS2781,
181 .fops = &w1_ds2781_fops,
182};
183
184static int __init w1_ds2781_init(void)
185{
186 ida_init(&bat_ida);
187 return w1_register_family(&w1_ds2781_family);
188}
189
190static void __exit w1_ds2781_exit(void)
191{
192 w1_unregister_family(&w1_ds2781_family);
193 ida_destroy(&bat_ida);
194}
195
196module_init(w1_ds2781_init);
197module_exit(w1_ds2781_exit);
198
199MODULE_LICENSE("GPL");
200MODULE_AUTHOR("Renata Sayakhova <renata@oktetlabs.ru>");
201MODULE_DESCRIPTION("1-wire Driver for Maxim/Dallas DS2781 Stand-Alone Fuel Gauge IC");
diff --git a/drivers/w1/slaves/w1_ds2781.h b/drivers/w1/slaves/w1_ds2781.h
new file mode 100644
index 000000000000..82bc66497b43
--- /dev/null
+++ b/drivers/w1/slaves/w1_ds2781.h
@@ -0,0 +1,136 @@
1/*
2 * 1-Wire implementation for the ds2780 chip
3 *
4 * Author: Renata Sayakhova <renata@oktetlabs.ru>
5 *
6 * Based on w1-ds2760 driver
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#ifndef _W1_DS2781_H
15#define _W1_DS2781_H
16
17/* Function commands */
18#define W1_DS2781_READ_DATA 0x69
19#define W1_DS2781_WRITE_DATA 0x6C
20#define W1_DS2781_COPY_DATA 0x48
21#define W1_DS2781_RECALL_DATA 0xB8
22#define W1_DS2781_LOCK 0x6A
23
24/* Register map */
25/* Register 0x00 Reserved */
26#define DS2781_STATUS 0x01
27#define DS2781_RAAC_MSB 0x02
28#define DS2781_RAAC_LSB 0x03
29#define DS2781_RSAC_MSB 0x04
30#define DS2781_RSAC_LSB 0x05
31#define DS2781_RARC 0x06
32#define DS2781_RSRC 0x07
33#define DS2781_IAVG_MSB 0x08
34#define DS2781_IAVG_LSB 0x09
35#define DS2781_TEMP_MSB 0x0A
36#define DS2781_TEMP_LSB 0x0B
37#define DS2781_VOLT_MSB 0x0C
38#define DS2781_VOLT_LSB 0x0D
39#define DS2781_CURRENT_MSB 0x0E
40#define DS2781_CURRENT_LSB 0x0F
41#define DS2781_ACR_MSB 0x10
42#define DS2781_ACR_LSB 0x11
43#define DS2781_ACRL_MSB 0x12
44#define DS2781_ACRL_LSB 0x13
45#define DS2781_AS 0x14
46#define DS2781_SFR 0x15
47#define DS2781_FULL_MSB 0x16
48#define DS2781_FULL_LSB 0x17
49#define DS2781_AE_MSB 0x18
50#define DS2781_AE_LSB 0x19
51#define DS2781_SE_MSB 0x1A
52#define DS2781_SE_LSB 0x1B
53/* Register 0x1C - 0x1E Reserved */
54#define DS2781_EEPROM 0x1F
55#define DS2781_EEPROM_BLOCK0_START 0x20
56/* Register 0x20 - 0x2F User EEPROM */
57#define DS2781_EEPROM_BLOCK0_END 0x2F
58/* Register 0x30 - 0x5F Reserved */
59#define DS2781_EEPROM_BLOCK1_START 0x60
60#define DS2781_CONTROL 0x60
61#define DS2781_AB 0x61
62#define DS2781_AC_MSB 0x62
63#define DS2781_AC_LSB 0x63
64#define DS2781_VCHG 0x64
65#define DS2781_IMIN 0x65
66#define DS2781_VAE 0x66
67#define DS2781_IAE 0x67
68#define DS2781_AE_40 0x68
69#define DS2781_RSNSP 0x69
70#define DS2781_FULL_40_MSB 0x6A
71#define DS2781_FULL_40_LSB 0x6B
72#define DS2781_FULL_4_SLOPE 0x6C
73#define DS2781_FULL_3_SLOPE 0x6D
74#define DS2781_FULL_2_SLOPE 0x6E
75#define DS2781_FULL_1_SLOPE 0x6F
76#define DS2781_AE_4_SLOPE 0x70
77#define DS2781_AE_3_SLOPE 0x71
78#define DS2781_AE_2_SLOPE 0x72
79#define DS2781_AE_1_SLOPE 0x73
80#define DS2781_SE_4_SLOPE 0x74
81#define DS2781_SE_3_SLOPE 0x75
82#define DS2781_SE_2_SLOPE 0x76
83#define DS2781_SE_1_SLOPE 0x77
84#define DS2781_RSGAIN_MSB 0x78
85#define DS2781_RSGAIN_LSB 0x79
86#define DS2781_RSTC 0x7A
87#define DS2781_COB 0x7B
88#define DS2781_TBP34 0x7C
89#define DS2781_TBP23 0x7D
90#define DS2781_TBP12 0x7E
91#define DS2781_EEPROM_BLOCK1_END 0x7F
92/* Register 0x7D - 0xFF Reserved */
93
94#define DS2781_FSGAIN_MSB 0xB0
95#define DS2781_FSGAIN_LSB 0xB1
96
97/* Number of valid register addresses */
98#define DS2781_DATA_SIZE 0xB2
99
100/* Status register bits */
101#define DS2781_STATUS_CHGTF (1 << 7)
102#define DS2781_STATUS_AEF (1 << 6)
103#define DS2781_STATUS_SEF (1 << 5)
104#define DS2781_STATUS_LEARNF (1 << 4)
105/* Bit 3 Reserved */
106#define DS2781_STATUS_UVF (1 << 2)
107#define DS2781_STATUS_PORF (1 << 1)
108/* Bit 0 Reserved */
109
110/* Control register bits */
111/* Bit 7 Reserved */
112#define DS2781_CONTROL_NBEN (1 << 7)
113#define DS2781_CONTROL_UVEN (1 << 6)
114#define DS2781_CONTROL_PMOD (1 << 5)
115#define DS2781_CONTROL_RNAOP (1 << 4)
116#define DS1781_CONTROL_UVTH (1 << 3)
117/* Bit 0 - 2 Reserved */
118
119/* Special feature register bits */
120/* Bit 1 - 7 Reserved */
121#define DS2781_SFR_PIOSC (1 << 0)
122
123/* EEPROM register bits */
124#define DS2781_EEPROM_EEC (1 << 7)
125#define DS2781_EEPROM_LOCK (1 << 6)
126/* Bit 2 - 6 Reserved */
127#define DS2781_EEPROM_BL1 (1 << 1)
128#define DS2781_EEPROM_BL0 (1 << 0)
129
130extern int w1_ds2781_io(struct device *dev, char *buf, int addr, size_t count,
131 int io);
132extern int w1_ds2781_io_nolock(struct device *dev, char *buf, int addr,
133 size_t count, int io);
134extern int w1_ds2781_eeprom_cmd(struct device *dev, int addr, int cmd);
135
136#endif /* !_W1_DS2781_H */
diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h
index 490cda2281bc..874aeb05011b 100644
--- a/drivers/w1/w1_family.h
+++ b/drivers/w1/w1_family.h
@@ -38,6 +38,7 @@
38#define W1_EEPROM_DS2431 0x2D 38#define W1_EEPROM_DS2431 0x2D
39#define W1_FAMILY_DS2760 0x30 39#define W1_FAMILY_DS2760 0x30
40#define W1_FAMILY_DS2780 0x32 40#define W1_FAMILY_DS2780 0x32
41#define W1_FAMILY_DS2781 0x3D
41#define W1_THERM_DS28EA00 0x42 42#define W1_THERM_DS28EA00 0x42
42 43
43#define MAXNAMELEN 32 44#define MAXNAMELEN 32
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 956d5ddddf6e..b80bc846a15a 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -23,9 +23,13 @@
23#include <linux/debugfs.h> 23#include <linux/debugfs.h>
24#include <linux/fsnotify.h> 24#include <linux/fsnotify.h>
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/seq_file.h>
27#include <linux/parser.h>
26#include <linux/magic.h> 28#include <linux/magic.h>
27#include <linux/slab.h> 29#include <linux/slab.h>
28 30
31#define DEBUGFS_DEFAULT_MODE 0755
32
29static struct vfsmount *debugfs_mount; 33static struct vfsmount *debugfs_mount;
30static int debugfs_mount_count; 34static int debugfs_mount_count;
31static bool debugfs_registered; 35static bool debugfs_registered;
@@ -125,11 +129,154 @@ static inline int debugfs_positive(struct dentry *dentry)
125 return dentry->d_inode && !d_unhashed(dentry); 129 return dentry->d_inode && !d_unhashed(dentry);
126} 130}
127 131
132struct debugfs_mount_opts {
133 uid_t uid;
134 gid_t gid;
135 umode_t mode;
136};
137
138enum {
139 Opt_uid,
140 Opt_gid,
141 Opt_mode,
142 Opt_err
143};
144
145static const match_table_t tokens = {
146 {Opt_uid, "uid=%u"},
147 {Opt_gid, "gid=%u"},
148 {Opt_mode, "mode=%o"},
149 {Opt_err, NULL}
150};
151
152struct debugfs_fs_info {
153 struct debugfs_mount_opts mount_opts;
154};
155
156static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts)
157{
158 substring_t args[MAX_OPT_ARGS];
159 int option;
160 int token;
161 char *p;
162
163 opts->mode = DEBUGFS_DEFAULT_MODE;
164
165 while ((p = strsep(&data, ",")) != NULL) {
166 if (!*p)
167 continue;
168
169 token = match_token(p, tokens, args);
170 switch (token) {
171 case Opt_uid:
172 if (match_int(&args[0], &option))
173 return -EINVAL;
174 opts->uid = option;
175 break;
176 case Opt_gid:
177 if (match_octal(&args[0], &option))
178 return -EINVAL;
179 opts->gid = option;
180 break;
181 case Opt_mode:
182 if (match_octal(&args[0], &option))
183 return -EINVAL;
184 opts->mode = option & S_IALLUGO;
185 break;
186 /*
187 * We might like to report bad mount options here;
188 * but traditionally debugfs has ignored all mount options
189 */
190 }
191 }
192
193 return 0;
194}
195
196static int debugfs_apply_options(struct super_block *sb)
197{
198 struct debugfs_fs_info *fsi = sb->s_fs_info;
199 struct inode *inode = sb->s_root->d_inode;
200 struct debugfs_mount_opts *opts = &fsi->mount_opts;
201
202 inode->i_mode &= ~S_IALLUGO;
203 inode->i_mode |= opts->mode;
204
205 inode->i_uid = opts->uid;
206 inode->i_gid = opts->gid;
207
208 return 0;
209}
210
211static int debugfs_remount(struct super_block *sb, int *flags, char *data)
212{
213 int err;
214 struct debugfs_fs_info *fsi = sb->s_fs_info;
215
216 err = debugfs_parse_options(data, &fsi->mount_opts);
217 if (err)
218 goto fail;
219
220 debugfs_apply_options(sb);
221
222fail:
223 return err;
224}
225
226static int debugfs_show_options(struct seq_file *m, struct dentry *root)
227{
228 struct debugfs_fs_info *fsi = root->d_sb->s_fs_info;
229 struct debugfs_mount_opts *opts = &fsi->mount_opts;
230
231 if (opts->uid != 0)
232 seq_printf(m, ",uid=%u", opts->uid);
233 if (opts->gid != 0)
234 seq_printf(m, ",gid=%u", opts->gid);
235 if (opts->mode != DEBUGFS_DEFAULT_MODE)
236 seq_printf(m, ",mode=%o", opts->mode);
237
238 return 0;
239}
240
241static const struct super_operations debugfs_super_operations = {
242 .statfs = simple_statfs,
243 .remount_fs = debugfs_remount,
244 .show_options = debugfs_show_options,
245};
246
128static int debug_fill_super(struct super_block *sb, void *data, int silent) 247static int debug_fill_super(struct super_block *sb, void *data, int silent)
129{ 248{
130 static struct tree_descr debug_files[] = {{""}}; 249 static struct tree_descr debug_files[] = {{""}};
250 struct debugfs_fs_info *fsi;
251 int err;
252
253 save_mount_options(sb, data);
254
255 fsi = kzalloc(sizeof(struct debugfs_fs_info), GFP_KERNEL);
256 sb->s_fs_info = fsi;
257 if (!fsi) {
258 err = -ENOMEM;
259 goto fail;
260 }
261
262 err = debugfs_parse_options(data, &fsi->mount_opts);
263 if (err)
264 goto fail;
265
266 err = simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
267 if (err)
268 goto fail;
269
270 sb->s_op = &debugfs_super_operations;
271
272 debugfs_apply_options(sb);
273
274 return 0;
131 275
132 return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files); 276fail:
277 kfree(fsi);
278 sb->s_fs_info = NULL;
279 return err;
133} 280}
134 281
135static struct dentry *debug_mount(struct file_system_type *fs_type, 282static struct dentry *debug_mount(struct file_system_type *fs_type,
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 7fdf6a7b7436..2a7a3f5d1ca6 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -22,76 +22,103 @@
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/security.h> 24#include <linux/security.h>
25#include <linux/hash.h>
25#include "sysfs.h" 26#include "sysfs.h"
26 27
27DEFINE_MUTEX(sysfs_mutex); 28DEFINE_MUTEX(sysfs_mutex);
28DEFINE_SPINLOCK(sysfs_assoc_lock); 29DEFINE_SPINLOCK(sysfs_assoc_lock);
29 30
31#define to_sysfs_dirent(X) rb_entry((X), struct sysfs_dirent, s_rb);
32
30static DEFINE_SPINLOCK(sysfs_ino_lock); 33static DEFINE_SPINLOCK(sysfs_ino_lock);
31static DEFINE_IDA(sysfs_ino_ida); 34static DEFINE_IDA(sysfs_ino_ida);
32 35
33/** 36/**
34 * sysfs_link_sibling - link sysfs_dirent into sibling list 37 * sysfs_name_hash
38 * @ns: Namespace tag to hash
39 * @name: Null terminated string to hash
40 *
41 * Returns 31 bit hash of ns + name (so it fits in an off_t )
42 */
43static unsigned int sysfs_name_hash(const void *ns, const char *name)
44{
45 unsigned long hash = init_name_hash();
46 unsigned int len = strlen(name);
47 while (len--)
48 hash = partial_name_hash(*name++, hash);
49 hash = ( end_name_hash(hash) ^ hash_ptr( (void *)ns, 31 ) );
50 hash &= 0x7fffffffU;
51 /* Reserve hash numbers 0, 1 and INT_MAX for magic directory entries */
52 if (hash < 1)
53 hash += 2;
54 if (hash >= INT_MAX)
55 hash = INT_MAX - 1;
56 return hash;
57}
58
59static int sysfs_name_compare(unsigned int hash, const void *ns,
60 const char *name, const struct sysfs_dirent *sd)
61{
62 if (hash != sd->s_hash)
63 return hash - sd->s_hash;
64 if (ns != sd->s_ns)
65 return ns - sd->s_ns;
66 return strcmp(name, sd->s_name);
67}
68
69static int sysfs_sd_compare(const struct sysfs_dirent *left,
70 const struct sysfs_dirent *right)
71{
72 return sysfs_name_compare(left->s_hash, left->s_ns, left->s_name,
73 right);
74}
75
76/**
77 * sysfs_link_subling - link sysfs_dirent into sibling rbtree
35 * @sd: sysfs_dirent of interest 78 * @sd: sysfs_dirent of interest
36 * 79 *
37 * Link @sd into its sibling list which starts from 80 * Link @sd into its sibling rbtree which starts from
38 * sd->s_parent->s_dir.children. 81 * sd->s_parent->s_dir.children.
39 * 82 *
40 * Locking: 83 * Locking:
41 * mutex_lock(sysfs_mutex) 84 * mutex_lock(sysfs_mutex)
85 *
86 * RETURNS:
87 * 0 on susccess -EEXIST on failure.
42 */ 88 */
43static void sysfs_link_sibling(struct sysfs_dirent *sd) 89static int sysfs_link_sibling(struct sysfs_dirent *sd)
44{ 90{
45 struct sysfs_dirent *parent_sd = sd->s_parent; 91 struct rb_node **node = &sd->s_parent->s_dir.children.rb_node;
46 92 struct rb_node *parent = NULL;
47 struct rb_node **p;
48 struct rb_node *parent;
49 93
50 if (sysfs_type(sd) == SYSFS_DIR) 94 if (sysfs_type(sd) == SYSFS_DIR)
51 parent_sd->s_dir.subdirs++; 95 sd->s_parent->s_dir.subdirs++;
52 96
53 p = &parent_sd->s_dir.inode_tree.rb_node; 97 while (*node) {
54 parent = NULL; 98 struct sysfs_dirent *pos;
55 while (*p) { 99 int result;
56 parent = *p; 100
57#define node rb_entry(parent, struct sysfs_dirent, inode_node) 101 pos = to_sysfs_dirent(*node);
58 if (sd->s_ino < node->s_ino) { 102 parent = *node;
59 p = &node->inode_node.rb_left; 103 result = sysfs_sd_compare(sd, pos);
60 } else if (sd->s_ino > node->s_ino) { 104 if (result < 0)
61 p = &node->inode_node.rb_right; 105 node = &pos->s_rb.rb_left;
62 } else { 106 else if (result > 0)
63 printk(KERN_CRIT "sysfs: inserting duplicate inode '%lx'\n", 107 node = &pos->s_rb.rb_right;
64 (unsigned long) sd->s_ino); 108 else
65 BUG(); 109 return -EEXIST;
66 }
67#undef node
68 }
69 rb_link_node(&sd->inode_node, parent, p);
70 rb_insert_color(&sd->inode_node, &parent_sd->s_dir.inode_tree);
71
72 p = &parent_sd->s_dir.name_tree.rb_node;
73 parent = NULL;
74 while (*p) {
75 int c;
76 parent = *p;
77#define node rb_entry(parent, struct sysfs_dirent, name_node)
78 c = strcmp(sd->s_name, node->s_name);
79 if (c < 0) {
80 p = &node->name_node.rb_left;
81 } else {
82 p = &node->name_node.rb_right;
83 }
84#undef node
85 } 110 }
86 rb_link_node(&sd->name_node, parent, p); 111 /* add new node and rebalance the tree */
87 rb_insert_color(&sd->name_node, &parent_sd->s_dir.name_tree); 112 rb_link_node(&sd->s_rb, parent, node);
113 rb_insert_color(&sd->s_rb, &sd->s_parent->s_dir.children);
114 return 0;
88} 115}
89 116
90/** 117/**
91 * sysfs_unlink_sibling - unlink sysfs_dirent from sibling list 118 * sysfs_unlink_sibling - unlink sysfs_dirent from sibling rbtree
92 * @sd: sysfs_dirent of interest 119 * @sd: sysfs_dirent of interest
93 * 120 *
94 * Unlink @sd from its sibling list which starts from 121 * Unlink @sd from its sibling rbtree which starts from
95 * sd->s_parent->s_dir.children. 122 * sd->s_parent->s_dir.children.
96 * 123 *
97 * Locking: 124 * Locking:
@@ -102,8 +129,7 @@ static void sysfs_unlink_sibling(struct sysfs_dirent *sd)
102 if (sysfs_type(sd) == SYSFS_DIR) 129 if (sysfs_type(sd) == SYSFS_DIR)
103 sd->s_parent->s_dir.subdirs--; 130 sd->s_parent->s_dir.subdirs--;
104 131
105 rb_erase(&sd->inode_node, &sd->s_parent->s_dir.inode_tree); 132 rb_erase(&sd->s_rb, &sd->s_parent->s_dir.children);
106 rb_erase(&sd->name_node, &sd->s_parent->s_dir.name_tree);
107} 133}
108 134
109/** 135/**
@@ -198,7 +224,7 @@ static void sysfs_deactivate(struct sysfs_dirent *sd)
198 rwsem_release(&sd->dep_map, 1, _RET_IP_); 224 rwsem_release(&sd->dep_map, 1, _RET_IP_);
199} 225}
200 226
201static int sysfs_alloc_ino(ino_t *pino) 227static int sysfs_alloc_ino(unsigned int *pino)
202{ 228{
203 int ino, rc; 229 int ino, rc;
204 230
@@ -217,7 +243,7 @@ static int sysfs_alloc_ino(ino_t *pino)
217 return rc; 243 return rc;
218} 244}
219 245
220static void sysfs_free_ino(ino_t ino) 246static void sysfs_free_ino(unsigned int ino)
221{ 247{
222 spin_lock(&sysfs_ino_lock); 248 spin_lock(&sysfs_ino_lock);
223 ida_remove(&sysfs_ino_ida, ino); 249 ida_remove(&sysfs_ino_ida, ino);
@@ -402,6 +428,7 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
402int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) 428int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
403{ 429{
404 struct sysfs_inode_attrs *ps_iattr; 430 struct sysfs_inode_attrs *ps_iattr;
431 int ret;
405 432
406 if (!!sysfs_ns_type(acxt->parent_sd) != !!sd->s_ns) { 433 if (!!sysfs_ns_type(acxt->parent_sd) != !!sd->s_ns) {
407 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", 434 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
@@ -410,12 +437,12 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
410 return -EINVAL; 437 return -EINVAL;
411 } 438 }
412 439
413 if (sysfs_find_dirent(acxt->parent_sd, sd->s_ns, sd->s_name)) 440 sd->s_hash = sysfs_name_hash(sd->s_ns, sd->s_name);
414 return -EEXIST;
415
416 sd->s_parent = sysfs_get(acxt->parent_sd); 441 sd->s_parent = sysfs_get(acxt->parent_sd);
417 442
418 sysfs_link_sibling(sd); 443 ret = sysfs_link_sibling(sd);
444 if (ret)
445 return ret;
419 446
420 /* Update timestamps on the parent */ 447 /* Update timestamps on the parent */
421 ps_iattr = acxt->parent_sd->s_iattr; 448 ps_iattr = acxt->parent_sd->s_iattr;
@@ -565,8 +592,8 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
565 const void *ns, 592 const void *ns,
566 const unsigned char *name) 593 const unsigned char *name)
567{ 594{
568 struct rb_node *p = parent_sd->s_dir.name_tree.rb_node; 595 struct rb_node *node = parent_sd->s_dir.children.rb_node;
569 struct sysfs_dirent *found = NULL; 596 unsigned int hash;
570 597
571 if (!!sysfs_ns_type(parent_sd) != !!ns) { 598 if (!!sysfs_ns_type(parent_sd) != !!ns) {
572 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", 599 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
@@ -575,33 +602,21 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
575 return NULL; 602 return NULL;
576 } 603 }
577 604
578 while (p) { 605 hash = sysfs_name_hash(ns, name);
579 int c; 606 while (node) {
580#define node rb_entry(p, struct sysfs_dirent, name_node) 607 struct sysfs_dirent *sd;
581 c = strcmp(name, node->s_name); 608 int result;
582 if (c < 0) { 609
583 p = node->name_node.rb_left; 610 sd = to_sysfs_dirent(node);
584 } else if (c > 0) { 611 result = sysfs_name_compare(hash, ns, name, sd);
585 p = node->name_node.rb_right; 612 if (result < 0)
586 } else { 613 node = node->rb_left;
587 found = node; 614 else if (result > 0)
588 p = node->name_node.rb_left; 615 node = node->rb_right;
589 } 616 else
590#undef node 617 return sd;
591 }
592
593 if (found) {
594 while (found->s_ns != ns) {
595 p = rb_next(&found->name_node);
596 if (!p)
597 return NULL;
598 found = rb_entry(p, struct sysfs_dirent, name_node);
599 if (strcmp(name, found->s_name))
600 return NULL;
601 }
602 } 618 }
603 619 return NULL;
604 return found;
605} 620}
606 621
607/** 622/**
@@ -804,9 +819,9 @@ static void __sysfs_remove_dir(struct sysfs_dirent *dir_sd)
804 819
805 pr_debug("sysfs %s: removing dir\n", dir_sd->s_name); 820 pr_debug("sysfs %s: removing dir\n", dir_sd->s_name);
806 sysfs_addrm_start(&acxt, dir_sd); 821 sysfs_addrm_start(&acxt, dir_sd);
807 pos = rb_first(&dir_sd->s_dir.inode_tree); 822 pos = rb_first(&dir_sd->s_dir.children);
808 while (pos) { 823 while (pos) {
809 struct sysfs_dirent *sd = rb_entry(pos, struct sysfs_dirent, inode_node); 824 struct sysfs_dirent *sd = to_sysfs_dirent(pos);
810 pos = rb_next(pos); 825 pos = rb_next(pos);
811 if (sysfs_type(sd) != SYSFS_DIR) 826 if (sysfs_type(sd) != SYSFS_DIR)
812 sysfs_remove_one(&acxt, sd); 827 sysfs_remove_one(&acxt, sd);
@@ -863,6 +878,7 @@ int sysfs_rename(struct sysfs_dirent *sd,
863 878
864 dup_name = sd->s_name; 879 dup_name = sd->s_name;
865 sd->s_name = new_name; 880 sd->s_name = new_name;
881 sd->s_hash = sysfs_name_hash(sd->s_ns, sd->s_name);
866 } 882 }
867 883
868 /* Move to the appropriate place in the appropriate directories rbtree. */ 884 /* Move to the appropriate place in the appropriate directories rbtree. */
@@ -919,38 +935,36 @@ static int sysfs_dir_release(struct inode *inode, struct file *filp)
919} 935}
920 936
921static struct sysfs_dirent *sysfs_dir_pos(const void *ns, 937static struct sysfs_dirent *sysfs_dir_pos(const void *ns,
922 struct sysfs_dirent *parent_sd, ino_t ino, struct sysfs_dirent *pos) 938 struct sysfs_dirent *parent_sd, loff_t hash, struct sysfs_dirent *pos)
923{ 939{
924 if (pos) { 940 if (pos) {
925 int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) && 941 int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) &&
926 pos->s_parent == parent_sd && 942 pos->s_parent == parent_sd &&
927 ino == pos->s_ino; 943 hash == pos->s_hash;
928 sysfs_put(pos); 944 sysfs_put(pos);
929 if (!valid) 945 if (!valid)
930 pos = NULL; 946 pos = NULL;
931 } 947 }
932 if (!pos && (ino > 1) && (ino < INT_MAX)) { 948 if (!pos && (hash > 1) && (hash < INT_MAX)) {
933 struct rb_node *p = parent_sd->s_dir.inode_tree.rb_node; 949 struct rb_node *node = parent_sd->s_dir.children.rb_node;
934 while (p) { 950 while (node) {
935#define node rb_entry(p, struct sysfs_dirent, inode_node) 951 pos = to_sysfs_dirent(node);
936 if (ino < node->s_ino) { 952
937 pos = node; 953 if (hash < pos->s_hash)
938 p = node->inode_node.rb_left; 954 node = node->rb_left;
939 } else if (ino > node->s_ino) { 955 else if (hash > pos->s_hash)
940 p = node->inode_node.rb_right; 956 node = node->rb_right;
941 } else { 957 else
942 pos = node;
943 break; 958 break;
944 }
945#undef node
946 } 959 }
947 } 960 }
961 /* Skip over entries in the wrong namespace */
948 while (pos && pos->s_ns != ns) { 962 while (pos && pos->s_ns != ns) {
949 struct rb_node *p = rb_next(&pos->inode_node); 963 struct rb_node *node = rb_next(&pos->s_rb);
950 if (!p) 964 if (!node)
951 pos = NULL; 965 pos = NULL;
952 else 966 else
953 pos = rb_entry(p, struct sysfs_dirent, inode_node); 967 pos = to_sysfs_dirent(node);
954 } 968 }
955 return pos; 969 return pos;
956} 970}
@@ -960,11 +974,11 @@ static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns,
960{ 974{
961 pos = sysfs_dir_pos(ns, parent_sd, ino, pos); 975 pos = sysfs_dir_pos(ns, parent_sd, ino, pos);
962 if (pos) do { 976 if (pos) do {
963 struct rb_node *p = rb_next(&pos->inode_node); 977 struct rb_node *node = rb_next(&pos->s_rb);
964 if (!p) 978 if (!node)
965 pos = NULL; 979 pos = NULL;
966 else 980 else
967 pos = rb_entry(p, struct sysfs_dirent, inode_node); 981 pos = to_sysfs_dirent(node);
968 } while (pos && pos->s_ns != ns); 982 } while (pos && pos->s_ns != ns);
969 return pos; 983 return pos;
970} 984}
@@ -1006,7 +1020,7 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
1006 len = strlen(name); 1020 len = strlen(name);
1007 ino = pos->s_ino; 1021 ino = pos->s_ino;
1008 type = dt_type(pos); 1022 type = dt_type(pos);
1009 filp->f_pos = ino; 1023 filp->f_pos = pos->s_hash;
1010 filp->private_data = sysfs_get(pos); 1024 filp->private_data = sysfs_get(pos);
1011 1025
1012 mutex_unlock(&sysfs_mutex); 1026 mutex_unlock(&sysfs_mutex);
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 85eb81683a29..feb2d69396cf 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -136,12 +136,13 @@ static int sysfs_sd_setsecdata(struct sysfs_dirent *sd, void **secdata, u32 *sec
136 void *old_secdata; 136 void *old_secdata;
137 size_t old_secdata_len; 137 size_t old_secdata_len;
138 138
139 iattrs = sd->s_iattr; 139 if (!sd->s_iattr) {
140 if (!iattrs) 140 sd->s_iattr = sysfs_init_inode_attrs(sd);
141 iattrs = sysfs_init_inode_attrs(sd); 141 if (!sd->s_iattr)
142 if (!iattrs) 142 return -ENOMEM;
143 return -ENOMEM; 143 }
144 144
145 iattrs = sd->s_iattr;
145 old_secdata = iattrs->ia_secdata; 146 old_secdata = iattrs->ia_secdata;
146 old_secdata_len = iattrs->ia_secdata_len; 147 old_secdata_len = iattrs->ia_secdata_len;
147 148
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index e34f0d99ea4e..140f26a34288 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -36,7 +36,7 @@ struct sysfs_dirent sysfs_root = {
36 .s_name = "", 36 .s_name = "",
37 .s_count = ATOMIC_INIT(1), 37 .s_count = ATOMIC_INIT(1),
38 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT), 38 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT),
39 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO, 39 .s_mode = S_IFDIR | S_IRUGO | S_IXUGO,
40 .s_ino = 1, 40 .s_ino = 1,
41}; 41};
42 42
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 7484a36ee678..661a9639570b 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -20,9 +20,8 @@ struct sysfs_elem_dir {
20 struct kobject *kobj; 20 struct kobject *kobj;
21 21
22 unsigned long subdirs; 22 unsigned long subdirs;
23 23 /* children rbtree starts here and goes through sd->s_rb */
24 struct rb_root inode_tree; 24 struct rb_root children;
25 struct rb_root name_tree;
26}; 25};
27 26
28struct sysfs_elem_symlink { 27struct sysfs_elem_symlink {
@@ -62,8 +61,7 @@ struct sysfs_dirent {
62 struct sysfs_dirent *s_parent; 61 struct sysfs_dirent *s_parent;
63 const char *s_name; 62 const char *s_name;
64 63
65 struct rb_node inode_node; 64 struct rb_node s_rb;
66 struct rb_node name_node;
67 65
68 union { 66 union {
69 struct completion *completion; 67 struct completion *completion;
@@ -71,6 +69,7 @@ struct sysfs_dirent {
71 } u; 69 } u;
72 70
73 const void *s_ns; /* namespace tag */ 71 const void *s_ns; /* namespace tag */
72 unsigned int s_hash; /* ns + name hash */
74 union { 73 union {
75 struct sysfs_elem_dir s_dir; 74 struct sysfs_elem_dir s_dir;
76 struct sysfs_elem_symlink s_symlink; 75 struct sysfs_elem_symlink s_symlink;
@@ -78,9 +77,9 @@ struct sysfs_dirent {
78 struct sysfs_elem_bin_attr s_bin_attr; 77 struct sysfs_elem_bin_attr s_bin_attr;
79 }; 78 };
80 79
81 unsigned int s_flags; 80 unsigned short s_flags;
82 umode_t s_mode; 81 umode_t s_mode;
83 ino_t s_ino; 82 unsigned int s_ino;
84 struct sysfs_inode_attrs *s_iattr; 83 struct sysfs_inode_attrs *s_iattr;
85}; 84};
86 85
@@ -95,11 +94,11 @@ struct sysfs_dirent {
95#define SYSFS_ACTIVE_REF (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR) 94#define SYSFS_ACTIVE_REF (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR)
96 95
97/* identify any namespace tag on sysfs_dirents */ 96/* identify any namespace tag on sysfs_dirents */
98#define SYSFS_NS_TYPE_MASK 0xff00 97#define SYSFS_NS_TYPE_MASK 0xf00
99#define SYSFS_NS_TYPE_SHIFT 8 98#define SYSFS_NS_TYPE_SHIFT 8
100 99
101#define SYSFS_FLAG_MASK ~(SYSFS_NS_TYPE_MASK|SYSFS_TYPE_MASK) 100#define SYSFS_FLAG_MASK ~(SYSFS_NS_TYPE_MASK|SYSFS_TYPE_MASK)
102#define SYSFS_FLAG_REMOVED 0x020000 101#define SYSFS_FLAG_REMOVED 0x02000
103 102
104static inline unsigned int sysfs_type(struct sysfs_dirent *sd) 103static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
105{ 104{
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 8cf7e98a2c7b..9d650476d5dc 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -225,6 +225,7 @@ struct acpi_processor_errata {
225 } piix4; 225 } piix4;
226}; 226};
227 227
228extern void acpi_processor_load_module(struct acpi_processor *pr);
228extern int acpi_processor_preregister_performance(struct 229extern int acpi_processor_preregister_performance(struct
229 acpi_processor_performance 230 acpi_processor_performance
230 __percpu *performance); 231 __percpu *performance);
diff --git a/include/linux/connector.h b/include/linux/connector.h
index 3c9c54fd5690..76384074262d 100644
--- a/include/linux/connector.h
+++ b/include/linux/connector.h
@@ -43,6 +43,7 @@
43#define CN_IDX_DRBD 0x8 43#define CN_IDX_DRBD 0x8
44#define CN_VAL_DRBD 0x1 44#define CN_VAL_DRBD 0x1
45#define CN_KVP_IDX 0x9 /* HyperV KVP */ 45#define CN_KVP_IDX 0x9 /* HyperV KVP */
46#define CN_KVP_VAL 0x1 /* queries from the kernel */
46 47
47#define CN_NETLINK_USERS 10 /* Highest index + 1 */ 48#define CN_NETLINK_USERS 10 /* Highest index + 1 */
48 49
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 1f6587590a1a..6e53b4823d7f 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -44,6 +44,13 @@ extern ssize_t arch_cpu_release(const char *, size_t);
44#endif 44#endif
45struct notifier_block; 45struct notifier_block;
46 46
47#ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
48extern int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env);
49extern ssize_t arch_print_cpu_modalias(struct device *dev,
50 struct device_attribute *attr,
51 char *bufptr);
52#endif
53
47/* 54/*
48 * CPU notifier priorities. 55 * CPU notifier priorities.
49 */ 56 */
diff --git a/include/linux/device.h b/include/linux/device.h
index b63fb393aa58..f62e21689fdd 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -238,8 +238,6 @@ struct device_driver {
238extern int __must_check driver_register(struct device_driver *drv); 238extern int __must_check driver_register(struct device_driver *drv);
239extern void driver_unregister(struct device_driver *drv); 239extern void driver_unregister(struct device_driver *drv);
240 240
241extern struct device_driver *get_driver(struct device_driver *drv);
242extern void put_driver(struct device_driver *drv);
243extern struct device_driver *driver_find(const char *name, 241extern struct device_driver *driver_find(const char *name,
244 struct bus_type *bus); 242 struct bus_type *bus);
245extern int driver_probe_done(void); 243extern int driver_probe_done(void);
@@ -946,14 +944,14 @@ int _dev_info(const struct device *dev, const char *fmt, ...)
946 944
947#define dev_info(dev, fmt, arg...) _dev_info(dev, fmt, ##arg) 945#define dev_info(dev, fmt, arg...) _dev_info(dev, fmt, ##arg)
948 946
949#if defined(DEBUG) 947#if defined(CONFIG_DYNAMIC_DEBUG)
950#define dev_dbg(dev, format, arg...) \
951 dev_printk(KERN_DEBUG, dev, format, ##arg)
952#elif defined(CONFIG_DYNAMIC_DEBUG)
953#define dev_dbg(dev, format, ...) \ 948#define dev_dbg(dev, format, ...) \
954do { \ 949do { \
955 dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \ 950 dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
956} while (0) 951} while (0)
952#elif defined(DEBUG)
953#define dev_dbg(dev, format, arg...) \
954 dev_printk(KERN_DEBUG, dev, format, ##arg)
957#else 955#else
958#define dev_dbg(dev, format, arg...) \ 956#define dev_dbg(dev, format, arg...) \
959({ \ 957({ \
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 0564e3c39882..7e3c53a900d8 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -15,20 +15,24 @@ struct _ddebug {
15 const char *function; 15 const char *function;
16 const char *filename; 16 const char *filename;
17 const char *format; 17 const char *format;
18 unsigned int lineno:24; 18 unsigned int lineno:18;
19 /* 19 /*
20 * The flags field controls the behaviour at the callsite. 20 * The flags field controls the behaviour at the callsite.
21 * The bits here are changed dynamically when the user 21 * The bits here are changed dynamically when the user
22 * writes commands to <debugfs>/dynamic_debug/control 22 * writes commands to <debugfs>/dynamic_debug/control
23 */ 23 */
24#define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */ 24#define _DPRINTK_FLAGS_NONE 0
25#define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */
25#define _DPRINTK_FLAGS_INCL_MODNAME (1<<1) 26#define _DPRINTK_FLAGS_INCL_MODNAME (1<<1)
26#define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2) 27#define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2)
27#define _DPRINTK_FLAGS_INCL_LINENO (1<<3) 28#define _DPRINTK_FLAGS_INCL_LINENO (1<<3)
28#define _DPRINTK_FLAGS_INCL_TID (1<<4) 29#define _DPRINTK_FLAGS_INCL_TID (1<<4)
30#if defined DEBUG
31#define _DPRINTK_FLAGS_DEFAULT _DPRINTK_FLAGS_PRINT
32#else
29#define _DPRINTK_FLAGS_DEFAULT 0 33#define _DPRINTK_FLAGS_DEFAULT 0
34#endif
30 unsigned int flags:8; 35 unsigned int flags:8;
31 char enabled;
32} __attribute__((aligned(8))); 36} __attribute__((aligned(8)));
33 37
34 38
@@ -62,21 +66,20 @@ int __dynamic_netdev_dbg(struct _ddebug *descriptor,
62 .format = (fmt), \ 66 .format = (fmt), \
63 .lineno = __LINE__, \ 67 .lineno = __LINE__, \
64 .flags = _DPRINTK_FLAGS_DEFAULT, \ 68 .flags = _DPRINTK_FLAGS_DEFAULT, \
65 .enabled = false, \
66 } 69 }
67 70
68#define dynamic_pr_debug(fmt, ...) \ 71#define dynamic_pr_debug(fmt, ...) \
69do { \ 72do { \
70 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ 73 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
71 if (unlikely(descriptor.enabled)) \ 74 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
72 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ 75 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \
73 ##__VA_ARGS__); \ 76 ##__VA_ARGS__); \
74} while (0) 77} while (0)
75 78
76#define dynamic_dev_dbg(dev, fmt, ...) \ 79#define dynamic_dev_dbg(dev, fmt, ...) \
77do { \ 80do { \
78 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ 81 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
79 if (unlikely(descriptor.enabled)) \ 82 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
80 __dynamic_dev_dbg(&descriptor, dev, fmt, \ 83 __dynamic_dev_dbg(&descriptor, dev, fmt, \
81 ##__VA_ARGS__); \ 84 ##__VA_ARGS__); \
82} while (0) 85} while (0)
@@ -84,7 +87,7 @@ do { \
84#define dynamic_netdev_dbg(dev, fmt, ...) \ 87#define dynamic_netdev_dbg(dev, fmt, ...) \
85do { \ 88do { \
86 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ 89 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
87 if (unlikely(descriptor.enabled)) \ 90 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
88 __dynamic_netdev_dbg(&descriptor, dev, fmt, \ 91 __dynamic_netdev_dbg(&descriptor, dev, fmt, \
89 ##__VA_ARGS__); \ 92 ##__VA_ARGS__); \
90} while (0) 93} while (0)
diff --git a/include/linux/errno.h b/include/linux/errno.h
index 46685832ed99..2d09bfa5c262 100644
--- a/include/linux/errno.h
+++ b/include/linux/errno.h
@@ -16,6 +16,7 @@
16#define ERESTARTNOHAND 514 /* restart if no handler.. */ 16#define ERESTARTNOHAND 514 /* restart if no handler.. */
17#define ENOIOCTLCMD 515 /* No ioctl command */ 17#define ENOIOCTLCMD 515 /* No ioctl command */
18#define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */ 18#define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
19#define EPROBE_DEFER 517 /* Driver requests probe retry */
19 20
20/* Defined for the NFSv3 protocol */ 21/* Defined for the NFSv3 protocol */
21#define EBADHANDLE 521 /* Illegal NFS file handle */ 22#define EBADHANDLE 521 /* Illegal NFS file handle */
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 0ae065a5fcb2..5852545e6bba 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -25,6 +25,173 @@
25#ifndef _HYPERV_H 25#ifndef _HYPERV_H
26#define _HYPERV_H 26#define _HYPERV_H
27 27
28#include <linux/types.h>
29
30/*
31 * An implementation of HyperV key value pair (KVP) functionality for Linux.
32 *
33 *
34 * Copyright (C) 2010, Novell, Inc.
35 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
36 *
37 */
38
39/*
40 * Maximum value size - used for both key names and value data, and includes
41 * any applicable NULL terminators.
42 *
43 * Note: This limit is somewhat arbitrary, but falls easily within what is
44 * supported for all native guests (back to Win 2000) and what is reasonable
45 * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
46 * limited to 255 character key names.
47 *
48 * MSDN recommends not storing data values larger than 2048 bytes in the
49 * registry.
50 *
51 * Note: This value is used in defining the KVP exchange message - this value
52 * cannot be modified without affecting the message size and compatibility.
53 */
54
55/*
56 * bytes, including any null terminators
57 */
58#define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
59
60
61/*
62 * Maximum key size - the registry limit for the length of an entry name
63 * is 256 characters, including the null terminator
64 */
65
66#define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
67
68/*
69 * In Linux, we implement the KVP functionality in two components:
70 * 1) The kernel component which is packaged as part of the hv_utils driver
71 * is responsible for communicating with the host and responsible for
72 * implementing the host/guest protocol. 2) A user level daemon that is
73 * responsible for data gathering.
74 *
75 * Host/Guest Protocol: The host iterates over an index and expects the guest
76 * to assign a key name to the index and also return the value corresponding to
77 * the key. The host will have atmost one KVP transaction outstanding at any
78 * given point in time. The host side iteration stops when the guest returns
79 * an error. Microsoft has specified the following mapping of key names to
80 * host specified index:
81 *
82 * Index Key Name
83 * 0 FullyQualifiedDomainName
84 * 1 IntegrationServicesVersion
85 * 2 NetworkAddressIPv4
86 * 3 NetworkAddressIPv6
87 * 4 OSBuildNumber
88 * 5 OSName
89 * 6 OSMajorVersion
90 * 7 OSMinorVersion
91 * 8 OSVersion
92 * 9 ProcessorArchitecture
93 *
94 * The Windows host expects the Key Name and Key Value to be encoded in utf16.
95 *
96 * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
97 * data gathering functionality in a user mode daemon. The user level daemon
98 * is also responsible for binding the key name to the index as well. The
99 * kernel and user-level daemon communicate using a connector channel.
100 *
101 * The user mode component first registers with the
102 * the kernel component. Subsequently, the kernel component requests, data
103 * for the specified keys. In response to this message the user mode component
104 * fills in the value corresponding to the specified key. We overload the
105 * sequence field in the cn_msg header to define our KVP message types.
106 *
107 *
108 * The kernel component simply acts as a conduit for communication between the
109 * Windows host and the user-level daemon. The kernel component passes up the
110 * index received from the Host to the user-level daemon. If the index is
111 * valid (supported), the corresponding key as well as its
112 * value (both are strings) is returned. If the index is invalid
113 * (not supported), a NULL key string is returned.
114 */
115
116
117/*
118 * Registry value types.
119 */
120
121#define REG_SZ 1
122#define REG_U32 4
123#define REG_U64 8
124
125enum hv_kvp_exchg_op {
126 KVP_OP_GET = 0,
127 KVP_OP_SET,
128 KVP_OP_DELETE,
129 KVP_OP_ENUMERATE,
130 KVP_OP_REGISTER,
131 KVP_OP_COUNT /* Number of operations, must be last. */
132};
133
134enum hv_kvp_exchg_pool {
135 KVP_POOL_EXTERNAL = 0,
136 KVP_POOL_GUEST,
137 KVP_POOL_AUTO,
138 KVP_POOL_AUTO_EXTERNAL,
139 KVP_POOL_AUTO_INTERNAL,
140 KVP_POOL_COUNT /* Number of pools, must be last. */
141};
142
143struct hv_kvp_hdr {
144 __u8 operation;
145 __u8 pool;
146 __u16 pad;
147} __attribute__((packed));
148
149struct hv_kvp_exchg_msg_value {
150 __u32 value_type;
151 __u32 key_size;
152 __u32 value_size;
153 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
154 union {
155 __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
156 __u32 value_u32;
157 __u64 value_u64;
158 };
159} __attribute__((packed));
160
161struct hv_kvp_msg_enumerate {
162 __u32 index;
163 struct hv_kvp_exchg_msg_value data;
164} __attribute__((packed));
165
166struct hv_kvp_msg_get {
167 struct hv_kvp_exchg_msg_value data;
168};
169
170struct hv_kvp_msg_set {
171 struct hv_kvp_exchg_msg_value data;
172};
173
174struct hv_kvp_msg_delete {
175 __u32 key_size;
176 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
177};
178
179struct hv_kvp_register {
180 __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
181};
182
183struct hv_kvp_msg {
184 struct hv_kvp_hdr kvp_hdr;
185 union {
186 struct hv_kvp_msg_get kvp_get;
187 struct hv_kvp_msg_set kvp_set;
188 struct hv_kvp_msg_delete kvp_delete;
189 struct hv_kvp_msg_enumerate kvp_enum_data;
190 struct hv_kvp_register kvp_register;
191 } body;
192} __attribute__((packed));
193
194#ifdef __KERNEL__
28#include <linux/scatterlist.h> 195#include <linux/scatterlist.h>
29#include <linux/list.h> 196#include <linux/list.h>
30#include <linux/uuid.h> 197#include <linux/uuid.h>
@@ -785,6 +952,7 @@ void vmbus_driver_unregister(struct hv_driver *hv_driver);
785 952
786#define HV_S_OK 0x00000000 953#define HV_S_OK 0x00000000
787#define HV_E_FAIL 0x80004005 954#define HV_E_FAIL 0x80004005
955#define HV_S_CONT 0x80070103
788#define HV_ERROR_NOT_SUPPORTED 0x80070032 956#define HV_ERROR_NOT_SUPPORTED 0x80070032
789#define HV_ERROR_MACHINE_LOCKED 0x800704F7 957#define HV_ERROR_MACHINE_LOCKED 0x800704F7
790 958
@@ -870,4 +1038,9 @@ struct hyperv_service_callback {
870extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *, 1038extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *,
871 struct icmsg_negotiate *, u8 *); 1039 struct icmsg_negotiate *, u8 *);
872 1040
1041int hv_kvp_init(struct hv_util_service *);
1042void hv_kvp_deinit(void);
1043void hv_kvp_onchannelcallback(void *);
1044
1045#endif /* __KERNEL__ */
873#endif /* _HYPERV_H */ 1046#endif /* _HYPERV_H */
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 83ac0713ed0a..fb69ad191ad7 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -560,4 +560,25 @@ struct amba_id {
560#endif 560#endif
561}; 561};
562 562
563/*
564 * Match x86 CPUs for CPU specific drivers.
565 * See documentation of "x86_match_cpu" for details.
566 */
567
568struct x86_cpu_id {
569 __u16 vendor;
570 __u16 family;
571 __u16 model;
572 __u16 feature; /* bit index */
573 kernel_ulong_t driver_data;
574};
575
576#define X86_FEATURE_MATCH(x) \
577 { X86_VENDOR_ANY, X86_FAMILY_ANY, X86_MODEL_ANY, x }
578
579#define X86_VENDOR_ANY 0xffff
580#define X86_FAMILY_ANY 0
581#define X86_MODEL_ANY 0
582#define X86_FEATURE_ANY 0 /* Same as FPU, you can't test for that */
583
563#endif /* LINUX_MOD_DEVICETABLE_H */ 584#endif /* LINUX_MOD_DEVICETABLE_H */
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 7dfaae7846ab..3e5cb2546e4f 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2687,14 +2687,14 @@ int netdev_info(const struct net_device *dev, const char *format, ...);
2687#define MODULE_ALIAS_NETDEV(device) \ 2687#define MODULE_ALIAS_NETDEV(device) \
2688 MODULE_ALIAS("netdev-" device) 2688 MODULE_ALIAS("netdev-" device)
2689 2689
2690#if defined(DEBUG) 2690#if defined(CONFIG_DYNAMIC_DEBUG)
2691#define netdev_dbg(__dev, format, args...) \
2692 netdev_printk(KERN_DEBUG, __dev, format, ##args)
2693#elif defined(CONFIG_DYNAMIC_DEBUG)
2694#define netdev_dbg(__dev, format, args...) \ 2691#define netdev_dbg(__dev, format, args...) \
2695do { \ 2692do { \
2696 dynamic_netdev_dbg(__dev, format, ##args); \ 2693 dynamic_netdev_dbg(__dev, format, ##args); \
2697} while (0) 2694} while (0)
2695#elif defined(DEBUG)
2696#define netdev_dbg(__dev, format, args...) \
2697 netdev_printk(KERN_DEBUG, __dev, format, ##args)
2698#else 2698#else
2699#define netdev_dbg(__dev, format, args...) \ 2699#define netdev_dbg(__dev, format, args...) \
2700({ \ 2700({ \
diff --git a/include/linux/pci.h b/include/linux/pci.h
index a16b1df3deff..d4afd703e948 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -946,6 +946,19 @@ int __must_check __pci_register_driver(struct pci_driver *, struct module *,
946 __pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME) 946 __pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
947 947
948void pci_unregister_driver(struct pci_driver *dev); 948void pci_unregister_driver(struct pci_driver *dev);
949
950/**
951 * module_pci_driver() - Helper macro for registering a PCI driver
952 * @__pci_driver: pci_driver struct
953 *
954 * Helper macro for PCI drivers which do not do anything special in module
955 * init/exit. This eliminates a lot of boilerplate. Each module may only
956 * use this macro once, and calling it replaces module_init() and module_exit()
957 */
958#define module_pci_driver(__pci_driver) \
959 module_driver(__pci_driver, pci_register_driver, \
960 pci_unregister_driver)
961
949void pci_remove_behind_bridge(struct pci_dev *dev); 962void pci_remove_behind_bridge(struct pci_dev *dev);
950struct pci_driver *pci_dev_driver(const struct pci_dev *dev); 963struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
951int pci_add_dynid(struct pci_driver *drv, 964int pci_add_dynid(struct pci_driver *drv,
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 1f77a4174ee0..0525927f203f 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -190,13 +190,13 @@ extern void dump_stack(void) __cold;
190#endif 190#endif
191 191
192/* If you are writing a driver, please use dev_dbg instead */ 192/* If you are writing a driver, please use dev_dbg instead */
193#if defined(DEBUG) 193#if defined(CONFIG_DYNAMIC_DEBUG)
194#define pr_debug(fmt, ...) \
195 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
196#elif defined(CONFIG_DYNAMIC_DEBUG)
197/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ 194/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
198#define pr_debug(fmt, ...) \ 195#define pr_debug(fmt, ...) \
199 dynamic_pr_debug(fmt, ##__VA_ARGS__) 196 dynamic_pr_debug(fmt, ##__VA_ARGS__)
197#elif defined(DEBUG)
198#define pr_debug(fmt, ...) \
199 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
200#else 200#else
201#define pr_debug(fmt, ...) \ 201#define pr_debug(fmt, ...) \
202 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 202 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
new file mode 100644
index 000000000000..2739ccb69571
--- /dev/null
+++ b/include/linux/sys_soc.h
@@ -0,0 +1,37 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2011
3 * Author: Lee Jones <lee.jones@linaro.org> for ST-Ericsson.
4 * License terms: GNU General Public License (GPL), version 2
5 */
6#ifndef __SOC_BUS_H
7#define __SOC_BUS_H
8
9#include <linux/device.h>
10
11struct soc_device_attribute {
12 const char *machine;
13 const char *family;
14 const char *revision;
15 const char *soc_id;
16};
17
18/**
19 * soc_device_register - register SoC as a device
20 * @soc_plat_dev_attr: Attributes passed from platform to be attributed to a SoC
21 */
22struct soc_device *soc_device_register(
23 struct soc_device_attribute *soc_plat_dev_attr);
24
25/**
26 * soc_device_unregister - unregister SoC device
27 * @dev: SoC device to be unregistered
28 */
29void soc_device_unregister(struct soc_device *soc_dev);
30
31/**
32 * soc_device_to_device - helper function to fetch struct device
33 * @soc: Previously registered SoC device container
34 */
35struct device *soc_device_to_device(struct soc_device *soc);
36
37#endif /* __SOC_BUS_H */
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index fea790a2b176..13ef2338be41 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -170,7 +170,7 @@ static bool driver_filter(struct device *dev)
170 return false; 170 return false;
171 171
172 /* driver filter on but not yet initialized */ 172 /* driver filter on but not yet initialized */
173 drv = get_driver(dev->driver); 173 drv = dev->driver;
174 if (!drv) 174 if (!drv)
175 return false; 175 return false;
176 176
@@ -185,7 +185,6 @@ static bool driver_filter(struct device *dev)
185 } 185 }
186 186
187 read_unlock_irqrestore(&driver_name_lock, flags); 187 read_unlock_irqrestore(&driver_name_lock, flags);
188 put_driver(drv);
189 188
190 return ret; 189 return ret;
191} 190}
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index dcdade39e47f..310c753cf83e 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -60,6 +60,7 @@ struct ddebug_iter {
60static DEFINE_MUTEX(ddebug_lock); 60static DEFINE_MUTEX(ddebug_lock);
61static LIST_HEAD(ddebug_tables); 61static LIST_HEAD(ddebug_tables);
62static int verbose = 0; 62static int verbose = 0;
63module_param(verbose, int, 0644);
63 64
64/* Return the last part of a pathname */ 65/* Return the last part of a pathname */
65static inline const char *basename(const char *path) 66static inline const char *basename(const char *path)
@@ -68,12 +69,24 @@ static inline const char *basename(const char *path)
68 return tail ? tail+1 : path; 69 return tail ? tail+1 : path;
69} 70}
70 71
72/* Return the path relative to source root */
73static inline const char *trim_prefix(const char *path)
74{
75 int skip = strlen(__FILE__) - strlen("lib/dynamic_debug.c");
76
77 if (strncmp(path, __FILE__, skip))
78 skip = 0; /* prefix mismatch, don't skip */
79
80 return path + skip;
81}
82
71static struct { unsigned flag:8; char opt_char; } opt_array[] = { 83static struct { unsigned flag:8; char opt_char; } opt_array[] = {
72 { _DPRINTK_FLAGS_PRINT, 'p' }, 84 { _DPRINTK_FLAGS_PRINT, 'p' },
73 { _DPRINTK_FLAGS_INCL_MODNAME, 'm' }, 85 { _DPRINTK_FLAGS_INCL_MODNAME, 'm' },
74 { _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' }, 86 { _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' },
75 { _DPRINTK_FLAGS_INCL_LINENO, 'l' }, 87 { _DPRINTK_FLAGS_INCL_LINENO, 'l' },
76 { _DPRINTK_FLAGS_INCL_TID, 't' }, 88 { _DPRINTK_FLAGS_INCL_TID, 't' },
89 { _DPRINTK_FLAGS_NONE, '_' },
77}; 90};
78 91
79/* format a string into buf[] which describes the _ddebug's flags */ 92/* format a string into buf[] which describes the _ddebug's flags */
@@ -83,58 +96,74 @@ static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
83 char *p = buf; 96 char *p = buf;
84 int i; 97 int i;
85 98
86 BUG_ON(maxlen < 4); 99 BUG_ON(maxlen < 6);
87 for (i = 0; i < ARRAY_SIZE(opt_array); ++i) 100 for (i = 0; i < ARRAY_SIZE(opt_array); ++i)
88 if (dp->flags & opt_array[i].flag) 101 if (dp->flags & opt_array[i].flag)
89 *p++ = opt_array[i].opt_char; 102 *p++ = opt_array[i].opt_char;
90 if (p == buf) 103 if (p == buf)
91 *p++ = '-'; 104 *p++ = '_';
92 *p = '\0'; 105 *p = '\0';
93 106
94 return buf; 107 return buf;
95} 108}
96 109
110#define vpr_info_dq(q, msg) \
111do { \
112 if (verbose) \
113 /* trim last char off format print */ \
114 pr_info("%s: func=\"%s\" file=\"%s\" " \
115 "module=\"%s\" format=\"%.*s\" " \
116 "lineno=%u-%u", \
117 msg, \
118 q->function ? q->function : "", \
119 q->filename ? q->filename : "", \
120 q->module ? q->module : "", \
121 (int)(q->format ? strlen(q->format) - 1 : 0), \
122 q->format ? q->format : "", \
123 q->first_lineno, q->last_lineno); \
124} while (0)
125
97/* 126/*
98 * Search the tables for _ddebug's which match the given 127 * Search the tables for _ddebug's which match the given `query' and
99 * `query' and apply the `flags' and `mask' to them. Tells 128 * apply the `flags' and `mask' to them. Returns number of matching
100 * the user which ddebug's were changed, or whether none 129 * callsites, normally the same as number of changes. If verbose,
101 * were matched. 130 * logs the changes. Takes ddebug_lock.
102 */ 131 */
103static void ddebug_change(const struct ddebug_query *query, 132static int ddebug_change(const struct ddebug_query *query,
104 unsigned int flags, unsigned int mask) 133 unsigned int flags, unsigned int mask)
105{ 134{
106 int i; 135 int i;
107 struct ddebug_table *dt; 136 struct ddebug_table *dt;
108 unsigned int newflags; 137 unsigned int newflags;
109 unsigned int nfound = 0; 138 unsigned int nfound = 0;
110 char flagbuf[8]; 139 char flagbuf[10];
111 140
112 /* search for matching ddebugs */ 141 /* search for matching ddebugs */
113 mutex_lock(&ddebug_lock); 142 mutex_lock(&ddebug_lock);
114 list_for_each_entry(dt, &ddebug_tables, link) { 143 list_for_each_entry(dt, &ddebug_tables, link) {
115 144
116 /* match against the module name */ 145 /* match against the module name */
117 if (query->module != NULL && 146 if (query->module && strcmp(query->module, dt->mod_name))
118 strcmp(query->module, dt->mod_name))
119 continue; 147 continue;
120 148
121 for (i = 0 ; i < dt->num_ddebugs ; i++) { 149 for (i = 0 ; i < dt->num_ddebugs ; i++) {
122 struct _ddebug *dp = &dt->ddebugs[i]; 150 struct _ddebug *dp = &dt->ddebugs[i];
123 151
124 /* match against the source filename */ 152 /* match against the source filename */
125 if (query->filename != NULL && 153 if (query->filename &&
126 strcmp(query->filename, dp->filename) && 154 strcmp(query->filename, dp->filename) &&
127 strcmp(query->filename, basename(dp->filename))) 155 strcmp(query->filename, basename(dp->filename)) &&
156 strcmp(query->filename, trim_prefix(dp->filename)))
128 continue; 157 continue;
129 158
130 /* match against the function */ 159 /* match against the function */
131 if (query->function != NULL && 160 if (query->function &&
132 strcmp(query->function, dp->function)) 161 strcmp(query->function, dp->function))
133 continue; 162 continue;
134 163
135 /* match against the format */ 164 /* match against the format */
136 if (query->format != NULL && 165 if (query->format &&
137 strstr(dp->format, query->format) == NULL) 166 !strstr(dp->format, query->format))
138 continue; 167 continue;
139 168
140 /* match against the line number range */ 169 /* match against the line number range */
@@ -151,13 +180,9 @@ static void ddebug_change(const struct ddebug_query *query,
151 if (newflags == dp->flags) 180 if (newflags == dp->flags)
152 continue; 181 continue;
153 dp->flags = newflags; 182 dp->flags = newflags;
154 if (newflags)
155 dp->enabled = 1;
156 else
157 dp->enabled = 0;
158 if (verbose) 183 if (verbose)
159 pr_info("changed %s:%d [%s]%s %s\n", 184 pr_info("changed %s:%d [%s]%s =%s\n",
160 dp->filename, dp->lineno, 185 trim_prefix(dp->filename), dp->lineno,
161 dt->mod_name, dp->function, 186 dt->mod_name, dp->function,
162 ddebug_describe_flags(dp, flagbuf, 187 ddebug_describe_flags(dp, flagbuf,
163 sizeof(flagbuf))); 188 sizeof(flagbuf)));
@@ -167,6 +192,8 @@ static void ddebug_change(const struct ddebug_query *query,
167 192
168 if (!nfound && verbose) 193 if (!nfound && verbose)
169 pr_info("no matches for query\n"); 194 pr_info("no matches for query\n");
195
196 return nfound;
170} 197}
171 198
172/* 199/*
@@ -186,8 +213,10 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
186 buf = skip_spaces(buf); 213 buf = skip_spaces(buf);
187 if (!*buf) 214 if (!*buf)
188 break; /* oh, it was trailing whitespace */ 215 break; /* oh, it was trailing whitespace */
216 if (*buf == '#')
217 break; /* token starts comment, skip rest of line */
189 218
190 /* Run `end' over a word, either whitespace separated or quoted */ 219 /* find `end' of word, whitespace separated or quoted */
191 if (*buf == '"' || *buf == '\'') { 220 if (*buf == '"' || *buf == '\'') {
192 int quote = *buf++; 221 int quote = *buf++;
193 for (end = buf ; *end && *end != quote ; end++) 222 for (end = buf ; *end && *end != quote ; end++)
@@ -199,8 +228,8 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
199 ; 228 ;
200 BUG_ON(end == buf); 229 BUG_ON(end == buf);
201 } 230 }
202 /* Here `buf' is the start of the word, `end' is one past the end */
203 231
232 /* `buf' is start of word, `end' is one past its end */
204 if (nwords == maxwords) 233 if (nwords == maxwords)
205 return -EINVAL; /* ran out of words[] before bytes */ 234 return -EINVAL; /* ran out of words[] before bytes */
206 if (*end) 235 if (*end)
@@ -279,6 +308,19 @@ static char *unescape(char *str)
279 return str; 308 return str;
280} 309}
281 310
311static int check_set(const char **dest, char *src, char *name)
312{
313 int rc = 0;
314
315 if (*dest) {
316 rc = -EINVAL;
317 pr_err("match-spec:%s val:%s overridden by %s",
318 name, *dest, src);
319 }
320 *dest = src;
321 return rc;
322}
323
282/* 324/*
283 * Parse words[] as a ddebug query specification, which is a series 325 * Parse words[] as a ddebug query specification, which is a series
284 * of (keyword, value) pairs chosen from these possibilities: 326 * of (keyword, value) pairs chosen from these possibilities:
@@ -290,11 +332,15 @@ static char *unescape(char *str)
290 * format <escaped-string-to-find-in-format> 332 * format <escaped-string-to-find-in-format>
291 * line <lineno> 333 * line <lineno>
292 * line <first-lineno>-<last-lineno> // where either may be empty 334 * line <first-lineno>-<last-lineno> // where either may be empty
335 *
336 * Only 1 of each type is allowed.
337 * Returns 0 on success, <0 on error.
293 */ 338 */
294static int ddebug_parse_query(char *words[], int nwords, 339static int ddebug_parse_query(char *words[], int nwords,
295 struct ddebug_query *query) 340 struct ddebug_query *query)
296{ 341{
297 unsigned int i; 342 unsigned int i;
343 int rc;
298 344
299 /* check we have an even number of words */ 345 /* check we have an even number of words */
300 if (nwords % 2 != 0) 346 if (nwords % 2 != 0)
@@ -303,41 +349,43 @@ static int ddebug_parse_query(char *words[], int nwords,
303 349
304 for (i = 0 ; i < nwords ; i += 2) { 350 for (i = 0 ; i < nwords ; i += 2) {
305 if (!strcmp(words[i], "func")) 351 if (!strcmp(words[i], "func"))
306 query->function = words[i+1]; 352 rc = check_set(&query->function, words[i+1], "func");
307 else if (!strcmp(words[i], "file")) 353 else if (!strcmp(words[i], "file"))
308 query->filename = words[i+1]; 354 rc = check_set(&query->filename, words[i+1], "file");
309 else if (!strcmp(words[i], "module")) 355 else if (!strcmp(words[i], "module"))
310 query->module = words[i+1]; 356 rc = check_set(&query->module, words[i+1], "module");
311 else if (!strcmp(words[i], "format")) 357 else if (!strcmp(words[i], "format"))
312 query->format = unescape(words[i+1]); 358 rc = check_set(&query->format, unescape(words[i+1]),
359 "format");
313 else if (!strcmp(words[i], "line")) { 360 else if (!strcmp(words[i], "line")) {
314 char *first = words[i+1]; 361 char *first = words[i+1];
315 char *last = strchr(first, '-'); 362 char *last = strchr(first, '-');
363 if (query->first_lineno || query->last_lineno) {
364 pr_err("match-spec:line given 2 times\n");
365 return -EINVAL;
366 }
316 if (last) 367 if (last)
317 *last++ = '\0'; 368 *last++ = '\0';
318 if (parse_lineno(first, &query->first_lineno) < 0) 369 if (parse_lineno(first, &query->first_lineno) < 0)
319 return -EINVAL; 370 return -EINVAL;
320 if (last != NULL) { 371 if (last) {
321 /* range <first>-<last> */ 372 /* range <first>-<last> */
322 if (parse_lineno(last, &query->last_lineno) < 0) 373 if (parse_lineno(last, &query->last_lineno)
374 < query->first_lineno) {
375 pr_err("last-line < 1st-line\n");
323 return -EINVAL; 376 return -EINVAL;
377 }
324 } else { 378 } else {
325 query->last_lineno = query->first_lineno; 379 query->last_lineno = query->first_lineno;
326 } 380 }
327 } else { 381 } else {
328 if (verbose) 382 pr_err("unknown keyword \"%s\"\n", words[i]);
329 pr_err("unknown keyword \"%s\"\n", words[i]);
330 return -EINVAL; 383 return -EINVAL;
331 } 384 }
385 if (rc)
386 return rc;
332 } 387 }
333 388 vpr_info_dq(query, "parsed");
334 if (verbose)
335 pr_info("q->function=\"%s\" q->filename=\"%s\" "
336 "q->module=\"%s\" q->format=\"%s\" q->lineno=%u-%u\n",
337 query->function, query->filename,
338 query->module, query->format, query->first_lineno,
339 query->last_lineno);
340
341 return 0; 389 return 0;
342} 390}
343 391
@@ -375,8 +423,6 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
375 if (i < 0) 423 if (i < 0)
376 return -EINVAL; 424 return -EINVAL;
377 } 425 }
378 if (flags == 0)
379 return -EINVAL;
380 if (verbose) 426 if (verbose)
381 pr_info("flags=0x%x\n", flags); 427 pr_info("flags=0x%x\n", flags);
382 428
@@ -405,7 +451,7 @@ static int ddebug_exec_query(char *query_string)
405 unsigned int flags = 0, mask = 0; 451 unsigned int flags = 0, mask = 0;
406 struct ddebug_query query; 452 struct ddebug_query query;
407#define MAXWORDS 9 453#define MAXWORDS 9
408 int nwords; 454 int nwords, nfound;
409 char *words[MAXWORDS]; 455 char *words[MAXWORDS];
410 456
411 nwords = ddebug_tokenize(query_string, words, MAXWORDS); 457 nwords = ddebug_tokenize(query_string, words, MAXWORDS);
@@ -417,8 +463,47 @@ static int ddebug_exec_query(char *query_string)
417 return -EINVAL; 463 return -EINVAL;
418 464
419 /* actually go and implement the change */ 465 /* actually go and implement the change */
420 ddebug_change(&query, flags, mask); 466 nfound = ddebug_change(&query, flags, mask);
421 return 0; 467 vpr_info_dq((&query), (nfound) ? "applied" : "no-match");
468
469 return nfound;
470}
471
472/* handle multiple queries in query string, continue on error, return
473 last error or number of matching callsites. Module name is either
474 in param (for boot arg) or perhaps in query string.
475*/
476static int ddebug_exec_queries(char *query)
477{
478 char *split;
479 int i, errs = 0, exitcode = 0, rc, nfound = 0;
480
481 for (i = 0; query; query = split) {
482 split = strpbrk(query, ";\n");
483 if (split)
484 *split++ = '\0';
485
486 query = skip_spaces(query);
487 if (!query || !*query || *query == '#')
488 continue;
489
490 if (verbose)
491 pr_info("query %d: \"%s\"\n", i, query);
492
493 rc = ddebug_exec_query(query);
494 if (rc < 0) {
495 errs++;
496 exitcode = rc;
497 } else
498 nfound += rc;
499 i++;
500 }
501 pr_info("processed %d queries, with %d matches, %d errs\n",
502 i, nfound, errs);
503
504 if (exitcode)
505 return exitcode;
506 return nfound;
422} 507}
423 508
424#define PREFIX_SIZE 64 509#define PREFIX_SIZE 64
@@ -452,7 +537,8 @@ static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
452 pos += snprintf(buf + pos, remaining(pos), "%s:", 537 pos += snprintf(buf + pos, remaining(pos), "%s:",
453 desc->function); 538 desc->function);
454 if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO) 539 if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
455 pos += snprintf(buf + pos, remaining(pos), "%d:", desc->lineno); 540 pos += snprintf(buf + pos, remaining(pos), "%d:",
541 desc->lineno);
456 if (pos - pos_after_tid) 542 if (pos - pos_after_tid)
457 pos += snprintf(buf + pos, remaining(pos), " "); 543 pos += snprintf(buf + pos, remaining(pos), " ");
458 if (pos >= PREFIX_SIZE) 544 if (pos >= PREFIX_SIZE)
@@ -527,14 +613,16 @@ EXPORT_SYMBOL(__dynamic_netdev_dbg);
527 613
528#endif 614#endif
529 615
530static __initdata char ddebug_setup_string[1024]; 616#define DDEBUG_STRING_SIZE 1024
617static __initdata char ddebug_setup_string[DDEBUG_STRING_SIZE];
618
531static __init int ddebug_setup_query(char *str) 619static __init int ddebug_setup_query(char *str)
532{ 620{
533 if (strlen(str) >= 1024) { 621 if (strlen(str) >= DDEBUG_STRING_SIZE) {
534 pr_warn("ddebug boot param string too large\n"); 622 pr_warn("ddebug boot param string too large\n");
535 return 0; 623 return 0;
536 } 624 }
537 strcpy(ddebug_setup_string, str); 625 strlcpy(ddebug_setup_string, str, DDEBUG_STRING_SIZE);
538 return 1; 626 return 1;
539} 627}
540 628
@@ -544,25 +632,33 @@ __setup("ddebug_query=", ddebug_setup_query);
544 * File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the 632 * File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the
545 * command text from userspace, parses and executes it. 633 * command text from userspace, parses and executes it.
546 */ 634 */
635#define USER_BUF_PAGE 4096
547static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, 636static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
548 size_t len, loff_t *offp) 637 size_t len, loff_t *offp)
549{ 638{
550 char tmpbuf[256]; 639 char *tmpbuf;
551 int ret; 640 int ret;
552 641
553 if (len == 0) 642 if (len == 0)
554 return 0; 643 return 0;
555 /* we don't check *offp -- multiple writes() are allowed */ 644 if (len > USER_BUF_PAGE - 1) {
556 if (len > sizeof(tmpbuf)-1) 645 pr_warn("expected <%d bytes into control\n", USER_BUF_PAGE);
557 return -E2BIG; 646 return -E2BIG;
558 if (copy_from_user(tmpbuf, ubuf, len)) 647 }
648 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
649 if (!tmpbuf)
650 return -ENOMEM;
651 if (copy_from_user(tmpbuf, ubuf, len)) {
652 kfree(tmpbuf);
559 return -EFAULT; 653 return -EFAULT;
654 }
560 tmpbuf[len] = '\0'; 655 tmpbuf[len] = '\0';
561 if (verbose) 656 if (verbose)
562 pr_info("read %d bytes from userspace\n", (int)len); 657 pr_info("read %d bytes from userspace\n", (int)len);
563 658
564 ret = ddebug_exec_query(tmpbuf); 659 ret = ddebug_exec_queries(tmpbuf);
565 if (ret) 660 kfree(tmpbuf);
661 if (ret < 0)
566 return ret; 662 return ret;
567 663
568 *offp += len; 664 *offp += len;
@@ -668,7 +764,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
668{ 764{
669 struct ddebug_iter *iter = m->private; 765 struct ddebug_iter *iter = m->private;
670 struct _ddebug *dp = p; 766 struct _ddebug *dp = p;
671 char flagsbuf[8]; 767 char flagsbuf[10];
672 768
673 if (verbose) 769 if (verbose)
674 pr_info("called m=%p p=%p\n", m, p); 770 pr_info("called m=%p p=%p\n", m, p);
@@ -679,10 +775,10 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
679 return 0; 775 return 0;
680 } 776 }
681 777
682 seq_printf(m, "%s:%u [%s]%s %s \"", 778 seq_printf(m, "%s:%u [%s]%s =%s \"",
683 dp->filename, dp->lineno, 779 trim_prefix(dp->filename), dp->lineno,
684 iter->table->mod_name, dp->function, 780 iter->table->mod_name, dp->function,
685 ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf))); 781 ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf)));
686 seq_escape(m, dp->format, "\t\r\n\""); 782 seq_escape(m, dp->format, "\t\r\n\"");
687 seq_puts(m, "\"\n"); 783 seq_puts(m, "\"\n");
688 784
@@ -708,10 +804,11 @@ static const struct seq_operations ddebug_proc_seqops = {
708}; 804};
709 805
710/* 806/*
711 * File_ops->open method for <debugfs>/dynamic_debug/control. Does the seq_file 807 * File_ops->open method for <debugfs>/dynamic_debug/control. Does
712 * setup dance, and also creates an iterator to walk the _ddebugs. 808 * the seq_file setup dance, and also creates an iterator to walk the
713 * Note that we create a seq_file always, even for O_WRONLY files 809 * _ddebugs. Note that we create a seq_file always, even for O_WRONLY
714 * where it's not needed, as doing so simplifies the ->release method. 810 * files where it's not needed, as doing so simplifies the ->release
811 * method.
715 */ 812 */
716static int ddebug_proc_open(struct inode *inode, struct file *file) 813static int ddebug_proc_open(struct inode *inode, struct file *file)
717{ 814{
@@ -846,33 +943,40 @@ static int __init dynamic_debug_init(void)
846 int ret = 0; 943 int ret = 0;
847 int n = 0; 944 int n = 0;
848 945
849 if (__start___verbose != __stop___verbose) { 946 if (__start___verbose == __stop___verbose) {
850 iter = __start___verbose; 947 pr_warn("_ddebug table is empty in a "
851 modname = iter->modname; 948 "CONFIG_DYNAMIC_DEBUG build");
852 iter_start = iter; 949 return 1;
853 for (; iter < __stop___verbose; iter++) { 950 }
854 if (strcmp(modname, iter->modname)) { 951 iter = __start___verbose;
855 ret = ddebug_add_module(iter_start, n, modname); 952 modname = iter->modname;
856 if (ret) 953 iter_start = iter;
857 goto out_free; 954 for (; iter < __stop___verbose; iter++) {
858 n = 0; 955 if (strcmp(modname, iter->modname)) {
859 modname = iter->modname; 956 ret = ddebug_add_module(iter_start, n, modname);
860 iter_start = iter; 957 if (ret)
861 } 958 goto out_free;
862 n++; 959 n = 0;
960 modname = iter->modname;
961 iter_start = iter;
863 } 962 }
864 ret = ddebug_add_module(iter_start, n, modname); 963 n++;
865 } 964 }
965 ret = ddebug_add_module(iter_start, n, modname);
966 if (ret)
967 goto out_free;
866 968
867 /* ddebug_query boot param got passed -> set it up */ 969 /* ddebug_query boot param got passed -> set it up */
868 if (ddebug_setup_string[0] != '\0') { 970 if (ddebug_setup_string[0] != '\0') {
869 ret = ddebug_exec_query(ddebug_setup_string); 971 ret = ddebug_exec_queries(ddebug_setup_string);
870 if (ret) 972 if (ret < 0)
871 pr_warn("Invalid ddebug boot param %s", 973 pr_warn("Invalid ddebug boot param %s",
872 ddebug_setup_string); 974 ddebug_setup_string);
873 else 975 else
874 pr_info("ddebug initialized with string %s", 976 pr_info("%d changes by ddebug_query\n", ret);
875 ddebug_setup_string); 977
978 /* keep tables even on ddebug_query parse error */
979 ret = 0;
876 } 980 }
877 981
878out_free: 982out_free:
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index e66e9b632617..75cbdb52bf5c 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -29,16 +29,17 @@
29 29
30u64 uevent_seqnum; 30u64 uevent_seqnum;
31char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH; 31char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH;
32static DEFINE_SPINLOCK(sequence_lock);
33#ifdef CONFIG_NET 32#ifdef CONFIG_NET
34struct uevent_sock { 33struct uevent_sock {
35 struct list_head list; 34 struct list_head list;
36 struct sock *sk; 35 struct sock *sk;
37}; 36};
38static LIST_HEAD(uevent_sock_list); 37static LIST_HEAD(uevent_sock_list);
39static DEFINE_MUTEX(uevent_sock_mutex);
40#endif 38#endif
41 39
40/* This lock protects uevent_seqnum and uevent_sock_list */
41static DEFINE_MUTEX(uevent_sock_mutex);
42
42/* the strings here must match the enum in include/linux/kobject.h */ 43/* the strings here must match the enum in include/linux/kobject.h */
43static const char *kobject_actions[] = { 44static const char *kobject_actions[] = {
44 [KOBJ_ADD] = "add", 45 [KOBJ_ADD] = "add",
@@ -136,7 +137,6 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
136 struct kobject *top_kobj; 137 struct kobject *top_kobj;
137 struct kset *kset; 138 struct kset *kset;
138 const struct kset_uevent_ops *uevent_ops; 139 const struct kset_uevent_ops *uevent_ops;
139 u64 seq;
140 int i = 0; 140 int i = 0;
141 int retval = 0; 141 int retval = 0;
142#ifdef CONFIG_NET 142#ifdef CONFIG_NET
@@ -243,17 +243,16 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
243 else if (action == KOBJ_REMOVE) 243 else if (action == KOBJ_REMOVE)
244 kobj->state_remove_uevent_sent = 1; 244 kobj->state_remove_uevent_sent = 1;
245 245
246 mutex_lock(&uevent_sock_mutex);
246 /* we will send an event, so request a new sequence number */ 247 /* we will send an event, so request a new sequence number */
247 spin_lock(&sequence_lock); 248 retval = add_uevent_var(env, "SEQNUM=%llu", (unsigned long long)++uevent_seqnum);
248 seq = ++uevent_seqnum; 249 if (retval) {
249 spin_unlock(&sequence_lock); 250 mutex_unlock(&uevent_sock_mutex);
250 retval = add_uevent_var(env, "SEQNUM=%llu", (unsigned long long)seq);
251 if (retval)
252 goto exit; 251 goto exit;
252 }
253 253
254#if defined(CONFIG_NET) 254#if defined(CONFIG_NET)
255 /* send netlink message */ 255 /* send netlink message */
256 mutex_lock(&uevent_sock_mutex);
257 list_for_each_entry(ue_sk, &uevent_sock_list, list) { 256 list_for_each_entry(ue_sk, &uevent_sock_list, list) {
258 struct sock *uevent_sock = ue_sk->sk; 257 struct sock *uevent_sock = ue_sk->sk;
259 struct sk_buff *skb; 258 struct sk_buff *skb;
@@ -290,8 +289,8 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
290 } else 289 } else
291 retval = -ENOMEM; 290 retval = -ENOMEM;
292 } 291 }
293 mutex_unlock(&uevent_sock_mutex);
294#endif 292#endif
293 mutex_unlock(&uevent_sock_mutex);
295 294
296 /* call uevent_helper, usually only enabled during early boot */ 295 /* call uevent_helper, usually only enabled during early boot */
297 if (uevent_helper[0] && !kobj_usermode_filter(kobj)) { 296 if (uevent_helper[0] && !kobj_usermode_filter(kobj)) {
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index b89efe6e4c85..8e730ccc3f2b 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1029,6 +1029,31 @@ static int do_amba_entry(const char *filename,
1029} 1029}
1030ADD_TO_DEVTABLE("amba", struct amba_id, do_amba_entry); 1030ADD_TO_DEVTABLE("amba", struct amba_id, do_amba_entry);
1031 1031
1032/* LOOKS like x86cpu:vendor:VVVV:family:FFFF:model:MMMM:feature:*,FEAT,*
1033 * All fields are numbers. It would be nicer to use strings for vendor
1034 * and feature, but getting those out of the build system here is too
1035 * complicated.
1036 */
1037
1038static int do_x86cpu_entry(const char *filename, struct x86_cpu_id *id,
1039 char *alias)
1040{
1041 id->feature = TO_NATIVE(id->feature);
1042 id->family = TO_NATIVE(id->family);
1043 id->model = TO_NATIVE(id->model);
1044 id->vendor = TO_NATIVE(id->vendor);
1045
1046 strcpy(alias, "x86cpu:");
1047 ADD(alias, "vendor:", id->vendor != X86_VENDOR_ANY, id->vendor);
1048 ADD(alias, ":family:", id->family != X86_FAMILY_ANY, id->family);
1049 ADD(alias, ":model:", id->model != X86_MODEL_ANY, id->model);
1050 strcat(alias, ":feature:*");
1051 if (id->feature != X86_FEATURE_ANY)
1052 sprintf(alias + strlen(alias), "%04X*", id->feature);
1053 return 1;
1054}
1055ADD_TO_DEVTABLE("x86cpu", struct x86_cpu_id, do_x86cpu_entry);
1056
1032/* Does namelen bytes of name exactly match the symbol? */ 1057/* Does namelen bytes of name exactly match the symbol? */
1033static bool sym_is(const char *name, unsigned namelen, const char *symbol) 1058static bool sym_is(const char *name, unsigned namelen, const char *symbol)
1034{ 1059{
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 11224eddcdc2..146fd6147e84 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -34,21 +34,13 @@
34#include <errno.h> 34#include <errno.h>
35#include <arpa/inet.h> 35#include <arpa/inet.h>
36#include <linux/connector.h> 36#include <linux/connector.h>
37#include <linux/hyperv.h>
37#include <linux/netlink.h> 38#include <linux/netlink.h>
38#include <ifaddrs.h> 39#include <ifaddrs.h>
39#include <netdb.h> 40#include <netdb.h>
40#include <syslog.h> 41#include <syslog.h>
41 42#include <sys/stat.h>
42/* 43#include <fcntl.h>
43 * KYS: TODO. Need to register these in the kernel.
44 *
45 * The following definitions are shared with the in-kernel component; do not
46 * change any of this without making the corresponding changes in
47 * the KVP kernel component.
48 */
49#define CN_KVP_IDX 0x9 /* MSFT KVP functionality */
50#define CN_KVP_VAL 0x1 /* This supports queries from the kernel */
51#define CN_KVP_USER_VAL 0x2 /* This supports queries from the user */
52 44
53/* 45/*
54 * KVP protocol: The user mode component first registers with the 46 * KVP protocol: The user mode component first registers with the
@@ -60,25 +52,8 @@
60 * We use this infrastructure for also supporting queries from user mode 52 * We use this infrastructure for also supporting queries from user mode
61 * application for state that may be maintained in the KVP kernel component. 53 * application for state that may be maintained in the KVP kernel component.
62 * 54 *
63 * XXXKYS: Have a shared header file between the user and kernel (TODO)
64 */ 55 */
65 56
66enum kvp_op {
67 KVP_REGISTER = 0, /* Register the user mode component*/
68 KVP_KERNEL_GET, /*Kernel is requesting the value for the specified key*/
69 KVP_KERNEL_SET, /*Kernel is providing the value for the specified key*/
70 KVP_USER_GET, /*User is requesting the value for the specified key*/
71 KVP_USER_SET /*User is providing the value for the specified key*/
72};
73
74#define HV_KVP_EXCHANGE_MAX_KEY_SIZE 512
75#define HV_KVP_EXCHANGE_MAX_VALUE_SIZE 2048
76
77struct hv_ku_msg {
78 __u32 kvp_index;
79 __u8 kvp_key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; /* Key name */
80 __u8 kvp_value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; /* Key value */
81};
82 57
83enum key_index { 58enum key_index {
84 FullyQualifiedDomainName = 0, 59 FullyQualifiedDomainName = 0,
@@ -93,10 +68,6 @@ enum key_index {
93 ProcessorArchitecture 68 ProcessorArchitecture
94}; 69};
95 70
96/*
97 * End of shared definitions.
98 */
99
100static char kvp_send_buffer[4096]; 71static char kvp_send_buffer[4096];
101static char kvp_recv_buffer[4096]; 72static char kvp_recv_buffer[4096];
102static struct sockaddr_nl addr; 73static struct sockaddr_nl addr;
@@ -109,6 +80,345 @@ static char *os_build;
109static char *lic_version; 80static char *lic_version;
110static struct utsname uts_buf; 81static struct utsname uts_buf;
111 82
83
84#define MAX_FILE_NAME 100
85#define ENTRIES_PER_BLOCK 50
86
87struct kvp_record {
88 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
89 __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
90};
91
92struct kvp_file_state {
93 int fd;
94 int num_blocks;
95 struct kvp_record *records;
96 int num_records;
97 __u8 fname[MAX_FILE_NAME];
98};
99
100static struct kvp_file_state kvp_file_info[KVP_POOL_COUNT];
101
102static void kvp_acquire_lock(int pool)
103{
104 struct flock fl = {F_WRLCK, SEEK_SET, 0, 0, 0};
105 fl.l_pid = getpid();
106
107 if (fcntl(kvp_file_info[pool].fd, F_SETLKW, &fl) == -1) {
108 syslog(LOG_ERR, "Failed to acquire the lock pool: %d", pool);
109 exit(-1);
110 }
111}
112
113static void kvp_release_lock(int pool)
114{
115 struct flock fl = {F_UNLCK, SEEK_SET, 0, 0, 0};
116 fl.l_pid = getpid();
117
118 if (fcntl(kvp_file_info[pool].fd, F_SETLK, &fl) == -1) {
119 perror("fcntl");
120 syslog(LOG_ERR, "Failed to release the lock pool: %d", pool);
121 exit(-1);
122 }
123}
124
125static void kvp_update_file(int pool)
126{
127 FILE *filep;
128 size_t bytes_written;
129
130 /*
131 * We are going to write our in-memory registry out to
132 * disk; acquire the lock first.
133 */
134 kvp_acquire_lock(pool);
135
136 filep = fopen(kvp_file_info[pool].fname, "w");
137 if (!filep) {
138 kvp_release_lock(pool);
139 syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
140 exit(-1);
141 }
142
143 bytes_written = fwrite(kvp_file_info[pool].records,
144 sizeof(struct kvp_record),
145 kvp_file_info[pool].num_records, filep);
146
147 fflush(filep);
148 kvp_release_lock(pool);
149}
150
151static void kvp_update_mem_state(int pool)
152{
153 FILE *filep;
154 size_t records_read = 0;
155 struct kvp_record *record = kvp_file_info[pool].records;
156 struct kvp_record *readp;
157 int num_blocks = kvp_file_info[pool].num_blocks;
158 int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
159
160 kvp_acquire_lock(pool);
161
162 filep = fopen(kvp_file_info[pool].fname, "r");
163 if (!filep) {
164 kvp_release_lock(pool);
165 syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
166 exit(-1);
167 }
168 while (!feof(filep)) {
169 readp = &record[records_read];
170 records_read += fread(readp, sizeof(struct kvp_record),
171 ENTRIES_PER_BLOCK * num_blocks,
172 filep);
173
174 if (!feof(filep)) {
175 /*
176 * We have more data to read.
177 */
178 num_blocks++;
179 record = realloc(record, alloc_unit * num_blocks);
180
181 if (record == NULL) {
182 syslog(LOG_ERR, "malloc failed");
183 exit(-1);
184 }
185 continue;
186 }
187 break;
188 }
189
190 kvp_file_info[pool].num_blocks = num_blocks;
191 kvp_file_info[pool].records = record;
192 kvp_file_info[pool].num_records = records_read;
193
194 kvp_release_lock(pool);
195}
196static int kvp_file_init(void)
197{
198 int ret, fd;
199 FILE *filep;
200 size_t records_read;
201 __u8 *fname;
202 struct kvp_record *record;
203 struct kvp_record *readp;
204 int num_blocks;
205 int i;
206 int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
207
208 if (access("/var/opt/hyperv", F_OK)) {
209 if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
210 syslog(LOG_ERR, " Failed to create /var/opt/hyperv");
211 exit(-1);
212 }
213 }
214
215 for (i = 0; i < KVP_POOL_COUNT; i++) {
216 fname = kvp_file_info[i].fname;
217 records_read = 0;
218 num_blocks = 1;
219 sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
220 fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
221
222 if (fd == -1)
223 return 1;
224
225
226 filep = fopen(fname, "r");
227 if (!filep)
228 return 1;
229
230 record = malloc(alloc_unit * num_blocks);
231 if (record == NULL) {
232 fclose(filep);
233 return 1;
234 }
235 while (!feof(filep)) {
236 readp = &record[records_read];
237 records_read += fread(readp, sizeof(struct kvp_record),
238 ENTRIES_PER_BLOCK,
239 filep);
240
241 if (!feof(filep)) {
242 /*
243 * We have more data to read.
244 */
245 num_blocks++;
246 record = realloc(record, alloc_unit *
247 num_blocks);
248 if (record == NULL) {
249 fclose(filep);
250 return 1;
251 }
252 continue;
253 }
254 break;
255 }
256 kvp_file_info[i].fd = fd;
257 kvp_file_info[i].num_blocks = num_blocks;
258 kvp_file_info[i].records = record;
259 kvp_file_info[i].num_records = records_read;
260 fclose(filep);
261
262 }
263
264 return 0;
265}
266
267static int kvp_key_delete(int pool, __u8 *key, int key_size)
268{
269 int i;
270 int j, k;
271 int num_records;
272 struct kvp_record *record;
273
274 /*
275 * First update the in-memory state.
276 */
277 kvp_update_mem_state(pool);
278
279 num_records = kvp_file_info[pool].num_records;
280 record = kvp_file_info[pool].records;
281
282 for (i = 0; i < num_records; i++) {
283 if (memcmp(key, record[i].key, key_size))
284 continue;
285 /*
286 * Found a match; just move the remaining
287 * entries up.
288 */
289 if (i == num_records) {
290 kvp_file_info[pool].num_records--;
291 kvp_update_file(pool);
292 return 0;
293 }
294
295 j = i;
296 k = j + 1;
297 for (; k < num_records; k++) {
298 strcpy(record[j].key, record[k].key);
299 strcpy(record[j].value, record[k].value);
300 j++;
301 }
302
303 kvp_file_info[pool].num_records--;
304 kvp_update_file(pool);
305 return 0;
306 }
307 return 1;
308}
309
310static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value,
311 int value_size)
312{
313 int i;
314 int j, k;
315 int num_records;
316 struct kvp_record *record;
317 int num_blocks;
318
319 if ((key_size > HV_KVP_EXCHANGE_MAX_KEY_SIZE) ||
320 (value_size > HV_KVP_EXCHANGE_MAX_VALUE_SIZE))
321 return 1;
322
323 /*
324 * First update the in-memory state.
325 */
326 kvp_update_mem_state(pool);
327
328 num_records = kvp_file_info[pool].num_records;
329 record = kvp_file_info[pool].records;
330 num_blocks = kvp_file_info[pool].num_blocks;
331
332 for (i = 0; i < num_records; i++) {
333 if (memcmp(key, record[i].key, key_size))
334 continue;
335 /*
336 * Found a match; just update the value -
337 * this is the modify case.
338 */
339 memcpy(record[i].value, value, value_size);
340 kvp_update_file(pool);
341 return 0;
342 }
343
344 /*
345 * Need to add a new entry;
346 */
347 if (num_records == (ENTRIES_PER_BLOCK * num_blocks)) {
348 /* Need to allocate a larger array for reg entries. */
349 record = realloc(record, sizeof(struct kvp_record) *
350 ENTRIES_PER_BLOCK * (num_blocks + 1));
351
352 if (record == NULL)
353 return 1;
354 kvp_file_info[pool].num_blocks++;
355
356 }
357 memcpy(record[i].value, value, value_size);
358 memcpy(record[i].key, key, key_size);
359 kvp_file_info[pool].records = record;
360 kvp_file_info[pool].num_records++;
361 kvp_update_file(pool);
362 return 0;
363}
364
365static int kvp_get_value(int pool, __u8 *key, int key_size, __u8 *value,
366 int value_size)
367{
368 int i;
369 int num_records;
370 struct kvp_record *record;
371
372 if ((key_size > HV_KVP_EXCHANGE_MAX_KEY_SIZE) ||
373 (value_size > HV_KVP_EXCHANGE_MAX_VALUE_SIZE))
374 return 1;
375
376 /*
377 * First update the in-memory state.
378 */
379 kvp_update_mem_state(pool);
380
381 num_records = kvp_file_info[pool].num_records;
382 record = kvp_file_info[pool].records;
383
384 for (i = 0; i < num_records; i++) {
385 if (memcmp(key, record[i].key, key_size))
386 continue;
387 /*
388 * Found a match; just copy the value out.
389 */
390 memcpy(value, record[i].value, value_size);
391 return 0;
392 }
393
394 return 1;
395}
396
397static void kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size,
398 __u8 *value, int value_size)
399{
400 struct kvp_record *record;
401
402 /*
403 * First update our in-memory database.
404 */
405 kvp_update_mem_state(pool);
406 record = kvp_file_info[pool].records;
407
408 if (index >= kvp_file_info[pool].num_records) {
409 /*
410 * This is an invalid index; terminate enumeration;
411 * - a NULL value will do the trick.
412 */
413 strcpy(value, "");
414 return;
415 }
416
417 memcpy(key, record[index].key, key_size);
418 memcpy(value, record[index].value, value_size);
419}
420
421
112void kvp_get_os_info(void) 422void kvp_get_os_info(void)
113{ 423{
114 FILE *file; 424 FILE *file;
@@ -332,7 +642,7 @@ int main(void)
332 struct pollfd pfd; 642 struct pollfd pfd;
333 struct nlmsghdr *incoming_msg; 643 struct nlmsghdr *incoming_msg;
334 struct cn_msg *incoming_cn_msg; 644 struct cn_msg *incoming_cn_msg;
335 struct hv_ku_msg *hv_msg; 645 struct hv_kvp_msg *hv_msg;
336 char *p; 646 char *p;
337 char *key_value; 647 char *key_value;
338 char *key_name; 648 char *key_name;
@@ -345,6 +655,11 @@ int main(void)
345 */ 655 */
346 kvp_get_os_info(); 656 kvp_get_os_info();
347 657
658 if (kvp_file_init()) {
659 syslog(LOG_ERR, "Failed to initialize the pools");
660 exit(-1);
661 }
662
348 fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); 663 fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
349 if (fd < 0) { 664 if (fd < 0) {
350 syslog(LOG_ERR, "netlink socket creation failed; error:%d", fd); 665 syslog(LOG_ERR, "netlink socket creation failed; error:%d", fd);
@@ -370,9 +685,11 @@ int main(void)
370 message = (struct cn_msg *)kvp_send_buffer; 685 message = (struct cn_msg *)kvp_send_buffer;
371 message->id.idx = CN_KVP_IDX; 686 message->id.idx = CN_KVP_IDX;
372 message->id.val = CN_KVP_VAL; 687 message->id.val = CN_KVP_VAL;
373 message->seq = KVP_REGISTER; 688
689 hv_msg = (struct hv_kvp_msg *)message->data;
690 hv_msg->kvp_hdr.operation = KVP_OP_REGISTER;
374 message->ack = 0; 691 message->ack = 0;
375 message->len = 0; 692 message->len = sizeof(struct hv_kvp_msg);
376 693
377 len = netlink_send(fd, message); 694 len = netlink_send(fd, message);
378 if (len < 0) { 695 if (len < 0) {
@@ -398,14 +715,15 @@ int main(void)
398 715
399 incoming_msg = (struct nlmsghdr *)kvp_recv_buffer; 716 incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
400 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg); 717 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
718 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data;
401 719
402 switch (incoming_cn_msg->seq) { 720 switch (hv_msg->kvp_hdr.operation) {
403 case KVP_REGISTER: 721 case KVP_OP_REGISTER:
404 /* 722 /*
405 * Driver is registering with us; stash away the version 723 * Driver is registering with us; stash away the version
406 * information. 724 * information.
407 */ 725 */
408 p = (char *)incoming_cn_msg->data; 726 p = (char *)hv_msg->body.kvp_register.version;
409 lic_version = malloc(strlen(p) + 1); 727 lic_version = malloc(strlen(p) + 1);
410 if (lic_version) { 728 if (lic_version) {
411 strcpy(lic_version, p); 729 strcpy(lic_version, p);
@@ -416,17 +734,65 @@ int main(void)
416 } 734 }
417 continue; 735 continue;
418 736
419 case KVP_KERNEL_GET: 737 /*
738 * The current protocol with the kernel component uses a
739 * NULL key name to pass an error condition.
740 * For the SET, GET and DELETE operations,
741 * use the existing protocol to pass back error.
742 */
743
744 case KVP_OP_SET:
745 if (kvp_key_add_or_modify(hv_msg->kvp_hdr.pool,
746 hv_msg->body.kvp_set.data.key,
747 hv_msg->body.kvp_set.data.key_size,
748 hv_msg->body.kvp_set.data.value,
749 hv_msg->body.kvp_set.data.value_size))
750 strcpy(hv_msg->body.kvp_set.data.key, "");
751 break;
752
753 case KVP_OP_GET:
754 if (kvp_get_value(hv_msg->kvp_hdr.pool,
755 hv_msg->body.kvp_set.data.key,
756 hv_msg->body.kvp_set.data.key_size,
757 hv_msg->body.kvp_set.data.value,
758 hv_msg->body.kvp_set.data.value_size))
759 strcpy(hv_msg->body.kvp_set.data.key, "");
760 break;
761
762 case KVP_OP_DELETE:
763 if (kvp_key_delete(hv_msg->kvp_hdr.pool,
764 hv_msg->body.kvp_delete.key,
765 hv_msg->body.kvp_delete.key_size))
766 strcpy(hv_msg->body.kvp_delete.key, "");
420 break; 767 break;
768
421 default: 769 default:
422 continue; 770 break;
771 }
772
773 if (hv_msg->kvp_hdr.operation != KVP_OP_ENUMERATE)
774 goto kvp_done;
775
776 /*
777 * If the pool is KVP_POOL_AUTO, dynamically generate
778 * both the key and the value; if not read from the
779 * appropriate pool.
780 */
781 if (hv_msg->kvp_hdr.pool != KVP_POOL_AUTO) {
782 kvp_pool_enumerate(hv_msg->kvp_hdr.pool,
783 hv_msg->body.kvp_enum_data.index,
784 hv_msg->body.kvp_enum_data.data.key,
785 HV_KVP_EXCHANGE_MAX_KEY_SIZE,
786 hv_msg->body.kvp_enum_data.data.value,
787 HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
788 goto kvp_done;
423 } 789 }
424 790
425 hv_msg = (struct hv_ku_msg *)incoming_cn_msg->data; 791 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data;
426 key_name = (char *)hv_msg->kvp_key; 792 key_name = (char *)hv_msg->body.kvp_enum_data.data.key;
427 key_value = (char *)hv_msg->kvp_value; 793 key_value = (char *)hv_msg->body.kvp_enum_data.data.value;
428 794
429 switch (hv_msg->kvp_index) { 795 switch (hv_msg->body.kvp_enum_data.index) {
430 case FullyQualifiedDomainName: 796 case FullyQualifiedDomainName:
431 kvp_get_domain_name(key_value, 797 kvp_get_domain_name(key_value,
432 HV_KVP_EXCHANGE_MAX_VALUE_SIZE); 798 HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
@@ -483,12 +849,12 @@ int main(void)
483 * already in the receive buffer. Update the cn_msg header to 849 * already in the receive buffer. Update the cn_msg header to
484 * reflect the key value that has been added to the message 850 * reflect the key value that has been added to the message
485 */ 851 */
852kvp_done:
486 853
487 incoming_cn_msg->id.idx = CN_KVP_IDX; 854 incoming_cn_msg->id.idx = CN_KVP_IDX;
488 incoming_cn_msg->id.val = CN_KVP_VAL; 855 incoming_cn_msg->id.val = CN_KVP_VAL;
489 incoming_cn_msg->seq = KVP_USER_SET;
490 incoming_cn_msg->ack = 0; 856 incoming_cn_msg->ack = 0;
491 incoming_cn_msg->len = sizeof(struct hv_ku_msg); 857 incoming_cn_msg->len = sizeof(struct hv_kvp_msg);
492 858
493 len = netlink_send(fd, incoming_cn_msg); 859 len = netlink_send(fd, incoming_cn_msg);
494 if (len < 0) { 860 if (len < 0) {