aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2012-03-16 15:15:48 -0400
committerArnd Bergmann <arnd@arndb.de>2012-03-16 15:15:48 -0400
commitab2f75ce55ef6f903348026271e30796f016851f (patch)
tree8e019d460e92ee6ac2b2ea54aa0b93770bf933ef
parentf56b71f5d5a3944acdcb0e5e1739574d95ddf61a (diff)
parentda5a70f3519fd6f73ece3eea261a861c9a4d6bbd (diff)
Merge branch 'depends/driver-core' into ux500/dt
Conflicts: drivers/base/cpu.c
-rw-r--r--Documentation/ABI/testing/sysfs-devices-soc58
-rw-r--r--Documentation/dynamic-debug-howto.txt30
-rw-r--r--Documentation/filesystems/debugfs.txt5
-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.c92
-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/bus.c6
-rw-r--r--drivers/base/cpu.c11
-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.c43
-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.c116
-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/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--fs/debugfs/inode.c149
-rw-r--r--fs/sysfs/dir.c228
-rw-r--r--fs/sysfs/inode.c3
-rw-r--r--fs/sysfs/mount.c2
-rw-r--r--fs/sysfs/sysfs.h18
-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/hyperv.h146
-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--scripts/mod/file2alias.c24
-rw-r--r--tools/hv/hv_kvp_daemon.c62
85 files changed, 1543 insertions, 915 deletions
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/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/arch/x86/Kconfig b/arch/x86/Kconfig
index 5bed94e189fa..6339aa496c4f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -179,6 +179,9 @@ config ARCH_HAS_DEFAULT_IDLE
179config ARCH_HAS_CACHE_LINE_SIZE 179config ARCH_HAS_CACHE_LINE_SIZE
180 def_bool y 180 def_bool y
181 181
182config ARCH_HAS_CPU_AUTOPROBE
183 def_bool y
184
182config HAVE_SETUP_PER_CPU_AREA 185config HAVE_SETUP_PER_CPU_AREA
183 def_bool y 186 def_bool y
184 187
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..940e2d483076
--- /dev/null
+++ b/arch/x86/kernel/cpu/match.c
@@ -0,0 +1,92 @@
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 -= 2;
67 for (i = 0; i < NCAPINTS*32; i++) {
68 if (boot_cpu_has(i)) {
69 n = snprintf(buf, size, ",%04X", i);
70 if (n < 0) {
71 WARN(1, "x86 features overflow page\n");
72 break;
73 }
74 size -= n;
75 buf += n;
76 }
77 }
78 *buf++ = ',';
79 *buf++ = '\n';
80 return buf - bufptr;
81}
82
83int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env)
84{
85 char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
86 if (buf) {
87 arch_print_cpu_modalias(NULL, NULL, buf);
88 add_uevent_var(env, "MODALIAS=%s", buf);
89 kfree(buf);
90 }
91 return 0;
92}
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/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/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/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..54dd031394f6 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};
219
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..501d167368d2 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, 7, },
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..0ef4c1f6ca54 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/*
@@ -73,15 +71,20 @@ kvp_register(void)
73{ 71{
74 72
75 struct cn_msg *msg; 73 struct cn_msg *msg;
74 struct hv_kvp_msg *kvp_msg;
75 char *version;
76 76
77 msg = kzalloc(sizeof(*msg) + strlen(HV_DRV_VERSION) + 1 , GFP_ATOMIC); 77 msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg), GFP_ATOMIC);
78 78
79 if (msg) { 79 if (msg) {
80 kvp_msg = (struct hv_kvp_msg *)msg->data;
81 version = kvp_msg->body.kvp_version;
80 msg->id.idx = CN_KVP_IDX; 82 msg->id.idx = CN_KVP_IDX;
81 msg->id.val = CN_KVP_VAL; 83 msg->id.val = CN_KVP_VAL;
82 msg->seq = KVP_REGISTER; 84
83 strcpy(msg->data, HV_DRV_VERSION); 85 kvp_msg->kvp_hdr.operation = KVP_OP_REGISTER;
84 msg->len = strlen(HV_DRV_VERSION) + 1; 86 strcpy(version, HV_DRV_VERSION);
87 msg->len = sizeof(struct hv_kvp_msg);
85 cn_netlink_send(msg, 0, GFP_ATOMIC); 88 cn_netlink_send(msg, 0, GFP_ATOMIC);
86 kfree(msg); 89 kfree(msg);
87 } 90 }
@@ -103,23 +106,24 @@ kvp_work_func(struct work_struct *dummy)
103static void 106static void
104kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) 107kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
105{ 108{
106 struct hv_ku_msg *message; 109 struct hv_kvp_msg *message;
110 struct hv_kvp_msg_enumerate *data;
107 111
108 message = (struct hv_ku_msg *)msg->data; 112 message = (struct hv_kvp_msg *)msg->data;
109 if (msg->seq == KVP_REGISTER) { 113 if (message->kvp_hdr.operation == KVP_OP_REGISTER) {
110 pr_info("KVP: user-mode registering done.\n"); 114 pr_info("KVP: user-mode registering done.\n");
111 kvp_register(); 115 kvp_register();
112 } 116 }
113 117
114 if (msg->seq == KVP_USER_SET) { 118 if (message->kvp_hdr.operation == KVP_OP_ENUMERATE) {
119 data = &message->body.kvp_enum_data;
115 /* 120 /*
116 * Complete the transaction by forwarding the key value 121 * Complete the transaction by forwarding the key value
117 * to the host. But first, cancel the timeout. 122 * to the host. But first, cancel the timeout.
118 */ 123 */
119 if (cancel_delayed_work_sync(&kvp_work)) 124 if (cancel_delayed_work_sync(&kvp_work))
120 kvp_respond_to_host(message->kvp_key, 125 kvp_respond_to_host(data->data.key, data->data.value,
121 message->kvp_value, 126 !strlen(data->data.key));
122 !strlen(message->kvp_key));
123 } 127 }
124} 128}
125 129
@@ -127,6 +131,7 @@ static void
127kvp_send_key(struct work_struct *dummy) 131kvp_send_key(struct work_struct *dummy)
128{ 132{
129 struct cn_msg *msg; 133 struct cn_msg *msg;
134 struct hv_kvp_msg *message;
130 int index = kvp_transaction.index; 135 int index = kvp_transaction.index;
131 136
132 msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg) , GFP_ATOMIC); 137 msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg) , GFP_ATOMIC);
@@ -134,9 +139,11 @@ kvp_send_key(struct work_struct *dummy)
134 if (msg) { 139 if (msg) {
135 msg->id.idx = CN_KVP_IDX; 140 msg->id.idx = CN_KVP_IDX;
136 msg->id.val = CN_KVP_VAL; 141 msg->id.val = CN_KVP_VAL;
137 msg->seq = KVP_KERNEL_GET; 142
138 ((struct hv_ku_msg *)msg->data)->kvp_index = index; 143 message = (struct hv_kvp_msg *)msg->data;
139 msg->len = sizeof(struct hv_ku_msg); 144 message->kvp_hdr.operation = KVP_OP_ENUMERATE;
145 message->body.kvp_enum_data.index = index;
146 msg->len = sizeof(struct hv_kvp_msg);
140 cn_netlink_send(msg, 0, GFP_ATOMIC); 147 cn_netlink_send(msg, 0, GFP_ATOMIC);
141 kfree(msg); 148 kfree(msg);
142 } 149 }
@@ -193,7 +200,7 @@ kvp_respond_to_host(char *key, char *value, int error)
193 kvp_msg = (struct hv_kvp_msg *) 200 kvp_msg = (struct hv_kvp_msg *)
194 &recv_buffer[sizeof(struct vmbuspipe_hdr) + 201 &recv_buffer[sizeof(struct vmbuspipe_hdr) +
195 sizeof(struct icmsg_hdr)]; 202 sizeof(struct icmsg_hdr)];
196 kvp_data = &kvp_msg->kvp_data; 203 kvp_data = &kvp_msg->body.kvp_enum_data;
197 key_name = key; 204 key_name = key;
198 205
199 /* 206 /*
@@ -268,7 +275,7 @@ void hv_kvp_onchannelcallback(void *context)
268 sizeof(struct vmbuspipe_hdr) + 275 sizeof(struct vmbuspipe_hdr) +
269 sizeof(struct icmsg_hdr)]; 276 sizeof(struct icmsg_hdr)];
270 277
271 kvp_data = &kvp_msg->kvp_data; 278 kvp_data = &kvp_msg->body.kvp_enum_data;
272 279
273 /* 280 /*
274 * We only support the "get" operation on 281 * We only support the "get" operation on
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..237fe5785f01 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,72 @@ 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};
335
336static const struct idle_cpu idle_cpu_westmere = {
337 .state_table = nehalem_cstates,
338 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
339};
340
341static const struct idle_cpu idle_cpu_atom = {
342 .state_table = atom_cstates,
343};
344
345static const struct idle_cpu idle_cpu_lincroft = {
346 .state_table = atom_cstates,
347 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
348};
349
350static const struct idle_cpu idle_cpu_snb = {
351 .state_table = snb_cstates,
352};
353
354#define ICPU(model, cpu) \
355 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&cpu }
356
357static const struct x86_cpu_id intel_idle_ids[] = {
358 ICPU(0x1a, idle_cpu_nehalem),
359 ICPU(0x1e, idle_cpu_nehalem),
360 ICPU(0x1f, idle_cpu_nehalem),
361 ICPU(0x25, idle_cpu_westmere),
362 ICPU(0x2c, idle_cpu_westmere),
363 ICPU(0x2f, idle_cpu_westmere),
364 ICPU(0x1c, idle_cpu_atom),
365 ICPU(0x26, idle_cpu_lincroft),
366 ICPU(0x2f, idle_cpu_westmere),
367 ICPU(0x2a, idle_cpu_snb),
368 ICPU(0x2d, idle_cpu_snb),
369 {}
370};
371MODULE_DEVICE_TABLE(x86cpu, intel_idle_ids);
372
326/* 373/*
327 * intel_idle_probe() 374 * intel_idle_probe()
328 */ 375 */
329static int intel_idle_probe(void) 376static int intel_idle_probe(void)
330{ 377{
331 unsigned int eax, ebx, ecx; 378 unsigned int eax, ebx, ecx;
379 const struct x86_cpu_id *id;
332 380
333 if (max_cstate == 0) { 381 if (max_cstate == 0) {
334 pr_debug(PREFIX "disabled\n"); 382 pr_debug(PREFIX "disabled\n");
335 return -EPERM; 383 return -EPERM;
336 } 384 }
337 385
338 if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) 386 id = x86_match_cpu(intel_idle_ids);
339 return -ENODEV; 387 if (!id) {
340 388 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
341 if (!boot_cpu_has(X86_FEATURE_MWAIT)) 389 boot_cpu_data.x86 == 6)
390 pr_debug(PREFIX "does not run on family %d model %d\n",
391 boot_cpu_data.x86, boot_cpu_data.x86_model);
342 return -ENODEV; 392 return -ENODEV;
393 }
343 394
344 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF) 395 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
345 return -ENODEV; 396 return -ENODEV;
@@ -353,43 +404,8 @@ static int intel_idle_probe(void)
353 404
354 pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates); 405 pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
355 406
356 407 icpu = (const struct idle_cpu *)id->driver_data;
357 if (boot_cpu_data.x86 != 6) /* family 6 */ 408 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 409
394 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */ 410 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
395 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE; 411 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
@@ -470,7 +486,7 @@ static int intel_idle_cpuidle_driver_init(void)
470 drv->state_count += 1; 486 drv->state_count += 1;
471 } 487 }
472 488
473 if (auto_demotion_disable_flags) 489 if (icpu->auto_demotion_disable_flags)
474 on_each_cpu(auto_demotion_disable, NULL, 1); 490 on_each_cpu(auto_demotion_disable, NULL, 1);
475 491
476 return 0; 492 return 0;
@@ -522,7 +538,7 @@ int intel_idle_cpu_init(int cpu)
522 return -EIO; 538 return -EIO;
523 } 539 }
524 540
525 if (auto_demotion_disable_flags) 541 if (icpu->auto_demotion_disable_flags)
526 smp_call_function_single(cpu, auto_demotion_disable, NULL, 1); 542 smp_call_function_single(cpu, auto_demotion_disable, NULL, 1);
527 543
528 return 0; 544 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/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/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..dd3779cf3a3b 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -22,76 +22,100 @@
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; 93
48 struct rb_node *parent; 94 while (*node) {
49 95 struct sysfs_dirent *pos;
50 if (sysfs_type(sd) == SYSFS_DIR) 96 int result;
51 parent_sd->s_dir.subdirs++; 97
52 98 pos = to_sysfs_dirent(*node);
53 p = &parent_sd->s_dir.inode_tree.rb_node; 99 parent = *node;
54 parent = NULL; 100 result = sysfs_sd_compare(sd, pos);
55 while (*p) { 101 if (result < 0)
56 parent = *p; 102 node = &pos->s_rb.rb_left;
57#define node rb_entry(parent, struct sysfs_dirent, inode_node) 103 else if (result > 0)
58 if (sd->s_ino < node->s_ino) { 104 node = &pos->s_rb.rb_right;
59 p = &node->inode_node.rb_left; 105 else
60 } else if (sd->s_ino > node->s_ino) { 106 return -EEXIST;
61 p = &node->inode_node.rb_right;
62 } else {
63 printk(KERN_CRIT "sysfs: inserting duplicate inode '%lx'\n",
64 (unsigned long) sd->s_ino);
65 BUG();
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 } 107 }
86 rb_link_node(&sd->name_node, parent, p); 108 /* add new node and rebalance the tree */
87 rb_insert_color(&sd->name_node, &parent_sd->s_dir.name_tree); 109 rb_link_node(&sd->s_rb, parent, node);
110 rb_insert_color(&sd->s_rb, &sd->s_parent->s_dir.children);
111 return 0;
88} 112}
89 113
90/** 114/**
91 * sysfs_unlink_sibling - unlink sysfs_dirent from sibling list 115 * sysfs_unlink_sibling - unlink sysfs_dirent from sibling rbtree
92 * @sd: sysfs_dirent of interest 116 * @sd: sysfs_dirent of interest
93 * 117 *
94 * Unlink @sd from its sibling list which starts from 118 * Unlink @sd from its sibling rbtree which starts from
95 * sd->s_parent->s_dir.children. 119 * sd->s_parent->s_dir.children.
96 * 120 *
97 * Locking: 121 * Locking:
@@ -99,11 +123,7 @@ static void sysfs_link_sibling(struct sysfs_dirent *sd)
99 */ 123 */
100static void sysfs_unlink_sibling(struct sysfs_dirent *sd) 124static void sysfs_unlink_sibling(struct sysfs_dirent *sd)
101{ 125{
102 if (sysfs_type(sd) == SYSFS_DIR) 126 rb_erase(&sd->s_rb, &sd->s_parent->s_dir.children);
103 sd->s_parent->s_dir.subdirs--;
104
105 rb_erase(&sd->inode_node, &sd->s_parent->s_dir.inode_tree);
106 rb_erase(&sd->name_node, &sd->s_parent->s_dir.name_tree);
107} 127}
108 128
109/** 129/**
@@ -198,7 +218,7 @@ static void sysfs_deactivate(struct sysfs_dirent *sd)
198 rwsem_release(&sd->dep_map, 1, _RET_IP_); 218 rwsem_release(&sd->dep_map, 1, _RET_IP_);
199} 219}
200 220
201static int sysfs_alloc_ino(ino_t *pino) 221static int sysfs_alloc_ino(unsigned int *pino)
202{ 222{
203 int ino, rc; 223 int ino, rc;
204 224
@@ -217,7 +237,7 @@ static int sysfs_alloc_ino(ino_t *pino)
217 return rc; 237 return rc;
218} 238}
219 239
220static void sysfs_free_ino(ino_t ino) 240static void sysfs_free_ino(unsigned int ino)
221{ 241{
222 spin_lock(&sysfs_ino_lock); 242 spin_lock(&sysfs_ino_lock);
223 ida_remove(&sysfs_ino_ida, ino); 243 ida_remove(&sysfs_ino_ida, ino);
@@ -402,6 +422,7 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
402int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) 422int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
403{ 423{
404 struct sysfs_inode_attrs *ps_iattr; 424 struct sysfs_inode_attrs *ps_iattr;
425 int ret;
405 426
406 if (!!sysfs_ns_type(acxt->parent_sd) != !!sd->s_ns) { 427 if (!!sysfs_ns_type(acxt->parent_sd) != !!sd->s_ns) {
407 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", 428 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
@@ -410,12 +431,12 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
410 return -EINVAL; 431 return -EINVAL;
411 } 432 }
412 433
413 if (sysfs_find_dirent(acxt->parent_sd, sd->s_ns, sd->s_name)) 434 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); 435 sd->s_parent = sysfs_get(acxt->parent_sd);
417 436
418 sysfs_link_sibling(sd); 437 ret = sysfs_link_sibling(sd);
438 if (ret)
439 return ret;
419 440
420 /* Update timestamps on the parent */ 441 /* Update timestamps on the parent */
421 ps_iattr = acxt->parent_sd->s_iattr; 442 ps_iattr = acxt->parent_sd->s_iattr;
@@ -565,8 +586,8 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
565 const void *ns, 586 const void *ns,
566 const unsigned char *name) 587 const unsigned char *name)
567{ 588{
568 struct rb_node *p = parent_sd->s_dir.name_tree.rb_node; 589 struct rb_node *node = parent_sd->s_dir.children.rb_node;
569 struct sysfs_dirent *found = NULL; 590 unsigned int hash;
570 591
571 if (!!sysfs_ns_type(parent_sd) != !!ns) { 592 if (!!sysfs_ns_type(parent_sd) != !!ns) {
572 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", 593 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
@@ -575,33 +596,21 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
575 return NULL; 596 return NULL;
576 } 597 }
577 598
578 while (p) { 599 hash = sysfs_name_hash(ns, name);
579 int c; 600 while (node) {
580#define node rb_entry(p, struct sysfs_dirent, name_node) 601 struct sysfs_dirent *sd;
581 c = strcmp(name, node->s_name); 602 int result;
582 if (c < 0) { 603
583 p = node->name_node.rb_left; 604 sd = to_sysfs_dirent(node);
584 } else if (c > 0) { 605 result = sysfs_name_compare(hash, ns, name, sd);
585 p = node->name_node.rb_right; 606 if (result < 0)
586 } else { 607 node = node->rb_left;
587 found = node; 608 else if (result > 0)
588 p = node->name_node.rb_left; 609 node = node->rb_right;
589 } 610 else
590#undef node 611 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 } 612 }
603 613 return NULL;
604 return found;
605} 614}
606 615
607/** 616/**
@@ -804,9 +813,9 @@ static void __sysfs_remove_dir(struct sysfs_dirent *dir_sd)
804 813
805 pr_debug("sysfs %s: removing dir\n", dir_sd->s_name); 814 pr_debug("sysfs %s: removing dir\n", dir_sd->s_name);
806 sysfs_addrm_start(&acxt, dir_sd); 815 sysfs_addrm_start(&acxt, dir_sd);
807 pos = rb_first(&dir_sd->s_dir.inode_tree); 816 pos = rb_first(&dir_sd->s_dir.children);
808 while (pos) { 817 while (pos) {
809 struct sysfs_dirent *sd = rb_entry(pos, struct sysfs_dirent, inode_node); 818 struct sysfs_dirent *sd = to_sysfs_dirent(pos);
810 pos = rb_next(pos); 819 pos = rb_next(pos);
811 if (sysfs_type(sd) != SYSFS_DIR) 820 if (sysfs_type(sd) != SYSFS_DIR)
812 sysfs_remove_one(&acxt, sd); 821 sysfs_remove_one(&acxt, sd);
@@ -863,6 +872,7 @@ int sysfs_rename(struct sysfs_dirent *sd,
863 872
864 dup_name = sd->s_name; 873 dup_name = sd->s_name;
865 sd->s_name = new_name; 874 sd->s_name = new_name;
875 sd->s_hash = sysfs_name_hash(sd->s_ns, sd->s_name);
866 } 876 }
867 877
868 /* Move to the appropriate place in the appropriate directories rbtree. */ 878 /* Move to the appropriate place in the appropriate directories rbtree. */
@@ -919,38 +929,36 @@ static int sysfs_dir_release(struct inode *inode, struct file *filp)
919} 929}
920 930
921static struct sysfs_dirent *sysfs_dir_pos(const void *ns, 931static struct sysfs_dirent *sysfs_dir_pos(const void *ns,
922 struct sysfs_dirent *parent_sd, ino_t ino, struct sysfs_dirent *pos) 932 struct sysfs_dirent *parent_sd, loff_t hash, struct sysfs_dirent *pos)
923{ 933{
924 if (pos) { 934 if (pos) {
925 int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) && 935 int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) &&
926 pos->s_parent == parent_sd && 936 pos->s_parent == parent_sd &&
927 ino == pos->s_ino; 937 hash == pos->s_hash;
928 sysfs_put(pos); 938 sysfs_put(pos);
929 if (!valid) 939 if (!valid)
930 pos = NULL; 940 pos = NULL;
931 } 941 }
932 if (!pos && (ino > 1) && (ino < INT_MAX)) { 942 if (!pos && (hash > 1) && (hash < INT_MAX)) {
933 struct rb_node *p = parent_sd->s_dir.inode_tree.rb_node; 943 struct rb_node *node = parent_sd->s_dir.children.rb_node;
934 while (p) { 944 while (node) {
935#define node rb_entry(p, struct sysfs_dirent, inode_node) 945 pos = to_sysfs_dirent(node);
936 if (ino < node->s_ino) { 946
937 pos = node; 947 if (hash < pos->s_hash)
938 p = node->inode_node.rb_left; 948 node = node->rb_left;
939 } else if (ino > node->s_ino) { 949 else if (hash > pos->s_hash)
940 p = node->inode_node.rb_right; 950 node = node->rb_right;
941 } else { 951 else
942 pos = node;
943 break; 952 break;
944 }
945#undef node
946 } 953 }
947 } 954 }
955 /* Skip over entries in the wrong namespace */
948 while (pos && pos->s_ns != ns) { 956 while (pos && pos->s_ns != ns) {
949 struct rb_node *p = rb_next(&pos->inode_node); 957 struct rb_node *node = rb_next(&pos->s_rb);
950 if (!p) 958 if (!node)
951 pos = NULL; 959 pos = NULL;
952 else 960 else
953 pos = rb_entry(p, struct sysfs_dirent, inode_node); 961 pos = to_sysfs_dirent(node);
954 } 962 }
955 return pos; 963 return pos;
956} 964}
@@ -960,11 +968,11 @@ static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns,
960{ 968{
961 pos = sysfs_dir_pos(ns, parent_sd, ino, pos); 969 pos = sysfs_dir_pos(ns, parent_sd, ino, pos);
962 if (pos) do { 970 if (pos) do {
963 struct rb_node *p = rb_next(&pos->inode_node); 971 struct rb_node *node = rb_next(&pos->s_rb);
964 if (!p) 972 if (!node)
965 pos = NULL; 973 pos = NULL;
966 else 974 else
967 pos = rb_entry(p, struct sysfs_dirent, inode_node); 975 pos = to_sysfs_dirent(node);
968 } while (pos && pos->s_ns != ns); 976 } while (pos && pos->s_ns != ns);
969 return pos; 977 return pos;
970} 978}
@@ -1006,7 +1014,7 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
1006 len = strlen(name); 1014 len = strlen(name);
1007 ino = pos->s_ino; 1015 ino = pos->s_ino;
1008 type = dt_type(pos); 1016 type = dt_type(pos);
1009 filp->f_pos = ino; 1017 filp->f_pos = pos->s_hash;
1010 filp->private_data = sysfs_get(pos); 1018 filp->private_data = sysfs_get(pos);
1011 1019
1012 mutex_unlock(&sysfs_mutex); 1020 mutex_unlock(&sysfs_mutex);
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 85eb81683a29..4291fd1617ab 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -216,9 +216,6 @@ static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode)
216 iattrs->ia_secdata, 216 iattrs->ia_secdata,
217 iattrs->ia_secdata_len); 217 iattrs->ia_secdata_len);
218 } 218 }
219
220 if (sysfs_type(sd) == SYSFS_DIR)
221 set_nlink(inode, sd->s_dir.subdirs + 2);
222} 219}
223 220
224int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 221int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
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..6289a00287db 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -19,10 +19,8 @@ struct sysfs_open_dirent;
19struct sysfs_elem_dir { 19struct sysfs_elem_dir {
20 struct kobject *kobj; 20 struct kobject *kobj;
21 21
22 unsigned long subdirs; 22 /* children rbtree starts here and goes through sd->s_rb */
23 23 struct rb_root children;
24 struct rb_root inode_tree;
25 struct rb_root name_tree;
26}; 24};
27 25
28struct sysfs_elem_symlink { 26struct sysfs_elem_symlink {
@@ -62,8 +60,7 @@ struct sysfs_dirent {
62 struct sysfs_dirent *s_parent; 60 struct sysfs_dirent *s_parent;
63 const char *s_name; 61 const char *s_name;
64 62
65 struct rb_node inode_node; 63 struct rb_node s_rb;
66 struct rb_node name_node;
67 64
68 union { 65 union {
69 struct completion *completion; 66 struct completion *completion;
@@ -71,6 +68,7 @@ struct sysfs_dirent {
71 } u; 68 } u;
72 69
73 const void *s_ns; /* namespace tag */ 70 const void *s_ns; /* namespace tag */
71 unsigned int s_hash; /* ns + name hash */
74 union { 72 union {
75 struct sysfs_elem_dir s_dir; 73 struct sysfs_elem_dir s_dir;
76 struct sysfs_elem_symlink s_symlink; 74 struct sysfs_elem_symlink s_symlink;
@@ -78,9 +76,9 @@ struct sysfs_dirent {
78 struct sysfs_elem_bin_attr s_bin_attr; 76 struct sysfs_elem_bin_attr s_bin_attr;
79 }; 77 };
80 78
81 unsigned int s_flags; 79 unsigned short s_flags;
82 umode_t s_mode; 80 umode_t s_mode;
83 ino_t s_ino; 81 unsigned int s_ino;
84 struct sysfs_inode_attrs *s_iattr; 82 struct sysfs_inode_attrs *s_iattr;
85}; 83};
86 84
@@ -95,11 +93,11 @@ struct sysfs_dirent {
95#define SYSFS_ACTIVE_REF (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR) 93#define SYSFS_ACTIVE_REF (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR)
96 94
97/* identify any namespace tag on sysfs_dirents */ 95/* identify any namespace tag on sysfs_dirents */
98#define SYSFS_NS_TYPE_MASK 0xff00 96#define SYSFS_NS_TYPE_MASK 0xf00
99#define SYSFS_NS_TYPE_SHIFT 8 97#define SYSFS_NS_TYPE_SHIFT 8
100 98
101#define SYSFS_FLAG_MASK ~(SYSFS_NS_TYPE_MASK|SYSFS_TYPE_MASK) 99#define SYSFS_FLAG_MASK ~(SYSFS_NS_TYPE_MASK|SYSFS_TYPE_MASK)
102#define SYSFS_FLAG_REMOVED 0x020000 100#define SYSFS_FLAG_REMOVED 0x02000
103 101
104static inline unsigned int sysfs_type(struct sysfs_dirent *sd) 102static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
105{ 103{
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/hyperv.h b/include/linux/hyperv.h
index 0ae065a5fcb2..e57a6c6ee0e8 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -25,6 +25,147 @@
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
123enum hv_kvp_exchg_op {
124 KVP_OP_GET = 0,
125 KVP_OP_SET,
126 KVP_OP_DELETE,
127 KVP_OP_ENUMERATE,
128 KVP_OP_REGISTER,
129 KVP_OP_COUNT /* Number of operations, must be last. */
130};
131
132enum hv_kvp_exchg_pool {
133 KVP_POOL_EXTERNAL = 0,
134 KVP_POOL_GUEST,
135 KVP_POOL_AUTO,
136 KVP_POOL_AUTO_EXTERNAL,
137 KVP_POOL_AUTO_INTERNAL,
138 KVP_POOL_COUNT /* Number of pools, must be last. */
139};
140
141struct hv_kvp_hdr {
142 __u8 operation;
143 __u8 pool;
144 __u16 pad;
145} __attribute__((packed));
146
147struct hv_kvp_exchg_msg_value {
148 __u32 value_type;
149 __u32 key_size;
150 __u32 value_size;
151 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
152 __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
153} __attribute__((packed));
154
155struct hv_kvp_msg_enumerate {
156 __u32 index;
157 struct hv_kvp_exchg_msg_value data;
158} __attribute__((packed));
159
160struct hv_kvp_msg {
161 struct hv_kvp_hdr kvp_hdr;
162 union {
163 struct hv_kvp_msg_enumerate kvp_enum_data;
164 char kvp_version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
165 } body;
166} __attribute__((packed));
167
168#ifdef __KERNEL__
28#include <linux/scatterlist.h> 169#include <linux/scatterlist.h>
29#include <linux/list.h> 170#include <linux/list.h>
30#include <linux/uuid.h> 171#include <linux/uuid.h>
@@ -870,4 +1011,9 @@ struct hyperv_service_callback {
870extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *, 1011extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *,
871 struct icmsg_negotiate *, u8 *); 1012 struct icmsg_negotiate *, u8 *);
872 1013
1014int hv_kvp_init(struct hv_util_service *);
1015void hv_kvp_deinit(void);
1016void hv_kvp_onchannelcallback(void *);
1017
1018#endif /* __KERNEL__ */
873#endif /* _HYPERV_H */ 1019#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 0eac07c95255..f486f635e7b5 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 f0e22f75143f..f9abd9357a0c 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -180,13 +180,13 @@ extern void dump_stack(void) __cold;
180#endif 180#endif
181 181
182/* If you are writing a driver, please use dev_dbg instead */ 182/* If you are writing a driver, please use dev_dbg instead */
183#if defined(DEBUG) 183#if defined(CONFIG_DYNAMIC_DEBUG)
184#define pr_debug(fmt, ...) \
185 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
186#elif defined(CONFIG_DYNAMIC_DEBUG)
187/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ 184/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
188#define pr_debug(fmt, ...) \ 185#define pr_debug(fmt, ...) \
189 dynamic_pr_debug(fmt, ##__VA_ARGS__) 186 dynamic_pr_debug(fmt, ##__VA_ARGS__)
187#elif defined(DEBUG)
188#define pr_debug(fmt, ...) \
189 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
190#else 190#else
191#define pr_debug(fmt, ...) \ 191#define pr_debug(fmt, ...) \
192 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 192 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/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index d0de2a2c3a2d..8df369491065 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1003,6 +1003,30 @@ static int do_amba_entry(const char *filename,
1003} 1003}
1004ADD_TO_DEVTABLE("amba", struct amba_id, do_amba_entry); 1004ADD_TO_DEVTABLE("amba", struct amba_id, do_amba_entry);
1005 1005
1006/* LOOKS like x86cpu:vendor:VVVV:family:FFFF:model:MMMM:feature:*,FEAT,*
1007 * All fields are numbers. It would be nicer to use strings for vendor
1008 * and feature, but getting those out of the build system here is too
1009 * complicated.
1010 */
1011
1012static int do_x86cpu_entry(const char *filename, struct x86_cpu_id *id,
1013 char *alias)
1014{
1015 id->feature = TO_NATIVE(id->feature);
1016 id->family = TO_NATIVE(id->family);
1017 id->model = TO_NATIVE(id->model);
1018 id->vendor = TO_NATIVE(id->vendor);
1019
1020 strcpy(alias, "x86cpu:");
1021 ADD(alias, "vendor:", id->vendor != X86_VENDOR_ANY, id->vendor);
1022 ADD(alias, ":family:", id->family != X86_FAMILY_ANY, id->family);
1023 ADD(alias, ":model:", id->model != X86_MODEL_ANY, id->model);
1024 ADD(alias, ":feature:*,", id->feature != X86_FEATURE_ANY, id->feature);
1025 strcat(alias, ",*");
1026 return 1;
1027}
1028ADD_TO_DEVTABLE("x86cpu", struct x86_cpu_id, do_x86cpu_entry);
1029
1006/* Does namelen bytes of name exactly match the symbol? */ 1030/* Does namelen bytes of name exactly match the symbol? */
1007static bool sym_is(const char *name, unsigned namelen, const char *symbol) 1031static bool sym_is(const char *name, unsigned namelen, const char *symbol)
1008{ 1032{
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 11224eddcdc2..4ebf70380582 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -34,21 +34,12 @@
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
42/*
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 43
53/* 44/*
54 * KVP protocol: The user mode component first registers with the 45 * KVP protocol: The user mode component first registers with the
@@ -60,25 +51,8 @@
60 * We use this infrastructure for also supporting queries from user mode 51 * We use this infrastructure for also supporting queries from user mode
61 * application for state that may be maintained in the KVP kernel component. 52 * application for state that may be maintained in the KVP kernel component.
62 * 53 *
63 * XXXKYS: Have a shared header file between the user and kernel (TODO)
64 */ 54 */
65 55
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 56
83enum key_index { 57enum key_index {
84 FullyQualifiedDomainName = 0, 58 FullyQualifiedDomainName = 0,
@@ -93,10 +67,6 @@ enum key_index {
93 ProcessorArchitecture 67 ProcessorArchitecture
94}; 68};
95 69
96/*
97 * End of shared definitions.
98 */
99
100static char kvp_send_buffer[4096]; 70static char kvp_send_buffer[4096];
101static char kvp_recv_buffer[4096]; 71static char kvp_recv_buffer[4096];
102static struct sockaddr_nl addr; 72static struct sockaddr_nl addr;
@@ -332,7 +302,7 @@ int main(void)
332 struct pollfd pfd; 302 struct pollfd pfd;
333 struct nlmsghdr *incoming_msg; 303 struct nlmsghdr *incoming_msg;
334 struct cn_msg *incoming_cn_msg; 304 struct cn_msg *incoming_cn_msg;
335 struct hv_ku_msg *hv_msg; 305 struct hv_kvp_msg *hv_msg;
336 char *p; 306 char *p;
337 char *key_value; 307 char *key_value;
338 char *key_name; 308 char *key_name;
@@ -370,9 +340,11 @@ int main(void)
370 message = (struct cn_msg *)kvp_send_buffer; 340 message = (struct cn_msg *)kvp_send_buffer;
371 message->id.idx = CN_KVP_IDX; 341 message->id.idx = CN_KVP_IDX;
372 message->id.val = CN_KVP_VAL; 342 message->id.val = CN_KVP_VAL;
373 message->seq = KVP_REGISTER; 343
344 hv_msg = (struct hv_kvp_msg *)message->data;
345 hv_msg->kvp_hdr.operation = KVP_OP_REGISTER;
374 message->ack = 0; 346 message->ack = 0;
375 message->len = 0; 347 message->len = sizeof(struct hv_kvp_msg);
376 348
377 len = netlink_send(fd, message); 349 len = netlink_send(fd, message);
378 if (len < 0) { 350 if (len < 0) {
@@ -398,14 +370,15 @@ int main(void)
398 370
399 incoming_msg = (struct nlmsghdr *)kvp_recv_buffer; 371 incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
400 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg); 372 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
373 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data;
401 374
402 switch (incoming_cn_msg->seq) { 375 switch (hv_msg->kvp_hdr.operation) {
403 case KVP_REGISTER: 376 case KVP_OP_REGISTER:
404 /* 377 /*
405 * Driver is registering with us; stash away the version 378 * Driver is registering with us; stash away the version
406 * information. 379 * information.
407 */ 380 */
408 p = (char *)incoming_cn_msg->data; 381 p = (char *)hv_msg->body.kvp_version;
409 lic_version = malloc(strlen(p) + 1); 382 lic_version = malloc(strlen(p) + 1);
410 if (lic_version) { 383 if (lic_version) {
411 strcpy(lic_version, p); 384 strcpy(lic_version, p);
@@ -416,17 +389,15 @@ int main(void)
416 } 389 }
417 continue; 390 continue;
418 391
419 case KVP_KERNEL_GET:
420 break;
421 default: 392 default:
422 continue; 393 break;
423 } 394 }
424 395
425 hv_msg = (struct hv_ku_msg *)incoming_cn_msg->data; 396 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data;
426 key_name = (char *)hv_msg->kvp_key; 397 key_name = (char *)hv_msg->body.kvp_enum_data.data.key;
427 key_value = (char *)hv_msg->kvp_value; 398 key_value = (char *)hv_msg->body.kvp_enum_data.data.value;
428 399
429 switch (hv_msg->kvp_index) { 400 switch (hv_msg->body.kvp_enum_data.index) {
430 case FullyQualifiedDomainName: 401 case FullyQualifiedDomainName:
431 kvp_get_domain_name(key_value, 402 kvp_get_domain_name(key_value,
432 HV_KVP_EXCHANGE_MAX_VALUE_SIZE); 403 HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
@@ -486,9 +457,8 @@ int main(void)
486 457
487 incoming_cn_msg->id.idx = CN_KVP_IDX; 458 incoming_cn_msg->id.idx = CN_KVP_IDX;
488 incoming_cn_msg->id.val = CN_KVP_VAL; 459 incoming_cn_msg->id.val = CN_KVP_VAL;
489 incoming_cn_msg->seq = KVP_USER_SET;
490 incoming_cn_msg->ack = 0; 460 incoming_cn_msg->ack = 0;
491 incoming_cn_msg->len = sizeof(struct hv_ku_msg); 461 incoming_cn_msg->len = sizeof(struct hv_kvp_msg);
492 462
493 len = netlink_send(fd, incoming_cn_msg); 463 len = netlink_send(fd, incoming_cn_msg);
494 if (len < 0) { 464 if (len < 0) {