aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-driver-hid-roccat-kone16
-rw-r--r--Documentation/ABI/testing/sysfs-driver-hid-roccat-koneplus108
-rw-r--r--Documentation/ABI/testing/sysfs-driver-hid-roccat-pyra18
-rw-r--r--Documentation/coccinelle.txt4
-rw-r--r--Documentation/kbuild/kbuild.txt8
-rw-r--r--Documentation/kbuild/kconfig-language.txt7
-rw-r--r--Documentation/kbuild/makefiles.txt15
-rw-r--r--Documentation/make/headers_install.txt5
-rw-r--r--Documentation/power/drivers-testing.txt8
-rw-r--r--Documentation/power/runtime_pm.txt31
-rw-r--r--Documentation/powerpc/dts-bindings/eeprom.txt28
-rw-r--r--Documentation/vm/Makefile2
-rw-r--r--MAINTAINERS1
-rw-r--r--Makefile1
-rw-r--r--arch/arm/plat-s3c24xx/cpu-freq.c1
-rw-r--r--arch/microblaze/Kconfig2
-rw-r--r--arch/microblaze/boot/Makefile12
-rw-r--r--arch/microblaze/include/asm/prom.h3
-rw-r--r--arch/microblaze/kernel/prom_parse.c38
-rw-r--r--arch/mips/Kconfig2
-rw-r--r--arch/powerpc/Kconfig2
-rw-r--r--arch/powerpc/boot/Makefile8
-rw-r--r--arch/powerpc/boot/dts/bluestone.dts8
-rw-r--r--arch/powerpc/boot/dts/cm5200.dts194
-rw-r--r--arch/powerpc/boot/dts/digsy_mtc.dts177
-rw-r--r--arch/powerpc/boot/dts/hotfoot.dts2
-rw-r--r--arch/powerpc/boot/dts/lite5200b.dts220
-rw-r--r--arch/powerpc/boot/dts/media5200.dts214
-rw-r--r--arch/powerpc/boot/dts/motionpro.dts194
-rw-r--r--arch/powerpc/boot/dts/mpc5200b.dtsi275
-rw-r--r--arch/powerpc/boot/dts/mucmc52.dts174
-rw-r--r--arch/powerpc/boot/dts/pcm030.dts196
-rw-r--r--arch/powerpc/boot/dts/pcm032.dts242
-rw-r--r--arch/powerpc/boot/dts/uc101.dts160
-rw-r--r--arch/powerpc/include/asm/prom.h5
-rw-r--r--arch/powerpc/kernel/prom_parse.c38
-rw-r--r--arch/powerpc/platforms/40x/ppc40x_simple.c13
-rw-r--r--arch/powerpc/platforms/512x/mpc5121_generic.c13
-rw-r--r--arch/powerpc/platforms/52xx/lite5200.c16
-rw-r--r--arch/powerpc/platforms/52xx/media5200.c13
-rw-r--r--arch/powerpc/platforms/52xx/mpc5200_simple.c13
-rw-r--r--arch/powerpc/platforms/83xx/mpc830x_rdb.c13
-rw-r--r--arch/powerpc/platforms/83xx/mpc831x_rdb.c11
-rw-r--r--arch/powerpc/platforms/83xx/mpc837x_rdb.c15
-rw-r--r--arch/powerpc/platforms/85xx/tqm85xx.c20
-rw-r--r--arch/powerpc/platforms/pseries/eeh_sysfs.c1
-rw-r--r--arch/powerpc/sysdev/mv64x60_dev.c1
-rw-r--r--arch/powerpc/sysdev/tsi108_dev.c1
-rw-r--r--arch/sparc/kernel/auxio_32.c2
-rw-r--r--arch/sparc/kernel/starfire.c2
-rw-r--r--arch/sparc/prom/init_32.c2
-rw-r--r--arch/sparc/prom/init_64.c4
-rw-r--r--arch/sparc/prom/tree_32.c17
-rw-r--r--arch/sparc/prom/tree_64.c18
-rw-r--r--arch/x86/include/asm/hypervisor.h12
-rw-r--r--arch/x86/include/asm/xen/hypervisor.h35
-rw-r--r--arch/x86/kernel/apic/apic.c5
-rw-r--r--arch/x86/xen/enlighten.c40
-rw-r--r--drivers/ata/Kconfig28
-rw-r--r--drivers/ata/Makefile1
-rw-r--r--drivers/ata/acard-ahci.c528
-rw-r--r--drivers/ata/ahci.h3
-rw-r--r--drivers/ata/libahci.c11
-rw-r--r--drivers/ata/libata-scsi.c60
-rw-r--r--drivers/ata/pata_hpt366.c51
-rw-r--r--drivers/ata/pata_hpt37x.c236
-rw-r--r--drivers/ata/pata_hpt3x2n.c150
-rw-r--r--drivers/base/core.c41
-rw-r--r--drivers/base/power/generic_ops.c6
-rw-r--r--drivers/base/power/main.c174
-rw-r--r--drivers/base/power/runtime.c47
-rw-r--r--drivers/base/power/wakeup.c20
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c10
-rw-r--r--drivers/char/snsc.h1
-rw-r--r--drivers/firewire/Kconfig2
-rw-r--r--drivers/firewire/core-cdev.c7
-rw-r--r--drivers/firewire/core-transaction.c58
-rw-r--r--drivers/firewire/core.h4
-rw-r--r--drivers/firewire/net.c47
-rw-r--r--drivers/firewire/nosy.c3
-rw-r--r--drivers/firewire/ohci.c672
-rw-r--r--drivers/hid/Kconfig17
-rw-r--r--drivers/hid/Makefile14
-rw-r--r--drivers/hid/hid-3m-pct.c2
-rw-r--r--drivers/hid/hid-a4tech.c6
-rw-r--r--drivers/hid/hid-apple.c63
-rw-r--r--drivers/hid/hid-axff.c14
-rw-r--r--drivers/hid/hid-belkin.c4
-rw-r--r--drivers/hid/hid-cando.c2
-rw-r--r--drivers/hid/hid-cherry.c3
-rw-r--r--drivers/hid/hid-core.c119
-rw-r--r--drivers/hid/hid-cypress.c4
-rw-r--r--drivers/hid/hid-debug.c4
-rw-r--r--drivers/hid/hid-drff.c14
-rw-r--r--drivers/hid/hid-egalax.c2
-rw-r--r--drivers/hid/hid-elecom.c3
-rw-r--r--drivers/hid/hid-emsff.c161
-rw-r--r--drivers/hid/hid-gaff.c13
-rw-r--r--drivers/hid/hid-ids.h11
-rw-r--r--drivers/hid/hid-input.c18
-rw-r--r--drivers/hid/hid-kye.c4
-rw-r--r--drivers/hid/hid-lg.c15
-rw-r--r--drivers/hid/hid-lg2ff.c9
-rw-r--r--drivers/hid/hid-lg3ff.c9
-rw-r--r--drivers/hid/hid-lg4ff.c9
-rw-r--r--drivers/hid/hid-lgff.c8
-rw-r--r--drivers/hid/hid-magicmouse.c20
-rw-r--r--drivers/hid/hid-microsoft.c7
-rw-r--r--drivers/hid/hid-monterey.c3
-rw-r--r--drivers/hid/hid-mosart.c22
-rw-r--r--drivers/hid/hid-ntrig.c9
-rw-r--r--drivers/hid/hid-ortek.c3
-rw-r--r--drivers/hid/hid-petalynx.c7
-rw-r--r--drivers/hid/hid-picolcd.c58
-rw-r--r--drivers/hid/hid-pl.c16
-rw-r--r--drivers/hid/hid-prodikeys.c27
-rw-r--r--drivers/hid/hid-quanta.c2
-rw-r--r--drivers/hid/hid-roccat-kone.c404
-rw-r--r--drivers/hid/hid-roccat-kone.h19
-rw-r--r--drivers/hid/hid-roccat-koneplus.c837
-rw-r--r--drivers/hid/hid-roccat-koneplus.h224
-rw-r--r--drivers/hid/hid-roccat-pyra.c411
-rw-r--r--drivers/hid/hid-roccat-pyra.h23
-rw-r--r--drivers/hid/hid-roccat.c53
-rw-r--r--drivers/hid/hid-roccat.h5
-rw-r--r--drivers/hid/hid-samsung.c8
-rw-r--r--drivers/hid/hid-sjoy.c16
-rw-r--r--drivers/hid/hid-sony.c11
-rw-r--r--drivers/hid/hid-stantum.c2
-rw-r--r--drivers/hid/hid-sunplus.c3
-rw-r--r--drivers/hid/hid-tmff.c27
-rw-r--r--drivers/hid/hid-topseed.c1
-rw-r--r--drivers/hid/hid-wacom.c28
-rw-r--r--drivers/hid/hid-zpff.c11
-rw-r--r--drivers/hid/hid-zydacron.c11
-rw-r--r--drivers/hid/hidraw.c36
-rw-r--r--drivers/hid/usbhid/Makefile6
-rw-r--r--drivers/hid/usbhid/hid-core.c105
-rw-r--r--drivers/hid/usbhid/hid-pidff.c164
-rw-r--r--drivers/hid/usbhid/hid-quirks.c2
-rw-r--r--drivers/hid/usbhid/hiddev.c241
-rw-r--r--drivers/hid/usbhid/usbhid.h1
-rw-r--r--drivers/hid/usbhid/usbkbd.c24
-rw-r--r--drivers/input/mouse/bcm5974.c40
-rw-r--r--drivers/misc/eeprom/at24.c43
-rw-r--r--drivers/mmc/host/Kconfig4
-rw-r--r--drivers/mmc/host/sdhci-of-core.c4
-rw-r--r--drivers/mtd/Kconfig2
-rw-r--r--drivers/mtd/maps/Kconfig2
-rw-r--r--drivers/net/bonding/bonding.h1
-rw-r--r--drivers/net/fs_enet/fs_enet-main.c1
-rw-r--r--drivers/net/gianfar.c1
-rw-r--r--drivers/net/ucc_geth.c1
-rw-r--r--drivers/net/xilinx_emaclite.c1
-rw-r--r--drivers/of/Kconfig8
-rw-r--r--drivers/of/Makefile1
-rw-r--r--drivers/of/address.c54
-rw-r--r--drivers/of/fdt.c430
-rw-r--r--drivers/of/of_mdio.c26
-rw-r--r--drivers/of/of_net.c48
-rw-r--r--drivers/of/platform.c22
-rw-r--r--drivers/pci/hotplug/acpiphp.h1
-rw-r--r--drivers/pci/hotplug/rpaphp_slot.c1
-rw-r--r--drivers/s390/char/tape_class.h1
-rw-r--r--drivers/sbus/char/jsflash.c2
-rw-r--r--drivers/scsi/ipr.c2
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c3
-rw-r--r--drivers/serial/Kconfig2
-rw-r--r--drivers/serial/of_serial.c1
-rw-r--r--drivers/sh/clk/core.c1
-rw-r--r--drivers/spi/spi.c92
-rw-r--r--drivers/usb/core/driver.c7
-rw-r--r--drivers/usb/musb/musb_debugfs.c1
-rw-r--r--drivers/video/xen-fbfront.c19
-rw-r--r--drivers/xen/events.c21
-rw-r--r--fs/cifs/cache.c16
-rw-r--r--fs/cifs/cifs_debug.c22
-rw-r--r--fs/cifs/cifs_spnego.c10
-rw-r--r--fs/cifs/cifsencrypt.c6
-rw-r--r--fs/cifs/cifsfs.c17
-rw-r--r--fs/cifs/cifsglob.h9
-rw-r--r--fs/cifs/cifssmb.c5
-rw-r--r--fs/cifs/connect.c462
-rw-r--r--fs/cifs/dir.c6
-rw-r--r--fs/cifs/file.c233
-rw-r--r--fs/cifs/inode.c6
-rw-r--r--fs/cifs/readdir.c1
-rw-r--r--fs/cifs/sess.c135
-rw-r--r--fs/cifs/transport.c2
-rw-r--r--fs/dlm/lowcomms.c63
-rw-r--r--fs/fuse/dev.c156
-rw-r--r--fs/fuse/dir.c53
-rw-r--r--fs/fuse/file.c66
-rw-r--r--fs/fuse/fuse_i.h27
-rw-r--r--fs/fuse/inode.c30
-rw-r--r--fs/gfs2/incore.h1
-rw-r--r--fs/namei.c8
-rw-r--r--fs/nilfs2/bmap.c47
-rw-r--r--fs/nilfs2/btnode.c3
-rw-r--r--fs/nilfs2/dir.c3
-rw-r--r--fs/nilfs2/file.c1
-rw-r--r--fs/nilfs2/ifile.c11
-rw-r--r--fs/nilfs2/inode.c180
-rw-r--r--fs/nilfs2/ioctl.c12
-rw-r--r--fs/nilfs2/mdt.c32
-rw-r--r--fs/nilfs2/namei.c1
-rw-r--r--fs/nilfs2/nilfs.h13
-rw-r--r--fs/nilfs2/page.c86
-rw-r--r--fs/nilfs2/page.h3
-rw-r--r--fs/nilfs2/recovery.c2
-rw-r--r--fs/nilfs2/sb.h8
-rw-r--r--fs/nilfs2/segment.c43
-rw-r--r--fs/nilfs2/super.c30
-rw-r--r--fs/nilfs2/the_nilfs.c6
-rw-r--r--fs/nilfs2/the_nilfs.h3
-rw-r--r--fs/sysfs/inode.c1
-rw-r--r--fs/sysfs/sysfs.h1
-rw-r--r--include/asm-generic/vmlinux.lds.h13
-rw-r--r--include/linux/Kbuild9
-rw-r--r--include/linux/audit.h1
-rw-r--r--include/linux/dcache.h2
-rw-r--r--include/linux/dcookies.h2
-rw-r--r--include/linux/device.h5
-rw-r--r--include/linux/firewire.h2
-rw-r--r--include/linux/firmware-map.h1
-rw-r--r--include/linux/fs.h2
-rw-r--r--include/linux/fuse.h26
-rw-r--r--include/linux/hid.h75
-rw-r--r--include/linux/hrtimer.h1
-rw-r--r--include/linux/libata.h6
-rw-r--r--include/linux/of_address.h6
-rw-r--r--include/linux/of_fdt.h18
-rw-r--r--include/linux/of_net.h15
-rw-r--r--include/linux/pipe_fs_i.h1
-rw-r--r--include/linux/pm.h51
-rw-r--r--include/linux/pm_runtime.h13
-rw-r--r--include/linux/sched.h2
-rw-r--r--include/linux/slab_def.h33
-rw-r--r--include/linux/slub_def.h55
-rw-r--r--include/linux/sunrpc/cache.h1
-rw-r--r--include/linux/suspend.h4
-rw-r--r--kernel/Makefile2
-rw-r--r--kernel/freezer.c9
-rw-r--r--kernel/power/Makefile5
-rw-r--r--kernel/power/hibernate.c7
-rw-r--r--kernel/power/process.c8
-rw-r--r--kernel/power/suspend.c2
-rw-r--r--mm/slab.c38
-rw-r--r--mm/slub.c30
-rw-r--r--scripts/.gitignore1
-rw-r--r--scripts/Makefile.lib23
-rw-r--r--scripts/basic/fixdep.c119
-rwxr-xr-xscripts/checksyscalls.sh4
-rw-r--r--scripts/coccinelle/misc/doubleinit.cocci6
-rw-r--r--scripts/coccinelle/null/deref_null.cocci39
-rwxr-xr-xscripts/config13
-rw-r--r--scripts/dtc/Makefile3
-rw-r--r--scripts/dtc/checks.c105
-rw-r--r--scripts/dtc/dtc-lexer.l175
-rw-r--r--scripts/dtc/dtc-lexer.lex.c_shipped551
-rw-r--r--scripts/dtc/dtc-parser.tab.c_shipped892
-rw-r--r--scripts/dtc/dtc-parser.tab.h_shipped82
-rw-r--r--scripts/dtc/dtc-parser.y160
-rw-r--r--scripts/dtc/dtc.c57
-rw-r--r--scripts/dtc/dtc.h77
-rw-r--r--scripts/dtc/flattree.c192
-rw-r--r--scripts/dtc/fstree.c12
-rw-r--r--scripts/dtc/livetree.c345
-rw-r--r--scripts/dtc/srcpos.c258
-rw-r--r--scripts/dtc/srcpos.h99
-rw-r--r--scripts/dtc/treesource.c48
-rw-r--r--scripts/dtc/util.c59
-rw-r--r--scripts/dtc/util.h56
-rw-r--r--scripts/dtc/version_gen.h2
-rw-r--r--scripts/genksyms/parse.c_shipped2
-rw-r--r--scripts/genksyms/parse.y2
-rwxr-xr-xscripts/headers.sh2
-rw-r--r--scripts/headers_check.pl6
-rw-r--r--scripts/headers_install.pl7
-rw-r--r--scripts/kconfig/conf.c2
-rw-r--r--scripts/kconfig/confdata.c27
-rw-r--r--scripts/kconfig/expr.c44
-rw-r--r--scripts/kconfig/expr.h3
-rw-r--r--scripts/kconfig/lkc.h7
-rw-r--r--scripts/kconfig/menu.c15
-rw-r--r--scripts/kconfig/nconf.c10
-rw-r--r--scripts/kconfig/symbol.c8
-rwxr-xr-xscripts/mkuboot.sh2
-rw-r--r--scripts/mod/modpost.c3
-rw-r--r--scripts/package/builddeb93
-rwxr-xr-xscripts/tags.sh2
-rw-r--r--security/apparmor/include/file.h3
-rw-r--r--security/apparmor/include/match.h1
-rw-r--r--security/selinux/include/avc.h1
-rw-r--r--tools/slub/slabinfo.c (renamed from Documentation/vm/slabinfo.c)6
-rw-r--r--usr/gen_init_cpio.c20
296 files changed, 8660 insertions, 6313 deletions
diff --git a/Documentation/ABI/testing/sysfs-driver-hid-roccat-kone b/Documentation/ABI/testing/sysfs-driver-hid-roccat-kone
index 063bda7fe707..698b8081c473 100644
--- a/Documentation/ABI/testing/sysfs-driver-hid-roccat-kone
+++ b/Documentation/ABI/testing/sysfs-driver-hid-roccat-kone
@@ -1,4 +1,4 @@
1What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/actual_dpi 1What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/kone/roccatkone<minor>/actual_dpi
2Date: March 2010 2Date: March 2010
3Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 3Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
4Description: It is possible to switch the dpi setting of the mouse with the 4Description: It is possible to switch the dpi setting of the mouse with the
@@ -17,13 +17,13 @@ Description: It is possible to switch the dpi setting of the mouse with the
17 17
18 This file is readonly. 18 This file is readonly.
19 19
20What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/actual_profile 20What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/kone/roccatkone<minor>/actual_profile
21Date: March 2010 21Date: March 2010
22Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 22Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
23Description: When read, this file returns the number of the actual profile. 23Description: When read, this file returns the number of the actual profile.
24 This file is readonly. 24 This file is readonly.
25 25
26What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/firmware_version 26What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/kone/roccatkone<minor>/firmware_version
27Date: March 2010 27Date: March 2010
28Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 28Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
29Description: When read, this file returns the raw integer version number of the 29Description: When read, this file returns the raw integer version number of the
@@ -33,7 +33,7 @@ Description: When read, this file returns the raw integer version number of the
33 left. E.g. a returned value of 138 means 1.38 33 left. E.g. a returned value of 138 means 1.38
34 This file is readonly. 34 This file is readonly.
35 35
36What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/profile[1-5] 36What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/kone/roccatkone<minor>/profile[1-5]
37Date: March 2010 37Date: March 2010
38Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 38Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
39Description: The mouse can store 5 profiles which can be switched by the 39Description: The mouse can store 5 profiles which can be switched by the
@@ -48,7 +48,7 @@ Description: The mouse can store 5 profiles which can be switched by the
48 stored in the profile doesn't need to fit the number of the 48 stored in the profile doesn't need to fit the number of the
49 store. 49 store.
50 50
51What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/settings 51What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/kone/roccatkone<minor>/settings
52Date: March 2010 52Date: March 2010
53Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 53Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
54Description: When read, this file returns the settings stored in the mouse. 54Description: When read, this file returns the settings stored in the mouse.
@@ -58,7 +58,7 @@ Description: When read, this file returns the settings stored in the mouse.
58 The data has to be 36 bytes long. The mouse will reject invalid 58 The data has to be 36 bytes long. The mouse will reject invalid
59 data. 59 data.
60 60
61What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/startup_profile 61What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/kone/roccatkone<minor>/startup_profile
62Date: March 2010 62Date: March 2010
63Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 63Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
64Description: The integer value of this attribute ranges from 1 to 5. 64Description: The integer value of this attribute ranges from 1 to 5.
@@ -67,7 +67,7 @@ Description: The integer value of this attribute ranges from 1 to 5.
67 When written, this file sets the number of the startup profile 67 When written, this file sets the number of the startup profile
68 and the mouse activates this profile immediately. 68 and the mouse activates this profile immediately.
69 69
70What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/tcu 70What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/kone/roccatkone<minor>/tcu
71Date: March 2010 71Date: March 2010
72Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 72Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
73Description: The mouse has a "Tracking Control Unit" which lets the user 73Description: The mouse has a "Tracking Control Unit" which lets the user
@@ -78,7 +78,7 @@ Description: The mouse has a "Tracking Control Unit" which lets the user
78 Writing 1 in this file will start the calibration which takes 78 Writing 1 in this file will start the calibration which takes
79 around 6 seconds to complete and activates the TCU. 79 around 6 seconds to complete and activates the TCU.
80 80
81What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/weight 81What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/kone/roccatkone<minor>/weight
82Date: March 2010 82Date: March 2010
83Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 83Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
84Description: The mouse can be equipped with one of four supplied weights 84Description: The mouse can be equipped with one of four supplied weights
diff --git a/Documentation/ABI/testing/sysfs-driver-hid-roccat-koneplus b/Documentation/ABI/testing/sysfs-driver-hid-roccat-koneplus
new file mode 100644
index 000000000000..0f9f30eb1742
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-driver-hid-roccat-koneplus
@@ -0,0 +1,108 @@
1What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/koneplus/roccatkoneplus<minor>/actual_profile
2Date: October 2010
3Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
4Description: When read, this file returns the number of the actual profile in
5 range 0-4.
6 This file is readonly.
7
8What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/koneplus/roccatkoneplus<minor>/firmware_version
9Date: October 2010
10Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
11Description: When read, this file returns the raw integer version number of the
12 firmware reported by the mouse. Using the integer value eases
13 further usage in other programs. To receive the real version
14 number the decimal point has to be shifted 2 positions to the
15 left. E.g. a returned value of 121 means 1.21
16 This file is readonly.
17
18What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/koneplus/roccatkoneplus<minor>/macro
19Date: October 2010
20Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
21Description: The mouse can store a macro with max 500 key/button strokes
22 internally.
23 When written, this file lets one set the sequence for a specific
24 button for a specific profile. Button and profile numbers are
25 included in written data. The data has to be 2082 bytes long.
26 This file is writeonly.
27
28What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/koneplus/roccatkoneplus<minor>/profile_buttons
29Date: August 2010
30Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
31Description: The mouse can store 5 profiles which can be switched by the
32 press of a button. A profile is split in settings and buttons.
33 profile_buttons holds informations about button layout.
34 When written, this file lets one write the respective profile
35 buttons back to the mouse. The data has to be 77 bytes long.
36 The mouse will reject invalid data.
37 Which profile to write is determined by the profile number
38 contained in the data.
39 This file is writeonly.
40
41What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/koneplus/roccatkoneplus<minor>/profile[1-5]_buttons
42Date: August 2010
43Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
44Description: The mouse can store 5 profiles which can be switched by the
45 press of a button. A profile is split in settings and buttons.
46 profile_buttons holds informations about button layout.
47 When read, these files return the respective profile buttons.
48 The returned data is 77 bytes in size.
49 This file is readonly.
50
51What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/koneplus/roccatkoneplus<minor>/profile_settings
52Date: October 2010
53Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
54Description: The mouse can store 5 profiles which can be switched by the
55 press of a button. A profile is split in settings and buttons.
56 profile_settings holds informations like resolution, sensitivity
57 and light effects.
58 When written, this file lets one write the respective profile
59 settings back to the mouse. The data has to be 43 bytes long.
60 The mouse will reject invalid data.
61 Which profile to write is determined by the profile number
62 contained in the data.
63 This file is writeonly.
64
65What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/koneplus/roccatkoneplus<minor>/profile[1-5]_settings
66Date: August 2010
67Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
68Description: The mouse can store 5 profiles which can be switched by the
69 press of a button. A profile is split in settings and buttons.
70 profile_settings holds informations like resolution, sensitivity
71 and light effects.
72 When read, these files return the respective profile settings.
73 The returned data is 43 bytes in size.
74 This file is readonly.
75
76What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/koneplus/roccatkoneplus<minor>/sensor
77Date: October 2010
78Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
79Description: The mouse has a tracking- and a distance-control-unit. These
80 can be activated/deactivated and the lift-off distance can be
81 set. The data has to be 6 bytes long.
82 This file is writeonly.
83
84What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/koneplus/roccatkoneplus<minor>/startup_profile
85Date: October 2010
86Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
87Description: The integer value of this attribute ranges from 0-4.
88 When read, this attribute returns the number of the profile
89 that's active when the mouse is powered on.
90 When written, this file sets the number of the startup profile
91 and the mouse activates this profile immediately.
92
93What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/koneplus/roccatkoneplus<minor>/tcu
94Date: October 2010
95Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
96Description: When written a calibration process for the tracking control unit
97 can be initiated/cancelled.
98 The data has to be 3 bytes long.
99 This file is writeonly.
100
101What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/koneplus/roccatkoneplus<minor>/tcu_image
102Date: October 2010
103Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
104Description: When read the mouse returns a 30x30 pixel image of the
105 sampled underground. This works only in the course of a
106 calibration process initiated with tcu.
107 The returned data is 1028 bytes in size.
108 This file is readonly.
diff --git a/Documentation/ABI/testing/sysfs-driver-hid-roccat-pyra b/Documentation/ABI/testing/sysfs-driver-hid-roccat-pyra
index ad1125b02ff4..1c37b823f142 100644
--- a/Documentation/ABI/testing/sysfs-driver-hid-roccat-pyra
+++ b/Documentation/ABI/testing/sysfs-driver-hid-roccat-pyra
@@ -1,4 +1,4 @@
1What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/actual_cpi 1What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/actual_cpi
2Date: August 2010 2Date: August 2010
3Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 3Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
4Description: It is possible to switch the cpi setting of the mouse with the 4Description: It is possible to switch the cpi setting of the mouse with the
@@ -14,14 +14,14 @@ Description: It is possible to switch the cpi setting of the mouse with the
14 14
15 This file is readonly. 15 This file is readonly.
16 16
17What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/actual_profile 17What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/actual_profile
18Date: August 2010 18Date: August 2010
19Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 19Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
20Description: When read, this file returns the number of the actual profile in 20Description: When read, this file returns the number of the actual profile in
21 range 0-4. 21 range 0-4.
22 This file is readonly. 22 This file is readonly.
23 23
24What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/firmware_version 24What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/firmware_version
25Date: August 2010 25Date: August 2010
26Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 26Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
27Description: When read, this file returns the raw integer version number of the 27Description: When read, this file returns the raw integer version number of the
@@ -31,7 +31,7 @@ Description: When read, this file returns the raw integer version number of the
31 left. E.g. a returned value of 138 means 1.38 31 left. E.g. a returned value of 138 means 1.38
32 This file is readonly. 32 This file is readonly.
33 33
34What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/profile_settings 34What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/profile_settings
35Date: August 2010 35Date: August 2010
36Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 36Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
37Description: The mouse can store 5 profiles which can be switched by the 37Description: The mouse can store 5 profiles which can be switched by the
@@ -45,7 +45,7 @@ Description: The mouse can store 5 profiles which can be switched by the
45 contained in the data. 45 contained in the data.
46 This file is writeonly. 46 This file is writeonly.
47 47
48What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/profile[1-5]_settings 48What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/profile[1-5]_settings
49Date: August 2010 49Date: August 2010
50Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 50Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
51Description: The mouse can store 5 profiles which can be switched by the 51Description: The mouse can store 5 profiles which can be switched by the
@@ -56,7 +56,7 @@ Description: The mouse can store 5 profiles which can be switched by the
56 The returned data is 13 bytes in size. 56 The returned data is 13 bytes in size.
57 This file is readonly. 57 This file is readonly.
58 58
59What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/profile_buttons 59What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/profile_buttons
60Date: August 2010 60Date: August 2010
61Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 61Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
62Description: The mouse can store 5 profiles which can be switched by the 62Description: The mouse can store 5 profiles which can be switched by the
@@ -69,7 +69,7 @@ Description: The mouse can store 5 profiles which can be switched by the
69 contained in the data. 69 contained in the data.
70 This file is writeonly. 70 This file is writeonly.
71 71
72What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/profile[1-5]_buttons 72What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/profile[1-5]_buttons
73Date: August 2010 73Date: August 2010
74Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 74Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
75Description: The mouse can store 5 profiles which can be switched by the 75Description: The mouse can store 5 profiles which can be switched by the
@@ -79,7 +79,7 @@ Description: The mouse can store 5 profiles which can be switched by the
79 The returned data is 19 bytes in size. 79 The returned data is 19 bytes in size.
80 This file is readonly. 80 This file is readonly.
81 81
82What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/startup_profile 82What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/startup_profile
83Date: August 2010 83Date: August 2010
84Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 84Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
85Description: The integer value of this attribute ranges from 0-4. 85Description: The integer value of this attribute ranges from 0-4.
@@ -87,7 +87,7 @@ Description: The integer value of this attribute ranges from 0-4.
87 that's active when the mouse is powered on. 87 that's active when the mouse is powered on.
88 This file is readonly. 88 This file is readonly.
89 89
90What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/settings 90What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/settings
91Date: August 2010 91Date: August 2010
92Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 92Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
93Description: When read, this file returns the settings stored in the mouse. 93Description: When read, this file returns the settings stored in the mouse.
diff --git a/Documentation/coccinelle.txt b/Documentation/coccinelle.txt
index 4a276ea7001c..96b690348ba1 100644
--- a/Documentation/coccinelle.txt
+++ b/Documentation/coccinelle.txt
@@ -36,6 +36,10 @@ as a regular user, and install it with
36 36
37 sudo make install 37 sudo make install
38 38
39The semantic patches in the kernel will work best with Coccinelle version
400.2.4 or later. Using earlier versions may incur some parse errors in the
41semantic patch code, but any results that are obtained should still be
42correct.
39 43
40 Using Coccinelle on the Linux kernel 44 Using Coccinelle on the Linux kernel
41~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 45~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/Documentation/kbuild/kbuild.txt b/Documentation/kbuild/kbuild.txt
index 1e5165aa9e4e..4a990317b84a 100644
--- a/Documentation/kbuild/kbuild.txt
+++ b/Documentation/kbuild/kbuild.txt
@@ -73,6 +73,14 @@ Specify the output directory when building the kernel.
73The output directory can also be specified using "O=...". 73The output directory can also be specified using "O=...".
74Setting "O=..." takes precedence over KBUILD_OUTPUT. 74Setting "O=..." takes precedence over KBUILD_OUTPUT.
75 75
76KBUILD_DEBARCH
77--------------------------------------------------
78For the deb-pkg target, allows overriding the normal heuristics deployed by
79deb-pkg. Normally deb-pkg attempts to guess the right architecture based on
80the UTS_MACHINE variable, and on some architectures also the kernel config.
81The value of KBUILD_DEBARCH is assumed (not checked) to be a valid Debian
82architecture.
83
76ARCH 84ARCH
77-------------------------------------------------- 85--------------------------------------------------
78Set ARCH to the architecture to be built. 86Set ARCH to the architecture to be built.
diff --git a/Documentation/kbuild/kconfig-language.txt b/Documentation/kbuild/kconfig-language.txt
index 2fe93ca7c77c..b507d61fd41c 100644
--- a/Documentation/kbuild/kconfig-language.txt
+++ b/Documentation/kbuild/kconfig-language.txt
@@ -112,7 +112,6 @@ applicable everywhere (see syntax).
112 (no prompts anywhere) and for symbols with no dependencies. 112 (no prompts anywhere) and for symbols with no dependencies.
113 That will limit the usefulness but on the other hand avoid 113 That will limit the usefulness but on the other hand avoid
114 the illegal configurations all over. 114 the illegal configurations all over.
115 kconfig should one day warn about such things.
116 115
117- numerical ranges: "range" <symbol> <symbol> ["if" <expr>] 116- numerical ranges: "range" <symbol> <symbol> ["if" <expr>]
118 This allows to limit the range of possible input values for int 117 This allows to limit the range of possible input values for int
@@ -268,7 +267,7 @@ separate list of options.
268 267
269choices: 268choices:
270 269
271 "choice" 270 "choice" [symbol]
272 <choice options> 271 <choice options>
273 <choice block> 272 <choice block>
274 "endchoice" 273 "endchoice"
@@ -282,6 +281,10 @@ single driver can be compiled/loaded into the kernel, but all drivers
282can be compiled as modules. 281can be compiled as modules.
283A choice accepts another option "optional", which allows to set the 282A choice accepts another option "optional", which allows to set the
284choice to 'n' and no entry needs to be selected. 283choice to 'n' and no entry needs to be selected.
284If no [symbol] is associated with a choice, then you can not have multiple
285definitions of that choice. If a [symbol] is associated to the choice,
286then you may define the same choice (ie. with the same entries) in another
287place.
285 288
286comment: 289comment:
287 290
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index 0ef00bd6e54d..86e3cd0d26a0 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -1136,6 +1136,21 @@ When kbuild executes, the following steps are followed (roughly):
1136 resulting in the target file being recompiled for no 1136 resulting in the target file being recompiled for no
1137 obvious reason. 1137 obvious reason.
1138 1138
1139 dtc
1140 Create flattend device tree blob object suitable for linking
1141 into vmlinux. Device tree blobs linked into vmlinux are placed
1142 in an init section in the image. Platform code *must* copy the
1143 blob to non-init memory prior to calling unflatten_device_tree().
1144
1145 Example:
1146 #arch/x86/platform/ce4100/Makefile
1147 clean-files := *dtb.S
1148
1149 DTC_FLAGS := -p 1024
1150 obj-y += foo.dtb.o
1151
1152 $(obj)/%.dtb: $(src)/%.dts
1153 $(call cmd,dtc)
1139 1154
1140--- 6.7 Custom kbuild commands 1155--- 6.7 Custom kbuild commands
1141 1156
diff --git a/Documentation/make/headers_install.txt b/Documentation/make/headers_install.txt
index f2481cabffcb..951eb9f1e040 100644
--- a/Documentation/make/headers_install.txt
+++ b/Documentation/make/headers_install.txt
@@ -39,8 +39,9 @@ INSTALL_HDR_PATH indicates where to install the headers. It defaults to
39The command "make headers_install_all" exports headers for all architectures 39The command "make headers_install_all" exports headers for all architectures
40simultaneously. (This is mostly of interest to distribution maintainers, 40simultaneously. (This is mostly of interest to distribution maintainers,
41who create an architecture-independent tarball from the resulting include 41who create an architecture-independent tarball from the resulting include
42directory.) Remember to provide the appropriate linux/asm directory via "mv" 42directory.) You also can use HDR_ARCH_LIST to specify list of architectures.
43or "ln -s" before building a C library with headers exported this way. 43Remember to provide the appropriate linux/asm directory via "mv" or "ln -s"
44before building a C library with headers exported this way.
44 45
45The kernel header export infrastructure is maintained by David Woodhouse 46The kernel header export infrastructure is maintained by David Woodhouse
46<dwmw2@infradead.org>. 47<dwmw2@infradead.org>.
diff --git a/Documentation/power/drivers-testing.txt b/Documentation/power/drivers-testing.txt
index 7f7a737f7f9f..638afdf4d6b8 100644
--- a/Documentation/power/drivers-testing.txt
+++ b/Documentation/power/drivers-testing.txt
@@ -23,10 +23,10 @@ Once you have resolved the suspend/resume-related problems with your test system
23without the new driver, you are ready to test it: 23without the new driver, you are ready to test it:
24 24
25a) Build the driver as a module, load it and try the test modes of hibernation 25a) Build the driver as a module, load it and try the test modes of hibernation
26 (see: Documents/power/basic-pm-debugging.txt, 1). 26 (see: Documentation/power/basic-pm-debugging.txt, 1).
27 27
28b) Load the driver and attempt to hibernate in the "reboot", "shutdown" and 28b) Load the driver and attempt to hibernate in the "reboot", "shutdown" and
29 "platform" modes (see: Documents/power/basic-pm-debugging.txt, 1). 29 "platform" modes (see: Documentation/power/basic-pm-debugging.txt, 1).
30 30
31c) Compile the driver directly into the kernel and try the test modes of 31c) Compile the driver directly into the kernel and try the test modes of
32 hibernation. 32 hibernation.
@@ -34,12 +34,12 @@ c) Compile the driver directly into the kernel and try the test modes of
34d) Attempt to hibernate with the driver compiled directly into the kernel 34d) Attempt to hibernate with the driver compiled directly into the kernel
35 in the "reboot", "shutdown" and "platform" modes. 35 in the "reboot", "shutdown" and "platform" modes.
36 36
37e) Try the test modes of suspend (see: Documents/power/basic-pm-debugging.txt, 37e) Try the test modes of suspend (see: Documentation/power/basic-pm-debugging.txt,
38 2). [As far as the STR tests are concerned, it should not matter whether or 38 2). [As far as the STR tests are concerned, it should not matter whether or
39 not the driver is built as a module.] 39 not the driver is built as a module.]
40 40
41f) Attempt to suspend to RAM using the s2ram tool with the driver loaded 41f) Attempt to suspend to RAM using the s2ram tool with the driver loaded
42 (see: Documents/power/basic-pm-debugging.txt, 2). 42 (see: Documentation/power/basic-pm-debugging.txt, 2).
43 43
44Each of the above tests should be repeated several times and the STD tests 44Each of the above tests should be repeated several times and the STD tests
45should be mixed with the STR tests. If any of them fails, the driver cannot be 45should be mixed with the STR tests. If any of them fails, the driver cannot be
diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt
index 41cc7b30d7dd..ffe55ffa540a 100644
--- a/Documentation/power/runtime_pm.txt
+++ b/Documentation/power/runtime_pm.txt
@@ -50,6 +50,15 @@ type's callbacks are not defined) of given device. The bus type, device type
50and device class callbacks are referred to as subsystem-level callbacks in what 50and device class callbacks are referred to as subsystem-level callbacks in what
51follows. 51follows.
52 52
53By default, the callbacks are always invoked in process context with interrupts
54enabled. However, subsystems can use the pm_runtime_irq_safe() helper function
55to tell the PM core that a device's ->runtime_suspend() and ->runtime_resume()
56callbacks should be invoked in atomic context with interrupts disabled
57(->runtime_idle() is still invoked the default way). This implies that these
58callback routines must not block or sleep, but it also means that the
59synchronous helper functions listed at the end of Section 4 can be used within
60an interrupt handler or in an atomic context.
61
53The subsystem-level suspend callback is _entirely_ _responsible_ for handling 62The subsystem-level suspend callback is _entirely_ _responsible_ for handling
54the suspend of the device as appropriate, which may, but need not include 63the suspend of the device as appropriate, which may, but need not include
55executing the device driver's own ->runtime_suspend() callback (from the 64executing the device driver's own ->runtime_suspend() callback (from the
@@ -237,6 +246,10 @@ defined in include/linux/pm.h:
237 Section 8); it may be modified only by the pm_runtime_no_callbacks() 246 Section 8); it may be modified only by the pm_runtime_no_callbacks()
238 helper function 247 helper function
239 248
249 unsigned int irq_safe;
250 - indicates that the ->runtime_suspend() and ->runtime_resume() callbacks
251 will be invoked with the spinlock held and interrupts disabled
252
240 unsigned int use_autosuspend; 253 unsigned int use_autosuspend;
241 - indicates that the device's driver supports delayed autosuspend (see 254 - indicates that the device's driver supports delayed autosuspend (see
242 Section 9); it may be modified only by the 255 Section 9); it may be modified only by the
@@ -344,6 +357,10 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
344 - decrement the device's usage counter; if the result is 0 then run 357 - decrement the device's usage counter; if the result is 0 then run
345 pm_runtime_idle(dev) and return its result 358 pm_runtime_idle(dev) and return its result
346 359
360 int pm_runtime_put_sync_suspend(struct device *dev);
361 - decrement the device's usage counter; if the result is 0 then run
362 pm_runtime_suspend(dev) and return its result
363
347 int pm_runtime_put_sync_autosuspend(struct device *dev); 364 int pm_runtime_put_sync_autosuspend(struct device *dev);
348 - decrement the device's usage counter; if the result is 0 then run 365 - decrement the device's usage counter; if the result is 0 then run
349 pm_runtime_autosuspend(dev) and return its result 366 pm_runtime_autosuspend(dev) and return its result
@@ -397,6 +414,11 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
397 PM attributes from /sys/devices/.../power (or prevent them from being 414 PM attributes from /sys/devices/.../power (or prevent them from being
398 added when the device is registered) 415 added when the device is registered)
399 416
417 void pm_runtime_irq_safe(struct device *dev);
418 - set the power.irq_safe flag for the device, causing the runtime-PM
419 suspend and resume callbacks (but not the idle callback) to be invoked
420 with interrupts disabled
421
400 void pm_runtime_mark_last_busy(struct device *dev); 422 void pm_runtime_mark_last_busy(struct device *dev);
401 - set the power.last_busy field to the current time 423 - set the power.last_busy field to the current time
402 424
@@ -438,6 +460,15 @@ pm_runtime_suspended()
438pm_runtime_mark_last_busy() 460pm_runtime_mark_last_busy()
439pm_runtime_autosuspend_expiration() 461pm_runtime_autosuspend_expiration()
440 462
463If pm_runtime_irq_safe() has been called for a device then the following helper
464functions may also be used in interrupt context:
465
466pm_runtime_suspend()
467pm_runtime_autosuspend()
468pm_runtime_resume()
469pm_runtime_get_sync()
470pm_runtime_put_sync_suspend()
471
4415. Run-time PM Initialization, Device Probing and Removal 4725. Run-time PM Initialization, Device Probing and Removal
442 473
443Initially, the run-time PM is disabled for all devices, which means that the 474Initially, the run-time PM is disabled for all devices, which means that the
diff --git a/Documentation/powerpc/dts-bindings/eeprom.txt b/Documentation/powerpc/dts-bindings/eeprom.txt
new file mode 100644
index 000000000000..4342c10de1bf
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/eeprom.txt
@@ -0,0 +1,28 @@
1EEPROMs (I2C)
2
3Required properties:
4
5 - compatible : should be "<manufacturer>,<type>"
6 If there is no specific driver for <manufacturer>, a generic
7 driver based on <type> is selected. Possible types are:
8 24c00, 24c01, 24c02, 24c04, 24c08, 24c16, 24c32, 24c64,
9 24c128, 24c256, 24c512, 24c1024, spd
10
11 - reg : the I2C address of the EEPROM
12
13Optional properties:
14
15 - pagesize : the length of the pagesize for writing. Please consult the
16 manual of your device, that value varies a lot. A wrong value
17 may result in data loss! If not specified, a safety value of
18 '1' is used which will be very slow.
19
20 - read-only: this parameterless property disables writes to the eeprom
21
22Example:
23
24eeprom@52 {
25 compatible = "atmel,24c32";
26 reg = <0x52>;
27 pagesize = <32>;
28};
diff --git a/Documentation/vm/Makefile b/Documentation/vm/Makefile
index 9dcff328b964..3fa4d0668864 100644
--- a/Documentation/vm/Makefile
+++ b/Documentation/vm/Makefile
@@ -2,7 +2,7 @@
2obj- := dummy.o 2obj- := dummy.o
3 3
4# List of programs to build 4# List of programs to build
5hostprogs-y := slabinfo page-types hugepage-mmap hugepage-shm map_hugetlb 5hostprogs-y := page-types hugepage-mmap hugepage-shm map_hugetlb
6 6
7# Tell kbuild to always build the programs 7# Tell kbuild to always build the programs
8always := $(hostprogs-y) 8always := $(hostprogs-y)
diff --git a/MAINTAINERS b/MAINTAINERS
index 23d04363a195..03c516a1edfa 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4268,6 +4268,7 @@ NILFS2 FILESYSTEM
4268M: KONISHI Ryusuke <konishi.ryusuke@lab.ntt.co.jp> 4268M: KONISHI Ryusuke <konishi.ryusuke@lab.ntt.co.jp>
4269L: linux-nilfs@vger.kernel.org 4269L: linux-nilfs@vger.kernel.org
4270W: http://www.nilfs.org/en/ 4270W: http://www.nilfs.org/en/
4271T: git git://git.kernel.org/pub/scm/linux/kernel/git/ryusuke/nilfs2.git
4271S: Supported 4272S: Supported
4272F: Documentation/filesystems/nilfs2.txt 4273F: Documentation/filesystems/nilfs2.txt
4273F: fs/nilfs2/ 4274F: fs/nilfs2/
diff --git a/Makefile b/Makefile
index 74b25559f831..6a457690d10b 100644
--- a/Makefile
+++ b/Makefile
@@ -224,6 +224,7 @@ ifeq ($(ARCH),m68knommu)
224endif 224endif
225 225
226KCONFIG_CONFIG ?= .config 226KCONFIG_CONFIG ?= .config
227export KCONFIG_CONFIG
227 228
228# SHELL used by kbuild 229# SHELL used by kbuild
229CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ 230CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
diff --git a/arch/arm/plat-s3c24xx/cpu-freq.c b/arch/arm/plat-s3c24xx/cpu-freq.c
index 1ecc15bfe9d4..25a8fc7f512e 100644
--- a/arch/arm/plat-s3c24xx/cpu-freq.c
+++ b/arch/arm/plat-s3c24xx/cpu-freq.c
@@ -21,7 +21,6 @@
21#include <linux/err.h> 21#include <linux/err.h>
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/sysdev.h> 23#include <linux/sysdev.h>
24#include <linux/kobject.h>
25#include <linux/sysfs.h> 24#include <linux/sysfs.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
27 26
diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig
index 387d5ffdfd3a..5f5018a71a3d 100644
--- a/arch/microblaze/Kconfig
+++ b/arch/microblaze/Kconfig
@@ -14,7 +14,7 @@ config MICROBLAZE
14 select HAVE_DMA_API_DEBUG 14 select HAVE_DMA_API_DEBUG
15 select TRACING_SUPPORT 15 select TRACING_SUPPORT
16 select OF 16 select OF
17 select OF_FLATTREE 17 select OF_EARLY_FLATTREE
18 18
19config SWAP 19config SWAP
20 def_bool n 20 def_bool n
diff --git a/arch/microblaze/boot/Makefile b/arch/microblaze/boot/Makefile
index be01d78750d9..4c4e58ef0cb6 100644
--- a/arch/microblaze/boot/Makefile
+++ b/arch/microblaze/boot/Makefile
@@ -10,9 +10,6 @@ targets := linux.bin linux.bin.gz simpleImage.%
10 10
11OBJCOPYFLAGS := -O binary 11OBJCOPYFLAGS := -O binary
12 12
13# Where the DTS files live
14dtstree := $(srctree)/$(src)/dts
15
16# Ensure system.dtb exists 13# Ensure system.dtb exists
17$(obj)/linked_dtb.o: $(obj)/system.dtb 14$(obj)/linked_dtb.o: $(obj)/system.dtb
18 15
@@ -51,14 +48,11 @@ $(obj)/simpleImage.%: vmlinux FORCE
51 $(call if_changed,strip) 48 $(call if_changed,strip)
52 @echo 'Kernel: $@ is ready' ' (#'`cat .version`')' 49 @echo 'Kernel: $@ is ready' ' (#'`cat .version`')'
53 50
54# Rule to build device tree blobs
55DTC = $(objtree)/scripts/dtc/dtc
56 51
57# Rule to build device tree blobs 52# Rule to build device tree blobs
58quiet_cmd_dtc = DTC $@ 53DTC_FLAGS := -p 1024
59 cmd_dtc = $(DTC) -O dtb -o $(obj)/$*.dtb -b 0 -p 1024 $(dtstree)/$*.dts
60 54
61$(obj)/%.dtb: $(dtstree)/%.dts FORCE 55$(obj)/%.dtb: $(src)/dts/%.dts FORCE
62 $(call if_changed,dtc) 56 $(call cmd,dtc)
63 57
64clean-files += *.dtb simpleImage.*.unstrip linux.bin.ub 58clean-files += *.dtb simpleImage.*.unstrip linux.bin.ub
diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h
index bdc38312ae4a..2e72af078b05 100644
--- a/arch/microblaze/include/asm/prom.h
+++ b/arch/microblaze/include/asm/prom.h
@@ -64,9 +64,6 @@ extern void kdump_move_device_tree(void);
64/* CPU OF node matching */ 64/* CPU OF node matching */
65struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); 65struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
66 66
67/* Get the MAC address */
68extern const void *of_get_mac_address(struct device_node *np);
69
70/** 67/**
71 * of_irq_map_pci - Resolve the interrupt for a PCI device 68 * of_irq_map_pci - Resolve the interrupt for a PCI device
72 * @pdev: the device whose interrupt is to be resolved 69 * @pdev: the device whose interrupt is to be resolved
diff --git a/arch/microblaze/kernel/prom_parse.c b/arch/microblaze/kernel/prom_parse.c
index 99d9b61cccb5..9ae24f4b882b 100644
--- a/arch/microblaze/kernel/prom_parse.c
+++ b/arch/microblaze/kernel/prom_parse.c
@@ -110,41 +110,3 @@ void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
110 cells = prop ? *(u32 *)prop : of_n_size_cells(dn); 110 cells = prop ? *(u32 *)prop : of_n_size_cells(dn);
111 *size = of_read_number(dma_window, cells); 111 *size = of_read_number(dma_window, cells);
112} 112}
113
114/**
115 * Search the device tree for the best MAC address to use. 'mac-address' is
116 * checked first, because that is supposed to contain to "most recent" MAC
117 * address. If that isn't set, then 'local-mac-address' is checked next,
118 * because that is the default address. If that isn't set, then the obsolete
119 * 'address' is checked, just in case we're using an old device tree.
120 *
121 * Note that the 'address' property is supposed to contain a virtual address of
122 * the register set, but some DTS files have redefined that property to be the
123 * MAC address.
124 *
125 * All-zero MAC addresses are rejected, because those could be properties that
126 * exist in the device tree, but were not set by U-Boot. For example, the
127 * DTS could define 'mac-address' and 'local-mac-address', with zero MAC
128 * addresses. Some older U-Boots only initialized 'local-mac-address'. In
129 * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
130 * but is all zeros.
131*/
132const void *of_get_mac_address(struct device_node *np)
133{
134 struct property *pp;
135
136 pp = of_find_property(np, "mac-address", NULL);
137 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
138 return pp->value;
139
140 pp = of_find_property(np, "local-mac-address", NULL);
141 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
142 return pp->value;
143
144 pp = of_find_property(np, "address", NULL);
145 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
146 return pp->value;
147
148 return NULL;
149}
150EXPORT_SYMBOL(of_get_mac_address);
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 0a9b5b8b2a19..f489ec30e071 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2218,7 +2218,7 @@ config SECCOMP
2218config USE_OF 2218config USE_OF
2219 bool "Flattened Device Tree support" 2219 bool "Flattened Device Tree support"
2220 select OF 2220 select OF
2221 select OF_FLATTREE 2221 select OF_EARLY_FLATTREE
2222 help 2222 help
2223 Include support for flattened device tree machine descriptions. 2223 Include support for flattened device tree machine descriptions.
2224 2224
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index e625e9e034ae..48fb4790bfec 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -116,7 +116,7 @@ config PPC
116 bool 116 bool
117 default y 117 default y
118 select OF 118 select OF
119 select OF_FLATTREE 119 select OF_EARLY_FLATTREE
120 select HAVE_FTRACE_MCOUNT_RECORD 120 select HAVE_FTRACE_MCOUNT_RECORD
121 select HAVE_DYNAMIC_FTRACE 121 select HAVE_DYNAMIC_FTRACE
122 select HAVE_FUNCTION_TRACER 122 select HAVE_FUNCTION_TRACER
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index fae8192c8fcc..96deec63bcf3 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -35,7 +35,7 @@ endif
35 35
36BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj) 36BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj)
37 37
38DTS_FLAGS ?= -p 1024 38DTC_FLAGS ?= -p 1024
39 39
40$(obj)/4xx.o: BOOTCFLAGS += -mcpu=405 40$(obj)/4xx.o: BOOTCFLAGS += -mcpu=405
41$(obj)/ebony.o: BOOTCFLAGS += -mcpu=405 41$(obj)/ebony.o: BOOTCFLAGS += -mcpu=405
@@ -332,10 +332,8 @@ $(obj)/treeImage.%: vmlinux $(obj)/%.dtb $(wrapperbits)
332 $(call if_changed,wrap,treeboot-$*,,$(obj)/$*.dtb) 332 $(call if_changed,wrap,treeboot-$*,,$(obj)/$*.dtb)
333 333
334# Rule to build device tree blobs 334# Rule to build device tree blobs
335DTC = $(objtree)/scripts/dtc/dtc 335$(obj)/%.dtb: $(src)/dts/%.dts
336 336 $(call cmd,dtc)
337$(obj)/%.dtb: $(dtstree)/%.dts
338 $(DTC) -O dtb -o $(obj)/$*.dtb -b 0 $(DTS_FLAGS) $(dtstree)/$*.dts
339 337
340# If there isn't a platform selected then just strip the vmlinux. 338# If there isn't a platform selected then just strip the vmlinux.
341ifeq (,$(image-y)) 339ifeq (,$(image-y))
diff --git a/arch/powerpc/boot/dts/bluestone.dts b/arch/powerpc/boot/dts/bluestone.dts
index 9bb3d72c0e5a..2a56a0dbd1f7 100644
--- a/arch/powerpc/boot/dts/bluestone.dts
+++ b/arch/powerpc/boot/dts/bluestone.dts
@@ -33,7 +33,7 @@
33 aliases { 33 aliases {
34 ethernet0 = &EMAC0; 34 ethernet0 = &EMAC0;
35 serial0 = &UART0; 35 serial0 = &UART0;
36 serial1 = &UART1; 36 //serial1 = &UART1; --gcl missing UART1 label
37 }; 37 };
38 38
39 cpus { 39 cpus {
@@ -52,7 +52,7 @@
52 d-cache-size = <32768>; 52 d-cache-size = <32768>;
53 dcr-controller; 53 dcr-controller;
54 dcr-access-method = "native"; 54 dcr-access-method = "native";
55 next-level-cache = <&L2C0>; 55 //next-level-cache = <&L2C0>; --gcl missing L2C0 label
56 }; 56 };
57 }; 57 };
58 58
@@ -142,7 +142,7 @@
142 /*RXEOB*/ 0x7 0x4 142 /*RXEOB*/ 0x7 0x4
143 /*SERR*/ 0x3 0x4 143 /*SERR*/ 0x3 0x4
144 /*TXDE*/ 0x4 0x4 144 /*TXDE*/ 0x4 0x4
145 /*RXDE*/ 0x5 0x4 145 /*RXDE*/ 0x5 0x4>;
146 }; 146 };
147 147
148 POB0: opb { 148 POB0: opb {
@@ -182,7 +182,7 @@
182 reg = <0x001a0000 0x00060000>; 182 reg = <0x001a0000 0x00060000>;
183 }; 183 };
184 }; 184 };
185 } 185 };
186 186
187 UART0: serial@ef600300 { 187 UART0: serial@ef600300 {
188 device_type = "serial"; 188 device_type = "serial";
diff --git a/arch/powerpc/boot/dts/cm5200.dts b/arch/powerpc/boot/dts/cm5200.dts
index dd3860846f15..ad3a4f4a2b04 100644
--- a/arch/powerpc/boot/dts/cm5200.dts
+++ b/arch/powerpc/boot/dts/cm5200.dts
@@ -10,220 +10,74 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13/dts-v1/; 13/include/ "mpc5200b.dtsi"
14 14
15/ { 15/ {
16 model = "schindler,cm5200"; 16 model = "schindler,cm5200";
17 compatible = "schindler,cm5200"; 17 compatible = "schindler,cm5200";
18 #address-cells = <1>;
19 #size-cells = <1>;
20 interrupt-parent = <&mpc5200_pic>;
21
22 cpus {
23 #address-cells = <1>;
24 #size-cells = <0>;
25
26 PowerPC,5200@0 {
27 device_type = "cpu";
28 reg = <0>;
29 d-cache-line-size = <32>;
30 i-cache-line-size = <32>;
31 d-cache-size = <0x4000>; // L1, 16K
32 i-cache-size = <0x4000>; // L1, 16K
33 timebase-frequency = <0>; // from bootloader
34 bus-frequency = <0>; // from bootloader
35 clock-frequency = <0>; // from bootloader
36 };
37 };
38
39 memory {
40 device_type = "memory";
41 reg = <0x00000000 0x04000000>; // 64MB
42 };
43 18
44 soc5200@f0000000 { 19 soc5200@f0000000 {
45 #address-cells = <1>;
46 #size-cells = <1>;
47 compatible = "fsl,mpc5200b-immr";
48 ranges = <0 0xf0000000 0x0000c000>;
49 reg = <0xf0000000 0x00000100>;
50 bus-frequency = <0>; // from bootloader
51 system-frequency = <0>; // from bootloader
52
53 cdm@200 {
54 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
55 reg = <0x200 0x38>;
56 };
57
58 mpc5200_pic: interrupt-controller@500 {
59 // 5200 interrupts are encoded into two levels;
60 interrupt-controller;
61 #interrupt-cells = <3>;
62 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
63 reg = <0x500 0x80>;
64 };
65
66 timer@600 { // General Purpose Timer 20 timer@600 { // General Purpose Timer
67 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
68 reg = <0x600 0x10>;
69 interrupts = <1 9 0>;
70 fsl,has-wdt; 21 fsl,has-wdt;
71 }; 22 };
72 23
73 timer@610 { // General Purpose Timer 24 can@900 {
74 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 25 status = "disabled";
75 reg = <0x610 0x10>;
76 interrupts = <1 10 0>;
77 };
78
79 timer@620 { // General Purpose Timer
80 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
81 reg = <0x620 0x10>;
82 interrupts = <1 11 0>;
83 };
84
85 timer@630 { // General Purpose Timer
86 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
87 reg = <0x630 0x10>;
88 interrupts = <1 12 0>;
89 };
90
91 timer@640 { // General Purpose Timer
92 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
93 reg = <0x640 0x10>;
94 interrupts = <1 13 0>;
95 };
96
97 timer@650 { // General Purpose Timer
98 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
99 reg = <0x650 0x10>;
100 interrupts = <1 14 0>;
101 };
102
103 timer@660 { // General Purpose Timer
104 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
105 reg = <0x660 0x10>;
106 interrupts = <1 15 0>;
107 };
108
109 timer@670 { // General Purpose Timer
110 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
111 reg = <0x670 0x10>;
112 interrupts = <1 16 0>;
113 }; 26 };
114 27
115 rtc@800 { // Real time clock 28 can@980 {
116 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc"; 29 status = "disabled";
117 reg = <0x800 0x100>;
118 interrupts = <1 5 0 1 6 0>;
119 }; 30 };
120 31
121 gpio_simple: gpio@b00 { 32 psc@2000 { // PSC1
122 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio"; 33 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
123 reg = <0xb00 0x40>;
124 interrupts = <1 7 0>;
125 gpio-controller;
126 #gpio-cells = <2>;
127 };
128
129 gpio_wkup: gpio@c00 {
130 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup";
131 reg = <0xc00 0x40>;
132 interrupts = <1 8 0 0 3 0>;
133 gpio-controller;
134 #gpio-cells = <2>;
135 };
136
137 spi@f00 {
138 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi";
139 reg = <0xf00 0x20>;
140 interrupts = <2 13 0 2 14 0>;
141 };
142
143 usb@1000 {
144 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be";
145 reg = <0x1000 0xff>;
146 interrupts = <2 6 0>;
147 };
148
149 dma-controller@1200 {
150 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm";
151 reg = <0x1200 0x80>;
152 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
153 3 4 0 3 5 0 3 6 0 3 7 0
154 3 8 0 3 9 0 3 10 0 3 11 0
155 3 12 0 3 13 0 3 14 0 3 15 0>;
156 }; 34 };
157 35
158 xlb@1f00 { 36 psc@2200 { // PSC2
159 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb"; 37 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
160 reg = <0x1f00 0x100>;
161 }; 38 };
162 39
163 serial@2000 { // PSC1 40 psc@2400 { // PSC3
164 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 41 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
165 reg = <0x2000 0x100>;
166 interrupts = <2 1 0>;
167 }; 42 };
168 43
169 serial@2200 { // PSC2 44 psc@2600 { // PSC4
170 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 45 status = "disabled";
171 reg = <0x2200 0x100>;
172 interrupts = <2 2 0>;
173 }; 46 };
174 47
175 serial@2400 { // PSC3 48 psc@2800 { // PSC5
176 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 49 status = "disabled";
177 reg = <0x2400 0x100>;
178 interrupts = <2 3 0>;
179 }; 50 };
180 51
181 serial@2c00 { // PSC6 52 psc@2c00 { // PSC6
182 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 53 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
183 reg = <0x2c00 0x100>;
184 interrupts = <2 4 0>;
185 }; 54 };
186 55
187 ethernet@3000 { 56 ethernet@3000 {
188 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
189 reg = <0x3000 0x400>;
190 local-mac-address = [ 00 00 00 00 00 00 ];
191 interrupts = <2 5 0>;
192 phy-handle = <&phy0>; 57 phy-handle = <&phy0>;
193 }; 58 };
194 59
195 mdio@3000 { 60 mdio@3000 {
196 #address-cells = <1>;
197 #size-cells = <0>;
198 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
199 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
200 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
201
202 phy0: ethernet-phy@0 { 61 phy0: ethernet-phy@0 {
203 reg = <0>; 62 reg = <0>;
204 }; 63 };
205 }; 64 };
206 65
207 i2c@3d40 { 66 ata@3a00 {
208 #address-cells = <1>; 67 status = "disabled";
209 #size-cells = <0>;
210 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
211 reg = <0x3d40 0x40>;
212 interrupts = <2 16 0>;
213 }; 68 };
214 69
215 sram@8000 { 70 i2c@3d00 {
216 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram"; 71 status = "disabled";
217 reg = <0x8000 0x4000>;
218 }; 72 };
73
219 }; 74 };
220 75
221 localbus { 76 pci@f0000d00 {
222 compatible = "fsl,mpc5200b-lpb","simple-bus"; 77 status = "disabled";
223 #address-cells = <2>; 78 };
224 #size-cells = <1>;
225 ranges = <0 0 0xfc000000 0x2000000>;
226 79
80 localbus {
227 // 16-bit flash device at LocalPlus Bus CS0 81 // 16-bit flash device at LocalPlus Bus CS0
228 flash@0,0 { 82 flash@0,0 {
229 compatible = "cfi-flash"; 83 compatible = "cfi-flash";
diff --git a/arch/powerpc/boot/dts/digsy_mtc.dts b/arch/powerpc/boot/dts/digsy_mtc.dts
index 8e9be6bfe23e..27bd267d631c 100644
--- a/arch/powerpc/boot/dts/digsy_mtc.dts
+++ b/arch/powerpc/boot/dts/digsy_mtc.dts
@@ -11,195 +11,68 @@
11 * option) any later version. 11 * option) any later version.
12 */ 12 */
13 13
14/dts-v1/; 14/include/ "mpc5200b.dtsi"
15 15
16/ { 16/ {
17 model = "intercontrol,digsy-mtc"; 17 model = "intercontrol,digsy-mtc";
18 compatible = "intercontrol,digsy-mtc"; 18 compatible = "intercontrol,digsy-mtc";
19 #address-cells = <1>;
20 #size-cells = <1>;
21 interrupt-parent = <&mpc5200_pic>;
22
23 cpus {
24 #address-cells = <1>;
25 #size-cells = <0>;
26
27 PowerPC,5200@0 {
28 device_type = "cpu";
29 reg = <0>;
30 d-cache-line-size = <32>;
31 i-cache-line-size = <32>;
32 d-cache-size = <0x4000>; // L1, 16K
33 i-cache-size = <0x4000>; // L1, 16K
34 timebase-frequency = <0>; // from bootloader
35 bus-frequency = <0>; // from bootloader
36 clock-frequency = <0>; // from bootloader
37 };
38 };
39 19
40 memory { 20 memory {
41 device_type = "memory";
42 reg = <0x00000000 0x02000000>; // 32MB 21 reg = <0x00000000 0x02000000>; // 32MB
43 }; 22 };
44 23
45 soc5200@f0000000 { 24 soc5200@f0000000 {
46 #address-cells = <1>;
47 #size-cells = <1>;
48 compatible = "fsl,mpc5200b-immr";
49 ranges = <0 0xf0000000 0x0000c000>;
50 reg = <0xf0000000 0x00000100>;
51 bus-frequency = <0>; // from bootloader
52 system-frequency = <0>; // from bootloader
53
54 cdm@200 {
55 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
56 reg = <0x200 0x38>;
57 };
58
59 mpc5200_pic: interrupt-controller@500 {
60 // 5200 interrupts are encoded into two levels;
61 interrupt-controller;
62 #interrupt-cells = <3>;
63 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
64 reg = <0x500 0x80>;
65 };
66
67 timer@600 { // General Purpose Timer 25 timer@600 { // General Purpose Timer
68 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
69 reg = <0x600 0x10>;
70 interrupts = <1 9 0>;
71 fsl,has-wdt; 26 fsl,has-wdt;
72 }; 27 };
73 28
74 timer@610 { // General Purpose Timer 29 rtc@800 {
75 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 30 status = "disabled";
76 reg = <0x610 0x10>;
77 interrupts = <1 10 0>;
78 };
79
80 timer@620 { // General Purpose Timer
81 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
82 reg = <0x620 0x10>;
83 interrupts = <1 11 0>;
84 };
85
86 timer@630 { // General Purpose Timer
87 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
88 reg = <0x630 0x10>;
89 interrupts = <1 12 0>;
90 };
91
92 timer@640 { // General Purpose Timer
93 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
94 reg = <0x640 0x10>;
95 interrupts = <1 13 0>;
96 };
97
98 timer@650 { // General Purpose Timer
99 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
100 reg = <0x650 0x10>;
101 interrupts = <1 14 0>;
102 }; 31 };
103 32
104 timer@660 { // General Purpose Timer 33 can@900 {
105 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 34 status = "disabled";
106 reg = <0x660 0x10>;
107 interrupts = <1 15 0>;
108 }; 35 };
109 36
110 timer@670 { // General Purpose Timer 37 can@980 {
111 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 38 status = "disabled";
112 reg = <0x670 0x10>;
113 interrupts = <1 16 0>;
114 }; 39 };
115 40
116 gpio_simple: gpio@b00 { 41 psc@2000 { // PSC1
117 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio"; 42 status = "disabled";
118 reg = <0xb00 0x40>;
119 interrupts = <1 7 0>;
120 gpio-controller;
121 #gpio-cells = <2>;
122 }; 43 };
123 44
124 gpio_wkup: gpio@c00 { 45 psc@2200 { // PSC2
125 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup"; 46 status = "disabled";
126 reg = <0xc00 0x40>;
127 interrupts = <1 8 0 0 3 0>;
128 gpio-controller;
129 #gpio-cells = <2>;
130 }; 47 };
131 48
132 spi@f00 { 49 psc@2400 { // PSC3
133 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi"; 50 status = "disabled";
134 reg = <0xf00 0x20>;
135 interrupts = <2 13 0 2 14 0>;
136 }; 51 };
137 52
138 usb@1000 { 53 psc@2600 { // PSC4
139 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be"; 54 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
140 reg = <0x1000 0xff>;
141 interrupts = <2 6 0>;
142 };
143
144 dma-controller@1200 {
145 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm";
146 reg = <0x1200 0x80>;
147 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
148 3 4 0 3 5 0 3 6 0 3 7 0
149 3 8 0 3 9 0 3 10 0 3 11 0
150 3 12 0 3 13 0 3 14 0 3 15 0>;
151 };
152
153 xlb@1f00 {
154 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb";
155 reg = <0x1f00 0x100>;
156 }; 55 };
157 56
158 serial@2600 { // PSC4 57 psc@2800 { // PSC5
159 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 58 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
160 reg = <0x2600 0x100>;
161 interrupts = <2 11 0>;
162 }; 59 };
163 60
164 serial@2800 { // PSC5 61 psc@2c00 { // PSC6
165 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 62 status = "disabled";
166 reg = <0x2800 0x100>;
167 interrupts = <2 12 0>;
168 }; 63 };
169 64
170 ethernet@3000 { 65 ethernet@3000 {
171 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
172 reg = <0x3000 0x400>;
173 local-mac-address = [ 00 00 00 00 00 00 ];
174 interrupts = <2 5 0>;
175 phy-handle = <&phy0>; 66 phy-handle = <&phy0>;
176 }; 67 };
177 68
178 mdio@3000 { 69 mdio@3000 {
179 #address-cells = <1>;
180 #size-cells = <0>;
181 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
182 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
183 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
184
185 phy0: ethernet-phy@0 { 70 phy0: ethernet-phy@0 {
186 reg = <0>; 71 reg = <0>;
187 }; 72 };
188 }; 73 };
189 74
190 ata@3a00 {
191 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata";
192 reg = <0x3a00 0x100>;
193 interrupts = <2 7 0>;
194 };
195
196 i2c@3d00 { 75 i2c@3d00 {
197 #address-cells = <1>;
198 #size-cells = <0>;
199 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
200 reg = <0x3d00 0x40>;
201 interrupts = <2 15 0>;
202
203 rtc@50 { 76 rtc@50 {
204 compatible = "at,24c08"; 77 compatible = "at,24c08";
205 reg = <0x50>; 78 reg = <0x50>;
@@ -211,16 +84,16 @@
211 }; 84 };
212 }; 85 };
213 86
214 sram@8000 { 87 i2c@3d40 {
215 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram"; 88 status = "disabled";
216 reg = <0x8000 0x4000>;
217 }; 89 };
218 }; 90 };
219 91
220 lpb { 92 pci@f0000d00 {
221 compatible = "fsl,mpc5200b-lpb","simple-bus"; 93 status = "disabled";
222 #address-cells = <2>; 94 };
223 #size-cells = <1>; 95
96 localbus {
224 ranges = <0 0 0xff000000 0x1000000>; 97 ranges = <0 0 0xff000000 0x1000000>;
225 98
226 // 16-bit flash device at LocalPlus Bus CS0 99 // 16-bit flash device at LocalPlus Bus CS0
diff --git a/arch/powerpc/boot/dts/hotfoot.dts b/arch/powerpc/boot/dts/hotfoot.dts
index cad9c3840afc..71d3bb4931dc 100644
--- a/arch/powerpc/boot/dts/hotfoot.dts
+++ b/arch/powerpc/boot/dts/hotfoot.dts
@@ -117,6 +117,8 @@
117 }; 117 };
118 118
119 IIC: i2c@ef600500 { 119 IIC: i2c@ef600500 {
120 #address-cells = <1>;
121 #size-cells = <0>;
120 compatible = "ibm,iic-405ep", "ibm,iic"; 122 compatible = "ibm,iic-405ep", "ibm,iic";
121 reg = <0xef600500 0x00000011>; 123 reg = <0xef600500 0x00000011>;
122 interrupt-parent = <&UIC0>; 124 interrupt-parent = <&UIC0>;
diff --git a/arch/powerpc/boot/dts/lite5200b.dts b/arch/powerpc/boot/dts/lite5200b.dts
index 59702ace900f..fb288bb882b6 100644
--- a/arch/powerpc/boot/dts/lite5200b.dts
+++ b/arch/powerpc/boot/dts/lite5200b.dts
@@ -10,256 +10,75 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13/dts-v1/; 13/include/ "mpc5200b.dtsi"
14 14
15/ { 15/ {
16 model = "fsl,lite5200b"; 16 model = "fsl,lite5200b";
17 compatible = "fsl,lite5200b"; 17 compatible = "fsl,lite5200b";
18 #address-cells = <1>;
19 #size-cells = <1>;
20 interrupt-parent = <&mpc5200_pic>;
21
22 cpus {
23 #address-cells = <1>;
24 #size-cells = <0>;
25
26 PowerPC,5200@0 {
27 device_type = "cpu";
28 reg = <0>;
29 d-cache-line-size = <32>;
30 i-cache-line-size = <32>;
31 d-cache-size = <0x4000>; // L1, 16K
32 i-cache-size = <0x4000>; // L1, 16K
33 timebase-frequency = <0>; // from bootloader
34 bus-frequency = <0>; // from bootloader
35 clock-frequency = <0>; // from bootloader
36 };
37 };
38 18
39 memory { 19 memory {
40 device_type = "memory";
41 reg = <0x00000000 0x10000000>; // 256MB 20 reg = <0x00000000 0x10000000>; // 256MB
42 }; 21 };
43 22
44 soc5200@f0000000 { 23 soc5200@f0000000 {
45 #address-cells = <1>;
46 #size-cells = <1>;
47 compatible = "fsl,mpc5200b-immr";
48 ranges = <0 0xf0000000 0x0000c000>;
49 reg = <0xf0000000 0x00000100>;
50 bus-frequency = <0>; // from bootloader
51 system-frequency = <0>; // from bootloader
52
53 cdm@200 {
54 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
55 reg = <0x200 0x38>;
56 };
57
58 mpc5200_pic: interrupt-controller@500 {
59 // 5200 interrupts are encoded into two levels;
60 interrupt-controller;
61 #interrupt-cells = <3>;
62 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
63 reg = <0x500 0x80>;
64 };
65
66 timer@600 { // General Purpose Timer 24 timer@600 { // General Purpose Timer
67 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
68 reg = <0x600 0x10>;
69 interrupts = <1 9 0>;
70 fsl,has-wdt; 25 fsl,has-wdt;
71 }; 26 };
72 27
73 timer@610 { // General Purpose Timer 28 psc@2000 { // PSC1
74 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 29 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
75 reg = <0x610 0x10>; 30 cell-index = <0>;
76 interrupts = <1 10 0>;
77 };
78
79 timer@620 { // General Purpose Timer
80 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
81 reg = <0x620 0x10>;
82 interrupts = <1 11 0>;
83 };
84
85 timer@630 { // General Purpose Timer
86 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
87 reg = <0x630 0x10>;
88 interrupts = <1 12 0>;
89 };
90
91 timer@640 { // General Purpose Timer
92 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
93 reg = <0x640 0x10>;
94 interrupts = <1 13 0>;
95 };
96
97 timer@650 { // General Purpose Timer
98 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
99 reg = <0x650 0x10>;
100 interrupts = <1 14 0>;
101 };
102
103 timer@660 { // General Purpose Timer
104 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
105 reg = <0x660 0x10>;
106 interrupts = <1 15 0>;
107 };
108
109 timer@670 { // General Purpose Timer
110 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
111 reg = <0x670 0x10>;
112 interrupts = <1 16 0>;
113 };
114
115 rtc@800 { // Real time clock
116 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc";
117 reg = <0x800 0x100>;
118 interrupts = <1 5 0 1 6 0>;
119 };
120
121 can@900 {
122 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
123 interrupts = <2 17 0>;
124 reg = <0x900 0x80>;
125 };
126
127 can@980 {
128 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
129 interrupts = <2 18 0>;
130 reg = <0x980 0x80>;
131 };
132
133 gpio_simple: gpio@b00 {
134 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio";
135 reg = <0xb00 0x40>;
136 interrupts = <1 7 0>;
137 gpio-controller;
138 #gpio-cells = <2>;
139 };
140
141 gpio_wkup: gpio@c00 {
142 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup";
143 reg = <0xc00 0x40>;
144 interrupts = <1 8 0 0 3 0>;
145 gpio-controller;
146 #gpio-cells = <2>;
147 }; 31 };
148 32
149 spi@f00 { 33 psc@2200 { // PSC2
150 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi"; 34 status = "disabled";
151 reg = <0xf00 0x20>;
152 interrupts = <2 13 0 2 14 0>;
153 }; 35 };
154 36
155 usb@1000 { 37 psc@2400 { // PSC3
156 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be"; 38 status = "disabled";
157 reg = <0x1000 0xff>;
158 interrupts = <2 6 0>;
159 }; 39 };
160 40
161 dma-controller@1200 { 41 psc@2600 { // PSC4
162 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm"; 42 status = "disabled";
163 reg = <0x1200 0x80>;
164 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
165 3 4 0 3 5 0 3 6 0 3 7 0
166 3 8 0 3 9 0 3 10 0 3 11 0
167 3 12 0 3 13 0 3 14 0 3 15 0>;
168 }; 43 };
169 44
170 xlb@1f00 { 45 psc@2800 { // PSC5
171 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb"; 46 status = "disabled";
172 reg = <0x1f00 0x100>;
173 }; 47 };
174 48
175 serial@2000 { // PSC1 49 psc@2c00 { // PSC6
176 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 50 status = "disabled";
177 cell-index = <0>;
178 reg = <0x2000 0x100>;
179 interrupts = <2 1 0>;
180 }; 51 };
181 52
182 // PSC2 in ac97 mode example 53 // PSC2 in ac97 mode example
183 //ac97@2200 { // PSC2 54 //ac97@2200 { // PSC2
184 // compatible = "fsl,mpc5200b-psc-ac97","fsl,mpc5200-psc-ac97"; 55 // compatible = "fsl,mpc5200b-psc-ac97","fsl,mpc5200-psc-ac97";
185 // cell-index = <1>; 56 // cell-index = <1>;
186 // reg = <0x2200 0x100>;
187 // interrupts = <2 2 0>;
188 //}; 57 //};
189 58
190 // PSC3 in CODEC mode example 59 // PSC3 in CODEC mode example
191 //i2s@2400 { // PSC3 60 //i2s@2400 { // PSC3
192 // compatible = "fsl,mpc5200b-psc-i2s"; //not 5200 compatible 61 // compatible = "fsl,mpc5200b-psc-i2s"; //not 5200 compatible
193 // cell-index = <2>; 62 // cell-index = <2>;
194 // reg = <0x2400 0x100>;
195 // interrupts = <2 3 0>;
196 //};
197
198 // PSC4 in uart mode example
199 //serial@2600 { // PSC4
200 // compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
201 // cell-index = <3>;
202 // reg = <0x2600 0x100>;
203 // interrupts = <2 11 0>;
204 //};
205
206 // PSC5 in uart mode example
207 //serial@2800 { // PSC5
208 // compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
209 // cell-index = <4>;
210 // reg = <0x2800 0x100>;
211 // interrupts = <2 12 0>;
212 //}; 63 //};
213 64
214 // PSC6 in spi mode example 65 // PSC6 in spi mode example
215 //spi@2c00 { // PSC6 66 //spi@2c00 { // PSC6
216 // compatible = "fsl,mpc5200b-psc-spi","fsl,mpc5200-psc-spi"; 67 // compatible = "fsl,mpc5200b-psc-spi","fsl,mpc5200-psc-spi";
217 // cell-index = <5>; 68 // cell-index = <5>;
218 // reg = <0x2c00 0x100>;
219 // interrupts = <2 4 0>;
220 //}; 69 //};
221 70
222 ethernet@3000 { 71 ethernet@3000 {
223 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
224 reg = <0x3000 0x400>;
225 local-mac-address = [ 00 00 00 00 00 00 ];
226 interrupts = <2 5 0>;
227 phy-handle = <&phy0>; 72 phy-handle = <&phy0>;
228 }; 73 };
229 74
230 mdio@3000 { 75 mdio@3000 {
231 #address-cells = <1>;
232 #size-cells = <0>;
233 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
234 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
235 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
236
237 phy0: ethernet-phy@0 { 76 phy0: ethernet-phy@0 {
238 reg = <0>; 77 reg = <0>;
239 }; 78 };
240 }; 79 };
241 80
242 ata@3a00 {
243 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata";
244 reg = <0x3a00 0x100>;
245 interrupts = <2 7 0>;
246 };
247
248 i2c@3d00 {
249 #address-cells = <1>;
250 #size-cells = <0>;
251 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
252 reg = <0x3d00 0x40>;
253 interrupts = <2 15 0>;
254 };
255
256 i2c@3d40 { 81 i2c@3d40 {
257 #address-cells = <1>;
258 #size-cells = <0>;
259 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
260 reg = <0x3d40 0x40>;
261 interrupts = <2 16 0>;
262
263 eeprom@50 { 82 eeprom@50 {
264 compatible = "atmel,24c02"; 83 compatible = "atmel,24c02";
265 reg = <0x50>; 84 reg = <0x50>;
@@ -273,12 +92,6 @@
273 }; 92 };
274 93
275 pci@f0000d00 { 94 pci@f0000d00 {
276 #interrupt-cells = <1>;
277 #size-cells = <2>;
278 #address-cells = <3>;
279 device_type = "pci";
280 compatible = "fsl,mpc5200b-pci","fsl,mpc5200-pci";
281 reg = <0xf0000d00 0x100>;
282 interrupt-map-mask = <0xf800 0 0 7>; 95 interrupt-map-mask = <0xf800 0 0 7>;
283 interrupt-map = <0xc000 0 0 1 &mpc5200_pic 0 0 3 // 1st slot 96 interrupt-map = <0xc000 0 0 1 &mpc5200_pic 0 0 3 // 1st slot
284 0xc000 0 0 2 &mpc5200_pic 1 1 3 97 0xc000 0 0 2 &mpc5200_pic 1 1 3
@@ -298,11 +111,6 @@
298 }; 111 };
299 112
300 localbus { 113 localbus {
301 compatible = "fsl,mpc5200b-lpb","fsl,mpc5200-lpb","simple-bus";
302
303 #address-cells = <2>;
304 #size-cells = <1>;
305
306 ranges = <0 0 0xfe000000 0x02000000>; 114 ranges = <0 0 0xfe000000 0x02000000>;
307 115
308 flash@0,0 { 116 flash@0,0 {
diff --git a/arch/powerpc/boot/dts/media5200.dts b/arch/powerpc/boot/dts/media5200.dts
index 0c3902bc5b6a..48d72f38e5ed 100644
--- a/arch/powerpc/boot/dts/media5200.dts
+++ b/arch/powerpc/boot/dts/media5200.dts
@@ -11,14 +11,11 @@
11 * option) any later version. 11 * option) any later version.
12 */ 12 */
13 13
14/dts-v1/; 14/include/ "mpc5200b.dtsi"
15 15
16/ { 16/ {
17 model = "fsl,media5200"; 17 model = "fsl,media5200";
18 compatible = "fsl,media5200"; 18 compatible = "fsl,media5200";
19 #address-cells = <1>;
20 #size-cells = <1>;
21 interrupt-parent = <&mpc5200_pic>;
22 19
23 aliases { 20 aliases {
24 console = &console; 21 console = &console;
@@ -30,16 +27,7 @@
30 }; 27 };
31 28
32 cpus { 29 cpus {
33 #address-cells = <1>;
34 #size-cells = <0>;
35
36 PowerPC,5200@0 { 30 PowerPC,5200@0 {
37 device_type = "cpu";
38 reg = <0>;
39 d-cache-line-size = <32>;
40 i-cache-line-size = <32>;
41 d-cache-size = <0x4000>; // L1, 16K
42 i-cache-size = <0x4000>; // L1, 16K
43 timebase-frequency = <33000000>; // 33 MHz, these were configured by U-Boot 31 timebase-frequency = <33000000>; // 33 MHz, these were configured by U-Boot
44 bus-frequency = <132000000>; // 132 MHz 32 bus-frequency = <132000000>; // 132 MHz
45 clock-frequency = <396000000>; // 396 MHz 33 clock-frequency = <396000000>; // 396 MHz
@@ -47,205 +35,57 @@
47 }; 35 };
48 36
49 memory { 37 memory {
50 device_type = "memory";
51 reg = <0x00000000 0x08000000>; // 128MB RAM 38 reg = <0x00000000 0x08000000>; // 128MB RAM
52 }; 39 };
53 40
54 soc@f0000000 { 41 soc5200@f0000000 {
55 #address-cells = <1>;
56 #size-cells = <1>;
57 compatible = "fsl,mpc5200b-immr";
58 ranges = <0 0xf0000000 0x0000c000>;
59 reg = <0xf0000000 0x00000100>;
60 bus-frequency = <132000000>;// 132 MHz 42 bus-frequency = <132000000>;// 132 MHz
61 system-frequency = <0>; // from bootloader
62
63 cdm@200 {
64 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
65 reg = <0x200 0x38>;
66 };
67
68 mpc5200_pic: interrupt-controller@500 {
69 // 5200 interrupts are encoded into two levels;
70 interrupt-controller;
71 #interrupt-cells = <3>;
72 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
73 reg = <0x500 0x80>;
74 };
75 43
76 timer@600 { // General Purpose Timer 44 timer@600 { // General Purpose Timer
77 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
78 reg = <0x600 0x10>;
79 interrupts = <1 9 0>;
80 fsl,has-wdt; 45 fsl,has-wdt;
81 }; 46 };
82 47
83 timer@610 { // General Purpose Timer 48 psc@2000 { // PSC1
84 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 49 status = "disabled";
85 reg = <0x610 0x10>;
86 interrupts = <1 10 0>;
87 };
88
89 timer@620 { // General Purpose Timer
90 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
91 reg = <0x620 0x10>;
92 interrupts = <1 11 0>;
93 };
94
95 timer@630 { // General Purpose Timer
96 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
97 reg = <0x630 0x10>;
98 interrupts = <1 12 0>;
99 };
100
101 timer@640 { // General Purpose Timer
102 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
103 reg = <0x640 0x10>;
104 interrupts = <1 13 0>;
105 };
106
107 timer@650 { // General Purpose Timer
108 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
109 reg = <0x650 0x10>;
110 interrupts = <1 14 0>;
111 };
112
113 timer@660 { // General Purpose Timer
114 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
115 reg = <0x660 0x10>;
116 interrupts = <1 15 0>;
117 };
118
119 timer@670 { // General Purpose Timer
120 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
121 reg = <0x670 0x10>;
122 interrupts = <1 16 0>;
123 };
124
125 rtc@800 { // Real time clock
126 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc";
127 reg = <0x800 0x100>;
128 interrupts = <1 5 0 1 6 0>;
129 };
130
131 can@900 {
132 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
133 interrupts = <2 17 0>;
134 reg = <0x900 0x80>;
135 }; 50 };
136 51
137 can@980 { 52 psc@2200 { // PSC2
138 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan"; 53 status = "disabled";
139 interrupts = <2 18 0>;
140 reg = <0x980 0x80>;
141 }; 54 };
142 55
143 gpio_simple: gpio@b00 { 56 psc@2400 { // PSC3
144 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio"; 57 status = "disabled";
145 reg = <0xb00 0x40>;
146 interrupts = <1 7 0>;
147 gpio-controller;
148 #gpio-cells = <2>;
149 }; 58 };
150 59
151 gpio_wkup: gpio@c00 { 60 psc@2600 { // PSC4
152 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup"; 61 status = "disabled";
153 reg = <0xc00 0x40>;
154 interrupts = <1 8 0 0 3 0>;
155 gpio-controller;
156 #gpio-cells = <2>;
157 }; 62 };
158 63
159 spi@f00 { 64 psc@2800 { // PSC5
160 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi"; 65 status = "disabled";
161 reg = <0xf00 0x20>;
162 interrupts = <2 13 0 2 14 0>;
163 };
164
165 usb@1000 {
166 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be";
167 reg = <0x1000 0x100>;
168 interrupts = <2 6 0>;
169 };
170
171 dma-controller@1200 {
172 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm";
173 reg = <0x1200 0x80>;
174 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
175 3 4 0 3 5 0 3 6 0 3 7 0
176 3 8 0 3 9 0 3 10 0 3 11 0
177 3 12 0 3 13 0 3 14 0 3 15 0>;
178 };
179
180 xlb@1f00 {
181 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb";
182 reg = <0x1f00 0x100>;
183 }; 66 };
184 67
185 // PSC6 in uart mode 68 // PSC6 in uart mode
186 console: serial@2c00 { // PSC6 69 console: psc@2c00 { // PSC6
187 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 70 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
188 cell-index = <5>;
189 port-number = <0>; // Logical port assignment
190 reg = <0x2c00 0x100>;
191 interrupts = <2 4 0>;
192 }; 71 };
193 72
194 eth0: ethernet@3000 { 73 ethernet@3000 {
195 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
196 reg = <0x3000 0x400>;
197 local-mac-address = [ 00 00 00 00 00 00 ];
198 interrupts = <2 5 0>;
199 phy-handle = <&phy0>; 74 phy-handle = <&phy0>;
200 }; 75 };
201 76
202 mdio@3000 { 77 mdio@3000 {
203 #address-cells = <1>;
204 #size-cells = <0>;
205 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
206 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
207 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
208
209 phy0: ethernet-phy@0 { 78 phy0: ethernet-phy@0 {
210 reg = <0>; 79 reg = <0>;
211 }; 80 };
212 }; 81 };
213 82
214 ata@3a00 { 83 usb@1000 {
215 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata"; 84 reg = <0x1000 0x100>;
216 reg = <0x3a00 0x100>;
217 interrupts = <2 7 0>;
218 };
219
220 i2c@3d00 {
221 #address-cells = <1>;
222 #size-cells = <0>;
223 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
224 reg = <0x3d00 0x40>;
225 interrupts = <2 15 0>;
226 };
227
228 i2c@3d40 {
229 #address-cells = <1>;
230 #size-cells = <0>;
231 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
232 reg = <0x3d40 0x40>;
233 interrupts = <2 16 0>;
234 };
235
236 sram@8000 {
237 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram";
238 reg = <0x8000 0x4000>;
239 }; 85 };
240 }; 86 };
241 87
242 pci@f0000d00 { 88 pci@f0000d00 {
243 #interrupt-cells = <1>;
244 #size-cells = <2>;
245 #address-cells = <3>;
246 device_type = "pci";
247 compatible = "fsl,mpc5200b-pci","fsl,mpc5200-pci";
248 reg = <0xf0000d00 0x100>;
249 interrupt-map-mask = <0xf800 0 0 7>; 89 interrupt-map-mask = <0xf800 0 0 7>;
250 interrupt-map = <0xc000 0 0 1 &media5200_fpga 0 2 // 1st slot 90 interrupt-map = <0xc000 0 0 1 &media5200_fpga 0 2 // 1st slot
251 0xc000 0 0 2 &media5200_fpga 0 3 91 0xc000 0 0 2 &media5200_fpga 0 3
@@ -262,37 +102,29 @@
262 102
263 0xe000 0 0 1 &media5200_fpga 0 5 // CoralIP 103 0xe000 0 0 1 &media5200_fpga 0 5 // CoralIP
264 >; 104 >;
265 clock-frequency = <0>; // From boot loader
266 interrupts = <2 8 0 2 9 0 2 10 0>;
267 interrupt-parent = <&mpc5200_pic>;
268 bus-range = <0 0>;
269 ranges = <0x42000000 0 0x80000000 0x80000000 0 0x20000000 105 ranges = <0x42000000 0 0x80000000 0x80000000 0 0x20000000
270 0x02000000 0 0xa0000000 0xa0000000 0 0x10000000 106 0x02000000 0 0xa0000000 0xa0000000 0 0x10000000
271 0x01000000 0 0x00000000 0xb0000000 0 0x01000000>; 107 0x01000000 0 0x00000000 0xb0000000 0 0x01000000>;
108 interrupt-parent = <&mpc5200_pic>;
272 }; 109 };
273 110
274 localbus { 111 localbus {
275 compatible = "fsl,mpc5200b-lpb","simple-bus";
276 #address-cells = <2>;
277 #size-cells = <1>;
278
279 ranges = < 0 0 0xfc000000 0x02000000 112 ranges = < 0 0 0xfc000000 0x02000000
280 1 0 0xfe000000 0x02000000 113 1 0 0xfe000000 0x02000000
281 2 0 0xf0010000 0x00010000 114 2 0 0xf0010000 0x00010000
282 3 0 0xf0020000 0x00010000 >; 115 3 0 0xf0020000 0x00010000 >;
283
284 flash@0,0 { 116 flash@0,0 {
285 compatible = "amd,am29lv28ml", "cfi-flash"; 117 compatible = "amd,am29lv28ml", "cfi-flash";
286 reg = <0 0x0 0x2000000>; // 32 MB 118 reg = <0 0x0 0x2000000>; // 32 MB
287 bank-width = <4>; // Width in bytes of the flash bank 119 bank-width = <4>; // Width in bytes of the flash bank
288 device-width = <2>; // Two devices on each bank 120 device-width = <2>; // Two devices on each bank
289 }; 121 };
290 122
291 flash@1,0 { 123 flash@1,0 {
292 compatible = "amd,am29lv28ml", "cfi-flash"; 124 compatible = "amd,am29lv28ml", "cfi-flash";
293 reg = <1 0 0x2000000>; // 32 MB 125 reg = <1 0 0x2000000>; // 32 MB
294 bank-width = <4>; // Width in bytes of the flash bank 126 bank-width = <4>; // Width in bytes of the flash bank
295 device-width = <2>; // Two devices on each bank 127 device-width = <2>; // Two devices on each bank
296 }; 128 };
297 129
298 media5200_fpga: fpga@2,0 { 130 media5200_fpga: fpga@2,0 {
diff --git a/arch/powerpc/boot/dts/motionpro.dts b/arch/powerpc/boot/dts/motionpro.dts
index 6ca4fc144a33..0b78e89ac69b 100644
--- a/arch/powerpc/boot/dts/motionpro.dts
+++ b/arch/powerpc/boot/dts/motionpro.dts
@@ -10,219 +10,73 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13/dts-v1/; 13/include/ "mpc5200b.dtsi"
14 14
15/ { 15/ {
16 model = "promess,motionpro"; 16 model = "promess,motionpro";
17 compatible = "promess,motionpro"; 17 compatible = "promess,motionpro";
18 #address-cells = <1>;
19 #size-cells = <1>;
20 interrupt-parent = <&mpc5200_pic>;
21
22 cpus {
23 #address-cells = <1>;
24 #size-cells = <0>;
25
26 PowerPC,5200@0 {
27 device_type = "cpu";
28 reg = <0>;
29 d-cache-line-size = <32>;
30 i-cache-line-size = <32>;
31 d-cache-size = <0x4000>; // L1, 16K
32 i-cache-size = <0x4000>; // L1, 16K
33 timebase-frequency = <0>; // from bootloader
34 bus-frequency = <0>; // from bootloader
35 clock-frequency = <0>; // from bootloader
36 };
37 };
38
39 memory {
40 device_type = "memory";
41 reg = <0x00000000 0x04000000>; // 64MB
42 };
43 18
44 soc5200@f0000000 { 19 soc5200@f0000000 {
45 #address-cells = <1>;
46 #size-cells = <1>;
47 compatible = "fsl,mpc5200b-immr";
48 ranges = <0 0xf0000000 0x0000c000>;
49 reg = <0xf0000000 0x00000100>;
50 bus-frequency = <0>; // from bootloader
51 system-frequency = <0>; // from bootloader
52
53 cdm@200 {
54 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
55 reg = <0x200 0x38>;
56 };
57
58 mpc5200_pic: interrupt-controller@500 {
59 // 5200 interrupts are encoded into two levels;
60 interrupt-controller;
61 #interrupt-cells = <3>;
62 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
63 reg = <0x500 0x80>;
64 };
65
66 timer@600 { // General Purpose Timer 20 timer@600 { // General Purpose Timer
67 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
68 reg = <0x600 0x10>;
69 interrupts = <1 9 0>;
70 fsl,has-wdt; 21 fsl,has-wdt;
71 }; 22 };
72 23
73 timer@610 { // General Purpose Timer 24 timer@660 { // Motion-PRO status LED
74 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
75 reg = <0x610 0x10>;
76 interrupts = <1 10 0>;
77 };
78
79 timer@620 { // General Purpose Timer
80 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
81 reg = <0x620 0x10>;
82 interrupts = <1 11 0>;
83 };
84
85 timer@630 { // General Purpose Timer
86 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
87 reg = <0x630 0x10>;
88 interrupts = <1 12 0>;
89 };
90
91 timer@640 { // General Purpose Timer
92 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
93 reg = <0x640 0x10>;
94 interrupts = <1 13 0>;
95 };
96
97 timer@650 { // General Purpose Timer
98 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
99 reg = <0x650 0x10>;
100 interrupts = <1 14 0>;
101 };
102
103 motionpro-led@660 { // Motion-PRO status LED
104 compatible = "promess,motionpro-led"; 25 compatible = "promess,motionpro-led";
105 label = "motionpro-statusled"; 26 label = "motionpro-statusled";
106 reg = <0x660 0x10>;
107 interrupts = <1 15 0>;
108 blink-delay = <100>; // 100 msec 27 blink-delay = <100>; // 100 msec
109 }; 28 };
110 29
111 motionpro-led@670 { // Motion-PRO ready LED 30 timer@670 { // Motion-PRO ready LED
112 compatible = "promess,motionpro-led"; 31 compatible = "promess,motionpro-led";
113 label = "motionpro-readyled"; 32 label = "motionpro-readyled";
114 reg = <0x670 0x10>;
115 interrupts = <1 16 0>;
116 };
117
118 rtc@800 { // Real time clock
119 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc";
120 reg = <0x800 0x100>;
121 interrupts = <1 5 0 1 6 0>;
122 };
123
124 can@980 {
125 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
126 interrupts = <2 18 0>;
127 reg = <0x980 0x80>;
128 }; 33 };
129 34
130 gpio_simple: gpio@b00 { 35 can@900 {
131 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio"; 36 status = "disabled";
132 reg = <0xb00 0x40>;
133 interrupts = <1 7 0>;
134 gpio-controller;
135 #gpio-cells = <2>;
136 }; 37 };
137 38
138 gpio_wkup: gpio@c00 { 39 psc@2000 { // PSC1
139 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup"; 40 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
140 reg = <0xc00 0x40>;
141 interrupts = <1 8 0 0 3 0>;
142 gpio-controller;
143 #gpio-cells = <2>;
144 };
145
146 spi@f00 {
147 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi";
148 reg = <0xf00 0x20>;
149 interrupts = <2 13 0 2 14 0>;
150 }; 41 };
151 42
152 usb@1000 { 43 // PSC2 in spi master mode
153 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be"; 44 psc@2200 { // PSC2
154 reg = <0x1000 0xff>; 45 compatible = "fsl,mpc5200b-psc-spi","fsl,mpc5200-psc-spi";
155 interrupts = <2 6 0>; 46 cell-index = <1>;
156 }; 47 };
157 48
158 dma-controller@1200 { 49 psc@2400 { // PSC3
159 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm"; 50 status = "disabled";
160 reg = <0x1200 0x80>;
161 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
162 3 4 0 3 5 0 3 6 0 3 7 0
163 3 8 0 3 9 0 3 10 0 3 11 0
164 3 12 0 3 13 0 3 14 0 3 15 0>;
165 }; 51 };
166 52
167 xlb@1f00 { 53 psc@2600 { // PSC4
168 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb"; 54 status = "disabled";
169 reg = <0x1f00 0x100>;
170 }; 55 };
171 56
172 serial@2000 { // PSC1 57 psc@2800 { // PSC5
173 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 58 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
174 reg = <0x2000 0x100>;
175 interrupts = <2 1 0>;
176 };
177
178 // PSC2 in spi master mode
179 spi@2200 { // PSC2
180 compatible = "fsl,mpc5200b-psc-spi","fsl,mpc5200-psc-spi";
181 cell-index = <1>;
182 reg = <0x2200 0x100>;
183 interrupts = <2 2 0>;
184 }; 59 };
185 60
186 // PSC5 in uart mode 61 psc@2c00 { // PSC6
187 serial@2800 { // PSC5 62 status = "disabled";
188 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
189 reg = <0x2800 0x100>;
190 interrupts = <2 12 0>;
191 }; 63 };
192 64
193 ethernet@3000 { 65 ethernet@3000 {
194 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
195 reg = <0x3000 0x400>;
196 local-mac-address = [ 00 00 00 00 00 00 ];
197 interrupts = <2 5 0>;
198 phy-handle = <&phy0>; 66 phy-handle = <&phy0>;
199 }; 67 };
200 68
201 mdio@3000 { 69 mdio@3000 {
202 #address-cells = <1>;
203 #size-cells = <0>;
204 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
205 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
206 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
207
208 phy0: ethernet-phy@2 { 70 phy0: ethernet-phy@2 {
209 reg = <2>; 71 reg = <2>;
210 }; 72 };
211 }; 73 };
212 74
213 ata@3a00 { 75 i2c@3d00 {
214 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata"; 76 status = "disabled";
215 reg = <0x3a00 0x100>;
216 interrupts = <2 7 0>;
217 }; 77 };
218 78
219 i2c@3d40 { 79 i2c@3d40 {
220 #address-cells = <1>;
221 #size-cells = <0>;
222 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
223 reg = <0x3d40 0x40>;
224 interrupts = <2 16 0>;
225
226 rtc@68 { 80 rtc@68 {
227 compatible = "dallas,ds1339"; 81 compatible = "dallas,ds1339";
228 reg = <0x68>; 82 reg = <0x68>;
@@ -235,10 +89,11 @@
235 }; 89 };
236 }; 90 };
237 91
92 pci@f0000d00 {
93 status = "disabled";
94 };
95
238 localbus { 96 localbus {
239 compatible = "fsl,mpc5200b-lpb","simple-bus";
240 #address-cells = <2>;
241 #size-cells = <1>;
242 ranges = <0 0 0xff000000 0x01000000 97 ranges = <0 0 0xff000000 0x01000000
243 1 0 0x50000000 0x00010000 98 1 0 0x50000000 0x00010000
244 2 0 0x50010000 0x00010000 99 2 0 0x50010000 0x00010000
@@ -280,5 +135,6 @@
280 #size-cells = <1>; 135 #size-cells = <1>;
281 #address-cells = <1>; 136 #address-cells = <1>;
282 }; 137 };
138
283 }; 139 };
284}; 140};
diff --git a/arch/powerpc/boot/dts/mpc5200b.dtsi b/arch/powerpc/boot/dts/mpc5200b.dtsi
new file mode 100644
index 000000000000..bc27548e895d
--- /dev/null
+++ b/arch/powerpc/boot/dts/mpc5200b.dtsi
@@ -0,0 +1,275 @@
1/*
2 * base MPC5200b Device Tree Source
3 *
4 * Copyright (C) 2010 SecretLab
5 * Grant Likely <grant@secretlab.ca>
6 * John Bonesio <bones@secretlab.ca>
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 as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14/dts-v1/;
15
16/ {
17 model = "fsl,mpc5200b";
18 compatible = "fsl,mpc5200b";
19 #address-cells = <1>;
20 #size-cells = <1>;
21 interrupt-parent = <&mpc5200_pic>;
22
23 cpus {
24 #address-cells = <1>;
25 #size-cells = <0>;
26
27 powerpc: PowerPC,5200@0 {
28 device_type = "cpu";
29 reg = <0>;
30 d-cache-line-size = <32>;
31 i-cache-line-size = <32>;
32 d-cache-size = <0x4000>; // L1, 16K
33 i-cache-size = <0x4000>; // L1, 16K
34 timebase-frequency = <0>; // from bootloader
35 bus-frequency = <0>; // from bootloader
36 clock-frequency = <0>; // from bootloader
37 };
38 };
39
40 memory: memory {
41 device_type = "memory";
42 reg = <0x00000000 0x04000000>; // 64MB
43 };
44
45 soc: soc5200@f0000000 {
46 #address-cells = <1>;
47 #size-cells = <1>;
48 compatible = "fsl,mpc5200b-immr";
49 ranges = <0 0xf0000000 0x0000c000>;
50 reg = <0xf0000000 0x00000100>;
51 bus-frequency = <0>; // from bootloader
52 system-frequency = <0>; // from bootloader
53
54 cdm@200 {
55 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
56 reg = <0x200 0x38>;
57 };
58
59 mpc5200_pic: interrupt-controller@500 {
60 // 5200 interrupts are encoded into two levels;
61 interrupt-controller;
62 #interrupt-cells = <3>;
63 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
64 reg = <0x500 0x80>;
65 };
66
67 timer@600 { // General Purpose Timer
68 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
69 reg = <0x600 0x10>;
70 interrupts = <1 9 0>;
71 };
72
73 timer@610 { // General Purpose Timer
74 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
75 reg = <0x610 0x10>;
76 interrupts = <1 10 0>;
77 };
78
79 timer@620 { // General Purpose Timer
80 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
81 reg = <0x620 0x10>;
82 interrupts = <1 11 0>;
83 };
84
85 timer@630 { // General Purpose Timer
86 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
87 reg = <0x630 0x10>;
88 interrupts = <1 12 0>;
89 };
90
91 timer@640 { // General Purpose Timer
92 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
93 reg = <0x640 0x10>;
94 interrupts = <1 13 0>;
95 };
96
97 timer@650 { // General Purpose Timer
98 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
99 reg = <0x650 0x10>;
100 interrupts = <1 14 0>;
101 };
102
103 timer@660 { // General Purpose Timer
104 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
105 reg = <0x660 0x10>;
106 interrupts = <1 15 0>;
107 };
108
109 timer@670 { // General Purpose Timer
110 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
111 reg = <0x670 0x10>;
112 interrupts = <1 16 0>;
113 };
114
115 rtc@800 { // Real time clock
116 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc";
117 reg = <0x800 0x100>;
118 interrupts = <1 5 0 1 6 0>;
119 };
120
121 can@900 {
122 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
123 interrupts = <2 17 0>;
124 reg = <0x900 0x80>;
125 };
126
127 can@980 {
128 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
129 interrupts = <2 18 0>;
130 reg = <0x980 0x80>;
131 };
132
133 gpio_simple: gpio@b00 {
134 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio";
135 reg = <0xb00 0x40>;
136 interrupts = <1 7 0>;
137 gpio-controller;
138 #gpio-cells = <2>;
139 };
140
141 gpio_wkup: gpio@c00 {
142 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup";
143 reg = <0xc00 0x40>;
144 interrupts = <1 8 0 0 3 0>;
145 gpio-controller;
146 #gpio-cells = <2>;
147 };
148
149 spi@f00 {
150 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi";
151 reg = <0xf00 0x20>;
152 interrupts = <2 13 0 2 14 0>;
153 };
154
155 usb: usb@1000 {
156 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be";
157 reg = <0x1000 0xff>;
158 interrupts = <2 6 0>;
159 };
160
161 dma-controller@1200 {
162 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm";
163 reg = <0x1200 0x80>;
164 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
165 3 4 0 3 5 0 3 6 0 3 7 0
166 3 8 0 3 9 0 3 10 0 3 11 0
167 3 12 0 3 13 0 3 14 0 3 15 0>;
168 };
169
170 xlb@1f00 {
171 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb";
172 reg = <0x1f00 0x100>;
173 };
174
175 psc1: psc@2000 { // PSC1
176 compatible = "fsl,mpc5200b-psc","fsl,mpc5200-psc";
177 reg = <0x2000 0x100>;
178 interrupts = <2 1 0>;
179 };
180
181 psc2: psc@2200 { // PSC2
182 compatible = "fsl,mpc5200b-psc","fsl,mpc5200-psc";
183 reg = <0x2200 0x100>;
184 interrupts = <2 2 0>;
185 };
186
187 psc3: psc@2400 { // PSC3
188 compatible = "fsl,mpc5200b-psc","fsl,mpc5200-psc";
189 reg = <0x2400 0x100>;
190 interrupts = <2 3 0>;
191 };
192
193 psc4: psc@2600 { // PSC4
194 compatible = "fsl,mpc5200b-psc","fsl,mpc5200-psc";
195 reg = <0x2600 0x100>;
196 interrupts = <2 11 0>;
197 };
198
199 psc5: psc@2800 { // PSC5
200 compatible = "fsl,mpc5200b-psc","fsl,mpc5200-psc";
201 reg = <0x2800 0x100>;
202 interrupts = <2 12 0>;
203 };
204
205 psc6: psc@2c00 { // PSC6
206 compatible = "fsl,mpc5200b-psc","fsl,mpc5200-psc";
207 reg = <0x2c00 0x100>;
208 interrupts = <2 4 0>;
209 };
210
211 eth0: ethernet@3000 {
212 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
213 reg = <0x3000 0x400>;
214 local-mac-address = [ 00 00 00 00 00 00 ];
215 interrupts = <2 5 0>;
216 };
217
218 mdio@3000 {
219 #address-cells = <1>;
220 #size-cells = <0>;
221 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
222 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
223 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
224 };
225
226 ata@3a00 {
227 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata";
228 reg = <0x3a00 0x100>;
229 interrupts = <2 7 0>;
230 };
231
232 i2c@3d00 {
233 #address-cells = <1>;
234 #size-cells = <0>;
235 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
236 reg = <0x3d00 0x40>;
237 interrupts = <2 15 0>;
238 };
239
240 i2c@3d40 {
241 #address-cells = <1>;
242 #size-cells = <0>;
243 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
244 reg = <0x3d40 0x40>;
245 interrupts = <2 16 0>;
246 };
247
248 sram@8000 {
249 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram";
250 reg = <0x8000 0x4000>;
251 };
252 };
253
254 pci: pci@f0000d00 {
255 #interrupt-cells = <1>;
256 #size-cells = <2>;
257 #address-cells = <3>;
258 device_type = "pci";
259 compatible = "fsl,mpc5200b-pci","fsl,mpc5200-pci";
260 reg = <0xf0000d00 0x100>;
261 // interrupt-map-mask = need to add
262 // interrupt-map = need to add
263 clock-frequency = <0>; // From boot loader
264 interrupts = <2 8 0 2 9 0 2 10 0>;
265 bus-range = <0 0>;
266 // ranges = need to add
267 };
268
269 localbus: localbus {
270 compatible = "fsl,mpc5200b-lpb","fsl,mpc5200-lpb","simple-bus";
271 #address-cells = <2>;
272 #size-cells = <1>;
273 ranges = <0 0 0xfc000000 0x2000000>;
274 };
275};
diff --git a/arch/powerpc/boot/dts/mucmc52.dts b/arch/powerpc/boot/dts/mucmc52.dts
index b72a7581d798..21d34720fcc9 100644
--- a/arch/powerpc/boot/dts/mucmc52.dts
+++ b/arch/powerpc/boot/dts/mucmc52.dts
@@ -11,172 +11,109 @@
11 * option) any later version. 11 * option) any later version.
12 */ 12 */
13 13
14/dts-v1/; 14/include/ "mpc5200b.dtsi"
15 15
16/ { 16/ {
17 model = "manroland,mucmc52"; 17 model = "manroland,mucmc52";
18 compatible = "manroland,mucmc52"; 18 compatible = "manroland,mucmc52";
19 #address-cells = <1>;
20 #size-cells = <1>;
21 interrupt-parent = <&mpc5200_pic>;
22
23 cpus {
24 #address-cells = <1>;
25 #size-cells = <0>;
26
27 PowerPC,5200@0 {
28 device_type = "cpu";
29 reg = <0>;
30 d-cache-line-size = <32>;
31 i-cache-line-size = <32>;
32 d-cache-size = <0x4000>; // L1, 16K
33 i-cache-size = <0x4000>; // L1, 16K
34 timebase-frequency = <0>; // from bootloader
35 bus-frequency = <0>; // from bootloader
36 clock-frequency = <0>; // from bootloader
37 };
38 };
39
40 memory {
41 device_type = "memory";
42 reg = <0x00000000 0x04000000>; // 64MB
43 };
44 19
45 soc5200@f0000000 { 20 soc5200@f0000000 {
46 #address-cells = <1>;
47 #size-cells = <1>;
48 compatible = "fsl,mpc5200b-immr";
49 ranges = <0 0xf0000000 0x0000c000>;
50 reg = <0xf0000000 0x00000100>;
51 bus-frequency = <0>; // from bootloader
52 system-frequency = <0>; // from bootloader
53
54 cdm@200 {
55 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
56 reg = <0x200 0x38>;
57 };
58
59 mpc5200_pic: interrupt-controller@500 {
60 // 5200 interrupts are encoded into two levels;
61 interrupt-controller;
62 #interrupt-cells = <3>;
63 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
64 reg = <0x500 0x80>;
65 };
66
67 gpt0: timer@600 { // GPT 0 in GPIO mode 21 gpt0: timer@600 { // GPT 0 in GPIO mode
68 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
69 reg = <0x600 0x10>;
70 interrupts = <1 9 0>;
71 gpio-controller; 22 gpio-controller;
72 #gpio-cells = <2>; 23 #gpio-cells = <2>;
73 }; 24 };
74 25
75 gpt1: timer@610 { // General Purpose Timer in GPIO mode 26 gpt1: timer@610 { // General Purpose Timer in GPIO mode
76 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
77 reg = <0x610 0x10>;
78 interrupts = <1 10 0>;
79 gpio-controller; 27 gpio-controller;
80 #gpio-cells = <2>; 28 #gpio-cells = <2>;
81 }; 29 };
82 30
83 gpt2: timer@620 { // General Purpose Timer in GPIO mode 31 gpt2: timer@620 { // General Purpose Timer in GPIO mode
84 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
85 reg = <0x620 0x10>;
86 interrupts = <1 11 0>;
87 gpio-controller; 32 gpio-controller;
88 #gpio-cells = <2>; 33 #gpio-cells = <2>;
89 }; 34 };
90 35
91 gpt3: timer@630 { // General Purpose Timer in GPIO mode 36 gpt3: timer@630 { // General Purpose Timer in GPIO mode
92 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
93 reg = <0x630 0x10>;
94 interrupts = <1 12 0>;
95 gpio-controller; 37 gpio-controller;
96 #gpio-cells = <2>; 38 #gpio-cells = <2>;
97 }; 39 };
98 40
99 gpio_simple: gpio@b00 { 41 timer@640 {
100 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio"; 42 status = "disabled";
101 reg = <0xb00 0x40>;
102 interrupts = <1 7 0>;
103 gpio-controller;
104 #gpio-cells = <2>;
105 }; 43 };
106 44
107 gpio_wkup: gpio@c00 { 45 timer@650 {
108 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup"; 46 status = "disabled";
109 reg = <0xc00 0x40>; 47 };
110 interrupts = <1 8 0 0 3 0>; 48
111 gpio-controller; 49 timer@660 {
112 #gpio-cells = <2>; 50 status = "disabled";
51 };
52
53 timer@670 {
54 status = "disabled";
113 }; 55 };
114 56
115 dma-controller@1200 { 57 rtc@800 {
116 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm"; 58 status = "disabled";
117 reg = <0x1200 0x80>;
118 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
119 3 4 0 3 5 0 3 6 0 3 7 0
120 3 8 0 3 9 0 3 10 0 3 11 0
121 3 12 0 3 13 0 3 14 0 3 15 0>;
122 }; 59 };
123 60
124 xlb@1f00 { 61 can@900 {
125 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb"; 62 status = "disabled";
126 reg = <0x1f00 0x100>;
127 }; 63 };
128 64
129 serial@2000 { /* PSC1 in UART mode */ 65 can@980 {
66 status = "disabled";
67 };
68
69 spi@f00 {
70 status = "disabled";
71 };
72
73 usb@1000 {
74 status = "disabled";
75 };
76
77 psc@2000 { // PSC1
130 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 78 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
131 reg = <0x2000 0x100>;
132 interrupts = <2 1 0>;
133 }; 79 };
134 80
135 serial@2200 { /* PSC2 in UART mode */ 81 psc@2200 { // PSC2
136 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 82 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
137 reg = <0x2200 0x100>;
138 interrupts = <2 2 0>;
139 }; 83 };
140 84
141 serial@2c00 { /* PSC6 in UART mode */ 85 psc@2400 { // PSC3
86 status = "disabled";
87 };
88
89 psc@2600 { // PSC4
90 status = "disabled";
91 };
92
93 psc@2800 { // PSC5
94 status = "disabled";
95 };
96
97 psc@2c00 { // PSC6
142 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 98 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
143 reg = <0x2c00 0x100>;
144 interrupts = <2 4 0>;
145 }; 99 };
146 100
147 ethernet@3000 { 101 ethernet@3000 {
148 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
149 reg = <0x3000 0x400>;
150 local-mac-address = [ 00 00 00 00 00 00 ];
151 interrupts = <2 5 0>;
152 phy-handle = <&phy0>; 102 phy-handle = <&phy0>;
153 }; 103 };
154 104
155 mdio@3000 { 105 mdio@3000 {
156 #address-cells = <1>;
157 #size-cells = <0>;
158 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
159 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
160 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
161
162 phy0: ethernet-phy@0 { 106 phy0: ethernet-phy@0 {
163 compatible = "intel,lxt971"; 107 compatible = "intel,lxt971";
164 reg = <0>; 108 reg = <0>;
165 }; 109 };
166 }; 110 };
167 111
168 ata@3a00 { 112 i2c@3d00 {
169 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata"; 113 status = "disabled";
170 reg = <0x3a00 0x100>;
171 interrupts = <2 7 0>;
172 }; 114 };
173 115
174 i2c@3d40 { 116 i2c@3d40 {
175 #address-cells = <1>;
176 #size-cells = <0>;
177 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
178 reg = <0x3d40 0x40>;
179 interrupts = <2 16 0>;
180 hwmon@2c { 117 hwmon@2c {
181 compatible = "ad,adm9240"; 118 compatible = "ad,adm9240";
182 reg = <0x2c>; 119 reg = <0x2c>;
@@ -186,20 +123,9 @@
186 reg = <0x51>; 123 reg = <0x51>;
187 }; 124 };
188 }; 125 };
189
190 sram@8000 {
191 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram";
192 reg = <0x8000 0x4000>;
193 };
194 }; 126 };
195 127
196 pci@f0000d00 { 128 pci@f0000d00 {
197 #interrupt-cells = <1>;
198 #size-cells = <2>;
199 #address-cells = <3>;
200 device_type = "pci";
201 compatible = "fsl,mpc5200b-pci","fsl,mpc5200-pci";
202 reg = <0xf0000d00 0x100>;
203 interrupt-map-mask = <0xf800 0 0 7>; 129 interrupt-map-mask = <0xf800 0 0 7>;
204 interrupt-map = < 130 interrupt-map = <
205 /* IDSEL 0x10 */ 131 /* IDSEL 0x10 */
@@ -208,20 +134,12 @@
208 0x8000 0 0 3 &mpc5200_pic 0 2 3 134 0x8000 0 0 3 &mpc5200_pic 0 2 3
209 0x8000 0 0 4 &mpc5200_pic 0 1 3 135 0x8000 0 0 4 &mpc5200_pic 0 1 3
210 >; 136 >;
211 clock-frequency = <0>; // From boot loader
212 interrupts = <2 8 0 2 9 0 2 10 0>;
213 bus-range = <0 0>;
214 ranges = <0x42000000 0 0x60000000 0x60000000 0 0x10000000 137 ranges = <0x42000000 0 0x60000000 0x60000000 0 0x10000000
215 0x02000000 0 0x90000000 0x90000000 0 0x10000000 138 0x02000000 0 0x90000000 0x90000000 0 0x10000000
216 0x01000000 0 0x00000000 0xa0000000 0 0x01000000>; 139 0x01000000 0 0x00000000 0xa0000000 0 0x01000000>;
217 }; 140 };
218 141
219 localbus { 142 localbus {
220 compatible = "fsl,mpc5200b-lpb","fsl,mpc5200-lpb","simple-bus";
221
222 #address-cells = <2>;
223 #size-cells = <1>;
224
225 ranges = <0 0 0xff800000 0x00800000 143 ranges = <0 0 0xff800000 0x00800000
226 1 0 0x80000000 0x00800000 144 1 0 0x80000000 0x00800000
227 3 0 0x80000000 0x00800000>; 145 3 0 0x80000000 0x00800000>;
diff --git a/arch/powerpc/boot/dts/pcm030.dts b/arch/powerpc/boot/dts/pcm030.dts
index 8a4ec30b21ae..9e354997eb7e 100644
--- a/arch/powerpc/boot/dts/pcm030.dts
+++ b/arch/powerpc/boot/dts/pcm030.dts
@@ -12,246 +12,92 @@
12 * option) any later version. 12 * option) any later version.
13 */ 13 */
14 14
15/dts-v1/; 15/include/ "mpc5200b.dtsi"
16 16
17/ { 17/ {
18 model = "phytec,pcm030"; 18 model = "phytec,pcm030";
19 compatible = "phytec,pcm030"; 19 compatible = "phytec,pcm030";
20 #address-cells = <1>;
21 #size-cells = <1>;
22 interrupt-parent = <&mpc5200_pic>;
23
24 cpus {
25 #address-cells = <1>;
26 #size-cells = <0>;
27
28 PowerPC,5200@0 {
29 device_type = "cpu";
30 reg = <0>;
31 d-cache-line-size = <32>;
32 i-cache-line-size = <32>;
33 d-cache-size = <0x4000>; // L1, 16K
34 i-cache-size = <0x4000>; // L1, 16K
35 timebase-frequency = <0>; // from bootloader
36 bus-frequency = <0>; // from bootloader
37 clock-frequency = <0>; // from bootloader
38 };
39 };
40
41 memory {
42 device_type = "memory";
43 reg = <0x00000000 0x04000000>; // 64MB
44 };
45 20
46 soc5200@f0000000 { 21 soc5200@f0000000 {
47 #address-cells = <1>; 22 timer@600 { // General Purpose Timer
48 #size-cells = <1>;
49 compatible = "fsl,mpc5200b-immr";
50 ranges = <0 0xf0000000 0x0000c000>;
51 bus-frequency = <0>; // from bootloader
52 system-frequency = <0>; // from bootloader
53
54 cdm@200 {
55 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
56 reg = <0x200 0x38>;
57 };
58
59 mpc5200_pic: interrupt-controller@500 {
60 // 5200 interrupts are encoded into two levels;
61 interrupt-controller;
62 #interrupt-cells = <3>;
63 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
64 reg = <0x500 0x80>;
65 };
66
67 timer@600 { // General Purpose Timer
68 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
69 reg = <0x600 0x10>;
70 interrupts = <1 9 0>;
71 fsl,has-wdt; 23 fsl,has-wdt;
72 }; 24 };
73 25
74 timer@610 { // General Purpose Timer
75 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
76 reg = <0x610 0x10>;
77 interrupts = <1 10 0>;
78 };
79
80 gpt2: timer@620 { // General Purpose Timer in GPIO mode 26 gpt2: timer@620 { // General Purpose Timer in GPIO mode
81 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio"; 27 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
82 reg = <0x620 0x10>;
83 interrupts = <1 11 0>;
84 gpio-controller; 28 gpio-controller;
85 #gpio-cells = <2>; 29 #gpio-cells = <2>;
86 }; 30 };
87 31
88 gpt3: timer@630 { // General Purpose Timer in GPIO mode 32 gpt3: timer@630 { // General Purpose Timer in GPIO mode
89 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio"; 33 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
90 reg = <0x630 0x10>;
91 interrupts = <1 12 0>;
92 gpio-controller; 34 gpio-controller;
93 #gpio-cells = <2>; 35 #gpio-cells = <2>;
94 }; 36 };
95 37
96 gpt4: timer@640 { // General Purpose Timer in GPIO mode 38 gpt4: timer@640 { // General Purpose Timer in GPIO mode
97 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio"; 39 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
98 reg = <0x640 0x10>;
99 interrupts = <1 13 0>;
100 gpio-controller; 40 gpio-controller;
101 #gpio-cells = <2>; 41 #gpio-cells = <2>;
102 }; 42 };
103 43
104 gpt5: timer@650 { // General Purpose Timer in GPIO mode 44 gpt5: timer@650 { // General Purpose Timer in GPIO mode
105 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio"; 45 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
106 reg = <0x650 0x10>;
107 interrupts = <1 14 0>;
108 gpio-controller; 46 gpio-controller;
109 #gpio-cells = <2>; 47 #gpio-cells = <2>;
110 }; 48 };
111 49
112 gpt6: timer@660 { // General Purpose Timer in GPIO mode 50 gpt6: timer@660 { // General Purpose Timer in GPIO mode
113 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio"; 51 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
114 reg = <0x660 0x10>;
115 interrupts = <1 15 0>;
116 gpio-controller; 52 gpio-controller;
117 #gpio-cells = <2>; 53 #gpio-cells = <2>;
118 }; 54 };
119 55
120 gpt7: timer@670 { // General Purpose Timer in GPIO mode 56 gpt7: timer@670 { // General Purpose Timer in GPIO mode
121 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio"; 57 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
122 reg = <0x670 0x10>;
123 interrupts = <1 16 0>;
124 gpio-controller;
125 #gpio-cells = <2>;
126 };
127
128 rtc@800 { // Real time clock
129 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc";
130 reg = <0x800 0x100>;
131 interrupts = <1 5 0 1 6 0>;
132 };
133
134 can@900 {
135 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
136 interrupts = <2 17 0>;
137 reg = <0x900 0x80>;
138 };
139
140 can@980 {
141 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
142 interrupts = <2 18 0>;
143 reg = <0x980 0x80>;
144 };
145
146 gpio_simple: gpio@b00 {
147 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio";
148 reg = <0xb00 0x40>;
149 interrupts = <1 7 0>;
150 gpio-controller; 58 gpio-controller;
151 #gpio-cells = <2>; 59 #gpio-cells = <2>;
152 }; 60 };
153 61
154 gpio_wkup: gpio@c00 { 62 psc@2000 { /* PSC1 in ac97 mode */
155 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup";
156 reg = <0xc00 0x40>;
157 interrupts = <1 8 0 0 3 0>;
158 gpio-controller;
159 #gpio-cells = <2>;
160 };
161
162 spi@f00 {
163 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi";
164 reg = <0xf00 0x20>;
165 interrupts = <2 13 0 2 14 0>;
166 };
167
168 usb@1000 {
169 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be";
170 reg = <0x1000 0xff>;
171 interrupts = <2 6 0>;
172 };
173
174 dma-controller@1200 {
175 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm";
176 reg = <0x1200 0x80>;
177 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
178 3 4 0 3 5 0 3 6 0 3 7 0
179 3 8 0 3 9 0 3 10 0 3 11 0
180 3 12 0 3 13 0 3 14 0 3 15 0>;
181 };
182
183 xlb@1f00 {
184 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb";
185 reg = <0x1f00 0x100>;
186 };
187
188 ac97@2000 { /* PSC1 in ac97 mode */
189 compatible = "mpc5200b-psc-ac97","fsl,mpc5200b-psc-ac97"; 63 compatible = "mpc5200b-psc-ac97","fsl,mpc5200b-psc-ac97";
190 cell-index = <0>; 64 cell-index = <0>;
191 reg = <0x2000 0x100>;
192 interrupts = <2 1 0>;
193 }; 65 };
194 66
195 /* PSC2 port is used by CAN1/2 */ 67 /* PSC2 port is used by CAN1/2 */
68 psc@2200 {
69 status = "disabled";
70 };
196 71
197 serial@2400 { /* PSC3 in UART mode */ 72 psc@2400 { /* PSC3 in UART mode */
198 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 73 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
199 cell-index = <2>;
200 reg = <0x2400 0x100>;
201 interrupts = <2 3 0>;
202 }; 74 };
203 75
204 /* PSC4 is ??? */ 76 /* PSC4 is ??? */
77 psc@2600 {
78 status = "disabled";
79 };
205 80
206 /* PSC5 is ??? */ 81 /* PSC5 is ??? */
82 psc@2800 {
83 status = "disabled";
84 };
207 85
208 serial@2c00 { /* PSC6 in UART mode */ 86 psc@2c00 { /* PSC6 in UART mode */
209 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 87 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
210 cell-index = <5>;
211 reg = <0x2c00 0x100>;
212 interrupts = <2 4 0>;
213 }; 88 };
214 89
215 ethernet@3000 { 90 ethernet@3000 {
216 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
217 reg = <0x3000 0x400>;
218 local-mac-address = [ 00 00 00 00 00 00 ];
219 interrupts = <2 5 0>;
220 phy-handle = <&phy0>; 91 phy-handle = <&phy0>;
221 }; 92 };
222 93
223 mdio@3000 { 94 mdio@3000 {
224 #address-cells = <1>;
225 #size-cells = <0>;
226 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
227 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
228 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
229
230 phy0: ethernet-phy@0 { 95 phy0: ethernet-phy@0 {
231 reg = <0>; 96 reg = <0>;
232 }; 97 };
233 }; 98 };
234 99
235 ata@3a00 {
236 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata";
237 reg = <0x3a00 0x100>;
238 interrupts = <2 7 0>;
239 };
240
241 i2c@3d00 {
242 #address-cells = <1>;
243 #size-cells = <0>;
244 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
245 reg = <0x3d00 0x40>;
246 interrupts = <2 15 0>;
247 };
248
249 i2c@3d40 { 100 i2c@3d40 {
250 #address-cells = <1>;
251 #size-cells = <0>;
252 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
253 reg = <0x3d40 0x40>;
254 interrupts = <2 16 0>;
255 rtc@51 { 101 rtc@51 {
256 compatible = "nxp,pcf8563"; 102 compatible = "nxp,pcf8563";
257 reg = <0x51>; 103 reg = <0x51>;
@@ -259,6 +105,7 @@
259 eeprom@52 { 105 eeprom@52 {
260 compatible = "catalyst,24c32"; 106 compatible = "catalyst,24c32";
261 reg = <0x52>; 107 reg = <0x52>;
108 pagesize = <32>;
262 }; 109 };
263 }; 110 };
264 111
@@ -269,12 +116,6 @@
269 }; 116 };
270 117
271 pci@f0000d00 { 118 pci@f0000d00 {
272 #interrupt-cells = <1>;
273 #size-cells = <2>;
274 #address-cells = <3>;
275 device_type = "pci";
276 compatible = "fsl,mpc5200b-pci","fsl,mpc5200-pci";
277 reg = <0xf0000d00 0x100>;
278 interrupt-map-mask = <0xf800 0 0 7>; 119 interrupt-map-mask = <0xf800 0 0 7>;
279 interrupt-map = <0xc000 0 0 1 &mpc5200_pic 0 0 3 // 1st slot 120 interrupt-map = <0xc000 0 0 1 &mpc5200_pic 0 0 3 // 1st slot
280 0xc000 0 0 2 &mpc5200_pic 1 1 3 121 0xc000 0 0 2 &mpc5200_pic 1 1 3
@@ -285,11 +126,12 @@
285 0xc800 0 0 2 &mpc5200_pic 1 2 3 126 0xc800 0 0 2 &mpc5200_pic 1 2 3
286 0xc800 0 0 3 &mpc5200_pic 1 3 3 127 0xc800 0 0 3 &mpc5200_pic 1 3 3
287 0xc800 0 0 4 &mpc5200_pic 0 0 3>; 128 0xc800 0 0 4 &mpc5200_pic 0 0 3>;
288 clock-frequency = <0>; // From boot loader
289 interrupts = <2 8 0 2 9 0 2 10 0>;
290 bus-range = <0 0>;
291 ranges = <0x42000000 0 0x80000000 0x80000000 0 0x20000000 129 ranges = <0x42000000 0 0x80000000 0x80000000 0 0x20000000
292 0x02000000 0 0xa0000000 0xa0000000 0 0x10000000 130 0x02000000 0 0xa0000000 0xa0000000 0 0x10000000
293 0x01000000 0 0x00000000 0xb0000000 0 0x01000000>; 131 0x01000000 0 0x00000000 0xb0000000 0 0x01000000>;
294 }; 132 };
133
134 localbus {
135 status = "disabled";
136 };
295}; 137};
diff --git a/arch/powerpc/boot/dts/pcm032.dts b/arch/powerpc/boot/dts/pcm032.dts
index 85d857a5d46e..1dd478bfff96 100644
--- a/arch/powerpc/boot/dts/pcm032.dts
+++ b/arch/powerpc/boot/dts/pcm032.dts
@@ -12,99 +12,37 @@
12 * option) any later version. 12 * option) any later version.
13 */ 13 */
14 14
15/dts-v1/; 15/include/ "mpc5200b.dtsi"
16 16
17/ { 17/ {
18 model = "phytec,pcm032"; 18 model = "phytec,pcm032";
19 compatible = "phytec,pcm032"; 19 compatible = "phytec,pcm032";
20 #address-cells = <1>;
21 #size-cells = <1>;
22 interrupt-parent = <&mpc5200_pic>;
23
24 cpus {
25 #address-cells = <1>;
26 #size-cells = <0>;
27
28 PowerPC,5200@0 {
29 device_type = "cpu";
30 reg = <0>;
31 d-cache-line-size = <32>;
32 i-cache-line-size = <32>;
33 d-cache-size = <0x4000>; // L1, 16K
34 i-cache-size = <0x4000>; // L1, 16K
35 timebase-frequency = <0>; // from bootloader
36 bus-frequency = <0>; // from bootloader
37 clock-frequency = <0>; // from bootloader
38 };
39 };
40 20
41 memory { 21 memory {
42 device_type = "memory";
43 reg = <0x00000000 0x08000000>; // 128MB 22 reg = <0x00000000 0x08000000>; // 128MB
44 }; 23 };
45 24
46 soc5200@f0000000 { 25 soc5200@f0000000 {
47 #address-cells = <1>; 26 timer@600 { // General Purpose Timer
48 #size-cells = <1>;
49 compatible = "fsl,mpc5200b-immr";
50 ranges = <0 0xf0000000 0x0000c000>;
51 bus-frequency = <0>; // from bootloader
52 system-frequency = <0>; // from bootloader
53
54 cdm@200 {
55 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
56 reg = <0x200 0x38>;
57 };
58
59 mpc5200_pic: interrupt-controller@500 {
60 // 5200 interrupts are encoded into two levels;
61 interrupt-controller;
62 #interrupt-cells = <3>;
63 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
64 reg = <0x500 0x80>;
65 };
66
67 timer@600 { // General Purpose Timer
68 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
69 reg = <0x600 0x10>;
70 interrupts = <1 9 0>;
71 fsl,has-wdt; 27 fsl,has-wdt;
72 }; 28 };
73 29
74 timer@610 { // General Purpose Timer
75 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
76 reg = <0x610 0x10>;
77 interrupts = <1 10 0>;
78 };
79
80 gpt2: timer@620 { // General Purpose Timer in GPIO mode 30 gpt2: timer@620 { // General Purpose Timer in GPIO mode
81 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
82 reg = <0x620 0x10>;
83 interrupts = <1 11 0>;
84 gpio-controller; 31 gpio-controller;
85 #gpio-cells = <2>; 32 #gpio-cells = <2>;
86 }; 33 };
87 34
88 gpt3: timer@630 { // General Purpose Timer in GPIO mode 35 gpt3: timer@630 { // General Purpose Timer in GPIO mode
89 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
90 reg = <0x630 0x10>;
91 interrupts = <1 12 0>;
92 gpio-controller; 36 gpio-controller;
93 #gpio-cells = <2>; 37 #gpio-cells = <2>;
94 }; 38 };
95 39
96 gpt4: timer@640 { // General Purpose Timer in GPIO mode 40 gpt4: timer@640 { // General Purpose Timer in GPIO mode
97 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
98 reg = <0x640 0x10>;
99 interrupts = <1 13 0>;
100 gpio-controller; 41 gpio-controller;
101 #gpio-cells = <2>; 42 #gpio-cells = <2>;
102 }; 43 };
103 44
104 gpt5: timer@650 { // General Purpose Timer in GPIO mode 45 gpt5: timer@650 { // General Purpose Timer in GPIO mode
105 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
106 reg = <0x650 0x10>;
107 interrupts = <1 14 0>;
108 gpio-controller; 46 gpio-controller;
109 #gpio-cells = <2>; 47 #gpio-cells = <2>;
110 }; 48 };
@@ -118,163 +56,62 @@
118 }; 56 };
119 57
120 gpt7: timer@670 { // General Purpose Timer in GPIO mode 58 gpt7: timer@670 { // General Purpose Timer in GPIO mode
121 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
122 reg = <0x670 0x10>;
123 interrupts = <1 16 0>;
124 gpio-controller; 59 gpio-controller;
125 #gpio-cells = <2>; 60 #gpio-cells = <2>;
126 }; 61 };
127 62
128 rtc@800 { // Real time clock 63 psc@2000 { /* PSC1 is ac97 */
129 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc";
130 reg = <0x800 0x100>;
131 interrupts = <1 5 0 1 6 0>;
132 };
133
134 can@900 {
135 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
136 interrupts = <2 17 0>;
137 reg = <0x900 0x80>;
138 };
139
140 can@980 {
141 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
142 interrupts = <2 18 0>;
143 reg = <0x980 0x80>;
144 };
145
146 gpio_simple: gpio@b00 {
147 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio";
148 reg = <0xb00 0x40>;
149 interrupts = <1 7 0>;
150 gpio-controller;
151 #gpio-cells = <2>;
152 };
153
154 gpio_wkup: gpio@c00 {
155 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup";
156 reg = <0xc00 0x40>;
157 interrupts = <1 8 0 0 3 0>;
158 gpio-controller;
159 #gpio-cells = <2>;
160 };
161
162 spi@f00 {
163 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi";
164 reg = <0xf00 0x20>;
165 interrupts = <2 13 0 2 14 0>;
166 };
167
168 usb@1000 {
169 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be";
170 reg = <0x1000 0xff>;
171 interrupts = <2 6 0>;
172 };
173
174 dma-controller@1200 {
175 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm";
176 reg = <0x1200 0x80>;
177 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
178 3 4 0 3 5 0 3 6 0 3 7 0
179 3 8 0 3 9 0 3 10 0 3 11 0
180 3 12 0 3 13 0 3 14 0 3 15 0>;
181 };
182
183 xlb@1f00 {
184 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb";
185 reg = <0x1f00 0x100>;
186 };
187
188 ac97@2000 { /* PSC1 is ac97 */
189 compatible = "fsl,mpc5200b-psc-ac97","fsl,mpc5200-psc-ac97"; 64 compatible = "fsl,mpc5200b-psc-ac97","fsl,mpc5200-psc-ac97";
190 cell-index = <0>; 65 cell-index = <0>;
191 reg = <0x2000 0x100>;
192 interrupts = <2 1 0>;
193 }; 66 };
194 67
195 /* PSC2 port is used by CAN1/2 */ 68 /* PSC2 port is used by CAN1/2 */
69 psc@2200 {
70 status = "disabled";
71 };
196 72
197 serial@2400 { /* PSC3 in UART mode */ 73 psc@2400 { /* PSC3 in UART mode */
198 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 74 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
199 cell-index = <2>;
200 reg = <0x2400 0x100>;
201 interrupts = <2 3 0>;
202 }; 75 };
203 76
204 /* PSC4 is ??? */ 77 /* PSC4 is ??? */
78 psc@2600 {
79 status = "disabled";
80 };
205 81
206 /* PSC5 is ??? */ 82 /* PSC5 is ??? */
83 psc@2800 {
84 status = "disabled";
85 };
207 86
208 serial@2c00 { /* PSC6 in UART mode */ 87 psc@2c00 { /* PSC6 in UART mode */
209 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 88 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
210 cell-index = <5>;
211 reg = <0x2c00 0x100>;
212 interrupts = <2 4 0>;
213 }; 89 };
214 90
215 ethernet@3000 { 91 ethernet@3000 {
216 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
217 reg = <0x3000 0x400>;
218 local-mac-address = [ 00 00 00 00 00 00 ];
219 interrupts = <2 5 0>;
220 phy-handle = <&phy0>; 92 phy-handle = <&phy0>;
221 }; 93 };
222 94
223 mdio@3000 { 95 mdio@3000 {
224 #address-cells = <1>;
225 #size-cells = <0>;
226 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
227 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
228 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
229
230 phy0: ethernet-phy@0 { 96 phy0: ethernet-phy@0 {
231 reg = <0>; 97 reg = <0>;
232 }; 98 };
233 }; 99 };
234 100
235 ata@3a00 {
236 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata";
237 reg = <0x3a00 0x100>;
238 interrupts = <2 7 0>;
239 };
240
241 i2c@3d00 {
242 #address-cells = <1>;
243 #size-cells = <0>;
244 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
245 reg = <0x3d00 0x40>;
246 interrupts = <2 15 0>;
247 };
248
249 i2c@3d40 { 101 i2c@3d40 {
250 #address-cells = <1>;
251 #size-cells = <0>;
252 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
253 reg = <0x3d40 0x40>;
254 interrupts = <2 16 0>;
255 rtc@51 { 102 rtc@51 {
256 compatible = "nxp,pcf8563"; 103 compatible = "nxp,pcf8563";
257 reg = <0x51>; 104 reg = <0x51>;
258 }; 105 };
259 eeprom@52 { 106 eeprom@52 {
260 compatible = "at24,24c32"; 107 compatible = "catalyst,24c32";
261 reg = <0x52>; 108 reg = <0x52>;
109 pagesize = <32>;
262 }; 110 };
263 }; 111 };
264
265 sram@8000 {
266 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram";
267 reg = <0x8000 0x4000>;
268 };
269 }; 112 };
270 113
271 pci@f0000d00 { 114 pci@f0000d00 {
272 #interrupt-cells = <1>;
273 #size-cells = <2>;
274 #address-cells = <3>;
275 device_type = "pci";
276 compatible = "fsl,mpc5200b-pci","fsl,mpc5200-pci";
277 reg = <0xf0000d00 0x100>;
278 interrupt-map-mask = <0xf800 0 0 7>; 115 interrupt-map-mask = <0xf800 0 0 7>;
279 interrupt-map = <0xc000 0 0 1 &mpc5200_pic 0 0 3 // 1st slot 116 interrupt-map = <0xc000 0 0 1 &mpc5200_pic 0 0 3 // 1st slot
280 0xc000 0 0 2 &mpc5200_pic 1 1 3 117 0xc000 0 0 2 &mpc5200_pic 1 1 3
@@ -285,20 +122,12 @@
285 0xc800 0 0 2 &mpc5200_pic 1 2 3 122 0xc800 0 0 2 &mpc5200_pic 1 2 3
286 0xc800 0 0 3 &mpc5200_pic 1 3 3 123 0xc800 0 0 3 &mpc5200_pic 1 3 3
287 0xc800 0 0 4 &mpc5200_pic 0 0 3>; 124 0xc800 0 0 4 &mpc5200_pic 0 0 3>;
288 clock-frequency = <0>; // From boot loader
289 interrupts = <2 8 0 2 9 0 2 10 0>;
290 bus-range = <0 0>;
291 ranges = <0x42000000 0 0x80000000 0x80000000 0 0x20000000 125 ranges = <0x42000000 0 0x80000000 0x80000000 0 0x20000000
292 0x02000000 0 0xa0000000 0xa0000000 0 0x10000000 126 0x02000000 0 0xa0000000 0xa0000000 0 0x10000000
293 0x01000000 0 0x00000000 0xb0000000 0 0x01000000>; 127 0x01000000 0 0x00000000 0xb0000000 0 0x01000000>;
294 }; 128 };
295 129
296 localbus { 130 localbus {
297 compatible = "fsl,mpc5200b-lpb","fsl,mpc5200-lpb","simple-bus";
298
299 #address-cells = <2>;
300 #size-cells = <1>;
301
302 ranges = <0 0 0xfe000000 0x02000000 131 ranges = <0 0 0xfe000000 0x02000000
303 1 0 0xfc000000 0x02000000 132 1 0 0xfc000000 0x02000000
304 2 0 0xfbe00000 0x00200000 133 2 0 0xfbe00000 0x00200000
@@ -351,40 +180,39 @@
351 bank-width = <2>; 180 bank-width = <2>;
352 }; 181 };
353 182
354 /* 183 /*
355 * example snippets for FPGA 184 * example snippets for FPGA
356 * 185 *
357 * fpga@3,0 { 186 * fpga@3,0 {
358 * compatible = "fpga_driver"; 187 * compatible = "fpga_driver";
359 * reg = <3 0 0x02000000>; 188 * reg = <3 0 0x02000000>;
360 * bank-width = <4>; 189 * bank-width = <4>;
361 * }; 190 * };
362 * 191 *
363 * fpga@4,0 { 192 * fpga@4,0 {
364 * compatible = "fpga_driver"; 193 * compatible = "fpga_driver";
365 * reg = <4 0 0x02000000>; 194 * reg = <4 0 0x02000000>;
366 * bank-width = <4>; 195 * bank-width = <4>;
367 * }; 196 * };
368 */ 197 */
369 198
370 /* 199 /*
371 * example snippets for free chipselects 200 * example snippets for free chipselects
372 * 201 *
373 * device@5,0 { 202 * device@5,0 {
374 * compatible = "custom_driver"; 203 * compatible = "custom_driver";
375 * reg = <5 0 0x02000000>; 204 * reg = <5 0 0x02000000>;
376 * }; 205 * };
377 * 206 *
378 * device@6,0 { 207 * device@6,0 {
379 * compatible = "custom_driver"; 208 * compatible = "custom_driver";
380 * reg = <6 0 0x02000000>; 209 * reg = <6 0 0x02000000>;
381 * }; 210 * };
382 * 211 *
383 * device@7,0 { 212 * device@7,0 {
384 * compatible = "custom_driver"; 213 * compatible = "custom_driver";
385 * reg = <7 0 0x02000000>; 214 * reg = <7 0 0x02000000>;
386 * }; 215 * };
387 */ 216 */
388 }; 217 };
389}; 218};
390
diff --git a/arch/powerpc/boot/dts/uc101.dts b/arch/powerpc/boot/dts/uc101.dts
index 019264c62904..ba83d5488ec6 100644
--- a/arch/powerpc/boot/dts/uc101.dts
+++ b/arch/powerpc/boot/dts/uc101.dts
@@ -11,79 +11,24 @@
11 * option) any later version. 11 * option) any later version.
12 */ 12 */
13 13
14/dts-v1/; 14/include/ "mpc5200b.dtsi"
15 15
16/ { 16/ {
17 model = "manroland,uc101"; 17 model = "manroland,uc101";
18 compatible = "manroland,uc101"; 18 compatible = "manroland,uc101";
19 #address-cells = <1>;
20 #size-cells = <1>;
21 interrupt-parent = <&mpc5200_pic>;
22
23 cpus {
24 #address-cells = <1>;
25 #size-cells = <0>;
26
27 PowerPC,5200@0 {
28 device_type = "cpu";
29 reg = <0>;
30 d-cache-line-size = <32>;
31 i-cache-line-size = <32>;
32 d-cache-size = <0x4000>; // L1, 16K
33 i-cache-size = <0x4000>; // L1, 16K
34 timebase-frequency = <0>; // from bootloader
35 bus-frequency = <0>; // from bootloader
36 clock-frequency = <0>; // from bootloader
37 };
38 };
39
40 memory {
41 device_type = "memory";
42 reg = <0x00000000 0x04000000>; // 64MB
43 };
44 19
45 soc5200@f0000000 { 20 soc5200@f0000000 {
46 #address-cells = <1>;
47 #size-cells = <1>;
48 compatible = "fsl,mpc5200b-immr";
49 ranges = <0 0xf0000000 0x0000c000>;
50 reg = <0xf0000000 0x00000100>;
51 bus-frequency = <0>; // from bootloader
52 system-frequency = <0>; // from bootloader
53
54 cdm@200 {
55 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
56 reg = <0x200 0x38>;
57 };
58
59 mpc5200_pic: interrupt-controller@500 {
60 // 5200 interrupts are encoded into two levels;
61 interrupt-controller;
62 #interrupt-cells = <3>;
63 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
64 reg = <0x500 0x80>;
65 };
66
67 gpt0: timer@600 { // General Purpose Timer in GPIO mode 21 gpt0: timer@600 { // General Purpose Timer in GPIO mode
68 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
69 reg = <0x600 0x10>;
70 interrupts = <1 9 0>;
71 gpio-controller; 22 gpio-controller;
72 #gpio-cells = <2>; 23 #gpio-cells = <2>;
73 }; 24 };
74 25
75 gpt1: timer@610 { // General Purpose Timer in GPIO mode 26 gpt1: timer@610 { // General Purpose Timer in GPIO mode
76 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
77 reg = <0x610 0x10>;
78 interrupts = <1 10 0>;
79 gpio-controller; 27 gpio-controller;
80 #gpio-cells = <2>; 28 #gpio-cells = <2>;
81 }; 29 };
82 30
83 gpt2: timer@620 { // General Purpose Timer in GPIO mode 31 gpt2: timer@620 { // General Purpose Timer in GPIO mode
84 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
85 reg = <0x620 0x10>;
86 interrupts = <1 11 0>;
87 gpio-controller; 32 gpio-controller;
88 #gpio-cells = <2>; 33 #gpio-cells = <2>;
89 }; 34 };
@@ -97,118 +42,85 @@
97 }; 42 };
98 43
99 gpt4: timer@640 { // General Purpose Timer in GPIO mode 44 gpt4: timer@640 { // General Purpose Timer in GPIO mode
100 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
101 reg = <0x640 0x10>;
102 interrupts = <1 13 0>;
103 gpio-controller; 45 gpio-controller;
104 #gpio-cells = <2>; 46 #gpio-cells = <2>;
105 }; 47 };
106 48
107 gpt5: timer@650 { // General Purpose Timer in GPIO mode 49 gpt5: timer@650 { // General Purpose Timer in GPIO mode
108 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
109 reg = <0x650 0x10>;
110 interrupts = <1 14 0>;
111 gpio-controller; 50 gpio-controller;
112 #gpio-cells = <2>; 51 #gpio-cells = <2>;
113 }; 52 };
114 53
115 gpt6: timer@660 { // General Purpose Timer in GPIO mode 54 gpt6: timer@660 { // General Purpose Timer in GPIO mode
116 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
117 reg = <0x660 0x10>;
118 interrupts = <1 15 0>;
119 gpio-controller; 55 gpio-controller;
120 #gpio-cells = <2>; 56 #gpio-cells = <2>;
121 }; 57 };
122 58
123 gpt7: timer@670 { // General Purpose Timer in GPIO mode 59 gpt7: timer@670 { // General Purpose Timer in GPIO mode
124 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
125 reg = <0x670 0x10>;
126 interrupts = <1 16 0>;
127 gpio-controller; 60 gpio-controller;
128 #gpio-cells = <2>; 61 #gpio-cells = <2>;
129 }; 62 };
130 63
131 gpio_simple: gpio@b00 { 64 rtc@800 {
132 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio"; 65 status = "disabled";
133 reg = <0xb00 0x40>;
134 interrupts = <1 7 0>;
135 gpio-controller;
136 #gpio-cells = <2>;
137 }; 66 };
138 67
139 gpio_wkup: gpio@c00 { 68 can@900 {
140 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup"; 69 status = "disabled";
141 reg = <0xc00 0x40>; 70 };
142 interrupts = <1 8 0 0 3 0>; 71
143 gpio-controller; 72 can@980 {
144 #gpio-cells = <2>; 73 status = "disabled";
145 }; 74 };
146 75
147 dma-controller@1200 { 76 spi@f00 {
148 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm"; 77 status = "disabled";
149 reg = <0x1200 0x80>;
150 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
151 3 4 0 3 5 0 3 6 0 3 7 0
152 3 8 0 3 9 0 3 10 0 3 11 0
153 3 12 0 3 13 0 3 14 0 3 15 0>;
154 }; 78 };
155 79
156 xlb@1f00 { 80 usb@1000 {
157 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb"; 81 status = "disabled";
158 reg = <0x1f00 0x100>;
159 }; 82 };
160 83
161 serial@2000 { /* PSC1 in UART mode */ 84 psc@2000 { // PSC1
162 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 85 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
163 reg = <0x2000 0x100>;
164 interrupts = <2 1 0>;
165 }; 86 };
166 87
167 serial@2200 { /* PSC2 in UART mode */ 88 psc@2200 { // PSC2
168 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 89 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
169 reg = <0x2200 0x100>;
170 interrupts = <2 2 0>;
171 }; 90 };
172 91
173 serial@2c00 { /* PSC6 in UART mode */ 92 psc@2400 { // PSC3
93 status = "disabled";
94 };
95
96 psc@2600 { // PSC4
97 status = "disabled";
98 };
99
100 psc@2800 { // PSC5
101 status = "disabled";
102 };
103
104 psc@2c00 { // PSC6
174 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 105 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
175 reg = <0x2c00 0x100>;
176 interrupts = <2 4 0>;
177 }; 106 };
178 107
179 ethernet@3000 { 108 ethernet@3000 {
180 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
181 reg = <0x3000 0x400>;
182 local-mac-address = [ 00 00 00 00 00 00 ];
183 interrupts = <2 5 0>;
184 phy-handle = <&phy0>; 109 phy-handle = <&phy0>;
185 }; 110 };
186 111
187 mdio@3000 { 112 mdio@3000 {
188 #address-cells = <1>;
189 #size-cells = <0>;
190 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
191 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
192 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
193
194 phy0: ethernet-phy@0 { 113 phy0: ethernet-phy@0 {
195 compatible = "intel,lxt971"; 114 compatible = "intel,lxt971";
196 reg = <0>; 115 reg = <0>;
197 }; 116 };
198 }; 117 };
199 118
200 ata@3a00 { 119 i2c@3d00 {
201 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata"; 120 status = "disabled";
202 reg = <0x3a00 0x100>;
203 interrupts = <2 7 0>;
204 }; 121 };
205 122
206 i2c@3d40 { 123 i2c@3d40 {
207 #address-cells = <1>;
208 #size-cells = <0>;
209 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
210 reg = <0x3d40 0x40>;
211 interrupts = <2 16 0>;
212 fsl,preserve-clocking; 124 fsl,preserve-clocking;
213 clock-frequency = <400000>; 125 clock-frequency = <400000>;
214 126
@@ -221,19 +133,13 @@
221 reg = <0x51>; 133 reg = <0x51>;
222 }; 134 };
223 }; 135 };
136 };
224 137
225 sram@8000 { 138 pci@f0000d00 {
226 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram"; 139 status = "disabled";
227 reg = <0x8000 0x4000>;
228 };
229 }; 140 };
230 141
231 localbus { 142 localbus {
232 compatible = "fsl,mpc5200b-lpb","fsl,mpc5200-lpb","simple-bus";
233
234 #address-cells = <2>;
235 #size-cells = <1>;
236
237 ranges = <0 0 0xff800000 0x00800000 143 ranges = <0 0 0xff800000 0x00800000
238 1 0 0x80000000 0x00800000 144 1 0 0x80000000 0x00800000
239 3 0 0x80000000 0x00800000>; 145 3 0 0x80000000 0x00800000>;
diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
index ae26f2efd089..d72757585595 100644
--- a/arch/powerpc/include/asm/prom.h
+++ b/arch/powerpc/include/asm/prom.h
@@ -42,7 +42,7 @@ extern void pci_create_OF_bus_map(void);
42 42
43/* Translate a DMA address from device space to CPU space */ 43/* Translate a DMA address from device space to CPU space */
44extern u64 of_translate_dma_address(struct device_node *dev, 44extern u64 of_translate_dma_address(struct device_node *dev,
45 const u32 *in_addr); 45 const __be32 *in_addr);
46 46
47#ifdef CONFIG_PCI 47#ifdef CONFIG_PCI
48extern unsigned long pci_address_to_pio(phys_addr_t address); 48extern unsigned long pci_address_to_pio(phys_addr_t address);
@@ -63,9 +63,6 @@ struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
63/* cache lookup */ 63/* cache lookup */
64struct device_node *of_find_next_cache_node(struct device_node *np); 64struct device_node *of_find_next_cache_node(struct device_node *np);
65 65
66/* Get the MAC address */
67extern const void *of_get_mac_address(struct device_node *np);
68
69#ifdef CONFIG_NUMA 66#ifdef CONFIG_NUMA
70extern int of_node_to_nid(struct device_node *device); 67extern int of_node_to_nid(struct device_node *device);
71#else 68#else
diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index 88334af038e5..c2b7a07cc3d3 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -117,41 +117,3 @@ void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
117 cells = prop ? *(u32 *)prop : of_n_size_cells(dn); 117 cells = prop ? *(u32 *)prop : of_n_size_cells(dn);
118 *size = of_read_number(dma_window, cells); 118 *size = of_read_number(dma_window, cells);
119} 119}
120
121/**
122 * Search the device tree for the best MAC address to use. 'mac-address' is
123 * checked first, because that is supposed to contain to "most recent" MAC
124 * address. If that isn't set, then 'local-mac-address' is checked next,
125 * because that is the default address. If that isn't set, then the obsolete
126 * 'address' is checked, just in case we're using an old device tree.
127 *
128 * Note that the 'address' property is supposed to contain a virtual address of
129 * the register set, but some DTS files have redefined that property to be the
130 * MAC address.
131 *
132 * All-zero MAC addresses are rejected, because those could be properties that
133 * exist in the device tree, but were not set by U-Boot. For example, the
134 * DTS could define 'mac-address' and 'local-mac-address', with zero MAC
135 * addresses. Some older U-Boots only initialized 'local-mac-address'. In
136 * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
137 * but is all zeros.
138*/
139const void *of_get_mac_address(struct device_node *np)
140{
141 struct property *pp;
142
143 pp = of_find_property(np, "mac-address", NULL);
144 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
145 return pp->value;
146
147 pp = of_find_property(np, "local-mac-address", NULL);
148 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
149 return pp->value;
150
151 pp = of_find_property(np, "address", NULL);
152 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
153 return pp->value;
154
155 return NULL;
156}
157EXPORT_SYMBOL(of_get_mac_address);
diff --git a/arch/powerpc/platforms/40x/ppc40x_simple.c b/arch/powerpc/platforms/40x/ppc40x_simple.c
index 546bbc229d19..2521d93ef136 100644
--- a/arch/powerpc/platforms/40x/ppc40x_simple.c
+++ b/arch/powerpc/platforms/40x/ppc40x_simple.c
@@ -50,7 +50,7 @@ machine_device_initcall(ppc40x_simple, ppc40x_device_probe);
50 * Again, if your board needs to do things differently then create a 50 * Again, if your board needs to do things differently then create a
51 * board.c file for it rather than adding it to this list. 51 * board.c file for it rather than adding it to this list.
52 */ 52 */
53static char *board[] __initdata = { 53static const char *board[] __initdata = {
54 "amcc,acadia", 54 "amcc,acadia",
55 "amcc,haleakala", 55 "amcc,haleakala",
56 "amcc,kilauea", 56 "amcc,kilauea",
@@ -60,14 +60,9 @@ static char *board[] __initdata = {
60 60
61static int __init ppc40x_probe(void) 61static int __init ppc40x_probe(void)
62{ 62{
63 unsigned long root = of_get_flat_dt_root(); 63 if (of_flat_dt_match(of_get_flat_dt_root(), board)) {
64 int i = 0; 64 ppc_pci_set_flags(PPC_PCI_REASSIGN_ALL_RSRC);
65 65 return 1;
66 for (i = 0; i < ARRAY_SIZE(board); i++) {
67 if (of_flat_dt_is_compatible(root, board[i])) {
68 ppc_pci_set_flags(PPC_PCI_REASSIGN_ALL_RSRC);
69 return 1;
70 }
71 } 66 }
72 67
73 return 0; 68 return 0;
diff --git a/arch/powerpc/platforms/512x/mpc5121_generic.c b/arch/powerpc/platforms/512x/mpc5121_generic.c
index e487eb06ec6b..926731f1ff01 100644
--- a/arch/powerpc/platforms/512x/mpc5121_generic.c
+++ b/arch/powerpc/platforms/512x/mpc5121_generic.c
@@ -26,7 +26,7 @@
26/* 26/*
27 * list of supported boards 27 * list of supported boards
28 */ 28 */
29static char *board[] __initdata = { 29static const char *board[] __initdata = {
30 "prt,prtlvt", 30 "prt,prtlvt",
31 NULL 31 NULL
32}; 32};
@@ -36,16 +36,7 @@ static char *board[] __initdata = {
36 */ 36 */
37static int __init mpc5121_generic_probe(void) 37static int __init mpc5121_generic_probe(void)
38{ 38{
39 unsigned long node = of_get_flat_dt_root(); 39 return of_flat_dt_match(of_get_flat_dt_root(), board);
40 int i = 0;
41
42 while (board[i]) {
43 if (of_flat_dt_is_compatible(node, board[i]))
44 break;
45 i++;
46 }
47
48 return board[i] != NULL;
49} 40}
50 41
51define_machine(mpc5121_generic) { 42define_machine(mpc5121_generic) {
diff --git a/arch/powerpc/platforms/52xx/lite5200.c b/arch/powerpc/platforms/52xx/lite5200.c
index de55bc0584b5..01ffa64d2aa7 100644
--- a/arch/powerpc/platforms/52xx/lite5200.c
+++ b/arch/powerpc/platforms/52xx/lite5200.c
@@ -172,20 +172,18 @@ static void __init lite5200_setup_arch(void)
172 mpc52xx_setup_pci(); 172 mpc52xx_setup_pci();
173} 173}
174 174
175static const char *board[] __initdata = {
176 "fsl,lite5200",
177 "fsl,lite5200b",
178 NULL,
179};
180
175/* 181/*
176 * Called very early, MMU is off, device-tree isn't unflattened 182 * Called very early, MMU is off, device-tree isn't unflattened
177 */ 183 */
178static int __init lite5200_probe(void) 184static int __init lite5200_probe(void)
179{ 185{
180 unsigned long node = of_get_flat_dt_root(); 186 return of_flat_dt_match(of_get_flat_dt_root(), board);
181 const char *model = of_get_flat_dt_prop(node, "model", NULL);
182
183 if (!of_flat_dt_is_compatible(node, "fsl,lite5200") &&
184 !of_flat_dt_is_compatible(node, "fsl,lite5200b"))
185 return 0;
186 pr_debug("%s board found\n", model ? model : "unknown");
187
188 return 1;
189} 187}
190 188
191define_machine(lite5200) { 189define_machine(lite5200) {
diff --git a/arch/powerpc/platforms/52xx/media5200.c b/arch/powerpc/platforms/52xx/media5200.c
index 0bac3a3dbecf..2c7780cb68e5 100644
--- a/arch/powerpc/platforms/52xx/media5200.c
+++ b/arch/powerpc/platforms/52xx/media5200.c
@@ -239,7 +239,7 @@ static void __init media5200_setup_arch(void)
239} 239}
240 240
241/* list of the supported boards */ 241/* list of the supported boards */
242static char *board[] __initdata = { 242static const char *board[] __initdata = {
243 "fsl,media5200", 243 "fsl,media5200",
244 NULL 244 NULL
245}; 245};
@@ -249,16 +249,7 @@ static char *board[] __initdata = {
249 */ 249 */
250static int __init media5200_probe(void) 250static int __init media5200_probe(void)
251{ 251{
252 unsigned long node = of_get_flat_dt_root(); 252 return of_flat_dt_match(of_get_flat_dt_root(), board);
253 int i = 0;
254
255 while (board[i]) {
256 if (of_flat_dt_is_compatible(node, board[i]))
257 break;
258 i++;
259 }
260
261 return (board[i] != NULL);
262} 253}
263 254
264define_machine(media5200_platform) { 255define_machine(media5200_platform) {
diff --git a/arch/powerpc/platforms/52xx/mpc5200_simple.c b/arch/powerpc/platforms/52xx/mpc5200_simple.c
index d45be5b5ad49..e36d6e232ae6 100644
--- a/arch/powerpc/platforms/52xx/mpc5200_simple.c
+++ b/arch/powerpc/platforms/52xx/mpc5200_simple.c
@@ -49,7 +49,7 @@ static void __init mpc5200_simple_setup_arch(void)
49} 49}
50 50
51/* list of the supported boards */ 51/* list of the supported boards */
52static char *board[] __initdata = { 52static const char *board[] __initdata = {
53 "intercontrol,digsy-mtc", 53 "intercontrol,digsy-mtc",
54 "manroland,mucmc52", 54 "manroland,mucmc52",
55 "manroland,uc101", 55 "manroland,uc101",
@@ -66,16 +66,7 @@ static char *board[] __initdata = {
66 */ 66 */
67static int __init mpc5200_simple_probe(void) 67static int __init mpc5200_simple_probe(void)
68{ 68{
69 unsigned long node = of_get_flat_dt_root(); 69 return of_flat_dt_match(of_get_flat_dt_root(), board);
70 int i = 0;
71
72 while (board[i]) {
73 if (of_flat_dt_is_compatible(node, board[i]))
74 break;
75 i++;
76 }
77
78 return (board[i] != NULL);
79} 70}
80 71
81define_machine(mpc5200_simple_platform) { 72define_machine(mpc5200_simple_platform) {
diff --git a/arch/powerpc/platforms/83xx/mpc830x_rdb.c b/arch/powerpc/platforms/83xx/mpc830x_rdb.c
index 846831d495b5..661d354e4ff2 100644
--- a/arch/powerpc/platforms/83xx/mpc830x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc830x_rdb.c
@@ -57,16 +57,19 @@ static void __init mpc830x_rdb_init_IRQ(void)
57 ipic_set_default_priority(); 57 ipic_set_default_priority();
58} 58}
59 59
60struct const char *board[] __initdata = {
61 "MPC8308RDB",
62 "fsl,mpc8308rdb",
63 "denx,mpc8308_p1m",
64 NULL
65}
66
60/* 67/*
61 * Called very early, MMU is off, device-tree isn't unflattened 68 * Called very early, MMU is off, device-tree isn't unflattened
62 */ 69 */
63static int __init mpc830x_rdb_probe(void) 70static int __init mpc830x_rdb_probe(void)
64{ 71{
65 unsigned long root = of_get_flat_dt_root(); 72 return of_flat_dt_match(of_get_flat_dt_root(), board);
66
67 return of_flat_dt_is_compatible(root, "MPC8308RDB") ||
68 of_flat_dt_is_compatible(root, "fsl,mpc8308rdb") ||
69 of_flat_dt_is_compatible(root, "denx,mpc8308_p1m");
70} 73}
71 74
72static struct of_device_id __initdata of_bus_ids[] = { 75static struct of_device_id __initdata of_bus_ids[] = {
diff --git a/arch/powerpc/platforms/83xx/mpc831x_rdb.c b/arch/powerpc/platforms/83xx/mpc831x_rdb.c
index ae525e4745d2..b54cd736a895 100644
--- a/arch/powerpc/platforms/83xx/mpc831x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc831x_rdb.c
@@ -60,15 +60,18 @@ static void __init mpc831x_rdb_init_IRQ(void)
60 ipic_set_default_priority(); 60 ipic_set_default_priority();
61} 61}
62 62
63struct const char *board[] __initdata = {
64 "MPC8313ERDB",
65 "fsl,mpc8315erdb",
66 NULL
67}
68
63/* 69/*
64 * Called very early, MMU is off, device-tree isn't unflattened 70 * Called very early, MMU is off, device-tree isn't unflattened
65 */ 71 */
66static int __init mpc831x_rdb_probe(void) 72static int __init mpc831x_rdb_probe(void)
67{ 73{
68 unsigned long root = of_get_flat_dt_root(); 74 return of_flat_dt_match(of_get_flat_dt_root(), board);
69
70 return of_flat_dt_is_compatible(root, "MPC8313ERDB") ||
71 of_flat_dt_is_compatible(root, "fsl,mpc8315erdb");
72} 75}
73 76
74static struct of_device_id __initdata of_bus_ids[] = { 77static struct of_device_id __initdata of_bus_ids[] = {
diff --git a/arch/powerpc/platforms/83xx/mpc837x_rdb.c b/arch/powerpc/platforms/83xx/mpc837x_rdb.c
index 910caa6b5810..7bafbf2ec0f9 100644
--- a/arch/powerpc/platforms/83xx/mpc837x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc837x_rdb.c
@@ -101,17 +101,20 @@ static void __init mpc837x_rdb_init_IRQ(void)
101 ipic_set_default_priority(); 101 ipic_set_default_priority();
102} 102}
103 103
104static const char *board[] __initdata = {
105 "fsl,mpc8377rdb",
106 "fsl,mpc8378rdb",
107 "fsl,mpc8379rdb",
108 "fsl,mpc8377wlan",
109 NULL
110};
111
104/* 112/*
105 * Called very early, MMU is off, device-tree isn't unflattened 113 * Called very early, MMU is off, device-tree isn't unflattened
106 */ 114 */
107static int __init mpc837x_rdb_probe(void) 115static int __init mpc837x_rdb_probe(void)
108{ 116{
109 unsigned long root = of_get_flat_dt_root(); 117 return of_flat_dt_match(of_get_flat_dt_root(), board);
110
111 return of_flat_dt_is_compatible(root, "fsl,mpc8377rdb") ||
112 of_flat_dt_is_compatible(root, "fsl,mpc8378rdb") ||
113 of_flat_dt_is_compatible(root, "fsl,mpc8379rdb") ||
114 of_flat_dt_is_compatible(root, "fsl,mpc8377wlan");
115} 118}
116 119
117define_machine(mpc837x_rdb) { 120define_machine(mpc837x_rdb) {
diff --git a/arch/powerpc/platforms/85xx/tqm85xx.c b/arch/powerpc/platforms/85xx/tqm85xx.c
index 8f29bbce5360..5e847d0b47c8 100644
--- a/arch/powerpc/platforms/85xx/tqm85xx.c
+++ b/arch/powerpc/platforms/85xx/tqm85xx.c
@@ -186,21 +186,21 @@ static int __init declare_of_platform_devices(void)
186} 186}
187machine_device_initcall(tqm85xx, declare_of_platform_devices); 187machine_device_initcall(tqm85xx, declare_of_platform_devices);
188 188
189static const char *board[] __initdata = {
190 "tqc,tqm8540",
191 "tqc,tqm8541",
192 "tqc,tqm8548",
193 "tqc,tqm8555",
194 "tqc,tqm8560",
195 NULL
196};
197
189/* 198/*
190 * Called very early, device-tree isn't unflattened 199 * Called very early, device-tree isn't unflattened
191 */ 200 */
192static int __init tqm85xx_probe(void) 201static int __init tqm85xx_probe(void)
193{ 202{
194 unsigned long root = of_get_flat_dt_root(); 203 return of_flat_dt_match(of_get_flat_dt_root(), board);
195
196 if ((of_flat_dt_is_compatible(root, "tqc,tqm8540")) ||
197 (of_flat_dt_is_compatible(root, "tqc,tqm8541")) ||
198 (of_flat_dt_is_compatible(root, "tqc,tqm8548")) ||
199 (of_flat_dt_is_compatible(root, "tqc,tqm8555")) ||
200 (of_flat_dt_is_compatible(root, "tqc,tqm8560")))
201 return 1;
202
203 return 0;
204} 204}
205 205
206define_machine(tqm85xx) { 206define_machine(tqm85xx) {
diff --git a/arch/powerpc/platforms/pseries/eeh_sysfs.c b/arch/powerpc/platforms/pseries/eeh_sysfs.c
index 15e13b568904..23982c7892d2 100644
--- a/arch/powerpc/platforms/pseries/eeh_sysfs.c
+++ b/arch/powerpc/platforms/pseries/eeh_sysfs.c
@@ -25,7 +25,6 @@
25#include <linux/pci.h> 25#include <linux/pci.h>
26#include <asm/ppc-pci.h> 26#include <asm/ppc-pci.h>
27#include <asm/pci-bridge.h> 27#include <asm/pci-bridge.h>
28#include <linux/kobject.h>
29 28
30/** 29/**
31 * EEH_SHOW_ATTR -- create sysfs entry for eeh statistic 30 * EEH_SHOW_ATTR -- create sysfs entry for eeh statistic
diff --git a/arch/powerpc/sysdev/mv64x60_dev.c b/arch/powerpc/sysdev/mv64x60_dev.c
index 1398bc454999..feaee402e2d6 100644
--- a/arch/powerpc/sysdev/mv64x60_dev.c
+++ b/arch/powerpc/sysdev/mv64x60_dev.c
@@ -16,6 +16,7 @@
16#include <linux/mv643xx.h> 16#include <linux/mv643xx.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/of_platform.h> 18#include <linux/of_platform.h>
19#include <linux/of_net.h>
19#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
20 21
21#include <asm/prom.h> 22#include <asm/prom.h>
diff --git a/arch/powerpc/sysdev/tsi108_dev.c b/arch/powerpc/sysdev/tsi108_dev.c
index d4d15aaf18fa..c2d675b6392c 100644
--- a/arch/powerpc/sysdev/tsi108_dev.c
+++ b/arch/powerpc/sysdev/tsi108_dev.c
@@ -19,6 +19,7 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/of_net.h>
22#include <asm/tsi108.h> 23#include <asm/tsi108.h>
23 24
24#include <asm/system.h> 25#include <asm/system.h>
diff --git a/arch/sparc/kernel/auxio_32.c b/arch/sparc/kernel/auxio_32.c
index 35f48837871a..8505e0ac78ba 100644
--- a/arch/sparc/kernel/auxio_32.c
+++ b/arch/sparc/kernel/auxio_32.c
@@ -121,7 +121,7 @@ void __init auxio_power_probe(void)
121 node = prom_searchsiblings(node, "obio"); 121 node = prom_searchsiblings(node, "obio");
122 node = prom_getchild(node); 122 node = prom_getchild(node);
123 node = prom_searchsiblings(node, "power"); 123 node = prom_searchsiblings(node, "power");
124 if (node == 0 || node == -1) 124 if (node == 0 || (s32)node == -1)
125 return; 125 return;
126 126
127 /* Map the power control register. */ 127 /* Map the power control register. */
diff --git a/arch/sparc/kernel/starfire.c b/arch/sparc/kernel/starfire.c
index a4446c0fb7a1..82281a566bb8 100644
--- a/arch/sparc/kernel/starfire.c
+++ b/arch/sparc/kernel/starfire.c
@@ -24,7 +24,7 @@ int this_is_starfire = 0;
24void check_if_starfire(void) 24void check_if_starfire(void)
25{ 25{
26 phandle ssnode = prom_finddevice("/ssp-serial"); 26 phandle ssnode = prom_finddevice("/ssp-serial");
27 if (ssnode != 0 && ssnode != -1) 27 if (ssnode != 0 && (s32)ssnode != -1)
28 this_is_starfire = 1; 28 this_is_starfire = 1;
29} 29}
30 30
diff --git a/arch/sparc/prom/init_32.c b/arch/sparc/prom/init_32.c
index d342dba4dd54..0a601b300639 100644
--- a/arch/sparc/prom/init_32.c
+++ b/arch/sparc/prom/init_32.c
@@ -60,7 +60,7 @@ void __init prom_init(struct linux_romvec *rp)
60 prom_nodeops = romvec->pv_nodeops; 60 prom_nodeops = romvec->pv_nodeops;
61 61
62 prom_root_node = prom_getsibling(0); 62 prom_root_node = prom_getsibling(0);
63 if((prom_root_node == 0) || (prom_root_node == -1)) 63 if ((prom_root_node == 0) || ((s32)prom_root_node == -1))
64 prom_halt(); 64 prom_halt();
65 65
66 if((((unsigned long) prom_nodeops) == 0) || 66 if((((unsigned long) prom_nodeops) == 0) ||
diff --git a/arch/sparc/prom/init_64.c b/arch/sparc/prom/init_64.c
index 9c6ac4b81ded..5016c5e20575 100644
--- a/arch/sparc/prom/init_64.c
+++ b/arch/sparc/prom/init_64.c
@@ -35,13 +35,13 @@ void __init prom_init(void *cif_handler, void *cif_stack)
35 prom_cif_init(cif_handler, cif_stack); 35 prom_cif_init(cif_handler, cif_stack);
36 36
37 prom_chosen_node = prom_finddevice(prom_chosen_path); 37 prom_chosen_node = prom_finddevice(prom_chosen_path);
38 if (!prom_chosen_node || prom_chosen_node == -1) 38 if (!prom_chosen_node || (s32)prom_chosen_node == -1)
39 prom_halt(); 39 prom_halt();
40 40
41 prom_stdout = prom_getint(prom_chosen_node, "stdout"); 41 prom_stdout = prom_getint(prom_chosen_node, "stdout");
42 42
43 node = prom_finddevice("/openprom"); 43 node = prom_finddevice("/openprom");
44 if (!node || node == -1) 44 if (!node || (s32)node == -1)
45 prom_halt(); 45 prom_halt();
46 46
47 prom_getstring(node, "version", prom_version, sizeof(prom_version)); 47 prom_getstring(node, "version", prom_version, sizeof(prom_version));
diff --git a/arch/sparc/prom/tree_32.c b/arch/sparc/prom/tree_32.c
index bc8e4cb87a68..f30e8d038f01 100644
--- a/arch/sparc/prom/tree_32.c
+++ b/arch/sparc/prom/tree_32.c
@@ -40,11 +40,11 @@ phandle prom_getchild(phandle node)
40{ 40{
41 phandle cnode; 41 phandle cnode;
42 42
43 if (node == -1) 43 if ((s32)node == -1)
44 return 0; 44 return 0;
45 45
46 cnode = __prom_getchild(node); 46 cnode = __prom_getchild(node);
47 if (cnode == 0 || cnode == -1) 47 if (cnode == 0 || (s32)cnode == -1)
48 return 0; 48 return 0;
49 49
50 return cnode; 50 return cnode;
@@ -72,11 +72,11 @@ phandle prom_getsibling(phandle node)
72{ 72{
73 phandle sibnode; 73 phandle sibnode;
74 74
75 if (node == -1) 75 if ((s32)node == -1)
76 return 0; 76 return 0;
77 77
78 sibnode = __prom_getsibling(node); 78 sibnode = __prom_getsibling(node);
79 if (sibnode == 0 || sibnode == -1) 79 if (sibnode == 0 || (s32)sibnode == -1)
80 return 0; 80 return 0;
81 81
82 return sibnode; 82 return sibnode;
@@ -219,7 +219,7 @@ static char *__prom_nextprop(phandle node, char * oprop)
219 */ 219 */
220char *prom_nextprop(phandle node, char *oprop, char *buffer) 220char *prom_nextprop(phandle node, char *oprop, char *buffer)
221{ 221{
222 if (node == 0 || node == -1) 222 if (node == 0 || (s32)node == -1)
223 return ""; 223 return "";
224 224
225 return __prom_nextprop(node, oprop); 225 return __prom_nextprop(node, oprop);
@@ -253,7 +253,7 @@ phandle prom_finddevice(char *name)
253 if (d != s + 3 && (!*d || *d == '/') 253 if (d != s + 3 && (!*d || *d == '/')
254 && d <= s + 3 + 8) { 254 && d <= s + 3 + 8) {
255 node2 = node; 255 node2 = node;
256 while (node2 && node2 != -1) { 256 while (node2 && (s32)node2 != -1) {
257 if (prom_getproperty (node2, "reg", (char *)reg, sizeof (reg)) > 0) { 257 if (prom_getproperty (node2, "reg", (char *)reg, sizeof (reg)) > 0) {
258 if (which_io == reg[0].which_io && phys_addr == reg[0].phys_addr) { 258 if (which_io == reg[0].which_io && phys_addr == reg[0].phys_addr) {
259 node = node2; 259 node = node2;
@@ -261,7 +261,7 @@ phandle prom_finddevice(char *name)
261 } 261 }
262 } 262 }
263 node2 = prom_getsibling(node2); 263 node2 = prom_getsibling(node2);
264 if (!node2 || node2 == -1) 264 if (!node2 || (s32)node2 == -1)
265 break; 265 break;
266 node2 = prom_searchsiblings(prom_getsibling(node2), nbuf); 266 node2 = prom_searchsiblings(prom_getsibling(node2), nbuf);
267 } 267 }
@@ -303,6 +303,7 @@ phandle prom_inst2pkg(int inst)
303 node = (*romvec->pv_v2devops.v2_inst2pkg)(inst); 303 node = (*romvec->pv_v2devops.v2_inst2pkg)(inst);
304 restore_current(); 304 restore_current();
305 spin_unlock_irqrestore(&prom_lock, flags); 305 spin_unlock_irqrestore(&prom_lock, flags);
306 if (node == -1) return 0; 306 if ((s32)node == -1)
307 return 0;
307 return node; 308 return node;
308} 309}
diff --git a/arch/sparc/prom/tree_64.c b/arch/sparc/prom/tree_64.c
index d93660048376..92204c3800b5 100644
--- a/arch/sparc/prom/tree_64.c
+++ b/arch/sparc/prom/tree_64.c
@@ -43,10 +43,10 @@ inline phandle prom_getchild(phandle node)
43{ 43{
44 phandle cnode; 44 phandle cnode;
45 45
46 if (node == -1) 46 if ((s32)node == -1)
47 return 0; 47 return 0;
48 cnode = __prom_getchild(node); 48 cnode = __prom_getchild(node);
49 if (cnode == -1) 49 if ((s32)cnode == -1)
50 return 0; 50 return 0;
51 return cnode; 51 return cnode;
52} 52}
@@ -56,10 +56,10 @@ inline phandle prom_getparent(phandle node)
56{ 56{
57 phandle cnode; 57 phandle cnode;
58 58
59 if (node == -1) 59 if ((s32)node == -1)
60 return 0; 60 return 0;
61 cnode = prom_node_to_node("parent", node); 61 cnode = prom_node_to_node("parent", node);
62 if (cnode == -1) 62 if ((s32)cnode == -1)
63 return 0; 63 return 0;
64 return cnode; 64 return cnode;
65} 65}
@@ -76,10 +76,10 @@ inline phandle prom_getsibling(phandle node)
76{ 76{
77 phandle sibnode; 77 phandle sibnode;
78 78
79 if (node == -1) 79 if ((s32)node == -1)
80 return 0; 80 return 0;
81 sibnode = __prom_getsibling(node); 81 sibnode = __prom_getsibling(node);
82 if (sibnode == -1) 82 if ((s32)sibnode == -1)
83 return 0; 83 return 0;
84 84
85 return sibnode; 85 return sibnode;
@@ -240,7 +240,7 @@ inline char *prom_firstprop(phandle node, char *buffer)
240 unsigned long args[7]; 240 unsigned long args[7];
241 241
242 *buffer = 0; 242 *buffer = 0;
243 if (node == -1) 243 if ((s32)node == -1)
244 return buffer; 244 return buffer;
245 245
246 args[0] = (unsigned long) prom_nextprop_name; 246 args[0] = (unsigned long) prom_nextprop_name;
@@ -266,7 +266,7 @@ inline char *prom_nextprop(phandle node, const char *oprop, char *buffer)
266 unsigned long args[7]; 266 unsigned long args[7];
267 char buf[32]; 267 char buf[32];
268 268
269 if (node == -1) { 269 if ((s32)node == -1) {
270 *buffer = 0; 270 *buffer = 0;
271 return buffer; 271 return buffer;
272 } 272 }
@@ -369,7 +369,7 @@ inline phandle prom_inst2pkg(int inst)
369 p1275_cmd_direct(args); 369 p1275_cmd_direct(args);
370 370
371 node = (int) args[4]; 371 node = (int) args[4];
372 if (node == -1) 372 if ((s32)node == -1)
373 return 0; 373 return 0;
374 return node; 374 return node;
375} 375}
diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hypervisor.h
index ff2546ce7178..7a15153c675d 100644
--- a/arch/x86/include/asm/hypervisor.h
+++ b/arch/x86/include/asm/hypervisor.h
@@ -20,6 +20,9 @@
20#ifndef _ASM_X86_HYPERVISOR_H 20#ifndef _ASM_X86_HYPERVISOR_H
21#define _ASM_X86_HYPERVISOR_H 21#define _ASM_X86_HYPERVISOR_H
22 22
23#include <asm/kvm_para.h>
24#include <asm/xen/hypervisor.h>
25
23extern void init_hypervisor(struct cpuinfo_x86 *c); 26extern void init_hypervisor(struct cpuinfo_x86 *c);
24extern void init_hypervisor_platform(void); 27extern void init_hypervisor_platform(void);
25 28
@@ -47,4 +50,13 @@ extern const struct hypervisor_x86 x86_hyper_vmware;
47extern const struct hypervisor_x86 x86_hyper_ms_hyperv; 50extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
48extern const struct hypervisor_x86 x86_hyper_xen_hvm; 51extern const struct hypervisor_x86 x86_hyper_xen_hvm;
49 52
53static inline bool hypervisor_x2apic_available(void)
54{
55 if (kvm_para_available())
56 return true;
57 if (xen_x2apic_para_available())
58 return true;
59 return false;
60}
61
50#endif 62#endif
diff --git a/arch/x86/include/asm/xen/hypervisor.h b/arch/x86/include/asm/xen/hypervisor.h
index 396ff4cc8ed4..66d0fff1ee84 100644
--- a/arch/x86/include/asm/xen/hypervisor.h
+++ b/arch/x86/include/asm/xen/hypervisor.h
@@ -37,4 +37,39 @@
37extern struct shared_info *HYPERVISOR_shared_info; 37extern struct shared_info *HYPERVISOR_shared_info;
38extern struct start_info *xen_start_info; 38extern struct start_info *xen_start_info;
39 39
40#include <asm/processor.h>
41
42static inline uint32_t xen_cpuid_base(void)
43{
44 uint32_t base, eax, ebx, ecx, edx;
45 char signature[13];
46
47 for (base = 0x40000000; base < 0x40010000; base += 0x100) {
48 cpuid(base, &eax, &ebx, &ecx, &edx);
49 *(uint32_t *)(signature + 0) = ebx;
50 *(uint32_t *)(signature + 4) = ecx;
51 *(uint32_t *)(signature + 8) = edx;
52 signature[12] = 0;
53
54 if (!strcmp("XenVMMXenVMM", signature) && ((eax - base) >= 2))
55 return base;
56 }
57
58 return 0;
59}
60
61#ifdef CONFIG_XEN
62extern bool xen_hvm_need_lapic(void);
63
64static inline bool xen_x2apic_para_available(void)
65{
66 return xen_hvm_need_lapic();
67}
68#else
69static inline bool xen_x2apic_para_available(void)
70{
71 return (xen_cpuid_base() != 0);
72}
73#endif
74
40#endif /* _ASM_X86_XEN_HYPERVISOR_H */ 75#endif /* _ASM_X86_XEN_HYPERVISOR_H */
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 79e6baa8aa0a..a51345ba449e 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -49,8 +49,8 @@
49#include <asm/mtrr.h> 49#include <asm/mtrr.h>
50#include <asm/smp.h> 50#include <asm/smp.h>
51#include <asm/mce.h> 51#include <asm/mce.h>
52#include <asm/kvm_para.h>
53#include <asm/tsc.h> 52#include <asm/tsc.h>
53#include <asm/hypervisor.h>
54 54
55unsigned int num_processors; 55unsigned int num_processors;
56 56
@@ -1476,7 +1476,8 @@ void __init enable_IR_x2apic(void)
1476 /* IR is required if there is APIC ID > 255 even when running 1476 /* IR is required if there is APIC ID > 255 even when running
1477 * under KVM 1477 * under KVM
1478 */ 1478 */
1479 if (max_physical_apicid > 255 || !kvm_para_available()) 1479 if (max_physical_apicid > 255 ||
1480 !hypervisor_x2apic_available())
1480 goto nox2apic; 1481 goto nox2apic;
1481 /* 1482 /*
1482 * without IR all CPUs can be addressed by IOAPIC/MSI 1483 * without IR all CPUs can be addressed by IOAPIC/MSI
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index aa8c89ae54cf..7e8d3bc80af6 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1174,6 +1174,15 @@ asmlinkage void __init xen_start_kernel(void)
1174 1174
1175 xen_smp_init(); 1175 xen_smp_init();
1176 1176
1177#ifdef CONFIG_ACPI_NUMA
1178 /*
1179 * The pages we from Xen are not related to machine pages, so
1180 * any NUMA information the kernel tries to get from ACPI will
1181 * be meaningless. Prevent it from trying.
1182 */
1183 acpi_numa = -1;
1184#endif
1185
1177 pgd = (pgd_t *)xen_start_info->pt_base; 1186 pgd = (pgd_t *)xen_start_info->pt_base;
1178 1187
1179 if (!xen_initial_domain()) 1188 if (!xen_initial_domain())
@@ -1256,25 +1265,6 @@ asmlinkage void __init xen_start_kernel(void)
1256#endif 1265#endif
1257} 1266}
1258 1267
1259static uint32_t xen_cpuid_base(void)
1260{
1261 uint32_t base, eax, ebx, ecx, edx;
1262 char signature[13];
1263
1264 for (base = 0x40000000; base < 0x40010000; base += 0x100) {
1265 cpuid(base, &eax, &ebx, &ecx, &edx);
1266 *(uint32_t *)(signature + 0) = ebx;
1267 *(uint32_t *)(signature + 4) = ecx;
1268 *(uint32_t *)(signature + 8) = edx;
1269 signature[12] = 0;
1270
1271 if (!strcmp("XenVMMXenVMM", signature) && ((eax - base) >= 2))
1272 return base;
1273 }
1274
1275 return 0;
1276}
1277
1278static int init_hvm_pv_info(int *major, int *minor) 1268static int init_hvm_pv_info(int *major, int *minor)
1279{ 1269{
1280 uint32_t eax, ebx, ecx, edx, pages, msr, base; 1270 uint32_t eax, ebx, ecx, edx, pages, msr, base;
@@ -1384,6 +1374,18 @@ static bool __init xen_hvm_platform(void)
1384 return true; 1374 return true;
1385} 1375}
1386 1376
1377bool xen_hvm_need_lapic(void)
1378{
1379 if (xen_pv_domain())
1380 return false;
1381 if (!xen_hvm_domain())
1382 return false;
1383 if (xen_feature(XENFEAT_hvm_pirqs) && xen_have_vector_callback)
1384 return false;
1385 return true;
1386}
1387EXPORT_SYMBOL_GPL(xen_hvm_need_lapic);
1388
1387const __refconst struct hypervisor_x86 x86_hyper_xen_hvm = { 1389const __refconst struct hypervisor_x86 x86_hyper_xen_hvm = {
1388 .name = "Xen HVM", 1390 .name = "Xen HVM",
1389 .detect = xen_hvm_platform, 1391 .detect = xen_hvm_platform,
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 36e2319264bd..c6b298d4c136 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -2,6 +2,14 @@
2# SATA/PATA driver configuration 2# SATA/PATA driver configuration
3# 3#
4 4
5config HAVE_PATA_PLATFORM
6 bool
7 help
8 This is an internal configuration node for any machine that
9 uses pata-platform driver to enable the relevant driver in the
10 configuration structure without having to submit endless patches
11 to update the PATA_PLATFORM entry.
12
5menuconfig ATA 13menuconfig ATA
6 tristate "Serial ATA and Parallel ATA drivers" 14 tristate "Serial ATA and Parallel ATA drivers"
7 depends on HAS_IOMEM 15 depends on HAS_IOMEM
@@ -90,6 +98,14 @@ config SATA_INIC162X
90 help 98 help
91 This option enables support for Initio 162x Serial ATA. 99 This option enables support for Initio 162x Serial ATA.
92 100
101config SATA_ACARD_AHCI
102 tristate "ACard AHCI variant (ATP 8620)"
103 depends on PCI
104 help
105 This option enables support for Acard.
106
107 If unsure, say N.
108
93config SATA_SIL24 109config SATA_SIL24
94 tristate "Silicon Image 3124/3132 SATA support" 110 tristate "Silicon Image 3124/3132 SATA support"
95 depends on PCI 111 depends on PCI
@@ -400,11 +416,11 @@ config PATA_HPT37X
400 If unsure, say N. 416 If unsure, say N.
401 417
402config PATA_HPT3X2N 418config PATA_HPT3X2N
403 tristate "HPT 372N/302N PATA support" 419 tristate "HPT 371N/372N/302N PATA support"
404 depends on PCI 420 depends on PCI
405 help 421 help
406 This option enables support for the N variant HPT PATA 422 This option enables support for the N variant HPT PATA
407 controllers via the new ATA layer 423 controllers via the new ATA layer.
408 424
409 If unsure, say N. 425 If unsure, say N.
410 426
@@ -765,14 +781,6 @@ config PATA_PCMCIA
765 781
766 If unsure, say N. 782 If unsure, say N.
767 783
768config HAVE_PATA_PLATFORM
769 bool
770 help
771 This is an internal configuration node for any machine that
772 uses pata-platform driver to enable the relevant driver in the
773 configuration structure without having to submit endless patches
774 to update the PATA_PLATFORM entry.
775
776config PATA_PLATFORM 784config PATA_PLATFORM
777 tristate "Generic platform device PATA support" 785 tristate "Generic platform device PATA support"
778 depends on EMBEDDED || PPC || HAVE_PATA_PLATFORM 786 depends on EMBEDDED || PPC || HAVE_PATA_PLATFORM
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index 2b67c900a459..27291aad6ca7 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_ATA) += libata.o
3 3
4# non-SFF interface 4# non-SFF interface
5obj-$(CONFIG_SATA_AHCI) += ahci.o libahci.o 5obj-$(CONFIG_SATA_AHCI) += ahci.o libahci.o
6obj-$(CONFIG_SATA_ACARD_AHCI) += acard-ahci.o libahci.o
6obj-$(CONFIG_SATA_AHCI_PLATFORM) += ahci_platform.o libahci.o 7obj-$(CONFIG_SATA_AHCI_PLATFORM) += ahci_platform.o libahci.o
7obj-$(CONFIG_SATA_FSL) += sata_fsl.o 8obj-$(CONFIG_SATA_FSL) += sata_fsl.o
8obj-$(CONFIG_SATA_INIC162X) += sata_inic162x.o 9obj-$(CONFIG_SATA_INIC162X) += sata_inic162x.o
diff --git a/drivers/ata/acard-ahci.c b/drivers/ata/acard-ahci.c
new file mode 100644
index 000000000000..339c210f03a6
--- /dev/null
+++ b/drivers/ata/acard-ahci.c
@@ -0,0 +1,528 @@
1
2/*
3 * acard-ahci.c - ACard AHCI SATA support
4 *
5 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
6 * Please ALWAYS copy linux-ide@vger.kernel.org
7 * on emails.
8 *
9 * Copyright 2010 Red Hat, Inc.
10 *
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 *
27 * libata documentation is available via 'make {ps|pdf}docs',
28 * as Documentation/DocBook/libata.*
29 *
30 * AHCI hardware documentation:
31 * http://www.intel.com/technology/serialata/pdf/rev1_0.pdf
32 * http://www.intel.com/technology/serialata/pdf/rev1_1.pdf
33 *
34 */
35
36#include <linux/kernel.h>
37#include <linux/module.h>
38#include <linux/pci.h>
39#include <linux/init.h>
40#include <linux/blkdev.h>
41#include <linux/delay.h>
42#include <linux/interrupt.h>
43#include <linux/dma-mapping.h>
44#include <linux/device.h>
45#include <linux/dmi.h>
46#include <linux/gfp.h>
47#include <scsi/scsi_host.h>
48#include <scsi/scsi_cmnd.h>
49#include <linux/libata.h>
50#include "ahci.h"
51
52#define DRV_NAME "acard-ahci"
53#define DRV_VERSION "1.0"
54
55/*
56 Received FIS structure limited to 80h.
57*/
58
59#define ACARD_AHCI_RX_FIS_SZ 128
60
61enum {
62 AHCI_PCI_BAR = 5,
63};
64
65enum board_ids {
66 board_acard_ahci,
67};
68
69struct acard_sg {
70 __le32 addr;
71 __le32 addr_hi;
72 __le32 reserved;
73 __le32 size; /* bit 31 (EOT) max==0x10000 (64k) */
74};
75
76static void acard_ahci_qc_prep(struct ata_queued_cmd *qc);
77static bool acard_ahci_qc_fill_rtf(struct ata_queued_cmd *qc);
78static int acard_ahci_port_start(struct ata_port *ap);
79static int acard_ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
80
81#ifdef CONFIG_PM
82static int acard_ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
83static int acard_ahci_pci_device_resume(struct pci_dev *pdev);
84#endif
85
86static struct scsi_host_template acard_ahci_sht = {
87 AHCI_SHT("acard-ahci"),
88};
89
90static struct ata_port_operations acard_ops = {
91 .inherits = &ahci_ops,
92 .qc_prep = acard_ahci_qc_prep,
93 .qc_fill_rtf = acard_ahci_qc_fill_rtf,
94 .port_start = acard_ahci_port_start,
95};
96
97#define AHCI_HFLAGS(flags) .private_data = (void *)(flags)
98
99static const struct ata_port_info acard_ahci_port_info[] = {
100 [board_acard_ahci] =
101 {
102 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ),
103 .flags = AHCI_FLAG_COMMON,
104 .pio_mask = ATA_PIO4,
105 .udma_mask = ATA_UDMA6,
106 .port_ops = &acard_ops,
107 },
108};
109
110static const struct pci_device_id acard_ahci_pci_tbl[] = {
111 /* ACard */
112 { PCI_VDEVICE(ARTOP, 0x000d), board_acard_ahci }, /* ATP8620 */
113
114 { } /* terminate list */
115};
116
117static struct pci_driver acard_ahci_pci_driver = {
118 .name = DRV_NAME,
119 .id_table = acard_ahci_pci_tbl,
120 .probe = acard_ahci_init_one,
121 .remove = ata_pci_remove_one,
122#ifdef CONFIG_PM
123 .suspend = acard_ahci_pci_device_suspend,
124 .resume = acard_ahci_pci_device_resume,
125#endif
126};
127
128#ifdef CONFIG_PM
129static int acard_ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
130{
131 struct ata_host *host = dev_get_drvdata(&pdev->dev);
132 struct ahci_host_priv *hpriv = host->private_data;
133 void __iomem *mmio = hpriv->mmio;
134 u32 ctl;
135
136 if (mesg.event & PM_EVENT_SUSPEND &&
137 hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
138 dev_printk(KERN_ERR, &pdev->dev,
139 "BIOS update required for suspend/resume\n");
140 return -EIO;
141 }
142
143 if (mesg.event & PM_EVENT_SLEEP) {
144 /* AHCI spec rev1.1 section 8.3.3:
145 * Software must disable interrupts prior to requesting a
146 * transition of the HBA to D3 state.
147 */
148 ctl = readl(mmio + HOST_CTL);
149 ctl &= ~HOST_IRQ_EN;
150 writel(ctl, mmio + HOST_CTL);
151 readl(mmio + HOST_CTL); /* flush */
152 }
153
154 return ata_pci_device_suspend(pdev, mesg);
155}
156
157static int acard_ahci_pci_device_resume(struct pci_dev *pdev)
158{
159 struct ata_host *host = dev_get_drvdata(&pdev->dev);
160 int rc;
161
162 rc = ata_pci_device_do_resume(pdev);
163 if (rc)
164 return rc;
165
166 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
167 rc = ahci_reset_controller(host);
168 if (rc)
169 return rc;
170
171 ahci_init_controller(host);
172 }
173
174 ata_host_resume(host);
175
176 return 0;
177}
178#endif
179
180static int acard_ahci_configure_dma_masks(struct pci_dev *pdev, int using_dac)
181{
182 int rc;
183
184 if (using_dac &&
185 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
186 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
187 if (rc) {
188 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
189 if (rc) {
190 dev_printk(KERN_ERR, &pdev->dev,
191 "64-bit DMA enable failed\n");
192 return rc;
193 }
194 }
195 } else {
196 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
197 if (rc) {
198 dev_printk(KERN_ERR, &pdev->dev,
199 "32-bit DMA enable failed\n");
200 return rc;
201 }
202 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
203 if (rc) {
204 dev_printk(KERN_ERR, &pdev->dev,
205 "32-bit consistent DMA enable failed\n");
206 return rc;
207 }
208 }
209 return 0;
210}
211
212static void acard_ahci_pci_print_info(struct ata_host *host)
213{
214 struct pci_dev *pdev = to_pci_dev(host->dev);
215 u16 cc;
216 const char *scc_s;
217
218 pci_read_config_word(pdev, 0x0a, &cc);
219 if (cc == PCI_CLASS_STORAGE_IDE)
220 scc_s = "IDE";
221 else if (cc == PCI_CLASS_STORAGE_SATA)
222 scc_s = "SATA";
223 else if (cc == PCI_CLASS_STORAGE_RAID)
224 scc_s = "RAID";
225 else
226 scc_s = "unknown";
227
228 ahci_print_info(host, scc_s);
229}
230
231static unsigned int acard_ahci_fill_sg(struct ata_queued_cmd *qc, void *cmd_tbl)
232{
233 struct scatterlist *sg;
234 struct acard_sg *acard_sg = cmd_tbl + AHCI_CMD_TBL_HDR_SZ;
235 unsigned int si, last_si = 0;
236
237 VPRINTK("ENTER\n");
238
239 /*
240 * Next, the S/G list.
241 */
242 for_each_sg(qc->sg, sg, qc->n_elem, si) {
243 dma_addr_t addr = sg_dma_address(sg);
244 u32 sg_len = sg_dma_len(sg);
245
246 /*
247 * ACard note:
248 * We must set an end-of-table (EOT) bit,
249 * and the segment cannot exceed 64k (0x10000)
250 */
251 acard_sg[si].addr = cpu_to_le32(addr & 0xffffffff);
252 acard_sg[si].addr_hi = cpu_to_le32((addr >> 16) >> 16);
253 acard_sg[si].size = cpu_to_le32(sg_len);
254 last_si = si;
255 }
256
257 acard_sg[last_si].size |= cpu_to_le32(1 << 31); /* set EOT */
258
259 return si;
260}
261
262static void acard_ahci_qc_prep(struct ata_queued_cmd *qc)
263{
264 struct ata_port *ap = qc->ap;
265 struct ahci_port_priv *pp = ap->private_data;
266 int is_atapi = ata_is_atapi(qc->tf.protocol);
267 void *cmd_tbl;
268 u32 opts;
269 const u32 cmd_fis_len = 5; /* five dwords */
270 unsigned int n_elem;
271
272 /*
273 * Fill in command table information. First, the header,
274 * a SATA Register - Host to Device command FIS.
275 */
276 cmd_tbl = pp->cmd_tbl + qc->tag * AHCI_CMD_TBL_SZ;
277
278 ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, cmd_tbl);
279 if (is_atapi) {
280 memset(cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32);
281 memcpy(cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb, qc->dev->cdb_len);
282 }
283
284 n_elem = 0;
285 if (qc->flags & ATA_QCFLAG_DMAMAP)
286 n_elem = acard_ahci_fill_sg(qc, cmd_tbl);
287
288 /*
289 * Fill in command slot information.
290 *
291 * ACard note: prd table length not filled in
292 */
293 opts = cmd_fis_len | (qc->dev->link->pmp << 12);
294 if (qc->tf.flags & ATA_TFLAG_WRITE)
295 opts |= AHCI_CMD_WRITE;
296 if (is_atapi)
297 opts |= AHCI_CMD_ATAPI | AHCI_CMD_PREFETCH;
298
299 ahci_fill_cmd_slot(pp, qc->tag, opts);
300}
301
302static bool acard_ahci_qc_fill_rtf(struct ata_queued_cmd *qc)
303{
304 struct ahci_port_priv *pp = qc->ap->private_data;
305 u8 *rx_fis = pp->rx_fis;
306
307 if (pp->fbs_enabled)
308 rx_fis += qc->dev->link->pmp * ACARD_AHCI_RX_FIS_SZ;
309
310 /*
311 * After a successful execution of an ATA PIO data-in command,
312 * the device doesn't send D2H Reg FIS to update the TF and
313 * the host should take TF and E_Status from the preceding PIO
314 * Setup FIS.
315 */
316 if (qc->tf.protocol == ATA_PROT_PIO && qc->dma_dir == DMA_FROM_DEVICE &&
317 !(qc->flags & ATA_QCFLAG_FAILED)) {
318 ata_tf_from_fis(rx_fis + RX_FIS_PIO_SETUP, &qc->result_tf);
319 qc->result_tf.command = (rx_fis + RX_FIS_PIO_SETUP)[15];
320 } else
321 ata_tf_from_fis(rx_fis + RX_FIS_D2H_REG, &qc->result_tf);
322
323 return true;
324}
325
326static int acard_ahci_port_start(struct ata_port *ap)
327{
328 struct ahci_host_priv *hpriv = ap->host->private_data;
329 struct device *dev = ap->host->dev;
330 struct ahci_port_priv *pp;
331 void *mem;
332 dma_addr_t mem_dma;
333 size_t dma_sz, rx_fis_sz;
334
335 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
336 if (!pp)
337 return -ENOMEM;
338
339 /* check FBS capability */
340 if ((hpriv->cap & HOST_CAP_FBS) && sata_pmp_supported(ap)) {
341 void __iomem *port_mmio = ahci_port_base(ap);
342 u32 cmd = readl(port_mmio + PORT_CMD);
343 if (cmd & PORT_CMD_FBSCP)
344 pp->fbs_supported = true;
345 else if (hpriv->flags & AHCI_HFLAG_YES_FBS) {
346 dev_printk(KERN_INFO, dev,
347 "port %d can do FBS, forcing FBSCP\n",
348 ap->port_no);
349 pp->fbs_supported = true;
350 } else
351 dev_printk(KERN_WARNING, dev,
352 "port %d is not capable of FBS\n",
353 ap->port_no);
354 }
355
356 if (pp->fbs_supported) {
357 dma_sz = AHCI_PORT_PRIV_FBS_DMA_SZ;
358 rx_fis_sz = ACARD_AHCI_RX_FIS_SZ * 16;
359 } else {
360 dma_sz = AHCI_PORT_PRIV_DMA_SZ;
361 rx_fis_sz = ACARD_AHCI_RX_FIS_SZ;
362 }
363
364 mem = dmam_alloc_coherent(dev, dma_sz, &mem_dma, GFP_KERNEL);
365 if (!mem)
366 return -ENOMEM;
367 memset(mem, 0, dma_sz);
368
369 /*
370 * First item in chunk of DMA memory: 32-slot command table,
371 * 32 bytes each in size
372 */
373 pp->cmd_slot = mem;
374 pp->cmd_slot_dma = mem_dma;
375
376 mem += AHCI_CMD_SLOT_SZ;
377 mem_dma += AHCI_CMD_SLOT_SZ;
378
379 /*
380 * Second item: Received-FIS area
381 */
382 pp->rx_fis = mem;
383 pp->rx_fis_dma = mem_dma;
384
385 mem += rx_fis_sz;
386 mem_dma += rx_fis_sz;
387
388 /*
389 * Third item: data area for storing a single command
390 * and its scatter-gather table
391 */
392 pp->cmd_tbl = mem;
393 pp->cmd_tbl_dma = mem_dma;
394
395 /*
396 * Save off initial list of interrupts to be enabled.
397 * This could be changed later
398 */
399 pp->intr_mask = DEF_PORT_IRQ;
400
401 ap->private_data = pp;
402
403 /* engage engines, captain */
404 return ahci_port_resume(ap);
405}
406
407static int acard_ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
408{
409 static int printed_version;
410 unsigned int board_id = ent->driver_data;
411 struct ata_port_info pi = acard_ahci_port_info[board_id];
412 const struct ata_port_info *ppi[] = { &pi, NULL };
413 struct device *dev = &pdev->dev;
414 struct ahci_host_priv *hpriv;
415 struct ata_host *host;
416 int n_ports, i, rc;
417
418 VPRINTK("ENTER\n");
419
420 WARN_ON(ATA_MAX_QUEUE > AHCI_MAX_CMDS);
421
422 if (!printed_version++)
423 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
424
425 /* acquire resources */
426 rc = pcim_enable_device(pdev);
427 if (rc)
428 return rc;
429
430 /* AHCI controllers often implement SFF compatible interface.
431 * Grab all PCI BARs just in case.
432 */
433 rc = pcim_iomap_regions_request_all(pdev, 1 << AHCI_PCI_BAR, DRV_NAME);
434 if (rc == -EBUSY)
435 pcim_pin_device(pdev);
436 if (rc)
437 return rc;
438
439 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
440 if (!hpriv)
441 return -ENOMEM;
442 hpriv->flags |= (unsigned long)pi.private_data;
443
444 if (!(hpriv->flags & AHCI_HFLAG_NO_MSI))
445 pci_enable_msi(pdev);
446
447 hpriv->mmio = pcim_iomap_table(pdev)[AHCI_PCI_BAR];
448
449 /* save initial config */
450 ahci_save_initial_config(&pdev->dev, hpriv, 0, 0);
451
452 /* prepare host */
453 if (hpriv->cap & HOST_CAP_NCQ)
454 pi.flags |= ATA_FLAG_NCQ;
455
456 if (hpriv->cap & HOST_CAP_PMP)
457 pi.flags |= ATA_FLAG_PMP;
458
459 ahci_set_em_messages(hpriv, &pi);
460
461 /* CAP.NP sometimes indicate the index of the last enabled
462 * port, at other times, that of the last possible port, so
463 * determining the maximum port number requires looking at
464 * both CAP.NP and port_map.
465 */
466 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
467
468 host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
469 if (!host)
470 return -ENOMEM;
471 host->private_data = hpriv;
472
473 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
474 host->flags |= ATA_HOST_PARALLEL_SCAN;
475 else
476 printk(KERN_INFO "ahci: SSS flag set, parallel bus scan disabled\n");
477
478 for (i = 0; i < host->n_ports; i++) {
479 struct ata_port *ap = host->ports[i];
480
481 ata_port_pbar_desc(ap, AHCI_PCI_BAR, -1, "abar");
482 ata_port_pbar_desc(ap, AHCI_PCI_BAR,
483 0x100 + ap->port_no * 0x80, "port");
484
485 /* set initial link pm policy */
486 /*
487 ap->pm_policy = NOT_AVAILABLE;
488 */
489 /* disabled/not-implemented port */
490 if (!(hpriv->port_map & (1 << i)))
491 ap->ops = &ata_dummy_port_ops;
492 }
493
494 /* initialize adapter */
495 rc = acard_ahci_configure_dma_masks(pdev, hpriv->cap & HOST_CAP_64);
496 if (rc)
497 return rc;
498
499 rc = ahci_reset_controller(host);
500 if (rc)
501 return rc;
502
503 ahci_init_controller(host);
504 acard_ahci_pci_print_info(host);
505
506 pci_set_master(pdev);
507 return ata_host_activate(host, pdev->irq, ahci_interrupt, IRQF_SHARED,
508 &acard_ahci_sht);
509}
510
511static int __init acard_ahci_init(void)
512{
513 return pci_register_driver(&acard_ahci_pci_driver);
514}
515
516static void __exit acard_ahci_exit(void)
517{
518 pci_unregister_driver(&acard_ahci_pci_driver);
519}
520
521MODULE_AUTHOR("Jeff Garzik");
522MODULE_DESCRIPTION("ACard AHCI SATA low-level driver");
523MODULE_LICENSE("GPL");
524MODULE_DEVICE_TABLE(pci, acard_ahci_pci_tbl);
525MODULE_VERSION(DRV_VERSION);
526
527module_init(acard_ahci_init);
528module_exit(acard_ahci_exit);
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 329cbbb91284..3e606c34f57b 100644
--- a/drivers/ata/ahci.h
+++ b/drivers/ata/ahci.h
@@ -311,6 +311,8 @@ extern struct device_attribute *ahci_sdev_attrs[];
311 311
312extern struct ata_port_operations ahci_ops; 312extern struct ata_port_operations ahci_ops;
313 313
314void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
315 u32 opts);
314void ahci_save_initial_config(struct device *dev, 316void ahci_save_initial_config(struct device *dev,
315 struct ahci_host_priv *hpriv, 317 struct ahci_host_priv *hpriv,
316 unsigned int force_port_map, 318 unsigned int force_port_map,
@@ -326,6 +328,7 @@ int ahci_stop_engine(struct ata_port *ap);
326void ahci_start_engine(struct ata_port *ap); 328void ahci_start_engine(struct ata_port *ap);
327int ahci_check_ready(struct ata_link *link); 329int ahci_check_ready(struct ata_link *link);
328int ahci_kick_engine(struct ata_port *ap); 330int ahci_kick_engine(struct ata_port *ap);
331int ahci_port_resume(struct ata_port *ap);
329void ahci_set_em_messages(struct ahci_host_priv *hpriv, 332void ahci_set_em_messages(struct ahci_host_priv *hpriv,
330 struct ata_port_info *pi); 333 struct ata_port_info *pi);
331int ahci_reset_em(struct ata_host *host); 334int ahci_reset_em(struct ata_host *host);
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index ebc08d65b3dd..26d452339e98 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -87,10 +87,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class,
87static void ahci_postreset(struct ata_link *link, unsigned int *class); 87static void ahci_postreset(struct ata_link *link, unsigned int *class);
88static void ahci_error_handler(struct ata_port *ap); 88static void ahci_error_handler(struct ata_port *ap);
89static void ahci_post_internal_cmd(struct ata_queued_cmd *qc); 89static void ahci_post_internal_cmd(struct ata_queued_cmd *qc);
90static int ahci_port_resume(struct ata_port *ap);
91static void ahci_dev_config(struct ata_device *dev); 90static void ahci_dev_config(struct ata_device *dev);
92static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
93 u32 opts);
94#ifdef CONFIG_PM 91#ifdef CONFIG_PM
95static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg); 92static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg);
96#endif 93#endif
@@ -1133,8 +1130,8 @@ static unsigned int ahci_dev_classify(struct ata_port *ap)
1133 return ata_dev_classify(&tf); 1130 return ata_dev_classify(&tf);
1134} 1131}
1135 1132
1136static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag, 1133void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
1137 u32 opts) 1134 u32 opts)
1138{ 1135{
1139 dma_addr_t cmd_tbl_dma; 1136 dma_addr_t cmd_tbl_dma;
1140 1137
@@ -1145,6 +1142,7 @@ static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
1145 pp->cmd_slot[tag].tbl_addr = cpu_to_le32(cmd_tbl_dma & 0xffffffff); 1142 pp->cmd_slot[tag].tbl_addr = cpu_to_le32(cmd_tbl_dma & 0xffffffff);
1146 pp->cmd_slot[tag].tbl_addr_hi = cpu_to_le32((cmd_tbl_dma >> 16) >> 16); 1143 pp->cmd_slot[tag].tbl_addr_hi = cpu_to_le32((cmd_tbl_dma >> 16) >> 16);
1147} 1144}
1145EXPORT_SYMBOL_GPL(ahci_fill_cmd_slot);
1148 1146
1149int ahci_kick_engine(struct ata_port *ap) 1147int ahci_kick_engine(struct ata_port *ap)
1150{ 1148{
@@ -1918,7 +1916,7 @@ static void ahci_pmp_detach(struct ata_port *ap)
1918 writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK); 1916 writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
1919} 1917}
1920 1918
1921static int ahci_port_resume(struct ata_port *ap) 1919int ahci_port_resume(struct ata_port *ap)
1922{ 1920{
1923 ahci_power_up(ap); 1921 ahci_power_up(ap);
1924 ahci_start_port(ap); 1922 ahci_start_port(ap);
@@ -1930,6 +1928,7 @@ static int ahci_port_resume(struct ata_port *ap)
1930 1928
1931 return 0; 1929 return 0;
1932} 1930}
1931EXPORT_SYMBOL_GPL(ahci_port_resume);
1933 1932
1934#ifdef CONFIG_PM 1933#ifdef CONFIG_PM
1935static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg) 1934static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg)
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 66aa4bee80a6..5defc74973d7 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -346,12 +346,11 @@ struct device_attribute *ata_common_sdev_attrs[] = {
346}; 346};
347EXPORT_SYMBOL_GPL(ata_common_sdev_attrs); 347EXPORT_SYMBOL_GPL(ata_common_sdev_attrs);
348 348
349static void ata_scsi_invalid_field(struct scsi_cmnd *cmd, 349static void ata_scsi_invalid_field(struct scsi_cmnd *cmd)
350 void (*done)(struct scsi_cmnd *))
351{ 350{
352 ata_scsi_set_sense(cmd, ILLEGAL_REQUEST, 0x24, 0x0); 351 ata_scsi_set_sense(cmd, ILLEGAL_REQUEST, 0x24, 0x0);
353 /* "Invalid field in cbd" */ 352 /* "Invalid field in cbd" */
354 done(cmd); 353 cmd->scsi_done(cmd);
355} 354}
356 355
357/** 356/**
@@ -719,7 +718,6 @@ EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
719 * ata_scsi_qc_new - acquire new ata_queued_cmd reference 718 * ata_scsi_qc_new - acquire new ata_queued_cmd reference
720 * @dev: ATA device to which the new command is attached 719 * @dev: ATA device to which the new command is attached
721 * @cmd: SCSI command that originated this ATA command 720 * @cmd: SCSI command that originated this ATA command
722 * @done: SCSI command completion function
723 * 721 *
724 * Obtain a reference to an unused ata_queued_cmd structure, 722 * Obtain a reference to an unused ata_queued_cmd structure,
725 * which is the basic libata structure representing a single 723 * which is the basic libata structure representing a single
@@ -736,21 +734,20 @@ EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
736 * Command allocated, or %NULL if none available. 734 * Command allocated, or %NULL if none available.
737 */ 735 */
738static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev, 736static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev,
739 struct scsi_cmnd *cmd, 737 struct scsi_cmnd *cmd)
740 void (*done)(struct scsi_cmnd *))
741{ 738{
742 struct ata_queued_cmd *qc; 739 struct ata_queued_cmd *qc;
743 740
744 qc = ata_qc_new_init(dev); 741 qc = ata_qc_new_init(dev);
745 if (qc) { 742 if (qc) {
746 qc->scsicmd = cmd; 743 qc->scsicmd = cmd;
747 qc->scsidone = done; 744 qc->scsidone = cmd->scsi_done;
748 745
749 qc->sg = scsi_sglist(cmd); 746 qc->sg = scsi_sglist(cmd);
750 qc->n_elem = scsi_sg_count(cmd); 747 qc->n_elem = scsi_sg_count(cmd);
751 } else { 748 } else {
752 cmd->result = (DID_OK << 16) | (QUEUE_FULL << 1); 749 cmd->result = (DID_OK << 16) | (QUEUE_FULL << 1);
753 done(cmd); 750 cmd->scsi_done(cmd);
754 } 751 }
755 752
756 return qc; 753 return qc;
@@ -1735,7 +1732,6 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
1735 * ata_scsi_translate - Translate then issue SCSI command to ATA device 1732 * ata_scsi_translate - Translate then issue SCSI command to ATA device
1736 * @dev: ATA device to which the command is addressed 1733 * @dev: ATA device to which the command is addressed
1737 * @cmd: SCSI command to execute 1734 * @cmd: SCSI command to execute
1738 * @done: SCSI command completion function
1739 * @xlat_func: Actor which translates @cmd to an ATA taskfile 1735 * @xlat_func: Actor which translates @cmd to an ATA taskfile
1740 * 1736 *
1741 * Our ->queuecommand() function has decided that the SCSI 1737 * Our ->queuecommand() function has decided that the SCSI
@@ -1759,7 +1755,6 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
1759 * needs to be deferred. 1755 * needs to be deferred.
1760 */ 1756 */
1761static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd, 1757static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
1762 void (*done)(struct scsi_cmnd *),
1763 ata_xlat_func_t xlat_func) 1758 ata_xlat_func_t xlat_func)
1764{ 1759{
1765 struct ata_port *ap = dev->link->ap; 1760 struct ata_port *ap = dev->link->ap;
@@ -1768,7 +1763,7 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
1768 1763
1769 VPRINTK("ENTER\n"); 1764 VPRINTK("ENTER\n");
1770 1765
1771 qc = ata_scsi_qc_new(dev, cmd, done); 1766 qc = ata_scsi_qc_new(dev, cmd);
1772 if (!qc) 1767 if (!qc)
1773 goto err_mem; 1768 goto err_mem;
1774 1769
@@ -1804,14 +1799,14 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
1804 1799
1805early_finish: 1800early_finish:
1806 ata_qc_free(qc); 1801 ata_qc_free(qc);
1807 qc->scsidone(cmd); 1802 cmd->scsi_done(cmd);
1808 DPRINTK("EXIT - early finish (good or error)\n"); 1803 DPRINTK("EXIT - early finish (good or error)\n");
1809 return 0; 1804 return 0;
1810 1805
1811err_did: 1806err_did:
1812 ata_qc_free(qc); 1807 ata_qc_free(qc);
1813 cmd->result = (DID_ERROR << 16); 1808 cmd->result = (DID_ERROR << 16);
1814 qc->scsidone(cmd); 1809 cmd->scsi_done(cmd);
1815err_mem: 1810err_mem:
1816 DPRINTK("EXIT - internal\n"); 1811 DPRINTK("EXIT - internal\n");
1817 return 0; 1812 return 0;
@@ -3116,7 +3111,6 @@ static inline void ata_scsi_dump_cdb(struct ata_port *ap,
3116} 3111}
3117 3112
3118static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, 3113static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
3119 void (*done)(struct scsi_cmnd *),
3120 struct ata_device *dev) 3114 struct ata_device *dev)
3121{ 3115{
3122 u8 scsi_op = scmd->cmnd[0]; 3116 u8 scsi_op = scmd->cmnd[0];
@@ -3150,9 +3144,9 @@ static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
3150 } 3144 }
3151 3145
3152 if (xlat_func) 3146 if (xlat_func)
3153 rc = ata_scsi_translate(dev, scmd, done, xlat_func); 3147 rc = ata_scsi_translate(dev, scmd, xlat_func);
3154 else 3148 else
3155 ata_scsi_simulate(dev, scmd, done); 3149 ata_scsi_simulate(dev, scmd);
3156 3150
3157 return rc; 3151 return rc;
3158 3152
@@ -3160,7 +3154,7 @@ static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
3160 DPRINTK("bad CDB len=%u, scsi_op=0x%02x, max=%u\n", 3154 DPRINTK("bad CDB len=%u, scsi_op=0x%02x, max=%u\n",
3161 scmd->cmd_len, scsi_op, dev->cdb_len); 3155 scmd->cmd_len, scsi_op, dev->cdb_len);
3162 scmd->result = DID_ERROR << 16; 3156 scmd->result = DID_ERROR << 16;
3163 done(scmd); 3157 scmd->scsi_done(scmd);
3164 return 0; 3158 return 0;
3165} 3159}
3166 3160
@@ -3199,7 +3193,7 @@ int ata_scsi_queuecmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
3199 3193
3200 dev = ata_scsi_find_dev(ap, scsidev); 3194 dev = ata_scsi_find_dev(ap, scsidev);
3201 if (likely(dev)) 3195 if (likely(dev))
3202 rc = __ata_scsi_queuecmd(cmd, cmd->scsi_done, dev); 3196 rc = __ata_scsi_queuecmd(cmd, dev);
3203 else { 3197 else {
3204 cmd->result = (DID_BAD_TARGET << 16); 3198 cmd->result = (DID_BAD_TARGET << 16);
3205 cmd->scsi_done(cmd); 3199 cmd->scsi_done(cmd);
@@ -3214,7 +3208,6 @@ int ata_scsi_queuecmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
3214 * ata_scsi_simulate - simulate SCSI command on ATA device 3208 * ata_scsi_simulate - simulate SCSI command on ATA device
3215 * @dev: the target device 3209 * @dev: the target device
3216 * @cmd: SCSI command being sent to device. 3210 * @cmd: SCSI command being sent to device.
3217 * @done: SCSI command completion function.
3218 * 3211 *
3219 * Interprets and directly executes a select list of SCSI commands 3212 * Interprets and directly executes a select list of SCSI commands
3220 * that can be handled internally. 3213 * that can be handled internally.
@@ -3223,8 +3216,7 @@ int ata_scsi_queuecmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
3223 * spin_lock_irqsave(host lock) 3216 * spin_lock_irqsave(host lock)
3224 */ 3217 */
3225 3218
3226void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd, 3219void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd)
3227 void (*done)(struct scsi_cmnd *))
3228{ 3220{
3229 struct ata_scsi_args args; 3221 struct ata_scsi_args args;
3230 const u8 *scsicmd = cmd->cmnd; 3222 const u8 *scsicmd = cmd->cmnd;
@@ -3233,17 +3225,17 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
3233 args.dev = dev; 3225 args.dev = dev;
3234 args.id = dev->id; 3226 args.id = dev->id;
3235 args.cmd = cmd; 3227 args.cmd = cmd;
3236 args.done = done; 3228 args.done = cmd->scsi_done;
3237 3229
3238 switch(scsicmd[0]) { 3230 switch(scsicmd[0]) {
3239 /* TODO: worth improving? */ 3231 /* TODO: worth improving? */
3240 case FORMAT_UNIT: 3232 case FORMAT_UNIT:
3241 ata_scsi_invalid_field(cmd, done); 3233 ata_scsi_invalid_field(cmd);
3242 break; 3234 break;
3243 3235
3244 case INQUIRY: 3236 case INQUIRY:
3245 if (scsicmd[1] & 2) /* is CmdDt set? */ 3237 if (scsicmd[1] & 2) /* is CmdDt set? */
3246 ata_scsi_invalid_field(cmd, done); 3238 ata_scsi_invalid_field(cmd);
3247 else if ((scsicmd[1] & 1) == 0) /* is EVPD clear? */ 3239 else if ((scsicmd[1] & 1) == 0) /* is EVPD clear? */
3248 ata_scsi_rbuf_fill(&args, ata_scsiop_inq_std); 3240 ata_scsi_rbuf_fill(&args, ata_scsiop_inq_std);
3249 else switch (scsicmd[2]) { 3241 else switch (scsicmd[2]) {
@@ -3269,7 +3261,7 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
3269 ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b2); 3261 ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b2);
3270 break; 3262 break;
3271 default: 3263 default:
3272 ata_scsi_invalid_field(cmd, done); 3264 ata_scsi_invalid_field(cmd);
3273 break; 3265 break;
3274 } 3266 }
3275 break; 3267 break;
@@ -3281,7 +3273,7 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
3281 3273
3282 case MODE_SELECT: /* unconditionally return */ 3274 case MODE_SELECT: /* unconditionally return */
3283 case MODE_SELECT_10: /* bad-field-in-cdb */ 3275 case MODE_SELECT_10: /* bad-field-in-cdb */
3284 ata_scsi_invalid_field(cmd, done); 3276 ata_scsi_invalid_field(cmd);
3285 break; 3277 break;
3286 3278
3287 case READ_CAPACITY: 3279 case READ_CAPACITY:
@@ -3292,7 +3284,7 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
3292 if ((scsicmd[1] & 0x1f) == SAI_READ_CAPACITY_16) 3284 if ((scsicmd[1] & 0x1f) == SAI_READ_CAPACITY_16)
3293 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap); 3285 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap);
3294 else 3286 else
3295 ata_scsi_invalid_field(cmd, done); 3287 ata_scsi_invalid_field(cmd);
3296 break; 3288 break;
3297 3289
3298 case REPORT_LUNS: 3290 case REPORT_LUNS:
@@ -3302,7 +3294,7 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
3302 case REQUEST_SENSE: 3294 case REQUEST_SENSE:
3303 ata_scsi_set_sense(cmd, 0, 0, 0); 3295 ata_scsi_set_sense(cmd, 0, 0, 0);
3304 cmd->result = (DRIVER_SENSE << 24); 3296 cmd->result = (DRIVER_SENSE << 24);
3305 done(cmd); 3297 cmd->scsi_done(cmd);
3306 break; 3298 break;
3307 3299
3308 /* if we reach this, then writeback caching is disabled, 3300 /* if we reach this, then writeback caching is disabled,
@@ -3324,14 +3316,14 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
3324 if ((tmp8 == 0x4) && (!scsicmd[3]) && (!scsicmd[4])) 3316 if ((tmp8 == 0x4) && (!scsicmd[3]) && (!scsicmd[4]))
3325 ata_scsi_rbuf_fill(&args, ata_scsiop_noop); 3317 ata_scsi_rbuf_fill(&args, ata_scsiop_noop);
3326 else 3318 else
3327 ata_scsi_invalid_field(cmd, done); 3319 ata_scsi_invalid_field(cmd);
3328 break; 3320 break;
3329 3321
3330 /* all other commands */ 3322 /* all other commands */
3331 default: 3323 default:
3332 ata_scsi_set_sense(cmd, ILLEGAL_REQUEST, 0x20, 0x0); 3324 ata_scsi_set_sense(cmd, ILLEGAL_REQUEST, 0x20, 0x0);
3333 /* "Invalid command operation code" */ 3325 /* "Invalid command operation code" */
3334 done(cmd); 3326 cmd->scsi_done(cmd);
3335 break; 3327 break;
3336 } 3328 }
3337} 3329}
@@ -3858,7 +3850,6 @@ EXPORT_SYMBOL_GPL(ata_sas_slave_configure);
3858/** 3850/**
3859 * ata_sas_queuecmd - Issue SCSI cdb to libata-managed device 3851 * ata_sas_queuecmd - Issue SCSI cdb to libata-managed device
3860 * @cmd: SCSI command to be sent 3852 * @cmd: SCSI command to be sent
3861 * @done: Completion function, called when command is complete
3862 * @ap: ATA port to which the command is being sent 3853 * @ap: ATA port to which the command is being sent
3863 * 3854 *
3864 * RETURNS: 3855 * RETURNS:
@@ -3866,18 +3857,17 @@ EXPORT_SYMBOL_GPL(ata_sas_slave_configure);
3866 * 0 otherwise. 3857 * 0 otherwise.
3867 */ 3858 */
3868 3859
3869int ata_sas_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), 3860int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap)
3870 struct ata_port *ap)
3871{ 3861{
3872 int rc = 0; 3862 int rc = 0;
3873 3863
3874 ata_scsi_dump_cdb(ap, cmd); 3864 ata_scsi_dump_cdb(ap, cmd);
3875 3865
3876 if (likely(ata_dev_enabled(ap->link.device))) 3866 if (likely(ata_dev_enabled(ap->link.device)))
3877 rc = __ata_scsi_queuecmd(cmd, done, ap->link.device); 3867 rc = __ata_scsi_queuecmd(cmd, ap->link.device);
3878 else { 3868 else {
3879 cmd->result = (DID_BAD_TARGET << 16); 3869 cmd->result = (DID_BAD_TARGET << 16);
3880 done(cmd); 3870 cmd->scsi_done(cmd);
3881 } 3871 }
3882 return rc; 3872 return rc;
3883} 3873}
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index 7688868557b9..d7e57db36bc8 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -25,7 +25,7 @@
25#include <linux/libata.h> 25#include <linux/libata.h>
26 26
27#define DRV_NAME "pata_hpt366" 27#define DRV_NAME "pata_hpt366"
28#define DRV_VERSION "0.6.8" 28#define DRV_VERSION "0.6.9"
29 29
30struct hpt_clock { 30struct hpt_clock {
31 u8 xfer_mode; 31 u8 xfer_mode;
@@ -110,18 +110,23 @@ static const struct hpt_clock hpt366_25[] = {
110 { 0, 0x01208585 } 110 { 0, 0x01208585 }
111}; 111};
112 112
113static const char *bad_ata33[] = { 113static const char * const bad_ata33[] = {
114 "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3", "Maxtor 90845U3", "Maxtor 90650U2", 114 "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3",
115 "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5", "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2", 115 "Maxtor 90845U3", "Maxtor 90650U2",
116 "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6", "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4", 116 "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5",
117 "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2",
118 "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6",
119 "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4",
117 "Maxtor 90510D4", 120 "Maxtor 90510D4",
118 "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2", 121 "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2",
119 "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7", "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4", 122 "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7",
120 "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5", "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2", 123 "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4",
124 "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5",
125 "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2",
121 NULL 126 NULL
122}; 127};
123 128
124static const char *bad_ata66_4[] = { 129static const char * const bad_ata66_4[] = {
125 "IBM-DTLA-307075", 130 "IBM-DTLA-307075",
126 "IBM-DTLA-307060", 131 "IBM-DTLA-307060",
127 "IBM-DTLA-307045", 132 "IBM-DTLA-307045",
@@ -140,12 +145,13 @@ static const char *bad_ata66_4[] = {
140 NULL 145 NULL
141}; 146};
142 147
143static const char *bad_ata66_3[] = { 148static const char * const bad_ata66_3[] = {
144 "WDC AC310200R", 149 "WDC AC310200R",
145 NULL 150 NULL
146}; 151};
147 152
148static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[]) 153static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr,
154 const char * const list[])
149{ 155{
150 unsigned char model_num[ATA_ID_PROD_LEN + 1]; 156 unsigned char model_num[ATA_ID_PROD_LEN + 1];
151 int i = 0; 157 int i = 0;
@@ -288,6 +294,7 @@ static struct ata_port_operations hpt366_port_ops = {
288static void hpt36x_init_chipset(struct pci_dev *dev) 294static void hpt36x_init_chipset(struct pci_dev *dev)
289{ 295{
290 u8 drive_fast; 296 u8 drive_fast;
297
291 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4)); 298 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
292 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78); 299 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
293 pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); 300 pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
@@ -349,16 +356,16 @@ static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
349 356
350 /* PCI clocking determines the ATA timing values to use */ 357 /* PCI clocking determines the ATA timing values to use */
351 /* info_hpt366 is safe against re-entry so we can scribble on it */ 358 /* info_hpt366 is safe against re-entry so we can scribble on it */
352 switch((reg1 & 0x700) >> 8) { 359 switch ((reg1 & 0x700) >> 8) {
353 case 9: 360 case 9:
354 hpriv = &hpt366_40; 361 hpriv = &hpt366_40;
355 break; 362 break;
356 case 5: 363 case 5:
357 hpriv = &hpt366_25; 364 hpriv = &hpt366_25;
358 break; 365 break;
359 default: 366 default:
360 hpriv = &hpt366_33; 367 hpriv = &hpt366_33;
361 break; 368 break;
362 } 369 }
363 /* Now kick off ATA set up */ 370 /* Now kick off ATA set up */
364 return ata_pci_bmdma_init_one(dev, ppi, &hpt36x_sht, hpriv, 0); 371 return ata_pci_bmdma_init_one(dev, ppi, &hpt36x_sht, hpriv, 0);
@@ -385,9 +392,9 @@ static const struct pci_device_id hpt36x[] = {
385}; 392};
386 393
387static struct pci_driver hpt36x_pci_driver = { 394static struct pci_driver hpt36x_pci_driver = {
388 .name = DRV_NAME, 395 .name = DRV_NAME,
389 .id_table = hpt36x, 396 .id_table = hpt36x,
390 .probe = hpt36x_init_one, 397 .probe = hpt36x_init_one,
391 .remove = ata_pci_remove_one, 398 .remove = ata_pci_remove_one,
392#ifdef CONFIG_PM 399#ifdef CONFIG_PM
393 .suspend = ata_pci_device_suspend, 400 .suspend = ata_pci_device_suspend,
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index 9ae4c0830577..efdd18bc8663 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -8,7 +8,7 @@
8 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org> 8 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org>
9 * Portions Copyright (C) 2001 Sun Microsystems, Inc. 9 * Portions Copyright (C) 2001 Sun Microsystems, Inc.
10 * Portions Copyright (C) 2003 Red Hat Inc 10 * Portions Copyright (C) 2003 Red Hat Inc
11 * Portions Copyright (C) 2005-2009 MontaVista Software, Inc. 11 * Portions Copyright (C) 2005-2010 MontaVista Software, Inc.
12 * 12 *
13 * TODO 13 * TODO
14 * Look into engine reset on timeout errors. Should not be required. 14 * Look into engine reset on timeout errors. Should not be required.
@@ -24,7 +24,7 @@
24#include <linux/libata.h> 24#include <linux/libata.h>
25 25
26#define DRV_NAME "pata_hpt37x" 26#define DRV_NAME "pata_hpt37x"
27#define DRV_VERSION "0.6.15" 27#define DRV_VERSION "0.6.18"
28 28
29struct hpt_clock { 29struct hpt_clock {
30 u8 xfer_speed; 30 u8 xfer_speed;
@@ -210,7 +210,7 @@ static u32 hpt37x_find_mode(struct ata_port *ap, int speed)
210{ 210{
211 struct hpt_clock *clocks = ap->host->private_data; 211 struct hpt_clock *clocks = ap->host->private_data;
212 212
213 while(clocks->xfer_speed) { 213 while (clocks->xfer_speed) {
214 if (clocks->xfer_speed == speed) 214 if (clocks->xfer_speed == speed)
215 return clocks->timing; 215 return clocks->timing;
216 clocks++; 216 clocks++;
@@ -219,7 +219,8 @@ static u32 hpt37x_find_mode(struct ata_port *ap, int speed)
219 return 0xffffffffU; /* silence compiler warning */ 219 return 0xffffffffU; /* silence compiler warning */
220} 220}
221 221
222static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[]) 222static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr,
223 const char * const list[])
223{ 224{
224 unsigned char model_num[ATA_ID_PROD_LEN + 1]; 225 unsigned char model_num[ATA_ID_PROD_LEN + 1];
225 int i = 0; 226 int i = 0;
@@ -237,18 +238,23 @@ static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, cons
237 return 0; 238 return 0;
238} 239}
239 240
240static const char *bad_ata33[] = { 241static const char * const bad_ata33[] = {
241 "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3", "Maxtor 90845U3", "Maxtor 90650U2", 242 "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3",
242 "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5", "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2", 243 "Maxtor 90845U3", "Maxtor 90650U2",
243 "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6", "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4", 244 "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5",
245 "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2",
246 "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6",
247 "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4",
244 "Maxtor 90510D4", 248 "Maxtor 90510D4",
245 "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2", 249 "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2",
246 "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7", "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4", 250 "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7",
247 "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5", "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2", 251 "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4",
252 "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5",
253 "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2",
248 NULL 254 NULL
249}; 255};
250 256
251static const char *bad_ata100_5[] = { 257static const char * const bad_ata100_5[] = {
252 "IBM-DTLA-307075", 258 "IBM-DTLA-307075",
253 "IBM-DTLA-307060", 259 "IBM-DTLA-307060",
254 "IBM-DTLA-307045", 260 "IBM-DTLA-307045",
@@ -302,6 +308,22 @@ static unsigned long hpt370a_filter(struct ata_device *adev, unsigned long mask)
302} 308}
303 309
304/** 310/**
311 * hpt372_filter - mode selection filter
312 * @adev: ATA device
313 * @mask: mode mask
314 *
315 * The Marvell bridge chips used on the HighPoint SATA cards do not seem
316 * to support the UltraDMA modes 1, 2, and 3 as well as any MWDMA modes...
317 */
318static unsigned long hpt372_filter(struct ata_device *adev, unsigned long mask)
319{
320 if (ata_id_is_sata(adev->id))
321 mask &= ~((0xE << ATA_SHIFT_UDMA) | ATA_MASK_MWDMA);
322
323 return mask;
324}
325
326/**
305 * hpt37x_cable_detect - Detect the cable type 327 * hpt37x_cable_detect - Detect the cable type
306 * @ap: ATA port to detect on 328 * @ap: ATA port to detect on
307 * 329 *
@@ -373,6 +395,7 @@ static int hpt37x_pre_reset(struct ata_link *link, unsigned long deadline)
373 { 0x50, 1, 0x04, 0x04 }, 395 { 0x50, 1, 0x04, 0x04 },
374 { 0x54, 1, 0x04, 0x04 } 396 { 0x54, 1, 0x04, 0x04 }
375 }; 397 };
398
376 if (!pci_test_config_bits(pdev, &hpt37x_enable_bits[ap->port_no])) 399 if (!pci_test_config_bits(pdev, &hpt37x_enable_bits[ap->port_no]))
377 return -ENOENT; 400 return -ENOENT;
378 401
@@ -586,11 +609,11 @@ static struct ata_port_operations hpt370a_port_ops = {
586}; 609};
587 610
588/* 611/*
589 * Configuration for HPT372, HPT371, HPT302. Slightly different PIO 612 * Configuration for HPT371 and HPT302. Slightly different PIO and DMA
590 * and DMA mode setting functionality. 613 * mode setting functionality.
591 */ 614 */
592 615
593static struct ata_port_operations hpt372_port_ops = { 616static struct ata_port_operations hpt302_port_ops = {
594 .inherits = &ata_bmdma_port_ops, 617 .inherits = &ata_bmdma_port_ops,
595 618
596 .bmdma_stop = hpt37x_bmdma_stop, 619 .bmdma_stop = hpt37x_bmdma_stop,
@@ -602,7 +625,17 @@ static struct ata_port_operations hpt372_port_ops = {
602}; 625};
603 626
604/* 627/*
605 * Configuration for HPT374. Mode setting works like 372 and friends 628 * Configuration for HPT372. Mode setting works like 371 and 302
629 * but we have a mode filter.
630 */
631
632static struct ata_port_operations hpt372_port_ops = {
633 .inherits = &hpt302_port_ops,
634 .mode_filter = hpt372_filter,
635};
636
637/*
638 * Configuration for HPT374. Mode setting and filtering works like 372
606 * but we have a different cable detection procedure for function 1. 639 * but we have a different cable detection procedure for function 1.
607 */ 640 */
608 641
@@ -647,12 +680,12 @@ static int hpt37x_calibrate_dpll(struct pci_dev *dev)
647 u32 reg5c; 680 u32 reg5c;
648 int tries; 681 int tries;
649 682
650 for(tries = 0; tries < 0x5000; tries++) { 683 for (tries = 0; tries < 0x5000; tries++) {
651 udelay(50); 684 udelay(50);
652 pci_read_config_byte(dev, 0x5b, &reg5b); 685 pci_read_config_byte(dev, 0x5b, &reg5b);
653 if (reg5b & 0x80) { 686 if (reg5b & 0x80) {
654 /* See if it stays set */ 687 /* See if it stays set */
655 for(tries = 0; tries < 0x1000; tries ++) { 688 for (tries = 0; tries < 0x1000; tries++) {
656 pci_read_config_byte(dev, 0x5b, &reg5b); 689 pci_read_config_byte(dev, 0x5b, &reg5b);
657 /* Failed ? */ 690 /* Failed ? */
658 if ((reg5b & 0x80) == 0) 691 if ((reg5b & 0x80) == 0)
@@ -660,7 +693,7 @@ static int hpt37x_calibrate_dpll(struct pci_dev *dev)
660 } 693 }
661 /* Turn off tuning, we have the DPLL set */ 694 /* Turn off tuning, we have the DPLL set */
662 pci_read_config_dword(dev, 0x5c, &reg5c); 695 pci_read_config_dword(dev, 0x5c, &reg5c);
663 pci_write_config_dword(dev, 0x5c, reg5c & ~ 0x100); 696 pci_write_config_dword(dev, 0x5c, reg5c & ~0x100);
664 return 1; 697 return 1;
665 } 698 }
666 } 699 }
@@ -672,6 +705,7 @@ static u32 hpt374_read_freq(struct pci_dev *pdev)
672{ 705{
673 u32 freq; 706 u32 freq;
674 unsigned long io_base = pci_resource_start(pdev, 4); 707 unsigned long io_base = pci_resource_start(pdev, 4);
708
675 if (PCI_FUNC(pdev->devfn) & 1) { 709 if (PCI_FUNC(pdev->devfn) & 1) {
676 struct pci_dev *pdev_0; 710 struct pci_dev *pdev_0;
677 711
@@ -737,23 +771,23 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
737 .udma_mask = ATA_UDMA5, 771 .udma_mask = ATA_UDMA5,
738 .port_ops = &hpt370a_port_ops 772 .port_ops = &hpt370a_port_ops
739 }; 773 };
740 /* HPT370 - UDMA100 */ 774 /* HPT370 - UDMA66 */
741 static const struct ata_port_info info_hpt370_33 = { 775 static const struct ata_port_info info_hpt370_33 = {
742 .flags = ATA_FLAG_SLAVE_POSS, 776 .flags = ATA_FLAG_SLAVE_POSS,
743 .pio_mask = ATA_PIO4, 777 .pio_mask = ATA_PIO4,
744 .mwdma_mask = ATA_MWDMA2, 778 .mwdma_mask = ATA_MWDMA2,
745 .udma_mask = ATA_UDMA5, 779 .udma_mask = ATA_UDMA4,
746 .port_ops = &hpt370_port_ops 780 .port_ops = &hpt370_port_ops
747 }; 781 };
748 /* HPT370A - UDMA100 */ 782 /* HPT370A - UDMA66 */
749 static const struct ata_port_info info_hpt370a_33 = { 783 static const struct ata_port_info info_hpt370a_33 = {
750 .flags = ATA_FLAG_SLAVE_POSS, 784 .flags = ATA_FLAG_SLAVE_POSS,
751 .pio_mask = ATA_PIO4, 785 .pio_mask = ATA_PIO4,
752 .mwdma_mask = ATA_MWDMA2, 786 .mwdma_mask = ATA_MWDMA2,
753 .udma_mask = ATA_UDMA5, 787 .udma_mask = ATA_UDMA4,
754 .port_ops = &hpt370a_port_ops 788 .port_ops = &hpt370a_port_ops
755 }; 789 };
756 /* HPT371, 372 and friends - UDMA133 */ 790 /* HPT372 - UDMA133 */
757 static const struct ata_port_info info_hpt372 = { 791 static const struct ata_port_info info_hpt372 = {
758 .flags = ATA_FLAG_SLAVE_POSS, 792 .flags = ATA_FLAG_SLAVE_POSS,
759 .pio_mask = ATA_PIO4, 793 .pio_mask = ATA_PIO4,
@@ -761,6 +795,14 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
761 .udma_mask = ATA_UDMA6, 795 .udma_mask = ATA_UDMA6,
762 .port_ops = &hpt372_port_ops 796 .port_ops = &hpt372_port_ops
763 }; 797 };
798 /* HPT371, 302 - UDMA133 */
799 static const struct ata_port_info info_hpt302 = {
800 .flags = ATA_FLAG_SLAVE_POSS,
801 .pio_mask = ATA_PIO4,
802 .mwdma_mask = ATA_MWDMA2,
803 .udma_mask = ATA_UDMA6,
804 .port_ops = &hpt302_port_ops
805 };
764 /* HPT374 - UDMA100, function 1 uses different prereset method */ 806 /* HPT374 - UDMA100, function 1 uses different prereset method */
765 static const struct ata_port_info info_hpt374_fn0 = { 807 static const struct ata_port_info info_hpt374_fn0 = {
766 .flags = ATA_FLAG_SLAVE_POSS, 808 .flags = ATA_FLAG_SLAVE_POSS,
@@ -805,64 +847,68 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
805 if (rev == 6) 847 if (rev == 6)
806 return -ENODEV; 848 return -ENODEV;
807 849
808 switch(rev) { 850 switch (rev) {
809 case 3: 851 case 3:
810 ppi[0] = &info_hpt370; 852 ppi[0] = &info_hpt370;
811 chip_table = &hpt370; 853 chip_table = &hpt370;
812 prefer_dpll = 0; 854 prefer_dpll = 0;
813 break; 855 break;
814 case 4: 856 case 4:
815 ppi[0] = &info_hpt370a; 857 ppi[0] = &info_hpt370a;
816 chip_table = &hpt370a; 858 chip_table = &hpt370a;
817 prefer_dpll = 0; 859 prefer_dpll = 0;
818 break; 860 break;
819 case 5: 861 case 5:
820 ppi[0] = &info_hpt372; 862 ppi[0] = &info_hpt372;
821 chip_table = &hpt372; 863 chip_table = &hpt372;
822 break; 864 break;
823 default: 865 default:
824 printk(KERN_ERR "pata_hpt37x: Unknown HPT366 " 866 printk(KERN_ERR "pata_hpt37x: Unknown HPT366 subtype, "
825 "subtype, please report (%d).\n", rev); 867 "please report (%d).\n", rev);
826 return -ENODEV; 868 return -ENODEV;
827 } 869 }
828 } else { 870 } else {
829 switch(dev->device) { 871 switch (dev->device) {
830 case PCI_DEVICE_ID_TTI_HPT372: 872 case PCI_DEVICE_ID_TTI_HPT372:
831 /* 372N if rev >= 2*/ 873 /* 372N if rev >= 2 */
832 if (rev >= 2) 874 if (rev >= 2)
833 return -ENODEV; 875 return -ENODEV;
834 ppi[0] = &info_hpt372; 876 ppi[0] = &info_hpt372;
835 chip_table = &hpt372a; 877 chip_table = &hpt372a;
836 break; 878 break;
837 case PCI_DEVICE_ID_TTI_HPT302: 879 case PCI_DEVICE_ID_TTI_HPT302:
838 /* 302N if rev > 1 */ 880 /* 302N if rev > 1 */
839 if (rev > 1) 881 if (rev > 1)
840 return -ENODEV; 882 return -ENODEV;
841 ppi[0] = &info_hpt372; 883 ppi[0] = &info_hpt302;
842 /* Check this */ 884 /* Check this */
843 chip_table = &hpt302; 885 chip_table = &hpt302;
844 break; 886 break;
845 case PCI_DEVICE_ID_TTI_HPT371: 887 case PCI_DEVICE_ID_TTI_HPT371:
846 if (rev > 1) 888 if (rev > 1)
847 return -ENODEV; 889 return -ENODEV;
848 ppi[0] = &info_hpt372; 890 ppi[0] = &info_hpt302;
849 chip_table = &hpt371; 891 chip_table = &hpt371;
850 /* Single channel device, master is not present 892 /*
851 but the BIOS (or us for non x86) must mark it 893 * Single channel device, master is not present
852 absent */ 894 * but the BIOS (or us for non x86) must mark it
853 pci_read_config_byte(dev, 0x50, &mcr1); 895 * absent
854 mcr1 &= ~0x04; 896 */
855 pci_write_config_byte(dev, 0x50, mcr1); 897 pci_read_config_byte(dev, 0x50, &mcr1);
856 break; 898 mcr1 &= ~0x04;
857 case PCI_DEVICE_ID_TTI_HPT374: 899 pci_write_config_byte(dev, 0x50, mcr1);
858 chip_table = &hpt374; 900 break;
859 if (!(PCI_FUNC(dev->devfn) & 1)) 901 case PCI_DEVICE_ID_TTI_HPT374:
860 *ppi = &info_hpt374_fn0; 902 chip_table = &hpt374;
861 else 903 if (!(PCI_FUNC(dev->devfn) & 1))
862 *ppi = &info_hpt374_fn1; 904 *ppi = &info_hpt374_fn0;
863 break; 905 else
864 default: 906 *ppi = &info_hpt374_fn1;
865 printk(KERN_ERR "pata_hpt37x: PCI table is bogus please report (%d).\n", dev->device); 907 break;
908 default:
909 printk(KERN_ERR
910 "pata_hpt37x: PCI table is bogus, please report (%d).\n",
911 dev->device);
866 return -ENODEV; 912 return -ENODEV;
867 } 913 }
868 } 914 }
@@ -893,9 +939,11 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
893 if (chip_table == &hpt372a) 939 if (chip_table == &hpt372a)
894 outb(0x0e, iobase + 0x9c); 940 outb(0x0e, iobase + 0x9c);
895 941
896 /* Some devices do not let this value be accessed via PCI space 942 /*
897 according to the old driver. In addition we must use the value 943 * Some devices do not let this value be accessed via PCI space
898 from FN 0 on the HPT374 */ 944 * according to the old driver. In addition we must use the value
945 * from FN 0 on the HPT374.
946 */
899 947
900 if (chip_table == &hpt374) { 948 if (chip_table == &hpt374) {
901 freq = hpt374_read_freq(dev); 949 freq = hpt374_read_freq(dev);
@@ -909,10 +957,11 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
909 u8 sr; 957 u8 sr;
910 u32 total = 0; 958 u32 total = 0;
911 959
912 printk(KERN_WARNING "pata_hpt37x: BIOS has not set timing clocks.\n"); 960 printk(KERN_WARNING
961 "pata_hpt37x: BIOS has not set timing clocks.\n");
913 962
914 /* This is the process the HPT371 BIOS is reported to use */ 963 /* This is the process the HPT371 BIOS is reported to use */
915 for(i = 0; i < 128; i++) { 964 for (i = 0; i < 128; i++) {
916 pci_read_config_byte(dev, 0x78, &sr); 965 pci_read_config_byte(dev, 0x78, &sr);
917 total += sr & 0x1FF; 966 total += sr & 0x1FF;
918 udelay(15); 967 udelay(15);
@@ -947,17 +996,22 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
947 996
948 /* Select the DPLL clock. */ 997 /* Select the DPLL clock. */
949 pci_write_config_byte(dev, 0x5b, 0x21); 998 pci_write_config_byte(dev, 0x5b, 0x21);
950 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low | 0x100); 999 pci_write_config_dword(dev, 0x5C,
1000 (f_high << 16) | f_low | 0x100);
951 1001
952 for(adjust = 0; adjust < 8; adjust++) { 1002 for (adjust = 0; adjust < 8; adjust++) {
953 if (hpt37x_calibrate_dpll(dev)) 1003 if (hpt37x_calibrate_dpll(dev))
954 break; 1004 break;
955 /* See if it'll settle at a fractionally different clock */ 1005 /*
1006 * See if it'll settle at a fractionally
1007 * different clock
1008 */
956 if (adjust & 1) 1009 if (adjust & 1)
957 f_low -= adjust >> 1; 1010 f_low -= adjust >> 1;
958 else 1011 else
959 f_high += adjust >> 1; 1012 f_high += adjust >> 1;
960 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low | 0x100); 1013 pci_write_config_dword(dev, 0x5C,
1014 (f_high << 16) | f_low | 0x100);
961 } 1015 }
962 if (adjust == 8) { 1016 if (adjust == 8) {
963 printk(KERN_ERR "pata_hpt37x: DPLL did not stabilize!\n"); 1017 printk(KERN_ERR "pata_hpt37x: DPLL did not stabilize!\n");
@@ -976,7 +1030,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
976 * Perform a final fixup. Note that we will have used the 1030 * Perform a final fixup. Note that we will have used the
977 * DPLL on the HPT372 which means we don't have to worry 1031 * DPLL on the HPT372 which means we don't have to worry
978 * about lack of UDMA133 support on lower clocks 1032 * about lack of UDMA133 support on lower clocks
979 */ 1033 */
980 1034
981 if (clock_slot < 2 && ppi[0] == &info_hpt370) 1035 if (clock_slot < 2 && ppi[0] == &info_hpt370)
982 ppi[0] = &info_hpt370_33; 1036 ppi[0] = &info_hpt370_33;
@@ -1001,9 +1055,9 @@ static const struct pci_device_id hpt37x[] = {
1001}; 1055};
1002 1056
1003static struct pci_driver hpt37x_pci_driver = { 1057static struct pci_driver hpt37x_pci_driver = {
1004 .name = DRV_NAME, 1058 .name = DRV_NAME,
1005 .id_table = hpt37x, 1059 .id_table = hpt37x,
1006 .probe = hpt37x_init_one, 1060 .probe = hpt37x_init_one,
1007 .remove = ata_pci_remove_one 1061 .remove = ata_pci_remove_one
1008}; 1062};
1009 1063
diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
index 32f3463216b8..d2239bbdb798 100644
--- a/drivers/ata/pata_hpt3x2n.c
+++ b/drivers/ata/pata_hpt3x2n.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Libata driver for the highpoint 372N and 302N UDMA66 ATA controllers. 2 * Libata driver for the HighPoint 371N, 372N, and 302N UDMA66 ATA controllers.
3 * 3 *
4 * This driver is heavily based upon: 4 * This driver is heavily based upon:
5 * 5 *
@@ -8,7 +8,7 @@
8 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org> 8 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org>
9 * Portions Copyright (C) 2001 Sun Microsystems, Inc. 9 * Portions Copyright (C) 2001 Sun Microsystems, Inc.
10 * Portions Copyright (C) 2003 Red Hat Inc 10 * Portions Copyright (C) 2003 Red Hat Inc
11 * Portions Copyright (C) 2005-2009 MontaVista Software, Inc. 11 * Portions Copyright (C) 2005-2010 MontaVista Software, Inc.
12 * 12 *
13 * 13 *
14 * TODO 14 * TODO
@@ -25,7 +25,7 @@
25#include <linux/libata.h> 25#include <linux/libata.h>
26 26
27#define DRV_NAME "pata_hpt3x2n" 27#define DRV_NAME "pata_hpt3x2n"
28#define DRV_VERSION "0.3.10" 28#define DRV_VERSION "0.3.13"
29 29
30enum { 30enum {
31 HPT_PCI_FAST = (1 << 31), 31 HPT_PCI_FAST = (1 << 31),
@@ -103,7 +103,7 @@ static u32 hpt3x2n_find_mode(struct ata_port *ap, int speed)
103{ 103{
104 struct hpt_clock *clocks = hpt3x2n_clocks; 104 struct hpt_clock *clocks = hpt3x2n_clocks;
105 105
106 while(clocks->xfer_speed) { 106 while (clocks->xfer_speed) {
107 if (clocks->xfer_speed == speed) 107 if (clocks->xfer_speed == speed)
108 return clocks->timing; 108 return clocks->timing;
109 clocks++; 109 clocks++;
@@ -113,6 +113,22 @@ static u32 hpt3x2n_find_mode(struct ata_port *ap, int speed)
113} 113}
114 114
115/** 115/**
116 * hpt372n_filter - mode selection filter
117 * @adev: ATA device
118 * @mask: mode mask
119 *
120 * The Marvell bridge chips used on the HighPoint SATA cards do not seem
121 * to support the UltraDMA modes 1, 2, and 3 as well as any MWDMA modes...
122 */
123static unsigned long hpt372n_filter(struct ata_device *adev, unsigned long mask)
124{
125 if (ata_id_is_sata(adev->id))
126 mask &= ~((0xE << ATA_SHIFT_UDMA) | ATA_MASK_MWDMA);
127
128 return mask;
129}
130
131/**
116 * hpt3x2n_cable_detect - Detect the cable type 132 * hpt3x2n_cable_detect - Detect the cable type
117 * @ap: ATA port to detect on 133 * @ap: ATA port to detect on
118 * 134 *
@@ -153,6 +169,7 @@ static int hpt3x2n_pre_reset(struct ata_link *link, unsigned long deadline)
153{ 169{
154 struct ata_port *ap = link->ap; 170 struct ata_port *ap = link->ap;
155 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 171 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
172
156 /* Reset the state machine */ 173 /* Reset the state machine */
157 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37); 174 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
158 udelay(100); 175 udelay(100);
@@ -328,10 +345,10 @@ static struct scsi_host_template hpt3x2n_sht = {
328}; 345};
329 346
330/* 347/*
331 * Configuration for HPT3x2n. 348 * Configuration for HPT302N/371N.
332 */ 349 */
333 350
334static struct ata_port_operations hpt3x2n_port_ops = { 351static struct ata_port_operations hpt3xxn_port_ops = {
335 .inherits = &ata_bmdma_port_ops, 352 .inherits = &ata_bmdma_port_ops,
336 353
337 .bmdma_stop = hpt3x2n_bmdma_stop, 354 .bmdma_stop = hpt3x2n_bmdma_stop,
@@ -345,6 +362,15 @@ static struct ata_port_operations hpt3x2n_port_ops = {
345 .prereset = hpt3x2n_pre_reset, 362 .prereset = hpt3x2n_pre_reset,
346}; 363};
347 364
365/*
366 * Configuration for HPT372N. Same as 302N/371N but we have a mode filter.
367 */
368
369static struct ata_port_operations hpt372n_port_ops = {
370 .inherits = &hpt3xxn_port_ops,
371 .mode_filter = &hpt372n_filter,
372};
373
348/** 374/**
349 * hpt3xn_calibrate_dpll - Calibrate the DPLL loop 375 * hpt3xn_calibrate_dpll - Calibrate the DPLL loop
350 * @dev: PCI device 376 * @dev: PCI device
@@ -359,12 +385,12 @@ static int hpt3xn_calibrate_dpll(struct pci_dev *dev)
359 u32 reg5c; 385 u32 reg5c;
360 int tries; 386 int tries;
361 387
362 for(tries = 0; tries < 0x5000; tries++) { 388 for (tries = 0; tries < 0x5000; tries++) {
363 udelay(50); 389 udelay(50);
364 pci_read_config_byte(dev, 0x5b, &reg5b); 390 pci_read_config_byte(dev, 0x5b, &reg5b);
365 if (reg5b & 0x80) { 391 if (reg5b & 0x80) {
366 /* See if it stays set */ 392 /* See if it stays set */
367 for(tries = 0; tries < 0x1000; tries ++) { 393 for (tries = 0; tries < 0x1000; tries++) {
368 pci_read_config_byte(dev, 0x5b, &reg5b); 394 pci_read_config_byte(dev, 0x5b, &reg5b);
369 /* Failed ? */ 395 /* Failed ? */
370 if ((reg5b & 0x80) == 0) 396 if ((reg5b & 0x80) == 0)
@@ -372,7 +398,7 @@ static int hpt3xn_calibrate_dpll(struct pci_dev *dev)
372 } 398 }
373 /* Turn off tuning, we have the DPLL set */ 399 /* Turn off tuning, we have the DPLL set */
374 pci_read_config_dword(dev, 0x5c, &reg5c); 400 pci_read_config_dword(dev, 0x5c, &reg5c);
375 pci_write_config_dword(dev, 0x5c, reg5c & ~ 0x100); 401 pci_write_config_dword(dev, 0x5c, reg5c & ~0x100);
376 return 1; 402 return 1;
377 } 403 }
378 } 404 }
@@ -388,8 +414,19 @@ static int hpt3x2n_pci_clock(struct pci_dev *pdev)
388 414
389 fcnt = inl(iobase + 0x90); /* Not PCI readable for some chips */ 415 fcnt = inl(iobase + 0x90); /* Not PCI readable for some chips */
390 if ((fcnt >> 12) != 0xABCDE) { 416 if ((fcnt >> 12) != 0xABCDE) {
391 printk(KERN_WARNING "hpt3xn: BIOS clock data not set.\n"); 417 int i;
392 return 33; /* Not BIOS set */ 418 u16 sr;
419 u32 total = 0;
420
421 printk(KERN_WARNING "pata_hpt3x2n: BIOS clock data not set.\n");
422
423 /* This is the process the HPT371 BIOS is reported to use */
424 for (i = 0; i < 128; i++) {
425 pci_read_config_word(pdev, 0x78, &sr);
426 total += sr & 0x1FF;
427 udelay(15);
428 }
429 fcnt = total / 128;
393 } 430 }
394 fcnt &= 0x1FF; 431 fcnt &= 0x1FF;
395 432
@@ -431,21 +468,27 @@ static int hpt3x2n_pci_clock(struct pci_dev *pdev)
431 * HPT372N 9 (HPT372N) * UDMA133 468 * HPT372N 9 (HPT372N) * UDMA133
432 * 469 *
433 * (1) UDMA133 support depends on the bus clock 470 * (1) UDMA133 support depends on the bus clock
434 *
435 * To pin down HPT371N
436 */ 471 */
437 472
438static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id) 473static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
439{ 474{
440 /* HPT372N and friends - UDMA133 */ 475 /* HPT372N - UDMA133 */
441 static const struct ata_port_info info = { 476 static const struct ata_port_info info_hpt372n = {
477 .flags = ATA_FLAG_SLAVE_POSS,
478 .pio_mask = ATA_PIO4,
479 .mwdma_mask = ATA_MWDMA2,
480 .udma_mask = ATA_UDMA6,
481 .port_ops = &hpt372n_port_ops
482 };
483 /* HPT302N and HPT371N - UDMA133 */
484 static const struct ata_port_info info_hpt3xxn = {
442 .flags = ATA_FLAG_SLAVE_POSS, 485 .flags = ATA_FLAG_SLAVE_POSS,
443 .pio_mask = ATA_PIO4, 486 .pio_mask = ATA_PIO4,
444 .mwdma_mask = ATA_MWDMA2, 487 .mwdma_mask = ATA_MWDMA2,
445 .udma_mask = ATA_UDMA6, 488 .udma_mask = ATA_UDMA6,
446 .port_ops = &hpt3x2n_port_ops 489 .port_ops = &hpt3xxn_port_ops
447 }; 490 };
448 const struct ata_port_info *ppi[] = { &info, NULL }; 491 const struct ata_port_info *ppi[] = { &info_hpt3xxn, NULL };
449 u8 rev = dev->revision; 492 u8 rev = dev->revision;
450 u8 irqmask; 493 u8 irqmask;
451 unsigned int pci_mhz; 494 unsigned int pci_mhz;
@@ -459,30 +502,36 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
459 if (rc) 502 if (rc)
460 return rc; 503 return rc;
461 504
462 switch(dev->device) { 505 switch (dev->device) {
463 case PCI_DEVICE_ID_TTI_HPT366: 506 case PCI_DEVICE_ID_TTI_HPT366:
464 if (rev < 6) 507 /* 372N if rev >= 6 */
465 return -ENODEV; 508 if (rev < 6)
466 break;
467 case PCI_DEVICE_ID_TTI_HPT371:
468 if (rev < 2)
469 return -ENODEV;
470 /* 371N if rev > 1 */
471 break;
472 case PCI_DEVICE_ID_TTI_HPT372:
473 /* 372N if rev >= 2*/
474 if (rev < 2)
475 return -ENODEV;
476 break;
477 case PCI_DEVICE_ID_TTI_HPT302:
478 if (rev < 2)
479 return -ENODEV;
480 break;
481 case PCI_DEVICE_ID_TTI_HPT372N:
482 break;
483 default:
484 printk(KERN_ERR "pata_hpt3x2n: PCI table is bogus please report (%d).\n", dev->device);
485 return -ENODEV; 509 return -ENODEV;
510 goto hpt372n;
511 case PCI_DEVICE_ID_TTI_HPT371:
512 /* 371N if rev >= 2 */
513 if (rev < 2)
514 return -ENODEV;
515 break;
516 case PCI_DEVICE_ID_TTI_HPT372:
517 /* 372N if rev >= 2 */
518 if (rev < 2)
519 return -ENODEV;
520 goto hpt372n;
521 case PCI_DEVICE_ID_TTI_HPT302:
522 /* 302N if rev >= 2 */
523 if (rev < 2)
524 return -ENODEV;
525 break;
526 case PCI_DEVICE_ID_TTI_HPT372N:
527hpt372n:
528 ppi[0] = &info_hpt372n;
529 break;
530 default:
531 printk(KERN_ERR
532 "pata_hpt3x2n: PCI table is bogus please report (%d).\n",
533 dev->device);
534 return -ENODEV;
486 } 535 }
487 536
488 /* Ok so this is a chip we support */ 537 /* Ok so this is a chip we support */
@@ -509,8 +558,10 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
509 pci_write_config_byte(dev, 0x50, mcr1); 558 pci_write_config_byte(dev, 0x50, mcr1);
510 } 559 }
511 560
512 /* Tune the PLL. HPT recommend using 75 for SATA, 66 for UDMA133 or 561 /*
513 50 for UDMA100. Right now we always use 66 */ 562 * Tune the PLL. HPT recommend using 75 for SATA, 66 for UDMA133 or
563 * 50 for UDMA100. Right now we always use 66
564 */
514 565
515 pci_mhz = hpt3x2n_pci_clock(dev); 566 pci_mhz = hpt3x2n_pci_clock(dev);
516 567
@@ -522,7 +573,7 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
522 pci_write_config_byte(dev, 0x5B, 0x21); 573 pci_write_config_byte(dev, 0x5B, 0x21);
523 574
524 /* Unlike the 37x we don't try jiggling the frequency */ 575 /* Unlike the 37x we don't try jiggling the frequency */
525 for(adjust = 0; adjust < 8; adjust++) { 576 for (adjust = 0; adjust < 8; adjust++) {
526 if (hpt3xn_calibrate_dpll(dev)) 577 if (hpt3xn_calibrate_dpll(dev))
527 break; 578 break;
528 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low); 579 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low);
@@ -534,8 +585,11 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
534 585
535 printk(KERN_INFO "pata_hpt37x: bus clock %dMHz, using 66MHz DPLL.\n", 586 printk(KERN_INFO "pata_hpt37x: bus clock %dMHz, using 66MHz DPLL.\n",
536 pci_mhz); 587 pci_mhz);
537 /* Set our private data up. We only need a few flags so we use 588
538 it directly */ 589 /*
590 * Set our private data up. We only need a few flags
591 * so we use it directly.
592 */
539 if (pci_mhz > 60) 593 if (pci_mhz > 60)
540 hpriv = (void *)(PCI66 | USE_DPLL); 594 hpriv = (void *)(PCI66 | USE_DPLL);
541 595
@@ -562,9 +616,9 @@ static const struct pci_device_id hpt3x2n[] = {
562}; 616};
563 617
564static struct pci_driver hpt3x2n_pci_driver = { 618static struct pci_driver hpt3x2n_pci_driver = {
565 .name = DRV_NAME, 619 .name = DRV_NAME,
566 .id_table = hpt3x2n, 620 .id_table = hpt3x2n,
567 .probe = hpt3x2n_init_one, 621 .probe = hpt3x2n_init_one,
568 .remove = ata_pci_remove_one 622 .remove = ata_pci_remove_one
569}; 623};
570 624
@@ -579,7 +633,7 @@ static void __exit hpt3x2n_exit(void)
579} 633}
580 634
581MODULE_AUTHOR("Alan Cox"); 635MODULE_AUTHOR("Alan Cox");
582MODULE_DESCRIPTION("low-level driver for the Highpoint HPT3x2n/30x"); 636MODULE_DESCRIPTION("low-level driver for the Highpoint HPT3xxN");
583MODULE_LICENSE("GPL"); 637MODULE_LICENSE("GPL");
584MODULE_DEVICE_TABLE(pci, hpt3x2n); 638MODULE_DEVICE_TABLE(pci, hpt3x2n);
585MODULE_VERSION(DRV_VERSION); 639MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 6ed645411c40..761359261589 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -338,6 +338,35 @@ static void device_remove_attributes(struct device *dev,
338 device_remove_file(dev, &attrs[i]); 338 device_remove_file(dev, &attrs[i]);
339} 339}
340 340
341static int device_add_bin_attributes(struct device *dev,
342 struct bin_attribute *attrs)
343{
344 int error = 0;
345 int i;
346
347 if (attrs) {
348 for (i = 0; attr_name(attrs[i]); i++) {
349 error = device_create_bin_file(dev, &attrs[i]);
350 if (error)
351 break;
352 }
353 if (error)
354 while (--i >= 0)
355 device_remove_bin_file(dev, &attrs[i]);
356 }
357 return error;
358}
359
360static void device_remove_bin_attributes(struct device *dev,
361 struct bin_attribute *attrs)
362{
363 int i;
364
365 if (attrs)
366 for (i = 0; attr_name(attrs[i]); i++)
367 device_remove_bin_file(dev, &attrs[i]);
368}
369
341static int device_add_groups(struct device *dev, 370static int device_add_groups(struct device *dev,
342 const struct attribute_group **groups) 371 const struct attribute_group **groups)
343{ 372{
@@ -378,12 +407,15 @@ static int device_add_attrs(struct device *dev)
378 error = device_add_attributes(dev, class->dev_attrs); 407 error = device_add_attributes(dev, class->dev_attrs);
379 if (error) 408 if (error)
380 return error; 409 return error;
410 error = device_add_bin_attributes(dev, class->dev_bin_attrs);
411 if (error)
412 goto err_remove_class_attrs;
381 } 413 }
382 414
383 if (type) { 415 if (type) {
384 error = device_add_groups(dev, type->groups); 416 error = device_add_groups(dev, type->groups);
385 if (error) 417 if (error)
386 goto err_remove_class_attrs; 418 goto err_remove_class_bin_attrs;
387 } 419 }
388 420
389 error = device_add_groups(dev, dev->groups); 421 error = device_add_groups(dev, dev->groups);
@@ -395,6 +427,9 @@ static int device_add_attrs(struct device *dev)
395 err_remove_type_groups: 427 err_remove_type_groups:
396 if (type) 428 if (type)
397 device_remove_groups(dev, type->groups); 429 device_remove_groups(dev, type->groups);
430 err_remove_class_bin_attrs:
431 if (class)
432 device_remove_bin_attributes(dev, class->dev_bin_attrs);
398 err_remove_class_attrs: 433 err_remove_class_attrs:
399 if (class) 434 if (class)
400 device_remove_attributes(dev, class->dev_attrs); 435 device_remove_attributes(dev, class->dev_attrs);
@@ -412,8 +447,10 @@ static void device_remove_attrs(struct device *dev)
412 if (type) 447 if (type)
413 device_remove_groups(dev, type->groups); 448 device_remove_groups(dev, type->groups);
414 449
415 if (class) 450 if (class) {
416 device_remove_attributes(dev, class->dev_attrs); 451 device_remove_attributes(dev, class->dev_attrs);
452 device_remove_bin_attributes(dev, class->dev_bin_attrs);
453 }
417} 454}
418 455
419 456
diff --git a/drivers/base/power/generic_ops.c b/drivers/base/power/generic_ops.c
index 81f2c84697f4..42f97f925629 100644
--- a/drivers/base/power/generic_ops.c
+++ b/drivers/base/power/generic_ops.c
@@ -39,7 +39,7 @@ EXPORT_SYMBOL_GPL(pm_generic_runtime_idle);
39 * 39 *
40 * If PM operations are defined for the @dev's driver and they include 40 * If PM operations are defined for the @dev's driver and they include
41 * ->runtime_suspend(), execute it and return its error code. Otherwise, 41 * ->runtime_suspend(), execute it and return its error code. Otherwise,
42 * return -EINVAL. 42 * return 0.
43 */ 43 */
44int pm_generic_runtime_suspend(struct device *dev) 44int pm_generic_runtime_suspend(struct device *dev)
45{ 45{
@@ -58,7 +58,7 @@ EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend);
58 * 58 *
59 * If PM operations are defined for the @dev's driver and they include 59 * If PM operations are defined for the @dev's driver and they include
60 * ->runtime_resume(), execute it and return its error code. Otherwise, 60 * ->runtime_resume(), execute it and return its error code. Otherwise,
61 * return -EINVAL. 61 * return 0.
62 */ 62 */
63int pm_generic_runtime_resume(struct device *dev) 63int pm_generic_runtime_resume(struct device *dev)
64{ 64{
@@ -185,7 +185,7 @@ static int __pm_generic_resume(struct device *dev, int event)
185 return 0; 185 return 0;
186 186
187 ret = callback(dev); 187 ret = callback(dev);
188 if (!ret) { 188 if (!ret && pm_runtime_enabled(dev)) {
189 pm_runtime_disable(dev); 189 pm_runtime_disable(dev);
190 pm_runtime_set_active(dev); 190 pm_runtime_set_active(dev);
191 pm_runtime_enable(dev); 191 pm_runtime_enable(dev);
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index ead3e79d6fcf..2a52270aeb30 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -26,6 +26,7 @@
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/async.h> 28#include <linux/async.h>
29#include <linux/suspend.h>
29 30
30#include "../base.h" 31#include "../base.h"
31#include "power.h" 32#include "power.h"
@@ -41,16 +42,13 @@
41 */ 42 */
42 43
43LIST_HEAD(dpm_list); 44LIST_HEAD(dpm_list);
45LIST_HEAD(dpm_prepared_list);
46LIST_HEAD(dpm_suspended_list);
47LIST_HEAD(dpm_noirq_list);
44 48
45static DEFINE_MUTEX(dpm_list_mtx); 49static DEFINE_MUTEX(dpm_list_mtx);
46static pm_message_t pm_transition; 50static pm_message_t pm_transition;
47 51
48/*
49 * Set once the preparation of devices for a PM transition has started, reset
50 * before starting to resume devices. Protected by dpm_list_mtx.
51 */
52static bool transition_started;
53
54static int async_error; 52static int async_error;
55 53
56/** 54/**
@@ -59,7 +57,7 @@ static int async_error;
59 */ 57 */
60void device_pm_init(struct device *dev) 58void device_pm_init(struct device *dev)
61{ 59{
62 dev->power.status = DPM_ON; 60 dev->power.in_suspend = false;
63 init_completion(&dev->power.completion); 61 init_completion(&dev->power.completion);
64 complete_all(&dev->power.completion); 62 complete_all(&dev->power.completion);
65 dev->power.wakeup = NULL; 63 dev->power.wakeup = NULL;
@@ -90,22 +88,11 @@ void device_pm_unlock(void)
90void device_pm_add(struct device *dev) 88void device_pm_add(struct device *dev)
91{ 89{
92 pr_debug("PM: Adding info for %s:%s\n", 90 pr_debug("PM: Adding info for %s:%s\n",
93 dev->bus ? dev->bus->name : "No Bus", 91 dev->bus ? dev->bus->name : "No Bus", dev_name(dev));
94 kobject_name(&dev->kobj));
95 mutex_lock(&dpm_list_mtx); 92 mutex_lock(&dpm_list_mtx);
96 if (dev->parent) { 93 if (dev->parent && dev->parent->power.in_suspend)
97 if (dev->parent->power.status >= DPM_SUSPENDING) 94 dev_warn(dev, "parent %s should not be sleeping\n",
98 dev_warn(dev, "parent %s should not be sleeping\n", 95 dev_name(dev->parent));
99 dev_name(dev->parent));
100 } else if (transition_started) {
101 /*
102 * We refuse to register parentless devices while a PM
103 * transition is in progress in order to avoid leaving them
104 * unhandled down the road
105 */
106 dev_WARN(dev, "Parentless device registered during a PM transaction\n");
107 }
108
109 list_add_tail(&dev->power.entry, &dpm_list); 96 list_add_tail(&dev->power.entry, &dpm_list);
110 mutex_unlock(&dpm_list_mtx); 97 mutex_unlock(&dpm_list_mtx);
111} 98}
@@ -117,8 +104,7 @@ void device_pm_add(struct device *dev)
117void device_pm_remove(struct device *dev) 104void device_pm_remove(struct device *dev)
118{ 105{
119 pr_debug("PM: Removing info for %s:%s\n", 106 pr_debug("PM: Removing info for %s:%s\n",
120 dev->bus ? dev->bus->name : "No Bus", 107 dev->bus ? dev->bus->name : "No Bus", dev_name(dev));
121 kobject_name(&dev->kobj));
122 complete_all(&dev->power.completion); 108 complete_all(&dev->power.completion);
123 mutex_lock(&dpm_list_mtx); 109 mutex_lock(&dpm_list_mtx);
124 list_del_init(&dev->power.entry); 110 list_del_init(&dev->power.entry);
@@ -135,10 +121,8 @@ void device_pm_remove(struct device *dev)
135void device_pm_move_before(struct device *deva, struct device *devb) 121void device_pm_move_before(struct device *deva, struct device *devb)
136{ 122{
137 pr_debug("PM: Moving %s:%s before %s:%s\n", 123 pr_debug("PM: Moving %s:%s before %s:%s\n",
138 deva->bus ? deva->bus->name : "No Bus", 124 deva->bus ? deva->bus->name : "No Bus", dev_name(deva),
139 kobject_name(&deva->kobj), 125 devb->bus ? devb->bus->name : "No Bus", dev_name(devb));
140 devb->bus ? devb->bus->name : "No Bus",
141 kobject_name(&devb->kobj));
142 /* Delete deva from dpm_list and reinsert before devb. */ 126 /* Delete deva from dpm_list and reinsert before devb. */
143 list_move_tail(&deva->power.entry, &devb->power.entry); 127 list_move_tail(&deva->power.entry, &devb->power.entry);
144} 128}
@@ -151,10 +135,8 @@ void device_pm_move_before(struct device *deva, struct device *devb)
151void device_pm_move_after(struct device *deva, struct device *devb) 135void device_pm_move_after(struct device *deva, struct device *devb)
152{ 136{
153 pr_debug("PM: Moving %s:%s after %s:%s\n", 137 pr_debug("PM: Moving %s:%s after %s:%s\n",
154 deva->bus ? deva->bus->name : "No Bus", 138 deva->bus ? deva->bus->name : "No Bus", dev_name(deva),
155 kobject_name(&deva->kobj), 139 devb->bus ? devb->bus->name : "No Bus", dev_name(devb));
156 devb->bus ? devb->bus->name : "No Bus",
157 kobject_name(&devb->kobj));
158 /* Delete deva from dpm_list and reinsert after devb. */ 140 /* Delete deva from dpm_list and reinsert after devb. */
159 list_move(&deva->power.entry, &devb->power.entry); 141 list_move(&deva->power.entry, &devb->power.entry);
160} 142}
@@ -166,8 +148,7 @@ void device_pm_move_after(struct device *deva, struct device *devb)
166void device_pm_move_last(struct device *dev) 148void device_pm_move_last(struct device *dev)
167{ 149{
168 pr_debug("PM: Moving %s:%s to end of list\n", 150 pr_debug("PM: Moving %s:%s to end of list\n",
169 dev->bus ? dev->bus->name : "No Bus", 151 dev->bus ? dev->bus->name : "No Bus", dev_name(dev));
170 kobject_name(&dev->kobj));
171 list_move_tail(&dev->power.entry, &dpm_list); 152 list_move_tail(&dev->power.entry, &dpm_list);
172} 153}
173 154
@@ -303,7 +284,7 @@ static int pm_noirq_op(struct device *dev,
303 pm_message_t state) 284 pm_message_t state)
304{ 285{
305 int error = 0; 286 int error = 0;
306 ktime_t calltime, delta, rettime; 287 ktime_t calltime = ktime_set(0, 0), delta, rettime;
307 288
308 if (initcall_debug) { 289 if (initcall_debug) {
309 pr_info("calling %s+ @ %i, parent: %s\n", 290 pr_info("calling %s+ @ %i, parent: %s\n",
@@ -405,7 +386,7 @@ static void pm_dev_err(struct device *dev, pm_message_t state, char *info,
405 int error) 386 int error)
406{ 387{
407 printk(KERN_ERR "PM: Device %s failed to %s%s: error %d\n", 388 printk(KERN_ERR "PM: Device %s failed to %s%s: error %d\n",
408 kobject_name(&dev->kobj), pm_verb(state.event), info, error); 389 dev_name(dev), pm_verb(state.event), info, error);
409} 390}
410 391
411static void dpm_show_time(ktime_t starttime, pm_message_t state, char *info) 392static void dpm_show_time(ktime_t starttime, pm_message_t state, char *info)
@@ -475,33 +456,24 @@ End:
475 */ 456 */
476void dpm_resume_noirq(pm_message_t state) 457void dpm_resume_noirq(pm_message_t state)
477{ 458{
478 struct list_head list;
479 ktime_t starttime = ktime_get(); 459 ktime_t starttime = ktime_get();
480 460
481 INIT_LIST_HEAD(&list);
482 mutex_lock(&dpm_list_mtx); 461 mutex_lock(&dpm_list_mtx);
483 transition_started = false; 462 while (!list_empty(&dpm_noirq_list)) {
484 while (!list_empty(&dpm_list)) { 463 struct device *dev = to_device(dpm_noirq_list.next);
485 struct device *dev = to_device(dpm_list.next); 464 int error;
486 465
487 get_device(dev); 466 get_device(dev);
488 if (dev->power.status > DPM_OFF) { 467 list_move_tail(&dev->power.entry, &dpm_suspended_list);
489 int error; 468 mutex_unlock(&dpm_list_mtx);
490
491 dev->power.status = DPM_OFF;
492 mutex_unlock(&dpm_list_mtx);
493 469
494 error = device_resume_noirq(dev, state); 470 error = device_resume_noirq(dev, state);
471 if (error)
472 pm_dev_err(dev, state, " early", error);
495 473
496 mutex_lock(&dpm_list_mtx); 474 mutex_lock(&dpm_list_mtx);
497 if (error)
498 pm_dev_err(dev, state, " early", error);
499 }
500 if (!list_empty(&dev->power.entry))
501 list_move_tail(&dev->power.entry, &list);
502 put_device(dev); 475 put_device(dev);
503 } 476 }
504 list_splice(&list, &dpm_list);
505 mutex_unlock(&dpm_list_mtx); 477 mutex_unlock(&dpm_list_mtx);
506 dpm_show_time(starttime, state, "early"); 478 dpm_show_time(starttime, state, "early");
507 resume_device_irqs(); 479 resume_device_irqs();
@@ -544,7 +516,7 @@ static int device_resume(struct device *dev, pm_message_t state, bool async)
544 dpm_wait(dev->parent, async); 516 dpm_wait(dev->parent, async);
545 device_lock(dev); 517 device_lock(dev);
546 518
547 dev->power.status = DPM_RESUMING; 519 dev->power.in_suspend = false;
548 520
549 if (dev->bus) { 521 if (dev->bus) {
550 if (dev->bus->pm) { 522 if (dev->bus->pm) {
@@ -610,19 +582,14 @@ static bool is_async(struct device *dev)
610 */ 582 */
611static void dpm_resume(pm_message_t state) 583static void dpm_resume(pm_message_t state)
612{ 584{
613 struct list_head list;
614 struct device *dev; 585 struct device *dev;
615 ktime_t starttime = ktime_get(); 586 ktime_t starttime = ktime_get();
616 587
617 INIT_LIST_HEAD(&list);
618 mutex_lock(&dpm_list_mtx); 588 mutex_lock(&dpm_list_mtx);
619 pm_transition = state; 589 pm_transition = state;
620 async_error = 0; 590 async_error = 0;
621 591
622 list_for_each_entry(dev, &dpm_list, power.entry) { 592 list_for_each_entry(dev, &dpm_suspended_list, power.entry) {
623 if (dev->power.status < DPM_OFF)
624 continue;
625
626 INIT_COMPLETION(dev->power.completion); 593 INIT_COMPLETION(dev->power.completion);
627 if (is_async(dev)) { 594 if (is_async(dev)) {
628 get_device(dev); 595 get_device(dev);
@@ -630,28 +597,24 @@ static void dpm_resume(pm_message_t state)
630 } 597 }
631 } 598 }
632 599
633 while (!list_empty(&dpm_list)) { 600 while (!list_empty(&dpm_suspended_list)) {
634 dev = to_device(dpm_list.next); 601 dev = to_device(dpm_suspended_list.next);
635 get_device(dev); 602 get_device(dev);
636 if (dev->power.status >= DPM_OFF && !is_async(dev)) { 603 if (!is_async(dev)) {
637 int error; 604 int error;
638 605
639 mutex_unlock(&dpm_list_mtx); 606 mutex_unlock(&dpm_list_mtx);
640 607
641 error = device_resume(dev, state, false); 608 error = device_resume(dev, state, false);
642
643 mutex_lock(&dpm_list_mtx);
644 if (error) 609 if (error)
645 pm_dev_err(dev, state, "", error); 610 pm_dev_err(dev, state, "", error);
646 } else if (dev->power.status == DPM_SUSPENDING) { 611
647 /* Allow new children of the device to be registered */ 612 mutex_lock(&dpm_list_mtx);
648 dev->power.status = DPM_RESUMING;
649 } 613 }
650 if (!list_empty(&dev->power.entry)) 614 if (!list_empty(&dev->power.entry))
651 list_move_tail(&dev->power.entry, &list); 615 list_move_tail(&dev->power.entry, &dpm_prepared_list);
652 put_device(dev); 616 put_device(dev);
653 } 617 }
654 list_splice(&list, &dpm_list);
655 mutex_unlock(&dpm_list_mtx); 618 mutex_unlock(&dpm_list_mtx);
656 async_synchronize_full(); 619 async_synchronize_full();
657 dpm_show_time(starttime, state, NULL); 620 dpm_show_time(starttime, state, NULL);
@@ -697,22 +660,18 @@ static void dpm_complete(pm_message_t state)
697 660
698 INIT_LIST_HEAD(&list); 661 INIT_LIST_HEAD(&list);
699 mutex_lock(&dpm_list_mtx); 662 mutex_lock(&dpm_list_mtx);
700 transition_started = false; 663 while (!list_empty(&dpm_prepared_list)) {
701 while (!list_empty(&dpm_list)) { 664 struct device *dev = to_device(dpm_prepared_list.prev);
702 struct device *dev = to_device(dpm_list.prev);
703 665
704 get_device(dev); 666 get_device(dev);
705 if (dev->power.status > DPM_ON) { 667 dev->power.in_suspend = false;
706 dev->power.status = DPM_ON; 668 list_move(&dev->power.entry, &list);
707 mutex_unlock(&dpm_list_mtx); 669 mutex_unlock(&dpm_list_mtx);
708 670
709 device_complete(dev, state); 671 device_complete(dev, state);
710 pm_runtime_put_sync(dev); 672 pm_runtime_put_sync(dev);
711 673
712 mutex_lock(&dpm_list_mtx); 674 mutex_lock(&dpm_list_mtx);
713 }
714 if (!list_empty(&dev->power.entry))
715 list_move(&dev->power.entry, &list);
716 put_device(dev); 675 put_device(dev);
717 } 676 }
718 list_splice(&list, &dpm_list); 677 list_splice(&list, &dpm_list);
@@ -802,15 +761,13 @@ End:
802 */ 761 */
803int dpm_suspend_noirq(pm_message_t state) 762int dpm_suspend_noirq(pm_message_t state)
804{ 763{
805 struct list_head list;
806 ktime_t starttime = ktime_get(); 764 ktime_t starttime = ktime_get();
807 int error = 0; 765 int error = 0;
808 766
809 INIT_LIST_HEAD(&list);
810 suspend_device_irqs(); 767 suspend_device_irqs();
811 mutex_lock(&dpm_list_mtx); 768 mutex_lock(&dpm_list_mtx);
812 while (!list_empty(&dpm_list)) { 769 while (!list_empty(&dpm_suspended_list)) {
813 struct device *dev = to_device(dpm_list.prev); 770 struct device *dev = to_device(dpm_suspended_list.prev);
814 771
815 get_device(dev); 772 get_device(dev);
816 mutex_unlock(&dpm_list_mtx); 773 mutex_unlock(&dpm_list_mtx);
@@ -823,12 +780,10 @@ int dpm_suspend_noirq(pm_message_t state)
823 put_device(dev); 780 put_device(dev);
824 break; 781 break;
825 } 782 }
826 dev->power.status = DPM_OFF_IRQ;
827 if (!list_empty(&dev->power.entry)) 783 if (!list_empty(&dev->power.entry))
828 list_move(&dev->power.entry, &list); 784 list_move(&dev->power.entry, &dpm_noirq_list);
829 put_device(dev); 785 put_device(dev);
830 } 786 }
831 list_splice_tail(&list, &dpm_list);
832 mutex_unlock(&dpm_list_mtx); 787 mutex_unlock(&dpm_list_mtx);
833 if (error) 788 if (error)
834 dpm_resume_noirq(resume_event(state)); 789 dpm_resume_noirq(resume_event(state));
@@ -876,6 +831,11 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
876 if (async_error) 831 if (async_error)
877 goto End; 832 goto End;
878 833
834 if (pm_wakeup_pending()) {
835 async_error = -EBUSY;
836 goto End;
837 }
838
879 if (dev->class) { 839 if (dev->class) {
880 if (dev->class->pm) { 840 if (dev->class->pm) {
881 pm_dev_dbg(dev, state, "class "); 841 pm_dev_dbg(dev, state, "class ");
@@ -907,9 +867,6 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
907 } 867 }
908 } 868 }
909 869
910 if (!error)
911 dev->power.status = DPM_OFF;
912
913 End: 870 End:
914 device_unlock(dev); 871 device_unlock(dev);
915 complete_all(&dev->power.completion); 872 complete_all(&dev->power.completion);
@@ -951,16 +908,14 @@ static int device_suspend(struct device *dev)
951 */ 908 */
952static int dpm_suspend(pm_message_t state) 909static int dpm_suspend(pm_message_t state)
953{ 910{
954 struct list_head list;
955 ktime_t starttime = ktime_get(); 911 ktime_t starttime = ktime_get();
956 int error = 0; 912 int error = 0;
957 913
958 INIT_LIST_HEAD(&list);
959 mutex_lock(&dpm_list_mtx); 914 mutex_lock(&dpm_list_mtx);
960 pm_transition = state; 915 pm_transition = state;
961 async_error = 0; 916 async_error = 0;
962 while (!list_empty(&dpm_list)) { 917 while (!list_empty(&dpm_prepared_list)) {
963 struct device *dev = to_device(dpm_list.prev); 918 struct device *dev = to_device(dpm_prepared_list.prev);
964 919
965 get_device(dev); 920 get_device(dev);
966 mutex_unlock(&dpm_list_mtx); 921 mutex_unlock(&dpm_list_mtx);
@@ -974,12 +929,11 @@ static int dpm_suspend(pm_message_t state)
974 break; 929 break;
975 } 930 }
976 if (!list_empty(&dev->power.entry)) 931 if (!list_empty(&dev->power.entry))
977 list_move(&dev->power.entry, &list); 932 list_move(&dev->power.entry, &dpm_suspended_list);
978 put_device(dev); 933 put_device(dev);
979 if (async_error) 934 if (async_error)
980 break; 935 break;
981 } 936 }
982 list_splice(&list, dpm_list.prev);
983 mutex_unlock(&dpm_list_mtx); 937 mutex_unlock(&dpm_list_mtx);
984 async_synchronize_full(); 938 async_synchronize_full();
985 if (!error) 939 if (!error)
@@ -1038,22 +992,20 @@ static int device_prepare(struct device *dev, pm_message_t state)
1038 */ 992 */
1039static int dpm_prepare(pm_message_t state) 993static int dpm_prepare(pm_message_t state)
1040{ 994{
1041 struct list_head list;
1042 int error = 0; 995 int error = 0;
1043 996
1044 INIT_LIST_HEAD(&list);
1045 mutex_lock(&dpm_list_mtx); 997 mutex_lock(&dpm_list_mtx);
1046 transition_started = true;
1047 while (!list_empty(&dpm_list)) { 998 while (!list_empty(&dpm_list)) {
1048 struct device *dev = to_device(dpm_list.next); 999 struct device *dev = to_device(dpm_list.next);
1049 1000
1050 get_device(dev); 1001 get_device(dev);
1051 dev->power.status = DPM_PREPARING;
1052 mutex_unlock(&dpm_list_mtx); 1002 mutex_unlock(&dpm_list_mtx);
1053 1003
1054 pm_runtime_get_noresume(dev); 1004 pm_runtime_get_noresume(dev);
1055 if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) { 1005 if (pm_runtime_barrier(dev) && device_may_wakeup(dev))
1056 /* Wake-up requested during system sleep transition. */ 1006 pm_wakeup_event(dev, 0);
1007
1008 if (pm_wakeup_pending()) {
1057 pm_runtime_put_sync(dev); 1009 pm_runtime_put_sync(dev);
1058 error = -EBUSY; 1010 error = -EBUSY;
1059 } else { 1011 } else {
@@ -1062,24 +1014,22 @@ static int dpm_prepare(pm_message_t state)
1062 1014
1063 mutex_lock(&dpm_list_mtx); 1015 mutex_lock(&dpm_list_mtx);
1064 if (error) { 1016 if (error) {
1065 dev->power.status = DPM_ON;
1066 if (error == -EAGAIN) { 1017 if (error == -EAGAIN) {
1067 put_device(dev); 1018 put_device(dev);
1068 error = 0; 1019 error = 0;
1069 continue; 1020 continue;
1070 } 1021 }
1071 printk(KERN_ERR "PM: Failed to prepare device %s " 1022 printk(KERN_INFO "PM: Device %s not prepared "
1072 "for power transition: error %d\n", 1023 "for power transition: code %d\n",
1073 kobject_name(&dev->kobj), error); 1024 dev_name(dev), error);
1074 put_device(dev); 1025 put_device(dev);
1075 break; 1026 break;
1076 } 1027 }
1077 dev->power.status = DPM_SUSPENDING; 1028 dev->power.in_suspend = true;
1078 if (!list_empty(&dev->power.entry)) 1029 if (!list_empty(&dev->power.entry))
1079 list_move_tail(&dev->power.entry, &list); 1030 list_move_tail(&dev->power.entry, &dpm_prepared_list);
1080 put_device(dev); 1031 put_device(dev);
1081 } 1032 }
1082 list_splice(&list, &dpm_list);
1083 mutex_unlock(&dpm_list_mtx); 1033 mutex_unlock(&dpm_list_mtx);
1084 return error; 1034 return error;
1085} 1035}
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 02c652be83e7..656493a5e073 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -250,13 +250,16 @@ static int rpm_callback(int (*cb)(struct device *), struct device *dev)
250 if (!cb) 250 if (!cb)
251 return -ENOSYS; 251 return -ENOSYS;
252 252
253 spin_unlock_irq(&dev->power.lock); 253 if (dev->power.irq_safe) {
254 retval = cb(dev);
255 } else {
256 spin_unlock_irq(&dev->power.lock);
254 257
255 retval = cb(dev); 258 retval = cb(dev);
256 259
257 spin_lock_irq(&dev->power.lock); 260 spin_lock_irq(&dev->power.lock);
261 }
258 dev->power.runtime_error = retval; 262 dev->power.runtime_error = retval;
259
260 return retval; 263 return retval;
261} 264}
262 265
@@ -404,7 +407,7 @@ static int rpm_suspend(struct device *dev, int rpmflags)
404 goto out; 407 goto out;
405 } 408 }
406 409
407 if (parent && !parent->power.ignore_children) { 410 if (parent && !parent->power.ignore_children && !dev->power.irq_safe) {
408 spin_unlock_irq(&dev->power.lock); 411 spin_unlock_irq(&dev->power.lock);
409 412
410 pm_request_idle(parent); 413 pm_request_idle(parent);
@@ -527,10 +530,13 @@ static int rpm_resume(struct device *dev, int rpmflags)
527 530
528 if (!parent && dev->parent) { 531 if (!parent && dev->parent) {
529 /* 532 /*
530 * Increment the parent's resume counter and resume it if 533 * Increment the parent's usage counter and resume it if
531 * necessary. 534 * necessary. Not needed if dev is irq-safe; then the
535 * parent is permanently resumed.
532 */ 536 */
533 parent = dev->parent; 537 parent = dev->parent;
538 if (dev->power.irq_safe)
539 goto skip_parent;
534 spin_unlock(&dev->power.lock); 540 spin_unlock(&dev->power.lock);
535 541
536 pm_runtime_get_noresume(parent); 542 pm_runtime_get_noresume(parent);
@@ -553,6 +559,7 @@ static int rpm_resume(struct device *dev, int rpmflags)
553 goto out; 559 goto out;
554 goto repeat; 560 goto repeat;
555 } 561 }
562 skip_parent:
556 563
557 if (dev->power.no_callbacks) 564 if (dev->power.no_callbacks)
558 goto no_callback; /* Assume success. */ 565 goto no_callback; /* Assume success. */
@@ -584,7 +591,7 @@ static int rpm_resume(struct device *dev, int rpmflags)
584 rpm_idle(dev, RPM_ASYNC); 591 rpm_idle(dev, RPM_ASYNC);
585 592
586 out: 593 out:
587 if (parent) { 594 if (parent && !dev->power.irq_safe) {
588 spin_unlock_irq(&dev->power.lock); 595 spin_unlock_irq(&dev->power.lock);
589 596
590 pm_runtime_put(parent); 597 pm_runtime_put(parent);
@@ -1065,7 +1072,6 @@ EXPORT_SYMBOL_GPL(pm_runtime_allow);
1065 * Set the power.no_callbacks flag, which tells the PM core that this 1072 * Set the power.no_callbacks flag, which tells the PM core that this
1066 * device is power-managed through its parent and has no run-time PM 1073 * device is power-managed through its parent and has no run-time PM
1067 * callbacks of its own. The run-time sysfs attributes will be removed. 1074 * callbacks of its own. The run-time sysfs attributes will be removed.
1068 *
1069 */ 1075 */
1070void pm_runtime_no_callbacks(struct device *dev) 1076void pm_runtime_no_callbacks(struct device *dev)
1071{ 1077{
@@ -1078,6 +1084,27 @@ void pm_runtime_no_callbacks(struct device *dev)
1078EXPORT_SYMBOL_GPL(pm_runtime_no_callbacks); 1084EXPORT_SYMBOL_GPL(pm_runtime_no_callbacks);
1079 1085
1080/** 1086/**
1087 * pm_runtime_irq_safe - Leave interrupts disabled during callbacks.
1088 * @dev: Device to handle
1089 *
1090 * Set the power.irq_safe flag, which tells the PM core that the
1091 * ->runtime_suspend() and ->runtime_resume() callbacks for this device should
1092 * always be invoked with the spinlock held and interrupts disabled. It also
1093 * causes the parent's usage counter to be permanently incremented, preventing
1094 * the parent from runtime suspending -- otherwise an irq-safe child might have
1095 * to wait for a non-irq-safe parent.
1096 */
1097void pm_runtime_irq_safe(struct device *dev)
1098{
1099 if (dev->parent)
1100 pm_runtime_get_sync(dev->parent);
1101 spin_lock_irq(&dev->power.lock);
1102 dev->power.irq_safe = 1;
1103 spin_unlock_irq(&dev->power.lock);
1104}
1105EXPORT_SYMBOL_GPL(pm_runtime_irq_safe);
1106
1107/**
1081 * update_autosuspend - Handle a change to a device's autosuspend settings. 1108 * update_autosuspend - Handle a change to a device's autosuspend settings.
1082 * @dev: Device to handle. 1109 * @dev: Device to handle.
1083 * @old_delay: The former autosuspend_delay value. 1110 * @old_delay: The former autosuspend_delay value.
@@ -1199,4 +1226,6 @@ void pm_runtime_remove(struct device *dev)
1199 /* Change the status back to 'suspended' to match the initial status. */ 1226 /* Change the status back to 'suspended' to match the initial status. */
1200 if (dev->power.runtime_status == RPM_ACTIVE) 1227 if (dev->power.runtime_status == RPM_ACTIVE)
1201 pm_runtime_set_suspended(dev); 1228 pm_runtime_set_suspended(dev);
1229 if (dev->power.irq_safe && dev->parent)
1230 pm_runtime_put_sync(dev->parent);
1202} 1231}
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index 71c5528e1c35..8ec406d8f548 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -542,26 +542,26 @@ static void pm_wakeup_update_hit_counts(void)
542} 542}
543 543
544/** 544/**
545 * pm_check_wakeup_events - Check for new wakeup events. 545 * pm_wakeup_pending - Check if power transition in progress should be aborted.
546 * 546 *
547 * Compare the current number of registered wakeup events with its preserved 547 * Compare the current number of registered wakeup events with its preserved
548 * value from the past to check if new wakeup events have been registered since 548 * value from the past and return true if new wakeup events have been registered
549 * the old value was stored. Check if the current number of wakeup events being 549 * since the old value was stored. Also return true if the current number of
550 * processed is zero. 550 * wakeup events being processed is different from zero.
551 */ 551 */
552bool pm_check_wakeup_events(void) 552bool pm_wakeup_pending(void)
553{ 553{
554 unsigned long flags; 554 unsigned long flags;
555 bool ret = true; 555 bool ret = false;
556 556
557 spin_lock_irqsave(&events_lock, flags); 557 spin_lock_irqsave(&events_lock, flags);
558 if (events_check_enabled) { 558 if (events_check_enabled) {
559 ret = ((unsigned int)atomic_read(&event_count) == saved_count) 559 ret = ((unsigned int)atomic_read(&event_count) != saved_count)
560 && !atomic_read(&events_in_progress); 560 || atomic_read(&events_in_progress);
561 events_check_enabled = ret; 561 events_check_enabled = !ret;
562 } 562 }
563 spin_unlock_irqrestore(&events_lock, flags); 563 spin_unlock_irqrestore(&events_lock, flags);
564 if (!ret) 564 if (ret)
565 pm_wakeup_update_hit_counts(); 565 pm_wakeup_update_hit_counts();
566 return ret; 566 return ret;
567} 567}
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 035da9e64a17..f27c04e18aaa 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -69,6 +69,8 @@
69#ifdef CONFIG_PPC_OF 69#ifdef CONFIG_PPC_OF
70#include <linux/of_device.h> 70#include <linux/of_device.h>
71#include <linux/of_platform.h> 71#include <linux/of_platform.h>
72#include <linux/of_address.h>
73#include <linux/of_irq.h>
72#endif 74#endif
73 75
74#define PFX "ipmi_si: " 76#define PFX "ipmi_si: "
@@ -2546,7 +2548,7 @@ static int __devinit ipmi_of_probe(struct platform_device *dev,
2546{ 2548{
2547 struct smi_info *info; 2549 struct smi_info *info;
2548 struct resource resource; 2550 struct resource resource;
2549 const int *regsize, *regspacing, *regshift; 2551 const __be32 *regsize, *regspacing, *regshift;
2550 struct device_node *np = dev->dev.of_node; 2552 struct device_node *np = dev->dev.of_node;
2551 int ret; 2553 int ret;
2552 int proplen; 2554 int proplen;
@@ -2599,9 +2601,9 @@ static int __devinit ipmi_of_probe(struct platform_device *dev,
2599 2601
2600 info->io.addr_data = resource.start; 2602 info->io.addr_data = resource.start;
2601 2603
2602 info->io.regsize = regsize ? *regsize : DEFAULT_REGSIZE; 2604 info->io.regsize = regsize ? be32_to_cpup(regsize) : DEFAULT_REGSIZE;
2603 info->io.regspacing = regspacing ? *regspacing : DEFAULT_REGSPACING; 2605 info->io.regspacing = regspacing ? be32_to_cpup(regspacing) : DEFAULT_REGSPACING;
2604 info->io.regshift = regshift ? *regshift : 0; 2606 info->io.regshift = regshift ? be32_to_cpup(regshift) : 0;
2605 2607
2606 info->irq = irq_of_parse_and_map(dev->dev.of_node, 0); 2608 info->irq = irq_of_parse_and_map(dev->dev.of_node, 0);
2607 info->dev = &dev->dev; 2609 info->dev = &dev->dev;
diff --git a/drivers/char/snsc.h b/drivers/char/snsc.h
index 4be62eda9fbc..e8c52c882b21 100644
--- a/drivers/char/snsc.h
+++ b/drivers/char/snsc.h
@@ -19,7 +19,6 @@
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/spinlock.h> 20#include <linux/spinlock.h>
21#include <linux/wait.h> 21#include <linux/wait.h>
22#include <linux/kobject.h>
23#include <linux/fs.h> 22#include <linux/fs.h>
24#include <linux/cdev.h> 23#include <linux/cdev.h>
25#include <linux/semaphore.h> 24#include <linux/semaphore.h>
diff --git a/drivers/firewire/Kconfig b/drivers/firewire/Kconfig
index 40a222e19b2d..68f942cb30f2 100644
--- a/drivers/firewire/Kconfig
+++ b/drivers/firewire/Kconfig
@@ -19,7 +19,7 @@ config FIREWIRE
19 19
20config FIREWIRE_OHCI 20config FIREWIRE_OHCI
21 tristate "OHCI-1394 controllers" 21 tristate "OHCI-1394 controllers"
22 depends on PCI && FIREWIRE 22 depends on PCI && FIREWIRE && MMU
23 help 23 help
24 Enable this driver if you have a FireWire controller based 24 Enable this driver if you have a FireWire controller based
25 on the OHCI specification. For all practical purposes, this 25 on the OHCI specification. For all practical purposes, this
diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index 14bb7b7b5dd7..48ae712e2101 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -1501,9 +1501,10 @@ static int ioctl_send_phy_packet(struct client *client, union ioctl_arg *arg)
1501 e->client = client; 1501 e->client = client;
1502 e->p.speed = SCODE_100; 1502 e->p.speed = SCODE_100;
1503 e->p.generation = a->generation; 1503 e->p.generation = a->generation;
1504 e->p.header[0] = a->data[0]; 1504 e->p.header[0] = TCODE_LINK_INTERNAL << 4;
1505 e->p.header[1] = a->data[1]; 1505 e->p.header[1] = a->data[0];
1506 e->p.header_length = 8; 1506 e->p.header[2] = a->data[1];
1507 e->p.header_length = 12;
1507 e->p.callback = outbound_phy_packet_callback; 1508 e->p.callback = outbound_phy_packet_callback;
1508 e->phy_packet.closure = a->closure; 1509 e->phy_packet.closure = a->closure;
1509 e->phy_packet.type = FW_CDEV_EVENT_PHY_PACKET_SENT; 1510 e->phy_packet.type = FW_CDEV_EVENT_PHY_PACKET_SENT;
diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
index b42a0bde8494..d00f8ce902cc 100644
--- a/drivers/firewire/core-transaction.c
+++ b/drivers/firewire/core-transaction.c
@@ -72,6 +72,15 @@
72#define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23)) 72#define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23))
73#define PHY_IDENTIFIER(id) ((id) << 30) 73#define PHY_IDENTIFIER(id) ((id) << 30)
74 74
75/* returns 0 if the split timeout handler is already running */
76static int try_cancel_split_timeout(struct fw_transaction *t)
77{
78 if (t->is_split_transaction)
79 return del_timer(&t->split_timeout_timer);
80 else
81 return 1;
82}
83
75static int close_transaction(struct fw_transaction *transaction, 84static int close_transaction(struct fw_transaction *transaction,
76 struct fw_card *card, int rcode) 85 struct fw_card *card, int rcode)
77{ 86{
@@ -81,7 +90,7 @@ static int close_transaction(struct fw_transaction *transaction,
81 spin_lock_irqsave(&card->lock, flags); 90 spin_lock_irqsave(&card->lock, flags);
82 list_for_each_entry(t, &card->transaction_list, link) { 91 list_for_each_entry(t, &card->transaction_list, link) {
83 if (t == transaction) { 92 if (t == transaction) {
84 if (!del_timer(&t->split_timeout_timer)) { 93 if (!try_cancel_split_timeout(t)) {
85 spin_unlock_irqrestore(&card->lock, flags); 94 spin_unlock_irqrestore(&card->lock, flags);
86 goto timed_out; 95 goto timed_out;
87 } 96 }
@@ -141,16 +150,28 @@ static void split_transaction_timeout_callback(unsigned long data)
141 card->tlabel_mask &= ~(1ULL << t->tlabel); 150 card->tlabel_mask &= ~(1ULL << t->tlabel);
142 spin_unlock_irqrestore(&card->lock, flags); 151 spin_unlock_irqrestore(&card->lock, flags);
143 152
144 card->driver->cancel_packet(card, &t->packet);
145
146 /*
147 * At this point cancel_packet will never call the transaction
148 * callback, since we just took the transaction out of the list.
149 * So do it here.
150 */
151 t->callback(card, RCODE_CANCELLED, NULL, 0, t->callback_data); 153 t->callback(card, RCODE_CANCELLED, NULL, 0, t->callback_data);
152} 154}
153 155
156static void start_split_transaction_timeout(struct fw_transaction *t,
157 struct fw_card *card)
158{
159 unsigned long flags;
160
161 spin_lock_irqsave(&card->lock, flags);
162
163 if (list_empty(&t->link) || WARN_ON(t->is_split_transaction)) {
164 spin_unlock_irqrestore(&card->lock, flags);
165 return;
166 }
167
168 t->is_split_transaction = true;
169 mod_timer(&t->split_timeout_timer,
170 jiffies + card->split_timeout_jiffies);
171
172 spin_unlock_irqrestore(&card->lock, flags);
173}
174
154static void transmit_complete_callback(struct fw_packet *packet, 175static void transmit_complete_callback(struct fw_packet *packet,
155 struct fw_card *card, int status) 176 struct fw_card *card, int status)
156{ 177{
@@ -162,7 +183,7 @@ static void transmit_complete_callback(struct fw_packet *packet,
162 close_transaction(t, card, RCODE_COMPLETE); 183 close_transaction(t, card, RCODE_COMPLETE);
163 break; 184 break;
164 case ACK_PENDING: 185 case ACK_PENDING:
165 t->timestamp = packet->timestamp; 186 start_split_transaction_timeout(t, card);
166 break; 187 break;
167 case ACK_BUSY_X: 188 case ACK_BUSY_X:
168 case ACK_BUSY_A: 189 case ACK_BUSY_A:
@@ -250,7 +271,7 @@ static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
250 break; 271 break;
251 272
252 default: 273 default:
253 WARN(1, "wrong tcode %d", tcode); 274 WARN(1, "wrong tcode %d\n", tcode);
254 } 275 }
255 common: 276 common:
256 packet->speed = speed; 277 packet->speed = speed;
@@ -349,11 +370,9 @@ void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode,
349 t->node_id = destination_id; 370 t->node_id = destination_id;
350 t->tlabel = tlabel; 371 t->tlabel = tlabel;
351 t->card = card; 372 t->card = card;
373 t->is_split_transaction = false;
352 setup_timer(&t->split_timeout_timer, 374 setup_timer(&t->split_timeout_timer,
353 split_transaction_timeout_callback, (unsigned long)t); 375 split_transaction_timeout_callback, (unsigned long)t);
354 /* FIXME: start this timer later, relative to t->timestamp */
355 mod_timer(&t->split_timeout_timer,
356 jiffies + card->split_timeout_jiffies);
357 t->callback = callback; 376 t->callback = callback;
358 t->callback_data = callback_data; 377 t->callback_data = callback_data;
359 378
@@ -423,7 +442,8 @@ static void transmit_phy_packet_callback(struct fw_packet *packet,
423} 442}
424 443
425static struct fw_packet phy_config_packet = { 444static struct fw_packet phy_config_packet = {
426 .header_length = 8, 445 .header_length = 12,
446 .header[0] = TCODE_LINK_INTERNAL << 4,
427 .payload_length = 0, 447 .payload_length = 0,
428 .speed = SCODE_100, 448 .speed = SCODE_100,
429 .callback = transmit_phy_packet_callback, 449 .callback = transmit_phy_packet_callback,
@@ -451,8 +471,8 @@ void fw_send_phy_config(struct fw_card *card,
451 471
452 mutex_lock(&phy_config_mutex); 472 mutex_lock(&phy_config_mutex);
453 473
454 phy_config_packet.header[0] = data; 474 phy_config_packet.header[1] = data;
455 phy_config_packet.header[1] = ~data; 475 phy_config_packet.header[2] = ~data;
456 phy_config_packet.generation = generation; 476 phy_config_packet.generation = generation;
457 INIT_COMPLETION(phy_config_done); 477 INIT_COMPLETION(phy_config_done);
458 478
@@ -638,7 +658,7 @@ int fw_get_response_length(struct fw_request *r)
638 } 658 }
639 659
640 default: 660 default:
641 WARN(1, "wrong tcode %d", tcode); 661 WARN(1, "wrong tcode %d\n", tcode);
642 return 0; 662 return 0;
643 } 663 }
644} 664}
@@ -694,7 +714,7 @@ void fw_fill_response(struct fw_packet *response, u32 *request_header,
694 break; 714 break;
695 715
696 default: 716 default:
697 WARN(1, "wrong tcode %d", tcode); 717 WARN(1, "wrong tcode %d\n", tcode);
698 } 718 }
699 719
700 response->payload_mapped = false; 720 response->payload_mapped = false;
@@ -925,7 +945,7 @@ void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
925 spin_lock_irqsave(&card->lock, flags); 945 spin_lock_irqsave(&card->lock, flags);
926 list_for_each_entry(t, &card->transaction_list, link) { 946 list_for_each_entry(t, &card->transaction_list, link) {
927 if (t->node_id == source && t->tlabel == tlabel) { 947 if (t->node_id == source && t->tlabel == tlabel) {
928 if (!del_timer(&t->split_timeout_timer)) { 948 if (!try_cancel_split_timeout(t)) {
929 spin_unlock_irqrestore(&card->lock, flags); 949 spin_unlock_irqrestore(&card->lock, flags);
930 goto timed_out; 950 goto timed_out;
931 } 951 }
diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
index e6239f971be6..f8dfcf1c6cbe 100644
--- a/drivers/firewire/core.h
+++ b/drivers/firewire/core.h
@@ -215,9 +215,11 @@ static inline bool is_next_generation(int new_generation, int old_generation)
215 215
216/* -transaction */ 216/* -transaction */
217 217
218#define TCODE_LINK_INTERNAL 0xe
219
218#define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4) 220#define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4)
219#define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0) 221#define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0)
220#define TCODE_IS_LINK_INTERNAL(tcode) ((tcode) == 0xe) 222#define TCODE_IS_LINK_INTERNAL(tcode) ((tcode) == TCODE_LINK_INTERNAL)
221#define TCODE_IS_REQUEST(tcode) (((tcode) & 2) == 0) 223#define TCODE_IS_REQUEST(tcode) (((tcode) & 2) == 0)
222#define TCODE_IS_RESPONSE(tcode) (((tcode) & 2) != 0) 224#define TCODE_IS_RESPONSE(tcode) (((tcode) & 2) != 0)
223#define TCODE_HAS_REQUEST_DATA(tcode) (((tcode) & 12) != 4) 225#define TCODE_HAS_REQUEST_DATA(tcode) (((tcode) & 12) != 4)
diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c
index 1a467a91fb0b..c2e194c58667 100644
--- a/drivers/firewire/net.c
+++ b/drivers/firewire/net.c
@@ -9,6 +9,7 @@
9#include <linux/bug.h> 9#include <linux/bug.h>
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <linux/device.h> 11#include <linux/device.h>
12#include <linux/ethtool.h>
12#include <linux/firewire.h> 13#include <linux/firewire.h>
13#include <linux/firewire-constants.h> 14#include <linux/firewire-constants.h>
14#include <linux/highmem.h> 15#include <linux/highmem.h>
@@ -179,6 +180,7 @@ struct fwnet_device {
179 /* Number of tx datagrams that have been queued but not yet acked */ 180 /* Number of tx datagrams that have been queued but not yet acked */
180 int queued_datagrams; 181 int queued_datagrams;
181 182
183 int peer_count;
182 struct list_head peer_list; 184 struct list_head peer_list;
183 struct fw_card *card; 185 struct fw_card *card;
184 struct net_device *netdev; 186 struct net_device *netdev;
@@ -996,15 +998,23 @@ static void fwnet_transmit_packet_failed(struct fwnet_packet_task *ptask)
996static void fwnet_write_complete(struct fw_card *card, int rcode, 998static void fwnet_write_complete(struct fw_card *card, int rcode,
997 void *payload, size_t length, void *data) 999 void *payload, size_t length, void *data)
998{ 1000{
999 struct fwnet_packet_task *ptask; 1001 struct fwnet_packet_task *ptask = data;
1000 1002 static unsigned long j;
1001 ptask = data; 1003 static int last_rcode, errors_skipped;
1002 1004
1003 if (rcode == RCODE_COMPLETE) { 1005 if (rcode == RCODE_COMPLETE) {
1004 fwnet_transmit_packet_done(ptask); 1006 fwnet_transmit_packet_done(ptask);
1005 } else { 1007 } else {
1006 fw_error("fwnet_write_complete: failed: %x\n", rcode);
1007 fwnet_transmit_packet_failed(ptask); 1008 fwnet_transmit_packet_failed(ptask);
1009
1010 if (printk_timed_ratelimit(&j, 1000) || rcode != last_rcode) {
1011 fw_error("fwnet_write_complete: "
1012 "failed: %x (skipped %d)\n", rcode, errors_skipped);
1013
1014 errors_skipped = 0;
1015 last_rcode = rcode;
1016 } else
1017 errors_skipped++;
1008 } 1018 }
1009} 1019}
1010 1020
@@ -1213,6 +1223,14 @@ static int fwnet_broadcast_start(struct fwnet_device *dev)
1213 return retval; 1223 return retval;
1214} 1224}
1215 1225
1226static void set_carrier_state(struct fwnet_device *dev)
1227{
1228 if (dev->peer_count > 1)
1229 netif_carrier_on(dev->netdev);
1230 else
1231 netif_carrier_off(dev->netdev);
1232}
1233
1216/* ifup */ 1234/* ifup */
1217static int fwnet_open(struct net_device *net) 1235static int fwnet_open(struct net_device *net)
1218{ 1236{
@@ -1226,6 +1244,10 @@ static int fwnet_open(struct net_device *net)
1226 } 1244 }
1227 netif_start_queue(net); 1245 netif_start_queue(net);
1228 1246
1247 spin_lock_irq(&dev->lock);
1248 set_carrier_state(dev);
1249 spin_unlock_irq(&dev->lock);
1250
1229 return 0; 1251 return 0;
1230} 1252}
1231 1253
@@ -1397,6 +1419,10 @@ static int fwnet_change_mtu(struct net_device *net, int new_mtu)
1397 return 0; 1419 return 0;
1398} 1420}
1399 1421
1422static const struct ethtool_ops fwnet_ethtool_ops = {
1423 .get_link = ethtool_op_get_link,
1424};
1425
1400static const struct net_device_ops fwnet_netdev_ops = { 1426static const struct net_device_ops fwnet_netdev_ops = {
1401 .ndo_open = fwnet_open, 1427 .ndo_open = fwnet_open,
1402 .ndo_stop = fwnet_stop, 1428 .ndo_stop = fwnet_stop,
@@ -1415,6 +1441,7 @@ static void fwnet_init_dev(struct net_device *net)
1415 net->hard_header_len = FWNET_HLEN; 1441 net->hard_header_len = FWNET_HLEN;
1416 net->type = ARPHRD_IEEE1394; 1442 net->type = ARPHRD_IEEE1394;
1417 net->tx_queue_len = FWNET_TX_QUEUE_LEN; 1443 net->tx_queue_len = FWNET_TX_QUEUE_LEN;
1444 net->ethtool_ops = &fwnet_ethtool_ops;
1418} 1445}
1419 1446
1420/* caller must hold fwnet_device_mutex */ 1447/* caller must hold fwnet_device_mutex */
@@ -1455,6 +1482,8 @@ static int fwnet_add_peer(struct fwnet_device *dev,
1455 1482
1456 spin_lock_irq(&dev->lock); 1483 spin_lock_irq(&dev->lock);
1457 list_add_tail(&peer->peer_link, &dev->peer_list); 1484 list_add_tail(&peer->peer_link, &dev->peer_list);
1485 dev->peer_count++;
1486 set_carrier_state(dev);
1458 spin_unlock_irq(&dev->lock); 1487 spin_unlock_irq(&dev->lock);
1459 1488
1460 return 0; 1489 return 0;
@@ -1535,13 +1564,15 @@ static int fwnet_probe(struct device *_dev)
1535 return ret; 1564 return ret;
1536} 1565}
1537 1566
1538static void fwnet_remove_peer(struct fwnet_peer *peer) 1567static void fwnet_remove_peer(struct fwnet_peer *peer, struct fwnet_device *dev)
1539{ 1568{
1540 struct fwnet_partial_datagram *pd, *pd_next; 1569 struct fwnet_partial_datagram *pd, *pd_next;
1541 1570
1542 spin_lock_irq(&peer->dev->lock); 1571 spin_lock_irq(&dev->lock);
1543 list_del(&peer->peer_link); 1572 list_del(&peer->peer_link);
1544 spin_unlock_irq(&peer->dev->lock); 1573 dev->peer_count--;
1574 set_carrier_state(dev);
1575 spin_unlock_irq(&dev->lock);
1545 1576
1546 list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link) 1577 list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link)
1547 fwnet_pd_delete(pd); 1578 fwnet_pd_delete(pd);
@@ -1558,7 +1589,7 @@ static int fwnet_remove(struct device *_dev)
1558 1589
1559 mutex_lock(&fwnet_device_mutex); 1590 mutex_lock(&fwnet_device_mutex);
1560 1591
1561 fwnet_remove_peer(peer); 1592 fwnet_remove_peer(peer, dev);
1562 1593
1563 if (list_empty(&dev->peer_list)) { 1594 if (list_empty(&dev->peer_list)) {
1564 net = dev->netdev; 1595 net = dev->netdev;
diff --git a/drivers/firewire/nosy.c b/drivers/firewire/nosy.c
index bf184fb59a5e..0618145376ad 100644
--- a/drivers/firewire/nosy.c
+++ b/drivers/firewire/nosy.c
@@ -302,7 +302,7 @@ nosy_open(struct inode *inode, struct file *file)
302 302
303 file->private_data = client; 303 file->private_data = client;
304 304
305 return 0; 305 return nonseekable_open(inode, file);
306fail: 306fail:
307 kfree(client); 307 kfree(client);
308 lynx_put(lynx); 308 lynx_put(lynx);
@@ -405,7 +405,6 @@ static const struct file_operations nosy_ops = {
405 .poll = nosy_poll, 405 .poll = nosy_poll,
406 .open = nosy_open, 406 .open = nosy_open,
407 .release = nosy_release, 407 .release = nosy_release,
408 .llseek = noop_llseek,
409}; 408};
410 409
411#define PHY_PACKET_SIZE 12 /* 1 payload, 1 inverse, 1 ack = 3 quadlets */ 410#define PHY_PACKET_SIZE 12 /* 1 payload, 1 inverse, 1 ack = 3 quadlets */
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
index e3c8b60bd86b..d77d120ddc25 100644
--- a/drivers/firewire/ohci.c
+++ b/drivers/firewire/ohci.c
@@ -18,6 +18,7 @@
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */ 19 */
20 20
21#include <linux/bitops.h>
21#include <linux/bug.h> 22#include <linux/bug.h>
22#include <linux/compiler.h> 23#include <linux/compiler.h>
23#include <linux/delay.h> 24#include <linux/delay.h>
@@ -40,6 +41,7 @@
40#include <linux/spinlock.h> 41#include <linux/spinlock.h>
41#include <linux/string.h> 42#include <linux/string.h>
42#include <linux/time.h> 43#include <linux/time.h>
44#include <linux/vmalloc.h>
43 45
44#include <asm/byteorder.h> 46#include <asm/byteorder.h>
45#include <asm/page.h> 47#include <asm/page.h>
@@ -80,17 +82,23 @@ struct descriptor {
80#define COMMAND_PTR(regs) ((regs) + 12) 82#define COMMAND_PTR(regs) ((regs) + 12)
81#define CONTEXT_MATCH(regs) ((regs) + 16) 83#define CONTEXT_MATCH(regs) ((regs) + 16)
82 84
83struct ar_buffer { 85#define AR_BUFFER_SIZE (32*1024)
84 struct descriptor descriptor; 86#define AR_BUFFERS_MIN DIV_ROUND_UP(AR_BUFFER_SIZE, PAGE_SIZE)
85 struct ar_buffer *next; 87/* we need at least two pages for proper list management */
86 __le32 data[0]; 88#define AR_BUFFERS (AR_BUFFERS_MIN >= 2 ? AR_BUFFERS_MIN : 2)
87}; 89
90#define MAX_ASYNC_PAYLOAD 4096
91#define MAX_AR_PACKET_SIZE (16 + MAX_ASYNC_PAYLOAD + 4)
92#define AR_WRAPAROUND_PAGES DIV_ROUND_UP(MAX_AR_PACKET_SIZE, PAGE_SIZE)
88 93
89struct ar_context { 94struct ar_context {
90 struct fw_ohci *ohci; 95 struct fw_ohci *ohci;
91 struct ar_buffer *current_buffer; 96 struct page *pages[AR_BUFFERS];
92 struct ar_buffer *last_buffer; 97 void *buffer;
98 struct descriptor *descriptors;
99 dma_addr_t descriptors_bus;
93 void *pointer; 100 void *pointer;
101 unsigned int last_buffer_index;
94 u32 regs; 102 u32 regs;
95 struct tasklet_struct tasklet; 103 struct tasklet_struct tasklet;
96}; 104};
@@ -117,6 +125,8 @@ struct context {
117 struct fw_ohci *ohci; 125 struct fw_ohci *ohci;
118 u32 regs; 126 u32 regs;
119 int total_allocation; 127 int total_allocation;
128 bool running;
129 bool flushing;
120 130
121 /* 131 /*
122 * List of page-sized buffers for storing DMA descriptors. 132 * List of page-sized buffers for storing DMA descriptors.
@@ -161,6 +171,9 @@ struct iso_context {
161 int excess_bytes; 171 int excess_bytes;
162 void *header; 172 void *header;
163 size_t header_length; 173 size_t header_length;
174
175 u8 sync;
176 u8 tags;
164}; 177};
165 178
166#define CONFIG_ROM_SIZE 1024 179#define CONFIG_ROM_SIZE 1024
@@ -177,7 +190,8 @@ struct fw_ohci {
177 u32 bus_time; 190 u32 bus_time;
178 bool is_root; 191 bool is_root;
179 bool csr_state_setclear_abdicate; 192 bool csr_state_setclear_abdicate;
180 193 int n_ir;
194 int n_it;
181 /* 195 /*
182 * Spinlock for accessing fw_ohci data. Never call out of 196 * Spinlock for accessing fw_ohci data. Never call out of
183 * this driver with this lock held. 197 * this driver with this lock held.
@@ -186,6 +200,9 @@ struct fw_ohci {
186 200
187 struct mutex phy_reg_mutex; 201 struct mutex phy_reg_mutex;
188 202
203 void *misc_buffer;
204 dma_addr_t misc_buffer_bus;
205
189 struct ar_context ar_request_ctx; 206 struct ar_context ar_request_ctx;
190 struct ar_context ar_response_ctx; 207 struct ar_context ar_response_ctx;
191 struct context at_request_ctx; 208 struct context at_request_ctx;
@@ -411,10 +428,6 @@ static const char *tcodes[] = {
411 [0xc] = "-reserved-", [0xd] = "-reserved-", 428 [0xc] = "-reserved-", [0xd] = "-reserved-",
412 [0xe] = "link internal", [0xf] = "-reserved-", 429 [0xe] = "link internal", [0xf] = "-reserved-",
413}; 430};
414static const char *phys[] = {
415 [0x0] = "phy config packet", [0x1] = "link-on packet",
416 [0x2] = "self-id packet", [0x3] = "-reserved-",
417};
418 431
419static void log_ar_at_event(char dir, int speed, u32 *header, int evt) 432static void log_ar_at_event(char dir, int speed, u32 *header, int evt)
420{ 433{
@@ -433,12 +446,6 @@ static void log_ar_at_event(char dir, int speed, u32 *header, int evt)
433 return; 446 return;
434 } 447 }
435 448
436 if (header[0] == ~header[1]) {
437 fw_notify("A%c %s, %s, %08x\n",
438 dir, evts[evt], phys[header[0] >> 30 & 0x3], header[0]);
439 return;
440 }
441
442 switch (tcode) { 449 switch (tcode) {
443 case 0x0: case 0x6: case 0x8: 450 case 0x0: case 0x6: case 0x8:
444 snprintf(specific, sizeof(specific), " = %08x", 451 snprintf(specific, sizeof(specific), " = %08x",
@@ -453,9 +460,13 @@ static void log_ar_at_event(char dir, int speed, u32 *header, int evt)
453 } 460 }
454 461
455 switch (tcode) { 462 switch (tcode) {
456 case 0xe: case 0xa: 463 case 0xa:
457 fw_notify("A%c %s, %s\n", dir, evts[evt], tcodes[tcode]); 464 fw_notify("A%c %s, %s\n", dir, evts[evt], tcodes[tcode]);
458 break; 465 break;
466 case 0xe:
467 fw_notify("A%c %s, PHY %08x %08x\n",
468 dir, evts[evt], header[1], header[2]);
469 break;
459 case 0x0: case 0x1: case 0x4: case 0x5: case 0x9: 470 case 0x0: case 0x1: case 0x4: case 0x5: case 0x9:
460 fw_notify("A%c spd %x tl %02x, " 471 fw_notify("A%c spd %x tl %02x, "
461 "%04x -> %04x, %s, " 472 "%04x -> %04x, %s, "
@@ -594,59 +605,150 @@ static int ohci_update_phy_reg(struct fw_card *card, int addr,
594 return ret; 605 return ret;
595} 606}
596 607
597static void ar_context_link_page(struct ar_context *ctx, 608static inline dma_addr_t ar_buffer_bus(struct ar_context *ctx, unsigned int i)
598 struct ar_buffer *ab, dma_addr_t ab_bus)
599{ 609{
600 size_t offset; 610 return page_private(ctx->pages[i]);
611}
601 612
602 ab->next = NULL; 613static void ar_context_link_page(struct ar_context *ctx, unsigned int index)
603 memset(&ab->descriptor, 0, sizeof(ab->descriptor)); 614{
604 ab->descriptor.control = cpu_to_le16(DESCRIPTOR_INPUT_MORE | 615 struct descriptor *d;
605 DESCRIPTOR_STATUS | 616
606 DESCRIPTOR_BRANCH_ALWAYS); 617 d = &ctx->descriptors[index];
607 offset = offsetof(struct ar_buffer, data); 618 d->branch_address &= cpu_to_le32(~0xf);
608 ab->descriptor.req_count = cpu_to_le16(PAGE_SIZE - offset); 619 d->res_count = cpu_to_le16(PAGE_SIZE);
609 ab->descriptor.data_address = cpu_to_le32(ab_bus + offset); 620 d->transfer_status = 0;
610 ab->descriptor.res_count = cpu_to_le16(PAGE_SIZE - offset);
611 ab->descriptor.branch_address = 0;
612 621
613 wmb(); /* finish init of new descriptors before branch_address update */ 622 wmb(); /* finish init of new descriptors before branch_address update */
614 ctx->last_buffer->descriptor.branch_address = cpu_to_le32(ab_bus | 1); 623 d = &ctx->descriptors[ctx->last_buffer_index];
615 ctx->last_buffer->next = ab; 624 d->branch_address |= cpu_to_le32(1);
616 ctx->last_buffer = ab; 625
626 ctx->last_buffer_index = index;
617 627
618 reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_WAKE); 628 reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_WAKE);
619 flush_writes(ctx->ohci); 629 flush_writes(ctx->ohci);
620} 630}
621 631
622static int ar_context_add_page(struct ar_context *ctx) 632static void ar_context_release(struct ar_context *ctx)
623{ 633{
624 struct device *dev = ctx->ohci->card.device; 634 unsigned int i;
625 struct ar_buffer *ab;
626 dma_addr_t uninitialized_var(ab_bus);
627 635
628 ab = dma_alloc_coherent(dev, PAGE_SIZE, &ab_bus, GFP_ATOMIC); 636 if (ctx->buffer)
629 if (ab == NULL) 637 vm_unmap_ram(ctx->buffer, AR_BUFFERS + AR_WRAPAROUND_PAGES);
630 return -ENOMEM;
631 638
632 ar_context_link_page(ctx, ab, ab_bus); 639 for (i = 0; i < AR_BUFFERS; i++)
640 if (ctx->pages[i]) {
641 dma_unmap_page(ctx->ohci->card.device,
642 ar_buffer_bus(ctx, i),
643 PAGE_SIZE, DMA_FROM_DEVICE);
644 __free_page(ctx->pages[i]);
645 }
646}
633 647
634 return 0; 648static void ar_context_abort(struct ar_context *ctx, const char *error_msg)
649{
650 if (reg_read(ctx->ohci, CONTROL_CLEAR(ctx->regs)) & CONTEXT_RUN) {
651 reg_write(ctx->ohci, CONTROL_CLEAR(ctx->regs), CONTEXT_RUN);
652 flush_writes(ctx->ohci);
653
654 fw_error("AR error: %s; DMA stopped\n", error_msg);
655 }
656 /* FIXME: restart? */
635} 657}
636 658
637static void ar_context_release(struct ar_context *ctx) 659static inline unsigned int ar_next_buffer_index(unsigned int index)
660{
661 return (index + 1) % AR_BUFFERS;
662}
663
664static inline unsigned int ar_prev_buffer_index(unsigned int index)
665{
666 return (index - 1 + AR_BUFFERS) % AR_BUFFERS;
667}
668
669static inline unsigned int ar_first_buffer_index(struct ar_context *ctx)
670{
671 return ar_next_buffer_index(ctx->last_buffer_index);
672}
673
674/*
675 * We search for the buffer that contains the last AR packet DMA data written
676 * by the controller.
677 */
678static unsigned int ar_search_last_active_buffer(struct ar_context *ctx,
679 unsigned int *buffer_offset)
638{ 680{
639 struct ar_buffer *ab, *ab_next; 681 unsigned int i, next_i, last = ctx->last_buffer_index;
640 size_t offset; 682 __le16 res_count, next_res_count;
641 dma_addr_t ab_bus; 683
684 i = ar_first_buffer_index(ctx);
685 res_count = ACCESS_ONCE(ctx->descriptors[i].res_count);
686
687 /* A buffer that is not yet completely filled must be the last one. */
688 while (i != last && res_count == 0) {
689
690 /* Peek at the next descriptor. */
691 next_i = ar_next_buffer_index(i);
692 rmb(); /* read descriptors in order */
693 next_res_count = ACCESS_ONCE(
694 ctx->descriptors[next_i].res_count);
695 /*
696 * If the next descriptor is still empty, we must stop at this
697 * descriptor.
698 */
699 if (next_res_count == cpu_to_le16(PAGE_SIZE)) {
700 /*
701 * The exception is when the DMA data for one packet is
702 * split over three buffers; in this case, the middle
703 * buffer's descriptor might be never updated by the
704 * controller and look still empty, and we have to peek
705 * at the third one.
706 */
707 if (MAX_AR_PACKET_SIZE > PAGE_SIZE && i != last) {
708 next_i = ar_next_buffer_index(next_i);
709 rmb();
710 next_res_count = ACCESS_ONCE(
711 ctx->descriptors[next_i].res_count);
712 if (next_res_count != cpu_to_le16(PAGE_SIZE))
713 goto next_buffer_is_active;
714 }
642 715
643 for (ab = ctx->current_buffer; ab; ab = ab_next) { 716 break;
644 ab_next = ab->next; 717 }
645 offset = offsetof(struct ar_buffer, data); 718
646 ab_bus = le32_to_cpu(ab->descriptor.data_address) - offset; 719next_buffer_is_active:
647 dma_free_coherent(ctx->ohci->card.device, PAGE_SIZE, 720 i = next_i;
648 ab, ab_bus); 721 res_count = next_res_count;
722 }
723
724 rmb(); /* read res_count before the DMA data */
725
726 *buffer_offset = PAGE_SIZE - le16_to_cpu(res_count);
727 if (*buffer_offset > PAGE_SIZE) {
728 *buffer_offset = 0;
729 ar_context_abort(ctx, "corrupted descriptor");
730 }
731
732 return i;
733}
734
735static void ar_sync_buffers_for_cpu(struct ar_context *ctx,
736 unsigned int end_buffer_index,
737 unsigned int end_buffer_offset)
738{
739 unsigned int i;
740
741 i = ar_first_buffer_index(ctx);
742 while (i != end_buffer_index) {
743 dma_sync_single_for_cpu(ctx->ohci->card.device,
744 ar_buffer_bus(ctx, i),
745 PAGE_SIZE, DMA_FROM_DEVICE);
746 i = ar_next_buffer_index(i);
649 } 747 }
748 if (end_buffer_offset > 0)
749 dma_sync_single_for_cpu(ctx->ohci->card.device,
750 ar_buffer_bus(ctx, i),
751 end_buffer_offset, DMA_FROM_DEVICE);
650} 752}
651 753
652#if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) 754#if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32)
@@ -689,6 +791,10 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
689 p.header[3] = cond_le32_to_cpu(buffer[3]); 791 p.header[3] = cond_le32_to_cpu(buffer[3]);
690 p.header_length = 16; 792 p.header_length = 16;
691 p.payload_length = p.header[3] >> 16; 793 p.payload_length = p.header[3] >> 16;
794 if (p.payload_length > MAX_ASYNC_PAYLOAD) {
795 ar_context_abort(ctx, "invalid packet length");
796 return NULL;
797 }
692 break; 798 break;
693 799
694 case TCODE_WRITE_RESPONSE: 800 case TCODE_WRITE_RESPONSE:
@@ -699,9 +805,8 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
699 break; 805 break;
700 806
701 default: 807 default:
702 /* FIXME: Stop context, discard everything, and restart? */ 808 ar_context_abort(ctx, "invalid tcode");
703 p.header_length = 0; 809 return NULL;
704 p.payload_length = 0;
705 } 810 }
706 811
707 p.payload = (void *) buffer + p.header_length; 812 p.payload = (void *) buffer + p.header_length;
@@ -751,121 +856,147 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
751 return buffer + length + 1; 856 return buffer + length + 1;
752} 857}
753 858
859static void *handle_ar_packets(struct ar_context *ctx, void *p, void *end)
860{
861 void *next;
862
863 while (p < end) {
864 next = handle_ar_packet(ctx, p);
865 if (!next)
866 return p;
867 p = next;
868 }
869
870 return p;
871}
872
873static void ar_recycle_buffers(struct ar_context *ctx, unsigned int end_buffer)
874{
875 unsigned int i;
876
877 i = ar_first_buffer_index(ctx);
878 while (i != end_buffer) {
879 dma_sync_single_for_device(ctx->ohci->card.device,
880 ar_buffer_bus(ctx, i),
881 PAGE_SIZE, DMA_FROM_DEVICE);
882 ar_context_link_page(ctx, i);
883 i = ar_next_buffer_index(i);
884 }
885}
886
754static void ar_context_tasklet(unsigned long data) 887static void ar_context_tasklet(unsigned long data)
755{ 888{
756 struct ar_context *ctx = (struct ar_context *)data; 889 struct ar_context *ctx = (struct ar_context *)data;
757 struct ar_buffer *ab; 890 unsigned int end_buffer_index, end_buffer_offset;
758 struct descriptor *d; 891 void *p, *end;
759 void *buffer, *end;
760 __le16 res_count;
761 892
762 ab = ctx->current_buffer; 893 p = ctx->pointer;
763 d = &ab->descriptor; 894 if (!p)
895 return;
764 896
765 res_count = ACCESS_ONCE(d->res_count); 897 end_buffer_index = ar_search_last_active_buffer(ctx,
766 if (res_count == 0) { 898 &end_buffer_offset);
767 size_t size, size2, rest, pktsize, size3, offset; 899 ar_sync_buffers_for_cpu(ctx, end_buffer_index, end_buffer_offset);
768 dma_addr_t start_bus; 900 end = ctx->buffer + end_buffer_index * PAGE_SIZE + end_buffer_offset;
769 void *start;
770 901
902 if (end_buffer_index < ar_first_buffer_index(ctx)) {
771 /* 903 /*
772 * This descriptor is finished and we may have a 904 * The filled part of the overall buffer wraps around; handle
773 * packet split across this and the next buffer. We 905 * all packets up to the buffer end here. If the last packet
774 * reuse the page for reassembling the split packet. 906 * wraps around, its tail will be visible after the buffer end
907 * because the buffer start pages are mapped there again.
775 */ 908 */
909 void *buffer_end = ctx->buffer + AR_BUFFERS * PAGE_SIZE;
910 p = handle_ar_packets(ctx, p, buffer_end);
911 if (p < buffer_end)
912 goto error;
913 /* adjust p to point back into the actual buffer */
914 p -= AR_BUFFERS * PAGE_SIZE;
915 }
776 916
777 offset = offsetof(struct ar_buffer, data); 917 p = handle_ar_packets(ctx, p, end);
778 start = ab; 918 if (p != end) {
779 start_bus = le32_to_cpu(ab->descriptor.data_address) - offset; 919 if (p > end)
780 buffer = ab->data; 920 ar_context_abort(ctx, "inconsistent descriptor");
781 921 goto error;
782 ab = ab->next; 922 }
783 d = &ab->descriptor;
784 size = start + PAGE_SIZE - ctx->pointer;
785 /* valid buffer data in the next page */
786 rest = le16_to_cpu(d->req_count) - le16_to_cpu(d->res_count);
787 /* what actually fits in this page */
788 size2 = min(rest, (size_t)PAGE_SIZE - offset - size);
789 memmove(buffer, ctx->pointer, size);
790 memcpy(buffer + size, ab->data, size2);
791
792 while (size > 0) {
793 void *next = handle_ar_packet(ctx, buffer);
794 pktsize = next - buffer;
795 if (pktsize >= size) {
796 /*
797 * We have handled all the data that was
798 * originally in this page, so we can now
799 * continue in the next page.
800 */
801 buffer = next;
802 break;
803 }
804 /* move the next packet to the start of the buffer */
805 memmove(buffer, next, size + size2 - pktsize);
806 size -= pktsize;
807 /* fill up this page again */
808 size3 = min(rest - size2,
809 (size_t)PAGE_SIZE - offset - size - size2);
810 memcpy(buffer + size + size2,
811 (void *) ab->data + size2, size3);
812 size2 += size3;
813 }
814
815 if (rest > 0) {
816 /* handle the packets that are fully in the next page */
817 buffer = (void *) ab->data +
818 (buffer - (start + offset + size));
819 end = (void *) ab->data + rest;
820
821 while (buffer < end)
822 buffer = handle_ar_packet(ctx, buffer);
823 923
824 ctx->current_buffer = ab; 924 ctx->pointer = p;
825 ctx->pointer = end; 925 ar_recycle_buffers(ctx, end_buffer_index);
826 926
827 ar_context_link_page(ctx, start, start_bus); 927 return;
828 } else {
829 ctx->pointer = start + PAGE_SIZE;
830 }
831 } else {
832 buffer = ctx->pointer;
833 ctx->pointer = end =
834 (void *) ab + PAGE_SIZE - le16_to_cpu(res_count);
835 928
836 while (buffer < end) 929error:
837 buffer = handle_ar_packet(ctx, buffer); 930 ctx->pointer = NULL;
838 }
839} 931}
840 932
841static int ar_context_init(struct ar_context *ctx, 933static int ar_context_init(struct ar_context *ctx, struct fw_ohci *ohci,
842 struct fw_ohci *ohci, u32 regs) 934 unsigned int descriptors_offset, u32 regs)
843{ 935{
844 struct ar_buffer ab; 936 unsigned int i;
937 dma_addr_t dma_addr;
938 struct page *pages[AR_BUFFERS + AR_WRAPAROUND_PAGES];
939 struct descriptor *d;
845 940
846 ctx->regs = regs; 941 ctx->regs = regs;
847 ctx->ohci = ohci; 942 ctx->ohci = ohci;
848 ctx->last_buffer = &ab;
849 tasklet_init(&ctx->tasklet, ar_context_tasklet, (unsigned long)ctx); 943 tasklet_init(&ctx->tasklet, ar_context_tasklet, (unsigned long)ctx);
850 944
851 ar_context_add_page(ctx); 945 for (i = 0; i < AR_BUFFERS; i++) {
852 ar_context_add_page(ctx); 946 ctx->pages[i] = alloc_page(GFP_KERNEL | GFP_DMA32);
853 ctx->current_buffer = ab.next; 947 if (!ctx->pages[i])
854 ctx->pointer = ctx->current_buffer->data; 948 goto out_of_memory;
949 dma_addr = dma_map_page(ohci->card.device, ctx->pages[i],
950 0, PAGE_SIZE, DMA_FROM_DEVICE);
951 if (dma_mapping_error(ohci->card.device, dma_addr)) {
952 __free_page(ctx->pages[i]);
953 ctx->pages[i] = NULL;
954 goto out_of_memory;
955 }
956 set_page_private(ctx->pages[i], dma_addr);
957 }
958
959 for (i = 0; i < AR_BUFFERS; i++)
960 pages[i] = ctx->pages[i];
961 for (i = 0; i < AR_WRAPAROUND_PAGES; i++)
962 pages[AR_BUFFERS + i] = ctx->pages[i];
963 ctx->buffer = vm_map_ram(pages, AR_BUFFERS + AR_WRAPAROUND_PAGES,
964 -1, PAGE_KERNEL_RO);
965 if (!ctx->buffer)
966 goto out_of_memory;
967
968 ctx->descriptors = ohci->misc_buffer + descriptors_offset;
969 ctx->descriptors_bus = ohci->misc_buffer_bus + descriptors_offset;
970
971 for (i = 0; i < AR_BUFFERS; i++) {
972 d = &ctx->descriptors[i];
973 d->req_count = cpu_to_le16(PAGE_SIZE);
974 d->control = cpu_to_le16(DESCRIPTOR_INPUT_MORE |
975 DESCRIPTOR_STATUS |
976 DESCRIPTOR_BRANCH_ALWAYS);
977 d->data_address = cpu_to_le32(ar_buffer_bus(ctx, i));
978 d->branch_address = cpu_to_le32(ctx->descriptors_bus +
979 ar_next_buffer_index(i) * sizeof(struct descriptor));
980 }
855 981
856 return 0; 982 return 0;
983
984out_of_memory:
985 ar_context_release(ctx);
986
987 return -ENOMEM;
857} 988}
858 989
859static void ar_context_run(struct ar_context *ctx) 990static void ar_context_run(struct ar_context *ctx)
860{ 991{
861 struct ar_buffer *ab = ctx->current_buffer; 992 unsigned int i;
862 dma_addr_t ab_bus; 993
863 size_t offset; 994 for (i = 0; i < AR_BUFFERS; i++)
995 ar_context_link_page(ctx, i);
864 996
865 offset = offsetof(struct ar_buffer, data); 997 ctx->pointer = ctx->buffer;
866 ab_bus = le32_to_cpu(ab->descriptor.data_address) - offset;
867 998
868 reg_write(ctx->ohci, COMMAND_PTR(ctx->regs), ab_bus | 1); 999 reg_write(ctx->ohci, COMMAND_PTR(ctx->regs), ctx->descriptors_bus | 1);
869 reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_RUN); 1000 reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_RUN);
870 flush_writes(ctx->ohci); 1001 flush_writes(ctx->ohci);
871} 1002}
@@ -1042,6 +1173,7 @@ static void context_run(struct context *ctx, u32 extra)
1042 le32_to_cpu(ctx->last->branch_address)); 1173 le32_to_cpu(ctx->last->branch_address));
1043 reg_write(ohci, CONTROL_CLEAR(ctx->regs), ~0); 1174 reg_write(ohci, CONTROL_CLEAR(ctx->regs), ~0);
1044 reg_write(ohci, CONTROL_SET(ctx->regs), CONTEXT_RUN | extra); 1175 reg_write(ohci, CONTROL_SET(ctx->regs), CONTEXT_RUN | extra);
1176 ctx->running = true;
1045 flush_writes(ohci); 1177 flush_writes(ohci);
1046} 1178}
1047 1179
@@ -1069,6 +1201,7 @@ static void context_stop(struct context *ctx)
1069 int i; 1201 int i;
1070 1202
1071 reg_write(ctx->ohci, CONTROL_CLEAR(ctx->regs), CONTEXT_RUN); 1203 reg_write(ctx->ohci, CONTROL_CLEAR(ctx->regs), CONTEXT_RUN);
1204 ctx->running = false;
1072 flush_writes(ctx->ohci); 1205 flush_writes(ctx->ohci);
1073 1206
1074 for (i = 0; i < 10; i++) { 1207 for (i = 0; i < 10; i++) {
@@ -1099,7 +1232,6 @@ static int at_context_queue_packet(struct context *ctx,
1099 struct descriptor *d, *last; 1232 struct descriptor *d, *last;
1100 __le32 *header; 1233 __le32 *header;
1101 int z, tcode; 1234 int z, tcode;
1102 u32 reg;
1103 1235
1104 d = context_get_descriptors(ctx, 4, &d_bus); 1236 d = context_get_descriptors(ctx, 4, &d_bus);
1105 if (d == NULL) { 1237 if (d == NULL) {
@@ -1113,21 +1245,27 @@ static int at_context_queue_packet(struct context *ctx,
1113 /* 1245 /*
1114 * The DMA format for asyncronous link packets is different 1246 * The DMA format for asyncronous link packets is different
1115 * from the IEEE1394 layout, so shift the fields around 1247 * from the IEEE1394 layout, so shift the fields around
1116 * accordingly. If header_length is 8, it's a PHY packet, to 1248 * accordingly.
1117 * which we need to prepend an extra quadlet.
1118 */ 1249 */
1119 1250
1251 tcode = (packet->header[0] >> 4) & 0x0f;
1120 header = (__le32 *) &d[1]; 1252 header = (__le32 *) &d[1];
1121 switch (packet->header_length) { 1253 switch (tcode) {
1122 case 16: 1254 case TCODE_WRITE_QUADLET_REQUEST:
1123 case 12: 1255 case TCODE_WRITE_BLOCK_REQUEST:
1256 case TCODE_WRITE_RESPONSE:
1257 case TCODE_READ_QUADLET_REQUEST:
1258 case TCODE_READ_BLOCK_REQUEST:
1259 case TCODE_READ_QUADLET_RESPONSE:
1260 case TCODE_READ_BLOCK_RESPONSE:
1261 case TCODE_LOCK_REQUEST:
1262 case TCODE_LOCK_RESPONSE:
1124 header[0] = cpu_to_le32((packet->header[0] & 0xffff) | 1263 header[0] = cpu_to_le32((packet->header[0] & 0xffff) |
1125 (packet->speed << 16)); 1264 (packet->speed << 16));
1126 header[1] = cpu_to_le32((packet->header[1] & 0xffff) | 1265 header[1] = cpu_to_le32((packet->header[1] & 0xffff) |
1127 (packet->header[0] & 0xffff0000)); 1266 (packet->header[0] & 0xffff0000));
1128 header[2] = cpu_to_le32(packet->header[2]); 1267 header[2] = cpu_to_le32(packet->header[2]);
1129 1268
1130 tcode = (packet->header[0] >> 4) & 0x0f;
1131 if (TCODE_IS_BLOCK_PACKET(tcode)) 1269 if (TCODE_IS_BLOCK_PACKET(tcode))
1132 header[3] = cpu_to_le32(packet->header[3]); 1270 header[3] = cpu_to_le32(packet->header[3]);
1133 else 1271 else
@@ -1136,18 +1274,18 @@ static int at_context_queue_packet(struct context *ctx,
1136 d[0].req_count = cpu_to_le16(packet->header_length); 1274 d[0].req_count = cpu_to_le16(packet->header_length);
1137 break; 1275 break;
1138 1276
1139 case 8: 1277 case TCODE_LINK_INTERNAL:
1140 header[0] = cpu_to_le32((OHCI1394_phy_tcode << 4) | 1278 header[0] = cpu_to_le32((OHCI1394_phy_tcode << 4) |
1141 (packet->speed << 16)); 1279 (packet->speed << 16));
1142 header[1] = cpu_to_le32(packet->header[0]); 1280 header[1] = cpu_to_le32(packet->header[1]);
1143 header[2] = cpu_to_le32(packet->header[1]); 1281 header[2] = cpu_to_le32(packet->header[2]);
1144 d[0].req_count = cpu_to_le16(12); 1282 d[0].req_count = cpu_to_le16(12);
1145 1283
1146 if (is_ping_packet(packet->header)) 1284 if (is_ping_packet(&packet->header[1]))
1147 d[0].control |= cpu_to_le16(DESCRIPTOR_PING); 1285 d[0].control |= cpu_to_le16(DESCRIPTOR_PING);
1148 break; 1286 break;
1149 1287
1150 case 4: 1288 case TCODE_STREAM_DATA:
1151 header[0] = cpu_to_le32((packet->header[0] & 0xffff) | 1289 header[0] = cpu_to_le32((packet->header[0] & 0xffff) |
1152 (packet->speed << 16)); 1290 (packet->speed << 16));
1153 header[1] = cpu_to_le32(packet->header[0] & 0xffff0000); 1291 header[1] = cpu_to_le32(packet->header[0] & 0xffff0000);
@@ -1197,6 +1335,8 @@ static int at_context_queue_packet(struct context *ctx,
1197 * some controllers (like a JMicron JMB381 PCI-e) misbehave and wind 1335 * some controllers (like a JMicron JMB381 PCI-e) misbehave and wind
1198 * up stalling out. So we just bail out in software and try again 1336 * up stalling out. So we just bail out in software and try again
1199 * later, and everyone is happy. 1337 * later, and everyone is happy.
1338 * FIXME: Test of IntEvent.busReset may no longer be necessary since we
1339 * flush AT queues in bus_reset_tasklet.
1200 * FIXME: Document how the locking works. 1340 * FIXME: Document how the locking works.
1201 */ 1341 */
1202 if (ohci->generation != packet->generation || 1342 if (ohci->generation != packet->generation ||
@@ -1210,14 +1350,23 @@ static int at_context_queue_packet(struct context *ctx,
1210 1350
1211 context_append(ctx, d, z, 4 - z); 1351 context_append(ctx, d, z, 4 - z);
1212 1352
1213 /* If the context isn't already running, start it up. */ 1353 if (!ctx->running)
1214 reg = reg_read(ctx->ohci, CONTROL_SET(ctx->regs));
1215 if ((reg & CONTEXT_RUN) == 0)
1216 context_run(ctx, 0); 1354 context_run(ctx, 0);
1217 1355
1218 return 0; 1356 return 0;
1219} 1357}
1220 1358
1359static void at_context_flush(struct context *ctx)
1360{
1361 tasklet_disable(&ctx->tasklet);
1362
1363 ctx->flushing = true;
1364 context_tasklet((unsigned long)ctx);
1365 ctx->flushing = false;
1366
1367 tasklet_enable(&ctx->tasklet);
1368}
1369
1221static int handle_at_packet(struct context *context, 1370static int handle_at_packet(struct context *context,
1222 struct descriptor *d, 1371 struct descriptor *d,
1223 struct descriptor *last) 1372 struct descriptor *last)
@@ -1227,7 +1376,7 @@ static int handle_at_packet(struct context *context,
1227 struct fw_ohci *ohci = context->ohci; 1376 struct fw_ohci *ohci = context->ohci;
1228 int evt; 1377 int evt;
1229 1378
1230 if (last->transfer_status == 0) 1379 if (last->transfer_status == 0 && !context->flushing)
1231 /* This descriptor isn't done yet, stop iteration. */ 1380 /* This descriptor isn't done yet, stop iteration. */
1232 return 0; 1381 return 0;
1233 1382
@@ -1261,11 +1410,15 @@ static int handle_at_packet(struct context *context,
1261 break; 1410 break;
1262 1411
1263 case OHCI1394_evt_missing_ack: 1412 case OHCI1394_evt_missing_ack:
1264 /* 1413 if (context->flushing)
1265 * Using a valid (current) generation count, but the 1414 packet->ack = RCODE_GENERATION;
1266 * node is not on the bus or not sending acks. 1415 else {
1267 */ 1416 /*
1268 packet->ack = RCODE_NO_ACK; 1417 * Using a valid (current) generation count, but the
1418 * node is not on the bus or not sending acks.
1419 */
1420 packet->ack = RCODE_NO_ACK;
1421 }
1269 break; 1422 break;
1270 1423
1271 case ACK_COMPLETE + 0x10: 1424 case ACK_COMPLETE + 0x10:
@@ -1278,6 +1431,13 @@ static int handle_at_packet(struct context *context,
1278 packet->ack = evt - 0x10; 1431 packet->ack = evt - 0x10;
1279 break; 1432 break;
1280 1433
1434 case OHCI1394_evt_no_status:
1435 if (context->flushing) {
1436 packet->ack = RCODE_GENERATION;
1437 break;
1438 }
1439 /* fall through */
1440
1281 default: 1441 default:
1282 packet->ack = RCODE_SEND_ERROR; 1442 packet->ack = RCODE_SEND_ERROR;
1283 break; 1443 break;
@@ -1583,9 +1743,23 @@ static void bus_reset_tasklet(unsigned long data)
1583 /* FIXME: Document how the locking works. */ 1743 /* FIXME: Document how the locking works. */
1584 spin_lock_irqsave(&ohci->lock, flags); 1744 spin_lock_irqsave(&ohci->lock, flags);
1585 1745
1586 ohci->generation = generation; 1746 ohci->generation = -1; /* prevent AT packet queueing */
1587 context_stop(&ohci->at_request_ctx); 1747 context_stop(&ohci->at_request_ctx);
1588 context_stop(&ohci->at_response_ctx); 1748 context_stop(&ohci->at_response_ctx);
1749
1750 spin_unlock_irqrestore(&ohci->lock, flags);
1751
1752 /*
1753 * Per OHCI 1.2 draft, clause 7.2.3.3, hardware may leave unsent
1754 * packets in the AT queues and software needs to drain them.
1755 * Some OHCI 1.1 controllers (JMicron) apparently require this too.
1756 */
1757 at_context_flush(&ohci->at_request_ctx);
1758 at_context_flush(&ohci->at_response_ctx);
1759
1760 spin_lock_irqsave(&ohci->lock, flags);
1761
1762 ohci->generation = generation;
1589 reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset); 1763 reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset);
1590 1764
1591 if (ohci->quirks & QUIRK_RESET_PACKET) 1765 if (ohci->quirks & QUIRK_RESET_PACKET)
@@ -1653,8 +1827,12 @@ static irqreturn_t irq_handler(int irq, void *data)
1653 if (!event || !~event) 1827 if (!event || !~event)
1654 return IRQ_NONE; 1828 return IRQ_NONE;
1655 1829
1656 /* busReset must not be cleared yet, see OHCI 1.1 clause 7.2.3.2 */ 1830 /*
1657 reg_write(ohci, OHCI1394_IntEventClear, event & ~OHCI1394_busReset); 1831 * busReset and postedWriteErr must not be cleared yet
1832 * (OHCI 1.1 clauses 7.2.3.2 and 13.2.8.1)
1833 */
1834 reg_write(ohci, OHCI1394_IntEventClear,
1835 event & ~(OHCI1394_busReset | OHCI1394_postedWriteErr));
1658 log_irqs(event); 1836 log_irqs(event);
1659 1837
1660 if (event & OHCI1394_selfIDComplete) 1838 if (event & OHCI1394_selfIDComplete)
@@ -1672,30 +1850,41 @@ static irqreturn_t irq_handler(int irq, void *data)
1672 if (event & OHCI1394_respTxComplete) 1850 if (event & OHCI1394_respTxComplete)
1673 tasklet_schedule(&ohci->at_response_ctx.tasklet); 1851 tasklet_schedule(&ohci->at_response_ctx.tasklet);
1674 1852
1675 iso_event = reg_read(ohci, OHCI1394_IsoRecvIntEventClear); 1853 if (event & OHCI1394_isochRx) {
1676 reg_write(ohci, OHCI1394_IsoRecvIntEventClear, iso_event); 1854 iso_event = reg_read(ohci, OHCI1394_IsoRecvIntEventClear);
1855 reg_write(ohci, OHCI1394_IsoRecvIntEventClear, iso_event);
1677 1856
1678 while (iso_event) { 1857 while (iso_event) {
1679 i = ffs(iso_event) - 1; 1858 i = ffs(iso_event) - 1;
1680 tasklet_schedule(&ohci->ir_context_list[i].context.tasklet); 1859 tasklet_schedule(
1681 iso_event &= ~(1 << i); 1860 &ohci->ir_context_list[i].context.tasklet);
1861 iso_event &= ~(1 << i);
1862 }
1682 } 1863 }
1683 1864
1684 iso_event = reg_read(ohci, OHCI1394_IsoXmitIntEventClear); 1865 if (event & OHCI1394_isochTx) {
1685 reg_write(ohci, OHCI1394_IsoXmitIntEventClear, iso_event); 1866 iso_event = reg_read(ohci, OHCI1394_IsoXmitIntEventClear);
1867 reg_write(ohci, OHCI1394_IsoXmitIntEventClear, iso_event);
1686 1868
1687 while (iso_event) { 1869 while (iso_event) {
1688 i = ffs(iso_event) - 1; 1870 i = ffs(iso_event) - 1;
1689 tasklet_schedule(&ohci->it_context_list[i].context.tasklet); 1871 tasklet_schedule(
1690 iso_event &= ~(1 << i); 1872 &ohci->it_context_list[i].context.tasklet);
1873 iso_event &= ~(1 << i);
1874 }
1691 } 1875 }
1692 1876
1693 if (unlikely(event & OHCI1394_regAccessFail)) 1877 if (unlikely(event & OHCI1394_regAccessFail))
1694 fw_error("Register access failure - " 1878 fw_error("Register access failure - "
1695 "please notify linux1394-devel@lists.sf.net\n"); 1879 "please notify linux1394-devel@lists.sf.net\n");
1696 1880
1697 if (unlikely(event & OHCI1394_postedWriteErr)) 1881 if (unlikely(event & OHCI1394_postedWriteErr)) {
1882 reg_read(ohci, OHCI1394_PostedWriteAddressHi);
1883 reg_read(ohci, OHCI1394_PostedWriteAddressLo);
1884 reg_write(ohci, OHCI1394_IntEventClear,
1885 OHCI1394_postedWriteErr);
1698 fw_error("PCI posted write error\n"); 1886 fw_error("PCI posted write error\n");
1887 }
1699 1888
1700 if (unlikely(event & OHCI1394_cycleTooLong)) { 1889 if (unlikely(event & OHCI1394_cycleTooLong)) {
1701 if (printk_ratelimit()) 1890 if (printk_ratelimit())
@@ -1719,7 +1908,8 @@ static irqreturn_t irq_handler(int irq, void *data)
1719 spin_lock(&ohci->lock); 1908 spin_lock(&ohci->lock);
1720 update_bus_time(ohci); 1909 update_bus_time(ohci);
1721 spin_unlock(&ohci->lock); 1910 spin_unlock(&ohci->lock);
1722 } 1911 } else
1912 flush_writes(ohci);
1723 1913
1724 return IRQ_HANDLED; 1914 return IRQ_HANDLED;
1725} 1915}
@@ -2495,6 +2685,10 @@ static int ohci_start_iso(struct fw_iso_context *base,
2495 reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, 1 << index); 2685 reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, 1 << index);
2496 reg_write(ohci, CONTEXT_MATCH(ctx->context.regs), match); 2686 reg_write(ohci, CONTEXT_MATCH(ctx->context.regs), match);
2497 context_run(&ctx->context, control); 2687 context_run(&ctx->context, control);
2688
2689 ctx->sync = sync;
2690 ctx->tags = tags;
2691
2498 break; 2692 break;
2499 } 2693 }
2500 2694
@@ -2592,6 +2786,26 @@ static int ohci_set_iso_channels(struct fw_iso_context *base, u64 *channels)
2592 return ret; 2786 return ret;
2593} 2787}
2594 2788
2789#ifdef CONFIG_PM
2790static void ohci_resume_iso_dma(struct fw_ohci *ohci)
2791{
2792 int i;
2793 struct iso_context *ctx;
2794
2795 for (i = 0 ; i < ohci->n_ir ; i++) {
2796 ctx = &ohci->ir_context_list[i];
2797 if (ctx->context.running)
2798 ohci_start_iso(&ctx->base, 0, ctx->sync, ctx->tags);
2799 }
2800
2801 for (i = 0 ; i < ohci->n_it ; i++) {
2802 ctx = &ohci->it_context_list[i];
2803 if (ctx->context.running)
2804 ohci_start_iso(&ctx->base, 0, ctx->sync, ctx->tags);
2805 }
2806}
2807#endif
2808
2595static int queue_iso_transmit(struct iso_context *ctx, 2809static int queue_iso_transmit(struct iso_context *ctx,
2596 struct fw_iso_packet *packet, 2810 struct fw_iso_packet *packet,
2597 struct fw_iso_buffer *buffer, 2811 struct fw_iso_buffer *buffer,
@@ -2901,7 +3115,7 @@ static int __devinit pci_probe(struct pci_dev *dev,
2901 struct fw_ohci *ohci; 3115 struct fw_ohci *ohci;
2902 u32 bus_options, max_receive, link_speed, version; 3116 u32 bus_options, max_receive, link_speed, version;
2903 u64 guid; 3117 u64 guid;
2904 int i, err, n_ir, n_it; 3118 int i, err;
2905 size_t size; 3119 size_t size;
2906 3120
2907 ohci = kzalloc(sizeof(*ohci), GFP_KERNEL); 3121 ohci = kzalloc(sizeof(*ohci), GFP_KERNEL);
@@ -2955,31 +3169,55 @@ static int __devinit pci_probe(struct pci_dev *dev,
2955 if (param_quirks) 3169 if (param_quirks)
2956 ohci->quirks = param_quirks; 3170 ohci->quirks = param_quirks;
2957 3171
2958 ar_context_init(&ohci->ar_request_ctx, ohci, 3172 /*
2959 OHCI1394_AsReqRcvContextControlSet); 3173 * Because dma_alloc_coherent() allocates at least one page,
3174 * we save space by using a common buffer for the AR request/
3175 * response descriptors and the self IDs buffer.
3176 */
3177 BUILD_BUG_ON(AR_BUFFERS * sizeof(struct descriptor) > PAGE_SIZE/4);
3178 BUILD_BUG_ON(SELF_ID_BUF_SIZE > PAGE_SIZE/2);
3179 ohci->misc_buffer = dma_alloc_coherent(ohci->card.device,
3180 PAGE_SIZE,
3181 &ohci->misc_buffer_bus,
3182 GFP_KERNEL);
3183 if (!ohci->misc_buffer) {
3184 err = -ENOMEM;
3185 goto fail_iounmap;
3186 }
3187
3188 err = ar_context_init(&ohci->ar_request_ctx, ohci, 0,
3189 OHCI1394_AsReqRcvContextControlSet);
3190 if (err < 0)
3191 goto fail_misc_buf;
2960 3192
2961 ar_context_init(&ohci->ar_response_ctx, ohci, 3193 err = ar_context_init(&ohci->ar_response_ctx, ohci, PAGE_SIZE/4,
2962 OHCI1394_AsRspRcvContextControlSet); 3194 OHCI1394_AsRspRcvContextControlSet);
3195 if (err < 0)
3196 goto fail_arreq_ctx;
2963 3197
2964 context_init(&ohci->at_request_ctx, ohci, 3198 err = context_init(&ohci->at_request_ctx, ohci,
2965 OHCI1394_AsReqTrContextControlSet, handle_at_packet); 3199 OHCI1394_AsReqTrContextControlSet, handle_at_packet);
3200 if (err < 0)
3201 goto fail_arrsp_ctx;
2966 3202
2967 context_init(&ohci->at_response_ctx, ohci, 3203 err = context_init(&ohci->at_response_ctx, ohci,
2968 OHCI1394_AsRspTrContextControlSet, handle_at_packet); 3204 OHCI1394_AsRspTrContextControlSet, handle_at_packet);
3205 if (err < 0)
3206 goto fail_atreq_ctx;
2969 3207
2970 reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, ~0); 3208 reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, ~0);
2971 ohci->ir_context_channels = ~0ULL; 3209 ohci->ir_context_channels = ~0ULL;
2972 ohci->ir_context_mask = reg_read(ohci, OHCI1394_IsoRecvIntMaskSet); 3210 ohci->ir_context_mask = reg_read(ohci, OHCI1394_IsoRecvIntMaskSet);
2973 reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, ~0); 3211 reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, ~0);
2974 n_ir = hweight32(ohci->ir_context_mask); 3212 ohci->n_ir = hweight32(ohci->ir_context_mask);
2975 size = sizeof(struct iso_context) * n_ir; 3213 size = sizeof(struct iso_context) * ohci->n_ir;
2976 ohci->ir_context_list = kzalloc(size, GFP_KERNEL); 3214 ohci->ir_context_list = kzalloc(size, GFP_KERNEL);
2977 3215
2978 reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0); 3216 reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0);
2979 ohci->it_context_mask = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet); 3217 ohci->it_context_mask = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet);
2980 reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0); 3218 reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0);
2981 n_it = hweight32(ohci->it_context_mask); 3219 ohci->n_it = hweight32(ohci->it_context_mask);
2982 size = sizeof(struct iso_context) * n_it; 3220 size = sizeof(struct iso_context) * ohci->n_it;
2983 ohci->it_context_list = kzalloc(size, GFP_KERNEL); 3221 ohci->it_context_list = kzalloc(size, GFP_KERNEL);
2984 3222
2985 if (ohci->it_context_list == NULL || ohci->ir_context_list == NULL) { 3223 if (ohci->it_context_list == NULL || ohci->ir_context_list == NULL) {
@@ -2987,15 +3225,8 @@ static int __devinit pci_probe(struct pci_dev *dev,
2987 goto fail_contexts; 3225 goto fail_contexts;
2988 } 3226 }
2989 3227
2990 /* self-id dma buffer allocation */ 3228 ohci->self_id_cpu = ohci->misc_buffer + PAGE_SIZE/2;
2991 ohci->self_id_cpu = dma_alloc_coherent(ohci->card.device, 3229 ohci->self_id_bus = ohci->misc_buffer_bus + PAGE_SIZE/2;
2992 SELF_ID_BUF_SIZE,
2993 &ohci->self_id_bus,
2994 GFP_KERNEL);
2995 if (ohci->self_id_cpu == NULL) {
2996 err = -ENOMEM;
2997 goto fail_contexts;
2998 }
2999 3230
3000 bus_options = reg_read(ohci, OHCI1394_BusOptions); 3231 bus_options = reg_read(ohci, OHCI1394_BusOptions);
3001 max_receive = (bus_options >> 12) & 0xf; 3232 max_receive = (bus_options >> 12) & 0xf;
@@ -3005,26 +3236,30 @@ static int __devinit pci_probe(struct pci_dev *dev,
3005 3236
3006 err = fw_card_add(&ohci->card, max_receive, link_speed, guid); 3237 err = fw_card_add(&ohci->card, max_receive, link_speed, guid);
3007 if (err) 3238 if (err)
3008 goto fail_self_id; 3239 goto fail_contexts;
3009 3240
3010 version = reg_read(ohci, OHCI1394_Version) & 0x00ff00ff; 3241 version = reg_read(ohci, OHCI1394_Version) & 0x00ff00ff;
3011 fw_notify("Added fw-ohci device %s, OHCI v%x.%x, " 3242 fw_notify("Added fw-ohci device %s, OHCI v%x.%x, "
3012 "%d IR + %d IT contexts, quirks 0x%x\n", 3243 "%d IR + %d IT contexts, quirks 0x%x\n",
3013 dev_name(&dev->dev), version >> 16, version & 0xff, 3244 dev_name(&dev->dev), version >> 16, version & 0xff,
3014 n_ir, n_it, ohci->quirks); 3245 ohci->n_ir, ohci->n_it, ohci->quirks);
3015 3246
3016 return 0; 3247 return 0;
3017 3248
3018 fail_self_id:
3019 dma_free_coherent(ohci->card.device, SELF_ID_BUF_SIZE,
3020 ohci->self_id_cpu, ohci->self_id_bus);
3021 fail_contexts: 3249 fail_contexts:
3022 kfree(ohci->ir_context_list); 3250 kfree(ohci->ir_context_list);
3023 kfree(ohci->it_context_list); 3251 kfree(ohci->it_context_list);
3024 context_release(&ohci->at_response_ctx); 3252 context_release(&ohci->at_response_ctx);
3253 fail_atreq_ctx:
3025 context_release(&ohci->at_request_ctx); 3254 context_release(&ohci->at_request_ctx);
3255 fail_arrsp_ctx:
3026 ar_context_release(&ohci->ar_response_ctx); 3256 ar_context_release(&ohci->ar_response_ctx);
3257 fail_arreq_ctx:
3027 ar_context_release(&ohci->ar_request_ctx); 3258 ar_context_release(&ohci->ar_request_ctx);
3259 fail_misc_buf:
3260 dma_free_coherent(ohci->card.device, PAGE_SIZE,
3261 ohci->misc_buffer, ohci->misc_buffer_bus);
3262 fail_iounmap:
3028 pci_iounmap(dev, ohci->registers); 3263 pci_iounmap(dev, ohci->registers);
3029 fail_iomem: 3264 fail_iomem:
3030 pci_release_region(dev, 0); 3265 pci_release_region(dev, 0);
@@ -3063,10 +3298,10 @@ static void pci_remove(struct pci_dev *dev)
3063 if (ohci->config_rom) 3298 if (ohci->config_rom)
3064 dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, 3299 dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE,
3065 ohci->config_rom, ohci->config_rom_bus); 3300 ohci->config_rom, ohci->config_rom_bus);
3066 dma_free_coherent(ohci->card.device, SELF_ID_BUF_SIZE,
3067 ohci->self_id_cpu, ohci->self_id_bus);
3068 ar_context_release(&ohci->ar_request_ctx); 3301 ar_context_release(&ohci->ar_request_ctx);
3069 ar_context_release(&ohci->ar_response_ctx); 3302 ar_context_release(&ohci->ar_response_ctx);
3303 dma_free_coherent(ohci->card.device, PAGE_SIZE,
3304 ohci->misc_buffer, ohci->misc_buffer_bus);
3070 context_release(&ohci->at_request_ctx); 3305 context_release(&ohci->at_request_ctx);
3071 context_release(&ohci->at_response_ctx); 3306 context_release(&ohci->at_response_ctx);
3072 kfree(ohci->it_context_list); 3307 kfree(ohci->it_context_list);
@@ -3117,7 +3352,20 @@ static int pci_resume(struct pci_dev *dev)
3117 return err; 3352 return err;
3118 } 3353 }
3119 3354
3120 return ohci_enable(&ohci->card, NULL, 0); 3355 /* Some systems don't setup GUID register on resume from ram */
3356 if (!reg_read(ohci, OHCI1394_GUIDLo) &&
3357 !reg_read(ohci, OHCI1394_GUIDHi)) {
3358 reg_write(ohci, OHCI1394_GUIDLo, (u32)ohci->card.guid);
3359 reg_write(ohci, OHCI1394_GUIDHi, (u32)(ohci->card.guid >> 32));
3360 }
3361
3362 err = ohci_enable(&ohci->card, NULL, 0);
3363 if (err)
3364 return err;
3365
3366 ohci_resume_iso_dma(ohci);
3367
3368 return 0;
3121} 3369}
3122#endif 3370#endif
3123 3371
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 401acecc7f32..ffbc278647bf 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -150,6 +150,16 @@ config DRAGONRISE_FF
150 Say Y here if you want to enable force feedback support for DragonRise Inc. 150 Say Y here if you want to enable force feedback support for DragonRise Inc.
151 game controllers. 151 game controllers.
152 152
153config HID_EMS_FF
154 tristate "EMS Production Inc. force feedback support"
155 depends on USB_HID
156 select INPUT_FF_MEMLESS
157 ---help---
158 Say Y here if you want to enable force feedback support for devices by
159 EMS Production Ltd.
160 Currently the following devices are known to be supported:
161 - Trio Linker Plus II
162
153config HID_EGALAX 163config HID_EGALAX
154 tristate "eGalax multi-touch panel" 164 tristate "eGalax multi-touch panel"
155 depends on USB_HID 165 depends on USB_HID
@@ -397,6 +407,13 @@ config HID_ROCCAT_KONE
397 ---help--- 407 ---help---
398 Support for Roccat Kone mouse. 408 Support for Roccat Kone mouse.
399 409
410config HID_ROCCAT_KONEPLUS
411 tristate "Roccat Kone[+] mouse support"
412 depends on USB_HID
413 select HID_ROCCAT
414 ---help---
415 Support for Roccat Kone[+] mouse.
416
400config HID_ROCCAT_PYRA 417config HID_ROCCAT_PYRA
401 tristate "Roccat Pyra mouse support" 418 tristate "Roccat Pyra mouse support"
402 depends on USB_HID 419 depends on USB_HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index c335605b9200..6eae9a90b8dd 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -1,7 +1,7 @@
1# 1#
2# Makefile for the HID driver 2# Makefile for the HID driver
3# 3#
4hid-objs := hid-core.o hid-input.o 4hid-y := hid-core.o hid-input.o
5 5
6ifdef CONFIG_DEBUG_FS 6ifdef CONFIG_DEBUG_FS
7 hid-objs += hid-debug.o 7 hid-objs += hid-debug.o
@@ -11,18 +11,18 @@ obj-$(CONFIG_HID) += hid.o
11 11
12hid-$(CONFIG_HIDRAW) += hidraw.o 12hid-$(CONFIG_HIDRAW) += hidraw.o
13 13
14hid-logitech-objs := hid-lg.o 14hid-logitech-y := hid-lg.o
15ifdef CONFIG_LOGITECH_FF 15ifdef CONFIG_LOGITECH_FF
16 hid-logitech-objs += hid-lgff.o 16 hid-logitech-y += hid-lgff.o
17endif 17endif
18ifdef CONFIG_LOGIRUMBLEPAD2_FF 18ifdef CONFIG_LOGIRUMBLEPAD2_FF
19 hid-logitech-objs += hid-lg2ff.o 19 hid-logitech-y += hid-lg2ff.o
20endif 20endif
21ifdef CONFIG_LOGIG940_FF 21ifdef CONFIG_LOGIG940_FF
22 hid-logitech-objs += hid-lg3ff.o 22 hid-logitech-y += hid-lg3ff.o
23endif 23endif
24ifdef CONFIG_LOGIWII_FF 24ifdef CONFIG_LOGIWII_FF
25 hid-logitech-objs += hid-lg4ff.o 25 hid-logitech-y += hid-lg4ff.o
26endif 26endif
27 27
28obj-$(CONFIG_HID_3M_PCT) += hid-3m-pct.o 28obj-$(CONFIG_HID_3M_PCT) += hid-3m-pct.o
@@ -35,6 +35,7 @@ obj-$(CONFIG_HID_CHERRY) += hid-cherry.o
35obj-$(CONFIG_HID_CHICONY) += hid-chicony.o 35obj-$(CONFIG_HID_CHICONY) += hid-chicony.o
36obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o 36obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o
37obj-$(CONFIG_HID_DRAGONRISE) += hid-drff.o 37obj-$(CONFIG_HID_DRAGONRISE) += hid-drff.o
38obj-$(CONFIG_HID_EMS_FF) += hid-emsff.o
38obj-$(CONFIG_HID_EGALAX) += hid-egalax.o 39obj-$(CONFIG_HID_EGALAX) += hid-egalax.o
39obj-$(CONFIG_HID_ELECOM) += hid-elecom.o 40obj-$(CONFIG_HID_ELECOM) += hid-elecom.o
40obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o 41obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o
@@ -55,6 +56,7 @@ obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o
55obj-$(CONFIG_HID_PICOLCD) += hid-picolcd.o 56obj-$(CONFIG_HID_PICOLCD) += hid-picolcd.o
56obj-$(CONFIG_HID_ROCCAT) += hid-roccat.o 57obj-$(CONFIG_HID_ROCCAT) += hid-roccat.o
57obj-$(CONFIG_HID_ROCCAT_KONE) += hid-roccat-kone.o 58obj-$(CONFIG_HID_ROCCAT_KONE) += hid-roccat-kone.o
59obj-$(CONFIG_HID_ROCCAT_KONEPLUS) += hid-roccat-koneplus.o
58obj-$(CONFIG_HID_ROCCAT_PYRA) += hid-roccat-pyra.o 60obj-$(CONFIG_HID_ROCCAT_PYRA) += hid-roccat-pyra.o
59obj-$(CONFIG_HID_SAMSUNG) += hid-samsung.o 61obj-$(CONFIG_HID_SAMSUNG) += hid-samsung.o
60obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o 62obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o
diff --git a/drivers/hid/hid-3m-pct.c b/drivers/hid/hid-3m-pct.c
index 4fb7c7528d16..5243ae2d3730 100644
--- a/drivers/hid/hid-3m-pct.c
+++ b/drivers/hid/hid-3m-pct.c
@@ -246,7 +246,7 @@ static int mmm_probe(struct hid_device *hdev, const struct hid_device_id *id)
246 246
247 md = kzalloc(sizeof(struct mmm_data), GFP_KERNEL); 247 md = kzalloc(sizeof(struct mmm_data), GFP_KERNEL);
248 if (!md) { 248 if (!md) {
249 dev_err(&hdev->dev, "cannot allocate 3M data\n"); 249 hid_err(hdev, "cannot allocate 3M data\n");
250 return -ENOMEM; 250 return -ENOMEM;
251 } 251 }
252 hid_set_drvdata(hdev, md); 252 hid_set_drvdata(hdev, md);
diff --git a/drivers/hid/hid-a4tech.c b/drivers/hid/hid-a4tech.c
index 1666c1684e79..902d1dfeb1b5 100644
--- a/drivers/hid/hid-a4tech.c
+++ b/drivers/hid/hid-a4tech.c
@@ -93,7 +93,7 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
93 93
94 a4 = kzalloc(sizeof(*a4), GFP_KERNEL); 94 a4 = kzalloc(sizeof(*a4), GFP_KERNEL);
95 if (a4 == NULL) { 95 if (a4 == NULL) {
96 dev_err(&hdev->dev, "can't alloc device descriptor\n"); 96 hid_err(hdev, "can't alloc device descriptor\n");
97 ret = -ENOMEM; 97 ret = -ENOMEM;
98 goto err_free; 98 goto err_free;
99 } 99 }
@@ -104,13 +104,13 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
104 104
105 ret = hid_parse(hdev); 105 ret = hid_parse(hdev);
106 if (ret) { 106 if (ret) {
107 dev_err(&hdev->dev, "parse failed\n"); 107 hid_err(hdev, "parse failed\n");
108 goto err_free; 108 goto err_free;
109 } 109 }
110 110
111 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 111 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
112 if (ret) { 112 if (ret) {
113 dev_err(&hdev->dev, "hw start failed\n"); 113 hid_err(hdev, "hw start failed\n");
114 goto err_free; 114 goto err_free;
115 } 115 }
116 116
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index eaeca564a8d3..61aa71233392 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -16,6 +16,8 @@
16 * any later version. 16 * any later version.
17 */ 17 */
18 18
19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
19#include <linux/device.h> 21#include <linux/device.h>
20#include <linux/hid.h> 22#include <linux/hid.h>
21#include <linux/module.h> 23#include <linux/module.h>
@@ -59,6 +61,27 @@ struct apple_key_translation {
59 u8 flags; 61 u8 flags;
60}; 62};
61 63
64static const struct apple_key_translation macbookair_fn_keys[] = {
65 { KEY_BACKSPACE, KEY_DELETE },
66 { KEY_ENTER, KEY_INSERT },
67 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
68 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
69 { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY },
70 { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY },
71 { KEY_F6, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
72 { KEY_F7, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
73 { KEY_F8, KEY_NEXTSONG, APPLE_FLAG_FKEY },
74 { KEY_F9, KEY_MUTE, APPLE_FLAG_FKEY },
75 { KEY_F10, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
76 { KEY_F11, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
77 { KEY_F12, KEY_EJECTCD, APPLE_FLAG_FKEY },
78 { KEY_UP, KEY_PAGEUP },
79 { KEY_DOWN, KEY_PAGEDOWN },
80 { KEY_LEFT, KEY_HOME },
81 { KEY_RIGHT, KEY_END },
82 { }
83};
84
62static const struct apple_key_translation apple_fn_keys[] = { 85static const struct apple_key_translation apple_fn_keys[] = {
63 { KEY_BACKSPACE, KEY_DELETE }, 86 { KEY_BACKSPACE, KEY_DELETE },
64 { KEY_ENTER, KEY_INSERT }, 87 { KEY_ENTER, KEY_INSERT },
@@ -146,7 +169,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
146 struct hid_usage *usage, __s32 value) 169 struct hid_usage *usage, __s32 value)
147{ 170{
148 struct apple_sc *asc = hid_get_drvdata(hid); 171 struct apple_sc *asc = hid_get_drvdata(hid);
149 const struct apple_key_translation *trans; 172 const struct apple_key_translation *trans, *table;
150 173
151 if (usage->code == KEY_FN) { 174 if (usage->code == KEY_FN) {
152 asc->fn_on = !!value; 175 asc->fn_on = !!value;
@@ -157,10 +180,16 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
157 if (fnmode) { 180 if (fnmode) {
158 int do_translate; 181 int do_translate;
159 182
160 trans = apple_find_translation((hid->product < 0x21d || 183 if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
161 hid->product >= 0x300) ? 184 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
162 powerbook_fn_keys : apple_fn_keys, 185 table = macbookair_fn_keys;
163 usage->code); 186 else if (hid->product < 0x21d || hid->product >= 0x300)
187 table = powerbook_fn_keys;
188 else
189 table = apple_fn_keys;
190
191 trans = apple_find_translation (table, usage->code);
192
164 if (trans) { 193 if (trans) {
165 if (test_bit(usage->code, asc->pressed_fn)) 194 if (test_bit(usage->code, asc->pressed_fn))
166 do_translate = 1; 195 do_translate = 1;
@@ -253,8 +282,8 @@ static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
253 282
254 if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 && 283 if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 &&
255 rdesc[53] == 0x65 && rdesc[59] == 0x65) { 284 rdesc[53] == 0x65 && rdesc[59] == 0x65) {
256 dev_info(&hdev->dev, "fixing up MacBook JIS keyboard report " 285 hid_info(hdev,
257 "descriptor\n"); 286 "fixing up MacBook JIS keyboard report descriptor\n");
258 rdesc[53] = rdesc[59] = 0xe7; 287 rdesc[53] = rdesc[59] = 0xe7;
259 } 288 }
260 return rdesc; 289 return rdesc;
@@ -324,7 +353,7 @@ static int apple_probe(struct hid_device *hdev,
324 353
325 asc = kzalloc(sizeof(*asc), GFP_KERNEL); 354 asc = kzalloc(sizeof(*asc), GFP_KERNEL);
326 if (asc == NULL) { 355 if (asc == NULL) {
327 dev_err(&hdev->dev, "can't alloc apple descriptor\n"); 356 hid_err(hdev, "can't alloc apple descriptor\n");
328 return -ENOMEM; 357 return -ENOMEM;
329 } 358 }
330 359
@@ -334,7 +363,7 @@ static int apple_probe(struct hid_device *hdev,
334 363
335 ret = hid_parse(hdev); 364 ret = hid_parse(hdev);
336 if (ret) { 365 if (ret) {
337 dev_err(&hdev->dev, "parse failed\n"); 366 hid_err(hdev, "parse failed\n");
338 goto err_free; 367 goto err_free;
339 } 368 }
340 369
@@ -345,7 +374,7 @@ static int apple_probe(struct hid_device *hdev,
345 374
346 ret = hid_hw_start(hdev, connect_mask); 375 ret = hid_hw_start(hdev, connect_mask);
347 if (ret) { 376 if (ret) {
348 dev_err(&hdev->dev, "hw start failed\n"); 377 hid_err(hdev, "hw start failed\n");
349 goto err_free; 378 goto err_free;
350 } 379 }
351 380
@@ -440,6 +469,18 @@ static const struct hid_device_id apple_devices[] = {
440 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, 469 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
441 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS), 470 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
442 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, 471 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
472 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI),
473 .driver_data = APPLE_HAS_FN },
474 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO),
475 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
476 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS),
477 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
478 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI),
479 .driver_data = APPLE_HAS_FN },
480 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO),
481 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
482 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
483 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
443 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI), 484 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
444 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, 485 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
445 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO), 486 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
@@ -473,7 +514,7 @@ static int __init apple_init(void)
473 514
474 ret = hid_register_driver(&apple_driver); 515 ret = hid_register_driver(&apple_driver);
475 if (ret) 516 if (ret)
476 printk(KERN_ERR "can't register apple driver\n"); 517 pr_err("can't register apple driver\n");
477 518
478 return ret; 519 return ret;
479} 520}
diff --git a/drivers/hid/hid-axff.c b/drivers/hid/hid-axff.c
index f42ee140738a..e5b961d6ff22 100644
--- a/drivers/hid/hid-axff.c
+++ b/drivers/hid/hid-axff.c
@@ -73,14 +73,14 @@ static int axff_init(struct hid_device *hid)
73 int error; 73 int error;
74 74
75 if (list_empty(report_list)) { 75 if (list_empty(report_list)) {
76 dev_err(&hid->dev, "no output reports found\n"); 76 hid_err(hid, "no output reports found\n");
77 return -ENODEV; 77 return -ENODEV;
78 } 78 }
79 79
80 report = list_first_entry(report_list, struct hid_report, list); 80 report = list_first_entry(report_list, struct hid_report, list);
81 81
82 if (report->maxfield < 4) { 82 if (report->maxfield < 4) {
83 dev_err(&hid->dev, "no fields in the report: %d\n", report->maxfield); 83 hid_err(hid, "no fields in the report: %d\n", report->maxfield);
84 return -ENODEV; 84 return -ENODEV;
85 } 85 }
86 86
@@ -101,7 +101,7 @@ static int axff_init(struct hid_device *hid)
101 axff->report->field[3]->value[0] = 0x00; 101 axff->report->field[3]->value[0] = 0x00;
102 usbhid_submit_report(hid, axff->report, USB_DIR_OUT); 102 usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
103 103
104 dev_info(&hid->dev, "Force Feedback for ACRUX game controllers by Sergei Kolzun<x0r@dv-life.ru>\n"); 104 hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun<x0r@dv-life.ru>\n");
105 105
106 return 0; 106 return 0;
107 107
@@ -114,17 +114,17 @@ static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
114{ 114{
115 int error; 115 int error;
116 116
117 dev_dbg(&hdev->dev, "ACRUX HID hardware probe..."); 117 dev_dbg(&hdev->dev, "ACRUX HID hardware probe...\n");
118 118
119 error = hid_parse(hdev); 119 error = hid_parse(hdev);
120 if (error) { 120 if (error) {
121 dev_err(&hdev->dev, "parse failed\n"); 121 hid_err(hdev, "parse failed\n");
122 return error; 122 return error;
123 } 123 }
124 124
125 error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); 125 error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
126 if (error) { 126 if (error) {
127 dev_err(&hdev->dev, "hw start failed\n"); 127 hid_err(hdev, "hw start failed\n");
128 return error; 128 return error;
129 } 129 }
130 130
@@ -134,7 +134,7 @@ static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
134 * Do not fail device initialization completely as device 134 * Do not fail device initialization completely as device
135 * may still be partially operable, just warn. 135 * may still be partially operable, just warn.
136 */ 136 */
137 dev_warn(&hdev->dev, 137 hid_warn(hdev,
138 "Failed to enable force feedback support, error: %d\n", 138 "Failed to enable force feedback support, error: %d\n",
139 error); 139 error);
140 } 140 }
diff --git a/drivers/hid/hid-belkin.c b/drivers/hid/hid-belkin.c
index 4ce7aa3a519f..a1a765a5b08a 100644
--- a/drivers/hid/hid-belkin.c
+++ b/drivers/hid/hid-belkin.c
@@ -56,14 +56,14 @@ static int belkin_probe(struct hid_device *hdev, const struct hid_device_id *id)
56 56
57 ret = hid_parse(hdev); 57 ret = hid_parse(hdev);
58 if (ret) { 58 if (ret) {
59 dev_err(&hdev->dev, "parse failed\n"); 59 hid_err(hdev, "parse failed\n");
60 goto err_free; 60 goto err_free;
61 } 61 }
62 62
63 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | 63 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT |
64 ((quirks & BELKIN_HIDDEV) ? HID_CONNECT_HIDDEV_FORCE : 0)); 64 ((quirks & BELKIN_HIDDEV) ? HID_CONNECT_HIDDEV_FORCE : 0));
65 if (ret) { 65 if (ret) {
66 dev_err(&hdev->dev, "hw start failed\n"); 66 hid_err(hdev, "hw start failed\n");
67 goto err_free; 67 goto err_free;
68 } 68 }
69 69
diff --git a/drivers/hid/hid-cando.c b/drivers/hid/hid-cando.c
index 5925bdcd417d..375b50929a50 100644
--- a/drivers/hid/hid-cando.c
+++ b/drivers/hid/hid-cando.c
@@ -207,7 +207,7 @@ static int cando_probe(struct hid_device *hdev, const struct hid_device_id *id)
207 207
208 td = kmalloc(sizeof(struct cando_data), GFP_KERNEL); 208 td = kmalloc(sizeof(struct cando_data), GFP_KERNEL);
209 if (!td) { 209 if (!td) {
210 dev_err(&hdev->dev, "cannot allocate Cando Touch data\n"); 210 hid_err(hdev, "cannot allocate Cando Touch data\n");
211 return -ENOMEM; 211 return -ENOMEM;
212 } 212 }
213 hid_set_drvdata(hdev, td); 213 hid_set_drvdata(hdev, td);
diff --git a/drivers/hid/hid-cherry.c b/drivers/hid/hid-cherry.c
index e880086c2311..888ece68a47c 100644
--- a/drivers/hid/hid-cherry.c
+++ b/drivers/hid/hid-cherry.c
@@ -30,8 +30,7 @@ static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
30 unsigned int *rsize) 30 unsigned int *rsize)
31{ 31{
32 if (*rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) { 32 if (*rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
33 dev_info(&hdev->dev, "fixing up Cherry Cymotion report " 33 hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
34 "descriptor\n");
35 rdesc[11] = rdesc[16] = 0xff; 34 rdesc[11] = rdesc[16] = 0xff;
36 rdesc[12] = rdesc[17] = 0x03; 35 rdesc[12] = rdesc[17] = 0x03;
37 } 36 }
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 3f9673d94da9..261168607c91 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -14,6 +14,8 @@
14 * any later version. 14 * any later version.
15 */ 15 */
16 16
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
17#include <linux/module.h> 19#include <linux/module.h>
18#include <linux/slab.h> 20#include <linux/slab.h>
19#include <linux/init.h> 21#include <linux/init.h>
@@ -59,7 +61,8 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type,
59 if (report_enum->report_id_hash[id]) 61 if (report_enum->report_id_hash[id])
60 return report_enum->report_id_hash[id]; 62 return report_enum->report_id_hash[id];
61 63
62 if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL))) 64 report = kzalloc(sizeof(struct hid_report), GFP_KERNEL);
65 if (!report)
63 return NULL; 66 return NULL;
64 67
65 if (id != 0) 68 if (id != 0)
@@ -90,8 +93,11 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
90 return NULL; 93 return NULL;
91 } 94 }
92 95
93 if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage) 96 field = kzalloc((sizeof(struct hid_field) +
94 + values * sizeof(unsigned), GFP_KERNEL))) return NULL; 97 usages * sizeof(struct hid_usage) +
98 values * sizeof(unsigned)), GFP_KERNEL);
99 if (!field)
100 return NULL;
95 101
96 field->index = report->maxfield++; 102 field->index = report->maxfield++;
97 report->field[field->index] = field; 103 report->field[field->index] = field;
@@ -172,10 +178,14 @@ static int close_collection(struct hid_parser *parser)
172 178
173static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type) 179static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
174{ 180{
181 struct hid_collection *collection = parser->device->collection;
175 int n; 182 int n;
176 for (n = parser->collection_stack_ptr - 1; n >= 0; n--) 183
177 if (parser->device->collection[parser->collection_stack[n]].type == type) 184 for (n = parser->collection_stack_ptr - 1; n >= 0; n--) {
178 return parser->device->collection[parser->collection_stack[n]].usage; 185 unsigned index = parser->collection_stack[n];
186 if (collection[index].type == type)
187 return collection[index].usage;
188 }
179 return 0; /* we know nothing about this usage type */ 189 return 0; /* we know nothing about this usage type */
180} 190}
181 191
@@ -209,7 +219,8 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
209 unsigned offset; 219 unsigned offset;
210 int i; 220 int i;
211 221
212 if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) { 222 report = hid_register_report(parser->device, report_type, parser->global.report_id);
223 if (!report) {
213 dbg_hid("hid_register_report failed\n"); 224 dbg_hid("hid_register_report failed\n");
214 return -1; 225 return -1;
215 } 226 }
@@ -227,7 +238,8 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
227 238
228 usages = max_t(int, parser->local.usage_index, parser->global.report_count); 239 usages = max_t(int, parser->local.usage_index, parser->global.report_count);
229 240
230 if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL) 241 field = hid_register_field(report, usages, parser->global.report_count);
242 if (!field)
231 return 0; 243 return 0;
232 244
233 field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL); 245 field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
@@ -652,13 +664,12 @@ int hid_parse_report(struct hid_device *device, __u8 *start,
652 return -ENOMEM; 664 return -ENOMEM;
653 device->rsize = size; 665 device->rsize = size;
654 666
655 parser = vmalloc(sizeof(struct hid_parser)); 667 parser = vzalloc(sizeof(struct hid_parser));
656 if (!parser) { 668 if (!parser) {
657 ret = -ENOMEM; 669 ret = -ENOMEM;
658 goto err; 670 goto err;
659 } 671 }
660 672
661 memset(parser, 0, sizeof(struct hid_parser));
662 parser->device = device; 673 parser->device = device;
663 674
664 end = start + size; 675 end = start + size;
@@ -672,7 +683,8 @@ int hid_parse_report(struct hid_device *device, __u8 *start,
672 683
673 if (dispatch_type[item.type](parser, &item)) { 684 if (dispatch_type[item.type](parser, &item)) {
674 dbg_hid("item %u %u %u %u parsing failed\n", 685 dbg_hid("item %u %u %u %u parsing failed\n",
675 item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag); 686 item.format, (unsigned)item.size,
687 (unsigned)item.type, (unsigned)item.tag);
676 goto err; 688 goto err;
677 } 689 }
678 690
@@ -737,13 +749,14 @@ static u32 s32ton(__s32 value, unsigned n)
737 * Search linux-kernel and linux-usb-devel archives for "hid-core extract". 749 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
738 */ 750 */
739 751
740static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n) 752static __u32 extract(const struct hid_device *hid, __u8 *report,
753 unsigned offset, unsigned n)
741{ 754{
742 u64 x; 755 u64 x;
743 756
744 if (n > 32) 757 if (n > 32)
745 printk(KERN_WARNING "HID: extract() called with n (%d) > 32! (%s)\n", 758 hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
746 n, current->comm); 759 n, current->comm);
747 760
748 report += offset >> 3; /* adjust byte index */ 761 report += offset >> 3; /* adjust byte index */
749 offset &= 7; /* now only need bit offset into one byte */ 762 offset &= 7; /* now only need bit offset into one byte */
@@ -760,18 +773,19 @@ static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
760 * endianness of register values by considering a register 773 * endianness of register values by considering a register
761 * a "cached" copy of the little endiad bit stream. 774 * a "cached" copy of the little endiad bit stream.
762 */ 775 */
763static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value) 776static void implement(const struct hid_device *hid, __u8 *report,
777 unsigned offset, unsigned n, __u32 value)
764{ 778{
765 u64 x; 779 u64 x;
766 u64 m = (1ULL << n) - 1; 780 u64 m = (1ULL << n) - 1;
767 781
768 if (n > 32) 782 if (n > 32)
769 printk(KERN_WARNING "HID: implement() called with n (%d) > 32! (%s)\n", 783 hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
770 n, current->comm); 784 __func__, n, current->comm);
771 785
772 if (value > m) 786 if (value > m)
773 printk(KERN_WARNING "HID: implement() called with too large value %d! (%s)\n", 787 hid_warn(hid, "%s() called with too large value %d! (%s)\n",
774 value, current->comm); 788 __func__, value, current->comm);
775 WARN_ON(value > m); 789 WARN_ON(value > m);
776 value &= m; 790 value &= m;
777 791
@@ -788,7 +802,7 @@ static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u3
788 * Search an array for a value. 802 * Search an array for a value.
789 */ 803 */
790 804
791static __inline__ int search(__s32 *array, __s32 value, unsigned n) 805static int search(__s32 *array, __s32 value, unsigned n)
792{ 806{
793 while (n--) { 807 while (n--) {
794 if (*array++ == value) 808 if (*array++ == value)
@@ -887,18 +901,22 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
887 __s32 max = field->logical_maximum; 901 __s32 max = field->logical_maximum;
888 __s32 *value; 902 __s32 *value;
889 903
890 if (!(value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC))) 904 value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
905 if (!value)
891 return; 906 return;
892 907
893 for (n = 0; n < count; n++) { 908 for (n = 0; n < count; n++) {
894 909
895 value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) : 910 value[n] = min < 0 ?
896 extract(data, offset + n * size, size); 911 snto32(extract(hid, data, offset + n * size, size),
912 size) :
913 extract(hid, data, offset + n * size, size);
897 914
898 if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */ 915 /* Ignore report if ErrorRollOver */
899 && value[n] >= min && value[n] <= max 916 if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
900 && field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1) 917 value[n] >= min && value[n] <= max &&
901 goto exit; 918 field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
919 goto exit;
902 } 920 }
903 921
904 for (n = 0; n < count; n++) { 922 for (n = 0; n < count; n++) {
@@ -928,7 +946,8 @@ exit:
928 * Output the field into the report. 946 * Output the field into the report.
929 */ 947 */
930 948
931static void hid_output_field(struct hid_field *field, __u8 *data) 949static void hid_output_field(const struct hid_device *hid,
950 struct hid_field *field, __u8 *data)
932{ 951{
933 unsigned count = field->report_count; 952 unsigned count = field->report_count;
934 unsigned offset = field->report_offset; 953 unsigned offset = field->report_offset;
@@ -937,9 +956,11 @@ static void hid_output_field(struct hid_field *field, __u8 *data)
937 956
938 for (n = 0; n < count; n++) { 957 for (n = 0; n < count; n++) {
939 if (field->logical_minimum < 0) /* signed values */ 958 if (field->logical_minimum < 0) /* signed values */
940 implement(data, offset + n * size, size, s32ton(field->value[n], size)); 959 implement(hid, data, offset + n * size, size,
960 s32ton(field->value[n], size));
941 else /* unsigned values */ 961 else /* unsigned values */
942 implement(data, offset + n * size, size, field->value[n]); 962 implement(hid, data, offset + n * size, size,
963 field->value[n]);
943 } 964 }
944} 965}
945 966
@@ -956,7 +977,7 @@ void hid_output_report(struct hid_report *report, __u8 *data)
956 977
957 memset(data, 0, ((report->size - 1) >> 3) + 1); 978 memset(data, 0, ((report->size - 1) >> 3) + 1);
958 for (n = 0; n < report->maxfield; n++) 979 for (n = 0; n < report->maxfield; n++)
959 hid_output_field(report->field[n], data); 980 hid_output_field(report->device, report->field[n], data);
960} 981}
961EXPORT_SYMBOL_GPL(hid_output_report); 982EXPORT_SYMBOL_GPL(hid_output_report);
962 983
@@ -1169,8 +1190,7 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1169 hdev->claimed |= HID_CLAIMED_HIDRAW; 1190 hdev->claimed |= HID_CLAIMED_HIDRAW;
1170 1191
1171 if (!hdev->claimed) { 1192 if (!hdev->claimed) {
1172 dev_err(&hdev->dev, "claimed by neither input, hiddev nor " 1193 hid_err(hdev, "claimed by neither input, hiddev nor hidraw\n");
1173 "hidraw\n");
1174 return -ENODEV; 1194 return -ENODEV;
1175 } 1195 }
1176 1196
@@ -1210,9 +1230,9 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1210 bus = "<UNKNOWN>"; 1230 bus = "<UNKNOWN>";
1211 } 1231 }
1212 1232
1213 dev_info(&hdev->dev, "%s: %s HID v%x.%02x %s [%s] on %s\n", 1233 hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1214 buf, bus, hdev->version >> 8, hdev->version & 0xff, 1234 buf, bus, hdev->version >> 8, hdev->version & 0xff,
1215 type, hdev->name, hdev->phys); 1235 type, hdev->name, hdev->phys);
1216 1236
1217 return 0; 1237 return 0;
1218} 1238}
@@ -1230,7 +1250,7 @@ void hid_disconnect(struct hid_device *hdev)
1230EXPORT_SYMBOL_GPL(hid_disconnect); 1250EXPORT_SYMBOL_GPL(hid_disconnect);
1231 1251
1232/* a list of devices for which there is a specialized driver on HID bus */ 1252/* a list of devices for which there is a specialized driver on HID bus */
1233static const struct hid_device_id hid_blacklist[] = { 1253static const struct hid_device_id hid_have_special_driver[] = {
1234 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) }, 1254 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
1235 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) }, 1255 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) },
1236 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) }, 1256 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
@@ -1276,6 +1296,12 @@ static const struct hid_device_id hid_blacklist[] = {
1276 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, 1296 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1277 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, 1297 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1278 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, 1298 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
1299 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
1300 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
1301 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
1302 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1303 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
1304 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
1279 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) }, 1305 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
1280 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) }, 1306 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
1281 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, 1307 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
@@ -1292,6 +1318,7 @@ static const struct hid_device_id hid_blacklist[] = {
1292 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) }, 1318 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
1293 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) }, 1319 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
1294 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, 1320 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
1321 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
1295 { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) }, 1322 { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
1296 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, 1323 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
1297 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, 1324 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
@@ -1304,6 +1331,7 @@ static const struct hid_device_id hid_blacklist[] = {
1304 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH3) }, 1331 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH3) },
1305 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH4) }, 1332 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH4) },
1306 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) }, 1333 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
1334 { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
1307 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) }, 1335 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
1308 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) }, 1336 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1309 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) }, 1337 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
@@ -1372,6 +1400,7 @@ static const struct hid_device_id hid_blacklist[] = {
1372 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) }, 1400 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1373 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) }, 1401 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
1374 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) }, 1402 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
1403 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
1375 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) }, 1404 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
1376 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, 1405 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1377 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) }, 1406 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
@@ -1499,9 +1528,9 @@ static int hid_bus_match(struct device *dev, struct device_driver *drv)
1499 if (!hid_match_device(hdev, hdrv)) 1528 if (!hid_match_device(hdev, hdrv))
1500 return 0; 1529 return 0;
1501 1530
1502 /* generic wants all non-blacklisted */ 1531 /* generic wants all that don't have specialized driver */
1503 if (!strncmp(hdrv->name, "generic-", 8)) 1532 if (!strncmp(hdrv->name, "generic-", 8))
1504 return !hid_match_id(hdev, hid_blacklist); 1533 return !hid_match_id(hdev, hid_have_special_driver);
1505 1534
1506 return 1; 1535 return 1;
1507} 1536}
@@ -1761,6 +1790,12 @@ static const struct hid_device_id hid_mouse_ignore_list[] = {
1761 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, 1790 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1762 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, 1791 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1763 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, 1792 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
1793 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
1794 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
1795 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
1796 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1797 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
1798 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
1764 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 1799 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1765 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1800 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1766 { } 1801 { }
@@ -1952,12 +1987,12 @@ static int __init hid_init(void)
1952 int ret; 1987 int ret;
1953 1988
1954 if (hid_debug) 1989 if (hid_debug)
1955 printk(KERN_WARNING "HID: hid_debug is now used solely for parser and driver debugging.\n" 1990 pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
1956 "HID: debugfs is now used for inspecting the device (report descriptor, reports)\n"); 1991 "debugfs is now used for inspecting the device (report descriptor, reports)\n");
1957 1992
1958 ret = bus_register(&hid_bus_type); 1993 ret = bus_register(&hid_bus_type);
1959 if (ret) { 1994 if (ret) {
1960 printk(KERN_ERR "HID: can't register hid bus\n"); 1995 pr_err("can't register hid bus\n");
1961 goto err; 1996 goto err;
1962 } 1997 }
1963 1998
diff --git a/drivers/hid/hid-cypress.c b/drivers/hid/hid-cypress.c
index 4cd0e2345991..2f0be4c66af7 100644
--- a/drivers/hid/hid-cypress.c
+++ b/drivers/hid/hid-cypress.c
@@ -107,13 +107,13 @@ static int cp_probe(struct hid_device *hdev, const struct hid_device_id *id)
107 107
108 ret = hid_parse(hdev); 108 ret = hid_parse(hdev);
109 if (ret) { 109 if (ret) {
110 dev_err(&hdev->dev, "parse failed\n"); 110 hid_err(hdev, "parse failed\n");
111 goto err_free; 111 goto err_free;
112 } 112 }
113 113
114 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 114 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
115 if (ret) { 115 if (ret) {
116 dev_err(&hdev->dev, "hw start failed\n"); 116 hid_err(hdev, "hw start failed\n");
117 goto err_free; 117 goto err_free;
118 } 118 }
119 119
diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index 75c5e23d09d2..555382fc7417 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -26,6 +26,8 @@
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
27 */ 27 */
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/debugfs.h> 31#include <linux/debugfs.h>
30#include <linux/seq_file.h> 32#include <linux/seq_file.h>
31#include <linux/sched.h> 33#include <linux/sched.h>
@@ -393,7 +395,7 @@ char *hid_resolv_usage(unsigned usage, struct seq_file *f) {
393 395
394 buf = resolv_usage_page(usage >> 16, f); 396 buf = resolv_usage_page(usage >> 16, f);
395 if (IS_ERR(buf)) { 397 if (IS_ERR(buf)) {
396 printk(KERN_ERR "error allocating HID debug buffer\n"); 398 pr_err("error allocating HID debug buffer\n");
397 return NULL; 399 return NULL;
398 } 400 }
399 401
diff --git a/drivers/hid/hid-drff.c b/drivers/hid/hid-drff.c
index 968b04f9b796..afcf3d67eb02 100644
--- a/drivers/hid/hid-drff.c
+++ b/drivers/hid/hid-drff.c
@@ -96,18 +96,18 @@ static int drff_init(struct hid_device *hid)
96 int error; 96 int error;
97 97
98 if (list_empty(report_list)) { 98 if (list_empty(report_list)) {
99 dev_err(&hid->dev, "no output reports found\n"); 99 hid_err(hid, "no output reports found\n");
100 return -ENODEV; 100 return -ENODEV;
101 } 101 }
102 102
103 report = list_first_entry(report_list, struct hid_report, list); 103 report = list_first_entry(report_list, struct hid_report, list);
104 if (report->maxfield < 1) { 104 if (report->maxfield < 1) {
105 dev_err(&hid->dev, "no fields in the report\n"); 105 hid_err(hid, "no fields in the report\n");
106 return -ENODEV; 106 return -ENODEV;
107 } 107 }
108 108
109 if (report->field[0]->report_count < 7) { 109 if (report->field[0]->report_count < 7) {
110 dev_err(&hid->dev, "not enough values in the field\n"); 110 hid_err(hid, "not enough values in the field\n");
111 return -ENODEV; 111 return -ENODEV;
112 } 112 }
113 113
@@ -133,8 +133,8 @@ static int drff_init(struct hid_device *hid)
133 drff->report->field[0]->value[6] = 0x00; 133 drff->report->field[0]->value[6] = 0x00;
134 usbhid_submit_report(hid, drff->report, USB_DIR_OUT); 134 usbhid_submit_report(hid, drff->report, USB_DIR_OUT);
135 135
136 dev_info(&hid->dev, "Force Feedback for DragonRise Inc. game " 136 hid_info(hid, "Force Feedback for DragonRise Inc. "
137 "controllers by Richard Walmsley <richwalm@gmail.com>\n"); 137 "game controllers by Richard Walmsley <richwalm@gmail.com>\n");
138 138
139 return 0; 139 return 0;
140} 140}
@@ -153,13 +153,13 @@ static int dr_probe(struct hid_device *hdev, const struct hid_device_id *id)
153 153
154 ret = hid_parse(hdev); 154 ret = hid_parse(hdev);
155 if (ret) { 155 if (ret) {
156 dev_err(&hdev->dev, "parse failed\n"); 156 hid_err(hdev, "parse failed\n");
157 goto err; 157 goto err;
158 } 158 }
159 159
160 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); 160 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
161 if (ret) { 161 if (ret) {
162 dev_err(&hdev->dev, "hw start failed\n"); 162 hid_err(hdev, "hw start failed\n");
163 goto err; 163 goto err;
164 } 164 }
165 165
diff --git a/drivers/hid/hid-egalax.c b/drivers/hid/hid-egalax.c
index 8fbff2358eb6..03bee1970d70 100644
--- a/drivers/hid/hid-egalax.c
+++ b/drivers/hid/hid-egalax.c
@@ -200,7 +200,7 @@ static int egalax_probe(struct hid_device *hdev, const struct hid_device_id *id)
200 200
201 td = kzalloc(sizeof(struct egalax_data), GFP_KERNEL); 201 td = kzalloc(sizeof(struct egalax_data), GFP_KERNEL);
202 if (!td) { 202 if (!td) {
203 dev_err(&hdev->dev, "cannot allocate eGalax data\n"); 203 hid_err(hdev, "cannot allocate eGalax data\n");
204 return -ENOMEM; 204 return -ENOMEM;
205 } 205 }
206 hid_set_drvdata(hdev, td); 206 hid_set_drvdata(hdev, td);
diff --git a/drivers/hid/hid-elecom.c b/drivers/hid/hid-elecom.c
index 6e31f305397d..79d0c61e7214 100644
--- a/drivers/hid/hid-elecom.c
+++ b/drivers/hid/hid-elecom.c
@@ -24,8 +24,7 @@ static __u8 *elecom_report_fixup(struct hid_device *hdev, __u8 *rdesc,
24 unsigned int *rsize) 24 unsigned int *rsize)
25{ 25{
26 if (*rsize >= 48 && rdesc[46] == 0x05 && rdesc[47] == 0x0c) { 26 if (*rsize >= 48 && rdesc[46] == 0x05 && rdesc[47] == 0x0c) {
27 dev_info(&hdev->dev, "Fixing up Elecom BM084 " 27 hid_info(hdev, "Fixing up Elecom BM084 report descriptor\n");
28 "report descriptor.\n");
29 rdesc[47] = 0x00; 28 rdesc[47] = 0x00;
30 } 29 }
31 return rdesc; 30 return rdesc;
diff --git a/drivers/hid/hid-emsff.c b/drivers/hid/hid-emsff.c
new file mode 100644
index 000000000000..81877c67caea
--- /dev/null
+++ b/drivers/hid/hid-emsff.c
@@ -0,0 +1,161 @@
1/*
2 * Force feedback support for EMS Trio Linker Plus II
3 *
4 * Copyright (c) 2010 Ignaz Forster <ignaz.forster@gmx.de>
5 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23
24#include <linux/hid.h>
25#include <linux/input.h>
26#include <linux/usb.h>
27
28#include "hid-ids.h"
29#include "usbhid/usbhid.h"
30
31struct emsff_device {
32 struct hid_report *report;
33};
34
35static int emsff_play(struct input_dev *dev, void *data,
36 struct ff_effect *effect)
37{
38 struct hid_device *hid = input_get_drvdata(dev);
39 struct emsff_device *emsff = data;
40 int weak, strong;
41
42 weak = effect->u.rumble.weak_magnitude;
43 strong = effect->u.rumble.strong_magnitude;
44
45 dbg_hid("called with 0x%04x 0x%04x\n", strong, weak);
46
47 weak = weak * 0xff / 0xffff;
48 strong = strong * 0xff / 0xffff;
49
50 emsff->report->field[0]->value[1] = weak;
51 emsff->report->field[0]->value[2] = strong;
52
53 dbg_hid("running with 0x%02x 0x%02x\n", strong, weak);
54 usbhid_submit_report(hid, emsff->report, USB_DIR_OUT);
55
56 return 0;
57}
58
59static int emsff_init(struct hid_device *hid)
60{
61 struct emsff_device *emsff;
62 struct hid_report *report;
63 struct hid_input *hidinput = list_first_entry(&hid->inputs,
64 struct hid_input, list);
65 struct list_head *report_list =
66 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
67 struct input_dev *dev = hidinput->input;
68 int error;
69
70 if (list_empty(report_list)) {
71 hid_err(hid, "no output reports found\n");
72 return -ENODEV;
73 }
74
75 report = list_first_entry(report_list, struct hid_report, list);
76 if (report->maxfield < 1) {
77 hid_err(hid, "no fields in the report\n");
78 return -ENODEV;
79 }
80
81 if (report->field[0]->report_count < 7) {
82 hid_err(hid, "not enough values in the field\n");
83 return -ENODEV;
84 }
85
86 emsff = kzalloc(sizeof(struct emsff_device), GFP_KERNEL);
87 if (!emsff)
88 return -ENOMEM;
89
90 set_bit(FF_RUMBLE, dev->ffbit);
91
92 error = input_ff_create_memless(dev, emsff, emsff_play);
93 if (error) {
94 kfree(emsff);
95 return error;
96 }
97
98 emsff->report = report;
99 emsff->report->field[0]->value[0] = 0x01;
100 emsff->report->field[0]->value[1] = 0x00;
101 emsff->report->field[0]->value[2] = 0x00;
102 emsff->report->field[0]->value[3] = 0x00;
103 emsff->report->field[0]->value[4] = 0x00;
104 emsff->report->field[0]->value[5] = 0x00;
105 emsff->report->field[0]->value[6] = 0x00;
106 usbhid_submit_report(hid, emsff->report, USB_DIR_OUT);
107
108 hid_info(hid, "force feedback for EMS based devices by Ignaz Forster <ignaz.forster@gmx.de>\n");
109
110 return 0;
111}
112
113static int ems_probe(struct hid_device *hdev, const struct hid_device_id *id)
114{
115 int ret;
116
117 ret = hid_parse(hdev);
118 if (ret) {
119 hid_err(hdev, "parse failed\n");
120 goto err;
121 }
122
123 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
124 if (ret) {
125 hid_err(hdev, "hw start failed\n");
126 goto err;
127 }
128
129 emsff_init(hdev);
130
131 return 0;
132err:
133 return ret;
134}
135
136static const struct hid_device_id ems_devices[] = {
137 { HID_USB_DEVICE(USB_VENDOR_ID_EMS, 0x118) },
138 { }
139};
140MODULE_DEVICE_TABLE(hid, ems_devices);
141
142static struct hid_driver ems_driver = {
143 .name = "hkems",
144 .id_table = ems_devices,
145 .probe = ems_probe,
146};
147
148static int ems_init(void)
149{
150 return hid_register_driver(&ems_driver);
151}
152
153static void ems_exit(void)
154{
155 hid_unregister_driver(&ems_driver);
156}
157
158module_init(ems_init);
159module_exit(ems_exit);
160MODULE_LICENSE("GPL");
161
diff --git a/drivers/hid/hid-gaff.c b/drivers/hid/hid-gaff.c
index 88dfcf49a5d7..279ba530003c 100644
--- a/drivers/hid/hid-gaff.c
+++ b/drivers/hid/hid-gaff.c
@@ -87,7 +87,7 @@ static int gaff_init(struct hid_device *hid)
87 int error; 87 int error;
88 88
89 if (list_empty(report_list)) { 89 if (list_empty(report_list)) {
90 dev_err(&hid->dev, "no output reports found\n"); 90 hid_err(hid, "no output reports found\n");
91 return -ENODEV; 91 return -ENODEV;
92 } 92 }
93 93
@@ -95,12 +95,12 @@ static int gaff_init(struct hid_device *hid)
95 95
96 report = list_entry(report_ptr, struct hid_report, list); 96 report = list_entry(report_ptr, struct hid_report, list);
97 if (report->maxfield < 1) { 97 if (report->maxfield < 1) {
98 dev_err(&hid->dev, "no fields in the report\n"); 98 hid_err(hid, "no fields in the report\n");
99 return -ENODEV; 99 return -ENODEV;
100 } 100 }
101 101
102 if (report->field[0]->report_count < 6) { 102 if (report->field[0]->report_count < 6) {
103 dev_err(&hid->dev, "not enough values in the field\n"); 103 hid_err(hid, "not enough values in the field\n");
104 return -ENODEV; 104 return -ENODEV;
105 } 105 }
106 106
@@ -128,8 +128,7 @@ static int gaff_init(struct hid_device *hid)
128 128
129 usbhid_submit_report(hid, gaff->report, USB_DIR_OUT); 129 usbhid_submit_report(hid, gaff->report, USB_DIR_OUT);
130 130
131 dev_info(&hid->dev, "Force Feedback for GreenAsia 0x12" 131 hid_info(hid, "Force Feedback for GreenAsia 0x12 devices by Lukasz Lubojanski <lukasz@lubojanski.info>\n");
132 " devices by Lukasz Lubojanski <lukasz@lubojanski.info>\n");
133 132
134 return 0; 133 return 0;
135} 134}
@@ -148,13 +147,13 @@ static int ga_probe(struct hid_device *hdev, const struct hid_device_id *id)
148 147
149 ret = hid_parse(hdev); 148 ret = hid_parse(hdev);
150 if (ret) { 149 if (ret) {
151 dev_err(&hdev->dev, "parse failed\n"); 150 hid_err(hdev, "parse failed\n");
152 goto err; 151 goto err;
153 } 152 }
154 153
155 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); 154 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
156 if (ret) { 155 if (ret) {
157 dev_err(&hdev->dev, "hw start failed\n"); 156 hid_err(hdev, "hw start failed\n");
158 goto err; 157 goto err;
159 } 158 }
160 159
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 8e11af86b014..f65cace77729 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -97,6 +97,12 @@
97#define USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI 0x0236 97#define USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI 0x0236
98#define USB_DEVICE_ID_APPLE_WELLSPRING3_ISO 0x0237 98#define USB_DEVICE_ID_APPLE_WELLSPRING3_ISO 0x0237
99#define USB_DEVICE_ID_APPLE_WELLSPRING3_JIS 0x0238 99#define USB_DEVICE_ID_APPLE_WELLSPRING3_JIS 0x0238
100#define USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI 0x023f
101#define USB_DEVICE_ID_APPLE_WELLSPRING4_ISO 0x0240
102#define USB_DEVICE_ID_APPLE_WELLSPRING4_JIS 0x0241
103#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242
104#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243
105#define USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS 0x0244
100#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI 0x0239 106#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI 0x0239
101#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO 0x023a 107#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO 0x023a
102#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b 108#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b
@@ -156,6 +162,7 @@
156#define USB_VENDOR_ID_CHICONY 0x04f2 162#define USB_VENDOR_ID_CHICONY 0x04f2
157#define USB_DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418 163#define USB_DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418
158#define USB_DEVICE_ID_CHICONY_MULTI_TOUCH 0xb19d 164#define USB_DEVICE_ID_CHICONY_MULTI_TOUCH 0xb19d
165#define USB_DEVICE_ID_CHICONY_WIRELESS 0x0618
159 166
160#define USB_VENDOR_ID_CIDC 0x1677 167#define USB_VENDOR_ID_CIDC 0x1677
161 168
@@ -208,6 +215,9 @@
208#define USB_VENDOR_ID_ELO 0x04E7 215#define USB_VENDOR_ID_ELO 0x04E7
209#define USB_DEVICE_ID_ELO_TS2700 0x0020 216#define USB_DEVICE_ID_ELO_TS2700 0x0020
210 217
218#define USB_VENDOR_ID_EMS 0x2006
219#define USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II 0x0118
220
211#define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f 221#define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f
212#define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100 222#define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100
213 223
@@ -480,6 +490,7 @@
480 490
481#define USB_VENDOR_ID_ROCCAT 0x1e7d 491#define USB_VENDOR_ID_ROCCAT 0x1e7d
482#define USB_DEVICE_ID_ROCCAT_KONE 0x2ced 492#define USB_DEVICE_ID_ROCCAT_KONE 0x2ced
493#define USB_DEVICE_ID_ROCCAT_KONEPLUS 0x2d51
483#define USB_DEVICE_ID_ROCCAT_PYRA_WIRED 0x2c24 494#define USB_DEVICE_ID_ROCCAT_PYRA_WIRED 0x2c24
484#define USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS 0x2cf6 495#define USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS 0x2cf6
485 496
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index d8d372bae3cc..e60fdb88101f 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -319,21 +319,21 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
319 319
320 switch (field->application) { 320 switch (field->application) {
321 case HID_GD_MOUSE: 321 case HID_GD_MOUSE:
322 case HID_GD_POINTER: code += 0x110; break; 322 case HID_GD_POINTER: code += BTN_MOUSE; break;
323 case HID_GD_JOYSTICK: 323 case HID_GD_JOYSTICK:
324 if (code <= 0xf) 324 if (code <= 0xf)
325 code += BTN_JOYSTICK; 325 code += BTN_JOYSTICK;
326 else 326 else
327 code += BTN_TRIGGER_HAPPY; 327 code += BTN_TRIGGER_HAPPY;
328 break; 328 break;
329 case HID_GD_GAMEPAD: code += 0x130; break; 329 case HID_GD_GAMEPAD: code += BTN_GAMEPAD; break;
330 default: 330 default:
331 switch (field->physical) { 331 switch (field->physical) {
332 case HID_GD_MOUSE: 332 case HID_GD_MOUSE:
333 case HID_GD_POINTER: code += 0x110; break; 333 case HID_GD_POINTER: code += BTN_MOUSE; break;
334 case HID_GD_JOYSTICK: code += 0x120; break; 334 case HID_GD_JOYSTICK: code += BTN_JOYSTICK; break;
335 case HID_GD_GAMEPAD: code += 0x130; break; 335 case HID_GD_GAMEPAD: code += BTN_GAMEPAD; break;
336 default: code += 0x100; 336 default: code += BTN_MISC;
337 } 337 }
338 } 338 }
339 339
@@ -817,14 +817,14 @@ static int hidinput_open(struct input_dev *dev)
817{ 817{
818 struct hid_device *hid = input_get_drvdata(dev); 818 struct hid_device *hid = input_get_drvdata(dev);
819 819
820 return hid->ll_driver->open(hid); 820 return hid_hw_open(hid);
821} 821}
822 822
823static void hidinput_close(struct input_dev *dev) 823static void hidinput_close(struct input_dev *dev)
824{ 824{
825 struct hid_device *hid = input_get_drvdata(dev); 825 struct hid_device *hid = input_get_drvdata(dev);
826 826
827 hid->ll_driver->close(hid); 827 hid_hw_close(hid);
828} 828}
829 829
830/* 830/*
@@ -871,7 +871,7 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
871 if (!hidinput || !input_dev) { 871 if (!hidinput || !input_dev) {
872 kfree(hidinput); 872 kfree(hidinput);
873 input_free_device(input_dev); 873 input_free_device(input_dev);
874 err_hid("Out of memory during hid input probe"); 874 hid_err(hid, "Out of memory during hid input probe\n");
875 goto out_unwind; 875 goto out_unwind;
876 } 876 }
877 877
diff --git a/drivers/hid/hid-kye.c b/drivers/hid/hid-kye.c
index 817247ee006c..f2ba9efc3a53 100644
--- a/drivers/hid/hid-kye.c
+++ b/drivers/hid/hid-kye.c
@@ -32,8 +32,8 @@ static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
32 rdesc[65] == 0x29 && rdesc[66] == 0x0f && 32 rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
33 rdesc[71] == 0x75 && rdesc[72] == 0x08 && 33 rdesc[71] == 0x75 && rdesc[72] == 0x08 &&
34 rdesc[73] == 0x95 && rdesc[74] == 0x01) { 34 rdesc[73] == 0x95 && rdesc[74] == 0x01) {
35 dev_info(&hdev->dev, "fixing up Kye/Genius Ergo Mouse report " 35 hid_info(hdev,
36 "descriptor\n"); 36 "fixing up Kye/Genius Ergo Mouse report descriptor\n");
37 rdesc[62] = 0x09; 37 rdesc[62] = 0x09;
38 rdesc[64] = 0x04; 38 rdesc[64] = 0x04;
39 rdesc[66] = 0x07; 39 rdesc[66] = 0x07;
diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c
index b629fba5a057..aef4104da141 100644
--- a/drivers/hid/hid-lg.c
+++ b/drivers/hid/hid-lg.c
@@ -53,23 +53,22 @@ static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
53 53
54 if ((quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 && 54 if ((quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 &&
55 rdesc[84] == 0x8c && rdesc[85] == 0x02) { 55 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
56 dev_info(&hdev->dev, "fixing up Logitech keyboard report " 56 hid_info(hdev,
57 "descriptor\n"); 57 "fixing up Logitech keyboard report descriptor\n");
58 rdesc[84] = rdesc[89] = 0x4d; 58 rdesc[84] = rdesc[89] = 0x4d;
59 rdesc[85] = rdesc[90] = 0x10; 59 rdesc[85] = rdesc[90] = 0x10;
60 } 60 }
61 if ((quirks & LG_RDESC_REL_ABS) && *rsize >= 50 && 61 if ((quirks & LG_RDESC_REL_ABS) && *rsize >= 50 &&
62 rdesc[32] == 0x81 && rdesc[33] == 0x06 && 62 rdesc[32] == 0x81 && rdesc[33] == 0x06 &&
63 rdesc[49] == 0x81 && rdesc[50] == 0x06) { 63 rdesc[49] == 0x81 && rdesc[50] == 0x06) {
64 dev_info(&hdev->dev, "fixing up rel/abs in Logitech " 64 hid_info(hdev,
65 "report descriptor\n"); 65 "fixing up rel/abs in Logitech report descriptor\n");
66 rdesc[33] = rdesc[50] = 0x02; 66 rdesc[33] = rdesc[50] = 0x02;
67 } 67 }
68 if ((quirks & LG_FF4) && *rsize >= 101 && 68 if ((quirks & LG_FF4) && *rsize >= 101 &&
69 rdesc[41] == 0x95 && rdesc[42] == 0x0B && 69 rdesc[41] == 0x95 && rdesc[42] == 0x0B &&
70 rdesc[47] == 0x05 && rdesc[48] == 0x09) { 70 rdesc[47] == 0x05 && rdesc[48] == 0x09) {
71 dev_info(&hdev->dev, "fixing up Logitech Speed Force Wireless " 71 hid_info(hdev, "fixing up Logitech Speed Force Wireless button descriptor\n");
72 "button descriptor\n");
73 rdesc[41] = 0x05; 72 rdesc[41] = 0x05;
74 rdesc[42] = 0x09; 73 rdesc[42] = 0x09;
75 rdesc[47] = 0x95; 74 rdesc[47] = 0x95;
@@ -288,7 +287,7 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
288 287
289 ret = hid_parse(hdev); 288 ret = hid_parse(hdev);
290 if (ret) { 289 if (ret) {
291 dev_err(&hdev->dev, "parse failed\n"); 290 hid_err(hdev, "parse failed\n");
292 goto err_free; 291 goto err_free;
293 } 292 }
294 293
@@ -297,7 +296,7 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
297 296
298 ret = hid_hw_start(hdev, connect_mask); 297 ret = hid_hw_start(hdev, connect_mask);
299 if (ret) { 298 if (ret) {
300 dev_err(&hdev->dev, "hw start failed\n"); 299 hid_err(hdev, "hw start failed\n");
301 goto err_free; 300 goto err_free;
302 } 301 }
303 302
diff --git a/drivers/hid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c
index 4258253c36b3..3c31bc650e5d 100644
--- a/drivers/hid/hid-lg2ff.c
+++ b/drivers/hid/hid-lg2ff.c
@@ -72,18 +72,18 @@ int lg2ff_init(struct hid_device *hid)
72 int error; 72 int error;
73 73
74 if (list_empty(report_list)) { 74 if (list_empty(report_list)) {
75 dev_err(&hid->dev, "no output report found\n"); 75 hid_err(hid, "no output report found\n");
76 return -ENODEV; 76 return -ENODEV;
77 } 77 }
78 78
79 report = list_entry(report_list->next, struct hid_report, list); 79 report = list_entry(report_list->next, struct hid_report, list);
80 80
81 if (report->maxfield < 1) { 81 if (report->maxfield < 1) {
82 dev_err(&hid->dev, "output report is empty\n"); 82 hid_err(hid, "output report is empty\n");
83 return -ENODEV; 83 return -ENODEV;
84 } 84 }
85 if (report->field[0]->report_count < 7) { 85 if (report->field[0]->report_count < 7) {
86 dev_err(&hid->dev, "not enough values in the field\n"); 86 hid_err(hid, "not enough values in the field\n");
87 return -ENODEV; 87 return -ENODEV;
88 } 88 }
89 89
@@ -110,8 +110,7 @@ int lg2ff_init(struct hid_device *hid)
110 110
111 usbhid_submit_report(hid, report, USB_DIR_OUT); 111 usbhid_submit_report(hid, report, USB_DIR_OUT);
112 112
113 dev_info(&hid->dev, "Force feedback for Logitech RumblePad/Rumblepad 2 by " 113 hid_info(hid, "Force feedback for Logitech RumblePad/Rumblepad 2 by Anssi Hannula <anssi.hannula@gmail.com>\n");
114 "Anssi Hannula <anssi.hannula@gmail.com>\n");
115 114
116 return 0; 115 return 0;
117} 116}
diff --git a/drivers/hid/hid-lg3ff.c b/drivers/hid/hid-lg3ff.c
index 4002832ee4af..f98644c26c1d 100644
--- a/drivers/hid/hid-lg3ff.c
+++ b/drivers/hid/hid-lg3ff.c
@@ -141,20 +141,20 @@ int lg3ff_init(struct hid_device *hid)
141 141
142 /* Find the report to use */ 142 /* Find the report to use */
143 if (list_empty(report_list)) { 143 if (list_empty(report_list)) {
144 err_hid("No output report found"); 144 hid_err(hid, "No output report found\n");
145 return -1; 145 return -1;
146 } 146 }
147 147
148 /* Check that the report looks ok */ 148 /* Check that the report looks ok */
149 report = list_entry(report_list->next, struct hid_report, list); 149 report = list_entry(report_list->next, struct hid_report, list);
150 if (!report) { 150 if (!report) {
151 err_hid("NULL output report"); 151 hid_err(hid, "NULL output report\n");
152 return -1; 152 return -1;
153 } 153 }
154 154
155 field = report->field[0]; 155 field = report->field[0];
156 if (!field) { 156 if (!field) {
157 err_hid("NULL field"); 157 hid_err(hid, "NULL field\n");
158 return -1; 158 return -1;
159 } 159 }
160 160
@@ -169,8 +169,7 @@ int lg3ff_init(struct hid_device *hid)
169 if (test_bit(FF_AUTOCENTER, dev->ffbit)) 169 if (test_bit(FF_AUTOCENTER, dev->ffbit))
170 dev->ff->set_autocenter = hid_lg3ff_set_autocenter; 170 dev->ff->set_autocenter = hid_lg3ff_set_autocenter;
171 171
172 dev_info(&hid->dev, "Force feedback for Logitech Flight System G940 by " 172 hid_info(hid, "Force feedback for Logitech Flight System G940 by Gary Stein <LordCnidarian@gmail.com>\n");
173 "Gary Stein <LordCnidarian@gmail.com>\n");
174 return 0; 173 return 0;
175} 174}
176 175
diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
index 7eef5a2ce948..fa550c8e1d1b 100644
--- a/drivers/hid/hid-lg4ff.c
+++ b/drivers/hid/hid-lg4ff.c
@@ -101,20 +101,20 @@ int lg4ff_init(struct hid_device *hid)
101 101
102 /* Find the report to use */ 102 /* Find the report to use */
103 if (list_empty(report_list)) { 103 if (list_empty(report_list)) {
104 err_hid("No output report found"); 104 hid_err(hid, "No output report found\n");
105 return -1; 105 return -1;
106 } 106 }
107 107
108 /* Check that the report looks ok */ 108 /* Check that the report looks ok */
109 report = list_entry(report_list->next, struct hid_report, list); 109 report = list_entry(report_list->next, struct hid_report, list);
110 if (!report) { 110 if (!report) {
111 err_hid("NULL output report"); 111 hid_err(hid, "NULL output report\n");
112 return -1; 112 return -1;
113 } 113 }
114 114
115 field = report->field[0]; 115 field = report->field[0];
116 if (!field) { 116 if (!field) {
117 err_hid("NULL field"); 117 hid_err(hid, "NULL field\n");
118 return -1; 118 return -1;
119 } 119 }
120 120
@@ -129,8 +129,7 @@ int lg4ff_init(struct hid_device *hid)
129 if (test_bit(FF_AUTOCENTER, dev->ffbit)) 129 if (test_bit(FF_AUTOCENTER, dev->ffbit))
130 dev->ff->set_autocenter = hid_lg4ff_set_autocenter; 130 dev->ff->set_autocenter = hid_lg4ff_set_autocenter;
131 131
132 dev_info(&hid->dev, "Force feedback for Logitech Speed Force Wireless by " 132 hid_info(hid, "Force feedback for Logitech Speed Force Wireless by Simon Wood <simon@mungewell.org>\n");
133 "Simon Wood <simon@mungewell.org>\n");
134 return 0; 133 return 0;
135} 134}
136 135
diff --git a/drivers/hid/hid-lgff.c b/drivers/hid/hid-lgff.c
index 61142b76a9b1..90d0ef2c92be 100644
--- a/drivers/hid/hid-lgff.c
+++ b/drivers/hid/hid-lgff.c
@@ -27,6 +27,8 @@
27 * e-mail - mail your message to <johann.deneux@it.uu.se> 27 * e-mail - mail your message to <johann.deneux@it.uu.se>
28 */ 28 */
29 29
30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
30#include <linux/input.h> 32#include <linux/input.h>
31#include <linux/usb.h> 33#include <linux/usb.h>
32#include <linux/hid.h> 34#include <linux/hid.h>
@@ -146,7 +148,7 @@ int lgff_init(struct hid_device* hid)
146 148
147 /* Find the report to use */ 149 /* Find the report to use */
148 if (list_empty(report_list)) { 150 if (list_empty(report_list)) {
149 err_hid("No output report found"); 151 hid_err(hid, "No output report found\n");
150 return -1; 152 return -1;
151 } 153 }
152 154
@@ -154,7 +156,7 @@ int lgff_init(struct hid_device* hid)
154 report = list_entry(report_list->next, struct hid_report, list); 156 report = list_entry(report_list->next, struct hid_report, list);
155 field = report->field[0]; 157 field = report->field[0];
156 if (!field) { 158 if (!field) {
157 err_hid("NULL field"); 159 hid_err(hid, "NULL field\n");
158 return -1; 160 return -1;
159 } 161 }
160 162
@@ -176,7 +178,7 @@ int lgff_init(struct hid_device* hid)
176 if ( test_bit(FF_AUTOCENTER, dev->ffbit) ) 178 if ( test_bit(FF_AUTOCENTER, dev->ffbit) )
177 dev->ff->set_autocenter = hid_lgff_set_autocenter; 179 dev->ff->set_autocenter = hid_lgff_set_autocenter;
178 180
179 printk(KERN_INFO "Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n"); 181 pr_info("Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n");
180 182
181 return 0; 183 return 0;
182} 184}
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index e6dc15171664..698e6459fd0b 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -12,6 +12,8 @@
12 * any later version. 12 * any later version.
13 */ 13 */
14 14
15#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16
15#include <linux/device.h> 17#include <linux/device.h>
16#include <linux/hid.h> 18#include <linux/hid.h>
17#include <linux/module.h> 19#include <linux/module.h>
@@ -433,6 +435,11 @@ static int magicmouse_input_mapping(struct hid_device *hdev,
433 if (!msc->input) 435 if (!msc->input)
434 msc->input = hi->input; 436 msc->input = hi->input;
435 437
438 /* Magic Trackpad does not give relative data after switching to MT */
439 if (hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD &&
440 field->flags & HID_MAIN_ITEM_RELATIVE)
441 return -1;
442
436 return 0; 443 return 0;
437} 444}
438 445
@@ -446,7 +453,7 @@ static int magicmouse_probe(struct hid_device *hdev,
446 453
447 msc = kzalloc(sizeof(*msc), GFP_KERNEL); 454 msc = kzalloc(sizeof(*msc), GFP_KERNEL);
448 if (msc == NULL) { 455 if (msc == NULL) {
449 dev_err(&hdev->dev, "can't alloc magicmouse descriptor\n"); 456 hid_err(hdev, "can't alloc magicmouse descriptor\n");
450 return -ENOMEM; 457 return -ENOMEM;
451 } 458 }
452 459
@@ -459,13 +466,13 @@ static int magicmouse_probe(struct hid_device *hdev,
459 466
460 ret = hid_parse(hdev); 467 ret = hid_parse(hdev);
461 if (ret) { 468 if (ret) {
462 dev_err(&hdev->dev, "magicmouse hid parse failed\n"); 469 hid_err(hdev, "magicmouse hid parse failed\n");
463 goto err_free; 470 goto err_free;
464 } 471 }
465 472
466 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 473 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
467 if (ret) { 474 if (ret) {
468 dev_err(&hdev->dev, "magicmouse hw start failed\n"); 475 hid_err(hdev, "magicmouse hw start failed\n");
469 goto err_free; 476 goto err_free;
470 } 477 }
471 478
@@ -486,7 +493,7 @@ static int magicmouse_probe(struct hid_device *hdev,
486 } 493 }
487 494
488 if (!report) { 495 if (!report) {
489 dev_err(&hdev->dev, "unable to register touch report\n"); 496 hid_err(hdev, "unable to register touch report\n");
490 ret = -ENOMEM; 497 ret = -ENOMEM;
491 goto err_stop_hw; 498 goto err_stop_hw;
492 } 499 }
@@ -495,8 +502,7 @@ static int magicmouse_probe(struct hid_device *hdev,
495 ret = hdev->hid_output_raw_report(hdev, feature, sizeof(feature), 502 ret = hdev->hid_output_raw_report(hdev, feature, sizeof(feature),
496 HID_FEATURE_REPORT); 503 HID_FEATURE_REPORT);
497 if (ret != sizeof(feature)) { 504 if (ret != sizeof(feature)) {
498 dev_err(&hdev->dev, "unable to request touch data (%d)\n", 505 hid_err(hdev, "unable to request touch data (%d)\n", ret);
499 ret);
500 goto err_stop_hw; 506 goto err_stop_hw;
501 } 507 }
502 508
@@ -540,7 +546,7 @@ static int __init magicmouse_init(void)
540 546
541 ret = hid_register_driver(&magicmouse_driver); 547 ret = hid_register_driver(&magicmouse_driver);
542 if (ret) 548 if (ret)
543 printk(KERN_ERR "can't register magicmouse driver\n"); 549 pr_err("can't register magicmouse driver\n");
544 550
545 return ret; 551 return ret;
546} 552}
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
index dc618c33d0a2..0f6fc54dc196 100644
--- a/drivers/hid/hid-microsoft.c
+++ b/drivers/hid/hid-microsoft.c
@@ -40,8 +40,7 @@ static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc,
40 40
41 if ((quirks & MS_RDESC) && *rsize == 571 && rdesc[557] == 0x19 && 41 if ((quirks & MS_RDESC) && *rsize == 571 && rdesc[557] == 0x19 &&
42 rdesc[559] == 0x29) { 42 rdesc[559] == 0x29) {
43 dev_info(&hdev->dev, "fixing up Microsoft Wireless Receiver " 43 hid_info(hdev, "fixing up Microsoft Wireless Receiver Model 1028 report descriptor\n");
44 "Model 1028 report descriptor\n");
45 rdesc[557] = 0x35; 44 rdesc[557] = 0x35;
46 rdesc[559] = 0x45; 45 rdesc[559] = 0x45;
47 } 46 }
@@ -155,14 +154,14 @@ static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
155 154
156 ret = hid_parse(hdev); 155 ret = hid_parse(hdev);
157 if (ret) { 156 if (ret) {
158 dev_err(&hdev->dev, "parse failed\n"); 157 hid_err(hdev, "parse failed\n");
159 goto err_free; 158 goto err_free;
160 } 159 }
161 160
162 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ? 161 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ?
163 HID_CONNECT_HIDINPUT_FORCE : 0)); 162 HID_CONNECT_HIDINPUT_FORCE : 0));
164 if (ret) { 163 if (ret) {
165 dev_err(&hdev->dev, "hw start failed\n"); 164 hid_err(hdev, "hw start failed\n");
166 goto err_free; 165 goto err_free;
167 } 166 }
168 167
diff --git a/drivers/hid/hid-monterey.c b/drivers/hid/hid-monterey.c
index c95c31e2d869..dedf757781ae 100644
--- a/drivers/hid/hid-monterey.c
+++ b/drivers/hid/hid-monterey.c
@@ -26,8 +26,7 @@ static __u8 *mr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
26 unsigned int *rsize) 26 unsigned int *rsize)
27{ 27{
28 if (*rsize >= 30 && rdesc[29] == 0x05 && rdesc[30] == 0x09) { 28 if (*rsize >= 30 && rdesc[29] == 0x05 && rdesc[30] == 0x09) {
29 dev_info(&hdev->dev, "fixing up button/consumer in HID report " 29 hid_info(hdev, "fixing up button/consumer in HID report descriptor\n");
30 "descriptor\n");
31 rdesc[30] = 0x0c; 30 rdesc[30] = 0x0c;
32 } 31 }
33 return rdesc; 32 return rdesc;
diff --git a/drivers/hid/hid-mosart.c b/drivers/hid/hid-mosart.c
index ac5421d568f1..9fb050ce6f04 100644
--- a/drivers/hid/hid-mosart.c
+++ b/drivers/hid/hid-mosart.c
@@ -90,6 +90,10 @@ static int mosart_input_mapping(struct hid_device *hdev, struct hid_input *hi,
90 case 0xff000000: 90 case 0xff000000:
91 /* ignore HID features */ 91 /* ignore HID features */
92 return -1; 92 return -1;
93
94 case HID_UP_BUTTON:
95 /* ignore buttons */
96 return -1;
93 } 97 }
94 98
95 return 0; 99 return 0;
@@ -199,7 +203,7 @@ static int mosart_probe(struct hid_device *hdev, const struct hid_device_id *id)
199 203
200 td = kmalloc(sizeof(struct mosart_data), GFP_KERNEL); 204 td = kmalloc(sizeof(struct mosart_data), GFP_KERNEL);
201 if (!td) { 205 if (!td) {
202 dev_err(&hdev->dev, "cannot allocate MosArt data\n"); 206 hid_err(hdev, "cannot allocate MosArt data\n");
203 return -ENOMEM; 207 return -ENOMEM;
204 } 208 }
205 td->valid = false; 209 td->valid = false;
@@ -230,6 +234,19 @@ static int mosart_probe(struct hid_device *hdev, const struct hid_device_id *id)
230 return ret; 234 return ret;
231} 235}
232 236
237#ifdef CONFIG_PM
238static int mosart_reset_resume(struct hid_device *hdev)
239{
240 struct hid_report_enum *re = hdev->report_enum
241 + HID_FEATURE_REPORT;
242 struct hid_report *r = re->report_id_hash[7];
243
244 r->field[0]->value[0] = 0x02;
245 usbhid_submit_report(hdev, r, USB_DIR_OUT);
246 return 0;
247}
248#endif
249
233static void mosart_remove(struct hid_device *hdev) 250static void mosart_remove(struct hid_device *hdev)
234{ 251{
235 hid_hw_stop(hdev); 252 hid_hw_stop(hdev);
@@ -258,6 +275,9 @@ static struct hid_driver mosart_driver = {
258 .input_mapped = mosart_input_mapped, 275 .input_mapped = mosart_input_mapped,
259 .usage_table = mosart_grabbed_usages, 276 .usage_table = mosart_grabbed_usages,
260 .event = mosart_event, 277 .event = mosart_event,
278#ifdef CONFIG_PM
279 .reset_resume = mosart_reset_resume,
280#endif
261}; 281};
262 282
263static int __init mosart_init(void) 283static int __init mosart_init(void)
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index 69169efa1e16..beb403421e72 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -130,8 +130,7 @@ static void ntrig_report_version(struct hid_device *hdev)
130 if (ret == 8) { 130 if (ret == 8) {
131 ret = ntrig_version_string(&data[2], buf); 131 ret = ntrig_version_string(&data[2], buf);
132 132
133 dev_info(&hdev->dev, 133 hid_info(hdev, "Firmware version: %s (%02x%02x %02x%02x)\n",
134 "Firmware version: %s (%02x%02x %02x%02x)\n",
135 buf, data[2], data[3], data[4], data[5]); 134 buf, data[2], data[3], data[4], data[5]);
136 } 135 }
137 136
@@ -831,7 +830,7 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)
831 830
832 nd = kmalloc(sizeof(struct ntrig_data), GFP_KERNEL); 831 nd = kmalloc(sizeof(struct ntrig_data), GFP_KERNEL);
833 if (!nd) { 832 if (!nd) {
834 dev_err(&hdev->dev, "cannot allocate N-Trig data\n"); 833 hid_err(hdev, "cannot allocate N-Trig data\n");
835 return -ENOMEM; 834 return -ENOMEM;
836 } 835 }
837 836
@@ -850,13 +849,13 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)
850 849
851 ret = hid_parse(hdev); 850 ret = hid_parse(hdev);
852 if (ret) { 851 if (ret) {
853 dev_err(&hdev->dev, "parse failed\n"); 852 hid_err(hdev, "parse failed\n");
854 goto err_free; 853 goto err_free;
855 } 854 }
856 855
857 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); 856 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
858 if (ret) { 857 if (ret) {
859 dev_err(&hdev->dev, "hw start failed\n"); 858 hid_err(hdev, "hw start failed\n");
860 goto err_free; 859 goto err_free;
861 } 860 }
862 861
diff --git a/drivers/hid/hid-ortek.c b/drivers/hid/hid-ortek.c
index 2e79716dca31..e90edfc63051 100644
--- a/drivers/hid/hid-ortek.c
+++ b/drivers/hid/hid-ortek.c
@@ -23,8 +23,7 @@ static __u8 *ortek_report_fixup(struct hid_device *hdev, __u8 *rdesc,
23 unsigned int *rsize) 23 unsigned int *rsize)
24{ 24{
25 if (*rsize >= 56 && rdesc[54] == 0x25 && rdesc[55] == 0x01) { 25 if (*rsize >= 56 && rdesc[54] == 0x25 && rdesc[55] == 0x01) {
26 dev_info(&hdev->dev, "Fixing up Ortek WKB-2000 " 26 hid_info(hdev, "Fixing up Ortek WKB-2000 report descriptor\n");
27 "report descriptor.\n");
28 rdesc[55] = 0x92; 27 rdesc[55] = 0x92;
29 } 28 }
30 return rdesc; 29 return rdesc;
diff --git a/drivers/hid/hid-petalynx.c b/drivers/hid/hid-petalynx.c
index 308d6ae48a3e..f1ea3ff8a98d 100644
--- a/drivers/hid/hid-petalynx.c
+++ b/drivers/hid/hid-petalynx.c
@@ -29,8 +29,7 @@ static __u8 *pl_report_fixup(struct hid_device *hdev, __u8 *rdesc,
29 if (*rsize >= 60 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 && 29 if (*rsize >= 60 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
30 rdesc[41] == 0x00 && rdesc[59] == 0x26 && 30 rdesc[41] == 0x00 && rdesc[59] == 0x26 &&
31 rdesc[60] == 0xf9 && rdesc[61] == 0x00) { 31 rdesc[60] == 0xf9 && rdesc[61] == 0x00) {
32 dev_info(&hdev->dev, "fixing up Petalynx Maxter Remote report " 32 hid_info(hdev, "fixing up Petalynx Maxter Remote report descriptor\n");
33 "descriptor\n");
34 rdesc[60] = 0xfa; 33 rdesc[60] = 0xfa;
35 rdesc[40] = 0xfa; 34 rdesc[40] = 0xfa;
36 } 35 }
@@ -77,13 +76,13 @@ static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id)
77 76
78 ret = hid_parse(hdev); 77 ret = hid_parse(hdev);
79 if (ret) { 78 if (ret) {
80 dev_err(&hdev->dev, "parse failed\n"); 79 hid_err(hdev, "parse failed\n");
81 goto err_free; 80 goto err_free;
82 } 81 }
83 82
84 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 83 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
85 if (ret) { 84 if (ret) {
86 dev_err(&hdev->dev, "hw start failed\n"); 85 hid_err(hdev, "hw start failed\n");
87 goto err_free; 86 goto err_free;
88 } 87 }
89 88
diff --git a/drivers/hid/hid-picolcd.c b/drivers/hid/hid-picolcd.c
index bc2e07740628..de9cf21b3494 100644
--- a/drivers/hid/hid-picolcd.c
+++ b/drivers/hid/hid-picolcd.c
@@ -253,7 +253,7 @@ static struct hid_report *picolcd_report(int id, struct hid_device *hdev, int di
253 if (report->id == id) 253 if (report->id == id)
254 return report; 254 return report;
255 } 255 }
256 dev_warn(&hdev->dev, "No report with id 0x%x found\n", id); 256 hid_warn(hdev, "No report with id 0x%x found\n", id);
257 return NULL; 257 return NULL;
258} 258}
259 259
@@ -1329,7 +1329,7 @@ static int picolcd_check_version(struct hid_device *hdev)
1329 1329
1330 verinfo = picolcd_send_and_wait(hdev, REPORT_VERSION, NULL, 0); 1330 verinfo = picolcd_send_and_wait(hdev, REPORT_VERSION, NULL, 0);
1331 if (!verinfo) { 1331 if (!verinfo) {
1332 dev_err(&hdev->dev, "no version response from PicoLCD"); 1332 hid_err(hdev, "no version response from PicoLCD\n");
1333 return -ENODEV; 1333 return -ENODEV;
1334 } 1334 }
1335 1335
@@ -1337,14 +1337,14 @@ static int picolcd_check_version(struct hid_device *hdev)
1337 data->version[0] = verinfo->raw_data[1]; 1337 data->version[0] = verinfo->raw_data[1];
1338 data->version[1] = verinfo->raw_data[0]; 1338 data->version[1] = verinfo->raw_data[0];
1339 if (data->status & PICOLCD_BOOTLOADER) { 1339 if (data->status & PICOLCD_BOOTLOADER) {
1340 dev_info(&hdev->dev, "PicoLCD, bootloader version %d.%d\n", 1340 hid_info(hdev, "PicoLCD, bootloader version %d.%d\n",
1341 verinfo->raw_data[1], verinfo->raw_data[0]); 1341 verinfo->raw_data[1], verinfo->raw_data[0]);
1342 } else { 1342 } else {
1343 dev_info(&hdev->dev, "PicoLCD, firmware version %d.%d\n", 1343 hid_info(hdev, "PicoLCD, firmware version %d.%d\n",
1344 verinfo->raw_data[1], verinfo->raw_data[0]); 1344 verinfo->raw_data[1], verinfo->raw_data[0]);
1345 } 1345 }
1346 } else { 1346 } else {
1347 dev_err(&hdev->dev, "confused, got unexpected version response from PicoLCD\n"); 1347 hid_err(hdev, "confused, got unexpected version response from PicoLCD\n");
1348 ret = -EINVAL; 1348 ret = -EINVAL;
1349 } 1349 }
1350 kfree(verinfo); 1350 kfree(verinfo);
@@ -1544,7 +1544,7 @@ static ssize_t picolcd_debug_eeprom_read(struct file *f, char __user *u,
1544 1544
1545 /* prepare buffer with info about what we want to read (addr & len) */ 1545 /* prepare buffer with info about what we want to read (addr & len) */
1546 raw_data[0] = *off & 0xff; 1546 raw_data[0] = *off & 0xff;
1547 raw_data[1] = (*off >> 8) && 0xff; 1547 raw_data[1] = (*off >> 8) & 0xff;
1548 raw_data[2] = s < 20 ? s : 20; 1548 raw_data[2] = s < 20 ? s : 20;
1549 if (*off + raw_data[2] > 0xff) 1549 if (*off + raw_data[2] > 0xff)
1550 raw_data[2] = 0x100 - *off; 1550 raw_data[2] = 0x100 - *off;
@@ -1583,7 +1583,7 @@ static ssize_t picolcd_debug_eeprom_write(struct file *f, const char __user *u,
1583 1583
1584 memset(raw_data, 0, sizeof(raw_data)); 1584 memset(raw_data, 0, sizeof(raw_data));
1585 raw_data[0] = *off & 0xff; 1585 raw_data[0] = *off & 0xff;
1586 raw_data[1] = (*off >> 8) && 0xff; 1586 raw_data[1] = (*off >> 8) & 0xff;
1587 raw_data[2] = s < 20 ? s : 20; 1587 raw_data[2] = s < 20 ? s : 20;
1588 if (*off + raw_data[2] > 0xff) 1588 if (*off + raw_data[2] > 0xff)
1589 raw_data[2] = 0x100 - *off; 1589 raw_data[2] = 0x100 - *off;
@@ -1867,6 +1867,7 @@ static void picolcd_debug_out_report(struct picolcd_data *data,
1867 report->id, raw_size); 1867 report->id, raw_size);
1868 hid_debug_event(hdev, buff); 1868 hid_debug_event(hdev, buff);
1869 if (raw_size + 5 > sizeof(raw_data)) { 1869 if (raw_size + 5 > sizeof(raw_data)) {
1870 kfree(buff);
1870 hid_debug_event(hdev, " TOO BIG\n"); 1871 hid_debug_event(hdev, " TOO BIG\n");
1871 return; 1872 return;
1872 } else { 1873 } else {
@@ -2328,8 +2329,7 @@ static void picolcd_init_devfs(struct picolcd_data *data,
2328 (flash_w ? S_IWUSR : 0) | (flash_r ? S_IRUSR : 0), 2329 (flash_w ? S_IWUSR : 0) | (flash_r ? S_IRUSR : 0),
2329 hdev->debug_dir, data, &picolcd_debug_flash_fops); 2330 hdev->debug_dir, data, &picolcd_debug_flash_fops);
2330 } else if (flash_r || flash_w) 2331 } else if (flash_r || flash_w)
2331 dev_warn(&hdev->dev, "Unexpected FLASH access reports, " 2332 hid_warn(hdev, "Unexpected FLASH access reports, please submit rdesc for review\n");
2332 "please submit rdesc for review\n");
2333} 2333}
2334 2334
2335static void picolcd_exit_devfs(struct picolcd_data *data) 2335static void picolcd_exit_devfs(struct picolcd_data *data)
@@ -2457,13 +2457,13 @@ static int picolcd_init_keys(struct picolcd_data *data,
2457 return -ENODEV; 2457 return -ENODEV;
2458 if (report->maxfield != 1 || report->field[0]->report_count != 2 || 2458 if (report->maxfield != 1 || report->field[0]->report_count != 2 ||
2459 report->field[0]->report_size != 8) { 2459 report->field[0]->report_size != 8) {
2460 dev_err(&hdev->dev, "unsupported KEY_STATE report"); 2460 hid_err(hdev, "unsupported KEY_STATE report\n");
2461 return -EINVAL; 2461 return -EINVAL;
2462 } 2462 }
2463 2463
2464 idev = input_allocate_device(); 2464 idev = input_allocate_device();
2465 if (idev == NULL) { 2465 if (idev == NULL) {
2466 dev_err(&hdev->dev, "failed to allocate input device"); 2466 hid_err(hdev, "failed to allocate input device\n");
2467 return -ENOMEM; 2467 return -ENOMEM;
2468 } 2468 }
2469 input_set_drvdata(idev, hdev); 2469 input_set_drvdata(idev, hdev);
@@ -2485,7 +2485,7 @@ static int picolcd_init_keys(struct picolcd_data *data,
2485 input_set_capability(idev, EV_KEY, data->keycode[i]); 2485 input_set_capability(idev, EV_KEY, data->keycode[i]);
2486 error = input_register_device(idev); 2486 error = input_register_device(idev);
2487 if (error) { 2487 if (error) {
2488 dev_err(&hdev->dev, "error registering the input device"); 2488 hid_err(hdev, "error registering the input device\n");
2489 input_free_device(idev); 2489 input_free_device(idev);
2490 return error; 2490 return error;
2491 } 2491 }
@@ -2522,9 +2522,8 @@ static int picolcd_probe_lcd(struct hid_device *hdev, struct picolcd_data *data)
2522 return error; 2522 return error;
2523 2523
2524 if (data->version[0] != 0 && data->version[1] != 3) 2524 if (data->version[0] != 0 && data->version[1] != 3)
2525 dev_info(&hdev->dev, "Device with untested firmware revision, " 2525 hid_info(hdev, "Device with untested firmware revision, please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n",
2526 "please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n", 2526 dev_name(&hdev->dev));
2527 dev_name(&hdev->dev));
2528 2527
2529 /* Setup keypad input device */ 2528 /* Setup keypad input device */
2530 error = picolcd_init_keys(data, picolcd_in_report(REPORT_KEY_STATE, hdev)); 2529 error = picolcd_init_keys(data, picolcd_in_report(REPORT_KEY_STATE, hdev));
@@ -2581,9 +2580,8 @@ static int picolcd_probe_bootloader(struct hid_device *hdev, struct picolcd_data
2581 return error; 2580 return error;
2582 2581
2583 if (data->version[0] != 1 && data->version[1] != 0) 2582 if (data->version[0] != 1 && data->version[1] != 0)
2584 dev_info(&hdev->dev, "Device with untested bootloader revision, " 2583 hid_info(hdev, "Device with untested bootloader revision, please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n",
2585 "please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n", 2584 dev_name(&hdev->dev));
2586 dev_name(&hdev->dev));
2587 2585
2588 picolcd_init_devfs(data, NULL, NULL, 2586 picolcd_init_devfs(data, NULL, NULL,
2589 picolcd_out_report(REPORT_BL_READ_MEMORY, hdev), 2587 picolcd_out_report(REPORT_BL_READ_MEMORY, hdev),
@@ -2605,7 +2603,7 @@ static int picolcd_probe(struct hid_device *hdev,
2605 */ 2603 */
2606 data = kzalloc(sizeof(struct picolcd_data), GFP_KERNEL); 2604 data = kzalloc(sizeof(struct picolcd_data), GFP_KERNEL);
2607 if (data == NULL) { 2605 if (data == NULL) {
2608 dev_err(&hdev->dev, "can't allocate space for Minibox PicoLCD device data\n"); 2606 hid_err(hdev, "can't allocate space for Minibox PicoLCD device data\n");
2609 error = -ENOMEM; 2607 error = -ENOMEM;
2610 goto err_no_cleanup; 2608 goto err_no_cleanup;
2611 } 2609 }
@@ -2621,7 +2619,7 @@ static int picolcd_probe(struct hid_device *hdev,
2621 /* Parse the device reports and start it up */ 2619 /* Parse the device reports and start it up */
2622 error = hid_parse(hdev); 2620 error = hid_parse(hdev);
2623 if (error) { 2621 if (error) {
2624 dev_err(&hdev->dev, "device report parse failed\n"); 2622 hid_err(hdev, "device report parse failed\n");
2625 goto err_cleanup_data; 2623 goto err_cleanup_data;
2626 } 2624 }
2627 2625
@@ -2631,25 +2629,25 @@ static int picolcd_probe(struct hid_device *hdev,
2631 error = hid_hw_start(hdev, 0); 2629 error = hid_hw_start(hdev, 0);
2632 hdev->claimed = 0; 2630 hdev->claimed = 0;
2633 if (error) { 2631 if (error) {
2634 dev_err(&hdev->dev, "hardware start failed\n"); 2632 hid_err(hdev, "hardware start failed\n");
2635 goto err_cleanup_data; 2633 goto err_cleanup_data;
2636 } 2634 }
2637 2635
2638 error = hdev->ll_driver->open(hdev); 2636 error = hid_hw_open(hdev);
2639 if (error) { 2637 if (error) {
2640 dev_err(&hdev->dev, "failed to open input interrupt pipe for key and IR events\n"); 2638 hid_err(hdev, "failed to open input interrupt pipe for key and IR events\n");
2641 goto err_cleanup_hid_hw; 2639 goto err_cleanup_hid_hw;
2642 } 2640 }
2643 2641
2644 error = device_create_file(&hdev->dev, &dev_attr_operation_mode_delay); 2642 error = device_create_file(&hdev->dev, &dev_attr_operation_mode_delay);
2645 if (error) { 2643 if (error) {
2646 dev_err(&hdev->dev, "failed to create sysfs attributes\n"); 2644 hid_err(hdev, "failed to create sysfs attributes\n");
2647 goto err_cleanup_hid_ll; 2645 goto err_cleanup_hid_ll;
2648 } 2646 }
2649 2647
2650 error = device_create_file(&hdev->dev, &dev_attr_operation_mode); 2648 error = device_create_file(&hdev->dev, &dev_attr_operation_mode);
2651 if (error) { 2649 if (error) {
2652 dev_err(&hdev->dev, "failed to create sysfs attributes\n"); 2650 hid_err(hdev, "failed to create sysfs attributes\n");
2653 goto err_cleanup_sysfs1; 2651 goto err_cleanup_sysfs1;
2654 } 2652 }
2655 2653
@@ -2668,7 +2666,7 @@ err_cleanup_sysfs2:
2668err_cleanup_sysfs1: 2666err_cleanup_sysfs1:
2669 device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay); 2667 device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay);
2670err_cleanup_hid_ll: 2668err_cleanup_hid_ll:
2671 hdev->ll_driver->close(hdev); 2669 hid_hw_close(hdev);
2672err_cleanup_hid_hw: 2670err_cleanup_hid_hw:
2673 hid_hw_stop(hdev); 2671 hid_hw_stop(hdev);
2674err_cleanup_data: 2672err_cleanup_data:
@@ -2699,7 +2697,7 @@ static void picolcd_remove(struct hid_device *hdev)
2699 picolcd_exit_devfs(data); 2697 picolcd_exit_devfs(data);
2700 device_remove_file(&hdev->dev, &dev_attr_operation_mode); 2698 device_remove_file(&hdev->dev, &dev_attr_operation_mode);
2701 device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay); 2699 device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay);
2702 hdev->ll_driver->close(hdev); 2700 hid_hw_close(hdev);
2703 hid_hw_stop(hdev); 2701 hid_hw_stop(hdev);
2704 hid_set_drvdata(hdev, NULL); 2702 hid_set_drvdata(hdev, NULL);
2705 2703
@@ -2753,7 +2751,7 @@ static void __exit picolcd_exit(void)
2753{ 2751{
2754 hid_unregister_driver(&picolcd_driver); 2752 hid_unregister_driver(&picolcd_driver);
2755#ifdef CONFIG_HID_PICOLCD_FB 2753#ifdef CONFIG_HID_PICOLCD_FB
2756 flush_scheduled_work(); 2754 flush_work_sync(&picolcd_fb_cleanup);
2757 WARN_ON(fb_pending); 2755 WARN_ON(fb_pending);
2758#endif 2756#endif
2759} 2757}
diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c
index 9f41e2bd8483..06e5300d43d2 100644
--- a/drivers/hid/hid-pl.c
+++ b/drivers/hid/hid-pl.c
@@ -103,7 +103,7 @@ static int plff_init(struct hid_device *hid)
103 */ 103 */
104 104
105 if (list_empty(report_list)) { 105 if (list_empty(report_list)) {
106 dev_err(&hid->dev, "no output reports found\n"); 106 hid_err(hid, "no output reports found\n");
107 return -ENODEV; 107 return -ENODEV;
108 } 108 }
109 109
@@ -112,14 +112,13 @@ static int plff_init(struct hid_device *hid)
112 report_ptr = report_ptr->next; 112 report_ptr = report_ptr->next;
113 113
114 if (report_ptr == report_list) { 114 if (report_ptr == report_list) {
115 dev_err(&hid->dev, "required output report is " 115 hid_err(hid, "required output report is missing\n");
116 "missing\n");
117 return -ENODEV; 116 return -ENODEV;
118 } 117 }
119 118
120 report = list_entry(report_ptr, struct hid_report, list); 119 report = list_entry(report_ptr, struct hid_report, list);
121 if (report->maxfield < 1) { 120 if (report->maxfield < 1) {
122 dev_err(&hid->dev, "no fields in the report\n"); 121 hid_err(hid, "no fields in the report\n");
123 return -ENODEV; 122 return -ENODEV;
124 } 123 }
125 124
@@ -137,7 +136,7 @@ static int plff_init(struct hid_device *hid)
137 weak = &report->field[3]->value[0]; 136 weak = &report->field[3]->value[0];
138 debug("detected 4-field device"); 137 debug("detected 4-field device");
139 } else { 138 } else {
140 dev_err(&hid->dev, "not enough fields or values\n"); 139 hid_err(hid, "not enough fields or values\n");
141 return -ENODEV; 140 return -ENODEV;
142 } 141 }
143 142
@@ -164,8 +163,7 @@ static int plff_init(struct hid_device *hid)
164 usbhid_submit_report(hid, plff->report, USB_DIR_OUT); 163 usbhid_submit_report(hid, plff->report, USB_DIR_OUT);
165 } 164 }
166 165
167 dev_info(&hid->dev, "Force feedback for PantherLord/GreenAsia " 166 hid_info(hid, "Force feedback for PantherLord/GreenAsia devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
168 "devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
169 167
170 return 0; 168 return 0;
171} 169}
@@ -185,13 +183,13 @@ static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id)
185 183
186 ret = hid_parse(hdev); 184 ret = hid_parse(hdev);
187 if (ret) { 185 if (ret) {
188 dev_err(&hdev->dev, "parse failed\n"); 186 hid_err(hdev, "parse failed\n");
189 goto err; 187 goto err;
190 } 188 }
191 189
192 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); 190 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
193 if (ret) { 191 if (ret) {
194 dev_err(&hdev->dev, "hw start failed\n"); 192 hid_err(hdev, "hw start failed\n");
195 goto err; 193 goto err;
196 } 194 }
197 195
diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c
index 48eab84f53b5..ab19f2905d27 100644
--- a/drivers/hid/hid-prodikeys.c
+++ b/drivers/hid/hid-prodikeys.c
@@ -16,6 +16,8 @@
16 * any later version. 16 * any later version.
17 */ 17 */
18 18
19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
19#include <linux/device.h> 21#include <linux/device.h>
20#include <linux/module.h> 22#include <linux/module.h>
21#include <linux/usb.h> 23#include <linux/usb.h>
@@ -130,7 +132,7 @@ static ssize_t store_channel(struct device *dev,
130 return -EINVAL; 132 return -EINVAL;
131} 133}
132 134
133static DEVICE_ATTR(channel, S_IRUGO | S_IWUGO, show_channel, 135static DEVICE_ATTR(channel, S_IRUGO | S_IWUSR | S_IWGRP , show_channel,
134 store_channel); 136 store_channel);
135 137
136static struct device_attribute *sysfs_device_attr_channel = { 138static struct device_attribute *sysfs_device_attr_channel = {
@@ -169,7 +171,7 @@ static ssize_t store_sustain(struct device *dev,
169 return -EINVAL; 171 return -EINVAL;
170} 172}
171 173
172static DEVICE_ATTR(sustain, S_IRUGO | S_IWUGO, show_sustain, 174static DEVICE_ATTR(sustain, S_IRUGO | S_IWUSR | S_IWGRP, show_sustain,
173 store_sustain); 175 store_sustain);
174 176
175static struct device_attribute *sysfs_device_attr_sustain = { 177static struct device_attribute *sysfs_device_attr_sustain = {
@@ -207,7 +209,7 @@ static ssize_t store_octave(struct device *dev,
207 return -EINVAL; 209 return -EINVAL;
208} 210}
209 211
210static DEVICE_ATTR(octave, S_IRUGO | S_IWUGO, show_octave, 212static DEVICE_ATTR(octave, S_IRUGO | S_IWUSR | S_IWGRP, show_octave,
211 store_octave); 213 store_octave);
212 214
213static struct device_attribute *sysfs_device_attr_octave = { 215static struct device_attribute *sysfs_device_attr_octave = {
@@ -285,11 +287,11 @@ static int pcmidi_get_output_report(struct pcmidi_snd *pm)
285 continue; 287 continue;
286 288
287 if (report->maxfield < 1) { 289 if (report->maxfield < 1) {
288 dev_err(&hdev->dev, "output report is empty\n"); 290 hid_err(hdev, "output report is empty\n");
289 break; 291 break;
290 } 292 }
291 if (report->field[0]->report_count != 2) { 293 if (report->field[0]->report_count != 2) {
292 dev_err(&hdev->dev, "field count too low\n"); 294 hid_err(hdev, "field count too low\n");
293 break; 295 break;
294 } 296 }
295 pm->pcmidi_report6 = report; 297 pm->pcmidi_report6 = report;
@@ -746,8 +748,8 @@ static __u8 *pk_report_fixup(struct hid_device *hdev, __u8 *rdesc,
746 if (*rsize == 178 && 748 if (*rsize == 178 &&
747 rdesc[111] == 0x06 && rdesc[112] == 0x00 && 749 rdesc[111] == 0x06 && rdesc[112] == 0x00 &&
748 rdesc[113] == 0xff) { 750 rdesc[113] == 0xff) {
749 dev_info(&hdev->dev, "fixing up pc-midi keyboard report " 751 hid_info(hdev,
750 "descriptor\n"); 752 "fixing up pc-midi keyboard report descriptor\n");
751 753
752 rdesc[144] = 0x18; /* report 4: was 0x10 report count */ 754 rdesc[144] = 0x18; /* report 4: was 0x10 report count */
753 } 755 }
@@ -805,7 +807,7 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)
805 807
806 pk = kzalloc(sizeof(*pk), GFP_KERNEL); 808 pk = kzalloc(sizeof(*pk), GFP_KERNEL);
807 if (pk == NULL) { 809 if (pk == NULL) {
808 dev_err(&hdev->dev, "prodikeys: can't alloc descriptor\n"); 810 hid_err(hdev, "can't alloc descriptor\n");
809 return -ENOMEM; 811 return -ENOMEM;
810 } 812 }
811 813
@@ -813,8 +815,7 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)
813 815
814 pm = kzalloc(sizeof(*pm), GFP_KERNEL); 816 pm = kzalloc(sizeof(*pm), GFP_KERNEL);
815 if (pm == NULL) { 817 if (pm == NULL) {
816 dev_err(&hdev->dev, 818 hid_err(hdev, "can't alloc descriptor\n");
817 "prodikeys: can't alloc descriptor\n");
818 ret = -ENOMEM; 819 ret = -ENOMEM;
819 goto err_free; 820 goto err_free;
820 } 821 }
@@ -827,7 +828,7 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)
827 828
828 ret = hid_parse(hdev); 829 ret = hid_parse(hdev);
829 if (ret) { 830 if (ret) {
830 dev_err(&hdev->dev, "prodikeys: hid parse failed\n"); 831 hid_err(hdev, "hid parse failed\n");
831 goto err_free; 832 goto err_free;
832 } 833 }
833 834
@@ -837,7 +838,7 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)
837 838
838 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 839 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
839 if (ret) { 840 if (ret) {
840 dev_err(&hdev->dev, "prodikeys: hw start failed\n"); 841 hid_err(hdev, "hw start failed\n");
841 goto err_free; 842 goto err_free;
842 } 843 }
843 844
@@ -896,7 +897,7 @@ static int pk_init(void)
896 897
897 ret = hid_register_driver(&pk_driver); 898 ret = hid_register_driver(&pk_driver);
898 if (ret) 899 if (ret)
899 printk(KERN_ERR "can't register prodikeys driver\n"); 900 pr_err("can't register prodikeys driver\n");
900 901
901 return ret; 902 return ret;
902} 903}
diff --git a/drivers/hid/hid-quanta.c b/drivers/hid/hid-quanta.c
index 54d3db50605b..87a54df4d4ac 100644
--- a/drivers/hid/hid-quanta.c
+++ b/drivers/hid/hid-quanta.c
@@ -195,7 +195,7 @@ static int quanta_probe(struct hid_device *hdev, const struct hid_device_id *id)
195 195
196 td = kmalloc(sizeof(struct quanta_data), GFP_KERNEL); 196 td = kmalloc(sizeof(struct quanta_data), GFP_KERNEL);
197 if (!td) { 197 if (!td) {
198 dev_err(&hdev->dev, "cannot allocate Quanta Touch data\n"); 198 hid_err(hdev, "cannot allocate Quanta Touch data\n");
199 return -ENOMEM; 199 return -ENOMEM;
200 } 200 }
201 td->valid = false; 201 td->valid = false;
diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c
index f77695762cb5..cbd8cc42e75a 100644
--- a/drivers/hid/hid-roccat-kone.c
+++ b/drivers/hid/hid-roccat-kone.c
@@ -35,6 +35,11 @@
35#include "hid-roccat.h" 35#include "hid-roccat.h"
36#include "hid-roccat-kone.h" 36#include "hid-roccat-kone.h"
37 37
38static uint profile_numbers[5] = {0, 1, 2, 3, 4};
39
40/* kone_class is used for creating sysfs attributes via roccat char device */
41static struct class *kone_class;
42
38static void kone_set_settings_checksum(struct kone_settings *settings) 43static void kone_set_settings_checksum(struct kone_settings *settings)
39{ 44{
40 uint16_t checksum = 0; 45 uint16_t checksum = 0;
@@ -90,8 +95,7 @@ static int kone_check_write(struct usb_device *usb_dev)
90 kfree(data); 95 kfree(data);
91 return 0; 96 return 0;
92 } else { /* unknown answer */ 97 } else { /* unknown answer */
93 dev_err(&usb_dev->dev, "got retval %d when checking write\n", 98 hid_err(usb_dev, "got retval %d when checking write\n", *data);
94 *data);
95 kfree(data); 99 kfree(data);
96 return -EIO; 100 return -EIO;
97 } 101 }
@@ -262,7 +266,8 @@ static int kone_get_firmware_version(struct usb_device *usb_dev, int *result)
262static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj, 266static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj,
263 struct bin_attribute *attr, char *buf, 267 struct bin_attribute *attr, char *buf,
264 loff_t off, size_t count) { 268 loff_t off, size_t count) {
265 struct device *dev = container_of(kobj, struct device, kobj); 269 struct device *dev =
270 container_of(kobj, struct device, kobj)->parent->parent;
266 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 271 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
267 272
268 if (off >= sizeof(struct kone_settings)) 273 if (off >= sizeof(struct kone_settings))
@@ -286,7 +291,8 @@ static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj,
286static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, 291static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj,
287 struct bin_attribute *attr, char *buf, 292 struct bin_attribute *attr, char *buf,
288 loff_t off, size_t count) { 293 loff_t off, size_t count) {
289 struct device *dev = container_of(kobj, struct device, kobj); 294 struct device *dev =
295 container_of(kobj, struct device, kobj)->parent->parent;
290 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 296 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
291 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 297 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
292 int retval = 0, difference; 298 int retval = 0, difference;
@@ -319,10 +325,11 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj,
319 return sizeof(struct kone_settings); 325 return sizeof(struct kone_settings);
320} 326}
321 327
322static ssize_t kone_sysfs_read_profilex(struct kobject *kobj, 328static ssize_t kone_sysfs_read_profilex(struct file *fp,
323 struct bin_attribute *attr, char *buf, 329 struct kobject *kobj, struct bin_attribute *attr,
324 loff_t off, size_t count, int number) { 330 char *buf, loff_t off, size_t count) {
325 struct device *dev = container_of(kobj, struct device, kobj); 331 struct device *dev =
332 container_of(kobj, struct device, kobj)->parent->parent;
326 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 333 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
327 334
328 if (off >= sizeof(struct kone_profile)) 335 if (off >= sizeof(struct kone_profile))
@@ -332,47 +339,18 @@ static ssize_t kone_sysfs_read_profilex(struct kobject *kobj,
332 count = sizeof(struct kone_profile) - off; 339 count = sizeof(struct kone_profile) - off;
333 340
334 mutex_lock(&kone->kone_lock); 341 mutex_lock(&kone->kone_lock);
335 memcpy(buf, ((char const *)&kone->profiles[number - 1]) + off, count); 342 memcpy(buf, ((char const *)&kone->profiles[*(uint *)(attr->private)]) + off, count);
336 mutex_unlock(&kone->kone_lock); 343 mutex_unlock(&kone->kone_lock);
337 344
338 return count; 345 return count;
339} 346}
340 347
341static ssize_t kone_sysfs_read_profile1(struct file *fp, struct kobject *kobj,
342 struct bin_attribute *attr, char *buf,
343 loff_t off, size_t count) {
344 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 1);
345}
346
347static ssize_t kone_sysfs_read_profile2(struct file *fp, struct kobject *kobj,
348 struct bin_attribute *attr, char *buf,
349 loff_t off, size_t count) {
350 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 2);
351}
352
353static ssize_t kone_sysfs_read_profile3(struct file *fp, struct kobject *kobj,
354 struct bin_attribute *attr, char *buf,
355 loff_t off, size_t count) {
356 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 3);
357}
358
359static ssize_t kone_sysfs_read_profile4(struct file *fp, struct kobject *kobj,
360 struct bin_attribute *attr, char *buf,
361 loff_t off, size_t count) {
362 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 4);
363}
364
365static ssize_t kone_sysfs_read_profile5(struct file *fp, struct kobject *kobj,
366 struct bin_attribute *attr, char *buf,
367 loff_t off, size_t count) {
368 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 5);
369}
370
371/* Writes data only if different to stored data */ 348/* Writes data only if different to stored data */
372static ssize_t kone_sysfs_write_profilex(struct kobject *kobj, 349static ssize_t kone_sysfs_write_profilex(struct file *fp,
373 struct bin_attribute *attr, char *buf, 350 struct kobject *kobj, struct bin_attribute *attr,
374 loff_t off, size_t count, int number) { 351 char *buf, loff_t off, size_t count) {
375 struct device *dev = container_of(kobj, struct device, kobj); 352 struct device *dev =
353 container_of(kobj, struct device, kobj)->parent->parent;
376 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 354 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
377 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 355 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
378 struct kone_profile *profile; 356 struct kone_profile *profile;
@@ -382,13 +360,14 @@ static ssize_t kone_sysfs_write_profilex(struct kobject *kobj,
382 if (off != 0 || count != sizeof(struct kone_profile)) 360 if (off != 0 || count != sizeof(struct kone_profile))
383 return -EINVAL; 361 return -EINVAL;
384 362
385 profile = &kone->profiles[number - 1]; 363 profile = &kone->profiles[*(uint *)(attr->private)];
386 364
387 mutex_lock(&kone->kone_lock); 365 mutex_lock(&kone->kone_lock);
388 difference = memcmp(buf, profile, sizeof(struct kone_profile)); 366 difference = memcmp(buf, profile, sizeof(struct kone_profile));
389 if (difference) { 367 if (difference) {
390 retval = kone_set_profile(usb_dev, 368 retval = kone_set_profile(usb_dev,
391 (struct kone_profile const *)buf, number); 369 (struct kone_profile const *)buf,
370 *(uint *)(attr->private) + 1);
392 if (!retval) 371 if (!retval)
393 memcpy(profile, buf, sizeof(struct kone_profile)); 372 memcpy(profile, buf, sizeof(struct kone_profile));
394 } 373 }
@@ -400,47 +379,19 @@ static ssize_t kone_sysfs_write_profilex(struct kobject *kobj,
400 return sizeof(struct kone_profile); 379 return sizeof(struct kone_profile);
401} 380}
402 381
403static ssize_t kone_sysfs_write_profile1(struct file *fp, struct kobject *kobj,
404 struct bin_attribute *attr, char *buf,
405 loff_t off, size_t count) {
406 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 1);
407}
408
409static ssize_t kone_sysfs_write_profile2(struct file *fp, struct kobject *kobj,
410 struct bin_attribute *attr, char *buf,
411 loff_t off, size_t count) {
412 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 2);
413}
414
415static ssize_t kone_sysfs_write_profile3(struct file *fp, struct kobject *kobj,
416 struct bin_attribute *attr, char *buf,
417 loff_t off, size_t count) {
418 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 3);
419}
420
421static ssize_t kone_sysfs_write_profile4(struct file *fp, struct kobject *kobj,
422 struct bin_attribute *attr, char *buf,
423 loff_t off, size_t count) {
424 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 4);
425}
426
427static ssize_t kone_sysfs_write_profile5(struct file *fp, struct kobject *kobj,
428 struct bin_attribute *attr, char *buf,
429 loff_t off, size_t count) {
430 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 5);
431}
432
433static ssize_t kone_sysfs_show_actual_profile(struct device *dev, 382static ssize_t kone_sysfs_show_actual_profile(struct device *dev,
434 struct device_attribute *attr, char *buf) 383 struct device_attribute *attr, char *buf)
435{ 384{
436 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 385 struct kone_device *kone =
386 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
437 return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile); 387 return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile);
438} 388}
439 389
440static ssize_t kone_sysfs_show_actual_dpi(struct device *dev, 390static ssize_t kone_sysfs_show_actual_dpi(struct device *dev,
441 struct device_attribute *attr, char *buf) 391 struct device_attribute *attr, char *buf)
442{ 392{
443 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 393 struct kone_device *kone =
394 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
444 return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi); 395 return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi);
445} 396}
446 397
@@ -448,11 +399,15 @@ static ssize_t kone_sysfs_show_actual_dpi(struct device *dev,
448static ssize_t kone_sysfs_show_weight(struct device *dev, 399static ssize_t kone_sysfs_show_weight(struct device *dev,
449 struct device_attribute *attr, char *buf) 400 struct device_attribute *attr, char *buf)
450{ 401{
451 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 402 struct kone_device *kone;
452 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 403 struct usb_device *usb_dev;
453 int weight = 0; 404 int weight = 0;
454 int retval; 405 int retval;
455 406
407 dev = dev->parent->parent;
408 kone = hid_get_drvdata(dev_get_drvdata(dev));
409 usb_dev = interface_to_usbdev(to_usb_interface(dev));
410
456 mutex_lock(&kone->kone_lock); 411 mutex_lock(&kone->kone_lock);
457 retval = kone_get_weight(usb_dev, &weight); 412 retval = kone_get_weight(usb_dev, &weight);
458 mutex_unlock(&kone->kone_lock); 413 mutex_unlock(&kone->kone_lock);
@@ -465,14 +420,16 @@ static ssize_t kone_sysfs_show_weight(struct device *dev,
465static ssize_t kone_sysfs_show_firmware_version(struct device *dev, 420static ssize_t kone_sysfs_show_firmware_version(struct device *dev,
466 struct device_attribute *attr, char *buf) 421 struct device_attribute *attr, char *buf)
467{ 422{
468 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 423 struct kone_device *kone =
424 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
469 return snprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version); 425 return snprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version);
470} 426}
471 427
472static ssize_t kone_sysfs_show_tcu(struct device *dev, 428static ssize_t kone_sysfs_show_tcu(struct device *dev,
473 struct device_attribute *attr, char *buf) 429 struct device_attribute *attr, char *buf)
474{ 430{
475 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 431 struct kone_device *kone =
432 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
476 return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.tcu); 433 return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.tcu);
477} 434}
478 435
@@ -504,11 +461,15 @@ static int kone_tcu_command(struct usb_device *usb_dev, int number)
504static ssize_t kone_sysfs_set_tcu(struct device *dev, 461static ssize_t kone_sysfs_set_tcu(struct device *dev,
505 struct device_attribute *attr, char const *buf, size_t size) 462 struct device_attribute *attr, char const *buf, size_t size)
506{ 463{
507 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 464 struct kone_device *kone;
508 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 465 struct usb_device *usb_dev;
509 int retval; 466 int retval;
510 unsigned long state; 467 unsigned long state;
511 468
469 dev = dev->parent->parent;
470 kone = hid_get_drvdata(dev_get_drvdata(dev));
471 usb_dev = interface_to_usbdev(to_usb_interface(dev));
472
512 retval = strict_strtoul(buf, 10, &state); 473 retval = strict_strtoul(buf, 10, &state);
513 if (retval) 474 if (retval)
514 return retval; 475 return retval;
@@ -556,7 +517,7 @@ static ssize_t kone_sysfs_set_tcu(struct device *dev,
556 517
557 retval = kone_set_settings(usb_dev, &kone->settings); 518 retval = kone_set_settings(usb_dev, &kone->settings);
558 if (retval) { 519 if (retval) {
559 dev_err(&usb_dev->dev, "couldn't set tcu state\n"); 520 hid_err(usb_dev, "couldn't set tcu state\n");
560 /* 521 /*
561 * try to reread valid settings into buffer overwriting 522 * try to reread valid settings into buffer overwriting
562 * first error code 523 * first error code
@@ -570,7 +531,7 @@ static ssize_t kone_sysfs_set_tcu(struct device *dev,
570 531
571 retval = size; 532 retval = size;
572exit_no_settings: 533exit_no_settings:
573 dev_err(&usb_dev->dev, "couldn't read settings\n"); 534 hid_err(usb_dev, "couldn't read settings\n");
574exit_unlock: 535exit_unlock:
575 mutex_unlock(&kone->kone_lock); 536 mutex_unlock(&kone->kone_lock);
576 return retval; 537 return retval;
@@ -579,18 +540,23 @@ exit_unlock:
579static ssize_t kone_sysfs_show_startup_profile(struct device *dev, 540static ssize_t kone_sysfs_show_startup_profile(struct device *dev,
580 struct device_attribute *attr, char *buf) 541 struct device_attribute *attr, char *buf)
581{ 542{
582 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 543 struct kone_device *kone =
544 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
583 return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.startup_profile); 545 return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.startup_profile);
584} 546}
585 547
586static ssize_t kone_sysfs_set_startup_profile(struct device *dev, 548static ssize_t kone_sysfs_set_startup_profile(struct device *dev,
587 struct device_attribute *attr, char const *buf, size_t size) 549 struct device_attribute *attr, char const *buf, size_t size)
588{ 550{
589 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 551 struct kone_device *kone;
590 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 552 struct usb_device *usb_dev;
591 int retval; 553 int retval;
592 unsigned long new_startup_profile; 554 unsigned long new_startup_profile;
593 555
556 dev = dev->parent->parent;
557 kone = hid_get_drvdata(dev_get_drvdata(dev));
558 usb_dev = interface_to_usbdev(to_usb_interface(dev));
559
594 retval = strict_strtoul(buf, 10, &new_startup_profile); 560 retval = strict_strtoul(buf, 10, &new_startup_profile);
595 if (retval) 561 if (retval)
596 return retval; 562 return retval;
@@ -617,160 +583,92 @@ static ssize_t kone_sysfs_set_startup_profile(struct device *dev,
617 return size; 583 return size;
618} 584}
619 585
620/* 586static struct device_attribute kone_attributes[] = {
621 * Read actual dpi settings. 587 /*
622 * Returns raw value for further processing. Refer to enum kone_polling_rates to 588 * Read actual dpi settings.
623 * get real value. 589 * Returns raw value for further processing. Refer to enum
624 */ 590 * kone_polling_rates to get real value.
625static DEVICE_ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL); 591 */
626 592 __ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL),
627static DEVICE_ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL); 593 __ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL),
628
629/*
630 * The mouse can be equipped with one of four supplied weights from 5 to 20
631 * grams which are recognized and its value can be read out.
632 * This returns the raw value reported by the mouse for easy evaluation by
633 * software. Refer to enum kone_weights to get corresponding real weight.
634 */
635static DEVICE_ATTR(weight, 0440, kone_sysfs_show_weight, NULL);
636
637/*
638 * Prints firmware version stored in mouse as integer.
639 * The raw value reported by the mouse is returned for easy evaluation, to get
640 * the real version number the decimal point has to be shifted 2 positions to
641 * the left. E.g. a value of 138 means 1.38.
642 */
643static DEVICE_ATTR(firmware_version, 0440,
644 kone_sysfs_show_firmware_version, NULL);
645
646/*
647 * Prints state of Tracking Control Unit as number where 0 = off and 1 = on
648 * Writing 0 deactivates tcu and writing 1 calibrates and activates the tcu
649 */
650static DEVICE_ATTR(tcu, 0660, kone_sysfs_show_tcu, kone_sysfs_set_tcu);
651
652/* Prints and takes the number of the profile the mouse starts with */
653static DEVICE_ATTR(startup_profile, 0660,
654 kone_sysfs_show_startup_profile,
655 kone_sysfs_set_startup_profile);
656
657static struct attribute *kone_attributes[] = {
658 &dev_attr_actual_dpi.attr,
659 &dev_attr_actual_profile.attr,
660 &dev_attr_weight.attr,
661 &dev_attr_firmware_version.attr,
662 &dev_attr_tcu.attr,
663 &dev_attr_startup_profile.attr,
664 NULL
665};
666
667static struct attribute_group kone_attribute_group = {
668 .attrs = kone_attributes
669};
670
671static struct bin_attribute kone_settings_attr = {
672 .attr = { .name = "settings", .mode = 0660 },
673 .size = sizeof(struct kone_settings),
674 .read = kone_sysfs_read_settings,
675 .write = kone_sysfs_write_settings
676};
677 594
678static struct bin_attribute kone_profile1_attr = { 595 /*
679 .attr = { .name = "profile1", .mode = 0660 }, 596 * The mouse can be equipped with one of four supplied weights from 5
680 .size = sizeof(struct kone_profile), 597 * to 20 grams which are recognized and its value can be read out.
681 .read = kone_sysfs_read_profile1, 598 * This returns the raw value reported by the mouse for easy evaluation
682 .write = kone_sysfs_write_profile1 599 * by software. Refer to enum kone_weights to get corresponding real
683}; 600 * weight.
601 */
602 __ATTR(weight, 0440, kone_sysfs_show_weight, NULL),
684 603
685static struct bin_attribute kone_profile2_attr = { 604 /*
686 .attr = { .name = "profile2", .mode = 0660 }, 605 * Prints firmware version stored in mouse as integer.
687 .size = sizeof(struct kone_profile), 606 * The raw value reported by the mouse is returned for easy evaluation,
688 .read = kone_sysfs_read_profile2, 607 * to get the real version number the decimal point has to be shifted 2
689 .write = kone_sysfs_write_profile2 608 * positions to the left. E.g. a value of 138 means 1.38.
690}; 609 */
610 __ATTR(firmware_version, 0440,
611 kone_sysfs_show_firmware_version, NULL),
691 612
692static struct bin_attribute kone_profile3_attr = { 613 /*
693 .attr = { .name = "profile3", .mode = 0660 }, 614 * Prints state of Tracking Control Unit as number where 0 = off and
694 .size = sizeof(struct kone_profile), 615 * 1 = on. Writing 0 deactivates tcu and writing 1 calibrates and
695 .read = kone_sysfs_read_profile3, 616 * activates the tcu
696 .write = kone_sysfs_write_profile3 617 */
697}; 618 __ATTR(tcu, 0660, kone_sysfs_show_tcu, kone_sysfs_set_tcu),
698 619
699static struct bin_attribute kone_profile4_attr = { 620 /* Prints and takes the number of the profile the mouse starts with */
700 .attr = { .name = "profile4", .mode = 0660 }, 621 __ATTR(startup_profile, 0660,
701 .size = sizeof(struct kone_profile), 622 kone_sysfs_show_startup_profile,
702 .read = kone_sysfs_read_profile4, 623 kone_sysfs_set_startup_profile),
703 .write = kone_sysfs_write_profile4 624 __ATTR_NULL
704}; 625};
705 626
706static struct bin_attribute kone_profile5_attr = { 627static struct bin_attribute kone_bin_attributes[] = {
707 .attr = { .name = "profile5", .mode = 0660 }, 628 {
708 .size = sizeof(struct kone_profile), 629 .attr = { .name = "settings", .mode = 0660 },
709 .read = kone_sysfs_read_profile5, 630 .size = sizeof(struct kone_settings),
710 .write = kone_sysfs_write_profile5 631 .read = kone_sysfs_read_settings,
632 .write = kone_sysfs_write_settings
633 },
634 {
635 .attr = { .name = "profile1", .mode = 0660 },
636 .size = sizeof(struct kone_profile),
637 .read = kone_sysfs_read_profilex,
638 .write = kone_sysfs_write_profilex,
639 .private = &profile_numbers[0]
640 },
641 {
642 .attr = { .name = "profile2", .mode = 0660 },
643 .size = sizeof(struct kone_profile),
644 .read = kone_sysfs_read_profilex,
645 .write = kone_sysfs_write_profilex,
646 .private = &profile_numbers[1]
647 },
648 {
649 .attr = { .name = "profile3", .mode = 0660 },
650 .size = sizeof(struct kone_profile),
651 .read = kone_sysfs_read_profilex,
652 .write = kone_sysfs_write_profilex,
653 .private = &profile_numbers[2]
654 },
655 {
656 .attr = { .name = "profile4", .mode = 0660 },
657 .size = sizeof(struct kone_profile),
658 .read = kone_sysfs_read_profilex,
659 .write = kone_sysfs_write_profilex,
660 .private = &profile_numbers[3]
661 },
662 {
663 .attr = { .name = "profile5", .mode = 0660 },
664 .size = sizeof(struct kone_profile),
665 .read = kone_sysfs_read_profilex,
666 .write = kone_sysfs_write_profilex,
667 .private = &profile_numbers[4]
668 },
669 __ATTR_NULL
711}; 670};
712 671
713static int kone_create_sysfs_attributes(struct usb_interface *intf)
714{
715 int retval;
716
717 retval = sysfs_create_group(&intf->dev.kobj, &kone_attribute_group);
718 if (retval)
719 goto exit_1;
720
721 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_settings_attr);
722 if (retval)
723 goto exit_2;
724
725 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile1_attr);
726 if (retval)
727 goto exit_3;
728
729 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile2_attr);
730 if (retval)
731 goto exit_4;
732
733 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile3_attr);
734 if (retval)
735 goto exit_5;
736
737 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile4_attr);
738 if (retval)
739 goto exit_6;
740
741 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile5_attr);
742 if (retval)
743 goto exit_7;
744
745 return 0;
746
747exit_7:
748 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile4_attr);
749exit_6:
750 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile3_attr);
751exit_5:
752 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile2_attr);
753exit_4:
754 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile1_attr);
755exit_3:
756 sysfs_remove_bin_file(&intf->dev.kobj, &kone_settings_attr);
757exit_2:
758 sysfs_remove_group(&intf->dev.kobj, &kone_attribute_group);
759exit_1:
760 return retval;
761}
762
763static void kone_remove_sysfs_attributes(struct usb_interface *intf)
764{
765 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile5_attr);
766 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile4_attr);
767 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile3_attr);
768 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile2_attr);
769 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile1_attr);
770 sysfs_remove_bin_file(&intf->dev.kobj, &kone_settings_attr);
771 sysfs_remove_group(&intf->dev.kobj, &kone_attribute_group);
772}
773
774static int kone_init_kone_device_struct(struct usb_device *usb_dev, 672static int kone_init_kone_device_struct(struct usb_device *usb_dev,
775 struct kone_device *kone) 673 struct kone_device *kone)
776{ 674{
@@ -818,32 +716,25 @@ static int kone_init_specials(struct hid_device *hdev)
818 716
819 kone = kzalloc(sizeof(*kone), GFP_KERNEL); 717 kone = kzalloc(sizeof(*kone), GFP_KERNEL);
820 if (!kone) { 718 if (!kone) {
821 dev_err(&hdev->dev, "can't alloc device descriptor\n"); 719 hid_err(hdev, "can't alloc device descriptor\n");
822 return -ENOMEM; 720 return -ENOMEM;
823 } 721 }
824 hid_set_drvdata(hdev, kone); 722 hid_set_drvdata(hdev, kone);
825 723
826 retval = kone_init_kone_device_struct(usb_dev, kone); 724 retval = kone_init_kone_device_struct(usb_dev, kone);
827 if (retval) { 725 if (retval) {
828 dev_err(&hdev->dev, 726 hid_err(hdev, "couldn't init struct kone_device\n");
829 "couldn't init struct kone_device\n");
830 goto exit_free; 727 goto exit_free;
831 } 728 }
832 729
833 retval = roccat_connect(hdev); 730 retval = roccat_connect(kone_class, hdev);
834 if (retval < 0) { 731 if (retval < 0) {
835 dev_err(&hdev->dev, "couldn't init char dev\n"); 732 hid_err(hdev, "couldn't init char dev\n");
836 /* be tolerant about not getting chrdev */ 733 /* be tolerant about not getting chrdev */
837 } else { 734 } else {
838 kone->roccat_claimed = 1; 735 kone->roccat_claimed = 1;
839 kone->chrdev_minor = retval; 736 kone->chrdev_minor = retval;
840 } 737 }
841
842 retval = kone_create_sysfs_attributes(intf);
843 if (retval) {
844 dev_err(&hdev->dev, "cannot create sysfs files\n");
845 goto exit_free;
846 }
847 } else { 738 } else {
848 hid_set_drvdata(hdev, NULL); 739 hid_set_drvdata(hdev, NULL);
849 } 740 }
@@ -854,7 +745,6 @@ exit_free:
854 return retval; 745 return retval;
855} 746}
856 747
857
858static void kone_remove_specials(struct hid_device *hdev) 748static void kone_remove_specials(struct hid_device *hdev)
859{ 749{
860 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 750 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
@@ -862,7 +752,6 @@ static void kone_remove_specials(struct hid_device *hdev)
862 752
863 if (intf->cur_altsetting->desc.bInterfaceProtocol 753 if (intf->cur_altsetting->desc.bInterfaceProtocol
864 == USB_INTERFACE_PROTOCOL_MOUSE) { 754 == USB_INTERFACE_PROTOCOL_MOUSE) {
865 kone_remove_sysfs_attributes(intf);
866 kone = hid_get_drvdata(hdev); 755 kone = hid_get_drvdata(hdev);
867 if (kone->roccat_claimed) 756 if (kone->roccat_claimed)
868 roccat_disconnect(kone->chrdev_minor); 757 roccat_disconnect(kone->chrdev_minor);
@@ -876,19 +765,19 @@ static int kone_probe(struct hid_device *hdev, const struct hid_device_id *id)
876 765
877 retval = hid_parse(hdev); 766 retval = hid_parse(hdev);
878 if (retval) { 767 if (retval) {
879 dev_err(&hdev->dev, "parse failed\n"); 768 hid_err(hdev, "parse failed\n");
880 goto exit; 769 goto exit;
881 } 770 }
882 771
883 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 772 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
884 if (retval) { 773 if (retval) {
885 dev_err(&hdev->dev, "hw start failed\n"); 774 hid_err(hdev, "hw start failed\n");
886 goto exit; 775 goto exit;
887 } 776 }
888 777
889 retval = kone_init_specials(hdev); 778 retval = kone_init_specials(hdev);
890 if (retval) { 779 if (retval) {
891 dev_err(&hdev->dev, "couldn't install mouse\n"); 780 hid_err(hdev, "couldn't install mouse\n");
892 goto exit_stop; 781 goto exit_stop;
893 } 782 }
894 783
@@ -1006,11 +895,24 @@ static struct hid_driver kone_driver = {
1006 895
1007static int __init kone_init(void) 896static int __init kone_init(void)
1008{ 897{
1009 return hid_register_driver(&kone_driver); 898 int retval;
899
900 /* class name has to be same as driver name */
901 kone_class = class_create(THIS_MODULE, "kone");
902 if (IS_ERR(kone_class))
903 return PTR_ERR(kone_class);
904 kone_class->dev_attrs = kone_attributes;
905 kone_class->dev_bin_attrs = kone_bin_attributes;
906
907 retval = hid_register_driver(&kone_driver);
908 if (retval)
909 class_destroy(kone_class);
910 return retval;
1010} 911}
1011 912
1012static void __exit kone_exit(void) 913static void __exit kone_exit(void)
1013{ 914{
915 class_destroy(kone_class);
1014 hid_unregister_driver(&kone_driver); 916 hid_unregister_driver(&kone_driver);
1015} 917}
1016 918
diff --git a/drivers/hid/hid-roccat-kone.h b/drivers/hid/hid-roccat-kone.h
index 130d6566ea82..64abb5b8a59a 100644
--- a/drivers/hid/hid-roccat-kone.h
+++ b/drivers/hid/hid-roccat-kone.h
@@ -14,14 +14,11 @@
14 14
15#include <linux/types.h> 15#include <linux/types.h>
16 16
17#pragma pack(push)
18#pragma pack(1)
19
20struct kone_keystroke { 17struct kone_keystroke {
21 uint8_t key; 18 uint8_t key;
22 uint8_t action; 19 uint8_t action;
23 uint16_t period; /* in milliseconds */ 20 uint16_t period; /* in milliseconds */
24}; 21} __attribute__ ((__packed__));
25 22
26enum kone_keystroke_buttons { 23enum kone_keystroke_buttons {
27 kone_keystroke_button_1 = 0xf0, /* left mouse button */ 24 kone_keystroke_button_1 = 0xf0, /* left mouse button */
@@ -44,7 +41,7 @@ struct kone_button_info {
44 uint8_t macro_name[16]; /* can be max 15 chars long */ 41 uint8_t macro_name[16]; /* can be max 15 chars long */
45 uint8_t count; 42 uint8_t count;
46 struct kone_keystroke keystrokes[20]; 43 struct kone_keystroke keystrokes[20];
47}; 44} __attribute__ ((__packed__));
48 45
49enum kone_button_info_types { 46enum kone_button_info_types {
50 /* valid button types until firmware 1.32 */ 47 /* valid button types until firmware 1.32 */
@@ -95,7 +92,7 @@ struct kone_light_info {
95 uint8_t red; /* range 0x00-0xff */ 92 uint8_t red; /* range 0x00-0xff */
96 uint8_t green; /* range 0x00-0xff */ 93 uint8_t green; /* range 0x00-0xff */
97 uint8_t blue; /* range 0x00-0xff */ 94 uint8_t blue; /* range 0x00-0xff */
98}; 95} __attribute__ ((__packed__));
99 96
100struct kone_profile { 97struct kone_profile {
101 uint16_t size; /* always 975 */ 98 uint16_t size; /* always 975 */
@@ -130,7 +127,7 @@ struct kone_profile {
130 struct kone_button_info button_infos[8]; 127 struct kone_button_info button_infos[8];
131 128
132 uint16_t checksum; /* \brief holds checksum of struct */ 129 uint16_t checksum; /* \brief holds checksum of struct */
133}; 130} __attribute__ ((__packed__));
134 131
135enum kone_polling_rates { 132enum kone_polling_rates {
136 kone_polling_rate_125 = 1, 133 kone_polling_rate_125 = 1,
@@ -147,7 +144,7 @@ struct kone_settings {
147 uint8_t calibration_data[4]; 144 uint8_t calibration_data[4];
148 uint8_t unknown3[2]; 145 uint8_t unknown3[2];
149 uint16_t checksum; 146 uint16_t checksum;
150}; 147} __attribute__ ((__packed__));
151 148
152/* 149/*
153 * 12 byte mouse event read by interrupt_read 150 * 12 byte mouse event read by interrupt_read
@@ -163,7 +160,7 @@ struct kone_mouse_event {
163 uint8_t event; 160 uint8_t event;
164 uint8_t value; /* press = 0, release = 1 */ 161 uint8_t value; /* press = 0, release = 1 */
165 uint8_t macro_key; /* 0 to 8 */ 162 uint8_t macro_key; /* 0 to 8 */
166}; 163} __attribute__ ((__packed__));
167 164
168enum kone_mouse_events { 165enum kone_mouse_events {
169 /* osd events are thought to be display on screen */ 166 /* osd events are thought to be display on screen */
@@ -191,9 +188,7 @@ struct kone_roccat_report {
191 uint8_t event; 188 uint8_t event;
192 uint8_t value; /* holds dpi or profile value */ 189 uint8_t value; /* holds dpi or profile value */
193 uint8_t key; /* macro key on overlong macro execution */ 190 uint8_t key; /* macro key on overlong macro execution */
194}; 191} __attribute__ ((__packed__));
195
196#pragma pack(pop)
197 192
198struct kone_device { 193struct kone_device {
199 /* 194 /*
diff --git a/drivers/hid/hid-roccat-koneplus.c b/drivers/hid/hid-roccat-koneplus.c
new file mode 100644
index 000000000000..1608c8d1efd6
--- /dev/null
+++ b/drivers/hid/hid-roccat-koneplus.c
@@ -0,0 +1,837 @@
1/*
2 * Roccat Kone[+] driver for Linux
3 *
4 * Copyright (c) 2010 Stefan Achatz <erazor_de@users.sourceforge.net>
5 */
6
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 as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 */
13
14/*
15 * Roccat Kone[+] is an updated/improved version of the Kone with more memory
16 * and functionality and without the non-standard behaviours the Kone had.
17 */
18
19#include <linux/device.h>
20#include <linux/input.h>
21#include <linux/hid.h>
22#include <linux/usb.h>
23#include <linux/module.h>
24#include <linux/slab.h>
25#include "hid-ids.h"
26#include "hid-roccat.h"
27#include "hid-roccat-koneplus.h"
28
29static uint profile_numbers[5] = {0, 1, 2, 3, 4};
30
31static struct class *koneplus_class;
32
33static void koneplus_profile_activated(struct koneplus_device *koneplus,
34 uint new_profile)
35{
36 koneplus->actual_profile = new_profile;
37}
38
39static int koneplus_send_control(struct usb_device *usb_dev, uint value,
40 enum koneplus_control_requests request)
41{
42 int len;
43 struct koneplus_control *control;
44
45 if ((request == KONEPLUS_CONTROL_REQUEST_PROFILE_SETTINGS ||
46 request == KONEPLUS_CONTROL_REQUEST_PROFILE_BUTTONS) &&
47 value > 4)
48 return -EINVAL;
49
50 control = kmalloc(sizeof(struct koneplus_control), GFP_KERNEL);
51 if (!control)
52 return -ENOMEM;
53
54 control->command = KONEPLUS_COMMAND_CONTROL;
55 control->value = value;
56 control->request = request;
57
58 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
59 USB_REQ_SET_CONFIGURATION,
60 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
61 KONEPLUS_USB_COMMAND_CONTROL, 0, control,
62 sizeof(struct koneplus_control),
63 USB_CTRL_SET_TIMEOUT);
64
65 kfree(control);
66
67 if (len != sizeof(struct koneplus_control))
68 return len;
69
70 return 0;
71}
72
73static int koneplus_receive(struct usb_device *usb_dev, uint usb_command,
74 void *buf, uint size) {
75 int len;
76
77 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
78 USB_REQ_CLEAR_FEATURE,
79 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
80 usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
81
82 return (len != size) ? -EIO : 0;
83}
84
85static int koneplus_receive_control_status(struct usb_device *usb_dev)
86{
87 int retval;
88 struct koneplus_control *control;
89
90 control = kmalloc(sizeof(struct koneplus_control), GFP_KERNEL);
91 if (!control)
92 return -ENOMEM;
93
94 do {
95 retval = koneplus_receive(usb_dev, KONEPLUS_USB_COMMAND_CONTROL,
96 control, sizeof(struct koneplus_control));
97
98 /* check if we get a completely wrong answer */
99 if (retval)
100 goto out;
101
102 if (control->value == KONEPLUS_CONTROL_REQUEST_STATUS_OK) {
103 retval = 0;
104 goto out;
105 }
106
107 /* indicates that hardware needs some more time to complete action */
108 if (control->value == KONEPLUS_CONTROL_REQUEST_STATUS_WAIT) {
109 msleep(500); /* windows driver uses 1000 */
110 continue;
111 }
112
113 /* seems to be critical - replug necessary */
114 if (control->value == KONEPLUS_CONTROL_REQUEST_STATUS_OVERLOAD) {
115 retval = -EINVAL;
116 goto out;
117 }
118
119 dev_err(&usb_dev->dev, "koneplus_receive_control_status: "
120 "unknown response value 0x%x\n", control->value);
121 retval = -EINVAL;
122 goto out;
123
124 } while (1);
125out:
126 kfree(control);
127 return retval;
128}
129
130static int koneplus_send(struct usb_device *usb_dev, uint command,
131 void *buf, uint size) {
132 int len;
133
134 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
135 USB_REQ_SET_CONFIGURATION,
136 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
137 command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
138
139 if (len != size)
140 return -EIO;
141
142 if (koneplus_receive_control_status(usb_dev))
143 return -EIO;
144
145 return 0;
146}
147
148static int koneplus_select_profile(struct usb_device *usb_dev, uint number,
149 enum koneplus_control_requests request)
150{
151 int retval;
152
153 retval = koneplus_send_control(usb_dev, number, request);
154 if (retval)
155 return retval;
156
157 /* allow time to settle things - windows driver uses 500 */
158 msleep(100);
159
160 retval = koneplus_receive_control_status(usb_dev);
161 if (retval)
162 return retval;
163
164 return 0;
165}
166
167static int koneplus_get_info(struct usb_device *usb_dev,
168 struct koneplus_info *buf)
169{
170 return koneplus_receive(usb_dev, KONEPLUS_USB_COMMAND_INFO,
171 buf, sizeof(struct koneplus_info));
172}
173
174static int koneplus_get_profile_settings(struct usb_device *usb_dev,
175 struct koneplus_profile_settings *buf, uint number)
176{
177 int retval;
178
179 retval = koneplus_select_profile(usb_dev, number,
180 KONEPLUS_CONTROL_REQUEST_PROFILE_SETTINGS);
181 if (retval)
182 return retval;
183
184 return koneplus_receive(usb_dev, KONEPLUS_USB_COMMAND_PROFILE_SETTINGS,
185 buf, sizeof(struct koneplus_profile_settings));
186}
187
188static int koneplus_set_profile_settings(struct usb_device *usb_dev,
189 struct koneplus_profile_settings const *settings)
190{
191 return koneplus_send(usb_dev, KONEPLUS_USB_COMMAND_PROFILE_SETTINGS,
192 (void *)settings, sizeof(struct koneplus_profile_settings));
193}
194
195static int koneplus_get_profile_buttons(struct usb_device *usb_dev,
196 struct koneplus_profile_buttons *buf, int number)
197{
198 int retval;
199
200 retval = koneplus_select_profile(usb_dev, number,
201 KONEPLUS_CONTROL_REQUEST_PROFILE_BUTTONS);
202 if (retval)
203 return retval;
204
205 return koneplus_receive(usb_dev, KONEPLUS_USB_COMMAND_PROFILE_BUTTONS,
206 buf, sizeof(struct koneplus_profile_buttons));
207}
208
209static int koneplus_set_profile_buttons(struct usb_device *usb_dev,
210 struct koneplus_profile_buttons const *buttons)
211{
212 return koneplus_send(usb_dev, KONEPLUS_USB_COMMAND_PROFILE_BUTTONS,
213 (void *)buttons, sizeof(struct koneplus_profile_buttons));
214}
215
216/* retval is 0-4 on success, < 0 on error */
217static int koneplus_get_startup_profile(struct usb_device *usb_dev)
218{
219 struct koneplus_startup_profile *buf;
220 int retval;
221
222 buf = kmalloc(sizeof(struct koneplus_startup_profile), GFP_KERNEL);
223
224 retval = koneplus_receive(usb_dev, KONEPLUS_USB_COMMAND_STARTUP_PROFILE,
225 buf, sizeof(struct koneplus_startup_profile));
226
227 if (retval)
228 goto out;
229
230 retval = buf->startup_profile;
231out:
232 kfree(buf);
233 return retval;
234}
235
236static int koneplus_set_startup_profile(struct usb_device *usb_dev,
237 int startup_profile)
238{
239 struct koneplus_startup_profile buf;
240
241 buf.command = KONEPLUS_COMMAND_STARTUP_PROFILE;
242 buf.size = sizeof(struct koneplus_startup_profile);
243 buf.startup_profile = startup_profile;
244
245 return koneplus_send(usb_dev, KONEPLUS_USB_COMMAND_STARTUP_PROFILE,
246 (char *)&buf, sizeof(struct koneplus_profile_buttons));
247}
248
249static ssize_t koneplus_sysfs_read(struct file *fp, struct kobject *kobj,
250 char *buf, loff_t off, size_t count,
251 size_t real_size, uint command)
252{
253 struct device *dev =
254 container_of(kobj, struct device, kobj)->parent->parent;
255 struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev));
256 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
257 int retval;
258
259 if (off != 0 || count != real_size)
260 return -EINVAL;
261
262 mutex_lock(&koneplus->koneplus_lock);
263 retval = koneplus_receive(usb_dev, command, buf, real_size);
264 mutex_unlock(&koneplus->koneplus_lock);
265
266 if (retval)
267 return retval;
268
269 return real_size;
270}
271
272static ssize_t koneplus_sysfs_write(struct file *fp, struct kobject *kobj,
273 void const *buf, loff_t off, size_t count,
274 size_t real_size, uint command)
275{
276 struct device *dev =
277 container_of(kobj, struct device, kobj)->parent->parent;
278 struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev));
279 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
280 int retval;
281
282 if (off != 0 || count != real_size)
283 return -EINVAL;
284
285 mutex_lock(&koneplus->koneplus_lock);
286 retval = koneplus_send(usb_dev, command, (void *)buf, real_size);
287 mutex_unlock(&koneplus->koneplus_lock);
288
289 if (retval)
290 return retval;
291
292 return real_size;
293}
294
295static ssize_t koneplus_sysfs_write_macro(struct file *fp,
296 struct kobject *kobj, struct bin_attribute *attr, char *buf,
297 loff_t off, size_t count)
298{
299 return koneplus_sysfs_write(fp, kobj, buf, off, count,
300 sizeof(struct koneplus_macro), KONEPLUS_USB_COMMAND_MACRO);
301}
302
303static ssize_t koneplus_sysfs_read_sensor(struct file *fp,
304 struct kobject *kobj, struct bin_attribute *attr, char *buf,
305 loff_t off, size_t count)
306{
307 return koneplus_sysfs_read(fp, kobj, buf, off, count,
308 sizeof(struct koneplus_sensor), KONEPLUS_USB_COMMAND_SENSOR);
309}
310
311static ssize_t koneplus_sysfs_write_sensor(struct file *fp,
312 struct kobject *kobj, struct bin_attribute *attr, char *buf,
313 loff_t off, size_t count)
314{
315 return koneplus_sysfs_write(fp, kobj, buf, off, count,
316 sizeof(struct koneplus_sensor), KONEPLUS_USB_COMMAND_SENSOR);
317}
318
319static ssize_t koneplus_sysfs_write_tcu(struct file *fp,
320 struct kobject *kobj, struct bin_attribute *attr, char *buf,
321 loff_t off, size_t count)
322{
323 return koneplus_sysfs_write(fp, kobj, buf, off, count,
324 sizeof(struct koneplus_tcu), KONEPLUS_USB_COMMAND_TCU);
325}
326
327static ssize_t koneplus_sysfs_read_tcu_image(struct file *fp,
328 struct kobject *kobj, struct bin_attribute *attr, char *buf,
329 loff_t off, size_t count)
330{
331 return koneplus_sysfs_read(fp, kobj, buf, off, count,
332 sizeof(struct koneplus_tcu_image), KONEPLUS_USB_COMMAND_TCU);
333}
334
335static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp,
336 struct kobject *kobj, struct bin_attribute *attr, char *buf,
337 loff_t off, size_t count)
338{
339 struct device *dev =
340 container_of(kobj, struct device, kobj)->parent->parent;
341 struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev));
342
343 if (off >= sizeof(struct koneplus_profile_settings))
344 return 0;
345
346 if (off + count > sizeof(struct koneplus_profile_settings))
347 count = sizeof(struct koneplus_profile_settings) - off;
348
349 mutex_lock(&koneplus->koneplus_lock);
350 memcpy(buf, ((void const *)&koneplus->profile_settings[*(uint *)(attr->private)]) + off,
351 count);
352 mutex_unlock(&koneplus->koneplus_lock);
353
354 return count;
355}
356
357static ssize_t koneplus_sysfs_write_profile_settings(struct file *fp,
358 struct kobject *kobj, struct bin_attribute *attr, char *buf,
359 loff_t off, size_t count)
360{
361 struct device *dev =
362 container_of(kobj, struct device, kobj)->parent->parent;
363 struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev));
364 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
365 int retval = 0;
366 int difference;
367 int profile_number;
368 struct koneplus_profile_settings *profile_settings;
369
370 if (off != 0 || count != sizeof(struct koneplus_profile_settings))
371 return -EINVAL;
372
373 profile_number = ((struct koneplus_profile_settings const *)buf)->number;
374 profile_settings = &koneplus->profile_settings[profile_number];
375
376 mutex_lock(&koneplus->koneplus_lock);
377 difference = memcmp(buf, profile_settings,
378 sizeof(struct koneplus_profile_settings));
379 if (difference) {
380 retval = koneplus_set_profile_settings(usb_dev,
381 (struct koneplus_profile_settings const *)buf);
382 if (!retval)
383 memcpy(profile_settings, buf,
384 sizeof(struct koneplus_profile_settings));
385 }
386 mutex_unlock(&koneplus->koneplus_lock);
387
388 if (retval)
389 return retval;
390
391 return sizeof(struct koneplus_profile_settings);
392}
393
394static ssize_t koneplus_sysfs_read_profilex_buttons(struct file *fp,
395 struct kobject *kobj, struct bin_attribute *attr, char *buf,
396 loff_t off, size_t count)
397{
398 struct device *dev =
399 container_of(kobj, struct device, kobj)->parent->parent;
400 struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev));
401
402 if (off >= sizeof(struct koneplus_profile_buttons))
403 return 0;
404
405 if (off + count > sizeof(struct koneplus_profile_buttons))
406 count = sizeof(struct koneplus_profile_buttons) - off;
407
408 mutex_lock(&koneplus->koneplus_lock);
409 memcpy(buf, ((void const *)&koneplus->profile_buttons[*(uint *)(attr->private)]) + off,
410 count);
411 mutex_unlock(&koneplus->koneplus_lock);
412
413 return count;
414}
415
416static ssize_t koneplus_sysfs_write_profile_buttons(struct file *fp,
417 struct kobject *kobj, struct bin_attribute *attr, char *buf,
418 loff_t off, size_t count)
419{
420 struct device *dev =
421 container_of(kobj, struct device, kobj)->parent->parent;
422 struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev));
423 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
424 int retval = 0;
425 int difference;
426 uint profile_number;
427 struct koneplus_profile_buttons *profile_buttons;
428
429 if (off != 0 || count != sizeof(struct koneplus_profile_buttons))
430 return -EINVAL;
431
432 profile_number = ((struct koneplus_profile_buttons const *)buf)->number;
433 profile_buttons = &koneplus->profile_buttons[profile_number];
434
435 mutex_lock(&koneplus->koneplus_lock);
436 difference = memcmp(buf, profile_buttons,
437 sizeof(struct koneplus_profile_buttons));
438 if (difference) {
439 retval = koneplus_set_profile_buttons(usb_dev,
440 (struct koneplus_profile_buttons const *)buf);
441 if (!retval)
442 memcpy(profile_buttons, buf,
443 sizeof(struct koneplus_profile_buttons));
444 }
445 mutex_unlock(&koneplus->koneplus_lock);
446
447 if (retval)
448 return retval;
449
450 return sizeof(struct koneplus_profile_buttons);
451}
452
453static ssize_t koneplus_sysfs_show_startup_profile(struct device *dev,
454 struct device_attribute *attr, char *buf)
455{
456 struct koneplus_device *koneplus =
457 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
458 return snprintf(buf, PAGE_SIZE, "%d\n", koneplus->startup_profile);
459}
460
461static ssize_t koneplus_sysfs_set_startup_profile(struct device *dev,
462 struct device_attribute *attr, char const *buf, size_t size)
463{
464 struct koneplus_device *koneplus;
465 struct usb_device *usb_dev;
466 unsigned long profile;
467 int retval;
468
469 dev = dev->parent->parent;
470 koneplus = hid_get_drvdata(dev_get_drvdata(dev));
471 usb_dev = interface_to_usbdev(to_usb_interface(dev));
472
473 retval = strict_strtoul(buf, 10, &profile);
474 if (retval)
475 return retval;
476
477 mutex_lock(&koneplus->koneplus_lock);
478 retval = koneplus_set_startup_profile(usb_dev, profile);
479 mutex_unlock(&koneplus->koneplus_lock);
480 if (retval)
481 return retval;
482
483 return size;
484}
485
486static ssize_t koneplus_sysfs_show_actual_profile(struct device *dev,
487 struct device_attribute *attr, char *buf)
488{
489 struct koneplus_device *koneplus =
490 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
491 return snprintf(buf, PAGE_SIZE, "%d\n", koneplus->actual_profile);
492}
493
494static ssize_t koneplus_sysfs_show_firmware_version(struct device *dev,
495 struct device_attribute *attr, char *buf)
496{
497 struct koneplus_device *koneplus =
498 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
499 return snprintf(buf, PAGE_SIZE, "%d\n", koneplus->info.firmware_version);
500}
501
502static struct device_attribute koneplus_attributes[] = {
503 __ATTR(startup_profile, 0660,
504 koneplus_sysfs_show_startup_profile,
505 koneplus_sysfs_set_startup_profile),
506 __ATTR(actual_profile, 0440,
507 koneplus_sysfs_show_actual_profile, NULL),
508 __ATTR(firmware_version, 0440,
509 koneplus_sysfs_show_firmware_version, NULL),
510 __ATTR_NULL
511};
512
513static struct bin_attribute koneplus_bin_attributes[] = {
514 {
515 .attr = { .name = "sensor", .mode = 0220 },
516 .size = sizeof(struct koneplus_sensor),
517 .read = koneplus_sysfs_read_sensor,
518 .write = koneplus_sysfs_write_sensor
519 },
520 {
521 .attr = { .name = "tcu", .mode = 0220 },
522 .size = sizeof(struct koneplus_tcu),
523 .write = koneplus_sysfs_write_tcu
524 },
525 {
526 .attr = { .name = "tcu_image", .mode = 0440 },
527 .size = sizeof(struct koneplus_tcu_image),
528 .read = koneplus_sysfs_read_tcu_image
529 },
530 {
531 .attr = { .name = "profile_settings", .mode = 0220 },
532 .size = sizeof(struct koneplus_profile_settings),
533 .write = koneplus_sysfs_write_profile_settings
534 },
535 {
536 .attr = { .name = "profile1_settings", .mode = 0440 },
537 .size = sizeof(struct koneplus_profile_settings),
538 .read = koneplus_sysfs_read_profilex_settings,
539 .private = &profile_numbers[0]
540 },
541 {
542 .attr = { .name = "profile2_settings", .mode = 0440 },
543 .size = sizeof(struct koneplus_profile_settings),
544 .read = koneplus_sysfs_read_profilex_settings,
545 .private = &profile_numbers[1]
546 },
547 {
548 .attr = { .name = "profile3_settings", .mode = 0440 },
549 .size = sizeof(struct koneplus_profile_settings),
550 .read = koneplus_sysfs_read_profilex_settings,
551 .private = &profile_numbers[2]
552 },
553 {
554 .attr = { .name = "profile4_settings", .mode = 0440 },
555 .size = sizeof(struct koneplus_profile_settings),
556 .read = koneplus_sysfs_read_profilex_settings,
557 .private = &profile_numbers[3]
558 },
559 {
560 .attr = { .name = "profile5_settings", .mode = 0440 },
561 .size = sizeof(struct koneplus_profile_settings),
562 .read = koneplus_sysfs_read_profilex_settings,
563 .private = &profile_numbers[4]
564 },
565 {
566 .attr = { .name = "profile_buttons", .mode = 0220 },
567 .size = sizeof(struct koneplus_profile_buttons),
568 .write = koneplus_sysfs_write_profile_buttons
569 },
570 {
571 .attr = { .name = "profile1_buttons", .mode = 0440 },
572 .size = sizeof(struct koneplus_profile_buttons),
573 .read = koneplus_sysfs_read_profilex_buttons,
574 .private = &profile_numbers[0]
575 },
576 {
577 .attr = { .name = "profile2_buttons", .mode = 0440 },
578 .size = sizeof(struct koneplus_profile_buttons),
579 .read = koneplus_sysfs_read_profilex_buttons,
580 .private = &profile_numbers[1]
581 },
582 {
583 .attr = { .name = "profile3_buttons", .mode = 0440 },
584 .size = sizeof(struct koneplus_profile_buttons),
585 .read = koneplus_sysfs_read_profilex_buttons,
586 .private = &profile_numbers[2]
587 },
588 {
589 .attr = { .name = "profile4_buttons", .mode = 0440 },
590 .size = sizeof(struct koneplus_profile_buttons),
591 .read = koneplus_sysfs_read_profilex_buttons,
592 .private = &profile_numbers[3]
593 },
594 {
595 .attr = { .name = "profile5_buttons", .mode = 0440 },
596 .size = sizeof(struct koneplus_profile_buttons),
597 .read = koneplus_sysfs_read_profilex_buttons,
598 .private = &profile_numbers[4]
599 },
600 {
601 .attr = { .name = "macro", .mode = 0220 },
602 .size = sizeof(struct koneplus_macro),
603 .write = koneplus_sysfs_write_macro
604 },
605 __ATTR_NULL
606};
607
608static int koneplus_init_koneplus_device_struct(struct usb_device *usb_dev,
609 struct koneplus_device *koneplus)
610{
611 int retval, i;
612 static uint wait = 70; /* device will freeze with just 60 */
613
614 mutex_init(&koneplus->koneplus_lock);
615
616 koneplus->startup_profile = koneplus_get_startup_profile(usb_dev);
617
618 msleep(wait);
619 retval = koneplus_get_info(usb_dev, &koneplus->info);
620 if (retval)
621 return retval;
622
623 for (i = 0; i < 5; ++i) {
624 msleep(wait);
625 retval = koneplus_get_profile_settings(usb_dev,
626 &koneplus->profile_settings[i], i);
627 if (retval)
628 return retval;
629
630 msleep(wait);
631 retval = koneplus_get_profile_buttons(usb_dev,
632 &koneplus->profile_buttons[i], i);
633 if (retval)
634 return retval;
635 }
636
637 koneplus_profile_activated(koneplus, koneplus->startup_profile);
638
639 return 0;
640}
641
642static int koneplus_init_specials(struct hid_device *hdev)
643{
644 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
645 struct usb_device *usb_dev = interface_to_usbdev(intf);
646 struct koneplus_device *koneplus;
647 int retval;
648
649 if (intf->cur_altsetting->desc.bInterfaceProtocol
650 == USB_INTERFACE_PROTOCOL_MOUSE) {
651
652 koneplus = kzalloc(sizeof(*koneplus), GFP_KERNEL);
653 if (!koneplus) {
654 dev_err(&hdev->dev, "can't alloc device descriptor\n");
655 return -ENOMEM;
656 }
657 hid_set_drvdata(hdev, koneplus);
658
659 retval = koneplus_init_koneplus_device_struct(usb_dev, koneplus);
660 if (retval) {
661 dev_err(&hdev->dev,
662 "couldn't init struct koneplus_device\n");
663 goto exit_free;
664 }
665
666 retval = roccat_connect(koneplus_class, hdev);
667 if (retval < 0) {
668 dev_err(&hdev->dev, "couldn't init char dev\n");
669 } else {
670 koneplus->chrdev_minor = retval;
671 koneplus->roccat_claimed = 1;
672 }
673 } else {
674 hid_set_drvdata(hdev, NULL);
675 }
676
677 return 0;
678exit_free:
679 kfree(koneplus);
680 return retval;
681}
682
683static void koneplus_remove_specials(struct hid_device *hdev)
684{
685 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
686 struct koneplus_device *koneplus;
687
688 if (intf->cur_altsetting->desc.bInterfaceProtocol
689 == USB_INTERFACE_PROTOCOL_MOUSE) {
690 koneplus = hid_get_drvdata(hdev);
691 if (koneplus->roccat_claimed)
692 roccat_disconnect(koneplus->chrdev_minor);
693 kfree(koneplus);
694 }
695}
696
697static int koneplus_probe(struct hid_device *hdev,
698 const struct hid_device_id *id)
699{
700 int retval;
701
702 retval = hid_parse(hdev);
703 if (retval) {
704 dev_err(&hdev->dev, "parse failed\n");
705 goto exit;
706 }
707
708 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
709 if (retval) {
710 dev_err(&hdev->dev, "hw start failed\n");
711 goto exit;
712 }
713
714 retval = koneplus_init_specials(hdev);
715 if (retval) {
716 dev_err(&hdev->dev, "couldn't install mouse\n");
717 goto exit_stop;
718 }
719
720 return 0;
721
722exit_stop:
723 hid_hw_stop(hdev);
724exit:
725 return retval;
726}
727
728static void koneplus_remove(struct hid_device *hdev)
729{
730 koneplus_remove_specials(hdev);
731 hid_hw_stop(hdev);
732}
733
734static void koneplus_keep_values_up_to_date(struct koneplus_device *koneplus,
735 u8 const *data)
736{
737 struct koneplus_mouse_report_button const *button_report;
738
739 switch (data[0]) {
740 case KONEPLUS_MOUSE_REPORT_NUMBER_BUTTON:
741 button_report = (struct koneplus_mouse_report_button const *)data;
742 switch (button_report->type) {
743 case KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE:
744 koneplus_profile_activated(koneplus, button_report->data1 - 1);
745 break;
746 }
747 break;
748 }
749}
750
751static void koneplus_report_to_chrdev(struct koneplus_device const *koneplus,
752 u8 const *data)
753{
754 struct koneplus_roccat_report roccat_report;
755 struct koneplus_mouse_report_button const *button_report;
756
757 if (data[0] != KONEPLUS_MOUSE_REPORT_NUMBER_BUTTON)
758 return;
759
760 button_report = (struct koneplus_mouse_report_button const *)data;
761
762 if ((button_report->type == KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_QUICKLAUNCH ||
763 button_report->type == KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_TIMER) &&
764 button_report->data2 != KONEPLUS_MOUSE_REPORT_BUTTON_ACTION_PRESS)
765 return;
766
767 roccat_report.type = button_report->type;
768 roccat_report.data1 = button_report->data1;
769 roccat_report.data2 = button_report->data2;
770 roccat_report.profile = koneplus->actual_profile + 1;
771 roccat_report_event(koneplus->chrdev_minor,
772 (uint8_t const *)&roccat_report,
773 sizeof(struct koneplus_roccat_report));
774}
775
776static int koneplus_raw_event(struct hid_device *hdev,
777 struct hid_report *report, u8 *data, int size)
778{
779 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
780 struct koneplus_device *koneplus = hid_get_drvdata(hdev);
781
782 if (intf->cur_altsetting->desc.bInterfaceProtocol
783 != USB_INTERFACE_PROTOCOL_MOUSE)
784 return 0;
785
786 koneplus_keep_values_up_to_date(koneplus, data);
787
788 if (koneplus->roccat_claimed)
789 koneplus_report_to_chrdev(koneplus, data);
790
791 return 0;
792}
793
794static const struct hid_device_id koneplus_devices[] = {
795 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
796 { }
797};
798
799MODULE_DEVICE_TABLE(hid, koneplus_devices);
800
801static struct hid_driver koneplus_driver = {
802 .name = "koneplus",
803 .id_table = koneplus_devices,
804 .probe = koneplus_probe,
805 .remove = koneplus_remove,
806 .raw_event = koneplus_raw_event
807};
808
809static int __init koneplus_init(void)
810{
811 int retval;
812
813 /* class name has to be same as driver name */
814 koneplus_class = class_create(THIS_MODULE, "koneplus");
815 if (IS_ERR(koneplus_class))
816 return PTR_ERR(koneplus_class);
817 koneplus_class->dev_attrs = koneplus_attributes;
818 koneplus_class->dev_bin_attrs = koneplus_bin_attributes;
819
820 retval = hid_register_driver(&koneplus_driver);
821 if (retval)
822 class_destroy(koneplus_class);
823 return retval;
824}
825
826static void __exit koneplus_exit(void)
827{
828 class_destroy(koneplus_class);
829 hid_unregister_driver(&koneplus_driver);
830}
831
832module_init(koneplus_init);
833module_exit(koneplus_exit);
834
835MODULE_AUTHOR("Stefan Achatz");
836MODULE_DESCRIPTION("USB Roccat Kone[+] driver");
837MODULE_LICENSE("GPL v2");
diff --git a/drivers/hid/hid-roccat-koneplus.h b/drivers/hid/hid-roccat-koneplus.h
new file mode 100644
index 000000000000..57a5c1ab7b05
--- /dev/null
+++ b/drivers/hid/hid-roccat-koneplus.h
@@ -0,0 +1,224 @@
1#ifndef __HID_ROCCAT_KONEPLUS_H
2#define __HID_ROCCAT_KONEPLUS_H
3
4/*
5 * Copyright (c) 2010 Stefan Achatz <erazor_de@users.sourceforge.net>
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/types.h>
16
17/*
18 * case 1: writes request 80 and reads value 1
19 *
20 */
21struct koneplus_control {
22 uint8_t command; /* KONEPLUS_COMMAND_CONTROL */
23 /*
24 * value is profile number in range 0-4 for requesting settings and buttons
25 * 1 if status ok for requesting status
26 */
27 uint8_t value;
28 uint8_t request;
29} __attribute__ ((__packed__));
30
31enum koneplus_control_requests {
32 KONEPLUS_CONTROL_REQUEST_STATUS = 0x00,
33 KONEPLUS_CONTROL_REQUEST_PROFILE_SETTINGS = 0x80,
34 KONEPLUS_CONTROL_REQUEST_PROFILE_BUTTONS = 0x90,
35};
36
37enum koneplus_control_values {
38 KONEPLUS_CONTROL_REQUEST_STATUS_OVERLOAD = 0,
39 KONEPLUS_CONTROL_REQUEST_STATUS_OK = 1,
40 KONEPLUS_CONTROL_REQUEST_STATUS_WAIT = 3,
41};
42
43struct koneplus_startup_profile {
44 uint8_t command; /* KONEPLUS_COMMAND_STARTUP_PROFILE */
45 uint8_t size; /* always 3 */
46 uint8_t startup_profile; /* Range 0-4! */
47} __attribute__ ((__packed__));
48
49struct koneplus_profile_settings {
50 uint8_t command; /* KONEPLUS_COMMAND_PROFILE_SETTINGS */
51 uint8_t size; /* always 43 */
52 uint8_t number; /* range 0-4 */
53 uint8_t advanced_sensitivity;
54 uint8_t sensitivity_x;
55 uint8_t sensitivity_y;
56 uint8_t cpi_levels_enabled;
57 uint8_t cpi_levels_x[5];
58 uint8_t cpi_startup_level; /* range 0-4 */
59 uint8_t cpi_levels_y[5]; /* range 1-60 means 100-6000 cpi */
60 uint8_t unknown1;
61 uint8_t polling_rate;
62 uint8_t lights_enabled;
63 uint8_t light_effect_mode;
64 uint8_t color_flow_effect;
65 uint8_t light_effect_type;
66 uint8_t light_effect_speed;
67 uint8_t lights[16];
68 uint16_t checksum;
69} __attribute__ ((__packed__));
70
71struct koneplus_profile_buttons {
72 uint8_t command; /* KONEPLUS_COMMAND_PROFILE_BUTTONS */
73 uint8_t size; /* always 77 */
74 uint8_t number; /* range 0-4 */
75 uint8_t data[72];
76 uint16_t checksum;
77} __attribute__ ((__packed__));
78
79struct koneplus_macro {
80 uint8_t command; /* KONEPLUS_COMMAND_MACRO */
81 uint16_t size; /* always 0x822 little endian */
82 uint8_t profile; /* range 0-4 */
83 uint8_t button; /* range 0-23 */
84 uint8_t data[2075];
85 uint16_t checksum;
86} __attribute__ ((__packed__));
87
88struct koneplus_info {
89 uint8_t command; /* KONEPLUS_COMMAND_INFO */
90 uint8_t size; /* always 6 */
91 uint8_t firmware_version;
92 uint8_t unknown[3];
93} __attribute__ ((__packed__));
94
95struct koneplus_e {
96 uint8_t command; /* KONEPLUS_COMMAND_E */
97 uint8_t size; /* always 3 */
98 uint8_t unknown; /* TODO 1; 0 before firmware update */
99} __attribute__ ((__packed__));
100
101struct koneplus_sensor {
102 uint8_t command; /* KONEPLUS_COMMAND_SENSOR */
103 uint8_t size; /* always 6 */
104 uint8_t data[4];
105} __attribute__ ((__packed__));
106
107struct koneplus_firmware_write {
108 uint8_t command; /* KONEPLUS_COMMAND_FIRMWARE_WRITE */
109 uint8_t unknown[1025];
110} __attribute__ ((__packed__));
111
112struct koneplus_firmware_write_control {
113 uint8_t command; /* KONEPLUS_COMMAND_FIRMWARE_WRITE_CONTROL */
114 /*
115 * value is 1 on success
116 * 3 means "not finished yet"
117 */
118 uint8_t value;
119 uint8_t unknown; /* always 0x75 */
120} __attribute__ ((__packed__));
121
122struct koneplus_tcu {
123 uint16_t usb_command; /* KONEPLUS_USB_COMMAND_TCU */
124 uint8_t data[2];
125} __attribute__ ((__packed__));
126
127struct koneplus_tcu_image {
128 uint16_t usb_command; /* KONEPLUS_USB_COMMAND_TCU */
129 uint8_t data[1024];
130 uint16_t checksum;
131} __attribute__ ((__packed__));
132
133enum koneplus_commands {
134 KONEPLUS_COMMAND_CONTROL = 0x4,
135 KONEPLUS_COMMAND_STARTUP_PROFILE = 0x5,
136 KONEPLUS_COMMAND_PROFILE_SETTINGS = 0x6,
137 KONEPLUS_COMMAND_PROFILE_BUTTONS = 0x7,
138 KONEPLUS_COMMAND_MACRO = 0x8,
139 KONEPLUS_COMMAND_INFO = 0x9,
140 KONEPLUS_COMMAND_E = 0xe,
141 KONEPLUS_COMMAND_SENSOR = 0xf,
142 KONEPLUS_COMMAND_FIRMWARE_WRITE = 0x1b,
143 KONEPLUS_COMMAND_FIRMWARE_WRITE_CONTROL = 0x1c,
144};
145
146enum koneplus_usb_commands {
147 KONEPLUS_USB_COMMAND_CONTROL = 0x304,
148 KONEPLUS_USB_COMMAND_STARTUP_PROFILE = 0x305,
149 KONEPLUS_USB_COMMAND_PROFILE_SETTINGS = 0x306,
150 KONEPLUS_USB_COMMAND_PROFILE_BUTTONS = 0x307,
151 KONEPLUS_USB_COMMAND_MACRO = 0x308,
152 KONEPLUS_USB_COMMAND_INFO = 0x309,
153 KONEPLUS_USB_COMMAND_TCU = 0x30c,
154 KONEPLUS_USB_COMMAND_E = 0x30e,
155 KONEPLUS_USB_COMMAND_SENSOR = 0x30f,
156 KONEPLUS_USB_COMMAND_FIRMWARE_WRITE = 0x31b,
157 KONEPLUS_USB_COMMAND_FIRMWARE_WRITE_CONTROL = 0x31c,
158};
159
160enum koneplus_mouse_report_numbers {
161 KONEPLUS_MOUSE_REPORT_NUMBER_HID = 1,
162 KONEPLUS_MOUSE_REPORT_NUMBER_AUDIO = 2,
163 KONEPLUS_MOUSE_REPORT_NUMBER_BUTTON = 3,
164};
165
166struct koneplus_mouse_report_button {
167 uint8_t report_number; /* always KONEPLUS_MOUSE_REPORT_NUMBER_BUTTON */
168 uint8_t zero1;
169 uint8_t type;
170 uint8_t data1;
171 uint8_t data2;
172 uint8_t zero2;
173 uint8_t unknown[2];
174} __attribute__ ((__packed__));
175
176enum koneplus_mouse_report_button_types {
177 /* data1 = new profile range 1-5 */
178 KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE = 0x20,
179
180 /* data1 = button number range 1-24; data2 = action */
181 KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_QUICKLAUNCH = 0x60,
182
183 /* data1 = button number range 1-24; data2 = action */
184 KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_TIMER = 0x80,
185
186 /* data1 = setting number range 1-5 */
187 KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI = 0xb0,
188
189 /* data1 and data2 = range 0x1-0xb */
190 KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_SENSITIVITY = 0xc0,
191
192 /* data1 = 22 = next track...
193 * data2 = action
194 */
195 KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_MULTIMEDIA = 0xf0,
196};
197
198enum koneplus_mouse_report_button_action {
199 KONEPLUS_MOUSE_REPORT_BUTTON_ACTION_PRESS = 0,
200 KONEPLUS_MOUSE_REPORT_BUTTON_ACTION_RELEASE = 1,
201};
202
203struct koneplus_roccat_report {
204 uint8_t type;
205 uint8_t data1;
206 uint8_t data2;
207 uint8_t profile;
208} __attribute__ ((__packed__));
209
210struct koneplus_device {
211 int actual_profile;
212
213 int roccat_claimed;
214 int chrdev_minor;
215
216 struct mutex koneplus_lock;
217
218 int startup_profile;
219 struct koneplus_info info;
220 struct koneplus_profile_settings profile_settings[5];
221 struct koneplus_profile_buttons profile_buttons[5];
222};
223
224#endif
diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c
index 9bf23047892a..02c58e015bee 100644
--- a/drivers/hid/hid-roccat-pyra.c
+++ b/drivers/hid/hid-roccat-pyra.c
@@ -27,6 +27,11 @@
27#include "hid-roccat.h" 27#include "hid-roccat.h"
28#include "hid-roccat-pyra.h" 28#include "hid-roccat-pyra.h"
29 29
30static uint profile_numbers[5] = {0, 1, 2, 3, 4};
31
32/* pyra_class is used for creating sysfs attributes via roccat char device */
33static struct class *pyra_class;
34
30static void profile_activated(struct pyra_device *pyra, 35static void profile_activated(struct pyra_device *pyra,
31 unsigned int new_profile) 36 unsigned int new_profile)
32{ 37{
@@ -87,9 +92,8 @@ static int pyra_receive_control_status(struct usb_device *usb_dev)
87 control.value == 1) 92 control.value == 1)
88 return 0; 93 return 0;
89 else { 94 else {
90 dev_err(&usb_dev->dev, "receive control status: " 95 hid_err(usb_dev, "receive control status: unknown response 0x%x 0x%x\n",
91 "unknown response 0x%x 0x%x\n", 96 control.request, control.value);
92 control.request, control.value);
93 return -EINVAL; 97 return -EINVAL;
94 } 98 }
95} 99}
@@ -221,9 +225,10 @@ static int pyra_set_settings(struct usb_device *usb_dev,
221 225
222static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, 226static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp,
223 struct kobject *kobj, struct bin_attribute *attr, char *buf, 227 struct kobject *kobj, struct bin_attribute *attr, char *buf,
224 loff_t off, size_t count, int number) 228 loff_t off, size_t count)
225{ 229{
226 struct device *dev = container_of(kobj, struct device, kobj); 230 struct device *dev =
231 container_of(kobj, struct device, kobj)->parent->parent;
227 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 232 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
228 233
229 if (off >= sizeof(struct pyra_profile_settings)) 234 if (off >= sizeof(struct pyra_profile_settings))
@@ -233,58 +238,19 @@ static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp,
233 count = sizeof(struct pyra_profile_settings) - off; 238 count = sizeof(struct pyra_profile_settings) - off;
234 239
235 mutex_lock(&pyra->pyra_lock); 240 mutex_lock(&pyra->pyra_lock);
236 memcpy(buf, ((char const *)&pyra->profile_settings[number]) + off, 241 memcpy(buf, ((char const *)&pyra->profile_settings[*(uint *)(attr->private)]) + off,
237 count); 242 count);
238 mutex_unlock(&pyra->pyra_lock); 243 mutex_unlock(&pyra->pyra_lock);
239 244
240 return count; 245 return count;
241} 246}
242 247
243static ssize_t pyra_sysfs_read_profile1_settings(struct file *fp,
244 struct kobject *kobj, struct bin_attribute *attr, char *buf,
245 loff_t off, size_t count)
246{
247 return pyra_sysfs_read_profilex_settings(fp, kobj,
248 attr, buf, off, count, 0);
249}
250
251static ssize_t pyra_sysfs_read_profile2_settings(struct file *fp,
252 struct kobject *kobj, struct bin_attribute *attr, char *buf,
253 loff_t off, size_t count)
254{
255 return pyra_sysfs_read_profilex_settings(fp, kobj,
256 attr, buf, off, count, 1);
257}
258
259static ssize_t pyra_sysfs_read_profile3_settings(struct file *fp,
260 struct kobject *kobj, struct bin_attribute *attr, char *buf,
261 loff_t off, size_t count)
262{
263 return pyra_sysfs_read_profilex_settings(fp, kobj,
264 attr, buf, off, count, 2);
265}
266
267static ssize_t pyra_sysfs_read_profile4_settings(struct file *fp,
268 struct kobject *kobj, struct bin_attribute *attr, char *buf,
269 loff_t off, size_t count)
270{
271 return pyra_sysfs_read_profilex_settings(fp, kobj,
272 attr, buf, off, count, 3);
273}
274
275static ssize_t pyra_sysfs_read_profile5_settings(struct file *fp,
276 struct kobject *kobj, struct bin_attribute *attr, char *buf,
277 loff_t off, size_t count)
278{
279 return pyra_sysfs_read_profilex_settings(fp, kobj,
280 attr, buf, off, count, 4);
281}
282
283static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, 248static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp,
284 struct kobject *kobj, struct bin_attribute *attr, char *buf, 249 struct kobject *kobj, struct bin_attribute *attr, char *buf,
285 loff_t off, size_t count, int number) 250 loff_t off, size_t count)
286{ 251{
287 struct device *dev = container_of(kobj, struct device, kobj); 252 struct device *dev =
253 container_of(kobj, struct device, kobj)->parent->parent;
288 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 254 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
289 255
290 if (off >= sizeof(struct pyra_profile_buttons)) 256 if (off >= sizeof(struct pyra_profile_buttons))
@@ -294,58 +260,19 @@ static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp,
294 count = sizeof(struct pyra_profile_buttons) - off; 260 count = sizeof(struct pyra_profile_buttons) - off;
295 261
296 mutex_lock(&pyra->pyra_lock); 262 mutex_lock(&pyra->pyra_lock);
297 memcpy(buf, ((char const *)&pyra->profile_buttons[number]) + off, 263 memcpy(buf, ((char const *)&pyra->profile_buttons[*(uint *)(attr->private)]) + off,
298 count); 264 count);
299 mutex_unlock(&pyra->pyra_lock); 265 mutex_unlock(&pyra->pyra_lock);
300 266
301 return count; 267 return count;
302} 268}
303 269
304static ssize_t pyra_sysfs_read_profile1_buttons(struct file *fp,
305 struct kobject *kobj, struct bin_attribute *attr, char *buf,
306 loff_t off, size_t count)
307{
308 return pyra_sysfs_read_profilex_buttons(fp, kobj,
309 attr, buf, off, count, 0);
310}
311
312static ssize_t pyra_sysfs_read_profile2_buttons(struct file *fp,
313 struct kobject *kobj, struct bin_attribute *attr, char *buf,
314 loff_t off, size_t count)
315{
316 return pyra_sysfs_read_profilex_buttons(fp, kobj,
317 attr, buf, off, count, 1);
318}
319
320static ssize_t pyra_sysfs_read_profile3_buttons(struct file *fp,
321 struct kobject *kobj, struct bin_attribute *attr, char *buf,
322 loff_t off, size_t count)
323{
324 return pyra_sysfs_read_profilex_buttons(fp, kobj,
325 attr, buf, off, count, 2);
326}
327
328static ssize_t pyra_sysfs_read_profile4_buttons(struct file *fp,
329 struct kobject *kobj, struct bin_attribute *attr, char *buf,
330 loff_t off, size_t count)
331{
332 return pyra_sysfs_read_profilex_buttons(fp, kobj,
333 attr, buf, off, count, 3);
334}
335
336static ssize_t pyra_sysfs_read_profile5_buttons(struct file *fp,
337 struct kobject *kobj, struct bin_attribute *attr, char *buf,
338 loff_t off, size_t count)
339{
340 return pyra_sysfs_read_profilex_buttons(fp, kobj,
341 attr, buf, off, count, 4);
342}
343
344static ssize_t pyra_sysfs_write_profile_settings(struct file *fp, 270static ssize_t pyra_sysfs_write_profile_settings(struct file *fp,
345 struct kobject *kobj, struct bin_attribute *attr, char *buf, 271 struct kobject *kobj, struct bin_attribute *attr, char *buf,
346 loff_t off, size_t count) 272 loff_t off, size_t count)
347{ 273{
348 struct device *dev = container_of(kobj, struct device, kobj); 274 struct device *dev =
275 container_of(kobj, struct device, kobj)->parent->parent;
349 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 276 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
350 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 277 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
351 int retval = 0; 278 int retval = 0;
@@ -381,7 +308,8 @@ static ssize_t pyra_sysfs_write_profile_buttons(struct file *fp,
381 struct kobject *kobj, struct bin_attribute *attr, char *buf, 308 struct kobject *kobj, struct bin_attribute *attr, char *buf,
382 loff_t off, size_t count) 309 loff_t off, size_t count)
383{ 310{
384 struct device *dev = container_of(kobj, struct device, kobj); 311 struct device *dev =
312 container_of(kobj, struct device, kobj)->parent->parent;
385 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 313 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
386 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 314 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
387 int retval = 0; 315 int retval = 0;
@@ -417,7 +345,8 @@ static ssize_t pyra_sysfs_read_settings(struct file *fp,
417 struct kobject *kobj, struct bin_attribute *attr, char *buf, 345 struct kobject *kobj, struct bin_attribute *attr, char *buf,
418 loff_t off, size_t count) 346 loff_t off, size_t count)
419{ 347{
420 struct device *dev = container_of(kobj, struct device, kobj); 348 struct device *dev =
349 container_of(kobj, struct device, kobj)->parent->parent;
421 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 350 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
422 351
423 if (off >= sizeof(struct pyra_settings)) 352 if (off >= sizeof(struct pyra_settings))
@@ -437,7 +366,8 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp,
437 struct kobject *kobj, struct bin_attribute *attr, char *buf, 366 struct kobject *kobj, struct bin_attribute *attr, char *buf,
438 loff_t off, size_t count) 367 loff_t off, size_t count)
439{ 368{
440 struct device *dev = container_of(kobj, struct device, kobj); 369 struct device *dev =
370 container_of(kobj, struct device, kobj)->parent->parent;
441 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 371 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
442 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 372 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
443 int retval = 0; 373 int retval = 0;
@@ -469,255 +399,125 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp,
469static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev, 399static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev,
470 struct device_attribute *attr, char *buf) 400 struct device_attribute *attr, char *buf)
471{ 401{
472 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 402 struct pyra_device *pyra =
403 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
473 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi); 404 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi);
474} 405}
475 406
476static ssize_t pyra_sysfs_show_actual_profile(struct device *dev, 407static ssize_t pyra_sysfs_show_actual_profile(struct device *dev,
477 struct device_attribute *attr, char *buf) 408 struct device_attribute *attr, char *buf)
478{ 409{
479 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 410 struct pyra_device *pyra =
411 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
480 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_profile); 412 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_profile);
481} 413}
482 414
483static ssize_t pyra_sysfs_show_firmware_version(struct device *dev, 415static ssize_t pyra_sysfs_show_firmware_version(struct device *dev,
484 struct device_attribute *attr, char *buf) 416 struct device_attribute *attr, char *buf)
485{ 417{
486 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 418 struct pyra_device *pyra =
419 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
487 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->firmware_version); 420 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->firmware_version);
488} 421}
489 422
490static ssize_t pyra_sysfs_show_startup_profile(struct device *dev, 423static ssize_t pyra_sysfs_show_startup_profile(struct device *dev,
491 struct device_attribute *attr, char *buf) 424 struct device_attribute *attr, char *buf)
492{ 425{
493 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 426 struct pyra_device *pyra =
427 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
494 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->settings.startup_profile); 428 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->settings.startup_profile);
495} 429}
496 430
497static DEVICE_ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL); 431static struct device_attribute pyra_attributes[] = {
498 432 __ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL),
499static DEVICE_ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL); 433 __ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL),
500 434 __ATTR(firmware_version, 0440,
501static DEVICE_ATTR(firmware_version, 0440, 435 pyra_sysfs_show_firmware_version, NULL),
502 pyra_sysfs_show_firmware_version, NULL); 436 __ATTR(startup_profile, 0440,
503 437 pyra_sysfs_show_startup_profile, NULL),
504static DEVICE_ATTR(startup_profile, 0440, 438 __ATTR_NULL
505 pyra_sysfs_show_startup_profile, NULL);
506
507static struct attribute *pyra_attributes[] = {
508 &dev_attr_actual_cpi.attr,
509 &dev_attr_actual_profile.attr,
510 &dev_attr_firmware_version.attr,
511 &dev_attr_startup_profile.attr,
512 NULL
513};
514
515static struct attribute_group pyra_attribute_group = {
516 .attrs = pyra_attributes
517}; 439};
518 440
519static struct bin_attribute pyra_profile_settings_attr = { 441static struct bin_attribute pyra_bin_attributes[] = {
442 {
520 .attr = { .name = "profile_settings", .mode = 0220 }, 443 .attr = { .name = "profile_settings", .mode = 0220 },
521 .size = sizeof(struct pyra_profile_settings), 444 .size = sizeof(struct pyra_profile_settings),
522 .write = pyra_sysfs_write_profile_settings 445 .write = pyra_sysfs_write_profile_settings
523}; 446 },
524 447 {
525static struct bin_attribute pyra_profile1_settings_attr = {
526 .attr = { .name = "profile1_settings", .mode = 0440 }, 448 .attr = { .name = "profile1_settings", .mode = 0440 },
527 .size = sizeof(struct pyra_profile_settings), 449 .size = sizeof(struct pyra_profile_settings),
528 .read = pyra_sysfs_read_profile1_settings 450 .read = pyra_sysfs_read_profilex_settings,
529}; 451 .private = &profile_numbers[0]
530 452 },
531static struct bin_attribute pyra_profile2_settings_attr = { 453 {
532 .attr = { .name = "profile2_settings", .mode = 0440 }, 454 .attr = { .name = "profile2_settings", .mode = 0440 },
533 .size = sizeof(struct pyra_profile_settings), 455 .size = sizeof(struct pyra_profile_settings),
534 .read = pyra_sysfs_read_profile2_settings 456 .read = pyra_sysfs_read_profilex_settings,
535}; 457 .private = &profile_numbers[1]
536 458 },
537static struct bin_attribute pyra_profile3_settings_attr = { 459 {
538 .attr = { .name = "profile3_settings", .mode = 0440 }, 460 .attr = { .name = "profile3_settings", .mode = 0440 },
539 .size = sizeof(struct pyra_profile_settings), 461 .size = sizeof(struct pyra_profile_settings),
540 .read = pyra_sysfs_read_profile3_settings 462 .read = pyra_sysfs_read_profilex_settings,
541}; 463 .private = &profile_numbers[2]
542 464 },
543static struct bin_attribute pyra_profile4_settings_attr = { 465 {
544 .attr = { .name = "profile4_settings", .mode = 0440 }, 466 .attr = { .name = "profile4_settings", .mode = 0440 },
545 .size = sizeof(struct pyra_profile_settings), 467 .size = sizeof(struct pyra_profile_settings),
546 .read = pyra_sysfs_read_profile4_settings 468 .read = pyra_sysfs_read_profilex_settings,
547}; 469 .private = &profile_numbers[3]
548 470 },
549static struct bin_attribute pyra_profile5_settings_attr = { 471 {
550 .attr = { .name = "profile5_settings", .mode = 0440 }, 472 .attr = { .name = "profile5_settings", .mode = 0440 },
551 .size = sizeof(struct pyra_profile_settings), 473 .size = sizeof(struct pyra_profile_settings),
552 .read = pyra_sysfs_read_profile5_settings 474 .read = pyra_sysfs_read_profilex_settings,
553}; 475 .private = &profile_numbers[4]
554 476 },
555static struct bin_attribute pyra_profile_buttons_attr = { 477 {
556 .attr = { .name = "profile_buttons", .mode = 0220 }, 478 .attr = { .name = "profile_buttons", .mode = 0220 },
557 .size = sizeof(struct pyra_profile_buttons), 479 .size = sizeof(struct pyra_profile_buttons),
558 .write = pyra_sysfs_write_profile_buttons 480 .write = pyra_sysfs_write_profile_buttons
559}; 481 },
560 482 {
561static struct bin_attribute pyra_profile1_buttons_attr = {
562 .attr = { .name = "profile1_buttons", .mode = 0440 }, 483 .attr = { .name = "profile1_buttons", .mode = 0440 },
563 .size = sizeof(struct pyra_profile_buttons), 484 .size = sizeof(struct pyra_profile_buttons),
564 .read = pyra_sysfs_read_profile1_buttons 485 .read = pyra_sysfs_read_profilex_buttons,
565}; 486 .private = &profile_numbers[0]
566 487 },
567static struct bin_attribute pyra_profile2_buttons_attr = { 488 {
568 .attr = { .name = "profile2_buttons", .mode = 0440 }, 489 .attr = { .name = "profile2_buttons", .mode = 0440 },
569 .size = sizeof(struct pyra_profile_buttons), 490 .size = sizeof(struct pyra_profile_buttons),
570 .read = pyra_sysfs_read_profile2_buttons 491 .read = pyra_sysfs_read_profilex_buttons,
571}; 492 .private = &profile_numbers[1]
572 493 },
573static struct bin_attribute pyra_profile3_buttons_attr = { 494 {
574 .attr = { .name = "profile3_buttons", .mode = 0440 }, 495 .attr = { .name = "profile3_buttons", .mode = 0440 },
575 .size = sizeof(struct pyra_profile_buttons), 496 .size = sizeof(struct pyra_profile_buttons),
576 .read = pyra_sysfs_read_profile3_buttons 497 .read = pyra_sysfs_read_profilex_buttons,
577}; 498 .private = &profile_numbers[2]
578 499 },
579static struct bin_attribute pyra_profile4_buttons_attr = { 500 {
580 .attr = { .name = "profile4_buttons", .mode = 0440 }, 501 .attr = { .name = "profile4_buttons", .mode = 0440 },
581 .size = sizeof(struct pyra_profile_buttons), 502 .size = sizeof(struct pyra_profile_buttons),
582 .read = pyra_sysfs_read_profile4_buttons 503 .read = pyra_sysfs_read_profilex_buttons,
583}; 504 .private = &profile_numbers[3]
584 505 },
585static struct bin_attribute pyra_profile5_buttons_attr = { 506 {
586 .attr = { .name = "profile5_buttons", .mode = 0440 }, 507 .attr = { .name = "profile5_buttons", .mode = 0440 },
587 .size = sizeof(struct pyra_profile_buttons), 508 .size = sizeof(struct pyra_profile_buttons),
588 .read = pyra_sysfs_read_profile5_buttons 509 .read = pyra_sysfs_read_profilex_buttons,
589}; 510 .private = &profile_numbers[4]
590 511 },
591static struct bin_attribute pyra_settings_attr = { 512 {
592 .attr = { .name = "settings", .mode = 0660 }, 513 .attr = { .name = "settings", .mode = 0660 },
593 .size = sizeof(struct pyra_settings), 514 .size = sizeof(struct pyra_settings),
594 .read = pyra_sysfs_read_settings, 515 .read = pyra_sysfs_read_settings,
595 .write = pyra_sysfs_write_settings 516 .write = pyra_sysfs_write_settings
517 },
518 __ATTR_NULL
596}; 519};
597 520
598static int pyra_create_sysfs_attributes(struct usb_interface *intf)
599{
600 int retval;
601
602 retval = sysfs_create_group(&intf->dev.kobj, &pyra_attribute_group);
603 if (retval)
604 goto exit_1;
605
606 retval = sysfs_create_bin_file(&intf->dev.kobj,
607 &pyra_profile_settings_attr);
608 if (retval)
609 goto exit_2;
610
611 retval = sysfs_create_bin_file(&intf->dev.kobj,
612 &pyra_profile1_settings_attr);
613 if (retval)
614 goto exit_3;
615
616 retval = sysfs_create_bin_file(&intf->dev.kobj,
617 &pyra_profile2_settings_attr);
618 if (retval)
619 goto exit_4;
620
621 retval = sysfs_create_bin_file(&intf->dev.kobj,
622 &pyra_profile3_settings_attr);
623 if (retval)
624 goto exit_5;
625
626 retval = sysfs_create_bin_file(&intf->dev.kobj,
627 &pyra_profile4_settings_attr);
628 if (retval)
629 goto exit_6;
630
631 retval = sysfs_create_bin_file(&intf->dev.kobj,
632 &pyra_profile5_settings_attr);
633 if (retval)
634 goto exit_7;
635
636 retval = sysfs_create_bin_file(&intf->dev.kobj,
637 &pyra_profile_buttons_attr);
638 if (retval)
639 goto exit_8;
640
641 retval = sysfs_create_bin_file(&intf->dev.kobj,
642 &pyra_profile1_buttons_attr);
643 if (retval)
644 goto exit_9;
645
646 retval = sysfs_create_bin_file(&intf->dev.kobj,
647 &pyra_profile2_buttons_attr);
648 if (retval)
649 goto exit_10;
650
651 retval = sysfs_create_bin_file(&intf->dev.kobj,
652 &pyra_profile3_buttons_attr);
653 if (retval)
654 goto exit_11;
655
656 retval = sysfs_create_bin_file(&intf->dev.kobj,
657 &pyra_profile4_buttons_attr);
658 if (retval)
659 goto exit_12;
660
661 retval = sysfs_create_bin_file(&intf->dev.kobj,
662 &pyra_profile5_buttons_attr);
663 if (retval)
664 goto exit_13;
665
666 retval = sysfs_create_bin_file(&intf->dev.kobj,
667 &pyra_settings_attr);
668 if (retval)
669 goto exit_14;
670
671 return 0;
672
673exit_14:
674 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile5_buttons_attr);
675exit_13:
676 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile4_buttons_attr);
677exit_12:
678 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile3_buttons_attr);
679exit_11:
680 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile2_buttons_attr);
681exit_10:
682 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile1_buttons_attr);
683exit_9:
684 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile_buttons_attr);
685exit_8:
686 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile5_settings_attr);
687exit_7:
688 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile4_settings_attr);
689exit_6:
690 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile3_settings_attr);
691exit_5:
692 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile2_settings_attr);
693exit_4:
694 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile1_settings_attr);
695exit_3:
696 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile_settings_attr);
697exit_2:
698 sysfs_remove_group(&intf->dev.kobj, &pyra_attribute_group);
699exit_1:
700 return retval;
701}
702
703static void pyra_remove_sysfs_attributes(struct usb_interface *intf)
704{
705 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_settings_attr);
706 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile5_buttons_attr);
707 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile4_buttons_attr);
708 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile3_buttons_attr);
709 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile2_buttons_attr);
710 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile1_buttons_attr);
711 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile_buttons_attr);
712 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile5_settings_attr);
713 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile4_settings_attr);
714 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile3_settings_attr);
715 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile2_settings_attr);
716 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile1_settings_attr);
717 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile_settings_attr);
718 sysfs_remove_group(&intf->dev.kobj, &pyra_attribute_group);
719}
720
721static int pyra_init_pyra_device_struct(struct usb_device *usb_dev, 521static int pyra_init_pyra_device_struct(struct usb_device *usb_dev,
722 struct pyra_device *pyra) 522 struct pyra_device *pyra)
723{ 523{
@@ -770,31 +570,24 @@ static int pyra_init_specials(struct hid_device *hdev)
770 570
771 pyra = kzalloc(sizeof(*pyra), GFP_KERNEL); 571 pyra = kzalloc(sizeof(*pyra), GFP_KERNEL);
772 if (!pyra) { 572 if (!pyra) {
773 dev_err(&hdev->dev, "can't alloc device descriptor\n"); 573 hid_err(hdev, "can't alloc device descriptor\n");
774 return -ENOMEM; 574 return -ENOMEM;
775 } 575 }
776 hid_set_drvdata(hdev, pyra); 576 hid_set_drvdata(hdev, pyra);
777 577
778 retval = pyra_init_pyra_device_struct(usb_dev, pyra); 578 retval = pyra_init_pyra_device_struct(usb_dev, pyra);
779 if (retval) { 579 if (retval) {
780 dev_err(&hdev->dev, 580 hid_err(hdev, "couldn't init struct pyra_device\n");
781 "couldn't init struct pyra_device\n");
782 goto exit_free; 581 goto exit_free;
783 } 582 }
784 583
785 retval = roccat_connect(hdev); 584 retval = roccat_connect(pyra_class, hdev);
786 if (retval < 0) { 585 if (retval < 0) {
787 dev_err(&hdev->dev, "couldn't init char dev\n"); 586 hid_err(hdev, "couldn't init char dev\n");
788 } else { 587 } else {
789 pyra->chrdev_minor = retval; 588 pyra->chrdev_minor = retval;
790 pyra->roccat_claimed = 1; 589 pyra->roccat_claimed = 1;
791 } 590 }
792
793 retval = pyra_create_sysfs_attributes(intf);
794 if (retval) {
795 dev_err(&hdev->dev, "cannot create sysfs files\n");
796 goto exit_free;
797 }
798 } else { 591 } else {
799 hid_set_drvdata(hdev, NULL); 592 hid_set_drvdata(hdev, NULL);
800 } 593 }
@@ -812,7 +605,6 @@ static void pyra_remove_specials(struct hid_device *hdev)
812 605
813 if (intf->cur_altsetting->desc.bInterfaceProtocol 606 if (intf->cur_altsetting->desc.bInterfaceProtocol
814 == USB_INTERFACE_PROTOCOL_MOUSE) { 607 == USB_INTERFACE_PROTOCOL_MOUSE) {
815 pyra_remove_sysfs_attributes(intf);
816 pyra = hid_get_drvdata(hdev); 608 pyra = hid_get_drvdata(hdev);
817 if (pyra->roccat_claimed) 609 if (pyra->roccat_claimed)
818 roccat_disconnect(pyra->chrdev_minor); 610 roccat_disconnect(pyra->chrdev_minor);
@@ -826,19 +618,19 @@ static int pyra_probe(struct hid_device *hdev, const struct hid_device_id *id)
826 618
827 retval = hid_parse(hdev); 619 retval = hid_parse(hdev);
828 if (retval) { 620 if (retval) {
829 dev_err(&hdev->dev, "parse failed\n"); 621 hid_err(hdev, "parse failed\n");
830 goto exit; 622 goto exit;
831 } 623 }
832 624
833 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 625 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
834 if (retval) { 626 if (retval) {
835 dev_err(&hdev->dev, "hw start failed\n"); 627 hid_err(hdev, "hw start failed\n");
836 goto exit; 628 goto exit;
837 } 629 }
838 630
839 retval = pyra_init_specials(hdev); 631 retval = pyra_init_specials(hdev);
840 if (retval) { 632 if (retval) {
841 dev_err(&hdev->dev, "couldn't install mouse\n"); 633 hid_err(hdev, "couldn't install mouse\n");
842 goto exit_stop; 634 goto exit_stop;
843 } 635 }
844 return 0; 636 return 0;
@@ -952,11 +744,24 @@ static struct hid_driver pyra_driver = {
952 744
953static int __init pyra_init(void) 745static int __init pyra_init(void)
954{ 746{
955 return hid_register_driver(&pyra_driver); 747 int retval;
748
749 /* class name has to be same as driver name */
750 pyra_class = class_create(THIS_MODULE, "pyra");
751 if (IS_ERR(pyra_class))
752 return PTR_ERR(pyra_class);
753 pyra_class->dev_attrs = pyra_attributes;
754 pyra_class->dev_bin_attrs = pyra_bin_attributes;
755
756 retval = hid_register_driver(&pyra_driver);
757 if (retval)
758 class_destroy(pyra_class);
759 return retval;
956} 760}
957 761
958static void __exit pyra_exit(void) 762static void __exit pyra_exit(void)
959{ 763{
764 class_destroy(pyra_class);
960 hid_unregister_driver(&pyra_driver); 765 hid_unregister_driver(&pyra_driver);
961} 766}
962 767
diff --git a/drivers/hid/hid-roccat-pyra.h b/drivers/hid/hid-roccat-pyra.h
index 22f80a8f26f9..14cbbe1621e0 100644
--- a/drivers/hid/hid-roccat-pyra.h
+++ b/drivers/hid/hid-roccat-pyra.h
@@ -14,14 +14,11 @@
14 14
15#include <linux/types.h> 15#include <linux/types.h>
16 16
17#pragma pack(push)
18#pragma pack(1)
19
20struct pyra_b { 17struct pyra_b {
21 uint8_t command; /* PYRA_COMMAND_B */ 18 uint8_t command; /* PYRA_COMMAND_B */
22 uint8_t size; /* always 3 */ 19 uint8_t size; /* always 3 */
23 uint8_t unknown; /* 1 */ 20 uint8_t unknown; /* 1 */
24}; 21} __attribute__ ((__packed__));
25 22
26struct pyra_control { 23struct pyra_control {
27 uint8_t command; /* PYRA_COMMAND_CONTROL */ 24 uint8_t command; /* PYRA_COMMAND_CONTROL */
@@ -31,7 +28,7 @@ struct pyra_control {
31 */ 28 */
32 uint8_t value; /* Range 0-4 */ 29 uint8_t value; /* Range 0-4 */
33 uint8_t request; 30 uint8_t request;
34}; 31} __attribute__ ((__packed__));
35 32
36enum pyra_control_requests { 33enum pyra_control_requests {
37 PYRA_CONTROL_REQUEST_STATUS = 0x00, 34 PYRA_CONTROL_REQUEST_STATUS = 0x00,
@@ -43,7 +40,7 @@ struct pyra_settings {
43 uint8_t command; /* PYRA_COMMAND_SETTINGS */ 40 uint8_t command; /* PYRA_COMMAND_SETTINGS */
44 uint8_t size; /* always 3 */ 41 uint8_t size; /* always 3 */
45 uint8_t startup_profile; /* Range 0-4! */ 42 uint8_t startup_profile; /* Range 0-4! */
46}; 43} __attribute__ ((__packed__));
47 44
48struct pyra_profile_settings { 45struct pyra_profile_settings {
49 uint8_t command; /* PYRA_COMMAND_PROFILE_SETTINGS */ 46 uint8_t command; /* PYRA_COMMAND_PROFILE_SETTINGS */
@@ -58,7 +55,7 @@ struct pyra_profile_settings {
58 uint8_t light_effect; 55 uint8_t light_effect;
59 uint8_t handedness; 56 uint8_t handedness;
60 uint16_t checksum; /* byte sum */ 57 uint16_t checksum; /* byte sum */
61}; 58} __attribute__ ((__packed__));
62 59
63struct pyra_profile_buttons { 60struct pyra_profile_buttons {
64 uint8_t command; /* PYRA_COMMAND_PROFILE_BUTTONS */ 61 uint8_t command; /* PYRA_COMMAND_PROFILE_BUTTONS */
@@ -66,7 +63,7 @@ struct pyra_profile_buttons {
66 uint8_t number; /* Range 0-4 */ 63 uint8_t number; /* Range 0-4 */
67 uint8_t buttons[14]; 64 uint8_t buttons[14];
68 uint16_t checksum; /* byte sum */ 65 uint16_t checksum; /* byte sum */
69}; 66} __attribute__ ((__packed__));
70 67
71struct pyra_info { 68struct pyra_info {
72 uint8_t command; /* PYRA_COMMAND_INFO */ 69 uint8_t command; /* PYRA_COMMAND_INFO */
@@ -75,7 +72,7 @@ struct pyra_info {
75 uint8_t unknown1; /* always 0 */ 72 uint8_t unknown1; /* always 0 */
76 uint8_t unknown2; /* always 1 */ 73 uint8_t unknown2; /* always 1 */
77 uint8_t unknown3; /* always 0 */ 74 uint8_t unknown3; /* always 0 */
78}; 75} __attribute__ ((__packed__));
79 76
80enum pyra_commands { 77enum pyra_commands {
81 PYRA_COMMAND_CONTROL = 0x4, 78 PYRA_COMMAND_CONTROL = 0x4,
@@ -107,13 +104,13 @@ struct pyra_mouse_event_button {
107 uint8_t type; 104 uint8_t type;
108 uint8_t data1; 105 uint8_t data1;
109 uint8_t data2; 106 uint8_t data2;
110}; 107} __attribute__ ((__packed__));
111 108
112struct pyra_mouse_event_audio { 109struct pyra_mouse_event_audio {
113 uint8_t report_number; /* always 2 */ 110 uint8_t report_number; /* always 2 */
114 uint8_t type; 111 uint8_t type;
115 uint8_t unused; /* always 0 */ 112 uint8_t unused; /* always 0 */
116}; 113} __attribute__ ((__packed__));
117 114
118/* hid audio controls */ 115/* hid audio controls */
119enum pyra_mouse_event_audio_types { 116enum pyra_mouse_event_audio_types {
@@ -167,9 +164,7 @@ struct pyra_roccat_report {
167 uint8_t type; 164 uint8_t type;
168 uint8_t value; 165 uint8_t value;
169 uint8_t key; 166 uint8_t key;
170}; 167} __attribute__ ((__packed__));
171
172#pragma pack(pop)
173 168
174struct pyra_device { 169struct pyra_device {
175 int actual_profile; 170 int actual_profile;
diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
index 5a6879e235ac..a14c579ea781 100644
--- a/drivers/hid/hid-roccat.c
+++ b/drivers/hid/hid-roccat.c
@@ -21,6 +21,8 @@
21 * It is inspired by hidraw, but uses only one circular buffer for all readers. 21 * It is inspired by hidraw, but uses only one circular buffer for all readers.
22 */ 22 */
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
24#include <linux/cdev.h> 26#include <linux/cdev.h>
25#include <linux/poll.h> 27#include <linux/poll.h>
26#include <linux/sched.h> 28#include <linux/sched.h>
@@ -65,7 +67,6 @@ struct roccat_reader {
65}; 67};
66 68
67static int roccat_major; 69static int roccat_major;
68static struct class *roccat_class;
69static struct cdev roccat_cdev; 70static struct cdev roccat_cdev;
70 71
71static struct roccat_device *devices[ROCCAT_MAX_DEVICES]; 72static struct roccat_device *devices[ROCCAT_MAX_DEVICES];
@@ -165,27 +166,22 @@ static int roccat_open(struct inode *inode, struct file *file)
165 mutex_lock(&device->readers_lock); 166 mutex_lock(&device->readers_lock);
166 167
167 if (!device) { 168 if (!device) {
168 printk(KERN_EMERG "roccat device with minor %d doesn't exist\n", 169 pr_emerg("roccat device with minor %d doesn't exist\n", minor);
169 minor);
170 error = -ENODEV; 170 error = -ENODEV;
171 goto exit_err; 171 goto exit_err;
172 } 172 }
173 173
174 if (!device->open++) { 174 if (!device->open++) {
175 /* power on device on adding first reader */ 175 /* power on device on adding first reader */
176 if (device->hid->ll_driver->power) { 176 error = hid_hw_power(device->hid, PM_HINT_FULLON);
177 error = device->hid->ll_driver->power(device->hid, 177 if (error < 0) {
178 PM_HINT_FULLON); 178 --device->open;
179 if (error < 0) { 179 goto exit_err;
180 --device->open;
181 goto exit_err;
182 }
183 } 180 }
184 error = device->hid->ll_driver->open(device->hid); 181
182 error = hid_hw_open(device->hid);
185 if (error < 0) { 183 if (error < 0) {
186 if (device->hid->ll_driver->power) 184 hid_hw_power(device->hid, PM_HINT_NORMAL);
187 device->hid->ll_driver->power(device->hid,
188 PM_HINT_NORMAL);
189 --device->open; 185 --device->open;
190 goto exit_err; 186 goto exit_err;
191 } 187 }
@@ -218,8 +214,7 @@ static int roccat_release(struct inode *inode, struct file *file)
218 device = devices[minor]; 214 device = devices[minor];
219 if (!device) { 215 if (!device) {
220 mutex_unlock(&devices_lock); 216 mutex_unlock(&devices_lock);
221 printk(KERN_EMERG "roccat device with minor %d doesn't exist\n", 217 pr_emerg("roccat device with minor %d doesn't exist\n", minor);
222 minor);
223 return -ENODEV; 218 return -ENODEV;
224 } 219 }
225 220
@@ -231,10 +226,8 @@ static int roccat_release(struct inode *inode, struct file *file)
231 if (!--device->open) { 226 if (!--device->open) {
232 /* removing last reader */ 227 /* removing last reader */
233 if (device->exist) { 228 if (device->exist) {
234 if (device->hid->ll_driver->power) 229 hid_hw_power(device->hid, PM_HINT_NORMAL);
235 device->hid->ll_driver->power(device->hid, 230 hid_hw_close(device->hid);
236 PM_HINT_NORMAL);
237 device->hid->ll_driver->close(device->hid);
238 } else { 231 } else {
239 kfree(device); 232 kfree(device);
240 } 233 }
@@ -295,12 +288,14 @@ EXPORT_SYMBOL_GPL(roccat_report_event);
295 288
296/* 289/*
297 * roccat_connect() - create a char device for special event output 290 * roccat_connect() - create a char device for special event output
291 * @class: the class thats used to create the device. Meant to hold device
292 * specific sysfs attributes.
298 * @hid: the hid device the char device should be connected to. 293 * @hid: the hid device the char device should be connected to.
299 * 294 *
300 * Return value is minor device number in Range [0, ROCCAT_MAX_DEVICES] on 295 * Return value is minor device number in Range [0, ROCCAT_MAX_DEVICES] on
301 * success, a negative error code on failure. 296 * success, a negative error code on failure.
302 */ 297 */
303int roccat_connect(struct hid_device *hid) 298int roccat_connect(struct class *klass, struct hid_device *hid)
304{ 299{
305 unsigned int minor; 300 unsigned int minor;
306 struct roccat_device *device; 301 struct roccat_device *device;
@@ -326,7 +321,7 @@ int roccat_connect(struct hid_device *hid)
326 return -EINVAL; 321 return -EINVAL;
327 } 322 }
328 323
329 device->dev = device_create(roccat_class, &hid->dev, 324 device->dev = device_create(klass, &hid->dev,
330 MKDEV(roccat_major, minor), NULL, 325 MKDEV(roccat_major, minor), NULL,
331 "%s%s%d", "roccat", hid->driver->name, minor); 326 "%s%s%d", "roccat", hid->driver->name, minor);
332 327
@@ -367,10 +362,10 @@ void roccat_disconnect(int minor)
367 362
368 device->exist = 0; /* TODO exist maybe not needed */ 363 device->exist = 0; /* TODO exist maybe not needed */
369 364
370 device_destroy(roccat_class, MKDEV(roccat_major, minor)); 365 device_destroy(device->dev->class, MKDEV(roccat_major, minor));
371 366
372 if (device->open) { 367 if (device->open) {
373 device->hid->ll_driver->close(device->hid); 368 hid_hw_close(device->hid);
374 wake_up_interruptible(&device->wait); 369 wake_up_interruptible(&device->wait);
375 } else { 370 } else {
376 kfree(device); 371 kfree(device);
@@ -398,14 +393,7 @@ static int __init roccat_init(void)
398 roccat_major = MAJOR(dev_id); 393 roccat_major = MAJOR(dev_id);
399 394
400 if (retval < 0) { 395 if (retval < 0) {
401 printk(KERN_WARNING "roccat: can't get major number\n"); 396 pr_warn("can't get major number\n");
402 return retval;
403 }
404
405 roccat_class = class_create(THIS_MODULE, "roccat");
406 if (IS_ERR(roccat_class)) {
407 retval = PTR_ERR(roccat_class);
408 unregister_chrdev_region(dev_id, ROCCAT_MAX_DEVICES);
409 return retval; 397 return retval;
410 } 398 }
411 399
@@ -420,7 +408,6 @@ static void __exit roccat_exit(void)
420 dev_t dev_id = MKDEV(roccat_major, 0); 408 dev_t dev_id = MKDEV(roccat_major, 0);
421 409
422 cdev_del(&roccat_cdev); 410 cdev_del(&roccat_cdev);
423 class_destroy(roccat_class);
424 unregister_chrdev_region(dev_id, ROCCAT_MAX_DEVICES); 411 unregister_chrdev_region(dev_id, ROCCAT_MAX_DEVICES);
425} 412}
426 413
diff --git a/drivers/hid/hid-roccat.h b/drivers/hid/hid-roccat.h
index 09e864e9f79d..5784281d613f 100644
--- a/drivers/hid/hid-roccat.h
+++ b/drivers/hid/hid-roccat.h
@@ -16,11 +16,12 @@
16#include <linux/types.h> 16#include <linux/types.h>
17 17
18#if defined(CONFIG_HID_ROCCAT) || defined(CONFIG_HID_ROCCAT_MODULE) 18#if defined(CONFIG_HID_ROCCAT) || defined(CONFIG_HID_ROCCAT_MODULE)
19int roccat_connect(struct hid_device *hid); 19int roccat_connect(struct class *klass, struct hid_device *hid);
20void roccat_disconnect(int minor); 20void roccat_disconnect(int minor);
21int roccat_report_event(int minor, u8 const *data, int len); 21int roccat_report_event(int minor, u8 const *data, int len);
22#else 22#else
23static inline int roccat_connect(struct hid_device *hid) { return -1; } 23static inline int roccat_connect(struct class *klass,
24 struct hid_device *hid) { return -1; }
24static inline void roccat_disconnect(int minor) {} 25static inline void roccat_disconnect(int minor) {}
25static inline int roccat_report_event(int minor, u8 const *data, int len) 26static inline int roccat_report_event(int minor, u8 const *data, int len)
26{ 27{
diff --git a/drivers/hid/hid-samsung.c b/drivers/hid/hid-samsung.c
index 35894444e000..3c1fd8af5e0c 100644
--- a/drivers/hid/hid-samsung.c
+++ b/drivers/hid/hid-samsung.c
@@ -57,8 +57,8 @@
57static inline void samsung_irda_dev_trace(struct hid_device *hdev, 57static inline void samsung_irda_dev_trace(struct hid_device *hdev,
58 unsigned int rsize) 58 unsigned int rsize)
59{ 59{
60 dev_info(&hdev->dev, "fixing up Samsung IrDA %d byte report " 60 hid_info(hdev, "fixing up Samsung IrDA %d byte report descriptor\n",
61 "descriptor\n", rsize); 61 rsize);
62} 62}
63 63
64static __u8 *samsung_irda_report_fixup(struct hid_device *hdev, __u8 *rdesc, 64static __u8 *samsung_irda_report_fixup(struct hid_device *hdev, __u8 *rdesc,
@@ -160,7 +160,7 @@ static int samsung_probe(struct hid_device *hdev,
160 160
161 ret = hid_parse(hdev); 161 ret = hid_parse(hdev);
162 if (ret) { 162 if (ret) {
163 dev_err(&hdev->dev, "parse failed\n"); 163 hid_err(hdev, "parse failed\n");
164 goto err_free; 164 goto err_free;
165 } 165 }
166 166
@@ -174,7 +174,7 @@ static int samsung_probe(struct hid_device *hdev,
174 174
175 ret = hid_hw_start(hdev, cmask); 175 ret = hid_hw_start(hdev, cmask);
176 if (ret) { 176 if (ret) {
177 dev_err(&hdev->dev, "hw start failed\n"); 177 hid_err(hdev, "hw start failed\n");
178 goto err_free; 178 goto err_free;
179 } 179 }
180 180
diff --git a/drivers/hid/hid-sjoy.c b/drivers/hid/hid-sjoy.c
index e10a7687ebf2..16f7cafc9695 100644
--- a/drivers/hid/hid-sjoy.c
+++ b/drivers/hid/hid-sjoy.c
@@ -74,26 +74,25 @@ static int sjoyff_init(struct hid_device *hid)
74 int error; 74 int error;
75 75
76 if (list_empty(report_list)) { 76 if (list_empty(report_list)) {
77 dev_err(&hid->dev, "no output reports found\n"); 77 hid_err(hid, "no output reports found\n");
78 return -ENODEV; 78 return -ENODEV;
79 } 79 }
80 80
81 report_ptr = report_ptr->next; 81 report_ptr = report_ptr->next;
82 82
83 if (report_ptr == report_list) { 83 if (report_ptr == report_list) {
84 dev_err(&hid->dev, "required output report is " 84 hid_err(hid, "required output report is missing\n");
85 "missing\n");
86 return -ENODEV; 85 return -ENODEV;
87 } 86 }
88 87
89 report = list_entry(report_ptr, struct hid_report, list); 88 report = list_entry(report_ptr, struct hid_report, list);
90 if (report->maxfield < 1) { 89 if (report->maxfield < 1) {
91 dev_err(&hid->dev, "no fields in the report\n"); 90 hid_err(hid, "no fields in the report\n");
92 return -ENODEV; 91 return -ENODEV;
93 } 92 }
94 93
95 if (report->field[0]->report_count < 3) { 94 if (report->field[0]->report_count < 3) {
96 dev_err(&hid->dev, "not enough values in the field\n"); 95 hid_err(hid, "not enough values in the field\n");
97 return -ENODEV; 96 return -ENODEV;
98 } 97 }
99 98
@@ -117,8 +116,7 @@ static int sjoyff_init(struct hid_device *hid)
117 sjoyff->report->field[0]->value[2] = 0x00; 116 sjoyff->report->field[0]->value[2] = 0x00;
118 usbhid_submit_report(hid, sjoyff->report, USB_DIR_OUT); 117 usbhid_submit_report(hid, sjoyff->report, USB_DIR_OUT);
119 118
120 dev_info(&hid->dev, 119 hid_info(hid, "Force feedback for SmartJoy PLUS PS2/USB adapter\n");
121 "Force feedback for SmartJoy PLUS PS2/USB adapter\n");
122 120
123 return 0; 121 return 0;
124} 122}
@@ -135,13 +133,13 @@ static int sjoy_probe(struct hid_device *hdev, const struct hid_device_id *id)
135 133
136 ret = hid_parse(hdev); 134 ret = hid_parse(hdev);
137 if (ret) { 135 if (ret) {
138 dev_err(&hdev->dev, "parse failed\n"); 136 hid_err(hdev, "parse failed\n");
139 goto err; 137 goto err;
140 } 138 }
141 139
142 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); 140 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
143 if (ret) { 141 if (ret) {
144 dev_err(&hdev->dev, "hw start failed\n"); 142 hid_err(hdev, "hw start failed\n");
145 goto err; 143 goto err;
146 } 144 }
147 145
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 677bb3da10e8..68d7b36e31e4 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -40,8 +40,7 @@ static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc,
40 40
41 if ((sc->quirks & VAIO_RDESC_CONSTANT) && 41 if ((sc->quirks & VAIO_RDESC_CONSTANT) &&
42 *rsize >= 56 && rdesc[54] == 0x81 && rdesc[55] == 0x07) { 42 *rsize >= 56 && rdesc[54] == 0x81 && rdesc[55] == 0x07) {
43 dev_info(&hdev->dev, "Fixing up Sony Vaio VGX report " 43 hid_info(hdev, "Fixing up Sony Vaio VGX report descriptor\n");
44 "descriptor\n");
45 rdesc[55] = 0x06; 44 rdesc[55] = 0x06;
46 } 45 }
47 return rdesc; 46 return rdesc;
@@ -89,7 +88,7 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
89 (3 << 8) | 0xf2, ifnum, buf, 17, 88 (3 << 8) | 0xf2, ifnum, buf, 17,
90 USB_CTRL_GET_TIMEOUT); 89 USB_CTRL_GET_TIMEOUT);
91 if (ret < 0) 90 if (ret < 0)
92 dev_err(&hdev->dev, "can't set operational mode\n"); 91 hid_err(hdev, "can't set operational mode\n");
93 92
94 kfree(buf); 93 kfree(buf);
95 94
@@ -110,7 +109,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
110 109
111 sc = kzalloc(sizeof(*sc), GFP_KERNEL); 110 sc = kzalloc(sizeof(*sc), GFP_KERNEL);
112 if (sc == NULL) { 111 if (sc == NULL) {
113 dev_err(&hdev->dev, "can't alloc sony descriptor\n"); 112 hid_err(hdev, "can't alloc sony descriptor\n");
114 return -ENOMEM; 113 return -ENOMEM;
115 } 114 }
116 115
@@ -119,14 +118,14 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
119 118
120 ret = hid_parse(hdev); 119 ret = hid_parse(hdev);
121 if (ret) { 120 if (ret) {
122 dev_err(&hdev->dev, "parse failed\n"); 121 hid_err(hdev, "parse failed\n");
123 goto err_free; 122 goto err_free;
124 } 123 }
125 124
126 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | 125 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT |
127 HID_CONNECT_HIDDEV_FORCE); 126 HID_CONNECT_HIDDEV_FORCE);
128 if (ret) { 127 if (ret) {
129 dev_err(&hdev->dev, "hw start failed\n"); 128 hid_err(hdev, "hw start failed\n");
130 goto err_free; 129 goto err_free;
131 } 130 }
132 131
diff --git a/drivers/hid/hid-stantum.c b/drivers/hid/hid-stantum.c
index 3171be28c3d5..b2be1d11916b 100644
--- a/drivers/hid/hid-stantum.c
+++ b/drivers/hid/hid-stantum.c
@@ -222,7 +222,7 @@ static int stantum_probe(struct hid_device *hdev,
222 222
223 sd = kmalloc(sizeof(struct stantum_data), GFP_KERNEL); 223 sd = kmalloc(sizeof(struct stantum_data), GFP_KERNEL);
224 if (!sd) { 224 if (!sd) {
225 dev_err(&hdev->dev, "cannot allocate Stantum data\n"); 225 hid_err(hdev, "cannot allocate Stantum data\n");
226 return -ENOMEM; 226 return -ENOMEM;
227 } 227 }
228 sd->valid = false; 228 sd->valid = false;
diff --git a/drivers/hid/hid-sunplus.c b/drivers/hid/hid-sunplus.c
index 164ed568f6cf..d484a0043dd4 100644
--- a/drivers/hid/hid-sunplus.c
+++ b/drivers/hid/hid-sunplus.c
@@ -27,8 +27,7 @@ static __u8 *sp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
27{ 27{
28 if (*rsize >= 107 && rdesc[104] == 0x26 && rdesc[105] == 0x80 && 28 if (*rsize >= 107 && rdesc[104] == 0x26 && rdesc[105] == 0x80 &&
29 rdesc[106] == 0x03) { 29 rdesc[106] == 0x03) {
30 dev_info(&hdev->dev, "fixing up Sunplus Wireless Desktop " 30 hid_info(hdev, "fixing up Sunplus Wireless Desktop report descriptor\n");
31 "report descriptor\n");
32 rdesc[105] = rdesc[110] = 0x03; 31 rdesc[105] = rdesc[110] = 0x03;
33 rdesc[106] = rdesc[111] = 0x21; 32 rdesc[106] = rdesc[111] = 0x21;
34 } 33 }
diff --git a/drivers/hid/hid-tmff.c b/drivers/hid/hid-tmff.c
index 25be4e1461bd..575862b0688e 100644
--- a/drivers/hid/hid-tmff.c
+++ b/drivers/hid/hid-tmff.c
@@ -151,28 +151,23 @@ static int tmff_init(struct hid_device *hid, const signed short *ff_bits)
151 switch (field->usage[0].hid) { 151 switch (field->usage[0].hid) {
152 case THRUSTMASTER_USAGE_FF: 152 case THRUSTMASTER_USAGE_FF:
153 if (field->report_count < 2) { 153 if (field->report_count < 2) {
154 dev_warn(&hid->dev, "ignoring FF field " 154 hid_warn(hid, "ignoring FF field with report_count < 2\n");
155 "with report_count < 2\n");
156 continue; 155 continue;
157 } 156 }
158 157
159 if (field->logical_maximum == 158 if (field->logical_maximum ==
160 field->logical_minimum) { 159 field->logical_minimum) {
161 dev_warn(&hid->dev, "ignoring FF field " 160 hid_warn(hid, "ignoring FF field with logical_maximum == logical_minimum\n");
162 "with logical_maximum "
163 "== logical_minimum\n");
164 continue; 161 continue;
165 } 162 }
166 163
167 if (tmff->report && tmff->report != report) { 164 if (tmff->report && tmff->report != report) {
168 dev_warn(&hid->dev, "ignoring FF field " 165 hid_warn(hid, "ignoring FF field in other report\n");
169 "in other report\n");
170 continue; 166 continue;
171 } 167 }
172 168
173 if (tmff->ff_field && tmff->ff_field != field) { 169 if (tmff->ff_field && tmff->ff_field != field) {
174 dev_warn(&hid->dev, "ignoring " 170 hid_warn(hid, "ignoring duplicate FF field\n");
175 "duplicate FF field\n");
176 continue; 171 continue;
177 } 172 }
178 173
@@ -185,16 +180,15 @@ static int tmff_init(struct hid_device *hid, const signed short *ff_bits)
185 break; 180 break;
186 181
187 default: 182 default:
188 dev_warn(&hid->dev, "ignoring unknown output " 183 hid_warn(hid, "ignoring unknown output usage %08x\n",
189 "usage %08x\n", 184 field->usage[0].hid);
190 field->usage[0].hid);
191 continue; 185 continue;
192 } 186 }
193 } 187 }
194 } 188 }
195 189
196 if (!tmff->report) { 190 if (!tmff->report) {
197 dev_err(&hid->dev, "can't find FF field in output reports\n"); 191 hid_err(hid, "can't find FF field in output reports\n");
198 error = -ENODEV; 192 error = -ENODEV;
199 goto fail; 193 goto fail;
200 } 194 }
@@ -203,8 +197,7 @@ static int tmff_init(struct hid_device *hid, const signed short *ff_bits)
203 if (error) 197 if (error)
204 goto fail; 198 goto fail;
205 199
206 dev_info(&hid->dev, "force feedback for ThrustMaster devices by Zinx " 200 hid_info(hid, "force feedback for ThrustMaster devices by Zinx Verituse <zinx@epicsol.org>\n");
207 "Verituse <zinx@epicsol.org>");
208 return 0; 201 return 0;
209 202
210fail: 203fail:
@@ -224,13 +217,13 @@ static int tm_probe(struct hid_device *hdev, const struct hid_device_id *id)
224 217
225 ret = hid_parse(hdev); 218 ret = hid_parse(hdev);
226 if (ret) { 219 if (ret) {
227 dev_err(&hdev->dev, "parse failed\n"); 220 hid_err(hdev, "parse failed\n");
228 goto err; 221 goto err;
229 } 222 }
230 223
231 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); 224 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
232 if (ret) { 225 if (ret) {
233 dev_err(&hdev->dev, "hw start failed\n"); 226 hid_err(hdev, "hw start failed\n");
234 goto err; 227 goto err;
235 } 228 }
236 229
diff --git a/drivers/hid/hid-topseed.c b/drivers/hid/hid-topseed.c
index 956ed9ac19d4..613ff7b1d746 100644
--- a/drivers/hid/hid-topseed.c
+++ b/drivers/hid/hid-topseed.c
@@ -66,6 +66,7 @@ static const struct hid_device_id ts_devices[] = {
66 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) }, 66 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
67 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) }, 67 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
68 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) }, 68 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
69 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
69 { } 70 { }
70}; 71};
71MODULE_DEVICE_TABLE(hid, ts_devices); 72MODULE_DEVICE_TABLE(hid, ts_devices);
diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c
index 724f46ed612f..06888323828c 100644
--- a/drivers/hid/hid-wacom.c
+++ b/drivers/hid/hid-wacom.c
@@ -18,6 +18,8 @@
18 * any later version. 18 * any later version.
19 */ 19 */
20 20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
21#include <linux/device.h> 23#include <linux/device.h>
22#include <linux/hid.h> 24#include <linux/hid.h>
23#include <linux/module.h> 25#include <linux/module.h>
@@ -141,8 +143,8 @@ static void wacom_poke(struct hid_device *hdev, u8 speed)
141 * Note that if the raw queries fail, it's not a hard failure and it 143 * Note that if the raw queries fail, it's not a hard failure and it
142 * is safe to continue 144 * is safe to continue
143 */ 145 */
144 dev_warn(&hdev->dev, "failed to poke device, command %d, err %d\n", 146 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
145 rep_data[0], ret); 147 rep_data[0], ret);
146 return; 148 return;
147} 149}
148 150
@@ -172,7 +174,7 @@ static ssize_t wacom_store_speed(struct device *dev,
172 return -EINVAL; 174 return -EINVAL;
173} 175}
174 176
175static DEVICE_ATTR(speed, S_IRUGO | S_IWUGO, 177static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
176 wacom_show_speed, wacom_store_speed); 178 wacom_show_speed, wacom_store_speed);
177 179
178static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, 180static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
@@ -312,7 +314,7 @@ static int wacom_probe(struct hid_device *hdev,
312 314
313 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); 315 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
314 if (wdata == NULL) { 316 if (wdata == NULL) {
315 dev_err(&hdev->dev, "can't alloc wacom descriptor\n"); 317 hid_err(hdev, "can't alloc wacom descriptor\n");
316 return -ENOMEM; 318 return -ENOMEM;
317 } 319 }
318 320
@@ -321,20 +323,20 @@ static int wacom_probe(struct hid_device *hdev,
321 /* Parse the HID report now */ 323 /* Parse the HID report now */
322 ret = hid_parse(hdev); 324 ret = hid_parse(hdev);
323 if (ret) { 325 if (ret) {
324 dev_err(&hdev->dev, "parse failed\n"); 326 hid_err(hdev, "parse failed\n");
325 goto err_free; 327 goto err_free;
326 } 328 }
327 329
328 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 330 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
329 if (ret) { 331 if (ret) {
330 dev_err(&hdev->dev, "hw start failed\n"); 332 hid_err(hdev, "hw start failed\n");
331 goto err_free; 333 goto err_free;
332 } 334 }
333 335
334 ret = device_create_file(&hdev->dev, &dev_attr_speed); 336 ret = device_create_file(&hdev->dev, &dev_attr_speed);
335 if (ret) 337 if (ret)
336 dev_warn(&hdev->dev, 338 hid_warn(hdev,
337 "can't create sysfs speed attribute err: %d\n", ret); 339 "can't create sysfs speed attribute err: %d\n", ret);
338 340
339 /* Set Wacom mode 2 with high reporting speed */ 341 /* Set Wacom mode 2 with high reporting speed */
340 wacom_poke(hdev, 1); 342 wacom_poke(hdev, 1);
@@ -349,8 +351,8 @@ static int wacom_probe(struct hid_device *hdev,
349 351
350 ret = power_supply_register(&hdev->dev, &wdata->battery); 352 ret = power_supply_register(&hdev->dev, &wdata->battery);
351 if (ret) { 353 if (ret) {
352 dev_warn(&hdev->dev, 354 hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n",
353 "can't create sysfs battery attribute, err: %d\n", ret); 355 ret);
354 /* 356 /*
355 * battery attribute is not critical for the tablet, but if it 357 * battery attribute is not critical for the tablet, but if it
356 * failed then there is no need to create ac attribute 358 * failed then there is no need to create ac attribute
@@ -367,8 +369,8 @@ static int wacom_probe(struct hid_device *hdev,
367 369
368 ret = power_supply_register(&hdev->dev, &wdata->ac); 370 ret = power_supply_register(&hdev->dev, &wdata->ac);
369 if (ret) { 371 if (ret) {
370 dev_warn(&hdev->dev, 372 hid_warn(hdev,
371 "can't create ac battery attribute, err: %d\n", ret); 373 "can't create ac battery attribute, err: %d\n", ret);
372 /* 374 /*
373 * ac attribute is not critical for the tablet, but if it 375 * ac attribute is not critical for the tablet, but if it
374 * failed then we don't want to battery attribute to exist 376 * failed then we don't want to battery attribute to exist
@@ -454,7 +456,7 @@ static int __init wacom_init(void)
454 456
455 ret = hid_register_driver(&wacom_driver); 457 ret = hid_register_driver(&wacom_driver);
456 if (ret) 458 if (ret)
457 printk(KERN_ERR "can't register wacom driver\n"); 459 pr_err("can't register wacom driver\n");
458 return ret; 460 return ret;
459} 461}
460 462
diff --git a/drivers/hid/hid-zpff.c b/drivers/hid/hid-zpff.c
index b7acceabba80..f31fab012f2f 100644
--- a/drivers/hid/hid-zpff.c
+++ b/drivers/hid/hid-zpff.c
@@ -75,14 +75,14 @@ static int zpff_init(struct hid_device *hid)
75 int error; 75 int error;
76 76
77 if (list_empty(report_list)) { 77 if (list_empty(report_list)) {
78 dev_err(&hid->dev, "no output report found\n"); 78 hid_err(hid, "no output report found\n");
79 return -ENODEV; 79 return -ENODEV;
80 } 80 }
81 81
82 report = list_entry(report_list->next, struct hid_report, list); 82 report = list_entry(report_list->next, struct hid_report, list);
83 83
84 if (report->maxfield < 4) { 84 if (report->maxfield < 4) {
85 dev_err(&hid->dev, "not enough fields in report\n"); 85 hid_err(hid, "not enough fields in report\n");
86 return -ENODEV; 86 return -ENODEV;
87 } 87 }
88 88
@@ -105,8 +105,7 @@ static int zpff_init(struct hid_device *hid)
105 zpff->report->field[3]->value[0] = 0x00; 105 zpff->report->field[3]->value[0] = 0x00;
106 usbhid_submit_report(hid, zpff->report, USB_DIR_OUT); 106 usbhid_submit_report(hid, zpff->report, USB_DIR_OUT);
107 107
108 dev_info(&hid->dev, "force feedback for Zeroplus based devices by " 108 hid_info(hid, "force feedback for Zeroplus based devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
109 "Anssi Hannula <anssi.hannula@gmail.com>\n");
110 109
111 return 0; 110 return 0;
112} 111}
@@ -123,13 +122,13 @@ static int zp_probe(struct hid_device *hdev, const struct hid_device_id *id)
123 122
124 ret = hid_parse(hdev); 123 ret = hid_parse(hdev);
125 if (ret) { 124 if (ret) {
126 dev_err(&hdev->dev, "parse failed\n"); 125 hid_err(hdev, "parse failed\n");
127 goto err; 126 goto err;
128 } 127 }
129 128
130 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); 129 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
131 if (ret) { 130 if (ret) {
132 dev_err(&hdev->dev, "hw start failed\n"); 131 hid_err(hdev, "hw start failed\n");
133 goto err; 132 goto err;
134 } 133 }
135 134
diff --git a/drivers/hid/hid-zydacron.c b/drivers/hid/hid-zydacron.c
index aac1f9273149..e90371508fd2 100644
--- a/drivers/hid/hid-zydacron.c
+++ b/drivers/hid/hid-zydacron.c
@@ -34,9 +34,8 @@ static __u8 *zc_report_fixup(struct hid_device *hdev, __u8 *rdesc,
34 rdesc[0x96] == 0xbc && rdesc[0x97] == 0xff && 34 rdesc[0x96] == 0xbc && rdesc[0x97] == 0xff &&
35 rdesc[0xca] == 0xbc && rdesc[0xcb] == 0xff && 35 rdesc[0xca] == 0xbc && rdesc[0xcb] == 0xff &&
36 rdesc[0xe1] == 0xbc && rdesc[0xe2] == 0xff) { 36 rdesc[0xe1] == 0xbc && rdesc[0xe2] == 0xff) {
37 dev_info(&hdev->dev, 37 hid_info(hdev,
38 "fixing up zydacron remote control report " 38 "fixing up zydacron remote control report descriptor\n");
39 "descriptor\n");
40 rdesc[0x96] = rdesc[0xca] = rdesc[0xe1] = 0x0c; 39 rdesc[0x96] = rdesc[0xca] = rdesc[0xe1] = 0x0c;
41 rdesc[0x97] = rdesc[0xcb] = rdesc[0xe2] = 0x00; 40 rdesc[0x97] = rdesc[0xcb] = rdesc[0xe2] = 0x00;
42 } 41 }
@@ -172,7 +171,7 @@ static int zc_probe(struct hid_device *hdev, const struct hid_device_id *id)
172 171
173 zc = kzalloc(sizeof(*zc), GFP_KERNEL); 172 zc = kzalloc(sizeof(*zc), GFP_KERNEL);
174 if (zc == NULL) { 173 if (zc == NULL) {
175 dev_err(&hdev->dev, "zydacron: can't alloc descriptor\n"); 174 hid_err(hdev, "can't alloc descriptor\n");
176 return -ENOMEM; 175 return -ENOMEM;
177 } 176 }
178 177
@@ -180,13 +179,13 @@ static int zc_probe(struct hid_device *hdev, const struct hid_device_id *id)
180 179
181 ret = hid_parse(hdev); 180 ret = hid_parse(hdev);
182 if (ret) { 181 if (ret) {
183 dev_err(&hdev->dev, "zydacron: parse failed\n"); 182 hid_err(hdev, "parse failed\n");
184 goto err_free; 183 goto err_free;
185 } 184 }
186 185
187 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 186 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
188 if (ret) { 187 if (ret) {
189 dev_err(&hdev->dev, "zydacron: hw start failed\n"); 188 hid_err(hdev, "hw start failed\n");
190 goto err_free; 189 goto err_free;
191 } 190 }
192 191
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index e1f07483691f..468e87b53ed2 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -19,6 +19,8 @@
19 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 19 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20 */ 20 */
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
22#include <linux/fs.h> 24#include <linux/fs.h>
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/errno.h> 26#include <linux/errno.h>
@@ -122,15 +124,15 @@ static ssize_t hidraw_write(struct file *file, const char __user *buffer, size_t
122 } 124 }
123 125
124 if (count > HID_MAX_BUFFER_SIZE) { 126 if (count > HID_MAX_BUFFER_SIZE) {
125 printk(KERN_WARNING "hidraw: pid %d passed too large report\n", 127 hid_warn(dev, "pid %d passed too large report\n",
126 task_pid_nr(current)); 128 task_pid_nr(current));
127 ret = -EINVAL; 129 ret = -EINVAL;
128 goto out; 130 goto out;
129 } 131 }
130 132
131 if (count < 2) { 133 if (count < 2) {
132 printk(KERN_WARNING "hidraw: pid %d passed too short report\n", 134 hid_warn(dev, "pid %d passed too short report\n",
133 task_pid_nr(current)); 135 task_pid_nr(current));
134 ret = -EINVAL; 136 ret = -EINVAL;
135 goto out; 137 goto out;
136 } 138 }
@@ -192,15 +194,13 @@ static int hidraw_open(struct inode *inode, struct file *file)
192 194
193 dev = hidraw_table[minor]; 195 dev = hidraw_table[minor];
194 if (!dev->open++) { 196 if (!dev->open++) {
195 if (dev->hid->ll_driver->power) { 197 err = hid_hw_power(dev->hid, PM_HINT_FULLON);
196 err = dev->hid->ll_driver->power(dev->hid, PM_HINT_FULLON); 198 if (err < 0)
197 if (err < 0) 199 goto out_unlock;
198 goto out_unlock; 200
199 } 201 err = hid_hw_open(dev->hid);
200 err = dev->hid->ll_driver->open(dev->hid);
201 if (err < 0) { 202 if (err < 0) {
202 if (dev->hid->ll_driver->power) 203 hid_hw_power(dev->hid, PM_HINT_NORMAL);
203 dev->hid->ll_driver->power(dev->hid, PM_HINT_NORMAL);
204 dev->open--; 204 dev->open--;
205 } 205 }
206 } 206 }
@@ -229,9 +229,8 @@ static int hidraw_release(struct inode * inode, struct file * file)
229 dev = hidraw_table[minor]; 229 dev = hidraw_table[minor];
230 if (!--dev->open) { 230 if (!--dev->open) {
231 if (list->hidraw->exist) { 231 if (list->hidraw->exist) {
232 if (dev->hid->ll_driver->power) 232 hid_hw_power(dev->hid, PM_HINT_NORMAL);
233 dev->hid->ll_driver->power(dev->hid, PM_HINT_NORMAL); 233 hid_hw_close(dev->hid);
234 dev->hid->ll_driver->close(dev->hid);
235 } else { 234 } else {
236 kfree(list->hidraw); 235 kfree(list->hidraw);
237 } 236 }
@@ -345,6 +344,9 @@ static const struct file_operations hidraw_ops = {
345 .open = hidraw_open, 344 .open = hidraw_open,
346 .release = hidraw_release, 345 .release = hidraw_release,
347 .unlocked_ioctl = hidraw_ioctl, 346 .unlocked_ioctl = hidraw_ioctl,
347#ifdef CONFIG_COMPAT
348 .compat_ioctl = hidraw_ioctl,
349#endif
348 .llseek = noop_llseek, 350 .llseek = noop_llseek,
349}; 351};
350 352
@@ -433,7 +435,7 @@ void hidraw_disconnect(struct hid_device *hid)
433 device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor)); 435 device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
434 436
435 if (hidraw->open) { 437 if (hidraw->open) {
436 hid->ll_driver->close(hid); 438 hid_hw_close(hid);
437 wake_up_interruptible(&hidraw->wait); 439 wake_up_interruptible(&hidraw->wait);
438 } else { 440 } else {
439 kfree(hidraw); 441 kfree(hidraw);
@@ -452,7 +454,7 @@ int __init hidraw_init(void)
452 hidraw_major = MAJOR(dev_id); 454 hidraw_major = MAJOR(dev_id);
453 455
454 if (result < 0) { 456 if (result < 0) {
455 printk(KERN_WARNING "hidraw: can't get major number\n"); 457 pr_warn("can't get major number\n");
456 result = 0; 458 result = 0;
457 goto out; 459 goto out;
458 } 460 }
diff --git a/drivers/hid/usbhid/Makefile b/drivers/hid/usbhid/Makefile
index 1329ecb37a1c..db3cf31c6fa1 100644
--- a/drivers/hid/usbhid/Makefile
+++ b/drivers/hid/usbhid/Makefile
@@ -3,15 +3,15 @@
3# 3#
4 4
5# Multipart objects. 5# Multipart objects.
6usbhid-objs := hid-core.o hid-quirks.o 6usbhid-y := hid-core.o hid-quirks.o
7 7
8# Optional parts of multipart objects. 8# Optional parts of multipart objects.
9 9
10ifeq ($(CONFIG_USB_HIDDEV),y) 10ifeq ($(CONFIG_USB_HIDDEV),y)
11 usbhid-objs += hiddev.o 11 usbhid-y += hiddev.o
12endif 12endif
13ifeq ($(CONFIG_HID_PID),y) 13ifeq ($(CONFIG_HID_PID),y)
14 usbhid-objs += hid-pidff.o 14 usbhid-y += hid-pidff.o
15endif 15endif
16 16
17obj-$(CONFIG_USB_HID) += usbhid.o 17obj-$(CONFIG_USB_HID) += usbhid.o
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 5489eab3a6bd..b336dd84036f 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -67,7 +67,6 @@ MODULE_PARM_DESC(quirks, "Add/modify USB HID quirks by specifying "
67 * Input submission and I/O error handler. 67 * Input submission and I/O error handler.
68 */ 68 */
69static DEFINE_MUTEX(hid_open_mut); 69static DEFINE_MUTEX(hid_open_mut);
70static struct workqueue_struct *resumption_waker;
71 70
72static void hid_io_error(struct hid_device *hid); 71static void hid_io_error(struct hid_device *hid);
73static int hid_submit_out(struct hid_device *hid); 72static int hid_submit_out(struct hid_device *hid);
@@ -136,10 +135,10 @@ static void hid_reset(struct work_struct *work)
136 hid_io_error(hid); 135 hid_io_error(hid);
137 break; 136 break;
138 default: 137 default:
139 err_hid("can't reset device, %s-%s/input%d, status %d", 138 hid_err(hid, "can't reset device, %s-%s/input%d, status %d\n",
140 hid_to_usb_dev(hid)->bus->bus_name, 139 hid_to_usb_dev(hid)->bus->bus_name,
141 hid_to_usb_dev(hid)->devpath, 140 hid_to_usb_dev(hid)->devpath,
142 usbhid->ifnum, rc); 141 usbhid->ifnum, rc);
143 /* FALLTHROUGH */ 142 /* FALLTHROUGH */
144 case -EHOSTUNREACH: 143 case -EHOSTUNREACH:
145 case -ENODEV: 144 case -ENODEV:
@@ -278,18 +277,18 @@ static void hid_irq_in(struct urb *urb)
278 hid_io_error(hid); 277 hid_io_error(hid);
279 return; 278 return;
280 default: /* error */ 279 default: /* error */
281 dev_warn(&urb->dev->dev, "input irq status %d " 280 hid_warn(urb->dev, "input irq status %d received\n",
282 "received\n", urb->status); 281 urb->status);
283 } 282 }
284 283
285 status = usb_submit_urb(urb, GFP_ATOMIC); 284 status = usb_submit_urb(urb, GFP_ATOMIC);
286 if (status) { 285 if (status) {
287 clear_bit(HID_IN_RUNNING, &usbhid->iofl); 286 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
288 if (status != -EPERM) { 287 if (status != -EPERM) {
289 err_hid("can't resubmit intr, %s-%s/input%d, status %d", 288 hid_err(hid, "can't resubmit intr, %s-%s/input%d, status %d\n",
290 hid_to_usb_dev(hid)->bus->bus_name, 289 hid_to_usb_dev(hid)->bus->bus_name,
291 hid_to_usb_dev(hid)->devpath, 290 hid_to_usb_dev(hid)->devpath,
292 usbhid->ifnum, status); 291 usbhid->ifnum, status);
293 hid_io_error(hid); 292 hid_io_error(hid);
294 } 293 }
295 } 294 }
@@ -300,10 +299,19 @@ static int hid_submit_out(struct hid_device *hid)
300 struct hid_report *report; 299 struct hid_report *report;
301 char *raw_report; 300 char *raw_report;
302 struct usbhid_device *usbhid = hid->driver_data; 301 struct usbhid_device *usbhid = hid->driver_data;
302 int r;
303 303
304 report = usbhid->out[usbhid->outtail].report; 304 report = usbhid->out[usbhid->outtail].report;
305 raw_report = usbhid->out[usbhid->outtail].raw_report; 305 raw_report = usbhid->out[usbhid->outtail].raw_report;
306 306
307 r = usb_autopm_get_interface_async(usbhid->intf);
308 if (r < 0)
309 return -1;
310
311 /*
312 * if the device hasn't been woken, we leave the output
313 * to resume()
314 */
307 if (!test_bit(HID_REPORTED_IDLE, &usbhid->iofl)) { 315 if (!test_bit(HID_REPORTED_IDLE, &usbhid->iofl)) {
308 usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0); 316 usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0);
309 usbhid->urbout->dev = hid_to_usb_dev(hid); 317 usbhid->urbout->dev = hid_to_usb_dev(hid);
@@ -313,17 +321,11 @@ static int hid_submit_out(struct hid_device *hid)
313 dbg_hid("submitting out urb\n"); 321 dbg_hid("submitting out urb\n");
314 322
315 if (usb_submit_urb(usbhid->urbout, GFP_ATOMIC)) { 323 if (usb_submit_urb(usbhid->urbout, GFP_ATOMIC)) {
316 err_hid("usb_submit_urb(out) failed"); 324 hid_err(hid, "usb_submit_urb(out) failed\n");
325 usb_autopm_put_interface_async(usbhid->intf);
317 return -1; 326 return -1;
318 } 327 }
319 usbhid->last_out = jiffies; 328 usbhid->last_out = jiffies;
320 } else {
321 /*
322 * queue work to wake up the device.
323 * as the work queue is freezeable, this is safe
324 * with respect to STD and STR
325 */
326 queue_work(resumption_waker, &usbhid->restart_work);
327 } 329 }
328 330
329 return 0; 331 return 0;
@@ -334,13 +336,16 @@ static int hid_submit_ctrl(struct hid_device *hid)
334 struct hid_report *report; 336 struct hid_report *report;
335 unsigned char dir; 337 unsigned char dir;
336 char *raw_report; 338 char *raw_report;
337 int len; 339 int len, r;
338 struct usbhid_device *usbhid = hid->driver_data; 340 struct usbhid_device *usbhid = hid->driver_data;
339 341
340 report = usbhid->ctrl[usbhid->ctrltail].report; 342 report = usbhid->ctrl[usbhid->ctrltail].report;
341 raw_report = usbhid->ctrl[usbhid->ctrltail].raw_report; 343 raw_report = usbhid->ctrl[usbhid->ctrltail].raw_report;
342 dir = usbhid->ctrl[usbhid->ctrltail].dir; 344 dir = usbhid->ctrl[usbhid->ctrltail].dir;
343 345
346 r = usb_autopm_get_interface_async(usbhid->intf);
347 if (r < 0)
348 return -1;
344 if (!test_bit(HID_REPORTED_IDLE, &usbhid->iofl)) { 349 if (!test_bit(HID_REPORTED_IDLE, &usbhid->iofl)) {
345 len = ((report->size - 1) >> 3) + 1 + (report->id > 0); 350 len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
346 if (dir == USB_DIR_OUT) { 351 if (dir == USB_DIR_OUT) {
@@ -375,17 +380,11 @@ static int hid_submit_ctrl(struct hid_device *hid)
375 usbhid->cr->wValue, usbhid->cr->wIndex, usbhid->cr->wLength); 380 usbhid->cr->wValue, usbhid->cr->wIndex, usbhid->cr->wLength);
376 381
377 if (usb_submit_urb(usbhid->urbctrl, GFP_ATOMIC)) { 382 if (usb_submit_urb(usbhid->urbctrl, GFP_ATOMIC)) {
378 err_hid("usb_submit_urb(ctrl) failed"); 383 usb_autopm_put_interface_async(usbhid->intf);
384 hid_err(hid, "usb_submit_urb(ctrl) failed\n");
379 return -1; 385 return -1;
380 } 386 }
381 usbhid->last_ctrl = jiffies; 387 usbhid->last_ctrl = jiffies;
382 } else {
383 /*
384 * queue work to wake up the device.
385 * as the work queue is freezeable, this is safe
386 * with respect to STD and STR
387 */
388 queue_work(resumption_waker, &usbhid->restart_work);
389 } 388 }
390 389
391 return 0; 390 return 0;
@@ -413,8 +412,8 @@ static void hid_irq_out(struct urb *urb)
413 case -ENOENT: 412 case -ENOENT:
414 break; 413 break;
415 default: /* error */ 414 default: /* error */
416 dev_warn(&urb->dev->dev, "output irq status %d " 415 hid_warn(urb->dev, "output irq status %d received\n",
417 "received\n", urb->status); 416 urb->status);
418 } 417 }
419 418
420 spin_lock_irqsave(&usbhid->lock, flags); 419 spin_lock_irqsave(&usbhid->lock, flags);
@@ -435,6 +434,7 @@ static void hid_irq_out(struct urb *urb)
435 434
436 clear_bit(HID_OUT_RUNNING, &usbhid->iofl); 435 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
437 spin_unlock_irqrestore(&usbhid->lock, flags); 436 spin_unlock_irqrestore(&usbhid->lock, flags);
437 usb_autopm_put_interface_async(usbhid->intf);
438 wake_up(&usbhid->wait); 438 wake_up(&usbhid->wait);
439} 439}
440 440
@@ -466,8 +466,7 @@ static void hid_ctrl(struct urb *urb)
466 case -EPIPE: /* report not available */ 466 case -EPIPE: /* report not available */
467 break; 467 break;
468 default: /* error */ 468 default: /* error */
469 dev_warn(&urb->dev->dev, "ctrl urb status %d " 469 hid_warn(urb->dev, "ctrl urb status %d received\n", status);
470 "received\n", status);
471 } 470 }
472 471
473 if (unplug) 472 if (unplug)
@@ -481,11 +480,13 @@ static void hid_ctrl(struct urb *urb)
481 wake_up(&usbhid->wait); 480 wake_up(&usbhid->wait);
482 } 481 }
483 spin_unlock(&usbhid->lock); 482 spin_unlock(&usbhid->lock);
483 usb_autopm_put_interface_async(usbhid->intf);
484 return; 484 return;
485 } 485 }
486 486
487 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); 487 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
488 spin_unlock(&usbhid->lock); 488 spin_unlock(&usbhid->lock);
489 usb_autopm_put_interface_async(usbhid->intf);
489 wake_up(&usbhid->wait); 490 wake_up(&usbhid->wait);
490} 491}
491 492
@@ -501,13 +502,13 @@ static void __usbhid_submit_report(struct hid_device *hid, struct hid_report *re
501 502
502 if (usbhid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) { 503 if (usbhid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) {
503 if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) { 504 if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) {
504 dev_warn(&hid->dev, "output queue full\n"); 505 hid_warn(hid, "output queue full\n");
505 return; 506 return;
506 } 507 }
507 508
508 usbhid->out[usbhid->outhead].raw_report = kmalloc(len, GFP_ATOMIC); 509 usbhid->out[usbhid->outhead].raw_report = kmalloc(len, GFP_ATOMIC);
509 if (!usbhid->out[usbhid->outhead].raw_report) { 510 if (!usbhid->out[usbhid->outhead].raw_report) {
510 dev_warn(&hid->dev, "output queueing failed\n"); 511 hid_warn(hid, "output queueing failed\n");
511 return; 512 return;
512 } 513 }
513 hid_output_report(report, usbhid->out[usbhid->outhead].raw_report); 514 hid_output_report(report, usbhid->out[usbhid->outhead].raw_report);
@@ -532,14 +533,14 @@ static void __usbhid_submit_report(struct hid_device *hid, struct hid_report *re
532 } 533 }
533 534
534 if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) { 535 if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) {
535 dev_warn(&hid->dev, "control queue full\n"); 536 hid_warn(hid, "control queue full\n");
536 return; 537 return;
537 } 538 }
538 539
539 if (dir == USB_DIR_OUT) { 540 if (dir == USB_DIR_OUT) {
540 usbhid->ctrl[usbhid->ctrlhead].raw_report = kmalloc(len, GFP_ATOMIC); 541 usbhid->ctrl[usbhid->ctrlhead].raw_report = kmalloc(len, GFP_ATOMIC);
541 if (!usbhid->ctrl[usbhid->ctrlhead].raw_report) { 542 if (!usbhid->ctrl[usbhid->ctrlhead].raw_report) {
542 dev_warn(&hid->dev, "control queueing failed\n"); 543 hid_warn(hid, "control queueing failed\n");
543 return; 544 return;
544 } 545 }
545 hid_output_report(report, usbhid->ctrl[usbhid->ctrlhead].raw_report); 546 hid_output_report(report, usbhid->ctrl[usbhid->ctrlhead].raw_report);
@@ -590,7 +591,7 @@ static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, un
590 return -1; 591 return -1;
591 592
592 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) { 593 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) {
593 dev_warn(&dev->dev, "event field not found\n"); 594 hid_warn(dev, "event field not found\n");
594 return -1; 595 return -1;
595 } 596 }
596 597
@@ -656,7 +657,7 @@ int usbhid_open(struct hid_device *hid)
656 mutex_lock(&hid_open_mut); 657 mutex_lock(&hid_open_mut);
657 if (!hid->open++) { 658 if (!hid->open++) {
658 res = usb_autopm_get_interface(usbhid->intf); 659 res = usb_autopm_get_interface(usbhid->intf);
659 /* the device must be awake to reliable request remote wakeup */ 660 /* the device must be awake to reliably request remote wakeup */
660 if (res < 0) { 661 if (res < 0) {
661 hid->open--; 662 hid->open--;
662 mutex_unlock(&hid_open_mut); 663 mutex_unlock(&hid_open_mut);
@@ -722,7 +723,7 @@ void usbhid_init_reports(struct hid_device *hid)
722 } 723 }
723 724
724 if (err) 725 if (err)
725 dev_warn(&hid->dev, "timeout initializing reports\n"); 726 hid_warn(hid, "timeout initializing reports\n");
726} 727}
727 728
728/* 729/*
@@ -857,18 +858,6 @@ static void usbhid_restart_queues(struct usbhid_device *usbhid)
857 usbhid_restart_ctrl_queue(usbhid); 858 usbhid_restart_ctrl_queue(usbhid);
858} 859}
859 860
860static void __usbhid_restart_queues(struct work_struct *work)
861{
862 struct usbhid_device *usbhid =
863 container_of(work, struct usbhid_device, restart_work);
864 int r;
865
866 r = usb_autopm_get_interface(usbhid->intf);
867 if (r < 0)
868 return;
869 usb_autopm_put_interface(usbhid->intf);
870}
871
872static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid) 861static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
873{ 862{
874 struct usbhid_device *usbhid = hid->driver_data; 863 struct usbhid_device *usbhid = hid->driver_data;
@@ -1140,8 +1129,7 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id *
1140 if (usb_endpoint_is_int_in(&interface->endpoint[n].desc)) 1129 if (usb_endpoint_is_int_in(&interface->endpoint[n].desc))
1141 has_in++; 1130 has_in++;
1142 if (!has_in) { 1131 if (!has_in) {
1143 dev_err(&intf->dev, "couldn't find an input interrupt " 1132 hid_err(intf, "couldn't find an input interrupt endpoint\n");
1144 "endpoint\n");
1145 return -ENODEV; 1133 return -ENODEV;
1146 } 1134 }
1147 1135
@@ -1206,14 +1194,13 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id *
1206 1194
1207 init_waitqueue_head(&usbhid->wait); 1195 init_waitqueue_head(&usbhid->wait);
1208 INIT_WORK(&usbhid->reset_work, hid_reset); 1196 INIT_WORK(&usbhid->reset_work, hid_reset);
1209 INIT_WORK(&usbhid->restart_work, __usbhid_restart_queues);
1210 setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid); 1197 setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid);
1211 spin_lock_init(&usbhid->lock); 1198 spin_lock_init(&usbhid->lock);
1212 1199
1213 ret = hid_add_device(hid); 1200 ret = hid_add_device(hid);
1214 if (ret) { 1201 if (ret) {
1215 if (ret != -ENODEV) 1202 if (ret != -ENODEV)
1216 dev_err(&intf->dev, "can't add hid device: %d\n", ret); 1203 hid_err(intf, "can't add hid device: %d\n", ret);
1217 goto err_free; 1204 goto err_free;
1218 } 1205 }
1219 1206
@@ -1241,7 +1228,6 @@ static void usbhid_disconnect(struct usb_interface *intf)
1241static void hid_cancel_delayed_stuff(struct usbhid_device *usbhid) 1228static void hid_cancel_delayed_stuff(struct usbhid_device *usbhid)
1242{ 1229{
1243 del_timer_sync(&usbhid->io_retry); 1230 del_timer_sync(&usbhid->io_retry);
1244 cancel_work_sync(&usbhid->restart_work);
1245 cancel_work_sync(&usbhid->reset_work); 1231 cancel_work_sync(&usbhid->reset_work);
1246} 1232}
1247 1233
@@ -1262,7 +1248,6 @@ static int hid_pre_reset(struct usb_interface *intf)
1262 spin_lock_irq(&usbhid->lock); 1248 spin_lock_irq(&usbhid->lock);
1263 set_bit(HID_RESET_PENDING, &usbhid->iofl); 1249 set_bit(HID_RESET_PENDING, &usbhid->iofl);
1264 spin_unlock_irq(&usbhid->lock); 1250 spin_unlock_irq(&usbhid->lock);
1265 cancel_work_sync(&usbhid->restart_work);
1266 hid_cease_io(usbhid); 1251 hid_cease_io(usbhid);
1267 1252
1268 return 0; 1253 return 0;
@@ -1461,9 +1446,6 @@ static int __init hid_init(void)
1461{ 1446{
1462 int retval = -ENOMEM; 1447 int retval = -ENOMEM;
1463 1448
1464 resumption_waker = create_freezeable_workqueue("usbhid_resumer");
1465 if (!resumption_waker)
1466 goto no_queue;
1467 retval = hid_register_driver(&hid_usb_driver); 1449 retval = hid_register_driver(&hid_usb_driver);
1468 if (retval) 1450 if (retval)
1469 goto hid_register_fail; 1451 goto hid_register_fail;
@@ -1481,8 +1463,6 @@ usb_register_fail:
1481usbhid_quirks_init_fail: 1463usbhid_quirks_init_fail:
1482 hid_unregister_driver(&hid_usb_driver); 1464 hid_unregister_driver(&hid_usb_driver);
1483hid_register_fail: 1465hid_register_fail:
1484 destroy_workqueue(resumption_waker);
1485no_queue:
1486 return retval; 1466 return retval;
1487} 1467}
1488 1468
@@ -1491,7 +1471,6 @@ static void __exit hid_exit(void)
1491 usb_deregister(&hid_driver); 1471 usb_deregister(&hid_driver);
1492 usbhid_quirks_exit(); 1472 usbhid_quirks_exit();
1493 hid_unregister_driver(&hid_usb_driver); 1473 hid_unregister_driver(&hid_usb_driver);
1494 destroy_workqueue(resumption_waker);
1495} 1474}
1496 1475
1497module_init(hid_init); 1476module_init(hid_init);
diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c
index ef381d79cfa8..f91c136821f7 100644
--- a/drivers/hid/usbhid/hid-pidff.c
+++ b/drivers/hid/usbhid/hid-pidff.c
@@ -22,7 +22,7 @@
22 22
23/* #define DEBUG */ 23/* #define DEBUG */
24 24
25#define debug(format, arg...) pr_debug("hid-pidff: " format "\n" , ## arg) 25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 26
27#include <linux/input.h> 27#include <linux/input.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
@@ -220,7 +220,7 @@ static int pidff_rescale_signed(int i, struct hid_field *field)
220static void pidff_set(struct pidff_usage *usage, u16 value) 220static void pidff_set(struct pidff_usage *usage, u16 value)
221{ 221{
222 usage->value[0] = pidff_rescale(value, 0xffff, usage->field); 222 usage->value[0] = pidff_rescale(value, 0xffff, usage->field);
223 debug("calculated from %d to %d", value, usage->value[0]); 223 pr_debug("calculated from %d to %d\n", value, usage->value[0]);
224} 224}
225 225
226static void pidff_set_signed(struct pidff_usage *usage, s16 value) 226static void pidff_set_signed(struct pidff_usage *usage, s16 value)
@@ -235,7 +235,7 @@ static void pidff_set_signed(struct pidff_usage *usage, s16 value)
235 usage->value[0] = 235 usage->value[0] =
236 pidff_rescale(value, 0x7fff, usage->field); 236 pidff_rescale(value, 0x7fff, usage->field);
237 } 237 }
238 debug("calculated from %d to %d", value, usage->value[0]); 238 pr_debug("calculated from %d to %d\n", value, usage->value[0]);
239} 239}
240 240
241/* 241/*
@@ -259,8 +259,9 @@ static void pidff_set_envelope_report(struct pidff_device *pidff,
259 pidff->set_envelope[PID_ATTACK_TIME].value[0] = envelope->attack_length; 259 pidff->set_envelope[PID_ATTACK_TIME].value[0] = envelope->attack_length;
260 pidff->set_envelope[PID_FADE_TIME].value[0] = envelope->fade_length; 260 pidff->set_envelope[PID_FADE_TIME].value[0] = envelope->fade_length;
261 261
262 debug("attack %u => %d", envelope->attack_level, 262 hid_dbg(pidff->hid, "attack %u => %d\n",
263 pidff->set_envelope[PID_ATTACK_LEVEL].value[0]); 263 envelope->attack_level,
264 pidff->set_envelope[PID_ATTACK_LEVEL].value[0]);
264 265
265 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_ENVELOPE], 266 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_ENVELOPE],
266 USB_DIR_OUT); 267 USB_DIR_OUT);
@@ -466,33 +467,33 @@ static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum)
466 pidff->create_new_effect_type->value[0] = efnum; 467 pidff->create_new_effect_type->value[0] = efnum;
467 usbhid_submit_report(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT], 468 usbhid_submit_report(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT],
468 USB_DIR_OUT); 469 USB_DIR_OUT);
469 debug("create_new_effect sent, type: %d", efnum); 470 hid_dbg(pidff->hid, "create_new_effect sent, type: %d\n", efnum);
470 471
471 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0; 472 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0;
472 pidff->block_load_status->value[0] = 0; 473 pidff->block_load_status->value[0] = 0;
473 usbhid_wait_io(pidff->hid); 474 usbhid_wait_io(pidff->hid);
474 475
475 for (j = 0; j < 60; j++) { 476 for (j = 0; j < 60; j++) {
476 debug("pid_block_load requested"); 477 hid_dbg(pidff->hid, "pid_block_load requested\n");
477 usbhid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_LOAD], 478 usbhid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_LOAD],
478 USB_DIR_IN); 479 USB_DIR_IN);
479 usbhid_wait_io(pidff->hid); 480 usbhid_wait_io(pidff->hid);
480 if (pidff->block_load_status->value[0] == 481 if (pidff->block_load_status->value[0] ==
481 pidff->status_id[PID_BLOCK_LOAD_SUCCESS]) { 482 pidff->status_id[PID_BLOCK_LOAD_SUCCESS]) {
482 debug("device reported free memory: %d bytes", 483 hid_dbg(pidff->hid, "device reported free memory: %d bytes\n",
483 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ? 484 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
484 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1); 485 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
485 return 0; 486 return 0;
486 } 487 }
487 if (pidff->block_load_status->value[0] == 488 if (pidff->block_load_status->value[0] ==
488 pidff->status_id[PID_BLOCK_LOAD_FULL]) { 489 pidff->status_id[PID_BLOCK_LOAD_FULL]) {
489 debug("not enough memory free: %d bytes", 490 hid_dbg(pidff->hid, "not enough memory free: %d bytes\n",
490 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ? 491 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
491 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1); 492 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
492 return -ENOSPC; 493 return -ENOSPC;
493 } 494 }
494 } 495 }
495 printk(KERN_ERR "hid-pidff: pid_block_load failed 60 times\n"); 496 hid_err(pidff->hid, "pid_block_load failed 60 times\n");
496 return -EIO; 497 return -EIO;
497} 498}
498 499
@@ -546,7 +547,8 @@ static int pidff_erase_effect(struct input_dev *dev, int effect_id)
546 struct pidff_device *pidff = dev->ff->private; 547 struct pidff_device *pidff = dev->ff->private;
547 int pid_id = pidff->pid_id[effect_id]; 548 int pid_id = pidff->pid_id[effect_id];
548 549
549 debug("starting to erase %d/%d", effect_id, pidff->pid_id[effect_id]); 550 hid_dbg(pidff->hid, "starting to erase %d/%d\n",
551 effect_id, pidff->pid_id[effect_id]);
550 /* Wait for the queue to clear. We do not want a full fifo to 552 /* Wait for the queue to clear. We do not want a full fifo to
551 prevent the effect removal. */ 553 prevent the effect removal. */
552 usbhid_wait_io(pidff->hid); 554 usbhid_wait_io(pidff->hid);
@@ -604,8 +606,7 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect,
604 type_id = PID_SAW_DOWN; 606 type_id = PID_SAW_DOWN;
605 break; 607 break;
606 default: 608 default:
607 printk(KERN_ERR 609 hid_err(pidff->hid, "invalid waveform\n");
608 "hid-pidff: invalid waveform\n");
609 return -EINVAL; 610 return -EINVAL;
610 } 611 }
611 612
@@ -696,7 +697,7 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect,
696 break; 697 break;
697 698
698 default: 699 default:
699 printk(KERN_ERR "hid-pidff: invalid type\n"); 700 hid_err(pidff->hid, "invalid type\n");
700 return -EINVAL; 701 return -EINVAL;
701 } 702 }
702 703
@@ -704,7 +705,7 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect,
704 pidff->pid_id[effect->id] = 705 pidff->pid_id[effect->id] =
705 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; 706 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
706 707
707 debug("uploaded"); 708 hid_dbg(pidff->hid, "uploaded\n");
708 709
709 return 0; 710 return 0;
710} 711}
@@ -770,14 +771,14 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table,
770 for (i = 0; i < report->maxfield; i++) { 771 for (i = 0; i < report->maxfield; i++) {
771 if (report->field[i]->maxusage != 772 if (report->field[i]->maxusage !=
772 report->field[i]->report_count) { 773 report->field[i]->report_count) {
773 debug("maxusage and report_count do not match, " 774 pr_debug("maxusage and report_count do not match, skipping\n");
774 "skipping");
775 continue; 775 continue;
776 } 776 }
777 for (j = 0; j < report->field[i]->maxusage; j++) { 777 for (j = 0; j < report->field[i]->maxusage; j++) {
778 if (report->field[i]->usage[j].hid == 778 if (report->field[i]->usage[j].hid ==
779 (HID_UP_PID | table[k])) { 779 (HID_UP_PID | table[k])) {
780 debug("found %d at %d->%d", k, i, j); 780 pr_debug("found %d at %d->%d\n",
781 k, i, j);
781 usage[k].field = report->field[i]; 782 usage[k].field = report->field[i];
782 usage[k].value = 783 usage[k].value =
783 &report->field[i]->value[j]; 784 &report->field[i]->value[j];
@@ -789,7 +790,7 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table,
789 break; 790 break;
790 } 791 }
791 if (!found && strict) { 792 if (!found && strict) {
792 debug("failed to locate %d", k); 793 pr_debug("failed to locate %d\n", k);
793 return -1; 794 return -1;
794 } 795 }
795 } 796 }
@@ -826,8 +827,8 @@ static void pidff_find_reports(struct hid_device *hid, int report_type,
826 continue; 827 continue;
827 ret = pidff_check_usage(report->field[0]->logical); 828 ret = pidff_check_usage(report->field[0]->logical);
828 if (ret != -1) { 829 if (ret != -1) {
829 debug("found usage 0x%02x from field->logical", 830 hid_dbg(hid, "found usage 0x%02x from field->logical\n",
830 pidff_reports[ret]); 831 pidff_reports[ret]);
831 pidff->reports[ret] = report; 832 pidff->reports[ret] = report;
832 continue; 833 continue;
833 } 834 }
@@ -845,8 +846,9 @@ static void pidff_find_reports(struct hid_device *hid, int report_type,
845 continue; 846 continue;
846 ret = pidff_check_usage(hid->collection[i - 1].usage); 847 ret = pidff_check_usage(hid->collection[i - 1].usage);
847 if (ret != -1 && !pidff->reports[ret]) { 848 if (ret != -1 && !pidff->reports[ret]) {
848 debug("found usage 0x%02x from collection array", 849 hid_dbg(hid,
849 pidff_reports[ret]); 850 "found usage 0x%02x from collection array\n",
851 pidff_reports[ret]);
850 pidff->reports[ret] = report; 852 pidff->reports[ret] = report;
851 } 853 }
852 } 854 }
@@ -861,7 +863,7 @@ static int pidff_reports_ok(struct pidff_device *pidff)
861 863
862 for (i = 0; i <= PID_REQUIRED_REPORTS; i++) { 864 for (i = 0; i <= PID_REQUIRED_REPORTS; i++) {
863 if (!pidff->reports[i]) { 865 if (!pidff->reports[i]) {
864 debug("%d missing", i); 866 hid_dbg(pidff->hid, "%d missing\n", i);
865 return 0; 867 return 0;
866 } 868 }
867 } 869 }
@@ -884,8 +886,7 @@ static struct hid_field *pidff_find_special_field(struct hid_report *report,
884 report->field[i]->logical_minimum == 1) 886 report->field[i]->logical_minimum == 1)
885 return report->field[i]; 887 return report->field[i];
886 else { 888 else {
887 printk(KERN_ERR "hid-pidff: logical_minimum " 889 pr_err("logical_minimum is not 1 as it should be\n");
888 "is not 1 as it should be\n");
889 return NULL; 890 return NULL;
890 } 891 }
891 } 892 }
@@ -924,7 +925,7 @@ static int pidff_find_special_keys(int *keys, struct hid_field *fld,
924 */ 925 */
925static int pidff_find_special_fields(struct pidff_device *pidff) 926static int pidff_find_special_fields(struct pidff_device *pidff)
926{ 927{
927 debug("finding special fields"); 928 hid_dbg(pidff->hid, "finding special fields\n");
928 929
929 pidff->create_new_effect_type = 930 pidff->create_new_effect_type =
930 pidff_find_special_field(pidff->reports[PID_CREATE_NEW_EFFECT], 931 pidff_find_special_field(pidff->reports[PID_CREATE_NEW_EFFECT],
@@ -945,32 +946,30 @@ static int pidff_find_special_fields(struct pidff_device *pidff)
945 pidff_find_special_field(pidff->reports[PID_EFFECT_OPERATION], 946 pidff_find_special_field(pidff->reports[PID_EFFECT_OPERATION],
946 0x78, 1); 947 0x78, 1);
947 948
948 debug("search done"); 949 hid_dbg(pidff->hid, "search done\n");
949 950
950 if (!pidff->create_new_effect_type || !pidff->set_effect_type) { 951 if (!pidff->create_new_effect_type || !pidff->set_effect_type) {
951 printk(KERN_ERR "hid-pidff: effect lists not found\n"); 952 hid_err(pidff->hid, "effect lists not found\n");
952 return -1; 953 return -1;
953 } 954 }
954 955
955 if (!pidff->effect_direction) { 956 if (!pidff->effect_direction) {
956 printk(KERN_ERR "hid-pidff: direction field not found\n"); 957 hid_err(pidff->hid, "direction field not found\n");
957 return -1; 958 return -1;
958 } 959 }
959 960
960 if (!pidff->device_control) { 961 if (!pidff->device_control) {
961 printk(KERN_ERR "hid-pidff: device control field not found\n"); 962 hid_err(pidff->hid, "device control field not found\n");
962 return -1; 963 return -1;
963 } 964 }
964 965
965 if (!pidff->block_load_status) { 966 if (!pidff->block_load_status) {
966 printk(KERN_ERR 967 hid_err(pidff->hid, "block load status field not found\n");
967 "hid-pidff: block load status field not found\n");
968 return -1; 968 return -1;
969 } 969 }
970 970
971 if (!pidff->effect_operation_status) { 971 if (!pidff->effect_operation_status) {
972 printk(KERN_ERR 972 hid_err(pidff->hid, "effect operation field not found\n");
973 "hid-pidff: effect operation field not found\n");
974 return -1; 973 return -1;
975 } 974 }
976 975
@@ -982,23 +981,22 @@ static int pidff_find_special_fields(struct pidff_device *pidff)
982 981
983 if (!PIDFF_FIND_SPECIAL_KEYS(type_id, create_new_effect_type, 982 if (!PIDFF_FIND_SPECIAL_KEYS(type_id, create_new_effect_type,
984 effect_types)) { 983 effect_types)) {
985 printk(KERN_ERR "hid-pidff: no effect types found\n"); 984 hid_err(pidff->hid, "no effect types found\n");
986 return -1; 985 return -1;
987 } 986 }
988 987
989 if (PIDFF_FIND_SPECIAL_KEYS(status_id, block_load_status, 988 if (PIDFF_FIND_SPECIAL_KEYS(status_id, block_load_status,
990 block_load_status) != 989 block_load_status) !=
991 sizeof(pidff_block_load_status)) { 990 sizeof(pidff_block_load_status)) {
992 printk(KERN_ERR 991 hid_err(pidff->hid,
993 "hidpidff: block load status identifiers not found\n"); 992 "block load status identifiers not found\n");
994 return -1; 993 return -1;
995 } 994 }
996 995
997 if (PIDFF_FIND_SPECIAL_KEYS(operation_id, effect_operation_status, 996 if (PIDFF_FIND_SPECIAL_KEYS(operation_id, effect_operation_status,
998 effect_operation_status) != 997 effect_operation_status) !=
999 sizeof(pidff_effect_operation_status)) { 998 sizeof(pidff_effect_operation_status)) {
1000 printk(KERN_ERR 999 hid_err(pidff->hid, "effect operation identifiers not found\n");
1001 "hidpidff: effect operation identifiers not found\n");
1002 return -1; 1000 return -1;
1003 } 1001 }
1004 1002
@@ -1017,8 +1015,8 @@ static int pidff_find_effects(struct pidff_device *pidff,
1017 int pidff_type = pidff->type_id[i]; 1015 int pidff_type = pidff->type_id[i];
1018 if (pidff->set_effect_type->usage[pidff_type].hid != 1016 if (pidff->set_effect_type->usage[pidff_type].hid !=
1019 pidff->create_new_effect_type->usage[pidff_type].hid) { 1017 pidff->create_new_effect_type->usage[pidff_type].hid) {
1020 printk(KERN_ERR "hid-pidff: " 1018 hid_err(pidff->hid,
1021 "effect type number %d is invalid\n", i); 1019 "effect type number %d is invalid\n", i);
1022 return -1; 1020 return -1;
1023 } 1021 }
1024 } 1022 }
@@ -1073,27 +1071,23 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
1073 int envelope_ok = 0; 1071 int envelope_ok = 0;
1074 1072
1075 if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) { 1073 if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) {
1076 printk(KERN_ERR 1074 hid_err(pidff->hid, "unknown set_effect report layout\n");
1077 "hid-pidff: unknown set_effect report layout\n");
1078 return -ENODEV; 1075 return -ENODEV;
1079 } 1076 }
1080 1077
1081 PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0); 1078 PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0);
1082 if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) { 1079 if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) {
1083 printk(KERN_ERR 1080 hid_err(pidff->hid, "unknown pid_block_load report layout\n");
1084 "hid-pidff: unknown pid_block_load report layout\n");
1085 return -ENODEV; 1081 return -ENODEV;
1086 } 1082 }
1087 1083
1088 if (PIDFF_FIND_FIELDS(effect_operation, PID_EFFECT_OPERATION, 1)) { 1084 if (PIDFF_FIND_FIELDS(effect_operation, PID_EFFECT_OPERATION, 1)) {
1089 printk(KERN_ERR 1085 hid_err(pidff->hid, "unknown effect_operation report layout\n");
1090 "hid-pidff: unknown effect_operation report layout\n");
1091 return -ENODEV; 1086 return -ENODEV;
1092 } 1087 }
1093 1088
1094 if (PIDFF_FIND_FIELDS(block_free, PID_BLOCK_FREE, 1)) { 1089 if (PIDFF_FIND_FIELDS(block_free, PID_BLOCK_FREE, 1)) {
1095 printk(KERN_ERR 1090 hid_err(pidff->hid, "unknown pid_block_free report layout\n");
1096 "hid-pidff: unknown pid_block_free report layout\n");
1097 return -ENODEV; 1091 return -ENODEV;
1098 } 1092 }
1099 1093
@@ -1105,27 +1099,26 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
1105 1099
1106 if (!envelope_ok) { 1100 if (!envelope_ok) {
1107 if (test_and_clear_bit(FF_CONSTANT, dev->ffbit)) 1101 if (test_and_clear_bit(FF_CONSTANT, dev->ffbit))
1108 printk(KERN_WARNING "hid-pidff: " 1102 hid_warn(pidff->hid,
1109 "has constant effect but no envelope\n"); 1103 "has constant effect but no envelope\n");
1110 if (test_and_clear_bit(FF_RAMP, dev->ffbit)) 1104 if (test_and_clear_bit(FF_RAMP, dev->ffbit))
1111 printk(KERN_WARNING "hid-pidff: " 1105 hid_warn(pidff->hid,
1112 "has ramp effect but no envelope\n"); 1106 "has ramp effect but no envelope\n");
1113 1107
1114 if (test_and_clear_bit(FF_PERIODIC, dev->ffbit)) 1108 if (test_and_clear_bit(FF_PERIODIC, dev->ffbit))
1115 printk(KERN_WARNING "hid-pidff: " 1109 hid_warn(pidff->hid,
1116 "has periodic effect but no envelope\n"); 1110 "has periodic effect but no envelope\n");
1117 } 1111 }
1118 1112
1119 if (test_bit(FF_CONSTANT, dev->ffbit) && 1113 if (test_bit(FF_CONSTANT, dev->ffbit) &&
1120 PIDFF_FIND_FIELDS(set_constant, PID_SET_CONSTANT, 1)) { 1114 PIDFF_FIND_FIELDS(set_constant, PID_SET_CONSTANT, 1)) {
1121 printk(KERN_WARNING 1115 hid_warn(pidff->hid, "unknown constant effect layout\n");
1122 "hid-pidff: unknown constant effect layout\n");
1123 clear_bit(FF_CONSTANT, dev->ffbit); 1116 clear_bit(FF_CONSTANT, dev->ffbit);
1124 } 1117 }
1125 1118
1126 if (test_bit(FF_RAMP, dev->ffbit) && 1119 if (test_bit(FF_RAMP, dev->ffbit) &&
1127 PIDFF_FIND_FIELDS(set_ramp, PID_SET_RAMP, 1)) { 1120 PIDFF_FIND_FIELDS(set_ramp, PID_SET_RAMP, 1)) {
1128 printk(KERN_WARNING "hid-pidff: unknown ramp effect layout\n"); 1121 hid_warn(pidff->hid, "unknown ramp effect layout\n");
1129 clear_bit(FF_RAMP, dev->ffbit); 1122 clear_bit(FF_RAMP, dev->ffbit);
1130 } 1123 }
1131 1124
@@ -1134,8 +1127,7 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
1134 test_bit(FF_FRICTION, dev->ffbit) || 1127 test_bit(FF_FRICTION, dev->ffbit) ||
1135 test_bit(FF_INERTIA, dev->ffbit)) && 1128 test_bit(FF_INERTIA, dev->ffbit)) &&
1136 PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) { 1129 PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) {
1137 printk(KERN_WARNING 1130 hid_warn(pidff->hid, "unknown condition effect layout\n");
1138 "hid-pidff: unknown condition effect layout\n");
1139 clear_bit(FF_SPRING, dev->ffbit); 1131 clear_bit(FF_SPRING, dev->ffbit);
1140 clear_bit(FF_DAMPER, dev->ffbit); 1132 clear_bit(FF_DAMPER, dev->ffbit);
1141 clear_bit(FF_FRICTION, dev->ffbit); 1133 clear_bit(FF_FRICTION, dev->ffbit);
@@ -1144,8 +1136,7 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
1144 1136
1145 if (test_bit(FF_PERIODIC, dev->ffbit) && 1137 if (test_bit(FF_PERIODIC, dev->ffbit) &&
1146 PIDFF_FIND_FIELDS(set_periodic, PID_SET_PERIODIC, 1)) { 1138 PIDFF_FIND_FIELDS(set_periodic, PID_SET_PERIODIC, 1)) {
1147 printk(KERN_WARNING 1139 hid_warn(pidff->hid, "unknown periodic effect layout\n");
1148 "hid-pidff: unknown periodic effect layout\n");
1149 clear_bit(FF_PERIODIC, dev->ffbit); 1140 clear_bit(FF_PERIODIC, dev->ffbit);
1150 } 1141 }
1151 1142
@@ -1184,12 +1175,12 @@ static void pidff_reset(struct pidff_device *pidff)
1184 if (pidff->pool[PID_SIMULTANEOUS_MAX].value) { 1175 if (pidff->pool[PID_SIMULTANEOUS_MAX].value) {
1185 while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) { 1176 while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) {
1186 if (i++ > 20) { 1177 if (i++ > 20) {
1187 printk(KERN_WARNING "hid-pidff: device reports " 1178 hid_warn(pidff->hid,
1188 "%d simultaneous effects\n", 1179 "device reports %d simultaneous effects\n",
1189 pidff->pool[PID_SIMULTANEOUS_MAX].value[0]); 1180 pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
1190 break; 1181 break;
1191 } 1182 }
1192 debug("pid_pool requested again"); 1183 hid_dbg(pidff->hid, "pid_pool requested again\n");
1193 usbhid_submit_report(hid, pidff->reports[PID_POOL], 1184 usbhid_submit_report(hid, pidff->reports[PID_POOL],
1194 USB_DIR_IN); 1185 USB_DIR_IN);
1195 usbhid_wait_io(hid); 1186 usbhid_wait_io(hid);
@@ -1215,7 +1206,7 @@ static int pidff_check_autocenter(struct pidff_device *pidff,
1215 1206
1216 error = pidff_request_effect_upload(pidff, 1); 1207 error = pidff_request_effect_upload(pidff, 1);
1217 if (error) { 1208 if (error) {
1218 printk(KERN_ERR "hid-pidff: upload request failed\n"); 1209 hid_err(pidff->hid, "upload request failed\n");
1219 return error; 1210 return error;
1220 } 1211 }
1221 1212
@@ -1224,8 +1215,8 @@ static int pidff_check_autocenter(struct pidff_device *pidff,
1224 pidff_autocenter(pidff, 0xffff); 1215 pidff_autocenter(pidff, 0xffff);
1225 set_bit(FF_AUTOCENTER, dev->ffbit); 1216 set_bit(FF_AUTOCENTER, dev->ffbit);
1226 } else { 1217 } else {
1227 printk(KERN_NOTICE "hid-pidff: " 1218 hid_notice(pidff->hid,
1228 "device has unknown autocenter control method\n"); 1219 "device has unknown autocenter control method\n");
1229 } 1220 }
1230 1221
1231 pidff_erase_pid(pidff, 1222 pidff_erase_pid(pidff,
@@ -1248,10 +1239,10 @@ int hid_pidff_init(struct hid_device *hid)
1248 int max_effects; 1239 int max_effects;
1249 int error; 1240 int error;
1250 1241
1251 debug("starting pid init"); 1242 hid_dbg(hid, "starting pid init\n");
1252 1243
1253 if (list_empty(&hid->report_enum[HID_OUTPUT_REPORT].report_list)) { 1244 if (list_empty(&hid->report_enum[HID_OUTPUT_REPORT].report_list)) {
1254 debug("not a PID device, no output report"); 1245 hid_dbg(hid, "not a PID device, no output report\n");
1255 return -ENODEV; 1246 return -ENODEV;
1256 } 1247 }
1257 1248
@@ -1265,7 +1256,7 @@ int hid_pidff_init(struct hid_device *hid)
1265 pidff_find_reports(hid, HID_FEATURE_REPORT, pidff); 1256 pidff_find_reports(hid, HID_FEATURE_REPORT, pidff);
1266 1257
1267 if (!pidff_reports_ok(pidff)) { 1258 if (!pidff_reports_ok(pidff)) {
1268 debug("reports not ok, aborting"); 1259 hid_dbg(hid, "reports not ok, aborting\n");
1269 error = -ENODEV; 1260 error = -ENODEV;
1270 goto fail; 1261 goto fail;
1271 } 1262 }
@@ -1278,8 +1269,8 @@ int hid_pidff_init(struct hid_device *hid)
1278 1269
1279 if (test_bit(FF_GAIN, dev->ffbit)) { 1270 if (test_bit(FF_GAIN, dev->ffbit)) {
1280 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff); 1271 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff);
1281 usbhid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN], 1272 usbhid_submit_report(hid, pidff->reports[PID_DEVICE_GAIN],
1282 USB_DIR_OUT); 1273 USB_DIR_OUT);
1283 } 1274 }
1284 1275
1285 error = pidff_check_autocenter(pidff, dev); 1276 error = pidff_check_autocenter(pidff, dev);
@@ -1290,23 +1281,23 @@ int hid_pidff_init(struct hid_device *hid)
1290 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_maximum - 1281 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_maximum -
1291 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum + 1282 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum +
1292 1; 1283 1;
1293 debug("max effects is %d", max_effects); 1284 hid_dbg(hid, "max effects is %d\n", max_effects);
1294 1285
1295 if (max_effects > PID_EFFECTS_MAX) 1286 if (max_effects > PID_EFFECTS_MAX)
1296 max_effects = PID_EFFECTS_MAX; 1287 max_effects = PID_EFFECTS_MAX;
1297 1288
1298 if (pidff->pool[PID_SIMULTANEOUS_MAX].value) 1289 if (pidff->pool[PID_SIMULTANEOUS_MAX].value)
1299 debug("max simultaneous effects is %d", 1290 hid_dbg(hid, "max simultaneous effects is %d\n",
1300 pidff->pool[PID_SIMULTANEOUS_MAX].value[0]); 1291 pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
1301 1292
1302 if (pidff->pool[PID_RAM_POOL_SIZE].value) 1293 if (pidff->pool[PID_RAM_POOL_SIZE].value)
1303 debug("device memory size is %d bytes", 1294 hid_dbg(hid, "device memory size is %d bytes\n",
1304 pidff->pool[PID_RAM_POOL_SIZE].value[0]); 1295 pidff->pool[PID_RAM_POOL_SIZE].value[0]);
1305 1296
1306 if (pidff->pool[PID_DEVICE_MANAGED_POOL].value && 1297 if (pidff->pool[PID_DEVICE_MANAGED_POOL].value &&
1307 pidff->pool[PID_DEVICE_MANAGED_POOL].value[0] == 0) { 1298 pidff->pool[PID_DEVICE_MANAGED_POOL].value[0] == 0) {
1308 printk(KERN_NOTICE "hid-pidff: " 1299 hid_notice(hid,
1309 "device does not support device managed pool\n"); 1300 "device does not support device managed pool\n");
1310 goto fail; 1301 goto fail;
1311 } 1302 }
1312 1303
@@ -1322,8 +1313,7 @@ int hid_pidff_init(struct hid_device *hid)
1322 ff->set_autocenter = pidff_set_autocenter; 1313 ff->set_autocenter = pidff_set_autocenter;
1323 ff->playback = pidff_playback; 1314 ff->playback = pidff_playback;
1324 1315
1325 printk(KERN_INFO "Force feedback for USB HID PID devices by " 1316 hid_info(dev, "Force feedback for USB HID PID devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
1326 "Anssi Hannula <anssi.hannula@gmail.com>\n");
1327 1317
1328 return 0; 1318 return 0;
1329 1319
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 2c185477eeb3..76b9a149c7df 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -85,7 +85,7 @@ static const struct hid_blacklist {
85 { USB_VENDOR_ID_PI_ENGINEERING, USB_DEVICE_ID_PI_ENGINEERING_VEC_USB_FOOTPEDAL, HID_QUIRK_HIDINPUT_FORCE }, 85 { USB_VENDOR_ID_PI_ENGINEERING, USB_DEVICE_ID_PI_ENGINEERING_VEC_USB_FOOTPEDAL, HID_QUIRK_HIDINPUT_FORCE },
86 86
87 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_MULTI_TOUCH, HID_QUIRK_MULTI_INPUT }, 87 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_MULTI_TOUCH, HID_QUIRK_MULTI_INPUT },
88 88 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS, HID_QUIRK_MULTI_INPUT },
89 { 0, 0 } 89 { 0, 0 }
90}; 90};
91 91
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index 984feb351a5a..af0a7c1002af 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -585,163 +585,168 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
585{ 585{
586 struct hiddev_list *list = file->private_data; 586 struct hiddev_list *list = file->private_data;
587 struct hiddev *hiddev = list->hiddev; 587 struct hiddev *hiddev = list->hiddev;
588 struct hid_device *hid = hiddev->hid; 588 struct hid_device *hid;
589 struct usb_device *dev;
590 struct hiddev_collection_info cinfo; 589 struct hiddev_collection_info cinfo;
591 struct hiddev_report_info rinfo; 590 struct hiddev_report_info rinfo;
592 struct hiddev_field_info finfo; 591 struct hiddev_field_info finfo;
593 struct hiddev_devinfo dinfo; 592 struct hiddev_devinfo dinfo;
594 struct hid_report *report; 593 struct hid_report *report;
595 struct hid_field *field; 594 struct hid_field *field;
596 struct usbhid_device *usbhid = hid->driver_data;
597 void __user *user_arg = (void __user *)arg; 595 void __user *user_arg = (void __user *)arg;
598 int i, r; 596 int i, r = -EINVAL;
599 597
600 /* Called without BKL by compat methods so no BKL taken */ 598 /* Called without BKL by compat methods so no BKL taken */
601 599
602 /* FIXME: Who or what stop this racing with a disconnect ?? */ 600 mutex_lock(&hiddev->existancelock);
603 if (!hiddev->exist || !hid) 601 if (!hiddev->exist) {
604 return -EIO; 602 r = -ENODEV;
603 goto ret_unlock;
604 }
605 605
606 dev = hid_to_usb_dev(hid); 606 hid = hiddev->hid;
607 607
608 switch (cmd) { 608 switch (cmd) {
609 609
610 case HIDIOCGVERSION: 610 case HIDIOCGVERSION:
611 return put_user(HID_VERSION, (int __user *)arg); 611 r = put_user(HID_VERSION, (int __user *)arg) ?
612 -EFAULT : 0;
613 break;
612 614
613 case HIDIOCAPPLICATION: 615 case HIDIOCAPPLICATION:
614 if (arg < 0 || arg >= hid->maxapplication) 616 if (arg < 0 || arg >= hid->maxapplication)
615 return -EINVAL; 617 break;
616 618
617 for (i = 0; i < hid->maxcollection; i++) 619 for (i = 0; i < hid->maxcollection; i++)
618 if (hid->collection[i].type == 620 if (hid->collection[i].type ==
619 HID_COLLECTION_APPLICATION && arg-- == 0) 621 HID_COLLECTION_APPLICATION && arg-- == 0)
620 break; 622 break;
621 623
622 if (i == hid->maxcollection) 624 if (i < hid->maxcollection)
623 return -EINVAL; 625 r = hid->collection[i].usage;
624 626 break;
625 return hid->collection[i].usage;
626 627
627 case HIDIOCGDEVINFO: 628 case HIDIOCGDEVINFO:
628 dinfo.bustype = BUS_USB; 629 {
629 dinfo.busnum = dev->bus->busnum; 630 struct usb_device *dev = hid_to_usb_dev(hid);
630 dinfo.devnum = dev->devnum; 631 struct usbhid_device *usbhid = hid->driver_data;
631 dinfo.ifnum = usbhid->ifnum; 632
632 dinfo.vendor = le16_to_cpu(dev->descriptor.idVendor); 633 dinfo.bustype = BUS_USB;
633 dinfo.product = le16_to_cpu(dev->descriptor.idProduct); 634 dinfo.busnum = dev->bus->busnum;
634 dinfo.version = le16_to_cpu(dev->descriptor.bcdDevice); 635 dinfo.devnum = dev->devnum;
635 dinfo.num_applications = hid->maxapplication; 636 dinfo.ifnum = usbhid->ifnum;
636 if (copy_to_user(user_arg, &dinfo, sizeof(dinfo))) 637 dinfo.vendor = le16_to_cpu(dev->descriptor.idVendor);
637 return -EFAULT; 638 dinfo.product = le16_to_cpu(dev->descriptor.idProduct);
638 639 dinfo.version = le16_to_cpu(dev->descriptor.bcdDevice);
639 return 0; 640 dinfo.num_applications = hid->maxapplication;
641
642 r = copy_to_user(user_arg, &dinfo, sizeof(dinfo)) ?
643 -EFAULT : 0;
644 break;
645 }
640 646
641 case HIDIOCGFLAG: 647 case HIDIOCGFLAG:
642 if (put_user(list->flags, (int __user *)arg)) 648 r = put_user(list->flags, (int __user *)arg) ?
643 return -EFAULT; 649 -EFAULT : 0;
644 650 break;
645 return 0;
646 651
647 case HIDIOCSFLAG: 652 case HIDIOCSFLAG:
648 { 653 {
649 int newflags; 654 int newflags;
650 if (get_user(newflags, (int __user *)arg)) 655
651 return -EFAULT; 656 if (get_user(newflags, (int __user *)arg)) {
657 r = -EFAULT;
658 break;
659 }
652 660
653 if ((newflags & ~HIDDEV_FLAGS) != 0 || 661 if ((newflags & ~HIDDEV_FLAGS) != 0 ||
654 ((newflags & HIDDEV_FLAG_REPORT) != 0 && 662 ((newflags & HIDDEV_FLAG_REPORT) != 0 &&
655 (newflags & HIDDEV_FLAG_UREF) == 0)) 663 (newflags & HIDDEV_FLAG_UREF) == 0))
656 return -EINVAL; 664 break;
657 665
658 list->flags = newflags; 666 list->flags = newflags;
659 667
660 return 0; 668 r = 0;
669 break;
661 } 670 }
662 671
663 case HIDIOCGSTRING: 672 case HIDIOCGSTRING:
664 mutex_lock(&hiddev->existancelock); 673 r = hiddev_ioctl_string(hiddev, cmd, user_arg);
665 if (hiddev->exist) 674 break;
666 r = hiddev_ioctl_string(hiddev, cmd, user_arg);
667 else
668 r = -ENODEV;
669 mutex_unlock(&hiddev->existancelock);
670 return r;
671 675
672 case HIDIOCINITREPORT: 676 case HIDIOCINITREPORT:
673 mutex_lock(&hiddev->existancelock);
674 if (!hiddev->exist) {
675 mutex_unlock(&hiddev->existancelock);
676 return -ENODEV;
677 }
678 usbhid_init_reports(hid); 677 usbhid_init_reports(hid);
679 mutex_unlock(&hiddev->existancelock); 678 r = 0;
680 679 break;
681 return 0;
682 680
683 case HIDIOCGREPORT: 681 case HIDIOCGREPORT:
684 if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) 682 if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) {
685 return -EFAULT; 683 r = -EFAULT;
684 break;
685 }
686 686
687 if (rinfo.report_type == HID_REPORT_TYPE_OUTPUT) 687 if (rinfo.report_type == HID_REPORT_TYPE_OUTPUT)
688 return -EINVAL; 688 break;
689 689
690 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) 690 report = hiddev_lookup_report(hid, &rinfo);
691 return -EINVAL; 691 if (report == NULL)
692 break;
692 693
693 mutex_lock(&hiddev->existancelock); 694 usbhid_submit_report(hid, report, USB_DIR_IN);
694 if (hiddev->exist) { 695 usbhid_wait_io(hid);
695 usbhid_submit_report(hid, report, USB_DIR_IN);
696 usbhid_wait_io(hid);
697 }
698 mutex_unlock(&hiddev->existancelock);
699 696
700 return 0; 697 r = 0;
698 break;
701 699
702 case HIDIOCSREPORT: 700 case HIDIOCSREPORT:
703 if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) 701 if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) {
704 return -EFAULT; 702 r = -EFAULT;
703 break;
704 }
705 705
706 if (rinfo.report_type == HID_REPORT_TYPE_INPUT) 706 if (rinfo.report_type == HID_REPORT_TYPE_INPUT)
707 return -EINVAL; 707 break;
708 708
709 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) 709 report = hiddev_lookup_report(hid, &rinfo);
710 return -EINVAL; 710 if (report == NULL)
711 break;
711 712
712 mutex_lock(&hiddev->existancelock); 713 usbhid_submit_report(hid, report, USB_DIR_OUT);
713 if (hiddev->exist) { 714 usbhid_wait_io(hid);
714 usbhid_submit_report(hid, report, USB_DIR_OUT);
715 usbhid_wait_io(hid);
716 }
717 mutex_unlock(&hiddev->existancelock);
718 715
719 return 0; 716 r = 0;
717 break;
720 718
721 case HIDIOCGREPORTINFO: 719 case HIDIOCGREPORTINFO:
722 if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) 720 if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) {
723 return -EFAULT; 721 r = -EFAULT;
722 break;
723 }
724 724
725 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) 725 report = hiddev_lookup_report(hid, &rinfo);
726 return -EINVAL; 726 if (report == NULL)
727 break;
727 728
728 rinfo.num_fields = report->maxfield; 729 rinfo.num_fields = report->maxfield;
729 730
730 if (copy_to_user(user_arg, &rinfo, sizeof(rinfo))) 731 r = copy_to_user(user_arg, &rinfo, sizeof(rinfo)) ?
731 return -EFAULT; 732 -EFAULT : 0;
732 733 break;
733 return 0;
734 734
735 case HIDIOCGFIELDINFO: 735 case HIDIOCGFIELDINFO:
736 if (copy_from_user(&finfo, user_arg, sizeof(finfo))) 736 if (copy_from_user(&finfo, user_arg, sizeof(finfo))) {
737 return -EFAULT; 737 r = -EFAULT;
738 break;
739 }
740
738 rinfo.report_type = finfo.report_type; 741 rinfo.report_type = finfo.report_type;
739 rinfo.report_id = finfo.report_id; 742 rinfo.report_id = finfo.report_id;
740 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) 743
741 return -EINVAL; 744 report = hiddev_lookup_report(hid, &rinfo);
745 if (report == NULL)
746 break;
742 747
743 if (finfo.field_index >= report->maxfield) 748 if (finfo.field_index >= report->maxfield)
744 return -EINVAL; 749 break;
745 750
746 field = report->field[finfo.field_index]; 751 field = report->field[finfo.field_index];
747 memset(&finfo, 0, sizeof(finfo)); 752 memset(&finfo, 0, sizeof(finfo));
@@ -760,10 +765,9 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
760 finfo.unit_exponent = field->unit_exponent; 765 finfo.unit_exponent = field->unit_exponent;
761 finfo.unit = field->unit; 766 finfo.unit = field->unit;
762 767
763 if (copy_to_user(user_arg, &finfo, sizeof(finfo))) 768 r = copy_to_user(user_arg, &finfo, sizeof(finfo)) ?
764 return -EFAULT; 769 -EFAULT : 0;
765 770 break;
766 return 0;
767 771
768 case HIDIOCGUCODE: 772 case HIDIOCGUCODE:
769 /* fall through */ 773 /* fall through */
@@ -772,57 +776,66 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
772 case HIDIOCGUSAGES: 776 case HIDIOCGUSAGES:
773 case HIDIOCSUSAGES: 777 case HIDIOCSUSAGES:
774 case HIDIOCGCOLLECTIONINDEX: 778 case HIDIOCGCOLLECTIONINDEX:
775 mutex_lock(&hiddev->existancelock); 779 r = hiddev_ioctl_usage(hiddev, cmd, user_arg);
776 if (hiddev->exist) 780 break;
777 r = hiddev_ioctl_usage(hiddev, cmd, user_arg);
778 else
779 r = -ENODEV;
780 mutex_unlock(&hiddev->existancelock);
781 return r;
782 781
783 case HIDIOCGCOLLECTIONINFO: 782 case HIDIOCGCOLLECTIONINFO:
784 if (copy_from_user(&cinfo, user_arg, sizeof(cinfo))) 783 if (copy_from_user(&cinfo, user_arg, sizeof(cinfo))) {
785 return -EFAULT; 784 r = -EFAULT;
785 break;
786 }
786 787
787 if (cinfo.index >= hid->maxcollection) 788 if (cinfo.index >= hid->maxcollection)
788 return -EINVAL; 789 break;
789 790
790 cinfo.type = hid->collection[cinfo.index].type; 791 cinfo.type = hid->collection[cinfo.index].type;
791 cinfo.usage = hid->collection[cinfo.index].usage; 792 cinfo.usage = hid->collection[cinfo.index].usage;
792 cinfo.level = hid->collection[cinfo.index].level; 793 cinfo.level = hid->collection[cinfo.index].level;
793 794
794 if (copy_to_user(user_arg, &cinfo, sizeof(cinfo))) 795 r = copy_to_user(user_arg, &cinfo, sizeof(cinfo)) ?
795 return -EFAULT; 796 -EFAULT : 0;
796 return 0; 797 break;
797 798
798 default: 799 default:
799
800 if (_IOC_TYPE(cmd) != 'H' || _IOC_DIR(cmd) != _IOC_READ) 800 if (_IOC_TYPE(cmd) != 'H' || _IOC_DIR(cmd) != _IOC_READ)
801 return -EINVAL; 801 break;
802 802
803 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGNAME(0))) { 803 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGNAME(0))) {
804 int len; 804 int len;
805 if (!hid->name) 805
806 return 0; 806 if (!hid->name) {
807 r = 0;
808 break;
809 }
810
807 len = strlen(hid->name) + 1; 811 len = strlen(hid->name) + 1;
808 if (len > _IOC_SIZE(cmd)) 812 if (len > _IOC_SIZE(cmd))
809 len = _IOC_SIZE(cmd); 813 len = _IOC_SIZE(cmd);
810 return copy_to_user(user_arg, hid->name, len) ? 814 r = copy_to_user(user_arg, hid->name, len) ?
811 -EFAULT : len; 815 -EFAULT : len;
816 break;
812 } 817 }
813 818
814 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGPHYS(0))) { 819 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGPHYS(0))) {
815 int len; 820 int len;
816 if (!hid->phys) 821
817 return 0; 822 if (!hid->phys) {
823 r = 0;
824 break;
825 }
826
818 len = strlen(hid->phys) + 1; 827 len = strlen(hid->phys) + 1;
819 if (len > _IOC_SIZE(cmd)) 828 if (len > _IOC_SIZE(cmd))
820 len = _IOC_SIZE(cmd); 829 len = _IOC_SIZE(cmd);
821 return copy_to_user(user_arg, hid->phys, len) ? 830 r = copy_to_user(user_arg, hid->phys, len) ?
822 -EFAULT : len; 831 -EFAULT : len;
832 break;
823 } 833 }
824 } 834 }
825 return -EINVAL; 835
836ret_unlock:
837 mutex_unlock(&hiddev->existancelock);
838 return r;
826} 839}
827 840
828#ifdef CONFIG_COMPAT 841#ifdef CONFIG_COMPAT
@@ -892,7 +905,7 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
892 hiddev->exist = 1; 905 hiddev->exist = 1;
893 retval = usb_register_dev(usbhid->intf, &hiddev_class); 906 retval = usb_register_dev(usbhid->intf, &hiddev_class);
894 if (retval) { 907 if (retval) {
895 err_hid("Not able to get a minor for this device."); 908 hid_err(hid, "Not able to get a minor for this device\n");
896 hid->hiddev = NULL; 909 hid->hiddev = NULL;
897 kfree(hiddev); 910 kfree(hiddev);
898 return -1; 911 return -1;
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h
index 89d2e847dcc6..1673cac93d77 100644
--- a/drivers/hid/usbhid/usbhid.h
+++ b/drivers/hid/usbhid/usbhid.h
@@ -95,7 +95,6 @@ struct usbhid_device {
95 unsigned long stop_retry; /* Time to give up, in jiffies */ 95 unsigned long stop_retry; /* Time to give up, in jiffies */
96 unsigned int retry_delay; /* Delay length in ms */ 96 unsigned int retry_delay; /* Delay length in ms */
97 struct work_struct reset_work; /* Task context for resets */ 97 struct work_struct reset_work; /* Task context for resets */
98 struct work_struct restart_work; /* waking up for output to be done in a task */
99 wait_queue_head_t wait; /* For sleeping */ 98 wait_queue_head_t wait; /* For sleeping */
100 int ledcount; /* counting the number of active leds */ 99 int ledcount; /* counting the number of active leds */
101}; 100};
diff --git a/drivers/hid/usbhid/usbkbd.c b/drivers/hid/usbhid/usbkbd.c
index a948605564fb..065817329f03 100644
--- a/drivers/hid/usbhid/usbkbd.c
+++ b/drivers/hid/usbhid/usbkbd.c
@@ -24,6 +24,8 @@
24 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 24 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
25 */ 25 */
26 26
27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
27#include <linux/kernel.h> 29#include <linux/kernel.h>
28#include <linux/slab.h> 30#include <linux/slab.h>
29#include <linux/module.h> 31#include <linux/module.h>
@@ -104,16 +106,18 @@ static void usb_kbd_irq(struct urb *urb)
104 if (usb_kbd_keycode[kbd->old[i]]) 106 if (usb_kbd_keycode[kbd->old[i]])
105 input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0); 107 input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0);
106 else 108 else
107 dev_info(&urb->dev->dev, 109 hid_info(urb->dev,
108 "Unknown key (scancode %#x) released.\n", kbd->old[i]); 110 "Unknown key (scancode %#x) released.\n",
111 kbd->old[i]);
109 } 112 }
110 113
111 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) { 114 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) {
112 if (usb_kbd_keycode[kbd->new[i]]) 115 if (usb_kbd_keycode[kbd->new[i]])
113 input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1); 116 input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1);
114 else 117 else
115 dev_info(&urb->dev->dev, 118 hid_info(urb->dev,
116 "Unknown key (scancode %#x) released.\n", kbd->new[i]); 119 "Unknown key (scancode %#x) released.\n",
120 kbd->new[i]);
117 } 121 }
118 } 122 }
119 123
@@ -124,9 +128,9 @@ static void usb_kbd_irq(struct urb *urb)
124resubmit: 128resubmit:
125 i = usb_submit_urb (urb, GFP_ATOMIC); 129 i = usb_submit_urb (urb, GFP_ATOMIC);
126 if (i) 130 if (i)
127 err_hid ("can't resubmit intr, %s-%s/input0, status %d", 131 hid_err(urb->dev, "can't resubmit intr, %s-%s/input0, status %d",
128 kbd->usbdev->bus->bus_name, 132 kbd->usbdev->bus->bus_name,
129 kbd->usbdev->devpath, i); 133 kbd->usbdev->devpath, i);
130} 134}
131 135
132static int usb_kbd_event(struct input_dev *dev, unsigned int type, 136static int usb_kbd_event(struct input_dev *dev, unsigned int type,
@@ -150,7 +154,7 @@ static int usb_kbd_event(struct input_dev *dev, unsigned int type,
150 *(kbd->leds) = kbd->newleds; 154 *(kbd->leds) = kbd->newleds;
151 kbd->led->dev = kbd->usbdev; 155 kbd->led->dev = kbd->usbdev;
152 if (usb_submit_urb(kbd->led, GFP_ATOMIC)) 156 if (usb_submit_urb(kbd->led, GFP_ATOMIC))
153 err_hid("usb_submit_urb(leds) failed"); 157 pr_err("usb_submit_urb(leds) failed\n");
154 158
155 return 0; 159 return 0;
156} 160}
@@ -160,7 +164,7 @@ static void usb_kbd_led(struct urb *urb)
160 struct usb_kbd *kbd = urb->context; 164 struct usb_kbd *kbd = urb->context;
161 165
162 if (urb->status) 166 if (urb->status)
163 dev_warn(&urb->dev->dev, "led urb status %d received\n", 167 hid_warn(urb->dev, "led urb status %d received\n",
164 urb->status); 168 urb->status);
165 169
166 if (*(kbd->leds) == kbd->newleds) 170 if (*(kbd->leds) == kbd->newleds)
@@ -169,7 +173,7 @@ static void usb_kbd_led(struct urb *urb)
169 *(kbd->leds) = kbd->newleds; 173 *(kbd->leds) = kbd->newleds;
170 kbd->led->dev = kbd->usbdev; 174 kbd->led->dev = kbd->usbdev;
171 if (usb_submit_urb(kbd->led, GFP_ATOMIC)) 175 if (usb_submit_urb(kbd->led, GFP_ATOMIC))
172 err_hid("usb_submit_urb(leds) failed"); 176 hid_err(urb->dev, "usb_submit_urb(leds) failed\n");
173} 177}
174 178
175static int usb_kbd_open(struct input_dev *dev) 179static int usb_kbd_open(struct input_dev *dev)
diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c
index b95231763911..ee82851afe3e 100644
--- a/drivers/input/mouse/bcm5974.c
+++ b/drivers/input/mouse/bcm5974.c
@@ -55,6 +55,14 @@
55#define USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI 0x0236 55#define USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI 0x0236
56#define USB_DEVICE_ID_APPLE_WELLSPRING3_ISO 0x0237 56#define USB_DEVICE_ID_APPLE_WELLSPRING3_ISO 0x0237
57#define USB_DEVICE_ID_APPLE_WELLSPRING3_JIS 0x0238 57#define USB_DEVICE_ID_APPLE_WELLSPRING3_JIS 0x0238
58/* MacbookAir3,2 (unibody), aka wellspring5 */
59#define USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI 0x023f
60#define USB_DEVICE_ID_APPLE_WELLSPRING4_ISO 0x0240
61#define USB_DEVICE_ID_APPLE_WELLSPRING4_JIS 0x0241
62/* MacbookAir3,1 (unibody), aka wellspring4 */
63#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242
64#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243
65#define USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS 0x0244
58 66
59#define BCM5974_DEVICE(prod) { \ 67#define BCM5974_DEVICE(prod) { \
60 .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \ 68 .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \
@@ -80,6 +88,14 @@ static const struct usb_device_id bcm5974_table[] = {
80 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI), 88 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI),
81 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ISO), 89 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ISO),
82 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_JIS), 90 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
91 /* MacbookAir3,2 */
92 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI),
93 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_ISO),
94 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_JIS),
95 /* MacbookAir3,1 */
96 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI),
97 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO),
98 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
83 /* Terminating entry */ 99 /* Terminating entry */
84 {} 100 {}
85}; 101};
@@ -234,6 +250,30 @@ static const struct bcm5974_config bcm5974_config_table[] = {
234 { DIM_X, DIM_X / SN_COORD, -4460, 5166 }, 250 { DIM_X, DIM_X / SN_COORD, -4460, 5166 },
235 { DIM_Y, DIM_Y / SN_COORD, -75, 6700 } 251 { DIM_Y, DIM_Y / SN_COORD, -75, 6700 }
236 }, 252 },
253 {
254 USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI,
255 USB_DEVICE_ID_APPLE_WELLSPRING4_ISO,
256 USB_DEVICE_ID_APPLE_WELLSPRING4_JIS,
257 HAS_INTEGRATED_BUTTON,
258 0x84, sizeof(struct bt_data),
259 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
260 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 },
261 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 },
262 { DIM_X, DIM_X / SN_COORD, -4620, 5140 },
263 { DIM_Y, DIM_Y / SN_COORD, -150, 6600 }
264 },
265 {
266 USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI,
267 USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO,
268 USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS,
269 HAS_INTEGRATED_BUTTON,
270 0x84, sizeof(struct bt_data),
271 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
272 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 },
273 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 },
274 { DIM_X, DIM_X / SN_COORD, -4616, 5112 },
275 { DIM_Y, DIM_Y / SN_COORD, -142, 5234 }
276 },
237 {} 277 {}
238}; 278};
239 279
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 559b0b3c16c3..ab1ad41786d1 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -20,6 +20,7 @@
20#include <linux/log2.h> 20#include <linux/log2.h>
21#include <linux/bitops.h> 21#include <linux/bitops.h>
22#include <linux/jiffies.h> 22#include <linux/jiffies.h>
23#include <linux/of.h>
23#include <linux/i2c.h> 24#include <linux/i2c.h>
24#include <linux/i2c/at24.h> 25#include <linux/i2c/at24.h>
25 26
@@ -457,6 +458,27 @@ static ssize_t at24_macc_write(struct memory_accessor *macc, const char *buf,
457 458
458/*-------------------------------------------------------------------------*/ 459/*-------------------------------------------------------------------------*/
459 460
461#ifdef CONFIG_OF
462static void at24_get_ofdata(struct i2c_client *client,
463 struct at24_platform_data *chip)
464{
465 const __be32 *val;
466 struct device_node *node = client->dev.of_node;
467
468 if (node) {
469 if (of_get_property(node, "read-only", NULL))
470 chip->flags |= AT24_FLAG_READONLY;
471 val = of_get_property(node, "pagesize", NULL);
472 if (val)
473 chip->page_size = be32_to_cpup(val);
474 }
475}
476#else
477static void at24_get_ofdata(struct i2c_client *client,
478 struct at24_platform_data *chip)
479{ }
480#endif /* CONFIG_OF */
481
460static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) 482static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
461{ 483{
462 struct at24_platform_data chip; 484 struct at24_platform_data chip;
@@ -485,6 +507,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
485 */ 507 */
486 chip.page_size = 1; 508 chip.page_size = 1;
487 509
510 /* update chipdata if OF is present */
511 at24_get_ofdata(client, &chip);
512
488 chip.setup = NULL; 513 chip.setup = NULL;
489 chip.context = NULL; 514 chip.context = NULL;
490 } 515 }
@@ -492,6 +517,11 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
492 if (!is_power_of_2(chip.byte_len)) 517 if (!is_power_of_2(chip.byte_len))
493 dev_warn(&client->dev, 518 dev_warn(&client->dev,
494 "byte_len looks suspicious (no power of 2)!\n"); 519 "byte_len looks suspicious (no power of 2)!\n");
520 if (!chip.page_size) {
521 dev_err(&client->dev, "page_size must not be 0!\n");
522 err = -EINVAL;
523 goto err_out;
524 }
495 if (!is_power_of_2(chip.page_size)) 525 if (!is_power_of_2(chip.page_size))
496 dev_warn(&client->dev, 526 dev_warn(&client->dev,
497 "page_size looks suspicious (no power of 2)!\n"); 527 "page_size looks suspicious (no power of 2)!\n");
@@ -597,19 +627,15 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
597 627
598 i2c_set_clientdata(client, at24); 628 i2c_set_clientdata(client, at24);
599 629
600 dev_info(&client->dev, "%zu byte %s EEPROM %s\n", 630 dev_info(&client->dev, "%zu byte %s EEPROM, %s, %u bytes/write\n",
601 at24->bin.size, client->name, 631 at24->bin.size, client->name,
602 writable ? "(writable)" : "(read-only)"); 632 writable ? "writable" : "read-only", at24->write_max);
603 if (use_smbus == I2C_SMBUS_WORD_DATA || 633 if (use_smbus == I2C_SMBUS_WORD_DATA ||
604 use_smbus == I2C_SMBUS_BYTE_DATA) { 634 use_smbus == I2C_SMBUS_BYTE_DATA) {
605 dev_notice(&client->dev, "Falling back to %s reads, " 635 dev_notice(&client->dev, "Falling back to %s reads, "
606 "performance will suffer\n", use_smbus == 636 "performance will suffer\n", use_smbus ==
607 I2C_SMBUS_WORD_DATA ? "word" : "byte"); 637 I2C_SMBUS_WORD_DATA ? "word" : "byte");
608 } 638 }
609 dev_dbg(&client->dev,
610 "page_size %d, num_addresses %d, write_max %d, use_smbus %d\n",
611 chip.page_size, num_addresses,
612 at24->write_max, use_smbus);
613 639
614 /* export data to kernel code */ 640 /* export data to kernel code */
615 if (chip.setup) 641 if (chip.setup)
@@ -660,6 +686,11 @@ static struct i2c_driver at24_driver = {
660 686
661static int __init at24_init(void) 687static int __init at24_init(void)
662{ 688{
689 if (!io_limit) {
690 pr_err("at24: io_limit must not be 0!\n");
691 return -EINVAL;
692 }
693
663 io_limit = rounddown_pow_of_two(io_limit); 694 io_limit = rounddown_pow_of_two(io_limit);
664 return i2c_add_driver(&at24_driver); 695 return i2c_add_driver(&at24_driver);
665} 696}
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index d618e8673996..e960a9300eb2 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -83,7 +83,7 @@ config MMC_RICOH_MMC
83 83
84config MMC_SDHCI_OF 84config MMC_SDHCI_OF
85 tristate "SDHCI support on OpenFirmware platforms" 85 tristate "SDHCI support on OpenFirmware platforms"
86 depends on MMC_SDHCI && PPC_OF 86 depends on MMC_SDHCI && OF
87 help 87 help
88 This selects the OF support for Secure Digital Host Controller 88 This selects the OF support for Secure Digital Host Controller
89 Interfaces. 89 Interfaces.
@@ -93,6 +93,7 @@ config MMC_SDHCI_OF
93config MMC_SDHCI_OF_ESDHC 93config MMC_SDHCI_OF_ESDHC
94 bool "SDHCI OF support for the Freescale eSDHC controller" 94 bool "SDHCI OF support for the Freescale eSDHC controller"
95 depends on MMC_SDHCI_OF 95 depends on MMC_SDHCI_OF
96 depends on PPC_OF
96 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER 97 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER
97 help 98 help
98 This selects the Freescale eSDHC controller support. 99 This selects the Freescale eSDHC controller support.
@@ -102,6 +103,7 @@ config MMC_SDHCI_OF_ESDHC
102config MMC_SDHCI_OF_HLWD 103config MMC_SDHCI_OF_HLWD
103 bool "SDHCI OF support for the Nintendo Wii SDHCI controllers" 104 bool "SDHCI OF support for the Nintendo Wii SDHCI controllers"
104 depends on MMC_SDHCI_OF 105 depends on MMC_SDHCI_OF
106 depends on PPC_OF
105 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER 107 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER
106 help 108 help
107 This selects the Secure Digital Host Controller Interface (SDHCI) 109 This selects the Secure Digital Host Controller Interface (SDHCI)
diff --git a/drivers/mmc/host/sdhci-of-core.c b/drivers/mmc/host/sdhci-of-core.c
index c51b71174c1d..fa19d849a920 100644
--- a/drivers/mmc/host/sdhci-of-core.c
+++ b/drivers/mmc/host/sdhci-of-core.c
@@ -122,7 +122,7 @@ static int __devinit sdhci_of_probe(struct platform_device *ofdev,
122 struct sdhci_of_data *sdhci_of_data = match->data; 122 struct sdhci_of_data *sdhci_of_data = match->data;
123 struct sdhci_host *host; 123 struct sdhci_host *host;
124 struct sdhci_of_host *of_host; 124 struct sdhci_of_host *of_host;
125 const u32 *clk; 125 const __be32 *clk;
126 int size; 126 int size;
127 int ret; 127 int ret;
128 128
@@ -166,7 +166,7 @@ static int __devinit sdhci_of_probe(struct platform_device *ofdev,
166 166
167 clk = of_get_property(np, "clock-frequency", &size); 167 clk = of_get_property(np, "clock-frequency", &size);
168 if (clk && size == sizeof(*clk) && *clk) 168 if (clk && size == sizeof(*clk) && *clk)
169 of_host->clock = *clk; 169 of_host->clock = be32_to_cpup(clk);
170 170
171 ret = sdhci_add_host(host); 171 ret = sdhci_add_host(host);
172 if (ret) 172 if (ret)
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 1e2cbf5d9aa1..b1f768917395 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -159,7 +159,7 @@ config MTD_AFS_PARTS
159 159
160config MTD_OF_PARTS 160config MTD_OF_PARTS
161 tristate "Flash partition map based on OF description" 161 tristate "Flash partition map based on OF description"
162 depends on (MICROBLAZE || PPC_OF) && MTD_PARTITIONS 162 depends on OF && MTD_PARTITIONS
163 help 163 help
164 This provides a partition parsing function which derives 164 This provides a partition parsing function which derives
165 the partition map from the children of the flash node, 165 the partition map from the children of the flash node,
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index a0dd7bba9481..5d37d315fa98 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -72,7 +72,7 @@ config MTD_PHYSMAP_BANKWIDTH
72 72
73config MTD_PHYSMAP_OF 73config MTD_PHYSMAP_OF
74 tristate "Flash device in physical memory map based on OF description" 74 tristate "Flash device in physical memory map based on OF description"
75 depends on (MICROBLAZE || PPC_OF) && (MTD_CFI || MTD_JEDECPROBE || MTD_ROM) 75 depends on OF && (MTD_CFI || MTD_JEDECPROBE || MTD_ROM)
76 help 76 help
77 This provides a 'mapping' driver which allows the NOR Flash and 77 This provides a 'mapping' driver which allows the NOR Flash and
78 ROM driver code to communicate with chips which are mapped 78 ROM driver code to communicate with chips which are mapped
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 4da384cc7603..31fe980e4e28 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -18,7 +18,6 @@
18#include <linux/timer.h> 18#include <linux/timer.h>
19#include <linux/proc_fs.h> 19#include <linux/proc_fs.h>
20#include <linux/if_bonding.h> 20#include <linux/if_bonding.h>
21#include <linux/kobject.h>
22#include <linux/cpumask.h> 21#include <linux/cpumask.h>
23#include <linux/in6.h> 22#include <linux/in6.h>
24#include "bond_3ad.h" 23#include "bond_3ad.h"
diff --git a/drivers/net/fs_enet/fs_enet-main.c b/drivers/net/fs_enet/fs_enet-main.c
index d684f187de57..7a1f3d0ffa78 100644
--- a/drivers/net/fs_enet/fs_enet-main.c
+++ b/drivers/net/fs_enet/fs_enet-main.c
@@ -40,6 +40,7 @@
40#include <linux/of_mdio.h> 40#include <linux/of_mdio.h>
41#include <linux/of_platform.h> 41#include <linux/of_platform.h>
42#include <linux/of_gpio.h> 42#include <linux/of_gpio.h>
43#include <linux/of_net.h>
43 44
44#include <linux/vmalloc.h> 45#include <linux/vmalloc.h>
45#include <asm/pgtable.h> 46#include <asm/pgtable.h>
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 45c4b7bfcf39..6de4675016b5 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -95,6 +95,7 @@
95#include <linux/phy.h> 95#include <linux/phy.h>
96#include <linux/phy_fixed.h> 96#include <linux/phy_fixed.h>
97#include <linux/of.h> 97#include <linux/of.h>
98#include <linux/of_net.h>
98 99
99#include "gianfar.h" 100#include "gianfar.h"
100#include "fsl_pq_mdio.h" 101#include "fsl_pq_mdio.h"
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index acbdab3d66ca..73a3e0d93237 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -28,6 +28,7 @@
28#include <linux/phy.h> 28#include <linux/phy.h>
29#include <linux/workqueue.h> 29#include <linux/workqueue.h>
30#include <linux/of_mdio.h> 30#include <linux/of_mdio.h>
31#include <linux/of_net.h>
31#include <linux/of_platform.h> 32#include <linux/of_platform.h>
32 33
33#include <asm/uaccess.h> 34#include <asm/uaccess.h>
diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c
index de6c3086d232..cad66ce1640b 100644
--- a/drivers/net/xilinx_emaclite.c
+++ b/drivers/net/xilinx_emaclite.c
@@ -24,6 +24,7 @@
24#include <linux/of_device.h> 24#include <linux/of_device.h>
25#include <linux/of_platform.h> 25#include <linux/of_platform.h>
26#include <linux/of_mdio.h> 26#include <linux/of_mdio.h>
27#include <linux/of_net.h>
27#include <linux/phy.h> 28#include <linux/phy.h>
28 29
29#define DRIVER_NAME "xilinx_emaclite" 30#define DRIVER_NAME "xilinx_emaclite"
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index aa675ebd8eb3..3c6e100a3ad0 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -19,6 +19,10 @@ config OF_FLATTREE
19 bool 19 bool
20 select DTC 20 select DTC
21 21
22config OF_EARLY_FLATTREE
23 bool
24 select OF_FLATTREE
25
22config OF_PROMTREE 26config OF_PROMTREE
23 bool 27 bool
24 28
@@ -49,6 +53,10 @@ config OF_I2C
49 help 53 help
50 OpenFirmware I2C accessors 54 OpenFirmware I2C accessors
51 55
56config OF_NET
57 depends on NETDEVICES
58 def_bool y
59
52config OF_SPI 60config OF_SPI
53 def_tristate SPI 61 def_tristate SPI
54 depends on SPI && !SPARC 62 depends on SPI && !SPARC
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index 7888155bea08..3ab21a0a4907 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -6,5 +6,6 @@ obj-$(CONFIG_OF_IRQ) += irq.o
6obj-$(CONFIG_OF_DEVICE) += device.o platform.o 6obj-$(CONFIG_OF_DEVICE) += device.o platform.o
7obj-$(CONFIG_OF_GPIO) += gpio.o 7obj-$(CONFIG_OF_GPIO) += gpio.o
8obj-$(CONFIG_OF_I2C) += of_i2c.o 8obj-$(CONFIG_OF_I2C) += of_i2c.o
9obj-$(CONFIG_OF_NET) += of_net.o
9obj-$(CONFIG_OF_SPI) += of_spi.o 10obj-$(CONFIG_OF_SPI) += of_spi.o
10obj-$(CONFIG_OF_MDIO) += of_mdio.o 11obj-$(CONFIG_OF_MDIO) += of_mdio.o
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 3a1c7e70b192..b4559c58c095 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -12,13 +12,13 @@
12 (ns) > 0) 12 (ns) > 0)
13 13
14static struct of_bus *of_match_bus(struct device_node *np); 14static struct of_bus *of_match_bus(struct device_node *np);
15static int __of_address_to_resource(struct device_node *dev, const u32 *addrp, 15static int __of_address_to_resource(struct device_node *dev,
16 u64 size, unsigned int flags, 16 const __be32 *addrp, u64 size, unsigned int flags,
17 struct resource *r); 17 struct resource *r);
18 18
19/* Debug utility */ 19/* Debug utility */
20#ifdef DEBUG 20#ifdef DEBUG
21static void of_dump_addr(const char *s, const u32 *addr, int na) 21static void of_dump_addr(const char *s, const __be32 *addr, int na)
22{ 22{
23 printk(KERN_DEBUG "%s", s); 23 printk(KERN_DEBUG "%s", s);
24 while (na--) 24 while (na--)
@@ -26,7 +26,7 @@ static void of_dump_addr(const char *s, const u32 *addr, int na)
26 printk("\n"); 26 printk("\n");
27} 27}
28#else 28#else
29static void of_dump_addr(const char *s, const u32 *addr, int na) { } 29static void of_dump_addr(const char *s, const __be32 *addr, int na) { }
30#endif 30#endif
31 31
32/* Callbacks for bus specific translators */ 32/* Callbacks for bus specific translators */
@@ -36,10 +36,10 @@ struct of_bus {
36 int (*match)(struct device_node *parent); 36 int (*match)(struct device_node *parent);
37 void (*count_cells)(struct device_node *child, 37 void (*count_cells)(struct device_node *child,
38 int *addrc, int *sizec); 38 int *addrc, int *sizec);
39 u64 (*map)(u32 *addr, const u32 *range, 39 u64 (*map)(u32 *addr, const __be32 *range,
40 int na, int ns, int pna); 40 int na, int ns, int pna);
41 int (*translate)(u32 *addr, u64 offset, int na); 41 int (*translate)(u32 *addr, u64 offset, int na);
42 unsigned int (*get_flags)(const u32 *addr); 42 unsigned int (*get_flags)(const __be32 *addr);
43}; 43};
44 44
45/* 45/*
@@ -55,7 +55,7 @@ static void of_bus_default_count_cells(struct device_node *dev,
55 *sizec = of_n_size_cells(dev); 55 *sizec = of_n_size_cells(dev);
56} 56}
57 57
58static u64 of_bus_default_map(u32 *addr, const u32 *range, 58static u64 of_bus_default_map(u32 *addr, const __be32 *range,
59 int na, int ns, int pna) 59 int na, int ns, int pna)
60{ 60{
61 u64 cp, s, da; 61 u64 cp, s, da;
@@ -85,7 +85,7 @@ static int of_bus_default_translate(u32 *addr, u64 offset, int na)
85 return 0; 85 return 0;
86} 86}
87 87
88static unsigned int of_bus_default_get_flags(const u32 *addr) 88static unsigned int of_bus_default_get_flags(const __be32 *addr)
89{ 89{
90 return IORESOURCE_MEM; 90 return IORESOURCE_MEM;
91} 91}
@@ -110,10 +110,10 @@ static void of_bus_pci_count_cells(struct device_node *np,
110 *sizec = 2; 110 *sizec = 2;
111} 111}
112 112
113static unsigned int of_bus_pci_get_flags(const u32 *addr) 113static unsigned int of_bus_pci_get_flags(const __be32 *addr)
114{ 114{
115 unsigned int flags = 0; 115 unsigned int flags = 0;
116 u32 w = addr[0]; 116 u32 w = be32_to_cpup(addr);
117 117
118 switch((w >> 24) & 0x03) { 118 switch((w >> 24) & 0x03) {
119 case 0x01: 119 case 0x01:
@@ -129,7 +129,8 @@ static unsigned int of_bus_pci_get_flags(const u32 *addr)
129 return flags; 129 return flags;
130} 130}
131 131
132static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna) 132static u64 of_bus_pci_map(u32 *addr, const __be32 *range, int na, int ns,
133 int pna)
133{ 134{
134 u64 cp, s, da; 135 u64 cp, s, da;
135 unsigned int af, rf; 136 unsigned int af, rf;
@@ -160,7 +161,7 @@ static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
160 return of_bus_default_translate(addr + 1, offset, na - 1); 161 return of_bus_default_translate(addr + 1, offset, na - 1);
161} 162}
162 163
163const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size, 164const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
164 unsigned int *flags) 165 unsigned int *flags)
165{ 166{
166 const __be32 *prop; 167 const __be32 *prop;
@@ -207,7 +208,7 @@ EXPORT_SYMBOL(of_get_pci_address);
207int of_pci_address_to_resource(struct device_node *dev, int bar, 208int of_pci_address_to_resource(struct device_node *dev, int bar,
208 struct resource *r) 209 struct resource *r)
209{ 210{
210 const u32 *addrp; 211 const __be32 *addrp;
211 u64 size; 212 u64 size;
212 unsigned int flags; 213 unsigned int flags;
213 214
@@ -237,12 +238,13 @@ static void of_bus_isa_count_cells(struct device_node *child,
237 *sizec = 1; 238 *sizec = 1;
238} 239}
239 240
240static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, int pna) 241static u64 of_bus_isa_map(u32 *addr, const __be32 *range, int na, int ns,
242 int pna)
241{ 243{
242 u64 cp, s, da; 244 u64 cp, s, da;
243 245
244 /* Check address type match */ 246 /* Check address type match */
245 if ((addr[0] ^ range[0]) & 0x00000001) 247 if ((addr[0] ^ range[0]) & cpu_to_be32(1))
246 return OF_BAD_ADDR; 248 return OF_BAD_ADDR;
247 249
248 /* Read address values, skipping high cell */ 250 /* Read address values, skipping high cell */
@@ -264,10 +266,10 @@ static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
264 return of_bus_default_translate(addr + 1, offset, na - 1); 266 return of_bus_default_translate(addr + 1, offset, na - 1);
265} 267}
266 268
267static unsigned int of_bus_isa_get_flags(const u32 *addr) 269static unsigned int of_bus_isa_get_flags(const __be32 *addr)
268{ 270{
269 unsigned int flags = 0; 271 unsigned int flags = 0;
270 u32 w = addr[0]; 272 u32 w = be32_to_cpup(addr);
271 273
272 if (w & 1) 274 if (w & 1)
273 flags |= IORESOURCE_IO; 275 flags |= IORESOURCE_IO;
@@ -330,7 +332,7 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
330 struct of_bus *pbus, u32 *addr, 332 struct of_bus *pbus, u32 *addr,
331 int na, int ns, int pna, const char *rprop) 333 int na, int ns, int pna, const char *rprop)
332{ 334{
333 const u32 *ranges; 335 const __be32 *ranges;
334 unsigned int rlen; 336 unsigned int rlen;
335 int rone; 337 int rone;
336 u64 offset = OF_BAD_ADDR; 338 u64 offset = OF_BAD_ADDR;
@@ -398,7 +400,7 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
398 * that can be mapped to a cpu physical address). This is not really specified 400 * that can be mapped to a cpu physical address). This is not really specified
399 * that way, but this is traditionally the way IBM at least do things 401 * that way, but this is traditionally the way IBM at least do things
400 */ 402 */
401u64 __of_translate_address(struct device_node *dev, const u32 *in_addr, 403u64 __of_translate_address(struct device_node *dev, const __be32 *in_addr,
402 const char *rprop) 404 const char *rprop)
403{ 405{
404 struct device_node *parent = NULL; 406 struct device_node *parent = NULL;
@@ -475,22 +477,22 @@ u64 __of_translate_address(struct device_node *dev, const u32 *in_addr,
475 return result; 477 return result;
476} 478}
477 479
478u64 of_translate_address(struct device_node *dev, const u32 *in_addr) 480u64 of_translate_address(struct device_node *dev, const __be32 *in_addr)
479{ 481{
480 return __of_translate_address(dev, in_addr, "ranges"); 482 return __of_translate_address(dev, in_addr, "ranges");
481} 483}
482EXPORT_SYMBOL(of_translate_address); 484EXPORT_SYMBOL(of_translate_address);
483 485
484u64 of_translate_dma_address(struct device_node *dev, const u32 *in_addr) 486u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr)
485{ 487{
486 return __of_translate_address(dev, in_addr, "dma-ranges"); 488 return __of_translate_address(dev, in_addr, "dma-ranges");
487} 489}
488EXPORT_SYMBOL(of_translate_dma_address); 490EXPORT_SYMBOL(of_translate_dma_address);
489 491
490const u32 *of_get_address(struct device_node *dev, int index, u64 *size, 492const __be32 *of_get_address(struct device_node *dev, int index, u64 *size,
491 unsigned int *flags) 493 unsigned int *flags)
492{ 494{
493 const u32 *prop; 495 const __be32 *prop;
494 unsigned int psize; 496 unsigned int psize;
495 struct device_node *parent; 497 struct device_node *parent;
496 struct of_bus *bus; 498 struct of_bus *bus;
@@ -525,8 +527,8 @@ const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
525} 527}
526EXPORT_SYMBOL(of_get_address); 528EXPORT_SYMBOL(of_get_address);
527 529
528static int __of_address_to_resource(struct device_node *dev, const u32 *addrp, 530static int __of_address_to_resource(struct device_node *dev,
529 u64 size, unsigned int flags, 531 const __be32 *addrp, u64 size, unsigned int flags,
530 struct resource *r) 532 struct resource *r)
531{ 533{
532 u64 taddr; 534 u64 taddr;
@@ -564,7 +566,7 @@ static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
564int of_address_to_resource(struct device_node *dev, int index, 566int of_address_to_resource(struct device_node *dev, int index,
565 struct resource *r) 567 struct resource *r)
566{ 568{
567 const u32 *addrp; 569 const __be32 *addrp;
568 u64 size; 570 u64 size;
569 unsigned int flags; 571 unsigned int flags;
570 572
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index c1360e02f921..c787c3d95c60 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -11,10 +11,12 @@
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/initrd.h> 13#include <linux/initrd.h>
14#include <linux/module.h>
14#include <linux/of.h> 15#include <linux/of.h>
15#include <linux/of_fdt.h> 16#include <linux/of_fdt.h>
16#include <linux/string.h> 17#include <linux/string.h>
17#include <linux/errno.h> 18#include <linux/errno.h>
19#include <linux/slab.h>
18 20
19#ifdef CONFIG_PPC 21#ifdef CONFIG_PPC
20#include <asm/machdep.h> 22#include <asm/machdep.h>
@@ -22,104 +24,19 @@
22 24
23#include <asm/page.h> 25#include <asm/page.h>
24 26
25int __initdata dt_root_addr_cells; 27char *of_fdt_get_string(struct boot_param_header *blob, u32 offset)
26int __initdata dt_root_size_cells;
27
28struct boot_param_header *initial_boot_params;
29
30char *find_flat_dt_string(u32 offset)
31{ 28{
32 return ((char *)initial_boot_params) + 29 return ((char *)blob) +
33 be32_to_cpu(initial_boot_params->off_dt_strings) + offset; 30 be32_to_cpu(blob->off_dt_strings) + offset;
34}
35
36/**
37 * of_scan_flat_dt - scan flattened tree blob and call callback on each.
38 * @it: callback function
39 * @data: context data pointer
40 *
41 * This function is used to scan the flattened device-tree, it is
42 * used to extract the memory information at boot before we can
43 * unflatten the tree
44 */
45int __init of_scan_flat_dt(int (*it)(unsigned long node,
46 const char *uname, int depth,
47 void *data),
48 void *data)
49{
50 unsigned long p = ((unsigned long)initial_boot_params) +
51 be32_to_cpu(initial_boot_params->off_dt_struct);
52 int rc = 0;
53 int depth = -1;
54
55 do {
56 u32 tag = be32_to_cpup((__be32 *)p);
57 char *pathp;
58
59 p += 4;
60 if (tag == OF_DT_END_NODE) {
61 depth--;
62 continue;
63 }
64 if (tag == OF_DT_NOP)
65 continue;
66 if (tag == OF_DT_END)
67 break;
68 if (tag == OF_DT_PROP) {
69 u32 sz = be32_to_cpup((__be32 *)p);
70 p += 8;
71 if (be32_to_cpu(initial_boot_params->version) < 0x10)
72 p = ALIGN(p, sz >= 8 ? 8 : 4);
73 p += sz;
74 p = ALIGN(p, 4);
75 continue;
76 }
77 if (tag != OF_DT_BEGIN_NODE) {
78 pr_err("Invalid tag %x in flat device tree!\n", tag);
79 return -EINVAL;
80 }
81 depth++;
82 pathp = (char *)p;
83 p = ALIGN(p + strlen(pathp) + 1, 4);
84 if ((*pathp) == '/') {
85 char *lp, *np;
86 for (lp = NULL, np = pathp; *np; np++)
87 if ((*np) == '/')
88 lp = np+1;
89 if (lp != NULL)
90 pathp = lp;
91 }
92 rc = it(p, pathp, depth, data);
93 if (rc != 0)
94 break;
95 } while (1);
96
97 return rc;
98} 31}
99 32
100/** 33/**
101 * of_get_flat_dt_root - find the root node in the flat blob 34 * of_fdt_get_property - Given a node in the given flat blob, return
35 * the property ptr
102 */ 36 */
103unsigned long __init of_get_flat_dt_root(void) 37void *of_fdt_get_property(struct boot_param_header *blob,
104{ 38 unsigned long node, const char *name,
105 unsigned long p = ((unsigned long)initial_boot_params) + 39 unsigned long *size)
106 be32_to_cpu(initial_boot_params->off_dt_struct);
107
108 while (be32_to_cpup((__be32 *)p) == OF_DT_NOP)
109 p += 4;
110 BUG_ON(be32_to_cpup((__be32 *)p) != OF_DT_BEGIN_NODE);
111 p += 4;
112 return ALIGN(p + strlen((char *)p) + 1, 4);
113}
114
115/**
116 * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr
117 *
118 * This function can be used within scan_flattened_dt callback to get
119 * access to properties
120 */
121void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
122 unsigned long *size)
123{ 40{
124 unsigned long p = node; 41 unsigned long p = node;
125 42
@@ -137,10 +54,10 @@ void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
137 sz = be32_to_cpup((__be32 *)p); 54 sz = be32_to_cpup((__be32 *)p);
138 noff = be32_to_cpup((__be32 *)(p + 4)); 55 noff = be32_to_cpup((__be32 *)(p + 4));
139 p += 8; 56 p += 8;
140 if (be32_to_cpu(initial_boot_params->version) < 0x10) 57 if (be32_to_cpu(blob->version) < 0x10)
141 p = ALIGN(p, sz >= 8 ? 8 : 4); 58 p = ALIGN(p, sz >= 8 ? 8 : 4);
142 59
143 nstr = find_flat_dt_string(noff); 60 nstr = of_fdt_get_string(blob, noff);
144 if (nstr == NULL) { 61 if (nstr == NULL) {
145 pr_warning("Can't find property index name !\n"); 62 pr_warning("Can't find property index name !\n");
146 return NULL; 63 return NULL;
@@ -156,21 +73,28 @@ void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
156} 73}
157 74
158/** 75/**
159 * of_flat_dt_is_compatible - Return true if given node has compat in compatible list 76 * of_fdt_is_compatible - Return true if given node from the given blob has
77 * compat in its compatible list
78 * @blob: A device tree blob
160 * @node: node to test 79 * @node: node to test
161 * @compat: compatible string to compare with compatible list. 80 * @compat: compatible string to compare with compatible list.
81 *
82 * On match, returns a non-zero value with smaller values returned for more
83 * specific compatible values.
162 */ 84 */
163int __init of_flat_dt_is_compatible(unsigned long node, const char *compat) 85int of_fdt_is_compatible(struct boot_param_header *blob,
86 unsigned long node, const char *compat)
164{ 87{
165 const char *cp; 88 const char *cp;
166 unsigned long cplen, l; 89 unsigned long cplen, l, score = 0;
167 90
168 cp = of_get_flat_dt_prop(node, "compatible", &cplen); 91 cp = of_fdt_get_property(blob, node, "compatible", &cplen);
169 if (cp == NULL) 92 if (cp == NULL)
170 return 0; 93 return 0;
171 while (cplen > 0) { 94 while (cplen > 0) {
95 score++;
172 if (of_compat_cmp(cp, compat, strlen(compat)) == 0) 96 if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
173 return 1; 97 return score;
174 l = strlen(cp) + 1; 98 l = strlen(cp) + 1;
175 cp += l; 99 cp += l;
176 cplen -= l; 100 cplen -= l;
@@ -179,7 +103,28 @@ int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
179 return 0; 103 return 0;
180} 104}
181 105
182static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size, 106/**
107 * of_fdt_match - Return true if node matches a list of compatible values
108 */
109int of_fdt_match(struct boot_param_header *blob, unsigned long node,
110 const char **compat)
111{
112 unsigned int tmp, score = 0;
113
114 if (!compat)
115 return 0;
116
117 while (*compat) {
118 tmp = of_fdt_is_compatible(blob, node, *compat);
119 if (tmp && (score == 0 || (tmp < score)))
120 score = tmp;
121 compat++;
122 }
123
124 return score;
125}
126
127static void *unflatten_dt_alloc(unsigned long *mem, unsigned long size,
183 unsigned long align) 128 unsigned long align)
184{ 129{
185 void *res; 130 void *res;
@@ -193,16 +138,18 @@ static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size,
193 138
194/** 139/**
195 * unflatten_dt_node - Alloc and populate a device_node from the flat tree 140 * unflatten_dt_node - Alloc and populate a device_node from the flat tree
141 * @blob: The parent device tree blob
196 * @p: pointer to node in flat tree 142 * @p: pointer to node in flat tree
197 * @dad: Parent struct device_node 143 * @dad: Parent struct device_node
198 * @allnextpp: pointer to ->allnext from last allocated device_node 144 * @allnextpp: pointer to ->allnext from last allocated device_node
199 * @fpsize: Size of the node path up at the current depth. 145 * @fpsize: Size of the node path up at the current depth.
200 */ 146 */
201unsigned long __init unflatten_dt_node(unsigned long mem, 147unsigned long unflatten_dt_node(struct boot_param_header *blob,
202 unsigned long *p, 148 unsigned long mem,
203 struct device_node *dad, 149 unsigned long *p,
204 struct device_node ***allnextpp, 150 struct device_node *dad,
205 unsigned long fpsize) 151 struct device_node ***allnextpp,
152 unsigned long fpsize)
206{ 153{
207 struct device_node *np; 154 struct device_node *np;
208 struct property *pp, **prev_pp = NULL; 155 struct property *pp, **prev_pp = NULL;
@@ -298,10 +245,10 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
298 sz = be32_to_cpup((__be32 *)(*p)); 245 sz = be32_to_cpup((__be32 *)(*p));
299 noff = be32_to_cpup((__be32 *)((*p) + 4)); 246 noff = be32_to_cpup((__be32 *)((*p) + 4));
300 *p += 8; 247 *p += 8;
301 if (be32_to_cpu(initial_boot_params->version) < 0x10) 248 if (be32_to_cpu(blob->version) < 0x10)
302 *p = ALIGN(*p, sz >= 8 ? 8 : 4); 249 *p = ALIGN(*p, sz >= 8 ? 8 : 4);
303 250
304 pname = find_flat_dt_string(noff); 251 pname = of_fdt_get_string(blob, noff);
305 if (pname == NULL) { 252 if (pname == NULL) {
306 pr_info("Can't find property name in list !\n"); 253 pr_info("Can't find property name in list !\n");
307 break; 254 break;
@@ -380,7 +327,8 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
380 if (tag == OF_DT_NOP) 327 if (tag == OF_DT_NOP)
381 *p += 4; 328 *p += 4;
382 else 329 else
383 mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize); 330 mem = unflatten_dt_node(blob, mem, p, np, allnextpp,
331 fpsize);
384 tag = be32_to_cpup((__be32 *)(*p)); 332 tag = be32_to_cpup((__be32 *)(*p));
385 } 333 }
386 if (tag != OF_DT_END_NODE) { 334 if (tag != OF_DT_END_NODE) {
@@ -391,6 +339,211 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
391 return mem; 339 return mem;
392} 340}
393 341
342/**
343 * __unflatten_device_tree - create tree of device_nodes from flat blob
344 *
345 * unflattens a device-tree, creating the
346 * tree of struct device_node. It also fills the "name" and "type"
347 * pointers of the nodes so the normal device-tree walking functions
348 * can be used.
349 * @blob: The blob to expand
350 * @mynodes: The device_node tree created by the call
351 * @dt_alloc: An allocator that provides a virtual address to memory
352 * for the resulting tree
353 */
354void __unflatten_device_tree(struct boot_param_header *blob,
355 struct device_node **mynodes,
356 void * (*dt_alloc)(u64 size, u64 align))
357{
358 unsigned long start, mem, size;
359 struct device_node **allnextp = mynodes;
360
361 pr_debug(" -> unflatten_device_tree()\n");
362
363 if (!blob) {
364 pr_debug("No device tree pointer\n");
365 return;
366 }
367
368 pr_debug("Unflattening device tree:\n");
369 pr_debug("magic: %08x\n", be32_to_cpu(blob->magic));
370 pr_debug("size: %08x\n", be32_to_cpu(blob->totalsize));
371 pr_debug("version: %08x\n", be32_to_cpu(blob->version));
372
373 if (be32_to_cpu(blob->magic) != OF_DT_HEADER) {
374 pr_err("Invalid device tree blob header\n");
375 return;
376 }
377
378 /* First pass, scan for size */
379 start = ((unsigned long)blob) +
380 be32_to_cpu(blob->off_dt_struct);
381 size = unflatten_dt_node(blob, 0, &start, NULL, NULL, 0);
382 size = (size | 3) + 1;
383
384 pr_debug(" size is %lx, allocating...\n", size);
385
386 /* Allocate memory for the expanded device tree */
387 mem = (unsigned long)
388 dt_alloc(size + 4, __alignof__(struct device_node));
389
390 ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef);
391
392 pr_debug(" unflattening %lx...\n", mem);
393
394 /* Second pass, do actual unflattening */
395 start = ((unsigned long)blob) +
396 be32_to_cpu(blob->off_dt_struct);
397 unflatten_dt_node(blob, mem, &start, NULL, &allnextp, 0);
398 if (be32_to_cpup((__be32 *)start) != OF_DT_END)
399 pr_warning("Weird tag at end of tree: %08x\n", *((u32 *)start));
400 if (be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeef)
401 pr_warning("End of tree marker overwritten: %08x\n",
402 be32_to_cpu(((__be32 *)mem)[size / 4]));
403 *allnextp = NULL;
404
405 pr_debug(" <- unflatten_device_tree()\n");
406}
407
408static void *kernel_tree_alloc(u64 size, u64 align)
409{
410 return kzalloc(size, GFP_KERNEL);
411}
412
413/**
414 * of_fdt_unflatten_tree - create tree of device_nodes from flat blob
415 *
416 * unflattens the device-tree passed by the firmware, creating the
417 * tree of struct device_node. It also fills the "name" and "type"
418 * pointers of the nodes so the normal device-tree walking functions
419 * can be used.
420 */
421void of_fdt_unflatten_tree(unsigned long *blob,
422 struct device_node **mynodes)
423{
424 struct boot_param_header *device_tree =
425 (struct boot_param_header *)blob;
426 __unflatten_device_tree(device_tree, mynodes, &kernel_tree_alloc);
427}
428EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree);
429
430/* Everything below here references initial_boot_params directly. */
431int __initdata dt_root_addr_cells;
432int __initdata dt_root_size_cells;
433
434struct boot_param_header *initial_boot_params;
435
436#ifdef CONFIG_OF_EARLY_FLATTREE
437
438/**
439 * of_scan_flat_dt - scan flattened tree blob and call callback on each.
440 * @it: callback function
441 * @data: context data pointer
442 *
443 * This function is used to scan the flattened device-tree, it is
444 * used to extract the memory information at boot before we can
445 * unflatten the tree
446 */
447int __init of_scan_flat_dt(int (*it)(unsigned long node,
448 const char *uname, int depth,
449 void *data),
450 void *data)
451{
452 unsigned long p = ((unsigned long)initial_boot_params) +
453 be32_to_cpu(initial_boot_params->off_dt_struct);
454 int rc = 0;
455 int depth = -1;
456
457 do {
458 u32 tag = be32_to_cpup((__be32 *)p);
459 char *pathp;
460
461 p += 4;
462 if (tag == OF_DT_END_NODE) {
463 depth--;
464 continue;
465 }
466 if (tag == OF_DT_NOP)
467 continue;
468 if (tag == OF_DT_END)
469 break;
470 if (tag == OF_DT_PROP) {
471 u32 sz = be32_to_cpup((__be32 *)p);
472 p += 8;
473 if (be32_to_cpu(initial_boot_params->version) < 0x10)
474 p = ALIGN(p, sz >= 8 ? 8 : 4);
475 p += sz;
476 p = ALIGN(p, 4);
477 continue;
478 }
479 if (tag != OF_DT_BEGIN_NODE) {
480 pr_err("Invalid tag %x in flat device tree!\n", tag);
481 return -EINVAL;
482 }
483 depth++;
484 pathp = (char *)p;
485 p = ALIGN(p + strlen(pathp) + 1, 4);
486 if ((*pathp) == '/') {
487 char *lp, *np;
488 for (lp = NULL, np = pathp; *np; np++)
489 if ((*np) == '/')
490 lp = np+1;
491 if (lp != NULL)
492 pathp = lp;
493 }
494 rc = it(p, pathp, depth, data);
495 if (rc != 0)
496 break;
497 } while (1);
498
499 return rc;
500}
501
502/**
503 * of_get_flat_dt_root - find the root node in the flat blob
504 */
505unsigned long __init of_get_flat_dt_root(void)
506{
507 unsigned long p = ((unsigned long)initial_boot_params) +
508 be32_to_cpu(initial_boot_params->off_dt_struct);
509
510 while (be32_to_cpup((__be32 *)p) == OF_DT_NOP)
511 p += 4;
512 BUG_ON(be32_to_cpup((__be32 *)p) != OF_DT_BEGIN_NODE);
513 p += 4;
514 return ALIGN(p + strlen((char *)p) + 1, 4);
515}
516
517/**
518 * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr
519 *
520 * This function can be used within scan_flattened_dt callback to get
521 * access to properties
522 */
523void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
524 unsigned long *size)
525{
526 return of_fdt_get_property(initial_boot_params, node, name, size);
527}
528
529/**
530 * of_flat_dt_is_compatible - Return true if given node has compat in compatible list
531 * @node: node to test
532 * @compat: compatible string to compare with compatible list.
533 */
534int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
535{
536 return of_fdt_is_compatible(initial_boot_params, node, compat);
537}
538
539/**
540 * of_flat_dt_match - Return true if node matches a list of compatible values
541 */
542int __init of_flat_dt_match(unsigned long node, const char **compat)
543{
544 return of_fdt_match(initial_boot_params, node, compat);
545}
546
394#ifdef CONFIG_BLK_DEV_INITRD 547#ifdef CONFIG_BLK_DEV_INITRD
395/** 548/**
396 * early_init_dt_check_for_initrd - Decode initrd location from flat tree 549 * early_init_dt_check_for_initrd - Decode initrd location from flat tree
@@ -539,6 +692,12 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
539 return 1; 692 return 1;
540} 693}
541 694
695static void *__init early_device_tree_alloc(u64 size, u64 align)
696{
697 unsigned long mem = early_init_dt_alloc_memory_arch(size, align);
698 return __va(mem);
699}
700
542/** 701/**
543 * unflatten_device_tree - create tree of device_nodes from flat blob 702 * unflatten_device_tree - create tree of device_nodes from flat blob
544 * 703 *
@@ -549,58 +708,13 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
549 */ 708 */
550void __init unflatten_device_tree(void) 709void __init unflatten_device_tree(void)
551{ 710{
552 unsigned long start, mem, size; 711 __unflatten_device_tree(initial_boot_params, &allnodes,
553 struct device_node **allnextp = &allnodes; 712 early_device_tree_alloc);
554
555 pr_debug(" -> unflatten_device_tree()\n");
556
557 if (!initial_boot_params) {
558 pr_debug("No device tree pointer\n");
559 return;
560 }
561
562 pr_debug("Unflattening device tree:\n");
563 pr_debug("magic: %08x\n", be32_to_cpu(initial_boot_params->magic));
564 pr_debug("size: %08x\n", be32_to_cpu(initial_boot_params->totalsize));
565 pr_debug("version: %08x\n", be32_to_cpu(initial_boot_params->version));
566
567 if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER) {
568 pr_err("Invalid device tree blob header\n");
569 return;
570 }
571
572 /* First pass, scan for size */
573 start = ((unsigned long)initial_boot_params) +
574 be32_to_cpu(initial_boot_params->off_dt_struct);
575 size = unflatten_dt_node(0, &start, NULL, NULL, 0);
576 size = (size | 3) + 1;
577
578 pr_debug(" size is %lx, allocating...\n", size);
579
580 /* Allocate memory for the expanded device tree */
581 mem = early_init_dt_alloc_memory_arch(size + 4,
582 __alignof__(struct device_node));
583 mem = (unsigned long) __va(mem);
584
585 ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef);
586
587 pr_debug(" unflattening %lx...\n", mem);
588
589 /* Second pass, do actual unflattening */
590 start = ((unsigned long)initial_boot_params) +
591 be32_to_cpu(initial_boot_params->off_dt_struct);
592 unflatten_dt_node(mem, &start, NULL, &allnextp, 0);
593 if (be32_to_cpup((__be32 *)start) != OF_DT_END)
594 pr_warning("Weird tag at end of tree: %08x\n", *((u32 *)start));
595 if (be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeef)
596 pr_warning("End of tree marker overwritten: %08x\n",
597 be32_to_cpu(((__be32 *)mem)[size / 4]));
598 *allnextp = NULL;
599 713
600 /* Get pointer to OF "/chosen" node for use everywhere */ 714 /* Get pointer to OF "/chosen" node for use everywhere */
601 of_chosen = of_find_node_by_path("/chosen"); 715 of_chosen = of_find_node_by_path("/chosen");
602 if (of_chosen == NULL) 716 if (of_chosen == NULL)
603 of_chosen = of_find_node_by_path("/chosen@0"); 717 of_chosen = of_find_node_by_path("/chosen@0");
604
605 pr_debug(" <- unflatten_device_tree()\n");
606} 718}
719
720#endif /* CONFIG_OF_EARLY_FLATTREE */
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 1fce00eb421b..dcd7857784f2 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -52,27 +52,35 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
52 52
53 /* Loop over the child nodes and register a phy_device for each one */ 53 /* Loop over the child nodes and register a phy_device for each one */
54 for_each_child_of_node(np, child) { 54 for_each_child_of_node(np, child) {
55 const __be32 *addr; 55 const __be32 *paddr;
56 u32 addr;
56 int len; 57 int len;
57 58
58 /* A PHY must have a reg property in the range [0-31] */ 59 /* A PHY must have a reg property in the range [0-31] */
59 addr = of_get_property(child, "reg", &len); 60 paddr = of_get_property(child, "reg", &len);
60 if (!addr || len < sizeof(*addr) || *addr >= 32 || *addr < 0) { 61 if (!paddr || len < sizeof(*paddr)) {
61 dev_err(&mdio->dev, "%s has invalid PHY address\n", 62 dev_err(&mdio->dev, "%s has invalid PHY address\n",
62 child->full_name); 63 child->full_name);
63 continue; 64 continue;
64 } 65 }
65 66
67 addr = be32_to_cpup(paddr);
68 if (addr >= 32) {
69 dev_err(&mdio->dev, "%s PHY address %i is too large\n",
70 child->full_name, addr);
71 continue;
72 }
73
66 if (mdio->irq) { 74 if (mdio->irq) {
67 mdio->irq[*addr] = irq_of_parse_and_map(child, 0); 75 mdio->irq[addr] = irq_of_parse_and_map(child, 0);
68 if (!mdio->irq[*addr]) 76 if (!mdio->irq[addr])
69 mdio->irq[*addr] = PHY_POLL; 77 mdio->irq[addr] = PHY_POLL;
70 } 78 }
71 79
72 phy = get_phy_device(mdio, be32_to_cpup(addr)); 80 phy = get_phy_device(mdio, addr);
73 if (!phy || IS_ERR(phy)) { 81 if (!phy || IS_ERR(phy)) {
74 dev_err(&mdio->dev, "error probing PHY at address %i\n", 82 dev_err(&mdio->dev, "error probing PHY at address %i\n",
75 *addr); 83 addr);
76 continue; 84 continue;
77 } 85 }
78 phy_scan_fixups(phy); 86 phy_scan_fixups(phy);
@@ -91,7 +99,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
91 } 99 }
92 100
93 dev_dbg(&mdio->dev, "registered phy %s at address %i\n", 101 dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
94 child->name, *addr); 102 child->name, addr);
95 } 103 }
96 104
97 return 0; 105 return 0;
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
new file mode 100644
index 000000000000..86f334a2769c
--- /dev/null
+++ b/drivers/of/of_net.c
@@ -0,0 +1,48 @@
1/*
2 * OF helpers for network devices.
3 *
4 * This file is released under the GPLv2
5 *
6 * Initially copied out of arch/powerpc/kernel/prom_parse.c
7 */
8#include <linux/etherdevice.h>
9#include <linux/kernel.h>
10#include <linux/of_net.h>
11
12/**
13 * Search the device tree for the best MAC address to use. 'mac-address' is
14 * checked first, because that is supposed to contain to "most recent" MAC
15 * address. If that isn't set, then 'local-mac-address' is checked next,
16 * because that is the default address. If that isn't set, then the obsolete
17 * 'address' is checked, just in case we're using an old device tree.
18 *
19 * Note that the 'address' property is supposed to contain a virtual address of
20 * the register set, but some DTS files have redefined that property to be the
21 * MAC address.
22 *
23 * All-zero MAC addresses are rejected, because those could be properties that
24 * exist in the device tree, but were not set by U-Boot. For example, the
25 * DTS could define 'mac-address' and 'local-mac-address', with zero MAC
26 * addresses. Some older U-Boots only initialized 'local-mac-address'. In
27 * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
28 * but is all zeros.
29*/
30const void *of_get_mac_address(struct device_node *np)
31{
32 struct property *pp;
33
34 pp = of_find_property(np, "mac-address", NULL);
35 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
36 return pp->value;
37
38 pp = of_find_property(np, "local-mac-address", NULL);
39 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
40 return pp->value;
41
42 pp = of_find_property(np, "address", NULL);
43 if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
44 return pp->value;
45
46 return NULL;
47}
48EXPORT_SYMBOL(of_get_mac_address);
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 5b4a07f1220e..c01cd1ac7617 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -633,6 +633,9 @@ EXPORT_SYMBOL(of_device_alloc);
633 * @np: pointer to node to create device for 633 * @np: pointer to node to create device for
634 * @bus_id: name to assign device 634 * @bus_id: name to assign device
635 * @parent: Linux device model parent device. 635 * @parent: Linux device model parent device.
636 *
637 * Returns pointer to created platform device, or NULL if a device was not
638 * registered. Unavailable devices will not get registered.
636 */ 639 */
637struct platform_device *of_platform_device_create(struct device_node *np, 640struct platform_device *of_platform_device_create(struct device_node *np,
638 const char *bus_id, 641 const char *bus_id,
@@ -640,6 +643,9 @@ struct platform_device *of_platform_device_create(struct device_node *np,
640{ 643{
641 struct platform_device *dev; 644 struct platform_device *dev;
642 645
646 if (!of_device_is_available(np))
647 return NULL;
648
643 dev = of_device_alloc(np, bus_id, parent); 649 dev = of_device_alloc(np, bus_id, parent);
644 if (!dev) 650 if (!dev)
645 return NULL; 651 return NULL;
@@ -683,8 +689,9 @@ static int of_platform_bus_create(const struct device_node *bus,
683 pr_debug(" create child: %s\n", child->full_name); 689 pr_debug(" create child: %s\n", child->full_name);
684 dev = of_platform_device_create(child, NULL, parent); 690 dev = of_platform_device_create(child, NULL, parent);
685 if (dev == NULL) 691 if (dev == NULL)
686 rc = -ENOMEM; 692 continue;
687 else if (!of_match_node(matches, child)) 693
694 if (!of_match_node(matches, child))
688 continue; 695 continue;
689 if (rc == 0) { 696 if (rc == 0) {
690 pr_debug(" and sub busses\n"); 697 pr_debug(" and sub busses\n");
@@ -733,10 +740,9 @@ int of_platform_bus_probe(struct device_node *root,
733 if (of_match_node(matches, root)) { 740 if (of_match_node(matches, root)) {
734 pr_debug(" root match, create all sub devices\n"); 741 pr_debug(" root match, create all sub devices\n");
735 dev = of_platform_device_create(root, NULL, parent); 742 dev = of_platform_device_create(root, NULL, parent);
736 if (dev == NULL) { 743 if (dev == NULL)
737 rc = -ENOMEM;
738 goto bail; 744 goto bail;
739 } 745
740 pr_debug(" create all sub busses\n"); 746 pr_debug(" create all sub busses\n");
741 rc = of_platform_bus_create(root, matches, &dev->dev); 747 rc = of_platform_bus_create(root, matches, &dev->dev);
742 goto bail; 748 goto bail;
@@ -748,9 +754,9 @@ int of_platform_bus_probe(struct device_node *root,
748 pr_debug(" match: %s\n", child->full_name); 754 pr_debug(" match: %s\n", child->full_name);
749 dev = of_platform_device_create(child, NULL, parent); 755 dev = of_platform_device_create(child, NULL, parent);
750 if (dev == NULL) 756 if (dev == NULL)
751 rc = -ENOMEM; 757 continue;
752 else 758
753 rc = of_platform_bus_create(child, matches, &dev->dev); 759 rc = of_platform_bus_create(child, matches, &dev->dev);
754 if (rc) { 760 if (rc) {
755 of_node_put(child); 761 of_node_put(child);
756 break; 762 break;
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index bab52047baa8..7722108e78df 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -36,7 +36,6 @@
36#define _ACPIPHP_H 36#define _ACPIPHP_H
37 37
38#include <linux/acpi.h> 38#include <linux/acpi.h>
39#include <linux/kobject.h>
40#include <linux/mutex.h> 39#include <linux/mutex.h>
41#include <linux/pci_hotplug.h> 40#include <linux/pci_hotplug.h>
42 41
diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c
index 2ea9cf1a8d02..b283bbea6d24 100644
--- a/drivers/pci/hotplug/rpaphp_slot.c
+++ b/drivers/pci/hotplug/rpaphp_slot.c
@@ -24,7 +24,6 @@
24 */ 24 */
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/kobject.h>
28#include <linux/sysfs.h> 27#include <linux/sysfs.h>
29#include <linux/pci.h> 28#include <linux/pci.h>
30#include <linux/string.h> 29#include <linux/string.h>
diff --git a/drivers/s390/char/tape_class.h b/drivers/s390/char/tape_class.h
index 707b7f48c232..9e32780c317f 100644
--- a/drivers/s390/char/tape_class.h
+++ b/drivers/s390/char/tape_class.h
@@ -14,7 +14,6 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/fs.h> 15#include <linux/fs.h>
16#include <linux/major.h> 16#include <linux/major.h>
17#include <linux/kobject.h>
18#include <linux/kobj_map.h> 17#include <linux/kobj_map.h>
19#include <linux/cdev.h> 18#include <linux/cdev.h>
20 19
diff --git a/drivers/sbus/char/jsflash.c b/drivers/sbus/char/jsflash.c
index a624f5af4320..e8566224fe4b 100644
--- a/drivers/sbus/char/jsflash.c
+++ b/drivers/sbus/char/jsflash.c
@@ -467,7 +467,7 @@ static int jsflash_init(void)
467 467
468 node = prom_getchild(prom_root_node); 468 node = prom_getchild(prom_root_node);
469 node = prom_searchsiblings(node, "flash-memory"); 469 node = prom_searchsiblings(node, "flash-memory");
470 if (node != 0 && node != -1) { 470 if (node != 0 && (s32)node != -1) {
471 if (prom_getproperty(node, "reg", 471 if (prom_getproperty(node, "reg",
472 (char *)&reg0, sizeof(reg0)) == -1) { 472 (char *)&reg0, sizeof(reg0)) == -1) {
473 printk("jsflash: no \"reg\" property\n"); 473 printk("jsflash: no \"reg\" property\n");
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index de2e09e49a3e..d3c5905b22ec 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -5748,7 +5748,7 @@ static int ipr_queuecommand_lck(struct scsi_cmnd *scsi_cmd,
5748 } 5748 }
5749 5749
5750 if (ipr_is_gata(res) && res->sata_port) 5750 if (ipr_is_gata(res) && res->sata_port)
5751 return ata_sas_queuecmd(scsi_cmd, done, res->sata_port->ap); 5751 return ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
5752 5752
5753 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg); 5753 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5754 ioarcb = &ipr_cmd->ioarcb; 5754 ioarcb = &ipr_cmd->ioarcb;
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 29251fabecc6..5815cbeb27a6 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -211,8 +211,7 @@ static int sas_queuecommand_lck(struct scsi_cmnd *cmd,
211 unsigned long flags; 211 unsigned long flags;
212 212
213 spin_lock_irqsave(dev->sata_dev.ap->lock, flags); 213 spin_lock_irqsave(dev->sata_dev.ap->lock, flags);
214 res = ata_sas_queuecmd(cmd, scsi_done, 214 res = ata_sas_queuecmd(cmd, dev->sata_dev.ap);
215 dev->sata_dev.ap);
216 spin_unlock_irqrestore(dev->sata_dev.ap->lock, flags); 215 spin_unlock_irqrestore(dev->sata_dev.ap->lock, flags);
217 goto out; 216 goto out;
218 } 217 }
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index ec3c214598d0..188aff6d263f 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -1412,7 +1412,7 @@ config SERIAL_NETX_CONSOLE
1412 1412
1413config SERIAL_OF_PLATFORM 1413config SERIAL_OF_PLATFORM
1414 tristate "Serial port on Open Firmware platform bus" 1414 tristate "Serial port on Open Firmware platform bus"
1415 depends on PPC_OF || MICROBLAZE 1415 depends on OF
1416 depends on SERIAL_8250 || SERIAL_OF_PLATFORM_NWPSERIAL 1416 depends on SERIAL_8250 || SERIAL_OF_PLATFORM_NWPSERIAL
1417 help 1417 help
1418 If you have a PowerPC based system that has serial ports 1418 If you have a PowerPC based system that has serial ports
diff --git a/drivers/serial/of_serial.c b/drivers/serial/of_serial.c
index 17849dcb9adc..5c7abe4c94dd 100644
--- a/drivers/serial/of_serial.c
+++ b/drivers/serial/of_serial.c
@@ -15,6 +15,7 @@
15#include <linux/serial_core.h> 15#include <linux/serial_core.h>
16#include <linux/serial_8250.h> 16#include <linux/serial_8250.h>
17#include <linux/of_address.h> 17#include <linux/of_address.h>
18#include <linux/of_irq.h>
18#include <linux/of_platform.h> 19#include <linux/of_platform.h>
19#include <linux/nwpserial.h> 20#include <linux/nwpserial.h>
20 21
diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c
index 3f5e387ed564..5f63c3b83828 100644
--- a/drivers/sh/clk/core.c
+++ b/drivers/sh/clk/core.c
@@ -21,7 +21,6 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/kobject.h>
25#include <linux/sysdev.h> 24#include <linux/sysdev.h>
26#include <linux/seq_file.h> 25#include <linux/seq_file.h>
27#include <linux/err.h> 26#include <linux/err.h>
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b02d0cbce890..34bb17f03019 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -28,6 +28,7 @@
28#include <linux/mod_devicetable.h> 28#include <linux/mod_devicetable.h>
29#include <linux/spi/spi.h> 29#include <linux/spi/spi.h>
30#include <linux/of_spi.h> 30#include <linux/of_spi.h>
31#include <linux/pm_runtime.h>
31 32
32static void spidev_release(struct device *dev) 33static void spidev_release(struct device *dev)
33{ 34{
@@ -100,9 +101,8 @@ static int spi_uevent(struct device *dev, struct kobj_uevent_env *env)
100 return 0; 101 return 0;
101} 102}
102 103
103#ifdef CONFIG_PM 104#ifdef CONFIG_PM_SLEEP
104 105static int spi_legacy_suspend(struct device *dev, pm_message_t message)
105static int spi_suspend(struct device *dev, pm_message_t message)
106{ 106{
107 int value = 0; 107 int value = 0;
108 struct spi_driver *drv = to_spi_driver(dev->driver); 108 struct spi_driver *drv = to_spi_driver(dev->driver);
@@ -117,7 +117,7 @@ static int spi_suspend(struct device *dev, pm_message_t message)
117 return value; 117 return value;
118} 118}
119 119
120static int spi_resume(struct device *dev) 120static int spi_legacy_resume(struct device *dev)
121{ 121{
122 int value = 0; 122 int value = 0;
123 struct spi_driver *drv = to_spi_driver(dev->driver); 123 struct spi_driver *drv = to_spi_driver(dev->driver);
@@ -132,18 +132,94 @@ static int spi_resume(struct device *dev)
132 return value; 132 return value;
133} 133}
134 134
135static int spi_pm_suspend(struct device *dev)
136{
137 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
138
139 if (pm)
140 return pm_generic_suspend(dev);
141 else
142 return spi_legacy_suspend(dev, PMSG_SUSPEND);
143}
144
145static int spi_pm_resume(struct device *dev)
146{
147 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
148
149 if (pm)
150 return pm_generic_resume(dev);
151 else
152 return spi_legacy_resume(dev);
153}
154
155static int spi_pm_freeze(struct device *dev)
156{
157 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
158
159 if (pm)
160 return pm_generic_freeze(dev);
161 else
162 return spi_legacy_suspend(dev, PMSG_FREEZE);
163}
164
165static int spi_pm_thaw(struct device *dev)
166{
167 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
168
169 if (pm)
170 return pm_generic_thaw(dev);
171 else
172 return spi_legacy_resume(dev);
173}
174
175static int spi_pm_poweroff(struct device *dev)
176{
177 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
178
179 if (pm)
180 return pm_generic_poweroff(dev);
181 else
182 return spi_legacy_suspend(dev, PMSG_HIBERNATE);
183}
184
185static int spi_pm_restore(struct device *dev)
186{
187 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
188
189 if (pm)
190 return pm_generic_restore(dev);
191 else
192 return spi_legacy_resume(dev);
193}
135#else 194#else
136#define spi_suspend NULL 195#define spi_pm_suspend NULL
137#define spi_resume NULL 196#define spi_pm_resume NULL
197#define spi_pm_freeze NULL
198#define spi_pm_thaw NULL
199#define spi_pm_poweroff NULL
200#define spi_pm_restore NULL
138#endif 201#endif
139 202
203static const struct dev_pm_ops spi_pm = {
204 .suspend = spi_pm_suspend,
205 .resume = spi_pm_resume,
206 .freeze = spi_pm_freeze,
207 .thaw = spi_pm_thaw,
208 .poweroff = spi_pm_poweroff,
209 .restore = spi_pm_restore,
210 SET_RUNTIME_PM_OPS(
211 pm_generic_runtime_suspend,
212 pm_generic_runtime_resume,
213 pm_generic_runtime_idle
214 )
215};
216
140struct bus_type spi_bus_type = { 217struct bus_type spi_bus_type = {
141 .name = "spi", 218 .name = "spi",
142 .dev_attrs = spi_dev_attrs, 219 .dev_attrs = spi_dev_attrs,
143 .match = spi_match_device, 220 .match = spi_match_device,
144 .uevent = spi_uevent, 221 .uevent = spi_uevent,
145 .suspend = spi_suspend, 222 .pm = &spi_pm,
146 .resume = spi_resume,
147}; 223};
148EXPORT_SYMBOL_GPL(spi_bus_type); 224EXPORT_SYMBOL_GPL(spi_bus_type);
149 225
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index b9278a1fb9e5..fca61720b873 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -375,7 +375,7 @@ static int usb_unbind_interface(struct device *dev)
375 * Just re-enable it without affecting the endpoint toggles. 375 * Just re-enable it without affecting the endpoint toggles.
376 */ 376 */
377 usb_enable_interface(udev, intf, false); 377 usb_enable_interface(udev, intf, false);
378 } else if (!error && intf->dev.power.status == DPM_ON) { 378 } else if (!error && !intf->dev.power.in_suspend) {
379 r = usb_set_interface(udev, intf->altsetting[0]. 379 r = usb_set_interface(udev, intf->altsetting[0].
380 desc.bInterfaceNumber, 0); 380 desc.bInterfaceNumber, 0);
381 if (r < 0) 381 if (r < 0)
@@ -960,7 +960,7 @@ void usb_rebind_intf(struct usb_interface *intf)
960 } 960 }
961 961
962 /* Try to rebind the interface */ 962 /* Try to rebind the interface */
963 if (intf->dev.power.status == DPM_ON) { 963 if (!intf->dev.power.in_suspend) {
964 intf->needs_binding = 0; 964 intf->needs_binding = 0;
965 rc = device_attach(&intf->dev); 965 rc = device_attach(&intf->dev);
966 if (rc < 0) 966 if (rc < 0)
@@ -1107,8 +1107,7 @@ static int usb_resume_interface(struct usb_device *udev,
1107 if (intf->condition == USB_INTERFACE_UNBOUND) { 1107 if (intf->condition == USB_INTERFACE_UNBOUND) {
1108 1108
1109 /* Carry out a deferred switch to altsetting 0 */ 1109 /* Carry out a deferred switch to altsetting 0 */
1110 if (intf->needs_altsetting0 && 1110 if (intf->needs_altsetting0 && !intf->dev.power.in_suspend) {
1111 intf->dev.power.status == DPM_ON) {
1112 usb_set_interface(udev, intf->altsetting[0]. 1111 usb_set_interface(udev, intf->altsetting[0].
1113 desc.bInterfaceNumber, 0); 1112 desc.bInterfaceNumber, 0);
1114 intf->needs_altsetting0 = 0; 1113 intf->needs_altsetting0 = 0;
diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
index 9e8639d4e862..b0176e4569e0 100644
--- a/drivers/usb/musb/musb_debugfs.c
+++ b/drivers/usb/musb/musb_debugfs.c
@@ -36,7 +36,6 @@
36#include <linux/sched.h> 36#include <linux/sched.h>
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/list.h> 38#include <linux/list.h>
39#include <linux/kobject.h>
40#include <linux/platform_device.h> 39#include <linux/platform_device.h>
41#include <linux/io.h> 40#include <linux/io.h>
42#include <linux/debugfs.h> 41#include <linux/debugfs.h>
diff --git a/drivers/video/xen-fbfront.c b/drivers/video/xen-fbfront.c
index 4abb0b9ed653..3e6934d4bea8 100644
--- a/drivers/video/xen-fbfront.c
+++ b/drivers/video/xen-fbfront.c
@@ -562,26 +562,24 @@ static void xenfb_init_shared_page(struct xenfb_info *info,
562static int xenfb_connect_backend(struct xenbus_device *dev, 562static int xenfb_connect_backend(struct xenbus_device *dev,
563 struct xenfb_info *info) 563 struct xenfb_info *info)
564{ 564{
565 int ret, evtchn; 565 int ret, evtchn, irq;
566 struct xenbus_transaction xbt; 566 struct xenbus_transaction xbt;
567 567
568 ret = xenbus_alloc_evtchn(dev, &evtchn); 568 ret = xenbus_alloc_evtchn(dev, &evtchn);
569 if (ret) 569 if (ret)
570 return ret; 570 return ret;
571 ret = bind_evtchn_to_irqhandler(evtchn, xenfb_event_handler, 571 irq = bind_evtchn_to_irqhandler(evtchn, xenfb_event_handler,
572 0, dev->devicetype, info); 572 0, dev->devicetype, info);
573 if (ret < 0) { 573 if (irq < 0) {
574 xenbus_free_evtchn(dev, evtchn); 574 xenbus_free_evtchn(dev, evtchn);
575 xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler"); 575 xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
576 return ret; 576 return irq;
577 } 577 }
578 info->irq = ret;
579
580 again: 578 again:
581 ret = xenbus_transaction_start(&xbt); 579 ret = xenbus_transaction_start(&xbt);
582 if (ret) { 580 if (ret) {
583 xenbus_dev_fatal(dev, ret, "starting transaction"); 581 xenbus_dev_fatal(dev, ret, "starting transaction");
584 return ret; 582 goto unbind_irq;
585 } 583 }
586 ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu", 584 ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
587 virt_to_mfn(info->page)); 585 virt_to_mfn(info->page));
@@ -603,20 +601,25 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
603 if (ret == -EAGAIN) 601 if (ret == -EAGAIN)
604 goto again; 602 goto again;
605 xenbus_dev_fatal(dev, ret, "completing transaction"); 603 xenbus_dev_fatal(dev, ret, "completing transaction");
606 return ret; 604 goto unbind_irq;
607 } 605 }
608 606
609 xenbus_switch_state(dev, XenbusStateInitialised); 607 xenbus_switch_state(dev, XenbusStateInitialised);
608 info->irq = irq;
610 return 0; 609 return 0;
611 610
612 error_xenbus: 611 error_xenbus:
613 xenbus_transaction_end(xbt, 1); 612 xenbus_transaction_end(xbt, 1);
614 xenbus_dev_fatal(dev, ret, "writing xenstore"); 613 xenbus_dev_fatal(dev, ret, "writing xenstore");
614 unbind_irq:
615 unbind_from_irqhandler(irq, info);
615 return ret; 616 return ret;
616} 617}
617 618
618static void xenfb_disconnect_backend(struct xenfb_info *info) 619static void xenfb_disconnect_backend(struct xenfb_info *info)
619{ 620{
621 /* Prevent xenfb refresh */
622 info->update_wanted = 0;
620 if (info->irq >= 0) 623 if (info->irq >= 0)
621 unbind_from_irqhandler(info->irq, info); 624 unbind_from_irqhandler(info->irq, info);
622 info->irq = -1; 625 info->irq = -1;
diff --git a/drivers/xen/events.c b/drivers/xen/events.c
index 65f8637d13cf..74681478100a 100644
--- a/drivers/xen/events.c
+++ b/drivers/xen/events.c
@@ -170,6 +170,9 @@ static struct irq_info *info_for_irq(unsigned irq)
170 170
171static unsigned int evtchn_from_irq(unsigned irq) 171static unsigned int evtchn_from_irq(unsigned irq)
172{ 172{
173 if (unlikely(WARN(irq < 0 || irq >= nr_irqs, "Invalid irq %d!\n", irq)))
174 return 0;
175
173 return info_for_irq(irq)->evtchn; 176 return info_for_irq(irq)->evtchn;
174} 177}
175 178
@@ -405,15 +408,21 @@ static int find_unbound_irq(void)
405{ 408{
406 struct irq_data *data; 409 struct irq_data *data;
407 int irq, res; 410 int irq, res;
408 int start = get_nr_hw_irqs(); 411 int bottom = get_nr_hw_irqs();
412 int top = nr_irqs-1;
409 413
410 if (start == nr_irqs) 414 if (bottom == nr_irqs)
411 goto no_irqs; 415 goto no_irqs;
412 416
413 /* nr_irqs is a magic value. Must not use it.*/ 417 /* This loop starts from the top of IRQ space and goes down.
414 for (irq = nr_irqs-1; irq > start; irq--) { 418 * We need this b/c if we have a PCI device in a Xen PV guest
419 * we do not have an IO-APIC (though the backend might have them)
420 * mapped in. To not have a collision of physical IRQs with the Xen
421 * event channels start at the top of the IRQ space for virtual IRQs.
422 */
423 for (irq = top; irq > bottom; irq--) {
415 data = irq_get_irq_data(irq); 424 data = irq_get_irq_data(irq);
416 /* only 0->15 have init'd desc; handle irq > 16 */ 425 /* only 15->0 have init'd desc; handle irq > 16 */
417 if (!data) 426 if (!data)
418 break; 427 break;
419 if (data->chip == &no_irq_chip) 428 if (data->chip == &no_irq_chip)
@@ -424,7 +433,7 @@ static int find_unbound_irq(void)
424 return irq; 433 return irq;
425 } 434 }
426 435
427 if (irq == start) 436 if (irq == bottom)
428 goto no_irqs; 437 goto no_irqs;
429 438
430 res = irq_alloc_desc_at(irq, -1); 439 res = irq_alloc_desc_at(irq, -1);
diff --git a/fs/cifs/cache.c b/fs/cifs/cache.c
index 224d7bbd1fcc..e654dfd092c3 100644
--- a/fs/cifs/cache.c
+++ b/fs/cifs/cache.c
@@ -64,7 +64,9 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
64 void *buffer, uint16_t maxbuf) 64 void *buffer, uint16_t maxbuf)
65{ 65{
66 const struct TCP_Server_Info *server = cookie_netfs_data; 66 const struct TCP_Server_Info *server = cookie_netfs_data;
67 const struct sockaddr *sa = (struct sockaddr *) &server->addr.sockAddr; 67 const struct sockaddr *sa = (struct sockaddr *) &server->dstaddr;
68 const struct sockaddr_in *addr = (struct sockaddr_in *) sa;
69 const struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) sa;
68 struct cifs_server_key *key = buffer; 70 struct cifs_server_key *key = buffer;
69 uint16_t key_len = sizeof(struct cifs_server_key); 71 uint16_t key_len = sizeof(struct cifs_server_key);
70 72
@@ -76,16 +78,16 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
76 */ 78 */
77 switch (sa->sa_family) { 79 switch (sa->sa_family) {
78 case AF_INET: 80 case AF_INET:
79 key->family = server->addr.sockAddr.sin_family; 81 key->family = sa->sa_family;
80 key->port = server->addr.sockAddr.sin_port; 82 key->port = addr->sin_port;
81 key->addr[0].ipv4_addr = server->addr.sockAddr.sin_addr; 83 key->addr[0].ipv4_addr = addr->sin_addr;
82 key_len += sizeof(key->addr[0].ipv4_addr); 84 key_len += sizeof(key->addr[0].ipv4_addr);
83 break; 85 break;
84 86
85 case AF_INET6: 87 case AF_INET6:
86 key->family = server->addr.sockAddr6.sin6_family; 88 key->family = sa->sa_family;
87 key->port = server->addr.sockAddr6.sin6_port; 89 key->port = addr6->sin6_port;
88 key->addr[0].ipv6_addr = server->addr.sockAddr6.sin6_addr; 90 key->addr[0].ipv6_addr = addr6->sin6_addr;
89 key_len += sizeof(key->addr[0].ipv6_addr); 91 key_len += sizeof(key->addr[0].ipv6_addr);
90 break; 92 break;
91 93
diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
index 103ab8b605b0..ede98300a8cd 100644
--- a/fs/cifs/cifs_debug.c
+++ b/fs/cifs/cifs_debug.c
@@ -119,29 +119,27 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
119 "Display Internal CIFS Data Structures for Debugging\n" 119 "Display Internal CIFS Data Structures for Debugging\n"
120 "---------------------------------------------------\n"); 120 "---------------------------------------------------\n");
121 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION); 121 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
122 seq_printf(m, "Features: "); 122 seq_printf(m, "Features:");
123#ifdef CONFIG_CIFS_DFS_UPCALL 123#ifdef CONFIG_CIFS_DFS_UPCALL
124 seq_printf(m, "dfs"); 124 seq_printf(m, " dfs");
125 seq_putc(m, ' ');
126#endif 125#endif
127#ifdef CONFIG_CIFS_FSCACHE 126#ifdef CONFIG_CIFS_FSCACHE
128 seq_printf(m, "fscache"); 127 seq_printf(m, " fscache");
129 seq_putc(m, ' ');
130#endif 128#endif
131#ifdef CONFIG_CIFS_WEAK_PW_HASH 129#ifdef CONFIG_CIFS_WEAK_PW_HASH
132 seq_printf(m, "lanman"); 130 seq_printf(m, " lanman");
133 seq_putc(m, ' ');
134#endif 131#endif
135#ifdef CONFIG_CIFS_POSIX 132#ifdef CONFIG_CIFS_POSIX
136 seq_printf(m, "posix"); 133 seq_printf(m, " posix");
137 seq_putc(m, ' ');
138#endif 134#endif
139#ifdef CONFIG_CIFS_UPCALL 135#ifdef CONFIG_CIFS_UPCALL
140 seq_printf(m, "spnego"); 136 seq_printf(m, " spnego");
141 seq_putc(m, ' ');
142#endif 137#endif
143#ifdef CONFIG_CIFS_XATTR 138#ifdef CONFIG_CIFS_XATTR
144 seq_printf(m, "xattr"); 139 seq_printf(m, " xattr");
140#endif
141#ifdef CONFIG_CIFS_ACL
142 seq_printf(m, " acl");
145#endif 143#endif
146 seq_putc(m, '\n'); 144 seq_putc(m, '\n');
147 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid); 145 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
diff --git a/fs/cifs/cifs_spnego.c b/fs/cifs/cifs_spnego.c
index 87044906cd1f..4dfba8283165 100644
--- a/fs/cifs/cifs_spnego.c
+++ b/fs/cifs/cifs_spnego.c
@@ -98,6 +98,8 @@ struct key *
98cifs_get_spnego_key(struct cifsSesInfo *sesInfo) 98cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
99{ 99{
100 struct TCP_Server_Info *server = sesInfo->server; 100 struct TCP_Server_Info *server = sesInfo->server;
101 struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
102 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
101 char *description, *dp; 103 char *description, *dp;
102 size_t desc_len; 104 size_t desc_len;
103 struct key *spnego_key; 105 struct key *spnego_key;
@@ -127,10 +129,10 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
127 dp = description + strlen(description); 129 dp = description + strlen(description);
128 130
129 /* add the server address */ 131 /* add the server address */
130 if (server->addr.sockAddr.sin_family == AF_INET) 132 if (server->dstaddr.ss_family == AF_INET)
131 sprintf(dp, "ip4=%pI4", &server->addr.sockAddr.sin_addr); 133 sprintf(dp, "ip4=%pI4", &sa->sin_addr);
132 else if (server->addr.sockAddr.sin_family == AF_INET6) 134 else if (server->dstaddr.ss_family == AF_INET6)
133 sprintf(dp, "ip6=%pI6", &server->addr.sockAddr6.sin6_addr); 135 sprintf(dp, "ip6=%pI6", &sa6->sin6_addr);
134 else 136 else
135 goto out; 137 goto out;
136 138
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index f856732161ab..66f3d50d0676 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -72,6 +72,7 @@ static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu,
72 return 0; 72 return 0;
73} 73}
74 74
75/* must be called with server->srv_mutex held */
75int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, 76int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
76 __u32 *pexpected_response_sequence_number) 77 __u32 *pexpected_response_sequence_number)
77{ 78{
@@ -84,14 +85,12 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
84 if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0) 85 if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0)
85 return rc; 86 return rc;
86 87
87 spin_lock(&GlobalMid_Lock);
88 cifs_pdu->Signature.Sequence.SequenceNumber = 88 cifs_pdu->Signature.Sequence.SequenceNumber =
89 cpu_to_le32(server->sequence_number); 89 cpu_to_le32(server->sequence_number);
90 cifs_pdu->Signature.Sequence.Reserved = 0; 90 cifs_pdu->Signature.Sequence.Reserved = 0;
91 91
92 *pexpected_response_sequence_number = server->sequence_number++; 92 *pexpected_response_sequence_number = server->sequence_number++;
93 server->sequence_number++; 93 server->sequence_number++;
94 spin_unlock(&GlobalMid_Lock);
95 94
96 rc = cifs_calculate_signature(cifs_pdu, server, smb_signature); 95 rc = cifs_calculate_signature(cifs_pdu, server, smb_signature);
97 if (rc) 96 if (rc)
@@ -149,6 +148,7 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec,
149 return rc; 148 return rc;
150} 149}
151 150
151/* must be called with server->srv_mutex held */
152int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, 152int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,
153 __u32 *pexpected_response_sequence_number) 153 __u32 *pexpected_response_sequence_number)
154{ 154{
@@ -162,14 +162,12 @@ int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,
162 if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0) 162 if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0)
163 return rc; 163 return rc;
164 164
165 spin_lock(&GlobalMid_Lock);
166 cifs_pdu->Signature.Sequence.SequenceNumber = 165 cifs_pdu->Signature.Sequence.SequenceNumber =
167 cpu_to_le32(server->sequence_number); 166 cpu_to_le32(server->sequence_number);
168 cifs_pdu->Signature.Sequence.Reserved = 0; 167 cifs_pdu->Signature.Sequence.Reserved = 0;
169 168
170 *pexpected_response_sequence_number = server->sequence_number++; 169 *pexpected_response_sequence_number = server->sequence_number++;
171 server->sequence_number++; 170 server->sequence_number++;
172 spin_unlock(&GlobalMid_Lock);
173 171
174 rc = cifs_calc_signature2(iov, n_vec, server, smb_signature); 172 rc = cifs_calc_signature2(iov, n_vec, server, smb_signature);
175 if (rc) 173 if (rc)
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 8e21e0fe65d5..5e7075d5f139 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -329,6 +329,8 @@ cifs_alloc_inode(struct super_block *sb)
329 cifs_inode->invalid_mapping = false; 329 cifs_inode->invalid_mapping = false;
330 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */ 330 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
331 cifs_inode->server_eof = 0; 331 cifs_inode->server_eof = 0;
332 cifs_inode->uniqueid = 0;
333 cifs_inode->createtime = 0;
332 334
333 /* Can not set i_flags here - they get immediately overwritten 335 /* Can not set i_flags here - they get immediately overwritten
334 to zero by the VFS */ 336 to zero by the VFS */
@@ -361,18 +363,19 @@ cifs_evict_inode(struct inode *inode)
361static void 363static void
362cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server) 364cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
363{ 365{
366 struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
367 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
368
364 seq_printf(s, ",addr="); 369 seq_printf(s, ",addr=");
365 370
366 switch (server->addr.sockAddr.sin_family) { 371 switch (server->dstaddr.ss_family) {
367 case AF_INET: 372 case AF_INET:
368 seq_printf(s, "%pI4", &server->addr.sockAddr.sin_addr.s_addr); 373 seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
369 break; 374 break;
370 case AF_INET6: 375 case AF_INET6:
371 seq_printf(s, "%pI6", 376 seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
372 &server->addr.sockAddr6.sin6_addr.s6_addr); 377 if (sa6->sin6_scope_id)
373 if (server->addr.sockAddr6.sin6_scope_id) 378 seq_printf(s, "%%%u", sa6->sin6_scope_id);
374 seq_printf(s, "%%%u",
375 server->addr.sockAddr6.sin6_scope_id);
376 break; 379 break;
377 default: 380 default:
378 seq_printf(s, "(unknown)"); 381 seq_printf(s, "(unknown)");
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 7136c0c3e2f9..606ca8bb7102 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -163,10 +163,7 @@ struct TCP_Server_Info {
163 char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; 163 char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
164 char *hostname; /* hostname portion of UNC string */ 164 char *hostname; /* hostname portion of UNC string */
165 struct socket *ssocket; 165 struct socket *ssocket;
166 union { 166 struct sockaddr_storage dstaddr;
167 struct sockaddr_in sockAddr;
168 struct sockaddr_in6 sockAddr6;
169 } addr;
170 struct sockaddr_storage srcaddr; /* locally bind to this IP */ 167 struct sockaddr_storage srcaddr; /* locally bind to this IP */
171 wait_queue_head_t response_q; 168 wait_queue_head_t response_q;
172 wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/ 169 wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
@@ -210,7 +207,7 @@ struct TCP_Server_Info {
210 char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */ 207 char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */
211 /* 16th byte of RFC1001 workstation name is always null */ 208 /* 16th byte of RFC1001 workstation name is always null */
212 char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; 209 char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
213 __u32 sequence_number; /* needed for CIFS PDU signature */ 210 __u32 sequence_number; /* for signing, protected by srv_mutex */
214 struct session_key session_key; 211 struct session_key session_key;
215 unsigned long lstrp; /* when we got last response from this server */ 212 unsigned long lstrp; /* when we got last response from this server */
216 u16 dialect; /* dialect index that server chose */ 213 u16 dialect; /* dialect index that server chose */
@@ -456,6 +453,7 @@ struct cifsInodeInfo {
456 bool invalid_mapping:1; /* pagecache is invalid */ 453 bool invalid_mapping:1; /* pagecache is invalid */
457 u64 server_eof; /* current file size on server */ 454 u64 server_eof; /* current file size on server */
458 u64 uniqueid; /* server inode number */ 455 u64 uniqueid; /* server inode number */
456 u64 createtime; /* creation time on server */
459#ifdef CONFIG_CIFS_FSCACHE 457#ifdef CONFIG_CIFS_FSCACHE
460 struct fscache_cookie *fscache; 458 struct fscache_cookie *fscache;
461#endif 459#endif
@@ -576,6 +574,7 @@ struct cifs_fattr {
576 u64 cf_uniqueid; 574 u64 cf_uniqueid;
577 u64 cf_eof; 575 u64 cf_eof;
578 u64 cf_bytes; 576 u64 cf_bytes;
577 u64 cf_createtime;
579 uid_t cf_uid; 578 uid_t cf_uid;
580 gid_t cf_gid; 579 gid_t cf_gid;
581 umode_t cf_mode; 580 umode_t cf_mode;
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 67acfb3acad2..2f6795e524d3 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -401,15 +401,12 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
401 else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) { 401 else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) {
402 cFYI(1, "Kerberos only mechanism, enable extended security"); 402 cFYI(1, "Kerberos only mechanism, enable extended security");
403 pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; 403 pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
404 } 404 } else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
405#ifdef CONFIG_CIFS_EXPERIMENTAL
406 else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
407 pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; 405 pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
408 else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) { 406 else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) {
409 cFYI(1, "NTLMSSP only mechanism, enable extended security"); 407 cFYI(1, "NTLMSSP only mechanism, enable extended security");
410 pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; 408 pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
411 } 409 }
412#endif
413 410
414 count = 0; 411 count = 0;
415 for (i = 0; i < CIFS_NUM_PROT; i++) { 412 for (i = 0; i < CIFS_NUM_PROT; i++) {
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index cc1a8604a790..a65d311d163a 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -64,8 +64,8 @@ struct smb_vol {
64 char *UNC; 64 char *UNC;
65 char *UNCip; 65 char *UNCip;
66 char *iocharset; /* local code page for mapping to and from Unicode */ 66 char *iocharset; /* local code page for mapping to and from Unicode */
67 char source_rfc1001_name[16]; /* netbios name of client */ 67 char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
68 char target_rfc1001_name[16]; /* netbios name of server for Win9x/ME */ 68 char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
69 uid_t cred_uid; 69 uid_t cred_uid;
70 uid_t linux_uid; 70 uid_t linux_uid;
71 gid_t linux_gid; 71 gid_t linux_gid;
@@ -115,8 +115,8 @@ struct smb_vol {
115#define TLINK_ERROR_EXPIRE (1 * HZ) 115#define TLINK_ERROR_EXPIRE (1 * HZ)
116#define TLINK_IDLE_EXPIRE (600 * HZ) 116#define TLINK_IDLE_EXPIRE (600 * HZ)
117 117
118static int ipv4_connect(struct TCP_Server_Info *server); 118static int ip_connect(struct TCP_Server_Info *server);
119static int ipv6_connect(struct TCP_Server_Info *server); 119static int generic_ip_connect(struct TCP_Server_Info *server);
120static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink); 120static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink);
121static void cifs_prune_tlinks(struct work_struct *work); 121static void cifs_prune_tlinks(struct work_struct *work);
122 122
@@ -200,10 +200,9 @@ cifs_reconnect(struct TCP_Server_Info *server)
200 while ((server->tcpStatus != CifsExiting) && 200 while ((server->tcpStatus != CifsExiting) &&
201 (server->tcpStatus != CifsGood)) { 201 (server->tcpStatus != CifsGood)) {
202 try_to_freeze(); 202 try_to_freeze();
203 if (server->addr.sockAddr6.sin6_family == AF_INET6) 203
204 rc = ipv6_connect(server); 204 /* we should try only the port we connected to before */
205 else 205 rc = generic_ip_connect(server);
206 rc = ipv4_connect(server);
207 if (rc) { 206 if (rc) {
208 cFYI(1, "reconnect error %d", rc); 207 cFYI(1, "reconnect error %d", rc);
209 msleep(3000); 208 msleep(3000);
@@ -477,7 +476,7 @@ incomplete_rcv:
477 * initialize frame) 476 * initialize frame)
478 */ 477 */
479 cifs_set_port((struct sockaddr *) 478 cifs_set_port((struct sockaddr *)
480 &server->addr.sockAddr, CIFS_PORT); 479 &server->dstaddr, CIFS_PORT);
481 cifs_reconnect(server); 480 cifs_reconnect(server);
482 csocket = server->ssocket; 481 csocket = server->ssocket;
483 wake_up(&server->response_q); 482 wake_up(&server->response_q);
@@ -817,11 +816,11 @@ cifs_parse_mount_options(char *options, const char *devname,
817 * informational, only used for servers that do not support 816 * informational, only used for servers that do not support
818 * port 445 and it can be overridden at mount time 817 * port 445 and it can be overridden at mount time
819 */ 818 */
820 memset(vol->source_rfc1001_name, 0x20, 15); 819 memset(vol->source_rfc1001_name, 0x20, RFC1001_NAME_LEN);
821 for (i = 0; i < strnlen(nodename, 15); i++) 820 for (i = 0; i < strnlen(nodename, RFC1001_NAME_LEN); i++)
822 vol->source_rfc1001_name[i] = toupper(nodename[i]); 821 vol->source_rfc1001_name[i] = toupper(nodename[i]);
823 822
824 vol->source_rfc1001_name[15] = 0; 823 vol->source_rfc1001_name[RFC1001_NAME_LEN] = 0;
825 /* null target name indicates to use *SMBSERVR default called name 824 /* null target name indicates to use *SMBSERVR default called name
826 if we end up sending RFC1001 session initialize */ 825 if we end up sending RFC1001 session initialize */
827 vol->target_rfc1001_name[0] = 0; 826 vol->target_rfc1001_name[0] = 0;
@@ -985,13 +984,11 @@ cifs_parse_mount_options(char *options, const char *devname,
985 return 1; 984 return 1;
986 } else if (strnicmp(value, "krb5", 4) == 0) { 985 } else if (strnicmp(value, "krb5", 4) == 0) {
987 vol->secFlg |= CIFSSEC_MAY_KRB5; 986 vol->secFlg |= CIFSSEC_MAY_KRB5;
988#ifdef CONFIG_CIFS_EXPERIMENTAL
989 } else if (strnicmp(value, "ntlmsspi", 8) == 0) { 987 } else if (strnicmp(value, "ntlmsspi", 8) == 0) {
990 vol->secFlg |= CIFSSEC_MAY_NTLMSSP | 988 vol->secFlg |= CIFSSEC_MAY_NTLMSSP |
991 CIFSSEC_MUST_SIGN; 989 CIFSSEC_MUST_SIGN;
992 } else if (strnicmp(value, "ntlmssp", 7) == 0) { 990 } else if (strnicmp(value, "ntlmssp", 7) == 0) {
993 vol->secFlg |= CIFSSEC_MAY_NTLMSSP; 991 vol->secFlg |= CIFSSEC_MAY_NTLMSSP;
994#endif
995 } else if (strnicmp(value, "ntlmv2i", 7) == 0) { 992 } else if (strnicmp(value, "ntlmv2i", 7) == 0) {
996 vol->secFlg |= CIFSSEC_MAY_NTLMV2 | 993 vol->secFlg |= CIFSSEC_MAY_NTLMV2 |
997 CIFSSEC_MUST_SIGN; 994 CIFSSEC_MUST_SIGN;
@@ -1168,22 +1165,22 @@ cifs_parse_mount_options(char *options, const char *devname,
1168 if (!value || !*value || (*value == ' ')) { 1165 if (!value || !*value || (*value == ' ')) {
1169 cFYI(1, "invalid (empty) netbiosname"); 1166 cFYI(1, "invalid (empty) netbiosname");
1170 } else { 1167 } else {
1171 memset(vol->source_rfc1001_name, 0x20, 15); 1168 memset(vol->source_rfc1001_name, 0x20,
1172 for (i = 0; i < 15; i++) { 1169 RFC1001_NAME_LEN);
1173 /* BB are there cases in which a comma can be 1170 /*
1174 valid in this workstation netbios name (and need 1171 * FIXME: are there cases in which a comma can
1175 special handling)? */ 1172 * be valid in workstation netbios name (and
1176 1173 * need special handling)?
1177 /* We do not uppercase netbiosname for user */ 1174 */
1175 for (i = 0; i < RFC1001_NAME_LEN; i++) {
1176 /* don't ucase netbiosname for user */
1178 if (value[i] == 0) 1177 if (value[i] == 0)
1179 break; 1178 break;
1180 else 1179 vol->source_rfc1001_name[i] = value[i];
1181 vol->source_rfc1001_name[i] =
1182 value[i];
1183 } 1180 }
1184 /* The string has 16th byte zero still from 1181 /* The string has 16th byte zero still from
1185 set at top of the function */ 1182 set at top of the function */
1186 if ((i == 15) && (value[i] != 0)) 1183 if (i == RFC1001_NAME_LEN && value[i] != 0)
1187 printk(KERN_WARNING "CIFS: netbiosname" 1184 printk(KERN_WARNING "CIFS: netbiosname"
1188 " longer than 15 truncated.\n"); 1185 " longer than 15 truncated.\n");
1189 } 1186 }
@@ -1193,7 +1190,8 @@ cifs_parse_mount_options(char *options, const char *devname,
1193 cFYI(1, "empty server netbiosname specified"); 1190 cFYI(1, "empty server netbiosname specified");
1194 } else { 1191 } else {
1195 /* last byte, type, is 0x20 for servr type */ 1192 /* last byte, type, is 0x20 for servr type */
1196 memset(vol->target_rfc1001_name, 0x20, 16); 1193 memset(vol->target_rfc1001_name, 0x20,
1194 RFC1001_NAME_LEN_WITH_NULL);
1197 1195
1198 for (i = 0; i < 15; i++) { 1196 for (i = 0; i < 15; i++) {
1199 /* BB are there cases in which a comma can be 1197 /* BB are there cases in which a comma can be
@@ -1210,7 +1208,7 @@ cifs_parse_mount_options(char *options, const char *devname,
1210 } 1208 }
1211 /* The string has 16th byte zero still from 1209 /* The string has 16th byte zero still from
1212 set at top of the function */ 1210 set at top of the function */
1213 if ((i == 15) && (value[i] != 0)) 1211 if (i == RFC1001_NAME_LEN && value[i] != 0)
1214 printk(KERN_WARNING "CIFS: server net" 1212 printk(KERN_WARNING "CIFS: server net"
1215 "biosname longer than 15 truncated.\n"); 1213 "biosname longer than 15 truncated.\n");
1216 } 1214 }
@@ -1341,10 +1339,8 @@ cifs_parse_mount_options(char *options, const char *devname,
1341 vol->no_psx_acl = 0; 1339 vol->no_psx_acl = 0;
1342 } else if (strnicmp(data, "noacl", 5) == 0) { 1340 } else if (strnicmp(data, "noacl", 5) == 0) {
1343 vol->no_psx_acl = 1; 1341 vol->no_psx_acl = 1;
1344#ifdef CONFIG_CIFS_EXPERIMENTAL
1345 } else if (strnicmp(data, "locallease", 6) == 0) { 1342 } else if (strnicmp(data, "locallease", 6) == 0) {
1346 vol->local_lease = 1; 1343 vol->local_lease = 1;
1347#endif
1348 } else if (strnicmp(data, "sign", 4) == 0) { 1344 } else if (strnicmp(data, "sign", 4) == 0) {
1349 vol->secFlg |= CIFSSEC_MUST_SIGN; 1345 vol->secFlg |= CIFSSEC_MUST_SIGN;
1350 } else if (strnicmp(data, "seal", 4) == 0) { 1346 } else if (strnicmp(data, "seal", 4) == 0) {
@@ -1454,35 +1450,71 @@ srcip_matches(struct sockaddr *srcaddr, struct sockaddr *rhs)
1454 } 1450 }
1455} 1451}
1456 1452
1453/*
1454 * If no port is specified in addr structure, we try to match with 445 port
1455 * and if it fails - with 139 ports. It should be called only if address
1456 * families of server and addr are equal.
1457 */
1458static bool
1459match_port(struct TCP_Server_Info *server, struct sockaddr *addr)
1460{
1461 unsigned short int port, *sport;
1462
1463 switch (addr->sa_family) {
1464 case AF_INET:
1465 sport = &((struct sockaddr_in *) &server->dstaddr)->sin_port;
1466 port = ((struct sockaddr_in *) addr)->sin_port;
1467 break;
1468 case AF_INET6:
1469 sport = &((struct sockaddr_in6 *) &server->dstaddr)->sin6_port;
1470 port = ((struct sockaddr_in6 *) addr)->sin6_port;
1471 break;
1472 default:
1473 WARN_ON(1);
1474 return false;
1475 }
1476
1477 if (!port) {
1478 port = htons(CIFS_PORT);
1479 if (port == *sport)
1480 return true;
1481
1482 port = htons(RFC1001_PORT);
1483 }
1484
1485 return port == *sport;
1486}
1457 1487
1458static bool 1488static bool
1459match_address(struct TCP_Server_Info *server, struct sockaddr *addr, 1489match_address(struct TCP_Server_Info *server, struct sockaddr *addr,
1460 struct sockaddr *srcaddr) 1490 struct sockaddr *srcaddr)
1461{ 1491{
1462 struct sockaddr_in *addr4 = (struct sockaddr_in *)addr;
1463 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr;
1464
1465 switch (addr->sa_family) { 1492 switch (addr->sa_family) {
1466 case AF_INET: 1493 case AF_INET: {
1467 if (addr4->sin_addr.s_addr != 1494 struct sockaddr_in *addr4 = (struct sockaddr_in *)addr;
1468 server->addr.sockAddr.sin_addr.s_addr) 1495 struct sockaddr_in *srv_addr4 =
1469 return false; 1496 (struct sockaddr_in *)&server->dstaddr;
1470 if (addr4->sin_port && 1497
1471 addr4->sin_port != server->addr.sockAddr.sin_port) 1498 if (addr4->sin_addr.s_addr != srv_addr4->sin_addr.s_addr)
1472 return false; 1499 return false;
1473 break; 1500 break;
1474 case AF_INET6: 1501 }
1502 case AF_INET6: {
1503 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr;
1504 struct sockaddr_in6 *srv_addr6 =
1505 (struct sockaddr_in6 *)&server->dstaddr;
1506
1475 if (!ipv6_addr_equal(&addr6->sin6_addr, 1507 if (!ipv6_addr_equal(&addr6->sin6_addr,
1476 &server->addr.sockAddr6.sin6_addr)) 1508 &srv_addr6->sin6_addr))
1477 return false; 1509 return false;
1478 if (addr6->sin6_scope_id != 1510 if (addr6->sin6_scope_id != srv_addr6->sin6_scope_id)
1479 server->addr.sockAddr6.sin6_scope_id)
1480 return false;
1481 if (addr6->sin6_port &&
1482 addr6->sin6_port != server->addr.sockAddr6.sin6_port)
1483 return false; 1511 return false;
1484 break; 1512 break;
1485 } 1513 }
1514 default:
1515 WARN_ON(1);
1516 return false; /* don't expect to be here */
1517 }
1486 1518
1487 if (!srcip_matches(srcaddr, (struct sockaddr *)&server->srcaddr)) 1519 if (!srcip_matches(srcaddr, (struct sockaddr *)&server->srcaddr))
1488 return false; 1520 return false;
@@ -1549,6 +1581,9 @@ cifs_find_tcp_session(struct sockaddr *addr, struct smb_vol *vol)
1549 (struct sockaddr *)&vol->srcaddr)) 1581 (struct sockaddr *)&vol->srcaddr))
1550 continue; 1582 continue;
1551 1583
1584 if (!match_port(server, addr))
1585 continue;
1586
1552 if (!match_security(server, vol)) 1587 if (!match_security(server, vol))
1553 continue; 1588 continue;
1554 1589
@@ -1681,14 +1716,13 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
1681 cFYI(1, "attempting ipv6 connect"); 1716 cFYI(1, "attempting ipv6 connect");
1682 /* BB should we allow ipv6 on port 139? */ 1717 /* BB should we allow ipv6 on port 139? */
1683 /* other OS never observed in Wild doing 139 with v6 */ 1718 /* other OS never observed in Wild doing 139 with v6 */
1684 memcpy(&tcp_ses->addr.sockAddr6, sin_server6, 1719 memcpy(&tcp_ses->dstaddr, sin_server6,
1685 sizeof(struct sockaddr_in6)); 1720 sizeof(struct sockaddr_in6));
1686 rc = ipv6_connect(tcp_ses); 1721 } else
1687 } else { 1722 memcpy(&tcp_ses->dstaddr, sin_server,
1688 memcpy(&tcp_ses->addr.sockAddr, sin_server, 1723 sizeof(struct sockaddr_in));
1689 sizeof(struct sockaddr_in)); 1724
1690 rc = ipv4_connect(tcp_ses); 1725 rc = ip_connect(tcp_ses);
1691 }
1692 if (rc < 0) { 1726 if (rc < 0) {
1693 cERROR(1, "Error connecting to socket. Aborting operation"); 1727 cERROR(1, "Error connecting to socket. Aborting operation");
1694 goto out_err_crypto_release; 1728 goto out_err_crypto_release;
@@ -1793,6 +1827,8 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
1793{ 1827{
1794 int rc = -ENOMEM, xid; 1828 int rc = -ENOMEM, xid;
1795 struct cifsSesInfo *ses; 1829 struct cifsSesInfo *ses;
1830 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr;
1831 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr;
1796 1832
1797 xid = GetXid(); 1833 xid = GetXid();
1798 1834
@@ -1836,12 +1872,10 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
1836 1872
1837 /* new SMB session uses our server ref */ 1873 /* new SMB session uses our server ref */
1838 ses->server = server; 1874 ses->server = server;
1839 if (server->addr.sockAddr6.sin6_family == AF_INET6) 1875 if (server->dstaddr.ss_family == AF_INET6)
1840 sprintf(ses->serverName, "%pI6", 1876 sprintf(ses->serverName, "%pI6", &addr6->sin6_addr);
1841 &server->addr.sockAddr6.sin6_addr);
1842 else 1877 else
1843 sprintf(ses->serverName, "%pI4", 1878 sprintf(ses->serverName, "%pI4", &addr->sin_addr);
1844 &server->addr.sockAddr.sin_addr.s_addr);
1845 1879
1846 if (volume_info->username) 1880 if (volume_info->username)
1847 strncpy(ses->userName, volume_info->username, 1881 strncpy(ses->userName, volume_info->username,
@@ -2136,19 +2170,106 @@ bind_socket(struct TCP_Server_Info *server)
2136} 2170}
2137 2171
2138static int 2172static int
2139ipv4_connect(struct TCP_Server_Info *server) 2173ip_rfc1001_connect(struct TCP_Server_Info *server)
2174{
2175 int rc = 0;
2176 /*
2177 * some servers require RFC1001 sessinit before sending
2178 * negprot - BB check reconnection in case where second
2179 * sessinit is sent but no second negprot
2180 */
2181 struct rfc1002_session_packet *ses_init_buf;
2182 struct smb_hdr *smb_buf;
2183 ses_init_buf = kzalloc(sizeof(struct rfc1002_session_packet),
2184 GFP_KERNEL);
2185 if (ses_init_buf) {
2186 ses_init_buf->trailer.session_req.called_len = 32;
2187
2188 if (server->server_RFC1001_name &&
2189 server->server_RFC1001_name[0] != 0)
2190 rfc1002mangle(ses_init_buf->trailer.
2191 session_req.called_name,
2192 server->server_RFC1001_name,
2193 RFC1001_NAME_LEN_WITH_NULL);
2194 else
2195 rfc1002mangle(ses_init_buf->trailer.
2196 session_req.called_name,
2197 DEFAULT_CIFS_CALLED_NAME,
2198 RFC1001_NAME_LEN_WITH_NULL);
2199
2200 ses_init_buf->trailer.session_req.calling_len = 32;
2201
2202 /*
2203 * calling name ends in null (byte 16) from old smb
2204 * convention.
2205 */
2206 if (server->workstation_RFC1001_name &&
2207 server->workstation_RFC1001_name[0] != 0)
2208 rfc1002mangle(ses_init_buf->trailer.
2209 session_req.calling_name,
2210 server->workstation_RFC1001_name,
2211 RFC1001_NAME_LEN_WITH_NULL);
2212 else
2213 rfc1002mangle(ses_init_buf->trailer.
2214 session_req.calling_name,
2215 "LINUX_CIFS_CLNT",
2216 RFC1001_NAME_LEN_WITH_NULL);
2217
2218 ses_init_buf->trailer.session_req.scope1 = 0;
2219 ses_init_buf->trailer.session_req.scope2 = 0;
2220 smb_buf = (struct smb_hdr *)ses_init_buf;
2221
2222 /* sizeof RFC1002_SESSION_REQUEST with no scope */
2223 smb_buf->smb_buf_length = 0x81000044;
2224 rc = smb_send(server, smb_buf, 0x44);
2225 kfree(ses_init_buf);
2226 /*
2227 * RFC1001 layer in at least one server
2228 * requires very short break before negprot
2229 * presumably because not expecting negprot
2230 * to follow so fast. This is a simple
2231 * solution that works without
2232 * complicating the code and causes no
2233 * significant slowing down on mount
2234 * for everyone else
2235 */
2236 usleep_range(1000, 2000);
2237 }
2238 /*
2239 * else the negprot may still work without this
2240 * even though malloc failed
2241 */
2242
2243 return rc;
2244}
2245
2246static int
2247generic_ip_connect(struct TCP_Server_Info *server)
2140{ 2248{
2141 int rc = 0; 2249 int rc = 0;
2142 int val; 2250 unsigned short int sport;
2143 bool connected = false; 2251 int slen, sfamily;
2144 __be16 orig_port = 0;
2145 struct socket *socket = server->ssocket; 2252 struct socket *socket = server->ssocket;
2253 struct sockaddr *saddr;
2254
2255 saddr = (struct sockaddr *) &server->dstaddr;
2256
2257 if (server->dstaddr.ss_family == AF_INET6) {
2258 sport = ((struct sockaddr_in6 *) saddr)->sin6_port;
2259 slen = sizeof(struct sockaddr_in6);
2260 sfamily = AF_INET6;
2261 } else {
2262 sport = ((struct sockaddr_in *) saddr)->sin_port;
2263 slen = sizeof(struct sockaddr_in);
2264 sfamily = AF_INET;
2265 }
2146 2266
2147 if (socket == NULL) { 2267 if (socket == NULL) {
2148 rc = sock_create_kern(PF_INET, SOCK_STREAM, 2268 rc = sock_create_kern(sfamily, SOCK_STREAM,
2149 IPPROTO_TCP, &socket); 2269 IPPROTO_TCP, &socket);
2150 if (rc < 0) { 2270 if (rc < 0) {
2151 cERROR(1, "Error %d creating socket", rc); 2271 cERROR(1, "Error %d creating socket", rc);
2272 server->ssocket = NULL;
2152 return rc; 2273 return rc;
2153 } 2274 }
2154 2275
@@ -2156,63 +2277,28 @@ ipv4_connect(struct TCP_Server_Info *server)
2156 cFYI(1, "Socket created"); 2277 cFYI(1, "Socket created");
2157 server->ssocket = socket; 2278 server->ssocket = socket;
2158 socket->sk->sk_allocation = GFP_NOFS; 2279 socket->sk->sk_allocation = GFP_NOFS;
2159 cifs_reclassify_socket4(socket); 2280 if (sfamily == AF_INET6)
2281 cifs_reclassify_socket6(socket);
2282 else
2283 cifs_reclassify_socket4(socket);
2160 } 2284 }
2161 2285
2162 rc = bind_socket(server); 2286 rc = bind_socket(server);
2163 if (rc < 0) 2287 if (rc < 0)
2164 return rc; 2288 return rc;
2165 2289
2166 /* user overrode default port */ 2290 rc = socket->ops->connect(socket, saddr, slen, 0);
2167 if (server->addr.sockAddr.sin_port) { 2291 if (rc < 0) {
2168 rc = socket->ops->connect(socket, (struct sockaddr *) 2292 cFYI(1, "Error %d connecting to server", rc);
2169 &server->addr.sockAddr,
2170 sizeof(struct sockaddr_in), 0);
2171 if (rc >= 0)
2172 connected = true;
2173 }
2174
2175 if (!connected) {
2176 /* save original port so we can retry user specified port
2177 later if fall back ports fail this time */
2178 orig_port = server->addr.sockAddr.sin_port;
2179
2180 /* do not retry on the same port we just failed on */
2181 if (server->addr.sockAddr.sin_port != htons(CIFS_PORT)) {
2182 server->addr.sockAddr.sin_port = htons(CIFS_PORT);
2183 rc = socket->ops->connect(socket,
2184 (struct sockaddr *)
2185 &server->addr.sockAddr,
2186 sizeof(struct sockaddr_in), 0);
2187 if (rc >= 0)
2188 connected = true;
2189 }
2190 }
2191 if (!connected) {
2192 server->addr.sockAddr.sin_port = htons(RFC1001_PORT);
2193 rc = socket->ops->connect(socket, (struct sockaddr *)
2194 &server->addr.sockAddr,
2195 sizeof(struct sockaddr_in), 0);
2196 if (rc >= 0)
2197 connected = true;
2198 }
2199
2200 /* give up here - unless we want to retry on different
2201 protocol families some day */
2202 if (!connected) {
2203 if (orig_port)
2204 server->addr.sockAddr.sin_port = orig_port;
2205 cFYI(1, "Error %d connecting to server via ipv4", rc);
2206 sock_release(socket); 2293 sock_release(socket);
2207 server->ssocket = NULL; 2294 server->ssocket = NULL;
2208 return rc; 2295 return rc;
2209 } 2296 }
2210 2297
2211
2212 /* 2298 /*
2213 * Eventually check for other socket options to change from 2299 * Eventually check for other socket options to change from
2214 * the default. sock_setsockopt not used because it expects 2300 * the default. sock_setsockopt not used because it expects
2215 * user space buffer 2301 * user space buffer
2216 */ 2302 */
2217 socket->sk->sk_rcvtimeo = 7 * HZ; 2303 socket->sk->sk_rcvtimeo = 7 * HZ;
2218 socket->sk->sk_sndtimeo = 5 * HZ; 2304 socket->sk->sk_sndtimeo = 5 * HZ;
@@ -2226,7 +2312,7 @@ ipv4_connect(struct TCP_Server_Info *server)
2226 } 2312 }
2227 2313
2228 if (server->tcp_nodelay) { 2314 if (server->tcp_nodelay) {
2229 val = 1; 2315 int val = 1;
2230 rc = kernel_setsockopt(socket, SOL_TCP, TCP_NODELAY, 2316 rc = kernel_setsockopt(socket, SOL_TCP, TCP_NODELAY,
2231 (char *)&val, sizeof(val)); 2317 (char *)&val, sizeof(val));
2232 if (rc) 2318 if (rc)
@@ -2237,161 +2323,39 @@ ipv4_connect(struct TCP_Server_Info *server)
2237 socket->sk->sk_sndbuf, 2323 socket->sk->sk_sndbuf,
2238 socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo); 2324 socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo);
2239 2325
2240 /* send RFC1001 sessinit */ 2326 if (sport == htons(RFC1001_PORT))
2241 if (server->addr.sockAddr.sin_port == htons(RFC1001_PORT)) { 2327 rc = ip_rfc1001_connect(server);
2242 /* some servers require RFC1001 sessinit before sending
2243 negprot - BB check reconnection in case where second
2244 sessinit is sent but no second negprot */
2245 struct rfc1002_session_packet *ses_init_buf;
2246 struct smb_hdr *smb_buf;
2247 ses_init_buf = kzalloc(sizeof(struct rfc1002_session_packet),
2248 GFP_KERNEL);
2249 if (ses_init_buf) {
2250 ses_init_buf->trailer.session_req.called_len = 32;
2251 if (server->server_RFC1001_name &&
2252 server->server_RFC1001_name[0] != 0)
2253 rfc1002mangle(ses_init_buf->trailer.
2254 session_req.called_name,
2255 server->server_RFC1001_name,
2256 RFC1001_NAME_LEN_WITH_NULL);
2257 else
2258 rfc1002mangle(ses_init_buf->trailer.
2259 session_req.called_name,
2260 DEFAULT_CIFS_CALLED_NAME,
2261 RFC1001_NAME_LEN_WITH_NULL);
2262
2263 ses_init_buf->trailer.session_req.calling_len = 32;
2264
2265 /* calling name ends in null (byte 16) from old smb
2266 convention. */
2267 if (server->workstation_RFC1001_name &&
2268 server->workstation_RFC1001_name[0] != 0)
2269 rfc1002mangle(ses_init_buf->trailer.
2270 session_req.calling_name,
2271 server->workstation_RFC1001_name,
2272 RFC1001_NAME_LEN_WITH_NULL);
2273 else
2274 rfc1002mangle(ses_init_buf->trailer.
2275 session_req.calling_name,
2276 "LINUX_CIFS_CLNT",
2277 RFC1001_NAME_LEN_WITH_NULL);
2278
2279 ses_init_buf->trailer.session_req.scope1 = 0;
2280 ses_init_buf->trailer.session_req.scope2 = 0;
2281 smb_buf = (struct smb_hdr *)ses_init_buf;
2282 /* sizeof RFC1002_SESSION_REQUEST with no scope */
2283 smb_buf->smb_buf_length = 0x81000044;
2284 rc = smb_send(server, smb_buf, 0x44);
2285 kfree(ses_init_buf);
2286 msleep(1); /* RFC1001 layer in at least one server
2287 requires very short break before negprot
2288 presumably because not expecting negprot
2289 to follow so fast. This is a simple
2290 solution that works without
2291 complicating the code and causes no
2292 significant slowing down on mount
2293 for everyone else */
2294 }
2295 /* else the negprot may still work without this
2296 even though malloc failed */
2297
2298 }
2299 2328
2300 return rc; 2329 return rc;
2301} 2330}
2302 2331
2303static int 2332static int
2304ipv6_connect(struct TCP_Server_Info *server) 2333ip_connect(struct TCP_Server_Info *server)
2305{ 2334{
2306 int rc = 0; 2335 unsigned short int *sport;
2307 int val; 2336 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr;
2308 bool connected = false; 2337 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr;
2309 __be16 orig_port = 0;
2310 struct socket *socket = server->ssocket;
2311 2338
2312 if (socket == NULL) { 2339 if (server->dstaddr.ss_family == AF_INET6)
2313 rc = sock_create_kern(PF_INET6, SOCK_STREAM, 2340 sport = &addr6->sin6_port;
2314 IPPROTO_TCP, &socket); 2341 else
2315 if (rc < 0) { 2342 sport = &addr->sin_port;
2316 cERROR(1, "Error %d creating ipv6 socket", rc);
2317 socket = NULL;
2318 return rc;
2319 }
2320 2343
2321 /* BB other socket options to set KEEPALIVE, NODELAY? */ 2344 if (*sport == 0) {
2322 cFYI(1, "ipv6 Socket created"); 2345 int rc;
2323 server->ssocket = socket;
2324 socket->sk->sk_allocation = GFP_NOFS;
2325 cifs_reclassify_socket6(socket);
2326 }
2327 2346
2328 rc = bind_socket(server); 2347 /* try with 445 port at first */
2329 if (rc < 0) 2348 *sport = htons(CIFS_PORT);
2330 return rc;
2331 2349
2332 /* user overrode default port */ 2350 rc = generic_ip_connect(server);
2333 if (server->addr.sockAddr6.sin6_port) {
2334 rc = socket->ops->connect(socket,
2335 (struct sockaddr *) &server->addr.sockAddr6,
2336 sizeof(struct sockaddr_in6), 0);
2337 if (rc >= 0)
2338 connected = true;
2339 }
2340
2341 if (!connected) {
2342 /* save original port so we can retry user specified port
2343 later if fall back ports fail this time */
2344
2345 orig_port = server->addr.sockAddr6.sin6_port;
2346 /* do not retry on the same port we just failed on */
2347 if (server->addr.sockAddr6.sin6_port != htons(CIFS_PORT)) {
2348 server->addr.sockAddr6.sin6_port = htons(CIFS_PORT);
2349 rc = socket->ops->connect(socket, (struct sockaddr *)
2350 &server->addr.sockAddr6,
2351 sizeof(struct sockaddr_in6), 0);
2352 if (rc >= 0)
2353 connected = true;
2354 }
2355 }
2356 if (!connected) {
2357 server->addr.sockAddr6.sin6_port = htons(RFC1001_PORT);
2358 rc = socket->ops->connect(socket, (struct sockaddr *)
2359 &server->addr.sockAddr6,
2360 sizeof(struct sockaddr_in6), 0);
2361 if (rc >= 0) 2351 if (rc >= 0)
2362 connected = true; 2352 return rc;
2363 }
2364
2365 /* give up here - unless we want to retry on different
2366 protocol families some day */
2367 if (!connected) {
2368 if (orig_port)
2369 server->addr.sockAddr6.sin6_port = orig_port;
2370 cFYI(1, "Error %d connecting to server via ipv6", rc);
2371 sock_release(socket);
2372 server->ssocket = NULL;
2373 return rc;
2374 }
2375
2376 /*
2377 * Eventually check for other socket options to change from
2378 * the default. sock_setsockopt not used because it expects
2379 * user space buffer
2380 */
2381 socket->sk->sk_rcvtimeo = 7 * HZ;
2382 socket->sk->sk_sndtimeo = 5 * HZ;
2383 2353
2384 if (server->tcp_nodelay) { 2354 /* if it failed, try with 139 port */
2385 val = 1; 2355 *sport = htons(RFC1001_PORT);
2386 rc = kernel_setsockopt(socket, SOL_TCP, TCP_NODELAY,
2387 (char *)&val, sizeof(val));
2388 if (rc)
2389 cFYI(1, "set TCP_NODELAY socket option error %d", rc);
2390 } 2356 }
2391 2357
2392 server->ssocket = socket; 2358 return generic_ip_connect(server);
2393
2394 return rc;
2395} 2359}
2396 2360
2397void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon, 2361void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon,
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index db2a58c00f7b..2e773825835e 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -293,10 +293,8 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
293 args.uid = NO_CHANGE_64; 293 args.uid = NO_CHANGE_64;
294 args.gid = NO_CHANGE_64; 294 args.gid = NO_CHANGE_64;
295 } 295 }
296 CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args, 296 CIFSSMBUnixSetFileInfo(xid, tcon, &args, fileHandle,
297 cifs_sb->local_nls, 297 current->tgid);
298 cifs_sb->mnt_cifs_flags &
299 CIFS_MOUNT_MAP_SPECIAL_CHR);
300 } else { 298 } else {
301 /* BB implement mode setting via Windows security 299 /* BB implement mode setting via Windows security
302 descriptors e.g. */ 300 descriptors e.g. */
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 5a28660ca2b5..d843631c028d 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -104,53 +104,6 @@ static inline int cifs_get_disposition(unsigned int flags)
104 return FILE_OPEN; 104 return FILE_OPEN;
105} 105}
106 106
107static inline int cifs_open_inode_helper(struct inode *inode,
108 struct cifsTconInfo *pTcon, __u32 oplock, FILE_ALL_INFO *buf,
109 char *full_path, int xid)
110{
111 struct cifsInodeInfo *pCifsInode = CIFS_I(inode);
112 struct timespec temp;
113 int rc;
114
115 if (pCifsInode->clientCanCacheRead) {
116 /* we have the inode open somewhere else
117 no need to discard cache data */
118 goto client_can_cache;
119 }
120
121 /* BB need same check in cifs_create too? */
122 /* if not oplocked, invalidate inode pages if mtime or file
123 size changed */
124 temp = cifs_NTtimeToUnix(buf->LastWriteTime);
125 if (timespec_equal(&inode->i_mtime, &temp) &&
126 (inode->i_size ==
127 (loff_t)le64_to_cpu(buf->EndOfFile))) {
128 cFYI(1, "inode unchanged on server");
129 } else {
130 if (inode->i_mapping) {
131 /* BB no need to lock inode until after invalidate
132 since namei code should already have it locked? */
133 rc = filemap_write_and_wait(inode->i_mapping);
134 mapping_set_error(inode->i_mapping, rc);
135 }
136 cFYI(1, "invalidating remote inode since open detected it "
137 "changed");
138 invalidate_remote_inode(inode);
139 }
140
141client_can_cache:
142 if (pTcon->unix_ext)
143 rc = cifs_get_inode_info_unix(&inode, full_path, inode->i_sb,
144 xid);
145 else
146 rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb,
147 xid, NULL);
148
149 cifs_set_oplock_level(pCifsInode, oplock);
150
151 return rc;
152}
153
154int cifs_posix_open(char *full_path, struct inode **pinode, 107int cifs_posix_open(char *full_path, struct inode **pinode,
155 struct super_block *sb, int mode, unsigned int f_flags, 108 struct super_block *sb, int mode, unsigned int f_flags,
156 __u32 *poplock, __u16 *pnetfid, int xid) 109 __u32 *poplock, __u16 *pnetfid, int xid)
@@ -213,6 +166,76 @@ posix_open_ret:
213 return rc; 166 return rc;
214} 167}
215 168
169static int
170cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
171 struct cifsTconInfo *tcon, unsigned int f_flags, __u32 *poplock,
172 __u16 *pnetfid, int xid)
173{
174 int rc;
175 int desiredAccess;
176 int disposition;
177 FILE_ALL_INFO *buf;
178
179 desiredAccess = cifs_convert_flags(f_flags);
180
181/*********************************************************************
182 * open flag mapping table:
183 *
184 * POSIX Flag CIFS Disposition
185 * ---------- ----------------
186 * O_CREAT FILE_OPEN_IF
187 * O_CREAT | O_EXCL FILE_CREATE
188 * O_CREAT | O_TRUNC FILE_OVERWRITE_IF
189 * O_TRUNC FILE_OVERWRITE
190 * none of the above FILE_OPEN
191 *
192 * Note that there is not a direct match between disposition
193 * FILE_SUPERSEDE (ie create whether or not file exists although
194 * O_CREAT | O_TRUNC is similar but truncates the existing
195 * file rather than creating a new file as FILE_SUPERSEDE does
196 * (which uses the attributes / metadata passed in on open call)
197 *?
198 *? O_SYNC is a reasonable match to CIFS writethrough flag
199 *? and the read write flags match reasonably. O_LARGEFILE
200 *? is irrelevant because largefile support is always used
201 *? by this client. Flags O_APPEND, O_DIRECT, O_DIRECTORY,
202 * O_FASYNC, O_NOFOLLOW, O_NONBLOCK need further investigation
203 *********************************************************************/
204
205 disposition = cifs_get_disposition(f_flags);
206
207 /* BB pass O_SYNC flag through on file attributes .. BB */
208
209 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
210 if (!buf)
211 return -ENOMEM;
212
213 if (tcon->ses->capabilities & CAP_NT_SMBS)
214 rc = CIFSSMBOpen(xid, tcon, full_path, disposition,
215 desiredAccess, CREATE_NOT_DIR, pnetfid, poplock, buf,
216 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
217 & CIFS_MOUNT_MAP_SPECIAL_CHR);
218 else
219 rc = SMBLegacyOpen(xid, tcon, full_path, disposition,
220 desiredAccess, CREATE_NOT_DIR, pnetfid, poplock, buf,
221 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
222 & CIFS_MOUNT_MAP_SPECIAL_CHR);
223
224 if (rc)
225 goto out;
226
227 if (tcon->unix_ext)
228 rc = cifs_get_inode_info_unix(&inode, full_path, inode->i_sb,
229 xid);
230 else
231 rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb,
232 xid, pnetfid);
233
234out:
235 kfree(buf);
236 return rc;
237}
238
216struct cifsFileInfo * 239struct cifsFileInfo *
217cifs_new_fileinfo(__u16 fileHandle, struct file *file, 240cifs_new_fileinfo(__u16 fileHandle, struct file *file,
218 struct tcon_link *tlink, __u32 oplock) 241 struct tcon_link *tlink, __u32 oplock)
@@ -317,10 +340,8 @@ int cifs_open(struct inode *inode, struct file *file)
317 struct cifsFileInfo *pCifsFile = NULL; 340 struct cifsFileInfo *pCifsFile = NULL;
318 struct cifsInodeInfo *pCifsInode; 341 struct cifsInodeInfo *pCifsInode;
319 char *full_path = NULL; 342 char *full_path = NULL;
320 int desiredAccess; 343 bool posix_open_ok = false;
321 int disposition;
322 __u16 netfid; 344 __u16 netfid;
323 FILE_ALL_INFO *buf = NULL;
324 345
325 xid = GetXid(); 346 xid = GetXid();
326 347
@@ -358,17 +379,7 @@ int cifs_open(struct inode *inode, struct file *file)
358 file->f_flags, &oplock, &netfid, xid); 379 file->f_flags, &oplock, &netfid, xid);
359 if (rc == 0) { 380 if (rc == 0) {
360 cFYI(1, "posix open succeeded"); 381 cFYI(1, "posix open succeeded");
361 382 posix_open_ok = true;
362 pCifsFile = cifs_new_fileinfo(netfid, file, tlink,
363 oplock);
364 if (pCifsFile == NULL) {
365 CIFSSMBClose(xid, tcon, netfid);
366 rc = -ENOMEM;
367 }
368
369 cifs_fscache_set_inode_cookie(inode, file);
370
371 goto out;
372 } else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { 383 } else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
373 if (tcon->ses->serverNOS) 384 if (tcon->ses->serverNOS)
374 cERROR(1, "server %s of type %s returned" 385 cERROR(1, "server %s of type %s returned"
@@ -385,103 +396,39 @@ int cifs_open(struct inode *inode, struct file *file)
385 or DFS errors */ 396 or DFS errors */
386 } 397 }
387 398
388 desiredAccess = cifs_convert_flags(file->f_flags); 399 if (!posix_open_ok) {
389 400 rc = cifs_nt_open(full_path, inode, cifs_sb, tcon,
390/********************************************************************* 401 file->f_flags, &oplock, &netfid, xid);
391 * open flag mapping table: 402 if (rc)
392 * 403 goto out;
393 * POSIX Flag CIFS Disposition
394 * ---------- ----------------
395 * O_CREAT FILE_OPEN_IF
396 * O_CREAT | O_EXCL FILE_CREATE
397 * O_CREAT | O_TRUNC FILE_OVERWRITE_IF
398 * O_TRUNC FILE_OVERWRITE
399 * none of the above FILE_OPEN
400 *
401 * Note that there is not a direct match between disposition
402 * FILE_SUPERSEDE (ie create whether or not file exists although
403 * O_CREAT | O_TRUNC is similar but truncates the existing
404 * file rather than creating a new file as FILE_SUPERSEDE does
405 * (which uses the attributes / metadata passed in on open call)
406 *?
407 *? O_SYNC is a reasonable match to CIFS writethrough flag
408 *? and the read write flags match reasonably. O_LARGEFILE
409 *? is irrelevant because largefile support is always used
410 *? by this client. Flags O_APPEND, O_DIRECT, O_DIRECTORY,
411 * O_FASYNC, O_NOFOLLOW, O_NONBLOCK need further investigation
412 *********************************************************************/
413
414 disposition = cifs_get_disposition(file->f_flags);
415
416 /* BB pass O_SYNC flag through on file attributes .. BB */
417
418 /* Also refresh inode by passing in file_info buf returned by SMBOpen
419 and calling get_inode_info with returned buf (at least helps
420 non-Unix server case) */
421
422 /* BB we can not do this if this is the second open of a file
423 and the first handle has writebehind data, we might be
424 able to simply do a filemap_fdatawrite/filemap_fdatawait first */
425 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
426 if (!buf) {
427 rc = -ENOMEM;
428 goto out;
429 }
430
431 if (tcon->ses->capabilities & CAP_NT_SMBS)
432 rc = CIFSSMBOpen(xid, tcon, full_path, disposition,
433 desiredAccess, CREATE_NOT_DIR, &netfid, &oplock, buf,
434 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
435 & CIFS_MOUNT_MAP_SPECIAL_CHR);
436 else
437 rc = -EIO; /* no NT SMB support fall into legacy open below */
438
439 if (rc == -EIO) {
440 /* Old server, try legacy style OpenX */
441 rc = SMBLegacyOpen(xid, tcon, full_path, disposition,
442 desiredAccess, CREATE_NOT_DIR, &netfid, &oplock, buf,
443 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
444 & CIFS_MOUNT_MAP_SPECIAL_CHR);
445 }
446 if (rc) {
447 cFYI(1, "cifs_open returned 0x%x", rc);
448 goto out;
449 } 404 }
450 405
451 rc = cifs_open_inode_helper(inode, tcon, oplock, buf, full_path, xid);
452 if (rc != 0)
453 goto out;
454
455 pCifsFile = cifs_new_fileinfo(netfid, file, tlink, oplock); 406 pCifsFile = cifs_new_fileinfo(netfid, file, tlink, oplock);
456 if (pCifsFile == NULL) { 407 if (pCifsFile == NULL) {
408 CIFSSMBClose(xid, tcon, netfid);
457 rc = -ENOMEM; 409 rc = -ENOMEM;
458 goto out; 410 goto out;
459 } 411 }
460 412
461 cifs_fscache_set_inode_cookie(inode, file); 413 cifs_fscache_set_inode_cookie(inode, file);
462 414
463 if (oplock & CIFS_CREATE_ACTION) { 415 if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) {
464 /* time to set mode which we can not set earlier due to 416 /* time to set mode which we can not set earlier due to
465 problems creating new read-only files */ 417 problems creating new read-only files */
466 if (tcon->unix_ext) { 418 struct cifs_unix_set_info_args args = {
467 struct cifs_unix_set_info_args args = { 419 .mode = inode->i_mode,
468 .mode = inode->i_mode, 420 .uid = NO_CHANGE_64,
469 .uid = NO_CHANGE_64, 421 .gid = NO_CHANGE_64,
470 .gid = NO_CHANGE_64, 422 .ctime = NO_CHANGE_64,
471 .ctime = NO_CHANGE_64, 423 .atime = NO_CHANGE_64,
472 .atime = NO_CHANGE_64, 424 .mtime = NO_CHANGE_64,
473 .mtime = NO_CHANGE_64, 425 .device = 0,
474 .device = 0, 426 };
475 }; 427 CIFSSMBUnixSetFileInfo(xid, tcon, &args, netfid,
476 CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args, 428 pCifsFile->pid);
477 cifs_sb->local_nls,
478 cifs_sb->mnt_cifs_flags &
479 CIFS_MOUNT_MAP_SPECIAL_CHR);
480 }
481 } 429 }
482 430
483out: 431out:
484 kfree(buf);
485 kfree(full_path); 432 kfree(full_path);
486 FreeXid(xid); 433 FreeXid(xid);
487 cifs_put_tlink(tlink); 434 cifs_put_tlink(tlink);
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index a853a89857a5..0c7e36910e31 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -518,6 +518,7 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
518 518
519 fattr->cf_eof = le64_to_cpu(info->EndOfFile); 519 fattr->cf_eof = le64_to_cpu(info->EndOfFile);
520 fattr->cf_bytes = le64_to_cpu(info->AllocationSize); 520 fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
521 fattr->cf_createtime = le64_to_cpu(info->CreationTime);
521 522
522 if (fattr->cf_cifsattrs & ATTR_DIRECTORY) { 523 if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
523 fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode; 524 fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
@@ -779,6 +780,10 @@ cifs_find_inode(struct inode *inode, void *opaque)
779 if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid) 780 if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
780 return 0; 781 return 0;
781 782
783 /* use createtime like an i_generation field */
784 if (CIFS_I(inode)->createtime != fattr->cf_createtime)
785 return 0;
786
782 /* don't match inode of different type */ 787 /* don't match inode of different type */
783 if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT)) 788 if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT))
784 return 0; 789 return 0;
@@ -796,6 +801,7 @@ cifs_init_inode(struct inode *inode, void *opaque)
796 struct cifs_fattr *fattr = (struct cifs_fattr *) opaque; 801 struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
797 802
798 CIFS_I(inode)->uniqueid = fattr->cf_uniqueid; 803 CIFS_I(inode)->uniqueid = fattr->cf_uniqueid;
804 CIFS_I(inode)->createtime = fattr->cf_createtime;
799 return 0; 805 return 0;
800} 806}
801 807
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index ec5b68e3b928..76b1b37c9e6b 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -160,6 +160,7 @@ cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info,
160 fattr->cf_cifsattrs = le32_to_cpu(info->ExtFileAttributes); 160 fattr->cf_cifsattrs = le32_to_cpu(info->ExtFileAttributes);
161 fattr->cf_eof = le64_to_cpu(info->EndOfFile); 161 fattr->cf_eof = le64_to_cpu(info->EndOfFile);
162 fattr->cf_bytes = le64_to_cpu(info->AllocationSize); 162 fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
163 fattr->cf_createtime = le64_to_cpu(info->CreationTime);
163 fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime); 164 fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
164 fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime); 165 fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);
165 fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime); 166 fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime);
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
index 7b01d3f6eed6..eb746486e49e 100644
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -420,7 +420,6 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
420 return 0; 420 return 0;
421} 421}
422 422
423#ifdef CONFIG_CIFS_EXPERIMENTAL
424/* BB Move to ntlmssp.c eventually */ 423/* BB Move to ntlmssp.c eventually */
425 424
426/* We do not malloc the blob, it is passed in pbuffer, because 425/* We do not malloc the blob, it is passed in pbuffer, because
@@ -431,13 +430,14 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
431 NEGOTIATE_MESSAGE *sec_blob = (NEGOTIATE_MESSAGE *)pbuffer; 430 NEGOTIATE_MESSAGE *sec_blob = (NEGOTIATE_MESSAGE *)pbuffer;
432 __u32 flags; 431 __u32 flags;
433 432
433 memset(pbuffer, 0, sizeof(NEGOTIATE_MESSAGE));
434 memcpy(sec_blob->Signature, NTLMSSP_SIGNATURE, 8); 434 memcpy(sec_blob->Signature, NTLMSSP_SIGNATURE, 8);
435 sec_blob->MessageType = NtLmNegotiate; 435 sec_blob->MessageType = NtLmNegotiate;
436 436
437 /* BB is NTLMV2 session security format easier to use here? */ 437 /* BB is NTLMV2 session security format easier to use here? */
438 flags = NTLMSSP_NEGOTIATE_56 | NTLMSSP_REQUEST_TARGET | 438 flags = NTLMSSP_NEGOTIATE_56 | NTLMSSP_REQUEST_TARGET |
439 NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE | 439 NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
440 NTLMSSP_NEGOTIATE_NTLM; 440 NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC;
441 if (ses->server->secMode & 441 if (ses->server->secMode &
442 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { 442 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) {
443 flags |= NTLMSSP_NEGOTIATE_SIGN; 443 flags |= NTLMSSP_NEGOTIATE_SIGN;
@@ -446,7 +446,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
446 NTLMSSP_NEGOTIATE_EXTENDED_SEC; 446 NTLMSSP_NEGOTIATE_EXTENDED_SEC;
447 } 447 }
448 448
449 sec_blob->NegotiateFlags |= cpu_to_le32(flags); 449 sec_blob->NegotiateFlags = cpu_to_le32(flags);
450 450
451 sec_blob->WorkstationName.BufferOffset = 0; 451 sec_blob->WorkstationName.BufferOffset = 0;
452 sec_blob->WorkstationName.Length = 0; 452 sec_blob->WorkstationName.Length = 0;
@@ -477,7 +477,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
477 flags = NTLMSSP_NEGOTIATE_56 | 477 flags = NTLMSSP_NEGOTIATE_56 |
478 NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_TARGET_INFO | 478 NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_TARGET_INFO |
479 NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE | 479 NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
480 NTLMSSP_NEGOTIATE_NTLM; 480 NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC;
481 if (ses->server->secMode & 481 if (ses->server->secMode &
482 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) 482 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
483 flags |= NTLMSSP_NEGOTIATE_SIGN; 483 flags |= NTLMSSP_NEGOTIATE_SIGN;
@@ -485,7 +485,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
485 flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN; 485 flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
486 486
487 tmp = pbuffer + sizeof(AUTHENTICATE_MESSAGE); 487 tmp = pbuffer + sizeof(AUTHENTICATE_MESSAGE);
488 sec_blob->NegotiateFlags |= cpu_to_le32(flags); 488 sec_blob->NegotiateFlags = cpu_to_le32(flags);
489 489
490 sec_blob->LmChallengeResponse.BufferOffset = 490 sec_blob->LmChallengeResponse.BufferOffset =
491 cpu_to_le32(sizeof(AUTHENTICATE_MESSAGE)); 491 cpu_to_le32(sizeof(AUTHENTICATE_MESSAGE));
@@ -544,8 +544,9 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
544 sec_blob->WorkstationName.MaximumLength = 0; 544 sec_blob->WorkstationName.MaximumLength = 0;
545 tmp += 2; 545 tmp += 2;
546 546
547 if ((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) && 547 if (((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) ||
548 !calc_seckey(ses)) { 548 (ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_EXTENDED_SEC))
549 && !calc_seckey(ses)) {
549 memcpy(tmp, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE); 550 memcpy(tmp, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE);
550 sec_blob->SessionKey.BufferOffset = cpu_to_le32(tmp - pbuffer); 551 sec_blob->SessionKey.BufferOffset = cpu_to_le32(tmp - pbuffer);
551 sec_blob->SessionKey.Length = cpu_to_le16(CIFS_CPHTXT_SIZE); 552 sec_blob->SessionKey.Length = cpu_to_le16(CIFS_CPHTXT_SIZE);
@@ -563,17 +564,6 @@ setup_ntlmv2_ret:
563 return rc; 564 return rc;
564} 565}
565 566
566
567static void setup_ntlmssp_neg_req(SESSION_SETUP_ANDX *pSMB,
568 struct cifsSesInfo *ses)
569{
570 build_ntlmssp_negotiate_blob(&pSMB->req.SecurityBlob[0], ses);
571 pSMB->req.SecurityBlobLength = cpu_to_le16(sizeof(NEGOTIATE_MESSAGE));
572
573 return;
574}
575#endif
576
577int 567int
578CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, 568CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
579 const struct nls_table *nls_cp) 569 const struct nls_table *nls_cp)
@@ -814,71 +804,70 @@ ssetup_ntlmssp_authenticate:
814 rc = -ENOSYS; 804 rc = -ENOSYS;
815 goto ssetup_exit; 805 goto ssetup_exit;
816#endif /* CONFIG_CIFS_UPCALL */ 806#endif /* CONFIG_CIFS_UPCALL */
817 } else { 807 } else if (type == RawNTLMSSP) {
818#ifdef CONFIG_CIFS_EXPERIMENTAL 808 if ((pSMB->req.hdr.Flags2 & SMBFLG2_UNICODE) == 0) {
819 if (type == RawNTLMSSP) { 809 cERROR(1, "NTLMSSP requires Unicode support");
820 if ((pSMB->req.hdr.Flags2 & SMBFLG2_UNICODE) == 0) { 810 rc = -ENOSYS;
821 cERROR(1, "NTLMSSP requires Unicode support"); 811 goto ssetup_exit;
822 rc = -ENOSYS; 812 }
813
814 cFYI(1, "ntlmssp session setup phase %d", phase);
815 pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
816 capabilities |= CAP_EXTENDED_SECURITY;
817 pSMB->req.Capabilities |= cpu_to_le32(capabilities);
818 switch(phase) {
819 case NtLmNegotiate:
820 build_ntlmssp_negotiate_blob(
821 pSMB->req.SecurityBlob, ses);
822 iov[1].iov_len = sizeof(NEGOTIATE_MESSAGE);
823 iov[1].iov_base = pSMB->req.SecurityBlob;
824 pSMB->req.SecurityBlobLength =
825 cpu_to_le16(sizeof(NEGOTIATE_MESSAGE));
826 break;
827 case NtLmAuthenticate:
828 /*
829 * 5 is an empirical value, large enough to hold
830 * authenticate message plus max 10 of av paris,
831 * domain, user, workstation names, flags, etc.
832 */
833 ntlmsspblob = kzalloc(
834 5*sizeof(struct _AUTHENTICATE_MESSAGE),
835 GFP_KERNEL);
836 if (!ntlmsspblob) {
837 cERROR(1, "Can't allocate NTLMSSP blob");
838 rc = -ENOMEM;
823 goto ssetup_exit; 839 goto ssetup_exit;
824 } 840 }
825 841
826 cFYI(1, "ntlmssp session setup phase %d", phase); 842 rc = build_ntlmssp_auth_blob(ntlmsspblob,
827 pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; 843 &blob_len, ses, nls_cp);
828 capabilities |= CAP_EXTENDED_SECURITY; 844 if (rc)
829 pSMB->req.Capabilities |= cpu_to_le32(capabilities);
830 if (phase == NtLmNegotiate) {
831 setup_ntlmssp_neg_req(pSMB, ses);
832 iov[1].iov_len = sizeof(NEGOTIATE_MESSAGE);
833 iov[1].iov_base = &pSMB->req.SecurityBlob[0];
834 } else if (phase == NtLmAuthenticate) {
835 /* 5 is an empirical value, large enought to
836 * hold authenticate message, max 10 of
837 * av paris, doamin,user,workstation mames,
838 * flags etc..
839 */
840 ntlmsspblob = kmalloc(
841 5*sizeof(struct _AUTHENTICATE_MESSAGE),
842 GFP_KERNEL);
843 if (!ntlmsspblob) {
844 cERROR(1, "Can't allocate NTLMSSP");
845 rc = -ENOMEM;
846 goto ssetup_exit;
847 }
848
849 rc = build_ntlmssp_auth_blob(ntlmsspblob,
850 &blob_len, ses, nls_cp);
851 if (rc)
852 goto ssetup_exit;
853 iov[1].iov_len = blob_len;
854 iov[1].iov_base = ntlmsspblob;
855 pSMB->req.SecurityBlobLength =
856 cpu_to_le16(blob_len);
857 /* Make sure that we tell the server that we
858 are using the uid that it just gave us back
859 on the response (challenge) */
860 smb_buf->Uid = ses->Suid;
861 } else {
862 cERROR(1, "invalid phase %d", phase);
863 rc = -ENOSYS;
864 goto ssetup_exit; 845 goto ssetup_exit;
865 } 846 iov[1].iov_len = blob_len;
866 /* unicode strings must be word aligned */ 847 iov[1].iov_base = ntlmsspblob;
867 if ((iov[0].iov_len + iov[1].iov_len) % 2) { 848 pSMB->req.SecurityBlobLength = cpu_to_le16(blob_len);
868 *bcc_ptr = 0; 849 /*
869 bcc_ptr++; 850 * Make sure that we tell the server that we are using
870 } 851 * the uid that it just gave us back on the response
871 unicode_oslm_strings(&bcc_ptr, nls_cp); 852 * (challenge)
872 } else { 853 */
873 cERROR(1, "secType %d not supported!", type); 854 smb_buf->Uid = ses->Suid;
855 break;
856 default:
857 cERROR(1, "invalid phase %d", phase);
874 rc = -ENOSYS; 858 rc = -ENOSYS;
875 goto ssetup_exit; 859 goto ssetup_exit;
876 } 860 }
877#else 861 /* unicode strings must be word aligned */
862 if ((iov[0].iov_len + iov[1].iov_len) % 2) {
863 *bcc_ptr = 0;
864 bcc_ptr++;
865 }
866 unicode_oslm_strings(&bcc_ptr, nls_cp);
867 } else {
878 cERROR(1, "secType %d not supported!", type); 868 cERROR(1, "secType %d not supported!", type);
879 rc = -ENOSYS; 869 rc = -ENOSYS;
880 goto ssetup_exit; 870 goto ssetup_exit;
881#endif
882 } 871 }
883 872
884 iov[2].iov_base = str_area; 873 iov[2].iov_base = str_area;
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index e0588cdf4cc5..59ca81b16919 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -119,7 +119,7 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
119 if (ssocket == NULL) 119 if (ssocket == NULL)
120 return -ENOTSOCK; /* BB eventually add reconnect code here */ 120 return -ENOTSOCK; /* BB eventually add reconnect code here */
121 121
122 smb_msg.msg_name = (struct sockaddr *) &server->addr.sockAddr; 122 smb_msg.msg_name = (struct sockaddr *) &server->dstaddr;
123 smb_msg.msg_namelen = sizeof(struct sockaddr); 123 smb_msg.msg_namelen = sizeof(struct sockaddr);
124 smb_msg.msg_control = NULL; 124 smb_msg.msg_control = NULL;
125 smb_msg.msg_controllen = 0; 125 smb_msg.msg_controllen = 0;
diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index 37a34c2c622a..9c64ae9e4c1a 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -63,6 +63,9 @@
63#define NEEDED_RMEM (4*1024*1024) 63#define NEEDED_RMEM (4*1024*1024)
64#define CONN_HASH_SIZE 32 64#define CONN_HASH_SIZE 32
65 65
66/* Number of messages to send before rescheduling */
67#define MAX_SEND_MSG_COUNT 25
68
66struct cbuf { 69struct cbuf {
67 unsigned int base; 70 unsigned int base;
68 unsigned int len; 71 unsigned int len;
@@ -108,6 +111,7 @@ struct connection {
108#define CF_INIT_PENDING 4 111#define CF_INIT_PENDING 4
109#define CF_IS_OTHERCON 5 112#define CF_IS_OTHERCON 5
110#define CF_CLOSE 6 113#define CF_CLOSE 6
114#define CF_APP_LIMITED 7
111 struct list_head writequeue; /* List of outgoing writequeue_entries */ 115 struct list_head writequeue; /* List of outgoing writequeue_entries */
112 spinlock_t writequeue_lock; 116 spinlock_t writequeue_lock;
113 int (*rx_action) (struct connection *); /* What to do when active */ 117 int (*rx_action) (struct connection *); /* What to do when active */
@@ -295,7 +299,17 @@ static void lowcomms_write_space(struct sock *sk)
295{ 299{
296 struct connection *con = sock2con(sk); 300 struct connection *con = sock2con(sk);
297 301
298 if (con && !test_and_set_bit(CF_WRITE_PENDING, &con->flags)) 302 if (!con)
303 return;
304
305 clear_bit(SOCK_NOSPACE, &con->sock->flags);
306
307 if (test_and_clear_bit(CF_APP_LIMITED, &con->flags)) {
308 con->sock->sk->sk_write_pending--;
309 clear_bit(SOCK_ASYNC_NOSPACE, &con->sock->flags);
310 }
311
312 if (!test_and_set_bit(CF_WRITE_PENDING, &con->flags))
299 queue_work(send_workqueue, &con->swork); 313 queue_work(send_workqueue, &con->swork);
300} 314}
301 315
@@ -915,6 +929,7 @@ static void tcp_connect_to_sock(struct connection *con)
915 struct sockaddr_storage saddr, src_addr; 929 struct sockaddr_storage saddr, src_addr;
916 int addr_len; 930 int addr_len;
917 struct socket *sock = NULL; 931 struct socket *sock = NULL;
932 int one = 1;
918 933
919 if (con->nodeid == 0) { 934 if (con->nodeid == 0) {
920 log_print("attempt to connect sock 0 foiled"); 935 log_print("attempt to connect sock 0 foiled");
@@ -960,6 +975,11 @@ static void tcp_connect_to_sock(struct connection *con)
960 make_sockaddr(&saddr, dlm_config.ci_tcp_port, &addr_len); 975 make_sockaddr(&saddr, dlm_config.ci_tcp_port, &addr_len);
961 976
962 log_print("connecting to %d", con->nodeid); 977 log_print("connecting to %d", con->nodeid);
978
979 /* Turn off Nagle's algorithm */
980 kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY, (char *)&one,
981 sizeof(one));
982
963 result = 983 result =
964 sock->ops->connect(sock, (struct sockaddr *)&saddr, addr_len, 984 sock->ops->connect(sock, (struct sockaddr *)&saddr, addr_len,
965 O_NONBLOCK); 985 O_NONBLOCK);
@@ -1011,6 +1031,10 @@ static struct socket *tcp_create_listen_sock(struct connection *con,
1011 goto create_out; 1031 goto create_out;
1012 } 1032 }
1013 1033
1034 /* Turn off Nagle's algorithm */
1035 kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY, (char *)&one,
1036 sizeof(one));
1037
1014 result = kernel_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, 1038 result = kernel_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
1015 (char *)&one, sizeof(one)); 1039 (char *)&one, sizeof(one));
1016 1040
@@ -1297,6 +1321,7 @@ static void send_to_sock(struct connection *con)
1297 const int msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL; 1321 const int msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL;
1298 struct writequeue_entry *e; 1322 struct writequeue_entry *e;
1299 int len, offset; 1323 int len, offset;
1324 int count = 0;
1300 1325
1301 mutex_lock(&con->sock_mutex); 1326 mutex_lock(&con->sock_mutex);
1302 if (con->sock == NULL) 1327 if (con->sock == NULL)
@@ -1319,14 +1344,27 @@ static void send_to_sock(struct connection *con)
1319 ret = kernel_sendpage(con->sock, e->page, offset, len, 1344 ret = kernel_sendpage(con->sock, e->page, offset, len,
1320 msg_flags); 1345 msg_flags);
1321 if (ret == -EAGAIN || ret == 0) { 1346 if (ret == -EAGAIN || ret == 0) {
1347 if (ret == -EAGAIN &&
1348 test_bit(SOCK_ASYNC_NOSPACE, &con->sock->flags) &&
1349 !test_and_set_bit(CF_APP_LIMITED, &con->flags)) {
1350 /* Notify TCP that we're limited by the
1351 * application window size.
1352 */
1353 set_bit(SOCK_NOSPACE, &con->sock->flags);
1354 con->sock->sk->sk_write_pending++;
1355 }
1322 cond_resched(); 1356 cond_resched();
1323 goto out; 1357 goto out;
1324 } 1358 }
1325 if (ret <= 0) 1359 if (ret <= 0)
1326 goto send_error; 1360 goto send_error;
1327 } 1361 }
1328 /* Don't starve people filling buffers */ 1362
1363 /* Don't starve people filling buffers */
1364 if (++count >= MAX_SEND_MSG_COUNT) {
1329 cond_resched(); 1365 cond_resched();
1366 count = 0;
1367 }
1330 1368
1331 spin_lock(&con->writequeue_lock); 1369 spin_lock(&con->writequeue_lock);
1332 e->offset += ret; 1370 e->offset += ret;
@@ -1430,20 +1468,19 @@ static void work_stop(void)
1430 1468
1431static int work_start(void) 1469static int work_start(void)
1432{ 1470{
1433 int error; 1471 recv_workqueue = alloc_workqueue("dlm_recv", WQ_MEM_RECLAIM |
1434 recv_workqueue = create_workqueue("dlm_recv"); 1472 WQ_HIGHPRI | WQ_FREEZEABLE, 0);
1435 error = IS_ERR(recv_workqueue); 1473 if (!recv_workqueue) {
1436 if (error) { 1474 log_print("can't start dlm_recv");
1437 log_print("can't start dlm_recv %d", error); 1475 return -ENOMEM;
1438 return error;
1439 } 1476 }
1440 1477
1441 send_workqueue = create_singlethread_workqueue("dlm_send"); 1478 send_workqueue = alloc_workqueue("dlm_send", WQ_MEM_RECLAIM |
1442 error = IS_ERR(send_workqueue); 1479 WQ_HIGHPRI | WQ_FREEZEABLE, 0);
1443 if (error) { 1480 if (!send_workqueue) {
1444 log_print("can't start dlm_send %d", error); 1481 log_print("can't start dlm_send");
1445 destroy_workqueue(recv_workqueue); 1482 destroy_workqueue(recv_workqueue);
1446 return error; 1483 return -ENOMEM;
1447 } 1484 }
1448 1485
1449 return 0; 1486 return 0;
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 6e07696308dc..cf8d28d1fbad 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -251,6 +251,20 @@ static void queue_request(struct fuse_conn *fc, struct fuse_req *req)
251 kill_fasync(&fc->fasync, SIGIO, POLL_IN); 251 kill_fasync(&fc->fasync, SIGIO, POLL_IN);
252} 252}
253 253
254void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
255 u64 nodeid, u64 nlookup)
256{
257 forget->forget_one.nodeid = nodeid;
258 forget->forget_one.nlookup = nlookup;
259
260 spin_lock(&fc->lock);
261 fc->forget_list_tail->next = forget;
262 fc->forget_list_tail = forget;
263 wake_up(&fc->waitq);
264 kill_fasync(&fc->fasync, SIGIO, POLL_IN);
265 spin_unlock(&fc->lock);
266}
267
254static void flush_bg_queue(struct fuse_conn *fc) 268static void flush_bg_queue(struct fuse_conn *fc)
255{ 269{
256 while (fc->active_background < fc->max_background && 270 while (fc->active_background < fc->max_background &&
@@ -438,12 +452,6 @@ static void fuse_request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
438 } 452 }
439} 453}
440 454
441void fuse_request_send_noreply(struct fuse_conn *fc, struct fuse_req *req)
442{
443 req->isreply = 0;
444 fuse_request_send_nowait(fc, req);
445}
446
447void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req) 455void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req)
448{ 456{
449 req->isreply = 1; 457 req->isreply = 1;
@@ -896,9 +904,15 @@ static int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs,
896 return err; 904 return err;
897} 905}
898 906
907static int forget_pending(struct fuse_conn *fc)
908{
909 return fc->forget_list_head.next != NULL;
910}
911
899static int request_pending(struct fuse_conn *fc) 912static int request_pending(struct fuse_conn *fc)
900{ 913{
901 return !list_empty(&fc->pending) || !list_empty(&fc->interrupts); 914 return !list_empty(&fc->pending) || !list_empty(&fc->interrupts) ||
915 forget_pending(fc);
902} 916}
903 917
904/* Wait until a request is available on the pending list */ 918/* Wait until a request is available on the pending list */
@@ -960,6 +974,120 @@ __releases(fc->lock)
960 return err ? err : reqsize; 974 return err ? err : reqsize;
961} 975}
962 976
977static struct fuse_forget_link *dequeue_forget(struct fuse_conn *fc,
978 unsigned max,
979 unsigned *countp)
980{
981 struct fuse_forget_link *head = fc->forget_list_head.next;
982 struct fuse_forget_link **newhead = &head;
983 unsigned count;
984
985 for (count = 0; *newhead != NULL && count < max; count++)
986 newhead = &(*newhead)->next;
987
988 fc->forget_list_head.next = *newhead;
989 *newhead = NULL;
990 if (fc->forget_list_head.next == NULL)
991 fc->forget_list_tail = &fc->forget_list_head;
992
993 if (countp != NULL)
994 *countp = count;
995
996 return head;
997}
998
999static int fuse_read_single_forget(struct fuse_conn *fc,
1000 struct fuse_copy_state *cs,
1001 size_t nbytes)
1002__releases(fc->lock)
1003{
1004 int err;
1005 struct fuse_forget_link *forget = dequeue_forget(fc, 1, NULL);
1006 struct fuse_forget_in arg = {
1007 .nlookup = forget->forget_one.nlookup,
1008 };
1009 struct fuse_in_header ih = {
1010 .opcode = FUSE_FORGET,
1011 .nodeid = forget->forget_one.nodeid,
1012 .unique = fuse_get_unique(fc),
1013 .len = sizeof(ih) + sizeof(arg),
1014 };
1015
1016 spin_unlock(&fc->lock);
1017 kfree(forget);
1018 if (nbytes < ih.len)
1019 return -EINVAL;
1020
1021 err = fuse_copy_one(cs, &ih, sizeof(ih));
1022 if (!err)
1023 err = fuse_copy_one(cs, &arg, sizeof(arg));
1024 fuse_copy_finish(cs);
1025
1026 if (err)
1027 return err;
1028
1029 return ih.len;
1030}
1031
1032static int fuse_read_batch_forget(struct fuse_conn *fc,
1033 struct fuse_copy_state *cs, size_t nbytes)
1034__releases(fc->lock)
1035{
1036 int err;
1037 unsigned max_forgets;
1038 unsigned count;
1039 struct fuse_forget_link *head;
1040 struct fuse_batch_forget_in arg = { .count = 0 };
1041 struct fuse_in_header ih = {
1042 .opcode = FUSE_BATCH_FORGET,
1043 .unique = fuse_get_unique(fc),
1044 .len = sizeof(ih) + sizeof(arg),
1045 };
1046
1047 if (nbytes < ih.len) {
1048 spin_unlock(&fc->lock);
1049 return -EINVAL;
1050 }
1051
1052 max_forgets = (nbytes - ih.len) / sizeof(struct fuse_forget_one);
1053 head = dequeue_forget(fc, max_forgets, &count);
1054 spin_unlock(&fc->lock);
1055
1056 arg.count = count;
1057 ih.len += count * sizeof(struct fuse_forget_one);
1058 err = fuse_copy_one(cs, &ih, sizeof(ih));
1059 if (!err)
1060 err = fuse_copy_one(cs, &arg, sizeof(arg));
1061
1062 while (head) {
1063 struct fuse_forget_link *forget = head;
1064
1065 if (!err) {
1066 err = fuse_copy_one(cs, &forget->forget_one,
1067 sizeof(forget->forget_one));
1068 }
1069 head = forget->next;
1070 kfree(forget);
1071 }
1072
1073 fuse_copy_finish(cs);
1074
1075 if (err)
1076 return err;
1077
1078 return ih.len;
1079}
1080
1081static int fuse_read_forget(struct fuse_conn *fc, struct fuse_copy_state *cs,
1082 size_t nbytes)
1083__releases(fc->lock)
1084{
1085 if (fc->minor < 16 || fc->forget_list_head.next->next == NULL)
1086 return fuse_read_single_forget(fc, cs, nbytes);
1087 else
1088 return fuse_read_batch_forget(fc, cs, nbytes);
1089}
1090
963/* 1091/*
964 * Read a single request into the userspace filesystem's buffer. This 1092 * Read a single request into the userspace filesystem's buffer. This
965 * function waits until a request is available, then removes it from 1093 * function waits until a request is available, then removes it from
@@ -998,6 +1126,14 @@ static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
998 return fuse_read_interrupt(fc, cs, nbytes, req); 1126 return fuse_read_interrupt(fc, cs, nbytes, req);
999 } 1127 }
1000 1128
1129 if (forget_pending(fc)) {
1130 if (list_empty(&fc->pending) || fc->forget_batch-- > 0)
1131 return fuse_read_forget(fc, cs, nbytes);
1132
1133 if (fc->forget_batch <= -8)
1134 fc->forget_batch = 16;
1135 }
1136
1001 req = list_entry(fc->pending.next, struct fuse_req, list); 1137 req = list_entry(fc->pending.next, struct fuse_req, list);
1002 req->state = FUSE_REQ_READING; 1138 req->state = FUSE_REQ_READING;
1003 list_move(&req->list, &fc->io); 1139 list_move(&req->list, &fc->io);
@@ -1090,7 +1226,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
1090 if (!fc) 1226 if (!fc)
1091 return -EPERM; 1227 return -EPERM;
1092 1228
1093 bufs = kmalloc(pipe->buffers * sizeof (struct pipe_buffer), GFP_KERNEL); 1229 bufs = kmalloc(pipe->buffers * sizeof(struct pipe_buffer), GFP_KERNEL);
1094 if (!bufs) 1230 if (!bufs)
1095 return -ENOMEM; 1231 return -ENOMEM;
1096 1232
@@ -1626,7 +1762,7 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
1626 if (!fc) 1762 if (!fc)
1627 return -EPERM; 1763 return -EPERM;
1628 1764
1629 bufs = kmalloc(pipe->buffers * sizeof (struct pipe_buffer), GFP_KERNEL); 1765 bufs = kmalloc(pipe->buffers * sizeof(struct pipe_buffer), GFP_KERNEL);
1630 if (!bufs) 1766 if (!bufs)
1631 return -ENOMEM; 1767 return -ENOMEM;
1632 1768
@@ -1770,6 +1906,8 @@ __acquires(fc->lock)
1770 flush_bg_queue(fc); 1906 flush_bg_queue(fc);
1771 end_requests(fc, &fc->pending); 1907 end_requests(fc, &fc->pending);
1772 end_requests(fc, &fc->processing); 1908 end_requests(fc, &fc->processing);
1909 while (forget_pending(fc))
1910 kfree(dequeue_forget(fc, 1, NULL));
1773} 1911}
1774 1912
1775/* 1913/*
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index f738599fd8cd..042af7346ec1 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -10,9 +10,9 @@
10 10
11#include <linux/pagemap.h> 11#include <linux/pagemap.h>
12#include <linux/file.h> 12#include <linux/file.h>
13#include <linux/gfp.h>
14#include <linux/sched.h> 13#include <linux/sched.h>
15#include <linux/namei.h> 14#include <linux/namei.h>
15#include <linux/slab.h>
16 16
17#if BITS_PER_LONG >= 64 17#if BITS_PER_LONG >= 64
18static inline void fuse_dentry_settime(struct dentry *entry, u64 time) 18static inline void fuse_dentry_settime(struct dentry *entry, u64 time)
@@ -169,7 +169,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
169 struct fuse_entry_out outarg; 169 struct fuse_entry_out outarg;
170 struct fuse_conn *fc; 170 struct fuse_conn *fc;
171 struct fuse_req *req; 171 struct fuse_req *req;
172 struct fuse_req *forget_req; 172 struct fuse_forget_link *forget;
173 struct dentry *parent; 173 struct dentry *parent;
174 u64 attr_version; 174 u64 attr_version;
175 175
@@ -182,8 +182,8 @@ static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
182 if (IS_ERR(req)) 182 if (IS_ERR(req))
183 return 0; 183 return 0;
184 184
185 forget_req = fuse_get_req(fc); 185 forget = fuse_alloc_forget();
186 if (IS_ERR(forget_req)) { 186 if (!forget) {
187 fuse_put_request(fc, req); 187 fuse_put_request(fc, req);
188 return 0; 188 return 0;
189 } 189 }
@@ -203,15 +203,14 @@ static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
203 if (!err) { 203 if (!err) {
204 struct fuse_inode *fi = get_fuse_inode(inode); 204 struct fuse_inode *fi = get_fuse_inode(inode);
205 if (outarg.nodeid != get_node_id(inode)) { 205 if (outarg.nodeid != get_node_id(inode)) {
206 fuse_send_forget(fc, forget_req, 206 fuse_queue_forget(fc, forget, outarg.nodeid, 1);
207 outarg.nodeid, 1);
208 return 0; 207 return 0;
209 } 208 }
210 spin_lock(&fc->lock); 209 spin_lock(&fc->lock);
211 fi->nlookup++; 210 fi->nlookup++;
212 spin_unlock(&fc->lock); 211 spin_unlock(&fc->lock);
213 } 212 }
214 fuse_put_request(fc, forget_req); 213 kfree(forget);
215 if (err || (outarg.attr.mode ^ inode->i_mode) & S_IFMT) 214 if (err || (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
216 return 0; 215 return 0;
217 216
@@ -263,7 +262,7 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
263{ 262{
264 struct fuse_conn *fc = get_fuse_conn_super(sb); 263 struct fuse_conn *fc = get_fuse_conn_super(sb);
265 struct fuse_req *req; 264 struct fuse_req *req;
266 struct fuse_req *forget_req; 265 struct fuse_forget_link *forget;
267 u64 attr_version; 266 u64 attr_version;
268 int err; 267 int err;
269 268
@@ -277,9 +276,9 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
277 if (IS_ERR(req)) 276 if (IS_ERR(req))
278 goto out; 277 goto out;
279 278
280 forget_req = fuse_get_req(fc); 279 forget = fuse_alloc_forget();
281 err = PTR_ERR(forget_req); 280 err = -ENOMEM;
282 if (IS_ERR(forget_req)) { 281 if (!forget) {
283 fuse_put_request(fc, req); 282 fuse_put_request(fc, req);
284 goto out; 283 goto out;
285 } 284 }
@@ -305,13 +304,13 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
305 attr_version); 304 attr_version);
306 err = -ENOMEM; 305 err = -ENOMEM;
307 if (!*inode) { 306 if (!*inode) {
308 fuse_send_forget(fc, forget_req, outarg->nodeid, 1); 307 fuse_queue_forget(fc, forget, outarg->nodeid, 1);
309 goto out; 308 goto out;
310 } 309 }
311 err = 0; 310 err = 0;
312 311
313 out_put_forget: 312 out_put_forget:
314 fuse_put_request(fc, forget_req); 313 kfree(forget);
315 out: 314 out:
316 return err; 315 return err;
317} 316}
@@ -378,7 +377,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
378 struct inode *inode; 377 struct inode *inode;
379 struct fuse_conn *fc = get_fuse_conn(dir); 378 struct fuse_conn *fc = get_fuse_conn(dir);
380 struct fuse_req *req; 379 struct fuse_req *req;
381 struct fuse_req *forget_req; 380 struct fuse_forget_link *forget;
382 struct fuse_create_in inarg; 381 struct fuse_create_in inarg;
383 struct fuse_open_out outopen; 382 struct fuse_open_out outopen;
384 struct fuse_entry_out outentry; 383 struct fuse_entry_out outentry;
@@ -392,9 +391,9 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
392 if (flags & O_DIRECT) 391 if (flags & O_DIRECT)
393 return -EINVAL; 392 return -EINVAL;
394 393
395 forget_req = fuse_get_req(fc); 394 forget = fuse_alloc_forget();
396 if (IS_ERR(forget_req)) 395 if (!forget)
397 return PTR_ERR(forget_req); 396 return -ENOMEM;
398 397
399 req = fuse_get_req(fc); 398 req = fuse_get_req(fc);
400 err = PTR_ERR(req); 399 err = PTR_ERR(req);
@@ -452,10 +451,10 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
452 if (!inode) { 451 if (!inode) {
453 flags &= ~(O_CREAT | O_EXCL | O_TRUNC); 452 flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
454 fuse_sync_release(ff, flags); 453 fuse_sync_release(ff, flags);
455 fuse_send_forget(fc, forget_req, outentry.nodeid, 1); 454 fuse_queue_forget(fc, forget, outentry.nodeid, 1);
456 return -ENOMEM; 455 return -ENOMEM;
457 } 456 }
458 fuse_put_request(fc, forget_req); 457 kfree(forget);
459 d_instantiate(entry, inode); 458 d_instantiate(entry, inode);
460 fuse_change_entry_timeout(entry, &outentry); 459 fuse_change_entry_timeout(entry, &outentry);
461 fuse_invalidate_attr(dir); 460 fuse_invalidate_attr(dir);
@@ -473,7 +472,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
473 out_put_request: 472 out_put_request:
474 fuse_put_request(fc, req); 473 fuse_put_request(fc, req);
475 out_put_forget_req: 474 out_put_forget_req:
476 fuse_put_request(fc, forget_req); 475 kfree(forget);
477 return err; 476 return err;
478} 477}
479 478
@@ -487,12 +486,12 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
487 struct fuse_entry_out outarg; 486 struct fuse_entry_out outarg;
488 struct inode *inode; 487 struct inode *inode;
489 int err; 488 int err;
490 struct fuse_req *forget_req; 489 struct fuse_forget_link *forget;
491 490
492 forget_req = fuse_get_req(fc); 491 forget = fuse_alloc_forget();
493 if (IS_ERR(forget_req)) { 492 if (!forget) {
494 fuse_put_request(fc, req); 493 fuse_put_request(fc, req);
495 return PTR_ERR(forget_req); 494 return -ENOMEM;
496 } 495 }
497 496
498 memset(&outarg, 0, sizeof(outarg)); 497 memset(&outarg, 0, sizeof(outarg));
@@ -519,10 +518,10 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
519 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, 518 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
520 &outarg.attr, entry_attr_timeout(&outarg), 0); 519 &outarg.attr, entry_attr_timeout(&outarg), 0);
521 if (!inode) { 520 if (!inode) {
522 fuse_send_forget(fc, forget_req, outarg.nodeid, 1); 521 fuse_queue_forget(fc, forget, outarg.nodeid, 1);
523 return -ENOMEM; 522 return -ENOMEM;
524 } 523 }
525 fuse_put_request(fc, forget_req); 524 kfree(forget);
526 525
527 if (S_ISDIR(inode->i_mode)) { 526 if (S_ISDIR(inode->i_mode)) {
528 struct dentry *alias; 527 struct dentry *alias;
@@ -545,7 +544,7 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
545 return 0; 544 return 0;
546 545
547 out_put_forget_req: 546 out_put_forget_req:
548 fuse_put_request(fc, forget_req); 547 kfree(forget);
549 return err; 548 return err;
550} 549}
551 550
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 8b984a2cebbd..95da1bc1c826 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1634,9 +1634,9 @@ static int fuse_ioctl_copy_user(struct page **pages, struct iovec *iov,
1634 * and 64bit. Fortunately we can determine which structure the server 1634 * and 64bit. Fortunately we can determine which structure the server
1635 * used from the size of the reply. 1635 * used from the size of the reply.
1636 */ 1636 */
1637static int fuse_copy_ioctl_iovec(struct iovec *dst, void *src, 1637static int fuse_copy_ioctl_iovec_old(struct iovec *dst, void *src,
1638 size_t transferred, unsigned count, 1638 size_t transferred, unsigned count,
1639 bool is_compat) 1639 bool is_compat)
1640{ 1640{
1641#ifdef CONFIG_COMPAT 1641#ifdef CONFIG_COMPAT
1642 if (count * sizeof(struct compat_iovec) == transferred) { 1642 if (count * sizeof(struct compat_iovec) == transferred) {
@@ -1680,6 +1680,42 @@ static int fuse_verify_ioctl_iov(struct iovec *iov, size_t count)
1680 return 0; 1680 return 0;
1681} 1681}
1682 1682
1683static int fuse_copy_ioctl_iovec(struct fuse_conn *fc, struct iovec *dst,
1684 void *src, size_t transferred, unsigned count,
1685 bool is_compat)
1686{
1687 unsigned i;
1688 struct fuse_ioctl_iovec *fiov = src;
1689
1690 if (fc->minor < 16) {
1691 return fuse_copy_ioctl_iovec_old(dst, src, transferred,
1692 count, is_compat);
1693 }
1694
1695 if (count * sizeof(struct fuse_ioctl_iovec) != transferred)
1696 return -EIO;
1697
1698 for (i = 0; i < count; i++) {
1699 /* Did the server supply an inappropriate value? */
1700 if (fiov[i].base != (unsigned long) fiov[i].base ||
1701 fiov[i].len != (unsigned long) fiov[i].len)
1702 return -EIO;
1703
1704 dst[i].iov_base = (void __user *) (unsigned long) fiov[i].base;
1705 dst[i].iov_len = (size_t) fiov[i].len;
1706
1707#ifdef CONFIG_COMPAT
1708 if (is_compat &&
1709 (ptr_to_compat(dst[i].iov_base) != fiov[i].base ||
1710 (compat_size_t) dst[i].iov_len != fiov[i].len))
1711 return -EIO;
1712#endif
1713 }
1714
1715 return 0;
1716}
1717
1718
1683/* 1719/*
1684 * For ioctls, there is no generic way to determine how much memory 1720 * For ioctls, there is no generic way to determine how much memory
1685 * needs to be read and/or written. Furthermore, ioctls are allowed 1721 * needs to be read and/or written. Furthermore, ioctls are allowed
@@ -1740,18 +1776,25 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1740 struct fuse_ioctl_out outarg; 1776 struct fuse_ioctl_out outarg;
1741 struct fuse_req *req = NULL; 1777 struct fuse_req *req = NULL;
1742 struct page **pages = NULL; 1778 struct page **pages = NULL;
1743 struct page *iov_page = NULL; 1779 struct iovec *iov_page = NULL;
1744 struct iovec *in_iov = NULL, *out_iov = NULL; 1780 struct iovec *in_iov = NULL, *out_iov = NULL;
1745 unsigned int in_iovs = 0, out_iovs = 0, num_pages = 0, max_pages; 1781 unsigned int in_iovs = 0, out_iovs = 0, num_pages = 0, max_pages;
1746 size_t in_size, out_size, transferred; 1782 size_t in_size, out_size, transferred;
1747 int err; 1783 int err;
1748 1784
1785#if BITS_PER_LONG == 32
1786 inarg.flags |= FUSE_IOCTL_32BIT;
1787#else
1788 if (flags & FUSE_IOCTL_COMPAT)
1789 inarg.flags |= FUSE_IOCTL_32BIT;
1790#endif
1791
1749 /* assume all the iovs returned by client always fits in a page */ 1792 /* assume all the iovs returned by client always fits in a page */
1750 BUILD_BUG_ON(sizeof(struct iovec) * FUSE_IOCTL_MAX_IOV > PAGE_SIZE); 1793 BUILD_BUG_ON(sizeof(struct fuse_ioctl_iovec) * FUSE_IOCTL_MAX_IOV > PAGE_SIZE);
1751 1794
1752 err = -ENOMEM; 1795 err = -ENOMEM;
1753 pages = kzalloc(sizeof(pages[0]) * FUSE_MAX_PAGES_PER_REQ, GFP_KERNEL); 1796 pages = kzalloc(sizeof(pages[0]) * FUSE_MAX_PAGES_PER_REQ, GFP_KERNEL);
1754 iov_page = alloc_page(GFP_KERNEL); 1797 iov_page = (struct iovec *) __get_free_page(GFP_KERNEL);
1755 if (!pages || !iov_page) 1798 if (!pages || !iov_page)
1756 goto out; 1799 goto out;
1757 1800
@@ -1760,7 +1803,7 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1760 * RETRY from server is not allowed. 1803 * RETRY from server is not allowed.
1761 */ 1804 */
1762 if (!(flags & FUSE_IOCTL_UNRESTRICTED)) { 1805 if (!(flags & FUSE_IOCTL_UNRESTRICTED)) {
1763 struct iovec *iov = page_address(iov_page); 1806 struct iovec *iov = iov_page;
1764 1807
1765 iov->iov_base = (void __user *)arg; 1808 iov->iov_base = (void __user *)arg;
1766 iov->iov_len = _IOC_SIZE(cmd); 1809 iov->iov_len = _IOC_SIZE(cmd);
@@ -1841,7 +1884,7 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1841 1884
1842 /* did it ask for retry? */ 1885 /* did it ask for retry? */
1843 if (outarg.flags & FUSE_IOCTL_RETRY) { 1886 if (outarg.flags & FUSE_IOCTL_RETRY) {
1844 char *vaddr; 1887 void *vaddr;
1845 1888
1846 /* no retry if in restricted mode */ 1889 /* no retry if in restricted mode */
1847 err = -EIO; 1890 err = -EIO;
@@ -1862,14 +1905,14 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1862 goto out; 1905 goto out;
1863 1906
1864 vaddr = kmap_atomic(pages[0], KM_USER0); 1907 vaddr = kmap_atomic(pages[0], KM_USER0);
1865 err = fuse_copy_ioctl_iovec(page_address(iov_page), vaddr, 1908 err = fuse_copy_ioctl_iovec(fc, iov_page, vaddr,
1866 transferred, in_iovs + out_iovs, 1909 transferred, in_iovs + out_iovs,
1867 (flags & FUSE_IOCTL_COMPAT) != 0); 1910 (flags & FUSE_IOCTL_COMPAT) != 0);
1868 kunmap_atomic(vaddr, KM_USER0); 1911 kunmap_atomic(vaddr, KM_USER0);
1869 if (err) 1912 if (err)
1870 goto out; 1913 goto out;
1871 1914
1872 in_iov = page_address(iov_page); 1915 in_iov = iov_page;
1873 out_iov = in_iov + in_iovs; 1916 out_iov = in_iov + in_iovs;
1874 1917
1875 err = fuse_verify_ioctl_iov(in_iov, in_iovs); 1918 err = fuse_verify_ioctl_iov(in_iov, in_iovs);
@@ -1891,8 +1934,7 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1891 out: 1934 out:
1892 if (req) 1935 if (req)
1893 fuse_put_request(fc, req); 1936 fuse_put_request(fc, req);
1894 if (iov_page) 1937 free_page((unsigned long) iov_page);
1895 __free_page(iov_page);
1896 while (num_pages) 1938 while (num_pages)
1897 __free_page(pages[--num_pages]); 1939 __free_page(pages[--num_pages]);
1898 kfree(pages); 1940 kfree(pages);
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 57d4a3a0f102..ae5744a2f9e9 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -53,6 +53,12 @@ extern struct mutex fuse_mutex;
53extern unsigned max_user_bgreq; 53extern unsigned max_user_bgreq;
54extern unsigned max_user_congthresh; 54extern unsigned max_user_congthresh;
55 55
56/* One forget request */
57struct fuse_forget_link {
58 struct fuse_forget_one forget_one;
59 struct fuse_forget_link *next;
60};
61
56/** FUSE inode */ 62/** FUSE inode */
57struct fuse_inode { 63struct fuse_inode {
58 /** Inode data */ 64 /** Inode data */
@@ -66,7 +72,7 @@ struct fuse_inode {
66 u64 nlookup; 72 u64 nlookup;
67 73
68 /** The request used for sending the FORGET message */ 74 /** The request used for sending the FORGET message */
69 struct fuse_req *forget_req; 75 struct fuse_forget_link *forget;
70 76
71 /** Time in jiffies until the file attributes are valid */ 77 /** Time in jiffies until the file attributes are valid */
72 u64 i_time; 78 u64 i_time;
@@ -255,7 +261,6 @@ struct fuse_req {
255 261
256 /** Data for asynchronous requests */ 262 /** Data for asynchronous requests */
257 union { 263 union {
258 struct fuse_forget_in forget_in;
259 struct { 264 struct {
260 struct fuse_release_in in; 265 struct fuse_release_in in;
261 struct path path; 266 struct path path;
@@ -369,6 +374,13 @@ struct fuse_conn {
369 /** Pending interrupts */ 374 /** Pending interrupts */
370 struct list_head interrupts; 375 struct list_head interrupts;
371 376
377 /** Queue of pending forgets */
378 struct fuse_forget_link forget_list_head;
379 struct fuse_forget_link *forget_list_tail;
380
381 /** Batching of FORGET requests (positive indicates FORGET batch) */
382 int forget_batch;
383
372 /** Flag indicating if connection is blocked. This will be 384 /** Flag indicating if connection is blocked. This will be
373 the case before the INIT reply is received, and if there 385 the case before the INIT reply is received, and if there
374 are too many outstading backgrounds requests */ 386 are too many outstading backgrounds requests */
@@ -543,8 +555,10 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
543/** 555/**
544 * Send FORGET command 556 * Send FORGET command
545 */ 557 */
546void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, 558void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
547 u64 nodeid, u64 nlookup); 559 u64 nodeid, u64 nlookup);
560
561struct fuse_forget_link *fuse_alloc_forget(void);
548 562
549/** 563/**
550 * Initialize READ or READDIR request 564 * Initialize READ or READDIR request
@@ -656,11 +670,6 @@ void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
656void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req); 670void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req);
657 671
658/** 672/**
659 * Send a request with no reply
660 */
661void fuse_request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
662
663/**
664 * Send a request in the background 673 * Send a request in the background
665 */ 674 */
666void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); 675void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index a8b31da19b93..f62b32cffea9 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -71,6 +71,11 @@ struct fuse_mount_data {
71 unsigned blksize; 71 unsigned blksize;
72}; 72};
73 73
74struct fuse_forget_link *fuse_alloc_forget()
75{
76 return kzalloc(sizeof(struct fuse_forget_link), GFP_KERNEL);
77}
78
74static struct inode *fuse_alloc_inode(struct super_block *sb) 79static struct inode *fuse_alloc_inode(struct super_block *sb)
75{ 80{
76 struct inode *inode; 81 struct inode *inode;
@@ -90,8 +95,8 @@ static struct inode *fuse_alloc_inode(struct super_block *sb)
90 INIT_LIST_HEAD(&fi->queued_writes); 95 INIT_LIST_HEAD(&fi->queued_writes);
91 INIT_LIST_HEAD(&fi->writepages); 96 INIT_LIST_HEAD(&fi->writepages);
92 init_waitqueue_head(&fi->page_waitq); 97 init_waitqueue_head(&fi->page_waitq);
93 fi->forget_req = fuse_request_alloc(); 98 fi->forget = fuse_alloc_forget();
94 if (!fi->forget_req) { 99 if (!fi->forget) {
95 kmem_cache_free(fuse_inode_cachep, inode); 100 kmem_cache_free(fuse_inode_cachep, inode);
96 return NULL; 101 return NULL;
97 } 102 }
@@ -111,24 +116,10 @@ static void fuse_destroy_inode(struct inode *inode)
111 struct fuse_inode *fi = get_fuse_inode(inode); 116 struct fuse_inode *fi = get_fuse_inode(inode);
112 BUG_ON(!list_empty(&fi->write_files)); 117 BUG_ON(!list_empty(&fi->write_files));
113 BUG_ON(!list_empty(&fi->queued_writes)); 118 BUG_ON(!list_empty(&fi->queued_writes));
114 if (fi->forget_req) 119 kfree(fi->forget);
115 fuse_request_free(fi->forget_req);
116 call_rcu(&inode->i_rcu, fuse_i_callback); 120 call_rcu(&inode->i_rcu, fuse_i_callback);
117} 121}
118 122
119void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
120 u64 nodeid, u64 nlookup)
121{
122 struct fuse_forget_in *inarg = &req->misc.forget_in;
123 inarg->nlookup = nlookup;
124 req->in.h.opcode = FUSE_FORGET;
125 req->in.h.nodeid = nodeid;
126 req->in.numargs = 1;
127 req->in.args[0].size = sizeof(struct fuse_forget_in);
128 req->in.args[0].value = inarg;
129 fuse_request_send_noreply(fc, req);
130}
131
132static void fuse_evict_inode(struct inode *inode) 123static void fuse_evict_inode(struct inode *inode)
133{ 124{
134 truncate_inode_pages(&inode->i_data, 0); 125 truncate_inode_pages(&inode->i_data, 0);
@@ -136,8 +127,8 @@ static void fuse_evict_inode(struct inode *inode)
136 if (inode->i_sb->s_flags & MS_ACTIVE) { 127 if (inode->i_sb->s_flags & MS_ACTIVE) {
137 struct fuse_conn *fc = get_fuse_conn(inode); 128 struct fuse_conn *fc = get_fuse_conn(inode);
138 struct fuse_inode *fi = get_fuse_inode(inode); 129 struct fuse_inode *fi = get_fuse_inode(inode);
139 fuse_send_forget(fc, fi->forget_req, fi->nodeid, fi->nlookup); 130 fuse_queue_forget(fc, fi->forget, fi->nodeid, fi->nlookup);
140 fi->forget_req = NULL; 131 fi->forget = NULL;
141 } 132 }
142} 133}
143 134
@@ -541,6 +532,7 @@ void fuse_conn_init(struct fuse_conn *fc)
541 INIT_LIST_HEAD(&fc->interrupts); 532 INIT_LIST_HEAD(&fc->interrupts);
542 INIT_LIST_HEAD(&fc->bg_queue); 533 INIT_LIST_HEAD(&fc->bg_queue);
543 INIT_LIST_HEAD(&fc->entry); 534 INIT_LIST_HEAD(&fc->entry);
535 fc->forget_list_tail = &fc->forget_list_head;
544 atomic_set(&fc->num_waiting, 0); 536 atomic_set(&fc->num_waiting, 0);
545 fc->max_background = FUSE_DEFAULT_MAX_BACKGROUND; 537 fc->max_background = FUSE_DEFAULT_MAX_BACKGROUND;
546 fc->congestion_threshold = FUSE_DEFAULT_CONGESTION_THRESHOLD; 538 fc->congestion_threshold = FUSE_DEFAULT_CONGESTION_THRESHOLD;
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 8d3d2b4a0a7d..a79790c06275 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -11,6 +11,7 @@
11#define __INCORE_DOT_H__ 11#define __INCORE_DOT_H__
12 12
13#include <linux/fs.h> 13#include <linux/fs.h>
14#include <linux/kobject.h>
14#include <linux/workqueue.h> 15#include <linux/workqueue.h>
15#include <linux/dlm.h> 16#include <linux/dlm.h>
16#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
diff --git a/fs/namei.c b/fs/namei.c
index 19433cdba011..24ece10470b6 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -202,7 +202,7 @@ static int acl_permission_check(struct inode *inode, int mask, unsigned int flag
202 * @inode: inode to check access rights for 202 * @inode: inode to check access rights for
203 * @mask: right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC) 203 * @mask: right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC)
204 * @check_acl: optional callback to check for Posix ACLs 204 * @check_acl: optional callback to check for Posix ACLs
205 * @flags IPERM_FLAG_ flags. 205 * @flags: IPERM_FLAG_ flags.
206 * 206 *
207 * Used to check for read/write/execute permissions on a file. 207 * Used to check for read/write/execute permissions on a file.
208 * We use "fsuid" for this, letting us set arbitrary permissions 208 * We use "fsuid" for this, letting us set arbitrary permissions
@@ -407,7 +407,7 @@ void path_put_long(struct path *path)
407/** 407/**
408 * nameidata_drop_rcu - drop this nameidata out of rcu-walk 408 * nameidata_drop_rcu - drop this nameidata out of rcu-walk
409 * @nd: nameidata pathwalk data to drop 409 * @nd: nameidata pathwalk data to drop
410 * @Returns: 0 on success, -ECHLID on failure 410 * Returns: 0 on success, -ECHILD on failure
411 * 411 *
412 * Path walking has 2 modes, rcu-walk and ref-walk (see 412 * Path walking has 2 modes, rcu-walk and ref-walk (see
413 * Documentation/filesystems/path-lookup.txt). __drop_rcu* functions attempt 413 * Documentation/filesystems/path-lookup.txt). __drop_rcu* functions attempt
@@ -468,7 +468,7 @@ static inline int nameidata_drop_rcu_maybe(struct nameidata *nd)
468 * nameidata_dentry_drop_rcu - drop nameidata and dentry out of rcu-walk 468 * nameidata_dentry_drop_rcu - drop nameidata and dentry out of rcu-walk
469 * @nd: nameidata pathwalk data to drop 469 * @nd: nameidata pathwalk data to drop
470 * @dentry: dentry to drop 470 * @dentry: dentry to drop
471 * @Returns: 0 on success, -ECHLID on failure 471 * Returns: 0 on success, -ECHILD on failure
472 * 472 *
473 * nameidata_dentry_drop_rcu attempts to drop the current nd->path and nd->root, 473 * nameidata_dentry_drop_rcu attempts to drop the current nd->path and nd->root,
474 * and dentry into ref-walk. @dentry must be a path found by a do_lookup call on 474 * and dentry into ref-walk. @dentry must be a path found by a do_lookup call on
@@ -530,7 +530,7 @@ static inline int nameidata_dentry_drop_rcu_maybe(struct nameidata *nd, struct d
530/** 530/**
531 * nameidata_drop_rcu_last - drop nameidata ending path walk out of rcu-walk 531 * nameidata_drop_rcu_last - drop nameidata ending path walk out of rcu-walk
532 * @nd: nameidata pathwalk data to drop 532 * @nd: nameidata pathwalk data to drop
533 * @Returns: 0 on success, -ECHLID on failure 533 * Returns: 0 on success, -ECHILD on failure
534 * 534 *
535 * nameidata_drop_rcu_last attempts to drop the current nd->path into ref-walk. 535 * nameidata_drop_rcu_last attempts to drop the current nd->path into ref-walk.
536 * nd->path should be the final element of the lookup, so nd->root is discarded. 536 * nd->path should be the final element of the lookup, so nd->root is discarded.
diff --git a/fs/nilfs2/bmap.c b/fs/nilfs2/bmap.c
index 8b782b062baa..3ee67c67cc52 100644
--- a/fs/nilfs2/bmap.c
+++ b/fs/nilfs2/bmap.c
@@ -35,7 +35,20 @@
35 35
36struct inode *nilfs_bmap_get_dat(const struct nilfs_bmap *bmap) 36struct inode *nilfs_bmap_get_dat(const struct nilfs_bmap *bmap)
37{ 37{
38 return nilfs_dat_inode(NILFS_I_NILFS(bmap->b_inode)); 38 return NILFS_I_NILFS(bmap->b_inode)->ns_dat;
39}
40
41static int nilfs_bmap_convert_error(struct nilfs_bmap *bmap,
42 const char *fname, int err)
43{
44 struct inode *inode = bmap->b_inode;
45
46 if (err == -EINVAL) {
47 nilfs_error(inode->i_sb, fname,
48 "broken bmap (inode number=%lu)\n", inode->i_ino);
49 err = -EIO;
50 }
51 return err;
39} 52}
40 53
41/** 54/**
@@ -66,8 +79,10 @@ int nilfs_bmap_lookup_at_level(struct nilfs_bmap *bmap, __u64 key, int level,
66 79
67 down_read(&bmap->b_sem); 80 down_read(&bmap->b_sem);
68 ret = bmap->b_ops->bop_lookup(bmap, key, level, ptrp); 81 ret = bmap->b_ops->bop_lookup(bmap, key, level, ptrp);
69 if (ret < 0) 82 if (ret < 0) {
83 ret = nilfs_bmap_convert_error(bmap, __func__, ret);
70 goto out; 84 goto out;
85 }
71 if (NILFS_BMAP_USE_VBN(bmap)) { 86 if (NILFS_BMAP_USE_VBN(bmap)) {
72 ret = nilfs_dat_translate(nilfs_bmap_get_dat(bmap), *ptrp, 87 ret = nilfs_dat_translate(nilfs_bmap_get_dat(bmap), *ptrp,
73 &blocknr); 88 &blocknr);
@@ -88,7 +103,8 @@ int nilfs_bmap_lookup_contig(struct nilfs_bmap *bmap, __u64 key, __u64 *ptrp,
88 down_read(&bmap->b_sem); 103 down_read(&bmap->b_sem);
89 ret = bmap->b_ops->bop_lookup_contig(bmap, key, ptrp, maxblocks); 104 ret = bmap->b_ops->bop_lookup_contig(bmap, key, ptrp, maxblocks);
90 up_read(&bmap->b_sem); 105 up_read(&bmap->b_sem);
91 return ret; 106
107 return nilfs_bmap_convert_error(bmap, __func__, ret);
92} 108}
93 109
94static int nilfs_bmap_do_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr) 110static int nilfs_bmap_do_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr)
@@ -144,7 +160,8 @@ int nilfs_bmap_insert(struct nilfs_bmap *bmap,
144 down_write(&bmap->b_sem); 160 down_write(&bmap->b_sem);
145 ret = nilfs_bmap_do_insert(bmap, key, rec); 161 ret = nilfs_bmap_do_insert(bmap, key, rec);
146 up_write(&bmap->b_sem); 162 up_write(&bmap->b_sem);
147 return ret; 163
164 return nilfs_bmap_convert_error(bmap, __func__, ret);
148} 165}
149 166
150static int nilfs_bmap_do_delete(struct nilfs_bmap *bmap, __u64 key) 167static int nilfs_bmap_do_delete(struct nilfs_bmap *bmap, __u64 key)
@@ -180,9 +197,12 @@ int nilfs_bmap_last_key(struct nilfs_bmap *bmap, unsigned long *key)
180 197
181 down_read(&bmap->b_sem); 198 down_read(&bmap->b_sem);
182 ret = bmap->b_ops->bop_last_key(bmap, &lastkey); 199 ret = bmap->b_ops->bop_last_key(bmap, &lastkey);
183 if (!ret)
184 *key = lastkey;
185 up_read(&bmap->b_sem); 200 up_read(&bmap->b_sem);
201
202 if (ret < 0)
203 ret = nilfs_bmap_convert_error(bmap, __func__, ret);
204 else
205 *key = lastkey;
186 return ret; 206 return ret;
187} 207}
188 208
@@ -210,7 +230,8 @@ int nilfs_bmap_delete(struct nilfs_bmap *bmap, unsigned long key)
210 down_write(&bmap->b_sem); 230 down_write(&bmap->b_sem);
211 ret = nilfs_bmap_do_delete(bmap, key); 231 ret = nilfs_bmap_do_delete(bmap, key);
212 up_write(&bmap->b_sem); 232 up_write(&bmap->b_sem);
213 return ret; 233
234 return nilfs_bmap_convert_error(bmap, __func__, ret);
214} 235}
215 236
216static int nilfs_bmap_do_truncate(struct nilfs_bmap *bmap, unsigned long key) 237static int nilfs_bmap_do_truncate(struct nilfs_bmap *bmap, unsigned long key)
@@ -261,7 +282,8 @@ int nilfs_bmap_truncate(struct nilfs_bmap *bmap, unsigned long key)
261 down_write(&bmap->b_sem); 282 down_write(&bmap->b_sem);
262 ret = nilfs_bmap_do_truncate(bmap, key); 283 ret = nilfs_bmap_do_truncate(bmap, key);
263 up_write(&bmap->b_sem); 284 up_write(&bmap->b_sem);
264 return ret; 285
286 return nilfs_bmap_convert_error(bmap, __func__, ret);
265} 287}
266 288
267/** 289/**
@@ -300,7 +322,8 @@ int nilfs_bmap_propagate(struct nilfs_bmap *bmap, struct buffer_head *bh)
300 down_write(&bmap->b_sem); 322 down_write(&bmap->b_sem);
301 ret = bmap->b_ops->bop_propagate(bmap, bh); 323 ret = bmap->b_ops->bop_propagate(bmap, bh);
302 up_write(&bmap->b_sem); 324 up_write(&bmap->b_sem);
303 return ret; 325
326 return nilfs_bmap_convert_error(bmap, __func__, ret);
304} 327}
305 328
306/** 329/**
@@ -344,7 +367,8 @@ int nilfs_bmap_assign(struct nilfs_bmap *bmap,
344 down_write(&bmap->b_sem); 367 down_write(&bmap->b_sem);
345 ret = bmap->b_ops->bop_assign(bmap, bh, blocknr, binfo); 368 ret = bmap->b_ops->bop_assign(bmap, bh, blocknr, binfo);
346 up_write(&bmap->b_sem); 369 up_write(&bmap->b_sem);
347 return ret; 370
371 return nilfs_bmap_convert_error(bmap, __func__, ret);
348} 372}
349 373
350/** 374/**
@@ -373,7 +397,8 @@ int nilfs_bmap_mark(struct nilfs_bmap *bmap, __u64 key, int level)
373 down_write(&bmap->b_sem); 397 down_write(&bmap->b_sem);
374 ret = bmap->b_ops->bop_mark(bmap, key, level); 398 ret = bmap->b_ops->bop_mark(bmap, key, level);
375 up_write(&bmap->b_sem); 399 up_write(&bmap->b_sem);
376 return ret; 400
401 return nilfs_bmap_convert_error(bmap, __func__, ret);
377} 402}
378 403
379/** 404/**
diff --git a/fs/nilfs2/btnode.c b/fs/nilfs2/btnode.c
index 5115814cb745..388e9e8f5286 100644
--- a/fs/nilfs2/btnode.c
+++ b/fs/nilfs2/btnode.c
@@ -104,8 +104,7 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
104 if (pblocknr == 0) { 104 if (pblocknr == 0) {
105 pblocknr = blocknr; 105 pblocknr = blocknr;
106 if (inode->i_ino != NILFS_DAT_INO) { 106 if (inode->i_ino != NILFS_DAT_INO) {
107 struct inode *dat = 107 struct inode *dat = NILFS_I_NILFS(inode)->ns_dat;
108 nilfs_dat_inode(NILFS_I_NILFS(inode));
109 108
110 /* blocknr is a virtual block number */ 109 /* blocknr is a virtual block number */
111 err = nilfs_dat_translate(dat, blocknr, &pblocknr); 110 err = nilfs_dat_translate(dat, blocknr, &pblocknr);
diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c
index cb003c8ee1f6..9d45773b79e6 100644
--- a/fs/nilfs2/dir.c
+++ b/fs/nilfs2/dir.c
@@ -91,7 +91,6 @@ static void nilfs_commit_chunk(struct page *page,
91 unsigned from, unsigned to) 91 unsigned from, unsigned to)
92{ 92{
93 struct inode *dir = mapping->host; 93 struct inode *dir = mapping->host;
94 struct nilfs_sb_info *sbi = NILFS_SB(dir->i_sb);
95 loff_t pos = page_offset(page) + from; 94 loff_t pos = page_offset(page) + from;
96 unsigned len = to - from; 95 unsigned len = to - from;
97 unsigned nr_dirty, copied; 96 unsigned nr_dirty, copied;
@@ -103,7 +102,7 @@ static void nilfs_commit_chunk(struct page *page,
103 i_size_write(dir, pos + copied); 102 i_size_write(dir, pos + copied);
104 if (IS_DIRSYNC(dir)) 103 if (IS_DIRSYNC(dir))
105 nilfs_set_transaction_flag(NILFS_TI_SYNC); 104 nilfs_set_transaction_flag(NILFS_TI_SYNC);
106 err = nilfs_set_file_dirty(sbi, dir, nr_dirty); 105 err = nilfs_set_file_dirty(dir, nr_dirty);
107 WARN_ON(err); /* do not happen */ 106 WARN_ON(err); /* do not happen */
108 unlock_page(page); 107 unlock_page(page);
109} 108}
diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c
index c9a30d7ff6fc..2f560c9fb808 100644
--- a/fs/nilfs2/file.c
+++ b/fs/nilfs2/file.c
@@ -155,6 +155,7 @@ const struct inode_operations nilfs_file_inode_operations = {
155 .truncate = nilfs_truncate, 155 .truncate = nilfs_truncate,
156 .setattr = nilfs_setattr, 156 .setattr = nilfs_setattr,
157 .permission = nilfs_permission, 157 .permission = nilfs_permission,
158 .fiemap = nilfs_fiemap,
158}; 159};
159 160
160/* end of file */ 161/* end of file */
diff --git a/fs/nilfs2/ifile.c b/fs/nilfs2/ifile.c
index 9f8a2da67f90..bfc73d3a30ed 100644
--- a/fs/nilfs2/ifile.c
+++ b/fs/nilfs2/ifile.c
@@ -149,14 +149,9 @@ int nilfs_ifile_get_inode_block(struct inode *ifile, ino_t ino,
149 } 149 }
150 150
151 err = nilfs_palloc_get_entry_block(ifile, ino, 0, out_bh); 151 err = nilfs_palloc_get_entry_block(ifile, ino, 0, out_bh);
152 if (unlikely(err)) { 152 if (unlikely(err))
153 if (err == -EINVAL) 153 nilfs_warning(sb, __func__, "unable to read inode: %lu",
154 nilfs_error(sb, __func__, "ifile is broken"); 154 (unsigned long) ino);
155 else
156 nilfs_warning(sb, __func__,
157 "unable to read inode: %lu",
158 (unsigned long) ino);
159 }
160 return err; 155 return err;
161} 156}
162 157
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
index 77b48c8fab17..2fd440d8d6b8 100644
--- a/fs/nilfs2/inode.c
+++ b/fs/nilfs2/inode.c
@@ -58,7 +58,7 @@ int nilfs_get_block(struct inode *inode, sector_t blkoff,
58 struct nilfs_inode_info *ii = NILFS_I(inode); 58 struct nilfs_inode_info *ii = NILFS_I(inode);
59 __u64 blknum = 0; 59 __u64 blknum = 0;
60 int err = 0, ret; 60 int err = 0, ret;
61 struct inode *dat = nilfs_dat_inode(NILFS_I_NILFS(inode)); 61 struct inode *dat = NILFS_I_NILFS(inode)->ns_dat;
62 unsigned maxblocks = bh_result->b_size >> inode->i_blkbits; 62 unsigned maxblocks = bh_result->b_size >> inode->i_blkbits;
63 63
64 down_read(&NILFS_MDT(dat)->mi_sem); 64 down_read(&NILFS_MDT(dat)->mi_sem);
@@ -96,11 +96,6 @@ int nilfs_get_block(struct inode *inode, sector_t blkoff,
96 inode->i_ino, 96 inode->i_ino,
97 (unsigned long long)blkoff); 97 (unsigned long long)blkoff);
98 err = 0; 98 err = 0;
99 } else if (err == -EINVAL) {
100 nilfs_error(inode->i_sb, __func__,
101 "broken bmap (inode=%lu)\n",
102 inode->i_ino);
103 err = -EIO;
104 } 99 }
105 nilfs_transaction_abort(inode->i_sb); 100 nilfs_transaction_abort(inode->i_sb);
106 goto out; 101 goto out;
@@ -109,6 +104,7 @@ int nilfs_get_block(struct inode *inode, sector_t blkoff,
109 nilfs_transaction_commit(inode->i_sb); /* never fails */ 104 nilfs_transaction_commit(inode->i_sb); /* never fails */
110 /* Error handling should be detailed */ 105 /* Error handling should be detailed */
111 set_buffer_new(bh_result); 106 set_buffer_new(bh_result);
107 set_buffer_delay(bh_result);
112 map_bh(bh_result, inode->i_sb, 0); /* dbn must be changed 108 map_bh(bh_result, inode->i_sb, 0); /* dbn must be changed
113 to proper value */ 109 to proper value */
114 } else if (ret == -ENOENT) { 110 } else if (ret == -ENOENT) {
@@ -185,10 +181,9 @@ static int nilfs_set_page_dirty(struct page *page)
185 181
186 if (ret) { 182 if (ret) {
187 struct inode *inode = page->mapping->host; 183 struct inode *inode = page->mapping->host;
188 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
189 unsigned nr_dirty = 1 << (PAGE_SHIFT - inode->i_blkbits); 184 unsigned nr_dirty = 1 << (PAGE_SHIFT - inode->i_blkbits);
190 185
191 nilfs_set_file_dirty(sbi, inode, nr_dirty); 186 nilfs_set_file_dirty(inode, nr_dirty);
192 } 187 }
193 return ret; 188 return ret;
194} 189}
@@ -229,7 +224,7 @@ static int nilfs_write_end(struct file *file, struct address_space *mapping,
229 start + copied); 224 start + copied);
230 copied = generic_write_end(file, mapping, pos, len, copied, page, 225 copied = generic_write_end(file, mapping, pos, len, copied, page,
231 fsdata); 226 fsdata);
232 nilfs_set_file_dirty(NILFS_SB(inode->i_sb), inode, nr_dirty); 227 nilfs_set_file_dirty(inode, nr_dirty);
233 err = nilfs_transaction_commit(inode->i_sb); 228 err = nilfs_transaction_commit(inode->i_sb);
234 return err ? : copied; 229 return err ? : copied;
235} 230}
@@ -425,13 +420,12 @@ static int __nilfs_read_inode(struct super_block *sb,
425 struct nilfs_root *root, unsigned long ino, 420 struct nilfs_root *root, unsigned long ino,
426 struct inode *inode) 421 struct inode *inode)
427{ 422{
428 struct nilfs_sb_info *sbi = NILFS_SB(sb); 423 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
429 struct inode *dat = nilfs_dat_inode(sbi->s_nilfs);
430 struct buffer_head *bh; 424 struct buffer_head *bh;
431 struct nilfs_inode *raw_inode; 425 struct nilfs_inode *raw_inode;
432 int err; 426 int err;
433 427
434 down_read(&NILFS_MDT(dat)->mi_sem); /* XXX */ 428 down_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
435 err = nilfs_ifile_get_inode_block(root->ifile, ino, &bh); 429 err = nilfs_ifile_get_inode_block(root->ifile, ino, &bh);
436 if (unlikely(err)) 430 if (unlikely(err))
437 goto bad_inode; 431 goto bad_inode;
@@ -461,7 +455,7 @@ static int __nilfs_read_inode(struct super_block *sb,
461 } 455 }
462 nilfs_ifile_unmap_inode(root->ifile, ino, bh); 456 nilfs_ifile_unmap_inode(root->ifile, ino, bh);
463 brelse(bh); 457 brelse(bh);
464 up_read(&NILFS_MDT(dat)->mi_sem); /* XXX */ 458 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
465 nilfs_set_inode_flags(inode); 459 nilfs_set_inode_flags(inode);
466 return 0; 460 return 0;
467 461
@@ -470,7 +464,7 @@ static int __nilfs_read_inode(struct super_block *sb,
470 brelse(bh); 464 brelse(bh);
471 465
472 bad_inode: 466 bad_inode:
473 up_read(&NILFS_MDT(dat)->mi_sem); /* XXX */ 467 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
474 return err; 468 return err;
475} 469}
476 470
@@ -629,7 +623,7 @@ static void nilfs_truncate_bmap(struct nilfs_inode_info *ii,
629 623
630 if (!test_bit(NILFS_I_BMAP, &ii->i_state)) 624 if (!test_bit(NILFS_I_BMAP, &ii->i_state))
631 return; 625 return;
632 repeat: 626repeat:
633 ret = nilfs_bmap_last_key(ii->i_bmap, &b); 627 ret = nilfs_bmap_last_key(ii->i_bmap, &b);
634 if (ret == -ENOENT) 628 if (ret == -ENOENT)
635 return; 629 return;
@@ -646,14 +640,10 @@ static void nilfs_truncate_bmap(struct nilfs_inode_info *ii,
646 nilfs_bmap_truncate(ii->i_bmap, b) == 0)) 640 nilfs_bmap_truncate(ii->i_bmap, b) == 0))
647 goto repeat; 641 goto repeat;
648 642
649 failed: 643failed:
650 if (ret == -EINVAL) 644 nilfs_warning(ii->vfs_inode.i_sb, __func__,
651 nilfs_error(ii->vfs_inode.i_sb, __func__, 645 "failed to truncate bmap (ino=%lu, err=%d)",
652 "bmap is broken (ino=%lu)", ii->vfs_inode.i_ino); 646 ii->vfs_inode.i_ino, ret);
653 else
654 nilfs_warning(ii->vfs_inode.i_sb, __func__,
655 "failed to truncate bmap (ino=%lu, err=%d)",
656 ii->vfs_inode.i_ino, ret);
657} 647}
658 648
659void nilfs_truncate(struct inode *inode) 649void nilfs_truncate(struct inode *inode)
@@ -682,7 +672,7 @@ void nilfs_truncate(struct inode *inode)
682 nilfs_set_transaction_flag(NILFS_TI_SYNC); 672 nilfs_set_transaction_flag(NILFS_TI_SYNC);
683 673
684 nilfs_mark_inode_dirty(inode); 674 nilfs_mark_inode_dirty(inode);
685 nilfs_set_file_dirty(NILFS_SB(sb), inode, 0); 675 nilfs_set_file_dirty(inode, 0);
686 nilfs_transaction_commit(sb); 676 nilfs_transaction_commit(sb);
687 /* May construct a logical segment and may fail in sync mode. 677 /* May construct a logical segment and may fail in sync mode.
688 But truncate has no return value. */ 678 But truncate has no return value. */
@@ -800,9 +790,9 @@ int nilfs_permission(struct inode *inode, int mask, unsigned int flags)
800 return generic_permission(inode, mask, flags, NULL); 790 return generic_permission(inode, mask, flags, NULL);
801} 791}
802 792
803int nilfs_load_inode_block(struct nilfs_sb_info *sbi, struct inode *inode, 793int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh)
804 struct buffer_head **pbh)
805{ 794{
795 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
806 struct nilfs_inode_info *ii = NILFS_I(inode); 796 struct nilfs_inode_info *ii = NILFS_I(inode);
807 int err; 797 int err;
808 798
@@ -843,9 +833,9 @@ int nilfs_inode_dirty(struct inode *inode)
843 return ret; 833 return ret;
844} 834}
845 835
846int nilfs_set_file_dirty(struct nilfs_sb_info *sbi, struct inode *inode, 836int nilfs_set_file_dirty(struct inode *inode, unsigned nr_dirty)
847 unsigned nr_dirty)
848{ 837{
838 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
849 struct nilfs_inode_info *ii = NILFS_I(inode); 839 struct nilfs_inode_info *ii = NILFS_I(inode);
850 840
851 atomic_add(nr_dirty, &sbi->s_nilfs->ns_ndirtyblks); 841 atomic_add(nr_dirty, &sbi->s_nilfs->ns_ndirtyblks);
@@ -878,11 +868,10 @@ int nilfs_set_file_dirty(struct nilfs_sb_info *sbi, struct inode *inode,
878 868
879int nilfs_mark_inode_dirty(struct inode *inode) 869int nilfs_mark_inode_dirty(struct inode *inode)
880{ 870{
881 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
882 struct buffer_head *ibh; 871 struct buffer_head *ibh;
883 int err; 872 int err;
884 873
885 err = nilfs_load_inode_block(sbi, inode, &ibh); 874 err = nilfs_load_inode_block(inode, &ibh);
886 if (unlikely(err)) { 875 if (unlikely(err)) {
887 nilfs_warning(inode->i_sb, __func__, 876 nilfs_warning(inode->i_sb, __func__,
888 "failed to reget inode block.\n"); 877 "failed to reget inode block.\n");
@@ -924,3 +913,134 @@ void nilfs_dirty_inode(struct inode *inode)
924 nilfs_mark_inode_dirty(inode); 913 nilfs_mark_inode_dirty(inode);
925 nilfs_transaction_commit(inode->i_sb); /* never fails */ 914 nilfs_transaction_commit(inode->i_sb); /* never fails */
926} 915}
916
917int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
918 __u64 start, __u64 len)
919{
920 struct the_nilfs *nilfs = NILFS_I_NILFS(inode);
921 __u64 logical = 0, phys = 0, size = 0;
922 __u32 flags = 0;
923 loff_t isize;
924 sector_t blkoff, end_blkoff;
925 sector_t delalloc_blkoff;
926 unsigned long delalloc_blklen;
927 unsigned int blkbits = inode->i_blkbits;
928 int ret, n;
929
930 ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC);
931 if (ret)
932 return ret;
933
934 mutex_lock(&inode->i_mutex);
935
936 isize = i_size_read(inode);
937
938 blkoff = start >> blkbits;
939 end_blkoff = (start + len - 1) >> blkbits;
940
941 delalloc_blklen = nilfs_find_uncommitted_extent(inode, blkoff,
942 &delalloc_blkoff);
943
944 do {
945 __u64 blkphy;
946 unsigned int maxblocks;
947
948 if (delalloc_blklen && blkoff == delalloc_blkoff) {
949 if (size) {
950 /* End of the current extent */
951 ret = fiemap_fill_next_extent(
952 fieinfo, logical, phys, size, flags);
953 if (ret)
954 break;
955 }
956 if (blkoff > end_blkoff)
957 break;
958
959 flags = FIEMAP_EXTENT_MERGED | FIEMAP_EXTENT_DELALLOC;
960 logical = blkoff << blkbits;
961 phys = 0;
962 size = delalloc_blklen << blkbits;
963
964 blkoff = delalloc_blkoff + delalloc_blklen;
965 delalloc_blklen = nilfs_find_uncommitted_extent(
966 inode, blkoff, &delalloc_blkoff);
967 continue;
968 }
969
970 /*
971 * Limit the number of blocks that we look up so as
972 * not to get into the next delayed allocation extent.
973 */
974 maxblocks = INT_MAX;
975 if (delalloc_blklen)
976 maxblocks = min_t(sector_t, delalloc_blkoff - blkoff,
977 maxblocks);
978 blkphy = 0;
979
980 down_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
981 n = nilfs_bmap_lookup_contig(
982 NILFS_I(inode)->i_bmap, blkoff, &blkphy, maxblocks);
983 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
984
985 if (n < 0) {
986 int past_eof;
987
988 if (unlikely(n != -ENOENT))
989 break; /* error */
990
991 /* HOLE */
992 blkoff++;
993 past_eof = ((blkoff << blkbits) >= isize);
994
995 if (size) {
996 /* End of the current extent */
997
998 if (past_eof)
999 flags |= FIEMAP_EXTENT_LAST;
1000
1001 ret = fiemap_fill_next_extent(
1002 fieinfo, logical, phys, size, flags);
1003 if (ret)
1004 break;
1005 size = 0;
1006 }
1007 if (blkoff > end_blkoff || past_eof)
1008 break;
1009 } else {
1010 if (size) {
1011 if (phys && blkphy << blkbits == phys + size) {
1012 /* The current extent goes on */
1013 size += n << blkbits;
1014 } else {
1015 /* Terminate the current extent */
1016 ret = fiemap_fill_next_extent(
1017 fieinfo, logical, phys, size,
1018 flags);
1019 if (ret || blkoff > end_blkoff)
1020 break;
1021
1022 /* Start another extent */
1023 flags = FIEMAP_EXTENT_MERGED;
1024 logical = blkoff << blkbits;
1025 phys = blkphy << blkbits;
1026 size = n << blkbits;
1027 }
1028 } else {
1029 /* Start a new extent */
1030 flags = FIEMAP_EXTENT_MERGED;
1031 logical = blkoff << blkbits;
1032 phys = blkphy << blkbits;
1033 size = n << blkbits;
1034 }
1035 blkoff += n;
1036 }
1037 cond_resched();
1038 } while (true);
1039
1040 /* If ret is 1 then we just hit the end of the extent array */
1041 if (ret == 1)
1042 ret = 0;
1043
1044 mutex_unlock(&inode->i_mutex);
1045 return ret;
1046}
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index b185e937a335..496738963fdb 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -233,7 +233,7 @@ nilfs_ioctl_do_get_vinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
233 int ret; 233 int ret;
234 234
235 down_read(&nilfs->ns_segctor_sem); 235 down_read(&nilfs->ns_segctor_sem);
236 ret = nilfs_dat_get_vinfo(nilfs_dat_inode(nilfs), buf, size, nmembs); 236 ret = nilfs_dat_get_vinfo(nilfs->ns_dat, buf, size, nmembs);
237 up_read(&nilfs->ns_segctor_sem); 237 up_read(&nilfs->ns_segctor_sem);
238 return ret; 238 return ret;
239} 239}
@@ -242,8 +242,7 @@ static ssize_t
242nilfs_ioctl_do_get_bdescs(struct the_nilfs *nilfs, __u64 *posp, int flags, 242nilfs_ioctl_do_get_bdescs(struct the_nilfs *nilfs, __u64 *posp, int flags,
243 void *buf, size_t size, size_t nmembs) 243 void *buf, size_t size, size_t nmembs)
244{ 244{
245 struct inode *dat = nilfs_dat_inode(nilfs); 245 struct nilfs_bmap *bmap = NILFS_I(nilfs->ns_dat)->i_bmap;
246 struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap;
247 struct nilfs_bdesc *bdescs = buf; 246 struct nilfs_bdesc *bdescs = buf;
248 int ret, i; 247 int ret, i;
249 248
@@ -421,7 +420,7 @@ static int nilfs_ioctl_free_vblocknrs(struct the_nilfs *nilfs,
421 size_t nmembs = argv->v_nmembs; 420 size_t nmembs = argv->v_nmembs;
422 int ret; 421 int ret;
423 422
424 ret = nilfs_dat_freev(nilfs_dat_inode(nilfs), buf, nmembs); 423 ret = nilfs_dat_freev(nilfs->ns_dat, buf, nmembs);
425 424
426 return (ret < 0) ? ret : nmembs; 425 return (ret < 0) ? ret : nmembs;
427} 426}
@@ -430,8 +429,7 @@ static int nilfs_ioctl_mark_blocks_dirty(struct the_nilfs *nilfs,
430 struct nilfs_argv *argv, void *buf) 429 struct nilfs_argv *argv, void *buf)
431{ 430{
432 size_t nmembs = argv->v_nmembs; 431 size_t nmembs = argv->v_nmembs;
433 struct inode *dat = nilfs_dat_inode(nilfs); 432 struct nilfs_bmap *bmap = NILFS_I(nilfs->ns_dat)->i_bmap;
434 struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap;
435 struct nilfs_bdesc *bdescs = buf; 433 struct nilfs_bdesc *bdescs = buf;
436 int ret, i; 434 int ret, i;
437 435
@@ -450,7 +448,7 @@ static int nilfs_ioctl_mark_blocks_dirty(struct the_nilfs *nilfs,
450 /* skip dead block */ 448 /* skip dead block */
451 continue; 449 continue;
452 if (bdescs[i].bd_level == 0) { 450 if (bdescs[i].bd_level == 0) {
453 ret = nilfs_mdt_mark_block_dirty(dat, 451 ret = nilfs_mdt_mark_block_dirty(nilfs->ns_dat,
454 bdescs[i].bd_offset); 452 bdescs[i].bd_offset);
455 if (ret < 0) { 453 if (ret < 0) {
456 WARN_ON(ret == -ENOENT); 454 WARN_ON(ret == -ENOENT);
diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c
index 39a5b84e2c9f..6a0e2a189f60 100644
--- a/fs/nilfs2/mdt.c
+++ b/fs/nilfs2/mdt.c
@@ -237,8 +237,6 @@ static int nilfs_mdt_read_block(struct inode *inode, unsigned long block,
237 * 237 *
238 * %-ENOENT - the specified block does not exist (hole block) 238 * %-ENOENT - the specified block does not exist (hole block)
239 * 239 *
240 * %-EINVAL - bmap is broken. (the caller should call nilfs_error())
241 *
242 * %-EROFS - Read only filesystem (for create mode) 240 * %-EROFS - Read only filesystem (for create mode)
243 */ 241 */
244int nilfs_mdt_get_block(struct inode *inode, unsigned long blkoff, int create, 242int nilfs_mdt_get_block(struct inode *inode, unsigned long blkoff, int create,
@@ -273,8 +271,6 @@ int nilfs_mdt_get_block(struct inode *inode, unsigned long blkoff, int create,
273 * %-ENOMEM - Insufficient memory available. 271 * %-ENOMEM - Insufficient memory available.
274 * 272 *
275 * %-EIO - I/O error 273 * %-EIO - I/O error
276 *
277 * %-EINVAL - bmap is broken. (the caller should call nilfs_error())
278 */ 274 */
279int nilfs_mdt_delete_block(struct inode *inode, unsigned long block) 275int nilfs_mdt_delete_block(struct inode *inode, unsigned long block)
280{ 276{
@@ -350,8 +346,6 @@ int nilfs_mdt_forget_block(struct inode *inode, unsigned long block)
350 * %-EIO - I/O error 346 * %-EIO - I/O error
351 * 347 *
352 * %-ENOENT - the specified block does not exist (hole block) 348 * %-ENOENT - the specified block does not exist (hole block)
353 *
354 * %-EINVAL - bmap is broken. (the caller should call nilfs_error())
355 */ 349 */
356int nilfs_mdt_mark_block_dirty(struct inode *inode, unsigned long block) 350int nilfs_mdt_mark_block_dirty(struct inode *inode, unsigned long block)
357{ 351{
@@ -499,31 +493,29 @@ int nilfs_mdt_freeze_buffer(struct inode *inode, struct buffer_head *bh)
499 struct buffer_head *bh_frozen; 493 struct buffer_head *bh_frozen;
500 struct page *page; 494 struct page *page;
501 int blkbits = inode->i_blkbits; 495 int blkbits = inode->i_blkbits;
502 int ret = -ENOMEM;
503 496
504 page = grab_cache_page(&shadow->frozen_data, bh->b_page->index); 497 page = grab_cache_page(&shadow->frozen_data, bh->b_page->index);
505 if (!page) 498 if (!page)
506 return ret; 499 return -ENOMEM;
507 500
508 if (!page_has_buffers(page)) 501 if (!page_has_buffers(page))
509 create_empty_buffers(page, 1 << blkbits, 0); 502 create_empty_buffers(page, 1 << blkbits, 0);
510 503
511 bh_frozen = nilfs_page_get_nth_block(page, bh_offset(bh) >> blkbits); 504 bh_frozen = nilfs_page_get_nth_block(page, bh_offset(bh) >> blkbits);
512 if (bh_frozen) { 505
513 if (!buffer_uptodate(bh_frozen)) 506 if (!buffer_uptodate(bh_frozen))
514 nilfs_copy_buffer(bh_frozen, bh); 507 nilfs_copy_buffer(bh_frozen, bh);
515 if (list_empty(&bh_frozen->b_assoc_buffers)) { 508 if (list_empty(&bh_frozen->b_assoc_buffers)) {
516 list_add_tail(&bh_frozen->b_assoc_buffers, 509 list_add_tail(&bh_frozen->b_assoc_buffers,
517 &shadow->frozen_buffers); 510 &shadow->frozen_buffers);
518 set_buffer_nilfs_redirected(bh); 511 set_buffer_nilfs_redirected(bh);
519 } else { 512 } else {
520 brelse(bh_frozen); /* already frozen */ 513 brelse(bh_frozen); /* already frozen */
521 }
522 ret = 0;
523 } 514 }
515
524 unlock_page(page); 516 unlock_page(page);
525 page_cache_release(page); 517 page_cache_release(page);
526 return ret; 518 return 0;
527} 519}
528 520
529struct buffer_head * 521struct buffer_head *
diff --git a/fs/nilfs2/namei.c b/fs/nilfs2/namei.c
index 6e9557ecf161..98034271cd02 100644
--- a/fs/nilfs2/namei.c
+++ b/fs/nilfs2/namei.c
@@ -577,6 +577,7 @@ const struct inode_operations nilfs_dir_inode_operations = {
577 .rename = nilfs_rename, 577 .rename = nilfs_rename,
578 .setattr = nilfs_setattr, 578 .setattr = nilfs_setattr,
579 .permission = nilfs_permission, 579 .permission = nilfs_permission,
580 .fiemap = nilfs_fiemap,
580}; 581};
581 582
582const struct inode_operations nilfs_special_inode_operations = { 583const struct inode_operations nilfs_special_inode_operations = {
diff --git a/fs/nilfs2/nilfs.h b/fs/nilfs2/nilfs.h
index 0ca98823db59..777e8fd04304 100644
--- a/fs/nilfs2/nilfs.h
+++ b/fs/nilfs2/nilfs.h
@@ -190,11 +190,6 @@ static inline int nilfs_doing_construction(void)
190 return nilfs_test_transaction_flag(NILFS_TI_WRITER); 190 return nilfs_test_transaction_flag(NILFS_TI_WRITER);
191} 191}
192 192
193static inline struct inode *nilfs_dat_inode(const struct the_nilfs *nilfs)
194{
195 return nilfs->ns_dat;
196}
197
198/* 193/*
199 * function prototype 194 * function prototype
200 */ 195 */
@@ -257,13 +252,13 @@ extern void nilfs_truncate(struct inode *);
257extern void nilfs_evict_inode(struct inode *); 252extern void nilfs_evict_inode(struct inode *);
258extern int nilfs_setattr(struct dentry *, struct iattr *); 253extern int nilfs_setattr(struct dentry *, struct iattr *);
259int nilfs_permission(struct inode *inode, int mask, unsigned int flags); 254int nilfs_permission(struct inode *inode, int mask, unsigned int flags);
260extern int nilfs_load_inode_block(struct nilfs_sb_info *, struct inode *, 255int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh);
261 struct buffer_head **);
262extern int nilfs_inode_dirty(struct inode *); 256extern int nilfs_inode_dirty(struct inode *);
263extern int nilfs_set_file_dirty(struct nilfs_sb_info *, struct inode *, 257int nilfs_set_file_dirty(struct inode *inode, unsigned nr_dirty);
264 unsigned);
265extern int nilfs_mark_inode_dirty(struct inode *); 258extern int nilfs_mark_inode_dirty(struct inode *);
266extern void nilfs_dirty_inode(struct inode *); 259extern void nilfs_dirty_inode(struct inode *);
260int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
261 __u64 start, __u64 len);
267 262
268/* super.c */ 263/* super.c */
269extern struct inode *nilfs_alloc_inode(struct super_block *); 264extern struct inode *nilfs_alloc_inode(struct super_block *);
diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c
index a6c3c2e817f8..0c432416cfef 100644
--- a/fs/nilfs2/page.c
+++ b/fs/nilfs2/page.c
@@ -491,7 +491,7 @@ unsigned nilfs_page_count_clean_buffers(struct page *page,
491 } 491 }
492 return nc; 492 return nc;
493} 493}
494 494
495void nilfs_mapping_init_once(struct address_space *mapping) 495void nilfs_mapping_init_once(struct address_space *mapping)
496{ 496{
497 memset(mapping, 0, sizeof(*mapping)); 497 memset(mapping, 0, sizeof(*mapping));
@@ -546,3 +546,87 @@ int __nilfs_clear_page_dirty(struct page *page)
546 } 546 }
547 return TestClearPageDirty(page); 547 return TestClearPageDirty(page);
548} 548}
549
550/**
551 * nilfs_find_uncommitted_extent - find extent of uncommitted data
552 * @inode: inode
553 * @start_blk: start block offset (in)
554 * @blkoff: start offset of the found extent (out)
555 *
556 * This function searches an extent of buffers marked "delayed" which
557 * starts from a block offset equal to or larger than @start_blk. If
558 * such an extent was found, this will store the start offset in
559 * @blkoff and return its length in blocks. Otherwise, zero is
560 * returned.
561 */
562unsigned long nilfs_find_uncommitted_extent(struct inode *inode,
563 sector_t start_blk,
564 sector_t *blkoff)
565{
566 unsigned int i;
567 pgoff_t index;
568 unsigned int nblocks_in_page;
569 unsigned long length = 0;
570 sector_t b;
571 struct pagevec pvec;
572 struct page *page;
573
574 if (inode->i_mapping->nrpages == 0)
575 return 0;
576
577 index = start_blk >> (PAGE_CACHE_SHIFT - inode->i_blkbits);
578 nblocks_in_page = 1U << (PAGE_CACHE_SHIFT - inode->i_blkbits);
579
580 pagevec_init(&pvec, 0);
581
582repeat:
583 pvec.nr = find_get_pages_contig(inode->i_mapping, index, PAGEVEC_SIZE,
584 pvec.pages);
585 if (pvec.nr == 0)
586 return length;
587
588 if (length > 0 && pvec.pages[0]->index > index)
589 goto out;
590
591 b = pvec.pages[0]->index << (PAGE_CACHE_SHIFT - inode->i_blkbits);
592 i = 0;
593 do {
594 page = pvec.pages[i];
595
596 lock_page(page);
597 if (page_has_buffers(page)) {
598 struct buffer_head *bh, *head;
599
600 bh = head = page_buffers(page);
601 do {
602 if (b < start_blk)
603 continue;
604 if (buffer_delay(bh)) {
605 if (length == 0)
606 *blkoff = b;
607 length++;
608 } else if (length > 0) {
609 goto out_locked;
610 }
611 } while (++b, bh = bh->b_this_page, bh != head);
612 } else {
613 if (length > 0)
614 goto out_locked;
615
616 b += nblocks_in_page;
617 }
618 unlock_page(page);
619
620 } while (++i < pagevec_count(&pvec));
621
622 index = page->index + 1;
623 pagevec_release(&pvec);
624 cond_resched();
625 goto repeat;
626
627out_locked:
628 unlock_page(page);
629out:
630 pagevec_release(&pvec);
631 return length;
632}
diff --git a/fs/nilfs2/page.h b/fs/nilfs2/page.h
index fb9e8a8a2038..622df27cd891 100644
--- a/fs/nilfs2/page.h
+++ b/fs/nilfs2/page.h
@@ -66,6 +66,9 @@ void nilfs_mapping_init(struct address_space *mapping,
66 struct backing_dev_info *bdi, 66 struct backing_dev_info *bdi,
67 const struct address_space_operations *aops); 67 const struct address_space_operations *aops);
68unsigned nilfs_page_count_clean_buffers(struct page *, unsigned, unsigned); 68unsigned nilfs_page_count_clean_buffers(struct page *, unsigned, unsigned);
69unsigned long nilfs_find_uncommitted_extent(struct inode *inode,
70 sector_t start_blk,
71 sector_t *blkoff);
69 72
70#define NILFS_PAGE_BUG(page, m, a...) \ 73#define NILFS_PAGE_BUG(page, m, a...) \
71 do { nilfs_page_bug(page); BUG(); } while (0) 74 do { nilfs_page_bug(page); BUG(); } while (0)
diff --git a/fs/nilfs2/recovery.c b/fs/nilfs2/recovery.c
index 5d2711c28da7..3dfcd3b7d389 100644
--- a/fs/nilfs2/recovery.c
+++ b/fs/nilfs2/recovery.c
@@ -535,7 +535,7 @@ static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
535 if (unlikely(err)) 535 if (unlikely(err))
536 goto failed_page; 536 goto failed_page;
537 537
538 err = nilfs_set_file_dirty(sbi, inode, 1); 538 err = nilfs_set_file_dirty(inode, 1);
539 if (unlikely(err)) 539 if (unlikely(err))
540 goto failed_page; 540 goto failed_page;
541 541
diff --git a/fs/nilfs2/sb.h b/fs/nilfs2/sb.h
index 35a07157b980..7a17715f215f 100644
--- a/fs/nilfs2/sb.h
+++ b/fs/nilfs2/sb.h
@@ -27,14 +27,6 @@
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/fs.h> 28#include <linux/fs.h>
29 29
30/*
31 * Mount options
32 */
33struct nilfs_mount_options {
34 unsigned long mount_opt;
35 __u64 snapshot_cno;
36};
37
38struct the_nilfs; 30struct the_nilfs;
39struct nilfs_sc_info; 31struct nilfs_sc_info;
40 32
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index 687d090cea34..55ebae5c7f39 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -504,17 +504,6 @@ static int nilfs_segctor_add_file_block(struct nilfs_sc_info *sci,
504 return err; 504 return err;
505} 505}
506 506
507static int nilfs_handle_bmap_error(int err, const char *fname,
508 struct inode *inode, struct super_block *sb)
509{
510 if (err == -EINVAL) {
511 nilfs_error(sb, fname, "broken bmap (inode=%lu)\n",
512 inode->i_ino);
513 err = -EIO;
514 }
515 return err;
516}
517
518/* 507/*
519 * Callback functions that enumerate, mark, and collect dirty blocks 508 * Callback functions that enumerate, mark, and collect dirty blocks
520 */ 509 */
@@ -524,9 +513,8 @@ static int nilfs_collect_file_data(struct nilfs_sc_info *sci,
524 int err; 513 int err;
525 514
526 err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); 515 err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh);
527 if (unlikely(err < 0)) 516 if (err < 0)
528 return nilfs_handle_bmap_error(err, __func__, inode, 517 return err;
529 sci->sc_super);
530 518
531 err = nilfs_segctor_add_file_block(sci, bh, inode, 519 err = nilfs_segctor_add_file_block(sci, bh, inode,
532 sizeof(struct nilfs_binfo_v)); 520 sizeof(struct nilfs_binfo_v));
@@ -539,13 +527,7 @@ static int nilfs_collect_file_node(struct nilfs_sc_info *sci,
539 struct buffer_head *bh, 527 struct buffer_head *bh,
540 struct inode *inode) 528 struct inode *inode)
541{ 529{
542 int err; 530 return nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh);
543
544 err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh);
545 if (unlikely(err < 0))
546 return nilfs_handle_bmap_error(err, __func__, inode,
547 sci->sc_super);
548 return 0;
549} 531}
550 532
551static int nilfs_collect_file_bmap(struct nilfs_sc_info *sci, 533static int nilfs_collect_file_bmap(struct nilfs_sc_info *sci,
@@ -588,9 +570,8 @@ static int nilfs_collect_dat_data(struct nilfs_sc_info *sci,
588 int err; 570 int err;
589 571
590 err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); 572 err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh);
591 if (unlikely(err < 0)) 573 if (err < 0)
592 return nilfs_handle_bmap_error(err, __func__, inode, 574 return err;
593 sci->sc_super);
594 575
595 err = nilfs_segctor_add_file_block(sci, bh, inode, sizeof(__le64)); 576 err = nilfs_segctor_add_file_block(sci, bh, inode, sizeof(__le64));
596 if (!err) 577 if (!err)
@@ -776,9 +757,8 @@ static int nilfs_test_metadata_dirty(struct the_nilfs *nilfs,
776 ret++; 757 ret++;
777 if (nilfs_mdt_fetch_dirty(nilfs->ns_sufile)) 758 if (nilfs_mdt_fetch_dirty(nilfs->ns_sufile))
778 ret++; 759 ret++;
779 if (ret || nilfs_doing_gc()) 760 if ((ret || nilfs_doing_gc()) && nilfs_mdt_fetch_dirty(nilfs->ns_dat))
780 if (nilfs_mdt_fetch_dirty(nilfs_dat_inode(nilfs))) 761 ret++;
781 ret++;
782 return ret; 762 return ret;
783} 763}
784 764
@@ -814,7 +794,7 @@ static void nilfs_segctor_clear_metadata_dirty(struct nilfs_sc_info *sci)
814 nilfs_mdt_clear_dirty(sci->sc_root->ifile); 794 nilfs_mdt_clear_dirty(sci->sc_root->ifile);
815 nilfs_mdt_clear_dirty(nilfs->ns_cpfile); 795 nilfs_mdt_clear_dirty(nilfs->ns_cpfile);
816 nilfs_mdt_clear_dirty(nilfs->ns_sufile); 796 nilfs_mdt_clear_dirty(nilfs->ns_sufile);
817 nilfs_mdt_clear_dirty(nilfs_dat_inode(nilfs)); 797 nilfs_mdt_clear_dirty(nilfs->ns_dat);
818} 798}
819 799
820static int nilfs_segctor_create_checkpoint(struct nilfs_sc_info *sci) 800static int nilfs_segctor_create_checkpoint(struct nilfs_sc_info *sci)
@@ -923,7 +903,7 @@ static void nilfs_segctor_fill_in_super_root(struct nilfs_sc_info *sci,
923 nilfs->ns_nongc_ctime : sci->sc_seg_ctime); 903 nilfs->ns_nongc_ctime : sci->sc_seg_ctime);
924 raw_sr->sr_flags = 0; 904 raw_sr->sr_flags = 0;
925 905
926 nilfs_write_inode_common(nilfs_dat_inode(nilfs), (void *)raw_sr + 906 nilfs_write_inode_common(nilfs->ns_dat, (void *)raw_sr +
927 NILFS_SR_DAT_OFFSET(isz), 1); 907 NILFS_SR_DAT_OFFSET(isz), 1);
928 nilfs_write_inode_common(nilfs->ns_cpfile, (void *)raw_sr + 908 nilfs_write_inode_common(nilfs->ns_cpfile, (void *)raw_sr +
929 NILFS_SR_CPFILE_OFFSET(isz), 1); 909 NILFS_SR_CPFILE_OFFSET(isz), 1);
@@ -1179,7 +1159,7 @@ static int nilfs_segctor_collect_blocks(struct nilfs_sc_info *sci, int mode)
1179 sci->sc_stage.scnt++; /* Fall through */ 1159 sci->sc_stage.scnt++; /* Fall through */
1180 case NILFS_ST_DAT: 1160 case NILFS_ST_DAT:
1181 dat_stage: 1161 dat_stage:
1182 err = nilfs_segctor_scan_file(sci, nilfs_dat_inode(nilfs), 1162 err = nilfs_segctor_scan_file(sci, nilfs->ns_dat,
1183 &nilfs_sc_dat_ops); 1163 &nilfs_sc_dat_ops);
1184 if (unlikely(err)) 1164 if (unlikely(err))
1185 break; 1165 break;
@@ -1563,7 +1543,6 @@ nilfs_segctor_update_payload_blocknr(struct nilfs_sc_info *sci,
1563 return 0; 1543 return 0;
1564 1544
1565 failed_bmap: 1545 failed_bmap:
1566 err = nilfs_handle_bmap_error(err, __func__, inode, sci->sc_super);
1567 return err; 1546 return err;
1568} 1547}
1569 1548
@@ -1783,6 +1762,7 @@ static void nilfs_clear_copied_buffers(struct list_head *list, int err)
1783 if (!err) { 1762 if (!err) {
1784 set_buffer_uptodate(bh); 1763 set_buffer_uptodate(bh);
1785 clear_buffer_dirty(bh); 1764 clear_buffer_dirty(bh);
1765 clear_buffer_delay(bh);
1786 clear_buffer_nilfs_volatile(bh); 1766 clear_buffer_nilfs_volatile(bh);
1787 } 1767 }
1788 brelse(bh); /* for b_assoc_buffers */ 1768 brelse(bh); /* for b_assoc_buffers */
@@ -1909,6 +1889,7 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci)
1909 b_assoc_buffers) { 1889 b_assoc_buffers) {
1910 set_buffer_uptodate(bh); 1890 set_buffer_uptodate(bh);
1911 clear_buffer_dirty(bh); 1891 clear_buffer_dirty(bh);
1892 clear_buffer_delay(bh);
1912 clear_buffer_nilfs_volatile(bh); 1893 clear_buffer_nilfs_volatile(bh);
1913 clear_buffer_nilfs_redirected(bh); 1894 clear_buffer_nilfs_redirected(bh);
1914 if (bh == segbuf->sb_super_root) { 1895 if (bh == segbuf->sb_super_root) {
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index e2dcc9c733f7..70dfdd532b83 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -47,7 +47,6 @@
47#include <linux/crc32.h> 47#include <linux/crc32.h>
48#include <linux/vfs.h> 48#include <linux/vfs.h>
49#include <linux/writeback.h> 49#include <linux/writeback.h>
50#include <linux/kobject.h>
51#include <linux/seq_file.h> 50#include <linux/seq_file.h>
52#include <linux/mount.h> 51#include <linux/mount.h>
53#include "nilfs.h" 52#include "nilfs.h"
@@ -111,12 +110,17 @@ void nilfs_error(struct super_block *sb, const char *function,
111 const char *fmt, ...) 110 const char *fmt, ...)
112{ 111{
113 struct nilfs_sb_info *sbi = NILFS_SB(sb); 112 struct nilfs_sb_info *sbi = NILFS_SB(sb);
113 struct va_format vaf;
114 va_list args; 114 va_list args;
115 115
116 va_start(args, fmt); 116 va_start(args, fmt);
117 printk(KERN_CRIT "NILFS error (device %s): %s: ", sb->s_id, function); 117
118 vprintk(fmt, args); 118 vaf.fmt = fmt;
119 printk("\n"); 119 vaf.va = &args;
120
121 printk(KERN_CRIT "NILFS error (device %s): %s: %pV\n",
122 sb->s_id, function, &vaf);
123
120 va_end(args); 124 va_end(args);
121 125
122 if (!(sb->s_flags & MS_RDONLY)) { 126 if (!(sb->s_flags & MS_RDONLY)) {
@@ -136,13 +140,17 @@ void nilfs_error(struct super_block *sb, const char *function,
136void nilfs_warning(struct super_block *sb, const char *function, 140void nilfs_warning(struct super_block *sb, const char *function,
137 const char *fmt, ...) 141 const char *fmt, ...)
138{ 142{
143 struct va_format vaf;
139 va_list args; 144 va_list args;
140 145
141 va_start(args, fmt); 146 va_start(args, fmt);
142 printk(KERN_WARNING "NILFS warning (device %s): %s: ", 147
143 sb->s_id, function); 148 vaf.fmt = fmt;
144 vprintk(fmt, args); 149 vaf.va = &args;
145 printk("\n"); 150
151 printk(KERN_WARNING "NILFS warning (device %s): %s: %pV\n",
152 sb->s_id, function, &vaf);
153
146 va_end(args); 154 va_end(args);
147} 155}
148 156
@@ -1010,11 +1018,11 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1010 struct nilfs_sb_info *sbi = NILFS_SB(sb); 1018 struct nilfs_sb_info *sbi = NILFS_SB(sb);
1011 struct the_nilfs *nilfs = sbi->s_nilfs; 1019 struct the_nilfs *nilfs = sbi->s_nilfs;
1012 unsigned long old_sb_flags; 1020 unsigned long old_sb_flags;
1013 struct nilfs_mount_options old_opts; 1021 unsigned long old_mount_opt;
1014 int err; 1022 int err;
1015 1023
1016 old_sb_flags = sb->s_flags; 1024 old_sb_flags = sb->s_flags;
1017 old_opts.mount_opt = sbi->s_mount_opt; 1025 old_mount_opt = sbi->s_mount_opt;
1018 1026
1019 if (!parse_options(data, sb, 1)) { 1027 if (!parse_options(data, sb, 1)) {
1020 err = -EINVAL; 1028 err = -EINVAL;
@@ -1083,7 +1091,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1083 1091
1084 restore_opts: 1092 restore_opts:
1085 sb->s_flags = old_sb_flags; 1093 sb->s_flags = old_sb_flags;
1086 sbi->s_mount_opt = old_opts.mount_opt; 1094 sbi->s_mount_opt = old_mount_opt;
1087 return err; 1095 return err;
1088} 1096}
1089 1097
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
index 0254be2d73c6..ad4ac607cf57 100644
--- a/fs/nilfs2/the_nilfs.c
+++ b/fs/nilfs2/the_nilfs.c
@@ -329,7 +329,6 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
329 printk(KERN_INFO "NILFS: recovery complete.\n"); 329 printk(KERN_INFO "NILFS: recovery complete.\n");
330 330
331 skip_recovery: 331 skip_recovery:
332 set_nilfs_loaded(nilfs);
333 nilfs_clear_recovery_info(&ri); 332 nilfs_clear_recovery_info(&ri);
334 sbi->s_super->s_flags = s_flags; 333 sbi->s_super->s_flags = s_flags;
335 return 0; 334 return 0;
@@ -651,12 +650,11 @@ int nilfs_discard_segments(struct the_nilfs *nilfs, __u64 *segnump,
651 650
652int nilfs_count_free_blocks(struct the_nilfs *nilfs, sector_t *nblocks) 651int nilfs_count_free_blocks(struct the_nilfs *nilfs, sector_t *nblocks)
653{ 652{
654 struct inode *dat = nilfs_dat_inode(nilfs);
655 unsigned long ncleansegs; 653 unsigned long ncleansegs;
656 654
657 down_read(&NILFS_MDT(dat)->mi_sem); /* XXX */ 655 down_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
658 ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile); 656 ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile);
659 up_read(&NILFS_MDT(dat)->mi_sem); /* XXX */ 657 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
660 *nblocks = (sector_t)ncleansegs * nilfs->ns_blocks_per_segment; 658 *nblocks = (sector_t)ncleansegs * nilfs->ns_blocks_per_segment;
661 return 0; 659 return 0;
662} 660}
diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h
index 69226e14b745..fd85e4c05c6b 100644
--- a/fs/nilfs2/the_nilfs.h
+++ b/fs/nilfs2/the_nilfs.h
@@ -36,8 +36,6 @@
36/* the_nilfs struct */ 36/* the_nilfs struct */
37enum { 37enum {
38 THE_NILFS_INIT = 0, /* Information from super_block is set */ 38 THE_NILFS_INIT = 0, /* Information from super_block is set */
39 THE_NILFS_LOADED, /* Roll-back/roll-forward has done and
40 the latest checkpoint was loaded */
41 THE_NILFS_DISCONTINUED, /* 'next' pointer chain has broken */ 39 THE_NILFS_DISCONTINUED, /* 'next' pointer chain has broken */
42 THE_NILFS_GC_RUNNING, /* gc process is running */ 40 THE_NILFS_GC_RUNNING, /* gc process is running */
43 THE_NILFS_SB_DIRTY, /* super block is dirty */ 41 THE_NILFS_SB_DIRTY, /* super block is dirty */
@@ -178,7 +176,6 @@ static inline int nilfs_##name(struct the_nilfs *nilfs) \
178} 176}
179 177
180THE_NILFS_FNS(INIT, init) 178THE_NILFS_FNS(INIT, init)
181THE_NILFS_FNS(LOADED, loaded)
182THE_NILFS_FNS(DISCONTINUED, discontinued) 179THE_NILFS_FNS(DISCONTINUED, discontinued)
183THE_NILFS_FNS(GC_RUNNING, gc_running) 180THE_NILFS_FNS(GC_RUNNING, gc_running)
184THE_NILFS_FNS(SB_DIRTY, sb_dirty) 181THE_NILFS_FNS(SB_DIRTY, sb_dirty)
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 30ac27345586..0a12eb89cd32 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -19,6 +19,7 @@
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/sched.h> 20#include <linux/sched.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/sysfs.h>
22#include <linux/xattr.h> 23#include <linux/xattr.h>
23#include <linux/security.h> 24#include <linux/security.h>
24#include "sysfs.h" 25#include "sysfs.h"
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index ffaaa816bfba..3d28af31d863 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <linux/lockdep.h> 11#include <linux/lockdep.h>
12#include <linux/kobject_ns.h>
12#include <linux/fs.h> 13#include <linux/fs.h>
13 14
14struct sysfs_open_dirent; 15struct sysfs_open_dirent;
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index bd69d79208de..05cbad03c5ab 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -67,7 +67,8 @@
67 * Align to a 32 byte boundary equal to the 67 * Align to a 32 byte boundary equal to the
68 * alignment gcc 4.5 uses for a struct 68 * alignment gcc 4.5 uses for a struct
69 */ 69 */
70#define STRUCT_ALIGN() . = ALIGN(32) 70#define STRUCT_ALIGNMENT 32
71#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
71 72
72/* The actual configuration determine if the init/exit sections 73/* The actual configuration determine if the init/exit sections
73 * are handled as text/data or they can be discarded (which 74 * are handled as text/data or they can be discarded (which
@@ -146,6 +147,13 @@
146#define TRACE_SYSCALLS() 147#define TRACE_SYSCALLS()
147#endif 148#endif
148 149
150
151#define KERNEL_DTB() \
152 STRUCT_ALIGN(); \
153 VMLINUX_SYMBOL(__dtb_start) = .; \
154 *(.dtb.init.rodata) \
155 VMLINUX_SYMBOL(__dtb_end) = .;
156
149/* .data section */ 157/* .data section */
150#define DATA_DATA \ 158#define DATA_DATA \
151 *(.data) \ 159 *(.data) \
@@ -468,7 +476,8 @@
468 MCOUNT_REC() \ 476 MCOUNT_REC() \
469 DEV_DISCARD(init.rodata) \ 477 DEV_DISCARD(init.rodata) \
470 CPU_DISCARD(init.rodata) \ 478 CPU_DISCARD(init.rodata) \
471 MEM_DISCARD(init.rodata) 479 MEM_DISCARD(init.rodata) \
480 KERNEL_DTB()
472 481
473#define INIT_TEXT \ 482#define INIT_TEXT \
474 *(.init.text) \ 483 *(.init.text) \
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index a354c199ab98..d1580c17cab3 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -20,15 +20,18 @@ header-y += wimax/
20objhdr-y += version.h 20objhdr-y += version.h
21 21
22ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/a.out.h \ 22ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/a.out.h \
23 $(srctree)/include/asm-$(SRCARCH)/a.out.h),) 23 $(srctree)/include/asm-$(SRCARCH)/a.out.h \
24 $(INSTALL_HDR_PATH)/include/asm-*/a.out.h),)
24header-y += a.out.h 25header-y += a.out.h
25endif 26endif
26ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/kvm.h \ 27ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/kvm.h \
27 $(srctree)/include/asm-$(SRCARCH)/kvm.h),) 28 $(srctree)/include/asm-$(SRCARCH)/kvm.h \
29 $(INSTALL_HDR_PATH)/include/asm-*/kvm.h),)
28header-y += kvm.h 30header-y += kvm.h
29endif 31endif
30ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/kvm_para.h \ 32ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/kvm_para.h \
31 $(srctree)/include/asm-$(SRCARCH)/kvm_para.h),) 33 $(srctree)/include/asm-$(SRCARCH)/kvm_para.h \
34 $(INSTALL_HDR_PATH)/include/asm-*/kvm_para.h),)
32header-y += kvm_para.h 35header-y += kvm_para.h
33endif 36endif
34 37
diff --git a/include/linux/audit.h b/include/linux/audit.h
index 8b5c0620abf9..359df0487690 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -372,6 +372,7 @@ struct audit_buffer;
372struct audit_context; 372struct audit_context;
373struct inode; 373struct inode;
374struct netlink_skb_parms; 374struct netlink_skb_parms;
375struct path;
375struct linux_binprm; 376struct linux_binprm;
376struct mq_attr; 377struct mq_attr;
377struct mqstat; 378struct mqstat;
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index bd07758943e0..59fcd24b1468 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -307,7 +307,7 @@ extern struct dentry *__d_lookup_rcu(struct dentry *parent, struct qstr *name,
307 * __d_rcu_to_refcount - take a refcount on dentry if sequence check is ok 307 * __d_rcu_to_refcount - take a refcount on dentry if sequence check is ok
308 * @dentry: dentry to take a ref on 308 * @dentry: dentry to take a ref on
309 * @seq: seqcount to verify against 309 * @seq: seqcount to verify against
310 * @Returns: 0 on failure, else 1. 310 * Returns: 0 on failure, else 1.
311 * 311 *
312 * __d_rcu_to_refcount operates on a dentry,seq pair that was returned 312 * __d_rcu_to_refcount operates on a dentry,seq pair that was returned
313 * by __d_lookup_rcu, to get a reference on an rcu-walk dentry. 313 * by __d_lookup_rcu, to get a reference on an rcu-walk dentry.
diff --git a/include/linux/dcookies.h b/include/linux/dcookies.h
index 24c806f12a6c..5ac3bdd5cee6 100644
--- a/include/linux/dcookies.h
+++ b/include/linux/dcookies.h
@@ -13,10 +13,10 @@
13#ifdef CONFIG_PROFILING 13#ifdef CONFIG_PROFILING
14 14
15#include <linux/dcache.h> 15#include <linux/dcache.h>
16#include <linux/path.h>
17#include <linux/types.h> 16#include <linux/types.h>
18 17
19struct dcookie_user; 18struct dcookie_user;
19struct path;
20 20
21/** 21/**
22 * dcookie_register - register a user of dcookies 22 * dcookie_register - register a user of dcookies
diff --git a/include/linux/device.h b/include/linux/device.h
index dd4895313468..d96af9701d60 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -197,6 +197,7 @@ struct class {
197 197
198 struct class_attribute *class_attrs; 198 struct class_attribute *class_attrs;
199 struct device_attribute *dev_attrs; 199 struct device_attribute *dev_attrs;
200 struct bin_attribute *dev_bin_attrs;
200 struct kobject *dev_kobj; 201 struct kobject *dev_kobj;
201 202
202 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); 203 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
@@ -508,13 +509,13 @@ static inline int device_is_registered(struct device *dev)
508 509
509static inline void device_enable_async_suspend(struct device *dev) 510static inline void device_enable_async_suspend(struct device *dev)
510{ 511{
511 if (dev->power.status == DPM_ON) 512 if (!dev->power.in_suspend)
512 dev->power.async_suspend = true; 513 dev->power.async_suspend = true;
513} 514}
514 515
515static inline void device_disable_async_suspend(struct device *dev) 516static inline void device_disable_async_suspend(struct device *dev)
516{ 517{
517 if (dev->power.status == DPM_ON) 518 if (!dev->power.in_suspend)
518 dev->power.async_suspend = false; 519 dev->power.async_suspend = false;
519} 520}
520 521
diff --git a/include/linux/firewire.h b/include/linux/firewire.h
index 1cd637ef62d2..9a3f5f9383f6 100644
--- a/include/linux/firewire.h
+++ b/include/linux/firewire.h
@@ -302,9 +302,9 @@ struct fw_packet {
302struct fw_transaction { 302struct fw_transaction {
303 int node_id; /* The generation is implied; it is always the current. */ 303 int node_id; /* The generation is implied; it is always the current. */
304 int tlabel; 304 int tlabel;
305 int timestamp;
306 struct list_head link; 305 struct list_head link;
307 struct fw_card *card; 306 struct fw_card *card;
307 bool is_split_transaction;
308 struct timer_list split_timeout_timer; 308 struct timer_list split_timeout_timer;
309 309
310 struct fw_packet packet; 310 struct fw_packet packet;
diff --git a/include/linux/firmware-map.h b/include/linux/firmware-map.h
index c6dcc1dfe781..43fe52fcef0f 100644
--- a/include/linux/firmware-map.h
+++ b/include/linux/firmware-map.h
@@ -17,7 +17,6 @@
17#define _LINUX_FIRMWARE_MAP_H 17#define _LINUX_FIRMWARE_MAP_H
18 18
19#include <linux/list.h> 19#include <linux/list.h>
20#include <linux/kobject.h>
21 20
22/* 21/*
23 * provide a dummy interface if CONFIG_FIRMWARE_MEMMAP is disabled 22 * provide a dummy interface if CONFIG_FIRMWARE_MEMMAP is disabled
diff --git a/include/linux/fs.h b/include/linux/fs.h
index baf3e556ff0e..f84d9928bdb1 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -382,7 +382,6 @@ struct inodes_stat_t {
382#include <linux/path.h> 382#include <linux/path.h>
383#include <linux/stat.h> 383#include <linux/stat.h>
384#include <linux/cache.h> 384#include <linux/cache.h>
385#include <linux/kobject.h>
386#include <linux/list.h> 385#include <linux/list.h>
387#include <linux/radix-tree.h> 386#include <linux/radix-tree.h>
388#include <linux/prio_tree.h> 387#include <linux/prio_tree.h>
@@ -402,6 +401,7 @@ struct hd_geometry;
402struct iovec; 401struct iovec;
403struct nameidata; 402struct nameidata;
404struct kiocb; 403struct kiocb;
404struct kobject;
405struct pipe_inode_info; 405struct pipe_inode_info;
406struct poll_table_struct; 406struct poll_table_struct;
407struct kstatfs; 407struct kstatfs;
diff --git a/include/linux/fuse.h b/include/linux/fuse.h
index c3c578e09833..d464de53db43 100644
--- a/include/linux/fuse.h
+++ b/include/linux/fuse.h
@@ -41,6 +41,12 @@
41 * 7.15 41 * 7.15
42 * - add store notify 42 * - add store notify
43 * - add retrieve notify 43 * - add retrieve notify
44 *
45 * 7.16
46 * - add BATCH_FORGET request
47 * - FUSE_IOCTL_UNRESTRICTED shall now return with array of 'struct
48 * fuse_ioctl_iovec' instead of ambiguous 'struct iovec'
49 * - add FUSE_IOCTL_32BIT flag
44 */ 50 */
45 51
46#ifndef _LINUX_FUSE_H 52#ifndef _LINUX_FUSE_H
@@ -72,7 +78,7 @@
72#define FUSE_KERNEL_VERSION 7 78#define FUSE_KERNEL_VERSION 7
73 79
74/** Minor version number of this interface */ 80/** Minor version number of this interface */
75#define FUSE_KERNEL_MINOR_VERSION 15 81#define FUSE_KERNEL_MINOR_VERSION 16
76 82
77/** The node ID of the root inode */ 83/** The node ID of the root inode */
78#define FUSE_ROOT_ID 1 84#define FUSE_ROOT_ID 1
@@ -200,12 +206,14 @@ struct fuse_file_lock {
200 * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine 206 * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine
201 * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed 207 * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed
202 * FUSE_IOCTL_RETRY: retry with new iovecs 208 * FUSE_IOCTL_RETRY: retry with new iovecs
209 * FUSE_IOCTL_32BIT: 32bit ioctl
203 * 210 *
204 * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs 211 * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs
205 */ 212 */
206#define FUSE_IOCTL_COMPAT (1 << 0) 213#define FUSE_IOCTL_COMPAT (1 << 0)
207#define FUSE_IOCTL_UNRESTRICTED (1 << 1) 214#define FUSE_IOCTL_UNRESTRICTED (1 << 1)
208#define FUSE_IOCTL_RETRY (1 << 2) 215#define FUSE_IOCTL_RETRY (1 << 2)
216#define FUSE_IOCTL_32BIT (1 << 3)
209 217
210#define FUSE_IOCTL_MAX_IOV 256 218#define FUSE_IOCTL_MAX_IOV 256
211 219
@@ -256,6 +264,7 @@ enum fuse_opcode {
256 FUSE_IOCTL = 39, 264 FUSE_IOCTL = 39,
257 FUSE_POLL = 40, 265 FUSE_POLL = 40,
258 FUSE_NOTIFY_REPLY = 41, 266 FUSE_NOTIFY_REPLY = 41,
267 FUSE_BATCH_FORGET = 42,
259 268
260 /* CUSE specific operations */ 269 /* CUSE specific operations */
261 CUSE_INIT = 4096, 270 CUSE_INIT = 4096,
@@ -290,6 +299,16 @@ struct fuse_forget_in {
290 __u64 nlookup; 299 __u64 nlookup;
291}; 300};
292 301
302struct fuse_forget_one {
303 __u64 nodeid;
304 __u64 nlookup;
305};
306
307struct fuse_batch_forget_in {
308 __u32 count;
309 __u32 dummy;
310};
311
293struct fuse_getattr_in { 312struct fuse_getattr_in {
294 __u32 getattr_flags; 313 __u32 getattr_flags;
295 __u32 dummy; 314 __u32 dummy;
@@ -510,6 +529,11 @@ struct fuse_ioctl_in {
510 __u32 out_size; 529 __u32 out_size;
511}; 530};
512 531
532struct fuse_ioctl_iovec {
533 __u64 base;
534 __u64 len;
535};
536
513struct fuse_ioctl_out { 537struct fuse_ioctl_out {
514 __s32 result; 538 __s32 result;
515 __u32 flags; 539 __u32 flags;
diff --git a/include/linux/hid.h b/include/linux/hid.h
index bb0f56f5c01e..20b9801f669b 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -820,6 +820,49 @@ static inline void hid_hw_stop(struct hid_device *hdev)
820 hdev->ll_driver->stop(hdev); 820 hdev->ll_driver->stop(hdev);
821} 821}
822 822
823/**
824 * hid_hw_open - signal underlaying HW to start delivering events
825 *
826 * @hdev: hid device
827 *
828 * Tell underlying HW to start delivering events from the device.
829 * This function should be called sometime after successful call
830 * to hid_hiw_start().
831 */
832static inline int __must_check hid_hw_open(struct hid_device *hdev)
833{
834 return hdev->ll_driver->open(hdev);
835}
836
837/**
838 * hid_hw_close - signal underlaying HW to stop delivering events
839 *
840 * @hdev: hid device
841 *
842 * This function indicates that we are not interested in the events
843 * from this device anymore. Delivery of events may or may not stop,
844 * depending on the number of users still outstanding.
845 */
846static inline void hid_hw_close(struct hid_device *hdev)
847{
848 hdev->ll_driver->close(hdev);
849}
850
851/**
852 * hid_hw_power - requests underlying HW to go into given power mode
853 *
854 * @hdev: hid device
855 * @level: requested power level (one of %PM_HINT_* defines)
856 *
857 * This function requests underlying hardware to enter requested power
858 * mode.
859 */
860
861static inline int hid_hw_power(struct hid_device *hdev, int level)
862{
863 return hdev->ll_driver->power ? hdev->ll_driver->power(hdev, level) : 0;
864}
865
823void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, 866void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
824 int interrupt); 867 int interrupt);
825 868
@@ -838,12 +881,32 @@ int hid_pidff_init(struct hid_device *hid);
838#define hid_pidff_init NULL 881#define hid_pidff_init NULL
839#endif 882#endif
840 883
841#define dbg_hid(format, arg...) if (hid_debug) \ 884#define dbg_hid(format, arg...) \
842 printk(KERN_DEBUG "%s: " format ,\ 885do { \
843 __FILE__ , ## arg) 886 if (hid_debug) \
844#define err_hid(format, arg...) printk(KERN_ERR "%s: " format "\n" , \ 887 printk(KERN_DEBUG "%s: " format, __FILE__, ##arg); \
845 __FILE__ , ## arg) 888} while (0)
846#endif /* HID_FF */ 889
890#define hid_printk(level, hid, fmt, arg...) \
891 dev_printk(level, &(hid)->dev, fmt, ##arg)
892#define hid_emerg(hid, fmt, arg...) \
893 dev_emerg(&(hid)->dev, fmt, ##arg)
894#define hid_crit(hid, fmt, arg...) \
895 dev_crit(&(hid)->dev, fmt, ##arg)
896#define hid_alert(hid, fmt, arg...) \
897 dev_alert(&(hid)->dev, fmt, ##arg)
898#define hid_err(hid, fmt, arg...) \
899 dev_err(&(hid)->dev, fmt, ##arg)
900#define hid_notice(hid, fmt, arg...) \
901 dev_notice(&(hid)->dev, fmt, ##arg)
902#define hid_warn(hid, fmt, arg...) \
903 dev_warn(&(hid)->dev, fmt, ##arg)
904#define hid_info(hid, fmt, arg...) \
905 dev_info(&(hid)->dev, fmt, ##arg)
906#define hid_dbg(hid, fmt, arg...) \
907 dev_dbg(&(hid)->dev, fmt, ##arg)
908
909#endif /* __KERNEL__ */
847 910
848#endif 911#endif
849 912
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 330586ffffbb..f376ddc64c4d 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -131,7 +131,6 @@ struct hrtimer_sleeper {
131 * @index: clock type index for per_cpu support when moving a 131 * @index: clock type index for per_cpu support when moving a
132 * timer to a base on another cpu. 132 * timer to a base on another cpu.
133 * @active: red black tree root node for the active timers 133 * @active: red black tree root node for the active timers
134 * @first: pointer to the timer node which expires first
135 * @resolution: the resolution of the clock, in nanoseconds 134 * @resolution: the resolution of the clock, in nanoseconds
136 * @get_time: function to retrieve the current time of the clock 135 * @get_time: function to retrieve the current time of the clock
137 * @softirq_time: the time when running the hrtimer queue in the softirq 136 * @softirq_time: the time when running the hrtimer queue in the softirq
diff --git a/include/linux/libata.h b/include/linux/libata.h
index d947b1231662..c9c5d7ad1a2b 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -996,8 +996,7 @@ extern int ata_sas_port_init(struct ata_port *);
996extern int ata_sas_port_start(struct ata_port *ap); 996extern int ata_sas_port_start(struct ata_port *ap);
997extern void ata_sas_port_stop(struct ata_port *ap); 997extern void ata_sas_port_stop(struct ata_port *ap);
998extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *); 998extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
999extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), 999extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
1000 struct ata_port *ap);
1001extern int sata_scr_valid(struct ata_link *link); 1000extern int sata_scr_valid(struct ata_link *link);
1002extern int sata_scr_read(struct ata_link *link, int reg, u32 *val); 1001extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
1003extern int sata_scr_write(struct ata_link *link, int reg, u32 val); 1002extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
@@ -1040,8 +1039,7 @@ extern unsigned int ata_do_dev_read_id(struct ata_device *dev,
1040 struct ata_taskfile *tf, u16 *id); 1039 struct ata_taskfile *tf, u16 *id);
1041extern void ata_qc_complete(struct ata_queued_cmd *qc); 1040extern void ata_qc_complete(struct ata_queued_cmd *qc);
1042extern int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active); 1041extern int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active);
1043extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd, 1042extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);
1044 void (*done)(struct scsi_cmnd *));
1045extern int ata_std_bios_param(struct scsi_device *sdev, 1043extern int ata_std_bios_param(struct scsi_device *sdev,
1046 struct block_device *bdev, 1044 struct block_device *bdev,
1047 sector_t capacity, int geom[]); 1045 sector_t capacity, int geom[]);
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 8aea06f0564c..2feda6ee6140 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -3,7 +3,7 @@
3#include <linux/ioport.h> 3#include <linux/ioport.h>
4#include <linux/of.h> 4#include <linux/of.h>
5 5
6extern u64 of_translate_address(struct device_node *np, const u32 *addr); 6extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
7extern int of_address_to_resource(struct device_node *dev, int index, 7extern int of_address_to_resource(struct device_node *dev, int index,
8 struct resource *r); 8 struct resource *r);
9extern void __iomem *of_iomap(struct device_node *device, int index); 9extern void __iomem *of_iomap(struct device_node *device, int index);
@@ -21,7 +21,7 @@ static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
21#endif 21#endif
22 22
23#ifdef CONFIG_PCI 23#ifdef CONFIG_PCI
24extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no, 24extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
25 u64 *size, unsigned int *flags); 25 u64 *size, unsigned int *flags);
26extern int of_pci_address_to_resource(struct device_node *dev, int bar, 26extern int of_pci_address_to_resource(struct device_node *dev, int bar,
27 struct resource *r); 27 struct resource *r);
@@ -32,7 +32,7 @@ static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
32 return -ENOSYS; 32 return -ENOSYS;
33} 33}
34 34
35static inline const u32 *of_get_pci_address(struct device_node *dev, 35static inline const __be32 *of_get_pci_address(struct device_node *dev,
36 int bar_no, u64 *size, unsigned int *flags) 36 int bar_no, u64 *size, unsigned int *flags)
37{ 37{
38 return NULL; 38 return NULL;
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index 7bbf5b328438..0ef22a1f129e 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -58,6 +58,23 @@ struct boot_param_header {
58}; 58};
59 59
60#if defined(CONFIG_OF_FLATTREE) 60#if defined(CONFIG_OF_FLATTREE)
61
62struct device_node;
63
64/* For scanning an arbitrary device-tree at any time */
65extern char *of_fdt_get_string(struct boot_param_header *blob, u32 offset);
66extern void *of_fdt_get_property(struct boot_param_header *blob,
67 unsigned long node,
68 const char *name,
69 unsigned long *size);
70extern int of_fdt_is_compatible(struct boot_param_header *blob,
71 unsigned long node,
72 const char *compat);
73extern int of_fdt_match(struct boot_param_header *blob, unsigned long node,
74 const char **compat);
75extern void of_fdt_unflatten_tree(unsigned long *blob,
76 struct device_node **mynodes);
77
61/* TBD: Temporary export of fdt globals - remove when code fully merged */ 78/* TBD: Temporary export of fdt globals - remove when code fully merged */
62extern int __initdata dt_root_addr_cells; 79extern int __initdata dt_root_addr_cells;
63extern int __initdata dt_root_size_cells; 80extern int __initdata dt_root_size_cells;
@@ -71,6 +88,7 @@ extern int of_scan_flat_dt(int (*it)(unsigned long node, const char *uname,
71extern void *of_get_flat_dt_prop(unsigned long node, const char *name, 88extern void *of_get_flat_dt_prop(unsigned long node, const char *name,
72 unsigned long *size); 89 unsigned long *size);
73extern int of_flat_dt_is_compatible(unsigned long node, const char *name); 90extern int of_flat_dt_is_compatible(unsigned long node, const char *name);
91extern int of_flat_dt_match(unsigned long node, const char **matches);
74extern unsigned long of_get_flat_dt_root(void); 92extern unsigned long of_get_flat_dt_root(void);
75 93
76extern int early_init_dt_scan_chosen(unsigned long node, const char *uname, 94extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
diff --git a/include/linux/of_net.h b/include/linux/of_net.h
new file mode 100644
index 000000000000..e913081fb52a
--- /dev/null
+++ b/include/linux/of_net.h
@@ -0,0 +1,15 @@
1/*
2 * OF helpers for network devices.
3 *
4 * This file is released under the GPLv2
5 */
6
7#ifndef __LINUX_OF_NET_H
8#define __LINUX_OF_NET_H
9
10#ifdef CONFIG_OF_NET
11#include <linux/of.h>
12extern const void *of_get_mac_address(struct device_node *np);
13#endif
14
15#endif /* __LINUX_OF_NET_H */
diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
index bb27d7ec2fb9..77257c92155a 100644
--- a/include/linux/pipe_fs_i.h
+++ b/include/linux/pipe_fs_i.h
@@ -30,6 +30,7 @@ struct pipe_buffer {
30 * struct pipe_inode_info - a linux kernel pipe 30 * struct pipe_inode_info - a linux kernel pipe
31 * @wait: reader/writer wait point in case of empty/full pipe 31 * @wait: reader/writer wait point in case of empty/full pipe
32 * @nrbufs: the number of non-empty pipe buffers in this pipe 32 * @nrbufs: the number of non-empty pipe buffers in this pipe
33 * @buffers: total number of buffers (should be a power of 2)
33 * @curbuf: the current pipe buffer entry 34 * @curbuf: the current pipe buffer entry
34 * @tmp_page: cached released page 35 * @tmp_page: cached released page
35 * @readers: number of current readers of this pipe 36 * @readers: number of current readers of this pipe
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 40f3f45702ba..dd9c7ab38270 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -367,45 +367,6 @@ extern struct dev_pm_ops generic_subsys_pm_ops;
367 { .event = PM_EVENT_AUTO_RESUME, }) 367 { .event = PM_EVENT_AUTO_RESUME, })
368 368
369/** 369/**
370 * Device power management states
371 *
372 * These state labels are used internally by the PM core to indicate the current
373 * status of a device with respect to the PM core operations.
374 *
375 * DPM_ON Device is regarded as operational. Set this way
376 * initially and when ->complete() is about to be called.
377 * Also set when ->prepare() fails.
378 *
379 * DPM_PREPARING Device is going to be prepared for a PM transition. Set
380 * when ->prepare() is about to be called.
381 *
382 * DPM_RESUMING Device is going to be resumed. Set when ->resume(),
383 * ->thaw(), or ->restore() is about to be called.
384 *
385 * DPM_SUSPENDING Device has been prepared for a power transition. Set
386 * when ->prepare() has just succeeded.
387 *
388 * DPM_OFF Device is regarded as inactive. Set immediately after
389 * ->suspend(), ->freeze(), or ->poweroff() has succeeded.
390 * Also set when ->resume()_noirq, ->thaw_noirq(), or
391 * ->restore_noirq() is about to be called.
392 *
393 * DPM_OFF_IRQ Device is in a "deep sleep". Set immediately after
394 * ->suspend_noirq(), ->freeze_noirq(), or
395 * ->poweroff_noirq() has just succeeded.
396 */
397
398enum dpm_state {
399 DPM_INVALID,
400 DPM_ON,
401 DPM_PREPARING,
402 DPM_RESUMING,
403 DPM_SUSPENDING,
404 DPM_OFF,
405 DPM_OFF_IRQ,
406};
407
408/**
409 * Device run-time power management status. 370 * Device run-time power management status.
410 * 371 *
411 * These status labels are used internally by the PM core to indicate the 372 * These status labels are used internally by the PM core to indicate the
@@ -463,8 +424,8 @@ struct wakeup_source;
463struct dev_pm_info { 424struct dev_pm_info {
464 pm_message_t power_state; 425 pm_message_t power_state;
465 unsigned int can_wakeup:1; 426 unsigned int can_wakeup:1;
466 unsigned async_suspend:1; 427 unsigned int async_suspend:1;
467 enum dpm_state status; /* Owned by the PM core */ 428 unsigned int in_suspend:1; /* Owned by the PM core */
468 spinlock_t lock; 429 spinlock_t lock;
469#ifdef CONFIG_PM_SLEEP 430#ifdef CONFIG_PM_SLEEP
470 struct list_head entry; 431 struct list_head entry;
@@ -486,6 +447,7 @@ struct dev_pm_info {
486 unsigned int run_wake:1; 447 unsigned int run_wake:1;
487 unsigned int runtime_auto:1; 448 unsigned int runtime_auto:1;
488 unsigned int no_callbacks:1; 449 unsigned int no_callbacks:1;
450 unsigned int irq_safe:1;
489 unsigned int use_autosuspend:1; 451 unsigned int use_autosuspend:1;
490 unsigned int timer_autosuspends:1; 452 unsigned int timer_autosuspends:1;
491 enum rpm_request request; 453 enum rpm_request request;
@@ -610,4 +572,11 @@ extern unsigned int pm_flags;
610#define PM_APM 1 572#define PM_APM 1
611#define PM_ACPI 2 573#define PM_ACPI 2
612 574
575extern int pm_generic_suspend(struct device *dev);
576extern int pm_generic_resume(struct device *dev);
577extern int pm_generic_freeze(struct device *dev);
578extern int pm_generic_thaw(struct device *dev);
579extern int pm_generic_restore(struct device *dev);
580extern int pm_generic_poweroff(struct device *dev);
581
613#endif /* _LINUX_PM_H */ 582#endif /* _LINUX_PM_H */
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index d19f1cca7f74..d34f067e2a7f 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -40,6 +40,7 @@ extern int pm_generic_runtime_idle(struct device *dev);
40extern int pm_generic_runtime_suspend(struct device *dev); 40extern int pm_generic_runtime_suspend(struct device *dev);
41extern int pm_generic_runtime_resume(struct device *dev); 41extern int pm_generic_runtime_resume(struct device *dev);
42extern void pm_runtime_no_callbacks(struct device *dev); 42extern void pm_runtime_no_callbacks(struct device *dev);
43extern void pm_runtime_irq_safe(struct device *dev);
43extern void __pm_runtime_use_autosuspend(struct device *dev, bool use); 44extern void __pm_runtime_use_autosuspend(struct device *dev, bool use);
44extern void pm_runtime_set_autosuspend_delay(struct device *dev, int delay); 45extern void pm_runtime_set_autosuspend_delay(struct device *dev, int delay);
45extern unsigned long pm_runtime_autosuspend_expiration(struct device *dev); 46extern unsigned long pm_runtime_autosuspend_expiration(struct device *dev);
@@ -81,6 +82,11 @@ static inline bool pm_runtime_suspended(struct device *dev)
81 && !dev->power.disable_depth; 82 && !dev->power.disable_depth;
82} 83}
83 84
85static inline bool pm_runtime_enabled(struct device *dev)
86{
87 return !dev->power.disable_depth;
88}
89
84static inline void pm_runtime_mark_last_busy(struct device *dev) 90static inline void pm_runtime_mark_last_busy(struct device *dev)
85{ 91{
86 ACCESS_ONCE(dev->power.last_busy) = jiffies; 92 ACCESS_ONCE(dev->power.last_busy) = jiffies;
@@ -119,11 +125,13 @@ static inline void pm_runtime_put_noidle(struct device *dev) {}
119static inline bool device_run_wake(struct device *dev) { return false; } 125static inline bool device_run_wake(struct device *dev) { return false; }
120static inline void device_set_run_wake(struct device *dev, bool enable) {} 126static inline void device_set_run_wake(struct device *dev, bool enable) {}
121static inline bool pm_runtime_suspended(struct device *dev) { return false; } 127static inline bool pm_runtime_suspended(struct device *dev) { return false; }
128static inline bool pm_runtime_enabled(struct device *dev) { return false; }
122 129
123static inline int pm_generic_runtime_idle(struct device *dev) { return 0; } 130static inline int pm_generic_runtime_idle(struct device *dev) { return 0; }
124static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; } 131static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; }
125static inline int pm_generic_runtime_resume(struct device *dev) { return 0; } 132static inline int pm_generic_runtime_resume(struct device *dev) { return 0; }
126static inline void pm_runtime_no_callbacks(struct device *dev) {} 133static inline void pm_runtime_no_callbacks(struct device *dev) {}
134static inline void pm_runtime_irq_safe(struct device *dev) {}
127 135
128static inline void pm_runtime_mark_last_busy(struct device *dev) {} 136static inline void pm_runtime_mark_last_busy(struct device *dev) {}
129static inline void __pm_runtime_use_autosuspend(struct device *dev, 137static inline void __pm_runtime_use_autosuspend(struct device *dev,
@@ -196,6 +204,11 @@ static inline int pm_runtime_put_sync(struct device *dev)
196 return __pm_runtime_idle(dev, RPM_GET_PUT); 204 return __pm_runtime_idle(dev, RPM_GET_PUT);
197} 205}
198 206
207static inline int pm_runtime_put_sync_suspend(struct device *dev)
208{
209 return __pm_runtime_suspend(dev, RPM_GET_PUT);
210}
211
199static inline int pm_runtime_put_sync_autosuspend(struct device *dev) 212static inline int pm_runtime_put_sync_autosuspend(struct device *dev)
200{ 213{
201 return __pm_runtime_suspend(dev, RPM_GET_PUT | RPM_AUTO); 214 return __pm_runtime_suspend(dev, RPM_GET_PUT | RPM_AUTO);
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 341acbbc434a..abc527aa8550 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -70,7 +70,6 @@ struct sched_param {
70#include <linux/smp.h> 70#include <linux/smp.h>
71#include <linux/sem.h> 71#include <linux/sem.h>
72#include <linux/signal.h> 72#include <linux/signal.h>
73#include <linux/path.h>
74#include <linux/compiler.h> 73#include <linux/compiler.h>
75#include <linux/completion.h> 74#include <linux/completion.h>
76#include <linux/pid.h> 75#include <linux/pid.h>
@@ -88,7 +87,6 @@ struct sched_param {
88#include <linux/timer.h> 87#include <linux/timer.h>
89#include <linux/hrtimer.h> 88#include <linux/hrtimer.h>
90#include <linux/task_io_accounting.h> 89#include <linux/task_io_accounting.h>
91#include <linux/kobject.h>
92#include <linux/latencytop.h> 90#include <linux/latencytop.h>
93#include <linux/cred.h> 91#include <linux/cred.h>
94 92
diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
index 791a502f6906..83203ae9390b 100644
--- a/include/linux/slab_def.h
+++ b/include/linux/slab_def.h
@@ -138,11 +138,12 @@ void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
138void *__kmalloc(size_t size, gfp_t flags); 138void *__kmalloc(size_t size, gfp_t flags);
139 139
140#ifdef CONFIG_TRACING 140#ifdef CONFIG_TRACING
141extern void *kmem_cache_alloc_notrace(struct kmem_cache *cachep, gfp_t flags); 141extern void *kmem_cache_alloc_trace(size_t size,
142 struct kmem_cache *cachep, gfp_t flags);
142extern size_t slab_buffer_size(struct kmem_cache *cachep); 143extern size_t slab_buffer_size(struct kmem_cache *cachep);
143#else 144#else
144static __always_inline void * 145static __always_inline void *
145kmem_cache_alloc_notrace(struct kmem_cache *cachep, gfp_t flags) 146kmem_cache_alloc_trace(size_t size, struct kmem_cache *cachep, gfp_t flags)
146{ 147{
147 return kmem_cache_alloc(cachep, flags); 148 return kmem_cache_alloc(cachep, flags);
148} 149}
@@ -179,10 +180,7 @@ found:
179#endif 180#endif
180 cachep = malloc_sizes[i].cs_cachep; 181 cachep = malloc_sizes[i].cs_cachep;
181 182
182 ret = kmem_cache_alloc_notrace(cachep, flags); 183 ret = kmem_cache_alloc_trace(size, cachep, flags);
183
184 trace_kmalloc(_THIS_IP_, ret,
185 size, slab_buffer_size(cachep), flags);
186 184
187 return ret; 185 return ret;
188 } 186 }
@@ -194,14 +192,16 @@ extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
194extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node); 192extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
195 193
196#ifdef CONFIG_TRACING 194#ifdef CONFIG_TRACING
197extern void *kmem_cache_alloc_node_notrace(struct kmem_cache *cachep, 195extern void *kmem_cache_alloc_node_trace(size_t size,
198 gfp_t flags, 196 struct kmem_cache *cachep,
199 int nodeid); 197 gfp_t flags,
198 int nodeid);
200#else 199#else
201static __always_inline void * 200static __always_inline void *
202kmem_cache_alloc_node_notrace(struct kmem_cache *cachep, 201kmem_cache_alloc_node_trace(size_t size,
203 gfp_t flags, 202 struct kmem_cache *cachep,
204 int nodeid) 203 gfp_t flags,
204 int nodeid)
205{ 205{
206 return kmem_cache_alloc_node(cachep, flags, nodeid); 206 return kmem_cache_alloc_node(cachep, flags, nodeid);
207} 207}
@@ -210,7 +210,6 @@ kmem_cache_alloc_node_notrace(struct kmem_cache *cachep,
210static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) 210static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
211{ 211{
212 struct kmem_cache *cachep; 212 struct kmem_cache *cachep;
213 void *ret;
214 213
215 if (__builtin_constant_p(size)) { 214 if (__builtin_constant_p(size)) {
216 int i = 0; 215 int i = 0;
@@ -234,13 +233,7 @@ found:
234#endif 233#endif
235 cachep = malloc_sizes[i].cs_cachep; 234 cachep = malloc_sizes[i].cs_cachep;
236 235
237 ret = kmem_cache_alloc_node_notrace(cachep, flags, node); 236 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
238
239 trace_kmalloc_node(_THIS_IP_, ret,
240 size, slab_buffer_size(cachep),
241 flags, node);
242
243 return ret;
244 } 237 }
245 return __kmalloc_node(size, flags, node); 238 return __kmalloc_node(size, flags, node);
246} 239}
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index e4f5ed180b9b..8b6e8ae5d5ca 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -10,9 +10,8 @@
10#include <linux/gfp.h> 10#include <linux/gfp.h>
11#include <linux/workqueue.h> 11#include <linux/workqueue.h>
12#include <linux/kobject.h> 12#include <linux/kobject.h>
13#include <linux/kmemleak.h>
14 13
15#include <trace/events/kmem.h> 14#include <linux/kmemleak.h>
16 15
17enum stat_item { 16enum stat_item {
18 ALLOC_FASTPATH, /* Allocation from cpu slab */ 17 ALLOC_FASTPATH, /* Allocation from cpu slab */
@@ -216,31 +215,40 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
216void *kmem_cache_alloc(struct kmem_cache *, gfp_t); 215void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
217void *__kmalloc(size_t size, gfp_t flags); 216void *__kmalloc(size_t size, gfp_t flags);
218 217
218static __always_inline void *
219kmalloc_order(size_t size, gfp_t flags, unsigned int order)
220{
221 void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order);
222 kmemleak_alloc(ret, size, 1, flags);
223 return ret;
224}
225
219#ifdef CONFIG_TRACING 226#ifdef CONFIG_TRACING
220extern void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags); 227extern void *
228kmem_cache_alloc_trace(struct kmem_cache *s, gfp_t gfpflags, size_t size);
229extern void *kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order);
221#else 230#else
222static __always_inline void * 231static __always_inline void *
223kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags) 232kmem_cache_alloc_trace(struct kmem_cache *s, gfp_t gfpflags, size_t size)
224{ 233{
225 return kmem_cache_alloc(s, gfpflags); 234 return kmem_cache_alloc(s, gfpflags);
226} 235}
236
237static __always_inline void *
238kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
239{
240 return kmalloc_order(size, flags, order);
241}
227#endif 242#endif
228 243
229static __always_inline void *kmalloc_large(size_t size, gfp_t flags) 244static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
230{ 245{
231 unsigned int order = get_order(size); 246 unsigned int order = get_order(size);
232 void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order); 247 return kmalloc_order_trace(size, flags, order);
233
234 kmemleak_alloc(ret, size, 1, flags);
235 trace_kmalloc(_THIS_IP_, ret, size, PAGE_SIZE << order, flags);
236
237 return ret;
238} 248}
239 249
240static __always_inline void *kmalloc(size_t size, gfp_t flags) 250static __always_inline void *kmalloc(size_t size, gfp_t flags)
241{ 251{
242 void *ret;
243
244 if (__builtin_constant_p(size)) { 252 if (__builtin_constant_p(size)) {
245 if (size > SLUB_MAX_SIZE) 253 if (size > SLUB_MAX_SIZE)
246 return kmalloc_large(size, flags); 254 return kmalloc_large(size, flags);
@@ -251,11 +259,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
251 if (!s) 259 if (!s)
252 return ZERO_SIZE_PTR; 260 return ZERO_SIZE_PTR;
253 261
254 ret = kmem_cache_alloc_notrace(s, flags); 262 return kmem_cache_alloc_trace(s, flags, size);
255
256 trace_kmalloc(_THIS_IP_, ret, size, s->size, flags);
257
258 return ret;
259 } 263 }
260 } 264 }
261 return __kmalloc(size, flags); 265 return __kmalloc(size, flags);
@@ -266,14 +270,14 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node);
266void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node); 270void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
267 271
268#ifdef CONFIG_TRACING 272#ifdef CONFIG_TRACING
269extern void *kmem_cache_alloc_node_notrace(struct kmem_cache *s, 273extern void *kmem_cache_alloc_node_trace(struct kmem_cache *s,
270 gfp_t gfpflags, 274 gfp_t gfpflags,
271 int node); 275 int node, size_t size);
272#else 276#else
273static __always_inline void * 277static __always_inline void *
274kmem_cache_alloc_node_notrace(struct kmem_cache *s, 278kmem_cache_alloc_node_trace(struct kmem_cache *s,
275 gfp_t gfpflags, 279 gfp_t gfpflags,
276 int node) 280 int node, size_t size)
277{ 281{
278 return kmem_cache_alloc_node(s, gfpflags, node); 282 return kmem_cache_alloc_node(s, gfpflags, node);
279} 283}
@@ -281,8 +285,6 @@ kmem_cache_alloc_node_notrace(struct kmem_cache *s,
281 285
282static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) 286static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
283{ 287{
284 void *ret;
285
286 if (__builtin_constant_p(size) && 288 if (__builtin_constant_p(size) &&
287 size <= SLUB_MAX_SIZE && !(flags & SLUB_DMA)) { 289 size <= SLUB_MAX_SIZE && !(flags & SLUB_DMA)) {
288 struct kmem_cache *s = kmalloc_slab(size); 290 struct kmem_cache *s = kmalloc_slab(size);
@@ -290,12 +292,7 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
290 if (!s) 292 if (!s)
291 return ZERO_SIZE_PTR; 293 return ZERO_SIZE_PTR;
292 294
293 ret = kmem_cache_alloc_node_notrace(s, flags, node); 295 return kmem_cache_alloc_node_trace(s, flags, node, size);
294
295 trace_kmalloc_node(_THIS_IP_, ret,
296 size, s->size, flags, node);
297
298 return ret;
299 } 296 }
300 return __kmalloc_node(size, flags, node); 297 return __kmalloc_node(size, flags, node);
301} 298}
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index 6950c981882d..78aa104250b7 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -13,6 +13,7 @@
13#ifndef _LINUX_SUNRPC_CACHE_H_ 13#ifndef _LINUX_SUNRPC_CACHE_H_
14#define _LINUX_SUNRPC_CACHE_H_ 14#define _LINUX_SUNRPC_CACHE_H_
15 15
16#include <linux/kref.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
17#include <asm/atomic.h> 18#include <asm/atomic.h>
18#include <linux/proc_fs.h> 19#include <linux/proc_fs.h>
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index 26697514c5ec..144b34be5c32 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -292,7 +292,7 @@ extern int unregister_pm_notifier(struct notifier_block *nb);
292/* drivers/base/power/wakeup.c */ 292/* drivers/base/power/wakeup.c */
293extern bool events_check_enabled; 293extern bool events_check_enabled;
294 294
295extern bool pm_check_wakeup_events(void); 295extern bool pm_wakeup_pending(void);
296extern bool pm_get_wakeup_count(unsigned int *count); 296extern bool pm_get_wakeup_count(unsigned int *count);
297extern bool pm_save_wakeup_count(unsigned int count); 297extern bool pm_save_wakeup_count(unsigned int count);
298#else /* !CONFIG_PM_SLEEP */ 298#else /* !CONFIG_PM_SLEEP */
@@ -309,7 +309,7 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)
309 309
310#define pm_notifier(fn, pri) do { (void)(fn); } while (0) 310#define pm_notifier(fn, pri) do { (void)(fn); } while (0)
311 311
312static inline bool pm_check_wakeup_events(void) { return true; } 312static inline bool pm_wakeup_pending(void) { return false; }
313#endif /* !CONFIG_PM_SLEEP */ 313#endif /* !CONFIG_PM_SLEEP */
314 314
315extern struct mutex pm_mutex; 315extern struct mutex pm_mutex;
diff --git a/kernel/Makefile b/kernel/Makefile
index 0b5ff083fa22..33e0a39cf359 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -121,7 +121,7 @@ $(obj)/configs.o: $(obj)/config_data.h
121# config_data.h contains the same information as ikconfig.h but gzipped. 121# config_data.h contains the same information as ikconfig.h but gzipped.
122# Info from config_data can be extracted from /proc/config* 122# Info from config_data can be extracted from /proc/config*
123targets += config_data.gz 123targets += config_data.gz
124$(obj)/config_data.gz: .config FORCE 124$(obj)/config_data.gz: $(KCONFIG_CONFIG) FORCE
125 $(call if_changed,gzip) 125 $(call if_changed,gzip)
126 126
127quiet_cmd_ikconfiggz = IKCFG $@ 127quiet_cmd_ikconfiggz = IKCFG $@
diff --git a/kernel/freezer.c b/kernel/freezer.c
index bd1d42b17cb2..66ecd2ead215 100644
--- a/kernel/freezer.c
+++ b/kernel/freezer.c
@@ -104,8 +104,13 @@ bool freeze_task(struct task_struct *p, bool sig_only)
104 } 104 }
105 105
106 if (should_send_signal(p)) { 106 if (should_send_signal(p)) {
107 if (!signal_pending(p)) 107 fake_signal_wake_up(p);
108 fake_signal_wake_up(p); 108 /*
109 * fake_signal_wake_up() goes through p's scheduler
110 * lock and guarantees that TASK_STOPPED/TRACED ->
111 * TASK_RUNNING transition can't race with task state
112 * testing in try_to_freeze_tasks().
113 */
109 } else if (sig_only) { 114 } else if (sig_only) {
110 return false; 115 return false;
111 } else { 116 } else {
diff --git a/kernel/power/Makefile b/kernel/power/Makefile
index f9063c6b185d..b75597235d85 100644
--- a/kernel/power/Makefile
+++ b/kernel/power/Makefile
@@ -1,7 +1,4 @@
1 1ccflags-$(CONFIG_PM_DEBUG) := -DDEBUG
2ifeq ($(CONFIG_PM_DEBUG),y)
3EXTRA_CFLAGS += -DDEBUG
4endif
5 2
6obj-$(CONFIG_PM) += main.o 3obj-$(CONFIG_PM) += main.o
7obj-$(CONFIG_PM_SLEEP) += console.o 4obj-$(CONFIG_PM_SLEEP) += console.o
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 048d0b514831..870f72bc72ae 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -62,7 +62,7 @@ void hibernation_set_ops(struct platform_hibernation_ops *ops)
62{ 62{
63 if (ops && !(ops->begin && ops->end && ops->pre_snapshot 63 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
64 && ops->prepare && ops->finish && ops->enter && ops->pre_restore 64 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
65 && ops->restore_cleanup)) { 65 && ops->restore_cleanup && ops->leave)) {
66 WARN_ON(1); 66 WARN_ON(1);
67 return; 67 return;
68 } 68 }
@@ -278,7 +278,7 @@ static int create_image(int platform_mode)
278 goto Enable_irqs; 278 goto Enable_irqs;
279 } 279 }
280 280
281 if (hibernation_test(TEST_CORE) || !pm_check_wakeup_events()) 281 if (hibernation_test(TEST_CORE) || pm_wakeup_pending())
282 goto Power_up; 282 goto Power_up;
283 283
284 in_suspend = 1; 284 in_suspend = 1;
@@ -516,7 +516,7 @@ int hibernation_platform_enter(void)
516 516
517 local_irq_disable(); 517 local_irq_disable();
518 sysdev_suspend(PMSG_HIBERNATE); 518 sysdev_suspend(PMSG_HIBERNATE);
519 if (!pm_check_wakeup_events()) { 519 if (pm_wakeup_pending()) {
520 error = -EAGAIN; 520 error = -EAGAIN;
521 goto Power_up; 521 goto Power_up;
522 } 522 }
@@ -647,6 +647,7 @@ int hibernate(void)
647 swsusp_free(); 647 swsusp_free();
648 if (!error) 648 if (!error)
649 power_down(); 649 power_down();
650 in_suspend = 0;
650 pm_restore_gfp_mask(); 651 pm_restore_gfp_mask();
651 } else { 652 } else {
652 pr_debug("PM: Image restored successfully.\n"); 653 pr_debug("PM: Image restored successfully.\n");
diff --git a/kernel/power/process.c b/kernel/power/process.c
index e50b4c1b2a0f..d6d2a10320e0 100644
--- a/kernel/power/process.c
+++ b/kernel/power/process.c
@@ -64,6 +64,12 @@ static int try_to_freeze_tasks(bool sig_only)
64 * perturb a task in TASK_STOPPED or TASK_TRACED. 64 * perturb a task in TASK_STOPPED or TASK_TRACED.
65 * It is "frozen enough". If the task does wake 65 * It is "frozen enough". If the task does wake
66 * up, it will immediately call try_to_freeze. 66 * up, it will immediately call try_to_freeze.
67 *
68 * Because freeze_task() goes through p's
69 * scheduler lock after setting TIF_FREEZE, it's
70 * guaranteed that either we see TASK_RUNNING or
71 * try_to_stop() after schedule() in ptrace/signal
72 * stop sees TIF_FREEZE.
67 */ 73 */
68 if (!task_is_stopped_or_traced(p) && 74 if (!task_is_stopped_or_traced(p) &&
69 !freezer_should_skip(p)) 75 !freezer_should_skip(p))
@@ -79,7 +85,7 @@ static int try_to_freeze_tasks(bool sig_only)
79 if (!todo || time_after(jiffies, end_time)) 85 if (!todo || time_after(jiffies, end_time))
80 break; 86 break;
81 87
82 if (!pm_check_wakeup_events()) { 88 if (pm_wakeup_pending()) {
83 wakeup = true; 89 wakeup = true;
84 break; 90 break;
85 } 91 }
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 031d5e3a6197..8850df68794d 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -164,7 +164,7 @@ static int suspend_enter(suspend_state_t state)
164 164
165 error = sysdev_suspend(PMSG_SUSPEND); 165 error = sysdev_suspend(PMSG_SUSPEND);
166 if (!error) { 166 if (!error) {
167 if (!suspend_test(TEST_CORE) && pm_check_wakeup_events()) { 167 if (!(suspend_test(TEST_CORE) || pm_wakeup_pending())) {
168 error = suspend_ops->enter(state); 168 error = suspend_ops->enter(state);
169 events_check_enabled = false; 169 events_check_enabled = false;
170 } 170 }
diff --git a/mm/slab.c b/mm/slab.c
index e9f92987954a..264037449f08 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3653,11 +3653,18 @@ void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags)
3653EXPORT_SYMBOL(kmem_cache_alloc); 3653EXPORT_SYMBOL(kmem_cache_alloc);
3654 3654
3655#ifdef CONFIG_TRACING 3655#ifdef CONFIG_TRACING
3656void *kmem_cache_alloc_notrace(struct kmem_cache *cachep, gfp_t flags) 3656void *
3657kmem_cache_alloc_trace(size_t size, struct kmem_cache *cachep, gfp_t flags)
3657{ 3658{
3658 return __cache_alloc(cachep, flags, __builtin_return_address(0)); 3659 void *ret;
3660
3661 ret = __cache_alloc(cachep, flags, __builtin_return_address(0));
3662
3663 trace_kmalloc(_RET_IP_, ret,
3664 size, slab_buffer_size(cachep), flags);
3665 return ret;
3659} 3666}
3660EXPORT_SYMBOL(kmem_cache_alloc_notrace); 3667EXPORT_SYMBOL(kmem_cache_alloc_trace);
3661#endif 3668#endif
3662 3669
3663#ifdef CONFIG_NUMA 3670#ifdef CONFIG_NUMA
@@ -3675,31 +3682,32 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid)
3675EXPORT_SYMBOL(kmem_cache_alloc_node); 3682EXPORT_SYMBOL(kmem_cache_alloc_node);
3676 3683
3677#ifdef CONFIG_TRACING 3684#ifdef CONFIG_TRACING
3678void *kmem_cache_alloc_node_notrace(struct kmem_cache *cachep, 3685void *kmem_cache_alloc_node_trace(size_t size,
3679 gfp_t flags, 3686 struct kmem_cache *cachep,
3680 int nodeid) 3687 gfp_t flags,
3688 int nodeid)
3681{ 3689{
3682 return __cache_alloc_node(cachep, flags, nodeid, 3690 void *ret;
3691
3692 ret = __cache_alloc_node(cachep, flags, nodeid,
3683 __builtin_return_address(0)); 3693 __builtin_return_address(0));
3694 trace_kmalloc_node(_RET_IP_, ret,
3695 size, slab_buffer_size(cachep),
3696 flags, nodeid);
3697 return ret;
3684} 3698}
3685EXPORT_SYMBOL(kmem_cache_alloc_node_notrace); 3699EXPORT_SYMBOL(kmem_cache_alloc_node_trace);
3686#endif 3700#endif
3687 3701
3688static __always_inline void * 3702static __always_inline void *
3689__do_kmalloc_node(size_t size, gfp_t flags, int node, void *caller) 3703__do_kmalloc_node(size_t size, gfp_t flags, int node, void *caller)
3690{ 3704{
3691 struct kmem_cache *cachep; 3705 struct kmem_cache *cachep;
3692 void *ret;
3693 3706
3694 cachep = kmem_find_general_cachep(size, flags); 3707 cachep = kmem_find_general_cachep(size, flags);
3695 if (unlikely(ZERO_OR_NULL_PTR(cachep))) 3708 if (unlikely(ZERO_OR_NULL_PTR(cachep)))
3696 return cachep; 3709 return cachep;
3697 ret = kmem_cache_alloc_node_notrace(cachep, flags, node); 3710 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
3698
3699 trace_kmalloc_node((unsigned long) caller, ret,
3700 size, cachep->buffer_size, flags, node);
3701
3702 return ret;
3703} 3711}
3704 3712
3705#if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_TRACING) 3713#if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_TRACING)
diff --git a/mm/slub.c b/mm/slub.c
index a2fe1727ed85..008cd743a36a 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -28,6 +28,8 @@
28#include <linux/math64.h> 28#include <linux/math64.h>
29#include <linux/fault-inject.h> 29#include <linux/fault-inject.h>
30 30
31#include <trace/events/kmem.h>
32
31/* 33/*
32 * Lock order: 34 * Lock order:
33 * 1. slab_lock(page) 35 * 1. slab_lock(page)
@@ -1774,11 +1776,21 @@ void *kmem_cache_alloc(struct kmem_cache *s, gfp_t gfpflags)
1774EXPORT_SYMBOL(kmem_cache_alloc); 1776EXPORT_SYMBOL(kmem_cache_alloc);
1775 1777
1776#ifdef CONFIG_TRACING 1778#ifdef CONFIG_TRACING
1777void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags) 1779void *kmem_cache_alloc_trace(struct kmem_cache *s, gfp_t gfpflags, size_t size)
1780{
1781 void *ret = slab_alloc(s, gfpflags, NUMA_NO_NODE, _RET_IP_);
1782 trace_kmalloc(_RET_IP_, ret, size, s->size, gfpflags);
1783 return ret;
1784}
1785EXPORT_SYMBOL(kmem_cache_alloc_trace);
1786
1787void *kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
1778{ 1788{
1779 return slab_alloc(s, gfpflags, NUMA_NO_NODE, _RET_IP_); 1789 void *ret = kmalloc_order(size, flags, order);
1790 trace_kmalloc(_RET_IP_, ret, size, PAGE_SIZE << order, flags);
1791 return ret;
1780} 1792}
1781EXPORT_SYMBOL(kmem_cache_alloc_notrace); 1793EXPORT_SYMBOL(kmalloc_order_trace);
1782#endif 1794#endif
1783 1795
1784#ifdef CONFIG_NUMA 1796#ifdef CONFIG_NUMA
@@ -1794,13 +1806,17 @@ void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags, int node)
1794EXPORT_SYMBOL(kmem_cache_alloc_node); 1806EXPORT_SYMBOL(kmem_cache_alloc_node);
1795 1807
1796#ifdef CONFIG_TRACING 1808#ifdef CONFIG_TRACING
1797void *kmem_cache_alloc_node_notrace(struct kmem_cache *s, 1809void *kmem_cache_alloc_node_trace(struct kmem_cache *s,
1798 gfp_t gfpflags, 1810 gfp_t gfpflags,
1799 int node) 1811 int node, size_t size)
1800{ 1812{
1801 return slab_alloc(s, gfpflags, node, _RET_IP_); 1813 void *ret = slab_alloc(s, gfpflags, node, _RET_IP_);
1814
1815 trace_kmalloc_node(_RET_IP_, ret,
1816 size, s->size, gfpflags, node);
1817 return ret;
1802} 1818}
1803EXPORT_SYMBOL(kmem_cache_alloc_node_notrace); 1819EXPORT_SYMBOL(kmem_cache_alloc_node_trace);
1804#endif 1820#endif
1805#endif 1821#endif
1806 1822
diff --git a/scripts/.gitignore b/scripts/.gitignore
index c5d5db54c009..e2741d23bab8 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -7,3 +7,4 @@ pnmtologo
7bin2c 7bin2c
8unifdef 8unifdef
9ihex2fw 9ihex2fw
10recordmcount
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 4c72c1189479..396da16aabf8 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -200,6 +200,29 @@ quiet_cmd_gzip = GZIP $@
200cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -f -9 > $@) || \ 200cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -f -9 > $@) || \
201 (rm -f $@ ; false) 201 (rm -f $@ ; false)
202 202
203# DTC
204# ---------------------------------------------------------------------------
205
206# Generate an assembly file to wrap the output of the device tree compiler
207quiet_cmd_dt_S_dtb= DTB $@
208cmd_dt_S_dtb= \
209( \
210 echo '\#include <asm-generic/vmlinux.lds.h>'; \
211 echo '.section .dtb.init.rodata,"a"'; \
212 echo '.balign STRUCT_ALIGNMENT'; \
213 echo '.global __dtb_$(*F)_begin'; \
214 echo '__dtb_$(*F)_begin:'; \
215 echo '.incbin "$<" '; \
216 echo '__dtb_$(*F)_end:'; \
217 echo '.global __dtb_$(*F)_end'; \
218 echo '.balign STRUCT_ALIGNMENT'; \
219) > $@
220
221$(obj)/%.dtb.S: $(obj)/%.dtb
222 $(call cmd,dt_S_dtb)
223
224quiet_cmd_dtc = DTC $@
225cmd_dtc = $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) $<
203 226
204# Bzip2 227# Bzip2
205# --------------------------------------------------------------------------- 228# ---------------------------------------------------------------------------
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index ea26b23de082..c9a16abacab4 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -138,38 +138,36 @@ static void print_cmdline(void)
138 printf("cmd_%s := %s\n\n", target, cmdline); 138 printf("cmd_%s := %s\n\n", target, cmdline);
139} 139}
140 140
141char * str_config = NULL; 141struct item {
142int size_config = 0; 142 struct item *next;
143int len_config = 0; 143 unsigned int len;
144 unsigned int hash;
145 char name[0];
146};
144 147
145/* 148#define HASHSZ 256
146 * Grow the configuration string to a desired length. 149static struct item *hashtab[HASHSZ];
147 * Usually the first growth is plenty.
148 */
149static void grow_config(int len)
150{
151 while (len_config + len > size_config) {
152 if (size_config == 0)
153 size_config = 2048;
154 str_config = realloc(str_config, size_config *= 2);
155 if (str_config == NULL)
156 { perror("fixdep:malloc"); exit(1); }
157 }
158}
159 150
151static unsigned int strhash(const char *str, unsigned int sz)
152{
153 /* fnv32 hash */
154 unsigned int i, hash = 2166136261U;
160 155
156 for (i = 0; i < sz; i++)
157 hash = (hash ^ str[i]) * 0x01000193;
158 return hash;
159}
161 160
162/* 161/*
163 * Lookup a value in the configuration string. 162 * Lookup a value in the configuration string.
164 */ 163 */
165static int is_defined_config(const char * name, int len) 164static int is_defined_config(const char *name, int len, unsigned int hash)
166{ 165{
167 const char * pconfig; 166 struct item *aux;
168 const char * plast = str_config + len_config - len; 167
169 for ( pconfig = str_config + 1; pconfig < plast; pconfig++ ) { 168 for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) {
170 if (pconfig[ -1] == '\n' 169 if (aux->hash == hash && aux->len == len &&
171 && pconfig[len] == '\n' 170 memcmp(aux->name, name, len) == 0)
172 && !memcmp(pconfig, name, len))
173 return 1; 171 return 1;
174 } 172 }
175 return 0; 173 return 0;
@@ -178,13 +176,19 @@ static int is_defined_config(const char * name, int len)
178/* 176/*
179 * Add a new value to the configuration string. 177 * Add a new value to the configuration string.
180 */ 178 */
181static void define_config(const char * name, int len) 179static void define_config(const char *name, int len, unsigned int hash)
182{ 180{
183 grow_config(len + 1); 181 struct item *aux = malloc(sizeof(*aux) + len);
184 182
185 memcpy(str_config+len_config, name, len); 183 if (!aux) {
186 len_config += len; 184 perror("fixdep:malloc");
187 str_config[len_config++] = '\n'; 185 exit(1);
186 }
187 memcpy(aux->name, name, len);
188 aux->len = len;
189 aux->hash = hash;
190 aux->next = hashtab[hash % HASHSZ];
191 hashtab[hash % HASHSZ] = aux;
188} 192}
189 193
190/* 194/*
@@ -192,40 +196,49 @@ static void define_config(const char * name, int len)
192 */ 196 */
193static void clear_config(void) 197static void clear_config(void)
194{ 198{
195 len_config = 0; 199 struct item *aux, *next;
196 define_config("", 0); 200 unsigned int i;
201
202 for (i = 0; i < HASHSZ; i++) {
203 for (aux = hashtab[i]; aux; aux = next) {
204 next = aux->next;
205 free(aux);
206 }
207 hashtab[i] = NULL;
208 }
197} 209}
198 210
199/* 211/*
200 * Record the use of a CONFIG_* word. 212 * Record the use of a CONFIG_* word.
201 */ 213 */
202static void use_config(char *m, int slen) 214static void use_config(const char *m, int slen)
203{ 215{
204 char s[PATH_MAX]; 216 unsigned int hash = strhash(m, slen);
205 char *p; 217 int c, i;
206 218
207 if (is_defined_config(m, slen)) 219 if (is_defined_config(m, slen, hash))
208 return; 220 return;
209 221
210 define_config(m, slen); 222 define_config(m, slen, hash);
211 223
212 memcpy(s, m, slen); s[slen] = 0; 224 printf(" $(wildcard include/config/");
213 225 for (i = 0; i < slen; i++) {
214 for (p = s; p < s + slen; p++) { 226 c = m[i];
215 if (*p == '_') 227 if (c == '_')
216 *p = '/'; 228 c = '/';
217 else 229 else
218 *p = tolower((int)*p); 230 c = tolower(c);
231 putchar(c);
219 } 232 }
220 printf(" $(wildcard include/config/%s.h) \\\n", s); 233 printf(".h) \\\n");
221} 234}
222 235
223static void parse_config_file(char *map, size_t len) 236static void parse_config_file(const char *map, size_t len)
224{ 237{
225 int *end = (int *) (map + len); 238 const int *end = (const int *) (map + len);
226 /* start at +1, so that p can never be < map */ 239 /* start at +1, so that p can never be < map */
227 int *m = (int *) map + 1; 240 const int *m = (const int *) map + 1;
228 char *p, *q; 241 const char *p, *q;
229 242
230 for (; m < end; m++) { 243 for (; m < end; m++) {
231 if (*m == INT_CONF) { p = (char *) m ; goto conf; } 244 if (*m == INT_CONF) { p = (char *) m ; goto conf; }
@@ -265,7 +278,7 @@ static int strrcmp(char *s, char *sub)
265 return memcmp(s + slen - sublen, sub, sublen); 278 return memcmp(s + slen - sublen, sub, sublen);
266} 279}
267 280
268static void do_config_file(char *filename) 281static void do_config_file(const char *filename)
269{ 282{
270 struct stat st; 283 struct stat st;
271 int fd; 284 int fd;
@@ -273,7 +286,7 @@ static void do_config_file(char *filename)
273 286
274 fd = open(filename, O_RDONLY); 287 fd = open(filename, O_RDONLY);
275 if (fd < 0) { 288 if (fd < 0) {
276 fprintf(stderr, "fixdep: "); 289 fprintf(stderr, "fixdep: error opening config file: ");
277 perror(filename); 290 perror(filename);
278 exit(2); 291 exit(2);
279 } 292 }
@@ -344,11 +357,15 @@ static void print_deps(void)
344 357
345 fd = open(depfile, O_RDONLY); 358 fd = open(depfile, O_RDONLY);
346 if (fd < 0) { 359 if (fd < 0) {
347 fprintf(stderr, "fixdep: "); 360 fprintf(stderr, "fixdep: error opening depfile: ");
348 perror(depfile); 361 perror(depfile);
349 exit(2); 362 exit(2);
350 } 363 }
351 fstat(fd, &st); 364 if (fstat(fd, &st) < 0) {
365 fprintf(stderr, "fixdep: error fstat'ing depfile: ");
366 perror(depfile);
367 exit(2);
368 }
352 if (st.st_size == 0) { 369 if (st.st_size == 0) {
353 fprintf(stderr,"fixdep: %s is empty\n",depfile); 370 fprintf(stderr,"fixdep: %s is empty\n",depfile);
354 close(fd); 371 close(fd);
diff --git a/scripts/checksyscalls.sh b/scripts/checksyscalls.sh
index 6bb42e72e0e5..3ab316e52313 100755
--- a/scripts/checksyscalls.sh
+++ b/scripts/checksyscalls.sh
@@ -6,7 +6,7 @@
6# and listed below so they are ignored. 6# and listed below so they are ignored.
7# 7#
8# Usage: 8# Usage:
9# syscallchk gcc gcc-options 9# checksyscalls.sh gcc gcc-options
10# 10#
11 11
12ignore_list() { 12ignore_list() {
@@ -204,5 +204,5 @@ sed -n -e '/^\#define/ s/[^_]*__NR_\([^[:space:]]*\).*/\
204\#endif/p' $1 204\#endif/p' $1
205} 205}
206 206
207(ignore_list && syscall_list ${srctree}/arch/x86/include/asm/unistd_32.h) | \ 207(ignore_list && syscall_list $(dirname $0)/../arch/x86/include/asm/unistd_32.h) | \
208$* -E -x c - > /dev/null 208$* -E -x c - > /dev/null
diff --git a/scripts/coccinelle/misc/doubleinit.cocci b/scripts/coccinelle/misc/doubleinit.cocci
index 55d7dc19dfe0..156b20adb351 100644
--- a/scripts/coccinelle/misc/doubleinit.cocci
+++ b/scripts/coccinelle/misc/doubleinit.cocci
@@ -7,7 +7,7 @@
7// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2. 7// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
8// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. 8// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
9// URL: http://coccinelle.lip6.fr/ 9// URL: http://coccinelle.lip6.fr/
10// Comments: 10// Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise
11// Options: -no_includes -include_headers 11// Options: -no_includes -include_headers
12 12
13virtual org 13virtual org
@@ -19,7 +19,7 @@ position p0,p;
19expression E; 19expression E;
20@@ 20@@
21 21
22struct I s =@p0 { ... .fld@p = E, ...}; 22struct I s =@p0 { ..., .fld@p = E, ...};
23 23
24@s@ 24@s@
25identifier I, s, r.fld; 25identifier I, s, r.fld;
@@ -27,7 +27,7 @@ position r.p0,p;
27expression E; 27expression E;
28@@ 28@@
29 29
30struct I s =@p0 { ... .fld@p = E, ...}; 30struct I s =@p0 { ..., .fld@p = E, ...};
31 31
32@script:python depends on org@ 32@script:python depends on org@
33p0 << r.p0; 33p0 << r.p0;
diff --git a/scripts/coccinelle/null/deref_null.cocci b/scripts/coccinelle/null/deref_null.cocci
index 9969d76d0f4b..cdac6cfcce92 100644
--- a/scripts/coccinelle/null/deref_null.cocci
+++ b/scripts/coccinelle/null/deref_null.cocci
@@ -11,21 +11,10 @@
11// Options: 11// Options:
12 12
13virtual context 13virtual context
14virtual patch
15virtual org 14virtual org
16virtual report 15virtual report
17 16
18@initialize:python depends on !context && patch && !org && !report@ 17@ifm@
19
20import sys
21print >> sys.stderr, "This semantic patch does not support the 'patch' mode."
22
23@depends on patch@
24@@
25
26this_rule_should_never_matches();
27
28@ifm depends on !patch@
29expression *E; 18expression *E;
30statement S1,S2; 19statement S1,S2;
31position p1; 20position p1;
@@ -35,7 +24,7 @@ if@p1 ((E == NULL && ...) || ...) S1 else S2
35 24
36// The following two rules are separate, because both can match a single 25// The following two rules are separate, because both can match a single
37// expression in different ways 26// expression in different ways
38@pr1 depends on !patch expression@ 27@pr1 expression@
39expression *ifm.E; 28expression *ifm.E;
40identifier f; 29identifier f;
41position p1; 30position p1;
@@ -43,7 +32,7 @@ position p1;
43 32
44 (E != NULL && ...) ? <+...E->f@p1...+> : ... 33 (E != NULL && ...) ? <+...E->f@p1...+> : ...
45 34
46@pr2 depends on !patch expression@ 35@pr2 expression@
47expression *ifm.E; 36expression *ifm.E;
48identifier f; 37identifier f;
49position p2; 38position p2;
@@ -59,7 +48,7 @@ position p2;
59 48
60// For org and report modes 49// For org and report modes
61 50
62@r depends on !context && !patch && (org || report) exists@ 51@r depends on !context && (org || report) exists@
63expression subE <= ifm.E; 52expression subE <= ifm.E;
64expression *ifm.E; 53expression *ifm.E;
65expression E1,E2; 54expression E1,E2;
@@ -99,7 +88,7 @@ if@p1 ((E == NULL && ...) || ...)
99} 88}
100else S3 89else S3
101 90
102@script:python depends on !context && !patch && !org && report@ 91@script:python depends on !context && !org && report@
103p << r.p; 92p << r.p;
104p1 << ifm.p1; 93p1 << ifm.p1;
105x << ifm.E; 94x << ifm.E;
@@ -109,7 +98,7 @@ msg="ERROR: %s is NULL but dereferenced." % (x)
109coccilib.report.print_report(p[0], msg) 98coccilib.report.print_report(p[0], msg)
110cocci.include_match(False) 99cocci.include_match(False)
111 100
112@script:python depends on !context && !patch && org && !report@ 101@script:python depends on !context && org && !report@
113p << r.p; 102p << r.p;
114p1 << ifm.p1; 103p1 << ifm.p1;
115x << ifm.E; 104x << ifm.E;
@@ -120,7 +109,7 @@ msg_safe=msg.replace("[","@(").replace("]",")")
120cocci.print_main(msg_safe,p) 109cocci.print_main(msg_safe,p)
121cocci.include_match(False) 110cocci.include_match(False)
122 111
123@s depends on !context && !patch && (org || report) exists@ 112@s depends on !context && (org || report) exists@
124expression subE <= ifm.E; 113expression subE <= ifm.E;
125expression *ifm.E; 114expression *ifm.E;
126expression E1,E2; 115expression E1,E2;
@@ -159,7 +148,7 @@ if@p1 ((E == NULL && ...) || ...)
159} 148}
160else S3 149else S3
161 150
162@script:python depends on !context && !patch && !org && report@ 151@script:python depends on !context && !org && report@
163p << s.p; 152p << s.p;
164p1 << ifm.p1; 153p1 << ifm.p1;
165x << ifm.E; 154x << ifm.E;
@@ -168,7 +157,7 @@ x << ifm.E;
168msg="ERROR: %s is NULL but dereferenced." % (x) 157msg="ERROR: %s is NULL but dereferenced." % (x)
169coccilib.report.print_report(p[0], msg) 158coccilib.report.print_report(p[0], msg)
170 159
171@script:python depends on !context && !patch && org && !report@ 160@script:python depends on !context && org && !report@
172p << s.p; 161p << s.p;
173p1 << ifm.p1; 162p1 << ifm.p1;
174x << ifm.E; 163x << ifm.E;
@@ -180,7 +169,7 @@ cocci.print_main(msg_safe,p)
180 169
181// For context mode 170// For context mode
182 171
183@depends on context && !patch && !org && !report exists@ 172@depends on context && !org && !report exists@
184expression subE <= ifm.E; 173expression subE <= ifm.E;
185expression *ifm.E; 174expression *ifm.E;
186expression E1,E2; 175expression E1,E2;
@@ -223,7 +212,7 @@ else S3
223// The following three rules are duplicates of ifm, pr1 and pr2 respectively. 212// The following three rules are duplicates of ifm, pr1 and pr2 respectively.
224// It is need because the previous rule as already made a "change". 213// It is need because the previous rule as already made a "change".
225 214
226@ifm1 depends on !patch@ 215@ifm1@
227expression *E; 216expression *E;
228statement S1,S2; 217statement S1,S2;
229position p1; 218position p1;
@@ -231,7 +220,7 @@ position p1;
231 220
232if@p1 ((E == NULL && ...) || ...) S1 else S2 221if@p1 ((E == NULL && ...) || ...) S1 else S2
233 222
234@pr11 depends on !patch expression@ 223@pr11 expression@
235expression *ifm1.E; 224expression *ifm1.E;
236identifier f; 225identifier f;
237position p1; 226position p1;
@@ -239,7 +228,7 @@ position p1;
239 228
240 (E != NULL && ...) ? <+...E->f@p1...+> : ... 229 (E != NULL && ...) ? <+...E->f@p1...+> : ...
241 230
242@pr12 depends on !patch expression@ 231@pr12 expression@
243expression *ifm1.E; 232expression *ifm1.E;
244identifier f; 233identifier f;
245position p2; 234position p2;
@@ -253,7 +242,7 @@ position p2;
253 sizeof(<+...E->f@p2...+>) 242 sizeof(<+...E->f@p2...+>)
254) 243)
255 244
256@depends on context && !patch && !org && !report exists@ 245@depends on context && !org && !report exists@
257expression subE <= ifm1.E; 246expression subE <= ifm1.E;
258expression *ifm1.E; 247expression *ifm1.E;
259expression E1,E2; 248expression E1,E2;
diff --git a/scripts/config b/scripts/config
index 608d7fdb13e8..a7c7c4b8e957 100755
--- a/scripts/config
+++ b/scripts/config
@@ -10,8 +10,10 @@ commands:
10 --enable|-e option Enable option 10 --enable|-e option Enable option
11 --disable|-d option Disable option 11 --disable|-d option Disable option
12 --module|-m option Turn option into a module 12 --module|-m option Turn option into a module
13 --set-str option value 13 --set-str option string
14 Set option to "value" 14 Set option to "string"
15 --set-val option value
16 Set option to value
15 --state|-s option Print state of option (n,y,m,undef) 17 --state|-s option Print state of option (n,y,m,undef)
16 18
17 --enable-after|-E beforeopt option 19 --enable-after|-E beforeopt option
@@ -86,7 +88,7 @@ while [ "$1" != "" ] ; do
86 B=$ARG 88 B=$ARG
87 shift 2 89 shift 2
88 ;; 90 ;;
89 --*) 91 -*)
90 checkarg "$1" 92 checkarg "$1"
91 shift 93 shift
92 ;; 94 ;;
@@ -109,6 +111,11 @@ while [ "$1" != "" ] ; do
109 shift 111 shift
110 ;; 112 ;;
111 113
114 --set-val)
115 set_var "CONFIG_$ARG" "CONFIG_$ARG=$1"
116 shift
117 ;;
118
112 --state|-s) 119 --state|-s)
113 if grep -q "# CONFIG_$ARG is not set" $FN ; then 120 if grep -q "# CONFIG_$ARG is not set" $FN ; then
114 echo n 121 echo n
diff --git a/scripts/dtc/Makefile b/scripts/dtc/Makefile
index 01cdb36fc583..04a31c17639f 100644
--- a/scripts/dtc/Makefile
+++ b/scripts/dtc/Makefile
@@ -4,7 +4,7 @@ hostprogs-y := dtc
4always := $(hostprogs-y) 4always := $(hostprogs-y)
5 5
6dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \ 6dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \
7 srcpos.o checks.o 7 srcpos.o checks.o util.o
8dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o 8dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o
9 9
10# Source files need to get at the userspace version of libfdt_env.h to compile 10# Source files need to get at the userspace version of libfdt_env.h to compile
@@ -19,6 +19,7 @@ HOSTCFLAGS_fstree.o := $(HOSTCFLAGS_DTC)
19HOSTCFLAGS_livetree.o := $(HOSTCFLAGS_DTC) 19HOSTCFLAGS_livetree.o := $(HOSTCFLAGS_DTC)
20HOSTCFLAGS_srcpos.o := $(HOSTCFLAGS_DTC) 20HOSTCFLAGS_srcpos.o := $(HOSTCFLAGS_DTC)
21HOSTCFLAGS_treesource.o := $(HOSTCFLAGS_DTC) 21HOSTCFLAGS_treesource.o := $(HOSTCFLAGS_DTC)
22HOSTCFLAGS_util.o := $(HOSTCFLAGS_DTC)
22 23
23HOSTCFLAGS_dtc-lexer.lex.o := $(HOSTCFLAGS_DTC) 24HOSTCFLAGS_dtc-lexer.lex.o := $(HOSTCFLAGS_DTC)
24HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC) 25HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC)
diff --git a/scripts/dtc/checks.c b/scripts/dtc/checks.c
index 95485796f253..a662a0044798 100644
--- a/scripts/dtc/checks.c
+++ b/scripts/dtc/checks.c
@@ -278,32 +278,112 @@ static void check_property_name_chars(struct check *c, struct node *dt,
278} 278}
279PROP_CHECK(property_name_chars, PROPNODECHARS, ERROR); 279PROP_CHECK(property_name_chars, PROPNODECHARS, ERROR);
280 280
281#define DESCLABEL_FMT "%s%s%s%s%s"
282#define DESCLABEL_ARGS(node,prop,mark) \
283 ((mark) ? "value of " : ""), \
284 ((prop) ? "'" : ""), \
285 ((prop) ? (prop)->name : ""), \
286 ((prop) ? "' in " : ""), (node)->fullpath
287
288static void check_duplicate_label(struct check *c, struct node *dt,
289 const char *label, struct node *node,
290 struct property *prop, struct marker *mark)
291{
292 struct node *othernode = NULL;
293 struct property *otherprop = NULL;
294 struct marker *othermark = NULL;
295
296 othernode = get_node_by_label(dt, label);
297
298 if (!othernode)
299 otherprop = get_property_by_label(dt, label, &othernode);
300 if (!othernode)
301 othermark = get_marker_label(dt, label, &othernode,
302 &otherprop);
303
304 if (!othernode)
305 return;
306
307 if ((othernode != node) || (otherprop != prop) || (othermark != mark))
308 FAIL(c, "Duplicate label '%s' on " DESCLABEL_FMT
309 " and " DESCLABEL_FMT,
310 label, DESCLABEL_ARGS(node, prop, mark),
311 DESCLABEL_ARGS(othernode, otherprop, othermark));
312}
313
314static void check_duplicate_label_node(struct check *c, struct node *dt,
315 struct node *node)
316{
317 struct label *l;
318
319 for_each_label(node->labels, l)
320 check_duplicate_label(c, dt, l->label, node, NULL, NULL);
321}
322static void check_duplicate_label_prop(struct check *c, struct node *dt,
323 struct node *node, struct property *prop)
324{
325 struct marker *m = prop->val.markers;
326 struct label *l;
327
328 for_each_label(prop->labels, l)
329 check_duplicate_label(c, dt, l->label, node, prop, NULL);
330
331 for_each_marker_of_type(m, LABEL)
332 check_duplicate_label(c, dt, m->ref, node, prop, m);
333}
334CHECK(duplicate_label, NULL, check_duplicate_label_node,
335 check_duplicate_label_prop, NULL, ERROR);
336
281static void check_explicit_phandles(struct check *c, struct node *root, 337static void check_explicit_phandles(struct check *c, struct node *root,
282 struct node *node) 338 struct node *node, struct property *prop)
283{ 339{
284 struct property *prop; 340 struct marker *m;
285 struct node *other; 341 struct node *other;
286 cell_t phandle; 342 cell_t phandle;
287 343
288 prop = get_property(node, "linux,phandle"); 344 if (!streq(prop->name, "phandle")
289 if (! prop) 345 && !streq(prop->name, "linux,phandle"))
290 return; /* No phandle, that's fine */ 346 return;
291 347
292 if (prop->val.len != sizeof(cell_t)) { 348 if (prop->val.len != sizeof(cell_t)) {
293 FAIL(c, "%s has bad length (%d) linux,phandle property", 349 FAIL(c, "%s has bad length (%d) %s property",
294 node->fullpath, prop->val.len); 350 node->fullpath, prop->val.len, prop->name);
351 return;
352 }
353
354 m = prop->val.markers;
355 for_each_marker_of_type(m, REF_PHANDLE) {
356 assert(m->offset == 0);
357 if (node != get_node_by_ref(root, m->ref))
358 /* "Set this node's phandle equal to some
359 * other node's phandle". That's nonsensical
360 * by construction. */ {
361 FAIL(c, "%s in %s is a reference to another node",
362 prop->name, node->fullpath);
363 return;
364 }
365 /* But setting this node's phandle equal to its own
366 * phandle is allowed - that means allocate a unique
367 * phandle for this node, even if it's not otherwise
368 * referenced. The value will be filled in later, so
369 * no further checking for now. */
295 return; 370 return;
296 } 371 }
297 372
298 phandle = propval_cell(prop); 373 phandle = propval_cell(prop);
374
299 if ((phandle == 0) || (phandle == -1)) { 375 if ((phandle == 0) || (phandle == -1)) {
300 FAIL(c, "%s has invalid linux,phandle value 0x%x", 376 FAIL(c, "%s has bad value (0x%x) in %s property",
301 node->fullpath, phandle); 377 node->fullpath, phandle, prop->name);
302 return; 378 return;
303 } 379 }
304 380
381 if (node->phandle && (node->phandle != phandle))
382 FAIL(c, "%s has %s property which replaces existing phandle information",
383 node->fullpath, prop->name);
384
305 other = get_node_by_phandle(root, phandle); 385 other = get_node_by_phandle(root, phandle);
306 if (other) { 386 if (other && (other != node)) {
307 FAIL(c, "%s has duplicated phandle 0x%x (seen before at %s)", 387 FAIL(c, "%s has duplicated phandle 0x%x (seen before at %s)",
308 node->fullpath, phandle, other->fullpath); 388 node->fullpath, phandle, other->fullpath);
309 return; 389 return;
@@ -311,7 +391,7 @@ static void check_explicit_phandles(struct check *c, struct node *root,
311 391
312 node->phandle = phandle; 392 node->phandle = phandle;
313} 393}
314NODE_CHECK(explicit_phandles, NULL, ERROR); 394PROP_CHECK(explicit_phandles, NULL, ERROR);
315 395
316static void check_name_properties(struct check *c, struct node *root, 396static void check_name_properties(struct check *c, struct node *root,
317 struct node *node) 397 struct node *node)
@@ -549,6 +629,9 @@ static struct check *check_table[] = {
549 &duplicate_node_names, &duplicate_property_names, 629 &duplicate_node_names, &duplicate_property_names,
550 &node_name_chars, &node_name_format, &property_name_chars, 630 &node_name_chars, &node_name_format, &property_name_chars,
551 &name_is_string, &name_properties, 631 &name_is_string, &name_properties,
632
633 &duplicate_label,
634
552 &explicit_phandles, 635 &explicit_phandles,
553 &phandle_references, &path_references, 636 &phandle_references, &path_references,
554 637
diff --git a/scripts/dtc/dtc-lexer.l b/scripts/dtc/dtc-lexer.l
index a627bbee91d4..e866ea5166ac 100644
--- a/scripts/dtc/dtc-lexer.l
+++ b/scripts/dtc/dtc-lexer.l
@@ -18,7 +18,7 @@
18 * USA 18 * USA
19 */ 19 */
20 20
21%option noyywrap noinput nounput yylineno 21%option noyywrap nounput noinput never-interactive
22 22
23%x INCLUDE 23%x INCLUDE
24%x BYTESTRING 24%x BYTESTRING
@@ -38,6 +38,13 @@ LINECOMMENT "//".*\n
38#include "srcpos.h" 38#include "srcpos.h"
39#include "dtc-parser.tab.h" 39#include "dtc-parser.tab.h"
40 40
41YYLTYPE yylloc;
42
43/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
44#define YY_USER_ACTION \
45 { \
46 srcpos_update(&yylloc, yytext, yyleng); \
47 }
41 48
42/*#define LEXDEBUG 1*/ 49/*#define LEXDEBUG 1*/
43 50
@@ -47,15 +54,10 @@ LINECOMMENT "//".*\n
47#define DPRINT(fmt, ...) do { } while (0) 54#define DPRINT(fmt, ...) do { } while (0)
48#endif 55#endif
49 56
50static int dts_version; /* = 0 */ 57static int dts_version = 1;
51 58
52#define BEGIN_DEFAULT() if (dts_version == 0) { \ 59#define BEGIN_DEFAULT() DPRINT("<V1>\n"); \
53 DPRINT("<INITIAL>\n"); \
54 BEGIN(INITIAL); \
55 } else { \
56 DPRINT("<V1>\n"); \
57 BEGIN(V1); \ 60 BEGIN(V1); \
58 }
59 61
60static void push_input_file(const char *filename); 62static void push_input_file(const char *filename);
61static int pop_input_file(void); 63static int pop_input_file(void);
@@ -75,18 +77,13 @@ static int pop_input_file(void);
75 } 77 }
76 78
77<*>{STRING} { 79<*>{STRING} {
78 yylloc.file = srcpos_file;
79 yylloc.first_line = yylineno;
80 DPRINT("String: %s\n", yytext); 80 DPRINT("String: %s\n", yytext);
81 yylval.data = data_copy_escape_string(yytext+1, 81 yylval.data = data_copy_escape_string(yytext+1,
82 yyleng-2); 82 yyleng-2);
83 yylloc.first_line = yylineno;
84 return DT_STRING; 83 return DT_STRING;
85 } 84 }
86 85
87<*>"/dts-v1/" { 86<*>"/dts-v1/" {
88 yylloc.file = srcpos_file;
89 yylloc.first_line = yylineno;
90 DPRINT("Keyword: /dts-v1/\n"); 87 DPRINT("Keyword: /dts-v1/\n");
91 dts_version = 1; 88 dts_version = 1;
92 BEGIN_DEFAULT(); 89 BEGIN_DEFAULT();
@@ -94,106 +91,57 @@ static int pop_input_file(void);
94 } 91 }
95 92
96<*>"/memreserve/" { 93<*>"/memreserve/" {
97 yylloc.file = srcpos_file;
98 yylloc.first_line = yylineno;
99 DPRINT("Keyword: /memreserve/\n"); 94 DPRINT("Keyword: /memreserve/\n");
100 BEGIN_DEFAULT(); 95 BEGIN_DEFAULT();
101 return DT_MEMRESERVE; 96 return DT_MEMRESERVE;
102 } 97 }
103 98
104<*>{LABEL}: { 99<*>{LABEL}: {
105 yylloc.file = srcpos_file;
106 yylloc.first_line = yylineno;
107 DPRINT("Label: %s\n", yytext); 100 DPRINT("Label: %s\n", yytext);
108 yylval.labelref = strdup(yytext); 101 yylval.labelref = xstrdup(yytext);
109 yylval.labelref[yyleng-1] = '\0'; 102 yylval.labelref[yyleng-1] = '\0';
110 return DT_LABEL; 103 return DT_LABEL;
111 } 104 }
112 105
113<INITIAL>[bodh]# {
114 yylloc.file = srcpos_file;
115 yylloc.first_line = yylineno;
116 if (*yytext == 'b')
117 yylval.cbase = 2;
118 else if (*yytext == 'o')
119 yylval.cbase = 8;
120 else if (*yytext == 'd')
121 yylval.cbase = 10;
122 else
123 yylval.cbase = 16;
124 DPRINT("Base: %d\n", yylval.cbase);
125 return DT_BASE;
126 }
127
128<INITIAL>[0-9a-fA-F]+ {
129 yylloc.file = srcpos_file;
130 yylloc.first_line = yylineno;
131 yylval.literal = strdup(yytext);
132 DPRINT("Literal: '%s'\n", yylval.literal);
133 return DT_LEGACYLITERAL;
134 }
135
136<V1>[0-9]+|0[xX][0-9a-fA-F]+ { 106<V1>[0-9]+|0[xX][0-9a-fA-F]+ {
137 yylloc.file = srcpos_file; 107 yylval.literal = xstrdup(yytext);
138 yylloc.first_line = yylineno;
139 yylval.literal = strdup(yytext);
140 DPRINT("Literal: '%s'\n", yylval.literal); 108 DPRINT("Literal: '%s'\n", yylval.literal);
141 return DT_LITERAL; 109 return DT_LITERAL;
142 } 110 }
143 111
144\&{LABEL} { /* label reference */ 112<*>\&{LABEL} { /* label reference */
145 yylloc.file = srcpos_file;
146 yylloc.first_line = yylineno;
147 DPRINT("Ref: %s\n", yytext+1); 113 DPRINT("Ref: %s\n", yytext+1);
148 yylval.labelref = strdup(yytext+1); 114 yylval.labelref = xstrdup(yytext+1);
149 return DT_REF; 115 return DT_REF;
150 } 116 }
151 117
152"&{/"{PATHCHAR}+\} { /* new-style path reference */ 118<*>"&{/"{PATHCHAR}+\} { /* new-style path reference */
153 yylloc.file = srcpos_file;
154 yylloc.first_line = yylineno;
155 yytext[yyleng-1] = '\0'; 119 yytext[yyleng-1] = '\0';
156 DPRINT("Ref: %s\n", yytext+2); 120 DPRINT("Ref: %s\n", yytext+2);
157 yylval.labelref = strdup(yytext+2); 121 yylval.labelref = xstrdup(yytext+2);
158 return DT_REF;
159 }
160
161<INITIAL>"&/"{PATHCHAR}+ { /* old-style path reference */
162 yylloc.file = srcpos_file;
163 yylloc.first_line = yylineno;
164 DPRINT("Ref: %s\n", yytext+1);
165 yylval.labelref = strdup(yytext+1);
166 return DT_REF; 122 return DT_REF;
167 } 123 }
168 124
169<BYTESTRING>[0-9a-fA-F]{2} { 125<BYTESTRING>[0-9a-fA-F]{2} {
170 yylloc.file = srcpos_file;
171 yylloc.first_line = yylineno;
172 yylval.byte = strtol(yytext, NULL, 16); 126 yylval.byte = strtol(yytext, NULL, 16);
173 DPRINT("Byte: %02x\n", (int)yylval.byte); 127 DPRINT("Byte: %02x\n", (int)yylval.byte);
174 return DT_BYTE; 128 return DT_BYTE;
175 } 129 }
176 130
177<BYTESTRING>"]" { 131<BYTESTRING>"]" {
178 yylloc.file = srcpos_file;
179 yylloc.first_line = yylineno;
180 DPRINT("/BYTESTRING\n"); 132 DPRINT("/BYTESTRING\n");
181 BEGIN_DEFAULT(); 133 BEGIN_DEFAULT();
182 return ']'; 134 return ']';
183 } 135 }
184 136
185<PROPNODENAME>{PROPNODECHAR}+ { 137<PROPNODENAME>{PROPNODECHAR}+ {
186 yylloc.file = srcpos_file;
187 yylloc.first_line = yylineno;
188 DPRINT("PropNodeName: %s\n", yytext); 138 DPRINT("PropNodeName: %s\n", yytext);
189 yylval.propnodename = strdup(yytext); 139 yylval.propnodename = xstrdup(yytext);
190 BEGIN_DEFAULT(); 140 BEGIN_DEFAULT();
191 return DT_PROPNODENAME; 141 return DT_PROPNODENAME;
192 } 142 }
193 143
194"/incbin/" { 144"/incbin/" {
195 yylloc.file = srcpos_file;
196 yylloc.first_line = yylineno;
197 DPRINT("Binary Include\n"); 145 DPRINT("Binary Include\n");
198 return DT_INCBIN; 146 return DT_INCBIN;
199 } 147 }
@@ -203,8 +151,6 @@ static int pop_input_file(void);
203<*>{LINECOMMENT}+ /* eat C++-style comments */ 151<*>{LINECOMMENT}+ /* eat C++-style comments */
204 152
205<*>. { 153<*>. {
206 yylloc.file = srcpos_file;
207 yylloc.first_line = yylineno;
208 DPRINT("Char: %c (\\x%02x)\n", yytext[0], 154 DPRINT("Char: %c (\\x%02x)\n", yytext[0],
209 (unsigned)yytext[0]); 155 (unsigned)yytext[0]);
210 if (yytext[0] == '[') { 156 if (yytext[0] == '[') {
@@ -221,100 +167,25 @@ static int pop_input_file(void);
221 167
222%% 168%%
223 169
224
225/*
226 * Stack of nested include file contexts.
227 */
228
229struct incl_file {
230 struct dtc_file *file;
231 YY_BUFFER_STATE yy_prev_buf;
232 int yy_prev_lineno;
233 struct incl_file *prev;
234};
235
236static struct incl_file *incl_file_stack;
237
238
239/*
240 * Detect infinite include recursion.
241 */
242#define MAX_INCLUDE_DEPTH (100)
243
244static int incl_depth = 0;
245
246
247static void push_input_file(const char *filename) 170static void push_input_file(const char *filename)
248{ 171{
249 struct incl_file *incl_file;
250 struct dtc_file *newfile;
251 struct search_path search, *searchptr = NULL;
252
253 assert(filename); 172 assert(filename);
254 173
255 if (incl_depth++ >= MAX_INCLUDE_DEPTH) 174 srcfile_push(filename);
256 die("Includes nested too deeply");
257
258 if (srcpos_file) {
259 search.dir = srcpos_file->dir;
260 search.next = NULL;
261 search.prev = NULL;
262 searchptr = &search;
263 }
264
265 newfile = dtc_open_file(filename, searchptr);
266 175
267 incl_file = xmalloc(sizeof(struct incl_file)); 176 yyin = current_srcfile->f;
268 177
269 /* 178 yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
270 * Save current context.
271 */
272 incl_file->yy_prev_buf = YY_CURRENT_BUFFER;
273 incl_file->yy_prev_lineno = yylineno;
274 incl_file->file = srcpos_file;
275 incl_file->prev = incl_file_stack;
276
277 incl_file_stack = incl_file;
278
279 /*
280 * Establish new context.
281 */
282 srcpos_file = newfile;
283 yylineno = 1;
284 yyin = newfile->file;
285 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
286} 179}
287 180
288 181
289static int pop_input_file(void) 182static int pop_input_file(void)
290{ 183{
291 struct incl_file *incl_file; 184 if (srcfile_pop() == 0)
292
293 if (incl_file_stack == 0)
294 return 0; 185 return 0;
295 186
296 dtc_close_file(srcpos_file); 187 yypop_buffer_state();
297 188 yyin = current_srcfile->f;
298 /*
299 * Pop.
300 */
301 --incl_depth;
302 incl_file = incl_file_stack;
303 incl_file_stack = incl_file->prev;
304
305 /*
306 * Recover old context.
307 */
308 yy_delete_buffer(YY_CURRENT_BUFFER);
309 yy_switch_to_buffer(incl_file->yy_prev_buf);
310 yylineno = incl_file->yy_prev_lineno;
311 srcpos_file = incl_file->file;
312 yyin = incl_file->file ? incl_file->file->file : NULL;
313
314 /*
315 * Free old state.
316 */
317 free(incl_file);
318 189
319 return 1; 190 return 1;
320} 191}
diff --git a/scripts/dtc/dtc-lexer.lex.c_shipped b/scripts/dtc/dtc-lexer.lex.c_shipped
index e27cc636e326..50c4420b4b2c 100644
--- a/scripts/dtc/dtc-lexer.lex.c_shipped
+++ b/scripts/dtc/dtc-lexer.lex.c_shipped
@@ -170,20 +170,7 @@ extern FILE *yyin, *yyout;
170#define EOB_ACT_END_OF_FILE 1 170#define EOB_ACT_END_OF_FILE 1
171#define EOB_ACT_LAST_MATCH 2 171#define EOB_ACT_LAST_MATCH 2
172 172
173 /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires 173 #define YY_LESS_LINENO(n)
174 * access to the local variable yy_act. Since yyless() is a macro, it would break
175 * existing scanners that call yyless() from OUTSIDE yylex.
176 * One obvious solution it to make yy_act a global. I tried that, and saw
177 * a 5% performance hit in a non-yylineno scanner, because yy_act is
178 * normally declared as a register variable-- so it is not worth it.
179 */
180 #define YY_LESS_LINENO(n) \
181 do { \
182 int yyl;\
183 for ( yyl = n; yyl < yyleng; ++yyl )\
184 if ( yytext[yyl] == '\n' )\
185 --yylineno;\
186 }while(0)
187 174
188/* Return all but the first "n" matched characters back to the input stream. */ 175/* Return all but the first "n" matched characters back to the input stream. */
189#define yyless(n) \ 176#define yyless(n) \
@@ -385,8 +372,8 @@ static void yy_fatal_error (yyconst char msg[] );
385 *yy_cp = '\0'; \ 372 *yy_cp = '\0'; \
386 (yy_c_buf_p) = yy_cp; 373 (yy_c_buf_p) = yy_cp;
387 374
388#define YY_NUM_RULES 20 375#define YY_NUM_RULES 17
389#define YY_END_OF_BUFFER 21 376#define YY_END_OF_BUFFER 18
390/* This struct is not used in this scanner, 377/* This struct is not used in this scanner,
391 but its presence is necessary. */ 378 but its presence is necessary. */
392struct yy_trans_info 379struct yy_trans_info
@@ -394,20 +381,19 @@ struct yy_trans_info
394 flex_int32_t yy_verify; 381 flex_int32_t yy_verify;
395 flex_int32_t yy_nxt; 382 flex_int32_t yy_nxt;
396 }; 383 };
397static yyconst flex_int16_t yy_accept[104] = 384static yyconst flex_int16_t yy_accept[94] =
398 { 0, 385 { 0,
399 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 386 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
400 21, 19, 16, 16, 19, 19, 19, 7, 7, 19, 387 18, 16, 13, 13, 16, 16, 16, 16, 16, 16,
401 7, 19, 19, 19, 19, 13, 14, 14, 19, 8, 388 16, 10, 11, 11, 6, 6, 13, 0, 2, 0,
402 8, 16, 0, 2, 0, 0, 9, 0, 0, 0, 389 7, 0, 0, 0, 0, 0, 0, 0, 5, 0,
403 0, 0, 0, 7, 7, 5, 0, 6, 0, 12, 390 9, 9, 11, 11, 6, 0, 7, 0, 0, 0,
404 12, 14, 14, 8, 0, 11, 9, 0, 0, 0, 391 0, 15, 0, 0, 0, 0, 6, 0, 14, 0,
405 0, 18, 0, 0, 0, 0, 8, 0, 17, 0, 392 0, 0, 0, 0, 8, 0, 0, 0, 0, 0,
406 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 393 0, 0, 0, 0, 0, 0, 0, 0, 3, 12,
407 0, 0, 0, 0, 0, 0, 0, 0, 3, 15,
408 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 394 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
409
410 0, 4, 0 395 0, 4, 0
396
411 } ; 397 } ;
412 398
413static yyconst flex_int32_t yy_ec[256] = 399static yyconst flex_int32_t yy_ec[256] =
@@ -416,16 +402,16 @@ static yyconst flex_int32_t yy_ec[256] =
416 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 402 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
417 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 403 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
418 1, 2, 1, 4, 5, 1, 1, 6, 1, 1, 404 1, 2, 1, 4, 5, 1, 1, 6, 1, 1,
419 1, 7, 8, 8, 9, 8, 10, 11, 12, 13, 405 1, 7, 5, 5, 8, 5, 9, 10, 11, 12,
420 13, 13, 13, 13, 13, 13, 13, 14, 1, 1, 406 12, 12, 12, 12, 12, 12, 12, 13, 1, 1,
421 1, 1, 8, 8, 15, 15, 15, 15, 15, 15, 407 1, 1, 5, 5, 14, 14, 14, 14, 14, 14,
422 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 408 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
423 16, 16, 16, 16, 16, 16, 16, 17, 16, 16, 409 15, 15, 15, 15, 15, 15, 15, 16, 15, 15,
424 1, 18, 19, 1, 16, 1, 15, 20, 21, 22, 410 1, 17, 18, 1, 15, 1, 14, 19, 20, 21,
425 411
426 23, 15, 16, 24, 25, 16, 16, 26, 27, 28, 412 22, 14, 15, 15, 23, 15, 15, 24, 25, 26,
427 24, 16, 16, 29, 30, 31, 32, 33, 16, 17, 413 15, 15, 15, 27, 28, 29, 30, 31, 15, 16,
428 16, 16, 34, 1, 35, 1, 1, 1, 1, 1, 414 15, 15, 32, 1, 33, 1, 1, 1, 1, 1,
429 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 415 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
430 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 416 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
431 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 417 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -442,136 +428,114 @@ static yyconst flex_int32_t yy_ec[256] =
442 1, 1, 1, 1, 1 428 1, 1, 1, 1, 1
443 } ; 429 } ;
444 430
445static yyconst flex_int32_t yy_meta[36] = 431static yyconst flex_int32_t yy_meta[34] =
446 { 0, 432 { 0,
447 1, 1, 1, 1, 2, 1, 2, 2, 2, 3, 433 1, 1, 1, 1, 2, 1, 2, 2, 3, 4,
448 4, 4, 4, 5, 6, 7, 7, 1, 1, 6, 434 4, 4, 5, 6, 7, 7, 1, 1, 6, 6,
449 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 435 6, 6, 7, 7, 7, 7, 7, 7, 7, 7,
450 7, 7, 7, 8, 1 436 7, 8, 1
451 } ; 437 } ;
452 438
453static yyconst flex_int16_t yy_base[117] = 439static yyconst flex_int16_t yy_base[106] =
454 { 0, 440 { 0,
455 0, 0, 30, 0, 44, 0, 67, 0, 97, 105, 441 0, 0, 237, 236, 25, 0, 47, 0, 30, 71,
456 302, 303, 35, 44, 40, 94, 112, 0, 129, 152, 442 244, 247, 82, 84, 84, 211, 95, 229, 218, 0,
457 296, 295, 159, 0, 176, 303, 0, 116, 95, 165, 443 111, 247, 0, 84, 83, 95, 106, 86, 247, 237,
458 49, 46, 102, 303, 296, 0, 0, 288, 290, 293, 444 0, 230, 231, 234, 207, 209, 212, 220, 247, 206,
459 264, 266, 270, 0, 0, 303, 0, 303, 264, 303, 445 247, 218, 0, 106, 116, 0, 0, 0, 223, 89,
460 0, 0, 195, 101, 0, 0, 0, 0, 284, 125, 446 226, 219, 199, 206, 200, 204, 0, 190, 213, 212,
461 277, 265, 225, 230, 216, 218, 0, 202, 224, 221, 447 202, 91, 178, 161, 247, 172, 144, 150, 140, 130,
462 217, 107, 196, 188, 303, 206, 179, 186, 178, 185, 448 140, 124, 128, 120, 138, 137, 123, 122, 247, 247,
463 183, 162, 161, 150, 169, 160, 145, 125, 303, 303, 449 134, 114, 132, 86, 135, 125, 90, 136, 247, 97,
464 137, 109, 190, 103, 203, 167, 108, 197, 303, 123, 450 29, 247, 247, 153, 156, 161, 165, 170, 176, 180,
465 451
466 29, 303, 303, 215, 221, 226, 229, 234, 240, 246, 452 187, 195, 200, 205, 212
467 250, 257, 265, 270, 275, 282
468 } ; 453 } ;
469 454
470static yyconst flex_int16_t yy_def[117] = 455static yyconst flex_int16_t yy_def[106] =
471 { 0, 456 { 0,
472 103, 1, 1, 3, 3, 5, 103, 7, 3, 3, 457 93, 1, 1, 1, 1, 5, 93, 7, 1, 1,
473 103, 103, 103, 103, 104, 105, 103, 106, 103, 19, 458 93, 93, 93, 93, 94, 95, 93, 96, 17, 97,
474 19, 20, 103, 107, 20, 103, 108, 109, 105, 103, 459 96, 93, 98, 99, 93, 93, 93, 94, 93, 94,
475 103, 103, 104, 103, 104, 110, 111, 103, 112, 113, 460 100, 93, 101, 102, 93, 93, 93, 96, 93, 93,
476 103, 103, 103, 106, 19, 103, 20, 103, 103, 103, 461 93, 96, 98, 99, 93, 103, 100, 104, 101, 101,
477 20, 108, 109, 103, 114, 110, 111, 115, 112, 112, 462 102, 93, 93, 93, 93, 93, 103, 104, 93, 93,
478 113, 103, 103, 103, 103, 103, 114, 115, 103, 103, 463 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
479 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 464 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
480 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 465 93, 93, 93, 93, 93, 105, 93, 105, 93, 105,
481 103, 103, 103, 103, 103, 116, 103, 116, 103, 116, 466 93, 93, 0, 93, 93, 93, 93, 93, 93, 93,
482 467
483 103, 103, 0, 103, 103, 103, 103, 103, 103, 103, 468 93, 93, 93, 93, 93
484 103, 103, 103, 103, 103, 103
485 } ; 469 } ;
486 470
487static yyconst flex_int16_t yy_nxt[339] = 471static yyconst flex_int16_t yy_nxt[281] =
488 { 0, 472 { 0,
489 12, 13, 14, 15, 12, 16, 12, 12, 12, 17, 473 12, 13, 14, 15, 12, 16, 12, 12, 17, 12,
490 18, 18, 18, 12, 19, 20, 20, 12, 12, 21, 474 12, 12, 12, 18, 18, 18, 12, 12, 18, 18,
491 19, 21, 19, 22, 20, 20, 20, 20, 20, 20, 475 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
492 20, 20, 20, 12, 12, 12, 32, 32, 102, 23, 476 18, 12, 12, 19, 20, 20, 20, 92, 21, 25,
493 12, 12, 12, 34, 20, 32, 32, 32, 32, 20, 477 26, 26, 22, 21, 21, 21, 21, 12, 13, 14,
494 20, 20, 20, 20, 24, 24, 24, 35, 25, 54, 478 15, 23, 16, 23, 23, 19, 23, 23, 23, 12,
495 54, 54, 26, 25, 25, 25, 25, 12, 13, 14, 479 24, 24, 24, 12, 12, 24, 24, 24, 24, 24,
496 15, 27, 12, 27, 27, 27, 23, 27, 27, 27, 480 24, 24, 24, 24, 24, 24, 24, 24, 12, 12,
497 12, 28, 28, 28, 12, 12, 28, 28, 28, 28, 481 25, 26, 26, 27, 27, 27, 27, 29, 43, 29,
498 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 482 43, 43, 45, 45, 45, 50, 39, 59, 46, 93,
499 483
500 12, 12, 29, 36, 103, 34, 17, 30, 31, 31, 484 30, 33, 30, 34, 45, 45, 45, 27, 27, 68,
501 29, 54, 54, 54, 17, 30, 31, 31, 39, 35, 485 43, 91, 43, 43, 69, 35, 87, 36, 39, 37,
502 52, 40, 52, 52, 52, 103, 78, 38, 38, 46, 486 42, 42, 42, 39, 42, 45, 45, 45, 89, 42,
503 101, 60, 79, 41, 69, 97, 42, 94, 43, 45, 487 42, 42, 42, 85, 85, 86, 85, 85, 86, 89,
504 45, 45, 46, 45, 47, 47, 93, 92, 45, 45, 488 84, 90, 83, 82, 81, 80, 79, 78, 77, 76,
505 45, 45, 47, 47, 47, 47, 47, 47, 47, 47, 489 75, 74, 90, 28, 28, 28, 28, 28, 28, 28,
506 47, 47, 47, 47, 47, 39, 47, 91, 40, 90, 490 28, 31, 31, 31, 38, 38, 38, 38, 41, 73,
507 99, 47, 47, 47, 47, 54, 54, 54, 89, 88, 491 41, 43, 72, 43, 71, 43, 43, 44, 33, 44,
508 41, 55, 87, 49, 100, 43, 51, 51, 51, 86, 492 44, 44, 44, 47, 69, 47, 47, 49, 49, 49,
509 51, 95, 95, 96, 85, 51, 51, 51, 51, 52, 493 49, 49, 49, 49, 49, 51, 51, 51, 51, 51,
510 494
511 99, 52, 52, 52, 95, 95, 96, 84, 46, 83, 495 51, 51, 51, 57, 70, 57, 58, 58, 58, 67,
512 82, 81, 39, 79, 100, 33, 33, 33, 33, 33, 496 58, 58, 88, 88, 88, 88, 88, 88, 88, 88,
513 33, 33, 33, 37, 80, 77, 37, 37, 37, 44, 497 34, 66, 65, 64, 63, 62, 61, 60, 52, 50,
514 40, 44, 50, 76, 50, 52, 75, 52, 74, 52, 498 39, 56, 39, 55, 54, 53, 52, 50, 48, 93,
515 52, 53, 73, 53, 53, 53, 53, 56, 56, 56, 499 40, 39, 32, 93, 19, 19, 11, 93, 93, 93,
516 72, 56, 56, 57, 71, 57, 57, 59, 59, 59, 500 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
517 59, 59, 59, 59, 59, 61, 61, 61, 61, 61, 501 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
518 61, 61, 61, 67, 70, 67, 68, 68, 68, 62, 502 93, 93, 93, 93, 93, 93, 93, 93, 93, 93
519 68, 68, 98, 98, 98, 98, 98, 98, 98, 98,
520 60, 66, 65, 64, 63, 62, 60, 58, 103, 48,
521
522 48, 103, 11, 103, 103, 103, 103, 103, 103, 103,
523 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
524 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
525 103, 103, 103, 103, 103, 103, 103, 103
526 } ; 503 } ;
527 504
528static yyconst flex_int16_t yy_chk[339] = 505static yyconst flex_int16_t yy_chk[281] =
529 { 0, 506 { 0,
530 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 507 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
531 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 508 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
532 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 509 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
533 1, 1, 1, 1, 1, 3, 13, 13, 101, 3, 510 1, 1, 1, 5, 5, 5, 5, 91, 5, 9,
534 3, 3, 3, 15, 3, 14, 14, 32, 32, 3, 511 9, 9, 5, 5, 5, 5, 5, 7, 7, 7,
535 3, 3, 3, 3, 5, 5, 5, 15, 5, 31,
536 31, 31, 5, 5, 5, 5, 5, 7, 7, 7,
537 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 512 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
538 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 513 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
539 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 514 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
540 515 10, 10, 10, 13, 13, 14, 14, 15, 24, 28,
541 7, 7, 9, 16, 29, 33, 9, 9, 9, 9, 516 24, 24, 25, 25, 25, 50, 24, 50, 25, 90,
542 10, 54, 54, 54, 10, 10, 10, 10, 17, 33, 517
543 28, 17, 28, 28, 28, 100, 72, 16, 29, 28, 518 15, 17, 28, 17, 26, 26, 26, 27, 27, 62,
544 97, 60, 72, 17, 60, 94, 17, 92, 17, 19, 519 44, 87, 44, 44, 62, 17, 84, 17, 44, 17,
545 19, 19, 19, 19, 19, 19, 91, 88, 19, 19, 520 21, 21, 21, 21, 21, 45, 45, 45, 86, 21,
546 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 521 21, 21, 21, 83, 83, 83, 85, 85, 85, 88,
547 19, 19, 20, 20, 20, 23, 20, 87, 23, 86, 522 82, 86, 81, 78, 77, 76, 75, 74, 73, 72,
548 96, 20, 20, 20, 20, 30, 30, 30, 85, 84, 523 71, 70, 88, 94, 94, 94, 94, 94, 94, 94,
549 23, 30, 83, 23, 96, 23, 25, 25, 25, 82, 524 94, 95, 95, 95, 96, 96, 96, 96, 97, 69,
550 25, 93, 93, 93, 81, 25, 25, 25, 25, 53, 525 97, 98, 68, 98, 67, 98, 98, 99, 66, 99,
551 526 99, 99, 99, 100, 64, 100, 100, 101, 101, 101,
552 98, 53, 53, 53, 95, 95, 95, 80, 53, 79, 527 101, 101, 101, 101, 101, 102, 102, 102, 102, 102,
553 78, 77, 76, 74, 98, 104, 104, 104, 104, 104, 528
554 104, 104, 104, 105, 73, 71, 105, 105, 105, 106, 529 102, 102, 102, 103, 63, 103, 104, 104, 104, 61,
555 70, 106, 107, 69, 107, 108, 68, 108, 66, 108, 530 104, 104, 105, 105, 105, 105, 105, 105, 105, 105,
556 108, 109, 65, 109, 109, 109, 109, 110, 110, 110, 531 60, 59, 58, 56, 55, 54, 53, 52, 51, 49,
557 64, 110, 110, 111, 63, 111, 111, 112, 112, 112, 532 42, 40, 38, 37, 36, 35, 34, 33, 32, 30,
558 112, 112, 112, 112, 112, 113, 113, 113, 113, 113, 533 19, 18, 16, 11, 4, 3, 93, 93, 93, 93,
559 113, 113, 113, 114, 62, 114, 115, 115, 115, 61, 534 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
560 115, 115, 116, 116, 116, 116, 116, 116, 116, 116, 535 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
561 59, 49, 43, 42, 41, 40, 39, 38, 35, 22, 536 93, 93, 93, 93, 93, 93, 93, 93, 93, 93
562
563 21, 11, 103, 103, 103, 103, 103, 103, 103, 103,
564 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
565 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
566 103, 103, 103, 103, 103, 103, 103, 103
567 } ; 537 } ;
568 538
569/* Table of booleans, true if rule could match eol. */
570static yyconst flex_int32_t yy_rule_can_match_eol[21] =
571 { 0,
5721, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
573 0, };
574
575static yy_state_type yy_last_accepting_state; 539static yy_state_type yy_last_accepting_state;
576static char *yy_last_accepting_cpos; 540static char *yy_last_accepting_cpos;
577 541
@@ -616,6 +580,13 @@ char *yytext;
616#include "srcpos.h" 580#include "srcpos.h"
617#include "dtc-parser.tab.h" 581#include "dtc-parser.tab.h"
618 582
583YYLTYPE yylloc;
584
585/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
586#define YY_USER_ACTION \
587 { \
588 srcpos_update(&yylloc, yytext, yyleng); \
589 }
619 590
620/*#define LEXDEBUG 1*/ 591/*#define LEXDEBUG 1*/
621 592
@@ -625,19 +596,14 @@ char *yytext;
625#define DPRINT(fmt, ...) do { } while (0) 596#define DPRINT(fmt, ...) do { } while (0)
626#endif 597#endif
627 598
628static int dts_version; /* = 0 */ 599static int dts_version = 1;
629 600
630#define BEGIN_DEFAULT() if (dts_version == 0) { \ 601#define BEGIN_DEFAULT() DPRINT("<V1>\n"); \
631 DPRINT("<INITIAL>\n"); \
632 BEGIN(INITIAL); \
633 } else { \
634 DPRINT("<V1>\n"); \
635 BEGIN(V1); \ 602 BEGIN(V1); \
636 }
637 603
638static void push_input_file(const char *filename); 604static void push_input_file(const char *filename);
639static int pop_input_file(void); 605static int pop_input_file(void);
640#line 641 "dtc-lexer.lex.c" 606#line 607 "dtc-lexer.lex.c"
641 607
642#define INITIAL 0 608#define INITIAL 0
643#define INCLUDE 1 609#define INCLUDE 1
@@ -826,9 +792,9 @@ YY_DECL
826 register char *yy_cp, *yy_bp; 792 register char *yy_cp, *yy_bp;
827 register int yy_act; 793 register int yy_act;
828 794
829#line 64 "dtc-lexer.l" 795#line 66 "dtc-lexer.l"
830 796
831#line 832 "dtc-lexer.lex.c" 797#line 798 "dtc-lexer.lex.c"
832 798
833 if ( !(yy_init) ) 799 if ( !(yy_init) )
834 { 800 {
@@ -881,35 +847,21 @@ yy_match:
881 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 847 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
882 { 848 {
883 yy_current_state = (int) yy_def[yy_current_state]; 849 yy_current_state = (int) yy_def[yy_current_state];
884 if ( yy_current_state >= 104 ) 850 if ( yy_current_state >= 94 )
885 yy_c = yy_meta[(unsigned int) yy_c]; 851 yy_c = yy_meta[(unsigned int) yy_c];
886 } 852 }
887 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; 853 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
888 ++yy_cp; 854 ++yy_cp;
889 } 855 }
890 while ( yy_base[yy_current_state] != 303 ); 856 while ( yy_current_state != 93 );
857 yy_cp = (yy_last_accepting_cpos);
858 yy_current_state = (yy_last_accepting_state);
891 859
892yy_find_action: 860yy_find_action:
893 yy_act = yy_accept[yy_current_state]; 861 yy_act = yy_accept[yy_current_state];
894 if ( yy_act == 0 )
895 { /* have to back up */
896 yy_cp = (yy_last_accepting_cpos);
897 yy_current_state = (yy_last_accepting_state);
898 yy_act = yy_accept[yy_current_state];
899 }
900 862
901 YY_DO_BEFORE_ACTION; 863 YY_DO_BEFORE_ACTION;
902 864
903 if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )
904 {
905 int yyl;
906 for ( yyl = 0; yyl < yyleng; ++yyl )
907 if ( yytext[yyl] == '\n' )
908
909 yylineno++;
910;
911 }
912
913do_action: /* This label is used only to access EOF actions. */ 865do_action: /* This label is used only to access EOF actions. */
914 866
915 switch ( yy_act ) 867 switch ( yy_act )
@@ -924,7 +876,7 @@ do_action: /* This label is used only to access EOF actions. */
924case 1: 876case 1:
925/* rule 1 can match eol */ 877/* rule 1 can match eol */
926YY_RULE_SETUP 878YY_RULE_SETUP
927#line 65 "dtc-lexer.l" 879#line 67 "dtc-lexer.l"
928{ 880{
929 char *name = strchr(yytext, '\"') + 1; 881 char *name = strchr(yytext, '\"') + 1;
930 yytext[yyleng-1] = '\0'; 882 yytext[yyleng-1] = '\0';
@@ -936,7 +888,7 @@ case YY_STATE_EOF(INCLUDE):
936case YY_STATE_EOF(BYTESTRING): 888case YY_STATE_EOF(BYTESTRING):
937case YY_STATE_EOF(PROPNODENAME): 889case YY_STATE_EOF(PROPNODENAME):
938case YY_STATE_EOF(V1): 890case YY_STATE_EOF(V1):
939#line 71 "dtc-lexer.l" 891#line 73 "dtc-lexer.l"
940{ 892{
941 if (!pop_input_file()) { 893 if (!pop_input_file()) {
942 yyterminate(); 894 yyterminate();
@@ -946,23 +898,18 @@ case YY_STATE_EOF(V1):
946case 2: 898case 2:
947/* rule 2 can match eol */ 899/* rule 2 can match eol */
948YY_RULE_SETUP 900YY_RULE_SETUP
949#line 77 "dtc-lexer.l" 901#line 79 "dtc-lexer.l"
950{ 902{
951 yylloc.file = srcpos_file;
952 yylloc.first_line = yylineno;
953 DPRINT("String: %s\n", yytext); 903 DPRINT("String: %s\n", yytext);
954 yylval.data = data_copy_escape_string(yytext+1, 904 yylval.data = data_copy_escape_string(yytext+1,
955 yyleng-2); 905 yyleng-2);
956 yylloc.first_line = yylineno;
957 return DT_STRING; 906 return DT_STRING;
958 } 907 }
959 YY_BREAK 908 YY_BREAK
960case 3: 909case 3:
961YY_RULE_SETUP 910YY_RULE_SETUP
962#line 87 "dtc-lexer.l" 911#line 86 "dtc-lexer.l"
963{ 912{
964 yylloc.file = srcpos_file;
965 yylloc.first_line = yylineno;
966 DPRINT("Keyword: /dts-v1/\n"); 913 DPRINT("Keyword: /dts-v1/\n");
967 dts_version = 1; 914 dts_version = 1;
968 BEGIN_DEFAULT(); 915 BEGIN_DEFAULT();
@@ -971,10 +918,8 @@ YY_RULE_SETUP
971 YY_BREAK 918 YY_BREAK
972case 4: 919case 4:
973YY_RULE_SETUP 920YY_RULE_SETUP
974#line 96 "dtc-lexer.l" 921#line 93 "dtc-lexer.l"
975{ 922{
976 yylloc.file = srcpos_file;
977 yylloc.first_line = yylineno;
978 DPRINT("Keyword: /memreserve/\n"); 923 DPRINT("Keyword: /memreserve/\n");
979 BEGIN_DEFAULT(); 924 BEGIN_DEFAULT();
980 return DT_MEMRESERVE; 925 return DT_MEMRESERVE;
@@ -982,158 +927,100 @@ YY_RULE_SETUP
982 YY_BREAK 927 YY_BREAK
983case 5: 928case 5:
984YY_RULE_SETUP 929YY_RULE_SETUP
985#line 104 "dtc-lexer.l" 930#line 99 "dtc-lexer.l"
986{ 931{
987 yylloc.file = srcpos_file;
988 yylloc.first_line = yylineno;
989 DPRINT("Label: %s\n", yytext); 932 DPRINT("Label: %s\n", yytext);
990 yylval.labelref = strdup(yytext); 933 yylval.labelref = xstrdup(yytext);
991 yylval.labelref[yyleng-1] = '\0'; 934 yylval.labelref[yyleng-1] = '\0';
992 return DT_LABEL; 935 return DT_LABEL;
993 } 936 }
994 YY_BREAK 937 YY_BREAK
995case 6: 938case 6:
996YY_RULE_SETUP 939YY_RULE_SETUP
997#line 113 "dtc-lexer.l" 940#line 106 "dtc-lexer.l"
998{
999 yylloc.file = srcpos_file;
1000 yylloc.first_line = yylineno;
1001 if (*yytext == 'b')
1002 yylval.cbase = 2;
1003 else if (*yytext == 'o')
1004 yylval.cbase = 8;
1005 else if (*yytext == 'd')
1006 yylval.cbase = 10;
1007 else
1008 yylval.cbase = 16;
1009 DPRINT("Base: %d\n", yylval.cbase);
1010 return DT_BASE;
1011 }
1012 YY_BREAK
1013case 7:
1014YY_RULE_SETUP
1015#line 128 "dtc-lexer.l"
1016{ 941{
1017 yylloc.file = srcpos_file; 942 yylval.literal = xstrdup(yytext);
1018 yylloc.first_line = yylineno;
1019 yylval.literal = strdup(yytext);
1020 DPRINT("Literal: '%s'\n", yylval.literal);
1021 return DT_LEGACYLITERAL;
1022 }
1023 YY_BREAK
1024case 8:
1025YY_RULE_SETUP
1026#line 136 "dtc-lexer.l"
1027{
1028 yylloc.file = srcpos_file;
1029 yylloc.first_line = yylineno;
1030 yylval.literal = strdup(yytext);
1031 DPRINT("Literal: '%s'\n", yylval.literal); 943 DPRINT("Literal: '%s'\n", yylval.literal);
1032 return DT_LITERAL; 944 return DT_LITERAL;
1033 } 945 }
1034 YY_BREAK 946 YY_BREAK
1035case 9: 947case 7:
1036YY_RULE_SETUP 948YY_RULE_SETUP
1037#line 144 "dtc-lexer.l" 949#line 112 "dtc-lexer.l"
1038{ /* label reference */ 950{ /* label reference */
1039 yylloc.file = srcpos_file;
1040 yylloc.first_line = yylineno;
1041 DPRINT("Ref: %s\n", yytext+1); 951 DPRINT("Ref: %s\n", yytext+1);
1042 yylval.labelref = strdup(yytext+1); 952 yylval.labelref = xstrdup(yytext+1);
1043 return DT_REF; 953 return DT_REF;
1044 } 954 }
1045 YY_BREAK 955 YY_BREAK
1046case 10: 956case 8:
1047YY_RULE_SETUP 957YY_RULE_SETUP
1048#line 152 "dtc-lexer.l" 958#line 118 "dtc-lexer.l"
1049{ /* new-style path reference */ 959{ /* new-style path reference */
1050 yylloc.file = srcpos_file;
1051 yylloc.first_line = yylineno;
1052 yytext[yyleng-1] = '\0'; 960 yytext[yyleng-1] = '\0';
1053 DPRINT("Ref: %s\n", yytext+2); 961 DPRINT("Ref: %s\n", yytext+2);
1054 yylval.labelref = strdup(yytext+2); 962 yylval.labelref = xstrdup(yytext+2);
1055 return DT_REF; 963 return DT_REF;
1056 } 964 }
1057 YY_BREAK 965 YY_BREAK
1058case 11: 966case 9:
1059YY_RULE_SETUP
1060#line 161 "dtc-lexer.l"
1061{ /* old-style path reference */
1062 yylloc.file = srcpos_file;
1063 yylloc.first_line = yylineno;
1064 DPRINT("Ref: %s\n", yytext+1);
1065 yylval.labelref = strdup(yytext+1);
1066 return DT_REF;
1067 }
1068 YY_BREAK
1069case 12:
1070YY_RULE_SETUP 967YY_RULE_SETUP
1071#line 169 "dtc-lexer.l" 968#line 125 "dtc-lexer.l"
1072{ 969{
1073 yylloc.file = srcpos_file;
1074 yylloc.first_line = yylineno;
1075 yylval.byte = strtol(yytext, NULL, 16); 970 yylval.byte = strtol(yytext, NULL, 16);
1076 DPRINT("Byte: %02x\n", (int)yylval.byte); 971 DPRINT("Byte: %02x\n", (int)yylval.byte);
1077 return DT_BYTE; 972 return DT_BYTE;
1078 } 973 }
1079 YY_BREAK 974 YY_BREAK
1080case 13: 975case 10:
1081YY_RULE_SETUP 976YY_RULE_SETUP
1082#line 177 "dtc-lexer.l" 977#line 131 "dtc-lexer.l"
1083{ 978{
1084 yylloc.file = srcpos_file;
1085 yylloc.first_line = yylineno;
1086 DPRINT("/BYTESTRING\n"); 979 DPRINT("/BYTESTRING\n");
1087 BEGIN_DEFAULT(); 980 BEGIN_DEFAULT();
1088 return ']'; 981 return ']';
1089 } 982 }
1090 YY_BREAK 983 YY_BREAK
1091case 14: 984case 11:
1092YY_RULE_SETUP 985YY_RULE_SETUP
1093#line 185 "dtc-lexer.l" 986#line 137 "dtc-lexer.l"
1094{ 987{
1095 yylloc.file = srcpos_file;
1096 yylloc.first_line = yylineno;
1097 DPRINT("PropNodeName: %s\n", yytext); 988 DPRINT("PropNodeName: %s\n", yytext);
1098 yylval.propnodename = strdup(yytext); 989 yylval.propnodename = xstrdup(yytext);
1099 BEGIN_DEFAULT(); 990 BEGIN_DEFAULT();
1100 return DT_PROPNODENAME; 991 return DT_PROPNODENAME;
1101 } 992 }
1102 YY_BREAK 993 YY_BREAK
1103case 15: 994case 12:
1104YY_RULE_SETUP 995YY_RULE_SETUP
1105#line 194 "dtc-lexer.l" 996#line 144 "dtc-lexer.l"
1106{ 997{
1107 yylloc.file = srcpos_file;
1108 yylloc.first_line = yylineno;
1109 DPRINT("Binary Include\n"); 998 DPRINT("Binary Include\n");
1110 return DT_INCBIN; 999 return DT_INCBIN;
1111 } 1000 }
1112 YY_BREAK 1001 YY_BREAK
1113case 16: 1002case 13:
1114/* rule 16 can match eol */ 1003/* rule 13 can match eol */
1115YY_RULE_SETUP 1004YY_RULE_SETUP
1116#line 201 "dtc-lexer.l" 1005#line 149 "dtc-lexer.l"
1117/* eat whitespace */ 1006/* eat whitespace */
1118 YY_BREAK 1007 YY_BREAK
1119case 17: 1008case 14:
1120/* rule 17 can match eol */ 1009/* rule 14 can match eol */
1121YY_RULE_SETUP 1010YY_RULE_SETUP
1122#line 202 "dtc-lexer.l" 1011#line 150 "dtc-lexer.l"
1123/* eat C-style comments */ 1012/* eat C-style comments */
1124 YY_BREAK 1013 YY_BREAK
1125case 18: 1014case 15:
1126/* rule 18 can match eol */ 1015/* rule 15 can match eol */
1127YY_RULE_SETUP 1016YY_RULE_SETUP
1128#line 203 "dtc-lexer.l" 1017#line 151 "dtc-lexer.l"
1129/* eat C++-style comments */ 1018/* eat C++-style comments */
1130 YY_BREAK 1019 YY_BREAK
1131case 19: 1020case 16:
1132YY_RULE_SETUP 1021YY_RULE_SETUP
1133#line 205 "dtc-lexer.l" 1022#line 153 "dtc-lexer.l"
1134{ 1023{
1135 yylloc.file = srcpos_file;
1136 yylloc.first_line = yylineno;
1137 DPRINT("Char: %c (\\x%02x)\n", yytext[0], 1024 DPRINT("Char: %c (\\x%02x)\n", yytext[0],
1138 (unsigned)yytext[0]); 1025 (unsigned)yytext[0]);
1139 if (yytext[0] == '[') { 1026 if (yytext[0] == '[') {
@@ -1148,12 +1035,12 @@ YY_RULE_SETUP
1148 return yytext[0]; 1035 return yytext[0];
1149 } 1036 }
1150 YY_BREAK 1037 YY_BREAK
1151case 20: 1038case 17:
1152YY_RULE_SETUP 1039YY_RULE_SETUP
1153#line 222 "dtc-lexer.l" 1040#line 168 "dtc-lexer.l"
1154ECHO; 1041ECHO;
1155 YY_BREAK 1042 YY_BREAK
1156#line 1157 "dtc-lexer.lex.c" 1043#line 1044 "dtc-lexer.lex.c"
1157 1044
1158 case YY_END_OF_BUFFER: 1045 case YY_END_OF_BUFFER:
1159 { 1046 {
@@ -1218,7 +1105,8 @@ ECHO;
1218 1105
1219 else 1106 else
1220 { 1107 {
1221 yy_cp = (yy_c_buf_p); 1108 yy_cp = (yy_last_accepting_cpos);
1109 yy_current_state = (yy_last_accepting_state);
1222 goto yy_find_action; 1110 goto yy_find_action;
1223 } 1111 }
1224 } 1112 }
@@ -1443,7 +1331,7 @@ static int yy_get_next_buffer (void)
1443 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 1331 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1444 { 1332 {
1445 yy_current_state = (int) yy_def[yy_current_state]; 1333 yy_current_state = (int) yy_def[yy_current_state];
1446 if ( yy_current_state >= 104 ) 1334 if ( yy_current_state >= 94 )
1447 yy_c = yy_meta[(unsigned int) yy_c]; 1335 yy_c = yy_meta[(unsigned int) yy_c];
1448 } 1336 }
1449 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; 1337 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1471,11 +1359,11 @@ static int yy_get_next_buffer (void)
1471 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 1359 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1472 { 1360 {
1473 yy_current_state = (int) yy_def[yy_current_state]; 1361 yy_current_state = (int) yy_def[yy_current_state];
1474 if ( yy_current_state >= 104 ) 1362 if ( yy_current_state >= 94 )
1475 yy_c = yy_meta[(unsigned int) yy_c]; 1363 yy_c = yy_meta[(unsigned int) yy_c];
1476 } 1364 }
1477 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; 1365 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1478 yy_is_jam = (yy_current_state == 103); 1366 yy_is_jam = (yy_current_state == 93);
1479 1367
1480 return yy_is_jam ? 0 : yy_current_state; 1368 return yy_is_jam ? 0 : yy_current_state;
1481} 1369}
@@ -1550,11 +1438,6 @@ static int yy_get_next_buffer (void)
1550 *(yy_c_buf_p) = '\0'; /* preserve yytext */ 1438 *(yy_c_buf_p) = '\0'; /* preserve yytext */
1551 (yy_hold_char) = *++(yy_c_buf_p); 1439 (yy_hold_char) = *++(yy_c_buf_p);
1552 1440
1553 if ( c == '\n' )
1554
1555 yylineno++;
1556;
1557
1558 return c; 1441 return c;
1559} 1442}
1560#endif /* ifndef YY_NO_INPUT */ 1443#endif /* ifndef YY_NO_INPUT */
@@ -1669,10 +1552,6 @@ static void yy_load_buffer_state (void)
1669 yyfree((void *) b ); 1552 yyfree((void *) b );
1670} 1553}
1671 1554
1672#ifndef __cplusplus
1673extern int isatty (int );
1674#endif /* __cplusplus */
1675
1676/* Initializes or reinitializes a buffer. 1555/* Initializes or reinitializes a buffer.
1677 * This function is sometimes called more than once on the same buffer, 1556 * This function is sometimes called more than once on the same buffer,
1678 * such as during a yyrestart() or at EOF. 1557 * such as during a yyrestart() or at EOF.
@@ -1696,7 +1575,7 @@ extern int isatty (int );
1696 b->yy_bs_column = 0; 1575 b->yy_bs_column = 0;
1697 } 1576 }
1698 1577
1699 b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; 1578 b->yy_is_interactive = 0;
1700 1579
1701 errno = oerrno; 1580 errno = oerrno;
1702} 1581}
@@ -2025,9 +1904,6 @@ static int yy_init_globals (void)
2025 * This function is called from yylex_destroy(), so don't allocate here. 1904 * This function is called from yylex_destroy(), so don't allocate here.
2026 */ 1905 */
2027 1906
2028 /* We do not touch yylineno unless the option is enabled. */
2029 yylineno = 1;
2030
2031 (yy_buffer_stack) = 0; 1907 (yy_buffer_stack) = 0;
2032 (yy_buffer_stack_top) = 0; 1908 (yy_buffer_stack_top) = 0;
2033 (yy_buffer_stack_max) = 0; 1909 (yy_buffer_stack_max) = 0;
@@ -2120,104 +1996,29 @@ void yyfree (void * ptr )
2120 1996
2121#define YYTABLES_NAME "yytables" 1997#define YYTABLES_NAME "yytables"
2122 1998
2123#line 222 "dtc-lexer.l" 1999#line 168 "dtc-lexer.l"
2124
2125
2126
2127
2128/*
2129 * Stack of nested include file contexts.
2130 */
2131
2132struct incl_file {
2133 struct dtc_file *file;
2134 YY_BUFFER_STATE yy_prev_buf;
2135 int yy_prev_lineno;
2136 struct incl_file *prev;
2137};
2138
2139static struct incl_file *incl_file_stack;
2140 2000
2141 2001
2142/*
2143 * Detect infinite include recursion.
2144 */
2145#define MAX_INCLUDE_DEPTH (100)
2146
2147static int incl_depth = 0;
2148
2149 2002
2150static void push_input_file(const char *filename) 2003static void push_input_file(const char *filename)
2151{ 2004{
2152 struct incl_file *incl_file;
2153 struct dtc_file *newfile;
2154 struct search_path search, *searchptr = NULL;
2155
2156 assert(filename); 2005 assert(filename);
2157 2006
2158 if (incl_depth++ >= MAX_INCLUDE_DEPTH) 2007 srcfile_push(filename);
2159 die("Includes nested too deeply");
2160
2161 if (srcpos_file) {
2162 search.dir = srcpos_file->dir;
2163 search.next = NULL;
2164 search.prev = NULL;
2165 searchptr = &search;
2166 }
2167
2168 newfile = dtc_open_file(filename, searchptr);
2169 2008
2170 incl_file = xmalloc(sizeof(struct incl_file)); 2009 yyin = current_srcfile->f;
2171 2010
2172 /* 2011 yypush_buffer_state(yy_create_buffer(yyin,YY_BUF_SIZE));
2173 * Save current context.
2174 */
2175 incl_file->yy_prev_buf = YY_CURRENT_BUFFER;
2176 incl_file->yy_prev_lineno = yylineno;
2177 incl_file->file = srcpos_file;
2178 incl_file->prev = incl_file_stack;
2179
2180 incl_file_stack = incl_file;
2181
2182 /*
2183 * Establish new context.
2184 */
2185 srcpos_file = newfile;
2186 yylineno = 1;
2187 yyin = newfile->file;
2188 yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
2189} 2012}
2190 2013
2191 2014
2192static int pop_input_file(void) 2015static int pop_input_file(void)
2193{ 2016{
2194 struct incl_file *incl_file; 2017 if (srcfile_pop() == 0)
2195
2196 if (incl_file_stack == 0)
2197 return 0; 2018 return 0;
2198 2019
2199 dtc_close_file(srcpos_file); 2020 yypop_buffer_state();
2200 2021 yyin = current_srcfile->f;
2201 /*
2202 * Pop.
2203 */
2204 --incl_depth;
2205 incl_file = incl_file_stack;
2206 incl_file_stack = incl_file->prev;
2207
2208 /*
2209 * Recover old context.
2210 */
2211 yy_delete_buffer(YY_CURRENT_BUFFER);
2212 yy_switch_to_buffer(incl_file->yy_prev_buf);
2213 yylineno = incl_file->yy_prev_lineno;
2214 srcpos_file = incl_file->file;
2215 yyin = incl_file->file ? incl_file->file->file : NULL;
2216
2217 /*
2218 * Free old state.
2219 */
2220 free(incl_file);
2221 2022
2222 return 1; 2023 return 1;
2223} 2024}
diff --git a/scripts/dtc/dtc-parser.tab.c_shipped b/scripts/dtc/dtc-parser.tab.c_shipped
index 27129377e5d2..9be2eea18a30 100644
--- a/scripts/dtc/dtc-parser.tab.c_shipped
+++ b/scripts/dtc/dtc-parser.tab.c_shipped
@@ -1,24 +1,23 @@
1/* A Bison parser, made by GNU Bison 2.3. */
2 1
3/* Skeleton implementation for Bison's Yacc-like parsers in C 2/* A Bison parser, made by GNU Bison 2.4.1. */
4 3
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 4/* Skeleton implementation for Bison's Yacc-like parsers in C
5
6 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc. 7 Free Software Foundation, Inc.
7 8
8 This program is free software; you can redistribute it and/or modify 9 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option) 11 the Free Software Foundation, either version 3 of the License, or
11 any later version. 12 (at your option) any later version.
12 13
13 This program is distributed in the hope that it will be useful, 14 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 17 GNU General Public License for more details.
17 18
18 You should have received a copy of the GNU General Public License 19 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 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22 21
23/* As a special exception, you may create a larger work that contains 22/* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work 23 part or all of the Bison parser skeleton and distribute that work
@@ -29,7 +28,7 @@
29 special exception, which will cause the skeleton and the resulting 28 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public 29 Bison output files to be licensed under the GNU General Public
31 License without this special exception. 30 License without this special exception.
32 31
33 This special exception was added by the Free Software Foundation in 32 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */ 33 version 2.2 of Bison. */
35 34
@@ -47,7 +46,7 @@
47#define YYBISON 1 46#define YYBISON 1
48 47
49/* Bison version. */ 48/* Bison version. */
50#define YYBISON_VERSION "2.3" 49#define YYBISON_VERSION "2.4.1"
51 50
52/* Skeleton name. */ 51/* Skeleton name. */
53#define YYSKELETON_NAME "yacc.c" 52#define YYSKELETON_NAME "yacc.c"
@@ -55,55 +54,32 @@
55/* Pure parsers. */ 54/* Pure parsers. */
56#define YYPURE 0 55#define YYPURE 0
57 56
58/* Using locations. */ 57/* Push parsers. */
59#define YYLSP_NEEDED 1 58#define YYPUSH 0
60
61 59
60/* Pull parsers. */
61#define YYPULL 1
62 62
63/* Tokens. */ 63/* Using locations. */
64#ifndef YYTOKENTYPE 64#define YYLSP_NEEDED 0
65# define YYTOKENTYPE
66 /* Put the tokens into the symbol table, so that GDB and other debuggers
67 know about them. */
68 enum yytokentype {
69 DT_V1 = 258,
70 DT_MEMRESERVE = 259,
71 DT_PROPNODENAME = 260,
72 DT_LITERAL = 261,
73 DT_LEGACYLITERAL = 262,
74 DT_BASE = 263,
75 DT_BYTE = 264,
76 DT_STRING = 265,
77 DT_LABEL = 266,
78 DT_REF = 267,
79 DT_INCBIN = 268
80 };
81#endif
82/* Tokens. */
83#define DT_V1 258
84#define DT_MEMRESERVE 259
85#define DT_PROPNODENAME 260
86#define DT_LITERAL 261
87#define DT_LEGACYLITERAL 262
88#define DT_BASE 263
89#define DT_BYTE 264
90#define DT_STRING 265
91#define DT_LABEL 266
92#define DT_REF 267
93#define DT_INCBIN 268
94
95 65
96 66
97 67
98/* Copy the first part of user declarations. */ 68/* Copy the first part of user declarations. */
99#line 23 "dtc-parser.y" 69
70/* Line 189 of yacc.c */
71#line 21 "dtc-parser.y"
100 72
101#include <stdio.h> 73#include <stdio.h>
102 74
103#include "dtc.h" 75#include "dtc.h"
104#include "srcpos.h" 76#include "srcpos.h"
105 77
78YYLTYPE yylloc;
79
106extern int yylex(void); 80extern int yylex(void);
81extern void print_error(char const *fmt, ...);
82extern void yyerror(char const *s);
107 83
108extern struct boot_info *the_boot_info; 84extern struct boot_info *the_boot_info;
109extern int treesource_error; 85extern int treesource_error;
@@ -111,6 +87,9 @@ extern int treesource_error;
111static unsigned long long eval_literal(const char *s, int base, int bits); 87static unsigned long long eval_literal(const char *s, int base, int bits);
112 88
113 89
90/* Line 189 of yacc.c */
91#line 92 "dtc-parser.tab.c"
92
114/* Enabling traces. */ 93/* Enabling traces. */
115#ifndef YYDEBUG 94#ifndef YYDEBUG
116# define YYDEBUG 0 95# define YYDEBUG 0
@@ -129,10 +108,35 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
129# define YYTOKEN_TABLE 0 108# define YYTOKEN_TABLE 0
130#endif 109#endif
131 110
111
112/* Tokens. */
113#ifndef YYTOKENTYPE
114# define YYTOKENTYPE
115 /* Put the tokens into the symbol table, so that GDB and other debuggers
116 know about them. */
117 enum yytokentype {
118 DT_V1 = 258,
119 DT_MEMRESERVE = 259,
120 DT_PROPNODENAME = 260,
121 DT_LITERAL = 261,
122 DT_BASE = 262,
123 DT_BYTE = 263,
124 DT_STRING = 264,
125 DT_LABEL = 265,
126 DT_REF = 266,
127 DT_INCBIN = 267
128 };
129#endif
130
131
132
132#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 133#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
133typedef union YYSTYPE 134typedef union YYSTYPE
134#line 37 "dtc-parser.y"
135{ 135{
136
137/* Line 214 of yacc.c */
138#line 39 "dtc-parser.y"
139
136 char *propnodename; 140 char *propnodename;
137 char *literal; 141 char *literal;
138 char *labelref; 142 char *labelref;
@@ -147,34 +151,23 @@ typedef union YYSTYPE
147 struct node *node; 151 struct node *node;
148 struct node *nodelist; 152 struct node *nodelist;
149 struct reserve_info *re; 153 struct reserve_info *re;
150} 154
151/* Line 187 of yacc.c. */ 155
152#line 153 "dtc-parser.tab.c" 156
153 YYSTYPE; 157/* Line 214 of yacc.c */
158#line 159 "dtc-parser.tab.c"
159} YYSTYPE;
160# define YYSTYPE_IS_TRIVIAL 1
154# define yystype YYSTYPE /* obsolescent; will be withdrawn */ 161# define yystype YYSTYPE /* obsolescent; will be withdrawn */
155# define YYSTYPE_IS_DECLARED 1 162# define YYSTYPE_IS_DECLARED 1
156# define YYSTYPE_IS_TRIVIAL 1
157#endif
158
159#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
160typedef struct YYLTYPE
161{
162 int first_line;
163 int first_column;
164 int last_line;
165 int last_column;
166} YYLTYPE;
167# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
168# define YYLTYPE_IS_DECLARED 1
169# define YYLTYPE_IS_TRIVIAL 1
170#endif 163#endif
171 164
172 165
173/* Copy the second part of user declarations. */ 166/* Copy the second part of user declarations. */
174 167
175 168
176/* Line 216 of yacc.c. */ 169/* Line 264 of yacc.c */
177#line 178 "dtc-parser.tab.c" 170#line 171 "dtc-parser.tab.c"
178 171
179#ifdef short 172#ifdef short
180# undef short 173# undef short
@@ -249,14 +242,14 @@ typedef short int yytype_int16;
249#if (defined __STDC__ || defined __C99__FUNC__ \ 242#if (defined __STDC__ || defined __C99__FUNC__ \
250 || defined __cplusplus || defined _MSC_VER) 243 || defined __cplusplus || defined _MSC_VER)
251static int 244static int
252YYID (int i) 245YYID (int yyi)
253#else 246#else
254static int 247static int
255YYID (i) 248YYID (yyi)
256 int i; 249 int yyi;
257#endif 250#endif
258{ 251{
259 return i; 252 return yyi;
260} 253}
261#endif 254#endif
262 255
@@ -332,15 +325,13 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
332 325
333#if (! defined yyoverflow \ 326#if (! defined yyoverflow \
334 && (! defined __cplusplus \ 327 && (! defined __cplusplus \
335 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ 328 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
336 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
337 329
338/* A type that is properly aligned for any stack member. */ 330/* A type that is properly aligned for any stack member. */
339union yyalloc 331union yyalloc
340{ 332{
341 yytype_int16 yyss; 333 yytype_int16 yyss_alloc;
342 YYSTYPE yyvs; 334 YYSTYPE yyvs_alloc;
343 YYLTYPE yyls;
344}; 335};
345 336
346/* The size of the maximum gap between one aligned stack and the next. */ 337/* The size of the maximum gap between one aligned stack and the next. */
@@ -349,8 +340,8 @@ union yyalloc
349/* The size of an array large to enough to hold all stacks, each with 340/* The size of an array large to enough to hold all stacks, each with
350 N elements. */ 341 N elements. */
351# define YYSTACK_BYTES(N) \ 342# define YYSTACK_BYTES(N) \
352 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ 343 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
353 + 2 * YYSTACK_GAP_MAXIMUM) 344 + YYSTACK_GAP_MAXIMUM)
354 345
355/* Copy COUNT objects from FROM to TO. The source and destination do 346/* Copy COUNT objects from FROM to TO. The source and destination do
356 not overlap. */ 347 not overlap. */
@@ -375,12 +366,12 @@ union yyalloc
375 elements in the stack, and YYPTR gives the new location of the 366 elements in the stack, and YYPTR gives the new location of the
376 stack. Advance YYPTR to a properly aligned location for the next 367 stack. Advance YYPTR to a properly aligned location for the next
377 stack. */ 368 stack. */
378# define YYSTACK_RELOCATE(Stack) \ 369# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
379 do \ 370 do \
380 { \ 371 { \
381 YYSIZE_T yynewbytes; \ 372 YYSIZE_T yynewbytes; \
382 YYCOPY (&yyptr->Stack, Stack, yysize); \ 373 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
383 Stack = &yyptr->Stack; \ 374 Stack = &yyptr->Stack_alloc; \
384 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ 375 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
385 yyptr += yynewbytes / sizeof (*yyptr); \ 376 yyptr += yynewbytes / sizeof (*yyptr); \
386 } \ 377 } \
@@ -389,22 +380,22 @@ union yyalloc
389#endif 380#endif
390 381
391/* YYFINAL -- State number of the termination state. */ 382/* YYFINAL -- State number of the termination state. */
392#define YYFINAL 9 383#define YYFINAL 4
393/* YYLAST -- Last index in YYTABLE. */ 384/* YYLAST -- Last index in YYTABLE. */
394#define YYLAST 73 385#define YYLAST 56
395 386
396/* YYNTOKENS -- Number of terminals. */ 387/* YYNTOKENS -- Number of terminals. */
397#define YYNTOKENS 27 388#define YYNTOKENS 25
398/* YYNNTS -- Number of nonterminals. */ 389/* YYNNTS -- Number of nonterminals. */
399#define YYNNTS 20 390#define YYNNTS 16
400/* YYNRULES -- Number of rules. */ 391/* YYNRULES -- Number of rules. */
401#define YYNRULES 45 392#define YYNRULES 39
402/* YYNRULES -- Number of states. */ 393/* YYNRULES -- Number of states. */
403#define YYNSTATES 76 394#define YYNSTATES 67
404 395
405/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ 396/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
406#define YYUNDEFTOK 2 397#define YYUNDEFTOK 2
407#define YYMAXUTOK 268 398#define YYMAXUTOK 267
408 399
409#define YYTRANSLATE(YYX) \ 400#define YYTRANSLATE(YYX) \
410 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) 401 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@@ -416,15 +407,15 @@ static const yytype_uint8 yytranslate[] =
416 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 407 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
417 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 408 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
418 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 409 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
419 24, 26, 2, 2, 25, 15, 2, 16, 2, 2, 410 22, 24, 2, 2, 23, 2, 2, 14, 2, 2,
420 2, 2, 2, 2, 2, 2, 2, 2, 2, 14, 411 2, 2, 2, 2, 2, 2, 2, 2, 2, 13,
421 20, 19, 21, 2, 2, 2, 2, 2, 2, 2, 412 18, 17, 19, 2, 2, 2, 2, 2, 2, 2,
422 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 413 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
423 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 414 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
424 2, 22, 2, 23, 2, 2, 2, 2, 2, 2, 415 2, 20, 2, 21, 2, 2, 2, 2, 2, 2,
425 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 416 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
426 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 417 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
427 2, 2, 2, 17, 2, 18, 2, 2, 2, 2, 418 2, 2, 2, 15, 2, 16, 2, 2, 2, 2,
428 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 419 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
429 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 420 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
430 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 421 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
@@ -438,7 +429,7 @@ static const yytype_uint8 yytranslate[] =
438 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 429 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
439 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 430 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
440 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 431 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
441 5, 6, 7, 8, 9, 10, 11, 12, 13 432 5, 6, 7, 8, 9, 10, 11, 12
442}; 433};
443 434
444#if YYDEBUG 435#if YYDEBUG
@@ -446,41 +437,37 @@ static const yytype_uint8 yytranslate[] =
446 YYRHS. */ 437 YYRHS. */
447static const yytype_uint8 yyprhs[] = 438static const yytype_uint8 yyprhs[] =
448{ 439{
449 0, 0, 3, 8, 11, 12, 15, 21, 22, 25, 440 0, 0, 3, 8, 9, 12, 17, 20, 22, 25,
450 27, 34, 36, 38, 41, 47, 48, 51, 57, 61, 441 29, 33, 39, 40, 43, 48, 51, 54, 57, 62,
451 64, 69, 74, 77, 87, 93, 96, 97, 100, 103, 442 67, 70, 80, 86, 89, 90, 93, 96, 97, 100,
452 104, 107, 110, 113, 114, 116, 118, 121, 122, 125, 443 103, 106, 108, 109, 112, 115, 116, 119, 122, 125
453 128, 129, 132, 135, 139, 140
454}; 444};
455 445
456/* YYRHS -- A `-1'-separated list of the rules' RHS. */ 446/* YYRHS -- A `-1'-separated list of the rules' RHS. */
457static const yytype_int8 yyrhs[] = 447static const yytype_int8 yyrhs[] =
458{ 448{
459 28, 0, -1, 3, 14, 29, 34, -1, 31, 34, 449 26, 0, -1, 3, 13, 27, 30, -1, -1, 28,
460 -1, -1, 30, 29, -1, 46, 4, 33, 33, 14, 450 27, -1, 4, 29, 29, 13, -1, 10, 28, -1,
461 -1, -1, 32, 31, -1, 30, -1, 46, 4, 33, 451 6, -1, 14, 31, -1, 30, 14, 31, -1, 30,
462 15, 33, 14, -1, 6, -1, 7, -1, 16, 35, 452 11, 31, -1, 15, 32, 39, 16, 13, -1, -1,
463 -1, 17, 36, 44, 18, 14, -1, -1, 36, 37, 453 32, 33, -1, 5, 17, 34, 13, -1, 5, 13,
464 -1, 46, 5, 19, 38, 14, -1, 46, 5, 14, 454 -1, 10, 33, -1, 35, 9, -1, 35, 18, 36,
465 -1, 39, 10, -1, 39, 20, 40, 21, -1, 39, 455 19, -1, 35, 20, 38, 21, -1, 35, 11, -1,
466 22, 43, 23, -1, 39, 12, -1, 39, 13, 24, 456 35, 12, 22, 9, 23, 29, 23, 29, 24, -1,
467 10, 25, 33, 25, 33, 26, -1, 39, 13, 24, 457 35, 12, 22, 9, 24, -1, 34, 10, -1, -1,
468 10, 26, -1, 38, 11, -1, -1, 38, 25, -1, 458 34, 23, -1, 35, 10, -1, -1, 36, 37, -1,
469 39, 11, -1, -1, 40, 42, -1, 40, 12, -1, 459 36, 11, -1, 36, 10, -1, 6, -1, -1, 38,
470 40, 11, -1, -1, 8, -1, 6, -1, 41, 7, 460 8, -1, 38, 10, -1, -1, 40, 39, -1, 40,
471 -1, -1, 43, 9, -1, 43, 11, -1, -1, 45, 461 33, -1, 5, 31, -1, 10, 40, -1
472 44, -1, 45, 37, -1, 46, 5, 35, -1, -1,
473 11, -1
474}; 462};
475 463
476/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ 464/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
477static const yytype_uint16 yyrline[] = 465static const yytype_uint16 yyrline[] =
478{ 466{
479 0, 89, 89, 93, 101, 104, 111, 119, 122, 129, 467 0, 86, 86, 95, 98, 105, 109, 117, 124, 128,
480 133, 140, 144, 151, 158, 166, 169, 176, 180, 187, 468 132, 145, 153, 156, 163, 167, 171, 179, 183, 187,
481 191, 195, 199, 203, 220, 231, 239, 242, 246, 254, 469 191, 195, 212, 222, 230, 233, 237, 245, 248, 252,
482 257, 261, 266, 274, 277, 281, 285, 293, 296, 300, 470 257, 264, 272, 275, 279, 287, 290, 294, 302, 306
483 308, 311, 315, 323, 331, 334
484}; 471};
485#endif 472#endif
486 473
@@ -490,13 +477,12 @@ static const yytype_uint16 yyrline[] =
490static const char *const yytname[] = 477static const char *const yytname[] =
491{ 478{
492 "$end", "error", "$undefined", "DT_V1", "DT_MEMRESERVE", 479 "$end", "error", "$undefined", "DT_V1", "DT_MEMRESERVE",
493 "DT_PROPNODENAME", "DT_LITERAL", "DT_LEGACYLITERAL", "DT_BASE", 480 "DT_PROPNODENAME", "DT_LITERAL", "DT_BASE", "DT_BYTE", "DT_STRING",
494 "DT_BYTE", "DT_STRING", "DT_LABEL", "DT_REF", "DT_INCBIN", "';'", "'-'", 481 "DT_LABEL", "DT_REF", "DT_INCBIN", "';'", "'/'", "'{'", "'}'", "'='",
495 "'/'", "'{'", "'}'", "'='", "'<'", "'>'", "'['", "']'", "'('", "','", 482 "'<'", "'>'", "'['", "']'", "'('", "','", "')'", "$accept", "sourcefile",
496 "')'", "$accept", "sourcefile", "memreserves", "memreserve", 483 "memreserves", "memreserve", "addr", "devicetree", "nodedef", "proplist",
497 "v0_memreserves", "v0_memreserve", "addr", "devicetree", "nodedef", 484 "propdef", "propdata", "propdataprefix", "celllist", "cellval",
498 "proplist", "propdef", "propdata", "propdataprefix", "celllist", 485 "bytestring", "subnodes", "subnode", 0
499 "cellbase", "cellval", "bytestring", "subnodes", "subnode", "label", 0
500}; 486};
501#endif 487#endif
502 488
@@ -506,29 +492,27 @@ static const char *const yytname[] =
506static const yytype_uint16 yytoknum[] = 492static const yytype_uint16 yytoknum[] =
507{ 493{
508 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 494 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
509 265, 266, 267, 268, 59, 45, 47, 123, 125, 61, 495 265, 266, 267, 59, 47, 123, 125, 61, 60, 62,
510 60, 62, 91, 93, 40, 44, 41 496 91, 93, 40, 44, 41
511}; 497};
512# endif 498# endif
513 499
514/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ 500/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
515static const yytype_uint8 yyr1[] = 501static const yytype_uint8 yyr1[] =
516{ 502{
517 0, 27, 28, 28, 29, 29, 30, 31, 31, 32, 503 0, 25, 26, 27, 27, 28, 28, 29, 30, 30,
518 32, 33, 33, 34, 35, 36, 36, 37, 37, 38, 504 30, 31, 32, 32, 33, 33, 33, 34, 34, 34,
519 38, 38, 38, 38, 38, 38, 39, 39, 39, 40, 505 34, 34, 34, 34, 35, 35, 35, 36, 36, 36,
520 40, 40, 40, 41, 41, 42, 42, 43, 43, 43, 506 36, 37, 38, 38, 38, 39, 39, 39, 40, 40
521 44, 44, 44, 45, 46, 46
522}; 507};
523 508
524/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ 509/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
525static const yytype_uint8 yyr2[] = 510static const yytype_uint8 yyr2[] =
526{ 511{
527 0, 2, 4, 2, 0, 2, 5, 0, 2, 1, 512 0, 2, 4, 0, 2, 4, 2, 1, 2, 3,
528 6, 1, 1, 2, 5, 0, 2, 5, 3, 2, 513 3, 5, 0, 2, 4, 2, 2, 2, 4, 4,
529 4, 4, 2, 9, 5, 2, 0, 2, 2, 0, 514 2, 9, 5, 2, 0, 2, 2, 0, 2, 2,
530 2, 2, 2, 0, 1, 1, 2, 0, 2, 2, 515 2, 1, 0, 2, 2, 0, 2, 2, 2, 2
531 0, 2, 2, 3, 0, 1
532}; 516};
533 517
534/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state 518/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
@@ -536,86 +520,79 @@ static const yytype_uint8 yyr2[] =
536 means the default is an error. */ 520 means the default is an error. */
537static const yytype_uint8 yydefact[] = 521static const yytype_uint8 yydefact[] =
538{ 522{
539 7, 0, 45, 0, 9, 0, 7, 0, 4, 1, 523 0, 0, 0, 3, 1, 0, 0, 0, 3, 7,
540 0, 3, 8, 0, 0, 4, 0, 15, 13, 11, 524 0, 6, 0, 2, 4, 0, 12, 8, 0, 0,
541 12, 0, 2, 5, 0, 40, 0, 0, 0, 16, 525 5, 35, 10, 9, 0, 0, 13, 0, 35, 15,
542 0, 40, 0, 0, 6, 0, 42, 41, 0, 10, 526 24, 38, 16, 39, 0, 37, 36, 0, 0, 11,
543 14, 18, 26, 43, 0, 0, 25, 17, 27, 19, 527 23, 14, 25, 17, 26, 20, 0, 27, 32, 0,
544 28, 22, 0, 29, 37, 0, 33, 0, 0, 35, 528 0, 0, 0, 31, 30, 29, 18, 28, 33, 34,
545 34, 32, 31, 20, 0, 30, 38, 39, 21, 0, 529 19, 0, 22, 0, 0, 0, 21
546 24, 36, 0, 0, 0, 23
547}; 530};
548 531
549/* YYDEFGOTO[NTERM-NUM]. */ 532/* YYDEFGOTO[NTERM-NUM]. */
550static const yytype_int8 yydefgoto[] = 533static const yytype_int8 yydefgoto[] =
551{ 534{
552 -1, 3, 14, 4, 5, 6, 27, 11, 18, 25, 535 -1, 2, 7, 8, 10, 13, 17, 21, 26, 37,
553 29, 44, 45, 56, 64, 65, 57, 30, 31, 7 536 38, 50, 57, 51, 27, 28
554}; 537};
555 538
556/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 539/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
557 STATE-NUM. */ 540 STATE-NUM. */
558#define YYPACT_NINF -14 541#define YYPACT_NINF -12
559static const yytype_int8 yypact[] = 542static const yytype_int8 yypact[] =
560{ 543{
561 30, -11, -14, 7, -14, -1, 27, 13, 27, -14, 544 10, -11, 18, -1, -12, 22, -1, 15, -1, -12,
562 8, -14, -14, 40, -1, 27, 35, -14, -14, -14, 545 22, -12, 20, 1, -12, 17, -12, -12, 20, 20,
563 -14, 21, -14, -14, 40, 24, 40, 28, 40, -14, 546 -12, 6, -12, -12, 21, 6, -12, 23, 6, -12,
564 32, 24, 46, 38, -14, 39, -14, -14, 26, -14, 547 -12, -12, -12, -12, 28, -12, -12, -6, 13, -12,
565 -14, -14, -14, -14, -9, 10, -14, -14, -14, -14, 548 -12, -12, -12, -12, -12, -12, 24, -12, -12, 33,
566 -14, -14, 31, -14, -14, 44, -2, 3, 23, -14, 549 -5, 0, -4, -12, -12, -12, -12, -12, -12, -12,
567 -14, -14, -14, -14, 50, -14, -14, -14, -14, 40, 550 -12, 22, -12, 25, 22, 19, -12
568 -14, -14, 33, 40, 36, -14
569}; 551};
570 552
571/* YYPGOTO[NTERM-NUM]. */ 553/* YYPGOTO[NTERM-NUM]. */
572static const yytype_int8 yypgoto[] = 554static const yytype_int8 yypgoto[] =
573{ 555{
574 -14, -14, 48, 29, 53, -14, -13, 47, 34, -14, 556 -12, -12, 36, 39, -10, -12, 8, -12, 12, -12,
575 37, -14, -14, -14, -14, -14, -14, 42, -14, -7 557 -12, -12, -12, -12, 27, 31
576}; 558};
577 559
578/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If 560/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
579 positive, shift that token. If negative, reduce the rule which 561 positive, shift that token. If negative, reduce the rule which
580 number is the opposite. If zero, do what YYDEFACT says. 562 number is the opposite. If zero, do what YYDEFACT says.
581 If YYTABLE_NINF, syntax error. */ 563 If YYTABLE_NINF, syntax error. */
582#define YYTABLE_NINF -45 564#define YYTABLE_NINF -1
583static const yytype_int8 yytable[] = 565static const yytype_uint8 yytable[] =
584{ 566{
585 21, 16, 46, 8, 59, 47, 60, 9, 16, 61, 567 15, 53, 3, 5, 40, 54, 55, 41, 58, 6,
586 62, 28, 66, 33, 67, 10, 48, 13, 32, 63, 568 59, 24, 18, 1, 56, 19, 25, 42, 4, 61,
587 49, 50, 51, 52, 32, 17, 68, 19, 20, -44, 569 62, 60, 43, 44, 45, 46, 22, 23, 9, 12,
588 53, -44, 54, 1, -44, 2, 26, 15, 2, 24, 570 20, 47, 31, 48, 29, 16, 16, 32, 30, 34,
589 41, 2, 34, 17, 15, 42, 19, 20, 69, 70, 571 35, 39, 52, 66, 14, 11, 49, 0, 64, 0,
590 35, 38, 39, 40, 58, 55, 72, 71, 73, 12, 572 0, 63, 0, 0, 65, 36, 33
591 74, 22, 75, 23, 0, 0, 0, 0, 36, 0,
592 0, 0, 43, 37
593}; 573};
594 574
595static const yytype_int8 yycheck[] = 575static const yytype_int8 yycheck[] =
596{ 576{
597 13, 8, 11, 14, 6, 14, 8, 0, 15, 11, 577 10, 6, 13, 4, 10, 10, 11, 13, 8, 10,
598 12, 24, 9, 26, 11, 16, 25, 4, 25, 21, 578 10, 5, 11, 3, 19, 14, 10, 23, 0, 23,
599 10, 11, 12, 13, 31, 17, 23, 6, 7, 5, 579 24, 21, 9, 10, 11, 12, 18, 19, 6, 14,
600 20, 4, 22, 3, 4, 11, 15, 8, 11, 4, 580 13, 18, 24, 20, 13, 15, 15, 25, 17, 16,
601 14, 11, 14, 17, 15, 19, 6, 7, 25, 26, 581 28, 13, 9, 24, 8, 6, 22, -1, 23, -1,
602 18, 5, 14, 14, 10, 24, 69, 7, 25, 6, 582 -1, 61, -1, -1, 64, 28, 25
603 73, 14, 26, 15, -1, -1, -1, -1, 31, -1,
604 -1, -1, 38, 31
605}; 583};
606 584
607/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing 585/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
608 symbol of state STATE-NUM. */ 586 symbol of state STATE-NUM. */
609static const yytype_uint8 yystos[] = 587static const yytype_uint8 yystos[] =
610{ 588{
611 0, 3, 11, 28, 30, 31, 32, 46, 14, 0, 589 0, 3, 26, 13, 0, 4, 10, 27, 28, 6,
612 16, 34, 31, 4, 29, 30, 46, 17, 35, 6, 590 29, 28, 14, 30, 27, 29, 15, 31, 11, 14,
613 7, 33, 34, 29, 4, 36, 15, 33, 33, 37, 591 13, 32, 31, 31, 5, 10, 33, 39, 40, 13,
614 44, 45, 46, 33, 14, 18, 37, 44, 5, 14, 592 17, 31, 33, 40, 16, 33, 39, 34, 35, 13,
615 14, 14, 19, 35, 38, 39, 11, 14, 25, 10, 593 10, 13, 23, 9, 10, 11, 12, 18, 20, 22,
616 11, 12, 13, 20, 22, 24, 40, 43, 10, 6, 594 36, 38, 9, 6, 10, 11, 19, 37, 8, 10,
617 8, 11, 12, 21, 41, 42, 9, 11, 23, 25, 595 21, 23, 24, 29, 23, 29, 24
618 26, 7, 33, 25, 33, 26
619}; 596};
620 597
621#define yyerrok (yyerrstatus = 0) 598#define yyerrok (yyerrstatus = 0)
@@ -728,7 +705,7 @@ do { \
728 { \ 705 { \
729 YYFPRINTF (stderr, "%s ", Title); \ 706 YYFPRINTF (stderr, "%s ", Title); \
730 yy_symbol_print (stderr, \ 707 yy_symbol_print (stderr, \
731 Type, Value, Location); \ 708 Type, Value); \
732 YYFPRINTF (stderr, "\n"); \ 709 YYFPRINTF (stderr, "\n"); \
733 } \ 710 } \
734} while (YYID (0)) 711} while (YYID (0))
@@ -742,19 +719,17 @@ do { \
742#if (defined __STDC__ || defined __C99__FUNC__ \ 719#if (defined __STDC__ || defined __C99__FUNC__ \
743 || defined __cplusplus || defined _MSC_VER) 720 || defined __cplusplus || defined _MSC_VER)
744static void 721static void
745yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) 722yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
746#else 723#else
747static void 724static void
748yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp) 725yy_symbol_value_print (yyoutput, yytype, yyvaluep)
749 FILE *yyoutput; 726 FILE *yyoutput;
750 int yytype; 727 int yytype;
751 YYSTYPE const * const yyvaluep; 728 YYSTYPE const * const yyvaluep;
752 YYLTYPE const * const yylocationp;
753#endif 729#endif
754{ 730{
755 if (!yyvaluep) 731 if (!yyvaluep)
756 return; 732 return;
757 YYUSE (yylocationp);
758# ifdef YYPRINT 733# ifdef YYPRINT
759 if (yytype < YYNTOKENS) 734 if (yytype < YYNTOKENS)
760 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); 735 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
@@ -776,14 +751,13 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
776#if (defined __STDC__ || defined __C99__FUNC__ \ 751#if (defined __STDC__ || defined __C99__FUNC__ \
777 || defined __cplusplus || defined _MSC_VER) 752 || defined __cplusplus || defined _MSC_VER)
778static void 753static void
779yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) 754yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
780#else 755#else
781static void 756static void
782yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp) 757yy_symbol_print (yyoutput, yytype, yyvaluep)
783 FILE *yyoutput; 758 FILE *yyoutput;
784 int yytype; 759 int yytype;
785 YYSTYPE const * const yyvaluep; 760 YYSTYPE const * const yyvaluep;
786 YYLTYPE const * const yylocationp;
787#endif 761#endif
788{ 762{
789 if (yytype < YYNTOKENS) 763 if (yytype < YYNTOKENS)
@@ -791,9 +765,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
791 else 765 else
792 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); 766 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
793 767
794 YY_LOCATION_PRINT (yyoutput, *yylocationp); 768 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
795 YYFPRINTF (yyoutput, ": ");
796 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
797 YYFPRINTF (yyoutput, ")"); 769 YYFPRINTF (yyoutput, ")");
798} 770}
799 771
@@ -805,17 +777,20 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
805#if (defined __STDC__ || defined __C99__FUNC__ \ 777#if (defined __STDC__ || defined __C99__FUNC__ \
806 || defined __cplusplus || defined _MSC_VER) 778 || defined __cplusplus || defined _MSC_VER)
807static void 779static void
808yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) 780yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
809#else 781#else
810static void 782static void
811yy_stack_print (bottom, top) 783yy_stack_print (yybottom, yytop)
812 yytype_int16 *bottom; 784 yytype_int16 *yybottom;
813 yytype_int16 *top; 785 yytype_int16 *yytop;
814#endif 786#endif
815{ 787{
816 YYFPRINTF (stderr, "Stack now"); 788 YYFPRINTF (stderr, "Stack now");
817 for (; bottom <= top; ++bottom) 789 for (; yybottom <= yytop; yybottom++)
818 YYFPRINTF (stderr, " %d", *bottom); 790 {
791 int yybot = *yybottom;
792 YYFPRINTF (stderr, " %d", yybot);
793 }
819 YYFPRINTF (stderr, "\n"); 794 YYFPRINTF (stderr, "\n");
820} 795}
821 796
@@ -833,12 +808,11 @@ do { \
833#if (defined __STDC__ || defined __C99__FUNC__ \ 808#if (defined __STDC__ || defined __C99__FUNC__ \
834 || defined __cplusplus || defined _MSC_VER) 809 || defined __cplusplus || defined _MSC_VER)
835static void 810static void
836yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule) 811yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
837#else 812#else
838static void 813static void
839yy_reduce_print (yyvsp, yylsp, yyrule) 814yy_reduce_print (yyvsp, yyrule)
840 YYSTYPE *yyvsp; 815 YYSTYPE *yyvsp;
841 YYLTYPE *yylsp;
842 int yyrule; 816 int yyrule;
843#endif 817#endif
844{ 818{
@@ -850,18 +824,18 @@ yy_reduce_print (yyvsp, yylsp, yyrule)
850 /* The symbols being reduced. */ 824 /* The symbols being reduced. */
851 for (yyi = 0; yyi < yynrhs; yyi++) 825 for (yyi = 0; yyi < yynrhs; yyi++)
852 { 826 {
853 fprintf (stderr, " $%d = ", yyi + 1); 827 YYFPRINTF (stderr, " $%d = ", yyi + 1);
854 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], 828 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
855 &(yyvsp[(yyi + 1) - (yynrhs)]) 829 &(yyvsp[(yyi + 1) - (yynrhs)])
856 , &(yylsp[(yyi + 1) - (yynrhs)]) ); 830 );
857 fprintf (stderr, "\n"); 831 YYFPRINTF (stderr, "\n");
858 } 832 }
859} 833}
860 834
861# define YY_REDUCE_PRINT(Rule) \ 835# define YY_REDUCE_PRINT(Rule) \
862do { \ 836do { \
863 if (yydebug) \ 837 if (yydebug) \
864 yy_reduce_print (yyvsp, yylsp, Rule); \ 838 yy_reduce_print (yyvsp, Rule); \
865} while (YYID (0)) 839} while (YYID (0))
866 840
867/* Nonzero means print parse trace. It is left uninitialized so that 841/* Nonzero means print parse trace. It is left uninitialized so that
@@ -1112,18 +1086,16 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
1112#if (defined __STDC__ || defined __C99__FUNC__ \ 1086#if (defined __STDC__ || defined __C99__FUNC__ \
1113 || defined __cplusplus || defined _MSC_VER) 1087 || defined __cplusplus || defined _MSC_VER)
1114static void 1088static void
1115yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp) 1089yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1116#else 1090#else
1117static void 1091static void
1118yydestruct (yymsg, yytype, yyvaluep, yylocationp) 1092yydestruct (yymsg, yytype, yyvaluep)
1119 const char *yymsg; 1093 const char *yymsg;
1120 int yytype; 1094 int yytype;
1121 YYSTYPE *yyvaluep; 1095 YYSTYPE *yyvaluep;
1122 YYLTYPE *yylocationp;
1123#endif 1096#endif
1124{ 1097{
1125 YYUSE (yyvaluep); 1098 YYUSE (yyvaluep);
1126 YYUSE (yylocationp);
1127 1099
1128 if (!yymsg) 1100 if (!yymsg)
1129 yymsg = "Deleting"; 1101 yymsg = "Deleting";
@@ -1136,10 +1108,8 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp)
1136 break; 1108 break;
1137 } 1109 }
1138} 1110}
1139
1140 1111
1141/* Prevent warnings from -Wmissing-prototypes. */ 1112/* Prevent warnings from -Wmissing-prototypes. */
1142
1143#ifdef YYPARSE_PARAM 1113#ifdef YYPARSE_PARAM
1144#if defined __STDC__ || defined __cplusplus 1114#if defined __STDC__ || defined __cplusplus
1145int yyparse (void *YYPARSE_PARAM); 1115int yyparse (void *YYPARSE_PARAM);
@@ -1155,23 +1125,20 @@ int yyparse ();
1155#endif /* ! YYPARSE_PARAM */ 1125#endif /* ! YYPARSE_PARAM */
1156 1126
1157 1127
1158 1128/* The lookahead symbol. */
1159/* The look-ahead symbol. */
1160int yychar; 1129int yychar;
1161 1130
1162/* The semantic value of the look-ahead symbol. */ 1131/* The semantic value of the lookahead symbol. */
1163YYSTYPE yylval; 1132YYSTYPE yylval;
1164 1133
1165/* Number of syntax errors so far. */ 1134/* Number of syntax errors so far. */
1166int yynerrs; 1135int yynerrs;
1167/* Location data for the look-ahead symbol. */
1168YYLTYPE yylloc;
1169 1136
1170 1137
1171 1138
1172/*----------. 1139/*-------------------------.
1173| yyparse. | 1140| yyparse or yypush_parse. |
1174`----------*/ 1141`-------------------------*/
1175 1142
1176#ifdef YYPARSE_PARAM 1143#ifdef YYPARSE_PARAM
1177#if (defined __STDC__ || defined __C99__FUNC__ \ 1144#if (defined __STDC__ || defined __C99__FUNC__ \
@@ -1195,79 +1162,70 @@ yyparse ()
1195#endif 1162#endif
1196#endif 1163#endif
1197{ 1164{
1198
1199 int yystate;
1200 int yyn;
1201 int yyresult;
1202 /* Number of tokens to shift before error messages enabled. */
1203 int yyerrstatus;
1204 /* Look-ahead token as an internal (translated) token number. */
1205 int yytoken = 0;
1206#if YYERROR_VERBOSE
1207 /* Buffer for error messages, and its allocated size. */
1208 char yymsgbuf[128];
1209 char *yymsg = yymsgbuf;
1210 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1211#endif
1212 1165
1213 /* Three stacks and their tools:
1214 `yyss': related to states,
1215 `yyvs': related to semantic values,
1216 `yyls': related to locations.
1217 1166
1218 Refer to the stacks thru separate pointers, to allow yyoverflow 1167 int yystate;
1219 to reallocate them elsewhere. */ 1168 /* Number of tokens to shift before error messages enabled. */
1169 int yyerrstatus;
1220 1170
1221 /* The state stack. */ 1171 /* The stacks and their tools:
1222 yytype_int16 yyssa[YYINITDEPTH]; 1172 `yyss': related to states.
1223 yytype_int16 *yyss = yyssa; 1173 `yyvs': related to semantic values.
1224 yytype_int16 *yyssp;
1225 1174
1226 /* The semantic value stack. */ 1175 Refer to the stacks thru separate pointers, to allow yyoverflow
1227 YYSTYPE yyvsa[YYINITDEPTH]; 1176 to reallocate them elsewhere. */
1228 YYSTYPE *yyvs = yyvsa;
1229 YYSTYPE *yyvsp;
1230 1177
1231 /* The location stack. */ 1178 /* The state stack. */
1232 YYLTYPE yylsa[YYINITDEPTH]; 1179 yytype_int16 yyssa[YYINITDEPTH];
1233 YYLTYPE *yyls = yylsa; 1180 yytype_int16 *yyss;
1234 YYLTYPE *yylsp; 1181 yytype_int16 *yyssp;
1235 /* The locations where the error started and ended. */
1236 YYLTYPE yyerror_range[2];
1237 1182
1238#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) 1183 /* The semantic value stack. */
1184 YYSTYPE yyvsa[YYINITDEPTH];
1185 YYSTYPE *yyvs;
1186 YYSTYPE *yyvsp;
1239 1187
1240 YYSIZE_T yystacksize = YYINITDEPTH; 1188 YYSIZE_T yystacksize;
1241 1189
1190 int yyn;
1191 int yyresult;
1192 /* Lookahead token as an internal (translated) token number. */
1193 int yytoken;
1242 /* The variables used to return semantic value and location from the 1194 /* The variables used to return semantic value and location from the
1243 action routines. */ 1195 action routines. */
1244 YYSTYPE yyval; 1196 YYSTYPE yyval;
1245 YYLTYPE yyloc; 1197
1198#if YYERROR_VERBOSE
1199 /* Buffer for error messages, and its allocated size. */
1200 char yymsgbuf[128];
1201 char *yymsg = yymsgbuf;
1202 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1203#endif
1204
1205#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1246 1206
1247 /* The number of symbols on the RHS of the reduced rule. 1207 /* The number of symbols on the RHS of the reduced rule.
1248 Keep to zero when no symbol should be popped. */ 1208 Keep to zero when no symbol should be popped. */
1249 int yylen = 0; 1209 int yylen = 0;
1250 1210
1211 yytoken = 0;
1212 yyss = yyssa;
1213 yyvs = yyvsa;
1214 yystacksize = YYINITDEPTH;
1215
1251 YYDPRINTF ((stderr, "Starting parse\n")); 1216 YYDPRINTF ((stderr, "Starting parse\n"));
1252 1217
1253 yystate = 0; 1218 yystate = 0;
1254 yyerrstatus = 0; 1219 yyerrstatus = 0;
1255 yynerrs = 0; 1220 yynerrs = 0;
1256 yychar = YYEMPTY; /* Cause a token to be read. */ 1221 yychar = YYEMPTY; /* Cause a token to be read. */
1257 1222
1258 /* Initialize stack pointers. 1223 /* Initialize stack pointers.
1259 Waste one element of value and location stack 1224 Waste one element of value and location stack
1260 so that they stay on the same level as the state stack. 1225 so that they stay on the same level as the state stack.
1261 The wasted elements are never initialized. */ 1226 The wasted elements are never initialized. */
1262
1263 yyssp = yyss; 1227 yyssp = yyss;
1264 yyvsp = yyvs; 1228 yyvsp = yyvs;
1265 yylsp = yyls;
1266#if YYLTYPE_IS_TRIVIAL
1267 /* Initialize the default location before parsing starts. */
1268 yylloc.first_line = yylloc.last_line = 1;
1269 yylloc.first_column = yylloc.last_column = 0;
1270#endif
1271 1229
1272 goto yysetstate; 1230 goto yysetstate;
1273 1231
@@ -1294,7 +1252,6 @@ yyparse ()
1294 memory. */ 1252 memory. */
1295 YYSTYPE *yyvs1 = yyvs; 1253 YYSTYPE *yyvs1 = yyvs;
1296 yytype_int16 *yyss1 = yyss; 1254 yytype_int16 *yyss1 = yyss;
1297 YYLTYPE *yyls1 = yyls;
1298 1255
1299 /* Each stack pointer address is followed by the size of the 1256 /* Each stack pointer address is followed by the size of the
1300 data in use in that stack, in bytes. This used to be a 1257 data in use in that stack, in bytes. This used to be a
@@ -1303,9 +1260,8 @@ yyparse ()
1303 yyoverflow (YY_("memory exhausted"), 1260 yyoverflow (YY_("memory exhausted"),
1304 &yyss1, yysize * sizeof (*yyssp), 1261 &yyss1, yysize * sizeof (*yyssp),
1305 &yyvs1, yysize * sizeof (*yyvsp), 1262 &yyvs1, yysize * sizeof (*yyvsp),
1306 &yyls1, yysize * sizeof (*yylsp),
1307 &yystacksize); 1263 &yystacksize);
1308 yyls = yyls1; 1264
1309 yyss = yyss1; 1265 yyss = yyss1;
1310 yyvs = yyvs1; 1266 yyvs = yyvs1;
1311 } 1267 }
@@ -1326,9 +1282,8 @@ yyparse ()
1326 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); 1282 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1327 if (! yyptr) 1283 if (! yyptr)
1328 goto yyexhaustedlab; 1284 goto yyexhaustedlab;
1329 YYSTACK_RELOCATE (yyss); 1285 YYSTACK_RELOCATE (yyss_alloc, yyss);
1330 YYSTACK_RELOCATE (yyvs); 1286 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1331 YYSTACK_RELOCATE (yyls);
1332# undef YYSTACK_RELOCATE 1287# undef YYSTACK_RELOCATE
1333 if (yyss1 != yyssa) 1288 if (yyss1 != yyssa)
1334 YYSTACK_FREE (yyss1); 1289 YYSTACK_FREE (yyss1);
@@ -1338,7 +1293,6 @@ yyparse ()
1338 1293
1339 yyssp = yyss + yysize - 1; 1294 yyssp = yyss + yysize - 1;
1340 yyvsp = yyvs + yysize - 1; 1295 yyvsp = yyvs + yysize - 1;
1341 yylsp = yyls + yysize - 1;
1342 1296
1343 YYDPRINTF ((stderr, "Stack size increased to %lu\n", 1297 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1344 (unsigned long int) yystacksize)); 1298 (unsigned long int) yystacksize));
@@ -1349,6 +1303,9 @@ yyparse ()
1349 1303
1350 YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 1304 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1351 1305
1306 if (yystate == YYFINAL)
1307 YYACCEPT;
1308
1352 goto yybackup; 1309 goto yybackup;
1353 1310
1354/*-----------. 1311/*-----------.
@@ -1357,16 +1314,16 @@ yyparse ()
1357yybackup: 1314yybackup:
1358 1315
1359 /* Do appropriate processing given the current state. Read a 1316 /* Do appropriate processing given the current state. Read a
1360 look-ahead token if we need one and don't already have one. */ 1317 lookahead token if we need one and don't already have one. */
1361 1318
1362 /* First try to decide what to do without reference to look-ahead token. */ 1319 /* First try to decide what to do without reference to lookahead token. */
1363 yyn = yypact[yystate]; 1320 yyn = yypact[yystate];
1364 if (yyn == YYPACT_NINF) 1321 if (yyn == YYPACT_NINF)
1365 goto yydefault; 1322 goto yydefault;
1366 1323
1367 /* Not known => get a look-ahead token if don't already have one. */ 1324 /* Not known => get a lookahead token if don't already have one. */
1368 1325
1369 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ 1326 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1370 if (yychar == YYEMPTY) 1327 if (yychar == YYEMPTY)
1371 { 1328 {
1372 YYDPRINTF ((stderr, "Reading a token: ")); 1329 YYDPRINTF ((stderr, "Reading a token: "));
@@ -1398,24 +1355,20 @@ yybackup:
1398 goto yyreduce; 1355 goto yyreduce;
1399 } 1356 }
1400 1357
1401 if (yyn == YYFINAL)
1402 YYACCEPT;
1403
1404 /* Count tokens shifted since error; after three, turn off error 1358 /* Count tokens shifted since error; after three, turn off error
1405 status. */ 1359 status. */
1406 if (yyerrstatus) 1360 if (yyerrstatus)
1407 yyerrstatus--; 1361 yyerrstatus--;
1408 1362
1409 /* Shift the look-ahead token. */ 1363 /* Shift the lookahead token. */
1410 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 1364 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1411 1365
1412 /* Discard the shifted token unless it is eof. */ 1366 /* Discard the shifted token. */
1413 if (yychar != YYEOF) 1367 yychar = YYEMPTY;
1414 yychar = YYEMPTY;
1415 1368
1416 yystate = yyn; 1369 yystate = yyn;
1417 *++yyvsp = yylval; 1370 *++yyvsp = yylval;
1418 *++yylsp = yylloc; 1371
1419 goto yynewstate; 1372 goto yynewstate;
1420 1373
1421 1374
@@ -1446,337 +1399,387 @@ yyreduce:
1446 GCC warning that YYVAL may be used uninitialized. */ 1399 GCC warning that YYVAL may be used uninitialized. */
1447 yyval = yyvsp[1-yylen]; 1400 yyval = yyvsp[1-yylen];
1448 1401
1449 /* Default location. */ 1402
1450 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1451 YY_REDUCE_PRINT (yyn); 1403 YY_REDUCE_PRINT (yyn);
1452 switch (yyn) 1404 switch (yyn)
1453 { 1405 {
1454 case 2: 1406 case 2:
1455#line 90 "dtc-parser.y" 1407
1408/* Line 1455 of yacc.c */
1409#line 87 "dtc-parser.y"
1456 { 1410 {
1457 the_boot_info = build_boot_info((yyvsp[(3) - (4)].re), (yyvsp[(4) - (4)].node), 0); 1411 the_boot_info = build_boot_info((yyvsp[(3) - (4)].re), (yyvsp[(4) - (4)].node),
1412 guess_boot_cpuid((yyvsp[(4) - (4)].node)));
1458 ;} 1413 ;}
1459 break; 1414 break;
1460 1415
1461 case 3: 1416 case 3:
1462#line 94 "dtc-parser.y" 1417
1418/* Line 1455 of yacc.c */
1419#line 95 "dtc-parser.y"
1463 { 1420 {
1464 the_boot_info = build_boot_info((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].node), 0); 1421 (yyval.re) = NULL;
1465 ;} 1422 ;}
1466 break; 1423 break;
1467 1424
1468 case 4: 1425 case 4:
1469#line 101 "dtc-parser.y" 1426
1427/* Line 1455 of yacc.c */
1428#line 99 "dtc-parser.y"
1470 { 1429 {
1471 (yyval.re) = NULL; 1430 (yyval.re) = chain_reserve_entry((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].re));
1472 ;} 1431 ;}
1473 break; 1432 break;
1474 1433
1475 case 5: 1434 case 5:
1476#line 105 "dtc-parser.y" 1435
1436/* Line 1455 of yacc.c */
1437#line 106 "dtc-parser.y"
1477 { 1438 {
1478 (yyval.re) = chain_reserve_entry((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].re)); 1439 (yyval.re) = build_reserve_entry((yyvsp[(2) - (4)].addr), (yyvsp[(3) - (4)].addr));
1479 ;} 1440 ;}
1480 break; 1441 break;
1481 1442
1482 case 6: 1443 case 6:
1483#line 112 "dtc-parser.y" 1444
1445/* Line 1455 of yacc.c */
1446#line 110 "dtc-parser.y"
1484 { 1447 {
1485 (yyval.re) = build_reserve_entry((yyvsp[(3) - (5)].addr), (yyvsp[(4) - (5)].addr), (yyvsp[(1) - (5)].labelref)); 1448 add_label(&(yyvsp[(2) - (2)].re)->labels, (yyvsp[(1) - (2)].labelref));
1449 (yyval.re) = (yyvsp[(2) - (2)].re);
1486 ;} 1450 ;}
1487 break; 1451 break;
1488 1452
1489 case 7: 1453 case 7:
1490#line 119 "dtc-parser.y" 1454
1455/* Line 1455 of yacc.c */
1456#line 118 "dtc-parser.y"
1491 { 1457 {
1492 (yyval.re) = NULL; 1458 (yyval.addr) = eval_literal((yyvsp[(1) - (1)].literal), 0, 64);
1493 ;} 1459 ;}
1494 break; 1460 break;
1495 1461
1496 case 8: 1462 case 8:
1497#line 123 "dtc-parser.y" 1463
1464/* Line 1455 of yacc.c */
1465#line 125 "dtc-parser.y"
1498 { 1466 {
1499 (yyval.re) = chain_reserve_entry((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].re)); 1467 (yyval.node) = name_node((yyvsp[(2) - (2)].node), "");
1500 ;} 1468 ;}
1501 break; 1469 break;
1502 1470
1503 case 9: 1471 case 9:
1504#line 130 "dtc-parser.y" 1472
1473/* Line 1455 of yacc.c */
1474#line 129 "dtc-parser.y"
1505 { 1475 {
1506 (yyval.re) = (yyvsp[(1) - (1)].re); 1476 (yyval.node) = merge_nodes((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node));
1507 ;} 1477 ;}
1508 break; 1478 break;
1509 1479
1510 case 10: 1480 case 10:
1511#line 134 "dtc-parser.y" 1481
1482/* Line 1455 of yacc.c */
1483#line 133 "dtc-parser.y"
1512 { 1484 {
1513 (yyval.re) = build_reserve_entry((yyvsp[(3) - (6)].addr), (yyvsp[(5) - (6)].addr) - (yyvsp[(3) - (6)].addr) + 1, (yyvsp[(1) - (6)].labelref)); 1485 struct node *target = get_node_by_ref((yyvsp[(1) - (3)].node), (yyvsp[(2) - (3)].labelref));
1486
1487 if (target)
1488 merge_nodes(target, (yyvsp[(3) - (3)].node));
1489 else
1490 print_error("label or path, '%s', not found", (yyvsp[(2) - (3)].labelref));
1491 (yyval.node) = (yyvsp[(1) - (3)].node);
1514 ;} 1492 ;}
1515 break; 1493 break;
1516 1494
1517 case 11: 1495 case 11:
1518#line 141 "dtc-parser.y" 1496
1497/* Line 1455 of yacc.c */
1498#line 146 "dtc-parser.y"
1519 { 1499 {
1520 (yyval.addr) = eval_literal((yyvsp[(1) - (1)].literal), 0, 64); 1500 (yyval.node) = build_node((yyvsp[(2) - (5)].proplist), (yyvsp[(3) - (5)].nodelist));
1521 ;} 1501 ;}
1522 break; 1502 break;
1523 1503
1524 case 12: 1504 case 12:
1525#line 145 "dtc-parser.y" 1505
1506/* Line 1455 of yacc.c */
1507#line 153 "dtc-parser.y"
1526 { 1508 {
1527 (yyval.addr) = eval_literal((yyvsp[(1) - (1)].literal), 16, 64); 1509 (yyval.proplist) = NULL;
1528 ;} 1510 ;}
1529 break; 1511 break;
1530 1512
1531 case 13: 1513 case 13:
1532#line 152 "dtc-parser.y" 1514
1515/* Line 1455 of yacc.c */
1516#line 157 "dtc-parser.y"
1533 { 1517 {
1534 (yyval.node) = name_node((yyvsp[(2) - (2)].node), "", NULL); 1518 (yyval.proplist) = chain_property((yyvsp[(2) - (2)].prop), (yyvsp[(1) - (2)].proplist));
1535 ;} 1519 ;}
1536 break; 1520 break;
1537 1521
1538 case 14: 1522 case 14:
1539#line 159 "dtc-parser.y" 1523
1524/* Line 1455 of yacc.c */
1525#line 164 "dtc-parser.y"
1540 { 1526 {
1541 (yyval.node) = build_node((yyvsp[(2) - (5)].proplist), (yyvsp[(3) - (5)].nodelist)); 1527 (yyval.prop) = build_property((yyvsp[(1) - (4)].propnodename), (yyvsp[(3) - (4)].data));
1542 ;} 1528 ;}
1543 break; 1529 break;
1544 1530
1545 case 15: 1531 case 15:
1546#line 166 "dtc-parser.y" 1532
1533/* Line 1455 of yacc.c */
1534#line 168 "dtc-parser.y"
1547 { 1535 {
1548 (yyval.proplist) = NULL; 1536 (yyval.prop) = build_property((yyvsp[(1) - (2)].propnodename), empty_data);
1549 ;} 1537 ;}
1550 break; 1538 break;
1551 1539
1552 case 16: 1540 case 16:
1553#line 170 "dtc-parser.y" 1541
1542/* Line 1455 of yacc.c */
1543#line 172 "dtc-parser.y"
1554 { 1544 {
1555 (yyval.proplist) = chain_property((yyvsp[(2) - (2)].prop), (yyvsp[(1) - (2)].proplist)); 1545 add_label(&(yyvsp[(2) - (2)].prop)->labels, (yyvsp[(1) - (2)].labelref));
1546 (yyval.prop) = (yyvsp[(2) - (2)].prop);
1556 ;} 1547 ;}
1557 break; 1548 break;
1558 1549
1559 case 17: 1550 case 17:
1560#line 177 "dtc-parser.y" 1551
1552/* Line 1455 of yacc.c */
1553#line 180 "dtc-parser.y"
1561 { 1554 {
1562 (yyval.prop) = build_property((yyvsp[(2) - (5)].propnodename), (yyvsp[(4) - (5)].data), (yyvsp[(1) - (5)].labelref)); 1555 (yyval.data) = data_merge((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].data));
1563 ;} 1556 ;}
1564 break; 1557 break;
1565 1558
1566 case 18: 1559 case 18:
1567#line 181 "dtc-parser.y" 1560
1561/* Line 1455 of yacc.c */
1562#line 184 "dtc-parser.y"
1568 { 1563 {
1569 (yyval.prop) = build_property((yyvsp[(2) - (3)].propnodename), empty_data, (yyvsp[(1) - (3)].labelref)); 1564 (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data));
1570 ;} 1565 ;}
1571 break; 1566 break;
1572 1567
1573 case 19: 1568 case 19:
1569
1570/* Line 1455 of yacc.c */
1574#line 188 "dtc-parser.y" 1571#line 188 "dtc-parser.y"
1575 { 1572 {
1576 (yyval.data) = data_merge((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].data)); 1573 (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data));
1577 ;} 1574 ;}
1578 break; 1575 break;
1579 1576
1580 case 20: 1577 case 20:
1578
1579/* Line 1455 of yacc.c */
1581#line 192 "dtc-parser.y" 1580#line 192 "dtc-parser.y"
1582 { 1581 {
1583 (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data)); 1582 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), REF_PATH, (yyvsp[(2) - (2)].labelref));
1584 ;} 1583 ;}
1585 break; 1584 break;
1586 1585
1587 case 21: 1586 case 21:
1588#line 196 "dtc-parser.y"
1589 {
1590 (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data));
1591 ;}
1592 break;
1593
1594 case 22:
1595#line 200 "dtc-parser.y"
1596 {
1597 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), REF_PATH, (yyvsp[(2) - (2)].labelref));
1598 ;}
1599 break;
1600 1587
1601 case 23: 1588/* Line 1455 of yacc.c */
1602#line 204 "dtc-parser.y" 1589#line 196 "dtc-parser.y"
1603 { 1590 {
1604 struct search_path path = { srcpos_file->dir, NULL, NULL }; 1591 FILE *f = srcfile_relative_open((yyvsp[(4) - (9)].data).val, NULL);
1605 struct dtc_file *file = dtc_open_file((yyvsp[(4) - (9)].data).val, &path); 1592 struct data d;
1606 struct data d = empty_data;
1607 1593
1608 if ((yyvsp[(6) - (9)].addr) != 0) 1594 if ((yyvsp[(6) - (9)].addr) != 0)
1609 if (fseek(file->file, (yyvsp[(6) - (9)].addr), SEEK_SET) != 0) 1595 if (fseek(f, (yyvsp[(6) - (9)].addr), SEEK_SET) != 0)
1610 yyerrorf("Couldn't seek to offset %llu in \"%s\": %s", 1596 print_error("Couldn't seek to offset %llu in \"%s\": %s",
1611 (unsigned long long)(yyvsp[(6) - (9)].addr), 1597 (unsigned long long)(yyvsp[(6) - (9)].addr),
1612 (yyvsp[(4) - (9)].data).val, strerror(errno)); 1598 (yyvsp[(4) - (9)].data).val,
1599 strerror(errno));
1613 1600
1614 d = data_copy_file(file->file, (yyvsp[(8) - (9)].addr)); 1601 d = data_copy_file(f, (yyvsp[(8) - (9)].addr));
1615 1602
1616 (yyval.data) = data_merge((yyvsp[(1) - (9)].data), d); 1603 (yyval.data) = data_merge((yyvsp[(1) - (9)].data), d);
1617 dtc_close_file(file); 1604 fclose(f);
1618 ;} 1605 ;}
1619 break; 1606 break;
1620 1607
1621 case 24: 1608 case 22:
1622#line 221 "dtc-parser.y" 1609
1610/* Line 1455 of yacc.c */
1611#line 213 "dtc-parser.y"
1623 { 1612 {
1624 struct search_path path = { srcpos_file->dir, NULL, NULL }; 1613 FILE *f = srcfile_relative_open((yyvsp[(4) - (5)].data).val, NULL);
1625 struct dtc_file *file = dtc_open_file((yyvsp[(4) - (5)].data).val, &path);
1626 struct data d = empty_data; 1614 struct data d = empty_data;
1627 1615
1628 d = data_copy_file(file->file, -1); 1616 d = data_copy_file(f, -1);
1629 1617
1630 (yyval.data) = data_merge((yyvsp[(1) - (5)].data), d); 1618 (yyval.data) = data_merge((yyvsp[(1) - (5)].data), d);
1631 dtc_close_file(file); 1619 fclose(f);
1632 ;} 1620 ;}
1633 break; 1621 break;
1634 1622
1635 case 25: 1623 case 23:
1636#line 232 "dtc-parser.y" 1624
1625/* Line 1455 of yacc.c */
1626#line 223 "dtc-parser.y"
1637 { 1627 {
1638 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1628 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
1639 ;} 1629 ;}
1640 break; 1630 break;
1641 1631
1642 case 26: 1632 case 24:
1643#line 239 "dtc-parser.y" 1633
1634/* Line 1455 of yacc.c */
1635#line 230 "dtc-parser.y"
1644 { 1636 {
1645 (yyval.data) = empty_data; 1637 (yyval.data) = empty_data;
1646 ;} 1638 ;}
1647 break; 1639 break;
1648 1640
1649 case 27: 1641 case 25:
1650#line 243 "dtc-parser.y" 1642
1643/* Line 1455 of yacc.c */
1644#line 234 "dtc-parser.y"
1651 { 1645 {
1652 (yyval.data) = (yyvsp[(1) - (2)].data); 1646 (yyval.data) = (yyvsp[(1) - (2)].data);
1653 ;} 1647 ;}
1654 break; 1648 break;
1655 1649
1656 case 28: 1650 case 26:
1657#line 247 "dtc-parser.y" 1651
1652/* Line 1455 of yacc.c */
1653#line 238 "dtc-parser.y"
1658 { 1654 {
1659 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1655 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
1660 ;} 1656 ;}
1661 break; 1657 break;
1662 1658
1663 case 29: 1659 case 27:
1664#line 254 "dtc-parser.y" 1660
1661/* Line 1455 of yacc.c */
1662#line 245 "dtc-parser.y"
1665 { 1663 {
1666 (yyval.data) = empty_data; 1664 (yyval.data) = empty_data;
1667 ;} 1665 ;}
1668 break; 1666 break;
1669 1667
1670 case 30: 1668 case 28:
1671#line 258 "dtc-parser.y" 1669
1670/* Line 1455 of yacc.c */
1671#line 249 "dtc-parser.y"
1672 { 1672 {
1673 (yyval.data) = data_append_cell((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].cell)); 1673 (yyval.data) = data_append_cell((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].cell));
1674 ;} 1674 ;}
1675 break; 1675 break;
1676 1676
1677 case 31: 1677 case 29:
1678#line 262 "dtc-parser.y" 1678
1679/* Line 1455 of yacc.c */
1680#line 253 "dtc-parser.y"
1679 { 1681 {
1680 (yyval.data) = data_append_cell(data_add_marker((yyvsp[(1) - (2)].data), REF_PHANDLE, 1682 (yyval.data) = data_append_cell(data_add_marker((yyvsp[(1) - (2)].data), REF_PHANDLE,
1681 (yyvsp[(2) - (2)].labelref)), -1); 1683 (yyvsp[(2) - (2)].labelref)), -1);
1682 ;} 1684 ;}
1683 break; 1685 break;
1684 1686
1685 case 32: 1687 case 30:
1686#line 267 "dtc-parser.y" 1688
1689/* Line 1455 of yacc.c */
1690#line 258 "dtc-parser.y"
1687 { 1691 {
1688 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1692 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
1689 ;} 1693 ;}
1690 break; 1694 break;
1691 1695
1692 case 33: 1696 case 31:
1693#line 274 "dtc-parser.y"
1694 {
1695 (yyval.cbase) = 16;
1696 ;}
1697 break;
1698 1697
1699 case 35: 1698/* Line 1455 of yacc.c */
1700#line 282 "dtc-parser.y" 1699#line 265 "dtc-parser.y"
1701 { 1700 {
1702 (yyval.cell) = eval_literal((yyvsp[(1) - (1)].literal), 0, 32); 1701 (yyval.cell) = eval_literal((yyvsp[(1) - (1)].literal), 0, 32);
1703 ;} 1702 ;}
1704 break; 1703 break;
1705 1704
1706 case 36: 1705 case 32:
1707#line 286 "dtc-parser.y"
1708 {
1709 (yyval.cell) = eval_literal((yyvsp[(2) - (2)].literal), (yyvsp[(1) - (2)].cbase), 32);
1710 ;}
1711 break;
1712 1706
1713 case 37: 1707/* Line 1455 of yacc.c */
1714#line 293 "dtc-parser.y" 1708#line 272 "dtc-parser.y"
1715 { 1709 {
1716 (yyval.data) = empty_data; 1710 (yyval.data) = empty_data;
1717 ;} 1711 ;}
1718 break; 1712 break;
1719 1713
1720 case 38: 1714 case 33:
1721#line 297 "dtc-parser.y" 1715
1716/* Line 1455 of yacc.c */
1717#line 276 "dtc-parser.y"
1722 { 1718 {
1723 (yyval.data) = data_append_byte((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].byte)); 1719 (yyval.data) = data_append_byte((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].byte));
1724 ;} 1720 ;}
1725 break; 1721 break;
1726 1722
1727 case 39: 1723 case 34:
1728#line 301 "dtc-parser.y" 1724
1725/* Line 1455 of yacc.c */
1726#line 280 "dtc-parser.y"
1729 { 1727 {
1730 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1728 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
1731 ;} 1729 ;}
1732 break; 1730 break;
1733 1731
1734 case 40: 1732 case 35:
1735#line 308 "dtc-parser.y" 1733
1734/* Line 1455 of yacc.c */
1735#line 287 "dtc-parser.y"
1736 { 1736 {
1737 (yyval.nodelist) = NULL; 1737 (yyval.nodelist) = NULL;
1738 ;} 1738 ;}
1739 break; 1739 break;
1740 1740
1741 case 41: 1741 case 36:
1742#line 312 "dtc-parser.y" 1742
1743/* Line 1455 of yacc.c */
1744#line 291 "dtc-parser.y"
1743 { 1745 {
1744 (yyval.nodelist) = chain_node((yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].nodelist)); 1746 (yyval.nodelist) = chain_node((yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].nodelist));
1745 ;} 1747 ;}
1746 break; 1748 break;
1747 1749
1748 case 42: 1750 case 37:
1749#line 316 "dtc-parser.y" 1751
1752/* Line 1455 of yacc.c */
1753#line 295 "dtc-parser.y"
1750 { 1754 {
1751 yyerror("syntax error: properties must precede subnodes"); 1755 print_error("syntax error: properties must precede subnodes");
1752 YYERROR; 1756 YYERROR;
1753 ;} 1757 ;}
1754 break; 1758 break;
1755 1759
1756 case 43: 1760 case 38:
1757#line 324 "dtc-parser.y"
1758 {
1759 (yyval.node) = name_node((yyvsp[(3) - (3)].node), (yyvsp[(2) - (3)].propnodename), (yyvsp[(1) - (3)].labelref));
1760 ;}
1761 break;
1762 1761
1763 case 44: 1762/* Line 1455 of yacc.c */
1764#line 331 "dtc-parser.y" 1763#line 303 "dtc-parser.y"
1765 { 1764 {
1766 (yyval.labelref) = NULL; 1765 (yyval.node) = name_node((yyvsp[(2) - (2)].node), (yyvsp[(1) - (2)].propnodename));
1767 ;} 1766 ;}
1768 break; 1767 break;
1769 1768
1770 case 45: 1769 case 39:
1771#line 335 "dtc-parser.y" 1770
1771/* Line 1455 of yacc.c */
1772#line 307 "dtc-parser.y"
1772 { 1773 {
1773 (yyval.labelref) = (yyvsp[(1) - (1)].labelref); 1774 add_label(&(yyvsp[(2) - (2)].node)->labels, (yyvsp[(1) - (2)].labelref));
1775 (yyval.node) = (yyvsp[(2) - (2)].node);
1774 ;} 1776 ;}
1775 break; 1777 break;
1776 1778
1777 1779
1778/* Line 1267 of yacc.c. */ 1780
1779#line 1780 "dtc-parser.tab.c" 1781/* Line 1455 of yacc.c */
1782#line 1783 "dtc-parser.tab.c"
1780 default: break; 1783 default: break;
1781 } 1784 }
1782 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); 1785 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -1786,7 +1789,6 @@ yyreduce:
1786 YY_STACK_PRINT (yyss, yyssp); 1789 YY_STACK_PRINT (yyss, yyssp);
1787 1790
1788 *++yyvsp = yyval; 1791 *++yyvsp = yyval;
1789 *++yylsp = yyloc;
1790 1792
1791 /* Now `shift' the result of the reduction. Determine what state 1793 /* Now `shift' the result of the reduction. Determine what state
1792 that goes to, based on the state we popped back to and the rule 1794 that goes to, based on the state we popped back to and the rule
@@ -1848,11 +1850,11 @@ yyerrlab:
1848#endif 1850#endif
1849 } 1851 }
1850 1852
1851 yyerror_range[0] = yylloc; 1853
1852 1854
1853 if (yyerrstatus == 3) 1855 if (yyerrstatus == 3)
1854 { 1856 {
1855 /* If just tried and failed to reuse look-ahead token after an 1857 /* If just tried and failed to reuse lookahead token after an
1856 error, discard it. */ 1858 error, discard it. */
1857 1859
1858 if (yychar <= YYEOF) 1860 if (yychar <= YYEOF)
@@ -1864,12 +1866,12 @@ yyerrlab:
1864 else 1866 else
1865 { 1867 {
1866 yydestruct ("Error: discarding", 1868 yydestruct ("Error: discarding",
1867 yytoken, &yylval, &yylloc); 1869 yytoken, &yylval);
1868 yychar = YYEMPTY; 1870 yychar = YYEMPTY;
1869 } 1871 }
1870 } 1872 }
1871 1873
1872 /* Else will try to reuse look-ahead token after shifting the error 1874 /* Else will try to reuse lookahead token after shifting the error
1873 token. */ 1875 token. */
1874 goto yyerrlab1; 1876 goto yyerrlab1;
1875 1877
@@ -1885,7 +1887,6 @@ yyerrorlab:
1885 if (/*CONSTCOND*/ 0) 1887 if (/*CONSTCOND*/ 0)
1886 goto yyerrorlab; 1888 goto yyerrorlab;
1887 1889
1888 yyerror_range[0] = yylsp[1-yylen];
1889 /* Do not reclaim the symbols of the rule which action triggered 1890 /* Do not reclaim the symbols of the rule which action triggered
1890 this YYERROR. */ 1891 this YYERROR. */
1891 YYPOPSTACK (yylen); 1892 YYPOPSTACK (yylen);
@@ -1919,24 +1920,16 @@ yyerrlab1:
1919 if (yyssp == yyss) 1920 if (yyssp == yyss)
1920 YYABORT; 1921 YYABORT;
1921 1922
1922 yyerror_range[0] = *yylsp; 1923
1923 yydestruct ("Error: popping", 1924 yydestruct ("Error: popping",
1924 yystos[yystate], yyvsp, yylsp); 1925 yystos[yystate], yyvsp);
1925 YYPOPSTACK (1); 1926 YYPOPSTACK (1);
1926 yystate = *yyssp; 1927 yystate = *yyssp;
1927 YY_STACK_PRINT (yyss, yyssp); 1928 YY_STACK_PRINT (yyss, yyssp);
1928 } 1929 }
1929 1930
1930 if (yyn == YYFINAL)
1931 YYACCEPT;
1932
1933 *++yyvsp = yylval; 1931 *++yyvsp = yylval;
1934 1932
1935 yyerror_range[1] = yylloc;
1936 /* Using YYLLOC is tempting, but would change the location of
1937 the look-ahead. YYLOC is available though. */
1938 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
1939 *++yylsp = yyloc;
1940 1933
1941 /* Shift the error token. */ 1934 /* Shift the error token. */
1942 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); 1935 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
@@ -1959,7 +1952,7 @@ yyabortlab:
1959 yyresult = 1; 1952 yyresult = 1;
1960 goto yyreturn; 1953 goto yyreturn;
1961 1954
1962#ifndef yyoverflow 1955#if !defined(yyoverflow) || YYERROR_VERBOSE
1963/*-------------------------------------------------. 1956/*-------------------------------------------------.
1964| yyexhaustedlab -- memory exhaustion comes here. | 1957| yyexhaustedlab -- memory exhaustion comes here. |
1965`-------------------------------------------------*/ 1958`-------------------------------------------------*/
@@ -1970,9 +1963,9 @@ yyexhaustedlab:
1970#endif 1963#endif
1971 1964
1972yyreturn: 1965yyreturn:
1973 if (yychar != YYEOF && yychar != YYEMPTY) 1966 if (yychar != YYEMPTY)
1974 yydestruct ("Cleanup: discarding lookahead", 1967 yydestruct ("Cleanup: discarding lookahead",
1975 yytoken, &yylval, &yylloc); 1968 yytoken, &yylval);
1976 /* Do not reclaim the symbols of the rule which action triggered 1969 /* Do not reclaim the symbols of the rule which action triggered
1977 this YYABORT or YYACCEPT. */ 1970 this YYABORT or YYACCEPT. */
1978 YYPOPSTACK (yylen); 1971 YYPOPSTACK (yylen);
@@ -1980,7 +1973,7 @@ yyreturn:
1980 while (yyssp != yyss) 1973 while (yyssp != yyss)
1981 { 1974 {
1982 yydestruct ("Cleanup: popping", 1975 yydestruct ("Cleanup: popping",
1983 yystos[*yyssp], yyvsp, yylsp); 1976 yystos[*yyssp], yyvsp);
1984 YYPOPSTACK (1); 1977 YYPOPSTACK (1);
1985 } 1978 }
1986#ifndef yyoverflow 1979#ifndef yyoverflow
@@ -1996,29 +1989,24 @@ yyreturn:
1996} 1989}
1997 1990
1998 1991
1999#line 340 "dtc-parser.y" 1992
1993/* Line 1675 of yacc.c */
1994#line 313 "dtc-parser.y"
2000 1995
2001 1996
2002void yyerrorf(char const *s, ...) 1997void print_error(char const *fmt, ...)
2003{ 1998{
2004 const char *fname = srcpos_file ? srcpos_file->name : "<no-file>";
2005 va_list va; 1999 va_list va;
2006 va_start(va, s);
2007
2008 if (strcmp(fname, "-") == 0)
2009 fname = "stdin";
2010 2000
2011 fprintf(stderr, "%s:%d ", fname, yylloc.first_line); 2001 va_start(va, fmt);
2012 vfprintf(stderr, s, va); 2002 srcpos_verror(&yylloc, fmt, va);
2013 fprintf(stderr, "\n"); 2003 va_end(va);
2014 2004
2015 treesource_error = 1; 2005 treesource_error = 1;
2016 va_end(va);
2017} 2006}
2018 2007
2019void yyerror (char const *s) 2008void yyerror(char const *s) {
2020{ 2009 print_error("%s", s);
2021 yyerrorf("%s", s);
2022} 2010}
2023 2011
2024static unsigned long long eval_literal(const char *s, int base, int bits) 2012static unsigned long long eval_literal(const char *s, int base, int bits)
@@ -2029,12 +2017,12 @@ static unsigned long long eval_literal(const char *s, int base, int bits)
2029 errno = 0; 2017 errno = 0;
2030 val = strtoull(s, &e, base); 2018 val = strtoull(s, &e, base);
2031 if (*e) 2019 if (*e)
2032 yyerror("bad characters in literal"); 2020 print_error("bad characters in literal");
2033 else if ((errno == ERANGE) 2021 else if ((errno == ERANGE)
2034 || ((bits < 64) && (val >= (1ULL << bits)))) 2022 || ((bits < 64) && (val >= (1ULL << bits))))
2035 yyerror("literal out of range"); 2023 print_error("literal out of range");
2036 else if (errno != 0) 2024 else if (errno != 0)
2037 yyerror("bad literal"); 2025 print_error("bad literal");
2038 return val; 2026 return val;
2039} 2027}
2040 2028
diff --git a/scripts/dtc/dtc-parser.tab.h_shipped b/scripts/dtc/dtc-parser.tab.h_shipped
index ba99100d55c9..95c9547adea5 100644
--- a/scripts/dtc/dtc-parser.tab.h_shipped
+++ b/scripts/dtc/dtc-parser.tab.h_shipped
@@ -1,24 +1,23 @@
1/* A Bison parser, made by GNU Bison 2.3. */
2 1
3/* Skeleton interface for Bison's Yacc-like parsers in C 2/* A Bison parser, made by GNU Bison 2.4.1. */
4 3
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 4/* Skeleton interface for Bison's Yacc-like parsers in C
5
6 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc. 7 Free Software Foundation, Inc.
7 8
8 This program is free software; you can redistribute it and/or modify 9 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option) 11 the Free Software Foundation, either version 3 of the License, or
11 any later version. 12 (at your option) any later version.
12 13
13 This program is distributed in the hope that it will be useful, 14 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 17 GNU General Public License for more details.
17 18
18 You should have received a copy of the GNU General Public License 19 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 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22 21
23/* As a special exception, you may create a larger work that contains 22/* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work 23 part or all of the Bison parser skeleton and distribute that work
@@ -29,10 +28,11 @@
29 special exception, which will cause the skeleton and the resulting 28 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public 29 Bison output files to be licensed under the GNU General Public
31 License without this special exception. 30 License without this special exception.
32 31
33 This special exception was added by the Free Software Foundation in 32 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */ 33 version 2.2 of Bison. */
35 34
35
36/* Tokens. */ 36/* Tokens. */
37#ifndef YYTOKENTYPE 37#ifndef YYTOKENTYPE
38# define YYTOKENTYPE 38# define YYTOKENTYPE
@@ -43,35 +43,24 @@
43 DT_MEMRESERVE = 259, 43 DT_MEMRESERVE = 259,
44 DT_PROPNODENAME = 260, 44 DT_PROPNODENAME = 260,
45 DT_LITERAL = 261, 45 DT_LITERAL = 261,
46 DT_LEGACYLITERAL = 262, 46 DT_BASE = 262,
47 DT_BASE = 263, 47 DT_BYTE = 263,
48 DT_BYTE = 264, 48 DT_STRING = 264,
49 DT_STRING = 265, 49 DT_LABEL = 265,
50 DT_LABEL = 266, 50 DT_REF = 266,
51 DT_REF = 267, 51 DT_INCBIN = 267
52 DT_INCBIN = 268
53 }; 52 };
54#endif 53#endif
55/* Tokens. */
56#define DT_V1 258
57#define DT_MEMRESERVE 259
58#define DT_PROPNODENAME 260
59#define DT_LITERAL 261
60#define DT_LEGACYLITERAL 262
61#define DT_BASE 263
62#define DT_BYTE 264
63#define DT_STRING 265
64#define DT_LABEL 266
65#define DT_REF 267
66#define DT_INCBIN 268
67
68 54
69 55
70 56
71#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 57#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
72typedef union YYSTYPE 58typedef union YYSTYPE
73#line 37 "dtc-parser.y"
74{ 59{
60
61/* Line 1676 of yacc.c */
62#line 39 "dtc-parser.y"
63
75 char *propnodename; 64 char *propnodename;
76 char *literal; 65 char *literal;
77 char *labelref; 66 char *labelref;
@@ -86,28 +75,17 @@ typedef union YYSTYPE
86 struct node *node; 75 struct node *node;
87 struct node *nodelist; 76 struct node *nodelist;
88 struct reserve_info *re; 77 struct reserve_info *re;
89} 78
90/* Line 1489 of yacc.c. */ 79
91#line 92 "dtc-parser.tab.h" 80
92 YYSTYPE; 81/* Line 1676 of yacc.c */
82#line 83 "dtc-parser.tab.h"
83} YYSTYPE;
84# define YYSTYPE_IS_TRIVIAL 1
93# define yystype YYSTYPE /* obsolescent; will be withdrawn */ 85# define yystype YYSTYPE /* obsolescent; will be withdrawn */
94# define YYSTYPE_IS_DECLARED 1 86# define YYSTYPE_IS_DECLARED 1
95# define YYSTYPE_IS_TRIVIAL 1
96#endif 87#endif
97 88
98extern YYSTYPE yylval; 89extern YYSTYPE yylval;
99 90
100#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
101typedef struct YYLTYPE
102{
103 int first_line;
104 int first_column;
105 int last_line;
106 int last_column;
107} YYLTYPE;
108# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
109# define YYLTYPE_IS_DECLARED 1
110# define YYLTYPE_IS_TRIVIAL 1
111#endif
112 91
113extern YYLTYPE yylloc;
diff --git a/scripts/dtc/dtc-parser.y b/scripts/dtc/dtc-parser.y
index b2ab562420ea..5e84a67fc1d2 100644
--- a/scripts/dtc/dtc-parser.y
+++ b/scripts/dtc/dtc-parser.y
@@ -18,15 +18,17 @@
18 * USA 18 * USA
19 */ 19 */
20 20
21%locations
22
23%{ 21%{
24#include <stdio.h> 22#include <stdio.h>
25 23
26#include "dtc.h" 24#include "dtc.h"
27#include "srcpos.h" 25#include "srcpos.h"
28 26
27YYLTYPE yylloc;
28
29extern int yylex(void); 29extern int yylex(void);
30extern void print_error(char const *fmt, ...);
31extern void yyerror(char const *s);
30 32
31extern struct boot_info *the_boot_info; 33extern struct boot_info *the_boot_info;
32extern int treesource_error; 34extern int treesource_error;
@@ -55,7 +57,6 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
55%token DT_MEMRESERVE 57%token DT_MEMRESERVE
56%token <propnodename> DT_PROPNODENAME 58%token <propnodename> DT_PROPNODENAME
57%token <literal> DT_LITERAL 59%token <literal> DT_LITERAL
58%token <literal> DT_LEGACYLITERAL
59%token <cbase> DT_BASE 60%token <cbase> DT_BASE
60%token <byte> DT_BYTE 61%token <byte> DT_BYTE
61%token <data> DT_STRING 62%token <data> DT_STRING
@@ -67,11 +68,8 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
67%type <data> propdataprefix 68%type <data> propdataprefix
68%type <re> memreserve 69%type <re> memreserve
69%type <re> memreserves 70%type <re> memreserves
70%type <re> v0_memreserve
71%type <re> v0_memreserves
72%type <addr> addr 71%type <addr> addr
73%type <data> celllist 72%type <data> celllist
74%type <cbase> cellbase
75%type <cell> cellval 73%type <cell> cellval
76%type <data> bytestring 74%type <data> bytestring
77%type <prop> propdef 75%type <prop> propdef
@@ -81,18 +79,14 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
81%type <node> nodedef 79%type <node> nodedef
82%type <node> subnode 80%type <node> subnode
83%type <nodelist> subnodes 81%type <nodelist> subnodes
84%type <labelref> label
85 82
86%% 83%%
87 84
88sourcefile: 85sourcefile:
89 DT_V1 ';' memreserves devicetree 86 DT_V1 ';' memreserves devicetree
90 { 87 {
91 the_boot_info = build_boot_info($3, $4, 0); 88 the_boot_info = build_boot_info($3, $4,
92 } 89 guess_boot_cpuid($4));
93 | v0_memreserves devicetree
94 {
95 the_boot_info = build_boot_info($1, $2, 0);
96 } 90 }
97 ; 91 ;
98 92
@@ -108,31 +102,14 @@ memreserves:
108 ; 102 ;
109 103
110memreserve: 104memreserve:
111 label DT_MEMRESERVE addr addr ';' 105 DT_MEMRESERVE addr addr ';'
112 { 106 {
113 $$ = build_reserve_entry($3, $4, $1); 107 $$ = build_reserve_entry($2, $3);
114 } 108 }
115 ; 109 | DT_LABEL memreserve
116
117v0_memreserves:
118 /* empty */
119 { 110 {
120 $$ = NULL; 111 add_label(&$2->labels, $1);
121 } 112 $$ = $2;
122 | v0_memreserve v0_memreserves
123 {
124 $$ = chain_reserve_entry($1, $2);
125 };
126 ;
127
128v0_memreserve:
129 memreserve
130 {
131 $$ = $1;
132 }
133 | label DT_MEMRESERVE addr '-' addr ';'
134 {
135 $$ = build_reserve_entry($3, $5 - $3 + 1, $1);
136 } 113 }
137 ; 114 ;
138 115
@@ -141,16 +118,26 @@ addr:
141 { 118 {
142 $$ = eval_literal($1, 0, 64); 119 $$ = eval_literal($1, 0, 64);
143 } 120 }
144 | DT_LEGACYLITERAL
145 {
146 $$ = eval_literal($1, 16, 64);
147 }
148 ; 121 ;
149 122
150devicetree: 123devicetree:
151 '/' nodedef 124 '/' nodedef
152 { 125 {
153 $$ = name_node($2, "", NULL); 126 $$ = name_node($2, "");
127 }
128 | devicetree '/' nodedef
129 {
130 $$ = merge_nodes($1, $3);
131 }
132 | devicetree DT_REF nodedef
133 {
134 struct node *target = get_node_by_ref($1, $2);
135
136 if (target)
137 merge_nodes(target, $3);
138 else
139 print_error("label or path, '%s', not found", $2);
140 $$ = $1;
154 } 141 }
155 ; 142 ;
156 143
@@ -173,13 +160,18 @@ proplist:
173 ; 160 ;
174 161
175propdef: 162propdef:
176 label DT_PROPNODENAME '=' propdata ';' 163 DT_PROPNODENAME '=' propdata ';'
164 {
165 $$ = build_property($1, $3);
166 }
167 | DT_PROPNODENAME ';'
177 { 168 {
178 $$ = build_property($2, $4, $1); 169 $$ = build_property($1, empty_data);
179 } 170 }
180 | label DT_PROPNODENAME ';' 171 | DT_LABEL propdef
181 { 172 {
182 $$ = build_property($2, empty_data, $1); 173 add_label(&$2->labels, $1);
174 $$ = $2;
183 } 175 }
184 ; 176 ;
185 177
@@ -202,31 +194,30 @@ propdata:
202 } 194 }
203 | propdataprefix DT_INCBIN '(' DT_STRING ',' addr ',' addr ')' 195 | propdataprefix DT_INCBIN '(' DT_STRING ',' addr ',' addr ')'
204 { 196 {
205 struct search_path path = { srcpos_file->dir, NULL, NULL }; 197 FILE *f = srcfile_relative_open($4.val, NULL);
206 struct dtc_file *file = dtc_open_file($4.val, &path); 198 struct data d;
207 struct data d = empty_data;
208 199
209 if ($6 != 0) 200 if ($6 != 0)
210 if (fseek(file->file, $6, SEEK_SET) != 0) 201 if (fseek(f, $6, SEEK_SET) != 0)
211 yyerrorf("Couldn't seek to offset %llu in \"%s\": %s", 202 print_error("Couldn't seek to offset %llu in \"%s\": %s",
212 (unsigned long long)$6, 203 (unsigned long long)$6,
213 $4.val, strerror(errno)); 204 $4.val,
205 strerror(errno));
214 206
215 d = data_copy_file(file->file, $8); 207 d = data_copy_file(f, $8);
216 208
217 $$ = data_merge($1, d); 209 $$ = data_merge($1, d);
218 dtc_close_file(file); 210 fclose(f);
219 } 211 }
220 | propdataprefix DT_INCBIN '(' DT_STRING ')' 212 | propdataprefix DT_INCBIN '(' DT_STRING ')'
221 { 213 {
222 struct search_path path = { srcpos_file->dir, NULL, NULL }; 214 FILE *f = srcfile_relative_open($4.val, NULL);
223 struct dtc_file *file = dtc_open_file($4.val, &path);
224 struct data d = empty_data; 215 struct data d = empty_data;
225 216
226 d = data_copy_file(file->file, -1); 217 d = data_copy_file(f, -1);
227 218
228 $$ = data_merge($1, d); 219 $$ = data_merge($1, d);
229 dtc_close_file(file); 220 fclose(f);
230 } 221 }
231 | propdata DT_LABEL 222 | propdata DT_LABEL
232 { 223 {
@@ -269,23 +260,11 @@ celllist:
269 } 260 }
270 ; 261 ;
271 262
272cellbase:
273 /* empty */
274 {
275 $$ = 16;
276 }
277 | DT_BASE
278 ;
279
280cellval: 263cellval:
281 DT_LITERAL 264 DT_LITERAL
282 { 265 {
283 $$ = eval_literal($1, 0, 32); 266 $$ = eval_literal($1, 0, 32);
284 } 267 }
285 | cellbase DT_LEGACYLITERAL
286 {
287 $$ = eval_literal($2, $1, 32);
288 }
289 ; 268 ;
290 269
291bytestring: 270bytestring:
@@ -308,57 +287,44 @@ subnodes:
308 { 287 {
309 $$ = NULL; 288 $$ = NULL;
310 } 289 }
311 | subnode subnodes 290 | subnode subnodes
312 { 291 {
313 $$ = chain_node($1, $2); 292 $$ = chain_node($1, $2);
314 } 293 }
315 | subnode propdef 294 | subnode propdef
316 { 295 {
317 yyerror("syntax error: properties must precede subnodes"); 296 print_error("syntax error: properties must precede subnodes");
318 YYERROR; 297 YYERROR;
319 } 298 }
320 ; 299 ;
321 300
322subnode: 301subnode:
323 label DT_PROPNODENAME nodedef 302 DT_PROPNODENAME nodedef
324 { 303 {
325 $$ = name_node($3, $2, $1); 304 $$ = name_node($2, $1);
326 } 305 }
327 ; 306 | DT_LABEL subnode
328
329label:
330 /* empty */
331 { 307 {
332 $$ = NULL; 308 add_label(&$2->labels, $1);
333 } 309 $$ = $2;
334 | DT_LABEL
335 {
336 $$ = $1;
337 } 310 }
338 ; 311 ;
339 312
340%% 313%%
341 314
342void yyerrorf(char const *s, ...) 315void print_error(char const *fmt, ...)
343{ 316{
344 const char *fname = srcpos_file ? srcpos_file->name : "<no-file>";
345 va_list va; 317 va_list va;
346 va_start(va, s);
347
348 if (strcmp(fname, "-") == 0)
349 fname = "stdin";
350 318
351 fprintf(stderr, "%s:%d ", fname, yylloc.first_line); 319 va_start(va, fmt);
352 vfprintf(stderr, s, va); 320 srcpos_verror(&yylloc, fmt, va);
353 fprintf(stderr, "\n"); 321 va_end(va);
354 322
355 treesource_error = 1; 323 treesource_error = 1;
356 va_end(va);
357} 324}
358 325
359void yyerror (char const *s) 326void yyerror(char const *s) {
360{ 327 print_error("%s", s);
361 yyerrorf("%s", s);
362} 328}
363 329
364static unsigned long long eval_literal(const char *s, int base, int bits) 330static unsigned long long eval_literal(const char *s, int base, int bits)
@@ -369,11 +335,11 @@ static unsigned long long eval_literal(const char *s, int base, int bits)
369 errno = 0; 335 errno = 0;
370 val = strtoull(s, &e, base); 336 val = strtoull(s, &e, base);
371 if (*e) 337 if (*e)
372 yyerror("bad characters in literal"); 338 print_error("bad characters in literal");
373 else if ((errno == ERANGE) 339 else if ((errno == ERANGE)
374 || ((bits < 64) && (val >= (1ULL << bits)))) 340 || ((bits < 64) && (val >= (1ULL << bits))))
375 yyerror("literal out of range"); 341 print_error("literal out of range");
376 else if (errno != 0) 342 else if (errno != 0)
377 yyerror("bad literal"); 343 print_error("bad literal");
378 return val; 344 return val;
379} 345}
diff --git a/scripts/dtc/dtc.c b/scripts/dtc/dtc.c
index d8fd43b4ac1a..cbc0193098e4 100644
--- a/scripts/dtc/dtc.c
+++ b/scripts/dtc/dtc.c
@@ -30,30 +30,7 @@ int quiet; /* Level of quietness */
30int reservenum; /* Number of memory reservation slots */ 30int reservenum; /* Number of memory reservation slots */
31int minsize; /* Minimum blob size */ 31int minsize; /* Minimum blob size */
32int padsize; /* Additional padding to blob */ 32int padsize; /* Additional padding to blob */
33 33int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */
34char *join_path(const char *path, const char *name)
35{
36 int lenp = strlen(path);
37 int lenn = strlen(name);
38 int len;
39 int needslash = 1;
40 char *str;
41
42 len = lenp + lenn + 2;
43 if ((lenp > 0) && (path[lenp-1] == '/')) {
44 needslash = 0;
45 len--;
46 }
47
48 str = xmalloc(len);
49 memcpy(str, path, lenp);
50 if (needslash) {
51 str[lenp] = '/';
52 lenp++;
53 }
54 memcpy(str+lenp, name, lenn+1);
55 return str;
56}
57 34
58static void fill_fullpaths(struct node *tree, const char *prefix) 35static void fill_fullpaths(struct node *tree, const char *prefix)
59{ 36{
@@ -104,8 +81,15 @@ static void __attribute__ ((noreturn)) usage(void)
104 fprintf(stderr, "\t\tSet the physical boot cpu\n"); 81 fprintf(stderr, "\t\tSet the physical boot cpu\n");
105 fprintf(stderr, "\t-f\n"); 82 fprintf(stderr, "\t-f\n");
106 fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n"); 83 fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n");
84 fprintf(stderr, "\t-s\n");
85 fprintf(stderr, "\t\tSort nodes and properties before outputting (only useful for\n\t\tcomparing trees)\n");
107 fprintf(stderr, "\t-v\n"); 86 fprintf(stderr, "\t-v\n");
108 fprintf(stderr, "\t\tPrint DTC version and exit\n"); 87 fprintf(stderr, "\t\tPrint DTC version and exit\n");
88 fprintf(stderr, "\t-H <phandle format>\n");
89 fprintf(stderr, "\t\tphandle formats are:\n");
90 fprintf(stderr, "\t\t\tlegacy - \"linux,phandle\" properties only\n");
91 fprintf(stderr, "\t\t\tepapr - \"phandle\" properties only\n");
92 fprintf(stderr, "\t\t\tboth - Both \"linux,phandle\" and \"phandle\" properties\n");
109 exit(3); 93 exit(3);
110} 94}
111 95
@@ -115,7 +99,7 @@ int main(int argc, char *argv[])
115 const char *inform = "dts"; 99 const char *inform = "dts";
116 const char *outform = "dts"; 100 const char *outform = "dts";
117 const char *outname = "-"; 101 const char *outname = "-";
118 int force = 0, check = 0; 102 int force = 0, check = 0, sort = 0;
119 const char *arg; 103 const char *arg;
120 int opt; 104 int opt;
121 FILE *outf = NULL; 105 FILE *outf = NULL;
@@ -127,7 +111,7 @@ int main(int argc, char *argv[])
127 minsize = 0; 111 minsize = 0;
128 padsize = 0; 112 padsize = 0;
129 113
130 while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:fcqb:v")) != EOF) { 114 while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:fcqb:vH:s")) != EOF) {
131 switch (opt) { 115 switch (opt) {
132 case 'I': 116 case 'I':
133 inform = optarg; 117 inform = optarg;
@@ -165,6 +149,22 @@ int main(int argc, char *argv[])
165 case 'v': 149 case 'v':
166 printf("Version: %s\n", DTC_VERSION); 150 printf("Version: %s\n", DTC_VERSION);
167 exit(0); 151 exit(0);
152 case 'H':
153 if (streq(optarg, "legacy"))
154 phandle_format = PHANDLE_LEGACY;
155 else if (streq(optarg, "epapr"))
156 phandle_format = PHANDLE_EPAPR;
157 else if (streq(optarg, "both"))
158 phandle_format = PHANDLE_BOTH;
159 else
160 die("Invalid argument \"%s\" to -H option\n",
161 optarg);
162 break;
163
164 case 's':
165 sort = 1;
166 break;
167
168 case 'h': 168 case 'h':
169 default: 169 default:
170 usage(); 170 usage();
@@ -182,6 +182,9 @@ int main(int argc, char *argv[])
182 if (minsize && padsize) 182 if (minsize && padsize)
183 die("Can't set both -p and -S\n"); 183 die("Can't set both -p and -S\n");
184 184
185 if (minsize)
186 fprintf(stderr, "DTC: Use of \"-S\" is deprecated; it will be removed soon, use \"-p\" instead\n");
187
185 fprintf(stderr, "DTC: %s->%s on file \"%s\"\n", 188 fprintf(stderr, "DTC: %s->%s on file \"%s\"\n",
186 inform, outform, arg); 189 inform, outform, arg);
187 190
@@ -200,6 +203,8 @@ int main(int argc, char *argv[])
200 fill_fullpaths(bi->dt, ""); 203 fill_fullpaths(bi->dt, "");
201 process_checks(force, bi); 204 process_checks(force, bi);
202 205
206 if (sort)
207 sort_tree(bi);
203 208
204 if (streq(outname, "-")) { 209 if (streq(outname, "-")) {
205 outf = stdout; 210 outf = stdout;
diff --git a/scripts/dtc/dtc.h b/scripts/dtc/dtc.h
index 08d54c870086..f37c97eb3dfc 100644
--- a/scripts/dtc/dtc.h
+++ b/scripts/dtc/dtc.h
@@ -34,7 +34,17 @@
34#include <libfdt_env.h> 34#include <libfdt_env.h>
35#include <fdt.h> 35#include <fdt.h>
36 36
37#include "util.h"
38
39#ifdef DEBUG
40#define debug(fmt,args...) printf(fmt, ##args)
41#else
42#define debug(fmt,args...)
43#endif
44
45
37#define DEFAULT_FDT_VERSION 17 46#define DEFAULT_FDT_VERSION 17
47
38/* 48/*
39 * Command line options 49 * Command line options
40 */ 50 */
@@ -42,36 +52,11 @@ extern int quiet; /* Level of quietness */
42extern int reservenum; /* Number of memory reservation slots */ 52extern int reservenum; /* Number of memory reservation slots */
43extern int minsize; /* Minimum blob size */ 53extern int minsize; /* Minimum blob size */
44extern int padsize; /* Additional padding to blob */ 54extern int padsize; /* Additional padding to blob */
55extern int phandle_format; /* Use linux,phandle or phandle properties */
45 56
46static inline void __attribute__((noreturn)) die(char * str, ...) 57#define PHANDLE_LEGACY 0x1
47{ 58#define PHANDLE_EPAPR 0x2
48 va_list ap; 59#define PHANDLE_BOTH 0x3
49
50 va_start(ap, str);
51 fprintf(stderr, "FATAL ERROR: ");
52 vfprintf(stderr, str, ap);
53 exit(1);
54}
55
56static inline void *xmalloc(size_t len)
57{
58 void *new = malloc(len);
59
60 if (! new)
61 die("malloc() failed\n");
62
63 return new;
64}
65
66static inline void *xrealloc(void *p, size_t len)
67{
68 void *new = realloc(p, len);
69
70 if (! new)
71 die("realloc() failed (len=%d)\n", len);
72
73 return new;
74}
75 60
76typedef uint32_t cell_t; 61typedef uint32_t cell_t;
77 62
@@ -140,13 +125,18 @@ int data_is_one_string(struct data d);
140#define MAX_NODENAME_LEN 31 125#define MAX_NODENAME_LEN 31
141 126
142/* Live trees */ 127/* Live trees */
128struct label {
129 char *label;
130 struct label *next;
131};
132
143struct property { 133struct property {
144 char *name; 134 char *name;
145 struct data val; 135 struct data val;
146 136
147 struct property *next; 137 struct property *next;
148 138
149 char *label; 139 struct label *labels;
150}; 140};
151 141
152struct node { 142struct node {
@@ -163,22 +153,28 @@ struct node {
163 cell_t phandle; 153 cell_t phandle;
164 int addr_cells, size_cells; 154 int addr_cells, size_cells;
165 155
166 char *label; 156 struct label *labels;
167}; 157};
168 158
159#define for_each_label(l0, l) \
160 for ((l) = (l0); (l); (l) = (l)->next)
161
169#define for_each_property(n, p) \ 162#define for_each_property(n, p) \
170 for ((p) = (n)->proplist; (p); (p) = (p)->next) 163 for ((p) = (n)->proplist; (p); (p) = (p)->next)
171 164
172#define for_each_child(n, c) \ 165#define for_each_child(n, c) \
173 for ((c) = (n)->children; (c); (c) = (c)->next_sibling) 166 for ((c) = (n)->children; (c); (c) = (c)->next_sibling)
174 167
175struct property *build_property(char *name, struct data val, char *label); 168void add_label(struct label **labels, char *label);
169
170struct property *build_property(char *name, struct data val);
176struct property *chain_property(struct property *first, struct property *list); 171struct property *chain_property(struct property *first, struct property *list);
177struct property *reverse_properties(struct property *first); 172struct property *reverse_properties(struct property *first);
178 173
179struct node *build_node(struct property *proplist, struct node *children); 174struct node *build_node(struct property *proplist, struct node *children);
180struct node *name_node(struct node *node, char *name, char *label); 175struct node *name_node(struct node *node, char *name);
181struct node *chain_node(struct node *first, struct node *list); 176struct node *chain_node(struct node *first, struct node *list);
177struct node *merge_nodes(struct node *old_node, struct node *new_node);
182 178
183void add_property(struct node *node, struct property *prop); 179void add_property(struct node *node, struct property *prop);
184void add_child(struct node *parent, struct node *child); 180void add_child(struct node *parent, struct node *child);
@@ -186,6 +182,10 @@ void add_child(struct node *parent, struct node *child);
186const char *get_unitname(struct node *node); 182const char *get_unitname(struct node *node);
187struct property *get_property(struct node *node, const char *propname); 183struct property *get_property(struct node *node, const char *propname);
188cell_t propval_cell(struct property *prop); 184cell_t propval_cell(struct property *prop);
185struct property *get_property_by_label(struct node *tree, const char *label,
186 struct node **node);
187struct marker *get_marker_label(struct node *tree, const char *label,
188 struct node **node, struct property **prop);
189struct node *get_subnode(struct node *node, const char *nodename); 189struct node *get_subnode(struct node *node, const char *nodename);
190struct node *get_node_by_path(struct node *tree, const char *path); 190struct node *get_node_by_path(struct node *tree, const char *path);
191struct node *get_node_by_label(struct node *tree, const char *label); 191struct node *get_node_by_label(struct node *tree, const char *label);
@@ -193,6 +193,8 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
193struct node *get_node_by_ref(struct node *tree, const char *ref); 193struct node *get_node_by_ref(struct node *tree, const char *ref);
194cell_t get_node_phandle(struct node *root, struct node *node); 194cell_t get_node_phandle(struct node *root, struct node *node);
195 195
196uint32_t guess_boot_cpuid(struct node *tree);
197
196/* Boot info (tree plus memreserve information */ 198/* Boot info (tree plus memreserve information */
197 199
198struct reserve_info { 200struct reserve_info {
@@ -200,10 +202,10 @@ struct reserve_info {
200 202
201 struct reserve_info *next; 203 struct reserve_info *next;
202 204
203 char *label; 205 struct label *labels;
204}; 206};
205 207
206struct reserve_info *build_reserve_entry(uint64_t start, uint64_t len, char *label); 208struct reserve_info *build_reserve_entry(uint64_t start, uint64_t len);
207struct reserve_info *chain_reserve_entry(struct reserve_info *first, 209struct reserve_info *chain_reserve_entry(struct reserve_info *first,
208 struct reserve_info *list); 210 struct reserve_info *list);
209struct reserve_info *add_reserve_entry(struct reserve_info *list, 211struct reserve_info *add_reserve_entry(struct reserve_info *list,
@@ -218,6 +220,7 @@ struct boot_info {
218 220
219struct boot_info *build_boot_info(struct reserve_info *reservelist, 221struct boot_info *build_boot_info(struct reserve_info *reservelist,
220 struct node *tree, uint32_t boot_cpuid_phys); 222 struct node *tree, uint32_t boot_cpuid_phys);
223void sort_tree(struct boot_info *bi);
221 224
222/* Checks */ 225/* Checks */
223 226
@@ -239,8 +242,4 @@ struct boot_info *dt_from_source(const char *f);
239 242
240struct boot_info *dt_from_fs(const char *dirname); 243struct boot_info *dt_from_fs(const char *dirname);
241 244
242/* misc */
243
244char *join_path(const char *path, const char *name);
245
246#endif /* _DTC_H */ 245#endif /* _DTC_H */
diff --git a/scripts/dtc/flattree.c b/scripts/dtc/flattree.c
index 76acd28c068d..ead0332c87e1 100644
--- a/scripts/dtc/flattree.c
+++ b/scripts/dtc/flattree.c
@@ -52,9 +52,9 @@ struct emitter {
52 void (*string)(void *, char *, int); 52 void (*string)(void *, char *, int);
53 void (*align)(void *, int); 53 void (*align)(void *, int);
54 void (*data)(void *, struct data); 54 void (*data)(void *, struct data);
55 void (*beginnode)(void *, const char *); 55 void (*beginnode)(void *, struct label *labels);
56 void (*endnode)(void *, const char *); 56 void (*endnode)(void *, struct label *labels);
57 void (*property)(void *, const char *); 57 void (*property)(void *, struct label *labels);
58}; 58};
59 59
60static void bin_emit_cell(void *e, cell_t val) 60static void bin_emit_cell(void *e, cell_t val)
@@ -89,17 +89,17 @@ static void bin_emit_data(void *e, struct data d)
89 *dtbuf = data_append_data(*dtbuf, d.val, d.len); 89 *dtbuf = data_append_data(*dtbuf, d.val, d.len);
90} 90}
91 91
92static void bin_emit_beginnode(void *e, const char *label) 92static void bin_emit_beginnode(void *e, struct label *labels)
93{ 93{
94 bin_emit_cell(e, FDT_BEGIN_NODE); 94 bin_emit_cell(e, FDT_BEGIN_NODE);
95} 95}
96 96
97static void bin_emit_endnode(void *e, const char *label) 97static void bin_emit_endnode(void *e, struct label *labels)
98{ 98{
99 bin_emit_cell(e, FDT_END_NODE); 99 bin_emit_cell(e, FDT_END_NODE);
100} 100}
101 101
102static void bin_emit_property(void *e, const char *label) 102static void bin_emit_property(void *e, struct label *labels)
103{ 103{
104 bin_emit_cell(e, FDT_PROP); 104 bin_emit_cell(e, FDT_PROP);
105} 105}
@@ -127,11 +127,21 @@ static void emit_offset_label(FILE *f, const char *label, int offset)
127 fprintf(f, "%s\t= . + %d\n", label, offset); 127 fprintf(f, "%s\t= . + %d\n", label, offset);
128} 128}
129 129
130#define ASM_EMIT_BELONG(f, fmt, ...) \
131 { \
132 fprintf((f), "\t.byte\t((" fmt ") >> 24) & 0xff\n", __VA_ARGS__); \
133 fprintf((f), "\t.byte\t((" fmt ") >> 16) & 0xff\n", __VA_ARGS__); \
134 fprintf((f), "\t.byte\t((" fmt ") >> 8) & 0xff\n", __VA_ARGS__); \
135 fprintf((f), "\t.byte\t(" fmt ") & 0xff\n", __VA_ARGS__); \
136 }
137
130static void asm_emit_cell(void *e, cell_t val) 138static void asm_emit_cell(void *e, cell_t val)
131{ 139{
132 FILE *f = e; 140 FILE *f = e;
133 141
134 fprintf(f, "\t.long\t0x%x\n", val); 142 fprintf(f, "\t.byte 0x%02x; .byte 0x%02x; .byte 0x%02x; .byte 0x%02x\n",
143 (val >> 24) & 0xff, (val >> 16) & 0xff,
144 (val >> 8) & 0xff, val & 0xff);
135} 145}
136 146
137static void asm_emit_string(void *e, char *str, int len) 147static void asm_emit_string(void *e, char *str, int len)
@@ -156,7 +166,7 @@ static void asm_emit_align(void *e, int a)
156{ 166{
157 FILE *f = e; 167 FILE *f = e;
158 168
159 fprintf(f, "\t.balign\t%d\n", a); 169 fprintf(f, "\t.balign\t%d, 0\n", a);
160} 170}
161 171
162static void asm_emit_data(void *e, struct data d) 172static void asm_emit_data(void *e, struct data d)
@@ -169,8 +179,7 @@ static void asm_emit_data(void *e, struct data d)
169 emit_offset_label(f, m->ref, m->offset); 179 emit_offset_label(f, m->ref, m->offset);
170 180
171 while ((d.len - off) >= sizeof(uint32_t)) { 181 while ((d.len - off) >= sizeof(uint32_t)) {
172 fprintf(f, "\t.long\t0x%x\n", 182 asm_emit_cell(e, fdt32_to_cpu(*((uint32_t *)(d.val+off))));
173 fdt32_to_cpu(*((uint32_t *)(d.val+off))));
174 off += sizeof(uint32_t); 183 off += sizeof(uint32_t);
175 } 184 }
176 185
@@ -182,37 +191,43 @@ static void asm_emit_data(void *e, struct data d)
182 assert(off == d.len); 191 assert(off == d.len);
183} 192}
184 193
185static void asm_emit_beginnode(void *e, const char *label) 194static void asm_emit_beginnode(void *e, struct label *labels)
186{ 195{
187 FILE *f = e; 196 FILE *f = e;
197 struct label *l;
188 198
189 if (label) { 199 for_each_label(labels, l) {
190 fprintf(f, "\t.globl\t%s\n", label); 200 fprintf(f, "\t.globl\t%s\n", l->label);
191 fprintf(f, "%s:\n", label); 201 fprintf(f, "%s:\n", l->label);
192 } 202 }
193 fprintf(f, "\t.long\tFDT_BEGIN_NODE\n"); 203 fprintf(f, "\t/* FDT_BEGIN_NODE */\n");
204 asm_emit_cell(e, FDT_BEGIN_NODE);
194} 205}
195 206
196static void asm_emit_endnode(void *e, const char *label) 207static void asm_emit_endnode(void *e, struct label *labels)
197{ 208{
198 FILE *f = e; 209 FILE *f = e;
210 struct label *l;
199 211
200 fprintf(f, "\t.long\tFDT_END_NODE\n"); 212 fprintf(f, "\t/* FDT_END_NODE */\n");
201 if (label) { 213 asm_emit_cell(e, FDT_END_NODE);
202 fprintf(f, "\t.globl\t%s_end\n", label); 214 for_each_label(labels, l) {
203 fprintf(f, "%s_end:\n", label); 215 fprintf(f, "\t.globl\t%s_end\n", l->label);
216 fprintf(f, "%s_end:\n", l->label);
204 } 217 }
205} 218}
206 219
207static void asm_emit_property(void *e, const char *label) 220static void asm_emit_property(void *e, struct label *labels)
208{ 221{
209 FILE *f = e; 222 FILE *f = e;
223 struct label *l;
210 224
211 if (label) { 225 for_each_label(labels, l) {
212 fprintf(f, "\t.globl\t%s\n", label); 226 fprintf(f, "\t.globl\t%s\n", l->label);
213 fprintf(f, "%s:\n", label); 227 fprintf(f, "%s:\n", l->label);
214 } 228 }
215 fprintf(f, "\t.long\tFDT_PROP\n"); 229 fprintf(f, "\t/* FDT_PROP */\n");
230 asm_emit_cell(e, FDT_PROP);
216} 231}
217 232
218static struct emitter asm_emitter = { 233static struct emitter asm_emitter = {
@@ -248,7 +263,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
248 struct node *child; 263 struct node *child;
249 int seen_name_prop = 0; 264 int seen_name_prop = 0;
250 265
251 emit->beginnode(etarget, tree->label); 266 emit->beginnode(etarget, tree->labels);
252 267
253 if (vi->flags & FTF_FULLPATH) 268 if (vi->flags & FTF_FULLPATH)
254 emit->string(etarget, tree->fullpath, 0); 269 emit->string(etarget, tree->fullpath, 0);
@@ -265,7 +280,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
265 280
266 nameoff = stringtable_insert(strbuf, prop->name); 281 nameoff = stringtable_insert(strbuf, prop->name);
267 282
268 emit->property(etarget, prop->label); 283 emit->property(etarget, prop->labels);
269 emit->cell(etarget, prop->val.len); 284 emit->cell(etarget, prop->val.len);
270 emit->cell(etarget, nameoff); 285 emit->cell(etarget, nameoff);
271 286
@@ -292,7 +307,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
292 flatten_tree(child, emit, etarget, strbuf, vi); 307 flatten_tree(child, emit, etarget, strbuf, vi);
293 } 308 }
294 309
295 emit->endnode(etarget, tree->label); 310 emit->endnode(etarget, tree->labels);
296} 311}
297 312
298static struct data flatten_reserve_list(struct reserve_info *reservelist, 313static struct data flatten_reserve_list(struct reserve_info *reservelist,
@@ -413,10 +428,13 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version)
413 if (padlen > 0) 428 if (padlen > 0)
414 blob = data_append_zeroes(blob, padlen); 429 blob = data_append_zeroes(blob, padlen);
415 430
416 fwrite(blob.val, blob.len, 1, f); 431 if (fwrite(blob.val, blob.len, 1, f) != 1) {
417 432 if (ferror(f))
418 if (ferror(f)) 433 die("Error writing device tree blob: %s\n",
419 die("Error writing device tree blob: %s\n", strerror(errno)); 434 strerror(errno));
435 else
436 die("Short write on device tree blob\n");
437 }
420 438
421 /* 439 /*
422 * data_merge() frees the right-hand element so only the blob 440 * data_merge() frees the right-hand element so only the blob
@@ -455,39 +473,44 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version)
455 die("Unknown device tree blob version %d\n", version); 473 die("Unknown device tree blob version %d\n", version);
456 474
457 fprintf(f, "/* autogenerated by dtc, do not edit */\n\n"); 475 fprintf(f, "/* autogenerated by dtc, do not edit */\n\n");
458 fprintf(f, "#define FDT_MAGIC 0x%x\n", FDT_MAGIC);
459 fprintf(f, "#define FDT_BEGIN_NODE 0x%x\n", FDT_BEGIN_NODE);
460 fprintf(f, "#define FDT_END_NODE 0x%x\n", FDT_END_NODE);
461 fprintf(f, "#define FDT_PROP 0x%x\n", FDT_PROP);
462 fprintf(f, "#define FDT_END 0x%x\n", FDT_END);
463 fprintf(f, "\n");
464 476
465 emit_label(f, symprefix, "blob_start"); 477 emit_label(f, symprefix, "blob_start");
466 emit_label(f, symprefix, "header"); 478 emit_label(f, symprefix, "header");
467 fprintf(f, "\t.long\tFDT_MAGIC\t\t\t\t/* magic */\n"); 479 fprintf(f, "\t/* magic */\n");
468 fprintf(f, "\t.long\t_%s_blob_abs_end - _%s_blob_start\t/* totalsize */\n", 480 asm_emit_cell(f, FDT_MAGIC);
469 symprefix, symprefix); 481 fprintf(f, "\t/* totalsize */\n");
470 fprintf(f, "\t.long\t_%s_struct_start - _%s_blob_start\t/* off_dt_struct */\n", 482 ASM_EMIT_BELONG(f, "_%s_blob_abs_end - _%s_blob_start",
483 symprefix, symprefix);
484 fprintf(f, "\t/* off_dt_struct */\n");
485 ASM_EMIT_BELONG(f, "_%s_struct_start - _%s_blob_start",
471 symprefix, symprefix); 486 symprefix, symprefix);
472 fprintf(f, "\t.long\t_%s_strings_start - _%s_blob_start\t/* off_dt_strings */\n", 487 fprintf(f, "\t/* off_dt_strings */\n");
488 ASM_EMIT_BELONG(f, "_%s_strings_start - _%s_blob_start",
473 symprefix, symprefix); 489 symprefix, symprefix);
474 fprintf(f, "\t.long\t_%s_reserve_map - _%s_blob_start\t/* off_dt_strings */\n", 490 fprintf(f, "\t/* off_mem_rsvmap */\n");
491 ASM_EMIT_BELONG(f, "_%s_reserve_map - _%s_blob_start",
475 symprefix, symprefix); 492 symprefix, symprefix);
476 fprintf(f, "\t.long\t%d\t\t\t\t\t/* version */\n", vi->version); 493 fprintf(f, "\t/* version */\n");
477 fprintf(f, "\t.long\t%d\t\t\t\t\t/* last_comp_version */\n", 494 asm_emit_cell(f, vi->version);
478 vi->last_comp_version); 495 fprintf(f, "\t/* last_comp_version */\n");
479 496 asm_emit_cell(f, vi->last_comp_version);
480 if (vi->flags & FTF_BOOTCPUID) 497
481 fprintf(f, "\t.long\t%i\t\t\t\t\t/* boot_cpuid_phys */\n", 498 if (vi->flags & FTF_BOOTCPUID) {
482 bi->boot_cpuid_phys); 499 fprintf(f, "\t/* boot_cpuid_phys */\n");
500 asm_emit_cell(f, bi->boot_cpuid_phys);
501 }
483 502
484 if (vi->flags & FTF_STRTABSIZE) 503 if (vi->flags & FTF_STRTABSIZE) {
485 fprintf(f, "\t.long\t_%s_strings_end - _%s_strings_start\t/* size_dt_strings */\n", 504 fprintf(f, "\t/* size_dt_strings */\n");
486 symprefix, symprefix); 505 ASM_EMIT_BELONG(f, "_%s_strings_end - _%s_strings_start",
506 symprefix, symprefix);
507 }
487 508
488 if (vi->flags & FTF_STRUCTSIZE) 509 if (vi->flags & FTF_STRUCTSIZE) {
489 fprintf(f, "\t.long\t_%s_struct_end - _%s_struct_start\t/* size_dt_struct */\n", 510 fprintf(f, "\t/* size_dt_struct */\n");
511 ASM_EMIT_BELONG(f, "_%s_struct_end - _%s_struct_start",
490 symprefix, symprefix); 512 symprefix, symprefix);
513 }
491 514
492 /* 515 /*
493 * Reserve map entries. 516 * Reserve map entries.
@@ -505,16 +528,17 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version)
505 * as it appears .quad isn't available in some assemblers. 528 * as it appears .quad isn't available in some assemblers.
506 */ 529 */
507 for (re = bi->reservelist; re; re = re->next) { 530 for (re = bi->reservelist; re; re = re->next) {
508 if (re->label) { 531 struct label *l;
509 fprintf(f, "\t.globl\t%s\n", re->label); 532
510 fprintf(f, "%s:\n", re->label); 533 for_each_label(re->labels, l) {
534 fprintf(f, "\t.globl\t%s\n", l->label);
535 fprintf(f, "%s:\n", l->label);
511 } 536 }
512 fprintf(f, "\t.long\t0x%08x, 0x%08x\n", 537 ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.address >> 32));
513 (unsigned int)(re->re.address >> 32), 538 ASM_EMIT_BELONG(f, "0x%08x",
514 (unsigned int)(re->re.address & 0xffffffff)); 539 (unsigned int)(re->re.address & 0xffffffff));
515 fprintf(f, "\t.long\t0x%08x, 0x%08x\n", 540 ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.size >> 32));
516 (unsigned int)(re->re.size >> 32), 541 ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.size & 0xffffffff));
517 (unsigned int)(re->re.size & 0xffffffff));
518 } 542 }
519 for (i = 0; i < reservenum; i++) { 543 for (i = 0; i < reservenum; i++) {
520 fprintf(f, "\t.long\t0, 0\n\t.long\t0, 0\n"); 544 fprintf(f, "\t.long\t0, 0\n\t.long\t0, 0\n");
@@ -524,7 +548,9 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version)
524 548
525 emit_label(f, symprefix, "struct_start"); 549 emit_label(f, symprefix, "struct_start");
526 flatten_tree(bi->dt, &asm_emitter, f, &strbuf, vi); 550 flatten_tree(bi->dt, &asm_emitter, f, &strbuf, vi);
527 fprintf(f, "\t.long\tFDT_END\n"); 551
552 fprintf(f, "\t/* FDT_END */\n");
553 asm_emit_cell(f, FDT_END);
528 emit_label(f, symprefix, "struct_end"); 554 emit_label(f, symprefix, "struct_end");
529 555
530 emit_label(f, symprefix, "strings_start"); 556 emit_label(f, symprefix, "strings_start");
@@ -601,7 +627,7 @@ static char *flat_read_string(struct inbuf *inb)
601 len++; 627 len++;
602 } while ((*p++) != '\0'); 628 } while ((*p++) != '\0');
603 629
604 str = strdup(inb->ptr); 630 str = xstrdup(inb->ptr);
605 631
606 inb->ptr += len; 632 inb->ptr += len;
607 633
@@ -643,7 +669,7 @@ static char *flat_read_stringtable(struct inbuf *inb, int offset)
643 p++; 669 p++;
644 } 670 }
645 671
646 return strdup(inb->base + offset); 672 return xstrdup(inb->base + offset);
647} 673}
648 674
649static struct property *flat_read_property(struct inbuf *dtbuf, 675static struct property *flat_read_property(struct inbuf *dtbuf,
@@ -663,7 +689,7 @@ static struct property *flat_read_property(struct inbuf *dtbuf,
663 689
664 val = flat_read_data(dtbuf, proplen); 690 val = flat_read_data(dtbuf, proplen);
665 691
666 return build_property(name, val, NULL); 692 return build_property(name, val);
667} 693}
668 694
669 695
@@ -688,7 +714,7 @@ static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)
688 if (re.size == 0) 714 if (re.size == 0)
689 break; 715 break;
690 716
691 new = build_reserve_entry(re.address, re.size, NULL); 717 new = build_reserve_entry(re.address, re.size);
692 reservelist = add_reserve_entry(reservelist, new); 718 reservelist = add_reserve_entry(reservelist, new);
693 } 719 }
694 720
@@ -710,7 +736,7 @@ static char *nodename_from_path(const char *ppath, const char *cpath)
710 if (!streq(ppath, "/")) 736 if (!streq(ppath, "/"))
711 plen++; 737 plen++;
712 738
713 return strdup(cpath + plen); 739 return xstrdup(cpath + plen);
714} 740}
715 741
716static struct node *unflatten_tree(struct inbuf *dtbuf, 742static struct node *unflatten_tree(struct inbuf *dtbuf,
@@ -776,7 +802,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
776 802
777struct boot_info *dt_from_blob(const char *fname) 803struct boot_info *dt_from_blob(const char *fname)
778{ 804{
779 struct dtc_file *dtcf; 805 FILE *f;
780 uint32_t magic, totalsize, version, size_dt, boot_cpuid_phys; 806 uint32_t magic, totalsize, version, size_dt, boot_cpuid_phys;
781 uint32_t off_dt, off_str, off_mem_rsvmap; 807 uint32_t off_dt, off_str, off_mem_rsvmap;
782 int rc; 808 int rc;
@@ -791,14 +817,14 @@ struct boot_info *dt_from_blob(const char *fname)
791 uint32_t val; 817 uint32_t val;
792 int flags = 0; 818 int flags = 0;
793 819
794 dtcf = dtc_open_file(fname, NULL); 820 f = srcfile_relative_open(fname, NULL);
795 821
796 rc = fread(&magic, sizeof(magic), 1, dtcf->file); 822 rc = fread(&magic, sizeof(magic), 1, f);
797 if (ferror(dtcf->file)) 823 if (ferror(f))
798 die("Error reading DT blob magic number: %s\n", 824 die("Error reading DT blob magic number: %s\n",
799 strerror(errno)); 825 strerror(errno));
800 if (rc < 1) { 826 if (rc < 1) {
801 if (feof(dtcf->file)) 827 if (feof(f))
802 die("EOF reading DT blob magic number\n"); 828 die("EOF reading DT blob magic number\n");
803 else 829 else
804 die("Mysterious short read reading magic number\n"); 830 die("Mysterious short read reading magic number\n");
@@ -808,11 +834,11 @@ struct boot_info *dt_from_blob(const char *fname)
808 if (magic != FDT_MAGIC) 834 if (magic != FDT_MAGIC)
809 die("Blob has incorrect magic number\n"); 835 die("Blob has incorrect magic number\n");
810 836
811 rc = fread(&totalsize, sizeof(totalsize), 1, dtcf->file); 837 rc = fread(&totalsize, sizeof(totalsize), 1, f);
812 if (ferror(dtcf->file)) 838 if (ferror(f))
813 die("Error reading DT blob size: %s\n", strerror(errno)); 839 die("Error reading DT blob size: %s\n", strerror(errno));
814 if (rc < 1) { 840 if (rc < 1) {
815 if (feof(dtcf->file)) 841 if (feof(f))
816 die("EOF reading DT blob size\n"); 842 die("EOF reading DT blob size\n");
817 else 843 else
818 die("Mysterious short read reading blob size\n"); 844 die("Mysterious short read reading blob size\n");
@@ -832,12 +858,12 @@ struct boot_info *dt_from_blob(const char *fname)
832 p = blob + sizeof(magic) + sizeof(totalsize); 858 p = blob + sizeof(magic) + sizeof(totalsize);
833 859
834 while (sizeleft) { 860 while (sizeleft) {
835 if (feof(dtcf->file)) 861 if (feof(f))
836 die("EOF before reading %d bytes of DT blob\n", 862 die("EOF before reading %d bytes of DT blob\n",
837 totalsize); 863 totalsize);
838 864
839 rc = fread(p, 1, sizeleft, dtcf->file); 865 rc = fread(p, 1, sizeleft, f);
840 if (ferror(dtcf->file)) 866 if (ferror(f))
841 die("Error reading DT blob: %s\n", 867 die("Error reading DT blob: %s\n",
842 strerror(errno)); 868 strerror(errno));
843 869
@@ -900,7 +926,7 @@ struct boot_info *dt_from_blob(const char *fname)
900 926
901 free(blob); 927 free(blob);
902 928
903 dtc_close_file(dtcf); 929 fclose(f);
904 930
905 return build_boot_info(reservelist, tree, boot_cpuid_phys); 931 return build_boot_info(reservelist, tree, boot_cpuid_phys);
906} 932}
diff --git a/scripts/dtc/fstree.c b/scripts/dtc/fstree.c
index 8fe1bdf239f0..f3774530170a 100644
--- a/scripts/dtc/fstree.c
+++ b/scripts/dtc/fstree.c
@@ -58,10 +58,9 @@ static struct node *read_fstree(const char *dirname)
58 "WARNING: Cannot open %s: %s\n", 58 "WARNING: Cannot open %s: %s\n",
59 tmpnam, strerror(errno)); 59 tmpnam, strerror(errno));
60 } else { 60 } else {
61 prop = build_property(strdup(de->d_name), 61 prop = build_property(xstrdup(de->d_name),
62 data_copy_file(pfile, 62 data_copy_file(pfile,
63 st.st_size), 63 st.st_size));
64 NULL);
65 add_property(tree, prop); 64 add_property(tree, prop);
66 fclose(pfile); 65 fclose(pfile);
67 } 66 }
@@ -69,8 +68,7 @@ static struct node *read_fstree(const char *dirname)
69 struct node *newchild; 68 struct node *newchild;
70 69
71 newchild = read_fstree(tmpnam); 70 newchild = read_fstree(tmpnam);
72 newchild = name_node(newchild, strdup(de->d_name), 71 newchild = name_node(newchild, xstrdup(de->d_name));
73 NULL);
74 add_child(tree, newchild); 72 add_child(tree, newchild);
75 } 73 }
76 74
@@ -86,8 +84,8 @@ struct boot_info *dt_from_fs(const char *dirname)
86 struct node *tree; 84 struct node *tree;
87 85
88 tree = read_fstree(dirname); 86 tree = read_fstree(dirname);
89 tree = name_node(tree, "", NULL); 87 tree = name_node(tree, "");
90 88
91 return build_boot_info(NULL, tree, 0); 89 return build_boot_info(NULL, tree, guess_boot_cpuid(tree));
92} 90}
93 91
diff --git a/scripts/dtc/livetree.c b/scripts/dtc/livetree.c
index 0ca3de550b3f..c9209d5c999e 100644
--- a/scripts/dtc/livetree.c
+++ b/scripts/dtc/livetree.c
@@ -24,17 +24,30 @@
24 * Tree building functions 24 * Tree building functions
25 */ 25 */
26 26
27struct property *build_property(char *name, struct data val, char *label) 27void add_label(struct label **labels, char *label)
28{
29 struct label *new;
30
31 /* Make sure the label isn't already there */
32 for_each_label(*labels, new)
33 if (streq(new->label, label))
34 return;
35
36 new = xmalloc(sizeof(*new));
37 new->label = label;
38 new->next = *labels;
39 *labels = new;
40}
41
42struct property *build_property(char *name, struct data val)
28{ 43{
29 struct property *new = xmalloc(sizeof(*new)); 44 struct property *new = xmalloc(sizeof(*new));
30 45
46 memset(new, 0, sizeof(*new));
47
31 new->name = name; 48 new->name = name;
32 new->val = val; 49 new->val = val;
33 50
34 new->next = NULL;
35
36 new->label = label;
37
38 return new; 51 return new;
39} 52}
40 53
@@ -78,17 +91,82 @@ struct node *build_node(struct property *proplist, struct node *children)
78 return new; 91 return new;
79} 92}
80 93
81struct node *name_node(struct node *node, char *name, char * label) 94struct node *name_node(struct node *node, char *name)
82{ 95{
83 assert(node->name == NULL); 96 assert(node->name == NULL);
84 97
85 node->name = name; 98 node->name = name;
86 99
87 node->label = label;
88
89 return node; 100 return node;
90} 101}
91 102
103struct node *merge_nodes(struct node *old_node, struct node *new_node)
104{
105 struct property *new_prop, *old_prop;
106 struct node *new_child, *old_child;
107 struct label *l;
108
109 /* Add new node labels to old node */
110 for_each_label(new_node->labels, l)
111 add_label(&old_node->labels, l->label);
112
113 /* Move properties from the new node to the old node. If there
114 * is a collision, replace the old value with the new */
115 while (new_node->proplist) {
116 /* Pop the property off the list */
117 new_prop = new_node->proplist;
118 new_node->proplist = new_prop->next;
119 new_prop->next = NULL;
120
121 /* Look for a collision, set new value if there is */
122 for_each_property(old_node, old_prop) {
123 if (streq(old_prop->name, new_prop->name)) {
124 /* Add new labels to old property */
125 for_each_label(new_prop->labels, l)
126 add_label(&old_prop->labels, l->label);
127
128 old_prop->val = new_prop->val;
129 free(new_prop);
130 new_prop = NULL;
131 break;
132 }
133 }
134
135 /* if no collision occurred, add property to the old node. */
136 if (new_prop)
137 add_property(old_node, new_prop);
138 }
139
140 /* Move the override child nodes into the primary node. If
141 * there is a collision, then merge the nodes. */
142 while (new_node->children) {
143 /* Pop the child node off the list */
144 new_child = new_node->children;
145 new_node->children = new_child->next_sibling;
146 new_child->parent = NULL;
147 new_child->next_sibling = NULL;
148
149 /* Search for a collision. Merge if there is */
150 for_each_child(old_node, old_child) {
151 if (streq(old_child->name, new_child->name)) {
152 merge_nodes(old_child, new_child);
153 new_child = NULL;
154 break;
155 }
156 }
157
158 /* if no collision occured, add child to the old node. */
159 if (new_child)
160 add_child(old_node, new_child);
161 }
162
163 /* The new node contents are now merged into the old node. Free
164 * the new node. */
165 free(new_node);
166
167 return old_node;
168}
169
92struct node *chain_node(struct node *first, struct node *list) 170struct node *chain_node(struct node *first, struct node *list)
93{ 171{
94 assert(first->next_sibling == NULL); 172 assert(first->next_sibling == NULL);
@@ -124,18 +202,15 @@ void add_child(struct node *parent, struct node *child)
124 *p = child; 202 *p = child;
125} 203}
126 204
127struct reserve_info *build_reserve_entry(uint64_t address, uint64_t size, 205struct reserve_info *build_reserve_entry(uint64_t address, uint64_t size)
128 char *label)
129{ 206{
130 struct reserve_info *new = xmalloc(sizeof(*new)); 207 struct reserve_info *new = xmalloc(sizeof(*new));
131 208
209 memset(new, 0, sizeof(*new));
210
132 new->re.address = address; 211 new->re.address = address;
133 new->re.size = size; 212 new->re.size = size;
134 213
135 new->next = NULL;
136
137 new->label = label;
138
139 return new; 214 return new;
140} 215}
141 216
@@ -208,6 +283,60 @@ cell_t propval_cell(struct property *prop)
208 return fdt32_to_cpu(*((cell_t *)prop->val.val)); 283 return fdt32_to_cpu(*((cell_t *)prop->val.val));
209} 284}
210 285
286struct property *get_property_by_label(struct node *tree, const char *label,
287 struct node **node)
288{
289 struct property *prop;
290 struct node *c;
291
292 *node = tree;
293
294 for_each_property(tree, prop) {
295 struct label *l;
296
297 for_each_label(prop->labels, l)
298 if (streq(l->label, label))
299 return prop;
300 }
301
302 for_each_child(tree, c) {
303 prop = get_property_by_label(c, label, node);
304 if (prop)
305 return prop;
306 }
307
308 *node = NULL;
309 return NULL;
310}
311
312struct marker *get_marker_label(struct node *tree, const char *label,
313 struct node **node, struct property **prop)
314{
315 struct marker *m;
316 struct property *p;
317 struct node *c;
318
319 *node = tree;
320
321 for_each_property(tree, p) {
322 *prop = p;
323 m = p->val.markers;
324 for_each_marker_of_type(m, LABEL)
325 if (streq(m->ref, label))
326 return m;
327 }
328
329 for_each_child(tree, c) {
330 m = get_marker_label(c, label, node, prop);
331 if (m)
332 return m;
333 }
334
335 *prop = NULL;
336 *node = NULL;
337 return NULL;
338}
339
211struct node *get_subnode(struct node *node, const char *nodename) 340struct node *get_subnode(struct node *node, const char *nodename)
212{ 341{
213 struct node *child; 342 struct node *child;
@@ -245,11 +374,13 @@ struct node *get_node_by_path(struct node *tree, const char *path)
245struct node *get_node_by_label(struct node *tree, const char *label) 374struct node *get_node_by_label(struct node *tree, const char *label)
246{ 375{
247 struct node *child, *node; 376 struct node *child, *node;
377 struct label *l;
248 378
249 assert(label && (strlen(label) > 0)); 379 assert(label && (strlen(label) > 0));
250 380
251 if (tree->label && streq(tree->label, label)) 381 for_each_label(tree->labels, l)
252 return tree; 382 if (streq(l->label, label))
383 return tree;
253 384
254 for_each_child(tree, child) { 385 for_each_child(tree, child) {
255 node = get_node_by_label(child, label); 386 node = get_node_by_label(child, label);
@@ -293,16 +424,186 @@ cell_t get_node_phandle(struct node *root, struct node *node)
293 if ((node->phandle != 0) && (node->phandle != -1)) 424 if ((node->phandle != 0) && (node->phandle != -1))
294 return node->phandle; 425 return node->phandle;
295 426
296 assert(! get_property(node, "linux,phandle"));
297
298 while (get_node_by_phandle(root, phandle)) 427 while (get_node_by_phandle(root, phandle))
299 phandle++; 428 phandle++;
300 429
301 node->phandle = phandle; 430 node->phandle = phandle;
302 add_property(node, 431
303 build_property("linux,phandle", 432 if (!get_property(node, "linux,phandle")
304 data_append_cell(empty_data, phandle), 433 && (phandle_format & PHANDLE_LEGACY))
305 NULL)); 434 add_property(node,
435 build_property("linux,phandle",
436 data_append_cell(empty_data, phandle)));
437
438 if (!get_property(node, "phandle")
439 && (phandle_format & PHANDLE_EPAPR))
440 add_property(node,
441 build_property("phandle",
442 data_append_cell(empty_data, phandle)));
443
444 /* If the node *does* have a phandle property, we must
445 * be dealing with a self-referencing phandle, which will be
446 * fixed up momentarily in the caller */
306 447
307 return node->phandle; 448 return node->phandle;
308} 449}
450
451uint32_t guess_boot_cpuid(struct node *tree)
452{
453 struct node *cpus, *bootcpu;
454 struct property *reg;
455
456 cpus = get_node_by_path(tree, "/cpus");
457 if (!cpus)
458 return 0;
459
460
461 bootcpu = cpus->children;
462 if (!bootcpu)
463 return 0;
464
465 reg = get_property(bootcpu, "reg");
466 if (!reg || (reg->val.len != sizeof(uint32_t)))
467 return 0;
468
469 /* FIXME: Sanity check node? */
470
471 return propval_cell(reg);
472}
473
474static int cmp_reserve_info(const void *ax, const void *bx)
475{
476 const struct reserve_info *a, *b;
477
478 a = *((const struct reserve_info * const *)ax);
479 b = *((const struct reserve_info * const *)bx);
480
481 if (a->re.address < b->re.address)
482 return -1;
483 else if (a->re.address > b->re.address)
484 return 1;
485 else if (a->re.size < b->re.size)
486 return -1;
487 else if (a->re.size > b->re.size)
488 return 1;
489 else
490 return 0;
491}
492
493static void sort_reserve_entries(struct boot_info *bi)
494{
495 struct reserve_info *ri, **tbl;
496 int n = 0, i = 0;
497
498 for (ri = bi->reservelist;
499 ri;
500 ri = ri->next)
501 n++;
502
503 if (n == 0)
504 return;
505
506 tbl = xmalloc(n * sizeof(*tbl));
507
508 for (ri = bi->reservelist;
509 ri;
510 ri = ri->next)
511 tbl[i++] = ri;
512
513 qsort(tbl, n, sizeof(*tbl), cmp_reserve_info);
514
515 bi->reservelist = tbl[0];
516 for (i = 0; i < (n-1); i++)
517 tbl[i]->next = tbl[i+1];
518 tbl[n-1]->next = NULL;
519
520 free(tbl);
521}
522
523static int cmp_prop(const void *ax, const void *bx)
524{
525 const struct property *a, *b;
526
527 a = *((const struct property * const *)ax);
528 b = *((const struct property * const *)bx);
529
530 return strcmp(a->name, b->name);
531}
532
533static void sort_properties(struct node *node)
534{
535 int n = 0, i = 0;
536 struct property *prop, **tbl;
537
538 for_each_property(node, prop)
539 n++;
540
541 if (n == 0)
542 return;
543
544 tbl = xmalloc(n * sizeof(*tbl));
545
546 for_each_property(node, prop)
547 tbl[i++] = prop;
548
549 qsort(tbl, n, sizeof(*tbl), cmp_prop);
550
551 node->proplist = tbl[0];
552 for (i = 0; i < (n-1); i++)
553 tbl[i]->next = tbl[i+1];
554 tbl[n-1]->next = NULL;
555
556 free(tbl);
557}
558
559static int cmp_subnode(const void *ax, const void *bx)
560{
561 const struct node *a, *b;
562
563 a = *((const struct node * const *)ax);
564 b = *((const struct node * const *)bx);
565
566 return strcmp(a->name, b->name);
567}
568
569static void sort_subnodes(struct node *node)
570{
571 int n = 0, i = 0;
572 struct node *subnode, **tbl;
573
574 for_each_child(node, subnode)
575 n++;
576
577 if (n == 0)
578 return;
579
580 tbl = xmalloc(n * sizeof(*tbl));
581
582 for_each_child(node, subnode)
583 tbl[i++] = subnode;
584
585 qsort(tbl, n, sizeof(*tbl), cmp_subnode);
586
587 node->children = tbl[0];
588 for (i = 0; i < (n-1); i++)
589 tbl[i]->next_sibling = tbl[i+1];
590 tbl[n-1]->next_sibling = NULL;
591
592 free(tbl);
593}
594
595static void sort_node(struct node *node)
596{
597 struct node *c;
598
599 sort_properties(node);
600 sort_subnodes(node);
601 for_each_child(node, c)
602 sort_node(c);
603}
604
605void sort_tree(struct boot_info *bi)
606{
607 sort_reserve_entries(bi);
608 sort_node(bi->dt);
609}
diff --git a/scripts/dtc/srcpos.c b/scripts/dtc/srcpos.c
index 9641b7628b4d..2dbc874288ca 100644
--- a/scripts/dtc/srcpos.c
+++ b/scripts/dtc/srcpos.c
@@ -17,100 +17,232 @@
17 * USA 17 * USA
18 */ 18 */
19 19
20#define _GNU_SOURCE
21
22#include <stdio.h>
23
20#include "dtc.h" 24#include "dtc.h"
21#include "srcpos.h" 25#include "srcpos.h"
22 26
23/*
24 * Like yylineno, this is the current open file pos.
25 */
26 27
27struct dtc_file *srcpos_file; 28static char *dirname(const char *path)
29{
30 const char *slash = strrchr(path, '/');
31
32 if (slash) {
33 int len = slash - path;
34 char *dir = xmalloc(len + 1);
35
36 memcpy(dir, path, len);
37 dir[len] = '\0';
38 return dir;
39 }
40 return NULL;
41}
42
43struct srcfile_state *current_srcfile; /* = NULL */
28 44
29static int dtc_open_one(struct dtc_file *file, 45/* Detect infinite include recursion. */
30 const char *search, 46#define MAX_SRCFILE_DEPTH (100)
31 const char *fname) 47static int srcfile_depth; /* = 0 */
48
49FILE *srcfile_relative_open(const char *fname, char **fullnamep)
32{ 50{
51 FILE *f;
33 char *fullname; 52 char *fullname;
34 53
35 if (search) { 54 if (streq(fname, "-")) {
36 fullname = xmalloc(strlen(search) + strlen(fname) + 2); 55 f = stdin;
37 56 fullname = xstrdup("<stdin>");
38 strcpy(fullname, search);
39 strcat(fullname, "/");
40 strcat(fullname, fname);
41 } else { 57 } else {
42 fullname = strdup(fname); 58 if (!current_srcfile || !current_srcfile->dir
59 || (fname[0] == '/'))
60 fullname = xstrdup(fname);
61 else
62 fullname = join_path(current_srcfile->dir, fname);
63
64 f = fopen(fullname, "r");
65 if (!f)
66 die("Couldn't open \"%s\": %s\n", fname,
67 strerror(errno));
43 } 68 }
44 69
45 file->file = fopen(fullname, "r"); 70 if (fullnamep)
46 if (!file->file) { 71 *fullnamep = fullname;
72 else
47 free(fullname); 73 free(fullname);
48 return 0;
49 }
50 74
51 file->name = fullname; 75 return f;
52 return 1;
53} 76}
54 77
78void srcfile_push(const char *fname)
79{
80 struct srcfile_state *srcfile;
81
82 if (srcfile_depth++ >= MAX_SRCFILE_DEPTH)
83 die("Includes nested too deeply");
84
85 srcfile = xmalloc(sizeof(*srcfile));
86
87 srcfile->f = srcfile_relative_open(fname, &srcfile->name);
88 srcfile->dir = dirname(srcfile->name);
89 srcfile->prev = current_srcfile;
90
91 srcfile->lineno = 1;
92 srcfile->colno = 1;
93
94 current_srcfile = srcfile;
95}
55 96
56struct dtc_file *dtc_open_file(const char *fname, 97int srcfile_pop(void)
57 const struct search_path *search)
58{ 98{
59 static const struct search_path default_search = { NULL, NULL, NULL }; 99 struct srcfile_state *srcfile = current_srcfile;
60 100
61 struct dtc_file *file; 101 assert(srcfile);
62 const char *slash;
63 102
64 file = xmalloc(sizeof(struct dtc_file)); 103 current_srcfile = srcfile->prev;
65 104
66 slash = strrchr(fname, '/'); 105 if (fclose(srcfile->f))
67 if (slash) { 106 die("Error closing \"%s\": %s\n", srcfile->name,
68 char *dir = xmalloc(slash - fname + 1); 107 strerror(errno));
69 108
70 memcpy(dir, fname, slash - fname); 109 /* FIXME: We allow the srcfile_state structure to leak,
71 dir[slash - fname] = 0; 110 * because it could still be referenced from a location
72 file->dir = dir; 111 * variable being carried through the parser somewhere. To
73 } else { 112 * fix this we could either allocate all the files from a
74 file->dir = NULL; 113 * table, or use a pool allocator. */
75 }
76 114
77 if (streq(fname, "-")) { 115 return current_srcfile ? 1 : 0;
78 file->name = "stdin"; 116}
79 file->file = stdin;
80 return file;
81 }
82 117
83 if (fname[0] == '/') { 118/*
84 file->file = fopen(fname, "r"); 119 * The empty source position.
85 if (!file->file) 120 */
86 goto fail;
87 121
88 file->name = strdup(fname); 122struct srcpos srcpos_empty = {
89 return file; 123 .first_line = 0,
90 } 124 .first_column = 0,
125 .last_line = 0,
126 .last_column = 0,
127 .file = NULL,
128};
91 129
92 if (!search) 130#define TAB_SIZE 8
93 search = &default_search;
94 131
95 while (search) { 132void srcpos_update(struct srcpos *pos, const char *text, int len)
96 if (dtc_open_one(file, search->dir, fname)) 133{
97 return file; 134 int i;
135
136 pos->file = current_srcfile;
137
138 pos->first_line = current_srcfile->lineno;
139 pos->first_column = current_srcfile->colno;
140
141 for (i = 0; i < len; i++)
142 if (text[i] == '\n') {
143 current_srcfile->lineno++;
144 current_srcfile->colno = 1;
145 } else if (text[i] == '\t') {
146 current_srcfile->colno =
147 ALIGN(current_srcfile->colno, TAB_SIZE);
148 } else {
149 current_srcfile->colno++;
150 }
151
152 pos->last_line = current_srcfile->lineno;
153 pos->last_column = current_srcfile->colno;
154}
98 155
99 if (errno != ENOENT) 156struct srcpos *
100 goto fail; 157srcpos_copy(struct srcpos *pos)
158{
159 struct srcpos *pos_new;
101 160
102 search = search->next; 161 pos_new = xmalloc(sizeof(struct srcpos));
103 } 162 memcpy(pos_new, pos, sizeof(struct srcpos));
163
164 return pos_new;
165}
166
167
168
169void
170srcpos_dump(struct srcpos *pos)
171{
172 printf("file : \"%s\"\n",
173 pos->file ? (char *) pos->file : "<no file>");
174 printf("first_line : %d\n", pos->first_line);
175 printf("first_column: %d\n", pos->first_column);
176 printf("last_line : %d\n", pos->last_line);
177 printf("last_column : %d\n", pos->last_column);
178 printf("file : %s\n", pos->file->name);
179}
104 180
105fail: 181
106 die("Couldn't open \"%s\": %s\n", fname, strerror(errno)); 182char *
183srcpos_string(struct srcpos *pos)
184{
185 const char *fname = "<no-file>";
186 char *pos_str;
187 int rc;
188
189 if (pos)
190 fname = pos->file->name;
191
192
193 if (pos->first_line != pos->last_line)
194 rc = asprintf(&pos_str, "%s:%d.%d-%d.%d", fname,
195 pos->first_line, pos->first_column,
196 pos->last_line, pos->last_column);
197 else if (pos->first_column != pos->last_column)
198 rc = asprintf(&pos_str, "%s:%d.%d-%d", fname,
199 pos->first_line, pos->first_column,
200 pos->last_column);
201 else
202 rc = asprintf(&pos_str, "%s:%d.%d", fname,
203 pos->first_line, pos->first_column);
204
205 if (rc == -1)
206 die("Couldn't allocate in srcpos string");
207
208 return pos_str;
209}
210
211void
212srcpos_verror(struct srcpos *pos, char const *fmt, va_list va)
213{
214 const char *srcstr;
215
216 srcstr = srcpos_string(pos);
217
218 fprintf(stdout, "Error: %s ", srcstr);
219 vfprintf(stdout, fmt, va);
220 fprintf(stdout, "\n");
107} 221}
108 222
109void dtc_close_file(struct dtc_file *file) 223void
224srcpos_error(struct srcpos *pos, char const *fmt, ...)
110{ 225{
111 if (fclose(file->file)) 226 va_list va;
112 die("Error closing \"%s\": %s\n", file->name, strerror(errno)); 227
228 va_start(va, fmt);
229 srcpos_verror(pos, fmt, va);
230 va_end(va);
231}
232
233
234void
235srcpos_warn(struct srcpos *pos, char const *fmt, ...)
236{
237 const char *srcstr;
238 va_list va;
239 va_start(va, fmt);
240
241 srcstr = srcpos_string(pos);
242
243 fprintf(stderr, "Warning: %s ", srcstr);
244 vfprintf(stderr, fmt, va);
245 fprintf(stderr, "\n");
113 246
114 free(file->dir); 247 va_end(va);
115 free(file);
116} 248}
diff --git a/scripts/dtc/srcpos.h b/scripts/dtc/srcpos.h
index e17c7c04db8e..bd7966e56a53 100644
--- a/scripts/dtc/srcpos.h
+++ b/scripts/dtc/srcpos.h
@@ -17,69 +17,70 @@
17 * USA 17 * USA
18 */ 18 */
19 19
20/* 20#ifndef _SRCPOS_H_
21 * Augment the standard YYLTYPE with a filenum index into an 21#define _SRCPOS_H_
22 * array of all opened filenames.
23 */
24 22
25#include <stdio.h> 23#include <stdio.h>
26 24
27struct dtc_file { 25struct srcfile_state {
26 FILE *f;
27 char *name;
28 char *dir; 28 char *dir;
29 const char *name; 29 int lineno, colno;
30 FILE *file; 30 struct srcfile_state *prev;
31}; 31};
32 32
33#if ! defined(YYLTYPE) && ! defined(YYLTYPE_IS_DECLARED) 33extern struct srcfile_state *current_srcfile; /* = NULL */
34typedef struct YYLTYPE { 34
35FILE *srcfile_relative_open(const char *fname, char **fullnamep);
36void srcfile_push(const char *fname);
37int srcfile_pop(void);
38
39struct srcpos {
35 int first_line; 40 int first_line;
36 int first_column; 41 int first_column;
37 int last_line; 42 int last_line;
38 int last_column; 43 int last_column;
39 struct dtc_file *file; 44 struct srcfile_state *file;
40} YYLTYPE; 45};
41
42#define YYLTYPE_IS_DECLARED 1
43#define YYLTYPE_IS_TRIVIAL 1
44#endif
45
46/* Cater to old parser templates. */
47#ifndef YYID
48#define YYID(n) (n)
49#endif
50 46
51#define YYLLOC_DEFAULT(Current, Rhs, N) \ 47#define YYLTYPE struct srcpos
52 do \
53 if (YYID (N)) \
54 { \
55 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
56 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
57 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
58 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
59 (Current).file = YYRHSLOC (Rhs, N).file; \
60 } \
61 else \
62 { \
63 (Current).first_line = (Current).last_line = \
64 YYRHSLOC (Rhs, 0).last_line; \
65 (Current).first_column = (Current).last_column = \
66 YYRHSLOC (Rhs, 0).last_column; \
67 (Current).file = YYRHSLOC (Rhs, 0).file; \
68 } \
69 while (YYID (0))
70 48
49#define YYLLOC_DEFAULT(Current, Rhs, N) \
50 do { \
51 if (N) { \
52 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
53 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
54 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
55 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
56 (Current).file = YYRHSLOC(Rhs, N).file; \
57 } else { \
58 (Current).first_line = (Current).last_line = \
59 YYRHSLOC(Rhs, 0).last_line; \
60 (Current).first_column = (Current).last_column = \
61 YYRHSLOC(Rhs, 0).last_column; \
62 (Current).file = YYRHSLOC (Rhs, 0).file; \
63 } \
64 } while (0)
71 65
72 66
73extern void yyerror(char const *); 67/*
74extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2))); 68 * Fictional source position used for IR nodes that are
69 * created without otherwise knowing a true source position.
70 * For example,constant definitions from the command line.
71 */
72extern struct srcpos srcpos_empty;
75 73
76extern struct dtc_file *srcpos_file; 74extern void srcpos_update(struct srcpos *pos, const char *text, int len);
75extern struct srcpos *srcpos_copy(struct srcpos *pos);
76extern char *srcpos_string(struct srcpos *pos);
77extern void srcpos_dump(struct srcpos *pos);
77 78
78struct search_path { 79extern void srcpos_verror(struct srcpos *pos, char const *, va_list va)
79 const char *dir; /* NULL for current directory */ 80 __attribute__((format(printf, 2, 0)));
80 struct search_path *prev, *next; 81extern void srcpos_error(struct srcpos *pos, char const *, ...)
81}; 82 __attribute__((format(printf, 2, 3)));
83extern void srcpos_warn(struct srcpos *pos, char const *, ...)
84 __attribute__((format(printf, 2, 3)));
82 85
83extern struct dtc_file *dtc_open_file(const char *fname, 86#endif /* _SRCPOS_H_ */
84 const struct search_path *search);
85extern void dtc_close_file(struct dtc_file *file);
diff --git a/scripts/dtc/treesource.c b/scripts/dtc/treesource.c
index 1521ff11bb97..c09aafade313 100644
--- a/scripts/dtc/treesource.c
+++ b/scripts/dtc/treesource.c
@@ -32,8 +32,8 @@ struct boot_info *dt_from_source(const char *fname)
32 the_boot_info = NULL; 32 the_boot_info = NULL;
33 treesource_error = 0; 33 treesource_error = 0;
34 34
35 srcpos_file = dtc_open_file(fname, NULL); 35 srcfile_push(fname);
36 yyin = srcpos_file->file; 36 yyin = current_srcfile->f;
37 37
38 if (yyparse() != 0) 38 if (yyparse() != 0)
39 die("Unable to parse input tree\n"); 39 die("Unable to parse input tree\n");
@@ -63,26 +63,20 @@ static void write_propval_string(FILE *f, struct data val)
63{ 63{
64 const char *str = val.val; 64 const char *str = val.val;
65 int i; 65 int i;
66 int newchunk = 1;
67 struct marker *m = val.markers; 66 struct marker *m = val.markers;
68 67
69 assert(str[val.len-1] == '\0'); 68 assert(str[val.len-1] == '\0');
70 69
70 while (m && (m->offset == 0)) {
71 if (m->type == LABEL)
72 fprintf(f, "%s: ", m->ref);
73 m = m->next;
74 }
75 fprintf(f, "\"");
76
71 for (i = 0; i < (val.len-1); i++) { 77 for (i = 0; i < (val.len-1); i++) {
72 char c = str[i]; 78 char c = str[i];
73 79
74 if (newchunk) {
75 while (m && (m->offset <= i)) {
76 if (m->type == LABEL) {
77 assert(m->offset == i);
78 fprintf(f, "%s: ", m->ref);
79 }
80 m = m->next;
81 }
82 fprintf(f, "\"");
83 newchunk = 0;
84 }
85
86 switch (c) { 80 switch (c) {
87 case '\a': 81 case '\a':
88 fprintf(f, "\\a"); 82 fprintf(f, "\\a");
@@ -113,7 +107,14 @@ static void write_propval_string(FILE *f, struct data val)
113 break; 107 break;
114 case '\0': 108 case '\0':
115 fprintf(f, "\", "); 109 fprintf(f, "\", ");
116 newchunk = 1; 110 while (m && (m->offset < i)) {
111 if (m->type == LABEL) {
112 assert(m->offset == (i+1));
113 fprintf(f, "%s: ", m->ref);
114 }
115 m = m->next;
116 }
117 fprintf(f, "\"");
117 break; 118 break;
118 default: 119 default:
119 if (isprint(c)) 120 if (isprint(c))
@@ -234,10 +235,11 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
234{ 235{
235 struct property *prop; 236 struct property *prop;
236 struct node *child; 237 struct node *child;
238 struct label *l;
237 239
238 write_prefix(f, level); 240 write_prefix(f, level);
239 if (tree->label) 241 for_each_label(tree->labels, l)
240 fprintf(f, "%s: ", tree->label); 242 fprintf(f, "%s: ", l->label);
241 if (tree->name && (*tree->name)) 243 if (tree->name && (*tree->name))
242 fprintf(f, "%s {\n", tree->name); 244 fprintf(f, "%s {\n", tree->name);
243 else 245 else
@@ -245,8 +247,8 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
245 247
246 for_each_property(tree, prop) { 248 for_each_property(tree, prop) {
247 write_prefix(f, level+1); 249 write_prefix(f, level+1);
248 if (prop->label) 250 for_each_label(prop->labels, l)
249 fprintf(f, "%s: ", prop->label); 251 fprintf(f, "%s: ", l->label);
250 fprintf(f, "%s", prop->name); 252 fprintf(f, "%s", prop->name);
251 write_propval(f, prop); 253 write_propval(f, prop);
252 } 254 }
@@ -266,8 +268,10 @@ void dt_to_source(FILE *f, struct boot_info *bi)
266 fprintf(f, "/dts-v1/;\n\n"); 268 fprintf(f, "/dts-v1/;\n\n");
267 269
268 for (re = bi->reservelist; re; re = re->next) { 270 for (re = bi->reservelist; re; re = re->next) {
269 if (re->label) 271 struct label *l;
270 fprintf(f, "%s: ", re->label); 272
273 for_each_label(re->labels, l)
274 fprintf(f, "%s: ", l->label);
271 fprintf(f, "/memreserve/\t0x%016llx 0x%016llx;\n", 275 fprintf(f, "/memreserve/\t0x%016llx 0x%016llx;\n",
272 (unsigned long long)re->re.address, 276 (unsigned long long)re->re.address,
273 (unsigned long long)re->re.size); 277 (unsigned long long)re->re.size);
diff --git a/scripts/dtc/util.c b/scripts/dtc/util.c
new file mode 100644
index 000000000000..d7ac27d2ae15
--- /dev/null
+++ b/scripts/dtc/util.c
@@ -0,0 +1,59 @@
1/*
2 * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 * USA
18 */
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <stdarg.h>
23#include <string.h>
24
25#include "util.h"
26
27char *xstrdup(const char *s)
28{
29 int len = strlen(s) + 1;
30 char *dup = xmalloc(len);
31
32 memcpy(dup, s, len);
33
34 return dup;
35}
36
37char *join_path(const char *path, const char *name)
38{
39 int lenp = strlen(path);
40 int lenn = strlen(name);
41 int len;
42 int needslash = 1;
43 char *str;
44
45 len = lenp + lenn + 2;
46 if ((lenp > 0) && (path[lenp-1] == '/')) {
47 needslash = 0;
48 len--;
49 }
50
51 str = xmalloc(len);
52 memcpy(str, path, lenp);
53 if (needslash) {
54 str[lenp] = '/';
55 lenp++;
56 }
57 memcpy(str+lenp, name, lenn+1);
58 return str;
59}
diff --git a/scripts/dtc/util.h b/scripts/dtc/util.h
new file mode 100644
index 000000000000..9cead842c11e
--- /dev/null
+++ b/scripts/dtc/util.h
@@ -0,0 +1,56 @@
1#ifndef _UTIL_H
2#define _UTIL_H
3
4/*
5 * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 */
22
23static inline void __attribute__((noreturn)) die(char * str, ...)
24{
25 va_list ap;
26
27 va_start(ap, str);
28 fprintf(stderr, "FATAL ERROR: ");
29 vfprintf(stderr, str, ap);
30 exit(1);
31}
32
33static inline void *xmalloc(size_t len)
34{
35 void *new = malloc(len);
36
37 if (!new)
38 die("malloc() failed\n");
39
40 return new;
41}
42
43static inline void *xrealloc(void *p, size_t len)
44{
45 void *new = realloc(p, len);
46
47 if (!new)
48 die("realloc() failed (len=%d)\n", len);
49
50 return new;
51}
52
53extern char *xstrdup(const char *s);
54extern char *join_path(const char *path, const char *name);
55
56#endif /* _UTIL_H */
diff --git a/scripts/dtc/version_gen.h b/scripts/dtc/version_gen.h
index 658ff42429d6..6158b867df99 100644
--- a/scripts/dtc/version_gen.h
+++ b/scripts/dtc/version_gen.h
@@ -1 +1 @@
#define DTC_VERSION "DTC 1.2.0" #define DTC_VERSION "DTC 1.2.0-g37c0b6a0"
diff --git a/scripts/genksyms/parse.c_shipped b/scripts/genksyms/parse.c_shipped
index eaee44e66a43..809b949e495b 100644
--- a/scripts/genksyms/parse.c_shipped
+++ b/scripts/genksyms/parse.c_shipped
@@ -160,7 +160,7 @@
160 160
161 161
162#include <assert.h> 162#include <assert.h>
163#include <malloc.h> 163#include <stdlib.h>
164#include "genksyms.h" 164#include "genksyms.h"
165 165
166static int is_typedef; 166static int is_typedef;
diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y
index 10d7dc724b6d..09a265cd7193 100644
--- a/scripts/genksyms/parse.y
+++ b/scripts/genksyms/parse.y
@@ -24,7 +24,7 @@
24%{ 24%{
25 25
26#include <assert.h> 26#include <assert.h>
27#include <malloc.h> 27#include <stdlib.h>
28#include "genksyms.h" 28#include "genksyms.h"
29 29
30static int is_typedef; 30static int is_typedef;
diff --git a/scripts/headers.sh b/scripts/headers.sh
index 1ddcdd38d97f..978b42b3acd7 100755
--- a/scripts/headers.sh
+++ b/scripts/headers.sh
@@ -13,7 +13,7 @@ do_command()
13 fi 13 fi
14} 14}
15 15
16archs=$(ls ${srctree}/arch) 16archs=${HDR_ARCH_LIST:-$(ls ${srctree}/arch)}
17 17
18for arch in ${archs}; do 18for arch in ${archs}; do
19 case ${arch} in 19 case ${arch} in
diff --git a/scripts/headers_check.pl b/scripts/headers_check.pl
index 50d6cfd1fa77..7957e7a5166a 100644
--- a/scripts/headers_check.pl
+++ b/scripts/headers_check.pl
@@ -64,10 +64,10 @@ sub check_include
64 64
65sub check_declarations 65sub check_declarations
66{ 66{
67 if ($line =~m/^\s*extern\b/) { 67 if ($line =~m/^(\s*extern|unsigned|char|short|int|long|void)\b/) {
68 printf STDERR "$filename:$lineno: " . 68 printf STDERR "$filename:$lineno: " .
69 "userspace cannot call function or variable " . 69 "userspace cannot reference function or " .
70 "defined in the kernel\n"; 70 "variable defined in the kernel\n";
71 } 71 }
72} 72}
73 73
diff --git a/scripts/headers_install.pl b/scripts/headers_install.pl
index 4ca3be3b2e50..efb3be10d428 100644
--- a/scripts/headers_install.pl
+++ b/scripts/headers_install.pl
@@ -45,6 +45,13 @@ foreach my $file (@files) {
45 close $in; 45 close $in;
46 46
47 system $unifdef . " $tmpfile > $installdir/$file"; 47 system $unifdef . " $tmpfile > $installdir/$file";
48 # unifdef will exit 0 on success, and will exit 1 when the
49 # file was processed successfully but no changes were made,
50 # so abort only when it's higher than that.
51 my $e = $? >> 8;
52 if ($e > 1) {
53 die "$tmpfile: $!\n";
54 }
48 unlink $tmpfile; 55 unlink $tmpfile;
49} 56}
50exit 0; 57exit 0;
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 5459a38be866..659326c3e895 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -529,8 +529,6 @@ int main(int ac, char **av)
529 } 529 }
530 break; 530 break;
531 case savedefconfig: 531 case savedefconfig:
532 conf_read(NULL);
533 break;
534 case silentoldconfig: 532 case silentoldconfig:
535 case oldaskconfig: 533 case oldaskconfig:
536 case oldconfig: 534 case oldconfig:
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 9df80114b47b..61c35bf2d9cb 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -440,12 +440,11 @@ static void conf_write_string(bool headerfile, const char *name,
440 fputs("\"\n", out); 440 fputs("\"\n", out);
441} 441}
442 442
443static void conf_write_symbol(struct symbol *sym, enum symbol_type type, 443static void conf_write_symbol(struct symbol *sym, FILE *out, bool write_no)
444 FILE *out, bool write_no)
445{ 444{
446 const char *str; 445 const char *str;
447 446
448 switch (type) { 447 switch (sym->type) {
449 case S_BOOLEAN: 448 case S_BOOLEAN:
450 case S_TRISTATE: 449 case S_TRISTATE:
451 switch (sym_get_tristate_value(sym)) { 450 switch (sym_get_tristate_value(sym)) {
@@ -532,7 +531,7 @@ int conf_write_defconfig(const char *filename)
532 goto next_menu; 531 goto next_menu;
533 } 532 }
534 } 533 }
535 conf_write_symbol(sym, sym->type, out, true); 534 conf_write_symbol(sym, out, true);
536 } 535 }
537next_menu: 536next_menu:
538 if (menu->list != NULL) { 537 if (menu->list != NULL) {
@@ -561,7 +560,6 @@ int conf_write(const char *name)
561 const char *basename; 560 const char *basename;
562 const char *str; 561 const char *str;
563 char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1]; 562 char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1];
564 enum symbol_type type;
565 time_t now; 563 time_t now;
566 int use_timestamp = 1; 564 int use_timestamp = 1;
567 char *env; 565 char *env;
@@ -633,14 +631,8 @@ int conf_write(const char *name)
633 if (!(sym->flags & SYMBOL_WRITE)) 631 if (!(sym->flags & SYMBOL_WRITE))
634 goto next; 632 goto next;
635 sym->flags &= ~SYMBOL_WRITE; 633 sym->flags &= ~SYMBOL_WRITE;
636 type = sym->type;
637 if (type == S_TRISTATE) {
638 sym_calc_value(modules_sym);
639 if (modules_sym->curr.tri == no)
640 type = S_BOOLEAN;
641 }
642 /* Write config symbol to file */ 634 /* Write config symbol to file */
643 conf_write_symbol(sym, type, out, true); 635 conf_write_symbol(sym, out, true);
644 } 636 }
645 637
646next: 638next:
@@ -833,8 +825,7 @@ int conf_write_autoconf(void)
833 " * Automatically generated C config: don't edit\n" 825 " * Automatically generated C config: don't edit\n"
834 " * %s\n" 826 " * %s\n"
835 " * %s" 827 " * %s"
836 " */\n" 828 " */\n",
837 "#define AUTOCONF_INCLUDED\n",
838 rootmenu.prompt->text, ctime(&now)); 829 rootmenu.prompt->text, ctime(&now));
839 830
840 for_all_symbols(i, sym) { 831 for_all_symbols(i, sym) {
@@ -843,7 +834,7 @@ int conf_write_autoconf(void)
843 continue; 834 continue;
844 835
845 /* write symbol to config file */ 836 /* write symbol to config file */
846 conf_write_symbol(sym, sym->type, out, false); 837 conf_write_symbol(sym, out, false);
847 838
848 /* update autoconf and tristate files */ 839 /* update autoconf and tristate files */
849 switch (sym->type) { 840 switch (sym->type) {
@@ -946,7 +937,7 @@ static void randomize_choice_values(struct symbol *csym)
946 int cnt, def; 937 int cnt, def;
947 938
948 /* 939 /*
949 * If choice is mod then we may have more items slected 940 * If choice is mod then we may have more items selected
950 * and if no then no-one. 941 * and if no then no-one.
951 * In both cases stop. 942 * In both cases stop.
952 */ 943 */
@@ -1042,10 +1033,10 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
1042 1033
1043 /* 1034 /*
1044 * We have different type of choice blocks. 1035 * We have different type of choice blocks.
1045 * If curr.tri equal to mod then we can select several 1036 * If curr.tri equals to mod then we can select several
1046 * choice symbols in one block. 1037 * choice symbols in one block.
1047 * In this case we do nothing. 1038 * In this case we do nothing.
1048 * If curr.tri equal yes then only one symbol can be 1039 * If curr.tri equals yes then only one symbol can be
1049 * selected in a choice block and we set it to yes, 1040 * selected in a choice block and we set it to yes,
1050 * and the rest to no. 1041 * and the rest to no.
1051 */ 1042 */
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 330e7c0048a8..001003452f68 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -64,7 +64,7 @@ struct expr *expr_alloc_or(struct expr *e1, struct expr *e2)
64 return e2 ? expr_alloc_two(E_OR, e1, e2) : e1; 64 return e2 ? expr_alloc_two(E_OR, e1, e2) : e1;
65} 65}
66 66
67struct expr *expr_copy(struct expr *org) 67struct expr *expr_copy(const struct expr *org)
68{ 68{
69 struct expr *e; 69 struct expr *e;
70 70
@@ -1013,6 +1013,48 @@ int expr_compare_type(enum expr_type t1, enum expr_type t2)
1013#endif 1013#endif
1014} 1014}
1015 1015
1016static inline struct expr *
1017expr_get_leftmost_symbol(const struct expr *e)
1018{
1019
1020 if (e == NULL)
1021 return NULL;
1022
1023 while (e->type != E_SYMBOL)
1024 e = e->left.expr;
1025
1026 return expr_copy(e);
1027}
1028
1029/*
1030 * Given expression `e1' and `e2', returns the leaf of the longest
1031 * sub-expression of `e1' not containing 'e2.
1032 */
1033struct expr *expr_simplify_unmet_dep(struct expr *e1, struct expr *e2)
1034{
1035 struct expr *ret;
1036
1037 switch (e1->type) {
1038 case E_OR:
1039 return expr_alloc_and(
1040 expr_simplify_unmet_dep(e1->left.expr, e2),
1041 expr_simplify_unmet_dep(e1->right.expr, e2));
1042 case E_AND: {
1043 struct expr *e;
1044 e = expr_alloc_and(expr_copy(e1), expr_copy(e2));
1045 e = expr_eliminate_dups(e);
1046 ret = (!expr_eq(e, e1)) ? e1 : NULL;
1047 expr_free(e);
1048 break;
1049 }
1050 default:
1051 ret = e1;
1052 break;
1053 }
1054
1055 return expr_get_leftmost_symbol(ret);
1056}
1057
1016void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken) 1058void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken)
1017{ 1059{
1018 if (!e) { 1060 if (!e) {
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index e57826ced380..3d238db49764 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -192,7 +192,7 @@ struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e
192struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2); 192struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2);
193struct expr *expr_alloc_and(struct expr *e1, struct expr *e2); 193struct expr *expr_alloc_and(struct expr *e1, struct expr *e2);
194struct expr *expr_alloc_or(struct expr *e1, struct expr *e2); 194struct expr *expr_alloc_or(struct expr *e1, struct expr *e2);
195struct expr *expr_copy(struct expr *org); 195struct expr *expr_copy(const struct expr *org);
196void expr_free(struct expr *e); 196void expr_free(struct expr *e);
197int expr_eq(struct expr *e1, struct expr *e2); 197int expr_eq(struct expr *e1, struct expr *e2);
198void expr_eliminate_eq(struct expr **ep1, struct expr **ep2); 198void expr_eliminate_eq(struct expr **ep1, struct expr **ep2);
@@ -207,6 +207,7 @@ struct expr *expr_extract_eq_and(struct expr **ep1, struct expr **ep2);
207struct expr *expr_extract_eq_or(struct expr **ep1, struct expr **ep2); 207struct expr *expr_extract_eq_or(struct expr **ep1, struct expr **ep2);
208void expr_extract_eq(enum expr_type type, struct expr **ep, struct expr **ep1, struct expr **ep2); 208void expr_extract_eq(enum expr_type type, struct expr **ep, struct expr **ep1, struct expr **ep2);
209struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym); 209struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym);
210struct expr *expr_simplify_unmet_dep(struct expr *e1, struct expr *e2);
210 211
211void expr_fprint(struct expr *e, FILE *out); 212void expr_fprint(struct expr *e, FILE *out);
212struct gstr; /* forward */ 213struct gstr; /* forward */
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 3f7240df0f3b..febf0c94d558 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -14,6 +14,7 @@
14static inline const char *gettext(const char *txt) { return txt; } 14static inline const char *gettext(const char *txt) { return txt; }
15static inline void textdomain(const char *domainname) {} 15static inline void textdomain(const char *domainname) {}
16static inline void bindtextdomain(const char *name, const char *dir) {} 16static inline void bindtextdomain(const char *name, const char *dir) {}
17static inline char *bind_textdomain_codeset(const char *dn, char *c) { return c; }
17#endif 18#endif
18 19
19#ifdef __cplusplus 20#ifdef __cplusplus
@@ -67,10 +68,12 @@ struct kconf_id {
67 enum symbol_type stype; 68 enum symbol_type stype;
68}; 69};
69 70
71#ifdef YYDEBUG
72extern int zconfdebug;
73#endif
74
70int zconfparse(void); 75int zconfparse(void);
71void zconfdump(FILE *out); 76void zconfdump(FILE *out);
72
73extern int zconfdebug;
74void zconf_starthelp(void); 77void zconf_starthelp(void);
75FILE *zconf_fopen(const char *name); 78FILE *zconf_fopen(const char *name);
76void zconf_initscan(const char *name); 79void zconf_initscan(const char *name);
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 5f77dcb8977e..5fdf10dc1d8a 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -203,7 +203,7 @@ void menu_add_option(int token, char *arg)
203 } 203 }
204} 204}
205 205
206static int menu_range_valid_sym(struct symbol *sym, struct symbol *sym2) 206static int menu_validate_number(struct symbol *sym, struct symbol *sym2)
207{ 207{
208 return sym2->type == S_INT || sym2->type == S_HEX || 208 return sym2->type == S_INT || sym2->type == S_HEX ||
209 (sym2->type == S_UNKNOWN && sym_string_valid(sym, sym2->name)); 209 (sym2->type == S_UNKNOWN && sym_string_valid(sym, sym2->name));
@@ -221,6 +221,15 @@ static void sym_check_prop(struct symbol *sym)
221 prop_warn(prop, 221 prop_warn(prop,
222 "default for config symbol '%s'" 222 "default for config symbol '%s'"
223 " must be a single symbol", sym->name); 223 " must be a single symbol", sym->name);
224 if (prop->expr->type != E_SYMBOL)
225 break;
226 sym2 = prop_get_symbol(prop);
227 if (sym->type == S_HEX || sym->type == S_INT) {
228 if (!menu_validate_number(sym, sym2))
229 prop_warn(prop,
230 "'%s': number is invalid",
231 sym->name);
232 }
224 break; 233 break;
225 case P_SELECT: 234 case P_SELECT:
226 sym2 = prop_get_symbol(prop); 235 sym2 = prop_get_symbol(prop);
@@ -240,8 +249,8 @@ static void sym_check_prop(struct symbol *sym)
240 if (sym->type != S_INT && sym->type != S_HEX) 249 if (sym->type != S_INT && sym->type != S_HEX)
241 prop_warn(prop, "range is only allowed " 250 prop_warn(prop, "range is only allowed "
242 "for int or hex symbols"); 251 "for int or hex symbols");
243 if (!menu_range_valid_sym(sym, prop->expr->left.sym) || 252 if (!menu_validate_number(sym, prop->expr->left.sym) ||
244 !menu_range_valid_sym(sym, prop->expr->right.sym)) 253 !menu_validate_number(sym, prop->expr->right.sym))
245 prop_warn(prop, "range is invalid"); 254 prop_warn(prop, "range is invalid");
246 break; 255 break;
247 default: 256 default:
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index 272a987f23e0..db56377393d7 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -248,7 +248,7 @@ search_help[] = N_(
248"Only relevant lines are shown.\n" 248"Only relevant lines are shown.\n"
249"\n\n" 249"\n\n"
250"Search examples:\n" 250"Search examples:\n"
251"Examples: USB = > find all symbols containing USB\n" 251"Examples: USB => find all symbols containing USB\n"
252" ^USB => find all symbols starting with USB\n" 252" ^USB => find all symbols starting with USB\n"
253" USB$ => find all symbols ending with USB\n" 253" USB$ => find all symbols ending with USB\n"
254"\n"); 254"\n");
@@ -1266,9 +1266,13 @@ static void conf_choice(struct menu *menu)
1266 if (child->sym == sym_get_choice_value(menu->sym)) 1266 if (child->sym == sym_get_choice_value(menu->sym))
1267 item_make(child, ':', "<X> %s", 1267 item_make(child, ':', "<X> %s",
1268 _(menu_get_prompt(child))); 1268 _(menu_get_prompt(child)));
1269 else 1269 else if (child->sym)
1270 item_make(child, ':', " %s", 1270 item_make(child, ':', " %s",
1271 _(menu_get_prompt(child))); 1271 _(menu_get_prompt(child)));
1272 else
1273 item_make(child, ':', "*** %s ***",
1274 _(menu_get_prompt(child)));
1275
1272 if (child->sym == active){ 1276 if (child->sym == active){
1273 last_top_row = top_row(curses_menu); 1277 last_top_row = top_row(curses_menu);
1274 selected_index = i; 1278 selected_index = i;
@@ -1334,7 +1338,7 @@ static void conf_choice(struct menu *menu)
1334 break; 1338 break;
1335 1339
1336 child = item_data(); 1340 child = item_data();
1337 if (!child || !menu_is_visible(child)) 1341 if (!child || !menu_is_visible(child) || !child->sym)
1338 continue; 1342 continue;
1339 switch (res) { 1343 switch (res) {
1340 case ' ': 1344 case ' ':
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index af6e9f3de950..a796c95fe8a0 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -351,12 +351,16 @@ void sym_calc_value(struct symbol *sym)
351 } 351 }
352 calc_newval: 352 calc_newval:
353 if (sym->dir_dep.tri == no && sym->rev_dep.tri != no) { 353 if (sym->dir_dep.tri == no && sym->rev_dep.tri != no) {
354 struct expr *e;
355 e = expr_simplify_unmet_dep(sym->rev_dep.expr,
356 sym->dir_dep.expr);
354 fprintf(stderr, "warning: ("); 357 fprintf(stderr, "warning: (");
355 expr_fprint(sym->rev_dep.expr, stderr); 358 expr_fprint(e, stderr);
356 fprintf(stderr, ") selects %s which has unmet direct dependencies (", 359 fprintf(stderr, ") selects %s which has unmet direct dependencies (",
357 sym->name); 360 sym->name);
358 expr_fprint(sym->dir_dep.expr, stderr); 361 expr_fprint(sym->dir_dep.expr, stderr);
359 fprintf(stderr, ")\n"); 362 fprintf(stderr, ")\n");
363 expr_free(e);
360 } 364 }
361 newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri); 365 newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri);
362 } 366 }
@@ -686,7 +690,7 @@ const char *sym_get_string_default(struct symbol *sym)
686 switch (sym->type) { 690 switch (sym->type) {
687 case S_BOOLEAN: 691 case S_BOOLEAN:
688 case S_TRISTATE: 692 case S_TRISTATE:
689 /* The visibility imay limit the value from yes => mod */ 693 /* The visibility may limit the value from yes => mod */
690 val = EXPR_AND(expr_calc_value(prop->expr), prop->visible.tri); 694 val = EXPR_AND(expr_calc_value(prop->expr), prop->visible.tri);
691 break; 695 break;
692 default: 696 default:
diff --git a/scripts/mkuboot.sh b/scripts/mkuboot.sh
index 2e3d3cd916b8..446739c7843a 100755
--- a/scripts/mkuboot.sh
+++ b/scripts/mkuboot.sh
@@ -11,7 +11,7 @@ if [ -z "${MKIMAGE}" ]; then
11 if [ -z "${MKIMAGE}" ]; then 11 if [ -z "${MKIMAGE}" ]; then
12 # Doesn't exist 12 # Doesn't exist
13 echo '"mkimage" command not found - U-Boot images will not be built' >&2 13 echo '"mkimage" command not found - U-Boot images will not be built' >&2
14 exit 0; 14 exit 1;
15 fi 15 fi
16fi 16fi
17 17
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 33122ca04e7c..97d2259ae999 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -790,6 +790,7 @@ static const char *section_white_list[] =
790{ 790{
791 ".comment*", 791 ".comment*",
792 ".debug*", 792 ".debug*",
793 ".zdebug*", /* Compressed debug sections. */
793 ".GCC-command-line", /* mn10300 */ 794 ".GCC-command-line", /* mn10300 */
794 ".mdebug*", /* alpha, score, mips etc. */ 795 ".mdebug*", /* alpha, score, mips etc. */
795 ".pdr", /* alpha, score, mips etc. */ 796 ".pdr", /* alpha, score, mips etc. */
@@ -1441,7 +1442,7 @@ static unsigned int *reloc_location(struct elf_info *elf,
1441 int section = shndx2secindex(sechdr->sh_info); 1442 int section = shndx2secindex(sechdr->sh_info);
1442 1443
1443 return (void *)elf->hdr + sechdrs[section].sh_offset + 1444 return (void *)elf->hdr + sechdrs[section].sh_offset +
1444 r->r_offset - sechdrs[section].sh_addr; 1445 r->r_offset;
1445} 1446}
1446 1447
1447static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) 1448static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
diff --git a/scripts/package/builddeb b/scripts/package/builddeb
index 49b74e1ee12d..b0b2357aef42 100644
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -25,8 +25,44 @@ create_package() {
25 chown -R root:root "$pdir" 25 chown -R root:root "$pdir"
26 chmod -R go-w "$pdir" 26 chmod -R go-w "$pdir"
27 27
28 # Attempt to find the correct Debian architecture
29 local forcearch="" debarch=""
30 case "$UTS_MACHINE" in
31 i386|ia64|alpha)
32 debarch="$UTS_MACHINE" ;;
33 x86_64)
34 debarch=amd64 ;;
35 sparc*)
36 debarch=sparc ;;
37 s390*)
38 debarch=s390 ;;
39 ppc*)
40 debarch=powerpc ;;
41 parisc*)
42 debarch=hppa ;;
43 mips*)
44 debarch=mips$(grep -q CPU_LITTLE_ENDIAN=y .config && echo el) ;;
45 arm*)
46 debarch=arm$(grep -q CONFIG_AEABI=y .config && echo el) ;;
47 *)
48 echo "" >&2
49 echo "** ** ** WARNING ** ** **" >&2
50 echo "" >&2
51 echo "Your architecture doesn't have it's equivalent" >&2
52 echo "Debian userspace architecture defined!" >&2
53 echo "Falling back to using your current userspace instead!" >&2
54 echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
55 echo "" >&2
56 esac
57 if [ -n "$KBUILD_DEBARCH" ] ; then
58 debarch="$KBUILD_DEBARCH"
59 fi
60 if [ -n "$debarch" ] ; then
61 forcearch="-DArchitecture=$debarch"
62 fi
63
28 # Create the package 64 # Create the package
29 dpkg-gencontrol -isp -p$pname -P"$pdir" 65 dpkg-gencontrol -isp $forcearch -p$pname -P"$pdir"
30 dpkg --build "$pdir" .. 66 dpkg --build "$pdir" ..
31} 67}
32 68
@@ -40,17 +76,27 @@ else
40fi 76fi
41tmpdir="$objtree/debian/tmp" 77tmpdir="$objtree/debian/tmp"
42fwdir="$objtree/debian/fwtmp" 78fwdir="$objtree/debian/fwtmp"
79kernel_headers_dir="$objtree/debian/hdrtmp"
80libc_headers_dir="$objtree/debian/headertmp"
43packagename=linux-image-$version 81packagename=linux-image-$version
44fwpackagename=linux-firmware-image 82fwpackagename=linux-firmware-image
83kernel_headers_packagename=linux-headers-$version
84libc_headers_packagename=linux-libc-dev
45 85
46if [ "$ARCH" = "um" ] ; then 86if [ "$ARCH" = "um" ] ; then
47 packagename=user-mode-linux-$version 87 packagename=user-mode-linux-$version
48fi 88fi
49 89
50# Setup the directory structure 90# Setup the directory structure
51rm -rf "$tmpdir" "$fwdir" 91rm -rf "$tmpdir" "$fwdir" "$kernel_headers_dir" "$libc_headers_dir"
52mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename" 92mkdir -m 755 -p "$tmpdir/DEBIAN"
53mkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename" 93mkdir -p "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
94mkdir -m 755 -p "$fwdir/DEBIAN"
95mkdir -p "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename"
96mkdir -m 755 -p "$libc_headers_dir/DEBIAN"
97mkdir -p "$libc_headers_dir/usr/share/doc/$libc_headers_packagename"
98mkdir -m 755 -p "$kernel_headers_dir/DEBIAN"
99mkdir -p "$kernel_headers_dir/usr/share/doc/$kernel_headers_packagename"
54if [ "$ARCH" = "um" ] ; then 100if [ "$ARCH" = "um" ] ; then
55 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" 101 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
56fi 102fi
@@ -81,6 +127,9 @@ if grep -q '^CONFIG_MODULES=y' .config ; then
81 fi 127 fi
82fi 128fi
83 129
130make headers_check
131make headers_install INSTALL_HDR_PATH="$libc_headers_dir/usr"
132
84# Install the maintainer scripts 133# Install the maintainer scripts
85# Note: hook scripts under /etc/kernel are also executed by official Debian 134# Note: hook scripts under /etc/kernel are also executed by official Debian
86# kernel packages, as well as kernel packages built using make-kpkg 135# kernel packages, as well as kernel packages built using make-kpkg
@@ -188,6 +237,30 @@ EOF
188 237
189fi 238fi
190 239
240# Build header package
241find . -name Makefile -o -name Kconfig\* -o -name \*.pl > /tmp/files$$
242find arch/x86/include include scripts -type f >> /tmp/files$$
243(cd $objtree; find .config Module.symvers include scripts -type f >> /tmp/objfiles$$)
244destdir=$kernel_headers_dir/usr/src/linux-headers-$version
245mkdir -p "$destdir"
246tar -c -f - -T /tmp/files$$ | (cd $destdir; tar -xf -)
247(cd $objtree; tar -c -f - -T /tmp/objfiles$$) | (cd $destdir; tar -xf -)
248rm -f /tmp/files$$ /tmp/objfiles$$
249arch=$(dpkg --print-architecture)
250
251cat <<EOF >> debian/control
252
253Package: $kernel_headers_packagename
254Provides: linux-headers, linux-headers-2.6
255Architecture: $arch
256Description: Linux kernel headers for $KERNELRELEASE on $arch
257 This package provides kernel header files for $KERNELRELEASE on $arch
258 .
259 This is useful for people who need to build external modules
260EOF
261
262create_package "$kernel_headers_packagename" "$kernel_headers_dir"
263
191# Do we have firmware? Move it out of the way and build it into a package. 264# Do we have firmware? Move it out of the way and build it into a package.
192if [ -e "$tmpdir/lib/firmware" ]; then 265if [ -e "$tmpdir/lib/firmware" ]; then
193 mv "$tmpdir/lib/firmware" "$fwdir/lib/" 266 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
@@ -203,6 +276,18 @@ EOF
203 create_package "$fwpackagename" "$fwdir" 276 create_package "$fwpackagename" "$fwdir"
204fi 277fi
205 278
279cat <<EOF >> debian/control
280
281Package: $libc_headers_packagename
282Section: devel
283Provides: linux-kernel-headers
284Architecture: any
285Description: Linux support headers for userspace development
286 This package provides userspaces headers from the Linux kernel. These headers
287 are used by the installed headers for GNU glibc and other system libraries.
288EOF
289
290create_package "$libc_headers_packagename" "$libc_headers_dir"
206create_package "$packagename" "$tmpdir" 291create_package "$packagename" "$tmpdir"
207 292
208exit 0 293exit 0
diff --git a/scripts/tags.sh b/scripts/tags.sh
index bbbe584d4494..92fdc4546141 100755
--- a/scripts/tags.sh
+++ b/scripts/tags.sh
@@ -123,7 +123,7 @@ exuberant()
123 -I ____cacheline_internodealigned_in_smp \ 123 -I ____cacheline_internodealigned_in_smp \
124 -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \ 124 -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \
125 -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \ 125 -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \
126 --extra=+f --c-kinds=-px \ 126 --extra=+f --c-kinds=+px \
127 --regex-asm='/^ENTRY\(([^)]*)\).*/\1/' \ 127 --regex-asm='/^ENTRY\(([^)]*)\).*/\1/' \
128 --regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/' \ 128 --regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/' \
129 --regex-c++='/^TRACE_EVENT\(([^,)]*).*/trace_\1/' \ 129 --regex-c++='/^TRACE_EVENT\(([^,)]*).*/trace_\1/' \
diff --git a/security/apparmor/include/file.h b/security/apparmor/include/file.h
index be36feabb16a..ab8c6d87f758 100644
--- a/security/apparmor/include/file.h
+++ b/security/apparmor/include/file.h
@@ -15,12 +15,11 @@
15#ifndef __AA_FILE_H 15#ifndef __AA_FILE_H
16#define __AA_FILE_H 16#define __AA_FILE_H
17 17
18#include <linux/path.h>
19
20#include "domain.h" 18#include "domain.h"
21#include "match.h" 19#include "match.h"
22 20
23struct aa_profile; 21struct aa_profile;
22struct path;
24 23
25/* 24/*
26 * We use MAY_EXEC, MAY_WRITE, MAY_READ, MAY_APPEND and the following flags 25 * We use MAY_EXEC, MAY_WRITE, MAY_READ, MAY_APPEND and the following flags
diff --git a/security/apparmor/include/match.h b/security/apparmor/include/match.h
index 734a6d35112c..19ba16e8aacd 100644
--- a/security/apparmor/include/match.h
+++ b/security/apparmor/include/match.h
@@ -15,6 +15,7 @@
15#ifndef __AA_MATCH_H 15#ifndef __AA_MATCH_H
16#define __AA_MATCH_H 16#define __AA_MATCH_H
17 17
18#include <linux/kref.h>
18#include <linux/workqueue.h> 19#include <linux/workqueue.h>
19 20
20#define DFA_NOMATCH 0 21#define DFA_NOMATCH 0
diff --git a/security/selinux/include/avc.h b/security/selinux/include/avc.h
index e94e82f73818..5615081b73ec 100644
--- a/security/selinux/include/avc.h
+++ b/security/selinux/include/avc.h
@@ -15,7 +15,6 @@
15#include <linux/audit.h> 15#include <linux/audit.h>
16#include <linux/lsm_audit.h> 16#include <linux/lsm_audit.h>
17#include <linux/in6.h> 17#include <linux/in6.h>
18#include <linux/path.h>
19#include <asm/system.h> 18#include <asm/system.h>
20#include "flask.h" 19#include "flask.h"
21#include "av_permissions.h" 20#include "av_permissions.h"
diff --git a/Documentation/vm/slabinfo.c b/tools/slub/slabinfo.c
index 92e729f4b676..516551c9f172 100644
--- a/Documentation/vm/slabinfo.c
+++ b/tools/slub/slabinfo.c
@@ -607,7 +607,7 @@ static int debug_opt_scan(char *opt)
607 } 607 }
608 608
609 for ( ; *opt; opt++) 609 for ( ; *opt; opt++)
610 switch (*opt) { 610 switch (*opt) {
611 case 'F' : case 'f': 611 case 'F' : case 'f':
612 if (sanity) 612 if (sanity)
613 return 0; 613 return 0;
@@ -1127,7 +1127,7 @@ static void read_slab_dir(void)
1127 continue; 1127 continue;
1128 switch (de->d_type) { 1128 switch (de->d_type) {
1129 case DT_LNK: 1129 case DT_LNK:
1130 alias->name = strdup(de->d_name); 1130 alias->name = strdup(de->d_name);
1131 count = readlink(de->d_name, buffer, sizeof(buffer)); 1131 count = readlink(de->d_name, buffer, sizeof(buffer));
1132 1132
1133 if (count < 0) 1133 if (count < 0)
@@ -1143,7 +1143,7 @@ static void read_slab_dir(void)
1143 case DT_DIR: 1143 case DT_DIR:
1144 if (chdir(de->d_name)) 1144 if (chdir(de->d_name))
1145 fatal("Unable to access slab %s\n", slab->name); 1145 fatal("Unable to access slab %s\n", slab->name);
1146 slab->name = strdup(de->d_name); 1146 slab->name = strdup(de->d_name);
1147 slab->alias = 0; 1147 slab->alias = 0;
1148 slab->refs = 0; 1148 slab->refs = 0;
1149 slab->aliases = get_obj("aliases"); 1149 slab->aliases = get_obj("aliases");
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index b2b3c2d1cf8b..7f06884ecd41 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -104,6 +104,8 @@ static int cpio_mkslink(const char *name, const char *target,
104 char s[256]; 104 char s[256];
105 time_t mtime = time(NULL); 105 time_t mtime = time(NULL);
106 106
107 if (name[0] == '/')
108 name++;
107 sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" 109 sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
108 "%08X%08X%08X%08X%08X%08X%08X", 110 "%08X%08X%08X%08X%08X%08X%08X",
109 "070701", /* magic */ 111 "070701", /* magic */
@@ -152,6 +154,8 @@ static int cpio_mkgeneric(const char *name, unsigned int mode,
152 char s[256]; 154 char s[256];
153 time_t mtime = time(NULL); 155 time_t mtime = time(NULL);
154 156
157 if (name[0] == '/')
158 name++;
155 sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" 159 sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
156 "%08X%08X%08X%08X%08X%08X%08X", 160 "%08X%08X%08X%08X%08X%08X%08X",
157 "070701", /* magic */ 161 "070701", /* magic */
@@ -245,6 +249,8 @@ static int cpio_mknod(const char *name, unsigned int mode,
245 else 249 else
246 mode |= S_IFCHR; 250 mode |= S_IFCHR;
247 251
252 if (name[0] == '/')
253 name++;
248 sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" 254 sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
249 "%08X%08X%08X%08X%08X%08X%08X", 255 "%08X%08X%08X%08X%08X%08X%08X",
250 "070701", /* magic */ 256 "070701", /* magic */
@@ -303,18 +309,18 @@ static int cpio_mkfile(const char *name, const char *location,
303 309
304 mode |= S_IFREG; 310 mode |= S_IFREG;
305 311
306 retval = stat (location, &buf);
307 if (retval) {
308 fprintf (stderr, "File %s could not be located\n", location);
309 goto error;
310 }
311
312 file = open (location, O_RDONLY); 312 file = open (location, O_RDONLY);
313 if (file < 0) { 313 if (file < 0) {
314 fprintf (stderr, "File %s could not be opened for reading\n", location); 314 fprintf (stderr, "File %s could not be opened for reading\n", location);
315 goto error; 315 goto error;
316 } 316 }
317 317
318 retval = fstat(file, &buf);
319 if (retval) {
320 fprintf(stderr, "File %s could not be stat()'ed\n", location);
321 goto error;
322 }
323
318 filebuf = malloc(buf.st_size); 324 filebuf = malloc(buf.st_size);
319 if (!filebuf) { 325 if (!filebuf) {
320 fprintf (stderr, "out of memory\n"); 326 fprintf (stderr, "out of memory\n");
@@ -332,6 +338,8 @@ static int cpio_mkfile(const char *name, const char *location,
332 /* data goes on last link */ 338 /* data goes on last link */
333 if (i == nlinks) size = buf.st_size; 339 if (i == nlinks) size = buf.st_size;
334 340
341 if (name[0] == '/')
342 name++;
335 namesize = strlen(name) + 1; 343 namesize = strlen(name) + 1;
336 sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" 344 sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
337 "%08lX%08X%08X%08X%08X%08X%08X", 345 "%08lX%08X%08X%08X%08X%08X%08X",